-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcmd.inc
2703 lines (2244 loc) · 54.7 KB
/
cmd.inc
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
;*******************************************************************************
;Copyright 2022-2024, Stefan Jakobsson
;
;Redistribution and use in source and binary forms, with or without modification,
;are permitted provided that the following conditions are met:
;
;1. Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
;
;2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
;AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
;FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;*******************************************************************************
;******************************************************************************
;Function name.......: cmd_init
;Purpose.............: Init commands
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: None
.proc cmd_init
;Set tab width
lda #4
sta keyboard_tabwidth
;Set auto indent = off
stz cmd_auto_indent_status
;Set word wrap = off
stz cmd_wordwrap_mode
lda #80
sta cmd_wordwrap_pos
rts
.endproc
;******************************************************************************
;Function name.......: cmd_insert
;Purpose.............: Inserts one char at cursor position and moves the cursor
; one step right. Does not refresh screen; users of this
; procedure are responsible to do screen refresh when done
;Input...............: A = Char to insert
;Returns.............: Nothing
;Error returns.......: C=1 if a line feed char was inserted, either directly
; or by the word wrap function
.proc cmd_insert
;Is linefeed char?
cmp #LF
bne :+
jmp cmd_insert_lf
;Store char in mem
: jsr mem_insert
bcs mem_full
;Increase current columm index
jsr mem_cur_col_inc
;Move cursor one step right
jsr cursor_move_right
bcc wrap
;Carry set, cursor at rightmost position, need to scroll
jsr mem_lnv_step_right
wrap:
;Word wrap enabled?
lda cmd_wordwrap_mode
beq exit ;Word wrap mode off, we're done
jmp cmd_word_wrap
exit:
clc
rts
mem_full:
jsr cmd_mem_full_msg
clc
rts
.endproc
;******************************************************************************
;Function name.......: cmd_word_wrap
;Purpose.............: If cursor is at set right margin, inserts a line break
; to wrap the current line at the previous blank space.
; If no blank space on the line, wraps at the right
; margin.
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: C=1 if a line feed char was inserted
.proc cmd_word_wrap
;Check if we're at the column where to wrap the line
lda mem_cur_col+2
ora mem_cur_col+1
bne nowrap
lda mem_cur_col
cmp cmd_wordwrap_pos
beq wrap
nowrap:
clc
rts
wrap:
;Backup pointers on stack
lda CRS_BNK
pha
lda CRS_ADR+1
pha
lda CRS_IDX
pha
;Goto prev space
jsr mem_crs_move_to_prev_blankspace
bcs bs_not_found
bs_found:
stx prevblank
sty prevblank+1
jsr cmd_insert_lf
wrap_step_back:
lda prevblank
bne :+
lda prevblank+1
beq wrap_done
: jsr cmd_go_right
lda prevblank
bne :+
dec prevblank+1
: dec prevblank
bra wrap_step_back
wrap_done:
;Restore stack
pla
pla
pla
;Return value
sec
rts
bs_not_found:
;Restore pointers
pla
sta CRS_IDX
pla
sta CRS_ADR+1
pla
sta CRS_BNK
;Insert LF
jsr cmd_insert_lf
;Return value
sec
rts
.segment "VARS"
prevblank: .res 2
.CODE
.endproc
;******************************************************************************
;Function name.......: cmd_justify
;Purpose.............: Prompts the user to confirm buffer justify
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: None
.proc cmd_justify
jsr cursor_disable
ldx #<msg
ldy #>msg
jsr screen_print_status
lda #21
sta APP_MOD
rts
msg:
.byt "justify buffer? (y/n)",0
.endproc
;******************************************************************************
;Function name.......: cmd_do_justify
;Purpose.............: Recalculates line wrapping for the whole buffer. Lines are
; wrapped at the column set by the line wrap feature.
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: None
.proc cmd_do_justify
;The buffer is rewrapped in the following two steps:
;1. Remove all line feeds within paragraphs, hereinafter referred to as "merge"
;2. Break each paragraph into lines of selected length, hereinafter referred to as "split"
;Merge all paragraphs by removing line feeds within them
merge:
jsr cmd_go_start
jsr setup
merge_loop:
jsr get_char ;Fetch next char
bcc :+
jmp split
: lda stream_lf ;Char=LF?
and #%00000001
beq :++
ldx #FLAG_NOT_FIRST_LINE
lda flags
and #FLAG_CONTENT_FOUND
beq :+
ldx #FLAG_NOT_FIRST_LINE+FLAG_EMPTY_PREV_LINE
: stx flags
lda indent
sta indent_prev
stz indent
bra merge_loop
: lda stream_lf ;After double LF? Keep line break, treated as new paragraph
and #%00000110
cmp #%00000110
beq merge_loop
lda cmd_auto_indent_status
bne merge_ai_on
lda stream_lf ;After single LF?
and #%00000010
beq merge_loop ;No, keep lookin'
lda stream_bs ;Line starts with blank space: Keep line break, treated as new paragraph
and #%00000001
bne merge_loop
merge_del:
jsr mem_delete ;Delete line break
bcs :+
cpx #1
bne merge_del
: jsr mem_crs_step_left ;Check if previous line ended with a blank space
lda #5
sta CRS_ADR
lda CRS_BNK
sta BNK_SEL
ldy CRS_IDX
lda (CRS_ADR),y
stz CRS_ADR
cmp #32
beq :+
jsr mem_crs_step_right
lda #32 ;It didn't, need to insert blank space
jsr mem_insert
bra merge_loop
: jsr mem_crs_step_right
bra merge_loop
merge_ai_on:
lda flags ;Content (other than blank spaces) previously found on this line?
and #FLAG_CONTENT_FOUND
bne merge_loop
lda stream_bs ;No. Char=Blank space?
and #%00000001
beq :+
inc indent
jmp merge_loop
: lda flags ;No, set content found now
ora #FLAG_CONTENT_FOUND
sta flags
lda flags
and #FLAG_NOT_FIRST_LINE
bne :+
jmp merge_loop
: lda indent ;Same level of indent as previous line?
cmp indent_prev
beq :+
jmp merge_loop ;No, keep line break, treated as new paragraph
: lda flags
and #FLAG_EMPTY_PREV_LINE
bne merge_del
jmp merge_loop
;Split paragraphs into lines of the selected length
split:
jsr cmd_go_start
jsr setup
split_loop:
jsr get_char ;Fetch char
bcc :+
jmp eof
: lda stream_lf ;Char=LF?
and #%00000001
beq :+
jsr mem_cur_col_ret
stz flags
stz indent
bra split_loop
: lda stream_bs
and #%00000001
beq :+
lda flags
and #FLAG_CONTENT_FOUND
bne :++
inc indent
bra :++
: lda flags
ora #FLAG_CONTENT_FOUND
sta flags
lda stream_bs ;At word boundary?
and #%00000011
cmp #%00000010
bne :+
lda CRS_BNK
sta word_boundary
lda CRS_ADR+1
sta word_boundary+1
lda CRS_IDX
sta word_boundary+2
lda flags
ora #FLAG_WORD_BOUNDARY
sta flags
: lda cmd_wordwrap_pos ;Beyond wrap column?
cmp mem_cur_col
bcs split_loop
lda flags ;Yes, split
and #FLAG_WORD_BOUNDARY
beq split_loop ;No word boundary found, keep lookin'
lda word_boundary
sta CRS_BNK
lda word_boundary+1
sta CRS_ADR+1
lda word_boundary+2
sta CRS_IDX
lda #LF
jsr mem_insert
jsr mem_cur_col_ret
lda cmd_auto_indent_status
beq :++
lda indent
sta indent_prev
: lda indent_prev
beq :+
lda #32
jsr mem_insert
jsr mem_cur_col_inc
dec indent_prev
bra :-
: stz stream_lf
stz stream_bs
lda #FLAG_CONTENT_FOUND
sta flags
jmp split_loop
eof:
jsr cmd_go_start
jmp screen_refresh
get_char:
jsr mem_crs_step_right
bcc :+
rts
: jsr mem_cur_col_inc
lda CRS_BNK ;Get char
sta BNK_SEL
lda #5
sta CRS_ADR
ldy CRS_IDX
lda (CRS_ADR),y
stz CRS_ADR
cmp #LF ;If char=LF
bne :+
sec
rol stream_lf
clc
rol stream_bs
clc
rts
: cmp #32 ;If char=blank space
bne :+
clc
rol stream_lf
sec
rol stream_bs
clc
rts
: clc ;Else
rol stream_lf
clc
rol stream_bs
clc
rts
setup:
stz flags
stz stream_lf
stz stream_bs
stz indent
rts
.segment "VARS"
flags: .res 1
stream_lf: .res 1
stream_bs: .res 1
indent: .res 1
indent_prev: .res 1
word_boundary: .res 3
.CODE
FLAG_CONTENT_FOUND = %10000000
FLAG_WORD_BOUNDARY = %01000000
FLAG_NOT_FIRST_LINE = %00100000
FLAG_EMPTY_PREV_LINE = %00010000
.endproc
;******************************************************************************
;Function name.......: cmd_insert_lf
;Purpose.............: Inserts line break char at cursor position and moves the
; cursor one step right. Does not refresh screen; users of
; this procedure are responsible to do screen refresh when
; done
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: C=1 if a line feed char was inserted
.proc cmd_insert_lf
;Is auto indent on?
lda cmd_auto_indent_status
beq linefeed_store ;No, continue storing the line feed in buffer
;Backup mem pointer on stack
lda CRS_BNK
pha
lda CRS_ADR+1
pha
lda CRS_IDX
pha
;Goto line start
jsr mem_crs_move_to_line_start
stx counter1
sty counter1+1
sta counter1+2
stz counter2
stz counter2+1
stz counter2+2
auto_indent_loop:
;Count leading blank spaces on the line
lda counter1+2
cmp counter2+2
bne :+
lda counter1+1
cmp counter2+1
bne :+
lda counter1
cmp counter2
beq auto_indent_stop
: lda CRS_BNK
sta BNK_SEL
lda #5
sta CRS_ADR
ldy CRS_IDX
lda (CRS_ADR),y
stz CRS_ADR
cmp #32
bne auto_indent_stop
jsr mem_crs_step_right
inc counter2
bne auto_indent_loop
inc counter2+1
bne auto_indent_loop
inc counter2+2
bra auto_indent_loop
auto_indent_stop:
;Restore mem pointer from stack
pla
sta CRS_IDX
pla
sta CRS_ADR+1
pla
sta CRS_BNK
linefeed_store:
;Store char in mem
lda #LF
jsr mem_insert
bcs mem_full
;Set line and column index
jsr mem_cur_col_ret
jsr mem_cur_line_inc
;Move cursor to first column of next row
jsr cursor_move_crlf
bcc :+
;C=1: We're at bottom of screen, need to scroll
jsr mem_scr_move_down
: jsr mem_cp_crs_lnv ;Set first visible char of line to cursor position, i.e. start of line
;If auto indent on, insert blank spaces
lda cmd_auto_indent_status
beq linefeed_exit
auto_indent_insert_blanks:
lda counter2
bne :+
lda counter2+1
bne :+
lda counter2+2
beq linefeed_exit
: lda #32
jsr cmd_insert
lda counter2
bne :++
lda counter2+1
bne :+
dec counter2+2
: dec counter2+1
: dec counter2
bra auto_indent_insert_blanks
linefeed_exit:
sec
rts
mem_full:
jsr cmd_mem_full_msg
clc
rts
.segment "VARS"
counter1: .res 3
counter2: .res 3
.CODE
.endproc
;******************************************************************************
;Function name.......: cmd_mem_full_msg
;Purpose.............: Shows memory full status message
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: Nothing
.proc cmd_mem_full_msg
ldx #<msg
ldy #>msg
lda #2
sta APP_MOD
jsr screen_print_status
rts
msg:
.byt "memory full", 0
.endproc
;******************************************************************************
;Function name.......: cmd_insert_tab
;Purpose.............: Inserts blank spaces until we reach next tab stop
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: Nothing
.proc cmd_insert_tab
;Save selection status on stack
lda selection_active
pha
;Hide cursor
jsr cursor_disable
;Get distance to next tab stop
jsr cmd_next_tab_stop
stx mod
;Insert calculated number of blanks
: lda #32
jsr cmd_insert
dec mod
bne :-
;Refresh
pla
beq :+
jsr screen_refresh
: jsr screen_println
jmp cursor_activate
.segment "VARS"
mod: .res 1
.CODE
.endproc
;******************************************************************************
;Function name.......: cmd_next_tab_stop
;Purpose.............: Calculates distance to next tab stop
;Input...............: Nothing
;Returns.............: X = distance
;Error returns.......: Nothing
.proc cmd_next_tab_stop
;Distance to next tab stop = T - ((X - 1) mod T))
;where X is current column number, and
; T is tab stop width
;Init
stz mod
sec
lda mem_cur_col
sbc #1
sta col
lda mem_cur_col+1
sbc #0
sta col+1
lda mem_cur_col+2
sbc #0
sta col+2
;Calculate: (X -1) mod T
ldx #24 ;Number of bits in column number
fetch_bit:
asl col
rol col+1
rol col+2
rol mod
subtract:
sec
lda mod
: tay ;Subtract tab width until underflow
sbc keyboard_tabwidth
bcs :-
sty mod
dex
bne fetch_bit
;Calculate T - ((X - 1) mod T))
sec
lda keyboard_tabwidth
sbc mod
tax
rts
col = tempvars ;3 bytes
mod = tempvars + 3 ;1 byte
.endproc
;******************************************************************************
;Function name.......: cmd_delete
;Purpose.............: Moves the cursor one step left and deletes that char
; Does not refresh screen; users of this procedure are
; responsible to do screen refresh when done
;Input...............: Nothing
;Returns.............: C=1 if at start of file, else C=0
; X=1 if a line feed was deleted, else X=0
;Error returns.......: None
.proc cmd_delete
;Check if cursor is within selection, if so delete the selection
lda selection_active ;Skip if no selection is active
beq :+
lda mem_cur_col
sta screen_print_col
lda mem_cur_col+1
sta screen_print_col+1
lda mem_cur_col+2
sta screen_print_col+2
lda mem_cur_line
sta screen_print_line
lda mem_cur_line+1
sta screen_print_line+1
lda mem_cur_line+2
sta screen_print_line+2
jsr selection_char_count ;Use selection character count function to decide if we're in a selection
cpx #0 ;X != 0 => The cursor is standing at an unselected char, skip
bne :+
cpy #0 ;Y == 0 => The cursor is standing at an unselected char, skip
beq :+
jmp selection_delete
;Delete one char from memory
: jsr mem_delete
bcc char_deleted ;C=1: We're at start of file, nothing was deleted
rts
;Check if we deleted a line break (indicated by X=1), a special case to handle
char_deleted:
cpx #1
beq linebreak_deleted
;We did not delete a line break, decrease column index, move cursor one column left and print line
jsr mem_cur_col_dec
jsr cursor_move_left
bcc exit
jsr mem_lnv_step_left
exit:
clc
ldx #0
rts
linebreak_deleted:
;Move cursor the beginning of line above the current line
stz CRS_X
jsr cursor_move_up
bcc :+
;Carry set, we're at top of screen and need to scroll vertically
jsr mem_scr_move_up
: ;Move to line start, and save the number of chars moved over
jsr mem_crs_move_to_line_start
stx counter
sty counter+1
sta counter+2
;Set first visible char of that line to start of line (cursor position)
jsr mem_cp_crs_lnv
;Set line and column index
jsr mem_cur_col_ret
jsr mem_cur_line_dec
;Loop to move the cursor back to the column we came from
loop:
lda counter
bne :+
lda counter+1
bne :+
lda counter+2
beq linebreak_deleted_exit
: jsr mem_crs_step_right
bcs linebreak_deleted_exit
jsr mem_cur_col_inc
jsr cursor_move_right
bcc continue
;C=1: We need to scroll horizontally
jsr mem_lnv_step_right
continue:
;Decrease column counter
lda counter
bne :++
lda counter+1
bne :+
dec counter+2
: dec counter+1
: dec counter
bra loop
linebreak_deleted_exit:
clc
ldx #1
rts
.segment "VARS"
counter: .res 3
.CODE
.endproc
;******************************************************************************
;Function name.......: cmd_go_start
;Purpose.............: Moves cursor to start of buffer
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: None
.proc cmd_go_start
;Set bank
lda mem_start
ina ;The head of buffer is the bank after mem_start (mem_start used for internal data storage)
sta BNK_SEL
sta CRS_BNK ;Cursor
sta LNV_BNK ;Line first visible char
sta SCR_BNK ;Screen first visible char
;Set address
lda #$a0
sta CRS_ADR+1 ;Cursor
sta LNV_ADR+1 ;Line first visible char
sta SCR_ADR+1 ;Screen first visible char
stz CRS_ADR ;Cursor
stz LNV_ADR ;Line first visible char
stz SCR_ADR ;Screen first visible char
;Set memory offset values
stz CRS_IDX ;Cursor
stz LNV_IDX ;Line first visible char
stz SCR_IDX ;Screen first visible char
;Set column and line
lda #1
sta mem_cur_col
stz mem_cur_col+1
stz mem_cur_col+2
sta mem_cur_line
stz mem_cur_line+1
stz mem_cur_line+2
;Move cursor
ldx #0
ldy #2
jsr cursor_move
rts
.endproc
;******************************************************************************
;Function name.......: cmd_go_left
;Purpose.............: Moves all mem pointers and cursor one step left. Does
; not refresh screen; users of this procedure are
; responsible to do screen refresh when done
;Input...............: Nothing
;Returns.............: C=1 if line changed, else C=0
;Error returns.......: None
.proc cmd_go_left
;Move mem pointer one step left, if C set we are at start of file, if X=1 we moved to line above
jsr mem_crs_step_left
bcs at_filestart
cpx #1
beq at_linebreak
;Decrease current column index
jsr mem_cur_col_dec
;Move cursor left, if C set we are at leftmost screen position, but not start of line (need to scroll)
jsr cursor_move_left
bcs at_leftmost
clc
rts
at_leftmost:
;Cursor at leftmost screen position (but not start of line), scroll the line
jsr mem_lnv_step_left
clc
rts
at_linebreak:
;Goto start of line
jsr mem_crs_move_to_line_start
;Also set first visible char to start of line
jsr mem_cp_crs_lnv
;Set line and column index
jsr mem_cur_col_ret
jsr mem_cur_line_dec
;Move cursor up one row to start of that row
stz CRS_X
jsr cursor_move_up
bcc :+
;C=1, we're at top of screen, need to scroll
jsr mem_scr_move_up
;Use existing function to go to end of line
: jsr keyboard_end_key
sec
rts
at_filestart:
;We are at start of file, nothing to do
clc
rts
.endproc
;******************************************************************************
;Function name.......: cmd_go_right
;Purpose.............: Moves all mem pointers and cursor one step right. Does
; not refresh screen; users of this procedure are
; responsible to do screen refresh when done
;Input...............: Nothing
;Returns.............: C=1 if line changed, else C=0
; X=1 if at EOF, else X=0
;Error returns.......: None
.proc cmd_go_right
;Move mem pointer one step right, carry set if at end of file, X=1 if at end of line
jsr mem_crs_step_right
bcs at_eof
cpx #1
beq at_eol
;Increase current column index
jsr mem_cur_col_inc
;Move cursor one step right
jsr cursor_move_right
bcs at_rightmost
clc
ldx #0
rts
at_rightmost:
;Cursor at rightmost position but not end of line, need to scroll
jsr mem_lnv_step_right
clc
ldx #0
rts
at_eof:
;End of file, do nothing
clc
ldx #1
rts
at_eol:
;Set current line and column to start of next row
jsr mem_cur_col_ret
jsr mem_cur_line_inc
;End of line, move cursor to start of next line, C=1 if at bottom of screen
jsr cursor_move_crlf
bcs at_bottom
jsr mem_cp_crs_lnv ;Set first visible char to cursor, i.e. start of line
sec
ldx #0
rts
at_bottom:
;Cursor at bottom of screen, but not end of file, need to scroll
jsr mem_cp_crs_lnv
jsr mem_scr_move_down
sec
ldx #0
rts
.endproc
;******************************************************************************
;Function name.......: cmd_go_up
;Purpose.............: Moves mem pointers and cursor one step up. Does not
; refresh screen; users of this procedure are responsible
; to do screen refresh
;Input...............: Nothing