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
|
.org $1000
tok:
.byte "dab"
msg:
.byte "oof, you divided a, and b on me.\n"
.org $2000
buffer:
.org $4000
cmd_buf:
.org $0
scr_row:
.byte $0
scr_col:
.byte $0
scr_trow:
.byte $0
scr_tcol:
.byte $0
scr_ptr:
.word $0
a:
.byte $0
b:
.byte $0
c:
.byte $0
d:
.byte $0
e:
.byte $0
f:
.byte $0
string:
.byte "Please, type something.\n"
string2:
.byte "You typed, "
end:
.byte $0
bits:
.byte $80
.byte $40
.byte $20
.byte $10
.byte $08
.byte $04
.byte $02
.byte $01
bitmask:
.byte $0
bitabl:
.qword $0
.qword $0
scr_str:
.byte $0
scr_end:
.byte $0
wrapped:
.byte $0
ptr:
.qword buffer
cptr:
.qword cmd_buf
tptr:
.qword tok
mptr:
.qword msg
.org $8000
reset:
cps
ldx.w
txs
ldy
lda
sta scr_end
lda
sta scr_str
ldx
sta.q bitabl
sta.q bitabl, x
tax
jsl clr_buf
jmp start
clr_buf:
lda
cpy.w
beq clr_buf_end
sta (ptr), y
iny
jmp clr_buf
clr_buf_end:
ldy.w
rtl
start:
lda
tax
sta $C000
phy
ldy.w
jsl clr_cbuf
ply
jmp print
clr_cbuf:
cpy.w
beq clr_cbuf_end
sta (cptr), y
iny
jmp clr_cbuf
clr_cbuf_end:
rtl
pull_y:
ply
rset_a:
lda
sta $C000
inc
read:
lda $C000
beq rset_a
jsl getchar
beq parse
jmp rset_a
print:
phy
txy
lda string, y
beq pull_y
ply
inx
jsl print_char
jmp print
getbit:
clc
lda scr_str
bne getbt0
ldx scr_row
jmp getbt1
getbt0:
lda scr_row
adc scr_str
tax
getbt1:
jsl bitpos
ldb bitabl, x
aba
cmp
jmp bitout
clrbit:
jsl bitpos
xor
ldb bitabl, x
aba
bitsav:
sta bitabl, x
bitout:
ldx bitmask
rtl
setbit:
jsl bitpos
ldb bitabl, x
oab
jmp bitsav
bitpos:
stx bitmask
txa
and
tax
lda bits, x
pha
lda bitmask
lsr
tax
pla
rtl
getchar:
lda $C002
ldb
stb e
pha
phy
cmp
beq cmd_cpy
getchar_pnt:
ply
pla
ldb e
bne reset_row
getchar_pnt1:
jsl print_char
lda a
cmp
beq getchar_line
jmp getchar_char
reset_row:
ldb e
stb scr_row
jmp getchar_pnt1
cmd_cpy:
ldb scr_row
stb e
jsl findst
clc
lda scr_row
adc scr_str
mul
tay
ldx.w
cmd_cpy_strt:
lda (ptr), y
beq getchar_pnt
phy
txy
sta (cptr), y
inx
ply
iny
jmp cmd_cpy_strt
getchar_line:
lda
jmp getchar_end
getchar_char:
lda
getchar_end:
rtl
findst:
jsl getbit
bcc findst_done
dec scr_row
bpo findst
inc scr_row
findst_done:
rtl
parse:
lda
tax
jsl dabbed
beq start
lda
tax
jmp result
print_char:
sta a
cmp
beq esc
cmp
beq nl
cmp
beq clr_scr
cmp
beq en_step
cmp
beq dis_step
cmp
beq bs
cmp
beq bs
sta a
printc:
lda a
sta (ptr), y
inc scr_col
iny
printc_2:
ldb
stb f
ldb scr_col
cpb
bcs printc_4
printc_3:
sta $C001
ldb f
beq printc_wrap
jmp printc_end
printc_4:
ldb scr_row
cpb
bcs printc_scrl
printc_5:
ldb
stb f
jmp printc_3
printc_scrl:
sta $C001
clc
lda
sta wrapped
jsl scrl_down
printc_wrap:
ldb
stb scr_col
ldb scr_row
cpb
bcs printc_wrap2
printc_wrap1:
inc scr_row
printc_wrap2:
phx
clc
lda scr_row
adc scr_str
tax
jsl setbit
plx
jsl update_pos
printc_end:
rtl
nl:
lda
sta (ptr), y
sta scr_col
lda scr_row
cmp
bne nl_inc
jsl scrl_down
lda
sta a
jmp printc_end
nl_inc:
inc scr_row
jsl update_pos
lda
sta a
jmp printc_end
clr_scr:
lda
sta scr_end
lda
sta scr_str
ldx
sta.q bitabl
sta.q bitabl, x
tay
jsl clr_buf
sta scr_col
sta scr_row
jsl update_pos
lda
sta $C001
jmp printc_end
en_step:
lda $C010
beq step_en
jmp stp_end
step_en:
lda
sta $C010
jmp stp_end
dis_step:
lda $C010
bne step_dis
jmp stp_end
step_dis:
lda
sta $C010
stp_end:
jmp printc_end
back:
lda
sta $C001
dey
lda
sta (ptr), y
dec scr_col
jsl update_pos
jmp printc_end
bs:
lda scr_col
beq back_wrap
jmp back
back_wrap:
jsl getbit
bcs back_wrap1
jmp printc_end
back_wrap1:
lda scr_row
beq back_wrap2
jmp backwrp
back_wrap2:
lda scr_str
bne back_scrl
jmp printc_end
back_scrl:
clc
jsl scrl_up
inc scr_row
backwrp:
clc
lda scr_row
adc scr_str
tax
backwrp2:
dec scr_row
jsl clrbit
ldb
stb scr_col
jsl update_pos
jmp back
esc:
lda $C000
lda $C002
cmp
beq shftesc
lda $C000
beq printc_end
lda $C002
sta c
lda
sta d
jsl isup
lda d
bne esc_end
jsl isdown
lda d
bne esc_end
lda
jsl isleft
lda d
bne esc_end
jsl isright
esc_end:
lda
sta d
jmp printc_end
shftesc:
lda $C000
lda $C000
beq printc_end
lda $C002
sta c
lda
sta d
jsl isshftup
lda d
bne shftesc_end
jsl isshftdown
shftesc_end:
lda
sta d
jmp printc_end
isup:
lda c
cmp
bne isup_done
lda
sta d
lda scr_row
beq isup_scrl
isup_2:
lda c
cmp
beq up
jmp isup_done
isup_scrl:
lda scr_str
beq isup_done
jsl scrl_up
isup_done:
rtl
isdown:
lda c
cmp
bne isdown_done
lda scr_row
cmp
beq isdown_scrl
lda c
cmp
beq down
jmp isdown_done
isdown_scrl:
lda scr_row
sta scr_trow
lda scr_col
sta scr_tcol
jsl scrl_down
lda scr_trow
sta scr_row
lda scr_tcol
sta scr_col
isdown_done:
rtl
isright:
lda c
cmp
bne isright_done
lda scr_col
cmp
beq isright_wrp
jmp right
isright_wrp:
inc scr_row
jsl getbit
bcs wrap_inc
dec scr_row
jmp isright_done
isright_scrl:
lda scr_str
beq isright_end
lda
sta wrapped
jsl scrl_down
dec scr_row
jmp isright_end
wrap_inc:
lda
sta scr_col
lda scr_row
cmp
bcs isright_scrl
isright_end:
jsl update_pos
isright_done:
lda
sta wrapped
rtl
isleft:
lda c
cmp
beq isleft_done
lda scr_col
beq isleft_wrp
lda c
cmp
beq left
jmp isleft_done
isleft_wrp:
jsl getbit
bcs wrap_dec
jmp isleft_done
wrap_dec:
lda scr_row
beq wrap_dec1
lda
sta wrapped
dec scr_row
wrap_dec1:
lda
sta scr_col
lda
sta d
lda scr_row
beq isleft_scrl
jmp isleft_end
isleft_scrl:
lda wrapped
bne isleft_end
lda scr_str
beq isleft_done
jsl scrl_up
jmp isleft_done
isleft_end:
jsl update_pos
isleft_done:
lda
sta wrapped
rtl
up:
dec scr_row
jsl update_pos
lda
sta d
jmp isup_done
down:
inc scr_row
jsl update_pos
lda
sta d
jmp isdown_done
right:
inc scr_col
jsl update_pos
jmp isright_done
left:
dec scr_col
jsl update_pos
lda
sta d
jmp isleft_done
isshftup:
lda c
cmp
bne isshftup_done
lda
sta d
lda scr_str
beq isshftup_done
jmp shftup
isshftup_done:
rtl
isshftdown:
lda c
cmp
bne isshftdown_done
lda
sta d
lda scr_end
cmp
bcs isshftdown_done
jmp shftdown
isshftdown_done:
rtl
shftup:
jsl scrl_up
lda
sta d
jmp isshftup_done
shftdown:
jsl scrl_down
lda
sta d
jmp isshftdown_done
update_pos:
ldb
stb f
clc
lda scr_row
adc scr_str
clc
mul
clc
adc scr_col
tay
lda
sta $C001
lda
sta $C001
jsl getrow
jsl getcol
lda
sta $C001
rtl
getrow:
lda scr_row
div
adc
sta $C001
tba
adc
sta $C001
rtl
getcol:
lda
sta $C001
lda scr_col
div
clc
adc
sta $C001
tba
clc
adc
sta $C001
rtl
scrl_down:
inc scr_str
inc scr_end
lda
sta $C001
lda
sta $C001
lda
sta $C001
lda wrapped
beq scrldn_save
scrldn1:
jsl rdrw_row
lda wrapped
beq scrldn_load
jmp scrldn_end
scrldn_save:
lda scr_row
pha
lda scr_col
pha
jmp scrldn1
scrldn_load:
pla
sta scr_col
pla
sta scr_row
jsl update_pos
scrldn_end:
lda
sta wrapped
scrldn_done:
rtl
scrl_up:
dec scr_str
dec scr_end
lda
sta $C001
lda
sta $C001
lda
sta $C001
lda scr_row
pha
lda scr_col
pha
lda
sta scr_row
jsl rdrw_row
pla
sta scr_col
pla
sta scr_row
jsl update_pos
scrlup_done:
rtl
rdrw_row:
lda
sta scr_col
jsl update_pos
rdrow_st:
lda (ptr), y
beq rdrow_inc
sta $C001
rdrow_inc:
inc scr_col
lda (ptr), y
beq rdrow_skip
iny
rdrow_inc1:
lda scr_col
cmp
bcs rdrow_end
jmp rdrow_st
rdrow_skip:
jsl update_pos
jmp rdrow_inc1
rdrow_end:
lda
sta scr_col
jsl update_pos
rdrow_done:
rtl
result:
phy
txy
lda string2, y
beq rset_y
ply
jsl print_char
inx
jmp result
rset_y:
ply
lda
tax
jmp print_buf
dabbed:
phy
txy
lda (cptr), y
beq dab_pend
cmp (tptr), y
bcc dab_pend
beq chk_str
bcs dab_pend
chk_str:
ply
inx
cpx
bne dabbed
ldx
pnt_msg:
phy
txy
lda (mptr), y
beq dab_peqnd
ply
jsl print_char
inx
jmp pnt_msg
dab_pend:
ply
lda
jmp dab_end
dab_peqnd:
ply
lda
jmp dab_end
dab_end:
rtl
print_buf:
phy
txy
lda (cptr), y
beq cmd_clr
ply
jsl print_char
inx
jmp print_buf
cmd_clr:
ply
lda
jsl print_char
jmp start
.org $FFC0
.qword reset
.org $FF50
.qword spin
.qword spin
.qword spin
.qword spin
.qword spin
.qword spin
.qword spin
done
|