mirror of https://github.com/pret/pokecrystal.git
recomment Predef and GetPredefFn -> GetPredefPointer
This commit is contained in:
parent
a6ad4ad37e
commit
5888db3493
113
main.asm
113
main.asm
|
@ -2910,74 +2910,55 @@ INCLUDE "engine/farcall.asm"
|
||||||
|
|
||||||
|
|
||||||
Predef: ; 2d83
|
Predef: ; 2d83
|
||||||
; call a function from given id a
|
; Call predefined function a.
|
||||||
|
; Preserves bc, de, hl and f.
|
||||||
|
|
||||||
; relies on $cfb4-8
|
ld [PredefID], a
|
||||||
|
ld a, [hROMBank]
|
||||||
; this function is somewhat unreadable at a glance
|
|
||||||
; the execution flow is as follows:
|
|
||||||
; save bank
|
|
||||||
; get function from id
|
|
||||||
; call function
|
|
||||||
; restore bank
|
|
||||||
; these are pushed to the stack in reverse
|
|
||||||
|
|
||||||
; most of the $cfbx trickery is just juggling hl (which is preserved)
|
|
||||||
; this allows hl, de and bc to be passed to the function
|
|
||||||
|
|
||||||
; input:
|
|
||||||
; a: id
|
|
||||||
; parameters bc, de, hl
|
|
||||||
|
|
||||||
; store id
|
|
||||||
ld [$cfb4], a
|
|
||||||
|
|
||||||
; save bank
|
|
||||||
ld a, [hROMBank] ; current bank
|
|
||||||
push af
|
push af
|
||||||
|
|
||||||
; get Predef function to call
|
ld a, BANK(GetPredefPointer)
|
||||||
; GetPredefFn also stores hl in $cfb5-6
|
|
||||||
ld a, BANK(GetPredefFn)
|
|
||||||
rst Bankswitch
|
rst Bankswitch
|
||||||
call GetPredefFn
|
call GetPredefPointer ; stores hl in PredefTemp
|
||||||
; switch bank to Predef function
|
|
||||||
|
; Switch to the new function's bank
|
||||||
rst Bankswitch
|
rst Bankswitch
|
||||||
|
|
||||||
; clean up after Predef call
|
; Instead of directly calling stuff,
|
||||||
ld hl, .cleanup
|
; push it to the stack in reverse.
|
||||||
|
|
||||||
|
ld hl, .Return
|
||||||
push hl
|
push hl
|
||||||
|
|
||||||
; call Predef function from ret
|
; Call the Predef function
|
||||||
ld a, [$cfb7]
|
ld a, [PredefAddress]
|
||||||
ld h, a
|
ld h, a
|
||||||
ld a, [$cfb8]
|
ld a, [PredefAddress + 1]
|
||||||
ld l, a
|
ld l, a
|
||||||
push hl
|
push hl
|
||||||
|
|
||||||
; get hl back
|
; Get hl back
|
||||||
ld a, [$cfb5]
|
ld a, [PredefTemp]
|
||||||
ld h, a
|
ld h, a
|
||||||
ld a, [$cfb6]
|
ld a, [PredefTemp + 1]
|
||||||
ld l, a
|
ld l, a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.cleanup
|
.Return
|
||||||
; store hl
|
; Clean up after the Predef call
|
||||||
|
|
||||||
ld a, h
|
ld a, h
|
||||||
ld [$cfb5], a
|
ld [PredefTemp], a
|
||||||
ld a, l
|
ld a, l
|
||||||
ld [$cfb6], a
|
ld [PredefTemp+1], a
|
||||||
|
|
||||||
; restore bank
|
pop hl
|
||||||
pop hl ; popping a pushed af. h = a (old bank)
|
|
||||||
ld a, h
|
ld a, h
|
||||||
rst Bankswitch
|
rst Bankswitch
|
||||||
|
|
||||||
; get hl back
|
ld a, [PredefTemp]
|
||||||
ld a, [$cfb5]
|
|
||||||
ld h, a
|
ld h, a
|
||||||
ld a, [$cfb6]
|
ld a, [PredefTemp + 1]
|
||||||
ld l, a
|
ld l, a
|
||||||
ret
|
ret
|
||||||
; 2dba
|
; 2dba
|
||||||
|
@ -14969,39 +14950,31 @@ x set x + $100 * $40000
|
||||||
; 854b
|
; 854b
|
||||||
|
|
||||||
|
|
||||||
GetPredefFn: ; 854b
|
GetPredefPointer: ; 854b
|
||||||
; input:
|
; Return the bank and address of PredefID in a and PredefAddress.
|
||||||
; [$cfb4] id
|
|
||||||
|
|
||||||
; save hl for later
|
; Save hl for later (back in Predef)
|
||||||
ld a, h
|
ld a, h
|
||||||
ld [$cfb5], a
|
ld [PredefTemp], a
|
||||||
ld a, l
|
ld a, l
|
||||||
ld [$cfb6], a
|
ld [PredefTemp + 1], a
|
||||||
|
|
||||||
push de
|
push de
|
||||||
|
ld a, [PredefID]
|
||||||
; get id
|
|
||||||
ld a, [$cfb4]
|
|
||||||
ld e, a
|
ld e, a
|
||||||
ld d, $0
|
ld d, 0
|
||||||
ld hl, PredefPointers
|
ld hl, PredefPointers
|
||||||
; seek
|
|
||||||
add hl, de
|
add hl, de
|
||||||
add hl, de
|
add hl, de
|
||||||
add hl, de
|
add hl, de
|
||||||
|
|
||||||
pop de
|
pop de
|
||||||
|
|
||||||
; store address in [$cfb7-8]
|
|
||||||
; addr lo
|
|
||||||
ld a, [hli]
|
ld a, [hli]
|
||||||
ld [$cfb8], a
|
ld [PredefAddress + 1], a
|
||||||
; addr hi
|
|
||||||
ld a, [hli]
|
ld a, [hli]
|
||||||
ld [$cfb7], a
|
ld [PredefAddress], a
|
||||||
; get bank
|
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
|
|
||||||
ret
|
ret
|
||||||
; 856b
|
; 856b
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue