From ba7b9fa6ea7fe4fc08bf43be107044bac0def2f4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 30 Sep 2026 06:26:50 +0000 Subject: [PATCH 1/4] docs: update progress [skip ci] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8bbdde80..eedc38d4 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 91.60% | 80.76% | 56.95% | 88.75% | +| 91.85% | 81.00% | 57.19% | 88.79% | -units 758/1027 complete, functions 11609/12563 matched. +units 760/1027 complete, functions 11627/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data -- 2.49.1 From 4830a261010a66673b219653c3ec54d3f7ae75f2 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Wed, 30 Sep 2026 01:30:53 -0500 Subject: [PATCH 2/4] fa: pf_dir 30/38, pf_file 44/45 (worker 886e3b81) (#344) --- README.md | 4 +- libs/RVL_SDK/src/fa/driver/nand_drv.c | 2 +- libs/RVL_SDK/src/fa/driver/sd_drv.c | 152 ++++++++++-------- libs/RVL_SDK/src/fa/pf_dir.c | 7 +- libs/RVL_SDK/src/fa/pf_fat16.c | 4 +- libs/RVL_SDK/src/fa/pf_file.c | 3 +- libs/RVL_SDK/src/fa/pf_path.c | 64 +++++--- .../attempts/fa-finish-driver-nand_drv.md | 23 +++ .../attempts/fa-finish-pdm_disk.md | 12 ++ .../attempts/fa-finish-pdm_partition.md | 23 +++ .../attempts/fa-finish-pf_cache.md | 11 ++ .../attempts/fa-finish-pf_cluster.md | 23 +++ .../attempts/fa-finish-pf_dir.md | 56 +++++++ .../attempts/fa-finish-pf_entry_iterator.md | 17 ++ .../attempts/fa-finish-pf_fat.md | 37 +++++ .../attempts/fa-finish-pf_fat12.md | 17 ++ .../attempts/fa-finish-pf_fat16.md | 11 ++ .../attempts/fa-finish-pf_file.md | 27 ++++ .../attempts/fa-finish-pf_path.md | 49 ++++++ .../attempts/fa-finish-pf_system.md | 69 ++++++++ .../attempts/fa-finish-pf_volume.md | 27 ++++ tools/decomp-assist/attempts/fa-sd-drv.md | 94 +++++++++++ 22 files changed, 627 insertions(+), 105 deletions(-) create mode 100644 tools/decomp-assist/attempts/fa-finish-driver-nand_drv.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pdm_disk.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pdm_partition.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_cache.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_cluster.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_dir.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_entry_iterator.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_fat.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_fat12.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_fat16.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_file.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_path.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_system.md create mode 100644 tools/decomp-assist/attempts/fa-finish-pf_volume.md create mode 100644 tools/decomp-assist/attempts/fa-sd-drv.md diff --git a/README.md b/README.md index eedc38d4..560a716b 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 91.85% | 81.00% | 57.19% | 88.79% | +| 91.87% | 81.01% | 57.19% | 88.79% | -units 760/1027 complete, functions 11627/12563 matched. +units 760/1027 complete, functions 11629/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data diff --git a/libs/RVL_SDK/src/fa/driver/nand_drv.c b/libs/RVL_SDK/src/fa/driver/nand_drv.c index e0b3105a..8202e42b 100644 --- a/libs/RVL_SDK/src/fa/driver/nand_drv.c +++ b/libs/RVL_SDK/src/fa/driver/nand_drv.c @@ -420,7 +420,7 @@ s32 fa_nanddrv_NotifyNANDFile(const char* path, u32 size) { if (pf_strcmp(info->path, path) == 0) { return 0; } if (nanddisk_info[index].disk == 0) { pf_strcpy(info->path, path); - info->file_size = size; + nanddisk_info[index].file_size = size; break; } } diff --git a/libs/RVL_SDK/src/fa/driver/sd_drv.c b/libs/RVL_SDK/src/fa/driver/sd_drv.c index 4a03b0b0..97c02dcc 100644 --- a/libs/RVL_SDK/src/fa/driver/sd_drv.c +++ b/libs/RVL_SDK/src/fa/driver/sd_drv.c @@ -219,9 +219,19 @@ const PFD_SDDRV_SIZE_DEPEND sddrv_size_depend_tbl[14] = { {0x007e0000, 0x04000000, 0x00002000, 0x000000ff, 0x0000003f, 0x40}, }; +static inline void update_media_drive(void) { + s8 drive; + if (g_pfd_sddrv_info.drive == 0 && pfd_get_media_drv_char(g_pfd_sddrv_info.disk, &drive, 1) == 1) { + g_pfd_sddrv_info.drive = drive; + } +} + +static inline void clear_mount_flag(void) { + g_pfd_sddrv_info.flags &= ~2; +} + s32 pfd_st_inter_callback(s32 status, void* data) { s32 result; - s8 drive; if ((status & 1) != 1) { return 0; @@ -234,9 +244,7 @@ s32 pfd_st_inter_callback(s32 status, void* data) { } } if (g_pfd_sddrv_info.disk != 0) { - if (g_pfd_sddrv_info.drive == 0 && pfd_get_media_drv_char(g_pfd_sddrv_info.disk, &drive, 1) == 1) { - g_pfd_sddrv_info.drive = drive; - } + update_media_drive(); pdm_disk_notify_media_insert(g_pfd_sddrv_info.disk); if (g_pfd_sddrv_info.drive != 0 && g_attach_func != 0) { g_attach_func(g_pfd_sddrv_info.drive); @@ -249,7 +257,6 @@ s32 pfd_st_inter_callback(s32 status, void* data) { s32 pfd_st_removal_callback(s32 status, void* data) { s32 result; - s8 drive; if ((status & 2) != 2) { return 0; @@ -263,9 +270,7 @@ s32 pfd_st_removal_callback(s32 status, void* data) { } } if (g_pfd_sddrv_info.disk != 0) { - if (g_pfd_sddrv_info.drive == 0 && pfd_get_media_drv_char(g_pfd_sddrv_info.disk, &drive, 1) == 1) { - g_pfd_sddrv_info.drive = drive; - } + update_media_drive(); pdm_disk_notify_media_eject(g_pfd_sddrv_info.disk); if (g_pfd_sddrv_info.drive != 0 && g_detach_func != 0) { g_detach_func(g_pfd_sddrv_info.drive); @@ -315,16 +320,7 @@ s32 pfd_sddrv_init(FADisk* disk) { g_pfd_sddrv_info.media_inserted = 1; } g_pfd_sddrv_info.device = device; - if (g_pfd_sddrv_info.media_inserted == 0) { - g_event = 1; - sd_result = ISD_RegisterDeviceIntrHandler(device, (SDDevIntrCallback)pfd_st_inter_callback, &g_event); - if (sd_result != 0) { - OSReport("ERR:Failed to regist intr handler1 [ret = 0x%x] pfd_sddrv_init()\n", sd_result); - ISD_UnmountCard(device); - g_pfd_sddrv_info.device = 0; - return -42; - } - } else { + if (g_pfd_sddrv_info.media_inserted != 0) { g_event = 2; sd_result = ISD_RegisterDeviceIntrHandler(device, (SDDevIntrCallback)pfd_st_removal_callback, &g_event); if (sd_result != 0) { @@ -333,9 +329,18 @@ s32 pfd_sddrv_init(FADisk* disk) { g_pfd_sddrv_info.device = 0; return -42; } + } else { + g_event = 1; + sd_result = ISD_RegisterDeviceIntrHandler(device, (SDDevIntrCallback)pfd_st_inter_callback, &g_event); + if (sd_result != 0) { + OSReport("ERR:Failed to regist intr handler1 [ret = 0x%x] pfd_sddrv_init()\n", sd_result); + ISD_UnmountCard(device); + g_pfd_sddrv_info.device = 0; + return -42; + } } - g_pfd_sddrv_info.flags |= 1; g_pfd_sddrv_info.disk = disk; + g_pfd_sddrv_info.flags |= 1; return 0; } @@ -440,7 +445,7 @@ s32 pfd_sddrv_unmount(FADisk* disk) { return -30; } if ((g_pfd_sddrv_info.flags & 2) != 0) { - g_pfd_sddrv_info.flags &= ~2; + clear_mount_flag(); } return 0; } @@ -452,12 +457,12 @@ s32 pfd_sddrv_finalize(FADisk* disk) { return -30; } if ((g_pfd_sddrv_info.flags & 2) != 0) { - g_pfd_sddrv_info.flags = g_pfd_sddrv_info.flags & 0xfffffffd; + clear_mount_flag(); } if ((g_pfd_sddrv_info.flags & 1) != 0) { result = ISD_UnregisterDeviceIntrHandler(g_pfd_sddrv_info.device); if (result != 0) { - OSReport("WARNING Faild to UnregisterDeviceIntrHandler sd card [ret = %d]\n"); + OSReport("WARNING Faild to UnregisterDeviceIntrHandler sd card [ret = %d]\n", result); } result = ISD_UnmountCard(g_pfd_sddrv_info.device); if (result != 0) { @@ -558,6 +563,7 @@ s32 pfd_sddrv_is_media_insert(void) { static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_sector, u32* blocks_read) { s32 result; + u32 current_sector; u32 completed; u8* current_buffer; if ((g_pfd_sddrv_info.flags & 2) == 0) { @@ -572,49 +578,49 @@ static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes return -30; } *blocks_read = 0xffffffff; + current_sector = sector; if (((u32)buffer & 0x1f) == 0) { if (g_pfd_sddrv_info.media_inserted == 0) { *blocks_read = 0; return -33; } if (blocks == 1) { - result = ISD_ReadBlock(g_pfd_sddrv_info.device, sector, buffer, 1); + result = ISD_ReadBlock(g_pfd_sddrv_info.device, current_sector, buffer, blocks); if (result != 0) { OSReport("INFO Failed to read SD card1 [ret = 0x%x] pfd_sddrv_physical_read()\n", result); *blocks_read = 0; return -37; } } else { - result = ISD_ReadMultiBlock(g_pfd_sddrv_info.device, sector, buffer, blocks); + result = ISD_ReadMultiBlock(g_pfd_sddrv_info.device, current_sector, buffer, blocks); if (result != 0) { OSReport("INFO Failed to read SD card2 [ret = 0x%x] pfd_sddrv_physical_read()\n", result); *blocks_read = 0; return -37; } } - *blocks_read = blocks; - return 0; - } - for (completed = 0, current_buffer = buffer; completed < blocks; current_buffer += bytes_per_sector, sector++, completed++) { - if (g_pfd_sddrv_info.media_inserted == 0) { - if (completed == 0) { + } else { + for (completed = 0, current_buffer = buffer; completed < blocks; current_buffer += bytes_per_sector, current_sector++, completed++) { + if (g_pfd_sddrv_info.media_inserted == 0) { + if (completed != 0) { + *blocks_read = completed; + return 0; + } *blocks_read = 0; return -33; } - *blocks_read = completed; - return 0; - } - result = ISD_ReadBlock(g_pfd_sddrv_info.device, sector, g_pfd_sddrv_buf, 1); - if (result != 0) { - OSReport("INFO Failed to read SD card3 [ret = 0x%x] pfd_sddrv_physical_read()\n", result); - if (completed == 0) { + result = ISD_ReadBlock(g_pfd_sddrv_info.device, current_sector, g_pfd_sddrv_buf, 1); + if (result != 0) { + OSReport("INFO Failed to read SD card3 [ret = 0x%x] pfd_sddrv_physical_read()\n", result); + if (completed != 0) { + *blocks_read = completed; + return 0; + } *blocks_read = 0; return -37; } - *blocks_read = completed; - return 0; + pf_memcpy(current_buffer, g_pfd_sddrv_buf, bytes_per_sector); } - pf_memcpy(current_buffer, g_pfd_sddrv_buf, bytes_per_sector); } *blocks_read = blocks; return 0; @@ -622,6 +628,7 @@ static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes s32 pfd_sddrv_physical_write(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_sector, u32* blocks_written) { s32 result; + u32 current_sector; u32 completed; u8* current_buffer; if ((g_pfd_sddrv_info.flags & 2) == 0) { @@ -636,48 +643,48 @@ s32 pfd_sddrv_physical_write(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_s return -30; } *blocks_written = 0xffffffff; + current_sector = sector; if (((u32)buffer & 0x1f) == 0) { if (g_pfd_sddrv_info.media_inserted == 0) { *blocks_written = 0; return -33; } if (blocks == 1) { - result = ISD_WriteBlock(g_pfd_sddrv_info.device, sector, buffer, 1); + result = ISD_WriteBlock(g_pfd_sddrv_info.device, current_sector, buffer, blocks); if (result != 0) { OSReport("INFO Failed to write SD card1 [ret = 0x%x] pfd_sddrv_physical_write()\n", result); *blocks_written = 0; return -36; } } else { - result = ISD_WriteMultiBlock(g_pfd_sddrv_info.device, sector, buffer, blocks); + result = ISD_WriteMultiBlock(g_pfd_sddrv_info.device, current_sector, buffer, blocks); if (result != 0) { OSReport("INFO Failed to write SD card2 [ret = 0x%x] pfd_sddrv_physical_write()\n", result); *blocks_written = 0; return -36; } } - *blocks_written = blocks; - return 0; - } - for (completed = 0, current_buffer = buffer; completed < blocks; current_buffer += bytes_per_sector, sector++, completed++) { - if (g_pfd_sddrv_info.media_inserted == 0) { - if (completed == 0) { + } else { + for (completed = 0, current_buffer = buffer; completed < blocks; current_buffer += bytes_per_sector, current_sector++, completed++) { + if (g_pfd_sddrv_info.media_inserted == 0) { + if (completed != 0) { + *blocks_written = completed; + return 0; + } *blocks_written = 0; return -33; } - *blocks_written = completed; - return 0; - } - pf_memcpy(g_pfd_sddrv_buf, current_buffer, bytes_per_sector); - result = ISD_WriteBlock(g_pfd_sddrv_info.device, sector, g_pfd_sddrv_buf, 1); - if (result != 0) { - OSReport("INFO Failed to write SD card3 [ret = 0x%x] pfd_sddrv_physical_write()\n", result); - if (completed == 0) { + pf_memcpy(g_pfd_sddrv_buf, current_buffer, bytes_per_sector); + result = ISD_WriteBlock(g_pfd_sddrv_info.device, current_sector, g_pfd_sddrv_buf, 1); + if (result != 0) { + OSReport("INFO Failed to write SD card3 [ret = 0x%x] pfd_sddrv_physical_write()\n", result); + if (completed != 0) { + *blocks_written = completed; + return 0; + } *blocks_written = 0; return -36; } - *blocks_written = completed; - return 0; } } *blocks_written = blocks; @@ -688,6 +695,7 @@ s32 pfd_sddrv_get_total_sectors(u32* sectors, u16* bytes_per_sector) { s32 result; u32 csd[4]; u32 c_size; + u32 cluster_blocks; u32 read_block_length; u16 multiplier; u16 minimum_multiplier; @@ -708,6 +716,7 @@ s32 pfd_sddrv_get_total_sectors(u32* sectors, u16* bytes_per_sector) { read_block_length = ((csd[1] >> 7) & 7) + 2; read_block_size = 1 << read_block_length; c_size = (((csd[2] & 3) << 10 | csd[1] >> 22) + 1); + cluster_blocks = c_size * read_block_size; multiplier = (csd[2] >> 8) & 0xf; minimum_multiplier = 9; if (multiplier >= 9) { @@ -717,8 +726,8 @@ s32 pfd_sddrv_get_total_sectors(u32* sectors, u16* bytes_per_sector) { if (minimum_multiplier <= 11) { max_multiplier = minimum_multiplier; } - multiplier_factor = 1 << (max_multiplier - 9); - *sectors = c_size * read_block_size * multiplier_factor; + multiplier_factor = 1 << (u16)(max_multiplier - 9); + *sectors = cluster_blocks * multiplier_factor; } else { *sectors = ((csd[1] >> 8 & 0x3fffff) + 1) * 0x400; } @@ -1423,32 +1432,33 @@ s32 pfd_sddrv_build_fat32_mbr_bpb(u32 total_sectors) { s32 pfd_sddrv_full_format(void) { s32 result; u32 retry_count; - u32 status; - u32 total_sectors; u16 bytes_per_sector; + u32 total_sectors; + u32 status; retry_count = 0; - while (retry_count < 5) { + do { if (g_pfd_sddrv_info.media_inserted == 0) { return -33; } result = ISD_ResetDevice(g_pfd_sddrv_info.device); if (result == 0) { + g_pfd_sddrv_info.media_ejected = 0; break; } OSReport("ERROR Failed to SD Card Reset [ret = 0x%x]. pfd_sddrv_full_format()\n", result); retry_count++; - } + } while (retry_count < 5); if (retry_count == 5) { return -38; } - g_pfd_sddrv_info.media_ejected = 0; if (g_pfd_sddrv_info.media_ejected != 0) { return -33; } result = ISD_GetDeviceStatus(g_pfd_sddrv_info.device, &status); if (result != 0) { - return result; + OSReport("ERR Failed to get sd card status. [ret = 0x%x]\n", result); + return -39; } if ((status & 4) != 0) { return -32; @@ -1466,17 +1476,17 @@ s32 pfd_sddrv_full_format(void) { return -34; } result = pfd_sddrv_build_mbr_bpb(total_sectors); - } else { - if ((status & 0x10000) == 0 || (status & 0x100000) == 0) { - return -31; - } + } else if ((status & 0x10000) != 0 && (status & 0x100000) != 0) { if (total_sectors > 0x4000000) { return -34; } result = pfd_sddrv_build_fat32_mbr_bpb(total_sectors); + } else { + return -31; } if (result != 0) { OSReport("ERR Failed to build up and write MBR and BPB fields.\n"); + return result; } - return result; + return 0; } diff --git a/libs/RVL_SDK/src/fa/pf_dir.c b/libs/RVL_SDK/src/fa/pf_dir.c index 6f1017a7..64b4a6ec 100644 --- a/libs/RVL_SDK/src/fa/pf_dir.c +++ b/libs/RVL_SDK/src/fa/pf_dir.c @@ -209,8 +209,8 @@ PFDIR_SDD* PFDIR_GetSDD(PF_VOLUME* volume, PF_DIR_ENT* entry) { entry->entry_offset == volume_dirs->sdds[i].dir_entry.entry_offset) { return &volume_dirs->sdds[i]; } - free_candidate++; i++; + free_candidate++; } if (first_free_sdd == 0) { return 0; @@ -1304,7 +1304,7 @@ void PFDIR_move(PF_STR* old_path, PF_STR* new_path) { volume_dirs->cache_signature = 0; } -void PFDIR_opendir(PF_STR* path, PFDIR_DIR** dir) { +pf_s32 PFDIR_opendir(PF_STR* path, PFDIR_DIR** dir) { PF_VOLUME* volume = PFPATH_GetVolumeFromPath(path); PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)volume; pf_s32 error = PFVOL_CheckForRead(volume); @@ -1312,7 +1312,7 @@ void PFDIR_opendir(PF_STR* path, PFDIR_DIR** dir) { if (error != 0) { pf_vol_set.last_error = error; ((PFDIR_VOLUME_DIRS*)volume)->last_error = error; - return; + return error; } error = PFDIR_p_opendir(volume, (PFDIR_STR*)path, dir); if (error != 0) { @@ -1321,6 +1321,7 @@ void PFDIR_opendir(PF_STR* path, PFDIR_DIR** dir) { } else { ((PFDIR_VOLUME_DIRS*)volume)->num_opened_directories += 1; } + return error; } pf_s32 PFDIR_closedir(PFDIR_DIR* dir) { diff --git a/libs/RVL_SDK/src/fa/pf_fat16.c b/libs/RVL_SDK/src/fa/pf_fat16.c index c935b5d2..be63b1a0 100644 --- a/libs/RVL_SDK/src/fa/pf_fat16.c +++ b/libs/RVL_SDK/src/fa/pf_fat16.c @@ -80,10 +80,10 @@ pf_s32 VFiPFFAT16_WriteFATEntry(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32 value) } pf_s32 PFFAT16_WriteFATEntryWithBuf(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32 value, PF_CACHE_PAGE* p_page) { - pf_u16 offset_in_sector; + pf_u16 fat_sector; pf_s32 err; pf_u32 fat_offset; - pf_u16 fat_sector; + pf_u16 offset_in_sector; pf_u32 current_fat; pf_s32 result; fat_offset = cluster * sizeof(pf_u16); diff --git a/libs/RVL_SDK/src/fa/pf_file.c b/libs/RVL_SDK/src/fa/pf_file.c index c029c635..9b4f9e95 100644 --- a/libs/RVL_SDK/src/fa/pf_file.c +++ b/libs/RVL_SDK/src/fa/pf_file.c @@ -1,4 +1,5 @@ #define PF_FA_STR_LAYOUT +#include #include #include #include @@ -951,7 +952,7 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode, } pf_s32 PFFILE_p_fread(PF_VOLUME* volume, pf_u8* buffer, pf_u32 size, pf_u32 count, - PFFILE_FILE* file, pf_u32* count_read) { + PFFILE_FILE* file, pf_u32* count_read) NO_INLINE { pf_u32 bytes_read = 0; pf_s32 error; diff --git a/libs/RVL_SDK/src/fa/pf_path.c b/libs/RVL_SDK/src/fa/pf_path.c index 8855715b..0a9805bc 100644 --- a/libs/RVL_SDK/src/fa/pf_path.c +++ b/libs/RVL_SDK/src/fa/pf_path.c @@ -326,7 +326,6 @@ pf_bool PFPATH_MatchFileNameWithPattern(const pf_s8* file_name, PF_STR* p_patter pf_u16 c_pat; PF_FILE_NAME_ITER name; PF_STR pattern; - pf_s8 sig[2]; pf_bool result; result = PF_TRUE; @@ -339,16 +338,15 @@ pf_bool PFPATH_MatchFileNameWithPattern(const pf_s8* file_name, PF_STR* p_patter if (PFSTR_GetCodeMode(p_pattern) == 1) { if (is_long_name == PF_FALSE && (pf_vol_set.setting & 0x02) == 0x02 && PFPATH_CheckExtShortNameSignature(&pattern) == 1) { - sig[0] = 1; - sig[1] = 2; - if (PFSTR_StrNCmp((PF_STR*)&name, sig, 1, 0, 2) == 0) { + result = PFPATH_CheckExtShortNameSignature(&pattern); + if (result == 1) { name.index += 2; pattern.p_head += 2; } } } else if ((pf_vol_set.setting & 0x02) == 0x02 && is_long_name == PF_FALSE && PFSTR_StrNCmp(p_pattern, (pf_s8*)".", 1, 0, 1) != 0 && PFSTR_StrNCmp(p_pattern, (pf_s8*)"..", 1, 0, 2) != 0 && - PFPATH_CheckExtShortName(p_pattern, 1, PF_TRUE) == 0) { + PFPATH_CheckExtShortName(p_pattern, 1, PF_FALSE) == 0) { result = PF_FALSE; } if (result == PF_TRUE) { @@ -360,9 +358,12 @@ pf_bool PFPATH_MatchFileNameWithPattern(const pf_s8* file_name, PF_STR* p_patter } pf_s32 PFPATH_cmpNameImpl(const pf_s8* name, const pf_s8* pattern, pf_u32* matched_end) { + pf_u32 read_char; + pf_s32 recursive_error; pf_u16 name_char; pf_u16 pattern_char; - pf_u16 converted_char; + pf_u16 converted_pattern; + pf_u16 converted_name; pf_s32 name_width; pf_s32 pattern_width; PF_PATH_VOLUME_SET* volume = &pf_vol_set; @@ -371,27 +372,32 @@ pf_s32 PFPATH_cmpNameImpl(const pf_s8* name, const pf_s8* pattern, pf_u32* match pattern_width = volume->codeset.oem_char_width(pattern); name_width = volume->codeset.oem_char_width(name); if (pattern_width == 1) { - pattern_char = pf_toupper(*pattern); + read_char = pf_toupper(*pattern); } else { - pattern_char = PF_GET_LE_U16((const pf_u8*)pattern); - if (PFPATH_OEM_ConvertFWchar(pattern, &converted_char) != 0) { - pattern_char = converted_char; - } + read_char = (pf_u16)PF_GET_LE_U16((const pf_u8*)pattern); } + pattern_char = (pf_u16)read_char; if (name_width == 1) { - name_char = pf_toupper(*name); + read_char = pf_toupper(*name); } else { - name_char = PF_GET_LE_U16((const pf_u8*)name); - if (PFPATH_OEM_ConvertFWchar(name, &converted_char) != 0) { - name_char = converted_char; - } + read_char = (pf_u16)PF_GET_LE_U16((const pf_u8*)name); + } + name_char = (pf_u16)read_char; + if (pattern_width == 2 && PFPATH_OEM_ConvertFWchar(pattern, &converted_pattern) == 1) { + pattern_char = converted_pattern; + } + if (name_width == 2 && PFPATH_OEM_ConvertFWchar(name, &converted_name) == 1) { + name_char = converted_name; } pattern += pattern_width; - if (pattern_char == '?') { + switch (pattern_char) { + case '?': { if (name_char == 0) { return 1; } - } else if (pattern_char == '*') { + break; + } + case '*': { do { pattern_width = volume->codeset.oem_char_width(pattern); if (pattern_width == 1) { @@ -400,21 +406,27 @@ pf_s32 PFPATH_cmpNameImpl(const pf_s8* name, const pf_s8* pattern, pf_u32* match pattern_char = PF_GET_LE_U16((const pf_u8*)pattern); } pattern += pattern_width; + if (pattern_char == '?') { + if (name_char == 0) { return 1; } + name += name_width; + name_width = volume->codeset.oem_char_width(name); + if (name_width == 1) { name_char = pf_toupper(*name); } + else { name_char = PF_GET_LE_U16((const pf_u8*)name); } + } } while (pattern_char == '*' || pattern_char == '?'); if (pattern_char == 0) { return 0; } while (name_char != 0) { + name += name_width; if (name_char == pattern_char) { - if (PFPATH_cmpNameImpl(name + name_width, pattern, matched_end) == 0) { + recursive_error = PFPATH_cmpNameImpl(name, pattern, matched_end); + if (recursive_error == 0) { return 0; } - } - if (*matched_end != 0) { - return 1; + if (*matched_end != 0) { return recursive_error; } } name_width = volume->codeset.oem_char_width(name); - name += name_width; if (name_width == 1) { name_char = pf_toupper(*name); } else { @@ -422,8 +434,10 @@ pf_s32 PFPATH_cmpNameImpl(const pf_s8* name, const pf_s8* pattern, pf_u32* match } } return 1; - } else if (name_char != pattern_char) { - return 1; + } + default: + if (name_char != pattern_char) { return 1; } + break; } name += name_width; if (*name == 0 || *pattern == 0) { diff --git a/tools/decomp-assist/attempts/fa-finish-driver-nand_drv.md b/tools/decomp-assist/attempts/fa-finish-driver-nand_drv.md new file mode 100644 index 00000000..0e2f3b17 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-driver-nand_drv.md @@ -0,0 +1,23 @@ +# fa/driver/nand_drv continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +fa_nanddrv_ParseCreateNANDFile: +- rotate independent local declarations: 130/130, 22 differences. +- common operation status exit: 130/130, 10 differences. +- reverse independent local declarations: 130/130, 22 differences. +- Retained: [130, 130, 10]. + +fa_nanddrv_NotifyNANDFile: +- rotate independent local declarations: 72/72, 12 differences. +- common operation status exit: 72/72, 12 differences. +- reverse independent local declarations: 72/72, 12 differences. +- Retained: [72, 72, 12]. + +fa_nanddrv_physical_write: +- rotate independent local declarations: 175/175, 30 differences. +- common operation status exit: 175/175, 38 differences. +- reverse independent local declarations: 175/175, 27 differences. +- Retained: [175, 175, 38]. + +NotifyNANDFile additionally used the indexed file-size destination (72/72, twelve differences reduced to six) and a separate candidate pointer (72/72, unchanged). Retained the indexed destination without the extra alias. Six pointer/stride register differences remain. ParseCreateNANDFile retains ten control-flow differences around the directory-change error exit. physical_write retains callee-saved register differences; all three declaration/return variants preserved instruction count. diff --git a/tools/decomp-assist/attempts/fa-finish-pdm_disk.md b/tools/decomp-assist/attempts/fa-finish-pdm_disk.md new file mode 100644 index 00000000..b63a6a53 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pdm_disk.md @@ -0,0 +1,12 @@ +# fa/pdm_disk continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +pdm_disk_convert_block_into_sector`: +- common operation status exit: 44/44, 0 differences. +- split local declaration from initialization: 44/44, 0 differences. +- Retained: [44, 44, 0]. + +The original symbol is literally named pdm_disk_convert_block_into_sector` with a trailing backtick in config/43U/symbols.txt and the extracted object. The C definition has the valid identifier without that backtick. Its 44 instructions and 176 bytes already agree exactly when compared under the two names. Three source variants were compiled and restored. ctxdiff rejects the absent backtick-bearing C symbol; no symbol rename, inline assembler alias or symbol-size change was introduced. This remains a symbol-identity mismatch, not a code mismatch. + +Third attempt: return small-sector validation failure before the conversion branch; 44/44 instructions, 41 positional differences. Restored original source. diff --git a/tools/decomp-assist/attempts/fa-finish-pdm_partition.md b/tools/decomp-assist/attempts/fa-finish-pdm_partition.md new file mode 100644 index 00000000..95fdc1e5 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pdm_partition.md @@ -0,0 +1,23 @@ +# fa/pdm_partition continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +pdm_part_is_master_boot_sector: +- rotate independent local declarations: 86/84, 82 differences. +- common operation status exit: 86/84, 82 differences. +- reverse independent local declarations: 86/84, 82 differences. +- Retained: [86, 84, 82]. + +pdm_part_chg_ltop: +- rotate independent local declarations: 51/51, 16 differences. +- common operation status exit: 51/51, 16 differences. +- reverse independent local declarations: 51/51, 16 differences. +- Retained: [51, 51, 16]. + +pdm_part_get_start_sector: +- rotate independent local declarations: 276/276, 148 differences. +- common operation status exit: 276/276, 141 differences. +- reverse independent local declarations: 276/276, 138 differences. +- Retained: [276, 276, 141]. + +Additional targeted attempts: remove the preliminary partition-start store and exchange array declarations (83/84, seventy-two differences); reverse the two endian addition groups (86/84, eighty-three differences); load the sector ratio before the partition-start value (51/51, sixteen differences, unchanged). All were restored. The target retains the preliminary store and a different byte-load schedule. Logical-sector conversion still swaps its two arithmetic registers; extended partition scanning still differs in register assignment and endian load scheduling. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_cache.md b/tools/decomp-assist/attempts/fa-finish-pf_cache.md new file mode 100644 index 00000000..de8e928f --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_cache.md @@ -0,0 +1,11 @@ +# fa/pf_cache continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFCACHE_DoWriteNumSectorAndFreeIfNeeded: +- rotate independent local declarations: 233/233, 9 differences. +- common operation status exit: 233/233, 9 differences. +- reverse independent local declarations: 233/233, 9 differences. +- Retained: [233, 233, 9]. + +Additional right-overlap last-sector attempts: request-end minus one and sector plus (count minus one) each produce 232/233 instructions with a hoisted end-sector register; page-start minus one plus overlap retains 233/233 and the same nine differences. Restored. The remaining block uses a cached request end in the candidate while the original recomputes it after memcpy and schedules the last-sector subtraction before successful-sector bookkeeping. Earlier reconstruction attempts are in pf_cache.attempts.md. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_cluster.md b/tools/decomp-assist/attempts/fa-finish-pf_cluster.md new file mode 100644 index 00000000..fa476690 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_cluster.md @@ -0,0 +1,23 @@ +# fa/pf_cluster continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFCLUSTER_CombineFiles: +- rotate independent local declarations: 207/207, 4 differences. +- common operation status exit: 207/207, 4 differences. +- reverse independent local declarations: 207/207, 58 differences. +- Retained: [207, 207, 4]. + +PFCLUSTER_InsertCluster: +- rotate independent local declarations: 126/126, 28 differences. +- common operation status exit: 126/126, 28 differences. +- reverse independent local declarations: 126/126, 40 differences. +- Retained: [126, 126, 28]. + +PFCLUSTER_DeleteCluster: +- rotate independent local declarations: 108/108, 35 differences. +- common operation status exit: 108/108, 35 differences. +- reverse independent local declarations: 108/108, 53 differences. +- Retained: [108, 108, 35]. + +Swapping the operands around the grouped cluster total leaves CombineFiles at 207 instructions and four differences, confined to the overflow comparison arithmetic schedule. Restored. InsertCluster and DeleteCluster retain equal counts with 28 and 35 register differences. Prior targeted attempts are in fa_pf_cluster_attempts.md. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_dir.md b/tools/decomp-assist/attempts/fa-finish-pf_dir.md new file mode 100644 index 00000000..14c30ef0 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_dir.md @@ -0,0 +1,56 @@ +# fa/pf_dir continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFDIR_GetSDD: +- normal path first, validation failure last: 69/69, 24 differences. +- common operation status exit: 69/69, 8 differences. +- Retained: [69, 69, 2]. + +PFDIR_p_fsexec_remove: +- normal path first, validation failure last: 178/176, 21 differences. +- common operation status exit: 178/176, 170 differences. +- Retained: [178, 176, 170]. + +PFDIR_opendir: +- Retained: [39, 39, 2]. + +PFDIR_p_fsnext: +- rotate independent local declarations: 193/193, 39 differences. +- normal path first, validation failure last: 192/193, 167 differences. +- common operation status exit: 193/193, 39 differences. +- Retained: [193, 193, 39]. + +PFDIR_p_rmdir: +- rotate independent local declarations: 203/202, 197 differences. +- normal path first, validation failure last: 202/202, 170 differences. +- common operation status exit: 203/202, 197 differences. +- Retained: [203, 202, 197]. + +PFDIR_p_fsexec: +- rotate independent local declarations: 207/280, 189 differences. +- normal path first, validation failure last: 207/280, 175 differences. +- common operation status exit: 207/280, 189 differences. +- Retained: [207, 280, 189]. + +PFDIR_p_move: +- rotate independent local declarations: 215/631, 212 differences. +- normal path first, validation failure last: 214/631, 212 differences. +- common operation status exit: 215/631, 212 differences. +- Retained: [215, 631, 212]. + +PFDIR_p_rename: +- rotate independent local declarations: 191/625, 182 differences. +- normal path first, validation failure last: 190/625, 184 differences. +- common operation status exit: 191/625, 182 differences. +- Retained: [191, 625, 182]. + +PFDIR_p_mkdir: +- rotate independent local declarations: 256/562, 254 differences. +- normal path first, validation failure last: 255/562, 243 differences. +- common operation status exit: 256/562, 254 differences. +- Retained: [256, 562, 254]. + +PFDIR_opendir is now instruction exact after restoring its status return type and retaining the read/open status across the handler-count update. Target r3 still holds the status at return; the former void definition allowed the count load to clobber it. No shared-header prototype changes were needed. + +GetSDD additionally tried exchanging the two body increments (69/69, same two differences); compiler still schedules its derived volume-array pointer after the independent candidate pointer. Missing allocation and long-name update paths remain in mkdir, rename and move. Prior targeted three-attempt records are in fa-dir.md. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_entry_iterator.md b/tools/decomp-assist/attempts/fa-finish-pf_entry_iterator.md new file mode 100644 index 00000000..91c33832 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_entry_iterator.md @@ -0,0 +1,17 @@ +# fa/pf_entry_iterator continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFENT_ITER_FindCluster: +- rotate independent local declarations: 237/237, 8 differences. +- common operation status exit: 237/237, 75 differences. +- reverse independent local declarations: 237/237, 11 differences. +- Retained: [237, 237, 8]. + +PFENT_ITER_GetLFNEntryName: +- rotate independent local declarations: 74/73, 33 differences. +- common operation status exit: 74/73, 33 differences. +- reverse independent local declarations: 74/73, 33 differences. +- Retained: [74, 73, 33]. + +GetLFNEntryName: direct i * 13 indexing and a separately incremented byte offset both produce 76 instructions against 73 and introduce pointer induction absent in the target. Restored the 74-instruction version. FindCluster remains 237/237 with eight r7/r8 differences in iterator initialization. Earlier targeted attempts are in pf_entry_iterator.attempts.md. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_fat.md b/tools/decomp-assist/attempts/fa-finish-pf_fat.md new file mode 100644 index 00000000..cff45915 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_fat.md @@ -0,0 +1,37 @@ +# fa/pf_fat continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFFAT_DoAllocateChain: +- rotate independent local declarations: 216/216, 55 differences. +- normal path first, validation failure last: 215/216, 186 differences. +- common operation status exit: 216/216, 5 differences. +- Retained: [216, 216, 5]. + +PFFAT_GetSector: +- rotate independent local declarations: 88/88, 7 differences. +- common operation status exit: 88/88, 7 differences. +- reverse independent local declarations: 88/88, 7 differences. +- Retained: [88, 88, 7]. + +PFFAT_GetClusterAllocated: +- rotate independent local declarations: 70/70, 6 differences. +- normal path first, validation failure last: 69/70, 28 differences. +- common operation status exit: 70/70, 6 differences. +- Retained: [70, 70, 6]. + +PFFAT_GetSectorSpecified: +- common operation status exit: 16/17, 6 differences. +- Retained: [16, 17, 6]. + +PFFAT_RefreshFSINFO: +- rotate independent local declarations: 93/93, 27 differences. +- common operation status exit: 93/93, 14 differences. +- reverse independent local declarations: 93/93, 26 differences. +- Retained: [93, 93, 14]. + +PFFAT_FreeChain: +- rotate independent local declarations: 256/254, 137 differences. +- normal path first, validation failure last: 256/254, 178 differences. +- common operation status exit: 256/254, 113 differences. +- Retained: [256, 254, 113]. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_fat12.md b/tools/decomp-assist/attempts/fa-finish-pf_fat12.md new file mode 100644 index 00000000..fdffd93b --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_fat12.md @@ -0,0 +1,17 @@ +# fa/pf_fat12 continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFFAT12_WriteFATEntryWithBuf: +- rotate independent local declarations: 175/175, 8 differences. +- common operation status exit: 175/175, 8 differences. +- reverse independent local declarations: 175/175, 28 differences. +- Retained: [175, 175, 8]. + +PFFAT12_ReadFATEntryWithBuf: +- rotate independent local declarations: 155/155, 34 differences. +- common operation status exit: 155/155, 48 differences. +- reverse independent local declarations: 155/155, 34 differences. +- Retained: [155, 155, 34]. + +Additional write attempt: use a sixteen-bit FAT-sector local and write pointer additions with the buffer first (175/175, eight differences, unchanged). Restored the original declarations. The remaining write differences are sector/offset coalescing across a sector boundary and two addition operand orders. Read differs in four callee-saved registers; all tested forms retain 155/155 instructions. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_fat16.md b/tools/decomp-assist/attempts/fa-finish-pf_fat16.md new file mode 100644 index 00000000..2c77dffc --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_fat16.md @@ -0,0 +1,11 @@ +# fa/pf_fat16 continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFFAT16_WriteFATEntryWithBuf: +- rotate independent local declarations: 66/66, 12 differences. +- common operation status exit: 66/66, 7 differences. +- reverse independent local declarations: 66/66, 16 differences. +- Retained: [66, 66, 7]. + +Swapping sector and offset declarations reduces seven differences to one at equal 66-instruction count. Reversing pointer addition and introducing an entry pointer each leave the final add operand order unchanged. Kept the declaration change. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_file.md b/tools/decomp-assist/attempts/fa-finish-pf_file.md new file mode 100644 index 00000000..5b8ae849 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_file.md @@ -0,0 +1,27 @@ +# fa/pf_file continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFFILE_GetSFD: +- normal path first, validation failure last: 113/113, 68 differences. +- common operation status exit: 113/113, 24 differences. +- split local declaration from initialization: compile failed: -------------------- +# 652: PFFILE_SFD* first_free_sfd = PF_NULL; +# Error: ^^^^^^^^^^ +# (10141) expression syntax error +# Too many errors printed, aborting program + +User break, cancelled... +ninja: build stopped: subcommand failed. +. +- Retained: [113, 113, 18]. + +PFFILE_fread: +- rotate independent local declarations: 97/67, 28 differences. +- common operation status exit: 97/67, 28 differences. +- reverse independent local declarations: 97/67, 28 differences. +- Retained: [97, 67, 28]. + +PFFILE_fread became instruction exact after marking the existing PFFILE_p_fread definition NO_INLINE. The target calls that independently emitted function, while the compiler's automatic inlining previously expanded it into this wrapper. Included the existing decomp utility header only in this translation unit to obtain the macro; no shared header changed. An initial build without that include rejected the undefined macro and was corrected immediately. + +GetSFD's targeted pointer/index initialization, loop-order and initializer-helper variations remain recorded in fa-file.md. Its 113/113 stream still differs in eighteen register and increment instructions. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_path.md b/tools/decomp-assist/attempts/fa-finish-pf_path.md new file mode 100644 index 00000000..8ba40c35 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_path.md @@ -0,0 +1,49 @@ +# fa/pf_path continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFPATH_parseShortName: +- rotate independent local declarations: 466/466, 102 differences. +- common operation status exit: 466/466, 2 differences. +- reverse independent local declarations: 466/466, 166 differences. +- Retained: [466, 466, 2]. + +PFPATH_getShortName: +- common operation status exit: 148/148, 2 differences. +- split local declaration from initialization: compile failed: h.c +# -------------------------------------- +# 598: pf_s32 nLen = -1; +# Error: ^^^^^^ +# (10141) expression syntax error +# Too many errors printed, aborting program + +User break, cancelled... +ninja: build stopped: subcommand failed. +. +- explicit increment assignment: compile failed: 617: *short_name += 1 = pDirEntry[i]; +# Error: ^ +# (10142) not an lvalue +# Too many errors printed, aborting program + +User break, cancelled... +ninja: build stopped: subcommand failed. +. +- Retained: [148, 148, 2]. + +PFPATH_MatchFileNameWithPattern: +- rotate independent local declarations: 192/199, 148 differences. +- common operation status exit: 192/199, 148 differences. +- reverse independent local declarations: 192/199, 157 differences. +- Retained: [192, 199, 148]. + +PFPATH_cmpNameImpl: +- rotate independent local declarations: 195/218, 181 differences. +- common operation status exit: 195/218, 181 differences. +- reverse independent local declarations: 195/218, 180 differences. +- Retained: [195, 218, 181]. + +Targeted cmpNameImpl attempts: separate pattern/name fullwidth conversion and a wildcard switch (202/218); advance names for wildcard question marks and before recursive comparisons (226/218); share the character-read temporary and retain recursive error status (222/218). Retained the third corrected wildcard flow. Register allocation and four extra instructions remain. + +Targeted MatchFileNameWithPattern attempts: replace manually assigned signature bytes with the existing signature-check helper (196/199, fourteen differences); retain the second signature check result and use the target non-wildcard extended-name check (196/199, identical prefix); retained this version. The target symbol includes three instructions from the following outlined iterator body after its return; no padding or symbol-size adjustment was added. + +getShortName and parseShortName are already objdiff exact; their raw ctxdiff differences are relocation-dependent conditional branches to shared outlined code. These are not source regressions. diff --git a/tools/decomp-assist/attempts/fa-finish-pf_system.md b/tools/decomp-assist/attempts/fa-finish-pf_system.md new file mode 100644 index 00000000..4c635841 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_system.md @@ -0,0 +1,69 @@ +# fa system continuation + +PFSYS_TimeStamp already reproduces all 29 original instructions in order. Its extracted symbol ends at mtlr, omitting the natural stack restoration and blr. No size or symbol adjustment attempted. + +store time before date +src 0x7c base 0x74 insns 31/29 +--- insert mine 10:10 base 10:18 + B 10 lwz r3, 0x1c(r1) + B 11 li r0, 1 + B 12 stw r3, 0(r30) + B 13 lwz r3, 0x18(r1) + B 14 addi r3, r3, 1 + B 15 stw r3, 4(r30) + B 16 lwz r3, 0x14(r1) + B 17 stw r3, 8(r30) +--- delete mine 11:12 base 19:19 + M 11 li r0, 1 +--- delete mine 18:25 base 25:25 + M 18 lwz r0, 0x1c(r1) + M 19 stw r0, 0(r30) + M 20 lwz r3, 0x18(r1) + M 21 addi r0, r3, 1 + M 22 stw r0, 4(r30) + M 23 lwz r0, 0x14(r1) + M 24 stw r0, 8(r30) +--- delete mine 29:31 base 29:29 + M 29 addi r1, r1, 0x40 + M 30 blr + +retain tick value as local +src 0x7c base 0x74 insns 31/29 +--- delete mine 29:31 base 29:29 + M 29 addi r1, r1, 0x40 + M 30 blr + +assign fixed millisecond before calendar fields +src 0x7c base 0x74 insns 31/29 +--- insert mine 10:10 base 10:11 + B 10 lwz r3, 0x1c(r1) +--- insert mine 11:11 base 12:24 + B 12 stw r3, 0(r30) + B 13 lwz r3, 0x18(r1) + B 14 addi r3, r3, 1 + B 15 stw r3, 4(r30) + B 16 lwz r3, 0x14(r1) + B 17 stw r3, 8(r30) + B 18 lwz r3, 0x10(r1) + B 19 stw r3, 0(r31) + B 20 lwz r3, 0xc(r1) + B 21 stw r3, 4(r31) + B 22 lwz r3, 8(r1) + B 23 stw r3, 8(r31) +--- delete mine 12:25 base 25:25 + M 12 lwz r0, 0x1c(r1) + M 13 stw r0, 0(r30) + M 14 lwz r3, 0x18(r1) + M 15 addi r0, r3, 1 + M 16 stw r0, 4(r30) + M 17 lwz r0, 0x14(r1) + M 18 stw r0, 8(r30) + M 19 lwz r0, 0x10(r1) + M 20 stw r0, 0(r31) + M 21 lwz r0, 0xc(r1) + M 22 stw r0, 4(r31) + M 23 lwz r0, 8(r1) + M 24 stw r0, 8(r31) +--- delete mine 29:31 base 29:29 + M 29 addi r1, r1, 0x40 + M 30 blr diff --git a/tools/decomp-assist/attempts/fa-finish-pf_volume.md b/tools/decomp-assist/attempts/fa-finish-pf_volume.md new file mode 100644 index 00000000..f85e0d69 --- /dev/null +++ b/tools/decomp-assist/attempts/fa-finish-pf_volume.md @@ -0,0 +1,27 @@ +# fa/pf_volume continuation + +Measured source variations; counts are source/target instructions and positional comparison differences. Each candidate was built separately and compared with ctxdiff. Variations were reverted unless instruction exact. Earlier targeted attempts remain in the existing fa attempt logs. + +PFVOL_p_setvol: +- rotate independent local declarations: 93/94, 83 differences. +- common operation status exit: 93/94, 83 differences. +- reverse independent local declarations: 93/94, 84 differences. +- Retained: [93, 94, 83]. + +PFVOL_attach: +- rotate independent local declarations: 174/176, 64 differences. +- common operation status exit: 174/176, 37 differences. +- reverse independent local declarations: 174/176, 64 differences. +- Retained: [174, 176, 37]. + +PFVOL_regctx: +- rotate independent local declarations: 75/75, 15 differences. +- common operation status exit: 75/75, 15 differences. +- reverse independent local declarations: 75/75, 20 differences. +- Retained: [75, 75, 15]. + +PFVOL_setcode: +- common operation status exit: 24/23, 20 differences. +- Retained: [23, 23, 17]. + +setcode additionally tried a copy helper taking both a destination codeset pointer and the source pointer (23/23, seventeen register/load-store differences, unchanged). Restored the original helper. The original aggregate-copy and loop variations, and all remaining volume functions' targeted three-attempt records, remain in fa-volume.md. diff --git a/tools/decomp-assist/attempts/fa-sd-drv.md b/tools/decomp-assist/attempts/fa-sd-drv.md new file mode 100644 index 00000000..3b900edd --- /dev/null +++ b/tools/decomp-assist/attempts/fa-sd-drv.md @@ -0,0 +1,94 @@ +# fa/driver/sd_drv + +Baseline 9/26. Matching vf/develop/sd_drv.c exists, but uses VFSys handles rather than this driver's single media state. Its API and error handling cannot be ported directly. + +Explicit adaptations: combined physical-I/O success exits and positive partial-completion tests (127/127, two argument register differences); reordered sector/counter locals (twelve differences reduced to two); extracted aligned single/multi helpers (141/127, rejected) and separate call helpers (127/127, unchanged, rejected). Added the missing unregister diagnostic argument. Corrected full-format reset/eject state, status diagnostic and success/error return boundaries (105/117 to 117/117, seven stack offsets remain). + +Three-source-variation sweep, source/target instruction counts and positional differences: + +pfd_sddrv_get_disk_info: +- rotate independent local declarations: 98/96, 0 positional differences. +- normal path first, validation failure last: 98/96, 80 positional differences. +- common operation status exit: 98/96, 29 positional differences. + +pfd_sddrv_physical_write: +- rotate independent local declarations: 127/127, 2 positional differences. +- normal path first, validation failure last: 127/127, 99 positional differences. +- common operation status exit: 127/127, 2 positional differences. + +pfd_sddrv_physical_read: +- rotate independent local declarations: 127/127, 2 positional differences. +- normal path first, validation failure last: 127/127, 99 positional differences. +- common operation status exit: 127/127, 2 positional differences. + +pfd_sddrv_full_format: +- rotate independent local declarations: 117/117, 7 positional differences. +- normal path first, validation failure last: 117/117, 78 positional differences. +- common operation status exit: 116/117, 62 positional differences. + +pfd_sddrv_init: +- rotate independent local declarations: 143/144, 137 positional differences. +- normal path first, validation failure last: 143/144, 141 positional differences. +- common operation status exit: 142/144, 138 positional differences. + +pfd_sddrv_finalize: +- normal path first, validation failure last: 57/57, 49 positional differences. +- common operation status exit: 57/57, 43 positional differences. +- Prior explicit helper extraction in this function: instruction stream unchanged; see adaptations above. + +pfd_st_inter_callback: +- normal path first, validation failure last: 65/69, 59 positional differences. +- common operation status exit: 65/69, 51 positional differences. +- Prior explicit helper extraction in this function: instruction stream unchanged; see adaptations above. + +pfd_st_removal_callback: +- normal path first, validation failure last: 62/66, 56 positional differences. +- common operation status exit: 62/66, 49 positional differences. +- Prior explicit helper extraction in this function: instruction stream unchanged; see adaptations above. + +pfd_sddrv_get_total_sectors: +- rotate independent local declarations: 79/80, 42 positional differences. +- normal path first, validation failure last: 79/80, 67 positional differences. +- common operation status exit: 79/80, 42 positional differences. + +pfd_sddrv_calc_fat32_mbr_bpb: +- rotate independent local declarations: 131/133, 94 positional differences. +- normal path first, validation failure last: 131/133, 122 positional differences. +- common operation status exit: 131/133, 98 positional differences. + +pfd_sddrv_store_fat32_bpb_buf: +- rotate independent local declarations: 296/370, 272 positional differences. +- normal path first, validation failure last: 296/370, 282 positional differences. +- common operation status exit: 296/370, 272 positional differences. + +pfd_sddrv_unmount: +- normal path first, validation failure last: 12/13, 11 positional differences. +- common operation status exit: 12/13, 8 positional differences. +- Prior explicit helper extraction in this function: instruction stream unchanged; see adaptations above. + +pfd_sddrv_store_fat32_mbr_buf: +- rotate independent local declarations: 187/207, 150 positional differences. +- normal path first, validation failure last: 187/207, 176 positional differences. +- common operation status exit: 187/207, 150 positional differences. + +pfd_sddrv_store_bpb_buf: +- rotate independent local declarations: 244/327, 233 positional differences. +- normal path first, validation failure last: 244/327, 233 positional differences. +- common operation status exit: 244/327, 233 positional differences. + +pfd_sddrv_build_fat32_mbr_bpb: +- rotate independent local declarations: 222/222, 211 positional differences. +- normal path first, validation failure last: 222/222, 181 positional differences. +- common operation status exit: 218/222, 204 positional differences. + +pfd_sddrv_store_mbr_buf: +- rotate independent local declarations: 155/202, 149 positional differences. +- normal path first, validation failure last: 155/202, 148 positional differences. +- common operation status exit: 155/202, 149 positional differences. + +pfd_sddrv_calc_mbr_bpb: +- rotate independent local declarations: 239/173, 171 positional differences. +- normal path first, validation failure last: 239/173, 171 positional differences. +- common operation status exit: 239/173, 171 positional differences. + +Retained targeted changes rather than generic common-return reshaping. Remaining format serializers differ in inline endian/copy expansion; calculators differ in arithmetic widths and iteration. Callback/global flag reload scheduling differs. get_disk_info has an identical 96-instruction prefix but two additional epilogue instructions. No symbol sizes changed. -- 2.49.1 From 8f534407d26631205235e4e998d61a32580811c9 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 30 Sep 2026 06:31:19 +0000 Subject: [PATCH 3/4] fa: link pf_attach/detach/mkdir/mount/remove/rename/rmdir/unmount pf_mount.c and pf_rename.c implemented; all 8 units objdiff 100% (text + relocs identical) and flipped to Matching. DOL hash verified. Co-Authored-By: wch --- configure.py | 16 ++++++++-------- libs/RVL_SDK/src/fa/pf_mount.c | 10 ++++++++++ libs/RVL_SDK/src/fa/pf_rename.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 libs/RVL_SDK/src/fa/pf_mount.c create mode 100644 libs/RVL_SDK/src/fa/pf_rename.c diff --git a/configure.py b/configure.py index f120143e..91f3271d 100644 --- a/configure.py +++ b/configure.py @@ -1708,7 +1708,7 @@ config.libs = [ Object(NonMatching, "fa/pf_volume_apiadd.c"), Object(NonMatching, "fa/pf_cp932.c"), Object(Matching, "fa/pf_api_util.c"), - Object(NonMatching, "fa/pf_attach.c"), + Object(Matching, "fa/pf_attach.c"), Object(NonMatching, "fa/pf_buffering.c"), Object(NonMatching, "fa/pf_cdelete.c"), Object(NonMatching, "fa/pf_chdir.c"), @@ -1721,7 +1721,7 @@ config.libs = [ Object(NonMatching, "fa/pf_createdir.c"), Object(NonMatching, "fa/pf_cut.c"), Object(NonMatching, "fa/pf_derrnum.c"), - Object(NonMatching, "fa/pf_detach.c"), + Object(Matching, "fa/pf_detach.c"), Object(NonMatching, "fa/pf_divide.c"), Object(Matching, "fa/pf_errnum.c"), Object(NonMatching, "fa/pf_fadjust.c"), @@ -1750,16 +1750,16 @@ config.libs = [ Object(NonMatching, "fa/pf_init_prfile2.c"), Object(NonMatching, "fa/pf_insert.c"), Object(NonMatching, "fa/pf_iswriteprotected.c"), - Object(NonMatching, "fa/pf_mkdir.c"), - Object(NonMatching, "fa/pf_mount.c"), + Object(Matching, "fa/pf_mkdir.c"), + Object(Matching, "fa/pf_mount.c"), Object(NonMatching, "fa/pf_move.c"), Object(NonMatching, "fa/pf_opendir.c"), Object(NonMatching, "fa/pf_readdir.c"), Object(NonMatching, "fa/pf_regctx.c"), - Object(NonMatching, "fa/pf_remove.c"), - Object(NonMatching, "fa/pf_rename.c"), + Object(Matching, "fa/pf_remove.c"), + Object(Matching, "fa/pf_rename.c"), Object(NonMatching, "fa/pf_rewinddir.c"), - Object(NonMatching, "fa/pf_rmdir.c"), + Object(Matching, "fa/pf_rmdir.c"), Object(NonMatching, "fa/pf_rmvvol.c"), Object(NonMatching, "fa/pf_seekdir.c"), Object(NonMatching, "fa/pf_setclstlink.c"), @@ -1771,7 +1771,7 @@ config.libs = [ Object(NonMatching, "fa/pf_setvolcfg.c"), Object(NonMatching, "fa/pf_sync.c"), Object(NonMatching, "fa/pf_telldir.c"), - Object(NonMatching, "fa/pf_unmount.c"), + Object(Matching, "fa/pf_unmount.c"), Object(NonMatching, "fa/pf_unregctx.c"), Object(NonMatching, "fa/pf_xdivide.c"), Object(Matching, "fa/pf_w_api_util.c"), diff --git a/libs/RVL_SDK/src/fa/pf_mount.c b/libs/RVL_SDK/src/fa/pf_mount.c new file mode 100644 index 00000000..88469ada --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_mount.c @@ -0,0 +1,10 @@ +#include + +extern pf_s32 PFVOL_mount(pf_s8 drv_char); +extern pf_s32 PFAPI_convertReturnValue(pf_s32 err); + +pf_int32 pf2_mount(pf_ch8 drive) { + pf_s32 err = PFVOL_mount(drive); + err = PFAPI_convertReturnValue(err); + return err; +} diff --git a/libs/RVL_SDK/src/fa/pf_rename.c b/libs/RVL_SDK/src/fa/pf_rename.c new file mode 100644 index 00000000..9c1f0c05 --- /dev/null +++ b/libs/RVL_SDK/src/fa/pf_rename.c @@ -0,0 +1,29 @@ +#define PF_FA_STR_LAYOUT +#include +#include + +typedef struct PFAPI_GLOBAL_STATE { + pf_u8 volume_state[0x40]; + pf_s32 last_error; +} PFAPI_GLOBAL_STATE; +extern PFAPI_GLOBAL_STATE pf_vol_set; + +extern pf_s32 PFSTR_InitStr(PF_STR* p_str, const pf_s8* s, pf_u32 code_mode); +extern pf_s32 PFDIR_rename(PF_STR* old_path, PF_STR* new_path); +extern pf_s32 PFAPI_convertReturnValue(pf_s32 err); + +pf_int32 pf2_rename(const pf_ch8* oldPath, const pf_ch8* newPath) { + pf_s32 err; + PF_STR old_str; + PF_STR new_str; + + err = PFSTR_InitStr(&old_str, (pf_s8*)oldPath, 1U); + err |= PFSTR_InitStr(&new_str, (pf_s8*)newPath, 1U); + if (err == 0) { + err = PFDIR_rename(&old_str, &new_str); + } else { + pf_vol_set.last_error = err; + } + err = PFAPI_convertReturnValue(err); + return err; +} -- 2.49.1 From e81a2616cd0a4f42eb04e72f3eca00a492332fa5 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Wed, 30 Sep 2026 01:43:30 -0500 Subject: [PATCH 4/4] vi3in1, kbd_lib, iplMemoryCardManager: closer non-exact functions (worker 04cfeb7d) (#345) --- libs/RVL_SDK/src/kbd/kbd_lib.c | 125 +++++++++--------- libs/RVL_SDK/src/vi/vi3in1.c | 2 +- src/scene/memoryCard/iplMemoryCardManager.cpp | 18 ++- .../iplMemoryCardManager.attempts.md | 66 +++++++++ tools/decomp-assist/kbd_lib.attempts.md | 73 ++++++++++ tools/decomp-assist/vi3in1.attempts.md | 30 +++++ 6 files changed, 247 insertions(+), 67 deletions(-) diff --git a/libs/RVL_SDK/src/kbd/kbd_lib.c b/libs/RVL_SDK/src/kbd/kbd_lib.c index 5e43d176..c4f1f1e9 100644 --- a/libs/RVL_SDK/src/kbd/kbd_lib.c +++ b/libs/RVL_SDK/src/kbd/kbd_lib.c @@ -10,6 +10,15 @@ typedef union { u32 locks : 26; u32 physical : 6; } bits; + struct { + u32 flags : 26; + u32 rightAlt : 1; + u32 leftAlt : 1; + u32 rightShift : 1; + u32 leftShift : 1; + u32 rightControl : 1; + u32 leftControl : 1; + } keys; } KBDModifierState; typedef struct { @@ -72,7 +81,7 @@ static USBKBDAttachCallback kbdDevAttachCallback; static USBKBDDetachCallback kbdDevDetachCallback; static void (*kbdKeyCallback)(KBDKeyEventData* event); -KBDKeyMapTable kbdKeyMaps; +KBDKeyMapTable kbdKeyMaps = {0}; typedef struct { u32 device; u8 leds; @@ -81,7 +90,7 @@ typedef struct { void* callbackArg; } KBDLEDCommand; -KBDLEDCommand kbdCmdBuf[12]; +KBDLEDCommand kbdCmdBuf[12] = {0}; KBDChannel kbdData[4]; KBDLEDCallbackData kbdLCBuf[12]; @@ -224,7 +233,8 @@ static void kbdEventHandler(void* device, char* report) { KBDChannel* data; u8* bytes; u8 status; - data = &kbdData[channel]; + data = kbdData; + data += channel; bytes = (u8*)report; status = bytes[2]; @@ -243,12 +253,12 @@ static void kbdEventHandler(void* device, char* report) { VIResetDimmingCount(); - for (i = 0, mask = 1; i < 8; i++, mask <<= 1) { - if ((data->modifiers & (u8)mask) != 0) { - if ((bytes[0] & (u8)mask) == 0) { + for (mask = 1, i = 0; i < 8; i++, mask <<= 1) { + if ((data->modifiers & mask) != 0) { + if ((bytes[0] & mask) == 0) { kbdProcKey((u8)(i + 0xe0), 0, channel); } - } else if ((bytes[0] & (u8)mask) != 0) { + } else if ((bytes[0] & mask) != 0) { kbdProcKey((u8)(i + 0xe0), 1, channel); } } @@ -392,86 +402,86 @@ static void kbdProcKey(u32 key, u32 pressed, u32 channel) { static void kbdProcMod(u32 key, u32 pressed, u32 channel) { KBDChannel* data; - s8 delta; + s32 delta; u8 flags; - u32 state; + KBDModifierState state; u32 finalState; s8 value; data = &kbdData[channel]; delta = (pressed & 1) != 0 ? 1 : -1; flags = kbdKeyMaps.maps[data->country].flags; - state = 0; + state.value = data->modState; - kbdGetModState(channel, &state); + kbdGetModState(channel, &state.value); switch (key) { case 0xF001: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 2; + state.value ^= 2; } } else { value = data->lockCount[1] + delta; data->lockCount[1] = value; - state = (state & 0xFFFFFFFD) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1E & 2); - } + state.keys.rightControl = (u8)value != 0; + } break; case 0xF005: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 0x20; + state.value ^= 0x20; } } else { value = data->lockCount[4] + delta; data->lockCount[4] = value; - state = (state & 0xFFFFFFDF) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1A & 0x20); - } + state.keys.rightAlt = (u8)value != 0; + } break; case 0xF000: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 1; + state.value ^= 1; } } else { value = data->lockCount[0] + delta; data->lockCount[0] = value; - state = (state & 0xFFFFFFFE) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1F); - } + state.keys.leftControl = (u8)value != 0; + } break; case 0xF008: if (((pressed & 1) != 0) && (data->lockProcessing != 0)) { - state ^= 0x200; + state.value ^= 0x200; } break; case 0xF007: if (((pressed & 1) != 0) && (data->lockProcessing != 0)) { - state ^= 0x100; + state.value ^= 0x100; } break; case 0xF006: if (((pressed & 1) != 0) && (data->lockProcessing != 0)) { u32 oldState; u32 lockState; - oldState = state; + oldState = state.value; lockState = oldState & 0xC0; switch (lockState) { case 0: if ((flags & 1) == 1) { - state = oldState | 0x40; + state.value = oldState | 0x40; } break; case 0x40: { - state = oldState & 0xFFFFFFBF; + state.value = oldState & 0xFFFFFFBF; if ((flags & 4) == 4) { - state = oldState & 0xFFFFFFBF | 0x80; + state.value = oldState & 0xFFFFFFBF | 0x80; } } break; case 0x80: - state = oldState & 0xFFFFFF7F; + state.value = oldState & 0xFFFFFF7F; break; case 0xC0: - state = oldState & 0xFFFFFF3F; + state.value = oldState & 0xFFFFFF3F; break; } } @@ -479,43 +489,43 @@ static void kbdProcMod(u32 key, u32 pressed, u32 channel) { case 0xF002: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 4; + state.value ^= 4; } } else { value = data->lockCount[2] + delta; data->lockCount[2] = value; - state = (state & 0xFFFFFFFB) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1D & 4); - } + state.keys.leftShift = (u8)value != 0; + } break; case 0xF003: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 8; + state.value ^= 8; } } else { value = data->lockCount[3] + delta; data->lockCount[3] = value; - state = (state & 0xFFFFFFF7) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1C & 8); - } + state.keys.rightShift = (u8)value != 0; + } break; case 0xF004: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 0x10; + state.value ^= 0x10; } } else { value = data->lockCount[5] + delta; data->lockCount[5] = value; - state = (state & 0xFFFFFFEF) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1B & 0x10); - } + state.keys.leftAlt = (u8)value != 0; + } break; case 0xF021: if (((pressed & 1) != 0) && (data->lockProcessing != 0)) { - state ^= 0x400; + state.value ^= 0x400; } break; } - finalState = state | 0x1000; + finalState = state.value | 0x1000; KBDSetModState(channel, finalState); } @@ -572,6 +582,7 @@ static void kbd_led_handler(BOOL success, void* callbackArg) { USBKBDErr KBDSetLedsAsync(u32 channel, u32 leds, USBKBDCmdLEDCallback callback, void* callbackArg) { u32 index; + u8 ledBits; BOOL interrupts; USBKBDErr result; if (!kbdInitialized) { @@ -583,7 +594,7 @@ USBKBDErr KBDSetLedsAsync(u32 channel, u32 leds, USBKBDCmdLEDCallback callback, if ((s32)kbdData[channel].flags == 1 || (s32)kbdData[channel].flags == 4) { return 5; } - leds &= 0xff; + ledBits = leds; interrupts = OSDisableInterrupts(); for (index = 0; index < 12; index++) { if (kbdCmdBuf[index].device == 0) { @@ -597,7 +608,7 @@ USBKBDErr KBDSetLedsAsync(u32 channel, u32 leds, USBKBDCmdLEDCallback callback, } kbdLCBuf[index].callbackAddress = (u32)callback; kbdLCBuf[index].callbackArg = callbackArg; - result = USBKBDSetLEDAsync((u32)kbdData[channel].device, leds, + result = USBKBDSetLEDAsync((u32)kbdData[channel].device, ledBits, (USBKBDCmdLEDAsync*)&kbdCmdBuf[index], kbd_led_handler, (void*)index); if (result != 0) { @@ -622,7 +633,7 @@ USBKBDErr KBDSetLeds(u32 channel, u32 leds) { leds &= 0xff; interrupts = OSDisableInterrupts(); for (index = 0; index < 12; index++) { - if (kbdCmdBuf[index].device == 0) { + if ((kbdCmdBuf + index)->device == 0) { kbdCmdBuf[index].device = (u32)kbdData[channel].device; break; } @@ -634,10 +645,10 @@ USBKBDErr KBDSetLeds(u32 channel, u32 leds) { result = USBKBDSetLED((u32)kbdData[channel].device, leds, (USBKBDCmdLED*)&kbdCmdBuf[index]); kbdCmdBuf[index].device = 0; - if (result != 0) { - return 7; + if (result == 0) { + return 0; } - return 0; + return 7; } void kbdInitMap(u32 country, u8 codeCount, u8 flags, u16* keyMap, u16* modifierMap, @@ -879,22 +890,18 @@ u16 KBDTranslateHidCode(u32 keyCode, u32 modifiers, s32 country) { group = 1; offset = 0; } else { - if ((modifiers & 0x20) == 0 && (modifiers & 5) != 5) { - if ((modifiers & 0x40) == 0) { - if ((modifiers & 0x80) == 0) { - group = 1; - shiftFlag = 1; - } else { - group = map->shiftIndex; - shiftFlag = 0x10; - } - } else { - group = map->lockIndex; - shiftFlag = 4; - } - } else { + if ((modifiers & 0x20) == 0x20 || (modifiers & 5) == 5) { group = map->altIndex; shiftFlag = 0x40; + } else if ((modifiers & 0x40) == 0x40) { + group = map->lockIndex; + shiftFlag = 4; + } else if ((modifiers & 0x80) == 0x80) { + group = map->shiftIndex; + shiftFlag = 0x10; + } else { + group = 1; + shiftFlag = 1; } if ((modifiers & 0x800) == 0 && (modifiers & 0x1D) != 0) { diff --git a/libs/RVL_SDK/src/vi/vi3in1.c b/libs/RVL_SDK/src/vi/vi3in1.c index 1b56acf0..4ba0c587 100644 --- a/libs/RVL_SDK/src/vi/vi3in1.c +++ b/libs/RVL_SDK/src/vi/vi3in1.c @@ -115,10 +115,10 @@ void VISetMacrovision(s32 type); u32 copyIndex; \ u8* destination = (dst); \ const u8* source = (src); \ + destination[0] = 0x40; \ for (copyIndex = 0; copyIndex < 0x1a; copyIndex++) { \ destination[copyIndex + 1] = source[copyIndex]; \ } \ - destination[0] = 0x40; \ } while (0) static u8 __wd0 = 0xff; diff --git a/src/scene/memoryCard/iplMemoryCardManager.cpp b/src/scene/memoryCard/iplMemoryCardManager.cpp index 791872d2..90e1f417 100644 --- a/src/scene/memoryCard/iplMemoryCardManager.cpp +++ b/src/scene/memoryCard/iplMemoryCardManager.cpp @@ -401,24 +401,28 @@ const wchar_t* MemoryCardManager::getComment(u8 slot, s16 index, int which) { } if (SCGetLanguage() == 0) { utility::CharacterCode::shiftJISToUTF16(dest, reinterpret_cast(comment), 0x20); - for (int pos = 0x1f; dest[pos] == 0x20 || dest[pos] == 0x3000 || dest[pos] == 10 || dest[pos] == 0; pos--) { - dest[pos] = 0; + for (int pos = 0x1f; + mFileCell[slot][file].comment[which][pos] == 0x20 || + mFileCell[slot][file].comment[which][pos] == 0x3000 || + mFileCell[slot][file].comment[which][pos] == 10 || + mFileCell[slot][file].comment[which][pos] == 0;) { + mFileCell[slot][file].comment[which][pos--] = 0; } } else { utility::CharacterCode::ANSIToUTF16(dest, reinterpret_cast(comment), 0x20); } bool found = false; int count = 0; - while (dest[count] != 0 && count < 0x20) { + while (mFileCell[slot][file].comment[which][count] != 0 && count < 0x20) { if (found) { - dest[count] = 0; - } else if (dest[count] == 10 || dest[count] == 0xd0a) { - dest[count] = 0; + mFileCell[slot][file].comment[which][count] = 0; + } else if (mFileCell[slot][file].comment[which][count] == 10 || mFileCell[slot][file].comment[which][count] == 0xd0a) { + mFileCell[slot][file].comment[which][count] = 0; found = true; } count++; } - return dest; + return mFileCell[slot][file].comment[which]; } GXTexObj* MemoryCardManager::create_banner(u8 slot, s16 index) { diff --git a/tools/decomp-assist/iplMemoryCardManager.attempts.md b/tools/decomp-assist/iplMemoryCardManager.attempts.md index 7020ae30..f3214869 100644 --- a/tools/decomp-assist/iplMemoryCardManager.attempts.md +++ b/tools/decomp-assist/iplMemoryCardManager.attempts.md @@ -105,3 +105,69 @@ Final instruction evidence: Measured waves 1-4, objdiff percent: 74.96, 92.0, 91.0, 92.0. Final instruction evidence: `src 0x64 base 0x64 insns 25/25; diffs 9: [11, 12, 13, 14, 15, 16, 17, 18, 19]` + +# Continuation from eaee2295 + +## update_file_array__Q33ipl5scene17MemoryCardManagerFUc +1. Compare command bounds directly instead of subtracting one: 97.5%; src 0x16c base 0x168 insns 91/90 +2. Use unsigned command local and a signed range test: 97.44444%; src 0x16c base 0x168 insns 91/90 +3. Switch on the separately loaded command value: 93.344444%; src 0x164 base 0x168 insns 89/90 + +## sort_file_array__Q33ipl5scene17MemoryCardManagerFUc +1. Use an unsigned file counter: 98.13725%; src 0xcc base 0xcc insns 51/51 +2. Assign the common file number and high key word before the directory branch: 72.333336%; src 0xbc base 0xcc insns 47/51 +3. Name the live sort key before copying its low and high words: 97.90196%; src 0xcc base 0xcc insns 51/51 + +## update_icon_anm__Q33ipl5scene17MemoryCardManagerFv +1. Keep the frame limit local to each comparison: 96.78571%; src 0x14c base 0x150 insns 83/84 +2. Reload frame counter after its store instead of using the local: 96.78571%; src 0x14c base 0x150 insns 83/84 +3. Use an explicit cell pointer only for animation-counter fields: 94.32143%; src 0x150 base 0x150 insns 84/84 + +## isBannerEnable__Q33ipl5scene17MemoryCardManagerFUcs +1. Direct member return without a result local: 92.30769%; src 0x68 base 0x68 insns 26/26 +2. Cache member file number before querying the icon array: 34.0%; src 0x60 base 0x68 insns 24/26 +3. Store banner flag in a word before Boolean conversion: 92.30769%; src 0x68 base 0x68 insns 26/26 + +## getBlocks__Q33ipl5scene17MemoryCardManagerFUcs +1. Keep the file index signed before directory lookup: 92.0%; src 0x64 base 0x64 insns 25/25 +2. Cache file number before querying directory state: 26.08%; src 0x5c base 0x64 insns 23/25 +3. Use a directory-entry pointer and word result local: 91.0%; src 0x64 base 0x64 insns 25/25 + +## isMoveEnable__Q33ipl5scene17MemoryCardManagerFUcUlPl +1. Initialize destination state from the queried state array: 88.89831%; src 0x1e4 base 0x1d8 insns 121/118 +2. Cache destination-card pointer before the readiness test: 83.89831%; src 0x1d4 base 0x1d8 insns 117/118 +3. Use a single ready predicate and explicit error-code branches: 89.66102%; src 0x1e4 base 0x1d8 insns 121/118 + +## isCopyEnable__Q33ipl5scene17MemoryCardManagerFUcUlPl +1. Initialize destination state from the queried state array: 88.89831%; src 0x1e4 base 0x1d8 insns 121/118 +2. Cache destination-card pointer before the readiness test: 83.89831%; src 0x1d4 base 0x1d8 insns 117/118 +3. Use a single ready predicate and explicit error-code branches: 89.66102%; src 0x1e4 base 0x1d8 insns 121/118 + +## create_icon__Q33ipl5scene17MemoryCardManagerFUcs +1. Use signed 16-bit frame directly in the shift and compare with eight: 86.17647%; src 0xcc base 0xcc insns 51/51 +2. Cache the current animation count before the frame loop: 86.84314%; src 0xc8 base 0xcc insns 50/51 +3. Advance frame after accumulating its duration: 86.17647%; src 0xcc base 0xcc insns 51/51 +4. Cache icon-state entry and current frame, use post-increment in shift: 86.17647%; src 0xcc base 0xcc insns 51/51 +5. Use a for-loop with signed 16-bit frame bound and direct shift: 83.01961%; src 0xcc base 0xcc insns 51/51 +6. Use separate signed 16-bit shift and current frame local: 86.17647%; src 0xcc base 0xcc insns 51/51 + +## _create_icon__Q33ipl5scene17MemoryCardManagerFUcsl +1. Compute the frame image pointer before choosing its texture format: 63.98%; src 0x174 base 0x190 insns 93/100 +2. Use a switch on the signed icon format: 77.64%; src 0x18c base 0x190 insns 99/100 +3. Share texture destination and TLUT pointer locals across format branches: 57.17%; src 0x164 base 0x190 insns 89/100 + +## getComment__Q33ipl5scene17MemoryCardManagerFUcsi +1. Direct cell-member trimming and return, variation 1: 88.29269%; src 0x1d4 base 0x1ec insns 117/123 +2. Direct cell-member trimming and return, variation 2: 90.04065%; src 0x1e4 base 0x1ec insns 121/123 +3. Direct cell-member trimming and return, variation 3: 88.55285%; src 0x1e0 base 0x1ec insns 120/123 +4. Keep cell-base pointer for the return and signed byte trim pointers: 90.04065%; src 0x1e4 base 0x1ec insns 121/123 +5. Use indexed reads and post-decrement indexed writes in wide trim: 93.08943%; src 0x1e8 base 0x1ec insns 122/123 +6. Use a signed file index and explicit pointer zero-initialization loop: 56.91057%; src 0x1e4 base 0x1ec insns 121/123 + +## create_banner__Q33ipl5scene17MemoryCardManagerFUcs +1. Compute banner data pointer before choosing format: 63.95283%; src 0x194 base 0x1a8 insns 101/106 +2. Use a structured banner-format switch: 72.79245%; src 0x1a4 base 0x1a8 insns 105/106 +3. Cache banner texture after validating file and icon metadata: 55.679245%; src 0x16c base 0x1a8 insns 91/106 + +A unit-only guarded u32 getBlocks return declaration was tested: same 25/25 instructions and nine epilogue-scheduling differences. Header and macro restored. No target or source data sections. +No new instruction-exact functions yet; retained source experiments remain uncommitted pending an exact-function gain. diff --git a/tools/decomp-assist/kbd_lib.attempts.md b/tools/decomp-assist/kbd_lib.attempts.md index a77f98dc..2a576654 100644 --- a/tools/decomp-assist/kbd_lib.attempts.md +++ b/tools/decomp-assist/kbd_lib.attempts.md @@ -64,3 +64,76 @@ Instruction diffs retained in /tmp/sol-low-kbd-final-ctx.txt. ## Final gate discrepancy KBDResetChannel has objdiff 100.0% and identical 176-byte instruction contents. The gate reports 12/21 instead of 13/21 because odiff.dis treats the first CR1 conditional-branch operand as an immediate and subtracts the different symbol offsets. Both disputed branch instruction words are identical. Tools were left unchanged. + +# Continuation from eaee2295 + +## kbdEventHandler +1. Use the word mask directly for both report bytes: 99.72043%; src 0x2e8 base 0x2e8 insns 186/186 +2. Initialize loop mask before the loop, retain byte conversion: 99.166664%; src 0x2ec base 0x2e8 insns 187/186 +3. Use report-status byte local for error classification: 98.63441%; src 0x2e8 base 0x2e8 insns 186/186 +4. Set mask before index in the word-mask loop initializer: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +5. Calculate report status before looking up channel data: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +6. Declare bytes before channel data and use a channel pointer expression: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +7. Use an unsigned report-status word only for the range check: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +8. Perform error classification before forming the channel pointer: 92.150536%; src 0x2f8 base 0x2e8 insns 190/186 +9. Form channel pointer with a byte-sized channel index: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +10. Typed HID report fields, variation 1: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +11. Typed HID report fields, variation 2: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +12. Typed HID report fields, variation 3: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +13. Separate channel-array base and channel selection: 99.83871%; src 0x2e8 base 0x2e8 insns 186/186 +14. Keep a typed channel-array local through channel lookup: 98.81721%; src 0x2e0 base 0x2e8 insns 184/186 +15. Use the report word status minus one as signed arithmetic before narrowing: 99.752686%; src 0x2e8 base 0x2e8 insns 186/186 +16. Declare and initialize channel record at the top of the found-channel block: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +17. Express channel selection with the index as the left operand: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +18. Declare a separate channel-array base for the selected record: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +19. Load report state before final channel selection and use a word local: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 + +## KBDSetModState +1. Merge physical bits using a scalar mask instead of bitfields: 98.690475%; src 0xa8 base 0xa8 insns 42/42 +2. Compute channel pointer before disabling interrupts: 86.54762%; src 0xa4 base 0xa8 insns 41/42 +3. Use an initialized modifier union and write both fields: 93.21429%; src 0xb0 base 0xa8 insns 44/42 + +## kbdProcKey +1. Initialize getter destination with the known channel modifier state: 94.50581%; src 0x2b4 base 0x2b0 insns 173/172 +2. Initialize event fields as one aggregate before channel lookup: build rejected (ninja: build stopped: subcommand failed.). +3. Read modifiers directly after validating the known channel: 87.6686%; src 0x294 base 0x2b0 insns 165/172 +4. Initialize a separate modifier destination then copy to the event: 94.50581%; src 0x2bc base 0x2b0 insns 175/172 +5. Zero-initialize the entire event before filling fields: 95.75581%; src 0x2c0 base 0x2b0 insns 176/172 +6. Check getter status explicitly and initialize on failure: 92.93604%; src 0x2dc base 0x2b0 insns 183/172 + +## kbd_led_handler +1. Use a typed callback record and clear command first: 48.16%; src 0x54 base 0x64 insns 21/25 +2. Return mapped result through if/else instead of switch: 39.36%; src 0x58 base 0x64 insns 22/25 +3. Reload callback at the call and compare against numeric zero: 62.2%; src 0x58 base 0x64 insns 22/25 + +## KBDSetLedsAsync +1. Keep narrowed LED bits in a separate byte: 79.5679%; src 0x138 base 0x144 insns 78/81 +2. Scan commands by index and test success before failure: 73.38271%; src 0x13c base 0x144 insns 79/81 +3. Use a command-record pointer during reservation: 74.80247%; src 0x134 base 0x144 insns 77/81 +4. Explicitly zero-initialize keyboard map and command records: 79.604935%; src 0x138 base 0x144 insns 78/81 +5. Explicitly zero-initialize all real keyboard workspaces: 79.604935%; src 0x138 base 0x144 insns 78/81 +6. Explicitly zero-initialize the typed per-channel state: 79.5679%; src 0x138 base 0x144 insns 78/81 + +## KBDSetLeds +1. Keep narrowed LED bits in a separate byte: 72.620255%; src 0x134 base 0x13c insns 77/79 +2. Scan commands by index and test success before failure: 73.177216%; src 0x138 base 0x13c insns 78/79 +3. Use a command-record pointer during reservation: 72.27848%; src 0x12c base 0x13c insns 75/79 + +## kbdProcMod +1. Use unsigned byte counts and logical nonzero masks: 75.78125%; src 0x3c0 base 0x400 insns 240/256 +2. Use an initialized modifier union for the switch updates: 75.78125%; src 0x3c0 base 0x400 insns 240/256 +3. Initialize from channel state and use word-sized count delta: 75.97656%; src 0x3c0 base 0x400 insns 240/256 +4. Update named physical modifier bitfields: 78.90625%; src 0x3a0 base 0x400 insns 232/256 + +## KBDTranslateHidCode +1. Prioritize alt, lock and shift groups in a flat decision chain: 91.70731%; src 0x290 base 0x290 insns 164/164 +2. Keep entry mask and group indices signed: 89.597565%; src 0x290 base 0x290 insns 164/164 +3. Separate character offset calculation from table indexing: 86.29878%; src 0x284 base 0x290 insns 161/164 + +## Data and workspace checks +Named mutable SDK version text: matched data 3992/5296. Rejected; no improvement or data regression. +Named constant SDK version text: matched data 3984/5296. Rejected; no improvement or data regression. +Place SDK version declaration after the region tables: matched data 3984/5296. Rejected; no improvement or data regression. +Explicit zero-initialization of real map and command workspaces reproduces target BSS order: key maps 0x000, command records 0x400, channel state 0x580, callback records 0xf20. No extra objects or placement directives. +Using the existing SDK command type was also tested and produced identical function scores; the original private declaration was restored. +No new instruction-exact functions yet; retained source experiments remain uncommitted pending an exact-function gain. diff --git a/tools/decomp-assist/vi3in1.attempts.md b/tools/decomp-assist/vi3in1.attempts.md index 056c21fc..25d2355e 100644 --- a/tools/decomp-assist/vi3in1.attempts.md +++ b/tools/decomp-assist/vi3in1.attempts.md @@ -19,3 +19,33 @@ String pools identical. Data 1512/1512 bytes in objdiff. 1. Indexed ACP copy, original assignment order: 265/267 instructions, 96.82022%; saved constant register and byte-copy allocation differ. 2. Masked WSS operands and command-first caption assignment: 265/267; WSS and caption differences removed. Retained. 3. Explicit ACP byte copies: 266/267, 78.92135%; enlarged frame and save set. Rejected. + +# Continuation from eaee2295 + +## __VISetRevolutionModeSimple +1. Store ACP command before the ascending byte transfer: 97.05618%; src 0x424 base 0x42c insns 265/267 +2. Initialize power and clock command arrays at declaration: 94.29588%; src 0x428 base 0x42c insns 266/267 +3. Use signed ACP index and store command first: 97.05618%; src 0x424 base 0x42c insns 265/267 + +## VISetMacrovision +1. Copy old type after volume masking: 99.48529%; src 0x110 base 0x110 insns 68/68 +2. Load type before first byte, combine new flag operands: 99.48529%; src 0x110 base 0x110 insns 68/68 +3. Express mode dispatch as a structured switch: 99.48529%; src 0x110 base 0x110 insns 68/68 +4. Use word-sized intermediates for newType: 94.85294%; src 0x10c base 0x110 insns 67/68 +5. Use word-sized intermediates for newType, oldType: 94.85294%; src 0x10c base 0x110 insns 67/68 +6. Use word-sized intermediates for newType, oldWd0: 94.85294%; src 0x10c base 0x110 insns 67/68 +7. Use word-sized intermediates for oldWd0: 99.48529%; src 0x110 base 0x110 insns 68/68 +8. Use word-sized intermediates for newType, oldWd2: 94.85294%; src 0x10c base 0x110 insns 67/68 +9. Use word-sized intermediates for oldWd0, mode: 98.60294%; src 0x110 base 0x110 insns 68/68 +10. Use word-sized intermediates for oldType, mode: 98.60294%; src 0x110 base 0x110 insns 68/68 +11. Load WSS state in oldWd2,oldType,oldWd0 order: 99.411766%; src 0x110 base 0x110 insns 68/68 +12. Load WSS state in oldType,oldWd2,oldWd0 order: 99.411766%; src 0x110 base 0x110 insns 68/68 +13. Load WSS state in oldWd2,oldWd0,oldType order: 99.411766%; src 0x110 base 0x110 insns 68/68 + +## __VISetMacrovision +1. Descending remaining-byte count and advancing source/destination: 94.26905% +2. Assign command byte before indexed ACP transfer: 96.77598% +3. Signed copy index and named per-byte value: 94.26905% + +All data sections remain 100%; the ACP command-first assignment preserves pool contents and reaches 866/866 instructions, but allocation still differs. +No new instruction-exact functions yet; retained source experiments remain uncommitted pending an exact-function gain. -- 2.49.1