forked from jbrandwood/teos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_hucard.s
342 lines (265 loc) · 6.19 KB
/
menu_hucard.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
; ***************************************************************************
; ***************************************************************************
;
; menu_hucard.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)
;
; ***************************************************************************
; ***************************************************************************
; ***************************************************************************
; ***************************************************************************
;
;
;
msg_main_title: db "%>%p5%xl",0
db $0C
db " RUN HuCARD"
db "%<%p0"
db $0A,$0A,$0A,0
msg_main_help: db "%p5"
db "%y",24
if HIRES
db "%x",9 ; 480 wide
endif
; db "----------------------------------------"
db " SEL%p6:Chg Menu%p5 <>%p6:Chg Page%p5 \\|%p6:Chg File%p5",$0A
if HIRES
db "%x",9 ; 480 wide
endif
db " "
db 30,31
; db "%p6:Parent%p5 I%p6:Select%p5",$0A
db "%p6:Parent%p5 "
db 28,29
db "%p6:Select File or Folder%p5",$0A,0
msg_main_pageno:db "%p5"
db "%y",1
if HIRES
db "%x",26+18 ; 480 wide
else
db "%x",26 ; 320 wide
endif
db "%s"
db "%r"
dw tos_show_page
db "%hu of "
db "%r"
dw tos_num_pages
db "%hu"
db "%p0"
db $0A,$0A,0
str_page: db " Page ",0
msg_empty_dir: db "%p2 This directory is empty!%p0",0
;
;
;
tos_hucard_menu:
if HIRES
ldx #<video_mode_480 ; Change to hi-res screen.
lda #>video_mode_480
jsr tos_screen_mode
endif
PUTS msg_main_title
PUTS msg_main_help
jsr f32_clear_cache ; Don't assume that it's valid!
ldx #15 ; Is this the same SDcard as
.cmp_sdcard: lda sdc_cid_value,x ; the last time?
cmp tos_cur_cardid,x
bne .new_sdcard
dex
bpl .cmp_sdcard
.old_sdcard: tii tos_cur_folder, f32_dir_cluster, 4
bra .new_directory
.new_sdcard: tii sdc_cid_value, tos_cur_cardid, 16
stz tos_cur_depth
tai tos_zero, tos_cur_page, (tos_cur_file - tos_cur_page) * 2
jsr f32_select_root ; New card resets to root dir.
.new_directory: tii f32_dir_cluster, tos_cur_folder, 4
jsr tos_scan_dir ; Find selectable entries.
.new_page: lda #FILES_PER_PAGE ; Calc file index of the 1st
sta <__bl ; entry on this page.
ldx tos_cur_depth
lda tos_cur_page,x
sta <__al
stz <__ah
jsr tos_mul8u
jsr tos_fastfwd_dir ; Skip the directory forward.
ldx tos_cur_depth ; Get the current page # to
lda tos_cur_page,x ; show onscreen.
ldy tos_num_pages
beq .skip0
inc a
.skip0: sta tos_show_page ; Move where "Page" is shown
cmp #10 ; depending upon if either
lda #<str_page ; value is single or double
ldx #>str_page ; digits.
bcc .skip1
inc a
bne .skip1
inx
.skip1: cpy #10
bcc .skip2
inc a
bne .skip2
inx
.skip2: sta <__di + 0
stx <__di + 1
; PUTS msg_main_title
; PUTS msg_main_help
PUTS msg_main_pageno
ldx tos_num_pages ; Any files in this directory?
beq .empty_dir
jsr tos_show_files ; Display the page of files.
ldx tos_cur_depth ; Make sure that the selection
lda tos_cur_file,x ; is available on this page.
cmp tos_num_files
bcc .selection_ok
lda tos_num_files
dec a
sta tos_cur_file,x
.selection_ok: jsr tos_set_hilite
.new_file: bra .wait_input
.empty_dir: PUTS msg_empty_dir
.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
if HIRES
ldx #<video_mode_320 ; Change to medium-res screen.
lda #>video_mode_320
jsr tos_screen_mode
endif
jmp tos_bram_menu
.same_menu: ldx tos_num_pages
beq .back_only
bit #JOY_L
bne .prev_page
bit #JOY_R
bne .next_page
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 .parent
; Change Page in current directory.
.prev_page: ldx tos_cur_depth
lda tos_cur_page,x
bne .dec_page
lda tos_num_pages
.dec_page: dec a
.chk_page: cmp tos_cur_page,x
beq .wait_input
sta tos_cur_page,x
bsr .clr_child_pos
jmp .new_page
.next_page: ldx tos_cur_depth
lda tos_cur_page,x
inc a
cmp tos_num_pages
bcc .chk_page
cla
bra .chk_page
; Change File in current directory.
.prev_file: ldx tos_cur_depth
lda tos_cur_file,x
bne .dec_file
lda tos_num_files
.dec_file: dec a
.chk_file: cmp tos_cur_file,x
beq .wait_input
pha
jsr tos_clr_hilite
ldx tos_cur_depth
pla
sta tos_cur_file,x
jsr tos_set_hilite
bsr .clr_child_pos
jmp .new_file
.next_file: ldx tos_cur_depth
lda tos_cur_file,x
inc a
cmp tos_num_files
bcc .chk_file
cla
bra .chk_file
;
.clr_child_pos: ldx tos_cur_depth ; Reset position in child dir.
stz tos_cur_page + 1,x ; Done here so that reentering
stz tos_cur_file + 1,x ; the child dir keeps position.
rts
.invalid: jmp .wait_input
;
.select: ldx tos_cur_depth
lda tos_cur_file,x
tay
asl a
asl a
tax
lda tos_file_type,y
beq .file
.directory: ldy tos_cur_depth ; Limit directory depth to 32.
iny
cpy #32
beq .invalid
sty tos_cur_depth
cly
.dir_loop: lda tos_1st_cluster,x
sta f32_dir_cluster,y
inx
iny
cpy #4
bne .dir_loop
jsr f32_dir_chosen
beq .changed
stz tos_cur_depth
jsr f32_select_root
.changed: jmp .new_directory
;
.parent: stw #dotdot,__ax ; Find the ".." directory entry.
jsr f32_find_name
bne .invalid
jsr f32_change_dir
bne .invalid
dec tos_cur_depth
jmp .new_directory
;
.file: cly ; Copy file's initial cluster
.file_loop: lda tos_1st_cluster,x ; and total length.
sta f32_fil_cluster,y
lda tos_file_length,x
sta f32_file_length,y
inx
iny
cpy #4
bne .file_loop
jsr f32_file_chosen ; Open the file using only the
bne .load_fail ; cluster/length, not a name.
PUTS msg_main_title
jsr tos_load_hucard ; Load the current file as
beq .load_good ; a HuCard image.
.load_fail: PUTS file_failed
bra .hang2
.load_good: jmp tos_exec_hucard
.hang:
.hang2: bra .hang2
file_loaded: db " File loaded!",$0A,0
file_failed: db " File error!",$0A,0
dotdot: db "..",0
;
;
;
.hang: jsr wait_vsync
bra .hang