gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 912554e01b5ff3616302a1e3f85b3b7aeba8fd55 parent 869db71c758af4a40f73d671177e8a133b79ed91 Author: toxa <untoxa@mail.ru> Date: Fri, 16 Oct 2020 23:03:14 +0300 asm version of pad_ex Diffstat:
| M | gbdk-lib/libc/gb/Makefile | 3 | ++- |
| D | gbdk-lib/libc/gb/pad_ex.c | 85 | ------------------------------------------------------------------------------- |
| A | gbdk-lib/libc/gb/pad_ex.s | 117 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | gbdk-lib/libc/gb/sgb.s | 10 | +++++----- |
4 files changed, 124 insertions(+), 91 deletions(-)
diff --git a/gbdk-lib/libc/gb/Makefile b/gbdk-lib/libc/gb/Makefile @@ -5,7 +5,7 @@ TOPDIR = ../.. THIS = gb PORT = gbz80 -CSRC = digits.c gprint.c gprintf.c gprintln.c gprintn.c pad_ex.c +CSRC = digits.c gprint.c gprintf.c gprintln.c gprintn.c ASSRC = cgb.s cpy_data.s drawing.s f_ibm_sh.s \ f_italic.s f_min.s f_spect.s get_bk_t.s get_data.s \ @@ -23,6 +23,7 @@ ASSRC = cgb.s cpy_data.s drawing.s f_ibm_sh.s \ crash_handler.s \ ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ mv_spr.s \ + pad_ex.s \ crt0.s ifeq ($(ASM),asxxxx) diff --git a/gbdk-lib/libc/gb/pad_ex.c b/gbdk-lib/libc/gb/pad_ex.c @@ -1,85 +0,0 @@ -#include <gb/gb.h> -#include <gb/sgb.h> - -UINT8 joypad_init(UINT8 npads, joypads_t * joypads) { - UINT8 np = npads; - if (sgb_check()) { - switch (np) { - case 2: - sgb_transfer("\x89\x01"); - break; - case 4: - sgb_transfer("\x89\x03"); - break; - default: - sgb_transfer("\x89\x00"); - np = 1; - break; - } - } else np = 1; - return joypads->npads = np; -} - -void joypad_ex(joypads_t * joypads) __naked { - joypads; - __asm - lda hl, 2(sp) - ld a, (hl+) - ld e, a - ld d, (hl) - - ld a, (de) - inc de - or a - jr z, 2$ - - dec a - and #3 - inc a -2$: - push bc - ld b, a -1$: - ld a, #0x30 - ldh (#_P1_REG), a - ldh a, (#_P1_REG) - and #0x0f - sub #0x0f - cpl - inc a ; A contains joypad number - - and #3 ; buffer overrun protection - - add e ; HL = DE + A - ld l, a - adc d - sub l - ld h, a - - ld a, #0x20 - ldh (#_P1_REG), a - ldh a, (#_P1_REG) - ldh a, (#_P1_REG) - and #0x0f - ld c, a - ld a, #0x10 - ldh (#_P1_REG), a - ldh a, (#_P1_REG) - ldh a, (#_P1_REG) - ldh a, (#_P1_REG) - ldh a, (#_P1_REG) - ldh a, (#_P1_REG) - ldh a, (#_P1_REG) - and #0x0f - swap a - or c - cpl - ld (hl), a - - dec b - jr nz, 1$ - pop bc - - ret - __endasm; -} diff --git a/gbdk-lib/libc/gb/pad_ex.s b/gbdk-lib/libc/gb/pad_ex.s @@ -0,0 +1,117 @@ + .include "global.s" + + .area _BASE + +_joypad_init:: + call _sgb_check + ld a, e + or a + jr Z, 1$ + + ldhl sp, #2 + ld a, (hl) + + cp a, #0x02 + jr Z, 3$ + cp a, #0x04 + jr Z, 4$ + jr 5$ +3$: + ld hl, #pkt_req_2 + call .sgb_transfer + call .sgb_wait4 + ld e, #0x02 + jr 2$ +4$: + ld hl, #pkt_req_4 + call .sgb_transfer + call .sgb_wait4 + ld e, #0x04 + jr 2$ +5$: + ld hl, #pkt_req_1 + call .sgb_transfer + call .sgb_wait4 +1$: + ld e, #0x01 +2$: + ldhl sp, #3 + ld a, (hl+) + ld h, (hl) + ld l, a + ld a, e + ld (hl+), a + xor a + ld (hl+), a + ld (hl+), a + ld (hl+), a + ld (hl), a + ret + +pkt_req_4: + .db 0x89, 0x03 +pkt_req_2: + .db 0x89, 0x01 +pkt_req_1: + .db 0x89, 0x00 + +_joypad_ex:: + lda hl, 2(sp) + ld a, (hl+) + ld e, a + ld d, (hl) + +.joypad_ex:: + ld a, (de) + inc de + or a + jr z, 2$ + + dec a + and #3 + inc a +2$: + push bc + ld b, a +1$: + ld a, #0x30 + ldh (#.P1), a + ldh a, (#.P1) + and #0x0f + sub #0x0f + cpl + inc a ; A contains joypad number + + and #3 ; buffer overrun protection + + add e ; HL = DE + A + ld l, a + adc d + sub l + ld h, a + + ld a, #0x20 + ldh (#.P1), a + ldh a, (#.P1) + ldh a, (#.P1) + and #0x0f + ld c, a + ld a, #0x10 + ldh (#.P1), a + ldh a, (#.P1) + ldh a, (#.P1) + ldh a, (#.P1) + ldh a, (#.P1) + ldh a, (#.P1) + ldh a, (#.P1) + and #0x0f + swap a + or c + cpl + ld (hl), a + + dec b + jr nz, 1$ + pop bc + + ret diff --git a/gbdk-lib/libc/gb/sgb.s b/gbdk-lib/libc/gb/sgb.s @@ -36,7 +36,7 @@ _sgb_check:: ; Banked PUSH BC LD HL,#.MLT_REQ_2 CALL .sgb_transfer - CALL .wait4 + CALL .sgb_wait4 LDH A,(.P1) AND #0x03 CP #0x03 @@ -76,7 +76,7 @@ _sgb_check:: ; Banked .sgb_mode: LD HL,#.MLT_REQ_1 CALL .sgb_transfer - CALL .wait4 + CALL .sgb_wait4 LD E,#0xFF POP BC RET @@ -88,7 +88,7 @@ _sgb_transfer:: LD H,(HL) LD L,A CALL .sgb_transfer - CALL .wait4 + CALL .sgb_wait4 POP BC RET @@ -142,10 +142,10 @@ _sgb_transfer_nowait:: POP BC DEC B RET Z - CALL .wait4 ; Software wait for about 4 frames + CALL .sgb_wait4 ; Software wait for about 4 frames JR 1$ -.wait4: +.sgb_wait4:: LD DE,#7000 1$: NOP ; 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.