-
Notifications
You must be signed in to change notification settings - Fork 2
/
game_keys.asm
154 lines (128 loc) · 2.34 KB
/
game_keys.asm
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
;Some more z88 gunk...
;Keyboard routines...hurrah!!!
;These work for games!
MODULE keyboard
SECTION code
INCLUDE "stdio.def"
XREF pkeys
XDEF keys
XDEF ktest1
XDEF kfind
XDEF retascii
;Return ascii value for a keystroke
;Entry: none
;Exit: a = key (0=none/multiple)
.retascii
call kfind
ld a,0
ret nz ;more than one key
inc d
ret z
ld e,d
dec e
ld d,0
ld hl,keytable
add hl,de
ld a,(hl)
ret
IF MAPKEY
;Transforms a raw key into a printable quantity
;Entry: d=raw key
;Output: dumps keys to stdout
.mapkey
ld e,d
ld d,0
ld hl,keytable
add hl,de
ld a,(hl)
and a
ret z
cp 127
jr c,mapkey1
ld d,a
ld a,1
call_oz(os_out)
ld a,d
.mapkey1
call_oz(os_out)
ld a,1
and a
ret
ENDIF
;Find a key...used in define keys...hopefully!
;Exit: d=key (255=no key)
; nz=more than one key..
.kfind
ld de,$FF47 ;$FF2F
ld bc,$FEB2
.nxhalf
in a,(c)
cpl
and a
jr z,npress
;Test for multiple keys..
inc d
ret nz
;Calc key value..
ld h,a
ld a,e
.kloop
sub 8
srl h
jr nc,kloop
ret nz ;a will have some value...
ld d,a
.npress
dec e
rlc b
jr c,nxhalf
;set zero flag
cp a
ret
;Read the keys!
.keys
ld hl,pkeys+7
ld e,1
.nxtkey
ld a,(hl)
dec hl
call ktest1
ccf
rl e
jp nc,nxtkey
ret
;Test a Z88 key
;Entry: a=key
;Exit: c=no key
; nc=key pressed
.ktest1
ld c,a
and 7
inc a
ld b,a
srl c
srl c
srl c
ld a,8
sub c
ld c,a
ld a,254
.hifind
rrca
djnz hifind
in a,($B2)
.nxkey
rra
dec c
jp nz,nxkey
ret
;Key table...
.keytable
;0-15
defm "",0,0,"[]-=\\",227,0,0,224,240,241,242,243,225
;16-31
defm "",0,0,"123456",0,0,"QWERTY"
;32-47
defm "",0,0,"ASDFGH.,ZXCVBN"
;48-64
defm "/;LMKJU7",163,34,"0P9OI8"