gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 677bfc9a44a6516933cc0e598c9e6d7ea382404c parent b5f2dcb585ba4b2d6e1bf83938d56ee1359df138 Author: Toxa <untoxa@mail.ru> Date: Fri, 3 Jun 2022 21:00:07 +0300 GB: universal __sdcccall(0)/__sdcccall(1) ___sdcc_bcall_ehl banked call trampoline second approach Diffstat:
| M | gbdk-lib/libc/targets/sm83/___sdcc_bcall.s | 52 | ++++++++++++++++++++++++++-------------------------- |
| M | gbdk-lib/libc/targets/sm83/___sdcc_bcall_ehl.s | 38 | +++++++++++++++++++++----------------- |
2 files changed, 47 insertions(+), 43 deletions(-)
diff --git a/gbdk-lib/libc/targets/sm83/___sdcc_bcall.s b/gbdk-lib/libc/targets/sm83/___sdcc_bcall.s @@ -1,30 +1,30 @@ - .include "global.s" + .include "global.s" - .area _HOME + .area _HOME + +;; !!! ONLY WORKS WITH __sdcccall(0) calling convention ___sdcc_bcall:: -banked_call:: ; Performs a long call. - pop hl ; Get the return address - ldh a, (__current_bank) - push af ; Push the current bank onto the stack - ld a, (hl+) ; Fetch the call address - ld e, a - ld a, (hl+) - ld d, a - ld a, (hl+) ; ...and page - inc hl ; Yes this should be here - push hl ; Push the real return address - ldh (__current_bank), a - ld (.MBC_ROM_PAGE), a ; Perform the switch - ld l, e - ld h, d - rst 0x20 +banked_call:: ; Performs a long call. + pop hl ; Get the return address + ldh a, (__current_bank) + push af ; Push the current bank onto the stack + ld a, (hl+) ; Fetch the call address + ld e, a + ld a, (hl+) + ld d, a + ld a, (hl+) ; ...and page + inc hl ; Yes this should be here + push hl ; Push the real return address + ldh (__current_bank), a + ld (.MBC_ROM_PAGE), a ; Perform the switch + ld l, e + ld h, d + rst 0x20 banked_ret:: - pop hl ; Get the return address - pop bc ; Pop the old bank - ld c, a - ld a, b - ldh (__current_bank), a - ld (.MBC_ROM_PAGE), a - ld a, c ; we must preserve A for the new calling convention - jp (hl) + pop bc ; Pop return address + pop af ; Pop the old bank + ldh (__current_bank), a + ld (.MBC_ROM_PAGE), a + push bc + ret diff --git a/gbdk-lib/libc/targets/sm83/___sdcc_bcall_ehl.s b/gbdk-lib/libc/targets/sm83/___sdcc_bcall_ehl.s @@ -1,18 +1,22 @@ - .include "global.s" + .include "global.s" - .area _HOME + .area _HOME -___sdcc_bcall_ehl:: ; Performs a long call. - ldh a, (__current_bank) - push af ; Push the current bank onto the stack - ld a, e - ldh (__current_bank), a - ld (.MBC_ROM_PAGE), a ; Perform the switch - rst 0x20 - pop bc ; Pop the old bank - ld c, a - ld a, b - ldh (__current_bank), a - ld (.MBC_ROM_PAGE), a - ld a, c - ret - +___sdcc_bcall_ehl:: ; Performs a long call. + ldh a, (__current_bank) + push af ; Push the current bank onto the stack + ld a, e + ldh (__current_bank), a + ld (.MBC_ROM_PAGE), a ; Perform the switch + rst 0x20 + push hl + ldhl sp, #3 + ld h, (hl) + ld l, a + ld a, h + ldh (__current_bank), a + ld (.MBC_ROM_PAGE), a + ld a, l + pop hl + add sp, #2 + ret +
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.