-
Notifications
You must be signed in to change notification settings - Fork 26
/
conio.pla
425 lines (419 loc) · 8.12 KB
/
conio.pla
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
include "inc/cmdsys.plh"
include "inc/conio.plh"
sysflags nojitc // Keep tone() from compiling and sounding different
//
// Handy constants.
//
const FULLMODE = 0
const MIXMODE = 1
//
// Apple II ZP locations.
//
const a2rndnum = $4E // ZP location of RND
const a2rndl = $4E
const a2rndh = $4F
//
// Apple II hardware constants.
//
const speaker = $C030
const showgraphics = $C050
const showtext = $C051
const showfull = $C052
const showmix = $C053
const showpage1 = $C054
const showpage2 = $C055
const showlores = $C056
const showhires = $C057
const keyboard = $C000
const keystrobe = $C010
const hgr1 = $2000
const hgr2 = $4000
const page1 = 0
const page2 = 1
//
// Apple III hardware constants.
//
const ENV_REG = $FFDF
//
// Predefined functions.
//
predef a2keypressed,a2home,a12echo(state),a2gotoxy(x,y),a2viewport(left, top, width, height),a2texttype(type)
predef a2textmode(cols),a2grmode(mix),a2grcolor(color),a2grplot(x,y),a2tone(duration, delay),a2rnd
//
// Exported function table.
//
word conio[]
//
// Function pointers.
//
word = @a2keypressed
word = @getc
word = @a12echo
word = @a2home
word = @a2gotoxy
word = @a2viewport
word = @a2texttype
word = @a2textmode
word = @a2grmode
word = @a2grcolor
word = @a2grplot
word = @a2tone
word = @a2rnd
//
// Screen row address arrays.
//
word txt1scrn[] = $0400,$0480,$0500,$0580,$0600,$0680,$0700,$0780
word = $0428,$04A8,$0528,$05A8,$0628,$06A8,$0728,$07A8
word = $0450,$04D0,$0550,$05D0,$0650,$06D0,$0750,$07D0
word txt2scrn[] = $0800,$0880,$0900,$0980,$0A00,$0A80,$0B00,$0B80
word = $0828,$08A8,$0928,$09A8,$0A28,$0AA8,$0B28,$0BA8
word = $0850,$08D0,$0950,$09D0,$0A50,$0AD0,$0B50,$0BD0
//
// Text screen parameters.
//
//byte textcols = 40
//byte curshpos = 0
//byte cursvpos = 0
//
// Apple 3 console codes.
//
byte textbwmode[] = 2, 16, 0
byte textclrmode[] = 2, 16, 1
byte grcharset[] = 1, 0, $7F, $7F, $7F, $7F, $00, $00, $00, $00
byte a3keyqueue = 0
//
// Random number for Apple 1 and III.
//
word randnum = 12345
//
// Native routines.
//
asm equates
!SOURCE "vmsrc/plvmzp.inc"
end
//
// def grscrn(rowaddrs)
//
asm a2grscrn(rowaddrs)
GRSCRN = $26
GRSCRNL = GRSCRN
GRSCRNH = GRSCRNL+1
LDA ESTKL,X
STA GRSCRNL
LDA ESTKH,X
STA GRSCRNH
RTS
end
//
// def grcolor(color)
//
asm a2grcolor(color)
GRCLR = $30
LDA #$0F
AND ESTKL,X
STA GRCLR
ASL
ASL
ASL
ASL
ORA GRCLR
STA GRCLR
RTS
end
//
// def grplot(x, y)
//
asm a2grplot(x, y)
STY IPY
LDA ESTKL,X
AND #$FE
CMP ESTKL,X
TAY
LDA (GRSCRN),Y
STA DSTL
INY
LDA (GRSCRN),Y
STA DSTH
LDY ESTKL+1,X
LDA (DST),Y
EOR GRCLR
STA TMPL
LDA #$FF
ADC #$00
EOR #$F0
AND TMPL
EOR GRCLR
STA (DST),Y
LDY IPY
INX
RTS
end
//
// Apple 1 routines.
//
def a1keypressed
return ^$D011 >= 128 ?? ^$D011 :: 0
end
def a1getkey
while not a1keypressed
randnum = randnum + 123
loop
return getc()
end
def a12echo(state)
return 0
end
def a1home
byte l
for l = 0 to 23
putln
next
return 0
end
def a1gotoxy(x, y)
//curshpos = x
//cursvpos = y
putln
while x
putc(' ')
x = x - 1
loop
return 0
end
def a1viewport(left, top, width, height)
return 0
end
def a1texttype(type)
return 0
end
def a1textmode(columns)
return 0
end
def a1grmode(mix)
return 0 // not supported
end
def a1tone(duration, delay)
byte i
while duration
for i = delay downto 0; next
duration--
loop
return 0
end
//
// Apple II routines.
//
def a2keypressed
return ^keyboard >= 128 ?? ^keyboard :: 0
end
def a2home
//curshpos = 0
//cursvpos = 0
return call($FC58, 0, 0, 0, 0) // home()
end
def a2gotoxy(x, y)
//curshpos = x
//cursvpos = y
^$24 = x + ^$20
return call($FB5B, y + ^$22, 0, 0, 0)
end
def a2viewport(left, top, width, height)
if !width or !height
left = 0
top = 0
width = 40
height = 24
fin
^$20 = left
^$21 = width
^$22 = top
^$23 = height + top
return a2gotoxy(0, 0)
end
def a2texttype(type)
^$32 = type
return 0
end
def a2textmode(columns)
call($FB39, 0, 0, 0, 0) // textmode()
return a2home
end
def a2grmode(mix)
call($FB2F, 0, 0, 0, 0) // initmode()
call($FB40, 0, 0, 0, 0) // grmode()
if !mix
^showfull
fin
a2home
return a2grscrn(@txt1scrn) // point to lo-res screen
end
def a2tone(duration, delay)
byte i
while duration
^speaker // toggle speaker
for i = delay downto 0; next
duration--
loop
return 0
end
def a2rnd
*a2rndnum = (*a2rndnum << 1) + *a2rndnum + 123
return *a2rndnum & $7FFF
end
//
// Apple III routines.
//
def dev_control(devnum, code, list)
byte params[5]
params.0 = 3
params.1 = devnum
params.2 = code
params:3 = list
return syscall($83, @params)
end
def dev_status(devnum, code, list)
byte params[5]
params.0 = 3
params.1 = devnum
params.2 = code
params:3 = list
return syscall($82, @params)
end
def a3keypressed
byte count
dev_status(cmdsys.devcons, 5, @count)
if count
a3keyqueue = getc
fin
return a3keyqueue ?? a3keyqueue | $80 :: 0
end
def a3getkey
byte keycode
repeat
randnum = randnum + 123
a3keypressed
keycode = a3keyqueue
until keycode
a3keyqueue = 0
return keycode
end
def a3echo(state)
return dev_control(cmdsys.devcons, 11, @state)
end
def a3home
//curshpos = 0
//cursvpos = 0
putc(28)
return 0
end
def a3gotoxy(x, y)
//curshpos = x
//cursvpos = y
putc(24)
putc(x)
putc(25)
putc(y)
return 0
end
def a3viewport(left, top, width, height)
if !width or !height
//
// Reset the full-screen viewport
//
left = 0
top = 0
width = 40//textcols
height = 24
fin
putc(1) // Reset viewport
putc(26)
putc(left)
putc(top)
putc(2)
putc(26)
putc(left + width - 1)
putc(top + height - 1)
putc(3)
return a3gotoxy(0, 0)
end
def a3texttype(type)
return 0
end
def a3textmode(columns)
puts(@textbwmode)
if columns > 40
a3viewport(0, 0, 80, 24)
else
a3viewport(0, 0, 40, 24)
fin
putc(28)
return 0
end
def a3grmode(mix)
byte i
if mix
mix = 19
else
mix = 23
fin
puts(@textclrmode)
dev_control(cmdsys.devcons, 17, @grcharset)
a3viewport(0, 20, 40, 4)
putc(28)
for i = 0 to mix
memset(txt1scrn[i], $0000, 40) // text screen
memset(txt2scrn[i], $0000, 40) // color screen
next
return a2grscrn(@txt2scrn) // point to color screen
end
def a3tone(duration, pitch)
byte env
env = ^ENV_REG
^ENV_REG = env | $C0
a2tone(duration, pitch)
^ENV_REG = env
return 0
end
//
// Apple 1 and III combined routines.
//
def a13rnd
randnum = (randnum << 1) + randnum + 123
return randnum & $7FFF
end
//
// Machine specific initialization.
//
when MACHID & MACHID_MODEL
is MACHID_III
conio:keypressed = @a3keypressed
conio:getkey = @a3getkey
conio:echo = @a3echo
conio:home = @a3home
conio:gotoxy = @a3gotoxy
conio:viewport = @a3viewport
conio:texttype = @a3texttype
conio:textmode = @a3textmode
conio:grmode = @a3grmode
conio:tone = @a3tone
conio:rnd = @a13rnd
break
is MACHID_I
conio:keypressed = @a1keypressed
conio:getkey = @a1getkey
conio:home = @a1home
conio:gotoxy = @a1gotoxy
conio:viewport = @a1viewport
conio:texttype = @a1texttype
conio:textmode = @a1textmode
conio:grmode = @a1grmode
conio:tone = @a1tone
conio:rnd = @a13rnd
break
otherwise // MACHID_II puts("Found MACHID_MODEL = $"); putb(MACHID & MACHID_MODEL); putln
wend
//
// Keep module in memory
//
return modkeep
done