diff options
| author | louist103 <35883445+louist103@users.noreply.github.com> | 2023-05-29 20:39:14 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-29 20:39:14 -0400 |
| commit | 51cd9df591322c4541ca9697a4ce4a6acde1fad6 (patch) | |
| tree | d168a1f3bddd564b377fd2e749c92be496a4d1f2 /src/code | |
| parent | 4143097c5a6080a1ebbb3d328b85178ab13ab8e6 (diff) | |
sys_flashrom matched (#1251)
* done
* WIP
* Fix the rebase
* fix build
* re match
* Last thing before the PR
* PR fixes
* PR Fixes (tharo)
* fix
* format
* PR fixes (hensldm)
* oops
* MAGIC
* Fix BSS and rename FLASH_MAGIC
* PR Fixes (Engineer)
* remove from functions.h
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/sys_flashrom.c | 287 | ||||
| -rw-r--r-- | src/code/title_setup.c | 2 | ||||
| -rw-r--r-- | src/code/z_sram_NES.c | 81 |
3 files changed, 291 insertions, 79 deletions
diff --git a/src/code/sys_flashrom.c b/src/code/sys_flashrom.c index 0db0b8744..c2665741e 100644 --- a/src/code/sys_flashrom.c +++ b/src/code/sys_flashrom.c @@ -1,44 +1,253 @@ +#include "prevent_bss_reordering.h" #include "global.h" #include "stack.h" #include "stackcheck.h" #include "system_malloc.h" -// extern UNK_TYPE1 D_801FBE10; -// extern UNK_TYPE1 D_801FBE28; -// extern UNK_TYPE1 D_801FBE2C; -// extern UNK_TYPE4 D_801FBE30; -extern STACK(sSysFlashromStack, 0x1000); -extern StackEntry sSysFlashromStackInfo; -extern OSThread sSysFlashromThread; -extern s80185D40 D_801FD008; -extern OSMesg D_801FD034[1]; - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_801857C0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_801857D0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185864.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185908.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185968.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_801859F0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185A2C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185B1C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185BE4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185C24.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/SysFlashrom_ThreadEntry.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185DDC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185EC4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185F04.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_80185F64.s") +OSMesgQueue sFlashromMesgQueue; +OSMesg sFlashromMesg[1]; +s32 sFlashromIsInit; +s32 sFlashromVendor; + +STACK(sSysFlashromStack, 0x1000); +StackEntry sSysFlashromStackInfo; +OSThread sSysFlashromThread; +FlashromRequest sFlashromRequest; +OSMesg sSysFlashromMsgBuf[1]; + +s32 SysFlashrom_IsInit(void) { + return sFlashromIsInit; +} + +const char* SysFlashrom_GetVendorStr(void) { + switch (sFlashromVendor) { + case FLASH_VERSION_MX_PROTO_A: + return "PROTO A"; + + case FLASH_VERSION_MX_A: + return "A"; + + case FLASH_VERSION_MX_C: + return "C"; + + case FLASH_VERSION_MEI: + return "D(NEW)"; + + case FLASH_VERSION_MX_B_AND_D: + return "B or D"; + + default: + return "UNKNOWN"; + } +} + +s32 SysFlashrom_CheckFlashType(void) { + u32 flashType; + u32 flashVendor; + + if (!SysFlashrom_IsInit()) { + return -1; + } + osFlashReadId(&flashType, &flashVendor); + sFlashromVendor = flashVendor; + if (flashType == FLASH_TYPE_MAGIC) { + if ((flashVendor == FLASH_VERSION_MX_PROTO_A) || (flashVendor == FLASH_VERSION_MX_A) || + (flashVendor == FLASH_VERSION_MX_C) || (flashVendor == FLASH_VERSION_MEI) || + (flashVendor == FLASH_VERSION_MX_B_AND_D)) { + return 0; + } else { + return -1; + } + } + return -1; +} + +s32 SysFlashrom_InitFlash(void) { + osCreateMesgQueue(&sFlashromMesgQueue, sFlashromMesg, ARRAY_COUNT(sFlashromMesg)); + osFlashInit(); + sFlashromIsInit = true; + if (SysFlashrom_CheckFlashType() != 0) { + sFlashromIsInit = false; + return -1; + } + return 0; +} + +s32 SysFlashrom_ReadData(void* addr, u32 pageNum, u32 pageCount) { + OSIoMesg msg; + + if (!SysFlashrom_IsInit()) { + return -1; + } + osInvalDCache(addr, pageCount * FLASH_PAGE_SIZE); + osFlashReadArray(&msg, OS_MESG_PRI_NORMAL, pageNum, addr, pageCount, &sFlashromMesgQueue); + osRecvMesg(&sFlashromMesgQueue, NULL, OS_MESG_BLOCK); + return 0; +} + +s32 SysFlashrom_EraseSector(u32 page) { + if (!SysFlashrom_IsInit()) { + return -1; + } + return osFlashSectorErase(page); +} + +s32 SysFlashrom_ExecWrite(void* addr, u32 pageNum, u32 pageCount) { + OSIoMesg msg; + s32 result; + u32 i; + + if (!SysFlashrom_IsInit()) { + return -1; + } + // Ensure the page is always aligned to a sector boundary. + if ((pageNum % FLASH_PAGE_SIZE) != 0) { + Fault_AddHungupAndCrash("../sys_flashrom.c", 275); + } + osWritebackDCache(addr, pageCount * FLASH_PAGE_SIZE); + for (i = 0; i < pageCount; i++) { + osFlashWriteBuffer(&msg, OS_MESG_PRI_NORMAL, (u8*)addr + i * FLASH_PAGE_SIZE, &sFlashromMesgQueue); + osRecvMesg(&sFlashromMesgQueue, NULL, OS_MESG_BLOCK); + result = osFlashWriteArray(i + pageNum); + if (result != 0) { + return result; + } + } + return 0; +} + +s32 SysFlashrom_AttemptWrite(void* addr, u32 pageNum, u32 pageCount) { + s32 result; + s32 i; + + if (!SysFlashrom_IsInit()) { + return -1; + } + osWritebackDCache(addr, pageCount * FLASH_PAGE_SIZE); + i = 0; +failRetry: + result = SysFlashrom_EraseSector(pageNum); + if (result != 0) { + if (i < 3) { + i++; + goto failRetry; + } + return result; + } + result = SysFlashrom_ExecWrite(addr, pageNum, pageCount); + if (result != 0) { + if (i < 3) { + i++; + goto failRetry; + } + return result; + } + return 0; +} + +// Flash bits can only by flipped with a write from 1 -> 0. Going from 0 -> 1 requires an erasure. +// This function will try to determine if any sectors need to be erased before writing saving erase cycles. +s32 SysFlashrom_NeedsToErase(void* data, void* addr, u32 pageCount) { + u32 size; + u32 i; + + for (i = 0; i < pageCount * FLASH_PAGE_SIZE; i += 4) { + if ((*(s32*)data & *(s32*)addr) != *(s32*)addr) { + return false; + } + } + return true; +} + +s32 SysFlashrom_WriteData(void* addr, u32 pageNum, u32 pageCount) { + void* data; + size_t size; + s32 ret; + + if (!SysFlashrom_IsInit()) { + return -1; + } + size = pageCount * FLASH_PAGE_SIZE; + data = SystemArena_Malloc(size); + if (data == NULL) { + ret = SysFlashrom_AttemptWrite(addr, pageNum, pageCount); + } else { + SysFlashrom_ReadData(data, pageNum, pageCount); + if (bcmp(data, addr, size) == 0) { + ret = 0; + } else { + // Will always erase the sector even if it wouldn't normally need to. + if (SysFlashrom_NeedsToErase(data, addr, pageCount)) { + ret = SysFlashrom_AttemptWrite(addr, pageNum, pageCount); + } else { + ret = SysFlashrom_AttemptWrite(addr, pageNum, pageCount); + } + if (ret == 0) { + SysFlashrom_ReadData(data, pageNum, pageCount); + if (bcmp(data, addr, size) == 0) { + ret = 0; + } else { + ret = -1; + } + } + } + SystemArena_Free(data); + } + return ret; +} + +void SysFlashrom_ThreadEntry(void* arg) { + FlashromRequest* req = (FlashromRequest*)arg; + + switch (req->requestType) { + case FLASHROM_REQUEST_WRITE: + req->response = SysFlashrom_WriteData(req->addr, req->pageNum, req->pageCount); + osSendMesg(&req->messageQueue, req->response, OS_MESG_BLOCK); + break; + + case FLASHROM_REQUEST_READ: + req->response = SysFlashrom_ReadData(req->addr, req->pageNum, req->pageCount); + osSendMesg(&req->messageQueue, req->response, OS_MESG_BLOCK); + break; + } +} + +void SysFlashrom_WriteDataAsync(u8* addr, u32 pageNum, u32 pageCount) { + FlashromRequest* req = &sFlashromRequest; + if (SysFlashrom_IsInit()) { + req->requestType = FLASHROM_REQUEST_WRITE; + req->addr = addr; + req->pageNum = pageNum; + req->pageCount = pageCount; + osCreateMesgQueue(&req->messageQueue, sSysFlashromMsgBuf, ARRAY_COUNT(sSysFlashromMsgBuf)); + StackCheck_Init(&sSysFlashromStackInfo, sSysFlashromStack, STACK_TOP(sSysFlashromStack), 0, 0x100, + "sys_flashrom"); + osCreateThread(&sSysFlashromThread, Z_THREAD_ID_FLASHROM, SysFlashrom_ThreadEntry, req, + STACK_TOP(sSysFlashromStack), Z_PRIORITY_FLASHROM); + osStartThread(&sSysFlashromThread); + } +} + +s32 SysFlashrom_IsBusy(void) { + OSMesgQueue* queue = &sFlashromRequest.messageQueue; + + if (!SysFlashrom_IsInit()) { + return -1; + } + return MQ_IS_FULL(queue); +} + +s32 SysFlashrom_AwaitResult(void) { + if (!SysFlashrom_IsInit()) { + return -1; + } + osRecvMesg(&sFlashromRequest.messageQueue, NULL, OS_MESG_BLOCK); + osDestroyThread(&sSysFlashromThread); + StackCheck_Cleanup(&sSysFlashromStackInfo); + return sFlashromRequest.response; +} + +void SysFlashrom_WriteDataSync(void* addr, u32 pageNum, u32 pageCount) { + SysFlashrom_WriteDataAsync(addr, pageNum, pageCount); + SysFlashrom_AwaitResult(); +} diff --git a/src/code/title_setup.c b/src/code/title_setup.c index 4e9293ce7..841c301e2 100644 --- a/src/code/title_setup.c +++ b/src/code/title_setup.c @@ -48,7 +48,7 @@ void Setup_SetRegs(void) { } void Setup_InitImpl(SetupState* this) { - func_80185908(); + SysFlashrom_InitFlash(); SaveContext_Init(); Setup_SetRegs(); diff --git a/src/code/z_sram_NES.c b/src/code/z_sram_NES.c index 6556adfa7..cfd230569 100644 --- a/src/code/z_sram_NES.c +++ b/src/code/z_sram_NES.c @@ -850,15 +850,15 @@ void Sram_ResetSaveFromMoonCrash(SramContext* sramCtx) { bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE); - if (func_80185968(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2], D_801C67F0[gSaveContext.fileNum * 2]) != - 0) { - func_80185968(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2 + 1], - D_801C67F0[gSaveContext.fileNum * 2 + 1]); + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2], + D_801C67F0[gSaveContext.fileNum * 2]) != 0) { + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2 + 1], + D_801C67F0[gSaveContext.fileNum * 2 + 1]); } Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save)); if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf)) { - func_80185968(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2 + 1], - D_801C67F0[gSaveContext.fileNum * 2 + 1]); + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2 + 1], + D_801C67F0[gSaveContext.fileNum * 2 + 1]); Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, sizeof(Save)); } gSaveContext.save.cutsceneIndex = cutsceneIndex; @@ -910,27 +910,27 @@ void Sram_OpenSave(FileSelectState* fileSelect, SramContext* sramCtx) { bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE); if (gSaveContext.fileNum == 0xFF) { - func_80185968(sramCtx->saveBuf, D_801C67C8[0], D_801C67F0[0]); + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[0], D_801C67F0[0]); } else if (fileSelect->unk_2446A[gSaveContext.fileNum] != 0) { phi_t1 = gSaveContext.fileNum + 2; phi_t1 *= 2; - if (func_80185968(sramCtx->saveBuf, D_801C67C8[phi_t1], D_801C67F0[phi_t1]) != 0) { - func_80185968(sramCtx->saveBuf, D_801C67C8[phi_t1 + 1], D_801C67F0[phi_t1 + 1]); + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1], D_801C67F0[phi_t1]) != 0) { + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1 + 1], D_801C67F0[phi_t1 + 1]); } } else { phi_t1 = gSaveContext.fileNum; phi_t1 *= 2; - if (func_80185968(sramCtx->saveBuf, D_801C67C8[phi_t1], D_801C67F0[phi_t1]) != 0) { - func_80185968(sramCtx->saveBuf, D_801C67C8[phi_t1 + 1], D_801C67F0[phi_t1 + 1]); + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1], D_801C67F0[phi_t1]) != 0) { + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1 + 1], D_801C67F0[phi_t1 + 1]); } } Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[phi_t1]); if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf)) { - func_80185968(sramCtx->saveBuf, D_801C67C8[phi_t1 + 1], D_801C67F0[phi_t1 + 1]); + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1 + 1], D_801C67F0[phi_t1 + 1]); Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[phi_t1]); } } @@ -1090,9 +1090,9 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) { phi_s2 = false; sp6E = 0; - if (func_80185968(sramCtx->saveBuf, D_801C67C8[sp64], D_801C67F0[sp64])) { + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64], D_801C67F0[sp64])) { sp6E = 1; - if (func_80185968(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { phi_s2 = true; } } @@ -1115,7 +1115,7 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) { if (CHECK_NEWF2(gSaveContext.save.saveInfo.playerData.newf)) {} phi_s2 = false; - if (func_80185968(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { phi_s2 = true; } @@ -1171,7 +1171,7 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) { func_80146EBC(sramCtx, D_801C67C8[sp64], D_801C6818[sp64]); } else if (sp6E == 0) { // TODO: == 0? temp_s2 = gSaveContext.save.saveInfo.checksum; - if (func_80185968(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { phi_s2_3 = 1; } else { Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save)); @@ -1182,7 +1182,7 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) { if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (phi_s2_3 != sp7A) || (phi_s2_3 != temp_s2)) { - func_80185968(sramCtx->saveBuf, D_801C67C8[sp64], D_801C67F0[sp64]); + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64], D_801C67F0[sp64]); Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save)); Lib_MemCpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save)); func_80146EBC(sramCtx, D_801C67C8[sp64], D_801C6818[sp64]); @@ -1210,7 +1210,7 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) { phi_s2 = false; } - if (func_80185968(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { phi_s2 = true; } @@ -1267,7 +1267,7 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) { func_80146EBC(sramCtx, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1]); } else if (!sp6E) { // TODO: == 0? temp_s2 = gSaveContext.save.saveInfo.checksum; - if (func_80185968(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) { phi_s2_3 = 1; } else { Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]); @@ -1279,7 +1279,7 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) { if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (phi_s2_3 != sp7A) || (phi_s2_3 != temp_s2)) { - func_80185968(sramCtx->saveBuf, D_801C67C8[sp64], D_801C67F0[sp64]); + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64], D_801C67F0[sp64]); Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]); func_80146EBC(sramCtx, D_801C67C8[sp64], D_801C67F0[sp64]); func_80146EBC(sramCtx, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1]); @@ -1381,11 +1381,12 @@ void func_80146628(FileSelectState* fileSelect2, SramContext* sramCtx) { // clear buffer bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE); // read to buffer - func_80185968(sramCtx->saveBuf, D_801C67C8[fileSelect->unk_2448E * 2], D_801C67F0[fileSelect->unk_2448E * 2]); + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[fileSelect->unk_2448E * 2], + D_801C67F0[fileSelect->unk_2448E * 2]); if (1) {} - func_80185968(&sramCtx->saveBuf[0x2000], D_801C67C8[fileSelect->unk_2448E * 2 + 1], - D_801C67F0[fileSelect->unk_2448E * 2 + 1]); + SysFlashrom_ReadData(&sramCtx->saveBuf[0x2000], D_801C67C8[fileSelect->unk_2448E * 2 + 1], + D_801C67F0[fileSelect->unk_2448E * 2 + 1]); if (1) {} // copy buffer to save context @@ -1518,7 +1519,7 @@ void Sram_Alloc(GameState* gameState, SramContext* sramCtx) { void func_80146EBC(SramContext* sramCtx, s32 curPage, s32 numPages) { sramCtx->curPage = curPage; sramCtx->numPages = numPages; - func_80185F64(sramCtx->saveBuf, curPage, numPages); + SysFlashrom_WriteDataSync(sramCtx->saveBuf, curPage, numPages); } /** @@ -1531,7 +1532,8 @@ void Sram_SaveSpecialEnterClockTown(PlayState* play) { gSaveContext.save.isFirstCycle = true; gSaveContext.save.isOwlSave = false; func_80145698(sramCtx); - func_80185F64(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2], D_801C6818[gSaveContext.fileNum * 2]); + SysFlashrom_WriteDataSync(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2], + D_801C6818[gSaveContext.fileNum * 2]); } /** @@ -1552,7 +1554,8 @@ void Sram_SaveSpecialNewDay(PlayState* play) { gSaveContext.save.day = day; gSaveContext.save.time = time; gSaveContext.save.cutsceneIndex = cutsceneIndex; - func_80185F64(play->sramCtx.saveBuf, D_801C67C8[gSaveContext.fileNum * 2], D_801C67F0[gSaveContext.fileNum * 2]); + SysFlashrom_WriteDataSync(play->sramCtx.saveBuf, D_801C67C8[gSaveContext.fileNum * 2], + D_801C67F0[gSaveContext.fileNum * 2]); } void func_80147008(SramContext* sramCtx, u32 curPage, u32 numPages) { @@ -1563,7 +1566,7 @@ void func_80147008(SramContext* sramCtx, u32 curPage, u32 numPages) { void func_80147020(SramContext* sramCtx) { // async flash write - func_80185DDC(sramCtx->saveBuf, sramCtx->curPage, sramCtx->numPages); + SysFlashrom_WriteDataAsync(sramCtx->saveBuf, sramCtx->curPage, sramCtx->numPages); sramCtx->unk_18 = osGetTime(); sramCtx->status = 2; @@ -1571,8 +1574,8 @@ void func_80147020(SramContext* sramCtx) { void func_80147068(SramContext* sramCtx) { if (sramCtx->status == 2) { - if (func_80185EC4() != 0) { // if task running - if (func_80185F04() == 0) { // wait for task done + if (SysFlashrom_IsBusy() != 0) { // if task running + if (SysFlashrom_AwaitResult() == 0) { // wait for task done // task success sramCtx->status = 4; } else { @@ -1592,7 +1595,7 @@ void func_80147138(SramContext* sramCtx, s32 curPage, s32 numPages) { } void func_80147150(SramContext* sramCtx) { - func_80185DDC(sramCtx->saveBuf, sramCtx->curPage, sramCtx->numPages); + SysFlashrom_WriteDataAsync(sramCtx->saveBuf, sramCtx->curPage, sramCtx->numPages); sramCtx->unk_18 = osGetTime(); sramCtx->status = 7; @@ -1600,18 +1603,18 @@ void func_80147150(SramContext* sramCtx) { void func_80147198(SramContext* sramCtx) { if (sramCtx->status == 7) { - if (func_80185EC4() != 0) { // Is task running - if (func_80185F04() == 0) { // Wait for task done - func_80185DDC(sramCtx->saveBuf, sramCtx->curPage + 0x80, sramCtx->numPages); + if (SysFlashrom_IsBusy() != 0) { // Is task running + if (SysFlashrom_AwaitResult() == 0) { // Wait for task done + SysFlashrom_WriteDataAsync(sramCtx->saveBuf, sramCtx->curPage + 0x80, sramCtx->numPages); sramCtx->status = 8; } else { - func_80185DDC(sramCtx->saveBuf, sramCtx->curPage + 0x80, sramCtx->numPages); + SysFlashrom_WriteDataAsync(sramCtx->saveBuf, sramCtx->curPage + 0x80, sramCtx->numPages); sramCtx->status = 8; } } } else if (sramCtx->status == 8) { - if (func_80185EC4() != 0) { // Is task running - if (func_80185F04() == 0) { // Wait for task done + if (SysFlashrom_IsBusy() != 0) { // Is task running + if (SysFlashrom_AwaitResult() == 0) { // Wait for task done sramCtx->status = 4; } else { sramCtx->status = 4; @@ -1623,7 +1626,7 @@ void func_80147198(SramContext* sramCtx) { gSaveContext.save.isOwlSave = false; gSaveContext.save.saveInfo.checksum = 0; // flash read to buffer then copy to save context - func_80185968(sramCtx->saveBuf, sramCtx->curPage, sramCtx->numPages); + SysFlashrom_ReadData(sramCtx->saveBuf, sramCtx->curPage, sramCtx->numPages); Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, offsetof(SaveContext, fileNum)); } } @@ -1664,9 +1667,9 @@ void func_80147414(SramContext* sramCtx, s32 fileNum, s32 arg2) { bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE); // Read save file - if (func_80185968(sramCtx->saveBuf, D_801C6840[fileNum * 2], D_801C6850[fileNum * 2]) != 0) { + if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C6840[fileNum * 2], D_801C6850[fileNum * 2]) != 0) { // If failed, read backup save file - func_80185968(sramCtx->saveBuf, D_801C6840[fileNum * 2 + 1], D_801C6850[fileNum * 2 + 1]); + SysFlashrom_ReadData(sramCtx->saveBuf, D_801C6840[fileNum * 2 + 1], D_801C6850[fileNum * 2 + 1]); } // Copy buffer to save context |
