I'm a long-time fan of old DOS games and a first-time reverse engineer
I'm currently trying to write a program to read tile sets from Captain Comic II: Fractured Reality (one of my all-time favorites) and output the tiles to an image buffer.
I used the information on the modding wiki and I have it almost working, in that the first tile in the set comes out fine, but subsequent tiles are corrupted. I think the problem is in the function I'm using to decode the RLE data from the file and write it to a buffer:
(I'm compiling it using Borland Turbo C++ v3.0 for DOSBox)
Code: Select all
// read in a single tile's worth of data from file and decode to tile buffer
int fr_get_tile(FILE **fr, unsigned char *tile_buffer)
{
int i, run_count, total, data;
if (*fr == NULL) return -1;
memset(tile_buffer, 0, TILE_BYTE_SIZE);
i = total = 0;
while (i < TILE_BYTE_SIZE) {
if ((run_count = getc(*fr)) == EOF) return -1;
if (run_count == 0) {
return 0;
} else if (run_count < 128) {
// copy literal bytes
for (total += run_count; run_count--; i++) {
if ((data = getc(*fr)) == EOF) return -1;
*tile_buffer++ = data;
}
} else {
// copy a run
run_count = 256 - run_count;
if ((data = getc(*fr)) == EOF) return -1;
for (total += run_count; run_count--; i++) {
*tile_buffer++ = data;
}
}
}
return i;
}
Thanks