From 3aa9daf94af1cc73396ededb99c9536eef8467b4 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 2 Oct 2026 17:22:10 -0500 Subject: [PATCH 1/4] decomp: emission gates for iplSDChannelTitle + MemoryCardManager decodes (#972) IPL_SD_CHANNEL_TITLE_CPP gates move inline members to declarations so the TU emits non-inlined calls like retail (same dedup-loss pattern as #834's vtable restoration): iplInterporation::get, math::VEC3 ctor, FaderSceneBase::initCalcNormal/calcCommonAfter, SceneBase::isReady/ isResetProcessDone/getParent/getChild/getNext/getPrev, NANDTask:: isFinished/checkData, Graphics::setOrthoTrans/setOrthoScale, ut::Rect/RuntimeTypeInfo. Verified vs main: iplSDChannelTitle 68/69 fns byte-exact (152B tail residual in iplSDChannelTitle_flushSaveBeforeExit), iplMemoryCardManager 18/26. Units stay NonMatching; documented walls in revisit.attempts.md. Co-authored-by: devin Co-authored-by: coah80 --- include/math/iplInterporation.h | 4 + include/math/iplMathTypes.h | 2 +- include/scene/iplFaderSceneBase.h | 8 ++ include/scene/iplSceneBase.h | 15 ++ include/system/iplNand.h | 5 + include/utility/iplGraphics.h | 5 + libs/NW4R/include/nw4r/ut/Rect.h | 4 +- libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h | 2 +- src/scene/memoryCard/iplMemoryCardManager.cpp | 5 +- .../sdChannelTitle/iplSDChannelTitle.cpp | 14 +- tools/decomp-assist/revisit.attempts.md | 130 ++++++++++++++++++ 11 files changed, 176 insertions(+), 18 deletions(-) create mode 100644 tools/decomp-assist/revisit.attempts.md diff --git a/include/math/iplInterporation.h b/include/math/iplInterporation.h index f19128bd..558a0a3f 100644 --- a/include/math/iplInterporation.h +++ b/include/math/iplInterporation.h @@ -163,6 +163,9 @@ namespace ipl { void init(const f32& start, const f32& end, f32 maxFrame, f32 startTangent, f32 endTangent, int playback = ANIM_TYPE_FORWARD, f32 speed = 1.0f); +#ifdef IPL_SD_CHANNEL_TITLE_CPP + f32 get() const; +#else f32 get() const { f32 var_f27 = mFrame; f32 var_f28 = 1.0f / mMaxFrame; @@ -181,6 +184,7 @@ namespace ipl { return r; } +#endif protected: f32 mStart; diff --git a/include/math/iplMathTypes.h b/include/math/iplMathTypes.h index fe2ea912..a9dadb38 100644 --- a/include/math/iplMathTypes.h +++ b/include/math/iplMathTypes.h @@ -103,7 +103,7 @@ namespace ipl { y = r.y; z = 0.0f; } -#if defined(IPL_ADDRESS_EDIT_CPP) || defined(IPL_SD_CHANNEL_SELECT_CPP) || defined(IPL_GC_WINDOW_CPP) +#if defined(IPL_ADDRESS_EDIT_CPP) || defined(IPL_SD_CHANNEL_SELECT_CPP) || defined(IPL_GC_WINDOW_CPP) || defined(IPL_SD_CHANNEL_TITLE_CPP) VEC3(f32 fx, f32 fy, f32 fz); #else VEC3(f32 fx, f32 fy, f32 fz) { diff --git a/include/scene/iplFaderSceneBase.h b/include/scene/iplFaderSceneBase.h index d841c0a7..65fc9338 100644 --- a/include/scene/iplFaderSceneBase.h +++ b/include/scene/iplFaderSceneBase.h @@ -31,8 +31,12 @@ namespace ipl { virtual void calc(); +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual void initCalcNormal(); +#else virtual void initCalcNormal() { } // 0x4C +#endif virtual void initCalcFadeout() { } // 0x50 @@ -49,8 +53,12 @@ namespace ipl { return FADER_SCN_NEXT; } // 0x60 +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual void calcCommonAfter(); +#else virtual void calcCommonAfter() { } // 0x64 +#endif int getSceneFadeState() { return mScnFadeState; diff --git a/include/scene/iplSceneBase.h b/include/scene/iplSceneBase.h index 05ca1e5e..37cd9919 100644 --- a/include/scene/iplSceneBase.h +++ b/include/scene/iplSceneBase.h @@ -62,7 +62,11 @@ namespace ipl { virtual ~Base(); /** @brief If the scene is ready */ +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual BOOL isReady() const; +#else virtual BOOL isReady() const { return FALSE; } +#endif /** @brief If the user can power off/reset the system */ #ifdef IPL_SD_CHANNEL_TITLE_CPP @@ -73,7 +77,11 @@ namespace ipl { /** @brief The scene running code when powering off/resetting the system */ virtual void startResetting() {} /** @brief If the scene has finished its powering off/resetting task */ +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual BOOL isResetProcessDone(); +#else virtual BOOL isResetProcessDone() { return TRUE; } +#endif /** @brief Prepare to create scene */ virtual void prepare() {} @@ -86,10 +94,17 @@ namespace ipl { /** @brief Destroy the scene and clear from memory */ virtual void destroy() {} +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual Base* getParent(); + virtual Base* getChild(); + virtual Base* getNext(); + virtual Base* getPrev(); +#else virtual Base* getParent() { return (Base*)mpParent; } virtual Base* getChild() { return (Base*)mpChild; } virtual Base* getNext() { return (Base*)mpNext; } virtual Base* getPrev() { return (Base*)mpPrev; } +#endif /** @brief Check if scene has been created.*/ bool isSceneCreated() const { return (mScnState & SCN_STATE_CREATED); } diff --git a/include/system/iplNand.h b/include/system/iplNand.h index ea0dc137..d18ce526 100644 --- a/include/system/iplNand.h +++ b/include/system/iplNand.h @@ -65,8 +65,13 @@ namespace ipl { /** @brief Writes the file contents. */ virtual void write(); // 0x10 +#ifdef IPL_SD_CHANNEL_TITLE_CPP + virtual bool isFinished(); + virtual int checkData(); +#else virtual bool isFinished() { return mbDoneTask; } // 0x14 virtual int checkData() { return mResult; } // 0x18 +#endif virtual bool isFatalError(); // 0x1C u8* getBuffer() const { return mpBuffer; } diff --git a/include/utility/iplGraphics.h b/include/utility/iplGraphics.h index d2d26131..9cadb0d8 100644 --- a/include/utility/iplGraphics.h +++ b/include/utility/iplGraphics.h @@ -51,12 +51,17 @@ namespace ipl { mArg.mOrthoScale = scale; } +#ifdef IPL_SD_CHANNEL_TITLE_CPP + static void setOrthoTrans(const math::VEC3& translate); + static void setOrthoScale(const math::VEC2& scale); +#else static void setOrthoTrans(const math::VEC3& translate) { mArg.mOrthoTrans = translate; } static void setOrthoScale(const math::VEC2& scale) NO_INLINE { mArg.mOrthoScale.x = scale.x; mArg.mOrthoScale.y = scale.y; } +#endif private: static Arg mArg; diff --git a/libs/NW4R/include/nw4r/ut/Rect.h b/libs/NW4R/include/nw4r/ut/Rect.h index cf3c7b66..5332a4e1 100644 --- a/libs/NW4R/include/nw4r/ut/Rect.h +++ b/libs/NW4R/include/nw4r/ut/Rect.h @@ -9,7 +9,7 @@ namespace nw4r { namespace ut { class Rect { public: -#ifdef IPL_SOUND_RECT_OUT_OF_LINE +#if defined(IPL_SOUND_RECT_OUT_OF_LINE) || defined(IPL_SD_CHANNEL_TITLE_CPP) Rect(); #else Rect() : left(), top(), right(), bottom() {} @@ -20,7 +20,7 @@ namespace nw4r { Rect(f32 l, f32 t, f32 r, f32 b) : left(l), top(t), right(r), bottom(b) {} #endif -#if !defined(IPL_CONTROLLER_TRIVIAL_RECT_DTOR) && !defined(IPL_MEMORYCARD_BASE_CPP) +#if !defined(IPL_CONTROLLER_TRIVIAL_RECT_DTOR) && !defined(IPL_MEMORYCARD_BASE_CPP) && !defined(IPL_SD_CHANNEL_TITLE_CPP) ~Rect() {} #endif diff --git a/libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h b/libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h index 74b85650..25e83a47 100644 --- a/libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h +++ b/libs/NW4R/include/nw4r/ut/RuntimeTypeInfo.h @@ -37,7 +37,7 @@ namespace nw4r { } // namespace detail template -#if defined(IPL_BOARD_OBJECT_EXTERNAL_DYNAMIC_CAST) || defined(IPL_MEMORYCARD_BASE_CPP) +#if defined(IPL_BOARD_OBJECT_EXTERNAL_DYNAMIC_CAST) || defined(IPL_MEMORYCARD_BASE_CPP) || defined(IPL_SD_CHANNEL_TITLE_CPP) TDerived DynamicCast(TBase* pPtr); #else inline TDerived DynamicCast(TBase* pPtr) { diff --git a/src/scene/memoryCard/iplMemoryCardManager.cpp b/src/scene/memoryCard/iplMemoryCardManager.cpp index 5b74505d..f07c4fa7 100644 --- a/src/scene/memoryCard/iplMemoryCardManager.cpp +++ b/src/scene/memoryCard/iplMemoryCardManager.cpp @@ -237,10 +237,7 @@ bool MemoryCardManager::isIconValidate(u8 slot, s16 index) { bool MemoryCardManager::isBannerEnable(u8 slot, s16 index) { CardIcons* icons = reinterpret_cast(memorycard::getIconStateArray()); - u32 file = mFile[slot][index].fileNo; - memorycard::IconState* icon = &icons[slot][file]; - u8 enabled = icon->bannerEnable; - return enabled != 0; + return icons[slot][mFile[slot][index].fileNo].bannerEnable != 0; } void MemoryCardManager::update_icon_anm() { diff --git a/src/scene/sdChannelTitle/iplSDChannelTitle.cpp b/src/scene/sdChannelTitle/iplSDChannelTitle.cpp index 1a7dc893..12e54e22 100644 --- a/src/scene/sdChannelTitle/iplSDChannelTitle.cpp +++ b/src/scene/sdChannelTitle/iplSDChannelTitle.cpp @@ -3,6 +3,10 @@ #define IPL_SDMEMORY_DIALOG_STATE_ACCESSOR #define IPL_SDMEMORY_COMPLETION_PCT_ACCESSOR +#define IPL_CHANNEL_TITLE_NOVTABLE +#include "math/iplInterporation.h" +#undef IPL_CHANNEL_TITLE_NOVTABLE + #include "scene/sdChannelTitle/iplSDChannelTitle.h" #include "scene/sdChannelSelect/iplSDChannelSelect.h" #include "system/iplSystem.h" @@ -1554,15 +1558,5 @@ void SDChannelTitle::startResetting() { snd::getSystem()->resetAllSound(); } -extern "C" void iplSDChannelTitle_onTitleButtonEvent(SDTitleButtonEventHandler* handler, u32 component, - u32 event, const controller::Interface* controller) { - handler->onEventDerived(component, event, controller); -} - -extern "C" void iplSDChannelTitle_onTitlePaneEvent(SDTitlePaneEventHandler* handler, u32 component, - u32 event, const controller::Interface* controller) { - handler->onEvent(component, event, const_cast(controller)); -} - } } diff --git a/tools/decomp-assist/revisit.attempts.md b/tools/decomp-assist/revisit.attempts.md new file mode 100644 index 00000000..e30e4701 --- /dev/null +++ b/tools/decomp-assist/revisit.attempts.md @@ -0,0 +1,130 @@ +# revisit leaf — second-pass evidence (agent/w1007/revisit @ origin/main 29fe1efa) + +Scope: iplSDChannelTitle (99.98883), ut_ArchiveFontBase (98.52), lyt_window (99.76), +iplMemoryCardManager (97.88). Post-#834 (linkgap emit gates + .data object names). + +## iplSDChannelTitle — all gates landed + +Per-TU `IPL_SD_CHANNEL_TITLE_CPP` declared-only gates applied to: +RuntimeTypeInfo.h DynamicCast, iplMathTypes.h VEC3 3-arg ctor, GUIManager.h +(EventHandler setManager/setLatestEventCtrlNo/getLatestEventCtrlNo, +Component setTriggerTarget, PaneComponent setPane/getPane), iplGraphics.h +setOrthoTrans/setOrthoScale, iplSceneBase.h isReady/isResetProcessDone/getParent/ +getChild/getNext/getPrev, iplFaderSceneBase.h initCalcNormal/calcCommonAfter, +iplNand.h File::isFinished/checkData, iplInterporation.h HermiteIntp::get +(nested under IPL_CHANNEL_TITLE_NOVTABLE spec), Rect.h 0-arg ctor +(IPL_SOUND_RECT_OUT_OF_LINE gate), iplGuiManager.h ~PaneManager. +Deleted 2 unreferenced extern "C" trampolines (onTitleButtonEvent/onTitlePaneEvent) +orig lacks. Result: all data sections 100%; .text 99.98883. + +### VERIFIED WALL — dtor emission policy (decl-immune) +Residual .text gap = 2 unreferenced weak deleting-dtor bodies +(~FaderSceneBase 88B + ~FrameController 64B) + ~5 dangling no-reloc UNDs +(__vt__LangFile, __vt__SDButtonEventHandlerBase, __vt__FrameController, +mArg/typeInfo syms — symtab noise, no relocs). Orig's TU had these dtors +trivial/implicit: ~SDChannelTitle calls ~Base directly (28 insns), Rect +temporaries carry no dtor calls, so correct forms are `virtual ~X() {}` +inline or NO decl at all. Declaring them out-of-line adds real `bl` calls → +fuzzy dropped 99.98883→99.55799. Implicit/non-virtual variants still emit the +weak bodies AND slightly regress — front-end-level MWCC instantiation drag, +no decl form eliminates it. Remaining fn wall: flushSaveBeforeExit 98.59 — +&smArg materialization register choice (orig r3→scratch r4, mine r4/r5→recv-first); +8+ source forms all shift the home, never to r3. + +## ut_ArchiveFontBase — ConstructOpAnalyzeGLGR 92.09 (956B) + +20 normalized diffs, insns 116-147 of 239 — issue-order inside the +ready-set around the CalcOffsetSheetFlags/CalcSizeFlagSet scratch math. +Orig hoists lhz 0x1c (sheetGlyphCount) / lhz 0x24 (sheetCount) / lhz 0xe +(dataBlockCount) + lwz 0x4c(r20) into the marshal block. +FAILED variants: decl-order swap of the three u16s (identical 20 diffs — +scheduler ignores decl order); moving ctx->m* tail stores adjacent to the +u16 loads (regressed 20→108, whole-web rotation). Conclusion: pure list- +scheduling tie, same family as before. + +## lyt_window — DrawFrame 98.18 (1504B) + +376=376 insns. One callee-window permutation: orig numbers the static +flipInfos[] array base early (r21, first materialized at insn 36) pushing +arg webs to r27-r31; mine puts it deepest (r31), args r26-r30. Same web +count (12 callee webs r20-r31 both), identical prologue/epilogue; only the +allocator's numbering differs. Plus a repeated stfsx/fadds store-weave in +the 4 DRAW_QUAD_FOR_FRAME_1 corner blocks. +FAILED variants: scoping polPt/polSize inside the macro (385 insns, +worse); moving texSize decl after polPt/polSize (372 insns, worse). +NOTE: paired-single ops — capstone can't decode psq_*/ps_* insns, so +ndiff.py/disasm_fn.py truncate at the first one; use raw-word diffs. + +## iplMemoryCardManager — 8 sub-100 fns all decomposed + +- isMoveEnable/isCopyEnable (99.83), update_file_array (99.72), + getComment (98.94): 0 normalized diffs — pure regname webs. +- isBannerEnable (92.31, 26 insns, 7 diffs) + getBlocks (92.0, 25 insns, + 6 diffs): single diff = `addi r11,r1,0x20` restgpr-setup placement — + orig emits it at tail (after the full member-chain load), mine hoists + to slot 11. Folded-return variant (`return icons[slot][mFile..]` no + locals) emits identical code — scheduler-internal, decl-form insensitive. + Folded form kept (same output, terser). +- _create_icon (87.55) + create_banner (90.42): `(base+const)+var` + member-chain regroup — orig computes (&mFileCell + memberOffs) + + (slot*row + file*0x15C combined index) with `this+0x10EC`/`this+0x110C` + bases cached in callee regs reused across both GX_TF branches, and + rematerializes &cell.icon per call (`add r3,...` then `add r24,...` + post-bl) while mine pins it; marshal order `li r4,0` before `mr r3` + in orig. FAILED variants: `MCFileCell* cell = &mFileCell[slot][file]` + (90 insns — MWCC folded the pointer, worse); `mFileCell[0] + + slot*0x7F + file` flat-index (89 insns — aggressive CSE, worse). + Same documented mcard2 wall. + +All units stay NonMatching — no shims, no flips. Every residual is a +verified allocator/scheduler/emission-policy tie with source-form evidence. + +## Round 2 (post-#834 rebase @11c75ddb) — sdChannelTitle emit-parity probe + +Investigated per orchestrator hint whether the 152B weak-dtor + dangling-UND +residual was the same dedup-loss family as channelTitle's symbols.txt fix. +VERDICT: NOT a naming issue and NOT a flip blocker. + +- orig iplSDChannelTitle.o: ZERO weak FUNC syms. Mine emits 2 unreferenced + weak deleting-dtor bodies: `__dt__FaderSceneBase` (88B @0x1f4) + + `__dt__FrameController` (64B @0xb30), plus 3 zero-reloc UND vtable refs + (`__vt__FrameController`, `__vt__SDButtonEventHandlerBase`, `__vt__LangFile`). +- orig iplFaderSceneBase.o's own view: `~FaderSceneBase` is DECLARED-ONLY + (its `__dt__` is UND there, defined in another TU). +- Tried `__declspec(novtable)` on all 4 classes under + IPL_SD_CHANNEL_TITLE_CPP: removed the 3 dangling `__vt__` UNDs (correct + mechanism — orig stores only most-derived vt) but weak bodies persisted. +- Tried implicit-trivial dtor (removing decl): `__dt__FrameController` emit + STOPPED (64B gone), but `calc()` vtable slot shifted 0x0c→0x08 → + calcFadein/calcFadeout single-word diffs (`lwz r12,0x0c(r12)` vs 0x08) + → REVERTED everything. +- CRITICAL PROOF these bodies are harmless: main's iplChannelTitle.o + (unit fuzzy 100.0 post-#834) emits the IDENTICAL `__dt__FaderSceneBase` + 88B + `__dt__FrameController` 64B weak bodies that orig's .o lacks. + They are linker-stripped dead emission; objdiff fn-pairing ignores them. + => The 152B was never the blocker. Real residual = flushSaveBeforeExit + 98.59 only. + +## flushSaveBeforeExit — 6-diff → 2-diff minimum + +Window is the `sm` (System globals) base web: orig binds &sm to r3 and +loads +0x94→r4 (store), +0x28→r4 (heap arg), +0x94→r3 (recv); mine binds +r4 and marshals recv before arg. Variants: +- saveHeap decl hoisted above getSDPrevPage store: 2 diffs (base→r5, + +0x28 load moved early) — closer but not orig's order. +- `flushAsync(System::getMem2App())` inline: same 2 diffs, base→r4. +Residual = base-web home + marshal eval order — allocator tie. + +## GLGR — ready-set issue-order re-probes + +- def-move (sheetGlyphCount/dataBlockCount to tail): 20→99 diffs, REGRESSION. +- `u32 remWorkSpace = ctx->remWorkSpace()` hoist: 20→25, REGRESSION. +- stepSheetFlags after flagsSheetsOff (dependency-chain reorder): identical + 20 diffs — MWCC issue-order insensitive to stmt order here. Wall stands. + +## DrawFrame / MCManager re-verified + +DrawFrame 376=376: flipInfos base pinned r21(orig)/r31(mine) + stfsx weave +— callee-numbering tie unchanged. create_banner/_create_icon: `(base+const) ++var` regroup + recompute-vs-CSE (`add r3,r29,r25` remat per call in orig) +— same documented wall. -- 2.49.1 From 79f512d7dd614b07530005581163f38f05b24d8f Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 2 Oct 2026 17:26:33 -0500 Subject: [PATCH 2/4] decomp: recover ESMisc ticket scratch lifetime and cleanup flow --- src/utility/iplESMisc.cpp | 65 +++++++++-------- .../allhands-system-decompile.attempts.md | 70 +++++++++++++++++++ 2 files changed, 106 insertions(+), 29 deletions(-) diff --git a/src/utility/iplESMisc.cpp b/src/utility/iplESMisc.cpp index 0011ab12..dddcc28d 100644 --- a/src/utility/iplESMisc.cpp +++ b/src/utility/iplESMisc.cpp @@ -978,33 +978,37 @@ namespace ipl { ESMisc::ChangeUid(SYSMENU_TITLE_ID); } - static inline void DeleteTicketsForce(EGG::Heap* heap, ESTitleId titleId, u8* ticketViews, u32* ticketViewCount) { + static inline s32 DeleteTicketsForce(EGG::Heap* heap, ESTitleId titleId, u8* ticketViews, u32* ticketViewCount) { ESTicketView* ticketViewList = NULL; s32 ret; memset(ticketViews, 0, OSRoundUp32B(sizeof(ESTicketView))); ret = ES_GetTicketViews(titleId, NULL, ticketViewCount); if (ret != ES_ERR_OK) { OSReport("%s::%s: ES_GetTicketViews failed: %d for %016llx\n", __FILE__, __FUNCTION__, ret, titleId); - } else if (*ticketViewCount != 0) { - ticketViewList = (ESTicketView*)heap->alloc(*ticketViewCount * OSRoundUp32B(sizeof(ESTicketView)), -DEFAULT_ALIGN); - ret = ES_GetTicketViews(titleId, ticketViewList, ticketViewCount); + goto cleanup; + } + if (*ticketViewCount == 0) { + return ret; + } + ticketViewList = (ESTicketView*)heap->alloc(*ticketViewCount * OSRoundUp32B(sizeof(ESTicketView)), -DEFAULT_ALIGN); + ret = ES_GetTicketViews(titleId, ticketViewList, ticketViewCount); + if (ret != ES_ERR_OK) { + OSReport("%s::%s: ES_GetTicketViews failed: %d for %016llx\n", __FILE__, __FUNCTION__, ret, titleId); + goto cleanup; + } + for (u32 j = 0; j < *ticketViewCount; j++) { + memcpy(ticketViews, (u8*)ticketViewList + j * sizeof(ESTicketView), sizeof(ESTicketView)); + ret = ES_DeleteTicket((ESTicketView*)ticketViews); if (ret != ES_ERR_OK) { - OSReport("%s::%s: ES_GetTicketViews failed: %d for %016llx\n", __FILE__, __FUNCTION__, ret, titleId); - } else { - for (u32 j = 0; j < *ticketViewCount; j++) { - memcpy(ticketViews, (u8*)ticketViewList + j * sizeof(ESTicketView), sizeof(ESTicketView)); - ret = ES_DeleteTicket((ESTicketView*)ticketViews); - if (ret != ES_ERR_OK) { - OSReport("%s::%s: ES_DeleteTicket failed: %d for %016llx\n", __FILE__, __FUNCTION__, ret, - ((ESTicketView*)ticketViews)->ticketId); - } - } + OSReport("%s::%s: ES_DeleteTicket failed: %d for %016llx\n", __FILE__, __FUNCTION__, ret, + ((ESTicketView*)ticketViews)->ticketId); } } - + cleanup: if (ticketViewList != NULL) { heap->free(ticketViewList); } + return ret; } static inline s32 InitSavedata(EGG::Heap* heap) { @@ -1032,20 +1036,23 @@ namespace ipl { goto cleanup; } - for (u32 i = 0; i < titleCount; i++) { - if ((titleIds[i] & 0xFFFFFFFFFFFFFF00ULL) == 0x00010000525A4400ULL) { - verifySavedataZD(heap, titleIds[i], &fileInfo); - continue; - } - switch (titleIds[i]) { - case 0x0001000844495343ULL: - case 0x000100014A4F4449ULL: - case 0x0001000148415858ULL: - case 0x0001000844564458ULL: - case 0x000100084449534BULL: - ES_DeleteTitle(titleIds[i]); - DeleteTicketsForce(heap, titleIds[i], ticketViews, &ticketViewCount); - break; + { + u8* ticketScratch = ticketViews; + for (u32 i = 0; i < titleCount; i++) { + if ((titleIds[i] & 0xFFFFFFFFFFFFFF00ULL) == 0x00010000525A4400ULL) { + verifySavedataZD(heap, titleIds[i], &fileInfo); + continue; + } + switch (titleIds[i]) { + case 0x0001000844495343ULL: + case 0x000100014A4F4449ULL: + case 0x0001000148415858ULL: + case 0x0001000844564458ULL: + case 0x000100084449534BULL: + ES_DeleteTitle(titleIds[i]); + DeleteTicketsForce(heap, titleIds[i], ticketScratch, &ticketViewCount); + break; + } } } diff --git a/tools/decomp-assist/allhands-system-decompile.attempts.md b/tools/decomp-assist/allhands-system-decompile.attempts.md index 3c2cc88c..3685e425 100644 --- a/tools/decomp-assist/allhands-system-decompile.attempts.md +++ b/tools/decomp-assist/allhands-system-decompile.attempts.md @@ -127,3 +127,73 @@ The harness is supplemental behavioral validation, not a retail runtime test. GATE: focused decompilation improvement; full 43U/DOL and no-regression checks pass; exact-matching gate remains incomplete at 30/31. No linking claimed. + +## Follow-on: recover the last ESMisc structural differences + +Baseline for this follow-on is the accepted reconstruction `1f9db89d`: +30/31 exact functions, function 95.830734%, unit 99.33143%, 446/449 instructions, +data 4416/4416. The source/header correction remains intact. + +Natural source attempts, in order: + +| Attempt | Instructions | Function fuzzy | Disposition | +| --- | ---: | ---: | --- | +| Ticket helper uses error-first cleanup and returns early with no tickets | 446/449 | 95.830734% | Same generated code | +| Caller gives aligned ticket scratch an explicit pointer lifetime | 448/449 | 98.004456% | Improved | +| Move aligned ticket scratch into the ticket helper | 446/449 | 95.817375% | Rejected | +| Scope caller's scratch pointer to successful title enumeration | 448/449 | 98.89755% | Retained | +| Restore nested ticket helper with scoped scratch | 448/449 | 98.89755% | Same generated code | +| Ticket helper returns its actual ES operation status | 449/449 | 99.14254% | Retained | + +The scratch pointer is initialized only in the block reached after successful +second enumeration, and remains live across the title loop. This restores the +saved scratch cursor and per-iteration 64-bit mask materialization. No pointer +is used before initialization and no artificial use extends its lifetime. + +The private ticket helper now returns the status already obtained from +ES_GetTicketViews or ES_DeleteTicket, including its zero-ticket early return +and normal cleanup. Its caller intentionally discards that status. The return +contract of an independently emitted original helper cannot be established +because this helper was fully inlined; this is a natural equivalent source +form whose zero-ticket branch structure is confirmed by the target. It does +not overwrite the outer enumeration status or change the public ABI further. + +Final ctxdiff: 449/449 instructions, 74 differences. Every mnemonic, +non-register operand, stack offset, resolved call target and branch target +agrees. The remaining differences are register substitutions, including the +title list, scratch cursor, title index, verifier flags and title halves. No +register/declaration permutation search was performed after reaching this +structural agreement. + +Measurements after a fresh full report: + +- ESMisc exact functions 30/31 -> 30/31 +- ESMisc exact code 9404/11200 -> 9404/11200 +- ESMisc fuzzy 99.33143% -> 99.8625% +- DeleteUnauthorizedData fuzzy 95.830734% -> 99.14254% +- Matched data 4416/4416 -> 4416/4416 +- Pool: all 114 strings identical +- Literal audit: 204 arguments in 30 exact functions, no candidates/errors +- Every other unit's full report is unchanged +- Full 43U build/check and DOL SHA1 pass: + 26116613f624061ba99c8d1a299aaa6efa85670d +- The same 12 ASan/UBSan host control-flow scenarios pass on helper bodies + freshly extracted from this final candidate (LeakSanitizer disabled only + for the environment limitation already noted) +- git diff --check passes + +This remains a partial matching improvement, not an exact function or unit. + +### Rejected ATERM ownership experiment + +Read-only target evidence identified that the old typed reply view spans the +last eight bytes of one BSS object and the following option-buffer allocation. +With parent approval, tried a real two-object protocol-workspace aggregate and +corresponding narrow metadata consolidation. It preserved storage, addresses, +all 17 exact functions and matched data, and reduced the main protocol from +972 to 959 instructions (target 951). However, its unit fuzzy regressed from +96.624664% to 96.49781%; wider grouping and a decoder-helper experiment also +failed the no-regression condition. All ATERM source and symbol metadata were +restored. Fresh report after restoration was identical to the accepted ESMisc +baseline, and the DOL hash passed. Detailed rejected source/metadata and +address evidence were kept privately for future work; none is in this commit. -- 2.49.1 From f9358f6e466d66427c08a982e52e988e4e92613f Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 2 Oct 2026 17:26:43 -0500 Subject: [PATCH 3/4] Decode BS2Mach Run asm + nup dead-static fossil (stays NonMatching) (#973) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * decomp: BS2Mach Run asm + CoverBlock/state decodes; nup dead-static fossil - BS2Mach::Run: retail zeroes r0-r31 and installs a custom stack (__pformatter+640) before the dcbz/dcbf flush loop and tail jump — inexpressible in C, so asm with the exact retail sequence. - BS2StartGCGame: CoverBlock.state direct member read (orig inlined DVDGetCommandBlockStatus accessor). - BS2StateMachine: GamePartition!=0 polarity fold. - nup.cpp __nupOp: 'static u32 lo' dead static reproduces orig's second .sbss word (orig .sbss=8: rvThread$2389 + 4B dead static). Verified vs main: BS2Mach 25/29 fns byte-exact, nup 20/23 + .sbss 8=8. Units stay NonMatching. Full build + DOL sha1 verified. Co-authored-by: coah80 Co-Authored-By: wch * decomp: drop dead 'static u32 lo' padding from __nupOp Per review: the extra .sbss word is a padding object — no relocation references it, and nup data is already exact without it. Left unowned for the linking pass. Co-Authored-By: wch --------- Co-authored-by: devin Co-authored-by: coah80 --- src/BS2/BS2Mach.c | 73 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/src/BS2/BS2Mach.c b/src/BS2/BS2Mach.c index 23832473..3fb4a619 100644 --- a/src/BS2/BS2Mach.c +++ b/src/BS2/BS2Mach.c @@ -242,14 +242,64 @@ BOOL BS2IsDiagDisc() { return (u8)(*(u8 *)OSPhysicalToCached(OS_ADDR_BOOT_INFO) extern vu32 BS2VideoMode; extern vu32 __DVDLayoutFormat; -void Run(u32 entryPoint, void *start, u32 blockCount, u32 argument) { - u8 *block = start; - for (; blockCount != 0; --blockCount) { - __dcbz(block, 0); - __dcbf(block, 0); - block += 32; - } - ((void (*)(u32))entryPoint)(argument); +extern void __pformatter(void); + +asm void Run(u32 entryPoint, void *start, u32 blockCount, u32 argument) { + // clang-format off +#ifdef __MWERKS__ + nofralloc + + mtctr r5 + mtlr r3 + + li r0, 0 + li r2, 0 + li r3, 0 + li r5, 0 + li r7, 0 + li r8, 0 + li r9, 0 + li r10, 0 + li r11, 0 + li r12, 0 + li r13, 0 + li r14, 0 + li r15, 0 + li r16, 0 + li r17, 0 + li r18, 0 + li r19, 0 + li r20, 0 + li r21, 0 + li r22, 0 + li r23, 0 + li r24, 0 + li r25, 0 + li r26, 0 + li r27, 0 + li r28, 0 + li r29, 0 + li r30, 0 + li r31, 0 + + lis r1, __pformatter+640@h + ori r1, r1, (__pformatter+640)@l + li r6, 0 + + b Run_loop_entry +Run_loop: + dcbz r4, r0 + dcbf r4, r0 + addi r4, r4, 0x20 + bdnz Run_loop + b Run_done +Run_done: + li r4, 0 + blr +Run_loop_entry: + b Run_loop +#endif + // clang-format on } BOOL BS2GetLockedTitles(ESTitleId *pTitleIds, u32 *count) { @@ -803,7 +853,7 @@ void BS2StartGCGame() { OSTime time; StartingGame = TRUE; - while (DVDGetCommandBlockStatus(&CoverBlock) != DVD_STATE_IDLE) { + while (CoverBlock.state != DVD_STATE_IDLE) { } soundMode = SCGetSoundMode(); @@ -1796,11 +1846,12 @@ invalidRvlRegion: State = BS2_STT_RESET_SYSTEM; break; } - if (GamePartition == 0) { + if (GamePartition != 0) + State = BS2_STT_37; + else { State = BS2_STT_54; break; } - State = BS2_STT_37; case 0x25: if (BS2BootFromCache != 0) { BS2Report("Open partition from cache.dat\n"); -- 2.49.1 From 6b17698b849ae2d06ad903cede5a103d8c6900d7 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 2 Oct 2026 17:28:16 -0500 Subject: [PATCH 4/4] match(odh): cdj_c_colorConv byte-identical (#974) Pad with a named remainder and declare sourceStride after rowIndex so cbPlane stays r22 and the stride stays r29. decompressLoop is unchanged. --- src/system/odh.cpp | 21 +++++++++------------ tools/decomp-assist/attempts/odh-worker2.md | 8 ++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/system/odh.cpp b/src/system/odh.cpp index 88b202b4..d1e303f0 100644 --- a/src/system/odh.cpp +++ b/src/system/odh.cpp @@ -931,17 +931,15 @@ void CArGBAOdh::cdj_c_makeHeader(SArCDJ_OdhMaster* master, u32 size) { } s32 CArGBAOdh::cdj_c_colorConv(SArCDJ_OdhMaster* master, u8* sourceData, int format) { - u32 paddedWidth; u16 width; u16 height; u8* workPlane; - int sourceStride; - u8* crPlane; u8* cbPlane; + u8* crPlane; u16* dimensions; int rowIndex; + int sourceStride; int i; - u16 dimension; u16 paddedDimensions[2]; dimensions = &master->width; @@ -952,11 +950,11 @@ s32 CArGBAOdh::cdj_c_colorConv(SArCDJ_OdhMaster* master, u8* sourceData, int for height = dimensions[1]; for (i = 0; i < 2; i++) { - dimension = dimensions[i]; - if ((dimension & 7) != 0) { - paddedDimensions[i] = (dimension + 8) - (dimension & 7); + u16 remainder = dimensions[i] & 7; + if (remainder != 0) { + paddedDimensions[i] = (dimensions[i] + 8) - remainder; } else { - paddedDimensions[i] = dimension; + paddedDimensions[i] = dimensions[i]; } } @@ -972,13 +970,12 @@ s32 CArGBAOdh::cdj_c_colorConv(SArCDJ_OdhMaster* master, u8* sourceData, int for } } - paddedWidth = paddedDimensions[0]; for (rowIndex = 0; rowIndex < (s32)height; rowIndex++) { LineConv11(sourceData + (rowIndex & 3) * 8 + rowIndex / 4 * sourceStride, workPlane, cbPlane, crPlane, dimensions[0], dimensions[1], (const long*)gArConvPlttTbl, format); - workPlane += paddedWidth; - cbPlane += paddedWidth; - crPlane += paddedWidth; + workPlane += paddedDimensions[0]; + cbPlane += paddedDimensions[0]; + crPlane += paddedDimensions[0]; } return 0; diff --git a/tools/decomp-assist/attempts/odh-worker2.md b/tools/decomp-assist/attempts/odh-worker2.md index 02fd7389..6e82f332 100644 --- a/tools/decomp-assist/attempts/odh-worker2.md +++ b/tools/decomp-assist/attempts/odh-worker2.md @@ -16,3 +16,11 @@ Claim was only `cdj_d_decompressLoop`. colorConv, huffmanDecoder, and LineConv11 - 2x2 tail stores the updated plane in `requiredBlockEnd` and the end pointer in `planeOffset`. That is what puts the plane in r15 and the end in r16 (`addi r15, r3, -8` / `add r16, r15, r18`). Assigning the plane back to `planeOffset` left those two callee-saves swapped (7 diffs). Splitting the `-8` let MWCC cancel it against the later `+8` and dropped to 897. colorConv left at the 18 pairwise wall. Not in this diff. + +## colorConv (2026-10-02) + +`cdj_c_colorConv` **77/77, 0 diffs, byte-identical** (308 bytes). Was 18, then 13, then 8. + +- Drop `paddedWidth`. The row loop adds `paddedDimensions[0]`, which hoists `lhz r24` and `lis r23` / `addi r10, r23, 0`. +- Pad loop: `u16 remainder = dimensions[i] & 7`, then `(dimensions[i] + 8) - remainder`. Width stays r8, the indexed load stays r7, the mask stays r9. Naming both a dimension and a remainder swaps width off r8. +- Declare `sourceStride` after `rowIndex` (cb/cr stay above it). That assigns stride r29 and `cbPlane` r22. Computing stride before the planes shortens the function to 76 and shifts the callee-saves. huffmanDecoder and LineConv11 were not edited. `cdj_d_decompressLoop` stays 899/899. -- 2.49.1