Zophar's Message Domain

Go Back   Zophar's Message Domain > Emulation Talk > Rom Hack

Reply
 
Thread Tools Display Modes
Old 01-31-2007, 09:51 PM   #1
sleepydude
Junior Member
 
Join Date: Dec 2006
Posts: 24
Default 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>
sleepydude is offline   Reply With Quote
Old 01-31-2007, 09:58 PM   #2
Lenophis
Senior Member
 
Lenophis's Avatar
 
Join Date: Apr 2003
Posts: 1,386
Default 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>
__________________
Lenophis is offline   Reply With Quote
Old 01-31-2007, 10:59 PM   #3
sleepydude
Junior Member
 
Join Date: Dec 2006
Posts: 24
Default 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>
sleepydude is offline   Reply With Quote
Old 02-01-2007, 04:51 AM   #4
Jathys
Senior Member
 
Join Date: May 2000
Posts: 1,840
Default 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.html</a></P>
Jathys is offline   Reply With Quote
Old 02-01-2007, 08:05 AM   #5
Imzogelmo
Junior Member
 
Join Date: Dec 2006
Posts: 5
Default 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>
Imzogelmo is offline   Reply With Quote
Old 02-02-2007, 07:01 PM   #6
Gideon Zhi
Senior Member
 
Join Date: Jul 1999
Posts: 499
Default 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>
Gideon Zhi is offline   Reply With Quote
Old 02-03-2007, 12:22 AM   #7
sleepydude
Junior Member
 
Join Date: Dec 2006
Posts: 24
Default 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 is offline   Reply With Quote
Old 02-03-2007, 03:34 AM   #8
sleepydude
Junior Member
 
Join Date: Dec 2006
Posts: 24
Default 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>
sleepydude is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:53 PM.

Contact Us - Zophar's Domain - Archive - Top

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