forked from jbrandwood/teos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_bram.s
1088 lines (863 loc) · 20.6 KB
/
menu_bram.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_bram.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_bram_menu - Text messages for the TENNOKOE SD menu.
;
;
;
;
BRAM_SAVE = 0
BRAM_SWAP = 1
BRAM_LOAD = 2
BRAM_DEL = 3
tbl_bram_title: dw msg_copy_bram
dw msg_swap_bram
dw msg_copy_slot
dw msg_wipe_file
cls_copy_bram: db $0C
msg_copy_bram: db "%>%p5%xl",0
db "%x",0
db "%y",0
db " TENNOKOE SD: Copy BACKUP RAM to SD "
db "%<%p0",$0A,$0A,$0A,0
cls_swap_bram: db $0C
msg_swap_bram: db "%>%p5%xl",0
db "%x",0
db "%y",0
db " TENNOKOE SD: Swap BACKUP RAM with SD "
db "%<%p0",$0A,$0A,$0A,0
cls_copy_slot: db $0C
msg_copy_slot: db "%>%p5%xl",0
db "%x",0
db "%y",0
db " TENNOKOE SD: Copy SD to BACKUP RAM "
db "%<%p0",$0A,$0A,$0A,0
cls_wipe_file: db $0C
msg_wipe_file: db "%>%p5%xl",0
db "%x",0
db "%y",0
; db "----------------------------------------"
db " TENNOKOE SD: Delete file in BACKUP RAM "
db "%<%p0",$0A,$0A,$0A,0
;
;
;
msg_bram_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 "%p0"
db "%p2"
db "%>Console %<"
db "%p2"
db "%r"
dw tos_bram_files + 0
db "Files: %3hu",$0A
db "%r"
dw tos_bram_free + 0
db "%x",9
db "%y",22
db "Free: %4u"
db "%xl",2
db "%x",2
db "%y",4
db "%p0%>",0
;
;
;
msg_bram_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_bram_slot
; db "%>Slot %02hu %<"
db "%>Slot #%hu %<"
db "%r"
dw tos_bram_files + 2
db "Files: %3hu",$0A
db "%r"
dw tos_bram_free + 2
db "%x",29
db "%y",22
db "Free: %4u"
db "%xl",22
db "%x",22
db "%y",4
db "%p0%>",0
;
;
;
tbl_bram_help: dw hlp_copy_bram ; Help if box is selected.
dw hlp_swap_bram
dw hlp_copy_slot
dw hlp_wipe_file
hlp_copy_bram: 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 BRAM 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_swap_bram: 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:Swap BRAM with 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_copy_slot: 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 BRAM %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_wipe_file: 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 from BRAM %p5",$0A
db "%y",23
db "%p0"
; db "----------------------------------------"
; db " ------------------ ",0
db 0
;
;
;
msg_bram_name: db "%10c %r"
dw tos_temp_length
db "%4u",$0A,$0A,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_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
;
;
;
bss
tos_bram_slot: ds 1
tos_bram_mode: ds 1
tos_bram_focus: ds 1 ; Which side is focused?
tos_bram_files: ds 2*2 ; # of files on LHS/RHS.
tos_bram_least: ds 2*2 ; Minimum LHS/RHS file choice.
tos_bram_chosen:ds 2*2 ; Current LHS/RHS file choice.
tos_bram_free: ds 2*2 ; BRAM unused on LHS/RHS.
tos_bram_first: ds 1
tos_bram_choice:ds 1
tos_bram_index: ds 1
tos_bram_hilite:ds 1
tos_bram_fname: ds 2 ; Ptr to selected name in BRAM.
tos_temp_index: ds 1
tos_temp_length:ds 2
code
; ***************************************************************************
; ***************************************************************************
;
; tos_bram_menu - TENNOKOE SD menu.
;
tos_bram_menu: stz tos_bram_mode
stz tos_bram_slot
jsr bm_exists ; Skip if there is no BRAM.
beq tos_bram_menu2
jmp tos_info_menu
tos_bram_menu2: jsr clear_screen
; PUTS msg_bram_title
; Verify contents of BRAM_BANK.
lda #BRAM_BANK
tam3
jsr bm_bram_to_bank
jsr bm_verify_mpr3 ; Verify the BRAM image.
beq .bram_info ; Is it OK?
bmi .bram_format ; Is it unformatted?
jmp tos_info_menu ; Wierd size or corrupt.
.bram_format: jsr bm_format_mpr3 ; Blank the slot.
.bram_info: ldx #0 ; Save BRAM info.
jsr tos_bram_info
; Verify contents of SLOT_BANK.
.new_slot: stz tos_hilite_idx ; Reset hilite pulsing.
lda #SLOT_BANK
tam3
if REALHW
jsr tos_load_slot ; Load the file data.
beq .got_slot
jsr bm_format_mpr3 ; Blank the slot.
else
tma2
pha
lda #BANK(fake_bram1)
tam2
tii fake_bram1,$6000,$800
pla
tam2
endif
.got_slot: jsr bm_verify_mpr3 ; Verify the BRAM image.
beq .slot_info ; Is it OK?
jsr bm_format_mpr3 ; Blank the slot.
.slot_info: ldx #2 ; Save BRAM info.
jsr tos_bram_info
; Has the mode just changed?
.new_mode: ldx tos_bram_mode ; Lookup which side has focus.
lda .tbl_focus_side,x
sta tos_bram_focus
lda .tbl_min_choice,x ; Lookup minimum selection.
sta tos_bram_least + 0 ; Set minimum selection.
sta tos_bram_least + 2
sta tos_bram_chosen + 0 ; Set current selection.
sta tos_bram_chosen + 2
cpx #BRAM_DEL ; Delete File mode?
beq .show_title
ldx #2
.calc_minimum: lda #8 ; Start at the last file
cmp tos_bram_files,x ; shown on the screen so
bcc .set_minimum ; scrolling is immediate.
lda tos_bram_files,x
.set_minimum: sta tos_bram_least,x ; Set minimum selection.
sta tos_bram_chosen,x ; Set current selection.
dex
dex
bpl .calc_minimum
.show_title: lda tos_bram_mode ; Lookup which title to display.
asl a
tay
ldx tbl_bram_title + 0,y
lda tbl_bram_title + 1,y
jsr tos_print_msg
; Redraw the menu screen to reflect changes.
.show_help: ldx tos_bram_mode ; Lookup which help to display.
ldy .tbl_focus_side,x ; Is there a file selected on
lda tos_bram_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_bram_help + 0,y
lda tbl_bram_help + 1,y
jsr tos_print_msg
; Display contents of BRAM_BANK.
.show_bram: ldx tos_bram_mode
cpx #BRAM_DEL
bne .bram_box_color
stz tos_hilite_idx ; Reset hilite pulsing.
.bram_box_color:lda .tbl_box_lhs,x
jsr tos_set_pen
PUTS msg_bram_lhs
lda #BRAM_BANK
tam3
ldx #0
jsr tos_bram_show
; Display contents of SLOT_BANK.
lda tos_bram_mode
cmp #BRAM_DEL
bne .show_slot
PUTS msg_blank_rhs
bra .wait_input
.show_slot: ldx tos_bram_mode
lda .tbl_box_rhs,x
jsr tos_set_pen
inc tos_bram_slot ; Show slot from '1' not '0'.
PUTS msg_bram_rhs
dec tos_bram_slot
lda #SLOT_BANK
tam3
ldx #2
jsr tos_bram_show
;
.wait_input: stz joytrg
.wait_loop: jsr wait_vsync_usb ; Wait, but check for USB.
lda joytrg
beq .wait_loop
bit #JOY_SEL
beq .same_menu
jmp tos_info_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_bram_mode
inc a
and #3
sta tos_bram_mode
jmp .new_mode
; Change Save Slot.
.prev_slot: lda tos_bram_slot
dec a
and #7
sta tos_bram_slot
jmp .new_slot
.next_slot: lda tos_bram_slot
inc a
and #7
sta tos_bram_slot
jmp .new_slot
; Change Selected File.
.prev_file: clx
ldy #2
.prev_loop: lda tos_bram_chosen,x ; Already at minimum selection?
cmp tos_bram_least,x
bne .check_other
; lda tos_bram_files,x ; Wrap around to end selection.
bra .set_prev_file
.check_other: cmp tos_bram_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_bram_chosen + 2
pla
sta tos_bram_chosen + 0
jmp .show_bram
.next_file: clx
ldy #2
.next_loop: lda tos_bram_chosen,x ; Already at maximum selection?
cmp tos_bram_files,x
bne .inc_next_file
lda tos_bram_chosen,y ; Is the other side on maximum?
cmp tos_bram_files,y
; lda tos_bram_least,x ; Wrap around to 1st selection.
; bcs .set_next_file
lda tos_bram_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_bram_mode
asl a
tax
jsr .vector
jmp tos_bram_menu2
.vector: jmp [.tbl_funcs,x]
.tbl_funcs: dw func_bram_save
dw func_bram_swap
dw func_bram_load
dw func_bram_del
.tbl_box_lhs: db 1,1,0,0 ; Palette for box per mode.
.tbl_box_rhs: db 0,1,1,0 ; Palette for box per mode.
.tbl_focus_side:db 0,4,2,0 ; Focused side per mode.
.tbl_min_choice:db 0,0,0,1 ; Minimum choice per mode.
; ***************************************************************************
; ***************************************************************************
;
; tos_bram_info - Save the info after a verify for later display.
;
; N.B. There can be a maximum of 126 files in the 2KB of BRAM.
;
tos_bram_info: lda <__bl ; Are there any BRAM files?
sta tos_bram_files + 0,x
stz tos_bram_files + 1,x
bne .calc
ldy #<2030 ; If not, then maximum free.
lda #>2030
bra .save
.calc: sec ; Calc amount of free memory.
lda #<($6800 - $02)
sbc <__bp + 0
tay
lda #>($6800 - $02)
sbc <__bp + 1
bcs .save
cla ; No memory free.
cly
.save: sta tos_bram_free + 1,x ; Save amount of free memory.
tya
sta tos_bram_free + 0,x
rts
; ***************************************************************************
; ***************************************************************************
;
; tos_bram_show - Display the BRAM files in the current bank.
;
; N.B. There can be a maximum of 126 files in the 2KB of BRAM.
;
tos_bram_show: lda tos_bram_chosen,x ; Decide which file to display
sta tos_bram_choice ; at the top of the box.
sec
sbc #7
bcs .first_to_show
lda #1
.first_to_show: sta tos_bram_first
.test_focus: lda #1
sta tos_bram_hilite ; Set hilite color to pulsing.
lda tos_bram_mode ; Only hilite a file in Delete.
cmp #$3
beq .first_in_bram
stz tos_bram_hilite ; Set hilite color to normal.
stz tos_bram_choice ; Do not hilite any file.
.first_in_bram: ldy #<$6010 ; Start after the BRAM signature.
lda #>$6010
stz tos_bram_index
.file_loop: inc tos_bram_index ; Increment file index.
sty <__bp + 0 ; Update file pointer.
sta <__bp + 1
ldy #1 ; End of file chain?
lda [__bp],y
sta tos_temp_length + 1 ; Size to display (hi-byte).
tay
ora [__bp]
bne .not_eof
.bram_corrupt: nop
jmp .rest ; EOF, remaining slots blank.
.not_eof: lda [__bp]
sta tos_temp_length + 0 ; Size to display (lo-byte).
.too_small: cmp #$10 ; Size < $0010 (min size)?
bcs .too_large
cpy #$00
beq .bram_corrupt
.too_large: cpy #$20 ; Size > $1FFF (max size)?
bcs .bram_corrupt
clc ; Calc address of next file.
adc <__bp + 0
say
adc <__bp + 1
cmp #$68 ; Is it beyond BRAM Size?
bcs .bram_corrupt
ldx tos_bram_index ; Skip off-screen files.
cpx tos_bram_first
bcc .file_loop
phy ; Preserve next file pointer.
pha
cla ; Select the palette to use
ldx tos_bram_index ; for this file entry.
cpx tos_bram_choice
bne .file_color
lda tos_bram_hilite
.file_color: jsr tos_set_pen
if 0
ldx #<msg_small_index ; Display bottom 2 digits
ldy #>msg_small_index
lda tos_bram_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_bram_index
cmp tos_bram_choice
bne .show_lhs_arrow
ldx #<msg_bram_larrow
ldy #>msg_bram_larrow
.show_lhs_arrow:tya
jsr tos_print_msg
.file_name: lda #$06 ; 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_bram_fname + 0 ; Save the addr of the selected
sty tos_bram_fname + 1 ; filename.
.show_name: PUTS msg_bram_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_bram_save - Copy BRAM to SD card slot.
;
func_bram_save: PUTS cls_copy_bram ; Confirm the operation.
inc tos_bram_slot ; Show slot from '1' not '0'.
PUTS .msg_warning
dec tos_bram_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_copy_bram ; Inform the user.
PUTS msg_save_bram
tma2 ; Copy the contents of BRAM
pha ; to the SLOT image in memory.
lda #BRAM_BANK
tam2
lda #SLOT_BANK
tam3
tii $4000, $6000, 2048
pla
tam2
jsr tos_save_slot ; Save the SLOT image to SD.
beq .finished
.failed: PUTS msg_fail_bram
.result: PUTS msg_press_a_key
jsr wait_for_key
.finished: rts
.msg_warning: db "%r"
dw tos_bram_slot
db "%y",11
db " Please press %p1RUN%p0 to confirm that you",$0A
db " want to copy BRAM 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_save_bram: db " Saving BRAM to SD card ...",$0A,$0A,0
msg_fail_bram: db " BRAM save failed!",$0A,$0A,0
; ***************************************************************************
; ***************************************************************************
;
; func_bram_swap - Swap BRAM with SD card slot.
;
func_bram_swap: PUTS cls_swap_bram
inc tos_bram_slot ; Show slot from '1' not '0'.
PUTS .msg_warning
dec tos_bram_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_swap_bram ; Inform the user.
PUTS msg_save_bram
tma2 ; Swap the contents of BRAM
pha ; to the SLOT image in memory.
lda #BRAM_BANK
tam2
lda #SLOT_BANK
tam3
stz <__ax + 0
stz <__bx + 0
lda #$40
sta <__ax + 1
lda #$60
sta <__bx + 1
cly
.swap_loop: lda [__ax],y
tax
lda [__bx],y
sta [__ax],y
txa
sta [__bx],y
iny
bne .swap_loop
inc <__ah
inc <__bh
bbr3 <__bh,.swap_loop
pla
tam2
jsr tos_save_slot ; Save the SLOT image to SD.
bne .failed
lda #BRAM_BANK ; Copy the contents of BRAM
tam3 ; image from memory to BRAM.
jsr bm_bank_to_bram
bra .finished
.failed: PUTS msg_fail_bram
.result: PUTS msg_press_a_key
jsr wait_for_key
.finished: rts
.msg_warning: db "%r"
dw tos_bram_slot
db "%y",11
db " Please press %p1RUN%p0 to confirm that you",$0A
db " want to swap BRAM with SD Slot #%hu!",$0A
db "%y",24
db "%x",12
db "%p5RUN%p6:Confirm swap",$0A
db "%x",13
db "%p5",30,31,"%p6:Cancel swap",$0A
db "%p0%y",14,0
; ***************************************************************************
; ***************************************************************************
;
; func_bram_load - Copy SD card slot to BRAM.
;
func_bram_load: PUTS cls_copy_slot
inc tos_bram_slot ; Show slot from '1' not '0'.
PUTS .msg_warning
dec tos_bram_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: lda #SLOT_BANK ; Copy the contents of SLOT
tam3 ; image from memory to BRAM.
jsr bm_bank_to_bram
rts
.msg_warning: db "%r"
dw tos_bram_slot
db "%y",11
db " Please press %p1RUN%p0 to confirm that you",$0A
db " want to copy SD Slot #%hu to BRAM!",$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
; ***************************************************************************
; ***************************************************************************
;
; func_bram_del - Delete a file from BRAM.
;
func_bram_del: lda tos_bram_files ; Are there any files in BRAM?
bne .wipe
rts
.wipe: PUTS cls_wipe_file
lda tos_bram_fname + 0 ; Get the addr of the selected
sta <__di + 0 ; filename.
lda tos_bram_fname + 1
sta <__di + 1
PUTS .msg_warning
.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