summaryrefslogtreecommitdiff
path: root/home/joypad.asm
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2014-07-12 09:02:49 -0400
committeryenatch <yenatch@gmail.com>2014-07-12 09:02:49 -0400
commitfb11ff7e55be56cef9234c8443614f04f2157a1e (patch)
treea6aa8d0745bd07d0b80090491b5e4b6652de4420 /home/joypad.asm
parent15427f532085846ab6b51719be687951a094cb6c (diff)
parent9f29f21d9d43baa7124991dcf3b093fc6c615706 (diff)
Merge pull request #48 from yenatch/master
Clean up post-split main.asm. Get rid of static wram addresses. Lay out a foundation for Yellow.
Diffstat (limited to 'home/joypad.asm')
-rw-r--r--home/joypad.asm39
1 files changed, 39 insertions, 0 deletions
diff --git a/home/joypad.asm b/home/joypad.asm
new file mode 100644
index 00000000..2002bb29
--- /dev/null
+++ b/home/joypad.asm
@@ -0,0 +1,39 @@
+ReadJoypad::
+; Poll joypad input.
+; Unlike the hardware register, button
+; presses are indicated by a set bit.
+
+ ld a, 1 << 5 ; select direction keys
+ ld c, 0
+
+ ld [rJOYP], a
+ rept 6
+ ld a, [rJOYP]
+ endr
+ cpl
+ and %1111
+ swap a
+ ld b, a
+
+ ld a, 1 << 4 ; select button keys
+ ld [rJOYP], a
+ rept 10
+ 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::
+; Update the joypad state variables:
+; [hJoyReleased] keys released since last time
+; [hJoyPressed] keys pressed since last time
+; [hJoyHeld] currently pressed keys
+ homecall _Joypad
+ ret