-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeyboard.inc
1591 lines (1332 loc) · 36.5 KB
/
keyboard.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.
;*******************************************************************************
;******************************************************************************
;General information on keyboard functions
;---------------------------------------------
;X16 Edit uses a custom PS/2 scan code handler to read status of modifier
;keys. The scan code handler is implemented in source file "scancode.inc".
;
;The status of each modifier key is represented by one bit (1=down, 0=up) in
;variable "scancode_modifiers" as follows:
;
;Bit # Key
;0 SHIFT
;1 ALT
;2 CTRL
;3 WIN
;4 CAPS
;
;The scan code handler consumes Ctrl key events. This means
;that the Kernal GETIN function returns the same result for A and Ctrl+A.
;The only way to know whether the Ctrl key key is pressed is
;to check the value of scancode_modifiers.
keyboard_shortcut_count = 26
;******************************************************************************
;Function name.......: keyboard_init
;Purpose.............: Initiallizes keyboard shortcuts
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_init
;Copy default shortcut table
ldx #0
: lda keyval,x
sta keyboard_ctrl_keyval,x
inx
cpx #keyboard_shortcut_count
bne :-
;Copy config file name to clipboard mem, temporarily used for this purpose during editor setup
lda mem_start
sta BNK_SEL
ldx #config_end-config
: lda config-1,x
sta clipboard_mem-1,x
dex
bne :-
;Read shortcut table from file, if available
bridge_setaddr KERNAL_CLOSE ;Close file #1
lda #1
bridge_call KERNAL_CLOSE
bridge_setaddr KERNAL_SETNAM ;Set file name
ldx #<clipboard_mem
ldy #>clipboard_mem
lda #config_end-config
bridge_call KERNAL_SETNAM
bridge_setaddr KERNAL_SETLFS ;Set file params
lda #1
ldx file_cur_device
ldy #3
bridge_call KERNAL_SETLFS
bridge_setaddr KERNAL_OPEN ;Open file for reading
bridge_call KERNAL_OPEN
bcs err
bridge_setaddr KERNAL_CHKIN ;Set file as input
ldx #1
bridge_call KERNAL_CHKIN
bcs close
ldy #0
loop:
bridge_setaddr KERNAL_CHRIN ;Get byte
bridge_call KERNAL_CHRIN
sta val
bridge_setaddr KERNAL_READST ;Check for EOF or errors
bridge_call KERNAL_READST
bne last
lda val ;Store byte in shortcut list
beq :+ ;Ignore zeros - invalid value
sta keyboard_ctrl_keyval,y
: iny
cpy #keyboard_shortcut_count
bne loop
bra close
last:
and #2 ;Read time out? Will be true if file was not found, then skip saving last value
bne close
lda val
sta keyboard_ctrl_keyval,y
close:
bridge_setaddr KERNAL_CLOSE ;Close file
lda #1
bridge_call KERNAL_CLOSE
bridge_setaddr KERNAL_CLRCHN ;Clear input/output channels
bridge_call KERNAL_CLRCHN
jmp file_read_disk_status
err:
rts
.ifndef alt_shortcuts
keyval: ;List of default shortcut keys
.byt $47, $58, $4f, $52, $4e
.byt $4a, $59, $56, $4b, $43
.byt $55, $19, $57, $53, $4c
.byt $41, $5a, $45, $49, $44
.byt $54, $42, $4d, $46, $0d
.byt $51
.else
keyval:
.byt $50, $57, $53, $4f, $4e
.byt $4a, $55, $59, $58, $43
.byt $56, $4c, $46, $48, $47
.byt $41, $52, $45, $49, $44
.byt $4b, $42, $4d, $00, $0d
.byt $51
.endif
config:
.byt "//:x16editrc"
config_end:
val = tempvars
.endproc
;******************************************************************************
;Function name.......: keyboard_read_and_dispatch
;Purpose.............: Reads one character from the keyboard buffer and
; dispatches that to proper key handler
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_read_and_dispatch
;Read keys
bridge_setaddr KERNAL_GETIN
bridge_call KERNAL_GETIN
bne gotachar
;No input to handle, run memory defrag instead during this interrupt cycle
jmp mem_run_defrag
gotachar:
;Store char in Y temporarily
tay
;Convert ESC key value sent by emulator to real key value - We could hopefully delete this later on
cmp #$03
bne :+
ldy #KEYVAL_ESC
;Calculate index in jump table
: lda APP_MOD
asl
tax
;Restore char in A
tya
;Jump to APP mode event handler
jmp (jmptbl,x)
jmptbl:
.word keyboard_mode_default ;APP mode 0
.word keyboard_mode_helpscreen ;APP mode 1
.word keyboard_mode_statusmessage ;APP mode 2
.word keyboard_mode_command ;APP mode 3
.word keyboard_mode_file_save ;APP mode 4
.word keyboard_mode_file_open ;APP mode 5
.word keyboard_mode_file_save_overwrite ;APP mode 6
.word keyboard_mode_file_open_save_before ;APP mode 7
.word keyboard_mode_exit_save_before ;APP mode 8
.word keyboard_mode_new_buffer_save_before ;APP mode 9
.word keyboard_mode_find ;APP mode 10
.word keyboard_mode_goto_line ;APP mode 11
.word keyboard_mode_replace_0 ;APP mode 12
.word keyboard_mode_replace_1 ;APP mode 13
.word keyboard_mode_replace_2 ;APP mode 14
.word keyboard_mode_word_wrap_prompt ;APP mode 15
.word keyboard_mode_select_encoding ;APP mode 16
.word keyboard_mode_set_device ;APP mode 17
.word keyboard_mode_file_dir ;APP mode 18
.word keyboard_mode_file_dir ;APP mode 19
.word keyboard_mode_dos_cmd ;APP mode 20
.word keyboard_mode_justify ;APP mode 21
.word keyboard_mode_compile ;APP mode 22
.word keyboard_mode_quote ;APP mode 23
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_default
;Purpose.............: Key dispatcher for the default mode, i.e. text entry
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_default
;Check modifier key status
ldx scancode_modifiers
cpx #KBD_MODIFIER_CTRL
beq ctrl
default:
;Hide mouse pointer
ldx #(VERA_SPRITE_ATTR & $ff) + 6
stx VERA_L
ldx #((VERA_SPRITE_ATTR >> 8) & $ff)
stx VERA_M
ldx #((VERA_SPRITE_ATTR >> 16) & $ff)
stx VERA_H
stz VERA_D0
;Search key value table for matches (control keys and other keys requiring special actions)
ldx #default_keyval_end-default_keyval
: cmp default_keyval-1,x
beq default_match
dex
bne :-
;Convert non-breaking space (Shift+space, ASCII 160) to normal space char (ASCII 32)
cmp #KEYVAL_SHIFT_SPACE
bne default_insert
lda #KEYVAL_SPACE
default_insert:
;Save selection status on stack
ldx selection_active
phx
;Insert char into buffer and update screen
jsr cmd_insert
plx
bne :+
bcs :+
jmp screen_println
: jmp screen_refresh
default_match:
;Action for special keys, for example arrow keys and function keys
dex
txa
asl
tax
jmp (default_jmptbl,x)
ctrl:
;Insert non-breaking space if Ctrl+Space
cmp #KEYVAL_SPACE
bne :+
lda #KEYVAL_SHIFT_SPACE
jmp default_insert
;Key 1..9 sets tab width
: cmp #$31
bcc :+
cmp #$3b
bcs :+
sec
sbc #48
jmp cmd_set_tab_width
;Convert lower case letters to upper case
: and #%11011111
;Look for matches in key value table
ldx #keyboard_shortcut_count
: cmp keyboard_ctrl_keyval-1,x
beq ctrl_match
dex
bne :-
;Exit
rts
ctrl_match:
;Action for Ctrl+key combinations
dex
txa
asl
tax
jmp (keyboard_ctrl_jmptbl,x)
default_keyval:
.byt KEYVAL_ESC, KEYVAL_ENTER, KEYVAL_BACKSPACE, KEYVAL_TAB, KEYVAL_LEFT
.byt KEYVAL_RIGHT, KEYVAL_UP, KEYVAL_DOWN, KEYVAL_HOME, KEYVAL_SHIFT_HOME
.byt KEYVAL_F1, KEYVAL_F2, KEYVAL_F3, KEYVAL_F4
.byt KEYVAL_F5, KEYVAL_F6, KEYVAL_F7, KEYVAL_F8
.byt KEYVAL_DELETE, KEYVAL_END, KEYVAL_PGUP, KEYVAL_PGDN
.byt KEYVAL_INSERT
default_keyval_end:
default_jmptbl:
.word keyboard_esc_key, keyboard_enter_key, keyboard_backspace_key, cmd_insert_tab, keyboard_leftarrow_key
.word keyboard_rightarrow_key, keyboard_uparrow_key, keyboard_downarrow_key, keyboard_home_key, keyboard_end_key
.word cmd_show_help, cmd_exit, cmd_file_save_prompt, cmd_justify
.word cmd_file_open_prompt, cmd_find, keyboard_cmd_pageup, keyboard_cmd_pagedown
.word keyboard_delete_key, keyboard_end_key, keyboard_cmd_pageup, keyboard_cmd_pagedown
.word mem_run_defrag ;=Ignore Insert key
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_command
;Purpose.............: Key dispatcher: The user has pressed and released ESC
; and the next key is interpreted as a command
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_command
;1..9
cmp #$31
bcc :+
cmp #$3b
bcs :+
sec
sbc #48
jsr cmd_set_tab_width
stz APP_MOD
jsr screen_clear_status
jmp cursor_activate
;Space, convert to non-breaking space
: cmp #KEYVAL_SPACE
bne :++
stz APP_MOD
jsr cursor_activate
jsr screen_clear_status
lda #KEYVAL_SHIFT_SPACE
ldx selection_active
phx
jsr cmd_insert
plx
bne :+
bcs :+
jmp screen_println
: jmp screen_refresh
;ESC key
: cmp #KEYVAL_ESC
bne :+
stz APP_MOD
jsr cursor_activate
jmp screen_clear_status
;Clear bit 5 to make upper and lower case the same value
: and #%11011111
;Search keyval table
ldy #keyboard_shortcut_count
: cmp keyboard_ctrl_keyval-1,y
beq match
dey
bne :-
;Uknown command, ignore
rts
match:
phy
stz APP_MOD
jsr screen_clear_status
jsr cursor_activate
pla
dea
asl
tax
jmp (keyboard_ctrl_jmptbl,x)
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_statusmessage
;Purpose.............: Key dispatcher: Showing a message in the status bar
;Input...............: Nothing
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_statusmessage
pha
;Any key press will close the status message
stz APP_MOD
jsr screen_clear_status
jsr cursor_activate
;If other than Esc key, send it to default handler
pla
cmp #KEYVAL_ESC
beq :+
jmp keyboard_mode_default
: rts
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_helpscreen
;Purpose.............: Key dispatcher: Showing the built-in help screen
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_helpscreen
;Exit help screen if ESC was pressed, ignore all other input
cmp #KEYVAL_ESC
beq exit_help
rts
exit_help:
stz APP_MOD
jsr screen_refresh
jsr screen_clear_status
jmp cursor_activate
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_exit_save_before
;Purpose.............: Key dispatcher: Prompting the user to save
; current buffer before program exit
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_exit_save_before
;ESC key pressed
cmp #KEYVAL_ESC
beq abort
;Clear bit 5 to make upper and lower case the same value
and #%11011111
;Y key pressed
cmp #KEYVAL_Y
beq save
;N key pressed
cmp #KEYVAL_N
beq discard
;Else ignore keypress
rts
save:
jsr cursor_activate
jsr screen_clear_status
jmp cmd_file_save_prompt
discard:
;Set app quit signal
lda #1
sta APP_QUIT
rts
abort:
jsr cursor_activate
stz APP_MOD
jmp screen_clear_status
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_file_save
;Purpose.............: Key dispatcher: Prompting the user to enter a file
; name, whereto the buffer is to be saved
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_file_save
;Enter key
cmp #KEYVAL_ENTER
beq write_file
;ESC key
cmp #KEYVAL_ESC
beq abort
;Temp store char
tax
;Clear bit 5 to make upper and lower case the same value
and #%11011111
;Ctrl+T
cmp #KEYVAL_T
bne :+
lda scancode_modifiers
cmp #KBD_MODIFIER_CTRL
beq tofiles
;Default, send key to prompt
: txa
jmp prompt_keypress
abort:
jsr prompt_close
stz APP_MOD
jmp screen_print_default_footer
write_file:
jsr screen_print_default_footer
lda file_dir_changed ;Dir was changed, do normal save
bne :++
lda prompt_len ;Check if same length as current file name, do normal save if not
beq :++
cmp file_cur_filename_len
bne :++
lda #<prompt_input ;Check if new file name is same as current file name, do save with overwrite if so
sta TMP1_ADR
lda #>prompt_input
sta TMP1_ADR+1
lda #<file_cur_filename
sta TMP2_ADR
lda #>file_cur_filename
sta TMP2_ADR+1
ldy #0
: lda (TMP1_ADR),y
cmp (TMP2_ADR),y
bne :+
iny
cpy prompt_len
bne :-
ldx #<prompt_input ;Overwrite current file without prompt
ldy #>prompt_input
lda prompt_len
jmp cmd_file_save_overwrite
: ldx #<prompt_input ;Save normally, will prompt for overwriting a file
ldy #>prompt_input
lda prompt_len
jmp cmd_file_save
tofiles:
lda #19
sta APP_MOD
jsr cursor_disable
jsr screen_print_dir_ctx_footer
ldx #1
ldy #0
jmp dir_show
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_file_save_overwrite
;Purpose.............: Key dispatcher: Prompting the user to confirm overwriting
; an existing file
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_file_save_overwrite
;ESC key
cmp #KEYVAL_ESC
beq abort
;Clear bit 5 to make upper and lower case the same value
and #%11011111
;Y key pressed
cmp #KEYVAL_Y
beq write_file
;N key
cmp #KEYVAL_N
beq abort
;Else ignore key
rts
abort:
stz APP_MOD ;mode_default
jsr cursor_activate
jmp screen_clear_status
write_file:
jmp cmd_file_save_overwrite
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_file_open
;Purpose.............: Key dispatcher: Prompting the user to enter a file name
; to be opened and read into the text buffer
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_file_open
;Enter key
cmp #KEYVAL_ENTER
beq read_file
;ESC key
cmp #KEYVAL_ESC
beq abort
;Temp store
tax
;Clear bit 5 to make upper and lower case the same value
and #%11011111
;Ctrl+T
cmp #KEYVAL_T
bne :+
lda scancode_modifiers
cmp #KBD_MODIFIER_CTRL
beq tofiles
;Default, send key to prompt
: txa
jmp prompt_keypress
abort:
jsr prompt_close
stz APP_MOD
jmp screen_print_default_footer
read_file:
jsr screen_print_default_footer
ldx #<prompt_input
ldy #>prompt_input
lda prompt_len
jmp cmd_file_open
tofiles:
lda #18
sta APP_MOD
jsr cursor_disable
jsr screen_print_dir_ctx_footer
ldx #1
ldy #0
jmp dir_show
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_file_dir
;Purpose.............: Key dispatcher: Showing directory listing
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_file_dir
ldx #0
loop:
cmp keyvals,x
beq match
inx
cpx #6
bcc loop
bne :+
;Check control
and #%11011111
ldy scancode_modifiers
cpy #KBD_MODIFIER_CTRL
beq loop
rts
: cpx #8
bcc loop
rts
match:
txa
asl
tax
jmp (jmptbl,x)
enterkey:
clc
lda dir_first
adc dir_selected
tax
lda dir_first+1
adc #0
tay
jsr dir_getitem
lda dir_type
cmp #'d'
bne :+
ldx #<dir_entry
ldy #>dir_entry
lda dir_filename_len
jmp dir_change
: jsr screen_clear_editor
jsr prompt_close
ldx #<dir_entry
ldy #>dir_entry
lda dir_filename_len
jsr prompt_default_input
jsr prompt_refresh
lda APP_MOD
cmp #18
beq open
save:
jsr screen_print_default_footer
jsr cursor_activate
ldx #<prompt_input
ldy #>prompt_input
lda prompt_len
jmp cmd_file_save
open:
stz APP_MOD
jsr screen_print_default_footer
jsr cursor_activate
ldx #<prompt_input
ldy #>prompt_input
lda prompt_len
jmp cmd_file_open
abort:
lda APP_MOD
cmp #18
beq abortopen
abortsave:
jsr screen_print_file_ctx_footer
jsr cursor_activate
lda #4
sta APP_MOD
jmp :+
abortopen:
jsr screen_print_file_ctx_footer
jsr cursor_activate
lda #5
sta APP_MOD
: jsr screen_clear_editor
jmp screen_refresh
uparrow:
ldx dir_selected
dex
jmp dir_select
downarrow:
ldx dir_selected
inx
jmp dir_select
nextpage:
jmp dir_nextpage
prevpage:
jmp dir_prevpage
keyvals:
.byt KEYVAL_ENTER, KEYVAL_ESC, KEYVAL_UP, KEYVAL_DOWN, KEYVAL_PGDN, KEYVAL_PGUP
.byt KEYVAL_Y, KEYVAL_V
jmptbl:
.word enterkey, abort, uparrow, downarrow, nextpage, prevpage, prevpage, nextpage
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_file_open_save_before
;Purpose.............: Key dispatcher: Prompting the user to save the current
; text buffer before opening and reading a file
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_file_open_save_before
;ESC key
cmp #KEYVAL_ESC
beq abort
;Clear bit 5 to make upper and lower case the same value
and #%11011111
;Y key pressed
cmp #KEYVAL_Y
beq save
;N key pressed
cmp #KEYVAL_N
beq discard
;Else ignore keypress
rts
save:
jsr cursor_activate
jmp cmd_file_save_prompt
discard:
jsr cursor_activate
stz mem_modified
jsr cmd_file_open_prompt
inc mem_modified
rts
abort:
jsr cursor_activate
stz APP_MOD
jsr screen_clear_status
rts
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_file_dos_cmd
;Purpose.............: Key dispatcher: Prompting the user to enter dos command
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_dos_cmd
;Enter key
cmp #KEYVAL_ENTER
beq enterkey
;ESC key
cmp #KEYVAL_ESC
beq abort
;Default
jmp prompt_keypress
enterkey:
jmp cmd_file_dos_command_exec
abort:
stz APP_MOD
jmp prompt_close
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_new_buffer_save_before
;Purpose.............: Key dispatcher: Prompting the user to save the current
; text buffer before creating a new buffer
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_new_buffer_save_before
;ESC key
cmp #KEYVAL_ESC
beq abort
;Clear bit 5 to make upper and lower case the same value
and #%11011111
;Y key pressed
cmp #KEYVAL_Y
beq save
;N key pressed
cmp #KEYVAL_N
beq discard
;Else ignore keypress
rts
save:
jsr cursor_activate
jmp cmd_file_save_prompt
discard:
jsr cursor_activate
jsr screen_clear_status
stz APP_MOD
stz mem_modified
jmp cmd_new_buffer
abort:
jsr cursor_activate
stz APP_MOD
jmp screen_clear_status
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_set_device
;Purpose.............: Key dispatcher: Prompting the user to enter device
; number
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_set_device
;ESC key
cmp #KEYVAL_ESC
beq abort
;Enter
cmp #KEYVAL_ENTER
beq enter
;Default
jmp prompt_keypress
abort:
stz APP_MOD
jmp prompt_close
enter:
jmp cmd_file_do_set_device
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_find
;Purpose.............: Key dispatcher: Prompting the user to enter a search
; param
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_find
;Enter key
cmp #KEYVAL_ENTER
beq search
;ESC key
cmp #KEYVAL_ESC
beq abort
jmp prompt_keypress
search:
jsr prompt_close
stz APP_MOD
jsr cursor_disable
ldx #<prompt_input
ldy #>prompt_input
lda prompt_len
jsr cmd_do_find
bcs notfound
jsr screen_refresh
jmp cursor_activate
notfound:
ldx #<msg
ldy #>msg
jsr screen_print_status
lda #2
sta APP_MOD
jmp cursor_activate
abort:
jsr prompt_close
stz APP_MOD
rts
msg:
.byt "string not found",0
.endproc
;******************************************************************************
;Function name.......: keyboard_mode_replace_0
;Purpose.............: Key dispatcher: Prompting the user to enter a search
; param
;Input...............: A=char
;Returns.............: Nothing
;Error returns.......: None
.proc keyboard_mode_replace_0
;Enter key
cmp #KEYVAL_ENTER
beq search