From 0fc62efb172105e3936ba945892274ed874376cb Mon Sep 17 00:00:00 2001 From: mateoconlechuga Date: Sun, 18 Dec 2022 12:37:23 -0700 Subject: [PATCH] enable usb by default and update to new fatdrvce api Signed-off-by: mateoconlechuga --- Makefile | 2 +- include/macros.inc | 2 +- src/libload.asm | 43 ++++++++++------- src/usb.asm | 115 +++++++++++++++++++++++---------------------- 4 files changed, 87 insertions(+), 75 deletions(-) diff --git a/Makefile b/Makefile index a7dba6b..0e31a59 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/include/macros.inc b/include/macros.inc index 9d8fc88..ddad10f 100644 --- a/include/macros.inc +++ b/include/macros.inc @@ -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 diff --git a/src/libload.asm b/src/libload.asm index e449bba..fa7b836 100644 --- a/src/libload.asm +++ b/src/libload.asm @@ -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 @@ -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: @@ -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 @@ -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 @@ -189,6 +197,7 @@ lib_fatdrvce: jp 39 jp 42 jp 45 + jp 48 .size := $ - lib_fatdrvce ; remove loaded libraries from usermem diff --git a/src/usb.asm b/src/usb.asm index 7e94f9f..c12af49 100644 --- a/src/usb.asm +++ b/src/usb.asm @@ -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: @@ -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 @@ -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 @@ -428,9 +428,9 @@ 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 @@ -438,10 +438,11 @@ usb_detach_only: 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 @@ -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 @@ -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 @@ -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