-
Notifications
You must be signed in to change notification settings - Fork 0
/
kosmon.asm
executable file
·2768 lines (2543 loc) · 38.7 KB
/
kosmon.asm
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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; KosMon - A Machine Language Monitor for C64 and PET.
;;
;; (C) 1986-1996 by Olaf Seibert. All Rights Reserved.
;; May be distributed under the GNU General Public License.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Hints for the C64 $C000 version:
; Move the entry point, marked with ///, to the indicated place,
; and change the base and BRK entry point accordingly.
; For a <4K version, set the symbol haveecmd to 0.
processor 6502
mac cset ; conditional set
ifnconst {1}
{1} = {2}
endif
endm
cset base, $9000 ; /// -$cc
c64 = 1
pet = 2
cset target, pet
; the settings below are for pets only.
; Note there is only allowance for Basic 2.0 (new roms) and 4.0.
cset petb2, 0 ; flag
cset petb4, 1 ; flag
cset petb440, 0 ; flag for petb4 only
cset petb480, 1 ; flag for petb4 only
lines = 25
#if petb4 && petb480
columns = 80
#else
columns = 40
#endif
mindiskdev = 8
diskdev = 8 ; my taste
printdev = 4 ; my taste
printsa = 7 ; my taste
cset havedashes, 1
#if target == c64
cset haveecmd, 1
havepfkeys = 1
#else
haveecmd = 0
havepfkeys = 0
#endif
#if [target == pet] && petb2
cset autorepeat, 1
#else
cset autorepeat, 0
#endif ; (target == pet) && petb2
#if autorepeat
slowrep = 23 ; time before first repeat (in jiffies)
fastrep = 4 ; time between repeats (in jiffies)
#endif ; autorepeat
;+++ absolute adresses
#if target == c64
pport = $01
status = $90
verck = 0 ; not needed
msgflg = $9d
fnlen = $b7
sa = $b9
fa = $ba
stal = $c1
memuss = stal+2
ndx = $c6
indx = $c8
lxsp = $c9
blnsw = $cc
gdbln = $ce
blnon = $cf
eal = $ae
crsw = $d0
pnt = $d1
pntr = $d3
qtsw = $d4
tblx = $d6
datax = $d7
ldtbl = $d9
rtsp = $0200
rtstack = $0201
keyd = $0277
gdcol = $0287
hibase = $0288
autodn = $0292
tmplin = $02a5
cirqv = $0314
cbrkv = $0316
;+++ external jumps
basnmi = $a002
vicreset = $e5a8
kbdget = $e5b4
scrcont = $e602
scrget = $e63a
scrprint = $e716
instlin = $e981
pokchr = $ea13
kbdinput = $f15b
busclse = $f651
ioinit = $fda3
second = $ff93
tksa = $ff96
iecin = $ffa5
iecout = $ffa8
untlk = $ffab
unlsn = $ffae
listen = $ffb1
talk = $ffb4
setlfs = $ffba
setnam = $ffbd
load = $ffd5
save = $ffd8
stop = $ffe1
#endif
#if target == pet
time = $8d
cirqv = $90
cbrkv = $92
status = $96
lstx = $97
nokey = $ff ; for lstx
verck = $9d
ndx = $9e
indx = $a1
lxsp = $a3
blnsw = $a7
blnct = $a8
gdbln = $a9
blnon = $aa
crsw = $ac
eal = $c9
fnlen = $d1
la = $d2
sa = $d3
fa = $d4
pnt = $c4
pntr = $c6
qtsw = $cd
tblx = $d8
datax = $d7
fnadr = $da
#if petb4 && petb480
ldtbl = 0 ; not implemented
#else
ldtbl = $e0
#endif ; petb4 && petb480
stal = $fb
memuss = stal+2
rtsp = $0200
rtstack = $0201
keyd = $026f
tmplin = 0 ; not implemented
msgflg = 0 ; not implemented
gdcol = 0 ; not implemented
autodn = 0 ; not implemented
hibase = 0 ; not implemented
;+++ external jumps
setnam = 0 ; not implemented
setlfs = 0 ; not implemented
#if petb2
basready = $c389 ; basic READY.
ioinit = 0
kbdget = $e285
scrprint = $e3d8 ; print .A to screen (could use FFD2)
vicreset = 0
instlin = $e5ba ; really: open line on screen
talk = $f0b6 ; send TALK
listen = $f0ba ; send LISTEN
second = $f128 ; send SA after LISTEN
tksa = $f164 ; send SA after TALK
iecout = $f16f ; send byte to IEEE bus
untlk = $f17f ; send UNTALK
unlsn = $f183 ; send UNLISTEN
iecin = $f18c ; get byte from IEEE bus
romload = $f322 ; O/S version of LOAD
searching = $f40a ; print SEARCHING FOR name
sendname = $f466 ; send program name to bus
loading = $f42e ; print LOADING
save = $f6a4 ; O/S version of SAVE
buslsnclse = $f6f0 ; send LISTEN, CLOSE and UNLISTEN
busclse = $f6fd ; send CLOSE and UNLISTEN
kbdinput = $f1e5 ; FFCF after checking for keyboard
stop = $f301 ; test STOP key
scrcont = $e2cc ; continue INPUT loop
scrget = $e2fc ; INPUT (get) byte from screen
pokchr = $e6ea ; put char (and colour) in screen memory
; the N-keybd version has an extra delay loop
; here but we can't avoid that: would not work
; with the B version.
#endif ; petb2
#if petb4
; Sigh... the E000 jumptable entries are not
; in the "upgrade" 4.0 version for PETs without
; CRT controller... sigh...
basready = $b3ff
ioinit = $e000
kbdget = $e0a7 ; $e003 would be better but less compatible
scrprint = $e202 ; $e009 print .A to screen
vicreset = $e018 ; lower case settings
instlin = $e021
talk = $f0d2
listen = $f0d5
second = $f143
tksa = $f193
iecout = $f19e
untlk = $f1ae
unlsn = $f1b9
iecin = $f1c0
romload = $f356
searching = $f449
sendname = $f4a5
loading = $f46d
save = $f6e3
buslsnclse = $f72f
busclse = $f73c
stop = $f335
kbdinput = $f219
#if petb440
scrcont = $e0ee ; accidentally the same in 40 and 80 colums
scrget = $e11e
pokchr = $e606 ; accidentally the same in 40 and 80 colums
#endif ; petb440
#if petb480
scrcont = $e0ee ; accidentally the same in 40 and 80 colums
scrget = $e121
pokchr = $e606 ; accidentally the same in 40 and 80 colums
#endif ; petb480
#endif ; petb4
;+++ tables and hardware addresses
screen = $8000
#if petb4 && petb480
ram96latch = $fff0 ; set to 0 to not support it.
#else
ram96latch = 0 ; set to 0 to not support it.
#endif
#endif ; target == pet
;+++ constants
cr = $0d
cu = $91; "^Q"
cd = $11; "^q"
home = $13; "^s"
rvs = $12; "^r"
off = $92; "^R"
pf1 = $85; "^E"
cri = $1d; "^]"
cl = $9d; "^]"
quote = 34
hexwidth = columns / 5 ; 8 or 16
ascwidth = 4 * columns / 5 ; 32 or 64
org base
; +++ program
;///mark with start
entry php
pha
lda #<romin
sta cbrkv
lda #>romin
sta cbrkv+1
lda #0
sta rtsp
pla
plp
brk
romin
#if target == c64
lda #$36
sta pport
#if .romin_end != ramin
jmp ramin
#endif
.romin_end
#endif
;///mark with end
subroutine
ramin cld
ldx #5
ic012 pla
sta rspace,x
dex
bpl ic012
tsx
stx spsave
stx stackmk
lda pclo
bne ic028
dec pchi
ic028 dec pclo
lsr pflag
lda fa
cmp #mindiskdev
bcs ic038
lda #diskdev
sta fa
ic038
#if msgflg
lda #$c0
sta msgflg
#endif
jsr docr
jmp rcmd
;lda #"R"
;bne docmd
error lda #"?"
jsr scrprint
prompt jsr docr
lda #"."
jsr scrprint
lda #0
sta ovflow
sta pflag
execute ldx stackmk
txs
ic05c jsr nextchr
cmp #"."
beq ic05c
docmd ldx #adrtab-cmdtab-1
cmdloop cmp cmdtab,x
bne cmdnxt
sta cmdchr
txa
asl ;a
tax
lda adrtab+1,x
pha
lda adrtab,x
pha
php
rti ;do the command
cmdnxt dex
bpl cmdloop
bmi error
; the p command is a prefix for the others.
; when used it prints on both the screen and printer #printdev.
pcmd sec
ror pflag ; set high bit
bne execute
;+++ pointer routines
ststlinc
jsr stastal
incstal inc stal
bne ic6a0
inc stal+1
bne ic6a0
inc ovflow
ic6a0 rts
decmuss ldx #2
dc.b $2c
decstal ldx #0
ldy stal,x
bne ic09b
ldy stal+1,x
bne ic099
inc ovflow
ic099 dec stal+1,x
ic09b dec stal,x
rts
staleqsv
lda stalsav
ldy stalsav+1
jmp ic0ce
steqend lda memuss
ldy memuss+1
ic0ce sec
sbc stal
sta loleft
tya
sbc stal+1
tay ;hileft
ora loleft
rts
swstend ldx #2
ic5f0 lda stal-1,x
pha
lda memuss-1,x
sta stal-1,x
pla
sta memuss-1,x
dex
bne ic5f0
rts
stpc sta pclo
stx pchi
rts
;/// move entry for $c000 here
;+++ conversion routines
sphex2 pha
jsr dospc
pla
jmp hex2
hex4 lda stal+1
jsr hex2
lda stal
hex2 pha
lsr ;a
lsr ;a
lsr ;a
lsr ;a
jsr hex1
tax
pla
and #$0f
jsr hex1
printxa pha
txa
jsr print
pla
jmp print
a2hexax pha
lsr ;a
lsr ;a
lsr ;a
lsr ;a
jsr hex1
tax
pla
and #$0f
hex1 clc
adc #$f6
bcc ic5eb
adc #6
ic5eb adc #$3a
rts
deci ldx #8
ica3d sec
lda stal
cmp tenpow,x
lda stal+1
sbc tenpow+1,x
bcs ica4e
dex
dex
bne ica3d
ica4e ldy #$30
sec
ica51 lda stal
sbc tenpow,x
pha
lda stal+1
sbc tenpow+1,x
bcc ica66
sta stal+1
pla
sta stal
iny
bne ica51
ica66 pla
tya
jsr print
dex
dex
bpl ica4e
rts
; print .SR
printps jsr dospc
lda pssave
bin8 ldx #8 ; print .A binary
ic704 rol ;a
pha
lda #"*"
bcs ic70c
lda #"."
ic70c jsr print
pla
dex
bne ic704
rts
getstend
jsr hex2stal
sta memuss
stx memuss+1
jsr eol
beq ic3ab
jsr hex2muss
ic3ab jmp docr
get3adrs ; get addresses to memuss, stalsav, stal.
jsr hex2muss
;sta memuss
;stx memuss+1
jsr hex2ax
sta stalsav
stx stalsav+1
hex2stal ; get address to stal
jsr hex2ax
sta stal
stx stal+1
rts
hex2muss ; get address to memuss
jsr hex2ax
sta memuss
stx memuss+1
rts
hex2ax jsr hex2a ; get hex address to a,x
;bcc errc6
tax
;jsr hex2a
;bcc errc6
;rts
hex2a ;lda #0 ; get hex byte to .A
;sta nybble
jsr nextchr
hexa2a jsr hex2nybb ; get hex byte in .A decoded to .A
asl ;a
asl ;a
asl ;a
asl ;a
sta nybble
jsr nextchr
jsr hex2nybb
ora nybble
sec
rts
errcd jmp error
hex2nybb ; convert character to hex nybble
cmp #":"
bcc ic651
sbc #7
ic651 and #$0f
rts
tst0f cmp #"0" ; test for 0-F
bcc ic50e
cmp #"G"
rts ;c=0:mogelijk cijfer
ic50e sec ;geen cijfer
rts
; hexadecimal or decimal input
hdin4 ldy #0
sty $00,x
sty $01,x
cmp #"$"
beq hexin4
jsr tst09
bcs errcd
icd14 pha ; decimal input
asl $00,x ; * 10
lda $00,x
rol $01,x
ldy $01,x
asl ;a
rol $01,x
asl ;a
rol $01,x
clc
adc $00,x
sta $00,x
bcc icd2c
iny
clc
icd2c pla
adc $00,x
sta $00,x
tya
adc $01,x
sta $01,x
jsr kbdinput
jsr tst09
bcc icd14
rts
hexin4 jsr hexin1 ; input 1-4 hexadecimal digits (4 significant)
bcs errcd
icd44 ldy #4
icd46 asl $00,x
rol $01,x
dey
bne icd46
ora $00,x
sta $00,x
jsr hexin1
bcc icd44
rts
hexin1 jsr kbdinput ; input 1 hexadecimal digit
cmp #"G"
bcs icd74
cmp #"A"
bcs icd70
tst09 cmp #"0" ; test if between 0 and 9
bcc icd74
cmp #":"
bcs icd74
and #$0f
rts
icd70 sbc #$37
clc
rts
icd74 sec
rts
bin2a ldx #8 ; binary to .A
ic752 pha
jsr nextchr
cmp #"*"
beq ic75b
clc
ic75b pla
rol ;a
dex
bne ic752
rts
eol lda pntr ; test if at the end of input
cmp indx
rts
nextchr jsr inpsksp ; get next nospace character
bne nocr ; always
inpsksp jsr input ; get character, skipping spaces
skipspc cmp #" "
beq inpsksp
ic653 rts
inpnocr jsr input ; get next character
nocr cmp #cr ; error if cr
bne ic653
jmp error ; prompt
;+++ command routines
ccmd lda #0 ; Compare command
dc.b $2c
tcmd lda #1 ; Transfer command
sta ctflag ; remember C or T
jsr get3adrs ; get Start, End, Dest
jsr docr
jsr steqend
jsr swstend
bcc ic10d
ic0f2 jsr staleqsv
bcs ic0fa
jmp prompt
ic0fa jsr ctbyte
inc memuss
bne ic103
inc memuss+1
ic103 jsr incstal
ldy ovflow
bne ic153
beq ic0f2
ic10d jsr staleqsv
clc
lda loleft
adc memuss
sta memuss
tya
adc memuss+1
sta memuss+1
;jsr swpadrs was subr
swpadrs ldx #2
ic0b1 lda stal-1,x
pha
lda stalsav-1,x
sta stal-1,x
pla
sta stalsav-1,x
dex
bne ic0b1
;rts
ic120 jsr ctbyte
jsr staleqsv
bcs prptc1
jsr decmuss
jsr decstal
ldy ovflow
bne ic153
beq ic120
ctbyte jsr ldastal
ldy ctflag
beq ic142
jmp stamuss
ic142 jsr cmpmuss
beq ic152
hex4stop ; print 4 hex digits, space, test STOP
jsr hex4
jsr dospc
jsr stop
beq ic153
ic152 rts
ic153 jmp prompt
fcmd jsr hex2stal
jsr hex2muss
jsr hex2a
;bcc errc1
sta apos
ic167 ldx ovflow
bne prptc1
jsr steqend
bcc prptc1
lda apos
jsr stastal
jsr incstal
bne ic167 ; always
prptc1 jmp prompt
hcmd jsr hex2stal
jsr hex2muss
ldx #0
jsr nextchr
cmp #"'"
bne hunthex
jsr nextchr
ic197 sta huntbuf,x
inx
jsr kbdinput
cmp #cr
beq ic1c4
cpx #end-huntbuf
bne ic197
beq ic1c4
hunthex ;stx nybble
jsr hexa2a
bcc errc1
ic1b0 sta huntbuf,x
inx
jsr inpsksp
cmp #cr
beq ic1c4
jsr hexa2a
bcc errc1
cpx #end-huntbuf
bne ic1b0
ic1c4 stx huntlen
jsr docr
huntloop
ldx #0
ldy #0
testnext
jsr ldastaly
cmp huntbuf,x
bne ic1e0
iny
inx
cpx huntlen
bne testnext
jsr hex4stop
ic1e0 jsr incstal
ldy ovflow
bne prptc1e
jsr steqend
bcs huntloop
prptc1e jmp prompt
errc1 jmp error
ycmd lda #0
sta huntlen
jsr hex2stal
jsr hex2muss
y02 jsr inpsksp
cmp #cr
beq yloop
jsr tst0f
bcs errc1
jsr hexa2a
ldy huntbuf
sty huntbuf+1
sta huntbuf
inc huntlen
bne y02
yloop jsr steqend
bcc prptc1e
jsr opredu
ldy oplen
cpy huntlen
bne y00
y01 jsr ldastaly
cmp huntbuf-1,y
bne y00
dey
bne y01
jsr dlinecm
y00 jsr adstalen
jsr stop
bne yloop
beq prptc1e
dcmd jsr getstend ; Disassemble command
dloop jsr steqend
bcc cuprpt
jsr ddashes
jsr adstalen
jsr stop
bne dloop
cuprpt jsr printcu
bne prptc1e
#if havedashes
ddashes jsr dlinecm
dashes jsr ldastal
tay
and #%11011111;jmp/jmp()
cmp #%01001100
beq dodashes
tya
and #%10011111;brk/rts/rti/jsr
cmp #%00000000
bne nodashes
cpy #%00100000;jsr
beq nodashes
dodashes
jsr docr
ldx #35
lda #"-"
ili0 jsr print
dex
bne ili0
nodashes
#else
ddashes = dlinecm
#endif ; havedashes
rts
dlinecm ldy #","
dline jsr dinstr
ldx #9
doxsp jsr dospc ; print .X spaces
dex
bne doxsp
rts
dinstr jsr crdotysp ; disassemble one opcode
dinstr2 jsr hex4
jsr dospc
jsr opredu
pha
jsr ddump
pla
jsr unpack
ldx #6
ic220 cpx #3
bne ic239
ldy oplen
beq ic239
;print hex byte/s
ic229 lda mode
cmp #$e8 ;relative
jsr ldastaly ; must preservr carry
bcs prtrelad
jsr hex2savx
dey
bne ic229
ic239 asl mode
bcc ic24c ;842184
lda modes1-1,x;$(#,),
jsr prtnosup
lda modes2-1,x; $$x y
beq ic24c
jsr prtnosup
ic24c dex
bne ic220
rts
prtrelad
jsr adcstala
tax
inx ;low
bne ic258
iny ;hi
ic258 tya
jsr hex2savx
txa
hex2savx stx .+7
jsr hex2
ldx #0 ; operand modified
rts
adstalen lda oplen
addstaa jsr ad1stala
sta stal
sty stal+1
rts
ad1stala sec ;signed accu
adcstala ldy stal+1
tax
bpl ic279
dey
ic279 adc stal
bcc ic27e
iny
ic27e rts
; Reduce opcode to essential instruction info
; used by a,d,y,scroll
opredu jsr ldastal
reduce tay
lsr ;a
bcc ic28e
lsr ;a
bcs ic29d
cmp #$22
beq ic2a5
and #7
ora #$80
ic28e lsr ;a
tax
lda illtab,x
bcs ic299
lsr ;a
lsr ;a
lsr ;a
lsr ;a
ic299 and #$0f
bne ic2a9
ic29d lsr ;a
bcc ic2a5
and #1
adc #1 ;c=1
dc.b $2c
ic2a5 lda #0
ldy #$80
ic2a9 tax
lda modes,x
sta mode
and #3
sta oplen
tya
and #$8f
tax
tya
ldy #3