i make small utility for processing GRF files. I successfully parse size, info, ....... yrel but i have problem with sprite decompressing. Maybe i wrong understand decompress procedure from http://www.ttdpatch.net/grfcodec/grf.html . For example, i extract (with HEX editor) first sprite from trg1r.grf (TTD cursor).
Code: Select all
0x0000: 14 0F 0F 0F 0E 0E 0D 0D 0D 0D 0C 0C 0B 0B 0A 20
0x0010: 20 20 20 20 20 E0 05 01 0F A0 17 01 21 A8 18 07
0x0020: 0E 0A 0A 0A 0A 0A 0A E0 05 02 21 20 B0 18 02 0E
0x0030: 0E A8 17 A0 18 01 0D A8 17 01 58 B0 18 01 0D C0
0x0040: 18 02 0C 0D E8 17 98 18 B8 19 01 20 90 18 B0 19
0x0050: A0 18 01 0C C0 17 90 19 02 0C 0C D8 73 C0 19 B0
0x0060: 18 01 0B D8 8A E8 19 90 19 02 0B 0B D8 A1 B0 19
0x0070: C0 18 D0 B8 E8 19 90 19 C8 CF 90 19 A0 B1 90 19
0x0080: 90 19 90 19 90 19 90 19 90 19 02 0B 0B E8 0E 90
0x0090: 19 C9 5B 01 88 E8 0E 90 19 E0 17 C9 5A 90 19 B0
0x00A0: 17 90 19 B8 17 90 19 02 88 6A B8 5C 90 19 D0 17
MSB is not set (0), it means code + next 127 bytes are verbatim chunk if code<>0. If code=0, next 128 bytes (without code byte) are verbatim chunk.
Now, we are on address 0x0080 (code): value 0x90 (10010000)
MSB is set (1), it means bits 3..7 are negate value of the length, bits 0..2 are high bits of an offset.
Low bits are in the next byte (lofs).
0x0081 (lofs): value 0x19 (00011001)
Okay. Bits 3..7 from code: 10010, after negate: 01101 = length = 13 bytes.
Bits 0..2 from code | lofs: 000 | 00011001 = offset = 25 bytes.
Now i copy to output 13 bytes from address 0x0067 (actual 0x0080 - offset 0x0019) and return back to address 0x0082.
byte (code) 0x0082: ........ etc
--
It's right? I use this method but output is "strange". Josef's C source don't help me. C isn't my favorite language.
And sorry, my english is wrong.
Michal