Tuesday, November 4, 2014

C64 Mercenary geometry decoded

Thanks to http://icu64.blogspot.com/ visual editing tools I've figured out the geometry data structure for pickup items in the C64 game of Mercenary. Perhaps this also applies to outdoor structures as well, I haven't check yet. Due to the fact that line segments only use 4 bits to reference verticie indicies, there can only be 16 verticies referenced (0-15.)

pickup object data structure:
1 byte: index of last verticie on the list (max of 0F)
Each verticie is 3 bytes, size of verticie section = (last vert index+1)*3
depth byte, height byte, width byte all from origin (check signed byte number system)
1 byte: index of last line segment on the list (I suppose max of FF)
Each line segment is 1 byte, size of line segment section = last seg index+1.
high nibble is index of 1st verticie, low nibble is index of 2nd verticie
signed byte number system:
FF,00,01, and 80, are all 00 (don't ask me why so many)

FE is -1, 81 is -126  (magnitude = FF - number)
02 is +1, 7F is +126 (magnitude = number - 01)

Example: table in Mercenary Second City that you can fly
Pickup item verticie magnitudes are a very small fraction of the 126 maximum. It reads this data structure every frame, so data compression isn't an option as compression requires compute time which is a very scarce resource on the 1Mhz CPU.

overview: 3e61-3e8e item 06 (Table) 45 bytes

3e61 0b num of last verticie

3e62 f9 vert 00 depth of right-rear leg bottom
3e63 00 vert 00 height of right-rear leg bottom
3e64 f3 vert 00 width of right-rear leg bottom

3e65 07 vert 01 depth of right-front leg bottom
3e66 00 vert 01 height of right-front leg bottom
3e67 f3 vert 01 width of right-front leg bottom

3e68 07 vert 02 depth of left-front leg bottom
3e69 00 vert 02 height of left-front leg bottom
3e6a 0d vert 02 width of left-front leg bottom

3e6b f9 vert 03 depth of left-rear leg bottom
3e6c 00 vert 03 height of left-rear leg bottom
3e6d 0d vert 03 width of left-rear leg bottom

3e6e f9 vert 04 depth of right-rear leg top
3e6f 06 vert 04 height of right-rear leg top
3d70 f3 vert 04 width of right-rear leg top

3e71 07 vert 05 depth of right-front leg top
3e72 06 vert 05 height of right-front leg top
3e73 f3 vert 05 width of right-front leg top

3e74 07 vert 06 depth of left-front leg top
3e75 06 vert 06 height of left-front leg top
3e76 0d vert 06 width of left-front leg top

3e77 f9 vert 07 depth of left-rear leg top
3e78 06 vert 07 height of left-rear leg top
3e79 0d vert 07 width of left-rear leg top

3e7a f6 vert 08 depth of right rear corner
3e7b 06 vert 08 height of right rear corner
3e7c f0 vert 08 width of right rear corner

3e7d 0a vert 09 depth of right front corner
3e7e 06 vert 09 height of right front corner
3e7f f0 vert 09 width of right front corner

3e80 0a vert 0a depth of left front corner
3e81 06 vert 0a height of left front corner
3e82 10 vert 0a width of left front corner

3e83 f6 vert 0b depth of left rear corner
3e84 06 vert 0b height of left rear corner
3d85 10 vert 0b width of left rear corner

3e86 07 num of last line segment

3e87 04 seg 00 right rear leg (right-rear leg bottom to right-rear leg top)
3e88 15 seg 01 right front leg (right-front leg bottom to right-front leg top)
3e89 26 seg 02 left front leg (left-front leg bottom to left-front leg top)
3e8a 37 seg 03 left rear leg (left-rear leg bottom to left-rear leg top)
3e8b 89 seg 04 right side (right-rear to right-front)
3e8c 9a seg 05 front side (right-front to left front)
3e8d ab seg 06 left side (left-front to left-rear)
3e3e b8 seg 07rear side (left-rear to right rear)

No comments:

Post a Comment