From 824276fbdcc4fa1d35784e1437a6c3f55d897a57 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 9 Oct 2026 08:13:37 +0000 Subject: [PATCH] decomp(sdmemory): match drawTransferTitles and link iplSDMemory; loadCardFileIcons 213 -> 126 (worker 76898382) --- config/43U/symbols.txt | 20 +- configure.py | 2 +- include/scene/sdChannelMemory/iplSDMemory.h | 11 +- .../sdChannelSelect/iplSDChannelSelect.h | 23 +- libs/NW4R/include/nw4r/lyt/pane.h | 2 +- src/scene/cardSequence/iplCardSequence.cpp | 207 +++++++++--------- src/scene/sdChannelMemory/iplSDMemory.cpp | 80 +++---- .../sdChannelSelect/iplSDChannelSelect.cpp | 49 +++-- .../sdChannelTitle/iplSDChannelTitle.cpp | 13 +- .../o2-cardseq-sdmem.attempts.md | 110 ++++++++++ 10 files changed, 293 insertions(+), 224 deletions(-) create mode 100644 tools/decomp-assist/o2-cardseq-sdmem.attempts.md diff --git a/config/43U/symbols.txt b/config/43U/symbols.txt index 3e7cf045..80a61539 100644 --- a/config/43U/symbols.txt +++ b/config/43U/symbols.txt @@ -4584,11 +4584,11 @@ enqueueLoadNotice__Q33ipl5scene15SDChannelSelectFv = .text:0x813DB308; // type:f enqueuePageNotice__Q33ipl5scene15SDChannelSelectFv = .text:0x813DB364; // type:function size:0x5C enqueueResultNotice__Q33ipl5scene15SDChannelSelectFUl = .text:0x813DB3C0; // type:function size:0x5C enqueueChannelNotice__Q33ipl5scene15SDChannelSelectFUxUl = .text:0x813DB41C; // type:function size:0x5C -enqueueMoveNotice__Q33ipl5scene15SDChannelSelectFUlUlUl = .text:0x813DB478; // type:function size:0x5C +enqueueMoveNotice__Q33ipl5scene15SDChannelSelectFUx = .text:0x813DB478; // type:function size:0x5C enqueueStateNotice__Q33ipl5scene15SDChannelSelectFUxUl = .text:0x813DB4D4; // type:function size:0x5C -enqueueErrorNotice__Q33ipl5scene15SDChannelSelectFUlUl = .text:0x813DB530; // type:function size:0x5C -enqueueCommandNotice__Q33ipl5scene15SDChannelSelectFUlUlUl = .text:0x813DB58C; // type:function size:0x60 -enqueueDeleteNotice__Q33ipl5scene15SDChannelSelectFUlUlUl = .text:0x813DB5EC; // type:function size:0x60 +enqueueErrorNotice__Q33ipl5scene15SDChannelSelectFPQ33ipl12NandSDWorker11TitleIdListPQ33ipl12NandSDWorker11TitleIdList = .text:0x813DB530; // type:function size:0x5C +enqueueCommandNotice__Q33ipl5scene15SDChannelSelectFPQ33ipl12NandSDWorker11TitleIdListPQ33ipl12NandSDWorker11TitleIdListPQ33ipl12NandSDWorker11TitleIdList = .text:0x813DB58C; // type:function size:0x60 +enqueueDeleteNotice__Q33ipl5scene15SDChannelSelectFUx = .text:0x813DB5EC; // type:function size:0x60 clearCommandQueue__Q33ipl5scene15SDChannelSelectFv = .text:0x813DB64C; // type:function size:0x40 clearNoticeQueue__Q33ipl5scene15SDChannelSelectFv = .text:0x813DB68C; // type:function size:0x40 processWorkerCommands__Q33ipl5scene15SDChannelSelectFv = .text:0x813DB6CC; // type:function size:0x518 @@ -4617,11 +4617,11 @@ updateDialogAnimation__Q33ipl5scene15SDChannelSelectFv = .text:0x813DCAC4; // ty setDialogMessage__Q33ipl5scene15SDChannelSelectFUlUl = .text:0x813DCEF0; // type:function size:0x24 isCurrentTitleUsageEnough__Q33ipl5scene15SDChannelSelectCFPCl = .text:0x813DCF14; // type:function size:0xCC getCurrentTitleUsage__Q33ipl5scene15SDChannelSelectCFPlPl = .text:0x813DCFE0; // type:function size:0xCC -collectTitlesByUsage__Q33ipl5scene15SDChannelSelectFPlPlPUxPcPUl = .text:0x813DD0AC; // type:function size:0x194 -collectTitlesFromNandUsage__Q33ipl5scene15SDChannelSelectFPlPlPUxPcPUl = .text:0x813DD240; // type:function size:0x198 -collectTitlesByChannelOrder__Q33ipl5scene15SDChannelSelectFPlPlPUxPcPUl = .text:0x813DD3D8; // type:function size:0x1F8 -collectTitlesBySpecialChannels__Q33ipl5scene15SDChannelSelectFPlPlPUxPcPUl = .text:0x813DD5D0; // type:function size:0x5A4 -collectTitlesForMode__Q33ipl5scene15SDChannelSelectFPlPlPUxPcPUli = .text:0x813DDB74; // type:function size:0x40 +collectTitlesByUsage__Q33ipl5scene15SDChannelSelectFPlPlPUxPA21_wPUl = .text:0x813DD0AC; // type:function size:0x194 +collectTitlesFromNandUsage__Q33ipl5scene15SDChannelSelectFPlPlPUxPA21_wPUl = .text:0x813DD240; // type:function size:0x198 +collectTitlesByChannelOrder__Q33ipl5scene15SDChannelSelectFPlPlPUxPA21_wPUl = .text:0x813DD3D8; // type:function size:0x1F8 +collectTitlesBySpecialChannels__Q33ipl5scene15SDChannelSelectFPlPlPUxPA21_wPUl = .text:0x813DD5D0; // type:function size:0x5A4 +collectTitlesForMode__Q33ipl5scene15SDChannelSelectFPlPlPUxPA21_wPUli = .text:0x813DDB74; // type:function size:0x40 findAdjacentChannel__Q33ipl5scene15SDChannelSelectCFiPiPi = .text:0x813DDBB4; // type:function size:0xB4 setCurrentPageAndRefresh__Q33ipl5scene15SDChannelSelectFiiPQ33ipl5scene12SDChannelObj = .text:0x813DDC68; // type:function size:0x18 handleFourPageDialog__Q33ipl5scene15SDChannelSelectFv = .text:0x813DDC80; // type:function size:0x58 @@ -4762,7 +4762,7 @@ iplSDChannelTitle_updateParentalResult = .text:0x813E69B4; // type:function size iplSDChannelTitle_updateDialogResult = .text:0x813E6B88; // type:function size:0x144 iplSDChannelTitle_startCopyProgress = .text:0x813E6CCC; // type:function size:0x158 iplSDChannelTitle_updateCopyPrepare = .text:0x813E6E24; // type:function size:0x17C -iplSDChannelTitle_copyTitleRange = .text:0x813E6FA0; // type:function size:0x14 +__as__Q43ipl5scene8SDMemory10TitleRangeFRCQ43ipl5scene8SDMemory10TitleRange = .text:0x813E6FA0; // type:function size:0x14 scope:weak iplSDChannelTitle_updateMemoryCalc = .text:0x813E6FB4; // type:function size:0xC0 iplSDChannelTitle_updateCopyStart = .text:0x813E7074; // type:function size:0x130 iplSDChannelTitle_updateAfterClearTmp = .text:0x813E71A4; // type:function size:0xA8 diff --git a/configure.py b/configure.py index dd8dc3dc..aee90111 100644 --- a/configure.py +++ b/configure.py @@ -864,7 +864,7 @@ config.libs = [ ] ), IPLSection("sdChannelMemory", [ - Object(NonMatching, "scene/sdChannelMemory/iplSDMemory.cpp"), + Object(Matching, "scene/sdChannelMemory/iplSDMemory.cpp"), ] ), IPLSection("setting", [ diff --git a/include/scene/sdChannelMemory/iplSDMemory.h b/include/scene/sdChannelMemory/iplSDMemory.h index 2ad39f8e..6fba2fc1 100644 --- a/include/scene/sdChannelMemory/iplSDMemory.h +++ b/include/scene/sdChannelMemory/iplSDMemory.h @@ -142,14 +142,9 @@ namespace ipl { u32 mTransferStatus; u64 mTransferStartTime; s32 mTransferFrame; - struct TitleListState { - ESTitleId* mpTitles; - u32 mCount; - ESTitleId* mpSecondaryTitles; - u32 mSecondaryCount; - ESTitleId* mpNames; - u32 mNameCount; - } mTitleListState; + NandSDWorker::TitleIdList mTitleList; + NandSDWorker::TitleIdList mNandTitleList; + NandSDWorker::TitleIdList mSDTitleList; scroller mScroller; s32 mButtonState; u8 mControllerFlags[4]; diff --git a/include/scene/sdChannelSelect/iplSDChannelSelect.h b/include/scene/sdChannelSelect/iplSDChannelSelect.h index 52b2b00c..8349ddd2 100644 --- a/include/scene/sdChannelSelect/iplSDChannelSelect.h +++ b/include/scene/sdChannelSelect/iplSDChannelSelect.h @@ -178,7 +178,7 @@ namespace ipl { BOOL onEventDerived(const char* paneName, u32 event, controller::Interface* controller); bool collectTitlesByUsage(s32* firstUsage, s32* secondUsage, - ESTitleId* titleIds, char* titleNames, + ESTitleId* titleIds, wchar_t (*titleNames)[21], u32* titleCount); static const char* mscChannelPaneNames[PAGE_COUNT][MAX_CHANNEL_INDEX]; @@ -197,6 +197,8 @@ namespace ipl { friend class SDChannelSelectEventHandler; friend class SDChannelSelectButtonEventHandler; #endif + friend class SDMemory; + void enqueueStartNotice(); bool enqueueFinishNotice(); bool enqueueNotice(u32 highTitleId, u32 lowTitleId, u32 result); @@ -204,11 +206,14 @@ namespace ipl { bool enqueuePageNotice(); bool enqueueResultNotice(u32 result); bool enqueueChannelNotice(u64 titleId, u32 value); - bool enqueueMoveNotice(u32 controller, u32 page, u32 index); + bool enqueueMoveNotice(ESTitleId titleId); bool enqueueStateNotice(u64 titleId, u32 state); - bool enqueueErrorNotice(u32 page, u32 index); - bool enqueueCommandNotice(u32 page, u32 index, u32 command); - bool enqueueDeleteNotice(u32 controller, u32 page, u32 index); + bool enqueueErrorNotice(NandSDWorker::TitleIdList* newTitles, + NandSDWorker::TitleIdList* replacingTitles); + bool enqueueCommandNotice(NandSDWorker::TitleIdList* titles, + NandSDWorker::TitleIdList* foundTitles, + NandSDWorker::TitleIdList* badTitles); + bool enqueueDeleteNotice(ESTitleId titleId); void clearCommandQueue(); void clearNoticeQueue(); void calcChannelObjects(); @@ -233,16 +238,16 @@ namespace ipl { bool isCurrentTitleUsageEnough(const s32* usage) const; void getCurrentTitleUsage(s32* bytes, s32* blocks) const; bool collectTitlesByChannelOrder(s32* firstUsage, s32* secondUsage, - ESTitleId* titleIds, char* titleNames, + ESTitleId* titleIds, wchar_t (*titleNames)[21], u32* titleCount); bool collectTitlesFromNandUsage(s32* firstUsage, s32* secondUsage, - ESTitleId* titleIds, char* titleNames, + ESTitleId* titleIds, wchar_t (*titleNames)[21], u32* titleCount); bool collectTitlesBySpecialChannels(s32* firstUsage, s32* secondUsage, - ESTitleId* titleIds, char* titleNames, + ESTitleId* titleIds, wchar_t (*titleNames)[21], u32* titleCount); bool collectTitlesForMode(s32* firstUsage, s32* secondUsage, - ESTitleId* titleIds, char* titleNames, + ESTitleId* titleIds, wchar_t (*titleNames)[21], u32* titleCount, int searchMode); bool findAdjacentChannel(int direction, int* page, int* index) const; void setStateAndPlaySelectSound(int state) NO_INLINE; diff --git a/libs/NW4R/include/nw4r/lyt/pane.h b/libs/NW4R/include/nw4r/lyt/pane.h index d30b01fe..e872b188 100644 --- a/libs/NW4R/include/nw4r/lyt/pane.h +++ b/libs/NW4R/include/nw4r/lyt/pane.h @@ -123,7 +123,7 @@ namespace nw4r { const math::MTX34& GetMtx() const { return mMtx; } void SetMtx(const math::MTX34& mtx) { mMtx = mtx; } - u8 GetAlpha() { return mAlpha; } + u8 GetAlpha() const { return mAlpha; } void SetAlpha(u8 alpha) { mAlpha = alpha; } const char* GetName() const { return mName; } diff --git a/src/scene/cardSequence/iplCardSequence.cpp b/src/scene/cardSequence/iplCardSequence.cpp index ddd83204..48a8a1af 100644 --- a/src/scene/cardSequence/iplCardSequence.cpp +++ b/src/scene/cardSequence/iplCardSequence.cpp @@ -707,49 +707,75 @@ extern "C" void clearAllCardFileEntries(s32 slot) { } while (file < CARD_MAX_FILE); } -static inline void updateCardIconAnimation(s32 slot, s32 fileNo, CARDDir* dir) { - s32 iconCount = 0; - s32 shift = 0; - s32 icon; - sThread->icons[slot][fileNo].unk_0x02 = 0; - sThread->icons[slot][fileNo].anmMax = 0; - sThread->icons[slot][fileNo].anmFrameBits = dir->iconSpeed; - sThread->icons[slot][fileNo].unk_0x06 = - (dir->iconSpeed & CARD_STAT_SPEED_MASK) << 2; - for (icon = 0; icon < CARD_ICON_MAX; ++icon) { - s32 iconSpeed = (dir->iconSpeed >> shift) & CARD_STAT_SPEED_MASK; - if (iconSpeed != 0) { - sThread->icons[slot][fileNo].anmMax = - sThread->icons[slot][fileNo].anmMax + (iconSpeed << 2); - } else { - sThread->icons[slot][fileNo].unk_0x07 = - (u8)(((dir->iconSpeed >> ((iconCount - 1) * 2)) << 2) & 0xC); - return; - } - iconCount = iconCount + 1; - shift = shift + 2; +static inline s32 readCardImages(s32 slot, s32 fileNo, CARDDir* dir, CARDFileInfo* fileInfo, + u32 address, s32 offset, s32 imageSize) { + s32 sectorSize; + u32 transferSize = (imageSize + offset + 0x1FF) & 0xFFFFFE00; + if (CARDGetSectorSize(slot, (u32*)§orSize) < CARD_RESULT_READY) { + sThread->icons[slot][fileNo].bannerEnable = 0; + sThread->icons[slot][fileNo].unk_0x01 = 0; + return 0; } - sThread->icons[slot][fileNo].unk_0x07 = - (dir->iconSpeed >> 0xC) & 0xC; + + u32 fileSize = (u32)dir->length * sectorSize; + if (address > fileSize) { + sThread->icons[slot][fileNo].bannerEnable = 0; + sThread->icons[slot][fileNo].unk_0x01 = 0; + return 0; + } + if (address + transferSize > fileSize) { + sThread->icons[slot][fileNo].bannerEnable = 0; + sThread->icons[slot][fileNo].unk_0x01 = 0; + return 0; + } + + if (imageSize > 0) { + s32 result = CARDRead(fileInfo, sThread->imageReadBuffer, transferSize, address); + if (result < CARD_RESULT_READY) { + return result; + } + memcpy(sThread->images[slot][fileNo], sThread->imageReadBuffer + offset, imageSize); + DCStoreRange(sThread->images[slot][fileNo], transferSize); + } + return 0; } -extern "C" s32 loadCardFileIcons(s32 slot, s32 fileNo, CARDDir* dir) { +static inline s32 readCardComment(s32 slot, s32 fileNo, CARDDir* dir, CARDFileInfo* fileInfo) { + u32 address = dir->commentAddr; + u32 base = address & 0xFFFFFE00; + s32 offset = address - base; + s32 readSize = ((address + 0x23F) & 0xFFFFFE00) - base; s32 sectorSize; - s32 commentSectorSize; - CARDFileInfo fileInfo; - u32 iconAddressBase; - s32 result; - s32 iconAddressOffset; - result = CARDFastOpen(slot, fileNo, &fileInfo); - if (result < CARD_RESULT_READY) { - return result; + s32 result = CARDGetSectorSize(slot, (u32*)§orSize); + if (result >= CARD_RESULT_READY) { + u32 fileSize; + if ((s32)base < 0 || base > (fileSize = (u32)dir->length * sectorSize)) { + result = 0; + } else { + u32 end = base + readSize; + if ((s32)end < 0 || end > fileSize) { + result = 0; + } else { + result = CARDRead(fileInfo, sThread->commentBuffer, readSize, base); + if (result >= CARD_RESULT_READY) { + memset(sThread->comments[slot][fileNo], 0, CARD_COMMENT_SIZE); + memcpy(sThread->comments[slot][fileNo], sThread->commentBuffer + offset, + CARD_COMMENT_SIZE); + return 0; + } + } + } } + memset(sThread->comments[slot][fileNo], 0, CARD_COMMENT_SIZE); + return result; +} + +static inline s32 loadCardIconImages(s32 slot, s32 fileNo, CARDDir* dir, CARDFileInfo* fileInfo) { s32 bannerImageSize = 0; u8 format = dir->bannerFormat & CARD_STAT_BANNER_MASK; u32 iconAddress = dir->iconAddr; - iconAddressBase = iconAddress & 0xFFFFFE00; - iconAddressOffset = iconAddress - iconAddressBase; + s32 iconAddressOffset = iconAddress - (iconAddress & 0xFFFFFE00); switch (format) { case CARD_STAT_BANNER_C8: { @@ -786,12 +812,33 @@ extern "C" s32 loadCardFileIcons(s32 slot, s32 fileNo, CARDDir* dir) { } } - s32 shift = 0; - BOOL hasTlut = FALSE; - s32 iconImageSize = 0; + s32 shift; + BOOL hasTlut; + s32 iconImageSize; s32 icon; - s32 iconCount = 0; - updateCardIconAnimation(slot, fileNo, dir); + s32 iconCount; + shift = 0; + iconCount = 0; + hasTlut = FALSE; + iconImageSize = 0; + sThread->icons[slot][fileNo].unk_0x02 = 0; + sThread->icons[slot][fileNo].anmMax = 0; + sThread->icons[slot][fileNo].anmFrameBits = dir->iconSpeed; + sThread->icons[slot][fileNo].unk_0x06 = (dir->iconSpeed & CARD_STAT_SPEED_MASK) << 2; + for (icon = 0; icon < CARD_ICON_MAX; ++icon) { + s32 iconSpeed = (dir->iconSpeed >> shift) & CARD_STAT_SPEED_MASK; + if (iconSpeed != 0) { + sThread->icons[slot][fileNo].anmMax = sThread->icons[slot][fileNo].anmMax + (iconSpeed << 2); + } else { + sThread->icons[slot][fileNo].unk_0x07 = + (u8)(((dir->iconSpeed >> ((iconCount - 1) * 2)) << 2) & 0xC); + goto animationDone; + } + iconCount = iconCount + 1; + shift = shift + 2; + } + sThread->icons[slot][fileNo].unk_0x07 = (dir->iconSpeed >> 0xC) & 0xC; +animationDone: if ((dir->iconSpeed & CARD_STAT_SPEED_MASK) == 0 || (dir->iconFormat & CARD_STAT_ICON_MASK) == 0) { sThread->icons[slot][fileNo].unk_0x01 = 0; iconImageSize = 0; @@ -801,7 +848,7 @@ extern "C" s32 loadCardFileIcons(s32 slot, s32 fileNo, CARDDir* dir) { for (icon = 0; icon < CARD_ICON_MAX; ++icon) { if (((dir->iconSpeed >> shift) & CARD_STAT_SPEED_MASK) != 0) { s32 iconFormat = (dir->iconFormat >> shift) & CARD_STAT_ICON_MASK; - s32 paletteSize = 0; + s32 paletteSize; switch (iconFormat) { case CARD_STAT_ICON_C8: paletteSize = 0x400; @@ -813,9 +860,9 @@ extern "C" s32 loadCardFileIcons(s32 slot, s32 fileNo, CARDDir* dir) { sThread->icons[slot][fileNo].iconFmt[iconCount] = GX_TF_RGB5A3; break; case CARD_STAT_ICON_NONE: { - u8* iconPalette = - &sThread->icons[slot][fileNo].iconFmt[iconCount]; - *iconPalette = iconPalette[-1]; + paletteSize = 0; + u8* previous = &sThread->icons[slot][fileNo].iconFmt[iconCount - 1]; + sThread->icons[slot][fileNo].iconFmt[iconCount] = *previous; break; } default: @@ -847,79 +894,23 @@ extern "C" s32 loadCardFileIcons(s32 slot, s32 fileNo, CARDDir* dir) { sThread->icons[slot][fileNo].anmDelta = 1; } - s32 totalImageSize = iconImageSize + bannerImageSize; - u32 transferSize = (totalImageSize + iconAddressOffset + 0x1FF) & 0xFFFFFE00; - result = CARDGetSectorSize(slot, (u32*)§orSize); - if (result < CARD_RESULT_READY) { - result = 0; - sThread->icons[slot][fileNo].bannerEnable = 0; - sThread->icons[slot][fileNo].unk_0x01 = 0; - } else { - u32 fileSize = (u32)dir->length * sectorSize; - if (iconAddressBase > fileSize) { - result = 0; - sThread->icons[slot][fileNo].bannerEnable = 0; - sThread->icons[slot][fileNo].unk_0x01 = 0; - } else if (iconAddressBase + transferSize > fileSize) { - result = 0; - sThread->icons[slot][fileNo].bannerEnable = 0; - sThread->icons[slot][fileNo].unk_0x01 = 0; - } else { - if (totalImageSize > 0) { - result = CARDRead(&fileInfo, sThread->imageReadBuffer, - transferSize, iconAddressBase); - if (result < CARD_RESULT_READY) { - return result; - } - memcpy(sThread->images[slot][fileNo], - sThread->imageReadBuffer + iconAddressOffset, - totalImageSize); - DCStoreRange(sThread->images[slot][fileNo], transferSize); - } - result = 0; - } - } + return readCardImages(slot, fileNo, dir, fileInfo, iconAddress & 0xFFFFFE00, iconAddressOffset, + bannerImageSize + iconImageSize); +} +extern "C" s32 loadCardFileIcons(s32 slot, s32 fileNo, CARDDir* dir) { + CARDFileInfo fileInfo; + s32 result = CARDFastOpen(slot, fileNo, &fileInfo); if (result < CARD_RESULT_READY) { return result; } - iconAddress = dir->commentAddr; - iconAddressBase = iconAddress & 0xFFFFFE00; - s32 commentDataOffset = iconAddress - iconAddressBase; - s32 imageSize = ((iconAddress + 0x23F) & 0xFFFFFE00) - iconAddressBase; - result = CARDGetSectorSize(slot, (u32*)&commentSectorSize); + result = loadCardIconImages(slot, fileNo, dir, &fileInfo); if (result < CARD_RESULT_READY) { - goto clearComment; - } - { - u32 fileSize; - if ((s32)iconAddressBase < 0 || - iconAddressBase > (fileSize = (u32)dir->length * commentSectorSize)) { - result = 0; - } else { - u32 endOffset = iconAddressBase + imageSize; - if ((s32)endOffset < 0 || endOffset > fileSize) { - result = 0; - goto clearComment; - } - result = CARDRead(&fileInfo, sThread->commentBuffer, imageSize, - iconAddressBase); - if (result < CARD_RESULT_READY) { - goto clearComment; - } - memset(sThread->comments[slot][fileNo], 0, CARD_COMMENT_SIZE); - memcpy(sThread->comments[slot][fileNo], - sThread->commentBuffer + commentDataOffset, CARD_COMMENT_SIZE); - result = 0; - goto commentDone; - } + return result; } -clearComment: - memset(sThread->comments[slot][fileNo], 0, CARD_COMMENT_SIZE); - -commentDone: + result = readCardComment(slot, fileNo, dir, &fileInfo); if (result < CARD_RESULT_READY) { return result; } diff --git a/src/scene/sdChannelMemory/iplSDMemory.cpp b/src/scene/sdChannelMemory/iplSDMemory.cpp index b24d3b74..6db3446c 100644 --- a/src/scene/sdChannelMemory/iplSDMemory.cpp +++ b/src/scene/sdChannelMemory/iplSDMemory.cpp @@ -26,23 +26,6 @@ #include "utility/iplLayout.h" #include -extern "C" bool iplSDChannelSelect_813DDB74(ipl::scene::SDChannelSelect* channelSelect, - ipl::scene::SDMemory::TitleRange* nandTitles, - ipl::scene::SDMemory::TitleRange* sdTitles, - ESTitleId* titleIds, wchar_t* titleNames, u32* titleCount, - s32 state); -extern "C" bool iplSDChannelSelect_813DB5EC(ipl::scene::SDChannelSelect* channelSelect, - ESTitleId titleId); -extern "C" bool iplSDChannelSelect_813DB4D4(ipl::scene::SDChannelSelect* channelSelect, - ESTitleId titleId, u32 flags); -extern "C" bool iplSDChannelSelect_813DB530(ipl::scene::SDChannelSelect* channelSelect, - ESTitleId** titleNames, ESTitleId** secondaryTitles); -extern "C" bool iplSDChannelSelect_813DB478(ipl::scene::SDChannelSelect* channelSelect, - ESTitleId titleId); -extern "C" bool iplSDChannelSelect_813DB58C(ipl::scene::SDChannelSelect* channelSelect, - ESTitleId** titles, ESTitleId** secondaryTitles, - ESTitleId** names); - namespace ipl { namespace scene { typedef ::gui::Component GuiComponent; @@ -725,8 +708,8 @@ namespace ipl { if (!mpMainLayout->isPlaying(-1)) { switch (mProcessState) { case 0: - if (iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, - mTitleIds, &mTitleNames[0][0], &mTitleCount, 2)) { + if (mpSDChannelSelect->collectTitlesForMode(&mNandTitleRange.mByteSize, &mSDTitleRange.mByteSize, + mTitleIds, mTitleNames, &mTitleCount, 2)) { mDialogState = 4; mpTitleLayout->getAnim(0)->initAnmFrame(); mpTitleLayout->getAnim(0)->play(); @@ -809,8 +792,8 @@ namespace ipl { if (System::getDialog()->getLastResult() != -1) { if (mpSDChannelSelect->getWorker()->get_async_result() == NandSDWorker::RESULT_OK) { - mNandTitleCount = mTitleListState.mSecondaryCount; - mTitleNameCount = mTitleListState.mNameCount; + mNandTitleCount = mNandTitleList.count; + mTitleNameCount = mSDTitleList.count; } else { mNandTitleCount = 0; mTitleNameCount = 0; @@ -924,8 +907,7 @@ namespace ipl { return; } - if (iplSDChannelSelect_813DB530(mpSDChannelSelect, &mTitleListState.mpNames, - &mTitleListState.mpSecondaryTitles)) { + if (mpSDChannelSelect->enqueueErrorNotice(&mSDTitleList, &mNandTitleList)) { mDialogState = 19; mCurrentTitleName[0] = L'\0'; mCurrentTitle = 0; @@ -998,7 +980,7 @@ namespace ipl { if (iplSDMemory_containsTitleId(this, mTitleIds[mCurrentTitle], mSDTitleIds, mTitleNameCount) || iplSDMemory_containsTitleId(this, mTitleIds[mCurrentTitle], mNandTitleIds, mNandTitleCount)) { ESTitleId titleId = mTitleIds[mCurrentTitle]; - if (iplSDChannelSelect_813DB478(mpSDChannelSelect, titleId)) { + if (mpSDChannelSelect->enqueueMoveNotice(titleId)) { mDialogState = 14; } else { System::getDialog()->terminate(); @@ -1048,7 +1030,7 @@ namespace ipl { void SDMemory::onDialogState16() { if (mTitleCount > mCurrentTitle && System::isReceiveScheduleStopped()) { - if (iplSDChannelSelect_813DB4D4(mpSDChannelSelect, mTitleIds[mCurrentTitle], 0)) { + if (mpSDChannelSelect->enqueueStateNotice(mTitleIds[mCurrentTitle], 0)) { mDialogState = 16; } else { System::getDialog()->terminate(); @@ -1103,7 +1085,7 @@ namespace ipl { System::getDialog()->setTitleForSDMemory(mCurrentTitleName); const ESTitleId titleId = mTitleIds[mCurrentTitle]; - if (iplSDChannelSelect_813DB5EC(mpSDChannelSelect, titleId)) { + if (mpSDChannelSelect->enqueueDeleteNotice(titleId)) { mDialogState = 18; } else { System::getDialog()->terminate(); @@ -1278,16 +1260,13 @@ namespace ipl { nw4r::lyt::Pane* footerPane; u32 nandTitleIndex; u32 titleIndex; - s32 visibleRows; - s32 row; wchar_t* messageForCount; s32 lineCount; wchar_t* messageLine; - s32 totalLines; + nw4r::lyt::TextBox* messageText; s32 lineIndex; wchar_t* lineEnd; u32 lineLength; - nw4r::lyt::TextBox* messageText; const nw4r::math::VEC3& translation = mpDialogLayout->FindPaneByName("N_Memo")->GetTranslate(); nw4r::math::VEC3 memoPosition; memoPosition.x = translation.x; @@ -1322,9 +1301,7 @@ namespace ipl { messageLine = System::getMessage(0xCB); messageText = static_cast( mpDialogLayout->FindPaneByName("T_Header_body")); - totalLines = lineCount + 1; - lineIndex = 0; - for (; lineIndex < totalLines; ++lineIndex) { + for (lineIndex = 0; lineIndex < lineCount + 1; ++lineIndex) { lineEnd = wcsstr(messageLine, L"\n"); if (lineEnd == NULL) { utility::layout::set_string(messageText, messageLine); @@ -1377,8 +1354,8 @@ namespace ipl { nw4r::ut::Rect textRect = mpDialogLayout->getTextDrawRect("T_Letter"); rowTop = textRect.bottom - textRect.top; - visibleRows = static_cast(static_cast(ceil(-rowTop / titleSizePane->GetSize().height))); - for (row = 0; row < visibleRows; ++row) { + s32 visibleRows = static_cast(static_cast(ceil(-rowTop / titleSizePane->GetSize().height))); + for (s32 row = 0; row < visibleRows; ++row) { rowY = bodyY + backgroundOffset; if (-500.0f < rowY && rowY < 500.0f) { nw4r::math::VEC2 translation(0.0f, backgroundOffset); @@ -1640,23 +1617,23 @@ namespace ipl { switch (paneIndex) { case 0: animator = mpTitleLayout->getAnim(7); - iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, - mTitleIds, &mTitleNames[0][0], &mTitleCount, 0); + mpSDChannelSelect->collectTitlesForMode(&mNandTitleRange.mByteSize, &mSDTitleRange.mByteSize, + mTitleIds, mTitleNames, &mTitleCount, 0); break; case 1: animator = mpTitleLayout->getAnim(10); - iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, - mTitleIds, &mTitleNames[0][0], &mTitleCount, 1); + mpSDChannelSelect->collectTitlesForMode(&mNandTitleRange.mByteSize, &mSDTitleRange.mByteSize, + mTitleIds, mTitleNames, &mTitleCount, 1); break; case 2: animator = mpTitleLayout->getAnim(13); - iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, - mTitleIds, &mTitleNames[0][0], &mTitleCount, 2); + mpSDChannelSelect->collectTitlesForMode(&mNandTitleRange.mByteSize, &mSDTitleRange.mByteSize, + mTitleIds, mTitleNames, &mTitleCount, 2); break; case 3: animator = mpTitleLayout->getAnim(16); - iplSDChannelSelect_813DDB74(mpSDChannelSelect, &mNandTitleRange, &mSDTitleRange, - mTitleIds, &mTitleNames[0][0], &mTitleCount, 3); + mpSDChannelSelect->collectTitlesForMode(&mNandTitleRange.mByteSize, &mSDTitleRange.mByteSize, + mTitleIds, mTitleNames, &mTitleCount, 3); break; case 4: animator = mpTitleLayout->getAnim(4); @@ -1676,16 +1653,13 @@ namespace ipl { memset(mSDTitleIds, 0, sizeof(mSDTitleIds)); mNandTitleCount = 0; mTitleNameCount = 0; - mTitleListState.mpTitles = mTitleIds; - mTitleListState.mCount = mTitleCount; - mTitleListState.mpSecondaryTitles = mNandTitleIds; - mTitleListState.mSecondaryCount = 0; - mTitleListState.mpNames = mSDTitleIds; - mTitleListState.mNameCount = 0; - iplSDChannelSelect_813DB58C(mpSDChannelSelect, - &mTitleListState.mpTitles, - &mTitleListState.mpSecondaryTitles, - &mTitleListState.mpNames); + mTitleList.titleIds = mTitleIds; + mTitleList.count = mTitleCount; + mNandTitleList.titleIds = mNandTitleIds; + mNandTitleList.count = 0; + mSDTitleList.titleIds = mSDTitleIds; + mSDTitleList.count = 0; + mpSDChannelSelect->enqueueCommandNotice(&mTitleList, &mNandTitleList, &mSDTitleList); } if (paneIndex == 4) { diff --git a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp index 0675d6c6..ff32cd28 100644 --- a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp +++ b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp @@ -352,7 +352,7 @@ namespace ipl { return true; } - bool SDChannelSelect::enqueueMoveNotice(u32 controller, u32 page, u32 index) { + bool SDChannelSelect::enqueueMoveNotice(ESTitleId titleId) { if (mCurrentSDState != 6) { return false; } @@ -361,7 +361,7 @@ namespace ipl { command.type = 6; command.arguments.values[0] = 0; command.arguments.values[1] = 0; - command.titleId = ((u64)page << 32) | index; + command.titleId = titleId; mCommandQueue.push(command); return true; } @@ -380,36 +380,39 @@ namespace ipl { return true; } - bool SDChannelSelect::enqueueErrorNotice(u32 page, u32 index) { + bool SDChannelSelect::enqueueErrorNotice(NandSDWorker::TitleIdList* newTitles, + NandSDWorker::TitleIdList* replacingTitles) { if (mCurrentSDState != 6) { return false; } SDChannelSelectCommand command; command.type = 11; - command.arguments.values[0] = page; - command.arguments.values[1] = index; + command.arguments.titleLists[0] = newTitles; + command.arguments.titleLists[1] = replacingTitles; command.titleId = 0; mCommandQueue.push(command); return true; } - bool SDChannelSelect::enqueueCommandNotice(u32 page, u32 index, u32 commandType) { + bool SDChannelSelect::enqueueCommandNotice(NandSDWorker::TitleIdList* titles, + NandSDWorker::TitleIdList* foundTitles, + NandSDWorker::TitleIdList* badTitles) { if (mCurrentSDState != 6) { return false; } SDChannelSelectCommand command; - command.arguments.values[0] = page; + command.arguments.titleLists[0] = titles; command.type = 12; - command.arguments.values[1] = index; - command.arguments.values[2] = commandType; + command.arguments.titleLists[1] = foundTitles; + command.arguments.titleLists[2] = badTitles; command.titleId = 0; mCommandQueue.push(command); return true; } - bool SDChannelSelect::enqueueDeleteNotice(u32 controller, u32 page, u32 index) { + bool SDChannelSelect::enqueueDeleteNotice(ESTitleId titleId) { if (mCurrentSDState != 6) { return false; } @@ -419,7 +422,7 @@ namespace ipl { command.arguments.values[0] = 0; command.arguments.values[1] = 0; command.arguments.values[2] = 0; - command.titleId = ((u64)page << 32) | index; + command.titleId = titleId; mCommandQueue.push(command); return true; } @@ -1326,7 +1329,7 @@ namespace ipl { bool SDChannelSelect::collectTitlesByUsage( s32* firstUsage, s32* secondUsage, ESTitleId* titleIds, - char* titleNames, u32* titleCount) { + wchar_t (*titleNames)[21], u32* titleCount) { s32 bytes; s32 blocks; getCurrentTitleUsage(&bytes, &blocks); @@ -1343,7 +1346,7 @@ namespace ipl { titleIds[*titleCount] = mpNandTitleInfo[index].curTitleId; wchar_t* titleName = System::getChannelManager()->getTitleName( page, channelIndex, 0); - memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + memcpy(titleNames[*titleCount], titleName, sizeof(*titleNames)); ++*titleCount; if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { @@ -1361,7 +1364,7 @@ namespace ipl { bool SDChannelSelect::collectTitlesFromNandUsage( s32* firstUsage, s32* secondUsage, - ESTitleId* titleIds, char* titleNames, u32* titleCount) { + ESTitleId* titleIds, wchar_t (*titleNames)[21], u32* titleCount) { s32 bytes; s32 blocks; getCurrentTitleUsage(&bytes, &blocks); @@ -1384,7 +1387,7 @@ namespace ipl { titleIds[*titleCount] = mpNandTitleInfo[index].curTitleId; wchar_t* titleName = System::getChannelManager()->getTitleName( page, channelIndex, 0); - memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + memcpy(titleNames[*titleCount], titleName, sizeof(*titleNames)); ++*titleCount; if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { @@ -1400,7 +1403,7 @@ namespace ipl { bool SDChannelSelect::collectTitlesByChannelOrder( s32* firstUsage, s32* secondUsage, ESTitleId* titleIds, - char* titleNames, u32* titleCount) { + wchar_t (*titleNames)[21], u32* titleCount) { static const int channelOrder[MAX_CHANNEL_INDEX] = { 11, 7, 3, 10, 6, 2, 9, 5, 1, 8, 4, 0, }; @@ -1427,7 +1430,7 @@ namespace ipl { titleIds[*titleCount] = mpNandTitleInfo[usageIndex].curTitleId; wchar_t* titleName = System::getChannelManager()->getTitleName(page, channelOrder[order], 0); - memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + memcpy(titleNames[*titleCount], titleName, sizeof(*titleNames)); ++*titleCount; if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { @@ -1445,7 +1448,7 @@ namespace ipl { bool SDChannelSelect::collectTitlesBySpecialChannels( s32* firstUsage, s32* secondUsage, ESTitleId* titleIds, - char* titleNames, u32* titleCount) { + wchar_t (*titleNames)[21], u32* titleCount) { s32 bytes; s32 blocks; getCurrentTitleUsage(&bytes, &blocks); @@ -1502,7 +1505,7 @@ namespace ipl { titleIds[*titleCount] = mpNandTitleInfo[usageIndex].curTitleId; wchar_t* titleName = System::getChannelManager()->getTitleName( page, channelIndex, 0); - memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + memcpy(titleNames[*titleCount], titleName, sizeof(*titleNames)); ++*titleCount; if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { @@ -1528,7 +1531,7 @@ namespace ipl { titleIds[*titleCount] = mpNandTitleInfo[usageIndex].curTitleId; wchar_t* titleName = System::getChannelManager()->getTitleName( page, channelIndex, 0); - memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + memcpy(titleNames[*titleCount], titleName, sizeof(*titleNames)); ++*titleCount; if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { @@ -1544,7 +1547,7 @@ namespace ipl { wchar_t* titleName = System::getChannelManager()->getTitleName( hadePage, hadeChannelIndex, 0); - memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + memcpy(titleNames[*titleCount], titleName, sizeof(*titleNames)); ++*titleCount; if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { @@ -1559,7 +1562,7 @@ namespace ipl { wchar_t* titleName = System::getChannelManager()->getTitleName( hatePage, hateChannelIndex, 0); - memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a); + memcpy(titleNames[*titleCount], titleName, sizeof(*titleNames)); ++*titleCount; if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) { @@ -1575,7 +1578,7 @@ namespace ipl { bool SDChannelSelect::collectTitlesForMode( s32* requiredBytes, s32* requiredBlocks, - ESTitleId* titleIds, char* titleNames, u32* titleCount, int searchMode) { + ESTitleId* titleIds, wchar_t (*titleNames)[21], u32* titleCount, int searchMode) { switch (searchMode) { case 0: return collectTitlesBySpecialChannels( diff --git a/src/scene/sdChannelTitle/iplSDChannelTitle.cpp b/src/scene/sdChannelTitle/iplSDChannelTitle.cpp index a878e281..e90e7e74 100644 --- a/src/scene/sdChannelTitle/iplSDChannelTitle.cpp +++ b/src/scene/sdChannelTitle/iplSDChannelTitle.cpp @@ -83,7 +83,6 @@ extern "C" void iplSDChannelTitle_setPageAndIndex(SDChannelTitle* scene, int pag extern "C" void iplSDChannelTitle_cleanupAndLeave(SDChannelTitle* scene); extern "C" void iplSDChannelTitle_confirmLeaveToSettings(SDChannelTitle* scene, bool settings); extern "C" void iplSDChannelTitle_flushSaveBeforeExit(SDChannelTitle* scene, int nextScene); -extern "C" SDMemory::TitleRange* iplSDChannelTitle_copyTitleRange(SDMemory::TitleRange*, const SDMemory::TitleRange*); static inline void setMemoryTitleLists(SDMemory* memory, SDMemory::TitleRange sdRange, SDMemory::TitleRange nandRange) { @@ -764,9 +763,9 @@ extern "C" void iplSDChannelTitle_updateCopyPrepare(SDChannelTitle* scene) { if (static_cast(scene->mTitleRange.mByteSize) < 0x3800000) { nandRange.mByteSize = 0x3800000; nandRange.mCount = scene->mTitleRange.mCount; - iplSDChannelTitle_copyTitleRange(&sdRange, &scene->mTitleRange); + sdRange = scene->mTitleRange; } else { - iplSDChannelTitle_copyTitleRange(&nandRange, iplSDChannelTitle_copyTitleRange(&sdRange, &scene->mTitleRange)); + nandRange = sdRange = scene->mTitleRange; } SDMemory* memory = &scene->mMemory; setMemoryTitleLists(memory, sdRange, nandRange); @@ -788,14 +787,6 @@ extern "C" void iplSDChannelTitle_updateCopyPrepare(SDChannelTitle* scene) { } } -extern "C" SDMemory::TitleRange* iplSDChannelTitle_copyTitleRange( - SDMemory::TitleRange* target, const SDMemory::TitleRange* source) { - s32 bytes = source->mByteSize; - target->mCount = source->mCount; - target->mByteSize = bytes; - return target; -} - extern "C" void iplSDChannelTitle_updateMemoryCalc(SDChannelTitle* scene) { if (!scene->mMemory.calc()) { return; diff --git a/tools/decomp-assist/o2-cardseq-sdmem.attempts.md b/tools/decomp-assist/o2-cardseq-sdmem.attempts.md new file mode 100644 index 00000000..c98c45c4 --- /dev/null +++ b/tools/decomp-assist/o2-cardseq-sdmem.attempts.md @@ -0,0 +1,110 @@ +# o2-cardseq-sdmem attempts + +Branch `agent/w1009/o2-cardseq-sdmem` from `20cf9f9f`. + +## iplSDMemory: SDMemory::drawTransferTitles (50 -> 0), unit linked + +Start: 50/451 differing, register-only. Earlier Opus run (data-d9 `9b634499`) had brought it +363 -> 50 with the MSL `wcsstr` overload and `TextBox::SetTextColor`. + +### Diagnosis with mwdbg + regsim + +Target vs ours, GPRs only: + +- alpha r31 / string-pool base r30 / bodyPane, titleSizePane r29; ours r29 / r31 / r30. +- line loop: lineCount r22, totalLines r23, `L"\n"` r24, messageLine r26, messageText r27, + lineIndex r28; ours r19 / r19 / r23 / r20 / r26 / r24. + +The capture shows vreg numbering = `this`, named locals (reverse declaration order), frontend +temps (reverse creation order), then codegen vregs (string base r70 first). Coloring is reverse +simplify order and picks the lowest free register, requesting saved registers from r31 down. +Replaying the capture with relabelled vregs (`/tmp` wrapper around `regsim.simulate/color`) +reproduced the whole target when: + +1. alpha lives in a codegen vreg created after the string base (any number 71..150), +2. totalLines sits between the third wcsstr's `s2` temp (v62) and lineEnd (v106/107), +3. row and visibleRows are numbered below every line-loop local, +4. messageText is numbered above lineIndex. + +### Source changes that produce it + +1. `nw4r::lyt::Pane::GetAlpha()` is `const` in real NW4R. With the const member the inline's + result is a codegen value, not a frontend temp, and alpha moves above the string base. + (An explicit `static_cast` around the call did the same; the const accessor is the real + declaration, so that is what landed.) 50 -> 20. +2. `visibleRows` / `row` declared in the title loop body (`s32 visibleRows = ...; for (s32 row = 0; ...)`). 20 -> 18. +3. `messageText` declared before `lineIndex`. With 2: 13. +4. No `totalLines` local: `for (lineIndex = 0; lineIndex < lineCount + 1; ++lineIndex)`. + With 1-3: 0 differing. + +Types of alpha tried first (u32, s32, int, u16): no change; s8/char: worse. A named +`memoPane` local: no change. + +### Linking the unit (Matching flip) + +Flipping the unit failed to link: the source called six SDChannelSelect members through +`extern "C" iplSDChannelSelect_813D....` placeholders. A temporary link with the existing +mangled names linked but changed the DOL: one weak function survived dedup, +`SDMemory::TitleRange::operator=`, because SDChannelTitle hand-wrote the same compiler-generated +function as `extern "C" iplSDChannelTitle_copyTitleRange`. Fixes (all byte-identical where noted): + +- SDChannelTitle: `sdRange = scene->mTitleRange;` / `nandRange = sdRange = scene->mTitleRange;` + instead of the hand-written copy; symbols.txt names 0x813E6FA0 + `__as__Q43ipl5scene8SDMemory10TitleRangeFRCQ43ipl5scene8SDMemory10TitleRange` (scope:weak). + The compiler emits it at the same place. Unit stays 69/69. +- SDChannelSelect, real parameter types from the command dispatch and NandSDWorker: + `enqueueMoveNotice(ESTitleId)` (type 6 -> copy_nand_app_to_sd_async), `enqueueDeleteNotice(ESTitleId)` + (type 13), `enqueueErrorNotice(TitleIdList*, TitleIdList*)` (type 11 -> check_backup_fits_async), + `enqueueCommandNotice(TitleIdList* x3)` (type 12; the worker casts paramA-C to TitleIdList*), + collect* `titleNames` as `wchar_t (*)[21]`. Object bytes identical, only symbol names change + (symbols.txt updated for the nine functions). `friend class SDMemory;` for the private members. +- SDMemory: `TitleListState` was three `NandSDWorker::TitleIdList`s; it is now + `mTitleList / mNandTitleList / mSDTitleList`, and the calls are member calls. Still 66/66. + +Full build: DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d with iplSDMemory Matching. +gate.py (SDMemory, SDChannelSelect, SDChannelTitle) --quick: 0 regressions, GATE PASS. + +## iplCardSequence: loadCardFileIcons (213 -> 135, equal size) + +Kept (all functions of the unit otherwise unchanged, pool identical): + +- Format-3 palette left uninitialized (lever 10). Asm proof: in the target icon loop r6 is + paletteSize; its only writes are `li r6,0x400` (case 1), `li r6,0x800` (case 2) and `li r6,0` + (case 0). Case 3 branches (`cmpwi r4,3; bge`) straight to the iconOffset update that reads r6 + (`add r22,r6,r22` / `add r21,r6,r21`) and `add r7,r7,r6`; no instruction writes r6 between + function entry and the loop. Case 0 sets paletteSize to 0 itself. 213 -> 387 (511 insns) with + the array form, -> 192 (512/512) with the existing `u8* iconPalette` pointer form. +- Image read as `static inline s32 readCardImages(...)`: the target's CARDRead failure is + `bge +8; b ` into the shared `if (result < 0)` test, the shape of an inlined early + `return` (a goto folds to `blt`, a top-level return branches to the epilogue). +- Comment read as `static inline s32 readCardComment(...)`: with only the image helper the two + sector-size slots swapped (0x8/0xC); as a second inline its `sectorSize` gets 0x8 again, and + its early `return 0` / final `return result` give the target's comment flow. +- Banner/icon setup + image read as `loadCardIconImages(...)`, and the block base/offset split + as `getCardBlockAddress(address, &offset)`: 231 -> 135, slot/fileNo/dir get r24/r25/r26. + +Allocator analysis (mwdbg + regsim, a want-map derived by aligning backend-01/04 PCode with the +target): remaining diffs are register-only. Target colors iconAddressBase r31, then the four +CSE multipliers (fileNo*64 r30, slot*8128 r29, fileNo*4 r28, slot*508 r27), dir r26, fileNo r25, +slot r24, iconAddressOffset r23; comment base r23 / offset r21 / readSize r22 / result r29. +In the current capture iconAddressOffset sits in the last simplify scan (colored first, r31) +and iconAddressBase leaves one scan earlier; no numbering of the existing temps fixes both. + +### loadCardFileIcons 135 -> 126 + +- NONE case as `u8* previous = &...iconFmt[iconCount - 1]; ...iconFmt[iconCount] = *previous;`: + gives the target's `add; lwz; addis; subi; add; lbz -1(p); stb 0(p)` shape (134). The array + form and `p[-1]` forms keep the -0x6fb4 in the displacement instead. +- Animation setup written in place with the icon loop's own `iconCount`/`shift`/`icon`, initialized + `shift, iconCount, hasTlut, iconImageSize` in that order, early exit by `goto animationDone`. + PCode value numbering reuses the first `li 0` of the block for the two zero stores; the target + reuses the animation shift (r3), which only happens when shift is the first zero in that block. + With the old helper the stores reused hasTlut. Anim region instruction order now matches. +- Block base as the common subexpression `iconAddress & 0xFFFFFE00` (IRO CSE temp, numbered just + above the CSE multipliers, as the simulator requires); offset `iconAddress - (iconAddress & ~0x1FF)`. + Base, params and the four multipliers now get the target registers (126). + +Tooling: private mwdbg copy on gdb port 9137 (/tmp/o2-cardseq-sdmem-mwdbg, retrowin32 rebuilt with +the port patched) because the shared port queue timed out; IRO log via the known 2-byte patch of a +/tmp copy of GC/3.0a5.2 (diagnosis only). Remaining in the simulator: transferSize must be numbered +below the image offset, the comment base/offset/readSize above every other temp, result low. -- 2.49.1