gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit ac368f922ef05e3713affa9f7bb152c67d4dc4dd parent 7c08346a6d55446fa75999dba5dc5994fa3038fb Author: Toxa <untoxa@mail.ru> Date: Thu, 9 May 2024 15:41:48 +0300 SMS/GG: fix joypad()/waitpad()/waitpadup() definitions; add delay required for reading the 3 and 6-button Genesis controller in waitpad()/waitpadup() for the SMS Diffstat:
| M | gbdk-lib/include/sms/sms.h | 6 | +++--- |
| M | gbdk-lib/libc/targets/z80/gg/pad.s | 13 | ++++++++++--- |
| M | gbdk-lib/libc/targets/z80/sms/pad.s | 48 | +++++++++++++++++++++++++++++++++++------------- |
3 files changed, 48 insertions(+), 19 deletions(-)
diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -438,18 +438,18 @@ void delay(uint16_t d) Z88DK_FASTCALL; /** Reads and returns the current state of the joypad. */ -uint8_t joypad(void) OLDCALL PRESERVES_REGS(b, c, d, e, h, iyh, iyl); +uint8_t joypad(void) OLDCALL PRESERVES_REGS(b, c, d, e, iyh, iyl); /** Waits until at least one of the buttons given in mask are pressed. */ -uint8_t waitpad(uint8_t mask) Z88DK_FASTCALL PRESERVES_REGS(b, c, d, e, iyh, iyl); +uint8_t waitpad(uint8_t mask) Z88DK_FASTCALL PRESERVES_REGS(d, e, iyh, iyl); /** Waits for the directional pad and all buttons to be released. Note: Checks in a loop that doesn't HALT at all, so the CPU will be maxed out until this call returns. */ -void waitpadup(void) PRESERVES_REGS(b, c, d, e, iyh, iyl); +void waitpadup(void) PRESERVES_REGS(d, e, iyh, iyl); /** Multiplayer joypad structure. diff --git a/gbdk-lib/libc/targets/z80/gg/pad.s b/gbdk-lib/libc/targets/z80/gg/pad.s @@ -4,7 +4,10 @@ .module JOYPad .area _HOME - ;; Get Keypad Button Status +; Get Keypad Button Status +; return result in l +; +;uint8_t joypad(void) OLDCALL PRESERVES_REGS(b, c, d, e, iyh, iyl); _joypad:: .jpad:: in a, (.JOY_PORT1) @@ -24,7 +27,9 @@ _joypad:: ld l, a ret - ;; Wait until all buttons have been released +; Wait until all buttons have been released +; +; void waitpadup(void) PRESERVES_REGS(d, e, iyh, iyl); .padup:: _waitpadup:: 1$: @@ -39,7 +44,9 @@ _waitpadup:: ret - ;; Wait for the key to be pressed +; Wait for the key to be pressed +; +; uint8_t waitpad(uint8_t mask) Z88DK_FASTCALL PRESERVES_REGS(d, e, iyh, iyl); _waitpad:: .wait_pad:: ld c, l diff --git a/gbdk-lib/libc/targets/z80/sms/pad.s b/gbdk-lib/libc/targets/z80/sms/pad.s @@ -4,7 +4,10 @@ .module JOYPad .area _HOME - ;; Get Keypad Button Status +; Get Keypad Button Status +; return result in l +; +;uint8_t joypad(void) OLDCALL PRESERVES_REGS(b, c, d, e, iyh, iyl); _joypad:: .jpad:: in a, (.JOY_PORT1) @@ -54,27 +57,46 @@ _joypad:: ld l, a ret - ;; Wait until all buttons have been released +; wait for 1/4 frame for the MD 3 and 6-button controllers +do_sleep: + push bc + ld c, #10 +0$: + ld b, #0xff +1$: + .rept 4 + ex (sp), hl + .endm + djnz 1$ + + dec c + jr nz, 0$ + pop bc + ret + +; Wait until all buttons have been released +; +; void waitpadup(void) PRESERVES_REGS(d, e, iyh, iyl); .padup:: _waitpadup:: 1$: - ld c, #0x7f ; wait for .jpad return zero 127 times in a row -2$: call .jpad + ld a, l or a ; have all buttons been released? - jr nz, 1$ ; not yet + ret z + call do_sleep ; wait 1/4 frame + jr 1$ ; not yet - dec c - jr nz, 2$ - - ret - - ;; Wait for the key to be pressed +; Wait for the key to be pressed +; +; uint8_t waitpad(uint8_t mask) Z88DK_FASTCALL PRESERVES_REGS(d, e, iyh, iyl); _waitpad:: .wait_pad:: ld c, l 1$: call .jpad ; read pad + ld a, l and c ; compare with mask? - jr z, 1$ ; loop if no intersection - ret + ret nz ; return if intersection + call do_sleep ; wait 1/4 frame + jr 1$
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.