-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathkernel64.src
4795 lines (3698 loc) · 94.9 KB
/
kernel64.src
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
.nam C64 KERNEL (C)1982,1988,1991 CBM
.subttl Copyright (C) 1982,1988,1991 Commodore Business Machines, Inc.
; ***********************************************************************
; * // *
; * CCCCCCC // 666666 444 444 *
; * CCC CCC // 666 444 444 *
; * CCC // 666 444 444 *
; * CCC // 6666666666 4444444444 *
; * CCC // 666 666 444 *
; * CCC CCC // 666 666 444 *
; * CCCCCCC // 6666666 444 *
; * // *
; * *
; * KKK KKK EEEEEEEEE RRRRRRRR NNN NN EEEEEEEEE LLL *
; * KKK KKK EEE RRR RRR NNNN NN EEE LLL *
; * KKK KKK EEE RRR RRR NNNNN NN EEE LLL *
; * KKKKK EEEEEE RRRRRRRR NNN NN NN EEEEEE LLL *
; * KKK KKK EEE RRR RRR NNN NNNN EEE LLL *
; * KKK KKK EEE RRR RRR NNN NNN EEE LLL *
; * KKK KKK EEEEEEEEE RRR RRR NNN NN EEEEEEEEE LLLLLLL *
; * *
; * *
; * E D I T O R K E R N E L *
; * *
; * *
; * COPYRIGHT (C)1991 BY COMMODORE BUSINESS MACHINES, INC. *
; * *
; * A L L R I G H T S R E S E R V E D *
; * *
; ***********************************************************************
; C65 Version 0.9A 910117
; ***********************************************************************
; * *
; * THIS LISTING CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF *
; * CBM, INC. REPRODUCTION, DISSEMINATION OR DISCLOSURE TO OTHERS *
; * WITHOUT EXPRESS WRITTEN PERMISSION IS PROHIBITED. THIS SOFTWARE *
; * IS INTENDED FOR USE IN SYSTEMS MANUFACTURED ONLY BY COMMODORE. *
; * *
; * INFORMATION IN THIS LISTING WILL CHANGE WITHOUT NOTICE. *
; * *
; * NO RESPONSIBILITY IS ASSUMED FOR THE RELIABILITY OF THIS SOFTWARE. *
; * *
; ***********************************************************************
;.end
.page
; Adapted from the following C64 Kernel files by Fred Bowen, as used
; in C64C ROM (CBM part numbers 901229-03 and 251913-01):
;
; .include disclaim
; .include declare
; .include editor1
;; .include conkat ;Japanese conversion tables
; .include editor2
; .include editor3
; .include serial
; .include rs232xmit
; .include rs232rcvr
; .include rs232io
; .include messages
; .include channelio
; .include openchnl
; .include close
; .include clall
; .include open
; .include load
; .include save
; .include time
; .include errors
;; .include tapefile ;replaced
;; .include tapectlr ;replaced
;; .include taperead ;replaced
;; .include tapewrite ;replaced
; .include init
; .include rs232nmi
; .include irqfile
; .include vectors
;
; The cassette driver code has been removed and replaced by Reset and
; DOS interface code for the C65 computer system. All other Kernel
; calls to cassette code patched to return a device-not-present or a
; stop-key status. RAMTAS speeded up by checking only 1st byte each page.
.page
.subttl DECLARE
* = $0000
d6510 *=*+1 ;6510 data direction register
r6510 *=*+1 ;6510 data register
* = $0090
status *=*+1 ;I/O operation status byte
stkey *=*+1 ;stop key flag
svxt *=*+1 ;cassette temporary
verck *=*+1 ;load or verify flag
c3p0 *=*+1 ;serial buffered character flag
bsour *=*+1 ;character buffer for serial
syno *=*+1 ;cassette sync #
xsav *=*+1 ;temp for basin
ldtnd *=*+1 ;index to logical file tables
dfltn *=*+1 ;default input device #
dflto *=*+1 ;default output device #
prty *=*+1 ;cassette parity
dpsw *=*+1 ;cassette dipole switch
msgflg *=*+1 ;Kernel message enable flag
ptr1 ;cassette error pass1
t1 *=*+1 ;temporary 1
ptr2 ;cassette error pass2
t2 *=*+1 ;temporary 2
time *=*+3 ;24 hour clock in 1/60th seconds
r2d2 ;serial bus usage
pcntr *=*+1 ;cassette stuff
bsour1 *=*+1 ;temp used by serial routine
count ;temp used by serial routine
cntdn *=*+1 ;cassette sync countdown
bufpt *=*+1 ;cassette buffer pointer
inbit ;rs-232 rcvr input bit storage
shcnl *=*+1 ;cassette short count
bitci ;rs-232 rcvr bit count in
rer *=*+1 ;cassette read error
rinone ;rs-232 rcvr flag for start bit check
rez *=*+1 ;cassete reading zeroes
ridata ;rs-232 rcvr byte buffer
rdflg *=*+1 ;cassette read mode
riprty ;rs-232 rcvr parity storage
shcnh *=*+1 ;cassette short cnt
sal *=*+1 ;starting address
sah *=*+1
eal *=*+1 ;ending address
eah *=*+1
cmp0 *=*+1
temp *=*+1
tape1 *=*+2 ;address of cassette buffer
bitts *=*+1 ;rs-232 trns bit count
nxtbit ;rs-232 trns next bit to be sent
diff *=*+1 ;cassette
rodata ;rs-232 trns byte buffer
prp *=*+1 ;cassette
fnlen *=*+1 ;length of current filename string
la *=*+1 ;current file logical addrress
sa *=*+1 ;current file secondary address
fa *=*+1 ;current file physical device #
fnadr *=*+2 ;address of current filename string
roprty ;rs-232 trns parity buffer
ochar *=*+1 ;cassette
fsblk *=*+1 ;cassette read block count
drive
mych *=*+1 ;cassette byte being built
cas1 *=*+1 ;cassette manual/controlled switch (updated during IRQ)
;Used by C65 newDOS!
tmp0
track
stal *=*+1
sector
stah *=*+1
memuss ;load temps (2 bytes)
imparm ;primm utility string pointer
tmp2 *=*+2
; variables for screen editor
lstx *=*+1 ;key scan index
ndx *=*+1 ;index to keyboard queue
rvs *=*+1 ;rvs field on flag
indx *=*+1 ;current input line end
lsxp *=*+1 ;current input column start
lstp *=*+1 ;current input line start
sfdx *=*+1 ;shift mode on print
blnsw *=*+1 ;cursor blink enable
blnct *=*+1 ;count to toggle cursor
gdbln *=*+1 ;character at cursor
blnon *=*+1 ;on/off blink flag
crsw *=*+1 ;input vs. get flag
pnt *=*+2 ;pointer to current line (text)
pntr *=*+1 ;current cursor column
qtsw *=*+1 ;quote switch
lnmx *=*+1 ;40/80 max position
tblx *=*+1 ;current cursor line
data *=*+1
insrt *=*+1 ;insert mode flag
ldtb1 *=*+26 ;screen lines high byte table & flags
user *=*+2 ;pointer to current line (attributes)
keytab *=*+2 ;keyscan table indirect
; rs-232 z-page
ribuf *=*+2 ;rs-232 input buffer pointer
robuf *=*+2 ;rs-232 output buffer pointer
frekzp *=*+4 ;free Kernel zero page 9/24/80
baszpt *=*+1 ;location $FF used by BASIC
* = $0100
bad *=*+1 ;stack
* = $0200
buf *=*+89 ;BASIC/monitor buffer
; tables for open files
lat *=*+10 ;logical file numbers
fat *=*+10 ;primary device numbers
sat *=*+10 ;secondary addresses
; system storage
keyd *=*+10 ;IRQ keyboard buffer
memstr *=*+2 ;start of memory
memsiz *=*+2 ;top of memory
timout *=*+1 ;IEEE timeout flag (unused)
; screen editor storage
color *=*+1 ;current foreground color
gdcol *=*+1 ;color at cursor
hibase *=*+1 ;base location of screen
xmax *=*+1 ;IRQ key buffer size
rptflg *=*+1 ;key repeat flag
kount *=*+1 ;delay between key repeats
delay *=*+1 ;delay before a key repeats
shflag *=*+1 ;shift flag byte
lstshf *=*+1 ;last shift pattern
keylog *=*+2 ;indirect for keyboard table setup
mode *=*+1 ;editor modes: LSB=pet/cattacanna, MSB=keybd lock
autodn *=*+1 ;auto scroll down flag (=0 on, >0 off)
; rs-232 storage
m51ctr *=*+1 ;6551 control register
m51cdr *=*+1 ;6551 command register
m51ajb *=*+2 ;non-standard (bittime/2-100)
rsstat *=*+1 ;rs-232 status register
bitnum *=*+1 ;number of bits to send (fast response)
baudof *=*+2 ;baud rate full bit time (created by open)
ridbe *=*+1 ;input buffer index to end
ridbs *=*+1 ;input buffer pointer to start
rodbs *=*+1 ;output buffer index to start
rodbe *=*+1 ;output buffer index to end
irqtmp *=*+2 ;holds IRQ during cassette operations
enabl *=*+1 ;rs-232 enables
caston *=*+1 ;TOD sense during cassette operations
kika26 *=*+1 ;temp storage for cassette read routine
stupid *=*+1 ;temp d1irq indicator for cassette read
lintmp *=*+1 ;temporary for line index
palnts *=*+1 ;PAL vs. NTSC flag (0=NTSC, >0=PAL)
* = $0300 ;BASIC indirects (10)
* = $0300+20 ;Kernel/OS indirects (20)
cinv *=*+2 ;IRQ vector
cbinv *=*+2 ;BRK vector
nminv *=*+2 ;NMI vector
iopen *=*+2 ; indirects for code
iclose *=*+2 ; conforms to Kernel spec 8/19/80
ichkin *=*+2
ickout *=*+2
iclrch *=*+2
ibasin *=*+2
ibsout *=*+2
istop *=*+2
igetin *=*+2
iclall *=*+2
usrcmd *=*+2 ;(unused) points to BRK handler
iload *=*+2
isave *=*+2
* = $0300+60
tbuffr *=*+192 ;cassette data buffer
* = $0400
vicscn *=*+1024 ;VIC text screen
ramloc ;beginning of BASIC program/data storage
.page
; I/O devices
vicreg = $d000
sidreg = $d400
viccol = $d800
* = $dc00 ;CIA #1 (6526)
colm ;keyboard matrix
d1pra *=*+1
rows ;keyboard matrix
d1prb *=*+1
d1ddra *=*+1
d1ddrb *=*+1
d1t1l *=*+1
d1t1h *=*+1
d1t2l *=*+1
d1t2h *=*+1
d1tod1 *=*+1
d1tods *=*+1
d1todm *=*+1
d1todh *=*+1
d1sdr *=*+1
d1icr *=*+1
d1cra *=*+1
d1crb *=*+1
* = $dd00 ;CIA #2 (6526)
d2pra *=*+1
d2prb *=*+1
d2ddra *=*+1
d2ddrb *=*+1
d2t1l *=*+1
d2t1h *=*+1
d2t2l *=*+1
d2t2h *=*+1
d2tod1 *=*+1
d2tods *=*+1
d2todm *=*+1
d2todh *=*+1
d2sdr *=*+1
d2icr *=*+1
d2cra *=*+1
d2crb *=*+1
timrb = $19 ;6526 crb enable one-shot tb
.page
; tape equates
blf = 1 ;basic load file
bdf = 2 ;basic data file
plf = 3 ;fixed program type
bdfh = 4 ;basic data file header
eot = 5 ;end of tape
sberr = 4
lberr = 8
sperr = 16
ckerr = 32
bufsz = 192 ;buffer size
; screen editor constants
llen = 40 ;single line 40 columns
nlines = 25 ;25 rows on screen
cr = $0d ;carriage return
maxchr = 80 ;maximum number of characters per logical line
nwrap = 2 ;maximum number of physical lines per logical line
;.end
;rsr 8/3/80 add & change z-page
;rsr 8/11/80 add memuss & plf type
;rsr 8/22/80 add rs-232 routines
;rsr 8/24/80 add open variables
;rsr 8/29/80 add baud space move rs232 to z-page
;rsr 9/2/80 add screen editor vars&con
;rsr 12/7/81 modify for vic-40
.page
.subttl EDITOR1
* = $e500 ;start of C64 Kernel
iobase ldx #<d1pra ;return address of 6526 (CIA #1)
ldy #>d1pra
rts
scrorg ldx #llen ;return screen size
ldy #nlines
rts
plot bcs 10$ ;read/plot cursor position
stx tblx
sty pntr
jsr stupt
10$ ldx tblx
ldy pntr
rts
.page
; initialize screen Editor
cint jsr panic ;restore default I/O channels & initialize VIC
lda #0 ;make sure we're in PET mode, keyboard locks off
sta mode
sta blnon ;we don't have a good character from the screen yet
lda #<shflog ;set shift logic indirects
sta keylog
lda #>shflog
sta keylog+1
lda #10
sta xmax ;maximum IRQ keyboard buffer size
sta delay ;delay before a key repeats
lda #14 ;initialize text color to lt. blue [901227-03]
sta color
lda #4
sta kount ;delay between key repeats
lda #12
sta blnct ;set cursor blink count
sta blnsw ;start cursor blinking
clsr lda hibase ;build screen lines high byte table, clear wrap flags
ora #$80
tay
lda #0
tax
10$ sty ldtb1,x
clc
adc #llen
bcc 20$
iny ;carry (bump high byte)
20$ inx
cpx #nlines+1 ;done # of lines?
bne 10$ ;...no
lda #$ff ;tag end of line table
sta ldtb1,x
ldx #nlines-1 ;clear from the bottom line up
30$ jsr clrln ;see scroll routines
dex
bpl 30$
; home function
nxtd ldy #0
sty pntr ;leftmost column
sty tblx ;topmost line
; move cursor to (pntr,tblx)
stupt ldx tblx ;get current line
lda pntr ;get current column
fndstr ldy ldtb1,x ;find begining of line
bmi stok ;...found
clc
adc #llen ;adjust pointer
sta pntr
dex
bpl fndstr ;...wrapped line(s)
stok jsr setpnt ;set up pnt indirect (901227-03)
lda #llen-1
inx
fndend ldy ldtb1,x
bmi stdone
clc
adc #llen
inx
bpl fndend
stdone sta lnmx
jmp scolor ;make color pointer follow (901227-03)
; this is a patch for input logic (901227-03)
; fixes input"xxxxxxx-40-xxxxx";a$ problem
finput cpx lsxp ;check if on same line
beq 10$ ;yes...return to send
jmp findst ;check if we wrapped down...
10$ rts
nop ;placeholder
; panic NMI entry
vpan jsr panic ;fix VIC screen
jmp nxtd ;home cursor
panic lda #3 ;restore default I/O channels
sta dflto
lda #0
sta dfltn
; init VIC
initv ldx #47 ;load all VIC registers
10$ lda tvic-1,x
sta vicreg-1,x
dex
bne 10$
rts
.page
; remove character from queue
lp2 ldy keyd
ldx #0
lp1 lda keyd+1,x
sta keyd,x
inx
cpx ndx
bne lp1
dec ndx
tya
cli
clc ;good return
rts
;--------------------------------------------------------------------
; fetch characters and display them until <cr>
;--------------------------------------------------------------------
loop4 jsr prt ;print the character in .A
loop3 lda ndx ;wait here for any buffered keystroke
sta blnsw ;...keep cursor blinking
sta autodn ;...enable auto scroll down
beq loop3
sei ;do the cursor blink thing
lda blnon
beq lp21 ;...branch if cursor not on
lda gdbln ;...get saved character
ldx gdcol ;...get saved color
ldy #0
sty blnon ;...flag cursor off
jsr dspp ;...display correct data at cursor position
lp21 jsr lp2 ;get the key from the IRQ buffer
cmp #$83 ;RUN key?
bne lp22 ;...no
ldx #10 ;...yes: fill buffer with canned message
sei
stx ndx
10$ lda runtbnew-1,x
sta keyd-1,x
dex
bne 10$
beq loop3
lp22 cmp #cr ;<CR> key?
bne loop4 ;...no
ldy lnmx
sty crsw ;...yes: set flag to pass characters from screen now
10$ lda (pnt),y ;...find last non-blank character on this line
cmp #' '
bne 20$ ;...got it
dey
bne 10$ ;...keep looking backwards from end of line
20$ iny
sty indx ;mark EOL
ldy #0
sty autodn ;disable auto scroll down
sty pntr ;mark beginning
sty qtsw ;clear quote mode
lda lsxp ;line input actually begins on
bmi lop5 ;...branch if wrapped line
ldx tblx
jsr finput ;analyze: does input begin & end in same line? column?
cpx lsxp
bne lop5 ;...not same line
lda lstp
sta pntr ;...begin input here
cmp indx
bcc lop5 ;...from this column. go pass characters
bcs clp2 ;...beyond this column. done input.
;--------------------------------------------------------------------
; input a line until carriage return
;--------------------------------------------------------------------
loop5 tya ;save current cursor position
pha
txa
pha
lda crsw ;where are we getting characters?
beq loop3 ;...from buffer (input is from keyboard)
lop5 ;...from screen (input is from screen)
ldy pntr
lda (pnt),y ;get a screen character
sta data
and #$3f ;convert from screen codes:
asl data
bit data
bpl 10$ ;...branch if not graphic character
ora #$80
10$ bcc 20$ ;...branch if not reverse field character
ldx qtsw
bne 30$
20$ bvs 30$ ;...branch if not shifted character
ora #$40
30$ inc pntr
jsr qtswc ;toggle quote mode IFF quote character
cpy indx
bne clp1 ;...branch if not on last input line
clp2 lda #0 ;clear flag, I/O is finished
sta crsw
lda #cr ;kludge for OPEN4,4:CMD4:LIST problem
ldx dfltn
cpx #3
beq 10$ ;...input is from screen
ldx dflto
cpx #3
beq 20$ ;...output is to screen
10$ jsr prt ;force a <cr>
20$ lda #cr ;pass a <cr> as the last character
clp1 sta data
pla ;restore cursor position (for BASIN)
tax
pla
tay
lda data ;kludge to translate PI character
cmp #$de
bne 10$ ;...branch if not PI
lda #$ff
10$ clc ;always a good return from keyboard or screen
rts
qtswc cmp #$22 ;test for quote character
bne 10$ ;...nope
lda qtsw
eor #$1 ;...yes: toggle quote flag
sta qtsw
lda #$22
10$ rts
;--------------------------------------------------------------------
; various entries from PRINT to output a character
;--------------------------------------------------------------------
nxt33 ora #$40 ;make a graphic character
nxt3 ldx rvs ;reverse mode?
beq nvs ;...no
nc3 ora #$80 ;make a reverse character
nvs ldx insrt ;in insert mode?
beq 10$ ;...no
dec insrt ;...yes: decrement field count
10$ ldx color ;get current foreground color
jsr dspp ;display the character
jsr wlogic ;check for wraparound
loop2 pla ;*** PRINT exits here ***
tay
lda insrt ;clear quote mode if quote was hit in insert mode
beq 10$
lsr qtsw
10$ pla ;restore registers
tax
pla
clc ;good return
cli
rts
.page
wlogic jsr chkdwn ;maybe we should we increment tblx
inc pntr ;bump charcter pointer
lda lnmx
cmp pntr ;if lnmx is less than pntr
bcs wlgrts ;...branch if lnmx>=pntr
cmp #maxchr-1 ;past max characters
beq wlog10 ;...branch if so
lda autodn ;should we auto scroll down?
beq wlog20 ;...branch if not
jmp bmt1 ;...else decide which way to scroll
wlog20 ldx tblx ;see if we should scroll down
cpx #nlines
bcc wlog30 ;...branch if not
jsr scrol ;else do the scroll
dec tblx ;and adjust current line#
ldx tblx
wlog30 asl ldtb1,x ;wrap the line
lsr ldtb1,x
inx ;index to next line
lda ldtb1,x ;get high order byte of address
ora #$80 ;make it a non-continuation line
sta ldtb1,x ;and put it back
dex ;get back to current line
lda lnmx ;continue the bytes taken out
clc
adc #llen
sta lnmx
findst lda ldtb1,x ;is this the first line?
bmi 10$ ;...branch if so
dex ;else backup 1
bne findst ;...until we are there
10$ jmp setpnt ;make sure pointers are right & rts
wlog10 dec tblx
jsr nxln
lda #0
sta pntr ;point to first byte
wlgrts rts
.page
bkln ldx tblx
bne bkln1
stx pntr
pla
pla
bne loop2
bkln1 dex
stx tblx
jsr stupt
ldy lnmx
sty pntr
rts
;--------------------------------------------------------------------
; print routine
;--------------------------------------------------------------------
prt pha
sta data ;save copy of character to print
txa ;save all registers
pha
tya
pha
lda #0
sta crsw ;flag output to screen
ldy pntr ;screen column to print to
lda data
bpl 10$ ;...branch if not shifted character
jmp nxtx ;...shifted
10$ cmp #cr ;<cr>?
bne 20$ ;...no
jmp nxt1
20$ cmp #' ' ;convert to screen codes
bcc 50$ ;...control character
cmp #$60 ;lower case?
bcc 30$ ;...no
and #$df ;convert $60-$7F to $40-$5F
bne 40$ ;...bra
30$ and #$3f ;convert $40-$5F to $00-$1F
40$ jsr qtswc ;if quote character, toggle quote switch
jmp nxt3 ;display the character
50$ ldx insrt ;insert mode set?
beq 60$ ;...no
jmp nc3 ;...yes, display it
60$ cmp #$14 ;<delete>?
bne ntcn1 ;...no
tya
bne bak1up
jsr bkln
jmp bk2
bak1up jsr chkbak ;should we dec tblx
dey
sty pntr
bk1 jsr scolor ;fix color ptrs
bk15 iny
lda (pnt),y
dey
sta (pnt),y
iny
lda (user),y
dey
sta (user),y
iny
cpy lnmx
bne bk15
bk2 lda #' '
sta (pnt),y
lda color
sta (user),y
bpl jpl3
ntcn1 ldx qtsw ;in quote mode?
beq 10$ ;...no
jmp nc3 ;...yes, display it but don't do it
10$ cmp #$12 ;<rvson>?
bne 20$
sta rvs
20$ cmp #$13 ;<home>?
bne 30$
jsr nxtd
30$ cmp #$1d ;<crsrrt>?
bne ncx2
iny
jsr chkdwn
sty pntr
dey
cpy lnmx
bcc ncz2
dec tblx
jsr nxln
ldy #0
jpl4 sty pntr
ncz2 jmp loop2
ncx2 cmp #$11 ;<crsrdn>?
bne colr1
clc
tya
adc #llen
tay
inc tblx
cmp lnmx
bcc jpl4
beq jpl4
dec tblx
curs10 sbc #llen
bcc gotdwn
sta pntr
bne curs10
gotdwn jsr nxln
jpl3 jmp loop2
colr1 jsr chkcol ;check for a color
jmp lower ;was jmp loop2
; shifted keys
nxtx and #$7f
cmp #$7f ;PI?
bne 10$
lda #$5e
10$ cmp #$20 ;function key?
bcc 20$
jmp nxt33
20$ cmp #cr ;<cr>?
bne 30$
jmp nxt1
30$ ldx qtsw ;quote mode?
bne 90$
cmp #$14 ;insert mode?
bne 80$
ldy lnmx
lda (pnt),y
cmp #' '
bne 40$
cpy pntr
bne 50$
40$ cpy #maxchr-1
beq 70$ ;exit if line too long
jsr newlin ;scroll down 1
50$ ldy lnmx
jsr scolor
60$ dey
lda (pnt),y
iny
sta (pnt),y
dey
lda (user),y
iny
sta (user),y
dey
cpy pntr
bne 60$
lda #$20
sta (pnt),y
lda color
sta (user),y
inc insrt
70$ jmp loop2
80$ ldx insrt
beq 100$
90$ ora #$40
jmp nc3
100$ cmp #$11 ;<crsrup>?
bne 120$
ldx tblx
beq jpl2
dec tblx
lda pntr
sec
sbc #llen
bcc 110$
sta pntr
bpl jpl2
110$ jsr stupt ;up a line
bne jpl2