git.y1.nz

gbdk-2020

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

commit f5dd2c740cd7b2c20f1ecbb93f0ab66ba30222b1
parent b947dd277e6d12b889112f1c8661941dc7ed314d
Author: Toxa <56631470+untoxa@users.noreply.github.com>
Date:   Fri, 29 Sep 2023 00:53:44 +0300

Merge pull request #580 from michel-iwaniec/nes_fix_fourscore_support

NES: Fix support for 4-player controllers using fourscore
Diffstat:
Mgbdk-lib/include/nes/nes.h16++++++++--------
Mgbdk-lib/libc/targets/mos6502/nes/global.s16++++++++--------
Mgbdk-lib/libc/targets/mos6502/nes/pad.s37++++++++++++++++++++++++++++++-------
Mgbdk-lib/libc/targets/mos6502/pad_ex.s44+++++++++++++++++++++++++++++++-------------
4 files changed, 77 insertions(+), 36 deletions(-)

diff --git a/gbdk-lib/include/nes/nes.h b/gbdk-lib/include/nes/nes.h @@ -75,14 +75,14 @@ void set_sprite_palette_entry(uint8_t palette, uint8_t entry, palette_color_t rg @see joypad */ -#define J_UP 0x10U -#define J_DOWN 0x20U -#define J_LEFT 0x40U -#define J_RIGHT 0x80U -#define J_A 0x01U -#define J_B 0x02U -#define J_SELECT 0x04U -#define J_START 0x08U +#define J_UP 0x08U +#define J_DOWN 0x04U +#define J_LEFT 0x02U +#define J_RIGHT 0x01U +#define J_A 0x80U +#define J_B 0x40U +#define J_SELECT 0x20U +#define J_START 0x10U /** Screen modes. Normally used by internal functions only. diff --git a/gbdk-lib/libc/targets/mos6502/nes/global.s b/gbdk-lib/libc/targets/mos6502/nes/global.s @@ -4,14 +4,14 @@ VRAM_DELAY_CYCLES_X8 = 167 ;; Keypad - .UP = 0x10 - .DOWN = 0x20 - .LEFT = 0x40 - .RIGHT = 0x80 - .A = 0x01 - .B = 0x02 - .SELECT = 0x04 - .START = 0x08 + .UP = 0x08 + .DOWN = 0x04 + .LEFT = 0x02 + .RIGHT = 0x01 + .A = 0x80 + .B = 0x40 + .SELECT = 0x20 + .START = 0x10 ;; Screen dimensions (in tiles) .DEVICE_SCREEN_WIDTH = 32 diff --git a/gbdk-lib/libc/targets/mos6502/nes/pad.s b/gbdk-lib/libc/targets/mos6502/nes/pad.s @@ -2,20 +2,43 @@ .area _HOME -_read_joypad:: - ; Strobe to latch joypad data +_strobe_joypads:: lda #1 sta JOY1 lda #0 sta JOY1 + rts + +_read_joypad:: + ; Strobe to latch joypad data + jsr _strobe_joypads +_read_joypad_no_strobe:: ; - ldy #8 -_read_joypad_loop: lda JOY1,x lsr - ror *.tmp+1 - dey - bne _read_joypad_loop + rol *.tmp+1 + lda JOY1,x + lsr + rol *.tmp+1 + lda JOY1,x + lsr + rol *.tmp+1 + lda JOY1,x + lsr + rol *.tmp+1 + lda JOY1,x + lsr + rol *.tmp+1 + lda JOY1,x + lsr + rol *.tmp+1 + lda JOY1,x + lsr + rol *.tmp+1 + lda JOY1,x + lsr + rol *.tmp+1 + ; lda *.tmp+1 rts diff --git a/gbdk-lib/libc/targets/mos6502/pad_ex.s b/gbdk-lib/libc/targets/mos6502/pad_ex.s @@ -1,6 +1,6 @@ .include "global.s" - MAX_JOYPADS = 2 + MAX_JOYPADS = 4 .globl _read_joypad .area OSEG (PAG, OVR) @@ -30,16 +30,34 @@ _joypad_init_loop: _joypad_ex:: .joypad_ex:: - sta *_joypad_init_PARM_2 - stx *_joypad_init_PARM_2+1 - ; Joypad #0 - ldx #0 - jsr _read_joypad - ldy #1 - sta [*_joypad_init_PARM_2],y - ; Joypad #1 - ldx #1 - jsr _read_joypad - ldy #2 - sta [*_joypad_init_PARM_2],y + .define .joypads_ptr "___SDCC_m6502_ret0" + .define .joypads_endof ".tmp" + sta *.joypads_ptr + stx *.joypads_ptr+1 + ; endof = Number of joypads + 1 + ldy #0 + lda [*.joypads_ptr],y + iny + sta *.joypads_endof + inc *.joypads_endof + ; + jsr _strobe_joypads +.joypad_ex_loop: + lda .joypad_ex_lut,y + tax + jsr _read_joypad_no_strobe + sta [*.joypads_ptr],y + iny + cpy *.joypads_endof + bne .joypad_ex_loop rts + +; +; Look-up table for getting joypad port offset from offset into joypads_t (=joypad index + 1) +; +.joypad_ex_lut: +.db 0 +.db 0 +.db 1 +.db 0 +.db 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.