-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
intest.z80
283 lines (230 loc) · 5.78 KB
/
intest.z80
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
;; intest.z80 - Input-test for the various console functions
; Entry point, after the PSP.
ORG 0x0100
; show our introduction
LD DE, INTRO_MSG
LD C,0x09
CALL 0x0005
;; function 1 (C_READ)
call C_READ_test
;; function 3 (A_READ) - mbasic.com
call A_READ_test
;; function 6 (C_RAWIO)
call C_RAWIO_test
;; function 9 (C_READSTRING)
call C_READSTRING_test
;; Exit
LD C,0x00
CALL 0x0005
;; Prompt for characters, echoing and returning them
C_READ_test:
LD DE, C_READ_PROMPT
LD C,0x09
CALL 0x0005
; we allow five input characters
LD B, 5
; We save the characters into the input area
LD HL,READ_STRING
C_READ_test_loop
PUSH HL
PUSH BC
LD C, 0x01
CALL 0x0005
POP BC
POP HL
LD (HL), A
INC HL
DJNZ C_READ_test_loop
LD DE, NEWLINE
LD C, 0x09
CALL 0x0005
LD DE, C_READ_OVER_1
LD C, 0x09
CALL 0x0005
; Show the characters
LD HL, READ_STRING
LD A, (HL)
LD B,5
SHOW_LOOP_C_READ:
PUSH HL
PUSH BC
LD A,(HL)
LD E, A
LD C, 0x02
CALL 0x0005
POP BC
POP HL
INC HL
DJNZ SHOW_LOOP_C_READ
LD DE, C_READ_OVER_2
LD C, 0x09
CALL 0x0005
RET
;; Prompt for characters returning them - NOTE: No echo is expected
A_READ_test:
LD DE, A_READ_PROMPT
LD C,0x09
CALL 0x0005
; we allow five input characters
LD B, 5
; We save the characters into the input area
LD HL,READ_STRING
A_READ_test_loop
PUSH HL
PUSH BC
LD C, 0x03
CALL 0x0005
POP BC
POP HL
LD (HL), A
INC HL
DJNZ A_READ_test_loop
LD DE, A_READ_OVER_1
LD C, 0x09
CALL 0x0005
; Show the characters
LD HL, READ_STRING
LD A, (HL)
LD B,5
SHOW_LOOP_A_READ:
PUSH HL
PUSH BC
LD A,(HL)
LD E, A
LD C, 0x02
CALL 0x0005
POP BC
POP HL
INC HL
DJNZ SHOW_LOOP_A_READ
LD DE, A_READ_OVER_2
LD C, 0x09
CALL 0x0005
RET
;; This works in a non-blocking way.
C_RAWIO_test:
LD DE, C_RAWIO_PROMPT
LD C, 0x09
CALL 0x0005
C_RAWIO_Test_loop:
LD DE, C_RAWIO_SPINNER_1
LD C, 0x09
CALL 0x0005
; see if a character is pending
LD C, 0x06
LD E, 0xff
CALL 0x0005
push af
LD DE, C_RAWIO_SPINNER_2
LD C, 0x09
CALL 0x0005
pop af
; was there nothing pending? then try again
CP 0x00
jr z, C_RAWIO_Test_loop
push af
LD DE, C_RAWIO_SPINNER_3
LD C, 0x09
CALL 0x0005
pop af
; got a character, was it q?
cp 'q'
jr nz, C_RAWIO_Test_loop
LD DE, NEWLINE
LD C, 0x09
CALL 0x0005
ret
;; Prompt the user to enter text, and echo it back.
C_READSTRING_test:
LD DE, C_READSTRING_PROMPT
LD C,0x09
CALL 0x0005
; Point to the buffer
LD HL, READ_STRING
; first byte is how many characters to allow (20 here)
LD A, 20
LD (HL), A
; DE points to the buffer
PUSH HL
POP DE
; call C_READSTRING
LD C, 10
CALL 0x005
;; Show the result
LD DE, NEWLINE
LD C, 0x09
CALL 0x0005
LD DE, C_READSTRING_OVER_1
LD C,0x09
CALL 0x0005
;; Now get the length, and show the output
LD HL, READ_STRING + 1
LD A, (HL)
LD B,A
SHOW_LOOP
INC HL
PUSH HL
PUSH BC
LD A,(HL)
LD E, A
LD C, 0x02
CALL 0x0005
POP BC
POP HL
DJNZ SHOW_LOOP
;; And finish
LD DE, C_READSTRING_OVER_2
LD C,0x09
CALL 0x0005
RET
;;
;; Text area
;;
INTRO_MSG:
DB "Simple input-test program, by Steve.", 0x0a, 0x0d, 0x0a, 0x0d,"$"
;; C_READ
C_READ_PROMPT:
DB 0x0a, 0x0d, "C_READ Test:", 0x0a, 0x0d
DB " This test allows you to enter FIVE characters, one by one.", 0x0a, 0x0d
DB " The characters SHOULD be echoed as you type them.", 0x0a, 0x0d, "$"
C_READ_OVER_1:
DB " Test complete - you entered '$"
C_READ_OVER_2:
DB "'." ; fall-through
NEWLINE:
DB 0x0a, 0x0d, "$"
;; A_READ
A_READ_PROMPT:
DB 0x0a, 0x0d, "A_READ Test:", 0x0a, 0x0d
DB " This test allows you to enter FIVE characters, one by one.", 0x0a, 0x0d
DB " The characters should NOT be echoed as you type them.", 0x0a, 0x0d, "$"
A_READ_OVER_1:
DB " Test complete - you entered '$"
A_READ_OVER_2:
DB "'.", 0x0a, 0x0d, "$"
;; C_RAWIO
C_RAWIO_PROMPT:
DB 0x0a, 0x0d, "C_RAWIO Test:", 0x0a, 0x0d
DB " This uses polling to read characters.", 0x0a, 0x0d
DB " Echo should NOT be enabled.", 0x0a, 0x0d
DB " Press 'q' to proceed/complete this test.", 0x0a, 0x0d, "$"
C_RAWIO_BUFFER:
DB 0x00, "$"
C_RAWIO_SPINNER_1:
DB "x", 0x08, "$"
C_RAWIO_SPINNER_2:
DB "X", 0x08, "$"
C_RAWIO_SPINNER_3:
DB "+", 0x08, "$"
;; C_READSTRING
C_READSTRING_PROMPT:
DB 0x0a, 0x0d, "C_READSTRING Test:", 0x0a, 0x0d
DB " Enter a string, terminated by newline..", 0x0a, 0x0d, "$"
C_READSTRING_OVER_1:
DB " Test complete - you entered '$"
C_READSTRING_OVER_2:
DB "'.", 0x0a, 0x0d, "$"
;;
;; DATA area
;;
READ_STRING: