Skip to content

Commit

Permalink
enable usb by default and update to new fatdrvce api
Browse files Browse the repository at this point in the history
Signed-off-by: mateoconlechuga <matthewwaltzis@gmail.com>
  • Loading branch information
mateoconlechuga committed Dec 18, 2022
1 parent c6f1b2d commit 0fc62ef
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ clean:
rm -f $(BIN_ENGLISH) $(BIN_FRENCH) $(BIN_DUTCH) $(RELEASE_ZIP)
rm -rf $(RELEASE_DIR)

.PHONY: all english french dutch clean release
.PHONY: all english french dutch compress clean release
2 changes: 1 addition & 1 deletion include/macros.inc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ setting_list_count := 1
setting_enable_usb := 2

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)
settings_adv_default := (1 shl setting_special_directories)
settings_adv_default := (1 shl setting_special_directories) or (1 shl setting_enable_usb)

; cesium flags

Expand Down
43 changes: 26 additions & 17 deletions src/libload.asm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ libload_load:
ld hl,lib_msddrvce
ld bc,lib_msddrvce.size
ldir
ld a,$c0
ld a,$C0
ld (libload_libload),a
ld (libload_usbdrvce),a
ld (libload_msddrvce),a
Expand Down Expand Up @@ -99,7 +99,7 @@ lib_usb_ResetDevice:

; msddrvce library functions
libload_msddrvce:
db $C0,"MSDDRVCE",0,0
db $C0,"MSDDRVCE",0,1

lib_msddrvce_tbl:
lib_msd_Open:
Expand All @@ -117,37 +117,43 @@ lib_msd_FindPartitions:

; fatdrvce library functions
libload_fatdrvce:
db $C0,"FATDRVCE",0,0
db $C0,"FATDRVCE",0,2

lib_fatdrvce_tbl:
lib_fat_Init:
lib_fat_Open:
jp 0
lib_fat_Deinit:
lib_fat_Close:
jp 3
lib_fat_DirList:
lib_fat_OpenDir:
jp 6
lib_fat_Open:
lib_fat_ReadDir:
jp 9
lib_fat_CloseDir:
jp 12
lib_fat_Close:
lib_fat_OpenFile:
jp 15
lib_fat_SetSize:
lib_fat_CloseFile:
jp 18
lib_fat_SetAttrib:
lib_fat_SetFileSize:
jp 21
lib_fat_GetFileSize:
jp 24
lib_fat_GetAttrib:
lib_fat_SetAttrib:
jp 27
lib_fat_SetPos:
lib_fat_GetAttrib:
jp 30
lib_fat_GetPos:
lib_fat_SetFileBlockOffset:
jp 33
lib_fat_Read:
lib_fat_GetFileBlockOffset:
jp 36
lib_fat_Write:
lib_fat_ReadFile:
jp 39
lib_fat_Create:
lib_fat_WriteFile:
jp 42
lib_fat_Delete:
lib_fat_Create:
jp 45
lib_fat_Delete:
jp 48

ld hl,(ti.asm_prgm_size)
ld (libload_unload.size),hl
Expand Down Expand Up @@ -178,9 +184,11 @@ lib_fatdrvce:
jp 0
jp 3
jp 6
jp 9
jp 12
jp 15
jp 18
jp 21
jp 24
jp 27
jp 30
Expand All @@ -189,6 +197,7 @@ lib_fatdrvce:
jp 39
jp 42
jp 45
jp 48
.size := $ - lib_fatdrvce

; remove loaded libraries from usermem
Expand Down
115 changes: 59 additions & 56 deletions src/usb.asm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ msd_partitions:
rb 8*10

fat_struct:
rb 1041
rb 768
fat_dir_struct:
rb 32
fat_file_struct:
rb 64
fat_path:
Expand Down Expand Up @@ -217,22 +219,24 @@ usb_selection := $ - 1
ld h,8 ; partition structure is 8 bytes
mlt hl
ld bc,msd_partitions
add hl,bc ; pointer to first (4 bytes) then last (4 bytes)
ld iy,fat_struct
lea de,iy + 9
ld bc,8
ldir
ld hl,lib_msd_Read
ld (iy + 0),hl ; read
ld hl,lib_msd_Write
ld (iy + 3),hl ; write
add hl,bc ; pointer to first lba (4 bytes)
ld de,(hl)
inc hl
inc hl
inc hl
ld hl,(hl)
push hl
push de
ld hl,msd_struct
ld (iy + 6),hl ; usr
ld iy,ti.flags
ld bc,fat_struct
push bc
call lib_fat_Init
pop bc
push hl
ld hl,lib_msd_Write
push hl
ld hl,lib_msd_Read
push hl
ld hl,fat_struct
push hl
call lib_fat_Open
pop bc, bc, bc, bc, bc, bc
ld iy,ti.flags
compare_hl_zero
jr z,.fat_init_completed
Expand Down Expand Up @@ -288,52 +292,48 @@ fat_get_directory_listing:
jr nz,.notroot ; if at root show exit directory

.notroot:
ld bc,0 ; don't skip any
push bc
ld b,2 ; allow for maximum of 512 directories
push bc
ld bc,item_location_base ; place to store
push bc
ld bc,1 ; get directories first
ld bc,fat_dir_struct
push bc
ld bc,fat_path ; path
push bc
ld bc,fat_struct ; global fat state
push bc
call lib_fat_DirList
call lib_fat_OpenDir
ld iy,ti.flags
pop bc,bc,bc,bc,bc,bc
inc hl
pop bc, bc, bc
compare_hl_zero
dec hl
jq z,.error
ld (number_of_items),hl
jq nz,.error
ld hl,(number_of_items)
.loop:
ld bc,18 ; each entry is 18 bytes
call ti._imulu
ld de,item_location_base
add hl,de
.find_files:
ld bc,0 ; don't skip any
push bc
ld b,3 ; allow for maximum of 768 files
push bc
push hl
ld c,0 ; get files
push bc
ld bc,fat_path ; path
push bc
ld bc,fat_struct ; global fat state
push hl
ld bc,fat_dir_struct
push bc
call lib_fat_DirList
call lib_fat_ReadDir
ld iy,ti.flags
pop bc,bc,bc,bc,bc,bc
inc hl
pop bc, bc
compare_hl_zero
dec hl
jq z,.error
ld bc,(number_of_items)
add hl,bc
ld (number_of_items),hl ; number of items in directory
pop hl
jq nz,.error
ld a,(hl) ; check if name[0] = 0
or a,a
jr z,.return
ld hl,(number_of_items)
inc hl
ld (number_of_items),hl
ld de,768
compare_hl_de
jr nz,.loop
.return:
ld bc,fat_dir_struct
push bc
call lib_fat_CloseDir
ld iy,ti.flags
pop bc
ret
.error:
xor a,a
Expand Down Expand Up @@ -428,20 +428,21 @@ usb_detach_only:
jr z,.no_fat
ld bc,fat_struct
push bc
call lib_fat_Deinit
pop bc
call lib_fat_Close
ld iy,ti.flags
pop bc
.no_fat:
ld a,(msd_enabled)
or a,a
jr z,.no_msd
ld bc,msd_struct
push bc
call lib_msd_Close
pop bc
ld iy,ti.flags
pop bc
.no_msd:
call lib_usb_Cleanup
ld iy,ti.flags
jp libload_unload

usb_detach: ; detach the fat library hooks
Expand Down Expand Up @@ -630,15 +631,17 @@ usb_open_tivar:
ld hl,(item_ptr)
.entry:
call usb_append_fat_path
ld bc,fat_file_struct
push bc
ld bc,0
push bc
ld bc,fat_path
push bc
ld bc,fat_struct
push bc
ld bc,fat_file_struct
push bc
call lib_fat_Open
call lib_fat_OpenFile
ld iy,ti.flags
pop bc,bc,bc
pop bc,bc,bc,bc
compare_hl_zero
jr nz,.error
call usb_directory_previous
Expand Down Expand Up @@ -710,7 +713,7 @@ fat_file_read_sector:
push bc
ld bc,fat_file_struct
push bc
call lib_fat_Read
call lib_fat_ReadFile
ld iy,ti.flags
pop bc,bc
pop de
Expand All @@ -721,7 +724,7 @@ fat_file_read_sector:
fat_file_close:
ld bc,fat_file_struct
push bc
call lib_fat_Close
call lib_fat_CloseFile
ld iy,ti.flags
pop bc
ret
Expand Down

0 comments on commit 0fc62ef

Please sign in to comment.