From 5a79e0caf9791371cdd1a872ddf971d1bc382423 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Wed, 30 Sep 2026 06:42:54 +0000 Subject: [PATCH] vi3in1, kbd_lib, iplMemoryCardManager: closer non-exact functions (worker 04cfeb7d) --- libs/RVL_SDK/src/kbd/kbd_lib.c | 125 +++++++++--------- libs/RVL_SDK/src/vi/vi3in1.c | 2 +- src/scene/memoryCard/iplMemoryCardManager.cpp | 18 ++- .../iplMemoryCardManager.attempts.md | 66 +++++++++ tools/decomp-assist/kbd_lib.attempts.md | 73 ++++++++++ tools/decomp-assist/vi3in1.attempts.md | 30 +++++ 6 files changed, 247 insertions(+), 67 deletions(-) diff --git a/libs/RVL_SDK/src/kbd/kbd_lib.c b/libs/RVL_SDK/src/kbd/kbd_lib.c index 5e43d176..c4f1f1e9 100644 --- a/libs/RVL_SDK/src/kbd/kbd_lib.c +++ b/libs/RVL_SDK/src/kbd/kbd_lib.c @@ -10,6 +10,15 @@ typedef union { u32 locks : 26; u32 physical : 6; } bits; + struct { + u32 flags : 26; + u32 rightAlt : 1; + u32 leftAlt : 1; + u32 rightShift : 1; + u32 leftShift : 1; + u32 rightControl : 1; + u32 leftControl : 1; + } keys; } KBDModifierState; typedef struct { @@ -72,7 +81,7 @@ static USBKBDAttachCallback kbdDevAttachCallback; static USBKBDDetachCallback kbdDevDetachCallback; static void (*kbdKeyCallback)(KBDKeyEventData* event); -KBDKeyMapTable kbdKeyMaps; +KBDKeyMapTable kbdKeyMaps = {0}; typedef struct { u32 device; u8 leds; @@ -81,7 +90,7 @@ typedef struct { void* callbackArg; } KBDLEDCommand; -KBDLEDCommand kbdCmdBuf[12]; +KBDLEDCommand kbdCmdBuf[12] = {0}; KBDChannel kbdData[4]; KBDLEDCallbackData kbdLCBuf[12]; @@ -224,7 +233,8 @@ static void kbdEventHandler(void* device, char* report) { KBDChannel* data; u8* bytes; u8 status; - data = &kbdData[channel]; + data = kbdData; + data += channel; bytes = (u8*)report; status = bytes[2]; @@ -243,12 +253,12 @@ static void kbdEventHandler(void* device, char* report) { VIResetDimmingCount(); - for (i = 0, mask = 1; i < 8; i++, mask <<= 1) { - if ((data->modifiers & (u8)mask) != 0) { - if ((bytes[0] & (u8)mask) == 0) { + for (mask = 1, i = 0; i < 8; i++, mask <<= 1) { + if ((data->modifiers & mask) != 0) { + if ((bytes[0] & mask) == 0) { kbdProcKey((u8)(i + 0xe0), 0, channel); } - } else if ((bytes[0] & (u8)mask) != 0) { + } else if ((bytes[0] & mask) != 0) { kbdProcKey((u8)(i + 0xe0), 1, channel); } } @@ -392,86 +402,86 @@ static void kbdProcKey(u32 key, u32 pressed, u32 channel) { static void kbdProcMod(u32 key, u32 pressed, u32 channel) { KBDChannel* data; - s8 delta; + s32 delta; u8 flags; - u32 state; + KBDModifierState state; u32 finalState; s8 value; data = &kbdData[channel]; delta = (pressed & 1) != 0 ? 1 : -1; flags = kbdKeyMaps.maps[data->country].flags; - state = 0; + state.value = data->modState; - kbdGetModState(channel, &state); + kbdGetModState(channel, &state.value); switch (key) { case 0xF001: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 2; + state.value ^= 2; } } else { value = data->lockCount[1] + delta; data->lockCount[1] = value; - state = (state & 0xFFFFFFFD) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1E & 2); - } + state.keys.rightControl = (u8)value != 0; + } break; case 0xF005: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 0x20; + state.value ^= 0x20; } } else { value = data->lockCount[4] + delta; data->lockCount[4] = value; - state = (state & 0xFFFFFFDF) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1A & 0x20); - } + state.keys.rightAlt = (u8)value != 0; + } break; case 0xF000: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 1; + state.value ^= 1; } } else { value = data->lockCount[0] + delta; data->lockCount[0] = value; - state = (state & 0xFFFFFFFE) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1F); - } + state.keys.leftControl = (u8)value != 0; + } break; case 0xF008: if (((pressed & 1) != 0) && (data->lockProcessing != 0)) { - state ^= 0x200; + state.value ^= 0x200; } break; case 0xF007: if (((pressed & 1) != 0) && (data->lockProcessing != 0)) { - state ^= 0x100; + state.value ^= 0x100; } break; case 0xF006: if (((pressed & 1) != 0) && (data->lockProcessing != 0)) { u32 oldState; u32 lockState; - oldState = state; + oldState = state.value; lockState = oldState & 0xC0; switch (lockState) { case 0: if ((flags & 1) == 1) { - state = oldState | 0x40; + state.value = oldState | 0x40; } break; case 0x40: { - state = oldState & 0xFFFFFFBF; + state.value = oldState & 0xFFFFFFBF; if ((flags & 4) == 4) { - state = oldState & 0xFFFFFFBF | 0x80; + state.value = oldState & 0xFFFFFFBF | 0x80; } } break; case 0x80: - state = oldState & 0xFFFFFF7F; + state.value = oldState & 0xFFFFFF7F; break; case 0xC0: - state = oldState & 0xFFFFFF3F; + state.value = oldState & 0xFFFFFF3F; break; } } @@ -479,43 +489,43 @@ static void kbdProcMod(u32 key, u32 pressed, u32 channel) { case 0xF002: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 4; + state.value ^= 4; } } else { value = data->lockCount[2] + delta; data->lockCount[2] = value; - state = (state & 0xFFFFFFFB) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1D & 4); - } + state.keys.leftShift = (u8)value != 0; + } break; case 0xF003: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 8; + state.value ^= 8; } } else { value = data->lockCount[3] + delta; data->lockCount[3] = value; - state = (state & 0xFFFFFFF7) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1C & 8); - } + state.keys.rightShift = (u8)value != 0; + } break; case 0xF004: if (data->lockState != 0) { if ((pressed & 1) != 0) { - state ^= 0x10; + state.value ^= 0x10; } } else { value = data->lockCount[5] + delta; data->lockCount[5] = value; - state = (state & 0xFFFFFFEF) | ((-(u32)(u8)value | (u32)(u8)value) >> 0x1B & 0x10); - } + state.keys.leftAlt = (u8)value != 0; + } break; case 0xF021: if (((pressed & 1) != 0) && (data->lockProcessing != 0)) { - state ^= 0x400; + state.value ^= 0x400; } break; } - finalState = state | 0x1000; + finalState = state.value | 0x1000; KBDSetModState(channel, finalState); } @@ -572,6 +582,7 @@ static void kbd_led_handler(BOOL success, void* callbackArg) { USBKBDErr KBDSetLedsAsync(u32 channel, u32 leds, USBKBDCmdLEDCallback callback, void* callbackArg) { u32 index; + u8 ledBits; BOOL interrupts; USBKBDErr result; if (!kbdInitialized) { @@ -583,7 +594,7 @@ USBKBDErr KBDSetLedsAsync(u32 channel, u32 leds, USBKBDCmdLEDCallback callback, if ((s32)kbdData[channel].flags == 1 || (s32)kbdData[channel].flags == 4) { return 5; } - leds &= 0xff; + ledBits = leds; interrupts = OSDisableInterrupts(); for (index = 0; index < 12; index++) { if (kbdCmdBuf[index].device == 0) { @@ -597,7 +608,7 @@ USBKBDErr KBDSetLedsAsync(u32 channel, u32 leds, USBKBDCmdLEDCallback callback, } kbdLCBuf[index].callbackAddress = (u32)callback; kbdLCBuf[index].callbackArg = callbackArg; - result = USBKBDSetLEDAsync((u32)kbdData[channel].device, leds, + result = USBKBDSetLEDAsync((u32)kbdData[channel].device, ledBits, (USBKBDCmdLEDAsync*)&kbdCmdBuf[index], kbd_led_handler, (void*)index); if (result != 0) { @@ -622,7 +633,7 @@ USBKBDErr KBDSetLeds(u32 channel, u32 leds) { leds &= 0xff; interrupts = OSDisableInterrupts(); for (index = 0; index < 12; index++) { - if (kbdCmdBuf[index].device == 0) { + if ((kbdCmdBuf + index)->device == 0) { kbdCmdBuf[index].device = (u32)kbdData[channel].device; break; } @@ -634,10 +645,10 @@ USBKBDErr KBDSetLeds(u32 channel, u32 leds) { result = USBKBDSetLED((u32)kbdData[channel].device, leds, (USBKBDCmdLED*)&kbdCmdBuf[index]); kbdCmdBuf[index].device = 0; - if (result != 0) { - return 7; + if (result == 0) { + return 0; } - return 0; + return 7; } void kbdInitMap(u32 country, u8 codeCount, u8 flags, u16* keyMap, u16* modifierMap, @@ -879,22 +890,18 @@ u16 KBDTranslateHidCode(u32 keyCode, u32 modifiers, s32 country) { group = 1; offset = 0; } else { - if ((modifiers & 0x20) == 0 && (modifiers & 5) != 5) { - if ((modifiers & 0x40) == 0) { - if ((modifiers & 0x80) == 0) { - group = 1; - shiftFlag = 1; - } else { - group = map->shiftIndex; - shiftFlag = 0x10; - } - } else { - group = map->lockIndex; - shiftFlag = 4; - } - } else { + if ((modifiers & 0x20) == 0x20 || (modifiers & 5) == 5) { group = map->altIndex; shiftFlag = 0x40; + } else if ((modifiers & 0x40) == 0x40) { + group = map->lockIndex; + shiftFlag = 4; + } else if ((modifiers & 0x80) == 0x80) { + group = map->shiftIndex; + shiftFlag = 0x10; + } else { + group = 1; + shiftFlag = 1; } if ((modifiers & 0x800) == 0 && (modifiers & 0x1D) != 0) { diff --git a/libs/RVL_SDK/src/vi/vi3in1.c b/libs/RVL_SDK/src/vi/vi3in1.c index 1b56acf0..4ba0c587 100644 --- a/libs/RVL_SDK/src/vi/vi3in1.c +++ b/libs/RVL_SDK/src/vi/vi3in1.c @@ -115,10 +115,10 @@ void VISetMacrovision(s32 type); u32 copyIndex; \ u8* destination = (dst); \ const u8* source = (src); \ + destination[0] = 0x40; \ for (copyIndex = 0; copyIndex < 0x1a; copyIndex++) { \ destination[copyIndex + 1] = source[copyIndex]; \ } \ - destination[0] = 0x40; \ } while (0) static u8 __wd0 = 0xff; diff --git a/src/scene/memoryCard/iplMemoryCardManager.cpp b/src/scene/memoryCard/iplMemoryCardManager.cpp index 791872d2..90e1f417 100644 --- a/src/scene/memoryCard/iplMemoryCardManager.cpp +++ b/src/scene/memoryCard/iplMemoryCardManager.cpp @@ -401,24 +401,28 @@ const wchar_t* MemoryCardManager::getComment(u8 slot, s16 index, int which) { } if (SCGetLanguage() == 0) { utility::CharacterCode::shiftJISToUTF16(dest, reinterpret_cast(comment), 0x20); - for (int pos = 0x1f; dest[pos] == 0x20 || dest[pos] == 0x3000 || dest[pos] == 10 || dest[pos] == 0; pos--) { - dest[pos] = 0; + for (int pos = 0x1f; + mFileCell[slot][file].comment[which][pos] == 0x20 || + mFileCell[slot][file].comment[which][pos] == 0x3000 || + mFileCell[slot][file].comment[which][pos] == 10 || + mFileCell[slot][file].comment[which][pos] == 0;) { + mFileCell[slot][file].comment[which][pos--] = 0; } } else { utility::CharacterCode::ANSIToUTF16(dest, reinterpret_cast(comment), 0x20); } bool found = false; int count = 0; - while (dest[count] != 0 && count < 0x20) { + while (mFileCell[slot][file].comment[which][count] != 0 && count < 0x20) { if (found) { - dest[count] = 0; - } else if (dest[count] == 10 || dest[count] == 0xd0a) { - dest[count] = 0; + mFileCell[slot][file].comment[which][count] = 0; + } else if (mFileCell[slot][file].comment[which][count] == 10 || mFileCell[slot][file].comment[which][count] == 0xd0a) { + mFileCell[slot][file].comment[which][count] = 0; found = true; } count++; } - return dest; + return mFileCell[slot][file].comment[which]; } GXTexObj* MemoryCardManager::create_banner(u8 slot, s16 index) { diff --git a/tools/decomp-assist/iplMemoryCardManager.attempts.md b/tools/decomp-assist/iplMemoryCardManager.attempts.md index 7020ae30..f3214869 100644 --- a/tools/decomp-assist/iplMemoryCardManager.attempts.md +++ b/tools/decomp-assist/iplMemoryCardManager.attempts.md @@ -105,3 +105,69 @@ Final instruction evidence: Measured waves 1-4, objdiff percent: 74.96, 92.0, 91.0, 92.0. Final instruction evidence: `src 0x64 base 0x64 insns 25/25; diffs 9: [11, 12, 13, 14, 15, 16, 17, 18, 19]` + +# Continuation from eaee2295 + +## update_file_array__Q33ipl5scene17MemoryCardManagerFUc +1. Compare command bounds directly instead of subtracting one: 97.5%; src 0x16c base 0x168 insns 91/90 +2. Use unsigned command local and a signed range test: 97.44444%; src 0x16c base 0x168 insns 91/90 +3. Switch on the separately loaded command value: 93.344444%; src 0x164 base 0x168 insns 89/90 + +## sort_file_array__Q33ipl5scene17MemoryCardManagerFUc +1. Use an unsigned file counter: 98.13725%; src 0xcc base 0xcc insns 51/51 +2. Assign the common file number and high key word before the directory branch: 72.333336%; src 0xbc base 0xcc insns 47/51 +3. Name the live sort key before copying its low and high words: 97.90196%; src 0xcc base 0xcc insns 51/51 + +## update_icon_anm__Q33ipl5scene17MemoryCardManagerFv +1. Keep the frame limit local to each comparison: 96.78571%; src 0x14c base 0x150 insns 83/84 +2. Reload frame counter after its store instead of using the local: 96.78571%; src 0x14c base 0x150 insns 83/84 +3. Use an explicit cell pointer only for animation-counter fields: 94.32143%; src 0x150 base 0x150 insns 84/84 + +## isBannerEnable__Q33ipl5scene17MemoryCardManagerFUcs +1. Direct member return without a result local: 92.30769%; src 0x68 base 0x68 insns 26/26 +2. Cache member file number before querying the icon array: 34.0%; src 0x60 base 0x68 insns 24/26 +3. Store banner flag in a word before Boolean conversion: 92.30769%; src 0x68 base 0x68 insns 26/26 + +## getBlocks__Q33ipl5scene17MemoryCardManagerFUcs +1. Keep the file index signed before directory lookup: 92.0%; src 0x64 base 0x64 insns 25/25 +2. Cache file number before querying directory state: 26.08%; src 0x5c base 0x64 insns 23/25 +3. Use a directory-entry pointer and word result local: 91.0%; src 0x64 base 0x64 insns 25/25 + +## isMoveEnable__Q33ipl5scene17MemoryCardManagerFUcUlPl +1. Initialize destination state from the queried state array: 88.89831%; src 0x1e4 base 0x1d8 insns 121/118 +2. Cache destination-card pointer before the readiness test: 83.89831%; src 0x1d4 base 0x1d8 insns 117/118 +3. Use a single ready predicate and explicit error-code branches: 89.66102%; src 0x1e4 base 0x1d8 insns 121/118 + +## isCopyEnable__Q33ipl5scene17MemoryCardManagerFUcUlPl +1. Initialize destination state from the queried state array: 88.89831%; src 0x1e4 base 0x1d8 insns 121/118 +2. Cache destination-card pointer before the readiness test: 83.89831%; src 0x1d4 base 0x1d8 insns 117/118 +3. Use a single ready predicate and explicit error-code branches: 89.66102%; src 0x1e4 base 0x1d8 insns 121/118 + +## create_icon__Q33ipl5scene17MemoryCardManagerFUcs +1. Use signed 16-bit frame directly in the shift and compare with eight: 86.17647%; src 0xcc base 0xcc insns 51/51 +2. Cache the current animation count before the frame loop: 86.84314%; src 0xc8 base 0xcc insns 50/51 +3. Advance frame after accumulating its duration: 86.17647%; src 0xcc base 0xcc insns 51/51 +4. Cache icon-state entry and current frame, use post-increment in shift: 86.17647%; src 0xcc base 0xcc insns 51/51 +5. Use a for-loop with signed 16-bit frame bound and direct shift: 83.01961%; src 0xcc base 0xcc insns 51/51 +6. Use separate signed 16-bit shift and current frame local: 86.17647%; src 0xcc base 0xcc insns 51/51 + +## _create_icon__Q33ipl5scene17MemoryCardManagerFUcsl +1. Compute the frame image pointer before choosing its texture format: 63.98%; src 0x174 base 0x190 insns 93/100 +2. Use a switch on the signed icon format: 77.64%; src 0x18c base 0x190 insns 99/100 +3. Share texture destination and TLUT pointer locals across format branches: 57.17%; src 0x164 base 0x190 insns 89/100 + +## getComment__Q33ipl5scene17MemoryCardManagerFUcsi +1. Direct cell-member trimming and return, variation 1: 88.29269%; src 0x1d4 base 0x1ec insns 117/123 +2. Direct cell-member trimming and return, variation 2: 90.04065%; src 0x1e4 base 0x1ec insns 121/123 +3. Direct cell-member trimming and return, variation 3: 88.55285%; src 0x1e0 base 0x1ec insns 120/123 +4. Keep cell-base pointer for the return and signed byte trim pointers: 90.04065%; src 0x1e4 base 0x1ec insns 121/123 +5. Use indexed reads and post-decrement indexed writes in wide trim: 93.08943%; src 0x1e8 base 0x1ec insns 122/123 +6. Use a signed file index and explicit pointer zero-initialization loop: 56.91057%; src 0x1e4 base 0x1ec insns 121/123 + +## create_banner__Q33ipl5scene17MemoryCardManagerFUcs +1. Compute banner data pointer before choosing format: 63.95283%; src 0x194 base 0x1a8 insns 101/106 +2. Use a structured banner-format switch: 72.79245%; src 0x1a4 base 0x1a8 insns 105/106 +3. Cache banner texture after validating file and icon metadata: 55.679245%; src 0x16c base 0x1a8 insns 91/106 + +A unit-only guarded u32 getBlocks return declaration was tested: same 25/25 instructions and nine epilogue-scheduling differences. Header and macro restored. No target or source data sections. +No new instruction-exact functions yet; retained source experiments remain uncommitted pending an exact-function gain. diff --git a/tools/decomp-assist/kbd_lib.attempts.md b/tools/decomp-assist/kbd_lib.attempts.md index a77f98dc..2a576654 100644 --- a/tools/decomp-assist/kbd_lib.attempts.md +++ b/tools/decomp-assist/kbd_lib.attempts.md @@ -64,3 +64,76 @@ Instruction diffs retained in /tmp/sol-low-kbd-final-ctx.txt. ## Final gate discrepancy KBDResetChannel has objdiff 100.0% and identical 176-byte instruction contents. The gate reports 12/21 instead of 13/21 because odiff.dis treats the first CR1 conditional-branch operand as an immediate and subtracts the different symbol offsets. Both disputed branch instruction words are identical. Tools were left unchanged. + +# Continuation from eaee2295 + +## kbdEventHandler +1. Use the word mask directly for both report bytes: 99.72043%; src 0x2e8 base 0x2e8 insns 186/186 +2. Initialize loop mask before the loop, retain byte conversion: 99.166664%; src 0x2ec base 0x2e8 insns 187/186 +3. Use report-status byte local for error classification: 98.63441%; src 0x2e8 base 0x2e8 insns 186/186 +4. Set mask before index in the word-mask loop initializer: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +5. Calculate report status before looking up channel data: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +6. Declare bytes before channel data and use a channel pointer expression: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +7. Use an unsigned report-status word only for the range check: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +8. Perform error classification before forming the channel pointer: 92.150536%; src 0x2f8 base 0x2e8 insns 190/186 +9. Form channel pointer with a byte-sized channel index: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +10. Typed HID report fields, variation 1: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +11. Typed HID report fields, variation 2: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +12. Typed HID report fields, variation 3: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +13. Separate channel-array base and channel selection: 99.83871%; src 0x2e8 base 0x2e8 insns 186/186 +14. Keep a typed channel-array local through channel lookup: 98.81721%; src 0x2e0 base 0x2e8 insns 184/186 +15. Use the report word status minus one as signed arithmetic before narrowing: 99.752686%; src 0x2e8 base 0x2e8 insns 186/186 +16. Declare and initialize channel record at the top of the found-channel block: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +17. Express channel selection with the index as the left operand: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +18. Declare a separate channel-array base for the selected record: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 +19. Load report state before final channel selection and use a word local: 99.78494%; src 0x2e8 base 0x2e8 insns 186/186 + +## KBDSetModState +1. Merge physical bits using a scalar mask instead of bitfields: 98.690475%; src 0xa8 base 0xa8 insns 42/42 +2. Compute channel pointer before disabling interrupts: 86.54762%; src 0xa4 base 0xa8 insns 41/42 +3. Use an initialized modifier union and write both fields: 93.21429%; src 0xb0 base 0xa8 insns 44/42 + +## kbdProcKey +1. Initialize getter destination with the known channel modifier state: 94.50581%; src 0x2b4 base 0x2b0 insns 173/172 +2. Initialize event fields as one aggregate before channel lookup: build rejected (ninja: build stopped: subcommand failed.). +3. Read modifiers directly after validating the known channel: 87.6686%; src 0x294 base 0x2b0 insns 165/172 +4. Initialize a separate modifier destination then copy to the event: 94.50581%; src 0x2bc base 0x2b0 insns 175/172 +5. Zero-initialize the entire event before filling fields: 95.75581%; src 0x2c0 base 0x2b0 insns 176/172 +6. Check getter status explicitly and initialize on failure: 92.93604%; src 0x2dc base 0x2b0 insns 183/172 + +## kbd_led_handler +1. Use a typed callback record and clear command first: 48.16%; src 0x54 base 0x64 insns 21/25 +2. Return mapped result through if/else instead of switch: 39.36%; src 0x58 base 0x64 insns 22/25 +3. Reload callback at the call and compare against numeric zero: 62.2%; src 0x58 base 0x64 insns 22/25 + +## KBDSetLedsAsync +1. Keep narrowed LED bits in a separate byte: 79.5679%; src 0x138 base 0x144 insns 78/81 +2. Scan commands by index and test success before failure: 73.38271%; src 0x13c base 0x144 insns 79/81 +3. Use a command-record pointer during reservation: 74.80247%; src 0x134 base 0x144 insns 77/81 +4. Explicitly zero-initialize keyboard map and command records: 79.604935%; src 0x138 base 0x144 insns 78/81 +5. Explicitly zero-initialize all real keyboard workspaces: 79.604935%; src 0x138 base 0x144 insns 78/81 +6. Explicitly zero-initialize the typed per-channel state: 79.5679%; src 0x138 base 0x144 insns 78/81 + +## KBDSetLeds +1. Keep narrowed LED bits in a separate byte: 72.620255%; src 0x134 base 0x13c insns 77/79 +2. Scan commands by index and test success before failure: 73.177216%; src 0x138 base 0x13c insns 78/79 +3. Use a command-record pointer during reservation: 72.27848%; src 0x12c base 0x13c insns 75/79 + +## kbdProcMod +1. Use unsigned byte counts and logical nonzero masks: 75.78125%; src 0x3c0 base 0x400 insns 240/256 +2. Use an initialized modifier union for the switch updates: 75.78125%; src 0x3c0 base 0x400 insns 240/256 +3. Initialize from channel state and use word-sized count delta: 75.97656%; src 0x3c0 base 0x400 insns 240/256 +4. Update named physical modifier bitfields: 78.90625%; src 0x3a0 base 0x400 insns 232/256 + +## KBDTranslateHidCode +1. Prioritize alt, lock and shift groups in a flat decision chain: 91.70731%; src 0x290 base 0x290 insns 164/164 +2. Keep entry mask and group indices signed: 89.597565%; src 0x290 base 0x290 insns 164/164 +3. Separate character offset calculation from table indexing: 86.29878%; src 0x284 base 0x290 insns 161/164 + +## Data and workspace checks +Named mutable SDK version text: matched data 3992/5296. Rejected; no improvement or data regression. +Named constant SDK version text: matched data 3984/5296. Rejected; no improvement or data regression. +Place SDK version declaration after the region tables: matched data 3984/5296. Rejected; no improvement or data regression. +Explicit zero-initialization of real map and command workspaces reproduces target BSS order: key maps 0x000, command records 0x400, channel state 0x580, callback records 0xf20. No extra objects or placement directives. +Using the existing SDK command type was also tested and produced identical function scores; the original private declaration was restored. +No new instruction-exact functions yet; retained source experiments remain uncommitted pending an exact-function gain. diff --git a/tools/decomp-assist/vi3in1.attempts.md b/tools/decomp-assist/vi3in1.attempts.md index 056c21fc..25d2355e 100644 --- a/tools/decomp-assist/vi3in1.attempts.md +++ b/tools/decomp-assist/vi3in1.attempts.md @@ -19,3 +19,33 @@ String pools identical. Data 1512/1512 bytes in objdiff. 1. Indexed ACP copy, original assignment order: 265/267 instructions, 96.82022%; saved constant register and byte-copy allocation differ. 2. Masked WSS operands and command-first caption assignment: 265/267; WSS and caption differences removed. Retained. 3. Explicit ACP byte copies: 266/267, 78.92135%; enlarged frame and save set. Rejected. + +# Continuation from eaee2295 + +## __VISetRevolutionModeSimple +1. Store ACP command before the ascending byte transfer: 97.05618%; src 0x424 base 0x42c insns 265/267 +2. Initialize power and clock command arrays at declaration: 94.29588%; src 0x428 base 0x42c insns 266/267 +3. Use signed ACP index and store command first: 97.05618%; src 0x424 base 0x42c insns 265/267 + +## VISetMacrovision +1. Copy old type after volume masking: 99.48529%; src 0x110 base 0x110 insns 68/68 +2. Load type before first byte, combine new flag operands: 99.48529%; src 0x110 base 0x110 insns 68/68 +3. Express mode dispatch as a structured switch: 99.48529%; src 0x110 base 0x110 insns 68/68 +4. Use word-sized intermediates for newType: 94.85294%; src 0x10c base 0x110 insns 67/68 +5. Use word-sized intermediates for newType, oldType: 94.85294%; src 0x10c base 0x110 insns 67/68 +6. Use word-sized intermediates for newType, oldWd0: 94.85294%; src 0x10c base 0x110 insns 67/68 +7. Use word-sized intermediates for oldWd0: 99.48529%; src 0x110 base 0x110 insns 68/68 +8. Use word-sized intermediates for newType, oldWd2: 94.85294%; src 0x10c base 0x110 insns 67/68 +9. Use word-sized intermediates for oldWd0, mode: 98.60294%; src 0x110 base 0x110 insns 68/68 +10. Use word-sized intermediates for oldType, mode: 98.60294%; src 0x110 base 0x110 insns 68/68 +11. Load WSS state in oldWd2,oldType,oldWd0 order: 99.411766%; src 0x110 base 0x110 insns 68/68 +12. Load WSS state in oldType,oldWd2,oldWd0 order: 99.411766%; src 0x110 base 0x110 insns 68/68 +13. Load WSS state in oldWd2,oldWd0,oldType order: 99.411766%; src 0x110 base 0x110 insns 68/68 + +## __VISetMacrovision +1. Descending remaining-byte count and advancing source/destination: 94.26905% +2. Assign command byte before indexed ACP transfer: 96.77598% +3. Signed copy index and named per-byte value: 94.26905% + +All data sections remain 100%; the ACP command-first assignment preserves pool contents and reaches 866/866 instructions, but allocation still differs. +No new instruction-exact functions yet; retained source experiments remain uncommitted pending an exact-function gain. -- 2.49.1