1
Programming / C++: array indexing issues
« on: February 06, 2018, 09:06:04 pm »
I can't have a long int as the index into an array of chars?
Just curious about a graphics decompressor I had previously written.
Example usage
I suppose I don't really NEED a 64KB decompression window (for SNES, probably even 32KB is overkill)
Just curious about a graphics decompressor I had previously written.
Code: [Select]
unsigned char readbyte, readbyte2, TypeKey, LZIterations, IterationKey;
unsigned long int romoff, WriteIndex;
unsigned short int DecompIterations, LZKey, LZReadIndex, Write=0x24;
unsigned char DataBuffer[0x10024];
(the odd size is because the original game code deliberately underflowed the decompression scratchpad position with 0x24 zeroed bytes to set the read position behind the write position.)Example usage
Code: [Select]
while(LZIterations>0)
{
DataBuffer[Write]=DataBuffer[LZReadIndex];
LZReadIndex++; Write++;
DataBuffer[Write]=DataBuffer[LZReadIndex];
LZReadIndex++; Write++;
LZIterations--;
}
I was using the long WriteIndex as the array index and it would crash/return corrupt data, replacing it with the short int Write made it work, but I don't know if that is correct.I suppose I don't really NEED a 64KB decompression window (for SNES, probably even 32KB is overkill)