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