Zophar's Message Domain

Zophar's Message Domain (http://www.zophar.net/forums/index.php)
-   Rom Hack (http://www.zophar.net/forums/forumdisplay.php?f=8)
-   -   ASM Problem (http://www.zophar.net/forums/showthread.php?t=8272)

sleepydude 01-31-2007 08:51 PM

ASM Problem
 
So, I'm writing a little routine to inject into an existing routine in FF6 and everything seems to be working fine until it comes time to return (RTL) from my subroutine. When it returns it goes to some crazy location and I can't figure out why, mostly because I barely know what I'm doing when it comes to ASM.
<P ID="signature"></P>

Lenophis 01-31-2007 08:58 PM

Re: ASM Problem
 
<blockquote><font class="small">In reply to:</font><hr>

So, I'm writing a little routine to inject into an existing routine in FF6 and everything seems to be working fine until it comes time to return (RTL) from my subroutine. When it returns it goes to some crazy location and I can't figure out why, mostly because I barely know what I'm doing when it comes to ASM.

<hr></blockquote>
Ok, this should be easy enough to fix.
How do you jump to this routine?
Did you insert your hook in the middle of pulling anything off of the stack? (PLP, PLA, PLX, etc)

JSR -> RTS
JSL -> RTL
JMP -> none, but if it's in a long call, you RTL. If it's in a normal call, you RTS.
<P ID="signature"><img src=http://dragonsbrethren.elazulspad.net/images/lenorhdnsignature.png></P>

sleepydude 01-31-2007 09:59 PM

Re: ASM Problem
 
It's a JSL => RTL thing. Basically I'm trying to throw a couple event commands in the middle of a normal routine, something to do with the menu loading and unloading. So yeah in the midst of the event executions there's some stack pushing and pulling I'm pretty sure, they're pretty invoved routines. I'm guessing what your saying is that the return locations are stored in the stack, so what I'd need to do is go through and account for whatever is taken off or put on the stack during the subroutine. Or I'm wrong.
<P ID="signature"></P>

Jathys 02-01-2007 03:51 AM

Re: ASM Problem
 
If you change the values of X, Y, or A in your coding, I'd test the following:
PHX : PHY : PHA <-- start of your coding
PLX : PLY : PLA <--- end of your coding

Do that and find out if you have any improvements. Whenever I have screwy stuff go on when hijacking code, it's because I changed X/Y when they were needed (RTS vs RTL is actually the second most common cause for me).

If that doesn't help...
1) Make sure you're pointing to your own code correctly. Basic stuff, I know, but it's an easy thing to screw up. Are you 100% sure that your code is running?
2) If you know your code's definitely running, comment out everything except for the absolute barebones (ie- the code you replaced with your pointer, if needed, and the RTL).... Does everything still get messed up?
<P ID="signature">http://jathys.zophar.net/index.htmlhttp://jathys.zophar.net/images/zd_avatar.gif</a></P>

Imzogelmo 02-01-2007 07:05 AM

Re: ASM Problem
 
Also, make sure that you didn't change the size of your X/Y/A, or at least change it back before you exit.

If you're doing the standard fare, remove-stuff-here-and-add-JSR, make sure the stuff you transferred to your new routine didn't have any kind of branches going part-way through it, or branching out of it, unless the branch is going to the very next line after it (which should be okay).
<P ID="signature"></P>

Gideon Zhi 02-02-2007 06:01 PM

Re: ASM Problem
 
> It's a JSL => RTL thing. Basically I'm trying to throw a couple event commands in the middle of a normal routine, something to do with the menu loading and unloading. So yeah in the midst of the event executions there's some stack pushing and pulling I'm pretty sure, they're pretty invoved routines. I'm guessing what your saying is that the return locations are stored in the stack, so what I'd need to do is go through and account for whatever is taken off or put on the stack during the subroutine. Or I'm wrong.

This is very likely a stack fault. I (accidentally) do it all the time - push something, then forget to pull it later. Make sure that the stack pointer remains the same on the first op in your routine as it is on the last (your RTL); if it's different at RTL than it is when it first lands in the routine, you have a stack fault. At this point, you need to make sure that you don't pull without pushing first, and that you haven't pushed anything that didn't get pulled at some point.

The other possibility is that your code is mismatching with the M or X flags on the status register. If you're trying to LDA #$0000 when M is set, the game will only LDA #$00 and then you've got an extra byte dangling there which can really, really mess things up. Go through and make sure that you're obeying the flags set on the status register as well.

These are absolutely the two most common mistakes I make when writing 65816, and believe me, I write a lot of 65816.

<P ID="signature"><hr><center>http://agtp.romhack.net<img src=http://agtp.romhack.net/linkage.gif></a>
Aeon Genesis ~ Aiyah! Thank you for the always and always.</center></P>

sleepydude 02-02-2007 11:22 PM

Re: ASM Problem
 
Sorry I haven't responded, I've been away, but thanks for all your suggestions. I'll try them out and let you all know what happened.
<P ID="signature"></P>

sleepydude 02-03-2007 02:34 AM

Re: ASM Problem
 
Yeah, the stack counter was messed up. I fixed it and after a little further tweaking my hack is almost working perfectly. I injected into the wrong routine, but that's easy enough to fix. Thanks.
<P ID="signature"></P>


All times are GMT. The time now is 06:39 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.