SuperSonicX Mon Jul 11, 2011 2:47 pm
This is a tutorial to add ring requirements to certain actions. Here is a standard check for rings:
- Code:
cmpi.w #20,($FFFFFE20).w ; do you have at least 20 rings?
bcc.s Code_Okay ; if yes, branch
Notice the code "cpmi.w #20($FFFFFE20).w". This calls to check your rings and see how many you have. bcc.s Code_Okay says to branch if you have enough. For example, put this at the beginning of any Sonic Routine (I'm showing the spindash here.) replacing the X with your number of rings.
- Code:
cmpi.w #X,($FFFFFE20).w ; do you have at least X rings?
bcc.s SonicSD_Okay ; if yes, branch
rts
SonicSD_Okay:
This will require X amount of rings to do the spindash. If you don't, the code will end without doing anything.
Subtracting Rings if has required amount:
Look at this code:
- Code:
sub.w #20,($FFFFFE20).w ; minus 20 rings
move.b #$80,($FFFFFE1D).w ; update ring counter
This says to subtract rings. So add this at the beginning of the SonicSD_Okay code you just added, changing X to the number you used above.
- Code:
sub.w #X,($FFFFFE20).w ; minus X rings
move.b #$80,($FFFFFE1D).w ; update ring counter
So this will take away X rings when you attempt a spindash with more than X rings.
This is it for the Tutorial: No credit required.