forked from hperaza/RSX280
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.mac
528 lines (422 loc) · 9.97 KB
/
main.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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
;***********************************************************************
;
; This file is part of RMD, a Resource Monitoring Display utility
; for the RSX280 OS. Copyright (C) 1985-2023, 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.
;
;***********************************************************************
; RSX-11M RMD look-alike program for RSX-280.
.Z280
ident 'V6.40'
include SYSFN.INC
include SYSTEM.INC
include QIO.INC
include DCB.INC
include AST.INC
include RMD.INC
include ERRORS.INC
public ACTPG,CLS,CLEOS,CLEOL,HOME,PUTCUR,SYSVN,HEADER,RATE
public FATAL,ERROR
extrn PUTCH,PUTSTR,PERROR,TTFLSH,ATTACH,DETACH,UCASE,ADEC
extrn GCCL,VCLS,VXY,VPUTC,VPUTS,VOUTP,VADEC,VADEC2,VHLDEC
extrn VSNAP,SKIPBL,SKIPW,CMDBUF,ERRCMD
extrn MEMPG,ATDPG,THDRPG,DEVPG,SYSUPT,SYSTIM,HELP,COMND,COMNDL
cseg
;-----------------------------------------------------------------------
START: jp MAIN
vt100 equ $
vclrscr:db 4,ESC,'[2J',0
vclreos:db 3,ESC,'[J',0,0
vclreol:db 3,ESC,'[K',0,0
vhome: db 3,ESC,'[H',0,0
vcurprf:db 2,ESC,'[',0,0,0
vcursep:db 1,';',0,0,0,0
vcurpst:db 1,'H',0,0,0,0
vcurbcd:db true
vcuryof:db 1
vcurxof:db 1
vxfirst:db false
tdlen equ $-vt100
vt52 equ $
db 4,ESC,'H',ESC,'J',0
db 2,ESC,'J',0,0,0
db 2,ESC,'K',0,0,0
db 2,ESC,'H',0,0,0
db 2,ESC,'Y',0,0,0
db 0,0,0,0,0,0
db 0,0,0,0,0,0
db false
db 32
db 32
db false
;-----------------------------------------------------------------------
; screen output routines
CLS: ld hl,vclrscr
jp putseq
CLEOS: ld hl,vclreos
jp putseq
CLEOL: ld hl,vclreol
jp putseq
HOME: ld hl,vhome
ld a,(hl)
or a
jp nz,putseq
ld hl,0
jp PUTCUR
; H = x coord, L = y coord
PUTCUR: push hl
push de
ex de,hl
ld hl,(vcuryof) ; H = vcurxof, L = vcuryof
add hl,de ; should not generate any CY from L to H
ex de,hl
ld a,(vxfirst)
or a
jr z,noswap
ld a,e
ld e,d
ld d,a
noswap: ld hl,vcurprf ; prefix
call putseq
ld c,e ; y coord
call pcurnum
ld hl,vcursep ; separator
call putseq
ld c,d ; x coord
call pcurnum
ld hl,vcurpst ; postfix
call putseq
;; call TTFLSH
pop de
pop hl
ret
pcurnum:ld a,(vcurbcd)
or a
jp z,PUTCH
ld a,c
jp ADEC ; note: no filler
putseq: ld a,(hl)
or a
ret z
push bc
ld b,a
inc hl
pseq1: ld c,(hl)
call PUTCH
inc hl
djnz pseq1
;; call TTFLSH
pop bc
ret
;-----------------------------------------------------------------------
; unsolicited char AST service routine
ttast: ex (sp),hl ; fetch argument
ld a,l
ld (astchr),a ; save received char
ld hl,astflg
set 1,(hl) ; signal a character has arrived
push de
ld e,2
SC .SETF ; set flag 2
pop de
pop hl
SC .ASTX
; mark-time AST service routine
tmast: ex (sp),hl ; drop argument
ld hl,astflg
set 0,(hl) ; signal time mark has arrived
push de
ld e,2
SC .SETF ; set flag 2
pop de
pop hl
SC .ASTX
;-----------------------------------------------------------------------
; Draw header
HEADER: or a ; check redisplay flag
jr nz,h1
VGTOXY 0,0
ld hl,sysnam
call VPUTS
ld c,' '
call VPUTC
call shvers ; show system version
call shsize ; show system memory size
h1: call shwhst ; show host name
call SYSTIM ; show current date and time
call SYSUPT ; show up time
ret
sysnam: db 'RSX-280',0
shvers: ld c,'V'
call VPUTC
ld hl,(SYSVN)
ld a,h
call VADEC ; note: no filler
ld c,'.'
call VPUTC
ld a,l
call VADEC2 ; note: two digits
ret
shsize: VGTOXY 15,0
ld hl,($MEMSZ) ; get memsize in kb [system.inc]
xor a ; no filler for number
call VHLDEC
ld c,'K'
jp VPUTC
shwhst: VGTOXY 21,0
ld hl,$HOSTN
ld b,9
snam: ld c,(hl)
call VPUTC
inc hl
djnz snam
ret
;-----------------------------------------------------------------------
; ***** The Main Routine *****
MAIN: ld sp,stack
xor a
ld (opts),a ; clear snapshot option
inc a
ld (RATE),a ; default replot rate is 1 second
call MEMPG ; default mode is memory display
ld (ACTPG),hl ; set display procedure
ld hl,SYSVN
ld c,I.VERS
SC .GIN ; get system version number
ld a,(SYSVN+2)
cp 2
jp nz,syserr
ld c,1
SC .SUPER ; put us in supervisor mode
jp c,FATAL
call GCCL ; get MCR command line
call PARSE ; parse command line and process options
ld a,(opts) ; snapshot requested?
or a
jp nz,snpsht ; if yes, output snapshot and exit
xor a
set 0,a ; for the initial mark time request
ld (astflg),a ; init AST flags
ld de,'TI'
ld c,0
ld b,5
SC .ALUN ; assign LUN 5 to TI:
ld hl,qterm
SC .QIO
ld a,(ttchr+1)
or a ; ANSI terminal?
jr nz,t1
ld hl,vt52 ; default to VT52 if not
ld de,vt100
ld bc,tdlen
ldir
t1: ld de,ttast ; attach with ASTs
ld c,5 ; LUN
call ATTACH
ld e,2
SC .CLEF ; clear flag 2
loop0: call CLS ; clear screen
call VCLS ; clear frame buffer
xor a ; redraw everything
call display ; call display routine
call VOUTP ; output frame buffer
loop: ld hl,astflg
bit 0,(hl) ; time mark?
jr z,wait ; jump if not yet arrived
res 0,(hl)
ld hl,(RATE)
ld h,0
ld d,2 ; units = seconds
ld e,0 ; no EFN
ld bc,tmast ; AST routine address
SC .MRKT ; setup AST to arrive in (RATE) seconds
wait: ld e,2
SC .WTSE ; wait for flag 2 (AST)
ld e,2
SC .CLEF ; clear flag 2
loopk: ld hl,astflg ; see what happened
bit 1,(hl) ; char arrived?
jr z,chkt ; jump if not
res 1,(hl)
ld a,(astchr) ; fetch char
call UCASE
cp ' ' ; space
jr z,loop0 ; redraw all
cp 3 ; ^C
jp z,quit ; exit program
cp 1Ah ; ^Z
jp z,quit ; exit program
cp ESC ; escape
jr nz,m1
ld hl,(ACTPG)
cpw hl,HELP+4
jr z,loopk ; ignore setup command for help screen
call COMND ; else prompt for and get command
jr loop0 ; replot everything afterwards
m1: call SELPG ; check for switch page command
jp loop0 ; loop to redraw everything
;; jr loopk ; note loopk and not chkt below, to avoid
;; ; multi-seq keys affecting responsiveness
chkt: ld hl,astflg
bit 0,(hl) ; time mark?
jr z,wait ; jump if not (and do not clear the bit here)
ld a,1
call display ; call display routine
call VOUTP ; output frame buffer
jp loop
display:
ld hl,(ACTPG)
ldw hl,(hl)
jp (hl)
snpsht: call VCLS ; clear frame buffer
xor a ; redraw everything
call display ; call display routine
call VSNAP ; output snapshot of the frame buffer
ld c,EX.SUC ; exit with success code
jp exit
quit: call CLS
ld c,EX.SUC ; exit with success code
jp exit
; select page
SELPG: cp 'M'
ld hl,MEMPG
jr z,setmod
cp 'A'
ld hl,ATDPG
jr z,setmod
cp 'D'
ld hl,DEVPG
jr z,setmod
cp 'T'
ld hl,THDRPG
jr z,setmod
;; cp 'H'
ld hl,HELP ; default mode for unknown commands
setmod: call (hl)
ld (ACTPG),hl
ret ; return with CY clear
syserr: ld hl,sysmsg
call ERROR
jp fatal1
sysmsg: db 'Invalid system type or version',0
;-----------------------------------------------------------------------
; Parse command line
PARSE: ex de,hl ; get pointer to command line into DE
call SKIPW ; skip program name
call SKIPBL
or a
ret z
call UCASE
call SELPG ; first option is page number
call SKIPW
pcm1: call SKIPBL
or a
ret z
cp '/' ; option?
jr nz,pcm4
inc de
call GETOPT
push de
ld de,CMDBUF
call SKIPBL
call UCASE
cp 'S' ; check for 'S'napshot option
jr nz,pcm2
ld a,1
ld (opts),a
jr pcm3 ; note CY clear
pcm2: ld de,CMDBUF
call COMNDL ; pass option to selected page
pcm3: pop de
jr c,pcm5
jr pcm1 ; loop until all processed
pcm4: call ERRCMD
pcm5: ld c,EX.ERR ; exit with error code
jp exit
GETOPT: ld hl,CMDBUF
gtop1: ld a,(de)
or a
jr z,gtop2
cp '/'
jr z,gtop2
ld (hl),a
inc hl
inc de
jr gtop1
gtop2: xor a
ld (hl),a
ret
;-----------------------------------------------------------------------
; Handle errors
ERROR: push hl
ld hl,rmdpfx
call PUTSTR
pop hl
call PUTSTR
ld c,CR
call PUTCH
scf
ret
FATAL: push af
ld hl,rmdpfx
call PUTSTR
pop af
call PERROR
ld c,CR
call PUTCH
fatal1: ld c,EX.ERR ; exit with error code
exit: push bc
call TTFLSH
ld c,5 ; LUN
call DETACH
pop bc
ld l,c ; exit code
ld h,0
SC .EXIT
rmdpfx: db CR,LF,'RMD -- ',0
;-----------------------------------------------------------------------
dseg
qterm: QIOW$ SF.GMC,5,1,iosb,,<ttchr,ttlen>
ttchr: db TC.ANS,0
ttlen equ $-ttchr
iosb: ds 4
RATE: ds 1 ; replot rate in seconds
ACTPG: ds 2 ; address of current page
SYSVN: ds 4 ; system version number and type
opts: ds 1 ; snapshot option
astflg: ds 1 ; AST flags:
; bit 0 set = mark time flag
; bit 1 set = unsolicited char arrived
astchr: ds 1 ; received char
public ?MEMRY
?MEMRY: ds 2
ds 128
stack equ $
;-----------------------------------------------------------------------
; Persistent data used by the display pages (any data stored in the
; overlay is volatile)
public MTOP,MBOT,DEVTBL ; MEMPG
MBOT: dw 0 ; bottom limit of region to display
MTOP: dw 0 ; top limit of region to display
DEVTBL: db 'SY',0 ; TODO: move the default settings to RMD.INC
db 'DY',1
db 'DU',0
db 'DU',2
public TSKNAM ; THDRPG
TSKNAM: db '...RMD'
public DEVNAM ; DEVPG
DEVNAM: dw 0
end START