git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit a99c8d6ac9d97bdea9eb5976d99237475e0deb82
parent 3eecf7e644f90331260461a678fc253da27ec662
Author: Toxa <untoxa@mail.ru>
Date:   Tue,  7 Sep 2021 21:27:54 +0300

SMS/GG: redefine buttons, support Game Gear START button

Diffstat:
Mgbdk-lib/include/gb/gb.h10+++++-----
Mgbdk-lib/include/sms/sms.h13+++++++++----
Mgbdk-lib/libc/targets/gbz80/gb/global.s10+++++-----
Mgbdk-lib/libc/targets/z80/gg/global.s12++++++++++--
Agbdk-lib/libc/targets/z80/gg/pad.s43+++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/libc/targets/z80/gg/pad_ex.s77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dgbdk-lib/libc/targets/z80/pad.s38--------------------------------------
Mgbdk-lib/libc/targets/z80/sms/global.s4++--
Agbdk-lib/libc/targets/z80/sms/pad.s38++++++++++++++++++++++++++++++++++++++
Rgbdk-lib/libc/targets/z80/pad_ex.s -> gbdk-lib/libc/targets/z80/sms/pad_ex.s0
10 files changed, 189 insertions(+), 56 deletions(-)

diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -33,14 +33,14 @@ @see joypad */ -#define J_START 0x80U -#define J_SELECT 0x40U -#define J_B 0x20U -#define J_A 0x10U -#define J_DOWN 0x08U #define J_UP 0x04U +#define J_DOWN 0x08U #define J_LEFT 0x02U #define J_RIGHT 0x01U +#define J_A 0x10U +#define J_B 0x20U +#define J_SELECT 0x40U +#define J_START 0x80U /** Screen modes. Normally used by internal functions only. diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -35,14 +35,19 @@ @see joypad */ -#define J_START 0b01000000 -#define J_SELECT 0b01000000 -#define J_B 0b00100000 -#define J_A 0b00010000 #define J_UP 0b00000001 #define J_DOWN 0b00000010 #define J_LEFT 0b00000100 #define J_RIGHT 0b00001000 +#define J_A 0b00010000 +#define J_B 0b00100000 +#if defined(__TARGET_sms) +#define J_SELECT 0b00100000 +#define J_START 0b00010000 +#elif defined(__TARGET_gg) +#define J_SELECT 0b00100000 +#define J_START 0b10000000 +#endif /** Screen modes. Normally used by internal functions only. diff --git a/gbdk-lib/libc/targets/gbz80/gb/global.s b/gbdk-lib/libc/targets/gbz80/gb/global.s @@ -27,14 +27,14 @@ rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) ;; Keypad - .START = 0x80 - .SELECT = 0x40 - .B = 0x20 - .A = 0x10 - .DOWN = 0x08 .UP = 0x04 + .DOWN = 0x08 .LEFT = 0x02 .RIGHT = 0x01 + .A = 0x10 + .B = 0x20 + .SELECT = 0x40 + .START = 0x80 .P14 = 0x10 .P15 = 0x20 diff --git a/gbdk-lib/libc/targets/z80/gg/global.s b/gbdk-lib/libc/targets/z80/gg/global.s @@ -1,3 +1,11 @@ + .GG_P0 = 0x00 + .GG_P1 = 0x01 + .GG_P2 = 0x02 + .GG_P3 = 0x03 + .GG_P4 = 0x04 + .GG_P5 = 0x05 + .GG_P6 = 0x06 + .MEMORY_CTL = 0x3E .MEMCTL_JOYON = 0b00000000 @@ -113,8 +121,8 @@ .RIGHT = 0b00001000 .A = 0b00010000 .B = 0b00100000 - .SELECT = 0b01000000 ; map to RESET - .START = 0b01000000 ; map to RESET + .SELECT = 0b00100000 ; map to B + .START = 0b10000000 ; Game Gear Start button .JOY_PORT1 = 0xDC diff --git a/gbdk-lib/libc/targets/z80/gg/pad.s b/gbdk-lib/libc/targets/z80/gg/pad.s @@ -0,0 +1,43 @@ + .include "global.s" + + .title "JOYPad utilities" + .module JOYPad + .area _HOME + + ;; Get Keypad Button Status +_joypad:: +.jpad:: + in a, (.JOY_PORT1) + cpl + and #0b00111111 + ld l, a + in a, (.GG_P0) + cpl + and #0b10000000 + or l + ld l, a + ret + + ;; Wait until all buttons have been released +.padup:: +_waitpadup:: +1$: + ld h,#0x7f ; wait for .jpad return zero 127 times in a row +2$: + call .jpad + or a ; have all buttons been released? + jr nz,1$ ; not yet + + dec h + jr nz,2$ + + ret + + ;; Wait for the key to be pressed +_waitpad:: +.wait_pad:: +1$: + call .jpad ; read pad + and l ; compare with mask? + jr z,1$ ; loop if no intersection + ret diff --git a/gbdk-lib/libc/targets/z80/gg/pad_ex.s b/gbdk-lib/libc/targets/z80/gg/pad_ex.s @@ -0,0 +1,76 @@ + .include "global.s" + + .title "JOYPad utilities" + .module JOYPad + .area _HOME + +; uint8_t joypad_init(uint8_t npads, joypads_t * joypads) __z88dk_callee; +_joypad_init:: + ld hl, #2 + add hl, sp + ld a, (hl) + or a + jr nz, 1$ + ld a, #1 + jr 2$ +1$: + cp #(.JOYPAD_COUNT + 1) + jr c, 2$ + ld a, #.JOYPAD_COUNT +2$: + inc hl + ld e, (hl) + inc hl + ld d, (hl) + + inc hl + pop bc ; pop return address + ld sp, hl ; dispose params + push bc ; push return address back + + ld (de), a ; number of joypads + ld l, a ; return number of joypads in l + xor a + inc de + ld (de), a + inc de + ld (de), a + inc de + ld (de), a + inc de + ld (de), a + + ret + +;void joypad_ex(joypads_t * joypads) __z88dk_fastcall; + +_joypad_ex:: + in a, (.GG_P0) + cpl + and #0b10000000 + ld b, a + ld c, #.JOY_PORT1 + in e, (c) + inc c + in d, (c) + ld a, e + rla + rl d + rla + rl d + ld a, e + cpl + and #0b00111111 + or b + ld e, a + ld a, d + cpl + and #0b01111111 + ld d, a + + inc hl + ld (hl), e + inc hl + ld (hl), d + + ret + diff --git a/gbdk-lib/libc/targets/z80/pad.s b/gbdk-lib/libc/targets/z80/pad.s @@ -1,38 +0,0 @@ - .include "global.s" - - .title "JOYPad utilities" - .module JOYPad - .area _HOME - - ;; Get Keypad Button Status -_joypad:: -.jpad:: - in a, (#.JOY_PORT1) - cpl - and #0b00111111 - ld l, a - ret - - ;; Wait until all buttons have been released -.padup:: -_waitpadup:: -1$: - ld h,#0x7f ; wait for .jpad return zero 127 times in a row -2$: - call .jpad - or a ; have all buttons been released? - jr nz,1$ ; not yet - - dec h - jr nz,2$ - - ret - - ;; Wait for the key to be pressed -_waitpad:: -.wait_pad:: -1$: - call .jpad ; read pad - and l ; compare with mask? - jr z,1$ ; loop if no intersection - ret diff --git a/gbdk-lib/libc/targets/z80/sms/global.s b/gbdk-lib/libc/targets/z80/sms/global.s @@ -111,8 +111,8 @@ .RIGHT = 0b00001000 .A = 0b00010000 .B = 0b00100000 - .SELECT = 0b01000000 ; map to RESET - .START = 0b01000000 ; map to RESET + .SELECT = 0b00100000 ; map to B + .START = 0b00010000 ; map to A .JOYPAD_COUNT = 2 diff --git a/gbdk-lib/libc/targets/z80/sms/pad.s b/gbdk-lib/libc/targets/z80/sms/pad.s @@ -0,0 +1,38 @@ + .include "global.s" + + .title "JOYPad utilities" + .module JOYPad + .area _HOME + + ;; Get Keypad Button Status +_joypad:: +.jpad:: + in a, (.JOY_PORT1) + cpl + and #0b00111111 + ld l, a + ret + + ;; Wait until all buttons have been released +.padup:: +_waitpadup:: +1$: + ld h,#0x7f ; wait for .jpad return zero 127 times in a row +2$: + call .jpad + or a ; have all buttons been released? + jr nz,1$ ; not yet + + dec h + jr nz,2$ + + ret + + ;; Wait for the key to be pressed +_waitpad:: +.wait_pad:: +1$: + call .jpad ; read pad + and l ; compare with mask? + jr z,1$ ; loop if no intersection + ret diff --git a/gbdk-lib/libc/targets/z80/pad_ex.s b/gbdk-lib/libc/targets/z80/sms/pad_ex.s

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.