adam_smasher wrote:
Can you give an example of this? I'm curious as to how these routines access their arguments and fix the return address.
Both the examples I gave were from real games. call 017d is Final Fantasy Legend 2, and rst 18 is Final Fantasy Legend 3.
Accessing the arguments is pretty simple. FFL3 just does this, since there's only one argument byte and it doesn't care about preserving registers at this point:
Code:
pop hl
ldi a,(hl)
push hl
FFL2 is a bit more complicated:
Code:
push af
push hl
push de
ld hl,sp+06
ld a,(hl) ; LSB of return address
ld e,a
add a,03
ldi (hl),a ; adjusted return address
ld d,(hl) ; MSB of return address
jr nc,+
inc (hl) ; adjust MSB if carry occurred
+
ld l,e
ld h,d ; hl now points to the first argument byte