-
Notifications
You must be signed in to change notification settings - Fork 82
/
monitor
679 lines (679 loc) · 13.2 KB
/
monitor
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
.PAG 'MONITOR 10/30/81'
;************************************************
;* *
;* KERNAL MONITOR *
;* *
;* ENTRY VIA CALL (JMP) OR BREAKPOINT (BRK) *
;* ---FUNCTIONS--- *
;* <:> ALTER MEMORY *
;* <;> ALTER REGISTERS *
;* <R> DISPLAY REGISTERS *
;* <M> DISPLAY MEMORY *
;* <G> START EXECUTION OF CODE *
;* <L> LOAD MEMORY *
;* <S> SAVE MEMORY *
;* <^> VIEW SEGMENT *
;* <@> DISK COMMAND *
;* <OTHER> LOAD AND EXECUTE FROM DISK *
;* *
;* FOR SYNTAX & SEMANTICS SEE CBM KERNAL MANUAL *
;* COPYRIGHT (C) 1981 BY CBM *
;************************************************
.PAG 'MONITOR'
;*****WARM START ENTRY*******
;
MONON JSR IOINIT ;GET I/O
JSR RESTOR ;VECTORS
JSR CINT ;SCREEN EDITOR
;
;*****COLD START ENTRY******
;
MONOFF LDA #<MONON ;POINT TO WARM START
STA EVECT
LDA #>MONON
STA EVECT+1
JSR CLRCH ;CLEAR CHANNELS
;
;*****CALL ENTRY*****
;
TIMC LDA #$40+$80
STA MSGFLG ;ERROR+MESSAGES ON
LDA #MS34-MS1 ;CALL ENTRY
STA TMPC
BNE B3 ;BRANCH ALWAYS
;
;*****BREAK ENTRY*****
;
TIMB JSR CLRCH ;CLR CHANNELS
LDA #MS36-MS1 ;BREAK ENTRY
STA TMPC
CLD
;
;SAVE .Y,.X,.A,FLAGS, AND PC
;
LDX #5
B1 PLA
STA PCH,X
DEX
BPL B1
;
B3
LDA I6509 ;SAVE INDIRECTION SEGMENT
STA XI6509
LDA CINV
STA INVL ;SAVE IRQ LOW
LDA CINV+1
STA INVH ;SAVE IRQ HIGH
;
TSX
STX SP ;SAVE ORIGINAL SP
CLI ;CLEAR INTS
;
B5 LDY TMPC ;MESSAGE CODE
JSR MSG ;PRINT BREAK/CALL
;
LDA #'R ;DISPLAY REGS ON ENTRY
BNE S0 ;BRANCH ALWAYS
;
;*****ERROR ENTRY*****
;
ERROPR JSR OUTQST
PLA
PLA
;
;*****COMMAND INTERPRETER ENTRY*****
;
STRTM1=*-1
LDA #$40+$80
STA MSGFLG ;I/O MESSAGES TO SCREEN
LDA #<BUF ;PUT FILENAME AT BOTTOM OF BASIC BUFFER
STA FNADR
LDA #>BUF
STA FNADR+1
LDA #IROM
STA FNADR+2
JSR CRLF
;
ST1 JSR BASIN ;READ COMMAND
CMP #$20
BEQ ST1 ;SPAN BLANKS
JMP (USRCMD) ;USER INDIRECT FOR MONITOR
;
;COMMAND INTERPRETER
;
S0 LDX #0
STX FNLEN
TAY ;SAVE CURRENT COMMAND
;
;PUT RETURN ADDRESS FOR COMMANDS ON STACK
;
LDA #>STRTM1
PHA
LDA #<STRTM1
PHA
;
TYA ;CURRENT COMMAND IN .A
;
S1 CMP CMDS,X ;IS IT THIS ONE?
BNE S2 ;NOTIT
;
STA SAVX ;SAVE CURRENT COMMAND
;
;INDIRECT JMP FROM TABLE
;
LDA CMDS+1,X
STA TMP0
LDA CMDS+2,X
STA TMP0+1
JMP (TMP0)
;
;EACH TABLE ENTRY IS 3 LONG---SKIP TO NEXT
;
S2 INX
INX
INX
CPX #CMDEND-CMDS
BCC S1 ;LOOP FOR ALL COMMANDS
;
;COMMAND NOT IN TABLE...LOOK ON DISK.
;COMMAND NAME CAN BE ANY LENGTH AND
;HAVE PARAMETERS.
;
LDX #0 ;LENGTH TO ZERO
S3 CMP #$D ;END OF NAME?
BEQ S4 ;YES...
CMP #$20 ;BLANK?
BEQ S4 ;YES
STA BUF,X
JSR BASIN ;GET NEXT
INX ;COUNT CHAR
BNE S3 ;AND CONTINUE
;
S4 STA TMPC
TXA ;COUNT
BEQ S6 ;IS ZERO
;
STA FNLEN
LDA #$40
STA MSGFLG ;MESSAGES OFF
LDA #8
STA FA ;WILL USE DEVICE #8
LDA #IROM ;COMMANDS ONLY LOAD TO ROM SEGMENT !!!***
STA I6509 ;TURN INDIRECT TO ROM SEGMENT
LDX #$FF
LDY #$FF
JSR LOAD ;TRY TO LOAD COMMAND
BCS S6 ;BAD LOAD...
;
LDA TMPC ;PASS LAST CHARACTER
JMP (STAL) ;GO DO IT
;
S6 RTS
.SKI 3
CMDS .BYT ':' ;ALTER MEMORY
.WOR ALTM
.BYT ';' ;ALTER REGISTERS
.WOR ALTR
.BYT 'R' ;DISPLAY REGISTERS
.WOR DSPLYR
.BYT 'M' ;DISPLAY MEMORY
.WOR DSPLYM
.BYT 'G' ;START EXECUTION
.WOR GO
.BYT 'L' ;LOAD MEMORY
.WOR LD
.BYT 'S' ;SAVE MEMORY
.WOR LD
.BYT '^' ;VIEW SEGMENT
.WOR VIEW
.BYT '@' ;DISK COMMAND (ALTERNATE)
.WOR DISK
.BYT 'Z' ;TRANSFER TO 2ND MICROPROCESSOR
.WOR IPCGO
CMDEND
.SKI 5
PUTP LDA TMP0 ;MOVE TMP0 TO PCH,PCL
STA PCL
LDA TMP0+1
STA PCH
RTS
.SKI 5
SETR LDA #<FLGS ;SET TO ACCESS REGS
STA TMP0
LDA #>FLGS
STA TMP0+1
LDA #IROM ;POINT INDIRECT AT ROMS
STA I6509
LDA #5
RTS
.SKI 5
;PRINTS ':' OR ';' BEFORE DATA TO PERMIT
;ALTER AFTER 'M' OR 'R' COMMAND
;
ALTRIT PHA ;PRESERVE ALTER CHARACTER
JSR CRLF
PLA
JSR BSOUT
.SKI 3
SPACE LDA #$20 ;OUTPUT A SPACE
.BYT $2C ;SKIP TWO BYTES
OUTQST LDA #'? ;OUTPUT QUESTION
.BYT $2C ;SKIP TWO BYTES
CRLF LDA #$D ;DO CARRIAGE RETURN
JMP BSOUT
.SKI 5
;DATA FOR REGISTER DISPLAY HEADING
;
REGK .BYT CR,$20,$20 ;3 SPACES
.BYT ' PC ',' IRQ ',' SR AC XR YR SP'
.SKI 5
;DISPLAY REGISTER FUNCTION
;
DSPLYR LDX #0
D2 LDA REGK,X
JSR BSOUT ;PRINT HEADING
INX
CPX #DSPLYR-REGK ;MAX LENGTH
BNE D2
LDA #';
JSR ALTRIT ;ALLOW ALTER AFTER DISPLAY
LDX PCH
LDY PCL
JSR WROA ;PRINT PROGRAM COUNTER
JSR SPACE
LDX INVH
LDY INVL
JSR WROA ;PRINT IRQ VECTOR
JSR SETR ;SET TO PRINT .P,.A,.X,.Y,.S
;
;DISPLAY MEMORY SUBROUTINE
;
DM STA TMPC ;BYTE COUNT
LDY #0 ;INDIRECT INDEX
DM1 JSR SPACE ;SPACE TWEEN BYTES
LDA (TMP0)Y
JSR WROB ;WRITE BYTE OF MEMORY
;
;INCREMENT INDIRECT
;
INC TMP0
BNE DM2
INC TMP0+1
;
DM2 DEC TMPC ;COUNT BYTES
BNE DM1 ;UNTIL ZERO
RTS
.SKI 5
;DISPLAY MEMORY FUNCTION
;
DSPLYM JSR RDOA ;READ START ADR
BCS ERRS1 ;ERR IF NO SA
JSR T2T2 ;SA TO TMP2
;
;ALLOW USER TO TYPE JUST ONE ADDRESS
;
JSR RDOA ;READ END ADR
BCC DSP123 ;GOOD...NO DEFAULT
;
LDA TMP2
STA TMP0 ;DEFAULT LOW BYTE
LDA TMP2+1
STA TMP0+1 ;DEFAULT HI BYTE
;
DSP123 JSR T2T2 ;SA TO TMP0, EA TO TMP2
DSP1 JSR STOP ;STOP KEY?
BEQ BEQS1 ;YES...BREAK LIST
;
LDA #':
JSR ALTRIT ;ALLOW ALTER
LDX TMP0+1
LDY TMP0
JSR WROA ;WRITE START ADDRESS
LDA #8 ;COUNT OF BYTES
JSR DM ;DISPLAY BYTES
;
;CHECK FOR END OF DISPLAY
;
SEC
LDA TMP2
SBC TMP0
LDA TMP2+1
SBC TMP0+1
BCS DSP1 ;END >= START
;
BEQS1 RTS ;A.O.K. EXIT
;
ERRS1 JMP ERROPR ;SYNTAX ERROR
.SKI 5
;ALTER REGISTER FUNCTION
;
ALTR JSR RDOA ;READ NEW PC
BCS ERRS1 ;ERROR...NO ADDRESS
;
JSR PUTP ;ALTER PC
;
JSR RDOA ;READ NEW IRQ
BCS ERRS1 ;ERROR...NO ADDRESS
;
LDA TMP0
STA INVL ;ALTER IRQ VECTOR
LDA TMP0+1
STA INVH
;
JSR SETR ;SET TO ALTER R'S
BNE A4 ;BRANCH ALWAYS
.SKI 2
;VIEW A SEGMENT (POINT INDIRECT)
;
VIEW JSR RDOB ;GET A BYTE
BCS ERRS1 ;IF SPACE,ERR
CMP #16 ;RANGE 0-15
BCS ERRS1 ;TO LARGE NO MODULO
STA I6509
RTS
.SKI 2
;ALTER MEMORY - READ ADR AND DATA
;
ALTM JSR RDOA ;READ ALTER ADR
BCS ERRS1 ;IF SPACE,ERR
;
LDA #8 ;ALLOW 8 BYTES CHANGE
;
;COMMON CODE FOR ':' AND ';'
;
A4 STA TMPC ;NUMBER OF BYTES TO CHANGE
;
A5 JSR RDOB ;READ BYTE
BCS A9 ;NONE...END OF LINE
;
LDY #0
STA (TMP0)Y ;STORE IT AWAY
;
;INCREMENT STORE ADDRESS
;
INC TMP0
BNE A6
INC TMP0+1
;
A6 DEC TMPC ;COUNT BYTE
BNE A5 ;UNTIL ZERO
;
A9 RTS
.SKI 5
;START EXECUTION FUNCTION
;
GO JSR RDOC ;SEE IF DEFAULT
BEQ G1 ;YES...PC IS ADDRESS
;
JSR RDOA ;NO...GET NEW ADDR
BCS ERRL ;ERROR...ADDRESS SCREWED UP
;
JSR PUTP ;MOVE ADDR TO P.C.
;
G1 LDX SP
TXS ;ORIG OR NEW SP VALUE TO SP
;
SEI ;PREVENT DISASTER
;
LDA INVH
STA CINV+1 ;SET UP IRQ VECTOR
LDA INVL
STA CINV
LDA XI6509 ;AND INDIRECTION REGISTER
STA I6509
;
;GET FLAGS,PCH,PCL,.A,.X,.Y
;
LDX #0
G2 LDA PCH,X
PHA ;EVERYBODY ON STACK
INX
CPX #6
BNE G2
;
;INTERRUPT RETURN SETS EVERYBODY UP
;FROM DATA ON STACK
;
JMP PREND
.SKI 3
ERRL JMP ERROPR ;SYNTAX ERROR JUMP
.SKI 3
;LOAD RAM FUNCTION
; *NOTE - LOAD/SAVE RESET INDIRECT TO ROM
;
LD LDY #1
STY FA ;DEFAULT DEVICE #1
DEY ;.Y=0 TO COUNT NAME LENGTH
LDA #$FF ;DEFAULT NO MOVE LOAD
STA TMP0
STA TMP0+1
LDA I6509 ;SAVE INDIRECT FOR SEG ADDRESS
STA T6509
LDA #IROM ;INDIRECT TO ROM FOR FILENAME
STA I6509
;
L1 JSR RDOC ;DEFAULT?
BEQ L5 ;YES...TRY LOAD
;
CMP #'
BEQ L1 ;SPAN BLANKS
;
CMP #'" ;STRING NEXT?
L2 BNE ERRL ;NO FILE NAME...
;
L3 JSR RDOC ;GET CHARACTER OF NAME
BEQ L5 ;END...ASSSUME LOAD
;
CMP #'" ;END OF STRING?
BEQ L8 ;YES...COULD STILL BE 'L' OR 'S'
;
STA (FNADR)Y ;STORE NAME
INC FNLEN
INY
CPY #16 ;MAX FILE NAME LENGTH
;
L4 BEQ ERRL ;FILE NAME TOO LONG
BNE L3 ;BRANCH ALWAYS
;
;SEE IF WE GOT A LOAD
;
L5 LDA SAVX ;GET LAST COMMAND
CMP #'L
BNE L2 ;NO..NOT A LOAD..ERROR
;
LDA T6509 ;GET SEGMENT TO LOAD TO
AND #IROM ;MASK OFF VERIFY BIT
LDX TMP0
LDY TMP0+1
JMP LOAD ;YES...DO LOAD
;
L8 JSR RDOC ;MORE STUFF?
BEQ L5 ;NO...DEFUALT LOAD
;
CMP #', ;DELEIMETER?
L9 BNE L2 ;NO...BAD SYNTAX
;
JSR RDOB ;YES...GET NEXT PARM
BCS L15 ;NOT GOOD
;
STA FA
;
JSR RDOC ;MORE PARMS?
BEQ L5 ;NO...DEFAULT LOAD
;
CMP #', ;DELIMETER?
L12 BNE L9 ;NO...BAD SYNTAX
;
JSR RDOB ;SEGMENT BYTE ?
BCS L15 ;NO...BAD
CMP #16 ;00-0F ALLOWED
BCS L15 ;TOO BIG...
STA T6509
STA STAS ;PREP SEGMENT
JSR RDOA ;START ADDRESS?
BCS L15 ;NO...BAD
;
;SET UP START SAVE ADDRESS
;
LDA TMP0
STA STAL
LDA TMP0+1
STA STAH
;
JSR RDOC ;DELIMETER?
BEQ L5 ;CR, DO LOAD
CMP #',
BNE L15 ;NO DELIM
;
JSR RDOB ;GET SEGMENT BYTE
BCS L15 ;NONE...
CMP #16 ;ALLOW ONLY 00-0F
BCS L15 ;TOO BIG...
STA EAS ;PREP SEGMENT
JSR RDOA ;TRY TO READ END
BCS L15 ;NONE...ERROR
;
;SET UP END SAVE ADDRESS
;
LDA TMP0
STA EAL
LDA TMP0+1
STA EAH
;
L20 JSR BASIN
CMP #$20
BEQ L20 ;SPAN BLANKS
;
CMP #CR
L14 BNE L12 ;MISSING CR AT END
LDA SAVX ;WAS COMMAND SAVE?
CMP #'S
BNE L14 ;NO...LOAD CAN'T HAVE PARMS
LDX #STAL ;GET PARAMS FOR SAVE
LDY #EAL
JMP SAVE
;
L15 JMP ERROPR
.SKI 5
;WRITE ADR FROM TMP0 STORES
;
WROA TXA ;HI-BYTE
JSR WROB
TYA ;LOW-BYTE
.SKI 3
;WRITE BYTE --- A = BYTE
;UNPACK BYTE DATA INTO TWO ASCII
;CHARACTERS. A=BYTE; X,A=CHARS
WROB PHA
LSR A
LSR A
LSR A
LSR A
JSR ASCII ;CONVERT TO ASCII
TAX
PLA
AND #$0F
.SKI 3
;CONVERT NYBBLE IN A TO ASCII AND
;PRINT IT
;
ASCII CLC
ADC #$F6
BCC ASC1
ADC #$06
ASC1 ADC #$3A
JMP BSOUT
.SKI 5
;EXCHANGE TEMPORARIES
;
T2T2 LDX #2
T2T21 LDA TMP0-1,X
PHA
LDA TMP2-1,X
STA TMP0-1,X
PLA
STA TMP2-1,X
DEX
BNE T2T21
RTS
.SKI 5
;READ HEX ADR,RETURN HI IN TMP0,
;LO IN TMP0+1,AND CY=1
;IF SP CY=0
;
RDOA JSR RDOB ;READ 2-CHAR BYTE
BCS RDOA2 ;SPACE
STA TMP0+1
JSR RDOB
STA TMP0
RDOA2 RTS
;READ HEX BYTE AND RETURN IN A
;AND CY=0 IF SP CY=1
RDOB LDA #0 ;SPACE
STA BAD ;READ NEXT CHAR
JSR RDOC
BEQ RDOB4 ;FAIL ON CR
CMP #' ;BLANK?
BEQ RDOB ;SPAN BLANKS...
;
JSR HEXIT ;CONVERT TO HEX NYBBLE
ASL A
ASL A
ASL A
ASL A
STA BAD
JSR RDOC ;2ND CHAR ASSUMED HEX
BEQ RDOB4 ;FAIL ON CR
JSR HEXIT
ORA BAD
;
RDOB4 RTS
.SKI 5
;CONVERT ASCII CHAR TO HEX NYBBLE
;
HEXIT CMP #$3A
PHP ;SAVE FLAGS
AND #$0F
PLP
BCC HEX09 ;0-9
ADC #8 ;ALPHA ADD 8+CY=9
HEX09 RTS
.SKI 5
;GET CHARACTER AND TEST FOR CR
;
RDOC JSR BASIN
CMP #$0D ;IS IT A CR
RTS ;RETURN WITH FLAGS
.SKI 5
;SEND DISK COMMAND OR READ STATUS
;
DISK LDA #0 ;CLEAR STATUS @ I/O BEGIN
STA STATUS
;
JSR RDOC ;SEE IF STATUS CHECK
BEQ DISK20 ;YES
;
PHA
LDA #8 ;FLOPPY IS DEVICE #8
JSR LISTN ;TELL FLOPPY TO RECEIVE
LDA #15+$60
JSR SECND ;ON COMMAND CHANNEL
;
PLA
LDX STATUS ;ERROR?
BPL DISK15 ;NO...OK
;
DISK5 JMP ERROR5 ;DEVICE NOT PRESENT
;
DISK10 JSR BASIN ;GET A CHARACTER
DISK15 CMP #$D ;SEE IF END
PHP ;SAVE FOR LATER
JSR CIOUT ;OUT TO FLOPPY
PLP ;END?
BNE DISK10 ;NO...CONTINUE
;
JMP UNLSN ;YES...FLOPPY DONE
;
DISK20 JSR CRLF
LDA #8 ;FLOPPY IS DEVICE #8
JSR TALK ;TELL FLOPPY TO SPEAK
LDA #15+$60
JSR TKSA ;FROM ERROR CHANNEL
;
LDA STATUS ;AN ERROR?
BMI DISK5 ;YES...
;
DISK25 JSR ACPTR ;GET A CHARACTER
CMP #$D ;SEE IF END
PHP ;TEST LATER
JSR BSOUT ;OUT TO SCREEN
PLP ;END?
BNE DISK25 ;NO...
JMP UNTLK ;YES...FLOPPY DONE
.SKI 5
; IPCGO - FREE BUS, INTERRUPT 2ND PROCESSOR
; GO INTO A LOOP, WAITING FOR REQUESTS.
;
IPCGO LDX #$FF
STX I6509 ;INDIRECTS TO BANK F ONLY
LDA TPI1+PB ;TPI1 PB4:=0 FREES DBUS
AND #$EF
STA TPI1+PB
NOP ;A PAUSE
LDA IPCIA+PRB ;CHECK NBUSY1
ROR A
BCS *+5
JMP ERROPR ;BUS NOT FREED, ERROR...
;
LDA #0 ;PB6 LO->HI IN 4US...
SEI
STA IPCIA+PRB ;INTERRUPT 2ND PROCESSEOR
LDA #$40 ;2 CYCLES (4US=8CYCLES)
NOP
NOP
NOP
NOP ;8 CYCLES OF GARB. 5US SAFER THAN 4!
STA IPCIA+PRB ;TURN PB6 BACK ON
CLI
IPLOOP JMP IPLOOP ;SIT DOWN
.END