2018-06-24 14:09:41 +00:00
|
|
|
Predef::
|
2013-09-09 03:54:12 +00:00
|
|
|
; Call predefined function a.
|
|
|
|
; Preserves bc, de, hl and f.
|
|
|
|
|
2018-01-23 22:39:09 +00:00
|
|
|
ld [wPredefID], a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hROMBank]
|
2013-09-09 03:54:12 +00:00
|
|
|
push af
|
|
|
|
|
|
|
|
ld a, BANK(GetPredefPointer)
|
|
|
|
rst Bankswitch
|
2020-12-23 21:29:30 +00:00
|
|
|
call GetPredefPointer ; stores hl in wPredefHL
|
2013-09-09 03:54:12 +00:00
|
|
|
|
|
|
|
; Switch to the new function's bank
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
; Instead of directly calling stuff,
|
|
|
|
; push it to the stack in reverse.
|
|
|
|
|
|
|
|
ld hl, .Return
|
|
|
|
push hl
|
2016-04-10 18:42:14 +00:00
|
|
|
|
2013-09-09 03:54:12 +00:00
|
|
|
; Call the Predef function
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wPredefAddress]
|
2013-09-09 03:54:12 +00:00
|
|
|
ld h, a
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wPredefAddress + 1]
|
2013-09-09 03:54:12 +00:00
|
|
|
ld l, a
|
|
|
|
push hl
|
|
|
|
|
|
|
|
; Get hl back
|
2020-12-23 21:29:30 +00:00
|
|
|
ld a, [wPredefHL]
|
2013-09-09 03:54:12 +00:00
|
|
|
ld h, a
|
2020-12-23 21:29:30 +00:00
|
|
|
ld a, [wPredefHL + 1]
|
2013-09-09 03:54:12 +00:00
|
|
|
ld l, a
|
|
|
|
ret
|
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.Return:
|
2013-09-09 03:54:12 +00:00
|
|
|
; Clean up after the Predef call
|
|
|
|
|
|
|
|
ld a, h
|
2020-12-23 21:29:30 +00:00
|
|
|
ld [wPredefHL], a
|
2013-09-09 03:54:12 +00:00
|
|
|
ld a, l
|
2020-12-23 21:29:30 +00:00
|
|
|
ld [wPredefHL + 1], a
|
2013-09-09 03:54:12 +00:00
|
|
|
|
|
|
|
pop hl
|
|
|
|
ld a, h
|
|
|
|
rst Bankswitch
|
|
|
|
|
2020-12-23 21:29:30 +00:00
|
|
|
ld a, [wPredefHL]
|
2013-09-09 03:54:12 +00:00
|
|
|
ld h, a
|
2020-12-23 21:29:30 +00:00
|
|
|
ld a, [wPredefHL + 1]
|
2013-09-09 03:54:12 +00:00
|
|
|
ld l, a
|
|
|
|
ret
|