News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

[SM] little help on hijacking

Started by auronlives69, August 24, 2013, 07:17:31 PM

Previous topic - Next topic

auronlives69

so after a year or two of slacking it i finally decided to continue working on my sm hack, thought before i start building more rooms i should learn some asm i made this code that refills health at a steady pace whenever low health warning is on but i can only make it work with fool xray with bts at 03
LoRom

org $9498B2
DW $B300
org $94B300


LDA $0A6A ;WARNING CHECK
CMP #$0000
BEQ END

LDA $05D5 ;TIMER
CMP #$0080
BEQ REFILL
INC A
STA $05D5
RTS

REFILL:
INC $09C2
STZ $05D5

END: RTS


i want this to be ran every frame but im a bit confused on how to hijack routines any help appreciated

Smiley

#1
The main site and Scyzer's tank have some documents containing a bunch of useful breakpoints.
Tank doc
Main site doc
The main game loop starts at $82:8948. Here's a small chunk of code to get you started:
lorom

org $828957
JSR $F720 ;let's hi-jack the main game loop...
org $82F720 ;make sure this is free space

STZ $0590 ;original code that was replaced by that JSR

Go nuts. Remember that the main loop also runs when the game is paused, in some menus etc. so you might want to add a check for the game state if you use this. The game state is held at $7E:0998 and the main state is 08 (normal gameplay). Scyzer's doc has a list of the other game states if you need them.

Hijacking routines isn't all that hard. The hardest part is finding your breakpoint if it isn't documented anywhere. Once you have your breakpoint, all you have to do is jump to some free space and write your code there. Always remember to put the original code you replaced with the jump somewhere in your code, otherwise you'll probably mess something up. For example, JSR $F720 in the above code replaced STZ $0590, so I put that in the very beginning of the new code.

And by the way, that CMP #$0000 in your code is useless; if you put a conditional branch, like BEQ, without a CMP before it, it'll automatically check it against 0. So you never ever need CMP #$0000.

Hope this helps.

auronlives69

thank you this is very useful  :grin: i can finally get the wheels moving with that push

auronlives69

hmm so i got it to work but not in the way i intended, it works when i do
lorom

org $828957 ;warning0A6A, health09C2
JSR $F720 ;main game loop
org $82F720 ;free space

STZ $0590 ;original code that was replaced by that JSR


LDA $0A6A ;warning check
BEQ END

LDA $0998 ;state check
CMP #$000F ;pause menu
BEQ END

LDA $05D5 ;timer
CMP #$0040
BEQ REFILL
INC $05D5
RTS

REFILL:
INC $09C2
STZ $05D5

END: RTS


but when i try to compare #$0008 and branch if not equal it seems to ignore the piece
LDA $0998 ;state check
CMP #$0008 ;normal value
BNE END



Black Falcon

#4
Quote from: auronlives69 on August 26, 2013, 07:24:34 AM

but when i try to compare #$0008 and branch if not equal it seems to ignore the piece
LDA $0998 ;state check
CMP #$0008 ;normal value
BNE END


What do you mean by ignore? If it just bypasses that BNE then that's normal, because if this code is run every frame during normal gameplay then $0998 is set to 0x08.
Note that this wouldn't work as soon as you press start, because that triggers gamestate 0x0C, which fades to black while doing normal gameplay thus disabling the code. When the screen is finally black it calls gamestates 0x0D and 0x0E, which load everything pause screen specific. The actual pause screen state 0x0F is only set after all the loading and transitioning is done.
Also you can't just INC health like that. You should put an overflow check in there, else the health would be increased indefinitely Aaaand nvm that.


Hope it helps  :^_^:

Smiley

Quote from: Black Falcon on August 26, 2013, 10:09:56 AM
Also you can't just INC health like that. You should put an overflow check in there, else the health would be increased indefinitely:
His code only increments the health if the low health warning is on, so in this case an overflow check isn't required.

auronlives69

thanks for clearing that up falcon, i was going crazy trying to figure it out