gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/z80/msxdos/pad.s
1 .include "global.s"
2
3 .title "JOYPad utilities"
4 .module JOYPad
5 .area _HOME
6
7 ;; Get Keypad Button Status
8 _joypad::
9 .jpad::
10 ld a, #0x06 ; ... <code> <caps> <graph> <ctrl> <shift>
11 out (.KBD_SELECT_ROW), a
12 in a, (.KBD_INPUT)
13 cpl
14
15 rrca
16 rl l
17 rrca
18 rrca
19 rl l ; shift graph
20
21 ld a, #0x07 ; <ret>, ...
22 out (.KBD_SELECT_ROW), a
23 in a, (.KBD_INPUT)
24 cpl
25
26 rlca
27 rl l
28 rl l
29 ld a, #0b00001110
30 and l
31 ld l, a
32
33 ld a, #0x08 ; <r><d><u><l><del><ins><home><space>
34 out (.KBD_SELECT_ROW), a
35 in a, (.KBD_INPUT)
36 cpl
37 and #0b11110001
38
39 or l
40 ld l, a ; <r><d><u><l><shift><graph><enter><space>
41
42 ret
43
44 ;; Wait until all buttons have been released
45 .padup::
46 _waitpadup::
47 1$:
48 ld h,#0x7f ; wait for .jpad return zero 127 times in a row
49 2$:
50 call .jpad
51 or a ; have all buttons been released?
52 jr nz,1$ ; not yet
53
54 dec h
55 jr nz,2$
56
57 ret
58
59 ;; Wait for the key to be pressed
60 _waitpad::
61 .wait_pad::
62 ld h, l
63 1$:
64 call .jpad ; read pad
65 and h ; compare with mask?
66 jr z,1$ ; loop if no intersection
67 ret
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.