From 7a97cd577bdcf7d56f45fc6b4a7e680f1d47033b Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 1 Oct 2024 17:23:52 +0200 Subject: [PATCH] input: added basci controller input subsystem --- src/input.s | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/main.s | 1 + src/video.s | 7 +++++++ src/wram.s | 5 +++++ 4 files changed, 61 insertions(+) create mode 100644 src/input.s diff --git a/src/input.s b/src/input.s new file mode 100644 index 0000000..b14edfd --- /dev/null +++ b/src/input.s @@ -0,0 +1,48 @@ + ; poll inputs + ; returns: + ; new inputs in [curr_inputs] + ; previous inputs in [prev_inputs] +poll_inputs: + ld a, [curr_inputs] + ld [prev_inputs], a + + ld a, P1FDPAD + call poll_p1 + swap a + ld b, a + + ld a, P1FBTN + call poll_p1 + or a, b + + + ld [curr_inputs], a + ld a, b + + ret + + + ; poll p1 + ; inputs: + ; a: P1 key matrix flag + ; returns + ; a: A0-3 -> inputs +poll_p1: + ld [RP1], a + ; wait for values to become stable + ldh a, [RP1] + ldh a, [RP1] + ldh a, [RP1] + ldh a, [RP1] + ldh a, [RP1] + ldh a, [RP1] ; last read counts + xor a, 0x0F + and a, 0x0F + + ld d, a + ; reset P1F + ld a, P1FNONE + ldh [RP1], a + ld a, d + + ret diff --git a/src/main.s b/src/main.s index 5661aed..9d751ff 100644 --- a/src/main.s +++ b/src/main.s @@ -30,6 +30,7 @@ main: #include "mem.s" #include "strings.s" #include "sys.s" +#include "input.s" ; fill bank .fill 0, 0x7FFF - $ diff --git a/src/video.s b/src/video.s index d7b97dd..b61bac0 100644 --- a/src/video.s +++ b/src/video.s @@ -2,19 +2,24 @@ vblank: call OAMDMAFN + call poll_inputs + ; test puts ld hl, STR_TITLE ld de, SCRN0 call puts + ret + ; wait for next vblank vblank_wait: ld a, [RLY] cp a, 144 jp c, vblank_wait ret + ; turns off the lcd lcd_off: ; *never* turn off LCD without waiting ; for vblank! @@ -25,12 +30,14 @@ lcd_off: ret + ; turns on the lcd lcd_on: ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON ld [RLCD], a ret + ; init video system video_init: call copy_tiles diff --git a/src/wram.s b/src/wram.s index 9bf26c9..c206cc6 100644 --- a/src/wram.s +++ b/src/wram.s @@ -8,6 +8,11 @@ shadow_oam: .adv OBJSMAX * oamsize #define ACTORS_MAX 16 + ; current frame's inputs +curr_inputs: .adv 1 + ; previous frame's inputs +prev_inputs: .adv 1 + ; actor type enum .se 1 .de ACTOR_TYPE_PLAYER, 1 -- 2.30.2