Language…
11 users online: crocodileman94, Green, Humpty Dumpty Magazine, Leozone20, Mischievous Marc, mmmdoggy, Nciktendo, sholmes, TriStain, uropsalis, Zavok - Guests: 69 - Bots: 175
Users: 62,822 (2,620 active)
Latest user: Leozone20

# Help/Feedback on creating a routine.

Hello all,

I'm writing some code for a combo system for my hack, and both wanted some help on learning how to access this code via killing an enemy, and also any feedback if there's something wrong or if something can be improved upon with this code:
Code
```; \$7C will be the RAM address for the combo timer. When at 0, the combo bonus is calculated and added to score, then the combo amount returns to 0.

LDA #\$6F
STA \$7C|!addr   ; Set timer to #\$6F every time an enemy is stomped.
INC A
STA \$1697|!addr ; Increase combo count by 1. (might be unnecessary because this number already increases when stomping enemies.)
BRA .ComboLoop

.ComboLoop:
LDA \$72|!addr   ; Mario's State, \$00 = Grounded
CMP #\$00
BNE .ComboLoop  ; Loop if not grounded.
LDA \$14|!addr   ; Every 4th frame...
AND #\$03
BNE .ComboLoop  ; Loop if not 4th frame.
LDA \$7C|!addr   ; Combo Timer (Will be set to #\$6F when enemy stomped)
CMP #\$00
BRA .ComboLoop  ; Otherwise, decrement timer and loop once more.

.EndCombo:      ; Squares the combo count and adds to the score using the multiplication register.
STA \$4202
STA \$4203

NOP #4
REP #\$20
LDA \$1487|!addr ; 16-bit RAM for the score tally patch.
SEP #\$20
STZ \$1697       ; Clear combo count.
RTL
```

Any and all help is much appreciated!

First things first, don't use the "|!addr" bit with 8-bit addresses (i.e. \$xx addresses). SA-1 doesn't remap those the same way as 16-bit addresses (\$xxxx), so it won't actually work correctly. Instead, 8-bit addresses can be left as is (i.e. "LDA \$xx" is fine even with SA-1). The only time you need to do something else is if you're accessing one of those 8-bit addresses as a 16-bit address (i.e. as \$00xx), in which case you need to use "|!dp" instead.

Secondly, this code does also have a few issues with infinite looping. The SNES is essentially single-threaded, so RAM addresses won't change on their own unless you are explicitly running code to do that. For instance, this code:
Code
```.ComboLoop:
LDA \$72|!addr   ; Mario's State, \$00 = Grounded
CMP #\$00
BNE .ComboLoop  ; Loop if not grounded.```

If \$72 is non-zero, this code will end up in an infinite loop since there's no code running that will actually change \$72's value. It is stuck at that non-zero value.

Instead of waiting for an event to come to you, routines like this work better as a response to an event. You want to find somewhere that has code already running under the conditions you need (for instance, SMW already has an event routine for bouncing off an enemy at \$01AB46), and then add your additional functionality to that. Depending on what specifically you need, that would be where you'd likely want to hijack with a patch.

Professional frame-by-frame time wizard. YouTube - Twitter - SMW Glitch List - SMW Randomizer