From d14d33d0b5c0480418540bcd9aac8c2c08d9e494 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 9 Oct 2026 12:59:15 -0500 Subject: [PATCH 1/2] cleanup: src/system and src/utility (gotos, comma conditions, placeholders) (worker 223c077f) (#1354) --- src/system/iplControllerManager.cpp | 31 ++-- src/system/iplDialogWindow.cpp | 123 +++++++------- src/system/iplNandMeta.cpp | 7 +- src/system/iplNandShared.cpp | 51 +++--- src/system/iplNigaoeManager.cpp | 8 +- src/system/iplNwc24Manager.cpp | 103 ++++++------ src/system/iplPlayTimeLog.cpp | 4 +- src/system/iplTVRCManager.cpp | 19 +-- src/system/odh.cpp | 35 ++-- tools/decomp-assist/cleanup2-x4.attempts.md | 171 ++++++++++++++++++++ 10 files changed, 353 insertions(+), 199 deletions(-) create mode 100644 tools/decomp-assist/cleanup2-x4.attempts.md diff --git a/src/system/iplControllerManager.cpp b/src/system/iplControllerManager.cpp index fbc66289..e8c7abd9 100644 --- a/src/system/iplControllerManager.cpp +++ b/src/system/iplControllerManager.cpp @@ -15,15 +15,6 @@ #undef IPL_CONTROLLER_NATIVE_HIERARCHY #include "system/iplSystem.h" -extern "C" void _savegpr_16(); -extern "C" void _restgpr_16(); -extern "C" void _savegpr_29(); -extern "C" void _restgpr_29(); -extern "C" void _savegpr_27(); -extern "C" void _restgpr_27(); -extern "C" void _savegpr_28(); -extern "C" void _restgpr_28(); - namespace ipl { namespace controller { void* Manager::mpBuf; @@ -83,6 +74,7 @@ namespace ipl { u32 deviceType; s32 probe = WPADProbe(chan, &deviceType); + // MWCC needs this probe dispatch to preserve the branch layout. if (probe == WPAD_ERR_NO_CONTROLLER) { goto probe_invalid; } @@ -117,25 +109,22 @@ namespace ipl { mControllers[chan] = NULL; } } else { - if (read != 0) { - goto store_null; - } - mInvalidCount[chan]++; - if (mInvalidCount[chan] > 0x3c) { - mInvalidCount[chan] = 0x3c; - if (mControllers[chan] != NULL) { - WPADControlMotor(chan, WPAD_MOTOR_STOP); + if (read == 0) { + mInvalidCount[chan]++; + if (mInvalidCount[chan] > 0x3c) { + mInvalidCount[chan] = 0x3c; + if (mControllers[chan] != NULL) { + WPADControlMotor(chan, WPAD_MOTOR_STOP); + } + mControllers[chan] = NULL; } + } else { mControllers[chan] = NULL; } } } goto channel_done; - store_null: - mControllers[chan] = NULL; - goto channel_done; - probe_invalid: KPADRead(chan, &mKPADStatus[chan], 1); mControllers[chan] = NULL; diff --git a/src/system/iplDialogWindow.cpp b/src/system/iplDialogWindow.cpp index 78d1ec75..20b51560 100644 --- a/src/system/iplDialogWindow.cpp +++ b/src/system/iplDialogWindow.cpp @@ -1209,79 +1209,82 @@ namespace ipl { void DialogWindow::start_trig_event(const char* paneName) { int btnNo; - if (!(mState == DIALOG_STATE_PAGE_FADE) && (btnNo = get_button_no(paneName), btnNo != -1)) { - int animIdx = -1; + if (mState != DIALOG_STATE_PAGE_FADE) { + btnNo = get_button_no(paneName); + if (btnNo != -1) { + int animIdx = -1; - // Get select animation - if (mDialogType == DIALOG_TYPE_BTN3) { - switch (btnNo) { - case DIALOG_BTN_TYPE_BTN2: { - mResult = RESULT_TOP_BUTTON; - animIdx = ANIM_BTN3_SELECT_BTN_A; - snd::getSystem()->startSE("WIPL_SE_DECIDE"); - break; - } - case DIALOG_BTN_TYPE_BTN1: { - mResult = RESULT_MIDDLE_BUTTON; - animIdx = ANIM_BTN3_SELECT_BTN_B; - snd::getSystem()->startSE("WIPL_SE_DECIDE"); - break; - } - case DIALOG_BTN_TYPE_BTN3: { - mResult = RESULT_BOTTOM_BUTTON; - animIdx = ANIM_BTN3_SELECT_BTN_C; - snd::getSystem()->startSE("WIPL_SE_CANCEL"); - break; - } - } - } else { - switch (btnNo) { - case DIALOG_BTN_TYPE_BTN2: { - mResult = RESULT_LEFT_BUTTON; - animIdx = ANIM_SELECT_BTN_A; - if (mbSwapSound) { + // Get select animation + if (mDialogType == DIALOG_TYPE_BTN3) { + switch (btnNo) { + case DIALOG_BTN_TYPE_BTN2: { + mResult = RESULT_TOP_BUTTON; + animIdx = ANIM_BTN3_SELECT_BTN_A; snd::getSystem()->startSE("WIPL_SE_DECIDE"); - } else { - snd::getSystem()->startSE("WIPL_SE_CANCEL"); + break; } - mPrevPage = mCurPage; - mCurPage--; - break; - } - case DIALOG_BTN_TYPE_BTN1: { - mResult = RESULT_BUTTON; - animIdx = ANIM_SELECT_BTN_B; - if (mbSwapSound) { - snd::getSystem()->startSE("WIPL_SE_CANCEL"); - } else { + case DIALOG_BTN_TYPE_BTN1: { + mResult = RESULT_MIDDLE_BUTTON; + animIdx = ANIM_BTN3_SELECT_BTN_B; snd::getSystem()->startSE("WIPL_SE_DECIDE"); + break; + } + case DIALOG_BTN_TYPE_BTN3: { + mResult = RESULT_BOTTOM_BUTTON; + animIdx = ANIM_BTN3_SELECT_BTN_C; + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + break; + } + } + } else { + switch (btnNo) { + case DIALOG_BTN_TYPE_BTN2: { + mResult = RESULT_LEFT_BUTTON; + animIdx = ANIM_SELECT_BTN_A; + if (mbSwapSound) { + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + } else { + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + } + mPrevPage = mCurPage; + mCurPage--; + break; + } + case DIALOG_BTN_TYPE_BTN1: { + mResult = RESULT_BUTTON; + animIdx = ANIM_SELECT_BTN_B; + if (mbSwapSound) { + snd::getSystem()->startSE("WIPL_SE_CANCEL"); + } else { + snd::getSystem()->startSE("WIPL_SE_DECIDE"); + } + mPrevPage = mCurPage; + mCurPage++; + break; } - mPrevPage = mCurPage; - mCurPage++; - break; } } - } - // Play select animation - mpCurDialog->gLayout->getAnim(animIdx)->play(); + // Play select animation + mpCurDialog->gLayout->getAnim(animIdx)->play(); - // Change page - if (mPageCount > 0) { - if (mpPages[mPrevPage].isLytAnim && mpPages[mPrevPage].layoutObj) { - mpPages[mPrevPage].layoutObj->getAnim()->stop(); - } + // Change page + if (mPageCount > 0) { + if (mpPages[mPrevPage].isLytAnim && mpPages[mPrevPage].layoutObj) { + mpPages[mPrevPage].layoutObj->getAnim()->stop(); + } - if (mCurPage < 0 || mCurPage == mPageCount) { + if (mCurPage < 0 || mCurPage == mPageCount) { + mbNextState = true; + mState = DIALOG_STATE_SELECT; + } else { + mState = DIALOG_STATE_PAGE_FADE_PREPARE; + mPageState = DIALOG_PAGE_FADE_OUT; + } + } else { mbNextState = true; mState = DIALOG_STATE_SELECT; - } else { - mState = DIALOG_STATE_PAGE_FADE_PREPARE; - mPageState = DIALOG_PAGE_FADE_OUT; } - } else { - mbNextState = true; - mState = DIALOG_STATE_SELECT; } } } diff --git a/src/system/iplNandMeta.cpp b/src/system/iplNandMeta.cpp index 0d58e092..4c6a0454 100644 --- a/src/system/iplNandMeta.cpp +++ b/src/system/iplNandMeta.cpp @@ -127,10 +127,11 @@ namespace ipl { } // Read the file - if (ES_ReadContentFile(mDescriptor, bufferOut, length) < ES_ERR_OK) { - failed: - IPLErrorLogAndDisplay(MESG_ERR_FILE, "ES", 0, 230); + if (ES_ReadContentFile(mDescriptor, bufferOut, length) >= ES_ERR_OK) { + return; } + failed: + IPLErrorLogAndDisplay(MESG_ERR_FILE, "ES", 0, 230); } BOOL MetaFile::closeTicketFile_() { diff --git a/src/system/iplNandShared.cpp b/src/system/iplNandShared.cpp index dece98b8..2899b49c 100644 --- a/src/system/iplNandShared.cpp +++ b/src/system/iplNandShared.cpp @@ -16,57 +16,58 @@ namespace ipl { } BOOL SharedFile::openTicketFile_() { - int code = 0; - int errcode = 0; + int errorStage = 0; + int errorCode = 0; ESTitleId titleId = 0; ESTicketId ticketId = 0; - int erridx = 0; + int contentIndex = 0; mTicket = (ESTicketView*)System::getSharedHeap()->alloc(OSRoundUp32B(sizeof(ESTicketView)), -DEFAULT_ALIGN); if (mTicketIdx >= 0) { if (utility::ESMisc::GetTicketView(System::getSharedHeap(), mTitleId, mTicket, mTicketIdx) < ES_ERR_OK) { - code = 100; + errorStage = 100; goto err; } } else { - u32 tikCount; - ESTicketView* tik; + u32 ticketCount; + ESTicketView* ticketViews; - if (utility::ESMisc::GetTicketViewList(System::getSharedHeap(), mTitleId, &tik, &tikCount) != ES_ERR_OK) { - code = code; + if (utility::ESMisc::GetTicketViewList(System::getSharedHeap(), mTitleId, &ticketViews, &ticketCount) != ES_ERR_OK) { + // MWCC needs these self-copies to preserve the error branches. + errorStage = errorStage; goto err; } else { - int tikIdx = utility::ESMisc::GetValidTicketIndex(System::getSharedHeap(), mTitleId, tik, tikCount); - if (tikIdx < 0) { + int ticketIndex = utility::ESMisc::GetValidTicketIndex(System::getSharedHeap(), mTitleId, ticketViews, ticketCount); + if (ticketIndex < 0) { goto err; } - if (tikIdx >= tikCount) { - code = code; + if (ticketIndex >= ticketCount) { + errorStage = errorStage; goto err; } - mTicketIdx = tikIdx; - memcpy(mTicket, &tik[tikIdx], sizeof(ESTicketView)); - System::getSharedHeap()->free(tik); + mTicketIdx = ticketIndex; + memcpy(mTicket, &ticketViews[ticketIndex], sizeof(ESTicketView)); + System::getSharedHeap()->free(ticketViews); } } - s32 ret = ES_OpenTitleContentFile(mTitleId, mTicket, mContentIdx); - mDescriptor = ret; + s32 contentDescriptor = ES_OpenTitleContentFile(mTitleId, mTicket, mContentIdx); + mDescriptor = contentDescriptor; - if (ret < ES_ERR_OK) { - errcode = ret; + if (contentDescriptor < ES_ERR_OK) { + errorCode = contentDescriptor; titleId = mTitleId; if (mTicket) { ticketId = mTicket->ticketId; } - erridx = mContentIdx; - code = 400; + contentIndex = mContentIdx; + errorStage = 400; goto err; } ARCHeader header ALIGN32; if (ES_ReadContentFile(mDescriptor, &header, sizeof(ARCHeader)) < ES_ERR_OK) { - code = 500; + errorStage = 500; goto err; } @@ -75,7 +76,7 @@ namespace ipl { if (ES_SeekContentFile(mDescriptor, 0, NAND_SEEK_BEG) < ES_ERR_OK || ES_ReadContentFile(mDescriptor, mpFSTBuffer, bufSize) < ES_ERR_OK || !ARCInitHandle(mpFSTBuffer, &mArc)) { - code = 600; + errorStage = 600; goto err; } @@ -88,9 +89,9 @@ namespace ipl { return result == TRUE; err: char errString[128]; - sprintf(errString, "ES %d, %llx, %llx, %x", errcode, titleId, ticketId, erridx); + sprintf(errString, "ES %d, %llx, %llx, %x", errorCode, titleId, ticketId, contentIndex); - IPLErrorLogAndDisplay(MESG_ERR_FILE, errString, code, 158); + IPLErrorLogAndDisplay(MESG_ERR_FILE, errString, errorStage, 158); return FALSE; } diff --git a/src/system/iplNigaoeManager.cpp b/src/system/iplNigaoeManager.cpp index 9667e3ea..044ef0de 100644 --- a/src/system/iplNigaoeManager.cpp +++ b/src/system/iplNigaoeManager.cpp @@ -30,16 +30,16 @@ namespace ipl { u8 mac[NCD_MAC_ADDRESS_LENGTH + 1]; mac[6] = mac[5] = mac[4] = mac[3] = mac[2] = mac[1] = mac[0] = 0; - u8 temp[3]; - temp[2] = temp[1] = temp[0] = 0; + u8 macByteText[3]; + macByteText[2] = macByteText[1] = macByteText[0] = 0; // Setup work u8* ncd_mac = ncd::NCDSetting::getMacAddr(); // Get mac values for (int i = 1; i < NCD_MAC_ADDRESS_LENGTH; i++) { - memcpy(temp, &ncd_mac[i * ARRAY_LENGTH(temp)], sizeof(temp) - 1); - mac[i] = strtol((char*)temp, NULL, 16); + memcpy(macByteText, &ncd_mac[i * ARRAY_LENGTH(macByteText)], sizeof(macByteText) - 1); + mac[i] = strtol((char*)macByteText, NULL, 16); } RFLiSetMacAddr(mac); diff --git a/src/system/iplNwc24Manager.cpp b/src/system/iplNwc24Manager.cpp index 406d3e14..6c2ea413 100644 --- a/src/system/iplNwc24Manager.cpp +++ b/src/system/iplNwc24Manager.cpp @@ -573,7 +573,7 @@ namespace ipl { if (msgType == NWC24_MSGTYPE_PUBLIC) { u32 index = 0; if (!readMsgFromAddr(&msgObj, msgFriendAddr.mailAddr, sizeof(NWC24UserMailAddr)) && !FILE_ERROR_OK) { - goto out; + goto cleanup; } msgFriendType = NWC24_FRIENDTYPE_EMAIL; if (searchFriendInfo(&msgFriendAddr, &index)) { @@ -604,14 +604,14 @@ namespace ipl { getMsgGroupId(&msgObj, &msgGroupId); OSReport("msg app_id %x group_id %x\n", msgAppId, msgGroupId); if (!is_valid_app_id(msgAppId, msgGroupId)) { - goto out; + goto cleanup; } // Get software update flag (display "Update" button) u32 msgMbUpdateSW = 0; result = readMsgMBUpdateSW(&msgObj, &msgMbUpdateSW); if (!FILE_ERROR_OK) { - goto out; + goto cleanup; } // Get opt out flag (display "Opt Out" button) @@ -620,7 +620,7 @@ namespace ipl { *(u32*)&msgOptOutAppId = 0; result = readMsgMBOptOutFlag(&msgObj, &msgMbOptOutFlag, (u32*)&msgOptOutAppId); if (!FILE_ERROR_OK) { - goto out; + goto cleanup; } bool msgBoardCanOptOut = (result & (bool)msgMbOptOutFlag); @@ -662,7 +662,7 @@ namespace ipl { // Get no reply flag (prevents replying to the message) BOOL msgNoReply = FALSE; if (!readMsgMBNoReply(&msgObj, &msgNoReply) && !FILE_ERROR_OK) { - goto out; + goto cleanup; } // Get delay timer (receive the message a later time) @@ -681,7 +681,7 @@ namespace ipl { continue; } } else if (!FILE_ERROR_OK) { - goto out; + goto cleanup; } // Get message date (if it fails to read, the current time will be used instead) @@ -698,14 +698,14 @@ namespace ipl { msgMbRegDate.mon = msgMonth - 1; msgMbRegDate.mday = msgDay; } else if (!FILE_ERROR_OK) { - goto out; + goto cleanup; } // Get title wchar_t msgTitleText[0x28]; memset(msgTitleText, 0, sizeof(msgTitleText)); if (!readMsgAltName(&msgObj, (u16*)msgTitleText, 0x28) && !FILE_ERROR_OK) { - goto out; + goto cleanup; } // If we failed to read it, NULL it out and use the friend's name instead. @@ -717,7 +717,7 @@ namespace ipl { u32 failedToMakeText = FALSE; msgBodyText = make_text(heap, &msgObj, msgType == NWC24_MSGTYPE_PUBLIC, &failedToMakeText); if (failedToMakeText) { - goto out; + goto cleanup; } // Get Mii data @@ -740,7 +740,7 @@ namespace ipl { // Get attachment count getMsgNumAttached(&msgObj, &msgNumAttached); if (mLastError == NWC24_ERR_BROKEN) { - goto out2; + goto message_received; } // Get attachment data @@ -753,7 +753,7 @@ namespace ipl { } if (!readMsgAttached(&msgObj, attachIndex, mAttachData[attachIndex], mAttachSize[attachIndex]) && !FILE_ERROR_OK) { - goto out; + goto cleanup; } getMsgAttachedType(&msgObj, attachIndex, &nwc24AttachTypes[attachIndex]); @@ -872,10 +872,10 @@ namespace ipl { msgRecordFlags.data, msgFriendAddr, msgFriendType, msgNoReply, msgTitleText[0] != 0 ? msgTitleText : msgFriendName, msgBodyText, msgHasMii ? &msgCharData : NULL, (const void**)mAttachData, mAttachSize, msgAttachTypes); - out2: + message_received: mbReviecedMsg = true; - out: + cleanup: if (msgBodyText != NULL) { delete[] msgBodyText; } @@ -916,51 +916,46 @@ namespace ipl { SCSimpleAddress address; if (SCGetSimpleAddressData(&address)) { - int i = 0; - - // Interesting way to do a for loop - goto start; - while (TRUE) { + int retryCount = 0; + while (!open()) { OSSleepMilliseconds(10); - if (++i > 1000) { - break; - } - start: - if (open()) { - char fullDlUrl[64]; - memset(fullDlUrl, 0, sizeof(fullDlUrl)); - - NWC24DlId dlIds[4] = { - DL_ID_0, - DL_ID_1, - DL_ID_5, - DL_ID_6, - }; - u16 dlIntervals[4] = { - DL_INTERVAL_0, - DL_INTERVAL_1, - DL_INTERVAL_2, - DL_INTERVAL_3, - }; - u8 dlPrios[4] = { - DL_PRIORITY_0, - DL_PRIORITY_1, - DL_PRIORITY_2, - DL_PRIORITY_3, - }; - - for (int j = 0; j < 4; j++) { - // Add DL task for announcements - snprintf(fullDlUrl, sizeof(fullDlUrl) / sizeof(char), "http://cfh.wapp.wii.com/announce/%03d/%d/%d.bin", - address.id >> SC_SIMPLE_ADDRESS_ID_COUNTRY, System::getLanguage(), j + 1); - - add_dl_task(dlIds[j], fullDlUrl, dlIntervals[j], dlPrios[j]); - } - - close(); + if (++retryCount > 1000) { return; } } + + char fullDlUrl[64]; + memset(fullDlUrl, 0, sizeof(fullDlUrl)); + + NWC24DlId dlIds[4] = { + DL_ID_0, + DL_ID_1, + DL_ID_5, + DL_ID_6, + }; + u16 dlIntervals[4] = { + DL_INTERVAL_0, + DL_INTERVAL_1, + DL_INTERVAL_2, + DL_INTERVAL_3, + }; + u8 dlPrios[4] = { + DL_PRIORITY_0, + DL_PRIORITY_1, + DL_PRIORITY_2, + DL_PRIORITY_3, + }; + + for (int j = 0; j < 4; j++) { + // Add DL task for announcements + snprintf(fullDlUrl, sizeof(fullDlUrl) / sizeof(char), "http://cfh.wapp.wii.com/announce/%03d/%d/%d.bin", + address.id >> SC_SIMPLE_ADDRESS_ID_COUNTRY, System::getLanguage(), j + 1); + + add_dl_task(dlIds[j], fullDlUrl, dlIntervals[j], dlPrios[j]); + } + + close(); + return; } } diff --git a/src/system/iplPlayTimeLog.cpp b/src/system/iplPlayTimeLog.cpp index f8a6b745..54272d61 100644 --- a/src/system/iplPlayTimeLog.cpp +++ b/src/system/iplPlayTimeLog.cpp @@ -339,8 +339,6 @@ namespace ipl { create_new_record(&event); } - // https://decomp.me/scratch/sRhsi - // Some sort of hellhole with loading arguments for createNewRecord?? void PlayTimeLog::create_new_record(const EventBuffer* event) { cdb::Manager* cdbManager = System::getCdbManager(); @@ -351,6 +349,7 @@ namespace ipl { const void* attachData[RBR_ATTACHMENT_MAX] = {(void*)event, NULL}; + // MWCC needs volatile reads to preserve the attachment constant layout. u32 attachSize[RBR_ATTACHMENT_MAX] = { *reinterpret_cast(&sPlayTimeLogAttachSize0), *reinterpret_cast(&sPlayTimeLogAttachSize1) @@ -468,6 +467,7 @@ namespace ipl { static const u32 attachSize1 = 0; static const RBRAttachmentType attachType0 = RBRAttachmentType_PlayTimeLog; static const RBRAttachmentType attachType1 = RBRAttachmentType_None; + // MWCC needs volatile reads to preserve the attachment constant layout. u32 attachSize[RBR_ATTACHMENT_MAX] = {*reinterpret_cast(&attachSize0), *reinterpret_cast(&attachSize1)}; RBRAttachmentType attachType[RBR_ATTACHMENT_MAX] = { diff --git a/src/system/iplTVRCManager.cpp b/src/system/iplTVRCManager.cpp index 9e7b5c63..a70ad1b4 100644 --- a/src/system/iplTVRCManager.cpp +++ b/src/system/iplTVRCManager.cpp @@ -77,7 +77,7 @@ namespace ipl { nand::wrapper::Close(&fileInfo); - // why + // MWCC needs this shared return block to preserve the settings error branches. if (result <= 0) { goto fail; open_err: @@ -223,7 +223,6 @@ namespace ipl { } } - /* idk*/ #define IS_DISABLED (mbInitialized && mbPrepTVRC && mbDisabled && !mbResetting) #define IS_ENABLED (mbInitialized && mbPrepTVRC && !mbDisabled && !mbResetting) @@ -242,7 +241,7 @@ namespace ipl { mDisabledTriggerState = 0; mDisabledTriggerTick = OSGetTick(); } - goto ret; + return; } switch (mState) { case STATE_0: { @@ -262,15 +261,14 @@ namespace ipl { mbRepeatCommand = 1; mState = STATE_2; mLastCommandTime = OSGetTime(); - goto fallthrough; + } else { + if (mLastCommandTime != 0 && OSTicksToMilliseconds(OSDiffTick(OSGetTime(), mLastCommandTime)) >= 5000) { + mLastCommandTime = 0; + } + break; } - if (mLastCommandTime != 0 && OSTicksToMilliseconds(OSDiffTick(OSGetTime(), mLastCommandTime)) >= 5000) { - mLastCommandTime = 0; - } - break; } case STATE_2: { - fallthrough: snd::getSystem()->muteOnBGM(10); System::getMasterController()->setForceInvalid(TRUE); mMuteStartTime = OSGetTime(); @@ -333,9 +331,6 @@ namespace ipl { break; } } - - ret: - return; } void TVRCManager::resetProcessAsync(BOOL flag) { diff --git a/src/system/odh.cpp b/src/system/odh.cpp index 5223eca0..0d67c2d1 100644 --- a/src/system/odh.cpp +++ b/src/system/odh.cpp @@ -1294,7 +1294,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blockX * 8; if (statusOrOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables,master->coefficients,master->workBuffer + statusOrOffset, @@ -1312,7 +1312,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blocksHigh * ((u32)master->blocksWide << 6); if (statusOrOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables + 64,master->coefficients,master->workBuffer + statusOrOffset, @@ -1332,7 +1332,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blocksWide * ((u32)master->blockY << 6)); if (statusOrOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables + 64,master->coefficients,master->workBuffer + statusOrOffset, @@ -1352,7 +1352,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w requiredBlockEnd = planeOffset + (blockRowSize * 2) + 8; if (requiredBlockEnd > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables,master->coefficients,master->workBuffer + planeOffset @@ -1368,7 +1368,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w } if (requiredBlockEnd + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables,master->coefficients, @@ -1386,7 +1386,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blocksHigh * ((u32)master->blocksWide << 7); if (statusOrOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables + 64,master->coefficients,master->workBuffer + statusOrOffset, @@ -1405,7 +1405,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blocksWide * ((u32)master->blockY << 6)); if (statusOrOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables + 64,master->coefficients,master->workBuffer + statusOrOffset, @@ -1424,7 +1424,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blocksWide * ((u32)master->blockY << 6) * 2; if (planeOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables,master->coefficients,master->workBuffer + planeOffset @@ -1441,7 +1441,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w planeOffset += (u32)master->blocksWide << 6; if (planeOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables,master->coefficients,master->workBuffer + planeOffset @@ -1459,7 +1459,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blocksWide * ((u32)master->blockY << 6)); if (statusOrOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables + 64,master->coefficients,master->workBuffer + statusOrOffset, @@ -1478,7 +1478,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blocksWide * ((u32)master->blockY << 6)); if (statusOrOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables + 64,master->coefficients,master->workBuffer + statusOrOffset, @@ -1498,7 +1498,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w requiredBlockEnd = planeOffset + (blockRowSize * 2) + 8; if (requiredBlockEnd > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables,master->coefficients,master->workBuffer + planeOffset @@ -1515,7 +1515,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w planeOffset = nextOffset; if (nextOffset + (blockRowSize * 2) + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables,master->coefficients,master->workBuffer + nextOffset @@ -1533,7 +1533,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w planeOffset = requiredBlockEnd + (blockRowSize * 2) + 8; if (planeOffset > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables,master->coefficients,master->workBuffer + requiredBlockEnd @@ -1549,7 +1549,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w } if (planeOffset + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables,master->coefficients, @@ -1567,7 +1567,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blocksWide * ((u32)master->blockY << 6)); if (statusOrOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables + 64,master->coefficients,master->workBuffer + statusOrOffset, @@ -1586,7 +1586,7 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w (u32)master->blocksWide * ((u32)master->blockY << 6)); if (statusOrOffset + blockRowSize + 8 > workBufferSize) { statusOrOffset = -0x7ffffffa; - goto finishBlock; + return statusOrOffset; } idct_fast (range_limit,master->quantizationTables + 64,master->coefficients,master->workBuffer + statusOrOffset, @@ -1600,7 +1600,6 @@ s32 CArGBAOdh::cdj_d_decompressLoop(SArCDJ_OdhMaster* master, int srcSize, int w } } while (master->blockY < master->blocksHigh); statusOrOffset = 0; -finishBlock: return statusOrOffset; } diff --git a/tools/decomp-assist/cleanup2-x4.attempts.md b/tools/decomp-assist/cleanup2-x4.attempts.md new file mode 100644 index 00000000..b2242341 --- /dev/null +++ b/tools/decomp-assist/cleanup2-x4.attempts.md @@ -0,0 +1,171 @@ +# cleanup2-x4 attempts + +Assigned worktree `/mnt/drive2/projects/wii-ipl-workers/data-d1`, branch `agent/w1009/cleanup2-x4`; baseline `aed62d85`. Scope is `src/system/` and `src/utility/`, excluding `iplNandSDWorker.cpp`, `iplSystem.cpp`, `iplSaveDataManager.cpp`, and `iplESMisc.cpp`. The pre-existing untracked `rx67c.attempts.md` is left alone. + +Read cleanup-common.md fully, including wave-2 guidance, and ran the full 43U build before source inspection. Baseline is 1028/1028 linked units, 12563/12563 exact functions, 100% code and data; completion checker returned `DECOMPLETE_OK`. DOL SHA1 is `26116613f624061ba99c8d1a299aaa6efa85670d`. + +Saved owned source files, built objects and report in `/tmp/cleanup2-x4-baseline`. Each trial changes one function or independent expression, builds its object, and compares all allocated section bytes, sizes, alignment, exported symbols and relocation targets. Local relocation targets resolve to section and offset so compiler literal renumbering cannot hide a code or data difference. Rejected trials restore the prior source and rebuild its exact object. + +Earlier cleanup-c2 trials already exhausted simple pragma removal and scoped-address variants in ChannelManager, Scroller pragma removal, cursor-copy alternatives, and set_string loop/flag versions. This pass does not repeat those families. Ordinary shared error/cleanup exits remain unless a useful exact simplification succeeds. Unknown header fields stay because headers are outside this worker's file assignment. + +## Trials +- KEEP `src/system/odh` decompressLoop use early returns for work-buffer errors: allocated sections, exported symbols and resolved relocations identical. +- ODH compressor retains two idiomatic jumps to its single return. Decoder work-buffer errors now return early, removing 17 gotos and the label; ctxdiff is 899/899 instructions, diffs 0. +- KEEP `src/system/iplDialogWindow` start_trig_event move button lookup out of comma condition: allocated sections, exported symbols and resolved relocations identical. +- REVERT `src/system/iplNwc24Manager` addDlTask move retry delay to loop tail and remove entry goto: .text 12756->12756 bytes; .text relocation targets; addDlTask__Q33ipl5nwc247ManagerFv: 80 diffs, 98->98 instructions +- REVERT `src/system/iplNwc24Manager` addDlTask express retry delay and count as for-loop update: .text 12756->12756 bytes; .text relocation targets; addDlTask__Q33ipl5nwc247ManagerFv: 80 diffs, 98->98 instructions +- KEEP `src/system/iplNwc24Manager` addDlTask poll open in the while condition and return on timeout: allocated sections, exported symbols and resolved relocations identical. +- KEEP `src/system/iplNwc24Manager` receive name the received-message and cleanup labels: allocated sections, exported symbols and resolved relocations identical. +- NWC24 make_text and receive retain their ordinary shared cleanup jumps; utility set_string and Scroller retain the compiler requirements already tested in cleanup-c2. NAND File and MetaFile keep their shared cleanup/error exits. No unproven header-field rename was introduced. +- REVERT `src/system/iplPlayTimeLog` create_new_record read attachment constants without use-site volatility: .sdata2 36->52 bytes; .text relocation targets +- REVERT `src/system/iplPlayTimeLog` write_record read attachment constants without use-site volatility: .sdata2 36->52 bytes +- REVERT `src/system/iplTVRCManager` loadResources return directly when opening settings fails: .text 3484->3480 bytes; exported symbols; .text relocation targets; loadResources___Q23ipl11TVRCManagerFPQ23EGG4Heap: 116 diffs, 140->139 instructions +- KEEP `src/system/iplTVRCManager` update replace shared empty exit goto with return: allocated sections, exported symbols and resolved relocations identical. +- KEEP `src/system/iplTVRCManager` update use normal STATE_1 to STATE_2 switch fallthrough: allocated sections, exported symbols and resolved relocations identical. +- REVERT `src/system/iplPlayTimeLog` create_new_record move required attachment volatility to constant declarations: .sbss2 missing->8 bytes; .sdata2 36->28 bytes; .text 4900->4900 bytes; exported symbols; .text relocation targets; create_new_record__Q23ipl11PlayTimeLogFPCQ23ipl11EventBuffer: 10 diffs, 79->79 instructions +- REVERT `src/system/iplPlayTimeLog` write_record move required attachment volatility to constant declarations: .sbss2 missing->8 bytes; .sdata2 36->28 bytes; .text 4900->4900 bytes; .text relocation targets; write_record__Q23ipl11PlayTimeLogFP10_CDBRecordPQ23ipl11EventBufferPUc: 11 diffs, 70->70 instructions +- REVERT `src/system/iplControllerManager` read structure probe dispatch and empty-read handling, removing seven gotos: .text 1632->1664 bytes; exported symbols; .text relocation targets; read__Q33ipl10controller7ManagerFv: 196 diffs, 190->198 instructions +- KEEP `src/system/iplPlayTimeLog` replace stale matching notes with one-line reasons for retained volatile reads: allocated sections, exported symbols and resolved relocations identical. +- REVERT `src/system/iplTVRCManager` loadResources guard settings processing with a structured open-success branch: .text 3484->3484 bytes; loadResources___Q23ipl11TVRCManagerFPQ23EGG4Heap: 2 diffs, 140->140 instructions +- REVERT `src/system/iplControllerManager` read structure the empty-read branch independently of probe dispatch: .text 1632->1632 bytes; .text relocation targets; read__Q33ipl10controller7ManagerFv: 71 diffs, 190->190 instructions +- REVERT `src/system/iplNandShared` openTicketFile remove two self-assignments: .text 1396->1388 bytes; exported symbols; .text relocation targets; openTicketFile___Q33ipl4nand10SharedFileFv: 137 diffs, 180->178 instructions +- REVERT `src/system/iplNandMeta` readTicketBlock combine seek failures in a structured read guard: .text 1560->1552 bytes; exported symbols; .text relocation targets; readTicketBlock___Q33ipl4nand8MetaFileFPvii: 38 diffs, 58->56 instructions +- KEEP `src/system/iplNigaoeManager` constructor name the MAC-byte text buffer: allocated sections, exported symbols and resolved relocations identical. +- KEEP `src/system/iplControllerManager` read put the zero-read branch first to preserve count/null block order: allocated sections, exported symbols and resolved relocations identical. +- KEEP `src/system/iplNandMeta` readTicketBlock move shared failure label outside the read condition: allocated sections, exported symbols and resolved relocations identical. +- KEEP `src/system/iplNandShared` openTicketFile name ticket/error locals and document required self-copies: allocated sections, exported symbols and resolved relocations identical. +- REVERT `src/system/iplControllerManager` read replace remaining probe dispatch with short-circuit range guards: .text 1632->1636 bytes; exported symbols; .text relocation targets; read__Q33ipl10controller7ManagerFv: 155 diffs, 190->191 instructions +- KEEP `src/system/iplControllerManager` remove unused register-helper declarations and explain retained probe dispatch: allocated sections, exported symbols and resolved relocations identical. +- KEEP `src/system/iplTVRCManager` explain retained settings return block and remove stale notes: allocated sections, exported symbols and resolved relocations identical. + +## Retained cleanup and compiler requirements + +- odh.cpp: removed 17 decoder error gotos and its label. Kept the compressor's ordinary shared return. +- iplDialogWindow.cpp: separated the button lookup from its comma condition while preserving the page-fade short circuit. +- iplNwc24Manager.cpp: replaced the jump into the retry loop with while (!open()), named retryCount, and named the received-message/cleanup labels. Kept ordinary shared message cleanup exits. +- iplPlayTimeLog.cpp: removed stale matching notes and documented the required volatile reads. Plain reads add 16 bytes of attachment constants; declaration-level volatility moves zero constants into .sbss2 and changes code. +- iplTVRCManager.cpp: removed the update exit goto and switch-entry goto through ordinary fallthrough. Kept the settings open-error entry with a compiler note. Direct return removes one instruction; a structured open-success branch changes two instructions. +- iplControllerManager.cpp: removed two empty-read gotos and one label, plus eight unused register-helper declarations. Kept probe dispatch with a compiler note; fully structured guards add one or eight instructions. Putting the zero-read branch first is exact. +- iplNandMeta.cpp: moved the read failure label out of the conditional block and used an early successful return. Kept the shared seek-error exit; merging its two seek checks removes two instructions. +- iplNandShared.cpp: named ticket list/count/index, content descriptor/index and error stage/code. Kept two self-copies with a compiler note; removal drops two instructions. Kept the idiomatic shared error report. +- iplNigaoeManager.cpp: renamed temp to macByteText where two hexadecimal digits become a MAC byte. + +Largest-first inventory covered all owned sources. There are no remaining owned decompiler local/var/temp placeholder declarations. Remaining unk_0x names are declarations in excluded headers or SDK headers, so no field role was guessed. ChannelManager and Scroller pragmas and utility runtime-type exit retain prior cleanup-c2 evidence. Other owned files contain ordinary loops/call arguments or common cleanup exits, not condition comma operators. + +All nine changed object images equal the saved baseline in every allocated section byte, size, alignment, exported symbol and resolved relocation. Pools are identical against retail objects. The 12 affected/reviewed functions have identical instruction counts and ctxdiff diffs 0. Every changed unit's live objdiff code, data, functions, sections and link measures remain 100% before the final gate. git diff --check passed. + +## Source commits + +- ff2a2f70 cleanup: return directly from ODH buffer errors +- bfa11006 cleanup: separate dialog button lookup from condition +- a257fe26 cleanup: structure NWC24 retries and name cleanup paths +- bc6239c1 cleanup: explain retained play-log constant loads +- 40e8f604 cleanup: use TV remote switch fallthrough +- 06ebd40d cleanup: structure zero-read handling and remove unused declarations +- b18898b8 cleanup: move NAND metadata failure label to common exit +- a5ea226e cleanup: name shared NAND ticket and error locals +- fa0522a3 cleanup: name MAC-byte text buffer + +## Final gate + +Ran gate.py once over all nine changed units with --quick, as required by cleanup-common.md. Full 43U build passed; zero regressions, forbidden-pattern additions or readability warnings. The DOL SHA1 remains 26116613f624061ba99c8d1a299aaa6efa85670d. The regenerated live report and linked DOL passed DECOMPLETE_OK; build/43U/ok is current. + +| Unit | Exact functions before -> after | Code bytes | Data bytes | Sections and links | +| --- | --- | --- | --- | --- | +| src/system/iplControllerManager | 10/10 -> 10/10 | 1632/1632 | 320/320 | 100% | +| src/system/iplNandShared | 8/8 -> 8/8 | 1372/1372 | 136/136 | 100% | +| src/system/iplNandMeta | 13/13 -> 13/13 | 1536/1536 | 136/136 | 100% | +| src/system/iplNigaoeManager | 9/9 -> 9/9 | 1148/1148 | 24/24 | 100% | +| src/system/iplPlayTimeLog | 18/18 -> 18/18 | 4856/4856 | 388/388 | 100% | +| src/system/iplNwc24Manager | 53/53 -> 53/53 | 10252/10252 | 888/888 | 100% | +| src/system/iplDialogWindow | 67/67 -> 67/67 | 12984/12984 | 1548/1548 | 100% | +| src/system/odh | 28/28 -> 28/28 | 14684/14684 | 6360/6360 | 100% | +| src/system/iplTVRCManager | 13/13 -> 13/13 | 3484/3484 | 120/120 | 100% | + +```text +full build: ok +main.dol sha1: 26116613f624061ba99c8d1a299aaa6efa85670d +[src/system/odh] pool: IDENTICAL +[src/system/odh] objdiff: code 14684/14684 data 6360/6360 functions 28/28 fuzzy 100.0000 linked code 14684 +[src/system/odh] instruction-exact functions: 28/28 +[src/system/odh] section .data size 464 match 100.0 +[src/system/odh] section .rodata size 5856 match 100.0 +[src/system/odh] section .sdata2 size 40 match 100.0 +[src/system/odh] section .text size 14684 match 100.0 +[src/system/odh] baseline: code 14684/14684 data 6360 functions 28 fuzzy 100.0000 +[src/system/iplDialogWindow] pool: IDENTICAL +[src/system/iplDialogWindow] objdiff: code 12984/12984 data 1548/1548 functions 67/67 fuzzy 100.0000 linked code 12984 +[src/system/iplDialogWindow] instruction-exact functions: 67/67 +[src/system/iplDialogWindow] section .ctors size 4 match 100.0 +[src/system/iplDialogWindow] section .data size 1376 match 100.0 +[src/system/iplDialogWindow] section .sbss size 16 match 100.0 +[src/system/iplDialogWindow] section .sdata size 104 match 100.0 +[src/system/iplDialogWindow] section .sdata2 size 48 match 100.0 +[src/system/iplDialogWindow] section .text size 12984 match 100.0 +[src/system/iplDialogWindow] baseline: code 12984/12984 data 1548 functions 67 fuzzy 100.0000 +[src/system/iplNwc24Manager] pool: IDENTICAL +[src/system/iplNwc24Manager] objdiff: code 10252/10252 data 888/888 functions 53/53 fuzzy 100.0000 linked code 10252 +[src/system/iplNwc24Manager] instruction-exact functions: 53/53 +[src/system/iplNwc24Manager] section .bss size 256 match 100.0 +[src/system/iplNwc24Manager] section .data size 576 match 100.0 +[src/system/iplNwc24Manager] section .sdata size 16 match 100.0 +[src/system/iplNwc24Manager] section .sdata2 size 40 match 100.0 +[src/system/iplNwc24Manager] section .text size 10252 match 100.0 +[src/system/iplNwc24Manager] baseline: code 10252/10252 data 888 functions 53 fuzzy 100.0000 +[src/system/iplPlayTimeLog] pool: IDENTICAL +[src/system/iplPlayTimeLog] objdiff: code 4856/4856 data 388/388 functions 18/18 fuzzy 100.0000 linked code 4856 +[src/system/iplPlayTimeLog] instruction-exact functions: 18/18 +[src/system/iplPlayTimeLog] section .bss size 208 match 100.0 +[src/system/iplPlayTimeLog] section .ctors size 4 match 100.0 +[src/system/iplPlayTimeLog] section .data size 88 match 100.0 +[src/system/iplPlayTimeLog] section .rodata size 24 match 100.0 +[src/system/iplPlayTimeLog] section .sdata size 24 match 100.0 +[src/system/iplPlayTimeLog] section .sdata2 size 40 match 100.0 +[src/system/iplPlayTimeLog] section .text size 4856 match 100.0 +[src/system/iplPlayTimeLog] baseline: code 4856/4856 data 388 functions 18 fuzzy 100.0000 +[src/system/iplTVRCManager] pool: IDENTICAL +[src/system/iplTVRCManager] objdiff: code 3484/3484 data 120/120 functions 13/13 fuzzy 100.0000 linked code 3484 +[src/system/iplTVRCManager] instruction-exact functions: 13/13 +[src/system/iplTVRCManager] section .data size 112 match 100.0 +[src/system/iplTVRCManager] section .sbss size 8 match 100.0 +[src/system/iplTVRCManager] section .text size 3484 match 100.0 +[src/system/iplTVRCManager] baseline: code 3484/3484 data 120 functions 13 fuzzy 100.0000 +[src/system/iplControllerManager] pool: IDENTICAL +[src/system/iplControllerManager] objdiff: code 1632/1632 data 320/320 functions 10/10 fuzzy 100.0000 linked code 1632 +[src/system/iplControllerManager] instruction-exact functions: 10/10 +[src/system/iplControllerManager] section .data size 280 match 100.0 +[src/system/iplControllerManager] section .sbss size 16 match 100.0 +[src/system/iplControllerManager] section .sdata2 size 24 match 100.0 +[src/system/iplControllerManager] section .text size 1632 match 100.0 +[src/system/iplControllerManager] baseline: code 1632/1632 data 320 functions 10 fuzzy 100.0000 +[src/system/iplNandMeta] pool: IDENTICAL +[src/system/iplNandMeta] objdiff: code 1536/1536 data 136/136 functions 13/13 fuzzy 100.0000 linked code 1536 +[src/system/iplNandMeta] instruction-exact functions: 13/13 +[src/system/iplNandMeta] section .data size 128 match 100.0 +[src/system/iplNandMeta] section .sdata size 8 match 100.0 +[src/system/iplNandMeta] section .text size 1536 match 100.0 +[src/system/iplNandMeta] baseline: code 1536/1536 data 136 functions 13 fuzzy 100.0000 +[src/system/iplNandShared] pool: IDENTICAL +[src/system/iplNandShared] objdiff: code 1372/1372 data 136/136 functions 8/8 fuzzy 100.0000 linked code 1372 +[src/system/iplNandShared] instruction-exact functions: 8/8 +[src/system/iplNandShared] section .data size 128 match 100.0 +[src/system/iplNandShared] section .sdata size 8 match 100.0 +[src/system/iplNandShared] section .text size 1372 match 100.0 +[src/system/iplNandShared] baseline: code 1372/1372 data 136 functions 8 fuzzy 100.0000 +[src/system/iplNigaoeManager] pool: IDENTICAL +[src/system/iplNigaoeManager] objdiff: code 1148/1148 data 24/24 functions 9/9 fuzzy 100.0000 linked code 1148 +[src/system/iplNigaoeManager] instruction-exact functions: 9/9 +[src/system/iplNigaoeManager] section .data size 24 match 100.0 +[src/system/iplNigaoeManager] section .text size 1148 match 100.0 +[src/system/iplNigaoeManager] baseline: code 1148/1148 data 24 functions 9 fuzzy 100.0000 +regressions vs baseline: 0 +global matched_code_percent: 100.00000 -> 100.00000 +global fuzzy_match_percent: 99.99989 -> 99.99989 +global complete_code_percent: 100.00000 -> 100.00000 +global matched_data_percent: 100.00000 -> 100.00000 +forbidden patterns added (net, per file): 0 +readability warnings (net, per file; must be 0 in the final result): 0 +GATE PASS +``` + +While this worker ran, origin/main advanced to 164de9ceaf496d1e69294db53cbed45881d168e1. Before the documentation commit, the leaf is 9 ahead / 6 behind. The assigned baseline stays aed62d85; no fetch, rebase, merge, push, PR or cross-worktree edit was performed. Parent integration must validate against its current main. The pre-existing untracked rx67c.attempts.md remains unchanged. -- 2.49.1 From 435996957ace414af9dce3b38b46661c26b294f0 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 9 Oct 2026 12:59:38 -0500 Subject: [PATCH 2/2] fix(jpeg): subtract the column in restart fallback result --- .../TMC_JPEG/src/jpegdec/jdec_main.c | 2 +- .../jpeg-restart-status-lifetime.attempts.md | 103 ++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tools/decomp-assist/jpeg-restart-status-lifetime.attempts.md diff --git a/libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main.c b/libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main.c index 06bb5c5f..98c03ed7 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main.c @@ -1127,7 +1127,7 @@ s32 TMCJPEGDEC_err_restart(TMCCJPEGDecWork* work) { state->posY = div; state->position = TMCJPEGDEC_get_position(work); - return state->result - (state->posY * state->maxX) - state->posY; + return state->result - (state->posY * state->maxX) - state->posX; } } #endif diff --git a/tools/decomp-assist/jpeg-restart-status-lifetime.attempts.md b/tools/decomp-assist/jpeg-restart-status-lifetime.attempts.md new file mode 100644 index 00000000..6d2fc83a --- /dev/null +++ b/tools/decomp-assist/jpeg-restart-status-lifetime.attempts.md @@ -0,0 +1,103 @@ +# JPEG restart scan-status lifetime investigation + +Base: `aed62d8530993250fe0237e5adfd3b5a4d811020` (43U only). +Target: `TMCJPEGDEC_err_restart`, 0x814EDAC0, 460 bytes / 115 instructions. + +The retained MWCC assembly remains unchanged. No inventory classification, +link setting, compiler option, or other function changed. No upstream or external +source was accessed; all target observations came from the locally split retail +object. This is not an exact-C conversion or a decompilation-completion claim. + +## Prior evidence and bounded new approach + +Read rx19 and the rx24 summary, then found the later `opus-ph.attempts.md` and +its preserved C. That log already tested the ordinary loop/exit/predicate forms +and reports front-end folding of the missing range-test exit branch. Its switch +candidate has 115 instructions but wrong signed comparisons and bound order. + +New hypothesis: the call's real error status may naturally stay live across the +marker-scan latch. Unlike an artificial flag or dummy copy, this status already +controls whether scanning can continue and is returned on read failure. Two +structured forms tested its lifetime without changing marker-read order or the +successful restart computation: + +| Form | Exact-name objdiff | Instructions | +| --- | ---: | ---: | +| Recovered ordinary-loop baseline | 95.73913% | 114/115 | +| `while (result >= 0)` scan with gated success | 91.13043% | 117/115 | +| `do` scan with error break and status latch | 92.13043% | 116/115 | + +Both new forms retain a status comparison absent in the target and still fold +the upper marker-bound test. They do not justify further status-flag sweeps. +All three trial implementations were removed. No debugger, compiler-memory, +register forcing, inline assembly addition, or optimizer control was used. + +## Independently proven inactive-fallback correction + +One existing fallback line returned +`state->result - state->posY * state->maxX - state->posY`. +The retail function instead ends with these data accesses and operations: + +- `lhz r4, 2(r31)`: posY +- `lhz r3, 0x10(r31)`: maxX +- `lwz r0, 0xc(r31)`: result +- `mullw r3, r4, r3` +- `lhz r4, 0(r31)`: posX +- `subf r0, r3, r0` +- `subf r3, r4, r0` + +`TMCCJPEGDecState` in `tmc_jpeg.h` independently names those offsets. The API's +normal decode completion in `src/api/decapi.c` uses the same remaining-MCU +formula, `state->result - (curY * maxX) - curX`; its error path calls this restart +function. Therefore the last subtraction must use posX. For total=100, +maxX=10, posY=2, posX=3, the correct target result is 77; the old fallback gives 78. + +Only this one inactive C line is corrected. It does not alter the active MWCC +implementation or make the remaining C fallback exact. + +## Validation + +Validation results are recorded below after the final build. + +- Final `ninja build/43U/ok`: passed (1,031 build steps); immediate repeat: + no work to do +- DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d` +- `tools/test_workflow_guards.py`: all 23 tests passed +- Fresh full objdiff report: 1,028 units, preserved in the external evidence + directory as `restored-full-report.json` +- Complete compiled `jdec_main.o` is byte-identical to the retained-production + baseline object, including all ELF metadata and relocations +- Original target versus final built `.text`: all 5,604 raw bytes identical +- Original target versus final built `.rodata`: all 256 raw bytes identical +- All 13 unit functions have identical instructions and resolved relocations +- Restart target: all 460 raw bytes, 115 instructions, and normalized + relocation records identical; this remains the retained assembly +- String pool comparison: identical (zero printable strings in `.data`) +- Target instruction sequence checked directly; 10,004 boundary/random + arithmetic states agree with the corrected unsigned return expression +- `git diff --check`: passed + +Evidence, including trial sources/objects, reports, raw function bytes, +relocation records, disassembly, sibling audit, build log and test log, is kept +outside the repository in the task's `jpeg-restart-evidence` directory. The +one-line fallback correction is the only production-source change. + +## Rebase validation + +Rebased the minimal correction onto `c3dd1c08c04a38975b63dded77a7aef6fce385f3`. +The final leaf passes `43U/ok`, retains the expected DOL SHA1, and passes all 23 +guard tests. Its freshly generated full report has identical global measures +and all 1,028 unit records to the freshly generated report on that main commit. +The complete `jdec_main.o` remains byte-identical to the production baseline; +the raw target, relocation, sibling and arithmetic audits pass again. + +## Final integration-base validation + +Rebased again onto `f2006bdd15fd1a6bed189aa53924fdfc7e0e841f` after the +independent hasChannel conversion and scene cleanup. Full `43U/ok`, expected DOL +SHA1, 23 guards, byte-identical `jdec_main.o`, and all focused audits pass again. +The fresh full report's global measures and all 1,028 unit records exactly match +the fresh report on this main commit. Current inventory is 165 functions, +167 bodies/blocks, 162 ORIGINAL and 3 PLACEHOLDER; this leaf changes none of +those counts. The inventory's expected failure still lists err_restart, +CNTCACHEClear and System::warning_run. -- 2.49.1