Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/home/joypad.asm
1270 views
1
ReadJoypad::
2
; Poll joypad input.
3
; Unlike the hardware register, button
4
; presses are indicated by a set bit.
5
6
ld a, 1 << 5 ; select direction keys
7
ld c, 0
8
9
ldh [rJOYP], a
10
REPT 6
11
ldh a, [rJOYP]
12
ENDR
13
cpl
14
and %1111
15
swap a
16
ld b, a
17
18
ld a, 1 << 4 ; select button keys
19
ldh [rJOYP], a
20
REPT 10
21
ldh a, [rJOYP]
22
ENDR
23
cpl
24
and %1111
25
or b
26
27
ldh [hJoyInput], a
28
29
ld a, 1 << 4 + 1 << 5 ; deselect keys
30
ldh [rJOYP], a
31
ret
32
33
Joypad::
34
; Update the joypad state variables:
35
; [hJoyReleased] keys released since last time
36
; [hJoyPressed] keys pressed since last time
37
; [hJoyHeld] currently pressed keys
38
homecall _Joypad
39
ret
40
41