summaryrefslogtreecommitdiff
path: root/src/home/input.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/home/input.asm')
-rw-r--r--src/home/input.asm66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/home/input.asm b/src/home/input.asm
new file mode 100644
index 0000000..28e2e71
--- /dev/null
+++ b/src/home/input.asm
@@ -0,0 +1,66 @@
+; read joypad data to refresh hKeysHeld, hKeysPressed, and hKeysReleased
+; the A + B + Start + Select combination resets the game
+ReadJoypad:
+ ld a, JOY_BTNS_SELECT
+ ldh [rJOYP], a
+ ldh a, [rJOYP]
+ ldh a, [rJOYP]
+ cpl
+ and JOY_INPUT_MASK
+ swap a
+ ld b, a ; buttons data
+ ld a, JOY_DPAD_SELECT
+ ldh [rJOYP], a
+ ldh a, [rJOYP]
+ ldh a, [rJOYP]
+ ldh a, [rJOYP]
+ ldh a, [rJOYP]
+ ldh a, [rJOYP]
+ ldh a, [rJOYP]
+ cpl
+ and JOY_INPUT_MASK
+ or b
+ ld c, a ; dpad data
+ cpl
+ ld b, a ; buttons data
+ ldh a, [hKeysHeld]
+ xor c
+ and b
+ ldh [hKeysReleased], a
+ ldh a, [hKeysHeld]
+ xor c
+ and c
+ ld b, a
+ ldh [hKeysPressed], a
+ ldh a, [hKeysHeld]
+ and BUTTONS
+ cp BUTTONS
+ jr nz, SaveButtonsHeld
+ ; A + B + Start + Select: reset game
+ call ResetSerial
+; fallthrough
+
+Reset:
+ ld a, [wInitialA]
+ di
+ jp Start
+
+SaveButtonsHeld:
+ ld a, c
+ ldh [hKeysHeld], a
+ ld a, JOY_BTNS_SELECT | JOY_DPAD_SELECT
+ ldh [rJOYP], a
+ ret
+
+; clear joypad hmem data
+ClearJoypad:
+ push hl
+ ld hl, hDPadRepeat
+ xor a
+ ld [hli], a ; hDPadRepeat
+ ld [hli], a ; hKeysReleased
+ ld [hli], a ; hDPadHeld
+ ld [hli], a ; hKeysHeld
+ ld [hli], a ; hKeysPressed
+ pop hl
+ ret