forked from hperaza/RSX280
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvbuf.mac
460 lines (407 loc) · 6.95 KB
/
vbuf.mac
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
;***********************************************************************
;
; This file is part of RMD, a Resource Monitoring Display utility
; for the RSX280 OS. Copyright (C) 1985-2022, Hector Peraza.
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License as
; published by the Free Software Foundation; either version 2 of
; the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
;***********************************************************************
; Video framebuffer functions.
.Z280
include RMD.INC
public VCLS,VCLEOS,VCLEOL,VXY,VGETXY,VPUTC,VPUTS,VPUTN
public VOUTP,VGETC,VAHEX,VHLHEX,VHLDEC,VADEC,VADEC2,VRPAD
public VSNAP
extrn PUTCH,HOME,PUTCUR,DIV8,TTFLSH
cseg
maxgap equ 8
;-----------------------------------------------------------------------
; Clear video buffer
VCLS: push hl
push bc
ld hl,vbuf
ld (vptr),hl
ld bc,hsize*vsize
cls1: ld (hl),' '
inc hl
dec bc
ld a,b
or c
jr nz,cls1
pop bc
pop hl
ret
; Clear from current position to end of buffer
VCLEOS: push hl
push de
ld hl,vbuf+hsize*vsize
ld de,(vptr)
or a
sbc hl,de
ex de,hl
ceos: ld a,(hl)
cp ' '
jr z,ceos1
ld (hl),' '+80h
ceos1: inc hl
dec de
ld a,d
or e
jr nz,ceos
pop de
pop hl
ret
; Clear from current position to end of line
VCLEOL: push hl
push bc
call VGETXY
ld a,hsize
sub h
ld b,a
ld hl,(vptr)
ceol: ld a,(hl)
cp ' '
jr z,ceol1
ld (hl),' '+80h
ceol1: inc hl
djnz ceol
pop bc
pop hl
ret
; Set "cursor" for subsequent output.
; H = x coord, L = y coord
VXY: ld a,l
cp vsize
ret nc
ld a,h
cp hsize
ret nc
push hl
push de
push bc
ld e,h
ld d,0
ld h,0
add hl,hl
add hl,hl
add hl,hl
add hl,hl ; *16
ld c,l
ld b,h
add hl,hl
add hl,hl ; *64
add hl,bc ; y*80
add hl,de ; +x
ld de,vbuf
add hl,de
ld (vptr),hl
pop bc
pop de
pop hl
ret
; Get current "cursor" coordinates
VGETXY: push bc
push de
ld hl,(vptr)
ld de,vbuf
or a
sbc hl,de
ld c,hsize
call DIV8
ld h,a ; y in L, x in H
pop de
pop bc
ret
; Store a single char in video buffer
VPUTC: push hl
ld hl,(vptr)
ld a,c
cp (hl)
jr z,vc1
or 80h
ld (hl),a
vc1: inc hl
ld (vptr),hl
pop hl
ret
; Store string in video buffer
VPUTS: push de
ex de,hl
ld hl,(vptr)
vp1: ld a,(de)
or a
jr z,vp3
cp (hl)
jr z,vp2
or 80h
ld (hl),a
vp2: inc hl
inc de
jr vp1
vp3: ld (vptr),hl
ex de,hl
pop de
ret
; Store string of specified length in video buffer
VPUTN: ld a,b
or a
ret z
push de
ex de,hl
ld hl,(vptr)
vn1: ld a,(de)
cp (hl)
jr z,vn2
or 80h
ld (hl),a
vn2: inc hl
inc de
djnz vn1
ld (vptr),hl
ex de,hl
pop de
ret
; Get character at current "cursor" position
VGETC: push hl
ld hl,(vptr)
ld a,(hl)
and 7Fh
pop hl
ret
; Refresh screen with video buffer contents, output only what has changed
; from the previous call.
VOUTP: call HOME
ld hl,vbuf
ld de,0 ; gap length counter
ld c,0 ; row position
nextl: call line
inc c
ld a,c
cp vsize
jr nz,nextl
call HOME
call TTFLSH
ret
line: ld b,0 ; column position
ld d,1 ; force direct cursor for new lines
nextc: push bc ; push screen coordinates
ld a,(hl)
or a ; hi-bit set?
jp p,cc3 ; skip if not
and 7Fh ; clear hi-bit
ld (hl),a
ld a,d ; and check gap
or a ; if too long
jr nz,cc1 ; use direct cursor positioning
ld a,e
or a
jr z,cc2
cp maxgap
jr nc,cc1
or a
sbc hl,de ; else display all chars in gap
; inc e ; including current char
cc0: ld c,(hl)
call PUTCH
inc hl
dec e
jr nz,cc0
; jr cc4
jr cc2
cc1: ex (sp),hl ; push buffer pointer, pop screen coordinates
call PUTCUR
ex (sp),hl ; push screen coordinates, restore buffer ptr
cc2: ld c,(hl)
call PUTCH
ld de,0 ; reset gap counter
jr cc4
cc3: inc de ; increase gap counter
cc4: inc hl
pop bc
inc b
ld a,b
cp hsize
jr nz,nextc
ret
; Output snapshot of the the video buffer contents to the terminal.
VSNAP: ld c,CR
call PUTCH
ld hl,vbuf
ld b,vsize ; column counter
snextl: push bc
ld c,LF
call PUTCH
ld b,hsize ; row counter
ld de,0 ; gap length counter
snextc: ld a,(hl)
and 7Fh ; clear hi-bit
cp ' ' ; space?
jr z,scc2 ; skip if yes
or a
sbc hl,de ; else display all chars in gap
inc e ; including current char
scc1: ld a,(hl)
and 7Fh
ld c,a
call PUTCH
inc hl
dec e
jr nz,scc1
dec e ; reset gap counter (becomes 0 below)
dec hl
scc2: inc e ; increase gap counter
inc hl
djnz snextc
ld c,CR
call PUTCH
pop bc
djnz snextl
call TTFLSH
ret
;-----------------------------------------------------------------------
; Output HL (VHLHEX) or A (VAHEX) as hexadecimal.
VHLHEX: ld a,h
call VAHEX
ld a,l
VAHEX: push af
rrca
rrca
rrca
rrca
call vnhex
pop af
vnhex: and 0Fh
add a,90h
daa
adc a,40h
daa
push hl
push bc
ld c,a
call VPUTC
pop bc
pop hl
ret
; Output HL as decimal, A = filler.
VHLDEC: ld (filler),a
push hl
push de
push bc
ld b,0
ld de,-10000
call sbcnt
ld de,-1000
call sbcnt
ld de,-100
call sbcnt
ld de,-10
call sbcnt
ld a,l
add a,'0'
ld c,a
call VPUTC
inc b
ld a,b
pop bc
pop de
pop hl
ret
sbcnt: ld c,'0'-1
sb1: inc c
add hl,de
jr c,sb1
sbc hl,de
ld a,b
or a
jr nz,sb2
ld a,c
cp '0'
jr nz,sb2
ld a,(filler)
or a
ret z
ld c,a
jr sb3
sb2: inc b
sb3: call VPUTC
ret
; Output A as decimal
VADEC: push de
push bc
ld d,0
ld b,100
call ad1
ld b,10
call ad1
add a,'0'
ld c,a
call VPUTC
pop bc
pop de
ret
ad1: ld c,'0'-1
ad2: inc c
sub b
jr nc,ad2
add a,b
push af
ld a,c
cp '0'
jr nz,ad4
inc d
dec d
jr z,ad5
ad4: call VPUTC
ld d,1
ad5: pop af
ret
VADEC2: push bc
ld c,'0'
a2: cp 10
jr c,a1
inc c
sub 10
jr a2
a1: push af
call VPUTC
pop af
add a,'0'
ld c,a
call VPUTC
pop bc
ret
; Pad field with spaces. Called with D = starting column, E = field width
VRPAD: push hl
call VGETXY
ld a,d ; get starting column
add a,e ; add field width
dec a
sub h ; subtract current column
pop hl
ret c ; return if current width >= field width
push bc
ld b,a
inc b
rtrm1: ld c,' '
call VPUTC
djnz rtrm1
pop bc
ret
;-----------------------------------------------------------------------
dseg
filler: ds 1
vptr: ds 2
vbuf: ds hsize*vsize
end