forked from jbrandwood/teos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_init.s
649 lines (476 loc) · 11.2 KB
/
menu_init.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
; ***************************************************************************
; ***************************************************************************
;
; menu_init.s
;
; TEOS Menu Screens
;
; Copyright John Brandwood 2019.
;
; 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)
;
; ***************************************************************************
; ***************************************************************************
; ***************************************************************************
; ***************************************************************************
;
;
;
wait_for_key: stz joytrg
.wait: lda joytrg
and #JOY_B1 + JOY_B2
beq .wait
rts
; ***************************************************************************
; ***************************************************************************
;
;
;
msg_wait_init: db "%>%p5"
db $0C
db " INITIALIZING...%<%p0"
db $0A,$0A,$0A,0
tos_menu_init: ldy #4 ; Decompress the 1st font file.
jsr tos_decompress
jsr upload_font8x8
ldy #8 ; Decompress the 2nd font file.
jsr tos_decompress
jsr upload_font8x16
jsr tos_init_crc16 ; Create CRC16 lookup table.
jsr tos_init_crc32 ; Create CRC32 lookup table.
PUTS msg_wait_init
; jsr show_mpr
; inc tos_tty_ypos
php
TED_CFG_FPGA
; Save Tennokoe Bank SRAM?
jsr f32_mount_vol ; Init SDcard and mount drive.
stx $2F00
cpx #$00
beq .stage1_ok
PUTS fat32_nomount
.hang: jmp .hang
.stage1_ok: PUTS fat32_mounted
; Save Tennokoe Bank SRAM?
lda tos_tennokoe ; Did we just run Tennokoe Bank?
beq .skip_tbank
stz tos_tennokoe
jsr tos_save_tbank ; Save the Tennokoe Bank SRAM.
.skip_tbank: nop
;
if 0
PUTS msg_press_a_key
jsr wait_for_key
jsr mb1_read_info
PUTS msg_press_a_key
jsr wait_for_key
endif
;
if 0
PUTS msg_wait_init
lda #BRAM_BANK ; Set up the directory bank.
tam3
lda #<$6000
ldx #>$6000
jsr show_page
PUTS msg_press_a_key
jsr wait_for_key
PUTS msg_wait_init
lda #BRAM_BANK + 15 ; Set up the directory bank.
tam3
lda #<$7F80
ldx #>$7F80
jsr show_page
PUTS msg_press_a_key
jsr wait_for_key
PUTS msg_wait_init
lda #BRAM_BANK + 16 ; Set up the directory bank.
tam3
lda #<$6000
ldx #>$6000
jsr show_page
PUTS msg_press_a_key
jsr wait_for_key
endif
if 0
lda #BRAM_BANK
tam3
jsr bm_bram_to_bank
PUTS msg_wait_init
lda #<$6000
ldx #>$6000
jsr show_page
PUTS msg_press_a_key
jsr wait_for_key
endif
; jsr tos_save_test
; beq .test_ok
;
; PUTS test_failed
;.hang2: jmp .hang2
;
;.test_ok: PUTS test_saved
;
; lda #<sdc_block_cnt
; ldx #>sdc_block_cnt
; jsr show_8bytes
; jsr wait_for_key
; jsr tos_load_test
; If emulating, then use the volume ID as the SDcard CID.
if REALHW
else
tii BS_BootSig32, sdc_cid_value, 16
endif
;
;.stage2: jsr wait_for_key
jmp tos_hucard_menu
msg_press_a_key:db $0A
db " Press%p1"
db 28,29
db "%p0 to continue.",$0A,0
test_failed: db " Test write failed!",$0A,0
test_saved: db " Test write OK!",$0A,0
fat32_mounted: db " FAT32 partition mounted.",$0A,0
fat32_nomount: db " FAT32 partition mount failed!",$0A,0
; ***************************************************************************
; ***************************************************************************
;
;
;
show_mpr: tma0
sta mpr + 0
tma1
sta mpr + 1
tma2
sta mpr + 2
tma3
sta mpr + 3
tma4
sta mpr + 4
tma5
sta mpr + 5
tma6
sta mpr + 6
tma7
sta mpr + 7
lda #<mpr
ldx #>mpr
jmp show_8bytes
.bss
mpr: ds 8
.code
; ***************************************************************************
; ***************************************************************************
;
; show_page - show a 16-bye hex dump
;
show_page: ldy #16
.loop: phy
bsr show_8bytes
clc
adc #$08
bcc .skip
inx
.skip: ply
dey
bne .loop
rts
show_8bytes: php
sei
pha
phx
sta <view + 0
stx <view + 1
cly
.line_loop: st0 #VDC_MAWR
lda tos_tty_ypos
lsr a
tax
cla
ror a
sta VDC_DL
stx VDC_DH
st0 #VDC_VWR
st1 #$20
st2 #$01
phy
ldx #1
.addr_loop: lda <view,x
lsr a
lsr a
lsr a
lsr a
ora #$30
cmp #$3A
bcc .addr_lo
adc #6
.addr_lo: sta VDC_DL
st2 #$01
lda <view,x
and #$0F
ora #$30
cmp #$3A
bcc .addr_hi
adc #6
.addr_hi: sta VDC_DL
st2 #$01
dex
bpl .addr_loop
st1 #$3A
st2 #$01
st1 #$20
st2 #$01
.byte_loop: lda [view],y
lsr a
lsr a
lsr a
lsr a
ora #$30
cmp #$3A
bcc .skip_lo
adc #6
.skip_lo: sta VDC_DL
st2 #$01
lda [view],y
and #$0F
ora #$30
cmp #$3A
bcc .skip_hi
adc #6
.skip_hi: sta VDC_DL
st2 #$01
iny
tya
bit #$00 ; $01 for 16-bits-per-block
bne .skip_space
st1 #$20
st2 #$01
.skip_space: bit #$07 ; $0F for 16-bytes-per-line
bne .byte_loop
ply
.char_loop: lda [view],y
cmp #$20
bcc .non_ascii
cmp #$7F
bcc .show_char
.non_ascii: lda #'.'
.show_char: sta VDC_DL
st2 #$01
iny
tya
bit #$07 ; $0F for 16-bytes-per-line
bne .char_loop
inc tos_tty_ypos
cpy #$08 ; $10 for 16-bytes-per-line
beq .finished
jmp .line_loop
.finished: lda <vdc_reg
sta VDC_AR
plx
pla
plp
rts
; ***************************************************************************
; ***************************************************************************
;
; tos_tbank_file - Select the TENNOKOE.BIN file.
;
; Args: tos_bram_slot = Pointer to directory entry in cache.
; Uses: __bp = Pointer to directory entry in cache.
;
; Returns: X = F32_OK (and Z flag) or an error code.
;
tos_tbank_file: jsr tos_chdir_tbed ; Select "/TBED/" directory.
bne .exit
lda #<.tennokoe_name ; Locate the named file in
ldy #>.tennokoe_name ; the current directory.
sta <__ax + 0
sty <__ax + 1
jsr f32_find_name
bne .exit
jsr f32_open_file ; Open file and create
bne .exit ; fragment map for I/O.
ldx #TOS_WRONG_SIZE ; Return error code.
lda f32_file_length + 1 ; Check that the file is 8KB.
cmp #$20
bne .close
lda f32_file_length + 3
ora f32_file_length + 2
ora f32_file_length + 0
bne .close
lda #8192 / 512
sta <__ax + 0 ; Lo-byte of # blocks in file.
stz <__ax + 1 ; Hi-byte of # blocks in file.
lda #$0F ; Map in TED2 512KB bank 0.
sta TED_BASE_ADDR + TED_REG_MAP
sta sdc_data_bank
stz <sdc_data_addr + 0 ; Load into $6000-$7FFF.
lda #$60
sta <sdc_data_addr + 1
lda #$40 ; RAMROM HuCard bank $40.
tam3
ldx #TOS_OK
.exit: txa ; Set flags for result.
rts
.close: jmp f32_close_file ; Close the file & set N & Z.
.tennokoe_name: db "TENNOKOE.BIN",0
; ***************************************************************************
; ***************************************************************************
;
; tos_load_tbank - Load the TENNOKOE.BIN file into HuCard bank $40.
;
tos_load_tbank: jsr tos_tbank_file ; Select "/TBED/TENNOKOE.BIN".
bne .failed
PUTS .loading
jsr f32_file_read ; Load the file into HuCard.
ldy #<.load_ok
lda #>.load_ok
jsr f32_close_file ; Close the file & set N & Z.
beq .finished
.failed: ldy #<.load_bad
lda #>.load_bad
.finished: phx ; Preserve result code.
sxy
jsr tos_print_msg
plx ; Restore result code.
lda #$0F ; Map in TED2 512KB bank 0.
sta TED_BASE_ADDR + TED_REG_MAP
lda #$40 ; RAMROM HuCard bank $40.
tam3
tma2 ; Use the BRAM bank as storage
pha ; to see if the user makes any
lda #BRAM_BANK ; changes to the Tennokoe Bank
tam2 ; SRAM contents.
txa ; Was the SRAM loaded from
beq .copy ; SD card?
tai tos_empty, $6000, $2000 ; Clear SRAM.
.copy: tii $6000, $4000, $2000 ; Copy SRAM to see changes.
pla ; Restore TED2 bank.
tam2
lda #$4F ; Set 512KB HuCard mapping.
sta TED_BASE_ADDR + TED_REG_MAP
lda #$40
tam3
phx
PUTS msg_press_a_key
jsr wait_for_key
plx
rts
.loading: db " Loading Tennokoe Bank SRAM from SD ...",$0A,$0A,0
.load_ok: db " SRAM loaded OK!",$0A,$0A
db " When you have finished, please remember to press",$0A
db " the RESET button on your Turbo EverDrive so that",$0A
db " your file chest changes are saved to the SD card!",$0A,$0A,0
.load_bad: db " Unable to read file!",$0A,0
; ***************************************************************************
; ***************************************************************************
;
; tos_save_tbank - Save the TENNOKOE.BIN file from HuCard bank $40.
;
tos_save_tbank: lda #$0F ; Map in TED2 512KB bank 0.
sta TED_BASE_ADDR + TED_REG_MAP
lda #$40 ; RAMROM HuCard bank $40.
tam3
tma2 ; Map in the copy of the SRAM
pha ; that we made before running
lda #BRAM_BANK ; the HuCard.
tam2
lda #$40 ; Did the Tennokoe Bank HuCard
sta .self_mod1 + 2 ; user change the contents of
lda #$60 ; the SRAM?
sta .self_mod2 + 2
clx
.loop:
.self_mod1: lda $4000,x ; Compare the 8KB of SRAM.
.self_mod2: cmp $6000,x
bne .save_sram
inx
bne .loop
inc .self_mod1 + 2
inc .self_mod2 + 2
bpl .loop
pla ; Don't save the SRAM if it
tam2 ; is unchanged.
txa ; Return TOS_OK.
bra .finished
.save_sram: pla ; Save the Tennokoe Bank SRAM
tam2 ; to SD card.
.retry: PUTS msg_wait_init ; Inform the user.
PUTS .msg_saving
jsr tos_tbank_file ; Select "/TBED/TENNOKOE.BIN".
bne .failed
if 0
ldx #F32_ERR_DSK_RD ; For testing the messages.
else
jsr f32_file_write ; Save the file from HuCard.
endif
jsr f32_close_file ; Close the file & set N & Z.
beq .success
;
.failed: PUTS .msg_failed ; Warn the user.
.wait1_input: stz joytrg ; Wait for input.
.wait1_loop: jsr wait_vsync
lda joytrg
beq .wait1_loop
bit #JOY_RUN
bne .danger
bit #JOY_B1
beq .wait1_input
.want_retry: PUTS msg_wait_init
bra .retry
;
.danger: PUTS .msg_danger
.wait2_input: stz joytrg
.wait2_loop: jsr wait_vsync
lda joytrg
beq .wait2_loop
bit #JOY_B1
bne .want_retry
bit #JOY_SEL
beq .wait2_input
bra .finished
;
.success: PUTS .msg_save_ok
PUTS msg_press_a_key
.wait0_input: stz joytrg ; Wait for input.
.wait0_loop: jsr wait_vsync
lda joytrg
beq .wait0_loop
bit #JOY_B1
beq .wait0_input
bra .finished
.finished: phx
lda #$4F ; Set 512KB mapping for HuCard.
sta TED_BASE_ADDR + TED_REG_MAP
lda #$40
tam3
plx
rts
.msg_saving: db " Saving Tennokoe Bank SRAM to SD ...",$0A,$0A,0
.msg_save_ok: db " SRAM saved OK!",$0A,0
.msg_failed: db "%p5"
db "%y",24
; db "----------------------------------------"
db " "
db 28,29
db "%p6:Retry saving the SRAM to SD card%p5",$0A
db " RUN%p6:Continue without saving SRAM",$0A
db "%p0"
db "%y",5
db " FAILED TO SAVE SRAM TO SD CARD!",$0A,$0A
; db "----------------------------------------"
db " If you continue, then you will lose",$0A
db " any changes that you just made to",$0A
db " the contents of the Tennokoe Bank",$0A
db " file chests.",$0A,0
.msg_danger: db $0A,$0A
db " Are you really sure?",$0A,$0A
db " Please press %p1SEL%p0 to confirm that you",$0A
db " want to lose all of the changes that",$0A
db " you made to the Tennokoe Bank SRAM!",$0A
db "%y",25
db "%p5"
db " SEL%p6:Continue without saving SRAM",$0A,0
; db " you made while in the Tennokoe Bank!",$0A