From fbb3a1985b5e153b4415c91aa26ac8599530d204 Mon Sep 17 00:00:00 2001 From: Niko Date: Thu, 20 Feb 2025 22:04:10 -0500 Subject: [PATCH] LOAD refactor --- decompile/General/233/233_20_CS_LoadBoss.c | 2 +- decompile/General/AltMods/Mods2.c | 2 +- .../General/GAMEPAD/GAMEPAD_03_PollVsync.c | 11 ++ .../General/LOAD/LOAD_16_DramFileCallback.c | 17 +- decompile/General/LOAD/LOAD_17_DramFile.c | 40 +---- .../General/LOAD/LOAD_18_VramFileCallback.c | 52 ++++--- decompile/General/LOAD/LOAD_19_VramFile.c | 48 ++---- decompile/General/LOAD/LOAD_21_ReadFile.c | 9 +- decompile/General/LOAD/LOAD_31_DriverMPK.c | 14 +- decompile/General/LOAD/LOAD_32_LangFile.c | 2 +- decompile/General/LOAD/LOAD_34_AppendQueue.c | 4 +- .../General/LOAD/LOAD_35_CDRequestCallback.c | 5 +- .../General/LOAD/LOAD_36_NextQueuedFile.c | 145 +++++++++--------- decompile/General/LOAD/LOAD_44_TenStages.c | 12 +- decompile/General/MAIN/MainDrawCb_01_Vsync.c | 13 +- .../General/MAIN/MainKillGame_00_StopCTR.c | 2 +- decompile/General/MAIN/MainMain.c | 8 +- decompile/General/zGlobal_DATA.c | 2 +- include/decomp_functions.h | 6 +- include/namespace_Load.h | 11 +- mods/Levels/PS1_TrackROM/src/ctr_main.c | 2 +- .../OxideFix/src/PodiumFix_AppendQueue.c | 2 +- 22 files changed, 176 insertions(+), 233 deletions(-) diff --git a/decompile/General/233/233_20_CS_LoadBoss.c b/decompile/General/233/233_20_CS_LoadBoss.c index 48a619504..904a7022c 100644 --- a/decompile/General/233/233_20_CS_LoadBoss.c +++ b/decompile/General/233/233_20_CS_LoadBoss.c @@ -41,7 +41,7 @@ void DECOMP_CS_LoadBoss(struct BossCutsceneData* bcd) //if (bcd->bodyFile != 0) { // CTR Model File (body) - LOAD_AppendQueue(sdata->ptrBigfileCdPos_2, LT_DRAM, bcd->bodyFile+index, ptrDestination, -0x2); + LOAD_AppendQueue(sdata->ptrBigfileCdPos_2, LT_DRAM, bcd->bodyFile+index, ptrDestination, 0); } // CTR Model File (head) diff --git a/decompile/General/AltMods/Mods2.c b/decompile/General/AltMods/Mods2.c index 53ab11264..01b1217ed 100644 --- a/decompile/General/AltMods/Mods2.c +++ b/decompile/General/AltMods/Mods2.c @@ -80,7 +80,7 @@ void Oxide_HookAppendLoadingQueue() // add oxide request lqs_curr->subfileIndex = packIndex + 0xf*2 + 0x18D; lqs_curr->ptrDestination = (void*)&data.podiumModel_firstPlace; - lqs_curr->callback.flags = 0xfffffffe; + lqs_curr->callback = 0; // increase size sdata->queueLength++; diff --git a/decompile/General/GAMEPAD/GAMEPAD_03_PollVsync.c b/decompile/General/GAMEPAD/GAMEPAD_03_PollVsync.c index 5c46f8f27..220362755 100644 --- a/decompile/General/GAMEPAD/GAMEPAD_03_PollVsync.c +++ b/decompile/General/GAMEPAD/GAMEPAD_03_PollVsync.c @@ -98,5 +98,16 @@ void DECOMP_GAMEPAD_PollVsync(struct GamepadSystem *gGamepads) void DebugProfiler_Subsection(int flag); DebugProfiler_Subsection(1); #endif + + // wait two vsyncs for VRAM upload to finish + if (sdata->frameFinishedVRAM != 0) + { + sdata->frameFinishedVRAM--; + + if (sdata->frameFinishedVRAM == 0) + { + sdata->queueReady = 1; + } + } #endif } \ No newline at end of file diff --git a/decompile/General/LOAD/LOAD_16_DramFileCallback.c b/decompile/General/LOAD/LOAD_16_DramFileCallback.c index 72471461c..f4010625d 100644 --- a/decompile/General/LOAD/LOAD_16_DramFileCallback.c +++ b/decompile/General/LOAD/LOAD_16_DramFileCallback.c @@ -30,20 +30,7 @@ void DECOMP_LOAD_DramFileCallback(struct LoadQueueSlot* lqs) } } - void* callbackFunc = lqs->callback.funcPtr; - - if(callbackFunc != 0) - { - // if function, and not flags - #ifndef REBUILD_PC - if(((unsigned int)callbackFunc & 0xff000000) == 0x80000000) - #else - if((int)callbackFunc > 0) - #endif - { - (*lqs->callback.funcPtr)(lqs); - } - } - sdata->queueReady = 1; + if (lqs->callbackFuncPtr != 0) + lqs->callbackFuncPtr(lqs); } \ No newline at end of file diff --git a/decompile/General/LOAD/LOAD_17_DramFile.c b/decompile/General/LOAD/LOAD_17_DramFile.c index 65d4fad1d..9a874757c 100644 --- a/decompile/General/LOAD/LOAD_17_DramFile.c +++ b/decompile/General/LOAD/LOAD_17_DramFile.c @@ -1,40 +1,2 @@ -#include -void DECOMP_LOAD_DramFileCallback(); - -void* DECOMP_LOAD_DramFile(void* bigfilePtr, int subfileIndex, int* ptrDestination, int callbackOrFlags) -{ - struct LoadQueueSlot lqs; - - if(callbackOrFlags == -1) - { - lqs.ptrBigfileCdPos = bigfilePtr; - lqs.flags = 0; - lqs.type = LT_DRAM; - lqs.subfileIndex = subfileIndex; - lqs.ptrDestination = DECOMP_LOAD_ReadFile(bigfilePtr, LT_DRAM, subfileIndex, 0, 0); - lqs.callback.funcPtr = NULL; - - DECOMP_LOAD_DramFileCallback(&lqs); - - // optimization, dont use instructions writing - // return value, let it use whatever sits on - // the register. Return value is never used - // because callback.funcptr is zero - return NULL; //was just `return;` - } - - if(callbackOrFlags == -2) - { - void* ptrDest = DECOMP_LOAD_ReadFile(bigfilePtr, LT_DRAM, subfileIndex, 0, DECOMP_LOAD_DramFileCallback); - - *ptrDestination = (int)ptrDest; - data.currSlot.ptrDestination = ptrDest; - - return ptrDest; - } - - // valid callback - - return DECOMP_LOAD_ReadFile(bigfilePtr, LT_DRAM, subfileIndex, ptrDestination, DECOMP_LOAD_DramFileCallback); -} \ No newline at end of file +// -- dead code -- \ No newline at end of file diff --git a/decompile/General/LOAD/LOAD_18_VramFileCallback.c b/decompile/General/LOAD/LOAD_18_VramFileCallback.c index 363067e8f..4f4e2922e 100644 --- a/decompile/General/LOAD/LOAD_18_VramFileCallback.c +++ b/decompile/General/LOAD/LOAD_18_VramFileCallback.c @@ -4,37 +4,39 @@ void DECOMP_LOAD_VramFileCallback(struct LoadQueueSlot* lqs) { int* vramBuf = lqs->ptrDestination; - if(vramBuf != 0) + #if 0 + // failure is impossible, + // this callback only happens on CdlComplete, + // which indicates a successful read + if(vramBuf == 0) while(1) {} + #endif + + struct VramHeader* vh = (struct VramHeader*)vramBuf; + + // if multiple TIMs are packed together + if(vramBuf[0] == 0x20) { - struct VramHeader* vh = (struct VramHeader*)vramBuf; + int size = vramBuf[1]; + vh = (struct VramHeader*)&vramBuf[2]; - // if multiple TIMs are packed together - if(vramBuf[0] == 0x20) - { - int size = vramBuf[1]; - vh = (struct VramHeader*)&vramBuf[2]; - - while(size != 0) - { - LoadImage(&vh->rect, VRAMHEADER_GETPIXLES(vh)); - - vramBuf = (int*)vh; - vramBuf = &vramBuf[size>>2]; - size = vramBuf[0]; - vh = (struct VramHeader*)&vramBuf[1]; - } - } - - // if just one TIM - else + while(size != 0) { LoadImage(&vh->rect, VRAMHEADER_GETPIXLES(vh)); + + vramBuf = (int*)vh; + vramBuf = &vramBuf[size>>2]; + size = vramBuf[0]; + vh = (struct VramHeader*)&vramBuf[1]; } } - sdata->frameFinishedVRAM = sdata->gGT->frameTimer_VsyncCallback; + // if just one TIM + else + { + LoadImage(&vh->rect, VRAMHEADER_GETPIXLES(vh)); + } - // BUGFIX: The OG CTR can crash in the loading screen - if (sdata->frameFinishedVRAM == 0) - sdata->frameFinishedVRAM = 1; + // wait 2 frames before starting the next load queue, + // this is handled in vsync callback. + sdata->frameFinishedVRAM = 2; } \ No newline at end of file diff --git a/decompile/General/LOAD/LOAD_19_VramFile.c b/decompile/General/LOAD/LOAD_19_VramFile.c index e099e320a..854b912aa 100644 --- a/decompile/General/LOAD/LOAD_19_VramFile.c +++ b/decompile/General/LOAD/LOAD_19_VramFile.c @@ -1,42 +1,22 @@ #include -void* DECOMP_LOAD_VramFile(void* bigfilePtr, int subfileIndex, int* ptrDestination, int callbackOrFlags) +void* DECOMP_LOAD_VramFile(void* bigfilePtr, int subfileIndex) { struct LoadQueueSlot lqs; - - if(callbackOrFlags == -1) - { - lqs.ptrBigfileCdPos = bigfilePtr; - lqs.flags = 0; - lqs.type = LT_VRAM; - lqs.subfileIndex = subfileIndex; - lqs.ptrDestination = DECOMP_LOAD_ReadFile(bigfilePtr, LT_VRAM, subfileIndex, 0, 0); - lqs.callback.funcPtr = NULL; - - DECOMP_LOAD_VramFileCallback(&lqs); - - VSync(2); - - sdata->frameFinishedVRAM = 0; - - // optimization, dont use instructions writing - // return value, let it use whatever sits on - // the register. Return value is never used - // because callback.funcptr is zero - return NULL; //was just `return;` - } - if(callbackOrFlags == -2) - { - void* ptrDest = DECOMP_LOAD_ReadFile(bigfilePtr, LT_VRAM, subfileIndex, 0, &DECOMP_LOAD_VramFileCallback); - - *ptrDestination = (int)ptrDest; - data.currSlot.ptrDestination = ptrDest; - - return ptrDest; - } + // callback=0 means this calls CdSync and is not async + lqs.ptrDestination = DECOMP_LOAD_ReadFile(bigfilePtr, subfileIndex, 0, 0); + + // undo allocation, next LOAD queue request + // will overwrite where VRAM was in RAM + DECOMP_MEMPACK_ReallocMem(0); + + // run callback + DECOMP_LOAD_VramFileCallback(&lqs); - // valid callback + // wait 2 frames for LoadImage to finish + VSync(2); - return DECOMP_LOAD_ReadFile(bigfilePtr, LT_VRAM, subfileIndex, ptrDestination, &DECOMP_LOAD_VramFileCallback); + // do NOT trigger code in vsync callback to handle queue + sdata->frameFinishedVRAM = 0; } \ No newline at end of file diff --git a/decompile/General/LOAD/LOAD_21_ReadFile.c b/decompile/General/LOAD/LOAD_21_ReadFile.c index 319c014e1..566dbba8a 100644 --- a/decompile/General/LOAD/LOAD_21_ReadFile.c +++ b/decompile/General/LOAD/LOAD_21_ReadFile.c @@ -1,6 +1,6 @@ #include -void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, u_int loadType, int subfileIndex, void *ptrDst, void * callback) +void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, /*u_int loadType,*/ int subfileIndex, void *ptrDst, void * callback) { // param1 is the Pointer to CD position of BIGFILE @@ -33,9 +33,6 @@ void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, u_int loadType, int subfil // undo sector-align alloc, // allocate just "needed" bytes DECOMP_MEMPACK_ReallocMem(eSize); - - if (loadType == LT_VRAM) - DECOMP_MEMPACK_ReallocMem(0); } sdata->callbackCdReadSuccess = 0; @@ -84,6 +81,10 @@ void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, u_int loadType, int subfil } #endif + +#if defined(REBUILD_PC) || defined(USE_PCDRV) + DECOMP_LOAD_ReadFileASyncCallback(CdlComplete, NULL); +#endif return ptrDst; } \ No newline at end of file diff --git a/decompile/General/LOAD/LOAD_31_DriverMPK.c b/decompile/General/LOAD/LOAD_31_DriverMPK.c index bd3369dff..538e40535 100644 --- a/decompile/General/LOAD/LOAD_31_DriverMPK.c +++ b/decompile/General/LOAD/LOAD_31_DriverMPK.c @@ -9,7 +9,7 @@ void highMp_DriverMPK(unsigned int param_1,int levelLOD, void (*param_3)(struct // high lod CTR model DECOMP_LOAD_AppendQueue(param_1,LT_DRAM, BI_RACERMODELHI + data.characterIDs[i], - &data.driverModelExtras[i],(void(*)(struct LoadQueueSlot*))0xfffffffe); + &data.driverModelExtras[i],(void(*)(struct LoadQueueSlot*))0); } // Time Trial MPK @@ -111,7 +111,7 @@ void DECOMP_LOAD_DriverMPK(unsigned int param_1,int levelLOD, void (*param_3)(st // low lod CTR model DECOMP_LOAD_AppendQueue(param_1,LT_DRAM, BI_RACERMODELLOW + data.characterIDs[i], - &data.driverModelExtras[i],(void(*)(struct LoadQueueSlot*))0xfffffffe); + &data.driverModelExtras[i],(void(*)(struct LoadQueueSlot*))0); } // load 4P MPK of fourth player @@ -173,7 +173,7 @@ void DECOMP_LOAD_DriverMPK(unsigned int param_1,int levelLOD, void (*param_3)(st // high lod model (temporary workaround) DECOMP_LOAD_AppendQueue(param_1,LT_DRAM, BI_RACERMODELHI + 0xF, - &data.driverModelExtras[0],(void(*)(struct LoadQueueSlot*))0xfffffffe); + &data.driverModelExtras[0],(void(*)(struct LoadQueueSlot*))0); } // get rid of oxide cause MPK is too big @@ -192,7 +192,7 @@ void DECOMP_LOAD_DriverMPK(unsigned int param_1,int levelLOD, void (*param_3)(st // high lod model DECOMP_LOAD_AppendQueue(param_1,LT_DRAM, BI_RACERMODELHI + data.characterIDs[0], - &data.driverModelExtras[0],(void(*)(struct LoadQueueSlot*))0xfffffffe); + &data.driverModelExtras[0],(void(*)(struct LoadQueueSlot*))0); // time trial mpk lastFileIndexMPK = BI_TIMETRIALPACK + data.characterIDs[1]; @@ -214,7 +214,7 @@ void DECOMP_LOAD_DriverMPK(unsigned int param_1,int levelLOD, void (*param_3)(st // high lod model DECOMP_LOAD_AppendQueue(param_1,LT_DRAM, BI_RACERMODELHI + data.characterIDs[0], - &data.driverModelExtras[0],(void(*)(struct LoadQueueSlot*))0xfffffffe); + &data.driverModelExtras[0],(void(*)(struct LoadQueueSlot*))0); // pack of four AIs with bosses lastFileIndexMPK = BI_2PARCADEPACK + 7; @@ -241,7 +241,7 @@ void DECOMP_LOAD_DriverMPK(unsigned int param_1,int levelLOD, void (*param_3)(st // high lod CTR model DECOMP_LOAD_AppendQueue(param_1,LT_DRAM, BI_RACERMODELHI + data.characterIDs[i], - &data.driverModelExtras[i],(void(*)(struct LoadQueueSlot*))0xfffffffe); + &data.driverModelExtras[i],(void(*)(struct LoadQueueSlot*))0); } // time trial mpk @@ -258,7 +258,7 @@ void DECOMP_LOAD_DriverMPK(unsigned int param_1,int levelLOD, void (*param_3)(st // med lod CTR model DECOMP_LOAD_AppendQueue(param_1,LT_DRAM, BI_RACERMODELMED + data.characterIDs[i], - &data.driverModelExtras[i],(void(*)(struct LoadQueueSlot*))0xfffffffe); + &data.driverModelExtras[i],(void(*)(struct LoadQueueSlot*))0); } // this also loads MPK diff --git a/decompile/General/LOAD/LOAD_32_LangFile.c b/decompile/General/LOAD/LOAD_32_LangFile.c index b7c65acc7..a2bf28964 100644 --- a/decompile/General/LOAD/LOAD_32_LangFile.c +++ b/decompile/General/LOAD/LOAD_32_LangFile.c @@ -32,7 +32,7 @@ void DECOMP_LOAD_LangFile(int bigfilePtr, int lang) lngFile = DECOMP_LOAD_ReadFile( - (struct BigHeader*)bigfilePtr, 1, BI_LANGUAGEFILE + lang, + (struct BigHeader*)bigfilePtr, BI_LANGUAGEFILE + lang, (void*)sdata->lngFile, NULL); // This is not ReadFileAsync, this is ReadFile, diff --git a/decompile/General/LOAD/LOAD_34_AppendQueue.c b/decompile/General/LOAD/LOAD_34_AppendQueue.c index 1ca22453c..0c3350109 100644 --- a/decompile/General/LOAD/LOAD_34_AppendQueue.c +++ b/decompile/General/LOAD/LOAD_34_AppendQueue.c @@ -4,7 +4,7 @@ void DECOMP_LOAD_AppendQueue(int bigfile, int type, int fileIndex, void* destina { struct LoadQueueSlot* lqs; - #ifdef USE_BIGQUEUE + #ifndef USE_BIGQUEUE if(sdata->queueLength >= 8) return; #endif @@ -15,7 +15,7 @@ void DECOMP_LOAD_AppendQueue(int bigfile, int type, int fileIndex, void* destina lqs->type = type; lqs->subfileIndex = fileIndex; lqs->ptrDestination = destinationPtr; - lqs->callback.funcPtr = callback; + lqs->callbackFuncPtr = callback; sdata->queueLength++; diff --git a/decompile/General/LOAD/LOAD_35_CDRequestCallback.c b/decompile/General/LOAD/LOAD_35_CDRequestCallback.c index 0d58d92d2..9df5d3f31 100644 --- a/decompile/General/LOAD/LOAD_35_CDRequestCallback.c +++ b/decompile/General/LOAD/LOAD_35_CDRequestCallback.c @@ -3,7 +3,6 @@ void DECOMP_LOAD_CDRequestCallback(struct LoadQueueSlot* lqs) { sdata->queueReady = 1; - - if (lqs->callback.funcPtr != 0) - lqs->callback.funcPtr(lqs); + if (lqs->callbackFuncPtr != 0) + lqs->callbackFuncPtr(lqs); } \ No newline at end of file diff --git a/decompile/General/LOAD/LOAD_36_NextQueuedFile.c b/decompile/General/LOAD/LOAD_36_NextQueuedFile.c index 954a23333..ec1c781da 100644 --- a/decompile/General/LOAD/LOAD_36_NextQueuedFile.c +++ b/decompile/General/LOAD/LOAD_36_NextQueuedFile.c @@ -2,90 +2,89 @@ void DECOMP_LOAD_NextQueuedFile() { - if( - (sdata->queueReady != 0) && - (sdata->XA_State == 0) && - (sdata->queueLength != 0) - ) + // Under 3 conditions, delay the load: + // During XA play + // Queue is in use + // Queue is empty + if (sdata->XA_State != 0) return; + if (sdata->queueReady == 0) return; + if (sdata->queueLength == 0) return; + + + sdata->queueReady = 0; + + struct LoadQueueSlot* curr = &data.currSlot; + + // retry previously-failed load + if(sdata->queueRetry != 0) + { + sdata->queueRetry = 0; + } + + // brand new load + else { - sdata->queueReady = 0; + // Naughty Dog had inline copying, + // is that faster on real PS1 hardware? - struct LoadQueueSlot* curr = &data.currSlot; + memcpy(curr, &sdata->queueSlots[0], sizeof(struct LoadQueueSlot)); - // retry previously-failed load - if(sdata->queueRetry != 0) - { - sdata->queueRetry = 0; - } + for(int i = 1; i < sdata->queueLength; i++) + memcpy(&sdata->queueSlots[i-1], &sdata->queueSlots[i], sizeof(struct LoadQueueSlot)); + } + + sdata->queueLength--; - // brand new load - else - { - // Naughty Dog had inline copying, - // is that faster on real PS1 hardware? - - memcpy(curr, &sdata->queueSlots[0], sizeof(struct LoadQueueSlot)); - - for(int i = 1; i < sdata->queueLength; i++) - memcpy(&sdata->queueSlots[i-1], &sdata->queueSlots[i], sizeof(struct LoadQueueSlot)); - } + if(curr->type == LT_RAW) + { + // For LT_RAW: + // INPUT curr->ptrDestination is where the file WILL load + // OUTPUT curr->ptrDestination is where the file DID load - if(curr->type == LT_RAW) - { - curr->ptrDestination = - DECOMP_LOAD_ReadFile( - curr->ptrBigfileCdPos, - LT_RAW, - curr->subfileIndex, - curr->ptrDestination, - DECOMP_LOAD_CDRequestCallback); - } + curr->ptrDestination = + DECOMP_LOAD_ReadFile( + curr->ptrBigfileCdPos, + curr->subfileIndex, + curr->ptrDestination, + DECOMP_LOAD_CDRequestCallback); + } + + else if(curr->type == LT_DRAM) + { + // For LT_DRAM: + // OUTPUT curr->ptrDestination is where the file DID load + // INPUT curr->ptrDestination is where the output pointer is written - else if(curr->type == LT_DRAM) - { - curr->ptrDestination = - DECOMP_LOAD_DramFile( - (void*)curr->ptrBigfileCdPos, - (int)curr->subfileIndex, - (int*)curr->ptrDestination, - (int)curr->callback.funcPtr); - } + int* prevValue = curr->ptrDestination; - else if(curr->type == LT_VRAM) + curr->ptrDestination = + DECOMP_LOAD_ReadFile( + curr->ptrBigfileCdPos, + curr->subfileIndex, + 0, + DECOMP_LOAD_DramFileCallback); + + if(prevValue != 0) { - curr->ptrDestination = - DECOMP_LOAD_VramFile( - (void*)curr->ptrBigfileCdPos, - (int)curr->subfileIndex, - (int*)curr->ptrDestination, - (int)curr->callback.funcPtr); + *prevValue = curr->ptrDestination; } - - sdata->queueLength--; - -#if defined(REBUILD_PC) || defined(USE_PCDRV) - DECOMP_LOAD_ReadFileASyncCallback(CdlComplete, NULL); -#endif - } - if( - // two frames after end of loading - (sdata->frameFinishedVRAM != 0) && - (2 < (unsigned int)(sdata->gGT->frameTimer_VsyncCallback - sdata->frameFinishedVRAM)) - ) + + else if(curr->type == LT_VRAM) { - struct LoadQueueSlot* curr = &data.currSlot; - - // UNUSED, there's no callback after completion - // of any VRAM file because its never the last in the queue - if(curr->callback.funcPtr != 0) - { - (*curr->callback.funcPtr)(curr); - } - - // reset timer - sdata->frameFinishedVRAM = 0; + // For LT_VRAM: + // OUTPUT curr->ptrDestination is where the file DID load + // INPUT curr->ptrDestination is ignored - sdata->queueReady = 1; + curr->ptrDestination = + DECOMP_LOAD_ReadFile( + curr->ptrBigfileCdPos, + curr->subfileIndex, + 0, + DECOMP_LOAD_VramFileCallback); + + // undo allocation, next LOAD queue request + // will overwrite where VRAM was in RAM + DECOMP_MEMPACK_ReallocMem(0); } } \ No newline at end of file diff --git a/decompile/General/LOAD/LOAD_44_TenStages.c b/decompile/General/LOAD/LOAD_44_TenStages.c index a7ad7783c..4cc127875 100644 --- a/decompile/General/LOAD/LOAD_44_TenStages.c +++ b/decompile/General/LOAD/LOAD_44_TenStages.c @@ -56,7 +56,7 @@ int DECOMP_LOAD_TenStages(struct GameTracker* gGT, int loadingStage, struct BigH #ifndef REBUILD_PC // Load Intro TIM for Copyright Page from VRAM file - DECOMP_LOAD_VramFile(bigfile, 0x1fe, 0, 0xffffffff); + DECOMP_LOAD_VramFile(bigfile, 0x1fe); DECOMP_MainInit_VRAMDisplay(); #endif @@ -777,7 +777,7 @@ int DECOMP_LOAD_TenStages(struct GameTracker* gGT, int loadingStage, struct BigH DECOMP_LOAD_AppendQueue( (int)bigfile, LT_DRAM, BI_DANCEMODELWIN + iVar9 + (podiumModel - 0x7e) * 2, - (void*)&data.podiumModel_firstPlace, (void(*)(struct LoadQueueSlot*))0xfffffffe); + (void*)&data.podiumModel_firstPlace, (void(*)(struct LoadQueueSlot*))0); } // podium second place exists @@ -788,7 +788,7 @@ int DECOMP_LOAD_TenStages(struct GameTracker* gGT, int loadingStage, struct BigH DECOMP_LOAD_AppendQueue( (int)bigfile, LT_DRAM, BI_DANCEMODELLOSE + iVar9 + (podiumModel - 0x7e) * 2, - (void*)&data.podiumModel_secondPlace, (void(*)(struct LoadQueueSlot*))0xfffffffe); + (void*)&data.podiumModel_secondPlace, (void(*)(struct LoadQueueSlot*))0); } // podium third place exists @@ -799,7 +799,7 @@ int DECOMP_LOAD_TenStages(struct GameTracker* gGT, int loadingStage, struct BigH DECOMP_LOAD_AppendQueue( (int)bigfile, LT_DRAM, BI_DANCEMODELLOSE + iVar9 + (podiumModel - 0x7e) * 2, - (void*)&data.podiumModel_thirdPlace, (void(*)(struct LoadQueueSlot*))0xfffffffe); + (void*)&data.podiumModel_thirdPlace, (void(*)(struct LoadQueueSlot*))0); } // TAWNA @@ -809,7 +809,7 @@ int DECOMP_LOAD_TenStages(struct GameTracker* gGT, int loadingStage, struct BigH DECOMP_LOAD_AppendQueue( (int)bigfile, LT_DRAM, BI_DANCETAWNAGIRL + iVar9 + (podiumModel - 0x8f) * 2, - (void*)&data.podiumModel_tawna, (void(*)(struct LoadQueueSlot*))0xfffffffe); + (void*)&data.podiumModel_tawna, (void(*)(struct LoadQueueSlot*))0); // if 0x7e+5 (dingo) if (gGT->podium_modelIndex_First == 0x83) @@ -818,7 +818,7 @@ int DECOMP_LOAD_TenStages(struct GameTracker* gGT, int loadingStage, struct BigH DECOMP_LOAD_AppendQueue( (int)bigfile, LT_DRAM, BI_DINGOFIRE + iVar9, - (void*)&data.podiumModel_dingoFire, (void(*)(struct LoadQueueSlot*))0xfffffffe); + (void*)&data.podiumModel_dingoFire, (void(*)(struct LoadQueueSlot*))0); } // add Podium diff --git a/decompile/General/MAIN/MainDrawCb_01_Vsync.c b/decompile/General/MAIN/MainDrawCb_01_Vsync.c index c09353747..9d17c1d11 100644 --- a/decompile/General/MAIN/MainDrawCb_01_Vsync.c +++ b/decompile/General/MAIN/MainDrawCb_01_Vsync.c @@ -10,7 +10,7 @@ void DECOMP_MainDrawCb_Vsync() gGT->frameTimer_VsyncCallback++; gGT->vSync_between_drawSync++; if ((gGT->gameMode1 & PAUSE_ALL) == 0) gGT->frameTimer_Confetti++; - + // 1 unit = 1/16th millisecond // 1 second = ~16,000 units // increment timer, and reset system clock @@ -32,6 +32,17 @@ void DECOMP_MainDrawCb_Vsync() void DebugProfiler_Subsection(int flag); DebugProfiler_Subsection(1); #endif + + // wait two vsyncs for VRAM upload to finish + if (sdata->frameFinishedVRAM != 0) + { + sdata->frameFinishedVRAM--; + + if (sdata->frameFinishedVRAM == 0) + { + sdata->queueReady = 1; + } + } #endif return; diff --git a/decompile/General/MAIN/MainKillGame_00_StopCTR.c b/decompile/General/MAIN/MainKillGame_00_StopCTR.c index b4b356a2c..fa0c16da7 100644 --- a/decompile/General/MAIN/MainKillGame_00_StopCTR.c +++ b/decompile/General/MAIN/MainKillGame_00_StopCTR.c @@ -4,7 +4,7 @@ void DECOMP_MainKillGame_StopCTR(void) { // set callback and save callback EnterCriticalSection(); - DrawSyncCallback(sdata->MainDrawCb_DrawSyncPtr); + DrawSyncCallback(0); ExitCriticalSection(); StopCallback(); diff --git a/decompile/General/MAIN/MainMain.c b/decompile/General/MAIN/MainMain.c index 29dc83779..7871141df 100644 --- a/decompile/General/MAIN/MainMain.c +++ b/decompile/General/MAIN/MainMain.c @@ -770,7 +770,7 @@ void StateZero() // set callback and save callback EnterCriticalSection(); - sdata->MainDrawCb_DrawSyncPtr = DrawSyncCallback(&DECOMP_MainDrawCb_DrawSync); + DrawSyncCallback(&DECOMP_MainDrawCb_DrawSync); ExitCriticalSection(); DECOMP_MEMCARD_InitCard(); @@ -845,14 +845,14 @@ void StateZero() #ifndef FastBoot #ifndef REBUILD_PC // Load Intro TIM for "SCEA Presents" from VRAM file - DECOMP_LOAD_VramFile(sdata->ptrBigfile1, 0x1fd, 0, 0xffffffff); + DECOMP_LOAD_VramFile(sdata->ptrBigfile1, 0x1fd); DECOMP_MainInit_VRAMDisplay(); #endif #endif // \SOUNDS\KART.HWL;1 DECOMP_howl_InitGlobals(data.kartHwlPath); - + VSyncCallback(DECOMP_MainDrawCb_Vsync); #if !defined(FastBoot) && !defined(USE_ONLINE) @@ -882,7 +882,7 @@ void StateZero() // the area between 2 screen buffers and top right corner in vram // sdata->ptrBigfile1 is the Pointer to "cd position of bigfile" // Add a bookmark before loading (param_3 is 0 in the call) - DECOMP_LOAD_VramFile(sdata->ptrBigfile1, 0x102, 0, 0xffffffff); + DECOMP_LOAD_VramFile(sdata->ptrBigfile1, 0x102); sdata->mainGameState = 3; diff --git a/decompile/General/zGlobal_DATA.c b/decompile/General/zGlobal_DATA.c index 3fc925499..a0239f3be 100644 --- a/decompile/General/zGlobal_DATA.c +++ b/decompile/General/zGlobal_DATA.c @@ -2729,7 +2729,7 @@ struct Data data = .subfileIndex = -1, .ptrDestination = 0, .size_UNUSED = 0, - .callback.flags = 0 + .callbackFuncPtr = 0 }, .characterIDs_2P_AIs = diff --git a/include/decomp_functions.h b/include/decomp_functions.h index 397a875d5..d190dd21c 100644 --- a/include/decomp_functions.h +++ b/include/decomp_functions.h @@ -281,9 +281,9 @@ void DECOMP_LOAD_Callback_Overlay_231(void); void DECOMP_LOAD_Callback_Overlay_232(void); void DECOMP_LOAD_Callback_Overlay_233(void); void DECOMP_LOAD_ReadFileASyncCallback(CdlIntrResult result, uint8_t* unk); -void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, u_int loadType, int subfileIndex, void* destination, /*int *size,*/ void * callback); -void* DECOMP_LOAD_VramFile(void* bigfilePtr, int subfileIndex, int* ptrDestination, /*int* size,*/ int callbackOrFlags); -void* DECOMP_LOAD_DramFile(void* bigfilePtr, int subfileIndex, int* ptrDestination, /*int* size,*/ int callbackOrFlags); +void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, /*u_int loadType,*/ int subfileIndex, void* destination, /*int *size,*/ void * callback); +void* DECOMP_LOAD_VramFile(void* bigfilePtr, int subfileIndex /*, int* ptrDestination, int* size, int callbackOrFlags*/); +//void* DECOMP_LOAD_DramFile(void* bigfilePtr, int subfileIndex, int* ptrDestination, /*int* size,*/ int callbackOrFlags); void* DECOMP_LOAD_ReadDirectory(char* filename); void* DECOMP_LOAD_XnfFile(char* filename, void* ptrDestination, int* size); int DECOMP_LOAD_TenStages(struct GameTracker* gGT, int loadingStage, struct BigHeader* bigfile); diff --git a/include/namespace_Load.h b/include/namespace_Load.h index 0d4d8547b..5f2fd1a05 100644 --- a/include/namespace_Load.h +++ b/include/namespace_Load.h @@ -160,16 +160,7 @@ struct LoadQueueSlot unsigned int size_UNUSED; // 0x14 - union - { - // last 4 bytes will either be a function pointer, - // or a flag that signifies there is no function pointer - - void (*funcPtr)(struct LoadQueueSlot*); - - unsigned int flags; - - } callback; + void (*callbackFuncPtr)(struct LoadQueueSlot*); }; _Static_assert(sizeof(struct LoadQueueSlot) == 0x18); \ No newline at end of file diff --git a/mods/Levels/PS1_TrackROM/src/ctr_main.c b/mods/Levels/PS1_TrackROM/src/ctr_main.c index b4b2c98f9..cf2bcf37b 100644 --- a/mods/Levels/PS1_TrackROM/src/ctr_main.c +++ b/mods/Levels/PS1_TrackROM/src/ctr_main.c @@ -438,7 +438,7 @@ void StateZero() // set callback and save callback EnterCriticalSection(); - sdata->MainDrawCb_DrawSyncPtr = DrawSyncCallback(&MainDrawCb_DrawSync); + DrawSyncCallback(&MainDrawCb_DrawSync); ExitCriticalSection(); MEMCARD_InitCard(); diff --git a/mods/Modules/OxideFix/src/PodiumFix_AppendQueue.c b/mods/Modules/OxideFix/src/PodiumFix_AppendQueue.c index 340134257..2cce48de9 100644 --- a/mods/Modules/OxideFix/src/PodiumFix_AppendQueue.c +++ b/mods/Modules/OxideFix/src/PodiumFix_AppendQueue.c @@ -32,7 +32,7 @@ void HookAppendLoadingQueue() // add oxide request lqs_curr->subfileIndex = packIndex + 0xf*2 + 0x18D; lqs_curr->ptrDestination = (void*)&data.podiumModel_firstPlace; - lqs_curr->callback.flags = 0xfffffffe; + lqs_curr->callback = 0xfffffffe; // old retail flag system // increase size sdata->queueLength++;