aboutsummaryrefslogtreecommitdiffstats
path: root/engine/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 /engine/joypad.asm
parentPull a lot of engine out of main.asm (diff)
parentUpdate INSTALL.md (diff)
downloadpokeyellow-fb11ff7e55be56cef9234c8443614f04f2157a1e.tar.gz
pokeyellow-fb11ff7e55be56cef9234c8443614f04f2157a1e.tar.xz
pokeyellow-fb11ff7e55be56cef9234c8443614f04f2157a1e.zip
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 'engine/joypad.asm')
-rw-r--r--engine/joypad.asm51
1 files changed, 51 insertions, 0 deletions
diff --git a/engine/joypad.asm b/engine/joypad.asm
new file mode 100644
index 00000000..d2ad1c31
--- /dev/null
+++ b/engine/joypad.asm
@@ -0,0 +1,51 @@
+_Joypad::
+ ld a, [hJoyInput]
+ cp A_BUTTON + B_BUTTON + SELECT + START ; soft reset
+ jp z, TrySoftReset
+ ld b, a
+ ld a, [hJoyHeldLast]
+ ld e, a
+ xor b
+ ld d, a
+ and e
+ ld [hJoyReleased], a
+ ld a, d
+ and b
+ ld [hJoyPressed], a
+ ld a, b
+ ld [hJoyHeldLast], a
+ ld a, [wd730]
+ bit 5, a
+ jr nz, DiscardButtonPresses
+ ld a, [hJoyHeldLast]
+ ld [hJoyHeld], a
+ ld a, [wJoyIgnore]
+ and a
+ ret z
+ cpl
+ ld b, a
+ ld a, [hJoyHeld]
+ and b
+ ld [hJoyHeld], a
+ ld a, [hJoyPressed]
+ and b
+ ld [hJoyPressed], a
+ ret
+
+DiscardButtonPresses:
+ xor a
+ ld [hJoyHeld], a
+ ld [hJoyPressed], a
+ ld [hJoyReleased], a
+ ret
+
+TrySoftReset:
+ call DelayFrame
+ ; reset joypad (to make sure the
+ ; player is really trying to reset)
+ ld a, $30
+ ld [rJOYP], a
+ ld hl, hSoftReset
+ dec [hl]
+ jp z, SoftReset
+ jp Joypad