1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
; read joypad data to refresh hKeysHeld, hKeysPressed, and hKeysReleased
; the A + B + Start + Select combination resets the game
ReadJoypad:
ld a, JOY_BTNS_SELECT
ldh [rJOYP], a
ldh a, [rJOYP]
ldh a, [rJOYP]
cpl
and JOY_INPUT_MASK
swap a
ld b, a ; buttons data
ld a, JOY_DPAD_SELECT
ldh [rJOYP], a
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
cpl
and JOY_INPUT_MASK
or b
ld c, a ; dpad data
cpl
ld b, a ; buttons data
ldh a, [hKeysHeld]
xor c
and b
ldh [hKeysReleased], a
ldh a, [hKeysHeld]
xor c
and c
ld b, a
ldh [hKeysPressed], a
ldh a, [hKeysHeld]
and BUTTONS
cp BUTTONS
jr nz, SaveButtonsHeld
; A + B + Start + Select: reset game
call ResetSerial
; fallthrough
Reset:
ld a, [wInitialA]
di
jp Start
SaveButtonsHeld:
ld a, c
ldh [hKeysHeld], a
ld a, JOY_BTNS_SELECT | JOY_DPAD_SELECT
ldh [rJOYP], a
ret
; clear joypad hmem data
ClearJoypad:
push hl
ld hl, hDPadRepeat
xor a
ld [hli], a ; hDPadRepeat
ld [hli], a ; hKeysReleased
ld [hli], a ; hDPadHeld
ld [hli], a ; hKeysHeld
ld [hli], a ; hKeysPressed
pop hl
ret
|