-
Notifications
You must be signed in to change notification settings - Fork 0
/
chooser.asm
938 lines (899 loc) · 15.9 KB
/
chooser.asm
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
CHOOSER_X = 23
CHOOSER_Y = 7
CHOOSER_CHOICE_X = 38
CHOOSER_CHOICE_Y = 8
CHOOSER_SCROLL_X = 55
CHOOSER_SCROLL_UP_Y = 10
CHOOSER_SCROLL_DOWN_Y = 18
CHOOSER_CANCEL_X = 24
CHOOSER_CANCEL_Y = 20
CHOOSER_ACTION_X = 50
CHOOSER_ACTION_Y = CHOOSER_CANCEL_Y
chooser_block: ; 34x15
.byte $70
.repeat 32
.byte $40
.endrepeat
.byte $6e
.byte "| Choose File: |"
.byte $6b
.repeat 30
.byte $40
.endrepeat
.byte $72,$40,$73
.byte "| |",$F1,"|"
.repeat 3
.byte "| |",$66,"|"
.endrepeat
.repeat 4
.byte "| | |"
.endrepeat
.byte "| |",$F2,"|"
.byte $6b
.repeat 8
.byte $40
.endrepeat
.byte $72
.repeat 16
.byte $40
.endrepeat
.byte $72
.repeat 4
.byte $40
.endrepeat
.byte $71,$40,$73
.byte "| Cancel | | Open |"
.byte $6d
.repeat 8
.byte $40
.endrepeat
.byte $71
.repeat 16
.byte $40
.endrepeat
.byte $71
.repeat 6
.byte $40
.endrepeat
.byte $7d
CHOOSER_ACTION_OPEN_TILES = 0
CHOOSER_ACTION_OPEN_PAL = 1
CHOOSER_ACTION_SAVE = 2
chooser_open_tiles:
jsr show_chooser
stz chooser_scroll
jsr scroll_chooser
lda #CHOOSER_ACTION_OPEN_TILES
sta chooser_action
rts
dos_directory:
dos_directory_dirs_only: .byte "$:*=D"
end_dos_directory_dirs_only:
dos_directory_prgs_only: .byte "$:*=P"
end_dos_directory_prgs_only:
show_chooser:
inc chooser_visible
stz selection_is_file
stz selection_is_dir
stz cursor_state
ldx #CHOOSER_X
ldy #CHOOSER_Y
jsr print_set_vera_addr
lda #$11
sta VERA_addr_bank ; set stride to 1
lda #<chooser_block
sta ZP_PTR_1
lda #>chooser_block
sta ZP_PTR_1+1
ldx #15
ldy #0
@loop:
lda (ZP_PTR_1),y
sta VERA_data0
lda #1 ; set to UI color
sta VERA_data0
iny
cpy #34
bne @loop
dex
beq @return
tya
clc
adc ZP_PTR_1
sta ZP_PTR_1
lda ZP_PTR_1+1
adc #0
sta ZP_PTR_1+1
inc VERA_addr_high
lda #(CHOOSER_X*2)
sta VERA_addr_low
ldy #0
bra @loop
@return:
rts
scroll_chooser: ; input: A = scroll position
stz file_list_len
stz dir_list_len
stz dir_read_done
stz dir_skipped
lda chooser_scroll
beq @scroll_zero
lda #1
ldx #<dos_directory
ldy #>dos_directory
jsr SETNAM
lda #1
ldx #8
ldy #0
jsr SETLFS
lda #BRAM_BANK
sta RAM_BANK
lda #0
ldx #<dir_staging
stx ZP_PTR_1
ldy #>dir_staging
sty ZP_PTR_1+1
jsr LOAD
jsr flush_line
stz SB1
@read_loop:
jsr read_dir_listing_line
lda dir_read_done
bne @check_scroll
inc SB1
bra @read_loop
@check_scroll:
lda SB1
cmp #9
bmi @scroll_zero
sec
sbc #8
cmp chooser_scroll
bpl @get_dirs
sta chooser_scroll
bra @get_dirs
@scroll_zero:
stz chooser_scroll
lda #$2E ; "."
sta dir_list
sta dir_list+1
stz dir_list+2
inc dir_list_len
@get_dirs:
stz dir_read_done
lda #(end_dos_directory_dirs_only-dos_directory_dirs_only)
ldx #<dos_directory_dirs_only
ldy #>dos_directory_dirs_only
jsr SETNAM
lda #1
ldx #8
ldy #0
jsr SETLFS
lda #BRAM_BANK
sta RAM_BANK
lda #0
ldx #<dir_staging
stx ZP_PTR_1
ldy #>dir_staging
sty ZP_PTR_1+1
jsr LOAD
jsr flush_line
clc
lda dir_list_len
beq @no_dotdot
lda #26
bra @init_dir_list
@no_dotdot:
lda #0
@init_dir_list:
adc #<dir_list
sta ZP_PTR_2
lda #>dir_list
adc #0
sta ZP_PTR_2+1
@dir_read_loop:
jsr read_dir_listing_line
lda dir_read_done
bne @print_dirs
lda dir_skipped
inc
cmp chooser_scroll
bpl @start_dir_copy
inc dir_skipped
bra @dir_read_loop
@start_dir_copy:
ldy #0
@dir_copy_loop:
lda filename_stage,y
sta (ZP_PTR_2),y
beq @next_dir
iny
cpy #26
beq @next_dir
bra @dir_copy_loop
@next_dir:
inc dir_list_len
lda dir_list_len
cmp #9
bpl @print_dirs
lda ZP_PTR_2
clc
adc #26
sta ZP_PTR_2
lda ZP_PTR_2+1
adc #0
sta ZP_PTR_2+1
bra @dir_read_loop
@print_dirs:
lda #<filename_stage
sta ZP_PTR_3
lda #>filename_stage
sta ZP_PTR_3+1
ldx #0
cpx dir_list_len
beq @load_file_listing
stz filename_stage+26
lda #<dir_list
sta ZP_PTR_2
lda #>dir_list
sta ZP_PTR_2+1
@dir_loop:
lda #$F4 ; file folder icon
sta filename_stage
lda #$20
sta filename_stage+1
ldy #0
@dir_stage_loop:
lda (ZP_PTR_2),y
jsr ascii_to_screen_code
sta filename_stage+2,y
cmp #$80 ; converted NULL
bne @next_dir_char
lda #0
sta filename_stage+2,y
bra @print_dir
@next_dir_char:
iny
cpy #25
bne @dir_stage_loop
lda (ZP_PTR_2),y
sta filename_stage+25
beq @print_dir
iny
lda (ZP_PTR_2),y
beq @print_dir
lda #$2A ; "*"
sta filename_stage+25
@print_dir:
phx
txa
clc
adc #(CHOOSER_Y+3)
tay
ldx #(CHOOSER_X+2)
lda #ZP_PTR_3
jsr print_string
lda ZP_PTR_2
clc
adc #26
sta ZP_PTR_2
lda ZP_PTR_2+1
adc #0
sta ZP_PTR_2+1
plx
inx
cpx dir_list_len
bne @dir_loop
@check_dir_count:
lda dir_list_len
cmp #9
bne @load_file_listing
jmp @done
@load_file_listing:
stz dir_read_done
lda #(end_dos_directory_prgs_only-dos_directory_prgs_only)
ldx #<dos_directory_prgs_only
ldy #>dos_directory_prgs_only
jsr SETNAM
lda #LOGICAL_FILE
ldx #8
ldy #0
jsr SETLFS
lda #BRAM_BANK
sta RAM_BANK
lda #0
ldx #<dir_staging
stx ZP_PTR_1
ldy #>dir_staging
sty ZP_PTR_1+1
jsr LOAD
jsr flush_line
lda #<file_list
sta ZP_PTR_2
lda #>file_list
sta ZP_PTR_2+1
@file_read_loop:
jsr read_dir_listing_line
lda dir_read_done
bne @print_files
lda dir_skipped
cmp chooser_scroll
beq @start_file_copy
inc dir_skipped
bra @file_read_loop
@start_file_copy:
ldy #0
@file_copy_loop:
lda filename_stage,y
sta (ZP_PTR_2),y
beq @next_file
iny
cpy #28
beq @next_file
bra @file_copy_loop
@next_file:
inc file_list_len
lda file_list_len
clc
adc dir_list_len
cmp #9
bpl @print_files
lda ZP_PTR_2
clc
adc #28
sta ZP_PTR_2
lda ZP_PTR_2+1
adc #0
sta ZP_PTR_2+1
bra @file_read_loop
@print_files:
lda #<filename_stage
sta ZP_PTR_3
lda #>filename_stage
sta ZP_PTR_3+1
stz filename_stage+28
ldx #0
lda #<file_list
sta ZP_PTR_2
lda #>file_list
sta ZP_PTR_2+1
cpx file_list_len
beq @done
@file_loop:
ldy #0
@file_stage_loop:
lda (ZP_PTR_2),y
jsr ascii_to_screen_code
sta filename_stage,y
cmp #$80 ; converted NULL
bne @next_file_char
lda #0
sta filename_stage,y
bra @print_file
@next_file_char:
iny
cpy #27
bne @file_stage_loop
lda (ZP_PTR_2),y
sta filename_stage+27
beq @print_file
iny
lda (ZP_PTR_2),y
beq @print_file
lda #$2A ; "*"
sta filename_stage+27
@print_file:
phx
txa
clc
adc dir_list_len
adc #(CHOOSER_Y+3)
tay
ldx #(CHOOSER_X+2)
lda #ZP_PTR_3
jsr print_string
lda ZP_PTR_2
clc
adc #28
sta ZP_PTR_2
lda ZP_PTR_2+1
adc #0
sta ZP_PTR_2+1
plx
inx
cpx file_list_len
bne @file_loop
@done:
; TODO change scroll nub
rts
flush_line:
phy
ldy #4 ; skip past line header
@loop:
lda (ZP_PTR_1),y
iny
cmp #0 ; check for null
bne @loop
tya
clc
adc ZP_PTR_1
sta ZP_PTR_1
lda ZP_PTR_1+1
adc #0
sta ZP_PTR_1+1
ply
rts
read_dir_listing_line:
ldx #0
ldy #4
@spaces:
lda (ZP_PTR_1),y
iny
cmp #$20
beq @spaces
cmp #$22
bne @not_file
@read_char:
lda (ZP_PTR_1),y
cmp #$22
beq @end_filename
sta filename_stage,x
iny
inx
cpx #28
bne @read_char
@end_filename:
stz filename_stage,x
bra @flush
@not_file:
inc dir_read_done
@flush:
jmp flush_line ; tail-optimization
chooser_open_pal:
jsr show_chooser
stz chooser_scroll
jsr scroll_chooser
lda #CHOOSER_ACTION_OPEN_PAL
sta chooser_action
rts
save_string: .asciiz " Save "
chooser_save_as:
jsr show_chooser
ldx #CHOOSER_ACTION_X
ldy #CHOOSER_ACTION_Y
lda #<save_string
sta ZP_PTR_1
lda #>save_string
sta ZP_PTR_1+1
lda #ZP_PTR_1
jsr print_string
stz chooser_scroll
jsr scroll_chooser
lda #CHOOSER_ACTION_SAVE
sta chooser_action
rts
chooser_click:
lda button_latch
bne @return
inc button_latch
cpy #CHOOSER_CHOICE_Y
bne @check_scroll
cpx #CHOOSER_CHOICE_X
bmi @return
cpx #(CHOOSER_CHOICE_X+17)
bpl @return
jmp chooser_choice_click ; tail-optimization
@check_scroll:
cpy #CHOOSER_SCROLL_UP_Y
bmi @return
cpy #(CHOOSER_SCROLL_DOWN_Y+1)
bpl @check_buttons
cpx #(CHOOSER_X+1)
bmi @return
cpx #(CHOOSER_X+31)
bpl @check_scrollbar
jmp chooser_file_click ; tail-optimization
@check_scrollbar:
cpx #CHOOSER_SCROLL_X
bne @return
cpy #CHOOSER_SCROLL_UP_Y
bne @check_scroll_down
jmp chooser_scroll_up ; tail-optimization
@check_scroll_down:
cpy #CHOOSER_SCROLL_DOWN_Y
bne @return
jmp chooser_scroll_down ; tail-optimization
@check_buttons:
cpy #CHOOSER_CANCEL_Y
bne @return
cpx #CHOOSER_CANCEL_X
bmi @return
cpx #(CHOOSER_CANCEL_X+8)
bpl @check_action
jmp close_chooser ; tail-optimization
@check_action:
cpx #CHOOSER_ACTION_X
bmi @return
cpx #(CHOOSER_ACTION_X+6)
bpl @return
jmp chooser_action_click ; tail-optimization
@return:
rts
chooser_choice_click:
lda chooser_action
cmp #CHOOSER_ACTION_SAVE
bne @return
txa
sec
sbc #CHOOSER_CHOICE_X
sta cursor_pos
ldx #0
@pos_loop:
lda selected_file,x
beq @adjust
cpx cursor_pos
beq @set_cursor
inx
cpx #27
bne @pos_loop
@adjust:
stx cursor_pos
@set_cursor:
lda #CHOOSER_CHOICE_X
clc
adc cursor_pos
tax
ldy #CHOOSER_CHOICE_Y
lda #$A0
jsr print_char
lda #1
sta cursor_state
lda #30
sta cursor_countdown
@return:
rts
chooser_cursor_tick:
jsr GETIN
bne @check_backspace
jmp @advance
@check_backspace:
cmp #$14
bne @check_delete
ldx cursor_pos
bne @do_backspace
jmp @advance
@do_backspace:
dec cursor_pos
@backspace_loop:
lda selected_file,x
sta selected_file-1,x
bne @continue_backspace
jmp @print_filename
@continue_backspace:
inx
cpx #28
bne @backspace_loop
stz selected_file+28
jmp @print_filename
@check_delete:
cmp #$19
bne @check_arrow_left
ldx cursor_pos
lda selected_file,x
bne @delete_loop
jmp @advance
@delete_loop:
lda selected_file+1,x
sta selected_file,x
beq @print_filename
inx
cpx #28
bne @delete_loop
stz selected_file+28
bra @print_filename
@check_arrow_left:
cmp #$9D
bne @check_arrow_right
lda cursor_pos
beq @advance
@dec_cursor_pos:
jsr chooser_replace_cursor
dec cursor_pos
lda #1
sta cursor_countdown
inc
sta cursor_state
bra @advance
@check_arrow_right:
cmp #$1D
bne @check_printable
ldx cursor_pos
lda selected_file,x
beq @advance
jsr chooser_replace_cursor
inc cursor_pos
lda #1
sta cursor_countdown
inc
sta cursor_state
bra @advance
@check_printable:
cmp #$20
bmi @advance
cmp #$7B
bpl @advance
cmp #$2A ; no asterix
beq @advance
cmp #$2F ; no slash
beq @advance
sta SB1
ldx cursor_pos
cpx #16
beq @advance
inc cursor_pos
@insert_loop:
lda selected_file,x
sta SB2
lda SB1
sta selected_file,x
beq @print_filename
lda SB2
sta SB1
inx
cpx #28
bne @insert_loop
stz selected_file+28
@print_filename:
jsr chooser_print_selected_file
lda #30
sta cursor_countdown
lda #2
sta cursor_state
rts
@advance:
dec cursor_countdown
bne @return
lda #30
sta cursor_countdown
lda cursor_state
eor #$03
sta cursor_state
cmp #1
bne @no_cursor
lda cursor_pos
clc
adc #CHOOSER_CHOICE_X
tax
ldy #CHOOSER_CHOICE_Y
lda #$A0
jmp print_char ; tail-optimization
@no_cursor:
jmp chooser_replace_cursor ; tail-optimization
@return:
rts
chooser_replace_cursor:
ldx cursor_pos
lda selected_file,x
sta SB1
txa
clc
adc #CHOOSER_CHOICE_X
tax
ldy #CHOOSER_CHOICE_Y
lda SB1
jsr ascii_to_screen_code
cmp #$80
bne @print
lda #$20
@print:
jmp print_char ; tail-optimization
chooser_file_click:
jsr check_double_click
bcc @select
jmp chooser_action_click ; tail-optimization
@select:
stz selection_is_dir
stz selection_is_file
stz cursor_state
tya
sec
sbc #CHOOSER_SCROLL_UP_Y
cmp dir_list_len
bmi @select_dir
sbc dir_list_len
cmp file_list_len
bpl @return
inc selection_is_file
tax
lda #<file_list
sta ZP_PTR_1
lda #>file_list
sta ZP_PTR_1+1
@find_filename:
cpx #0
beq @choose
dex
lda ZP_PTR_1
clc
adc #28
sta ZP_PTR_1
lda ZP_PTR_1+1
adc #0
sta ZP_PTR_1+1
bra @find_filename
@select_dir:
inc selection_is_dir
tax
lda #<dir_list
sta ZP_PTR_1
lda #>dir_list
sta ZP_PTR_1+1
@find_dir:
cpx #0
beq @choose
dex
lda ZP_PTR_1
clc
adc #26
sta ZP_PTR_1
lda ZP_PTR_1+1
adc #0
sta ZP_PTR_1+1
bra @find_dir
@return: ; placed centrally
rts
@choose:
ldy #0
@choose_loop:
lda (ZP_PTR_1),y
sta selected_file,y
beq chooser_print_selected_file
iny
cpy #28
bne @choose_loop
chooser_print_selected_file:
ldy #0
lda #<filename_stage
sta ZP_PTR_2
lda #>filename_stage
sta ZP_PTR_2+1
@print_copy_loop:
lda selected_file,y
jsr ascii_to_screen_code
cmp #$80
beq @pad
sta (ZP_PTR_2),y
iny
cpy #16
bne @print_copy_loop
lda selected_file,y
beq @pad
jsr ascii_to_screen_code
tax
iny
lda selected_file,y
bne @asterix
dey
txa
sta (ZP_PTR_2),y
iny
bra @add_null
@asterix:
dey
lda #$2A
sta (ZP_PTR_2),y
iny
bra @add_null
@pad:
cpy #17
beq @add_null
lda #$20
sta (ZP_PTR_2),y
iny
bra @pad
@add_null:
lda #0
sta (ZP_PTR_2),y
lda #ZP_PTR_2
ldx #CHOOSER_CHOICE_X
ldy #CHOOSER_CHOICE_Y
jmp print_string ; tail-optimization
chooser_clear_file_row: .asciiz " "
chooser_scroll_up:
lda chooser_scroll
beq @return
dec chooser_scroll
jsr chooser_clear_all
jmp scroll_chooser ; tail-optimization
@return:
rts
chooser_scroll_down:
inc chooser_scroll
jsr chooser_clear_all
jmp scroll_chooser ; tail-optimization
chooser_clear_all:
lda #<chooser_clear_file_row
sta ZP_PTR_1
lda #>chooser_clear_file_row
sta ZP_PTR_1+1
ldx #(CHOOSER_X+1)
ldy #CHOOSER_SCROLL_UP_Y
@loop:
lda #ZP_PTR_1
jsr print_string
iny
cpy #(CHOOSER_SCROLL_DOWN_Y+1)
bne @loop
rts
close_chooser:
stz chooser_visible
stz cursor_state
jmp load_tile ; tail-optimization
chooser_action_click:
lda selection_is_dir
bne @change_dir
lda selection_is_file
beq @return ; nothing selected
ldx #0
lda chooser_action
cmp #CHOOSER_ACTION_OPEN_PAL
bne @copy_tile_fn
@copy_pal_fn:
lda selected_file,x
sta pal_filename,x
inx
cpx #29
bne @copy_pal_fn
jsr load_pal_file
bra @close
@copy_tile_fn:
lda selected_file,x
sta tile_filename,x
inx
cpx #29
bne @copy_tile_fn
lda chooser_action
cmp #CHOOSER_ACTION_OPEN_TILES
bne @check_save
jsr load_tile_file
bra @close
@check_save:
cmp #CHOOSER_ACTION_SAVE
bne @close ; something is wrong, just close out
jsr save_tile_file
@close:
jmp close_chooser ; tail-optimization
@return: ; central location
rts
@change_dir:
ldx #3
@length_loop:
lda dos_cd_start,x
beq @do_cd
inx
bra @length_loop
@do_cd:
txa
ldx #<dos_cd_start
ldy #>dos_cd_start
jsr SETNAM
lda #15
ldx #8
ldy #15
jsr SETLFS
jsr OPEN
ldx #15
jsr CHKIN
@read_loop:
jsr CHRIN
jsr READST
and #$40 ; check for EOF
beq @read_loop
lda #15
jsr CLOSE
jsr CLRCHN
stz selected_file
jsr chooser_print_selected_file
jsr chooser_clear_all
stz chooser_scroll
jmp scroll_chooser ; tail-optimization