summaryrefslogtreecommitdiff
path: root/engine/joypad.asm
diff options
context:
space:
mode:
Diffstat (limited to 'engine/joypad.asm')
-rw-r--r--engine/joypad.asm36
1 files changed, 35 insertions, 1 deletions
diff --git a/engine/joypad.asm b/engine/joypad.asm
index 87f92635..d50eea08 100644
--- a/engine/joypad.asm
+++ b/engine/joypad.asm
@@ -1,12 +1,46 @@
+ReadJoypad_::
+; Poll joypad input.
+; Unlike the hardware register, button
+; presses are indicated by a set bit.
+ ldh a, [hDisableJoypadPolling]
+ and a
+ ret nz
+
+ ld a, 1 << 5 ; select direction keys
+
+ ldh [rJOYP], a
+ ldh a, [rJOYP]
+ ldh a, [rJOYP]
+ cpl
+ and %1111
+ swap a
+ ld b, a
+
+ ld a, 1 << 4 ; select button keys
+ ldh [rJOYP], a
+REPT 6
+ ldh a, [rJOYP]
+ENDR
+ cpl
+ and %1111
+ or b
+
+ ldh [hJoyInput], a
+
+ ld a, 1 << 4 + 1 << 5 ; deselect keys
+ ldh [rJOYP], a
+ ret
+
_Joypad::
; hJoyReleased: (hJoyLast ^ hJoyInput) & hJoyLast
; hJoyPressed: (hJoyLast ^ hJoyInput) & hJoyInput
ldh a, [hJoyInput]
+ ld b, a
+ and A_BUTTON + B_BUTTON + SELECT + START + D_UP
cp A_BUTTON + B_BUTTON + SELECT + START ; soft reset
jp z, TrySoftReset
- ld b, a
ldh a, [hJoyLast]
ld e, a
xor b