-
Notifications
You must be signed in to change notification settings - Fork 10
/
abn6502rom.s
executable file
·2950 lines (2654 loc) · 69.9 KB
/
abn6502rom.s
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
.feature string_escapes ; Allow c-style string escapes when using ca65
.feature org_per_seg
.feature c_comments
.export I2CADDR, I2CREG, i2c_read, i2c_test, main, kb_rptr, PRIMM, printk, printbyte, wkey, PORTB, TIMEOUT,exitirq, printa, newline, setpulses, scrp, scwp, simpledelay, selectbaudrate, MILLISH,resetkb, clrscn,checkkeyboard, kb_buffer, MONRDKEY,CRSRPNT, t2irqreg1, MILLIS
;BASIC := 1 ; 1 if BASIC is enabled
;DEBUG = 1
PORTB = $6000 ; PB0: SCK/SCL, PB1: RF CS, PB2: RF CE, PB3: SDA, PB4,PB5: MISO ,PB6: PS/2 Clock In, PB7: MOSI/T1 Out (Tape drive output)
PORTA = $6001
DDRB = $6002
DDRA = $6003
T1CL = $6004
T1CH = $6005
T1LL = $6006
T1LH = $6007
T2CL = $6008
T2CH = $6009
SR1 = $600A
ACR = $600B ; [7] PB.7 T1 OUT, [6] T1 mode , [5] T2, [4:2] Shift register control, [1] PB Latch enable, [0] PA Latch Enable
PCR = $600C ; [7:5] CB2 Control, [4] CBl Control, [3:1] CA2 Control, [0] CAl Control
IFR = $600D ; [7:0] IRQ Tl T2 CBl CB2 SR CA1 CA2
IER = $600E ; [7:0] S/C Tl T2 CBl CB2 SR CA1 CA2
PORTANHS = $600F
CTRL = $7000
TIMEOUT = 7998 ; Should be around 2ms
RELEASE = %00000001
SHIFT = %00000010
ECODE = %00000100
CRSR = %01000000
CRSRF = %10000000
KTIMEOUT= %00100000
DBGFLAG = %00010000
kb_buffer = $0200 ; 128-byte kb buffer 0200-0280
scbuf = $0280 ; Scan code buffer
USERLANDH = $03 ; RAM page userland code starts
; Screen constants
SCREENSTARTH = $08 ; Change this to the page your Video RAM starts! (VRAM at $0800 requires a few jumpers to change from the default $2000 - this will change in the next build of R1)
SCREENSTARTL = $4c ; Top left of screen - may differ between VGA screens
LINESTART = $0c
LINEEND = $3E
NUMLINES = 28
;Custom keyboard mappings
DN_ARR_KEY = $F3
UP_ARR_KEY = $F4
PGUP_KEY = $F6
PGDN_KEY = $F5
L_ARR_KEY = $F2
R_ARR_KEY = $F1
HOME_KEY = $F0
ESC_KEY = $1b
PRTSC_KEY = $EF
F12_KEY = $EC
F11_KEY = $EB
F10_KEY = $EA
F9_KEY = $E9
movedfromzp = scbuf+8
brkcnt = movedfromzp
RF_STS = movedfromzp+1
MONCNT = movedfromzp+2
TMP = movedfromzp+3;
TMP2 = movedfromzp+4
RF_ERR = movedfromzp+5
ERRS = movedfromzp+6
TMP3 = movedfromzp+7
ABUF = movedfromzp+8 ; 8 bytes
;to $2F
;ABUF = $28
TMP4 = movedfromzp+16
SVCSR = movedfromzp+17
;+1
I2CADDR = movedfromzp+19
I2CREG = movedfromzp+20
zp_s = $f8
kb_wptr = zp_s
kb_rptr = zp_s+1
kb_flags = zp_s+2
kb_last = zp_s+3
scwp = zp_s+4
scrp = zp_s+5
outb = zp_s+6
inb = zp_s+7
zp_s2 = $e0
MONH = zp_s2+1
MONL = zp_s2
KEYBOARD = zp_s2+2
SPITMP = zp_s2+3
MILLIS = zp_s2+4
MILLISH = zp_s2+5
CRSRPNT = zp_s2+6
CRSRPNT2 = CRSRPNT+1
zp_s3 = $e8
SVP = zp_s3 ; Save pointer
SVPH =zp_s3+1
HXH = zp_s3+2
SLB = zp_s3+3 ; Size low byte
SHB = zp_s3+4
CRSRCHR = zp_s3+5
PRIMMZP1 = zp_s3+6
PRIMMZP2 = zp_s3+7
zp_s4 = $f0
t2irqreg1 = zp_s4
t2irqreg2 = zp_s4+1
USERLANDP = zp_s4+2 ; JMP Pointer
USERLANDPH = zp_s4+3
DEBUGP = zp_s4+4
DEBUGPH = zp_s4+5
zp_s5 = $d8
SCRLPNT = zp_s5 ; also +1
SCRLPNT2 = zp_s5+2 ; also +3
; Tape constants
KCS300PL = 4 ; Kansas City Standard takes 4 1200 Hz pulses for a 0
KCS300PH = 8 ; and 8 2400Hz pulses for a 1
; Tape vars
TAPEVARS = movedfromzp+32
CBIT = TAPEVARS
RXBYTE = TAPEVARS+1
BITNO = TAPEVARS+1 ; Reusing
TAPEFLAGS = TAPEVARS+2
PULSES = TAPEVARS+3
NRZBYTE = TAPEVARS+4
onesinarow = TAPEVARS+5
plsperiod = TAPEVARS+6 ; also +7
PULSESL = TAPEVARS+8 ; Config variable if we do something other than KCS
PULSESH = TAPEVARS+9 ; ^^
plzpnt = zp_s4+6 ; also +7
CT1L = TAPEVARS+10
CT1H = TAPEVARS+11
LT1L = TAPEVARS+12
LT1H = TAPEVARS+13
LOADTIMEOUT = TAPEVARS+14
; CE = $69
MSGBUF = TAPEVARS+15
;+32bytes == To
RF24REGS = MSGBUF+32
uservia = PORTB
mosi = %10000000
miso = %00100000
SDA = 8; PB3 bitmask
SDA_INV = $F7
SCL = 16; PB4 bitmask
SCL_INV = $EF
.segment "RODATA"
;.org $8000 ; Not strictly needed with CA65 but shows correct address in listing.txt
.list on ; Does this work?
nmi:
reset:
cld ; Because you never know
;CLEAR RAM
sei ; In case this was not a hw reset
ldx #$0
lda #0
clearzp:
sta $00,x
inx
bne clearzp
;Assumes x and A are 0 from above
clearstack:
sta $0100,x
inx
bne clearstack
clearp2:
sta $0200,x
inx
bne clearp2
clearp3:
sta $0300,x
inx
bne clearp3
ldx #$FF
txs
noclear: ;Soft reset point - BRK
jsr clrscn
lda #$F1
sta CTRL
lda #SCREENSTARTL
sta CRSRPNT
lda #SCREENSTARTH
sta CRSRPNT2
;lda #2
;sta PORTB ; Set SPI CS high
lda #%10010111 ; Port B DDR for SPI
sta DDRB
lda #0
sta DDRA ; Port A all inputs
sta kb_rptr ; Init keyboard pointers before enabling interrupts
sta kb_wptr
sta RF_ERR ; Reset RF error
;cli ; Enable interrupts
lda #%11000000 ; Set T1
sta IER
LDA #%01000000
STA ACR ; T1 continuous, PB7 disabled
LDA #<TIMEOUT
STA T1CL ; Set low byte of timer1 counter
LDA #>TIMEOUT
STA T1CH ; Set high byte of timer1 counter
ldx #$10 ; Read first tx addr byte = should be default, if not then no module connected
stx kb_flags ; Debug enabled
jsr rw_reg
cmp #$E7
bne norfmodule
jsr initrf24
bne welcome ; BRA
norfmodule:
;debug, disable RF
inc RF_ERR ; No module, set RF_ERR
welcome:
jsr PRIMM
message: .asciiz "GREETINGS PROFESSOR FALKEN.", "\n", "SHALL WE PLAY A GAME?", "\n"
welcomedone:
;Let's enable the keyboard
lda #$91
sta CTRL
jsr resetkb
lda #1
sta CTRL
cli
main: ; loop
lda RF_ERR
bne skiprf
bit ACR ; If ACR.7 is set then we can't use SPI since MOSI is outputting TM1.
bpl rfstuff
skiprf:
jmp nomsg
rfstuff:
;jsr readrf24regs ; Debug - we can also just do an rf_nop to read rf24 status (RF_STS)
jsr rf_nop ; Not debug
;If msg received, put it in MSGBUF
bit RF_STS
bvs gtgm ; Check irq
lda RF_STS
cmp #$0e ; Check if fifo empty
bne gtgm
;lda SLB
;bne nextpacket
jmp nomsg; No msg received
gtgm:
jsr getmessage
lda MSGBUF
bne datapacket ; Check for control message
lda MSGBUF+1
cmp #$31 ; Trust but verify
beq ctrlmsg
jsr initrf24 ; Junk package. Reset radio.
jmp nomsg
ctrlmsg:
lda MSGBUF+2
sta SLB ; Data size low byte
lda MSGBUF+3
sta SHB ; Data size high byte
jsr PRIMM
.asciiz "Receiving $"
lda SHB
jsr printbyte
lda SLB
jsr printbyte
jsr PRIMM
.asciiz " bytes. \n"
inc SHB
lda #0
sta SVP
lda #USERLANDH
sta SVPH ; Save pointer starts at #USERLANDH
jmp main
datapacket:
getmsg:
;inc $d2 ; Debug
;lda $90
;cmp #1
;bne nextpacket ; Data package with ID > 1
nextpacket:
ldx #2
fetchpacket:
lda MSGBUF,x
ldy #0
sta (SVP),y
inc SVP
bne nnhb
inc SVPH
nnhb:
dec SLB
bne movealong
dec SHB
beq txdone ; 0 bytes left - All done!
movealong:
dec SHB
lda SHB
jsr printbyte
inc SHB
lda SLB
jsr printbyte
jsr PRIMM
.asciiz " bytes left(hex) "
lda CRSRPNT
and #%11000000 ; keep only section bits
ora #LINESTART ;
sta CRSRPNT
inx
cpx #32
bne fetchpacket
jmp main
txdone:
lda #USERLANDH
sta USERLANDPH
lda #0
sta SLB
sta SHB
sta SVPH ; Reset
sta kb_rptr ; Reset the keyboard pointers here.
sta kb_wptr
sta USERLANDP
jsr PRIMM
.asciiz "\nData loaded into RAM at $"
LDA #USERLANDH
jsr printbyte
;lda #USERLAND
;jsr printbyte
jsr PRIMM
.asciiz "00. \nPress F5 or type \"run\" to start executing. \n"
nomsg:
jsr checkcursor
.ifdef DEBUG
lda kb_flags
and #DBGFLAG
beq nodebug
lda CRSRPNT ; Save cursor..
sta SVCSR
pha
lda CRSRPNT2
sta SVCSR+1
pha
LDA #$65 ; Print debug in top right corner of screen
sta CRSRPNT
lda #$08
sta CRSRPNT2
;lda #$6f
;sta CRSRPNT
lda (DEBUGP),y
jsr printbyte
inc CRSRPNT ; Space
;LDA #$72 ; Debug ERRS and show cursor pointer next to timer on screen
;sta CRSRPNT
;lda #$27
;sta CRSRPNT2
lda ERRS
jsr printbyte
inc CRSRPNT ; Space
lda SVCSR+1
jsr printbyte
lda SVCSR
jsr printbyte
inc CRSRPNT ; Space
lda MILLISH
jsr printbyte
inc CRSRPNT ; Space
lda IER
jsr printbyte
inc CRSRPNT ; Space
lda IFR
jsr printbyte
inc CRSRPNT ; Space
;lda kbshift
;jsr printbyte
;inc CRSRPNT ; Space
pla
sta CRSRPNT2
pla
sta CRSRPNT
nodebug:
.endif
jsr checkkeyboard
bne key_pressed
jmp main
checkkeyboard: ; Returns Z flag if nothing ready, not Z if something, kb_rptr in x
;sei ; Instead of disabling IRQ we might want to use the re-compare method.
;Load to x, then do the compare, then check if changed. Redo if changed. Idea for later..
lda #0
ldx scrp
cpx scwp
beq nonewsc
rescan:
jsr keyboard_handling
lda #0
ldx scrp
cpx scwp
bne rescan
cpx #7 ; Top of buffer
bcc nonewsc
sta scrp ; 0
sta scwp ; 0
nonewsc:
ldx kb_rptr
cpx kb_wptr
;bne gotkey
;sta kb_rptr
;sta kb_wptr
gotkey:
rts
copyscreen:
ldy #0
copypages:
lda (SVP),y
sta (SLB),y
iny
bne copypages
inc SVPH
inc SHB
dex
bne copyscreen
rts
printscreen:
lda #0
sta SVP
sta SLB
lda #SCREENSTARTH
sta SVPH
lda #$38
sta SHB
ldx #8
jsr copyscreen
lda #0
sta SVP
sta SLB
lda #$38
sta SVPH
lda #$40
sta SHB ; End pointer
jmp eom
loadscreen:
lda #0
sta SVP
sta SLB
lda #$38
sta SVPH
lda #SCREENSTARTH
sta SHB
ldx #8
jsr copyscreen
lda #0
sta SVP
sta SLB
sta SHB
jmp eom
key_pressed:
;ldx kb_rptr ; Should already be in x
lda kb_buffer, x
cmp #$0a ; enter - go new line
beq enter_pressed
cmp #$0d
beq enter_pressed
cmp #$1b ; escape - clear display
beq esc
cmp #$08
beq back
cmp #$FE ;Scan code $05
beq f1
cmp #$FD
beq f2
cmp #$FC
beq f3
cmp #$FB
beq f4
cmp #$FA
beq f5
cmp #$F9
beq f6
cmp #$F8
beq f7
cmp #$F7
beq f8
cmp #PRTSC_KEY
beq printscreen
cmp #L_ARR_KEY
beq golrudarr
cmp #R_ARR_KEY
beq golrudarr
cmp #UP_ARR_KEY
beq golrudarr
cmp #DN_ARR_KEY
beq golrudarr
cmp #F12_KEY
beq f12
jsr printk
printedkey:
inc kb_rptr
jmp main
golrudarr:
jmp lrudarr
back:
jmp backspace_pressed
f12:
jmp loadscreen
f8:
jmp f8_pressed
f7:
jmp f7_pressed
f6:
jmp f6_pressed
f5:
jmp f5_pressed
f4:
jmp f4_pressed
f3:
jmp f3_pressed
f2:
jmp f2_pressed
f1:
jmp f1_pressed
esc:
jmp esc_pressed
enter_pressed:
lda CRSRCHR
sta (CRSRPNT),y
ldx #0
lda kb_buffer,x
parsecmd:
cmp #'r'
beq read
cmp #'w'
beq write
cmp #'H'
beq strangegame
cmp #'h'
beq strangegame
jmp err
read:
jmp jread
strangegame:
jsr PRIMM
.asciiz "\n", "A STRANGE GAME. THE ONLY WINNING ", "\n", "MOVE IS NOT TO PLAY.", "\n"
wrotegtnw:
jmp eom
jerr:
jmp err
write:
ldy #$FF
inx
lda kb_buffer,x
cmp #'r'
bne jerr
ldx #6
jsr asctobyte
sta MONH ; Maybe we'll find a better place
inx
jsr asctobyte
sta MONL
nextbyte:
inx
lda kb_buffer,x
cmp #' '
beq nextbyte
cmp '.'
beq nextbyte
cmp ','
beq nextbyte
cmp '$'
beq nextbyte
cmp #$0a
beq exitwrite
stbyte:
jsr asctobyte
iny
sta (MONL),y
jmp nextbyte
exitwrite:
; inc kb_rptr
; jmp newmon ; Previous behavior
jsr PRIMM
.asciiz "\nWrote "
iny
tya
jsr printbyte
jsr PRIMM
.asciiz " bytes. Press F1 to enter monitor\n"
jmp eom
jread:
inx
lda kb_buffer,x
cmp #'u'
beq run
cmp #'e'
bne err
ldx #5
jsr asctobyte
sta MONH
inx
jsr asctobyte
sta MONL
; inc kb_rptr
; jmp newmon
jsr PRIMM
.asciiz "\nRead:\n"
reread:
lda CRSRPNT
and #%11000000 ; keep only section bits
ora #LINESTART ;
sta CRSRPNT
ldy #0
sty kb_rptr
sty kb_wptr
lda (MONL),y
jsr printbyte
jsr checkkeyboard
beq reread
jsr PRIMM
.asciiz "\nPress F1 to enter monitor\n"
jmp eom
err:
lda CRSRPNT
jsr crnl
sta CRSRPNT
bcc clkbptr
inc CRSRPNT2
lda (CRSRPNT),y
sta CRSRCHR
clkbptr:
; Clear keyboard pointers if this is the end of message
inc kb_rptr
lda kb_rptr
cmp kb_wptr
bne notdone
eom:
; lda (CRSRPNT),y ; Save new char under cursor ; Here or in err:?
; sta CRSRCHR
lda #0
sta kb_rptr
sta kb_wptr
notdone:
jmp main
run:
jmp (USERLANDP)
esc_pressed:
jsr clrscn
lda #SCREENSTARTL
sta CRSRPNT
lda #SCREENSTARTH
sta CRSRPNT2
jmp clkbptr
backspace_pressed:
jsr rubout
jmp main
f1_pressed:
lda #0
sta kb_rptr
sta kb_wptr
jsr clrscn
jmp monmon
f2_pressed:
lda #$10
sta SVPH
lda #$01
sta SHB
lda #0
sta SVP
sta SLB
inc SLB
jsr savetotape
jmp eom
f3_pressed:
.ifdef BASIC
lda #>RAMSTART2
sta SVPH
lda #<RAMSTART2
sta SVP
.endif
jsr loadfromtape
jmp eom
f4_pressed:
.ifdef BASIC
jsr clrscn
lda #0
sta kb_rptr
sta kb_wptr
lda #SCREENSTARTH
sta CRSRPNT+1
lda #SCREENSTARTL
sta CRSRPNT
jmp COLD_START
.endif
jmp eom
f5_pressed:
;jsr rf_nop
jmp run
f6_pressed:
;jsr readrf24regs
;jsr PRIMM
;.asciiz "Read RF24 configuration!"
;jsr newline
jmp eom
f7_pressed:
jsr resetkb
jmp eom
f8_pressed:
jmp reset
newmon:
jsr clrscn
monmon:
lda #29
sta MONCNT
lda MONH
pha
lda MONL
pha
jsr mon
pla
sta MONL
pla
sta MONH
jsr checkkeyboard
beq monmon
parsekey:
lda kb_buffer,x
inc kb_rptr
cmp #ESC_KEY ; escape - exit
beq exitmon
cmp #PGUP_KEY
beq monpgup
cmp #PGDN_KEY
beq monpgdn
cmp #UP_ARR_KEY
beq monup
cmp #DN_ARR_KEY
beq mondn
jsr checkkeyboard
bne parsekey
; Let's loop here until keypress
jmp monmon ; No data - restart monitor
mondn: ; Arrow keys invert the natural direction because pressing down naturally means you want to see another line
clc
lda MONL
adc #$08
sta MONL
bcc monmon
inc MONH
jmp monmon
monup: ; Pressing up means you want to see a line higher up == lower
sec
lda MONL
sbc #$08
sta MONL
bcs monmon
dec MONH
jmp monmon
monpgdn:
clc
lda MONL
adc #$D8
sta MONL
bcc monmon
inc MONH
jmp monmon
monpgup:
sec
lda MONL
sbc #$D8
sta MONL
bcs monmon
dec MONH
jmp monmon
exitmon:
jsr clrscn ; Clear screen on monitor exit
lda #SCREENSTARTL
sta CRSRPNT
lda #SCREENSTARTH
sta CRSRPNT2
jmp eom
; lda #0
; sta MILLISH
asctohex:
cmp #$60
bcc caps
sbc #$21
caps:
sbc #'0'-1
cmp #10
bcc nothex
sbc #7
nothex:
rts
checkcursor:
bit MILLIS
bmi isneg
lda kb_flags
and #$7f
sta kb_flags ; Reset flip
bne skippedcursor ; BRA
isneg:
bit kb_flags ; Same as last?
bpl flip
bmi skippedcursor ; We already flipped
flip:
ldy #0
lda kb_flags
eor #CRSR
ora #CRSRF ; Set flip bit
sta kb_flags
bit kb_flags
bvs cursoroff
cursoron:
lda #'_'
sta (CRSRPNT),y
bne cursordone ; BRA
cursoroff:
lda CRSRCHR
sta (CRSRPNT),y
cursordone:
skippedcursor:
rts
MONRDKEY:
sty TMP4
stx TMP3 ; X to TMP3
chkkb:
jsr checkcursor
jsr checkkeyboard
beq chkkb ; We can either block here or return $06 = ACK
lda kb_buffer, x
inc kb_rptr
; cmp #$08
; bne notback
; lda #$5F ; OSI basic thinks _ is rubout. Fall through.
; notback:
cmp #$0A
bne nonewline
lda #$0D ; NL to CR
nonewline:
ldy TMP4
ldx TMP3
rts
.ifdef BASIC
MONISCNTC:
sty TMP4
stx TMP3 ; X to TMP3
jsr checkkeyboard
beq NOTCNTC
lda kb_buffer, x
inc kb_rptr
cmp #'^'
bne NOTCNTC
lda kb_flags
and #ECODE
beq NOTCNTC ; If strangely not actually holding CTRL or other extended key
ldy TMP4
ldx TMP3
sec
;jmp STOP
jmp CONTROL_C_TYPED
NOTCNTC:
ldy TMP4
ldx TMP3
clc
rts
bell:
lda #$02
sta CTRL
jsr simpledelay
lda #1
sta CTRL
bne donerubout
MONCOUT:
cmp #0
beq skipcout
sty TMP4
stx TMP3 ; X to TMP3
pha
lda kb_flags
ora #CRSRF ; Set flip bit
sta kb_flags
ldy #0
lda #0
sta (CRSRPNT),y
pla
cmp #7
beq bell
cmp #$0D
bne notcr
jmp donerubout
notcr:
cmp #$08
bne notrubout
lda #' '
sta (CRSRPNT),y
jsr normcrsr ; Backspace
dec kb_rptr
jmp donerubout
notrubout:
jsr printk
donerubout:
ldy TMP4
ldx TMP3
skipcout:
rts
.endif
clrscn:
lda #0
sta CRSRPNT
lda #SCREENSTARTH ; Clear before screen to after screen