From ce074d3d001c8848c5c41c7f534f2419ef409f1f Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:02:16 -0500 Subject: [PATCH] decomp(sd): recover scissor projection expressions --- .../sdChannelSelect/iplSDChannelSelect.cpp | 21 +++--- .../sd-selection-scissor-20261003.md | 66 +++++++++++++++++++ 2 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 tools/decomp-assist/sd-selection-scissor-20261003.md diff --git a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp index 199e4c84..eae17629 100644 --- a/src/scene/sdChannelSelect/iplSDChannelSelect.cpp +++ b/src/scene/sdChannelSelect/iplSDChannelSelect.cpp @@ -2719,14 +2719,10 @@ namespace ipl { if (mState == 7 || mState == 12 || mState == 14) { nw4r::math::MTX44 matrix; - f32 rightScale = projection.right / mScale.x; - f32 leftScale = projection.left / mScale.x; - f32 bottomScale = projection.bottom / mScale.y; - f32 topScale = projection.top / mScale.y; - f32 bottom = mPosition.y - bottomScale; - f32 right = mPosition.x + rightScale; - f32 left = mPosition.x + leftScale; - f32 top = mPosition.y - topScale; + f32 right = mPosition.x + projection.right / mScale.x; + f32 left = mPosition.x + projection.left / mScale.x; + f32 bottom = mPosition.y - projection.bottom / mScale.y; + f32 top = mPosition.y - projection.top / mScale.y; MTXOrtho(matrix, top, bottom, left, right, -100.0f, 100.0f); nw4r::math::VEC4 input(position.x, position.y, 0.0f, 1.0f); @@ -2734,14 +2730,13 @@ namespace ipl { nw4r::math::VEC4Transform(&transformed, &matrix, &input); framebufferWidth = renderMode->fbWidth; framebufferHeight = renderMode->efbHeight; - scissorWidth = projection.GetWidth(); + const f32 projectionWidth = projection.GetWidth(); + scissorX = ((1.0f + transformed.x) * framebufferWidth / 2) - + ((mThumbOffsetX * mScale.x) * (framebufferWidth / projectionWidth)); scissorY = (framebufferHeight - ((1.0f + transformed.y) * framebufferHeight / 2)) - (mThumbOffsetY * mScale.y); - f32 widthScale = framebufferWidth / scissorWidth; - scissorX = ((1.0f + transformed.x) * framebufferWidth / 2) - - ((mThumbOffsetX * mScale.x) * widthScale); scissorWidth = 2.0f * (mThumbOffsetX * mScale.x) * - (framebufferWidth / scissorWidth); + (framebufferWidth / projectionWidth); scissorHeight = 2.0f * (mThumbOffsetY * mScale.y); } else { framebufferWidth = renderMode->fbWidth; diff --git a/tools/decomp-assist/sd-selection-scissor-20261003.md b/tools/decomp-assist/sd-selection-scissor-20261003.md new file mode 100644 index 00000000..0215f709 --- /dev/null +++ b/tools/decomp-assist/sd-selection-scissor-20261003.md @@ -0,0 +1,66 @@ +# SD channel scissor reconstruction, 2026-10-03 + +Baseline b9407106. Read AGENTS and the prior SD selection, fz16, scene4, +data-d5, and structural-round attempt records. Only the owned SD selection +source and this evidence file change; no header or linking changes. + +## Retained expression reconstruction + +- Express each orthographic bound directly from position and the projection + quotient, rather than keeping four extra quotient temporaries. +- Keep the input projection width distinct from the output scissor width. +- Calculate transformed X before Y and use the width quotient directly, + removing the one-use widthScale temporary. + +These ordinary expressions also occur in the sibling ChannelSelect routine. +The arithmetic grouping is preserved. The original framebuffer conversion, +projection and transformed-bound sequence is recovered; no register sweep or +allocation directive was used. + +setChannelScissor: 93.4721% -> 99.14163% with separated projection width and +X/Y calculations, then -> 99.5279% with direct orthographic bounds. +233/233 instructions throughout. Fifteen register substitutions remain, +primarily exchanging the X and width values. Unit fuzzy: +99.582596% -> 99.749435%. Exact code stays 29412/33828, functions 122/129, +and data 2960/2960. All other functions and all other units are unchanged. + +collectTitlesBySpecialChannels remains unchanged. The 361/361-instruction +comparison has four repeated count-store/threshold-load schedules, 16 total +instruction differences. Lookup arguments, special-title constants, reverse +NAND and cache traversal, 42-byte names, 64-bit title writes, usage additions, +and threshold exits agree. No new qualifier or forced alias barrier was used. + +## Verification + +- Configured 43U with ../toolchain/wibo-build/wibo +- Full all_source/report/ok build passes +- Pool identical, 101/101 strings +- Literal audit: 73 arguments in 122 reported-exact functions, no skips/errors +- Every reported-exact function is instruction/relocation-identical to the + baseline; 117 also have zero ctxdiff against the original +- Five preexisting reported-exact functions have relocation differences: + constructor and createBaseLayout vtable offsets/binding, draw and + getChannelPanePosition VEC3 constructor family, and four onEvent predicate + calls. The predicate calls test different fields and were reported to the + parent immediately for a separate correction; no claim that all 122 + functions are semantically exact is made +- Every allocated non-code section is byte-identical to the baseline +- Complete report comparison: only setChannelScissor improves; no regression +- DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d +- git diff --check passes + +The native C++ harness uses the extracted before/after function bodies with +local matrix/render-mode shims and captured GX calls. With floating-point +contraction disabled and UBSan/float-cast checks enabled, 250000 finite cases +pass, including all three transformed states, ordinary states, framebuffer +boundaries up to the existing 1705 clip cap, and 219852 fully clipped cases. +All orthographic bounds are bit-identical and all four GX arguments agree. +This checks the local equations and clipping, not the Wii rendering pipeline. +An initial out-of-domain test with 65535-wide framebuffers reproduced an +existing negative-to-unsigned clipping conversion; that domain is excluded +from the equivalence test, not changed in production. + +Local harness: /tmp/sdselection-scissor-test.cpp, executable without .cpp. +GATE: full build, DOL, pool, literal, data/exact preservation, report +nonregression and focused numeric tests pass. Known preexisting relocation +false positives are recorded above and require separate review. -- 2.49.1