-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimon.mac
More file actions
290 lines (242 loc) · 4.45 KB
/
simon.mac
File metadata and controls
290 lines (242 loc) · 4.45 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
; NOTE:: this program places the note array at F000H so it
; may destroy part of the system in later versions!
public play$simon
extrn speak ; votrax speak entry point
extrn rst$rs232$driver
extrn rst$io$driver
extrn pmsg
extrn dec$out
extrn pio$a$8255
extrn pio$c$8255
extrn mem$bot
extrn print$string
extrn linbuf
extrn inp$dec
extrn asc$dec
extrn crlf
extrn cr
extrn lf
extrn eot
; =-=-=-=-=-=-=-=-=- Play Game Of Simon =-=-=-=-=-=-=-=-=-
; Plays game of simon usinfg external hardware attached to
; Universal parallel port.
play$simon:
call print$string
defb cr,lf,lf,'Welcome to Simon.',cr,lf
defb 'Please attach SIMON to parallel port, then press any key.',eot
call speak
defm 'WELCOME TO SYMON',eot
ld c,2
call rst$rs232$driver ; wait for a keypress from keyboard or rs-232
call print$string
defb cr,lf,'The LED''s will show the # of correct notes entered.',eot
try$agn:call crlf
ld hl,simsg2
call pmsg
call speak
simsg2: defm 'How many notes to try for? ',eot
ld hl,linbuf
call inp$dec ; input decimal string
ld hl,linbuf
call asc$dec
jr c,try$agn
or a ; CR just pressed?
jr z,try$agn
no$err: call crlf
ld b,e ; only keep lower byte
; get random notes
sstart: ld d,b ; create d random notes
ld c,0
ld hl,mem$bot ; put table at 0f000h
get$ran:defb 0edh,05fh ; 'ld a,r' - get random value from refresh register
srl a
and 3 ; need 0-3
cp c ; check to see if next note the same
jr z,get$ran ; get a new random number
ld c,a ; keep for next pass
ld e,1 ; now compute 2^a
cp 0
jr z,store
ld e,2
cp 1
jr z,store
ld e,4
cp 2
jr z,store
ld e,8
store: ld a,255
sub e ; 255-2^a
and 0fh
ld (hl),a ; store in table
inc hl
dec d ; dec. number of notes to make
jr nz,get$ran ; go make more
; start note output
ld c,0 ; start with 1 note correct
next$note:
inc c ; another note right
ld e,0
ld hl,mem$bot ; point to start of note table
send$nt:ld a,(hl)
inc hl
out (pio$a$8255),a ; start note
call tone$wait ; wait a bit
ld a,255
out (pio$a$8255),a ; turn off note
inc e
ld a,c
cp e
jr nz,send$nt ; send next note in sequence
ld e,0
ld hl,mem$bot
wait$1: ld a,c
push de
push bc
ld c,10h ; display # of correct on leds
ld d,0
dec a
ld e,a
call rst$io$driver
pop bc
pop de
wait$11:in a,(pio$c$8255) ; wait for button to be pressed
and 0fh
cp 0fh
jr z,wait$11
call wait$2msec ; wait for key debounce
call wait$2msec
in a,(pio$c$8255)
and 0fh
push af ; save pressed button
got2: in a,(pio$c$8255) ; wait till person releases the button
and 0fh
cp 0fh
jr nz,got2
pop af ; get back pressed button
cp (hl) ; same note?
jr nz,missed ; person pressed wrong key
got$it: inc e
inc hl
ld a,c
push bc
inc b
cp b
pop bc
jr nz,wait$2
call print$string
defb cr,lf,'You got all ',eot
ld h,0
ld l,b
push bc
call dec$out
pop bc
call print$string
defb ' tones correct.',cr,lf,eot
call speak
defm 'VARY GOOD, TRY AGAIN',eot
jp do$tune
wait$2: in a,(pio$c$8255)
and 0fh
cp 0fh
jr nz,wait$2
ld a,e
cp c
jp nz,wait$1
; retry delay
retry: call tone$wait
call tone$wait
jp next$note
; person pressed wrong key
missed: call print$string
defb cr,lf,lf,'You missed it! You had ',eot
ld h,0
ld l,c
push bc
call dec$out
pop bc
call print$string
defb ' notes in the sequence. Try again at the tone.',eot
call speak
defm 'SORRY, YOU MISSED THAT ONE',eot
.comment\
ld d,2
sloop3: ld e,2
sloop1: ld a,251
out (pio$a$8255),a
call tone$2$wait
ld a,254
out (pio$a$8255),a
call tone$2$wait
dec e
jr nz,sloop1
ld e,2
sloop2: ld a,247
out (pio$a$8255),a
call tone$2$wait
ld a,253
out (pio$a$8255),a
call tone$2$wait
dec e
jr nz,sloop2
dec d
jr nz,sloop3
ld a,255
out (pio$a$8255),a
call wait$2sec
\
jp sstart ; restart program
do$tune:
ld d,7
sloop4: ld a,254
out (pio$a$8255),a
call tone$2$wait
ld a,253
out (pio$a$8255),a
call tone$2$wait
ld a,251
out (pio$a$8255),a
call tone$2$wait
ld a,247
out (pio$a$8255),a
call tone$2$wait
ld a,255
out (pio$a$8255),a
dec d
jr nz,sloop4
call wait$2sec
jp sstart ; restart program
; wait 2 seconds
wait$2sec:
call tone$wait
call tone$wait
call tone$wait
call tone$wait
ret
; wait 527 ms
tone$wait:
push bc
ld b,251
wait$3: call wait$2msec
djnz wait$3
pop bc
ret
; wait 170 ms
tone$2$wait:
push bc
ld b,81
wait$4: call wait$2msec
djnz wait$4
pop bc
ret
wait$2msec: ; wait 2.1 msec
push af
push hl
ld hl,323
dec: dec hl ; 6 loop takes 6.5 usec
ld a,h ; 4
or l ; 4
jr nz,dec ; 12
pop hl
pop af
ret
end