News: 11 March 2016 - Forum Rules

Author Topic: [MD/GEN] Game has a custom table limited to 46 entries, want to change that  (Read 1534 times)

fusaru

  • Jr. Member
  • **
  • Posts: 22
    • View Profile
I'm facing a problem with the Genesis game "Raiden Trad".
The game uses its own system to load palettes. I've figure out pretty much everything I need, but I can't add further palettes to the game due to an (intentional?) limit.

Palettes are not loaded through pointers. Instead an auto generated index number is used. Here is a copy & pasted example from the game
Code: [Select]
00 28 7F FF 00 01 05 02
0028 - wait 28 counts
7FFF -RAM location? (not important for this, can be ignored)
0001 - make the palette permanent  (not important for this, can be ignored)
05 - give me a palette
02 - give me palette with index 02 (possible values are 01 to 46)

All palettes are stored in a big table in the ROM, starting here: 027200
The position of the palette in the table equals the index number. So the first palette is 01 (00 is not used), the second one is 02 etc.

Here is a piece of this big table, showing how the color data for stage 2 is stored:
Code: [Select]
00 00 01 08 00 04 00 10 00 00 00 00 06 00 00 04 00 40 04 40 00 44 04 44 00 4C 04 48 04 84 08 84 04 88 0A AA 08 C8 00 88
00 00 01 08 00 04 00 10  defines that this a background palette (other types are character palettes, single flashing colors etc...)
00 00 00 00 06 00 00 04 00 40 04 40 00 44 04 44 00 4C 04 48 04 84 08 84 04 88 0A AA 08 C8 00 88  the actual color data

Up to 46 entries are possible. 46 sounds like a lot, but actually its not for this type of game.
Everything after palette Nr. 46 is ignored. So if I add another one, I can't call with 47 (also tried 48, 49... no dice). To make sure I understood this, I've added a new palette right in the middle of the table. It was perfectly usable. All palettes after it got a new index number though, and the last one, now the 47th palette, became unusable.

So I need to know what defines this 46 palette limit and how to change it. How does one approach such an issue?
(MD hacks):
Complete --> see contributions page
Twin Hawk (arcade graphics), Toki

FAST6191

  • Hero Member
  • *****
  • Posts: 3299
    • View Profile
Interesting setup. It is not out of the realm of reason but it is not something I see much, much less on older systems. I am going to have to properly go through what you wrote when I get back but it sounds like some pointer maths is involved at some level.

Assuming the 46 limit is not a bit limit (it is not 2 to any natural power so it is likely not that) then a first step is to evaluate the function that decodes the 46, if it was the same as a power of 2 then you can still change things but it is often a lot more work as expanding it means sorting everything that follows from it and in this case I would not be surprised to hear the next number limit you encounter is 64.
You would mainly want to start by looking for something "if number is greater than 46 then assume 46" type arrangements, coding like that is not necessary in games and often omitted (compared to say a car or a computer machine tool which would really want to check the numbers it is getting are sane) but still worth starting there. For the 68K then there are not so many compare arrangements so it might be a mask of some form (something like do boolean AND with 0F for every index value).
It could run deeper after this -- just because you have 16 bit addressing you don't have 2^16 bits of RAM and the 46 could be a soft limit of some form to prevent it but that is how I would start approaching this.

fusaru

  • Jr. Member
  • **
  • Posts: 22
    • View Profile
Problem solved.

Thank you very much for the input. The way I've described it made things look way too complicated. Some vital info was also missing,
The hint with the mask nevertheless brought to me to the right track.

So here is how it works (I've created 2 new palettes and used them ingame without problems)
The game's palette table starts at 027200. Or so I thought at first. This here is placed right before the game's palettes and is the key to everything:
Code: [Select]
00 50 A0 00 C8 00 F0 00 18 01 40 01 68 01 90 01 B8 01 E0 01 28 02 50 02 98 02 C0 02 DC 02 04 03 2C 03 44 03 6C 03 94 03 BC 03 00 00 CE 03 E0 03 F2 03 04 04 16 04 00 00 00 00 28 04 50 04 78 04 A0 04 B2 04 C4 04 EC 04 04 05 16 05 3E 05 66 05 78 05 A0 05 C8 05 F0 05 18 06 40 06 68 06 7E 06 88 06 EC 06 40 07 68 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 CC 07 D6 07 16 08 46 09 86 09 C6 09 D6 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Upon closer inspection, what I copied and pasted above actually defines palette location.
00 50 needs to be ignored, I don't know what that does.
After understanding that, it was a simple as swapping bytes e.g.
A0 00 C8 00 F0 00 18 01 --> swapped this to 00A0, 00C8, 000F, 0118
Going forward from 027200 by 00A0 bytes brought me to the first palette
Going forward from 027200 by 00C8 bytes brought me to the second palette and so on...

So making a new palette what a simple as pasting the new palette data right after the final, 46th palette, and then adding the distance (byte swapped) to that table I've pasted above. Theoretically this should be expandable until I have a palette that is has a distance of FFFF bytes from  027200.
(MD hacks):
Complete --> see contributions page
Twin Hawk (arcade graphics), Toki