pokered/engine/joypad.asm

62 lines
868 B
NASM
Raw Normal View History

2014-05-31 08:31:08 +00:00
_Joypad::
2015-01-23 17:48:14 +00:00
; hJoyReleased: (hJoyLast ^ hJoyInput) & hJoyLast
; hJoyPressed: (hJoyLast ^ hJoyInput) & hJoyInput
ldh a, [hJoyInput]
2014-05-31 08:31:08 +00:00
cp A_BUTTON + B_BUTTON + SELECT + START ; soft reset
jp z, TrySoftReset
2015-01-23 17:48:14 +00:00
2014-05-31 08:31:08 +00:00
ld b, a
ldh a, [hJoyLast]
2014-05-31 08:31:08 +00:00
ld e, a
xor b
ld d, a
and e
ldh [hJoyReleased], a
2014-05-31 08:31:08 +00:00
ld a, d
and b
ldh [hJoyPressed], a
2014-05-31 08:31:08 +00:00
ld a, b
ldh [hJoyLast], a
2015-01-23 17:48:14 +00:00
ld a, [wStatusFlags5]
bit BIT_DISABLE_JOYPAD, a
2014-05-31 08:31:08 +00:00
jr nz, DiscardButtonPresses
2015-01-23 17:48:14 +00:00
ldh a, [hJoyLast]
ldh [hJoyHeld], a
2015-01-23 17:48:14 +00:00
2014-05-31 08:31:08 +00:00
ld a, [wJoyIgnore]
and a
ret z
2015-01-23 17:48:14 +00:00
2014-05-31 08:31:08 +00:00
cpl
ld b, a
ldh a, [hJoyHeld]
2014-05-31 08:31:08 +00:00
and b
ldh [hJoyHeld], a
ldh a, [hJoyPressed]
2014-05-31 08:31:08 +00:00
and b
ldh [hJoyPressed], a
2014-05-31 08:31:08 +00:00
ret
DiscardButtonPresses:
xor a
ldh [hJoyHeld], a
ldh [hJoyPressed], a
ldh [hJoyReleased], a
2014-05-31 08:31:08 +00:00
ret
TrySoftReset:
call DelayFrame
2015-01-23 17:48:14 +00:00
; deselect (redundant)
2014-05-31 08:31:08 +00:00
ld a, $30
ldh [rJOYP], a
2015-01-23 17:48:14 +00:00
2014-05-31 08:31:08 +00:00
ld hl, hSoftReset
dec [hl]
jp z, SoftReset
2015-01-23 17:48:14 +00:00
2014-05-31 08:31:08 +00:00
jp Joypad