n64 icon indicating copy to clipboard operation
n64 copied to clipboard

gfxdis: Support comma separated values and 0x prefixes in data input

Open Kelebek1 opened this issue 4 days ago • 0 comments

This change is intended to make it easier to copy values from m2c-generated code. m2c gives output like:

        temp_v0 = gDisplayListHead;
        gDisplayListHead = temp_v0 + 8;
        temp_v0->words.w1 = 0;
        temp_v0->words.w0 = 0xE7000000;
        temp_v0_2 = gDisplayListHead;
        gDisplayListHead = temp_v0_2 + 8;
        temp_v0_2->words.w1 = 0;
        temp_v0_2->words.w0 = 0xE3000A01;
        temp_v0_3 = gDisplayListHead;
        gDisplayListHead = temp_v0_3 + 8;
        temp_v0_3->words.w0 = 0xE200001C;
        temp_v0_3->words.w1 = 0x504240;
        temp_v0_4 = gDisplayListHead;
        gDisplayListHead = temp_v0_4 + 8;
        temp_v0_4->words.w1 = 0;
        temp_v0_4->words.w0 = 0xE3000C00;
        temp_v0_5 = gDisplayListHead;
        gDisplayListHead = temp_v0_5 + 8;
        temp_v0_5->words.w1 = 0;
        temp_v0_5->words.w0 = 0xE3001201;
        temp_v0_6 = gDisplayListHead;
        gDisplayListHead = temp_v0_6 + 8;
        temp_v0_6->words.w1 = 0xFF2FFFFF;
        temp_v0_6->words.w0 = 0xFC119623;

Currently this has a few issues:

  • gfxdis does not support the 0x prefix, so you can't just double click and copy, you need to specifically select just the bytes.
  • gfxdis doesn't support non-padded values, it adds bytes 1 by 1 to the vector, so if all 4 aren't provided, everything gets misaligned. Since m2c doesn't do this, we have to manually fill in 8 digits when m2c just outputs a 0, for example.
  • m2c doesn't just output 0 but values with all differing digit counts, such as 0x504240 above. You have to be careful to count the digits and pad the remaining, and it's easy to make mistakes with this. Add 1 digit too many or too few, and it's very hard to see, and breaks everything after the mistake.

This PR adds the abilities to separate values with commas, supports the 0x hex prefix, and it pads out values which are not 8 digits, as long as one of those markers are included to separate the inputs.

For example, this input is now valid from the above m2c: 0xE7000000,0,E3000A0100xE200001C0x5042400xE3000C0000xE300120100xFC1196230xFF2FFFFF and it decompiles correctly. The only thing unsupported is if the second comma is removed, because there's no way to differentiate the 0 being the second graphics word, and the E3 being the first word of the next command. However you can replace the second comma with 0x and it works just fine, which is how values should be input anyway. Commas are very optional and m2c gives the 0x on everything besides 0 pretty much.

There may be off-by-one errors or something I've done wrong here, I'm bad at C. My manual tests seem to work though. These are optional additions and don't invalidate any current gfxdis inputs.

Kelebek1 avatar Feb 22 '25 19:02 Kelebek1