forked from jbrandwood/teos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_mb128.s
1172 lines (902 loc) · 22.7 KB
/
menu_mb128.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
; ***************************************************************************
; ***************************************************************************
;
; menu_mb128.s
;
; TEOS Menu Screens
;
; Copyright John Brandwood 2019-2022.
;
; Distributed under the Boost Software License, Version 1.0.
; (See accompanying file LICENSE_1_0.txt or copy at
; http://www.boost.org/LICENSE_1_0.txt)
;
; ***************************************************************************
; ***************************************************************************
; ***************************************************************************
; ***************************************************************************
;
; tos_m128_menu - Text messages for the Memory Base SD menu.
;
msg_m128_init: db "%>%p5%xl",0
db $0C
db " MEMORY BASE SD: Reading the MB128 "
; db " MEMORY BASE SD: Initializing ... "
db "%<%p0",$0A,$0A,$0A,0
;msg_m128_none: db " Memory Base 128 not detected!",$0A,0
;
;
;
M128_SAVE = 0
M128_LOAD = 1
M128_DEL = 2
M128_FRAG = 3
tbl_m128_title: dw msg_m128_save
dw msg_m128_load
dw msg_m128_del
dw msg_m128_frag
cls_m128_save: db $0C
msg_m128_save: db "%>%p5%xl",0
db "%x",0
db "%y",0
db " MEMORY BASE SD: Copy the MB128 to SD "
db "%<%p0",$0A,$0A,$0A,0
cls_m128_load: db $0C
msg_m128_load: db "%>%p5%xl",0
db "%x",0
db "%y",0
db " MEMORY BASE SD: Copy SD to the MB128 "
db "%<%p0",$0A,$0A,$0A,0
cls_m128_del: db $0C
msg_m128_del: db "%>%p5%xl",0
db "%x",0
db "%y",0
db " MEMORY BASE SD: Delete file in MB128 "
db "%<%p0",$0A,$0A,$0A,0
cls_m128_frag: db $0C
msg_m128_frag: db "%>%p5%xl",0
db "%x",0
db "%y",0
; db " MEMORY BASE SD: Delete file in MB128"
; db " MEMORY BASE SD: Defragment MB128 "
db " MEMORY BASE SD: Defragment the MB128 "
db "%<%p0",$0A,$0A,$0A,0
;
;
;
msg_m128_lhs: db "%<%xl",0
db "%y",2
db "%x",1
db "%b",18,19,0
db "%p3"
db "%y",3
db "%x",2
db " Name Size"
db "%x",1
db "%y",21
db "%p2"
db "%>MB128 %<"
db "%r"
dw tos_m128_files + 0
db "Files: %3hu",$0A
db "%r"
dw tos_m128_free + 0
db "%x",9
db "%y",22
db "Free: %4u"
db "%xl",2
db "%x",2
db "%y",4
db "%p0%>",0
;
;
;
msg_m128_rhs: db "%<%xl",0
db "%y",2
db "%x",21
db "%b",18,19,0
db "%p3"
db "%y",3
db "%x",22
db " Name Size"
db "%x",21
db "%y",21
db "%p2"
db "%r"
dw tos_m128_slot
db "%>Slot #%hu %<"
db "%r"
dw tos_m128_files + 2
db "Files: %3hu",$0A
db "%r"
dw tos_m128_free + 2
db "%x",29
db "%y",22
db "Free: %4u"
db "%xl",22
db "%x",22
db "%y",4
db "%p0%>",0
;
;
;
msg_m128_1frag: db "%>%xl",22
db "%x",22
db "%y",5
db "%p3"
; db "------------------",$0A
; db "Congratulations!",$0A,$0A,$0A,$0A
db "MB128 free space",$0A,$0A
db "is defragmented.",$0A,$0A,$0A,$0A
; db "It does not need",$0A,$0A
; db "defragmentation!",$0A,$0A
db "The maximum size",$0A,$0A
db "of a new file is",$0A,$0A
db "%r"
dw tos_m128_maxsz
db "%p2%lu%p3"
db " bytes.",$0A,$0A
db "%<%xl",0
db 0
msg_m128_nfrag: db "%>%xl",22
db "%x",22
db "%y",5
db "%p3"
; db "------------------",$0A
db "MB128 free space",$0A,$0A
db "is fragmented in",$0A,$0A
db "%r"
dw tos_m128_frags
db "%p2%hu%p3"
db " blocks.",$0A,$0A,$0A,$0A
db "Defragment MB128",$0A,$0A
db "to maximize size",$0A,$0A
db "of future files.",$0A,$0A
db "%<%xl",0
db 0
;
;
;
tbl_m128_help: dw hlp_m128_save ; Help if box is selected.
dw hlp_m128_load
dw hlp_m128_del
dw hlp_m128_frag
hlp_m128_save: db "%<%p5%xl",0
db "%x",0
db "%y",24
db " SEL%p6:Chg Menu%p5 <>%p6:Chg Slot%p5 \\|%p6:Scroll %p5",$0A
db " "
db 30,31
db "%p6:Chg Mode%p5"
db " "
db 28,29
db "%p6:Copy MB128 to Slot %p5",$0A
db "%y",23
db "%p0"
db "%xl",19
db "%x",19
db "%y",3
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db ">>",$0A
db 0
;
hlp_m128_load: db "%<%p5%xl",0
db "%x",0
db "%y",24
db " SEL%p6:Chg Menu%p5 <>%p6:Chg Slot%p5 \\|%p6:Scroll %p5",$0A
db " "
db 30,31
db "%p6:Chg Mode%p5"
db " "
db 28,29
db "%p6:Copy Slot to MB128 %p5",$0A
db "%y",23
db "%p0"
db "%xl",19
db "%x",19
db "%y",3
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db "<<",$0A
db 0
;
hlp_m128_del: db "%<%p5%xl",0
db "%x",0
db "%y",24
db " SEL%p6:Chg Menu%p5 <>%p6:Chg Slot%p5 \\|%p6:Chg File%p5",$0A
db " "
db 30,31
db "%p6:Chg Mode%p5"
db " "
db 28,29
db "%p6:Delete File in MB128 %p5",$0A
db "%y",23
db "%p0"
db 0
;
hlp_m128_frag: db "%<%p5%xl",0
db "%x",0
db "%y",24
db " SEL%p6:Chg Menu%p5 <>%p6:Chg Slot%p5 \\|%p6:Scroll %p5",$0A
db " "
db 30,31
db "%p6:Chg Mode%p5"
db " "
db 28,29
db "%p6:Defragment the MB128 %p5",$0A
db "%y",23
db "%p0"
db 0
;
;
;
msg_m128_name: db "%8c %r"
dw tos_temp_length
db "%4u",$0A,$0A,0
;
;
msg_m128_format:db " The Memory Base 128 is unformatted! ",$0A,$0A,0
msg_m128_damage:db " The Memory Base 128 directory seems ",$0A
db " to be corrupted and cannot be used! ",$0A,$0A,0
msg_m128_empty: db " TEOS will use a new formatted image ",$0A
db " instead, but your MB128 will remain ",$0A
db " unchanged unless you choose to copy ",$0A
db " the contents of an SD Slot to it.",$0A,$0A,0
; db " an SD card SLOT to it.",$0A,$0A,0
;msg_m128_empty:db " An empty MB128 image will be shown. ",$0A,$0A,0
; USE COPIES FROM BRAM MENU
if 0
msg_small_index:db "%-2hu",0
msg_large_index:db "%02hu",0
msg_bram_larrow:db $1C,0
msg_bram_rarrow:db $1D,0
msg_bram_space: db " ",0
msg_bram_name: db "%10c %r"
dw tos_temp_length
db "%4u",$0A,$0A,0
msg_bram_spaces:db " "
db " ",$0A,$0A,0
msg_blank_rhs: db "%<%xl",0
db "%y",2
db "%x",19
db "%p0"
db "%b",20,21,1
db "%p0%>",0
endif
;
;
;
bss
tos_m128_slot: ds 1
tos_m128_mode: ds 1
tos_m128_focus: ds 1 ; Which side is focused?
tos_m128_frags: ds 2*2 ; # of frags on LHS/RHS.
tos_m128_files: ds 2*2 ; # of files on LHS/RHS.
tos_m128_least: ds 2*2 ; Minimum LHS/RHS file choice.
tos_m128_chosen:ds 2*2 ; Current LHS/RHS file choice.
tos_m128_free: ds 2*2 ; Blocks unused on LHS/RHS.
tos_m128_first: ds 1
tos_m128_choice:ds 1
tos_m128_index: ds 1
tos_m128_hilite:ds 1
tos_m128_fname: ds 2 ; Ptr to selected name in MB128.
tos_m128_trash: ds 1 ; Is the MB128 contents bad?
tos_slot_trash: ds 1 ; Is the SLOT contents bad?
tos_m128_maxsz: ds 4 ; Maximum file size.
code
; ***************************************************************************
; ***************************************************************************
;
; tos_m128_menu - Memory Base SD menu.
;
tos_m128_menu: stz tos_m128_mode
stz tos_m128_slot
tos_m128_init: if REALHW
PUTS msg_m128_init
jsr mb1_detect ; Skip if there is no MB128.
beq .start_menu
endif
jmp tos_hucard_menu
.start_menu: stw #$0000,VCE_CTA
stw #red464_palette,__ax
ldx #8
jsr copy_palettes
; jsr clear_screen
; Verify contents of BRAM_BANK.
stz tos_m128_trash ; Mark the MB128 as good.
lda #BRAM_BANK
sta mb1_base_bank
jsr mb1_load_dir ; Load the directory.
bne .bad_m128
jsr mb1_csum_dir ; Fix directory for display.
beq .m128_info
.bad_m128: stx tos_m128_trash ; Mark the MB128 as bad.
cpx #MB1_ERR_IDENT ; What kind of error?
bne .corrupt
PUTS msg_m128_format
bra .wait_user
.corrupt: PUTS msg_m128_damage
.wait_user: PUTS msg_m128_empty
PUTS msg_press_a_key
jsr wait_for_key
lda #BRAM_BANK ; Format the MB128 image.
jsr mb1_new_image
jsr mb1_csum_dir ; Fix directory for display.
.m128_info: ldx #0 ; Save MB128 info.
jsr tos_m128_info
lda tos_m128_free ; Save maximum file size.
jsr mb1_xvert_size
sta tos_m128_maxsz + 0
stx tos_m128_maxsz + 1
sty tos_m128_maxsz + 2
stz tos_m128_maxsz + 3
; Verify contents of SLOT_BANK.
.new_slot: stz tos_hilite_idx ; Reset hilite pulsing.
stz tos_slot_trash ; Mark the SLOT as good.
lda #SLOT_BANK ; Load the file data.
jsr tos_load_m128
bne .bad_slot
jsr mb1_test_dir ; Check the directory signature
bne .bad_slot ; and checksum.
jsr mb1_csum_dir ; Fix directory for display.
beq .slot_info
.bad_slot: stx tos_slot_trash ; Mark the SLOT as bad.
lda #SLOT_BANK ; Format the SLOT image.
jsr mb1_new_image
jsr mb1_csum_dir ; Fix directory for display.
.slot_info: ldx #2 ; Save SLOT info.
jsr tos_m128_info
; Has the mode just changed?
.new_mode: ldx tos_m128_mode ; Lookup which side has focus.
lda .tbl_focus_side,x
sta tos_m128_focus
lda .tbl_min_choice,x ; Lookup minimum selection.
sta tos_m128_least + 0 ; Set minimum selection.
sta tos_m128_least + 2
sta tos_m128_chosen + 0 ; Set current selection.
sta tos_m128_chosen + 2
cpx #M128_DEL ; Delete File mode?
bcs .show_title
ldx #2
.calc_minimum: lda #8 ; Start at the last file
cmp tos_m128_files,x ; shown on the screen so
bcc .set_minimum ; scrolling is immediate.
lda tos_m128_files,x
.set_minimum: sta tos_m128_least,x ; Set minimum selection.
sta tos_m128_chosen,x ; Set current selection.
dex
dex
bpl .calc_minimum
.show_title: lda tos_m128_mode ; Lookup which title to display.
asl a
tay
ldx tbl_m128_title + 0,y
lda tbl_m128_title + 1,y
jsr tos_print_msg
; Redraw the menu screen to reflect changes.
.show_help: ldx tos_m128_mode ; Lookup which help to display.
ldy .tbl_focus_side,x ; Is there a file selected on
lda tos_m128_chosen,y ; the side that has focus?
sax
; beq .lookup_help
; clc ; If so, use 2nd set of help
; adc #4 ; messages.
.lookup_help: asl a
tay
ldx tbl_m128_help + 0,y
lda tbl_m128_help + 1,y
jsr tos_print_msg
; Display contents of BRAM_BANK.
.show_m128: ldx tos_m128_mode
cpx #M128_DEL
bne .m128_box_color
stz tos_hilite_idx ; Reset hilite pulsing.
.m128_box_color:lda .tbl_box_lhs,x
jsr tos_set_pen
PUTS msg_m128_lhs
lda #BRAM_BANK
tam3
ldx #0
jsr tos_m128_show
; Display contents of SLOT_BANK.
lda tos_m128_mode
cmp #M128_DEL
bcc .show_slot
bne .show_frag
.show_null: PUTS msg_blank_rhs ; RHS shows blank.
bra .wait_input
.show_frag: PUTS msg_blank_rhs ; RHS shows fragmentation.
lda tos_m128_frags
cmp #2
bcs .show_nfrag
PUTS msg_m128_1frag ; Defragmented!
bra .wait_input
.show_nfrag: PUTS msg_m128_nfrag ; Fragmented!
bra .wait_input
.show_slot: ldx tos_m128_mode
lda .tbl_box_rhs,x
jsr tos_set_pen
inc tos_m128_slot
PUTS msg_m128_rhs
dec tos_m128_slot
lda #SLOT_BANK
tam3
ldx #2
jsr tos_m128_show
;
.wait_input: stz joytrg
.wait_loop: jsr wait_vsync_usb
lda joytrg
beq .wait_loop
bit #JOY_SEL
beq .same_menu
stw #$0000,VCE_CTA
stw #cpc464_palette,__ax
ldx #8
jsr copy_palettes
jmp tos_hucard_menu
.same_menu: bit #JOY_L
bne .prev_slot
bit #JOY_R
bne .next_slot
bit #JOY_U
bne .prev_file
bit #JOY_D
bne .next_file
bit #JOY_B1
bne .select
.back_only: bit #JOY_B2
beq .wait_input
; jmp .chg_mode
; Change Mode.
lda tos_m128_mode
inc a
and #3
; cmp #3
; bcc .save_mode
; cla
.save_mode: sta tos_m128_mode
jmp .new_mode
; Change Save Slot.
.prev_slot: lda tos_m128_slot
dec a
and #7
sta tos_m128_slot
jmp .new_slot
.next_slot: lda tos_m128_slot
inc a
and #7
sta tos_m128_slot
jmp .new_slot
; Change Selected File.
.prev_file: clx
ldy #2
.prev_loop: lda tos_m128_chosen,x ; Already at minimum selection?
cmp tos_m128_least,x
bne .check_other
; lda tos_m128_files,x ; Wrap around to end selection.
bra .set_prev_file
.check_other: cmp tos_m128_chosen,y ; Is the other side on a higher
bcc .set_prev_file ; selection?
dec a
.set_prev_file: pha
sxy
txa
bne .prev_loop
.changed_choice:pla
sta tos_m128_chosen + 2
pla
sta tos_m128_chosen + 0
jmp .show_m128
.next_file: clx
ldy #2
.next_loop: lda tos_m128_chosen,x ; Already at maximum selection?
cmp tos_m128_files,x
bne .inc_next_file
lda tos_m128_chosen,y ; Is the other side on maximum?
cmp tos_m128_files,y
; lda tos_m128_least,x ; Wrap around to 1st selection.
; bcs .set_next_file
lda tos_m128_chosen,x ; Else stay on current choice.
dec a
.inc_next_file: inc a
.set_next_file: pha
sxy
txa
bne .next_loop
bra .changed_choice
.select: lda tos_m128_mode
asl a
tax
jsr .vector
jmp tos_m128_init
.vector: jmp [.tbl_funcs,x]
.tbl_funcs: dw func_m128_save
dw func_m128_load
dw func_m128_del
dw func_m128_frag
.tbl_box_lhs: db 1,0,0,1 ; Palette for box per mode.
.tbl_box_rhs: db 0,1,0,0 ; Palette for box per mode.
.tbl_focus_side:db 0,2,0,0 ; Focused side per mode.
.tbl_min_choice:db 0,0,1,0 ; Minimum choice per mode.
; ***************************************************************************
; ***************************************************************************
;
; tos_m128_info - Save the info after a verify for later display.
;
; N.B. There can be a maximum of 63 files in the MB128.
;
tos_m128_info: lda mb1_frag_count
sta tos_m128_frags + 0,x
stz tos_m128_frags + 1,x
lda mb1_file_count
sta tos_m128_files + 0,x
stz tos_m128_files + 1,x
sec
lda #<256
sbc mb1_directory + MB1_HEAD_USED + 0
sta tos_m128_free + 0,x
lda #>256
sbc mb1_directory + MB1_HEAD_USED + 1
sta tos_m128_free + 1,x
rts
; ***************************************************************************
; ***************************************************************************
;
; tos_m128_show - Display the BRAM files in the current bank.
;
; N.B. There can be a maximum of 63 files in the MB128.
;
tos_m128_show: lda tos_m128_chosen,x ; Decide which file to display
sta tos_m128_choice ; at the top of the box.
sec
sbc #7
bcs .first_to_show
lda #1
.first_to_show: sta tos_m128_first
.test_focus: lda #1
sta tos_m128_hilite ; Set hilite color to pulsing.
lda tos_m128_mode ; Only hilite a file in Delete.
cmp #2
beq .first_in_m128
stz tos_m128_hilite ; Set hilite color to normal.
stz tos_m128_choice ; Do not hilite any file.
.first_in_m128: ldy #<mb1_directory + 16 ; Start at the first file.
lda #>mb1_directory + 16
stz tos_m128_index
.file_loop: inc tos_m128_index ; Increment file index.
cpy #>mb1_directory + 1024 ; Is it beyond directory?
bcs .rest ; EOD, remaining slots blank.
sty <__bp + 0 ; Update file pointer.
sta <__bp + 1
.not_eof: lda [__bp] ; Sector# or zero at end.
beq .rest
ldy #MB1_FILE_SIZE
lda [__bp],y
sta tos_temp_length + 0 ; Size to display (lo-byte).
stz tos_temp_length + 1 ; Size to display (hi-byte).
lda #$10 ; Calc address of next file.
clc
adc <__bp + 0
say
cla
adc <__bp + 1
ldx tos_m128_index ; Skip off-screen files.
cpx tos_m128_first
bcc .file_loop
phy ; Preserve next file pointer.
pha
cla ; Select the palette to use
ldx tos_m128_index ; for this file entry.
cpx tos_m128_choice
bne .file_color
lda tos_m128_hilite
.file_color: jsr tos_set_pen
if 0
ldx #<msg_small_index ; Display bottom 2 digits
ldy #>msg_small_index
lda tos_m128_index
cmp #100
bcc .show_index
sbc #100
ldx #<msg_large_index
ldy #>msg_large_index
.show_index: sta tos_temp_index ; Truncated to 2 digits.
lda #<tos_temp_index ; Display the file index.
sta <__di + 0
lda #>tos_temp_index
sta <__di + 1
; tya
; jsr tos_print_msg
endif
ldx #<msg_bram_space ; Display the LHS file cursor.
ldy #>msg_bram_space
lda tos_m128_index
cmp tos_m128_choice
bne .show_lhs_arrow
ldx #<msg_bram_larrow
ldy #>msg_bram_larrow
.show_lhs_arrow:tya
jsr tos_print_msg
.file_name: lda #MB1_FILE_NAME ; Display the file name & size.
clc
adc <__bp + 0
sta <__di + 0
tax
cla
adc <__bp + 1
sta <__di + 1
tay
lda tos_tty_tile + 1 ; Is this entry in the hilite
and #$F0 ; color?
beq .show_name
stx tos_m128_fname + 0 ; Save the addr of the selected
sty tos_m128_fname + 1 ; filename.
.show_name: PUTS msg_m128_name
pla ; Restore next file pointer.
ply
ldx tos_tty_ypos ; Display the rest of the
cpx #20 ; BRAM files in the box.
bcs .done
jmp .file_loop
.rest: lda tos_tty_ypos ; Blank out the rest of the
cmp #20 ; BRAM files in the box.
bcs .done
PUTS msg_bram_spaces
bra .rest
.done: rts
; ***************************************************************************
; ***************************************************************************
;
; func_m128_save - Copy MB128 to SD card slot.
;
func_m128_save: PUTS cls_m128_save ; Confirm the operation.
inc tos_m128_slot ; Show slot from '1' not '0'.
PUTS .msg_warning
dec tos_m128_slot
.wait_input: stz joytrg ; Wait for input.
.wait_loop: jsr wait_vsync_usb
lda joytrg
beq .wait_loop
bit #JOY_RUN
bne .confirmed
bit #JOY_B2
beq .wait_input
rts
.confirmed: PUTS cls_m128_save ; Inform the user.
lda tos_m128_trash ; Is the MB128 corrupt?
bne .skip_load ; Save clean copy from memory.
PUTS .msg_load
lda #BRAM_BANK ; Load the MB128 image.
jsr mb1_load_image
bne .failed
.skip_load: PUTS .msg_save
lda #BRAM_BANK ; Save image to the SD card.
jsr tos_save_m128
bne .failed
PUTS msg_m128_done
bra .result
.failed: PUTS msg_m128_fail
.result: PUTS msg_press_a_key
jsr wait_for_key
.finished: rts
.msg_warning: db "%r"
dw tos_m128_slot
db "%y",11
db " Please press %p1RUN%p0 to confirm that you",$0A
db " want to copy the MB128 to SD Slot #%hu",$0A
db "%y",24
db "%x",12
db "%p5RUN%p6:Confirm copy",$0A
db "%x",13
db "%p5",30,31,"%p6:Cancel copy",$0A
db "%p0%y",14,0
.msg_load: db " Loading data from MB128",0
.msg_save: db " Saving data to SD card.",$0A,$0A,0
; ***************************************************************************
; ***************************************************************************
;
; func_m128_load - Copy SD card slot to MB128.
;
func_m128_load: PUTS cls_m128_load
inc tos_m128_slot ; Show slot from '1' not '0'.
PUTS .msg_warning
dec tos_m128_slot
.wait_input: stz joytrg ; Wait for input.
.wait_loop: jsr wait_vsync_usb
lda joytrg
beq .wait_loop
bit #JOY_RUN
bne .confirmed
bit #JOY_B2
beq .wait_input
rts
.confirmed: PUTS cls_m128_load ; Inform the user.
lda tos_slot_trash ; Is the SLOT corrupt?
bne .skip_load ; Save clean copy from memory.
PUTS .msg_load
lda #SLOT_BANK ; Load image from the SD card.
jsr tos_load_m128
bne .failed
.skip_load: PUTS .msg_save
lda #SLOT_BANK ; Save the MB128 image.
jsr mb1_save_image
bne .failed
PUTS msg_m128_done
bra .result
.failed: PUTS msg_m128_fail
.result: PUTS msg_press_a_key
jsr wait_for_key
.finished: rts
.msg_warning: db "%r"
dw tos_m128_slot
db "%y",11
db " Please press %p1RUN%p0 to confirm that you",$0A
db " want to copy SD Slot #%hu to the MB128",$0A
db "%y",24
db "%x",12
db "%p5RUN%p6:Confirm copy",$0A
db "%x",13
db "%p5",30,31,"%p6:Cancel copy",$0A
db "%p0%y",14,0
.msg_load: db " Loading data from SD card.",$0A,$0A,0
.msg_save: db " Saving data to MB128",0
msg_m128_fail: db " MB128 operation failed!",$0A,$0A,0