Skip to content

Commit 0fc62ef

Browse files
enable usb by default and update to new fatdrvce api
Signed-off-by: mateoconlechuga <matthewwaltzis@gmail.com>
1 parent c6f1b2d commit 0fc62ef

File tree

4 files changed

+87
-75
lines changed

4 files changed

+87
-75
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ clean:
7272
rm -f $(BIN_ENGLISH) $(BIN_FRENCH) $(BIN_DUTCH) $(RELEASE_ZIP)
7373
rm -rf $(RELEASE_DIR)
7474

75-
.PHONY: all english french dutch clean release
75+
.PHONY: all english french dutch compress clean release

include/macros.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ setting_list_count := 1
245245
setting_enable_usb := 2
246246

247247
settings_default := (1 shl setting_show_battery) or (1 shl setting_enable_shortcuts) or (1 shl setting_delete_confirm) or (1 shl setting_basic_indicator)
248-
settings_adv_default := (1 shl setting_special_directories)
248+
settings_adv_default := (1 shl setting_special_directories) or (1 shl setting_enable_usb)
249249

250250
; cesium flags
251251

src/libload.asm

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ libload_load:
4343
ld hl,lib_msddrvce
4444
ld bc,lib_msddrvce.size
4545
ldir
46-
ld a,$c0
46+
ld a,$C0
4747
ld (libload_libload),a
4848
ld (libload_usbdrvce),a
4949
ld (libload_msddrvce),a
@@ -99,7 +99,7 @@ lib_usb_ResetDevice:
9999

100100
; msddrvce library functions
101101
libload_msddrvce:
102-
db $C0,"MSDDRVCE",0,0
102+
db $C0,"MSDDRVCE",0,1
103103

104104
lib_msddrvce_tbl:
105105
lib_msd_Open:
@@ -117,37 +117,43 @@ lib_msd_FindPartitions:
117117

118118
; fatdrvce library functions
119119
libload_fatdrvce:
120-
db $C0,"FATDRVCE",0,0
120+
db $C0,"FATDRVCE",0,2
121121

122122
lib_fatdrvce_tbl:
123-
lib_fat_Init:
123+
lib_fat_Open:
124124
jp 0
125-
lib_fat_Deinit:
125+
lib_fat_Close:
126126
jp 3
127-
lib_fat_DirList:
127+
lib_fat_OpenDir:
128128
jp 6
129-
lib_fat_Open:
129+
lib_fat_ReadDir:
130+
jp 9
131+
lib_fat_CloseDir:
130132
jp 12
131-
lib_fat_Close:
133+
lib_fat_OpenFile:
132134
jp 15
133-
lib_fat_SetSize:
135+
lib_fat_CloseFile:
134136
jp 18
135-
lib_fat_SetAttrib:
137+
lib_fat_SetFileSize:
138+
jp 21
139+
lib_fat_GetFileSize:
136140
jp 24
137-
lib_fat_GetAttrib:
141+
lib_fat_SetAttrib:
138142
jp 27
139-
lib_fat_SetPos:
143+
lib_fat_GetAttrib:
140144
jp 30
141-
lib_fat_GetPos:
145+
lib_fat_SetFileBlockOffset:
142146
jp 33
143-
lib_fat_Read:
147+
lib_fat_GetFileBlockOffset:
144148
jp 36
145-
lib_fat_Write:
149+
lib_fat_ReadFile:
146150
jp 39
147-
lib_fat_Create:
151+
lib_fat_WriteFile:
148152
jp 42
149-
lib_fat_Delete:
153+
lib_fat_Create:
150154
jp 45
155+
lib_fat_Delete:
156+
jp 48
151157

152158
ld hl,(ti.asm_prgm_size)
153159
ld (libload_unload.size),hl
@@ -178,9 +184,11 @@ lib_fatdrvce:
178184
jp 0
179185
jp 3
180186
jp 6
187+
jp 9
181188
jp 12
182189
jp 15
183190
jp 18
191+
jp 21
184192
jp 24
185193
jp 27
186194
jp 30
@@ -189,6 +197,7 @@ lib_fatdrvce:
189197
jp 39
190198
jp 42
191199
jp 45
200+
jp 48
192201
.size := $ - lib_fatdrvce
193202

194203
; remove loaded libraries from usermem

src/usb.asm

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ msd_partitions:
4242
rb 8*10
4343

4444
fat_struct:
45-
rb 1041
45+
rb 768
46+
fat_dir_struct:
47+
rb 32
4648
fat_file_struct:
4749
rb 64
4850
fat_path:
@@ -217,22 +219,24 @@ usb_selection := $ - 1
217219
ld h,8 ; partition structure is 8 bytes
218220
mlt hl
219221
ld bc,msd_partitions
220-
add hl,bc ; pointer to first (4 bytes) then last (4 bytes)
221-
ld iy,fat_struct
222-
lea de,iy + 9
223-
ld bc,8
224-
ldir
225-
ld hl,lib_msd_Read
226-
ld (iy + 0),hl ; read
227-
ld hl,lib_msd_Write
228-
ld (iy + 3),hl ; write
222+
add hl,bc ; pointer to first lba (4 bytes)
223+
ld de,(hl)
224+
inc hl
225+
inc hl
226+
inc hl
227+
ld hl,(hl)
228+
push hl
229+
push de
229230
ld hl,msd_struct
230-
ld (iy + 6),hl ; usr
231-
ld iy,ti.flags
232-
ld bc,fat_struct
233-
push bc
234-
call lib_fat_Init
235-
pop bc
231+
push hl
232+
ld hl,lib_msd_Write
233+
push hl
234+
ld hl,lib_msd_Read
235+
push hl
236+
ld hl,fat_struct
237+
push hl
238+
call lib_fat_Open
239+
pop bc, bc, bc, bc, bc, bc
236240
ld iy,ti.flags
237241
compare_hl_zero
238242
jr z,.fat_init_completed
@@ -288,52 +292,48 @@ fat_get_directory_listing:
288292
jr nz,.notroot ; if at root show exit directory
289293

290294
.notroot:
291-
ld bc,0 ; don't skip any
292-
push bc
293-
ld b,2 ; allow for maximum of 512 directories
294-
push bc
295-
ld bc,item_location_base ; place to store
296-
push bc
297-
ld bc,1 ; get directories first
295+
ld bc,fat_dir_struct
298296
push bc
299297
ld bc,fat_path ; path
300298
push bc
301299
ld bc,fat_struct ; global fat state
302300
push bc
303-
call lib_fat_DirList
301+
call lib_fat_OpenDir
304302
ld iy,ti.flags
305-
pop bc,bc,bc,bc,bc,bc
306-
inc hl
303+
pop bc, bc, bc
307304
compare_hl_zero
308-
dec hl
309-
jq z,.error
310-
ld (number_of_items),hl
305+
jq nz,.error
306+
ld hl,(number_of_items)
307+
.loop:
311308
ld bc,18 ; each entry is 18 bytes
312309
call ti._imulu
313310
ld de,item_location_base
314311
add hl,de
315-
.find_files:
316-
ld bc,0 ; don't skip any
317-
push bc
318-
ld b,3 ; allow for maximum of 768 files
319-
push bc
320312
push hl
321-
ld c,0 ; get files
322-
push bc
323-
ld bc,fat_path ; path
324-
push bc
325-
ld bc,fat_struct ; global fat state
313+
push hl
314+
ld bc,fat_dir_struct
326315
push bc
327-
call lib_fat_DirList
316+
call lib_fat_ReadDir
328317
ld iy,ti.flags
329-
pop bc,bc,bc,bc,bc,bc
330-
inc hl
318+
pop bc, bc
331319
compare_hl_zero
332-
dec hl
333-
jq z,.error
334-
ld bc,(number_of_items)
335-
add hl,bc
336-
ld (number_of_items),hl ; number of items in directory
320+
pop hl
321+
jq nz,.error
322+
ld a,(hl) ; check if name[0] = 0
323+
or a,a
324+
jr z,.return
325+
ld hl,(number_of_items)
326+
inc hl
327+
ld (number_of_items),hl
328+
ld de,768
329+
compare_hl_de
330+
jr nz,.loop
331+
.return:
332+
ld bc,fat_dir_struct
333+
push bc
334+
call lib_fat_CloseDir
335+
ld iy,ti.flags
336+
pop bc
337337
ret
338338
.error:
339339
xor a,a
@@ -428,20 +428,21 @@ usb_detach_only:
428428
jr z,.no_fat
429429
ld bc,fat_struct
430430
push bc
431-
call lib_fat_Deinit
432-
pop bc
431+
call lib_fat_Close
433432
ld iy,ti.flags
433+
pop bc
434434
.no_fat:
435435
ld a,(msd_enabled)
436436
or a,a
437437
jr z,.no_msd
438438
ld bc,msd_struct
439439
push bc
440440
call lib_msd_Close
441-
pop bc
442441
ld iy,ti.flags
442+
pop bc
443443
.no_msd:
444444
call lib_usb_Cleanup
445+
ld iy,ti.flags
445446
jp libload_unload
446447

447448
usb_detach: ; detach the fat library hooks
@@ -630,15 +631,17 @@ usb_open_tivar:
630631
ld hl,(item_ptr)
631632
.entry:
632633
call usb_append_fat_path
634+
ld bc,fat_file_struct
635+
push bc
636+
ld bc,0
637+
push bc
633638
ld bc,fat_path
634639
push bc
635640
ld bc,fat_struct
636641
push bc
637-
ld bc,fat_file_struct
638-
push bc
639-
call lib_fat_Open
642+
call lib_fat_OpenFile
640643
ld iy,ti.flags
641-
pop bc,bc,bc
644+
pop bc,bc,bc,bc
642645
compare_hl_zero
643646
jr nz,.error
644647
call usb_directory_previous
@@ -710,7 +713,7 @@ fat_file_read_sector:
710713
push bc
711714
ld bc,fat_file_struct
712715
push bc
713-
call lib_fat_Read
716+
call lib_fat_ReadFile
714717
ld iy,ti.flags
715718
pop bc,bc
716719
pop de
@@ -721,7 +724,7 @@ fat_file_read_sector:
721724
fat_file_close:
722725
ld bc,fat_file_struct
723726
push bc
724-
call lib_fat_Close
727+
call lib_fat_CloseFile
725728
ld iy,ti.flags
726729
pop bc
727730
ret

0 commit comments

Comments
 (0)