Romhacking.net

Romhacking => Programming => Topic started by: justin3009 on January 21, 2011, 10:54:34 pm

Title: [MMX3] Why isn't this code working?
Post by: justin3009 on January 21, 2011, 10:54:34 pm
Code: [Select]
$00/D674 69 40       ADC #$40                A:4002 X:0030 Y:002A P:envMXdIzc - Switching to Acid Bomb via menu
$00/D676 A8          TAY                     A:4042 X:0030 Y:002A P:envMXdIzc

What this is doing is carrying the value so it picks out what palette to use for X's weapon palettes. (Same goes for Zero)

What I have in place of that code is 20 82 FF so it jumps to FF82 for the extra.  This is what the code reads now.

Code: [Select]
$00/FF82 AD 8E 0A    LDA $0A8E  [$06:0A8E]   A:4002 X:0030 Y:002A P:envMXdIzc
$00/FF85 D0 04       BNE $04    [$FF8B]      A:4000 X:0030 Y:002A P:envMXdIZc
$00/FF87 69 40       ADC #$40                A:4000 X:0030 Y:002A P:envMXdIZc
$00/FF89 A8          TAY                     A:4040 X:0030 Y:002A P:envMXdIzc
$00/FF8A 60          RTS                     A:4040 X:0030 Y:0040 P:envMXdIzc

For some reason, it refuses to load the palette correctly at all now.  Strangely, this code was working before but I accidentally reverted back to an older version before I put in these changes :/



Edit: Well I got the code to work correctly but it's incredibly inconvenient.

Code: [Select]
$00/FF82 69 40       ADC #$40                A:4002 X:0030 Y:0015 P:envMXdIzc
$00/FF84 A8          TAY                     A:4042 X:0030 Y:0015 P:envMXdIzc
$00/FF85 AD 8E 0A    LDA $0A8E  [$06:0A8E]   A:4042 X:0030 Y:0042 P:envMXdIzc - Check character. 00 = X, 02 = Zero
$00/FF88 D0 01       BNE $01    [$FF8B]      A:4002 X:0030 Y:0042 P:envMXdIzc
$00/FF8B AD 0B 0A    LDA $0A0B  [$06:0A0B]   A:4002 X:0030 Y:0042 P:envMXdIzc - Check current weapon equipped. 00 = Nothing, anything above is.
$00/FF8E D0 04       BNE $04    [$FF94]      A:4002 X:0030 Y:0042 P:envMXdIzc
$00/FF94 69 40       ADC #$40                A:4002 X:0030 Y:0042 P:envMXdIzc - Repeats the code at FF82.
$00/FF96 A8          TAY                     A:4042 X:0030 Y:0042 P:envMXdIzc
$00/FF97 60          RTS                     A:4042 X:0030 Y:0042 P:envMXdIzc

I really don't like this at all.  It seems a lot sloppier.  I'm not sure why I have to do it this way now.  It was working properly before..How strange.
Title: Re: [MMX3] Why isn't this code working?
Post by: Mauron on January 21, 2011, 11:46:55 pm
Could you post the full routine? I can't see anything wrong with the part you posted (although it can be helpful to put a CLC before an ADC).
Title: Re: [MMX3] Why isn't this code working?
Post by: justin3009 on January 22, 2011, 12:00:21 am
Code: [Select]
$00/D66E A2 30       LDX #$30                A:4020 X:0048 Y:0015 P:envMXdIZc
$00/D670 AD 0B 0A    LDA $0A0B  [$06:0A0B]   A:4020 X:0030 Y:0015 P:envMXdIzc
$00/D673 18          CLC                     A:4002 X:0030 Y:0015 P:envMXdIzc
$00/D674 69 40       ADC #$40                A:4002 X:0030 Y:002A P:envMXdIzc
$00/D676 A8          TAY                     A:4042 X:0030 Y:002A P:envMXdIzc

Well there's probably my issue right there.  It loads up what weapon is there first then clears the carry flag.  Since I have it loading another variable that ends up being 00 or 02, it cancels out the LDA here ~_~

Edit: Slightly reduced the code.

Code: [Select]
$00/FF82 69 40       ADC #$40                A:4002 X:0030 Y:0015 P:envMXdIzc
$00/FF84 A8          TAY                     A:4042 X:0030 Y:0015 P:envMXdIzc
$00/FF85 AD 8E 0A    LDA $0A8E  [$06:0A8E]   A:4042 X:0030 Y:0042 P:envMXdIzc - Check character
$00/FF88 D0 01       BNE $01    [$FF8B]      A:4002 X:0030 Y:0042 P:envMXdIzc
$00/FF8B AD 0B 0A    LDA $0A0B  [$06:0A0B]   A:4002 X:0030 Y:0042 P:envMXdIzc - Check Weapon
$00/FF8E D0 03       BNE $03    [$FF93]      A:4002 X:0030 Y:0042 P:envMXdIzc
$00/FF93 60          RTS                     A:4002 X:0030 Y:0042 P:envMXdIzc
- Since it already has the ADC being loaded, you can just cut straight to an RTS and bam.  That cuts down on 4 bytes of code.