From 5166ef739ef9545ed6472f850df3279798c32584 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 22:27:54 -0500 Subject: [PATCH 01/21] Match PlayTimeLog record creation (#76) --- src/system/iplPlayTimeLog.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/system/iplPlayTimeLog.cpp b/src/system/iplPlayTimeLog.cpp index 8f708e5a..0d36680c 100644 --- a/src/system/iplPlayTimeLog.cpp +++ b/src/system/iplPlayTimeLog.cpp @@ -7,10 +7,10 @@ namespace ipl { static const wchar_t scNumber[] = L"0123456789"; - extern const u32 scCreateRecordAttachSize0 = sizeof(EventBuffer); - extern const u32 scCreateRecordAttachSize1 = 0; - extern const RBRAttachmentType scCreateRecordAttachType0 = RBRAttachmentType_PlayTimeLog; - extern const RBRAttachmentType scCreateRecordAttachType1 = RBRAttachmentType_None; + extern const u32 sPlayTimeLogAttachSize0 = sizeof(EventBuffer); + extern const u32 sPlayTimeLogAttachSize1 = 0; + extern const RBRAttachmentType sPlayTimeLogAttachType0 = RBRAttachmentType_PlayTimeLog; + extern const RBRAttachmentType sPlayTimeLogAttachType1 = RBRAttachmentType_None; PlayTimeLog PlayTimeLog::smArg; BOOL search_cb_(void* playTime, CDBRecord* record) { @@ -351,11 +351,15 @@ namespace ipl { const void* attachData[RBR_ATTACHMENT_MAX] = {(void*)event, NULL}; - u32 attachSize[RBR_ATTACHMENT_MAX] = {*reinterpret_cast(&scCreateRecordAttachSize0), - *reinterpret_cast(&scCreateRecordAttachSize1)}; + u32 attachSize[RBR_ATTACHMENT_MAX] = { + *reinterpret_cast(&sPlayTimeLogAttachSize0), + *reinterpret_cast(&sPlayTimeLogAttachSize1) + }; + RBRAttachmentType attachType[RBR_ATTACHMENT_MAX] = { - *reinterpret_cast(&scCreateRecordAttachType0), - *reinterpret_cast(&scCreateRecordAttachType1)}; + *reinterpret_cast(&sPlayTimeLogAttachType0), + *reinterpret_cast(&sPlayTimeLogAttachType1) + }; NWC24FriendAddr friendAddr; memset(&friendAddr, 0, sizeof(NWC24FriendAddr)); -- 2.49.1 From 953b301d7628da9632d3cfeb80dd2423c2b29a7f Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 22:29:28 -0500 Subject: [PATCH 02/21] Link matching iplUtility unit (#77) * Link matching iplUtility unit * Mark utility constructor shim weak --- configure.py | 2 +- src/utility/iplUtility.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.py b/configure.py index 251a622d..eb1e1320 100644 --- a/configure.py +++ b/configure.py @@ -673,7 +673,7 @@ config.libs = [ Object(Matching, "utility/iplFrameController.cpp"), Object(Equivalent, "utility/iplGraphics.cpp"), Object(Matching, "utility/iplCapture.cpp"), - Object(Equivalent, "utility/iplUtility.cpp"), + Object(Matching, "utility/iplUtility.cpp"), Object(Matching, "utility/iplThread.cpp"), Object(Matching, "utility/iplMessageBase.cpp"), Object(Matching, "utility/iplJpegDecoder.cpp"), diff --git a/src/utility/iplUtility.cpp b/src/utility/iplUtility.cpp index ad710442..fb801b75 100644 --- a/src/utility/iplUtility.cpp +++ b/src/utility/iplUtility.cpp @@ -723,7 +723,7 @@ namespace ipl { } // namespace utility #ifndef NON_MATCHING - math::VEC2 ForceCTORWeak() { + __declspec(weak) math::VEC2 ForceCTORWeak() { return math::VEC2(NULL, NULL); } #endif // NON_MATCHING -- 2.49.1 From a95c8a4b1d4c98b150cdb68d47bb2302772adca9 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 22:45:45 -0500 Subject: [PATCH 03/21] Match and link RsoSystem (#79) --- configure.py | 2 +- src/system/RsoSystem.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/configure.py b/configure.py index eb1e1320..610214a7 100644 --- a/configure.py +++ b/configure.py @@ -655,7 +655,7 @@ config.libs = [ Object(Matching, "system/iplPostmanManager.cpp"), Object(NonMatching, "system/iplSaveDataManager.cpp"), Object(Matching, "system/iplChannelRsoThread.cpp"), - Object(Equivalent, "system/RsoSystem.cpp"), + Object(Matching, "system/RsoSystem.cpp"), Object(Matching, "system/iplCdbBackup.cpp"), Object(NonMatching, "system/odh.cpp"), Object(Matching, "system/iplSDVFWorker.cpp"), diff --git a/src/system/RsoSystem.cpp b/src/system/RsoSystem.cpp index 9b83a64c..7f86fa65 100644 --- a/src/system/RsoSystem.cpp +++ b/src/system/RsoSystem.cpp @@ -1,3 +1,22 @@ +#include +#include + +extern "C" const unsigned char lbl_8169622C; +extern "C" const unsigned char lbl_8169622D; +extern "C" const unsigned char lbl_8169622E; +extern "C" const unsigned char lbl_8169622F; +extern "C" const char lbl_81639230[65]; + +#define NW4R_DB_ASSERT_H +#define NW4R_ASSERT(x) \ + { \ + if (!(x)) { \ + GXColor front = {*((volatile const unsigned char*)&lbl_8169622C), *((volatile const unsigned char*)&lbl_8169622D), *((volatile const unsigned char*)&lbl_8169622E), *((volatile const unsigned char*)&lbl_8169622F)}; \ + GXColor back = {0, 0, 0, 0}; \ + OSFatal((GXColor)front, (GXColor)back, lbl_81639230); \ + } \ + } + #include "scene/channelSelect/iplChannelSelect.h" #include "scene/channelTitle/iplChannelTitle.h" @@ -306,3 +325,16 @@ __declspec(export) void IplRso_symbolMaker() { wideTextWriter->CalcStringRect(&rect, L"", 0); wideTextWriter->CalcStringRect(&rect, L""); } + +extern "C" __declspec(section ".sdata") const unsigned char lbl_8169622C = 255; +extern "C" __declspec(section ".sdata") const unsigned char lbl_8169622D = 255; +extern "C" __declspec(section ".sdata") const unsigned char lbl_8169622E = 255; +extern "C" __declspec(section ".sdata") const unsigned char lbl_8169622F = 0; + +extern "C" __declspec(section ".data") const char lbl_81639230[65] = "Error#004\nAn error has occurred.\nThe system files are corrupted."; + +extern "C" __declspec(section ".data") __declspec(align(1)) const f32 rso_data_pad_f32 = 0.0f; +extern "C" __declspec(section ".data") __declspec(align(1)) const u16 rso_data_pad_u16 = 0; +extern "C" __declspec(section ".data") __declspec(align(1)) const u8 rso_data_pad_u8 = 0; + +extern "C" __declspec(section ".sdata2") const f32 lbl_81694598 = 0.0f; -- 2.49.1 From 69ff7c2582be3f2f7ff1ad8cc30b76f6201c1fc3 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 22:57:22 -0500 Subject: [PATCH 04/21] Match and link iplSaveDataManager (#82) * Match save data manager initialization * Match save data manager empty string --- src/system/iplSaveDataManager.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/system/iplSaveDataManager.cpp b/src/system/iplSaveDataManager.cpp index 87748139..53cba973 100644 --- a/src/system/iplSaveDataManager.cpp +++ b/src/system/iplSaveDataManager.cpp @@ -274,7 +274,7 @@ namespace ipl { u32 fileLen = sizeof(Data); BOOL bCreateNew = FALSE; - BOOL bNeedFlush = FALSE; + bool bNeedFlush = false; ES_SetUid(SYSMENU_TITLE_ID); @@ -330,12 +330,21 @@ namespace ipl { NETMD5Sum md5; NETCalcMD5(md5, &manager->mData, fileLen - NET_MD5_DIGEST_SIZE); - for (int i = 0; i < NET_MD5_DIGEST_SIZE; i++) { - if (md5[i] != manager->mData.MD5Sum[i]) { + u8* data = (u8*)manager; + u32* loopFileLen = &fileLen; + volatile NETMD5Sum& md5Ref = md5; + u32 i = 0; + while (i < NET_MD5_DIGEST_SIZE) { + u8 md5Byte = md5Ref[i]; + u32 offset = i; + offset += *loopFileLen; + u32 fileByte = *(u8*)(offset + (u32)data + NET_MD5_DIGEST_SIZE); + if (md5Byte != fileByte) { // Invalid MD5 sum, create new bCreateNew = TRUE; break; } + i++; } } } @@ -382,7 +391,8 @@ namespace ipl { } } - if (bNeedFlush | manager->updateChanInfos()) { + bool flush = bNeedFlush | manager->updateChanInfos(); + if (flush) { if (manager->mpUpdatedFile) { delete manager->mpUpdatedFile; } @@ -1245,7 +1255,7 @@ namespace ipl { void Manager::updateVersion(u32 newVersion, u32 oldVersion) { if ((newVersion & 0xFFFF0000) != (oldVersion & 0xFFFF0000)) { OSReport("[SaveDataManager] Invalid major version change %d -> %d\n", oldVersion >> 16, newVersion >> 16); - OSHalt("", 1344); + OSHalt("\0\0\0", 1344); } mData.fileSize = sizeof(Data); mData.version = newVersion; -- 2.49.1 From 0eedd89260dc42c75bf14e9293fdc09e4b091bef Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:02:58 -0500 Subject: [PATCH 05/21] Match tiInputForm helper functions (#83) --- src/keyboard/tiInputForm.cpp | 263 ++++++++++++++++++++++++++++------- 1 file changed, 211 insertions(+), 52 deletions(-) diff --git a/src/keyboard/tiInputForm.cpp b/src/keyboard/tiInputForm.cpp index 6ab7a557..de686405 100644 --- a/src/keyboard/tiInputForm.cpp +++ b/src/keyboard/tiInputForm.cpp @@ -51,7 +51,6 @@ extern "C" asm void __dt__Q39textinput11nw4rmanager6LayoutFv(); extern "C" asm void __dt__Q34nw4r2ut10CharWriterFv(); extern "C" asm void __ct__Q39textinput11nw4rmanager6LayoutFPQ34nw4r3lyt24MultiArcResourceAccessorPCcPQ29textinput13EventObserver(); extern "C" asm void __ct__Q34nw4r2ut7ResFontFv(); -extern "C" asm void csLanguageDependencyDataUEJ__Q29textinput9inputform(); extern "C" asm void __dt__Q39textinput8tistring10StringBaseFv(); extern "C" asm void KPRLookAhead(); extern "C" asm void set__Q39textinput8tistring10StringBaseFPCw(); @@ -69,6 +68,19 @@ extern "C" asm void searchPaneComponent__Q39textinput3gui11PaneManagerFPCc(); #pragma push #pragma section const_type ".data" extern "C" const char lbl_8165C820[]; +extern "C" const char lbl_8165C830[]; +extern "C" const char lbl_8165C8C0[]; +extern "C" const char lbl_8165C8CC[]; +extern "C" const char lbl_8165C8E0[]; +extern "C" const char lbl_8165C8F0[]; +extern "C" const char lbl_8165C900[]; +extern "C" const char lbl_8165C918[]; +extern "C" const char lbl_8165C928[]; +extern "C" const char lbl_8165C938[]; +extern "C" const char lbl_8165C950[]; +extern "C" const char lbl_8165C960[]; +extern "C" const char lbl_816973A4[]; +extern "C" const char lbl_816973AC[]; #pragma pop extern "C" const f32 lbl_81694D28; extern "C" void _savegpr_20(); @@ -1030,6 +1042,93 @@ resetContextPredict_L1: addi r1, r1, 0x10 blr } + +struct InputFormAnimationFile { + u32 id; + char fileName[0x40]; +}; + +#pragma push +#pragma section const_type ".rodata" +extern "C" const InputFormAnimationFile csAninationFile__Q29textinput9inputform[8] = { + {0, "fs_VK_textBox_a_normal.brlan"}, + {1, "fs_VK_textBox_a_Foucus_IN.brlan"}, + {2, "fs_VK_textBox_a_Focus-OUT.brlan"}, + {3, "fs_VK_textBox_a_Roll_over.brlan"}, + {4, "fs_VK_textBox_a_Pushed.brlan"}, + {5, "fs_VK_textBox_a_Fade_IN.brlan"}, + {6, "fs_VK_textBox_a_Fade_OUT.brlan"}, + {7, "fs_VK_textBox_a_Off.brlan"}, +}; + +#pragma section data_type ".rodata" +extern "C" const void* csVisiblePaneUEJ__Q29textinput9inputform[9] = { + (const void*)0x00010002, + lbl_8165C8C0, + 0, + 0, + 0, + lbl_816973A4, + lbl_816973AC, + 0, + 0, +}; + +extern "C" const void* csVisiblePaneKOR__Q29textinput9inputform[9] = { + (const void*)0x00010002, + lbl_816973A4, + 0, + 0, + 0, + lbl_816973AC, + lbl_8165C8C0, + 0, + 0, +}; + +extern "C" const void* csVisiblePaneCHN__Q29textinput9inputform[10] = { + (const void*)0x00010002, + lbl_816973AC, + 0, + 0, + 0, + lbl_816973A4, + lbl_8165C8C0, + 0, + 0, + 0, +}; + +extern "C" const void* csLanguageDependencyDataUEJ__Q29textinput9inputform[4] = { + csVisiblePaneUEJ__Q29textinput9inputform, + lbl_8165C8CC, + lbl_8165C8E0, + lbl_8165C8F0, +}; + +extern "C" const void* csLanguageDependencyDataKOR__Q29textinput9inputform[4] = { + csVisiblePaneKOR__Q29textinput9inputform, + lbl_8165C900, + lbl_8165C918, + lbl_8165C928, +}; + +extern "C" const void* csLanguageDependencyDataCHN__Q29textinput9inputform[4] = { + csVisiblePaneCHN__Q29textinput9inputform, + lbl_8165C938, + lbl_8165C950, + lbl_8165C960, +}; +#pragma section data_type ".data" + +extern "C" const u32 pppURLCheck[10] = { + 0x00680074, 0x00740070, 0x003A002F, 0x002F0000, 0x00000000, + 0x00680074, 0x00740070, 0x0073003A, 0x002F002F, 0x00000000 +}; + +extern "C" const u32 lbl_816152D0[4] = {0x00200000, 0, 0, 0}; +#pragma pop + extern "C" const f32 lbl_81694D28 = 0.0f; extern "C" const f32 lbl_81694D2C = 640.0f; extern "C" const f64 lbl_81694D30 = 4503601774854144.0; @@ -1056,11 +1155,6 @@ extern "C" const f32 lbl_81694D78 = 14592.0f; extern "C" const f64 lbl_81694D80 = 4503599627370496.0; extern "C" const f32 lbl_81694D88 = 15.0f; extern "C" f32 lbl_81698D1C; -extern "C" const u32 pppURLCheck[10] = { - 0x00680074, 0x00740070, 0x003A002F, 0x002F0000, 0x00000000, - 0x00680074, 0x0073003A, 0x002F002F, 0x00000000, 0x00000000 -}; -extern "C" const u32 lbl_816152D0[4] = {0x00200000, 0, 0, 0}; bool mbHyphen; @@ -1068,6 +1162,40 @@ bool mbHyphen; #pragma section const_type ".data" extern "C" const char lbl_8165C820[] = "P_txtScrll_UP"; extern "C" const char lbl_8165C830[] = "P_txtScrll_DOWN"; +extern "C" const void* lbl_8165C840[32] = { + 0, + lbl_8165C820, + (const void*)0x00000008, + 0, + csAninationFile__Q29textinput9inputform, + csAninationFile__Q29textinput9inputform + 1, + csAninationFile__Q29textinput9inputform + 2, + csAninationFile__Q29textinput9inputform + 3, + csAninationFile__Q29textinput9inputform + 4, + csAninationFile__Q29textinput9inputform + 5, + csAninationFile__Q29textinput9inputform + 6, + 0, + 0, + 0, + 0, + 0, + lbl_8165C830, + (const void*)0x00000008, + 0, + csAninationFile__Q29textinput9inputform, + csAninationFile__Q29textinput9inputform + 1, + csAninationFile__Q29textinput9inputform + 2, + csAninationFile__Q29textinput9inputform + 3, + csAninationFile__Q29textinput9inputform + 4, + csAninationFile__Q29textinput9inputform + 5, + csAninationFile__Q29textinput9inputform + 6, + 0, + 0, + 0, + 0, + 0, + 0, +}; extern "C" const char lbl_8165C8C0[] = "N_JPNUSAEUR"; extern "C" const char lbl_8165C8CC[] = "N_separateBarAll"; extern "C" const char lbl_8165C8E0[] = "T_2l_TextBox"; @@ -1078,6 +1206,83 @@ extern "C" const char lbl_8165C928[] = "T_title_textKOR"; extern "C" const char lbl_8165C938[] = "N_separateBarCHN"; extern "C" const char lbl_8165C950[] = "T_2l_TextBoxCHN"; extern "C" const char lbl_8165C960[] = "T_title_textCHN"; +extern "C" const u16 lbl_8165C970[16] = { + 0x00a4, 0x00ac, 0x00af, 0x00b2, 0x00b3, 0x00b6, 0x00b8, 0x00b9, + 0x00bc, 0x00bd, 0x00be, 0x00d0, 0x00de, 0x00f0, 0x00fe, 0x0000, +}; + +extern "C" u16 ToIndependentClass__Q39textinput9inputform13DeadKeyStreamFw(u16 code) { + if (code < 0x300 || code > 0x330) { + return code; + } + switch (code) { + case 0x300: + return 0x60; + case 0x301: + return 0xb4; + case 0x302: + return 0x5e; + case 0x303: + return 0x7e; + case 0x308: + return 0xa8; + case 0x30d: + return 0x27; + case 0x30e: + return 0x22; + case 0x327: + return 0xb8; + default: + return code; + } +} + +void Base::setLanguage(Language language) { + meLanguage = language; + switch (language) { + case JP: + setPredictMode(PM_Atok); + break; + case USA: + setPredictMode(PM_USEn); + break; + case UK: + setPredictMode(PM_En); + break; + case FR: + setPredictMode(PM_De); + break; + case DE: + setPredictMode(PM_It); + break; + case IT: + setPredictMode(PM_Nl); + break; + case SP: + if (meDestination == DST_EU) { + setPredictMode(PM_Sp); + } else { + setPredictMode(PM_USSp); + } + break; + case NL: + if (meDestination == DST_EU) { + setPredictMode(PM_Fr); + } else { + setPredictMode(PM_USFr); + } + break; + case CN: + setPredictMode(PM_11); + break; + case KR: + setPredictMode(PM_12); + break; + default: + break; + } +} + extern "C" const char lbl_8165CBE0[] = "T_2l_TextBox"; extern "C" const char lbl_8165D258[] = "RevoIpl_RodinNTLGProM_32_I4.brfnt"; extern "C" const char lbl_8165D27C[] = "P_txtScrll_UP"; @@ -4382,52 +4587,6 @@ checkHeadOfSentence_L7: blr } -void Base::setLanguage(Language language) { - meLanguage = language; - switch (language) { - case JP: - setPredictMode(PM_Atok); - break; - case USA: - setPredictMode(PM_USEn); - break; - case UK: - setPredictMode(PM_En); - break; - case FR: - setPredictMode(PM_De); - break; - case DE: - setPredictMode(PM_It); - break; - case IT: - setPredictMode(PM_Nl); - break; - case SP: - if (meDestination == DST_EU) { - setPredictMode(PM_Sp); - } else { - setPredictMode(PM_USSp); - } - break; - case NL: - if (meDestination == DST_EU) { - setPredictMode(PM_Fr); - } else { - setPredictMode(PM_USFr); - } - break; - case CN: - setPredictMode(PM_11); - break; - case KR: - setPredictMode(PM_12); - break; - default: - break; - } -} - void Base::setLineDrawInfo(bool lineDraw, u32 lineCount) { mbLineDraw = lineDraw; muSpecifyLineDrawCount = lineCount; -- 2.49.1 From cf00659e46866b5019b1df437e2c10f71c0c1e57 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:03:41 -0500 Subject: [PATCH 06/21] Match iplController data (#84) --- src/system/iplController.cpp | 393 +++++++++++++++++++++++++++++++---- 1 file changed, 354 insertions(+), 39 deletions(-) diff --git a/src/system/iplController.cpp b/src/system/iplController.cpp index 6ba04ea6..a1a9d3e9 100644 --- a/src/system/iplController.cpp +++ b/src/system/iplController.cpp @@ -14,17 +14,337 @@ #include "system/iplSystem.h" const f32 lbl_8160D2C0[] = {0.2, 0.3, 0, 0}; -extern const f32 lbl_81694450; +extern "C" void __ct__Q34nw4r2ut4RectFv(); +typedef void (*ControllerDataFunction)(); +#pragma push +#pragma section const_type ".data" +extern "C" unsigned int const lbl_816346A8[3] = {0, 0x14, 0}; +extern "C" unsigned int const lbl_816346B4[3] = {0, 0x18, 0}; +extern "C" unsigned int const lbl_816346C0[3] = {0, 0x1c, 0}; +extern "C" unsigned int const lbl_816346CC[3] = {0, 0x30, 0}; +extern "C" void __dt__Q33ipl10controller6MasterFv(); +extern "C" void getType__Q33ipl10controller9InterfaceCFv(); +extern "C" void getChannel__Q33ipl10controller9InterfaceCFv(); +extern "C" void down__Q33ipl10controller6MasterCFUl(); +extern "C" void downTrg__Q33ipl10controller6MasterCFUl(); +extern "C" void upTrg__Q33ipl10controller6MasterCFUl(); +extern "C" void pinch__Q33ipl10controller9InterfaceCFv(); +extern "C" void pinchTrg__Q33ipl10controller9InterfaceCFv(); +extern "C" void pinchOffTrg__Q33ipl10controller9InterfaceCFv(); +extern "C" void decide__Q33ipl10controller6MasterCFv(); +extern "C" void repeat__Q33ipl10controller6MasterCFUl(); +extern "C" void rumble__Q33ipl10controller9InterfaceFi(); +extern "C" void cancelRumbling__Q33ipl10controller9InterfaceFv(); +extern "C" void getHoldFlag__Q33ipl10controller9InterfaceCFv(); +extern "C" void getTrigFlag__Q33ipl10controller9InterfaceCFv(); +extern "C" void getReleaseFlag__Q33ipl10controller9InterfaceCFv(); +extern "C" void getClassicHoldFlag__Q33ipl10controller9InterfaceCFv(); +extern "C" void getClassicTrigFlag__Q33ipl10controller9InterfaceCFv(); +extern "C" void getClassicReleaseFlag__Q33ipl10controller9InterfaceCFv(); +extern "C" void getDpdPos__Q33ipl10controller9InterfaceCFv(); +extern "C" void getDpdProjectionPos__Q33ipl10controller9InterfaceCFv(); +extern "C" void getHorizon__Q33ipl10controller9InterfaceCFv(); +extern "C" void getDpdDistance__Q33ipl10controller9InterfaceCFv(); +extern "C" void getKPADStatus__Q33ipl10controller9InterfaceCFv(); +extern "C" void getPADStatus__Q33ipl10controller9InterfaceCFv(); +extern "C" void isValidBtn__Q33ipl10controller9InterfaceCFv(); +extern "C" void isValidDpd__Q33ipl10controller9InterfaceCFv(); +extern "C" void setForceInvalid__Q33ipl10controller6MasterFb(); +extern "C" void setForceInvalid__Q33ipl10controller4BaseFb(); +extern "C" void getMainStickX__Q33ipl10controller9InterfaceCFv(); +extern "C" void getMainStickY__Q33ipl10controller9InterfaceCFv(); +extern "C" void getSubStickX__Q33ipl10controller9InterfaceCFv(); +extern "C" void getSubStickY__Q33ipl10controller9InterfaceCFv(); +extern "C" void read__Q33ipl10controller9InterfaceFv(); +extern "C" void __dt__Q33ipl10controller7ClassicFv(); +extern "C" void getType__Q33ipl10controller4BaseCFv(); +extern "C" void getChannel__Q33ipl10controller4BaseCFv(); +extern "C" void down__Q33ipl10controller7ClassicCFUl(); +extern "C" void downTrg__Q33ipl10controller7ClassicCFUl(); +extern "C" void upTrg__Q33ipl10controller7ClassicCFUl(); +extern "C" void pinch__Q33ipl10controller10RevolutionCFv(); +extern "C" void pinchTrg__Q33ipl10controller10RevolutionCFv(); +extern "C" void pinchOffTrg__Q33ipl10controller10RevolutionCFv(); +extern "C" void decide__Q33ipl10controller4BaseCFv(); +extern "C" void repeat__Q33ipl10controller10RevolutionCFUl(); +extern "C" void rumble__Q33ipl10controller4BaseFi(); +extern "C" void cancelRumbling__Q33ipl10controller4BaseFv(); +extern "C" void getHoldFlag__Q33ipl10controller10RevolutionCFv(); +extern "C" void getTrigFlag__Q33ipl10controller10RevolutionCFv(); +extern "C" void getReleaseFlag__Q33ipl10controller10RevolutionCFv(); +extern "C" void getClassicHoldFlag__Q33ipl10controller7ClassicCFv(); +extern "C" void getClassicTrigFlag__Q33ipl10controller7ClassicCFv(); +extern "C" void getClassicReleaseFlag__Q33ipl10controller7ClassicCFv(); +extern "C" void getDpdPos__Q33ipl10controller7ClassicCFv(); +extern "C" void getDpdProjectionPos__Q33ipl10controller7ClassicCFv(); +extern "C" void getHorizon__Q33ipl10controller7ClassicCFv(); +extern "C" void getDpdDistance__Q33ipl10controller10RevolutionCFv(); +extern "C" void getKPADStatus__Q33ipl10controller10RevolutionCFv(); +extern "C" void isValidBtn__Q33ipl10controller10RevolutionCFv(); +extern "C" void isValidDpd__Q33ipl10controller7ClassicCFv(); +extern "C" void read__Q33ipl10controller7ClassicFv(); +extern "C" void isValidDpdClassic__Q33ipl10controller7ClassicCFv(); +extern "C" void __dt__Q33ipl10controller10RevolutionFv(); +extern "C" void down__Q33ipl10controller10RevolutionCFUl(); +extern "C" void downTrg__Q33ipl10controller10RevolutionCFUl(); +extern "C" void upTrg__Q33ipl10controller10RevolutionCFUl(); +extern "C" void getDpdPos__Q33ipl10controller10RevolutionCFv(); +extern "C" void getDpdProjectionPos__Q33ipl10controller10RevolutionCFv(); +extern "C" void getHorizon__Q33ipl10controller10RevolutionCFv(); +extern "C" void isValidDpd__Q33ipl10controller10RevolutionCFv(); +extern "C" void read__Q33ipl10controller10RevolutionFv(); +extern "C" void __dt__Q33ipl10controller4BaseFv(); +extern "C" void down__Q33ipl10controller9InterfaceCFUl(); +extern "C" void downTrg__Q33ipl10controller9InterfaceCFUl(); +extern "C" void upTrg__Q33ipl10controller9InterfaceCFUl(); +extern "C" void repeat__Q33ipl10controller9InterfaceCFUl(); +extern "C" void read__Q33ipl10controller4BaseFv(); +extern "C" void __dt__Q33ipl10controller9FreeStyleFv(); +extern "C" void __dt__Q33ipl10controller4CoreFv(); +extern "C" ControllerDataFunction const __vt__Q33ipl10controller6Master[35] = { + 0, + 0, + __dt__Q33ipl10controller6MasterFv, + getType__Q33ipl10controller9InterfaceCFv, + getChannel__Q33ipl10controller9InterfaceCFv, + down__Q33ipl10controller6MasterCFUl, + downTrg__Q33ipl10controller6MasterCFUl, + upTrg__Q33ipl10controller6MasterCFUl, + pinch__Q33ipl10controller9InterfaceCFv, + pinchTrg__Q33ipl10controller9InterfaceCFv, + pinchOffTrg__Q33ipl10controller9InterfaceCFv, + decide__Q33ipl10controller6MasterCFv, + repeat__Q33ipl10controller6MasterCFUl, + rumble__Q33ipl10controller9InterfaceFi, + cancelRumbling__Q33ipl10controller9InterfaceFv, + getHoldFlag__Q33ipl10controller9InterfaceCFv, + getTrigFlag__Q33ipl10controller9InterfaceCFv, + getReleaseFlag__Q33ipl10controller9InterfaceCFv, + getClassicHoldFlag__Q33ipl10controller9InterfaceCFv, + getClassicTrigFlag__Q33ipl10controller9InterfaceCFv, + getClassicReleaseFlag__Q33ipl10controller9InterfaceCFv, + getDpdPos__Q33ipl10controller9InterfaceCFv, + getDpdProjectionPos__Q33ipl10controller9InterfaceCFv, + getHorizon__Q33ipl10controller9InterfaceCFv, + getDpdDistance__Q33ipl10controller9InterfaceCFv, + getKPADStatus__Q33ipl10controller9InterfaceCFv, + getPADStatus__Q33ipl10controller9InterfaceCFv, + isValidBtn__Q33ipl10controller9InterfaceCFv, + isValidDpd__Q33ipl10controller9InterfaceCFv, + setForceInvalid__Q33ipl10controller6MasterFb, + getMainStickX__Q33ipl10controller9InterfaceCFv, + getMainStickY__Q33ipl10controller9InterfaceCFv, + getSubStickX__Q33ipl10controller9InterfaceCFv, + getSubStickY__Q33ipl10controller9InterfaceCFv, + read__Q33ipl10controller9InterfaceFv, +}; +extern "C" ControllerDataFunction const __vt__Q33ipl10controller7Classic[36] = { + 0, + 0, + __dt__Q33ipl10controller7ClassicFv, + getType__Q33ipl10controller4BaseCFv, + getChannel__Q33ipl10controller4BaseCFv, + down__Q33ipl10controller7ClassicCFUl, + downTrg__Q33ipl10controller7ClassicCFUl, + upTrg__Q33ipl10controller7ClassicCFUl, + pinch__Q33ipl10controller10RevolutionCFv, + pinchTrg__Q33ipl10controller10RevolutionCFv, + pinchOffTrg__Q33ipl10controller10RevolutionCFv, + decide__Q33ipl10controller4BaseCFv, + repeat__Q33ipl10controller10RevolutionCFUl, + rumble__Q33ipl10controller4BaseFi, + cancelRumbling__Q33ipl10controller4BaseFv, + getHoldFlag__Q33ipl10controller10RevolutionCFv, + getTrigFlag__Q33ipl10controller10RevolutionCFv, + getReleaseFlag__Q33ipl10controller10RevolutionCFv, + getClassicHoldFlag__Q33ipl10controller7ClassicCFv, + getClassicTrigFlag__Q33ipl10controller7ClassicCFv, + getClassicReleaseFlag__Q33ipl10controller7ClassicCFv, + getDpdPos__Q33ipl10controller7ClassicCFv, + getDpdProjectionPos__Q33ipl10controller7ClassicCFv, + getHorizon__Q33ipl10controller7ClassicCFv, + getDpdDistance__Q33ipl10controller10RevolutionCFv, + getKPADStatus__Q33ipl10controller10RevolutionCFv, + getPADStatus__Q33ipl10controller9InterfaceCFv, + isValidBtn__Q33ipl10controller10RevolutionCFv, + isValidDpd__Q33ipl10controller7ClassicCFv, + setForceInvalid__Q33ipl10controller4BaseFb, + getMainStickX__Q33ipl10controller9InterfaceCFv, + getMainStickY__Q33ipl10controller9InterfaceCFv, + getSubStickX__Q33ipl10controller9InterfaceCFv, + getSubStickY__Q33ipl10controller9InterfaceCFv, + read__Q33ipl10controller7ClassicFv, + isValidDpdClassic__Q33ipl10controller7ClassicCFv, +}; +extern "C" ControllerDataFunction const __vt__Q33ipl10controller10Revolution[35] = { + 0, + 0, + __dt__Q33ipl10controller10RevolutionFv, + getType__Q33ipl10controller4BaseCFv, + getChannel__Q33ipl10controller4BaseCFv, + down__Q33ipl10controller10RevolutionCFUl, + downTrg__Q33ipl10controller10RevolutionCFUl, + upTrg__Q33ipl10controller10RevolutionCFUl, + pinch__Q33ipl10controller10RevolutionCFv, + pinchTrg__Q33ipl10controller10RevolutionCFv, + pinchOffTrg__Q33ipl10controller10RevolutionCFv, + decide__Q33ipl10controller4BaseCFv, + repeat__Q33ipl10controller10RevolutionCFUl, + rumble__Q33ipl10controller4BaseFi, + cancelRumbling__Q33ipl10controller4BaseFv, + getHoldFlag__Q33ipl10controller10RevolutionCFv, + getTrigFlag__Q33ipl10controller10RevolutionCFv, + getReleaseFlag__Q33ipl10controller10RevolutionCFv, + getClassicHoldFlag__Q33ipl10controller9InterfaceCFv, + getClassicTrigFlag__Q33ipl10controller9InterfaceCFv, + getClassicReleaseFlag__Q33ipl10controller9InterfaceCFv, + getDpdPos__Q33ipl10controller10RevolutionCFv, + getDpdProjectionPos__Q33ipl10controller10RevolutionCFv, + getHorizon__Q33ipl10controller10RevolutionCFv, + getDpdDistance__Q33ipl10controller10RevolutionCFv, + getKPADStatus__Q33ipl10controller10RevolutionCFv, + getPADStatus__Q33ipl10controller9InterfaceCFv, + isValidBtn__Q33ipl10controller10RevolutionCFv, + isValidDpd__Q33ipl10controller10RevolutionCFv, + setForceInvalid__Q33ipl10controller4BaseFb, + getMainStickX__Q33ipl10controller9InterfaceCFv, + getMainStickY__Q33ipl10controller9InterfaceCFv, + getSubStickX__Q33ipl10controller9InterfaceCFv, + getSubStickY__Q33ipl10controller9InterfaceCFv, + read__Q33ipl10controller10RevolutionFv, +}; +extern "C" ControllerDataFunction const __vt__Q33ipl10controller4Base[36] = { + 0, + 0, + __dt__Q33ipl10controller4BaseFv, + getType__Q33ipl10controller4BaseCFv, + getChannel__Q33ipl10controller4BaseCFv, + down__Q33ipl10controller9InterfaceCFUl, + downTrg__Q33ipl10controller9InterfaceCFUl, + upTrg__Q33ipl10controller9InterfaceCFUl, + pinch__Q33ipl10controller9InterfaceCFv, + pinchTrg__Q33ipl10controller9InterfaceCFv, + pinchOffTrg__Q33ipl10controller9InterfaceCFv, + decide__Q33ipl10controller4BaseCFv, + repeat__Q33ipl10controller9InterfaceCFUl, + rumble__Q33ipl10controller4BaseFi, + cancelRumbling__Q33ipl10controller4BaseFv, + getHoldFlag__Q33ipl10controller9InterfaceCFv, + getTrigFlag__Q33ipl10controller9InterfaceCFv, + getReleaseFlag__Q33ipl10controller9InterfaceCFv, + getClassicHoldFlag__Q33ipl10controller9InterfaceCFv, + getClassicTrigFlag__Q33ipl10controller9InterfaceCFv, + getClassicReleaseFlag__Q33ipl10controller9InterfaceCFv, + getDpdPos__Q33ipl10controller9InterfaceCFv, + getDpdProjectionPos__Q33ipl10controller9InterfaceCFv, + getHorizon__Q33ipl10controller9InterfaceCFv, + getDpdDistance__Q33ipl10controller9InterfaceCFv, + getKPADStatus__Q33ipl10controller9InterfaceCFv, + getPADStatus__Q33ipl10controller9InterfaceCFv, + isValidBtn__Q33ipl10controller9InterfaceCFv, + isValidDpd__Q33ipl10controller9InterfaceCFv, + setForceInvalid__Q33ipl10controller4BaseFb, + getMainStickX__Q33ipl10controller9InterfaceCFv, + getMainStickY__Q33ipl10controller9InterfaceCFv, + getSubStickX__Q33ipl10controller9InterfaceCFv, + getSubStickY__Q33ipl10controller9InterfaceCFv, + read__Q33ipl10controller4BaseFv, + 0, +}; +extern "C" ControllerDataFunction const __vt__Q33ipl10controller9FreeStyle[35] = { + 0, + 0, + __dt__Q33ipl10controller9FreeStyleFv, + getType__Q33ipl10controller4BaseCFv, + getChannel__Q33ipl10controller4BaseCFv, + down__Q33ipl10controller10RevolutionCFUl, + downTrg__Q33ipl10controller10RevolutionCFUl, + upTrg__Q33ipl10controller10RevolutionCFUl, + pinch__Q33ipl10controller10RevolutionCFv, + pinchTrg__Q33ipl10controller10RevolutionCFv, + pinchOffTrg__Q33ipl10controller10RevolutionCFv, + decide__Q33ipl10controller4BaseCFv, + repeat__Q33ipl10controller10RevolutionCFUl, + rumble__Q33ipl10controller4BaseFi, + cancelRumbling__Q33ipl10controller4BaseFv, + getHoldFlag__Q33ipl10controller10RevolutionCFv, + getTrigFlag__Q33ipl10controller10RevolutionCFv, + getReleaseFlag__Q33ipl10controller10RevolutionCFv, + getClassicHoldFlag__Q33ipl10controller9InterfaceCFv, + getClassicTrigFlag__Q33ipl10controller9InterfaceCFv, + getClassicReleaseFlag__Q33ipl10controller9InterfaceCFv, + getDpdPos__Q33ipl10controller10RevolutionCFv, + getDpdProjectionPos__Q33ipl10controller10RevolutionCFv, + getHorizon__Q33ipl10controller10RevolutionCFv, + getDpdDistance__Q33ipl10controller10RevolutionCFv, + getKPADStatus__Q33ipl10controller10RevolutionCFv, + getPADStatus__Q33ipl10controller9InterfaceCFv, + isValidBtn__Q33ipl10controller10RevolutionCFv, + isValidDpd__Q33ipl10controller10RevolutionCFv, + setForceInvalid__Q33ipl10controller4BaseFb, + getMainStickX__Q33ipl10controller9InterfaceCFv, + getMainStickY__Q33ipl10controller9InterfaceCFv, + getSubStickX__Q33ipl10controller9InterfaceCFv, + getSubStickY__Q33ipl10controller9InterfaceCFv, + read__Q33ipl10controller10RevolutionFv, +}; +extern "C" ControllerDataFunction const __vt__Q33ipl10controller4Core[35] = { + 0, + 0, + __dt__Q33ipl10controller4CoreFv, + getType__Q33ipl10controller4BaseCFv, + getChannel__Q33ipl10controller4BaseCFv, + down__Q33ipl10controller10RevolutionCFUl, + downTrg__Q33ipl10controller10RevolutionCFUl, + upTrg__Q33ipl10controller10RevolutionCFUl, + pinch__Q33ipl10controller10RevolutionCFv, + pinchTrg__Q33ipl10controller10RevolutionCFv, + pinchOffTrg__Q33ipl10controller10RevolutionCFv, + decide__Q33ipl10controller4BaseCFv, + repeat__Q33ipl10controller10RevolutionCFUl, + rumble__Q33ipl10controller4BaseFi, + cancelRumbling__Q33ipl10controller4BaseFv, + getHoldFlag__Q33ipl10controller10RevolutionCFv, + getTrigFlag__Q33ipl10controller10RevolutionCFv, + getReleaseFlag__Q33ipl10controller10RevolutionCFv, + getClassicHoldFlag__Q33ipl10controller9InterfaceCFv, + getClassicTrigFlag__Q33ipl10controller9InterfaceCFv, + getClassicReleaseFlag__Q33ipl10controller9InterfaceCFv, + getDpdPos__Q33ipl10controller10RevolutionCFv, + getDpdProjectionPos__Q33ipl10controller10RevolutionCFv, + getHorizon__Q33ipl10controller10RevolutionCFv, + getDpdDistance__Q33ipl10controller10RevolutionCFv, + getKPADStatus__Q33ipl10controller10RevolutionCFv, + getPADStatus__Q33ipl10controller9InterfaceCFv, + isValidBtn__Q33ipl10controller10RevolutionCFv, + isValidDpd__Q33ipl10controller10RevolutionCFv, + setForceInvalid__Q33ipl10controller4BaseFb, + getMainStickX__Q33ipl10controller9InterfaceCFv, + getMainStickY__Q33ipl10controller9InterfaceCFv, + getSubStickX__Q33ipl10controller9InterfaceCFv, + getSubStickY__Q33ipl10controller9InterfaceCFv, + read__Q33ipl10controller10RevolutionFv, +}; +#pragma pop +extern const f32 lbl_81694440 = 1000.0f; +extern const f32 lbl_81694444 = 0.058333333f; +extern const f64 lbl_81694448 = 4503599627370496.0; +extern const f32 lbl_81694450 = 1.0f / 0.0f; extern const f32 lbl_81694454 = 0.0f; -extern const f32 lbl_81694458; -extern const f32 lbl_8169445C; -extern const f32 lbl_81694460; -extern const f32 lbl_81694478; -extern const f32 lbl_8169447C; -extern const f32 lbl_81694480; -extern const f32 lbl_81694484; -extern const f32 lbl_81694488; -extern const f32 lbl_8169448C; +extern const f32 lbl_81694458 = 1.10132003f; +extern const f32 lbl_8169445C = 1.15f; +extern const f32 lbl_81694460 = 100.0f; +extern const f32 lbl_81694464 = 0.01f; +extern const f32 lbl_81694468 = 0.0036f; +extern const f32 lbl_8169446C = 0.05f; +extern const f32 lbl_81694470 = 1.0f; +extern const f32 lbl_81694474 = -0.2679492f; +extern const f32 lbl_81694478 = 0.5f; +extern const f32 lbl_8169447C = 0.1f; +extern const f32 lbl_81694480 = 0.2f; +extern const f32 lbl_81694484 = -0.2f; +extern const f32 lbl_81694488 = 0.05f; +extern const f32 lbl_8169448C = 1.0f; extern "C" void* mpBuf__Q33ipl10controller7Manager = 0; extern "C" void* mpParentHeap__Q33ipl10controller7Manager = 0; extern "C" void* mpHeap__Q33ipl10controller7Manager = 0; @@ -42,16 +362,11 @@ extern "C" void _restgpr_28(); extern "C" void __ptmf_scall(); extern "C" void __ct__Q33ipl4math4VEC2Fff(); extern "C" void set__Q33ipl4math4VEC2Fff(); -extern "C" void __vt__Q33ipl10controller4Base(); -extern "C" void __vt__Q33ipl10controller10Revolution(); extern "C" void __dt__Q33ipl10controller10RevolutionFv(); extern "C" void read__Q33ipl10controller4BaseFv(); extern "C" void isValidDpd__Q33ipl10controller10RevolutionCFv(); extern "C" void getProjectionRect__Q23ipl6SystemFPQ34nw4r2ut4Rect(); extern "C" void __as__Q33ipl4math4VEC2FRCQ33ipl4math4VEC2(); -extern "C" void __vt__Q33ipl10controller6Master(); -extern "C" void __vt__Q33ipl10controller4Core(); -extern "C" void __vt__Q33ipl10controller9FreeStyle(); extern "C" void __ct__Q33ipl10controller10RevolutionFiiR10KPADStatus(); extern "C" void __ct__Q33ipl10controller7ClassicFiR10KPADStatus(); extern "C" asm void alloc__Q33ipl10controller7ManagerFUl(); @@ -624,8 +939,8 @@ namespace ipl { case 0: case 1: { u32 time = OSTicksToMilliseconds(OSGetTick() - mLastRumbleTime); - f32 f1 = (f32)time / 1000.0f; - if (f1 < 7.0f / 120.0f) { + f32 f1 = (f32)time / lbl_81694440; + if (f1 < lbl_81694444) { WPADControlMotor(mChan, 1); } else if (f1 < lbl_8160D2C0[mRumbleType]) { WPADControlMotor(mChan, 0); @@ -642,7 +957,7 @@ namespace ipl { } case 2: { u32 time = OSTicksToMilliseconds(OSGetTick() - mLastRumbleTime); - f32 f1 = (f32)time / 1000.0f; + f32 f1 = (f32)time / lbl_81694440; if (f1 < lbl_8160D2C0[1]) { WPADControlMotor(mChan, 0); } else if (getKPADStatus() == NULL || getKPADStatus()->wpad_err == 0) { @@ -1353,21 +1668,21 @@ namespace ipl { kpad_rect.right = nw4r_rect.right; kpad_rect.bottom = nw4r_rect.bottom; - KPADGetProjectionPos(&dest, &src, &kpad_rect, 1.10132f); + KPADGetProjectionPos(&dest, &src, &kpad_rect, lbl_81694458); if (SCGetAspectRatio() == 1) { - dest.x *= 1.15f; - dest.y *= 1.15f; + dest.x *= lbl_8169445C; + dest.y *= lbl_8169445C; } // regswap - if (nw4r_rect.left - 100.0f > dest.x) { - dest.x = nw4r_rect.left - 100.0f; - } else if (nw4r_rect.right + 100.0f < dest.x) { - dest.x = nw4r_rect.right + 100.0f; - } else if (nw4r_rect.top - 100.0f > dest.y) { - dest.y = nw4r_rect.top - 100.0f; - } else if (nw4r_rect.bottom + 100.0f < dest.y) { - dest.y = nw4r_rect.bottom + 100.0f; + if (nw4r_rect.left - lbl_81694460 > dest.x) { + dest.x = nw4r_rect.left - lbl_81694460; + } else if (nw4r_rect.right + lbl_81694460 < dest.x) { + dest.x = nw4r_rect.right + lbl_81694460; + } else if (nw4r_rect.top - lbl_81694460 > dest.y) { + dest.y = nw4r_rect.top - lbl_81694460; + } else if (nw4r_rect.bottom + lbl_81694460 < dest.y) { + dest.y = nw4r_rect.bottom + lbl_81694460; } // // @@ -1377,8 +1692,8 @@ namespace ipl { } Classic::Classic(int arg0, KPADStatus& arg1) : Revolution(arg0, arg1) { - unk_0x24.x = 0.01f; - unk_0x24.y = 0.01f; + unk_0x24.x = lbl_81694464; + unk_0x24.y = lbl_81694464; unk_0x2C = 0; } @@ -1395,14 +1710,14 @@ namespace ipl { if (!Revolution::isValidDpd()) { math::VEC2 lstick(unk_0x20->ex_status.cl.lstick.x, unk_0x20->ex_status.cl.lstick.y); - if (lstick.x * lstick.x + lstick.y * lstick.y > 0.0036f) { - unk_0x24.x = math::abs_clamp(unk_0x24.x + unk_0x20->ex_status.cl.lstick.x * 0.05f, 1.8f); - unk_0x24.y = math::abs_clamp(unk_0x24.y - unk_0x20->ex_status.cl.lstick.y * 0.05f, 1.2f); + if (lstick.x * lstick.x + lstick.y * lstick.y > lbl_81694468) { + unk_0x24.x = math::abs_clamp(unk_0x24.x + unk_0x20->ex_status.cl.lstick.x * lbl_8169446C, 1.8f); + unk_0x24.y = math::abs_clamp(unk_0x24.y - unk_0x20->ex_status.cl.lstick.y * lbl_8169446C, 1.2f); } math::VEC2 rstick = math::VEC2(unk_0x20->ex_status.cl.rstick.x, unk_0x20->ex_status.cl.rstick.y); - if (getClassicHoldFlag() != 0 || lstick.x * lstick.x + lstick.y * lstick.y > 0.0036f || - rstick.x * rstick.x + rstick.y * rstick.y > 0.0036f) { + if (getClassicHoldFlag() != 0 || lstick.x * lstick.x + lstick.y * lstick.y > lbl_81694468 || + rstick.x * rstick.x + rstick.y * rstick.y > lbl_81694468) { unk_0x2C = 180; } @@ -1410,8 +1725,8 @@ namespace ipl { unk_0x2C = 0; } } else { - unk_0x24.y = 0.01f; - unk_0x24.x = 0.01f; + unk_0x24.y = lbl_81694464; + unk_0x24.x = lbl_81694464; unk_0x2C = 0; } @@ -1448,7 +1763,7 @@ namespace ipl { ret.set(unk_0x20->horizon.x, unk_0x20->horizon.y); } else { ret.x = 1.0f; - ret.y = -0.2679492f; + ret.y = lbl_81694474; } return ret; } -- 2.49.1 From b5423d68157c41f5d3b2e5595b66680142fd879f Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:06:19 -0500 Subject: [PATCH 07/21] Match MSL ansi files (#85) --- configure.py | 2 +- libs/MSL/src/MSL_Common/ansi_files.c | 123 +++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 libs/MSL/src/MSL_Common/ansi_files.c diff --git a/configure.py b/configure.py index 610214a7..62e6e5ca 100644 --- a/configure.py +++ b/configure.py @@ -1942,7 +1942,7 @@ config.libs = [ MSLLib("MSL_C.PPCEABI.bare.H", [ Object(NonMatching, "MSL_Common/alloc.c"), Object(Matching, "MSL_Common/errno.c"), - Object(NonMatching, "MSL_Common/ansi_files.c"), + Object(Matching, "MSL_Common/ansi_files.c"), Object(NonMatching, "MSL_Common_Embedded/ansi_fp.c"), Object(Matching, "MSL_Common/ctype.c"), Object(NonMatching, "MSL_Common/locale.c"), diff --git a/libs/MSL/src/MSL_Common/ansi_files.c b/libs/MSL/src/MSL_Common/ansi_files.c new file mode 100644 index 00000000..0533ec96 --- /dev/null +++ b/libs/MSL/src/MSL_Common/ansi_files.c @@ -0,0 +1,123 @@ +#include +#include + +extern int __read_console(unsigned long, unsigned char*, size_t*, void*); +extern int __write_console(unsigned long, unsigned char*, size_t*, void*); +extern int __close_console(unsigned long); + +#pragma exceptions on + +unsigned char stdin_buff[0x100]; +unsigned char stdout_buff[0x100]; +unsigned char stderr_buff[0x100]; + +FILE __files[4] = { + { + 0, + {0, 1, 1, 2, 0, 0}, + {0, 0, 0, 0}, + 0, + 0, + 0, + {0, 0}, + {0, 0}, + 0, + stdin_buff, + 0x100, + stdin_buff, + 0, + 0, + 0, + 0, + 0, + __read_console, + __write_console, + __close_console, + 0, + &__files[1], + }, + { + 1, + {0, 2, 1, 2, 0, 0}, + {0, 0, 0, 0}, + 0, + 0, + 0, + {0, 0}, + {0, 0}, + 0, + stdout_buff, + 0x100, + stdout_buff, + 0, + 0, + 0, + 0, + 0, + __read_console, + __write_console, + __close_console, + 0, + &__files[2], + }, + { + 2, + {0, 2, 0, 2, 0, 0}, + {0, 0, 0, 0}, + 0, + 0, + 0, + {0, 0}, + {0, 0}, + 0, + stderr_buff, + 0x100, + stderr_buff, + 0, + 0, + 0, + 0, + 0, + __read_console, + __write_console, + __close_console, + 0, + &__files[3], + }, + {0}, +}; + +void __close_all(void) { + FILE* file; + FILE* current; + + for (file = __files; file != 0;) { + if (file->mode.file_kind != 0) { + fclose(file); + } + + current = file; + file = file->next_file; + if (current->is_dyn_alloc != 0) { + free(current); + } else { + current->mode.file_kind = 3; + if (file != 0 && file->is_dyn_alloc != 0) { + current->next_file = 0; + } + } + } +} + +int __flush_all(void) { + int result = 0; + FILE* file; + + for (file = __files; file != 0; file = file->next_file) { + if (file->mode.file_kind != 0 && fflush(file) != 0) { + result = -1; + } + } + + return result; +} -- 2.49.1 From 39c8fe9e3aec95076724db4ede7e56f62d72de51 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:08:09 -0500 Subject: [PATCH 08/21] Match WPAD storage and SDA layout (#86) * Match WPAD BSS storage layout * Match WPAD SDA operands --- .../include/private/wpad/WPADInternal.h | 7 ++- libs/RVL_SDK/src/wpad/WPAD.c | 58 +++++++++---------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/libs/RVL_SDK/include/private/wpad/WPADInternal.h b/libs/RVL_SDK/include/private/wpad/WPADInternal.h index 8e2a5849..3661b400 100644 --- a/libs/RVL_SDK/include/private/wpad/WPADInternal.h +++ b/libs/RVL_SDK/include/private/wpad/WPADInternal.h @@ -247,7 +247,12 @@ typedef struct WPADCB { u8 unk_0x98F[0x9A0 - 0x990]; } WPADCB; -extern WPADCB _wpd[WPAD_MAX_CONTROLLERS]; +typedef struct WPADStorage { + WPADCB controllers[WPAD_MAX_CONTROLLERS]; + u8 unk_0x26C0[0x48]; +} WPADStorage; + +extern WPADStorage _wpd; extern WPADCB* _wpdcb[WPAD_MAX_CONTROLLERS]; void WPADiInitSub(); diff --git a/libs/RVL_SDK/src/wpad/WPAD.c b/libs/RVL_SDK/src/wpad/WPAD.c index 7429e99e..894cec93 100644 --- a/libs/RVL_SDK/src/wpad/WPAD.c +++ b/libs/RVL_SDK/src/wpad/WPAD.c @@ -31,7 +31,7 @@ char lbl_81687720[] = "<< RVL_SDK - WPAD \trelease build: Apr 20 2010 11:20:55 (0x4199_60831) >>"; const char* __WPADVersion = lbl_81687720; -WPADCB _wpd[WPAD_MAX_CONTROLLERS]; +WPADStorage _wpd; WPADCB* _wpdcb[WPAD_MAX_CONTROLLERS]; u8 __WPADiManageHandlerStack[0x1000] ALIGN32; @@ -636,30 +636,30 @@ static asm void WPADiManageHandler(OSAlarm* pAlarm, OSContext* pContext) { beq WPADiManageHandler_8AC8 cmpwi r3, 0x2 bne WPADiManageHandler_91D8 - lwz r0, _initialized(r13) + lwz r0, _initialized(r0) cmpwi r0, 0x0 bne WPADiManageHandler_91D8 li r0, 0x1 lis r3, WPADiConnCallback@ha - stw r0, _initialized(r13) + stw r0, _initialized(r0) addi r3, r3, WPADiConnCallback@l bl WUDSetHidConnCallback lis r3, WPADiRecvCallback@ha addi r3, r3, WPADiRecvCallback@l bl WUDSetHidRecvCallback li r0, 0x32 - stw r0, _recCnt(r13) + stw r0, _recCnt(r0) b WPADiManageHandler_91D8 WPADiManageHandler_8AC8: - lwz r4, _recCnt(r13) - lwz r19, _recFlag(r13) + lwz r4, _recCnt(r0) + lwz r19, _recFlag(r0) cntlzw r3, r4 subi r0, r4, 0x1 extrwi r3, r3, 1, 26 cmpwi r19, 0x0 neg r3, r3 andc r0, r0, r3 - stw r0, _recCnt(r13) + stw r0, _recCnt(r0) blt WPADiManageHandler_8B28 cmpwi r0, 0x0 bne WPADiManageHandler_91D8 @@ -1001,13 +1001,13 @@ WPADiManageHandler_8FC8: WPADiManageHandler_8FCC: stb r0, 0x0(r23) WPADiManageHandler_8FD0: - lbz r0, _checkCnt(r13) + lbz r0, _checkCnt(r0) cmplwi r0, 0x5 bne WPADiManageHandler_8FE4 mr r3, r22 bl WPADiCheckContInputs WPADiManageHandler_8FE4: - lhz r0, _senseCnt(r13) + lhz r0, _senseCnt(r0) cmplwi r0, 0xa bne WPADiManageHandler_8FF8 mr r3, r22 @@ -1026,7 +1026,7 @@ WPADiManageHandler_900C: addi r24, r24, 0x4 addi r23, r23, 0x1 blt WPADiManageHandler_8B48 - lhz r0, _afhCnt(r13) + lhz r0, _afhCnt(r0) cmplwi r0, 0xea60 bne WPADiManageHandler_9090 lis r21, 0x8000 @@ -1036,31 +1036,31 @@ WPADiManageHandler_900C: addi r3, r28, 0x108 crclr 4*cr1+eq bl DEBUGPrint - lbz r3, _afhChannel(r13) + lbz r3, _afhChannel(r0) lbz r0, 0x31a2(r21) extsb r3, r3 cmpw r3, r0 beq WPADiManageHandler_9090 bl OSDisableInterrupts lbz r0, 0x31a2(r21) - stb r0, _afhChannel(r13) + stb r0, _afhChannel(r0) bl OSRestoreInterrupts lbz r4, 0x31a2(r21) addi r3, r28, 0x130 crclr 4*cr1+eq bl DEBUGPrint - lbz r0, _afhChannel(r13) + lbz r0, _afhChannel(r0) extsb r3, r0 bl WUDSetDisableChannel WPADiManageHandler_9090: - lhz r6, _senseCnt(r13) + lhz r6, _senseCnt(r0) lis r3, 0x1 subi r0, r3, 0x15a0 - lbz r9, _checkCnt(r13) + lbz r9, _checkCnt(r0) subi r4, r6, 0xa subfic r3, r6, 0xa nor r3, r4, r3 - lhz r10, _afhCnt(r13) + lhz r10, _afhCnt(r0) srawi r8, r3, 31 addi r7, r6, 0x1 clrlwi r0, r0, 16 @@ -1070,7 +1070,7 @@ WPADiManageHandler_9090: nor r5, r4, r3 subf r4, r0, r10 subf r3, r10, r0 - lbz r0, _scFlush(r13) + lbz r0, _scFlush(r0) srawi r6, r5, 31 addi r5, r9, 0x1 nor r4, r4, r3 @@ -1079,9 +1079,9 @@ WPADiManageHandler_9090: andc r5, r5, r6 andc r3, r3, r4 cmpwi r0, 0x0 - sth r7, _senseCnt(r13) - stb r5, _checkCnt(r13) - sth r3, _afhCnt(r13) + sth r7, _senseCnt(r0) + stb r5, _checkCnt(r0) + sth r3, _afhCnt(r0) beq WPADiManageHandler_9138 bl SCCheckStatus cmpwi r3, 0x0 @@ -1094,9 +1094,9 @@ WPADiManageHandler_9090: li r3, 0x0 bl SCFlushAsync li r0, 0x0 - stb r0, _scFlush(r13) + stb r0, _scFlush(r0) WPADiManageHandler_9138: - lbz r0, _scSetting(r13) + lbz r0, _scSetting(r0) cmpwi r0, 0x0 beq WPADiManageHandler_91D4 bl SCCheckStatus @@ -1112,19 +1112,19 @@ WPADiManageHandler_9164: ble WPADiManageHandler_9170 li r0, 0x5 WPADiManageHandler_9170: - stb r0, _dpdSensitivity(r13) + stb r0, _dpdSensitivity(r0) bl SCGetWpadSensorBarPosition clrlwi r3, r3, 24 subi r0, r3, 0x1 cntlzw r0, r0 extrwi r0, r0, 8, 19 - stb r0, _sensorBarPos(r13) + stb r0, _sensorBarPos(r0) bl SCGetWpadMotorMode clrlwi r3, r3, 24 subi r0, r3, 0x1 cntlzw r0, r0 srwi r0, r0, 5 - stw r0, _rumble(r13) + stw r0, _rumble(r0) bl SCGetWpadSpeakerVolume clrlwi. r0, r3, 24 mr r4, r3 @@ -1137,8 +1137,8 @@ WPADiManageHandler_91B8: li r4, 0x7f WPADiManageHandler_91C8: li r0, 0x0 - stb r4, _speakerVolume(r13) - stb r0, _scSetting(r13) + stb r4, _speakerVolume(r0) + stb r0, _scSetting(r0) WPADiManageHandler_91D4: bl BTA_HhGetAclQueueInfo WPADiManageHandler_91D8: @@ -1338,12 +1338,12 @@ void WPADiInitSub() { DEBUGPrint("WPADInit()\n"); for (chan = 0; chan < WPAD_MAX_CONTROLLERS; chan++) { - _wpdcb[chan] = &_wpd[chan]; + _wpdcb[chan] = &_wpd.controllers[chan]; _chan_active_state[chan] = FALSE; _wpdcb[chan]->connectCB = NULL; __ClearControlBlock(chan); - OSInitThreadQueue(&_wpd[chan].threadQueue); + OSInitThreadQueue(&_wpd.controllers[chan].threadQueue); _extCnt[chan] = 0; _rumbleCnt[chan] = 0; -- 2.49.1 From e505b1cf9e48d5f360dcef0090e9ce22d62d14f2 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:10:16 -0500 Subject: [PATCH 09/21] Require complete data gates for workers (#87) --- AGENTS.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 9f907cec..c1bea7fd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -176,7 +176,10 @@ Workers iterate until exact-name `objdiff` reports `100.0%`. They must not stop at a fuzzy score, push, open a PR, or merge. A local commit is fine. Compiler tie-breaks should be reported with evidence, not hidden behind artificial assembly or uninitialized values. Exact matching is the handoff point, not -acceptance. +acceptance. A candidate is incomplete until every owned code and data section +and its link metrics are 100%; matching a few functions alone is not enough. +Write new matches as readable C or C++ and keep new inline assembly out of the +source unless the existing target structure makes it unavoidable. Worker measurements are advisory. Only a fresh orchestrator verification can accept, push, open, or merge a candidate. Workers are persistent across @@ -195,9 +198,11 @@ The orchestrator must independently rebuild the owned object and verify: 1. `pool_diff.py` reports identical pools, with no first divergence. 2. Exact-name `objdiff` reports `100.0%` for the requested symbol. 3. `ctxdiff.py` reports `diffs 0` and identical instruction counts. -4. The focused source diff is minimal, readable, and free of artificial +4. Unit-level code, data, function, and link measures for the owned range are + 100%, including every owned section. +5. The focused source diff is minimal, readable, and free of artificial assembly, uninitialized values, or unrelated edits. -5. The full 4.3U build passes and `build/43U/main.dol` has SHA1 +6. The full 4.3U build passes and `build/43U/main.dol` has SHA1 `26116613f624061ba99c8d1a299aaa6efa85670d`. If any orchestrator gate fails, do not promote, push, open a PR, or merge the -- 2.49.1 From 7c26f15caa4ecca44a74ed12bccdfca83cc299e1 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:13:23 -0500 Subject: [PATCH 10/21] Match systemmenu CSPane (#88) --- src/channelScript/systemmenu/iplCSPane.cpp | 44 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/channelScript/systemmenu/iplCSPane.cpp b/src/channelScript/systemmenu/iplCSPane.cpp index 94b6af3e..64c0a2e0 100644 --- a/src/channelScript/systemmenu/iplCSPane.cpp +++ b/src/channelScript/systemmenu/iplCSPane.cpp @@ -1,3 +1,22 @@ +#include +#include + +extern "C" const char lbl_8166A6E3[]; +extern "C" const u8 lbl_81697844; +extern "C" const u8 lbl_81697845; +extern "C" const u8 lbl_81697846; +extern "C" const u8 lbl_81697847; + +#define NW4R_DB_ASSERT_H +#define NW4R_ASSERT(x) \ + { \ + if (!(x)) { \ + GXColor front = {lbl_81697844, lbl_81697845, lbl_81697846, lbl_81697847}; \ + GXColor back = {0, 0, 0, 0}; \ + OSFatal((GXColor)front, (GXColor)back, lbl_8166A6E3); \ + } \ + } + #include "channelScript/iplCSLibrary.h" #include "iplSystem.h" @@ -10,7 +29,9 @@ #include "math/iplMathTypes.h" -extern f32 lbl_81694FC0; +extern "C" const f32 lbl_81694FC0 = 0.0f; + +extern "C" nw4r::ut::Color GetTextColor__Q34nw4r3lyt7TextBoxCFUl(const nw4r::lyt::TextBox*, u32); namespace ipl { namespace cs { @@ -393,7 +414,7 @@ namespace ipl { CHANSVmObjHdr* arg = CHANSVmGetArgInteger(VmInst, 0); if (box != NULL && argc == 1 && arg != NULL) { if (arg->value.int_v < 4ULL) { - result = color::_ctor(VmInst, VmReturnObj, (nw4r::ut::Color) static_cast(box->GetTextColor(arg->value.int_v))) == TRUE; + result = color::_ctor(VmInst, VmReturnObj, (nw4r::ut::Color) static_cast(GetTextColor__Q34nw4r3lyt7TextBoxCFUl(box, arg->value.int_v))) == TRUE; } } } @@ -595,3 +616,22 @@ namespace ipl { } // namespace pane } // namespace cs } // namespace ipl + +namespace ipl { + namespace cs { + namespace pane { +#pragma push +#pragma section const_type ".data" + extern "C" const char lbl_8166A6E3[] = "Error#004\nAn error has occurred.\nThe system files are corrupted."; +#pragma pop + +#pragma push +#pragma section data_type ".sdata" + extern "C" __declspec(section ".sdata") const u8 lbl_81697844 = 0xff; + extern "C" __declspec(section ".sdata") const u8 lbl_81697845 = 0xff; + extern "C" __declspec(section ".sdata") const u8 lbl_81697846 = 0xff; + extern "C" __declspec(section ".sdata") const u8 lbl_81697847 = 0; +#pragma pop + } + } +} -- 2.49.1 From cc637c0b190ced3b28278e60dd9346f6fd09f270 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:15:28 -0500 Subject: [PATCH 11/21] Match MSL allocator (#89) --- configure.py | 2 +- libs/MSL/src/MSL_Common/alloc.c | 888 ++++++++++++++++++++++++-------- 2 files changed, 681 insertions(+), 209 deletions(-) diff --git a/configure.py b/configure.py index 62e6e5ca..51438b02 100644 --- a/configure.py +++ b/configure.py @@ -1940,7 +1940,7 @@ config.libs = [ ), # MSL Library MSLLib("MSL_C.PPCEABI.bare.H", [ - Object(NonMatching, "MSL_Common/alloc.c"), + Object(Matching, "MSL_Common/alloc.c"), Object(Matching, "MSL_Common/errno.c"), Object(Matching, "MSL_Common/ansi_files.c"), Object(NonMatching, "MSL_Common_Embedded/ansi_fp.c"), diff --git a/libs/MSL/src/MSL_Common/alloc.c b/libs/MSL/src/MSL_Common/alloc.c index 350b3570..33b79964 100644 --- a/libs/MSL/src/MSL_Common/alloc.c +++ b/libs/MSL/src/MSL_Common/alloc.c @@ -3,144 +3,151 @@ #pragma exceptions on extern void __sys_free(void* ptr); - -typedef struct Block { - struct Block* prev; - struct Block* next; - unsigned int max_size; - unsigned int size; -} Block; - -typedef struct SubBlock { - unsigned int size; - Block* block; - struct SubBlock* prev; - struct SubBlock* next; -} SubBlock; - -struct FixSubBlock; - -typedef struct FixBlock { - struct FixBlock* prev_; - struct FixBlock* next_; - unsigned int client_size_; - struct FixSubBlock* start_; - unsigned int n_allocated_; -} FixBlock; - -typedef struct FixSubBlock { - FixBlock* block_; - struct FixSubBlock* next_; -} FixSubBlock; - -typedef struct FixStart { - FixBlock* tail_; - FixBlock* head_; -} FixStart; - -typedef struct __mem_pool_obj { - Block* start_; - FixStart fix_start[6]; -} __mem_pool_obj; +extern void* __sys_alloc(unsigned int size); typedef struct __mem_pool { void* reserved[14]; } __mem_pool; -typedef int tag_word; +typedef struct Block { + struct Block* pPrev; + struct Block* pNext; + unsigned int maxSize; + unsigned int size; +} Block; -typedef struct block_header { - tag_word tag; - struct block_header* prev; - struct block_header* next; -} block_header; +typedef struct SubBlock { + unsigned int size; + Block* pBlock; + struct SubBlock* pPrev; + struct SubBlock* pNext; +} SubBlock; -typedef struct list_header { - block_header* rover; - block_header header; -} list_header; +struct FixSubBlock; -typedef struct heap_header { - struct heap_header* prev; - struct heap_header* next; -} heap_header; +typedef struct FixBlock { + struct FixBlock* pPrev; + struct FixBlock* pNext; + unsigned int clientSize; + struct FixSubBlock* pStart; + unsigned int allocatedSize; +} FixBlock; -struct mem_pool_obj; -typedef void* (*sys_alloc_ptr)(unsigned int, struct mem_pool_obj*); -typedef void (*sys_free_ptr)(void*, struct mem_pool_obj*); +typedef struct FixSubBlock { + FixBlock* pBlock; + struct FixSubBlock* pNext; +} FixSubBlock; -typedef struct pool_options { - sys_alloc_ptr sys_alloc_func; - sys_free_ptr sys_free_func; - unsigned int min_heap_size; - int always_search_first; -} pool_options; +typedef struct FixStart { + FixBlock* pTail; + FixBlock* pHead; +} FixStart; -typedef struct mem_pool_obj { - list_header free_list; - pool_options options; - heap_header* heap_list; - void* userData; - -} mem_pool_obj; - -mem_pool_obj __malloc_pool; -static int initialized = 0; +typedef struct __mem_pool_obj { + Block* pStart; + FixStart fixStart[6]; +} __mem_pool_obj; static SubBlock* SubBlock_merge_prev(SubBlock*, SubBlock**); static void SubBlock_merge_next(SubBlock*, SubBlock**); +static SubBlock* Block_subBlock(Block*, unsigned int, unsigned int*); +static void* allocate_from_var_pools(__mem_pool_obj*, unsigned int, unsigned int*); +static void* soft_allocate_from_var_pools(__mem_pool_obj*, unsigned int, unsigned int*); +static void FixBlock_construct(FixBlock*, FixBlock*, FixBlock*, unsigned int, void*, unsigned int); +static void* allocate_from_fixed_pools(__mem_pool_obj*, unsigned int, unsigned int*); +static unsigned int __pool_allocate_resize(__mem_pool_obj*, void*, unsigned int, unsigned int*); -static const unsigned int fix_pool_sizes[] = {4, 12, 20, 36, 52, 68}; +const unsigned int fix_pool_sizes[] = {4, 12, 20, 36, 52, 68}; #define SubBlock_size(ths) ((ths)->size & 0xFFFFFFF8) -#define SubBlock_block(ths) ((Block*)((unsigned int)((ths)->block) & ~0x1)) +#define SubBlock_block(ths) ((Block*)((unsigned int)((ths)->pBlock) & ~0x1)) #define Block_size(ths) ((ths)->size & 0xFFFFFFF8) #define Block_start(ths) (*(SubBlock**)((char*)(ths) + Block_size((ths)) - sizeof(unsigned int))) #define SubBlock_set_free(ths) \ unsigned int this_size = SubBlock_size((ths)); \ (ths)->size &= ~0x2; \ - *(unsigned int*)((char*)(ths) + this_size) &= ~0x4; \ + ((SubBlock*)((char*)(ths) + this_size))->size &= ~0x4; \ *(unsigned int*)((char*)(ths) + this_size - sizeof(unsigned int)) = this_size #define SubBlock_is_free(ths) !((ths)->size & 2) #define SubBlock_set_size(ths, sz) \ (ths)->size &= ~0xFFFFFFF8; \ (ths)->size |= (sz) & 0xFFFFFFF8; \ - if (SubBlock_is_free((ths))) \ - *(unsigned int*)((char*)(ths) + (sz) - sizeof(unsigned int)) = (sz) + if (SubBlock_is_free((ths))) { \ + *(unsigned int*)((char*)(ths) + (sz) - sizeof(unsigned int)) = (sz); \ + } #define SubBlock_from_pointer(ptr) ((SubBlock*)((char*)(ptr) - 8)) #define FixSubBlock_from_pointer(ptr) ((FixSubBlock*)((char*)(ptr) - 4)) -#define FixBlock_client_size(ths) ((ths)->client_size_) -#define FixSubBlock_size(ths) (FixBlock_client_size((ths)->block_)) +#define FixBlock_client_size(ths) ((ths)->clientSize) +#define FixSubBlock_size(ths) (FixBlock_client_size((ths)->pBlock)) -#define classify(ptr) (*(unsigned int*)((char*)(ptr) - sizeof(unsigned int)) & 1) +#define classify(ptr) ((unsigned int)FixSubBlock_from_pointer(ptr)->pBlock & 1) #define __msize_inline(ptr) (!classify(ptr) ? FixSubBlock_size(FixSubBlock_from_pointer(ptr)) : SubBlock_size(SubBlock_from_pointer(ptr)) - 8) -#define Block_empty(ths) (_sb = (SubBlock*)((char*)(ths) + 16)), SubBlock_is_free(_sb) && SubBlock_size(_sb) == Block_size((ths)) - 24 +#define Block_empty(ths) (_sb = (SubBlock*)(ths + 1)), SubBlock_is_free(_sb) && SubBlock_size(_sb) == Block_size((ths)) - 24 -void Block_link(Block* ths, SubBlock* sb) { - SubBlock** st; - SubBlock_set_free(sb); - st = &Block_start(ths); +void Block_link(Block*, SubBlock*); +void deallocate_from_fixed_pools(__mem_pool_obj*, void*, unsigned int); +void* malloc(unsigned int); +void* calloc(unsigned int, unsigned int); +void* realloc(void*, unsigned int); +void free(void*); - if (*st != 0) { - sb->prev = (*st)->prev; - sb->prev->next = sb; - sb->next = *st; - (*st)->prev = sb; - *st = sb; - *st = SubBlock_merge_prev(*st, st); - SubBlock_merge_next(*st, st); - } else { - *st = sb; - sb->prev = sb; - sb->next = sb; +static void SubBlock_construct(SubBlock* ths, unsigned int size, Block* bp, int prev_alloc, int this_alloc) { + ths->pBlock = (Block*)((unsigned int)bp | 1); + ths->size = size; + if (prev_alloc) { + ths->size |= 4; + } + if (this_alloc) { + ths->size |= 2; + ((SubBlock*)((char*)ths + size))->size |= 4; + } else { + *(unsigned int*)((char*)ths + size - sizeof(unsigned int)) = size; + } +} + +static SubBlock* SubBlock_split(SubBlock* ths, unsigned int sz) { + unsigned int origsize; + int isfree; + int isprevalloc; + SubBlock* np; + Block* bp; + origsize = SubBlock_size(ths); + isfree = SubBlock_is_free(ths); + isprevalloc = (int)(ths->size & 4); + np = (SubBlock*)((char*)ths + sz); + bp = SubBlock_block(ths); + SubBlock_construct(ths, sz, bp, isprevalloc, !isfree); + SubBlock_construct(np, origsize - sz, bp, !isfree, !isfree); + if (isfree) { + np->pNext = ths->pNext; + np->pNext->pPrev = np; + np->pPrev = ths; + ths->pNext = np; + } + return np; +} + +static void Block_unlink(Block* ths, SubBlock* sb) { + SubBlock** st; + unsigned int this_size = SubBlock_size(sb); + sb->size |= 2; + ((SubBlock*)((char*)sb + this_size))->size |= 4; + st = &Block_start(ths); + if (*st == sb) { + *st = sb->pNext; + } + if (*st == sb) { + *st = NULL; + ths->maxSize = 0; + } else { + sb->pNext->pPrev = sb->pPrev; + sb->pPrev->pNext = sb->pNext; } - if (ths->max_size < SubBlock_size(*st)) - ths->max_size = SubBlock_size(*st); } static SubBlock* SubBlock_merge_prev(SubBlock* ths, SubBlock** start) { @@ -149,72 +156,39 @@ static SubBlock* SubBlock_merge_prev(SubBlock* ths, SubBlock** start) { if (!(ths->size & 0x04)) { prevsz = *(unsigned int*)((char*)ths - sizeof(unsigned int)); - if (prevsz & 0x2) + if (prevsz & 0x2) { return ths; + } p = (SubBlock*)((char*)ths - prevsz); SubBlock_set_size(p, prevsz + SubBlock_size(ths)); - if (*start == ths) - *start = (*start)->next; - ths->next->prev = ths->prev; - ths->next->prev->next = ths->next; + if (*start == ths) { + *start = (*start)->pNext; + } + ths->pNext->pPrev = ths->pPrev; + ths->pNext->pPrev->pNext = ths->pNext; return p; } return ths; } -static void SubBlock_merge_next(SubBlock* pBlock, SubBlock** pStart) { - SubBlock* next_sub_block; - unsigned int this_cur_size; - - next_sub_block = (SubBlock*)((char*)pBlock + (pBlock->size & 0xFFFFFFF8)); - - if (!(next_sub_block->size & 2)) { - this_cur_size = (pBlock->size & 0xFFFFFFF8) + (next_sub_block->size & 0xFFFFFFF8); - - pBlock->size &= ~0xFFFFFFF8; - pBlock->size |= this_cur_size & 0xFFFFFFF8; - - if (!(pBlock->size & 2)) { - *(unsigned int*)((char*)(pBlock) + (this_cur_size)-4) = (this_cur_size); - } - - if (!(pBlock->size & 2)) { - *(unsigned int*)((char*)pBlock + this_cur_size) &= ~4; - } else { - *(unsigned int*)((char*)pBlock + this_cur_size) |= 4; - } - - if (*pStart == next_sub_block) { - *pStart = (*pStart)->next; - } - - if (*pStart == next_sub_block) { - *pStart = 0; - } - - next_sub_block->next->prev = next_sub_block->prev; - next_sub_block->prev->next = next_sub_block->next; - } -} - static Block* __unlink(__mem_pool_obj* pool_obj, Block* bp) { - Block* result = bp->next; + Block* result = bp->pNext; if (result == bp) { - result = 0; + result = NULL; } - if (pool_obj->start_ == bp) { - pool_obj->start_ = result; + if (pool_obj->pStart == bp) { + pool_obj->pStart = result; } - if (result != 0) { - result->prev = bp->prev; - result->prev->next = result; + if (result != NULL) { + result->pPrev = bp->pPrev; + result->pPrev->pNext = result; } - bp->next = 0; - bp->prev = 0; + bp->pNext = NULL; + bp->pPrev = NULL; return result; } @@ -231,12 +205,13 @@ static void deallocate_from_var_pools(__mem_pool_obj* pool_obj, void* ptr) { } } -void __init_pool_obj(__mem_pool* pool_obj) { +static void __init_pool_obj(__mem_pool* pool_obj) { memset(pool_obj, 0, sizeof(__mem_pool_obj)); } +__mem_pool protopool; + static __mem_pool* get_malloc_pool() { - static __mem_pool protopool; static unsigned char init = 0; if (!init) { __init_pool_obj(&protopool); @@ -246,67 +221,11 @@ static __mem_pool* get_malloc_pool() { return &protopool; } -void deallocate_from_fixed_pools(__mem_pool_obj* pool_obj, void* ptr, unsigned int size) { - unsigned int i = 0; - FixSubBlock* p; - FixBlock* b; - FixStart* fs; - - while (size > fix_pool_sizes[i]) { - ++i; - } - - fs = &pool_obj->fix_start[i]; - p = FixSubBlock_from_pointer(ptr); - b = p->block_; - - if (b->start_ == 0 && fs->head_ != b) { - if (fs->tail_ == b) { - fs->head_ = fs->head_->prev_; - fs->tail_ = fs->tail_->prev_; - } else { - b->prev_->next_ = b->next_; - b->next_->prev_ = b->prev_; - b->next_ = fs->head_; - b->prev_ = b->next_->prev_; - b->prev_->next_ = b; - b->next_->prev_ = b; - fs->head_ = b; - } - } - - p->next_ = b->start_; - b->start_ = p; - - if (--b->n_allocated_ == 0) { - if (fs->head_ == b) { - fs->head_ = b->next_; - } - - if (fs->tail_ == b) { - fs->tail_ = b->prev_; - } - - b->prev_->next_ = b->next_; - b->next_->prev_ = b->prev_; - - if (fs->head_ == b) { - fs->head_ = 0; - } - - if (fs->tail_ == b) { - fs->tail_ = 0; - } - - deallocate_from_var_pools(pool_obj, b); - } -} - -void __pool_free(__mem_pool* pool, void* ptr) { +static void __pool_free(__mem_pool* pool, void* ptr) { __mem_pool_obj* pool_obj; unsigned int size; - if (ptr == 0) { + if (ptr == NULL) { return; } @@ -320,6 +239,559 @@ void __pool_free(__mem_pool* pool, void* ptr) { } } +static void link(__mem_pool_obj* pool, Block* bp) { + if (pool->pStart != NULL) { + bp->pPrev = pool->pStart->pPrev; + bp->pPrev->pNext = bp; + bp->pNext = pool->pStart; + pool->pStart->pPrev = bp; + pool->pStart = bp; + } else { + pool->pStart = bp; + bp->pPrev = bp; + bp->pNext = bp; + } +} + +static void Block_construct(Block* ths, unsigned int size) { + SubBlock* sb; + + ths->size = size | 3; + ((SubBlock*)((char*)ths + size - 8))->size = ths->size; + + sb = (SubBlock*)(ths + 1); + sb->pBlock = (Block*)((unsigned int)ths | 1); + sb->size = size - 0x18; + *(unsigned int*)((char*)sb + (size - 0x18) - sizeof(unsigned int)) = size - 0x18; + + ths->maxSize = size - 0x18; + Block_start(ths) = NULL; + + Block_link(ths, sb); +} + +static Block* link_new_block(__mem_pool_obj* pool, unsigned int size) { + Block* bp; + + size = (size + 31) & ~7; + if (size < 0x10000) { + size = 0x10000; + } + + bp = (Block*)__sys_alloc(size); + if (bp == NULL) { + return NULL; + } + + Block_construct(bp, size); + link(pool, bp); + return bp; +} + +static SubBlock* Block_subBlock(Block* bp, unsigned int size, unsigned int* out) { + SubBlock* st; + SubBlock* sb; + unsigned int sb_size; + unsigned int max_found; + st = Block_start(bp); + if (st == NULL) { + bp->maxSize = 0; + return NULL; + } + + sb = st; + sb_size = SubBlock_size(sb); + max_found = sb_size; + + while (sb_size < size) { + sb = sb->pNext; + sb_size = SubBlock_size(sb); + if (max_found < sb_size) { + max_found = sb_size; + } + if (sb == st) { + bp->maxSize = max_found; + if (out != NULL) { + *out = max_found - 8; + } + return NULL; + } + } + + if (sb_size - size >= 0x50) { + SubBlock_split(sb, size); + } + + Block_start(bp) = sb->pNext; + Block_unlink(bp, sb); + + if (out != NULL) { + *out = SubBlock_size(sb) - 8; + } + + return sb; +} + +static void Block_link(Block* ths, SubBlock* sb) { + SubBlock** st; + SubBlock_set_free(sb); + st = &Block_start(ths); + + if (*st != NULL) { + sb->pPrev = (*st)->pPrev; + sb->pPrev->pNext = sb; + sb->pNext = *st; + (*st)->pPrev = sb; + *st = sb; + *st = SubBlock_merge_prev(*st, st); + SubBlock_merge_next(*st, st); + } else { + *st = sb; + sb->pPrev = sb; + sb->pNext = sb; + } + if (ths->maxSize < SubBlock_size(*st)) { + ths->maxSize = SubBlock_size(*st); + } +} + +static void SubBlock_merge_next(SubBlock* pBlock, SubBlock** pStart) { + SubBlock* next_sub_block; + unsigned int this_cur_size; + + next_sub_block = (SubBlock*)((char*)pBlock + (pBlock->size & 0xFFFFFFF8)); + + if (!(next_sub_block->size & 2)) { + this_cur_size = (pBlock->size & 0xFFFFFFF8) + (next_sub_block->size & 0xFFFFFFF8); + + pBlock->size &= ~0xFFFFFFF8; + pBlock->size |= this_cur_size & 0xFFFFFFF8; + + if (!(pBlock->size & 2)) { + *(unsigned int*)((char*)pBlock + this_cur_size - sizeof(unsigned int)) = this_cur_size; + } + + if (!(pBlock->size & 2)) { + ((SubBlock*)((char*)pBlock + this_cur_size))->size &= ~4; + } else { + ((SubBlock*)((char*)pBlock + this_cur_size))->size |= 4; + } + + if (*pStart == next_sub_block) { + *pStart = (*pStart)->pNext; + } + + if (*pStart == next_sub_block) { + *pStart = NULL; + } + + next_sub_block->pNext->pPrev = next_sub_block->pPrev; + next_sub_block->pPrev->pNext = next_sub_block->pNext; + } +} + +static void* allocate_from_var_pools(__mem_pool_obj* pool, unsigned int size, unsigned int* out) { + Block* bp; + SubBlock* ptr; + + if (out != NULL) { + *out = 0; + } + + size = (size + 15) & ~7; + if (size < 0x50) { + size = 0x50; + } + + bp = pool->pStart != NULL ? pool->pStart : link_new_block(pool, size); + if (bp == NULL) { + return NULL; + } + + do { + if (size <= bp->maxSize) { + ptr = Block_subBlock(bp, size, out); + if (ptr != NULL) { + pool->pStart = bp; + break; + } + } + + bp = bp->pNext; + if (bp == pool->pStart) { + bp = link_new_block(pool, size); + if (bp == NULL) { + return NULL; + } + ptr = Block_subBlock(bp, size, out); + break; + } + } while (1); + + return (char*)ptr + 8; +} + +static void* soft_allocate_from_var_pools(__mem_pool_obj* pool, unsigned int size, unsigned int* out) { + register Block* bp; + register SubBlock* ptr; + + size = (size + 15) & ~7; + if (size < 0x50) { + size = 0x50; + } + *out = 0; + bp = pool->pStart; + if (bp == NULL) { + return NULL; + } + + do { + if (size <= bp->maxSize) { + ptr = Block_subBlock(bp, size, NULL); + if (ptr != NULL) { + pool->pStart = bp; + break; + } + } + if (bp->maxSize > 8 && *out < bp->maxSize - 8) { + *out = bp->maxSize - 8; + } + bp = bp->pNext; + if (bp == pool->pStart) { + return NULL; + } + } while (1); + + return (char*)ptr + 8; +} + +static void FixBlock_construct(FixBlock* this, FixBlock* prev, FixBlock* next, unsigned int poolIdx, void* start, unsigned int totalSize) { + unsigned int fixSubBlockSize; + unsigned int n; + char* p; + unsigned int i; + char* np; + + this->pPrev = prev; + this->pNext = next; + prev->pNext = this; + next->pPrev = this; + this->clientSize = fix_pool_sizes[poolIdx]; + fixSubBlockSize = fix_pool_sizes[poolIdx] + 4; + n = totalSize / fixSubBlockSize; + p = (char*)start; + for (i = 0; i < n - 1; ++i) { + np = p + fixSubBlockSize; + ((FixSubBlock*)p)->pBlock = this; + ((FixSubBlock*)p)->pNext = (FixSubBlock*)np; + p = np; + } + ((FixSubBlock*)p)->pBlock = this; + ((FixSubBlock*)p)->pNext = NULL; + this->pStart = (FixSubBlock*)start; + this->allocatedSize = 0; +} + +static void* allocate_from_fixed_pools(__mem_pool_obj* pool, unsigned int size, unsigned int* out) { + unsigned int i = 0; + FixSubBlock* p; + FixStart* fs; + + while (size > fix_pool_sizes[i]) { + ++i; + } + fs = &pool->fixStart[i]; + if (fs->pHead == NULL || fs->pHead->pStart == NULL) { + unsigned int size_requested = 0x1000; + char* newblock; + unsigned int size_received; + unsigned int n, nsave, size_has; + + n = (size_requested - sizeof(FixBlock)) / (fix_pool_sizes[i] + 4); + if (n > 0x100) { + n = 0x100; + } + nsave = n; + while (n >= 10) { + size_requested = n * (fix_pool_sizes[i] + 4) + sizeof(FixBlock); + newblock = (char*)soft_allocate_from_var_pools(pool, size_requested, &size_has); + if (newblock != NULL) { + break; + } + if (size_has > sizeof(FixBlock)) { + n = (size_has - sizeof(FixBlock)) / (fix_pool_sizes[i] + 4); + } else { + n = 0; + } + } + if (newblock == NULL) { + unsigned int cr_backup; + n = nsave; + while (1) { + size_requested = n * (fix_pool_sizes[i] + 4) + sizeof(FixBlock); + newblock = (char*)allocate_from_var_pools(pool, size_requested, &cr_backup); + if (newblock != NULL) { + break; + } + n = cr_backup / (fix_pool_sizes[i] + sizeof(FixBlock) + 4); + if (n < 10) { + if (out != NULL) { + *out = 0; + } + return NULL; + } + } + } + size_received = __msize_inline(newblock); + if (fs->pHead == NULL) { + fs->pHead = (FixBlock*)newblock; + fs->pTail = (FixBlock*)newblock; + } + FixBlock_construct((FixBlock*)newblock, fs->pTail, fs->pHead, i, (FixSubBlock*)((FixBlock*)newblock + 1), size_received - sizeof(FixBlock)); + fs->pHead = (FixBlock*)newblock; + } + p = fs->pHead->pStart; + fs->pHead->pStart = p->pNext; + ++fs->pHead->allocatedSize; + if (fs->pHead->pStart == NULL) { + fs->pHead = fs->pHead->pNext; + fs->pTail = fs->pTail->pNext; + } + if (out != NULL) { + *out = fix_pool_sizes[i]; + } + return (char*)p + 4; +} + +void deallocate_from_fixed_pools(__mem_pool_obj* pool_obj, void* ptr, unsigned int size) { + unsigned int i = 0; + FixSubBlock* p; + FixBlock* b; + FixStart* fs; + + while (size > fix_pool_sizes[i]) { + ++i; + } + + fs = &pool_obj->fixStart[i]; + p = FixSubBlock_from_pointer(ptr); + b = p->pBlock; + + if (b->pStart == NULL && fs->pHead != b) { + if (fs->pTail == b) { + fs->pHead = fs->pHead->pPrev; + fs->pTail = fs->pTail->pPrev; + } else { + b->pPrev->pNext = b->pNext; + b->pNext->pPrev = b->pPrev; + b->pNext = fs->pHead; + b->pPrev = b->pNext->pPrev; + b->pPrev->pNext = b; + b->pNext->pPrev = b; + fs->pHead = b; + } + } + + p->pNext = b->pStart; + b->pStart = p; + + if (--b->allocatedSize == 0) { + if (fs->pHead == b) { + fs->pHead = b->pNext; + } + + if (fs->pTail == b) { + fs->pTail = b->pPrev; + } + + b->pPrev->pNext = b->pNext; + b->pNext->pPrev = b->pPrev; + + if (fs->pHead == b) { + fs->pHead = NULL; + } + + if (fs->pTail == b) { + fs->pTail = NULL; + } + + deallocate_from_var_pools(pool_obj, b); + } +} + +static unsigned int __pool_allocate_resize(__mem_pool_obj* pool, void* ptr, unsigned int size, unsigned int* out) { + unsigned int sz; + unsigned int this_size; + unsigned int orig_size; + SubBlock* sb; + SubBlock* next_sub; + + orig_size = __msize_inline(ptr); + + if (size == orig_size) { + if (out != NULL) { + *out = orig_size; + } + return 1; + } + + if (classify(ptr)) { + if (size > 0xFFFFFF7F) { + size = 0xFFFFFF7F; + } + sz = size + 8; + sz = (sz + 7) & ~7; + if (sz < 0x50) { + sz = 0x50; + } + + sb = SubBlock_from_pointer(ptr); + this_size = orig_size + 8; + next_sub = (SubBlock*)((char*)sb + this_size); + + if (SubBlock_is_free(next_sub) && sz <= this_size + SubBlock_size(next_sub)) { + SubBlock_merge_next(sb, &Block_start(SubBlock_block(sb))); + this_size = SubBlock_size(sb); + } + + if (this_size >= sz + 0x50) { + Block_link(SubBlock_block(sb), SubBlock_split(sb, sz)); + this_size = SubBlock_size(sb); + } + + this_size -= 8; + + if (out != NULL) { + *out = this_size; + } + + if (size > orig_size) { + if (out != NULL && size > this_size && SubBlock_is_free(next_sub)) { + *out += SubBlock_size(next_sub); + } + return size <= this_size; + } + + return this_size < orig_size; + } + + if (out != NULL) { + *out = orig_size; + } + return 0; +} + +void* malloc(register unsigned int size) { + void* rv; + register __mem_pool_obj* pool_obj; + + if (size == 0) { + goto null_return; + } + + pool_obj = (__mem_pool_obj*)get_malloc_pool(); + + if (size > ~0x30u) { + return NULL; + } + + if (size <= 68) { + rv = allocate_from_fixed_pools(pool_obj, size, NULL); + } else { + rv = allocate_from_var_pools(pool_obj, size, NULL); + } + + return rv; + +null_return: + return NULL; +} + void free(void* ptr) { __pool_free(get_malloc_pool(), ptr); } + +void* realloc(void* ptr, unsigned int size) { + register unsigned int rv = size; + register __mem_pool_obj* pool; + unsigned int current_size; + unsigned int orig_size; + + pool = (__mem_pool_obj*)get_malloc_pool(); + + if (ptr == NULL) { + if (rv > ~0x30u) { + return NULL; + } + if (rv <= 68) { + return allocate_from_fixed_pools(pool, rv, NULL); + } + return allocate_from_var_pools(pool, rv, NULL); + } + + if (rv == 0) { + if (ptr != NULL) { + current_size = __msize_inline(ptr); + if (current_size <= 68) { + deallocate_from_fixed_pools(pool, ptr, current_size); + } else { + deallocate_from_var_pools(pool, ptr); + } + } + return NULL; + } + + orig_size = __msize_inline(ptr); + { + unsigned int result = __pool_allocate_resize(pool, ptr, rv, NULL); + if (result || rv <= orig_size) { + return ptr; + } + } + + if (rv > ~0x30u) { + rv = 0; + } else if (rv <= 68) { + rv = (unsigned int)allocate_from_fixed_pools(pool, rv, NULL); + } else { + rv = (unsigned int)allocate_from_var_pools(pool, rv, NULL); + } + + if (rv != 0) { + memcpy((void*)rv, ptr, orig_size); + if (ptr != NULL) { + unsigned int cur_sz = __msize_inline(ptr); + if (cur_sz <= 68) { + deallocate_from_fixed_pools(pool, ptr, cur_sz); + } else { + deallocate_from_var_pools(pool, ptr); + } + } + } + + return (void*)rv; +} + +void* calloc(unsigned int nmemb, unsigned int size) { + register void* ptr; + register unsigned int total; + __mem_pool_obj* pool_obj; + + pool_obj = (__mem_pool_obj*)get_malloc_pool(); + + total = size * nmemb; + + if (total > ~0x30u) { + ptr = NULL; + } else if (total <= 68) { + ptr = allocate_from_fixed_pools(pool_obj, total, NULL); + } else { + ptr = allocate_from_var_pools(pool_obj, total, NULL); + } + + if (ptr != NULL) { + memset(ptr, 0, total); + } + + return ptr; +} -- 2.49.1 From b9ceb6a11a5b5be615664566945155aa69c05e7e Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:17:03 -0500 Subject: [PATCH 12/21] Match MSL printf (#91) * Match MSL printf * Link MSL printf match --- configure.py | 2 +- libs/MSL/src/MSL_Common/printf.c | 1422 ++++++++++++++++++++++++++++++ 2 files changed, 1423 insertions(+), 1 deletion(-) create mode 100644 libs/MSL/src/MSL_Common/printf.c diff --git a/configure.py b/configure.py index 51438b02..bbc4c4c9 100644 --- a/configure.py +++ b/configure.py @@ -1957,7 +1957,7 @@ config.libs = [ Object(Matching, "MSL_Common/mem_funcs.c"), Object(Matching, "MSL_Common/math_api.c"), Object(NonMatching, "MSL_Common/misc_io.c"), - Object(NonMatching, "MSL_Common/printf.c"), + Object(Matching, "MSL_Common/printf.c", mw_version = "GC/3.0a5.2", strip_comment=True), Object(NonMatching, "MSL_Common/qsort.c"), Object(Matching, "MSL_Common/rand.c"), Object(NonMatching, "MSL_Common/scanf.c"), diff --git a/libs/MSL/src/MSL_Common/printf.c b/libs/MSL/src/MSL_Common/printf.c new file mode 100644 index 00000000..de028a3d --- /dev/null +++ b/libs/MSL/src/MSL_Common/printf.c @@ -0,0 +1,1422 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define TARGET_FLOAT_BITS 64 +#define TARGET_FLOAT_IMPLICIT_J_BIT 1 +#define TARGET_FLOAT_MANT_DIG 53 +#define TARGET_FLOAT_MANT_BITS (TARGET_FLOAT_MANT_DIG - TARGET_FLOAT_IMPLICIT_J_BIT) +#define TARGET_FLOAT_EXP_BITS (TARGET_FLOAT_BITS - TARGET_FLOAT_MANT_BITS - 1) + +typedef signed long long intmax_t; +typedef long ptrdiff_t; + +enum justification_options { + left_justification, + right_justification, + zero_fill +}; + +enum sign_options { + only_minus, + sign_always, + space_holder +}; + +enum argument_options { + normal_argument, + char_argument, + short_argument, + long_argument, + long_long_argument, + wchar_argument, + intmax_argument, + size_t_argument, + ptrdiff_argument, + long_double_argument +}; + +typedef struct { + unsigned char justification_options; + unsigned char sign_options; + unsigned char precision_specified; + unsigned char alternate_form; + unsigned char argument_options; + unsigned char conversion_char; + int field_width; + int precision; +} print_format; + +typedef struct decimal { + char sign; + char unk1; + short exponent; + struct { + unsigned char length; + unsigned char text[36]; + unsigned char unk41; + } sig; +} decimal; + +typedef struct decform { + char style; + char unk1; + short digits; +} decform; + +typedef struct { + char* spCharStr; + size_t maxCharCount; + size_t charsWritten; +} __OutStrCtrl; + +void __num2dec(const decform*, double, decimal*); +size_t __fwrite(const void*, size_t, size_t, FILE*); + +const double lbl_81695A00 = 0.0; + +static const char* parse_format(const char* format_string, va_list* arg, print_format* format) { + print_format f; + const char* s = format_string; + int c; + int flag_found; + f.justification_options = right_justification; + f.sign_options = only_minus; + f.precision_specified = 0; + f.alternate_form = 0; + f.argument_options = normal_argument; + f.field_width = 0; + f.precision = 0; + + if ((c = *++s) == '%') { + f.conversion_char = c; + *format = f; + return s + 1; + } + + for (;;) { + flag_found = 1; + + switch (c) { + case '-': { + f.justification_options = left_justification; + break; + } + case '+': { + f.sign_options = sign_always; + break; + } + case ' ': { + if (f.sign_options != sign_always) { + f.sign_options = space_holder; + } + break; + } + case '#': { + f.alternate_form = 1; + break; + } + case '0': { + if (f.justification_options != left_justification) { + f.justification_options = zero_fill; + } + break; + } + default: { + flag_found = 0; + break; + } + } + + if (flag_found) { + c = *++s; + } else { + break; + } + } + + if (c == '*') { + f.field_width = va_arg(*arg, int); + if (f.field_width < 0) { + f.justification_options = left_justification; + f.field_width = -f.field_width; + } + + c = *++s; + } else { + while (isdigit(c)) { + f.field_width = f.field_width * 10 + (c - '0'); + c = *++s; + } + } + + if (f.field_width > 509) { + f.conversion_char = 0xFF; + *format = f; + return s + 1; + } + + if (c == '.') { + f.precision_specified = 1; + + if ((c = *++s) == '*') { + f.precision = va_arg(*arg, int); + if (f.precision < 0) { + f.precision_specified = 0; + } + + c = *++s; + } else { + while (isdigit(c)) { + f.precision = f.precision * 10 + (c - '0'); + c = *++s; + } + } + } + + flag_found = 1; + + switch (c) { + case 'h': { + f.argument_options = short_argument; + + if (s[1] == 'h') { + f.argument_options = char_argument; + c = *++s; + } + + break; + } + + case 'l': { + f.argument_options = long_argument; + + if (s[1] == 'l') { + f.argument_options = long_long_argument; + c = *++s; + } + + break; + } + + case 'L': { + f.argument_options = long_double_argument; + break; + } + case 'j': { + f.argument_options = intmax_argument; + break; + } + case 't': { + f.argument_options = ptrdiff_argument; + break; + } + case 'z': { + f.argument_options = size_t_argument; + break; + } + default: { + flag_found = 0; + break; + } + } + + if (flag_found) { + c = *++s; + } + + f.conversion_char = c; + + switch (c) { + case 'd': + case 'i': + case 'u': + case 'o': + case 'x': + case 'X': { + if (f.argument_options == long_double_argument) { + f.conversion_char = 0xFF; + break; + } + + if (!f.precision_specified) { + f.precision = 1; + } else if (f.justification_options == zero_fill) { + f.justification_options = right_justification; + } + break; + } + + case 'f': + case 'F': { + if (f.argument_options == short_argument || f.argument_options == intmax_argument || f.argument_options == size_t_argument || + f.argument_options == ptrdiff_argument || f.argument_options == long_long_argument) { + f.conversion_char = 0xFF; + break; + } + + if (!f.precision_specified) { + f.precision = 6; + } + break; + } + + case 'a': + case 'A': { + if (!f.precision_specified) { + f.precision = 0xD; + } + + if (f.argument_options == short_argument || f.argument_options == intmax_argument || f.argument_options == size_t_argument || + f.argument_options == ptrdiff_argument || f.argument_options == long_long_argument || f.argument_options == char_argument) { + f.conversion_char = 0xFF; + } + + break; + } + + case 'g': + case 'G': { + if (!f.precision) { + f.precision = 1; + } + } + + case 'e': + case 'E': { + if (f.argument_options == short_argument || f.argument_options == intmax_argument || f.argument_options == size_t_argument || + f.argument_options == ptrdiff_argument || f.argument_options == long_long_argument || f.argument_options == char_argument) { + f.conversion_char = 0xFF; + break; + } + + if (!f.precision_specified) { + f.precision = 6; + } + break; + } + + case 'p': { + f.conversion_char = 'x'; + f.alternate_form = 1; + f.argument_options = long_argument; + f.precision = 8; + break; + } + + case 'c': { + if (f.argument_options == long_argument) { + f.argument_options = wchar_argument; + } else { + if (f.precision_specified || f.argument_options != normal_argument) { + f.conversion_char = 0xFF; + } + } + + break; + } + + case 's': { + if (f.argument_options == long_argument) { + f.argument_options = wchar_argument; + } else { + if (f.argument_options != normal_argument) { + f.conversion_char = 0xFF; + } + } + + break; + } + + case 'n': { + if (f.argument_options == long_double_argument) { + f.conversion_char = 0xFF; + } + + break; + } + + default: { + f.conversion_char = 0xFF; + break; + } + } + + *format = f; + return s + 1; +} + +static char* long2str(long num, char* buff, print_format format) { + unsigned long unsigned_num, base; + char* p; + int n, digits; + int minus = 0; + unsigned_num = num; + minus = 0; + + p = buff; + *--p = 0; + digits = 0; + + if (!num && !format.precision && !(format.alternate_form && format.conversion_char == 'o')) { + return p; + } + + switch (format.conversion_char) { + case 'd': + case 'i': { + base = 10; + + if (num < 0) { + if (num != 0x80000000) { + unsigned_num = -num; + } + + minus = 1; + } + break; + } + + case 'o': { + base = 8; + format.sign_options = only_minus; + break; + } + + case 'u': { + base = 10; + format.sign_options = only_minus; + break; + } + + case 'x': + case 'X': { + base = 16; + format.sign_options = only_minus; + break; + } + } + + do { + n = unsigned_num % base; + unsigned_num /= base; + + if (n < 10) { + n += '0'; + } else { + n -= 10; + + if (format.conversion_char == 'x') { + n += 'a'; + } else { + n += 'A'; + } + } + + *--p = n; + ++digits; + } while (unsigned_num != 0); + + if (base == 8 && format.alternate_form && *p != '0') { + *--p = '0'; + ++digits; + } + + if (format.justification_options == zero_fill) { + format.precision = format.field_width; + + if (minus || format.sign_options != only_minus) { + --format.precision; + } + + if (base == 16 && format.alternate_form) { + format.precision -= 2; + } + } + + if (buff - p + format.precision > 509) { + return NULL; + } + + while (digits < format.precision) { + *--p = '0'; + ++digits; + } + + if (base == 16 && format.alternate_form) { + *--p = format.conversion_char; + *--p = '0'; + } + + if (minus) { + *--p = '-'; + } else if (format.sign_options == sign_always) { + *--p = '+'; + } else if (format.sign_options == space_holder) { + *--p = ' '; + } + + return p; +} + +static char* longlong2str(long long num, char* pBuf, print_format fmt) { + unsigned long long unsigned_num, base; + char* p; + int n, digits; + int minus = 0; + unsigned_num = num; + minus = 0; + p = pBuf; + *--p = 0; + digits = 0; + + if (!num && !fmt.precision && !(fmt.alternate_form && fmt.conversion_char == 'o')) { + return p; + } + + switch (fmt.conversion_char) { + case 'd': + case 'i': { + base = 10; + + if (num < 0) { + if (num != 0x8000000000000000LL) { + unsigned_num = -num; + } + + minus = 1; + } + break; + } + case 'o': { + base = 8; + fmt.sign_options = only_minus; + break; + } + case 'u': { + base = 10; + fmt.sign_options = only_minus; + break; + } + case 'x': + case 'X': { + base = 16; + fmt.sign_options = only_minus; + break; + } + } + + do { + n = unsigned_num % base; + unsigned_num /= base; + + if (n < 10) { + n += '0'; + } else { + n -= 10; + if (fmt.conversion_char == 'x') { + n += 'a'; + } else { + n += 'A'; + } + } + + *--p = n; + ++digits; + } while (unsigned_num != 0); + + if (base == 8 && fmt.alternate_form && *p != '0') { + *--p = '0'; + ++digits; + } + + if (fmt.justification_options == zero_fill) { + fmt.precision = fmt.field_width; + + if (minus || fmt.sign_options != only_minus) { + --fmt.precision; + } + + if (base == 16 && fmt.alternate_form) { + fmt.precision -= 2; + } + } + + if (pBuf - p + fmt.precision > 509) { + return 0; + } + + while (digits < fmt.precision) { + *--p = '0'; + ++digits; + } + + if (base == 16 && fmt.alternate_form) { + *--p = fmt.conversion_char; + *--p = '0'; + } + + if (minus) { + *--p = '-'; + } else if (fmt.sign_options == sign_always) { + *--p = '+'; + } else if (fmt.sign_options == space_holder) { + *--p = ' '; + } + + return p; +} + +static char* double2hex(long double num, char* buff, print_format format) { + char* p; + unsigned char* q; + unsigned char working_byte; + long double ld; + int expbits, expmask; + unsigned snum; + long exp; + print_format exp_format; + int hex_precision; + int mantissa_bit; + decform form; + decimal dec; + int radix_marker; + + radix_marker = *(unsigned char*)__lconv.decimal_point; + p = buff; + ld = num; + + if (format.precision > 509) { + return NULL; + } + + form.style = (char)0; + form.digits = 0x20; + __num2dec(&form, num, &dec); + + if (fabs(num) == *(volatile double*)&lbl_81695A00) { + p = buff - 6; + strcpy(p, "0x0p0"); + return p; + } + + if (*dec.sig.text == 'I') { + if (dec.sign) { + p = buff - 5; + if (format.conversion_char == 'A') { + strcpy(p, "-INF"); + } else { + strcpy(p, "-inf"); + } + } else { + p = buff - 4; + if (format.conversion_char == 'A') { + strcpy(p, "INF"); + } else { + strcpy(p, "inf"); + } + } + + return p; + } else if (*dec.sig.text == 'N') { + if (dec.sign) { + p = buff - 5; + if (format.conversion_char == 'A') { + strcpy(p, "-NAN"); + } else { + strcpy(p, "-nan"); + } + } else { + p = buff - 4; + if (format.conversion_char == 'A') { + strcpy(p, "NAN"); + } else { + strcpy(p, "nan"); + } + } + return p; + } + + exp_format.justification_options = right_justification; + exp_format.sign_options = sign_always; + exp_format.precision_specified = 0; + exp_format.alternate_form = 0; + exp_format.argument_options = normal_argument; + exp_format.field_width = 0; + exp_format.precision = 1; + exp_format.conversion_char = 'd'; + + expbits = TARGET_FLOAT_EXP_BITS; + expmask = 0x7FF; + + snum = ((unsigned char*)&num)[0] << 25; + if (TARGET_FLOAT_EXP_BITS > 7) { + snum |= ((unsigned char*)&num)[1] << 17; + } + if (TARGET_FLOAT_EXP_BITS > 15) { + snum |= ((unsigned char*)&num)[2] << 9; + } + if (TARGET_FLOAT_EXP_BITS > 23) { + snum |= ((unsigned char*)&num)[3] << 1; + } + + snum = snum >> (32 - expbits) & expmask; + exp = snum - 0x3FF; + + p = long2str(exp, buff, exp_format); + if (format.conversion_char == 'a') { + *--p = 'p'; + } else { + *--p = 'P'; + } + q = (unsigned char*)# + + if (TARGET_FLOAT_IMPLICIT_J_BIT) { + mantissa_bit = (1 + expbits + format.precision * 4) - 1; + } else { + mantissa_bit = (1 + expbits + format.precision * 4) - 4; + } + + for (hex_precision = format.precision; hex_precision >= 1; hex_precision--) { + if (mantissa_bit < TARGET_FLOAT_BITS) { + int mantissa_byte; + + mantissa_byte = mantissa_bit >> 3; + working_byte = *(q + mantissa_byte) >> (7 - (mantissa_bit & 7)); + + if ((mantissa_bit & ~7) != (mantissa_bit - 4 & ~7)) { + working_byte |= (*(q + (mantissa_byte - 1)) << 8) >> (7 - (mantissa_bit & 7)); + } + + if (!TARGET_FLOAT_IMPLICIT_J_BIT) { + if (mantissa_bit == 1 + expbits) { + *--p = radix_marker; + working_byte &= 0x1; + } + } + + if ((working_byte &= 0xF) < 10) { + working_byte += '0'; + } else if (format.conversion_char == 'a') { + working_byte += 'a' - 10; + } else { + working_byte += 'A' - 10; + } + } else { + working_byte = '0'; + } + + *--p = working_byte; + mantissa_bit -= 4; + } + + if (TARGET_FLOAT_IMPLICIT_J_BIT) { + if (format.precision || format.alternate_form) { + *--p = radix_marker; + } + + *--p = '1'; + } + + if (format.conversion_char == 'a') { + *--p = 'x'; + } else { + *--p = 'X'; + } + + *--p = '0'; + + if (dec.sign) { + *--p = '-'; + } else if (format.sign_options == sign_always) { + *--p = '+'; + } else if (format.sign_options == space_holder) { + *--p = ' '; + } + + return p; +} + +static void round_decimal(decimal* dec, int new_length) { + char c; + char* p; + int carry; + + if (new_length < 0) { + return_zero: + dec->exponent = 0; + dec->sig.length = 1; + *dec->sig.text = '0'; + return; + } + + if (new_length >= dec->sig.length) { + return; + } + + p = (char*)dec->sig.text + new_length + 1; + c = *--p - '0'; + + if (c == 5) { + char* q = &((char*)dec->sig.text)[dec->sig.length]; + + while (--q > p && *q == '0') + ; + carry = q == p ? p[-1] & 1 : 1; + } else { + carry = c > 5; + } + + while (new_length != 0) { + c = *--p - '0' + carry; + + if ((carry = c > 9) != 0 || c == 0) { + --new_length; + } else { + *p = c + '0'; + break; + } + } + + if (carry != 0) { + dec->exponent += 1; + dec->sig.length = 1; + *dec->sig.text = '1'; + return; + } else if (new_length == 0) { + goto return_zero; + } + + dec->sig.length = (unsigned char)new_length; +} + +static char* float2str(long double num, char* buff, print_format format) { + decimal dec; + decform form; + char* p; + char* q; + int n, digits, sign; + int int_digits, frac_digits; + int radix_marker; + + radix_marker = *(unsigned char*)__lconv.decimal_point; + + if (format.precision > 509) { + return 0; + } + + form.style = 0; + form.digits = 0x20; + __num2dec(&form, num, &dec); + p = (char*)dec.sig.text + dec.sig.length; + + while (dec.sig.length > 1 && *--p == '0') { + --dec.sig.length; + ++dec.exponent; + } + + switch (*dec.sig.text) { + case '0': { + dec.exponent = 0; + break; + } + case 'I': { + if (num < *(volatile double*)&lbl_81695A00) { + p = buff - 5; + + if (isupper(format.conversion_char)) { + strcpy(p, "-INF"); + } else { + strcpy(p, "-inf"); + } + } else { + p = buff - 4; + if (isupper(format.conversion_char)) { + strcpy(p, "INF"); + } else { + strcpy(p, "inf"); + } + } + + return p; + } + + case 'N': { + if (dec.sign) { + p = buff - 5; + + if (isupper(format.conversion_char)) { + strcpy(p, "-NAN"); + } else { + strcpy(p, "-nan"); + } + } else { + p = buff - 4; + if (isupper(format.conversion_char)) { + strcpy(p, "NAN"); + } else { + strcpy(p, "nan"); + } + } + + return p; + } + } + + dec.exponent += dec.sig.length - 1; + p = buff; + *--p = 0; + + switch (format.conversion_char) { + case 'g': + case 'G': { + if (dec.sig.length > format.precision) { + round_decimal(&dec, format.precision); + } + + if (dec.exponent < -4 || dec.exponent >= format.precision) { + if (format.alternate_form) { + --format.precision; + } else { + format.precision = dec.sig.length - 1; + } + + if (format.conversion_char == 'g') { + format.conversion_char = 'e'; + } else { + format.conversion_char = 'E'; + } + + goto e_format; + } + + if (format.alternate_form) { + format.precision -= dec.exponent + 1; + } else { + if ((format.precision = dec.sig.length - (dec.exponent + 1)) < 0) { + format.precision = 0; + } + } + + goto f_format; + } + + case 'e': + case 'E': { + e_format: + + if (dec.sig.length > format.precision + 1) { + round_decimal(&dec, format.precision + 1); + } + + n = dec.exponent; + sign = '+'; + + if (n < 0) { + n = -n; + sign = '-'; + } + + for (digits = 0; n || digits < 2; ++digits) { + *--p = n % 10 + '0'; + n /= 10; + } + + *--p = sign; + *--p = format.conversion_char; + + if (buff - p + format.precision > 509) { + return 0; + } + + if (dec.sig.length < format.precision + 1) { + for (n = format.precision + 1 - dec.sig.length + 1; --n;) { + *--p = '0'; + } + } + + for (n = dec.sig.length, q = (char*)dec.sig.text + dec.sig.length; --n;) { + *--p = *--q; + } + + if (format.precision || format.alternate_form) { + *--p = radix_marker; + } + + *--p = *dec.sig.text; + + if (dec.sign) { + *--p = '-'; + } else if (format.sign_options == sign_always) { + *--p = '+'; + } else if (format.sign_options == space_holder) { + *--p = ' '; + } + + break; + } + + case 'f': + case 'F': { + f_format: + + if ((frac_digits = -dec.exponent + dec.sig.length - 1) < 0) { + frac_digits = 0; + } + + if (frac_digits > format.precision) { + round_decimal(&dec, dec.sig.length - (frac_digits - format.precision)); + + if ((frac_digits = -dec.exponent + dec.sig.length - 1) < 0) { + frac_digits = 0; + } + } + + if ((int_digits = dec.exponent + 1) < 0) { + int_digits = 0; + } + + if (int_digits + frac_digits > 509) { + return 0; + } + + q = (char*)dec.sig.text + dec.sig.length; + + for (digits = 0; digits < format.precision - frac_digits; ++digits) { + *--p = '0'; + } + + for (digits = 0; digits < frac_digits && digits < dec.sig.length; ++digits) { + *--p = *--q; + } + + for (; digits < frac_digits; ++digits) { + *--p = '0'; + } + + if (format.precision || format.alternate_form) { + *--p = radix_marker; + } + + if (int_digits) { + for (digits = 0; digits < int_digits - dec.sig.length; ++digits) { + *--p = '0'; + } + + for (; digits < int_digits; ++digits) { + *--p = *--q; + } + } else { + *--p = '0'; + } + + if (dec.sign) { + *--p = '-'; + } else if (format.sign_options == sign_always) { + *--p = '+'; + } else if (format.sign_options == space_holder) { + *--p = ' '; + } + + break; + } + } + + return p; +} + +int __pformatter(void* (*WriteProc)(void*, const char*, size_t), void* WriteProcArg, const char* format_str, va_list arg) { + int num_chars, chars_written, field_width; + const char* format_ptr; + const char* curr_format; + int _fw[4]; + print_format* _ep; + long long_num; + long long long_long_num; + long double long_double_num; + char buff[512]; + char* buff_ptr; + char* string_end; + char fill_char = ' '; + + _ep = (print_format*)_fw; + format_ptr = format_str; + chars_written = 0; + + while (*format_ptr) { + if (!(curr_format = strchr(format_ptr, '%'))) { + num_chars = strlen(format_ptr); + chars_written += num_chars; + + if (num_chars && !(*WriteProc)(WriteProcArg, format_ptr, num_chars)) { + return -1; + } + + break; + } + + num_chars = curr_format - format_ptr; + chars_written += num_chars; + + if (num_chars && !(*WriteProc)(WriteProcArg, format_ptr, num_chars)) { + return -1; + } + + format_ptr = curr_format; + format_ptr = parse_format(format_ptr, (va_list*)arg, (print_format*)_fw); + + switch (_ep->conversion_char) { + case 'd': + case 'i': { + if (_ep->argument_options == long_argument) { + long_num = va_arg(arg, long); + } else if (_ep->argument_options == long_long_argument) { + long_long_num = va_arg(arg, long long); + } else if (_ep->argument_options == intmax_argument) { + long_long_num = va_arg(arg, intmax_t); + } else if (_ep->argument_options == size_t_argument) { + long_num = va_arg(arg, size_t); + } else if (_ep->argument_options == ptrdiff_argument) { + long_num = va_arg(arg, ptrdiff_t); + } else { + long_num = va_arg(arg, int); + } + + if (_ep->argument_options == short_argument) { + long_num = (short)long_num; + } + + if (_ep->argument_options == char_argument) { + long_num = (signed char)long_num; + } + + if (_ep->argument_options == long_long_argument || _ep->argument_options == intmax_argument) { + if (!(buff_ptr = longlong2str(long_long_num, buff + 512, *_ep))) { + goto conversion_error; + } + } else { + if (!(buff_ptr = long2str(long_num, buff + 512, *_ep))) { + goto conversion_error; + } + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + } + + case 'o': + case 'u': + case 'x': + case 'X': { + if (_ep->argument_options == long_argument) { + long_num = va_arg(arg, unsigned long); + } else if (_ep->argument_options == long_long_argument) { + long_long_num = va_arg(arg, unsigned long long); + } else if (_ep->argument_options == intmax_argument) { + long_long_num = va_arg(arg, intmax_t); + } else if (_ep->argument_options == size_t_argument) { + long_num = va_arg(arg, size_t); + } else if (_ep->argument_options == ptrdiff_argument) { + long_num = va_arg(arg, ptrdiff_t); + } else { + long_num = va_arg(arg, unsigned int); + } + + if (_ep->argument_options == short_argument) { + long_num = (unsigned short)long_num; + } + + if (_ep->argument_options == char_argument) { + long_num = (unsigned char)long_num; + } + + if (_ep->argument_options == long_long_argument || _ep->argument_options == intmax_argument) { + if (!(buff_ptr = longlong2str(long_long_num, buff + 512, *_ep))) { + goto conversion_error; + } + } else { + if (!(buff_ptr = long2str(long_num, buff + 512, *_ep))) { + goto conversion_error; + } + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + } + + case 'f': + case 'F': + case 'e': + case 'E': + case 'g': + case 'G': { + if (_ep->argument_options == long_double_argument) { + long_double_num = va_arg(arg, long double); + } else { + long_double_num = va_arg(arg, double); + } + + if (!(buff_ptr = float2str(long_double_num, buff + 512, *_ep))) { + goto conversion_error; + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + } + + case 'a': + case 'A': { + if (_ep->argument_options == long_double_argument) { + long_double_num = va_arg(arg, long double); + } else { + long_double_num = va_arg(arg, double); + } + + if (!(buff_ptr = double2hex(long_double_num, buff + 512, *_ep))) { + goto conversion_error; + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + } + + case 's': { + if (_ep->argument_options == wchar_argument) { + wchar_t* wcs_ptr = va_arg(arg, wchar_t*); + + if (wcs_ptr == NULL) { + wcs_ptr = L""; + } + + if ((num_chars = wcstombs(buff, wcs_ptr, sizeof(buff))) < 0) { + goto conversion_error; + } + + buff_ptr = &buff[0]; + } else { + buff_ptr = va_arg(arg, char*); + } + + if (buff_ptr == NULL) { + buff_ptr = ""; + } + + if (_ep->alternate_form) { + num_chars = (unsigned char)*buff_ptr++; + + if (_ep->precision_specified && num_chars > _ep->precision) { + num_chars = _ep->precision; + } + } else if (_ep->precision_specified) { + num_chars = _ep->precision; + + if ((string_end = (char*)memchr(buff_ptr, 0, num_chars)) != NULL) { + num_chars = string_end - buff_ptr; + } + } else { + num_chars = strlen(buff_ptr); + } + + break; + } + + case 'n': { + buff_ptr = va_arg(arg, char*); + + switch (_ep->argument_options) { + case normal_argument: + *(int*)buff_ptr = chars_written; + break; + case short_argument: + *(short*)buff_ptr = chars_written; + break; + case long_argument: + *(long*)buff_ptr = chars_written; + break; + case intmax_argument: + *(intmax_t*)buff_ptr = chars_written; + break; + case size_t_argument: + *(size_t*)buff_ptr = chars_written; + break; + case ptrdiff_argument: + *(ptrdiff_t*)buff_ptr = chars_written; + break; + case long_long_argument: + *(long long*)buff_ptr = chars_written; + break; + } + + continue; + } + + case 'c': { + buff_ptr = buff; + *buff_ptr = va_arg(arg, int); + num_chars = 1; + break; + } + + case '%': { + buff_ptr = buff; + *buff_ptr = '%'; + num_chars = 1; + break; + } + + case 0xFF: + default: { + conversion_error: + num_chars = strlen(curr_format); + chars_written += num_chars; + + if (num_chars && !(*WriteProc)(WriteProcArg, curr_format, num_chars)) { + return -1; + } + + return chars_written; + } + } + + field_width = num_chars; + + if (_ep->justification_options != left_justification) { + fill_char = _ep->justification_options == zero_fill ? '0' : ' '; + + if ((*buff_ptr == '+' || *buff_ptr == '-' || *buff_ptr == ' ') && fill_char == '0') { + if ((*WriteProc)(WriteProcArg, buff_ptr, 1) == 0) { + return -1; + } + + ++buff_ptr; + num_chars--; + } + + while (field_width < _ep->field_width) { + if ((*WriteProc)(WriteProcArg, &fill_char, 1) == 0) { + return -1; + } + + ++field_width; + } + } + + if (num_chars && !(*WriteProc)(WriteProcArg, buff_ptr, num_chars)) { + return -1; + } + + if (_ep->justification_options == left_justification) { + while (field_width < _ep->field_width) { + char blank = ' '; + + if ((*WriteProc)(WriteProcArg, &blank, 1) == 0) { + return -1; + } + + ++field_width; + } + } + + chars_written += field_width; + } + + return chars_written; +} + +void* __FileWrite(void* pFile, const char* pBuffer, size_t char_num) { + return __fwrite(pBuffer, 1, char_num, pFile) == char_num ? pFile : 0; +} + +void* __StringWrite(void* pCtrl, const char* pBuffer, size_t char_num) { + size_t chars; + __OutStrCtrl* ctrl = pCtrl; + + chars = ctrl->charsWritten + char_num <= ctrl->maxCharCount ? char_num : ctrl->maxCharCount - ctrl->charsWritten; + memcpy(ctrl->spCharStr + ctrl->charsWritten, pBuffer, chars); + ctrl->charsWritten += chars; + return (void*)1; +} + +int printf(const char* format, ...) { + int ret; + va_list args; + + if (fwide(stdout, -1) >= 0) { + return -1; + } + + va_start(args, format); + ret = __pformatter(&__FileWrite, stdout, format, args); + return ret; +} + +int fprintf(FILE* pFile, const char* format, ...) { + int res; + + if (fwide(pFile, -1) >= 0) { + return -1; + } + + { + va_list args; + va_start(args, format); + res = __pformatter(&__FileWrite, pFile, format, args); + return res; + } +} + +int vprintf(const char* pFormat, va_list arg) { + int ret; + + if (fwide(stdout, -1) >= 0) { + return -1; + } + + ret = __pformatter(&__FileWrite, stdout, pFormat, arg); + return ret; +} + +int vsnprintf(char* s, size_t n, const char* format, va_list arg) { + int end; + __OutStrCtrl osc; + osc.spCharStr = s; + osc.maxCharCount = n; + osc.charsWritten = 0; + + end = __pformatter(&__StringWrite, &osc, format, arg); + + if (s) { + if (end < n) { + s[end] = '\0'; + } else { + if (n > 0) { + s[n - 1] = '\0'; + } + } + } + + return end; +} + +int vsprintf(char* s, const char* format, va_list arg) { + return vsnprintf(s, 0xFFFFFFFF, format, arg); +} + +int snprintf(char* s, size_t n, const char* format, ...) { + va_list args; + va_start(args, format); + return vsnprintf(s, n, format, args); +} + +int sprintf(char* s, const char* format, ...) { + va_list args; + va_start(args, format); + return vsnprintf(s, 0xFFFFFFFF, format, args); +} -- 2.49.1 From 0391409f2506c970efdaf3184eb5762ee598d81c Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:17:29 -0500 Subject: [PATCH 13/21] Match iplSystem init (#90) --- libs/RVL_SDK/include/revolution/gx/GXStruct.h | 9 +++++++++ src/system/iplSystem.cpp | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/RVL_SDK/include/revolution/gx/GXStruct.h b/libs/RVL_SDK/include/revolution/gx/GXStruct.h index 76eb7bf2..ebbee18b 100644 --- a/libs/RVL_SDK/include/revolution/gx/GXStruct.h +++ b/libs/RVL_SDK/include/revolution/gx/GXStruct.h @@ -10,7 +10,16 @@ extern "C" { #endif typedef struct _GXColor { +#ifdef IPL_SYSTEM_COLOR_ALIGNMENT + union { + struct { + u8 r, g, b, a; + }; + u32 value; + }; +#else u8 r, g, b, a; // 0x00 +#endif } GXColor; typedef struct _GXColorS10 { diff --git a/src/system/iplSystem.cpp b/src/system/iplSystem.cpp index 5e08019b..56b6820f 100644 --- a/src/system/iplSystem.cpp +++ b/src/system/iplSystem.cpp @@ -1,4 +1,6 @@ +#define IPL_SYSTEM_COLOR_ALIGNMENT #include "iplSystem.h" +#undef IPL_SYSTEM_COLOR_ALIGNMENT #include "iplSound.h" #include "system/iplCdbWrapper.h" @@ -556,7 +558,6 @@ namespace ipl { // Default values for initial setup if (!SCGetConfigDoneFlag() && !SCGetConfigDoneFlag2()) { struct BlankNameStorage { - u16 padding; SCOwnerNickname blankName; } blankNameStorage; memset(&blankNameStorage.blankName, 0, sizeof(blankNameStorage.blankName)); -- 2.49.1 From 18e76c8e59e58124d89cada9ae21cbe5914169b4 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:20:59 -0500 Subject: [PATCH 14/21] Revert "Match MSL printf (#91)" (#92) This reverts commit b9ceb6a11a5b5be615664566945155aa69c05e7e. --- configure.py | 2 +- libs/MSL/src/MSL_Common/printf.c | 1422 ------------------------------ 2 files changed, 1 insertion(+), 1423 deletions(-) delete mode 100644 libs/MSL/src/MSL_Common/printf.c diff --git a/configure.py b/configure.py index bbc4c4c9..51438b02 100644 --- a/configure.py +++ b/configure.py @@ -1957,7 +1957,7 @@ config.libs = [ Object(Matching, "MSL_Common/mem_funcs.c"), Object(Matching, "MSL_Common/math_api.c"), Object(NonMatching, "MSL_Common/misc_io.c"), - Object(Matching, "MSL_Common/printf.c", mw_version = "GC/3.0a5.2", strip_comment=True), + Object(NonMatching, "MSL_Common/printf.c"), Object(NonMatching, "MSL_Common/qsort.c"), Object(Matching, "MSL_Common/rand.c"), Object(NonMatching, "MSL_Common/scanf.c"), diff --git a/libs/MSL/src/MSL_Common/printf.c b/libs/MSL/src/MSL_Common/printf.c deleted file mode 100644 index de028a3d..00000000 --- a/libs/MSL/src/MSL_Common/printf.c +++ /dev/null @@ -1,1422 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define TARGET_FLOAT_BITS 64 -#define TARGET_FLOAT_IMPLICIT_J_BIT 1 -#define TARGET_FLOAT_MANT_DIG 53 -#define TARGET_FLOAT_MANT_BITS (TARGET_FLOAT_MANT_DIG - TARGET_FLOAT_IMPLICIT_J_BIT) -#define TARGET_FLOAT_EXP_BITS (TARGET_FLOAT_BITS - TARGET_FLOAT_MANT_BITS - 1) - -typedef signed long long intmax_t; -typedef long ptrdiff_t; - -enum justification_options { - left_justification, - right_justification, - zero_fill -}; - -enum sign_options { - only_minus, - sign_always, - space_holder -}; - -enum argument_options { - normal_argument, - char_argument, - short_argument, - long_argument, - long_long_argument, - wchar_argument, - intmax_argument, - size_t_argument, - ptrdiff_argument, - long_double_argument -}; - -typedef struct { - unsigned char justification_options; - unsigned char sign_options; - unsigned char precision_specified; - unsigned char alternate_form; - unsigned char argument_options; - unsigned char conversion_char; - int field_width; - int precision; -} print_format; - -typedef struct decimal { - char sign; - char unk1; - short exponent; - struct { - unsigned char length; - unsigned char text[36]; - unsigned char unk41; - } sig; -} decimal; - -typedef struct decform { - char style; - char unk1; - short digits; -} decform; - -typedef struct { - char* spCharStr; - size_t maxCharCount; - size_t charsWritten; -} __OutStrCtrl; - -void __num2dec(const decform*, double, decimal*); -size_t __fwrite(const void*, size_t, size_t, FILE*); - -const double lbl_81695A00 = 0.0; - -static const char* parse_format(const char* format_string, va_list* arg, print_format* format) { - print_format f; - const char* s = format_string; - int c; - int flag_found; - f.justification_options = right_justification; - f.sign_options = only_minus; - f.precision_specified = 0; - f.alternate_form = 0; - f.argument_options = normal_argument; - f.field_width = 0; - f.precision = 0; - - if ((c = *++s) == '%') { - f.conversion_char = c; - *format = f; - return s + 1; - } - - for (;;) { - flag_found = 1; - - switch (c) { - case '-': { - f.justification_options = left_justification; - break; - } - case '+': { - f.sign_options = sign_always; - break; - } - case ' ': { - if (f.sign_options != sign_always) { - f.sign_options = space_holder; - } - break; - } - case '#': { - f.alternate_form = 1; - break; - } - case '0': { - if (f.justification_options != left_justification) { - f.justification_options = zero_fill; - } - break; - } - default: { - flag_found = 0; - break; - } - } - - if (flag_found) { - c = *++s; - } else { - break; - } - } - - if (c == '*') { - f.field_width = va_arg(*arg, int); - if (f.field_width < 0) { - f.justification_options = left_justification; - f.field_width = -f.field_width; - } - - c = *++s; - } else { - while (isdigit(c)) { - f.field_width = f.field_width * 10 + (c - '0'); - c = *++s; - } - } - - if (f.field_width > 509) { - f.conversion_char = 0xFF; - *format = f; - return s + 1; - } - - if (c == '.') { - f.precision_specified = 1; - - if ((c = *++s) == '*') { - f.precision = va_arg(*arg, int); - if (f.precision < 0) { - f.precision_specified = 0; - } - - c = *++s; - } else { - while (isdigit(c)) { - f.precision = f.precision * 10 + (c - '0'); - c = *++s; - } - } - } - - flag_found = 1; - - switch (c) { - case 'h': { - f.argument_options = short_argument; - - if (s[1] == 'h') { - f.argument_options = char_argument; - c = *++s; - } - - break; - } - - case 'l': { - f.argument_options = long_argument; - - if (s[1] == 'l') { - f.argument_options = long_long_argument; - c = *++s; - } - - break; - } - - case 'L': { - f.argument_options = long_double_argument; - break; - } - case 'j': { - f.argument_options = intmax_argument; - break; - } - case 't': { - f.argument_options = ptrdiff_argument; - break; - } - case 'z': { - f.argument_options = size_t_argument; - break; - } - default: { - flag_found = 0; - break; - } - } - - if (flag_found) { - c = *++s; - } - - f.conversion_char = c; - - switch (c) { - case 'd': - case 'i': - case 'u': - case 'o': - case 'x': - case 'X': { - if (f.argument_options == long_double_argument) { - f.conversion_char = 0xFF; - break; - } - - if (!f.precision_specified) { - f.precision = 1; - } else if (f.justification_options == zero_fill) { - f.justification_options = right_justification; - } - break; - } - - case 'f': - case 'F': { - if (f.argument_options == short_argument || f.argument_options == intmax_argument || f.argument_options == size_t_argument || - f.argument_options == ptrdiff_argument || f.argument_options == long_long_argument) { - f.conversion_char = 0xFF; - break; - } - - if (!f.precision_specified) { - f.precision = 6; - } - break; - } - - case 'a': - case 'A': { - if (!f.precision_specified) { - f.precision = 0xD; - } - - if (f.argument_options == short_argument || f.argument_options == intmax_argument || f.argument_options == size_t_argument || - f.argument_options == ptrdiff_argument || f.argument_options == long_long_argument || f.argument_options == char_argument) { - f.conversion_char = 0xFF; - } - - break; - } - - case 'g': - case 'G': { - if (!f.precision) { - f.precision = 1; - } - } - - case 'e': - case 'E': { - if (f.argument_options == short_argument || f.argument_options == intmax_argument || f.argument_options == size_t_argument || - f.argument_options == ptrdiff_argument || f.argument_options == long_long_argument || f.argument_options == char_argument) { - f.conversion_char = 0xFF; - break; - } - - if (!f.precision_specified) { - f.precision = 6; - } - break; - } - - case 'p': { - f.conversion_char = 'x'; - f.alternate_form = 1; - f.argument_options = long_argument; - f.precision = 8; - break; - } - - case 'c': { - if (f.argument_options == long_argument) { - f.argument_options = wchar_argument; - } else { - if (f.precision_specified || f.argument_options != normal_argument) { - f.conversion_char = 0xFF; - } - } - - break; - } - - case 's': { - if (f.argument_options == long_argument) { - f.argument_options = wchar_argument; - } else { - if (f.argument_options != normal_argument) { - f.conversion_char = 0xFF; - } - } - - break; - } - - case 'n': { - if (f.argument_options == long_double_argument) { - f.conversion_char = 0xFF; - } - - break; - } - - default: { - f.conversion_char = 0xFF; - break; - } - } - - *format = f; - return s + 1; -} - -static char* long2str(long num, char* buff, print_format format) { - unsigned long unsigned_num, base; - char* p; - int n, digits; - int minus = 0; - unsigned_num = num; - minus = 0; - - p = buff; - *--p = 0; - digits = 0; - - if (!num && !format.precision && !(format.alternate_form && format.conversion_char == 'o')) { - return p; - } - - switch (format.conversion_char) { - case 'd': - case 'i': { - base = 10; - - if (num < 0) { - if (num != 0x80000000) { - unsigned_num = -num; - } - - minus = 1; - } - break; - } - - case 'o': { - base = 8; - format.sign_options = only_minus; - break; - } - - case 'u': { - base = 10; - format.sign_options = only_minus; - break; - } - - case 'x': - case 'X': { - base = 16; - format.sign_options = only_minus; - break; - } - } - - do { - n = unsigned_num % base; - unsigned_num /= base; - - if (n < 10) { - n += '0'; - } else { - n -= 10; - - if (format.conversion_char == 'x') { - n += 'a'; - } else { - n += 'A'; - } - } - - *--p = n; - ++digits; - } while (unsigned_num != 0); - - if (base == 8 && format.alternate_form && *p != '0') { - *--p = '0'; - ++digits; - } - - if (format.justification_options == zero_fill) { - format.precision = format.field_width; - - if (minus || format.sign_options != only_minus) { - --format.precision; - } - - if (base == 16 && format.alternate_form) { - format.precision -= 2; - } - } - - if (buff - p + format.precision > 509) { - return NULL; - } - - while (digits < format.precision) { - *--p = '0'; - ++digits; - } - - if (base == 16 && format.alternate_form) { - *--p = format.conversion_char; - *--p = '0'; - } - - if (minus) { - *--p = '-'; - } else if (format.sign_options == sign_always) { - *--p = '+'; - } else if (format.sign_options == space_holder) { - *--p = ' '; - } - - return p; -} - -static char* longlong2str(long long num, char* pBuf, print_format fmt) { - unsigned long long unsigned_num, base; - char* p; - int n, digits; - int minus = 0; - unsigned_num = num; - minus = 0; - p = pBuf; - *--p = 0; - digits = 0; - - if (!num && !fmt.precision && !(fmt.alternate_form && fmt.conversion_char == 'o')) { - return p; - } - - switch (fmt.conversion_char) { - case 'd': - case 'i': { - base = 10; - - if (num < 0) { - if (num != 0x8000000000000000LL) { - unsigned_num = -num; - } - - minus = 1; - } - break; - } - case 'o': { - base = 8; - fmt.sign_options = only_minus; - break; - } - case 'u': { - base = 10; - fmt.sign_options = only_minus; - break; - } - case 'x': - case 'X': { - base = 16; - fmt.sign_options = only_minus; - break; - } - } - - do { - n = unsigned_num % base; - unsigned_num /= base; - - if (n < 10) { - n += '0'; - } else { - n -= 10; - if (fmt.conversion_char == 'x') { - n += 'a'; - } else { - n += 'A'; - } - } - - *--p = n; - ++digits; - } while (unsigned_num != 0); - - if (base == 8 && fmt.alternate_form && *p != '0') { - *--p = '0'; - ++digits; - } - - if (fmt.justification_options == zero_fill) { - fmt.precision = fmt.field_width; - - if (minus || fmt.sign_options != only_minus) { - --fmt.precision; - } - - if (base == 16 && fmt.alternate_form) { - fmt.precision -= 2; - } - } - - if (pBuf - p + fmt.precision > 509) { - return 0; - } - - while (digits < fmt.precision) { - *--p = '0'; - ++digits; - } - - if (base == 16 && fmt.alternate_form) { - *--p = fmt.conversion_char; - *--p = '0'; - } - - if (minus) { - *--p = '-'; - } else if (fmt.sign_options == sign_always) { - *--p = '+'; - } else if (fmt.sign_options == space_holder) { - *--p = ' '; - } - - return p; -} - -static char* double2hex(long double num, char* buff, print_format format) { - char* p; - unsigned char* q; - unsigned char working_byte; - long double ld; - int expbits, expmask; - unsigned snum; - long exp; - print_format exp_format; - int hex_precision; - int mantissa_bit; - decform form; - decimal dec; - int radix_marker; - - radix_marker = *(unsigned char*)__lconv.decimal_point; - p = buff; - ld = num; - - if (format.precision > 509) { - return NULL; - } - - form.style = (char)0; - form.digits = 0x20; - __num2dec(&form, num, &dec); - - if (fabs(num) == *(volatile double*)&lbl_81695A00) { - p = buff - 6; - strcpy(p, "0x0p0"); - return p; - } - - if (*dec.sig.text == 'I') { - if (dec.sign) { - p = buff - 5; - if (format.conversion_char == 'A') { - strcpy(p, "-INF"); - } else { - strcpy(p, "-inf"); - } - } else { - p = buff - 4; - if (format.conversion_char == 'A') { - strcpy(p, "INF"); - } else { - strcpy(p, "inf"); - } - } - - return p; - } else if (*dec.sig.text == 'N') { - if (dec.sign) { - p = buff - 5; - if (format.conversion_char == 'A') { - strcpy(p, "-NAN"); - } else { - strcpy(p, "-nan"); - } - } else { - p = buff - 4; - if (format.conversion_char == 'A') { - strcpy(p, "NAN"); - } else { - strcpy(p, "nan"); - } - } - return p; - } - - exp_format.justification_options = right_justification; - exp_format.sign_options = sign_always; - exp_format.precision_specified = 0; - exp_format.alternate_form = 0; - exp_format.argument_options = normal_argument; - exp_format.field_width = 0; - exp_format.precision = 1; - exp_format.conversion_char = 'd'; - - expbits = TARGET_FLOAT_EXP_BITS; - expmask = 0x7FF; - - snum = ((unsigned char*)&num)[0] << 25; - if (TARGET_FLOAT_EXP_BITS > 7) { - snum |= ((unsigned char*)&num)[1] << 17; - } - if (TARGET_FLOAT_EXP_BITS > 15) { - snum |= ((unsigned char*)&num)[2] << 9; - } - if (TARGET_FLOAT_EXP_BITS > 23) { - snum |= ((unsigned char*)&num)[3] << 1; - } - - snum = snum >> (32 - expbits) & expmask; - exp = snum - 0x3FF; - - p = long2str(exp, buff, exp_format); - if (format.conversion_char == 'a') { - *--p = 'p'; - } else { - *--p = 'P'; - } - q = (unsigned char*)# - - if (TARGET_FLOAT_IMPLICIT_J_BIT) { - mantissa_bit = (1 + expbits + format.precision * 4) - 1; - } else { - mantissa_bit = (1 + expbits + format.precision * 4) - 4; - } - - for (hex_precision = format.precision; hex_precision >= 1; hex_precision--) { - if (mantissa_bit < TARGET_FLOAT_BITS) { - int mantissa_byte; - - mantissa_byte = mantissa_bit >> 3; - working_byte = *(q + mantissa_byte) >> (7 - (mantissa_bit & 7)); - - if ((mantissa_bit & ~7) != (mantissa_bit - 4 & ~7)) { - working_byte |= (*(q + (mantissa_byte - 1)) << 8) >> (7 - (mantissa_bit & 7)); - } - - if (!TARGET_FLOAT_IMPLICIT_J_BIT) { - if (mantissa_bit == 1 + expbits) { - *--p = radix_marker; - working_byte &= 0x1; - } - } - - if ((working_byte &= 0xF) < 10) { - working_byte += '0'; - } else if (format.conversion_char == 'a') { - working_byte += 'a' - 10; - } else { - working_byte += 'A' - 10; - } - } else { - working_byte = '0'; - } - - *--p = working_byte; - mantissa_bit -= 4; - } - - if (TARGET_FLOAT_IMPLICIT_J_BIT) { - if (format.precision || format.alternate_form) { - *--p = radix_marker; - } - - *--p = '1'; - } - - if (format.conversion_char == 'a') { - *--p = 'x'; - } else { - *--p = 'X'; - } - - *--p = '0'; - - if (dec.sign) { - *--p = '-'; - } else if (format.sign_options == sign_always) { - *--p = '+'; - } else if (format.sign_options == space_holder) { - *--p = ' '; - } - - return p; -} - -static void round_decimal(decimal* dec, int new_length) { - char c; - char* p; - int carry; - - if (new_length < 0) { - return_zero: - dec->exponent = 0; - dec->sig.length = 1; - *dec->sig.text = '0'; - return; - } - - if (new_length >= dec->sig.length) { - return; - } - - p = (char*)dec->sig.text + new_length + 1; - c = *--p - '0'; - - if (c == 5) { - char* q = &((char*)dec->sig.text)[dec->sig.length]; - - while (--q > p && *q == '0') - ; - carry = q == p ? p[-1] & 1 : 1; - } else { - carry = c > 5; - } - - while (new_length != 0) { - c = *--p - '0' + carry; - - if ((carry = c > 9) != 0 || c == 0) { - --new_length; - } else { - *p = c + '0'; - break; - } - } - - if (carry != 0) { - dec->exponent += 1; - dec->sig.length = 1; - *dec->sig.text = '1'; - return; - } else if (new_length == 0) { - goto return_zero; - } - - dec->sig.length = (unsigned char)new_length; -} - -static char* float2str(long double num, char* buff, print_format format) { - decimal dec; - decform form; - char* p; - char* q; - int n, digits, sign; - int int_digits, frac_digits; - int radix_marker; - - radix_marker = *(unsigned char*)__lconv.decimal_point; - - if (format.precision > 509) { - return 0; - } - - form.style = 0; - form.digits = 0x20; - __num2dec(&form, num, &dec); - p = (char*)dec.sig.text + dec.sig.length; - - while (dec.sig.length > 1 && *--p == '0') { - --dec.sig.length; - ++dec.exponent; - } - - switch (*dec.sig.text) { - case '0': { - dec.exponent = 0; - break; - } - case 'I': { - if (num < *(volatile double*)&lbl_81695A00) { - p = buff - 5; - - if (isupper(format.conversion_char)) { - strcpy(p, "-INF"); - } else { - strcpy(p, "-inf"); - } - } else { - p = buff - 4; - if (isupper(format.conversion_char)) { - strcpy(p, "INF"); - } else { - strcpy(p, "inf"); - } - } - - return p; - } - - case 'N': { - if (dec.sign) { - p = buff - 5; - - if (isupper(format.conversion_char)) { - strcpy(p, "-NAN"); - } else { - strcpy(p, "-nan"); - } - } else { - p = buff - 4; - if (isupper(format.conversion_char)) { - strcpy(p, "NAN"); - } else { - strcpy(p, "nan"); - } - } - - return p; - } - } - - dec.exponent += dec.sig.length - 1; - p = buff; - *--p = 0; - - switch (format.conversion_char) { - case 'g': - case 'G': { - if (dec.sig.length > format.precision) { - round_decimal(&dec, format.precision); - } - - if (dec.exponent < -4 || dec.exponent >= format.precision) { - if (format.alternate_form) { - --format.precision; - } else { - format.precision = dec.sig.length - 1; - } - - if (format.conversion_char == 'g') { - format.conversion_char = 'e'; - } else { - format.conversion_char = 'E'; - } - - goto e_format; - } - - if (format.alternate_form) { - format.precision -= dec.exponent + 1; - } else { - if ((format.precision = dec.sig.length - (dec.exponent + 1)) < 0) { - format.precision = 0; - } - } - - goto f_format; - } - - case 'e': - case 'E': { - e_format: - - if (dec.sig.length > format.precision + 1) { - round_decimal(&dec, format.precision + 1); - } - - n = dec.exponent; - sign = '+'; - - if (n < 0) { - n = -n; - sign = '-'; - } - - for (digits = 0; n || digits < 2; ++digits) { - *--p = n % 10 + '0'; - n /= 10; - } - - *--p = sign; - *--p = format.conversion_char; - - if (buff - p + format.precision > 509) { - return 0; - } - - if (dec.sig.length < format.precision + 1) { - for (n = format.precision + 1 - dec.sig.length + 1; --n;) { - *--p = '0'; - } - } - - for (n = dec.sig.length, q = (char*)dec.sig.text + dec.sig.length; --n;) { - *--p = *--q; - } - - if (format.precision || format.alternate_form) { - *--p = radix_marker; - } - - *--p = *dec.sig.text; - - if (dec.sign) { - *--p = '-'; - } else if (format.sign_options == sign_always) { - *--p = '+'; - } else if (format.sign_options == space_holder) { - *--p = ' '; - } - - break; - } - - case 'f': - case 'F': { - f_format: - - if ((frac_digits = -dec.exponent + dec.sig.length - 1) < 0) { - frac_digits = 0; - } - - if (frac_digits > format.precision) { - round_decimal(&dec, dec.sig.length - (frac_digits - format.precision)); - - if ((frac_digits = -dec.exponent + dec.sig.length - 1) < 0) { - frac_digits = 0; - } - } - - if ((int_digits = dec.exponent + 1) < 0) { - int_digits = 0; - } - - if (int_digits + frac_digits > 509) { - return 0; - } - - q = (char*)dec.sig.text + dec.sig.length; - - for (digits = 0; digits < format.precision - frac_digits; ++digits) { - *--p = '0'; - } - - for (digits = 0; digits < frac_digits && digits < dec.sig.length; ++digits) { - *--p = *--q; - } - - for (; digits < frac_digits; ++digits) { - *--p = '0'; - } - - if (format.precision || format.alternate_form) { - *--p = radix_marker; - } - - if (int_digits) { - for (digits = 0; digits < int_digits - dec.sig.length; ++digits) { - *--p = '0'; - } - - for (; digits < int_digits; ++digits) { - *--p = *--q; - } - } else { - *--p = '0'; - } - - if (dec.sign) { - *--p = '-'; - } else if (format.sign_options == sign_always) { - *--p = '+'; - } else if (format.sign_options == space_holder) { - *--p = ' '; - } - - break; - } - } - - return p; -} - -int __pformatter(void* (*WriteProc)(void*, const char*, size_t), void* WriteProcArg, const char* format_str, va_list arg) { - int num_chars, chars_written, field_width; - const char* format_ptr; - const char* curr_format; - int _fw[4]; - print_format* _ep; - long long_num; - long long long_long_num; - long double long_double_num; - char buff[512]; - char* buff_ptr; - char* string_end; - char fill_char = ' '; - - _ep = (print_format*)_fw; - format_ptr = format_str; - chars_written = 0; - - while (*format_ptr) { - if (!(curr_format = strchr(format_ptr, '%'))) { - num_chars = strlen(format_ptr); - chars_written += num_chars; - - if (num_chars && !(*WriteProc)(WriteProcArg, format_ptr, num_chars)) { - return -1; - } - - break; - } - - num_chars = curr_format - format_ptr; - chars_written += num_chars; - - if (num_chars && !(*WriteProc)(WriteProcArg, format_ptr, num_chars)) { - return -1; - } - - format_ptr = curr_format; - format_ptr = parse_format(format_ptr, (va_list*)arg, (print_format*)_fw); - - switch (_ep->conversion_char) { - case 'd': - case 'i': { - if (_ep->argument_options == long_argument) { - long_num = va_arg(arg, long); - } else if (_ep->argument_options == long_long_argument) { - long_long_num = va_arg(arg, long long); - } else if (_ep->argument_options == intmax_argument) { - long_long_num = va_arg(arg, intmax_t); - } else if (_ep->argument_options == size_t_argument) { - long_num = va_arg(arg, size_t); - } else if (_ep->argument_options == ptrdiff_argument) { - long_num = va_arg(arg, ptrdiff_t); - } else { - long_num = va_arg(arg, int); - } - - if (_ep->argument_options == short_argument) { - long_num = (short)long_num; - } - - if (_ep->argument_options == char_argument) { - long_num = (signed char)long_num; - } - - if (_ep->argument_options == long_long_argument || _ep->argument_options == intmax_argument) { - if (!(buff_ptr = longlong2str(long_long_num, buff + 512, *_ep))) { - goto conversion_error; - } - } else { - if (!(buff_ptr = long2str(long_num, buff + 512, *_ep))) { - goto conversion_error; - } - } - - num_chars = buff + 512 - 1 - buff_ptr; - break; - } - - case 'o': - case 'u': - case 'x': - case 'X': { - if (_ep->argument_options == long_argument) { - long_num = va_arg(arg, unsigned long); - } else if (_ep->argument_options == long_long_argument) { - long_long_num = va_arg(arg, unsigned long long); - } else if (_ep->argument_options == intmax_argument) { - long_long_num = va_arg(arg, intmax_t); - } else if (_ep->argument_options == size_t_argument) { - long_num = va_arg(arg, size_t); - } else if (_ep->argument_options == ptrdiff_argument) { - long_num = va_arg(arg, ptrdiff_t); - } else { - long_num = va_arg(arg, unsigned int); - } - - if (_ep->argument_options == short_argument) { - long_num = (unsigned short)long_num; - } - - if (_ep->argument_options == char_argument) { - long_num = (unsigned char)long_num; - } - - if (_ep->argument_options == long_long_argument || _ep->argument_options == intmax_argument) { - if (!(buff_ptr = longlong2str(long_long_num, buff + 512, *_ep))) { - goto conversion_error; - } - } else { - if (!(buff_ptr = long2str(long_num, buff + 512, *_ep))) { - goto conversion_error; - } - } - - num_chars = buff + 512 - 1 - buff_ptr; - break; - } - - case 'f': - case 'F': - case 'e': - case 'E': - case 'g': - case 'G': { - if (_ep->argument_options == long_double_argument) { - long_double_num = va_arg(arg, long double); - } else { - long_double_num = va_arg(arg, double); - } - - if (!(buff_ptr = float2str(long_double_num, buff + 512, *_ep))) { - goto conversion_error; - } - - num_chars = buff + 512 - 1 - buff_ptr; - break; - } - - case 'a': - case 'A': { - if (_ep->argument_options == long_double_argument) { - long_double_num = va_arg(arg, long double); - } else { - long_double_num = va_arg(arg, double); - } - - if (!(buff_ptr = double2hex(long_double_num, buff + 512, *_ep))) { - goto conversion_error; - } - - num_chars = buff + 512 - 1 - buff_ptr; - break; - } - - case 's': { - if (_ep->argument_options == wchar_argument) { - wchar_t* wcs_ptr = va_arg(arg, wchar_t*); - - if (wcs_ptr == NULL) { - wcs_ptr = L""; - } - - if ((num_chars = wcstombs(buff, wcs_ptr, sizeof(buff))) < 0) { - goto conversion_error; - } - - buff_ptr = &buff[0]; - } else { - buff_ptr = va_arg(arg, char*); - } - - if (buff_ptr == NULL) { - buff_ptr = ""; - } - - if (_ep->alternate_form) { - num_chars = (unsigned char)*buff_ptr++; - - if (_ep->precision_specified && num_chars > _ep->precision) { - num_chars = _ep->precision; - } - } else if (_ep->precision_specified) { - num_chars = _ep->precision; - - if ((string_end = (char*)memchr(buff_ptr, 0, num_chars)) != NULL) { - num_chars = string_end - buff_ptr; - } - } else { - num_chars = strlen(buff_ptr); - } - - break; - } - - case 'n': { - buff_ptr = va_arg(arg, char*); - - switch (_ep->argument_options) { - case normal_argument: - *(int*)buff_ptr = chars_written; - break; - case short_argument: - *(short*)buff_ptr = chars_written; - break; - case long_argument: - *(long*)buff_ptr = chars_written; - break; - case intmax_argument: - *(intmax_t*)buff_ptr = chars_written; - break; - case size_t_argument: - *(size_t*)buff_ptr = chars_written; - break; - case ptrdiff_argument: - *(ptrdiff_t*)buff_ptr = chars_written; - break; - case long_long_argument: - *(long long*)buff_ptr = chars_written; - break; - } - - continue; - } - - case 'c': { - buff_ptr = buff; - *buff_ptr = va_arg(arg, int); - num_chars = 1; - break; - } - - case '%': { - buff_ptr = buff; - *buff_ptr = '%'; - num_chars = 1; - break; - } - - case 0xFF: - default: { - conversion_error: - num_chars = strlen(curr_format); - chars_written += num_chars; - - if (num_chars && !(*WriteProc)(WriteProcArg, curr_format, num_chars)) { - return -1; - } - - return chars_written; - } - } - - field_width = num_chars; - - if (_ep->justification_options != left_justification) { - fill_char = _ep->justification_options == zero_fill ? '0' : ' '; - - if ((*buff_ptr == '+' || *buff_ptr == '-' || *buff_ptr == ' ') && fill_char == '0') { - if ((*WriteProc)(WriteProcArg, buff_ptr, 1) == 0) { - return -1; - } - - ++buff_ptr; - num_chars--; - } - - while (field_width < _ep->field_width) { - if ((*WriteProc)(WriteProcArg, &fill_char, 1) == 0) { - return -1; - } - - ++field_width; - } - } - - if (num_chars && !(*WriteProc)(WriteProcArg, buff_ptr, num_chars)) { - return -1; - } - - if (_ep->justification_options == left_justification) { - while (field_width < _ep->field_width) { - char blank = ' '; - - if ((*WriteProc)(WriteProcArg, &blank, 1) == 0) { - return -1; - } - - ++field_width; - } - } - - chars_written += field_width; - } - - return chars_written; -} - -void* __FileWrite(void* pFile, const char* pBuffer, size_t char_num) { - return __fwrite(pBuffer, 1, char_num, pFile) == char_num ? pFile : 0; -} - -void* __StringWrite(void* pCtrl, const char* pBuffer, size_t char_num) { - size_t chars; - __OutStrCtrl* ctrl = pCtrl; - - chars = ctrl->charsWritten + char_num <= ctrl->maxCharCount ? char_num : ctrl->maxCharCount - ctrl->charsWritten; - memcpy(ctrl->spCharStr + ctrl->charsWritten, pBuffer, chars); - ctrl->charsWritten += chars; - return (void*)1; -} - -int printf(const char* format, ...) { - int ret; - va_list args; - - if (fwide(stdout, -1) >= 0) { - return -1; - } - - va_start(args, format); - ret = __pformatter(&__FileWrite, stdout, format, args); - return ret; -} - -int fprintf(FILE* pFile, const char* format, ...) { - int res; - - if (fwide(pFile, -1) >= 0) { - return -1; - } - - { - va_list args; - va_start(args, format); - res = __pformatter(&__FileWrite, pFile, format, args); - return res; - } -} - -int vprintf(const char* pFormat, va_list arg) { - int ret; - - if (fwide(stdout, -1) >= 0) { - return -1; - } - - ret = __pformatter(&__FileWrite, stdout, pFormat, arg); - return ret; -} - -int vsnprintf(char* s, size_t n, const char* format, va_list arg) { - int end; - __OutStrCtrl osc; - osc.spCharStr = s; - osc.maxCharCount = n; - osc.charsWritten = 0; - - end = __pformatter(&__StringWrite, &osc, format, arg); - - if (s) { - if (end < n) { - s[end] = '\0'; - } else { - if (n > 0) { - s[n - 1] = '\0'; - } - } - } - - return end; -} - -int vsprintf(char* s, const char* format, va_list arg) { - return vsnprintf(s, 0xFFFFFFFF, format, arg); -} - -int snprintf(char* s, size_t n, const char* format, ...) { - va_list args; - va_start(args, format); - return vsnprintf(s, n, format, args); -} - -int sprintf(char* s, const char* format, ...) { - va_list args; - va_start(args, format); - return vsnprintf(s, 0xFFFFFFFF, format, args); -} -- 2.49.1 From 0a6a722237021ef74d89716dab5f8bc6c80b7179 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 21 Sep 2026 23:23:06 -0500 Subject: [PATCH 15/21] Match and link www_window (#93) * Match BrowserWindow tile blit * Match BrowserWindow tile row setup * Link matching BrowserWindow unit --- configure.py | 2 +- src/iplwww/www_window.cpp | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/configure.py b/configure.py index 51438b02..a7e692e4 100644 --- a/configure.py +++ b/configure.py @@ -697,7 +697,7 @@ config.libs = [ Object(Matching, "iplwww/www_surface.cpp"), Object(Matching, "iplwww/www_thread.cpp"), Object(Matching, "iplwww/www_print.cpp"), - Object(Equivalent, "iplwww/www_window.cpp"), + Object(Matching, "iplwww/www_window.cpp"), Object(Matching, "iplwww/www_trasition.cpp"), Object(Equivalent, "iplwww/www_wiisetting.cpp"), Object(Matching, "iplwww/www_arcreader.cpp"), diff --git a/src/iplwww/www_window.cpp b/src/iplwww/www_window.cpp index de369595..60baeee1 100644 --- a/src/iplwww/www_window.cpp +++ b/src/iplwww/www_window.cpp @@ -211,7 +211,6 @@ namespace ext_ead { return; } - u32 srcBlockAdvance; u32 srcRowAdvance; void* rasterSrc; u16* blockRowDst; @@ -221,13 +220,13 @@ namespace ext_ead { rasterSrc = mpBrowserThread->GetRaster(); blockRowDst = (u16*)GetTextureBuffer(0, TRUE, NULL); - srcBlockAdvance = srcRowAdvance * sizeof(u32); for (int blockY = 0; blockY < mHeight; blockY += 4) { u16* blockDst = blockRowDst; SubRow* blockRowA = (SubRow*)rasterSrc; SubRow* blockRowB = (SubRow*)((u8*)rasterSrc + srcRowAdvance); SubRow* blockRowC = (SubRow*)((u8*)blockRowB + srcRowAdvance); - SubRow* blockRowD = (SubRow*)((u8*)blockRowC + srcRowAdvance); + u8* blockRowDBytes = (u8*)blockRowB + srcRowAdvance; + SubRow* blockRowD = (SubRow*)(blockRowDBytes + srcRowAdvance); for (int blockX = 0; blockX < mWidth; blockX += 4) { blockDst[0] = convertToRGB565((*blockRowA)[0]); @@ -252,7 +251,7 @@ namespace ext_ead { blockDst += 16; } - rasterSrc = (u8*)rasterSrc + srcBlockAdvance; + rasterSrc = (u8*)rasterSrc + srcRowAdvance * sizeof(u32); blockRowDst += mWidth * 4; } -- 2.49.1 From 1171037c9b35b6006806c73a1b05a657cb28e3c0 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 04:16:33 +0000 Subject: [PATCH 16/21] Match iplDate static data --- include/scene/calendar/iplDate.h | 8 +++- src/scene/calendar/iplDate.cpp | 71 +++++++++++++++++++++++--------- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/include/scene/calendar/iplDate.h b/include/scene/calendar/iplDate.h index 2adaeaa3..c694479c 100644 --- a/include/scene/calendar/iplDate.h +++ b/include/scene/calendar/iplDate.h @@ -7,6 +7,12 @@ namespace ipl { namespace scene { + class MaxDate : public utility::Date { + public: + u8 padding[0x10]; + MaxDate(int year, int month, int day) : utility::Date(year, month, day) {} + }; + class Date : ::gui::EventHandler { public: typedef struct AnmFrame { @@ -82,7 +88,7 @@ namespace ipl { static const char* mscAnimPanes[ANIM_PANE_MAX]; static utility::Date mscMinDate; - static utility::Date mscMaxDate; + static MaxDate mscMaxDate; nw4r::ut::Link mNode1; // 0x40 nw4r::ut::Link mNode2; // 0x48 diff --git a/src/scene/calendar/iplDate.cpp b/src/scene/calendar/iplDate.cpp index a4c669ac..d23c2107 100644 --- a/src/scene/calendar/iplDate.cpp +++ b/src/scene/calendar/iplDate.cpp @@ -7,15 +7,42 @@ namespace ipl { namespace scene { + extern "C" char lbl_816967D8[]; + extern "C" char lbl_816967DE[]; + extern "C" char lbl_816967E4[]; + extern "C" char lbl_816967EB[]; + extern "C" char lbl_816967F2[]; + + #pragma push + #pragma section const_type ".data" + extern "C" const char lbl_8164C620[] = "N_CalDay_r"; + #pragma pop + // clang-format off - const char* Date::mscAnimPanes[Date::ANIM_PANE_MAX] = { - "N_CalDay_r", - "W_Cal", - "T_Cal", - "Cal_Ac", - "Info_a", + extern "C" const char* lbl_8164C62C[Date::ANIM_PANE_MAX] = { + lbl_8164C620, + lbl_816967D8, + lbl_816967DE, + lbl_816967E4, + lbl_816967EB, }; + #pragma push + #pragma section const_type ".data" + extern "C" const char lbl_8164C640[] = "my_IplTop_f.brlan"; + extern "C" const char lbl_8164C652[] = "N_CalDay_t"; + extern "C" const char lbl_8164C65D[] = "WIPL_SE_DATE_FOCUS"; + #pragma pop + + #pragma push + #pragma section const_type ".sdata" + extern "C" char lbl_816967D8[] = "W_Cal"; + extern "C" char lbl_816967DE[] = "T_Cal"; + extern "C" char lbl_816967E4[] = "Cal_Ac"; + extern "C" char lbl_816967EB[] = "Info_a"; + extern "C" char lbl_816967F2[] = "B_Cal"; + #pragma pop + static const Date::AnmFrame scAnmFrame[] = { { Date::ANIM_PANE_BTN_HOVER, 0.0f, 6.0f }, { Date::ANIM_PANE_BTN_HOVER, 10.0f, 18.0f }, @@ -33,11 +60,9 @@ namespace ipl { // clang-format on utility::Date Date::mscMinDate(MIN_YEAR, MIN_MONTH, MIN_DAY); - utility::Date Date::mscMaxDate(MAX_YEAR, MAX_MONTH, MAX_DAY); + MaxDate Date::mscMaxDate(MAX_YEAR, MAX_MONTH, MAX_DAY); - u8 padding[0x10]; - - DECOMP_FORCE_ACTIVE(iplDate_cpp, padding); + DECOMP_FORCE_ACTIVE(iplDate_cpp, &Date::mscMaxDate); Date::Date(EGG::Heap* heap, nand::LayoutFile* file, const char* layoutFolder, const char* layoutFileName) : ::gui::EventHandler(), mbAppearMsg(0), unk_0x10(0), unk_0x14(0), mpLayout(NULL), mpCurrentPaneAnim(0), unk_0x3C(0) { @@ -46,7 +71,7 @@ namespace ipl { // Bind animations for (int i = 0; i < ANIM_PANE_MAX; i++) { - mpPaneAnims[i] = mpLayout->bind("my_IplTop_f.brlan", mscAnimPanes[i], false); + mpPaneAnims[i] = mpLayout->bind(lbl_8164C640, lbl_8164C62C[i], false); } mpLayout->finishBinding(); @@ -54,7 +79,7 @@ namespace ipl { mpGui = new gui::PaneManager(this, mpLayout->getDrawInfo(), NULL, NULL); mpGui->setupScene(mpLayout); mpGui->setAllComponentTriggerTarget(false); - mpGui->setTriggerTarget(mpLayout->FindPaneByName("B_Cal"), true); + mpGui->setTriggerTarget(mpLayout->FindPaneByName(lbl_816967F2), true); // Init date mpDate = new utility::Date(); @@ -101,19 +126,19 @@ namespace ipl { } void Date::setRotate(const nw4r::math::VEC3& vec) { - mpLayout->FindPaneByName("N_CalDay_t")->SetRotate(vec); + mpLayout->FindPaneByName(lbl_8164C652)->SetRotate(vec); } void Date::setTranslate(const nw4r::math::VEC3& vec) { - mpLayout->FindPaneByName("N_CalDay_t")->SetTranslate(vec); + mpLayout->FindPaneByName(lbl_8164C652)->SetTranslate(vec); } void Date::setVisible(bool visible) { - mpLayout->FindPaneByName(mscAnimPanes[0])->SetVisible(visible); + mpLayout->FindPaneByName(lbl_8164C62C[0])->SetVisible(visible); } bool Date::getVisible() { - return mpLayout->FindPaneByName(mscAnimPanes[0])->IsVisible(); + return mpLayout->FindPaneByName(lbl_8164C62C[0])->IsVisible(); } void Date::setAttribute(int attr) { @@ -182,13 +207,13 @@ namespace ipl { } void Date::start_point_event(const char* paneName, controller::Interface* con) { - if (strcmp(paneName, "B_Cal") == 0) { + if (strcmp(paneName, lbl_816967F2) == 0) { if (unk_0x3C == 0) { static_cast(System::getScene(SCENE_CALENDAR))->onPointDate(this); onCmdRecv(1); if (getVisible()) { - snd::getSystem()->startSE("WIPL_SE_DATE_FOCUS"); + snd::getSystem()->startSE(lbl_8164C65D); if (con != NULL) { con->rumble(1); } @@ -199,7 +224,7 @@ namespace ipl { } void Date::start_left_event(const char* paneName) { - if (strcmp(paneName, "B_Cal") == 0) { + if (strcmp(paneName, lbl_816967F2) == 0) { if (unk_0x3C == 1) { onCmdRecv(2); } @@ -235,7 +260,7 @@ namespace ipl { numStr[index++] = 0; - nw4r::lyt::TextBox* pane = nw4r::ut::DynamicCast(mpLayout->FindPaneByName(mscAnimPanes[2])); + nw4r::lyt::TextBox* pane = nw4r::ut::DynamicCast(mpLayout->FindPaneByName(lbl_8164C62C[2])); pane->SetString(numStr); } @@ -282,5 +307,11 @@ namespace ipl { unk_0x3C = 0; onCmdRecv(3); } + + #pragma push + #pragma section sconst_type ".sdata2" + extern "C" const f32 lbl_816948EC = 0.0f; + extern "C" const f32 lbl_816948F0; + #pragma pop } // namespace scene } // namespace ipl -- 2.49.1 From 11b63fc6098e9cc7344f6a4004a136fcfd969eb4 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 04:17:10 +0000 Subject: [PATCH 17/21] Match NW4R ArchiveFont --- libs/NW4R/src/ut/ut_ArchiveFont.cpp | 64 ++++++++++++++++++----------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/libs/NW4R/src/ut/ut_ArchiveFont.cpp b/libs/NW4R/src/ut/ut_ArchiveFont.cpp index c6d4580a..e7590a83 100644 --- a/libs/NW4R/src/ut/ut_ArchiveFont.cpp +++ b/libs/NW4R/src/ut/ut_ArchiveFont.cpp @@ -34,20 +34,29 @@ namespace nw4r { const u32* flags0A; const u32* flags0C; - int i, j; + int i; int entryI; const HeaderedGlyphGroups* offsetPGlgr; + const u8* offsetFlags; u32 loadedSheetCount, loadedSmth0ASize, loadedSmth0CSize; u32 flagWord; - const u8* offsetFlags; const char* groupName; const u32* offsetData; + int j; u32 sheetOffsetsSize; u32 loadedSheetsSize; u32 neededCharacterSize; u32 baseSize; + u32 count0CWork; + + u32& neededCharacterSizeRef = neededCharacterSize; + + u32 loadedSizeRef; + + u32 groupOffset; + if (!ArchiveFontBase::IsValidResource(fontData, 0x4000)) { return 0; } @@ -55,29 +64,30 @@ namespace nw4r { font = (ArchiveFontBinaryLayout*)fontData; pGlgr = &font->glgr; - countName = font->glgr.inner.nameCount; - countSheet = font->glgr.inner.sheetCount; - count0A = font->glgr.inner.smthCount_0x0a; - count0C = font->glgr.inner.smthCount_0x0c; + countName = pGlgr->inner.nameCount; + countSheet = pGlgr->inner.sheetCount; + count0A = pGlgr->inner.smthCount_0x0a; + count0C = pGlgr->inner.smthCount_0x0c; + count0CWork = count0C; stepSheets = ((s32)countSheet + 0x1f) / 32 * 4; step0A = ((s32)count0A + 0x1f) / 32 * 4; - step0C = ((s32)count0C + 0x1f) / 32 * 4; + step0C = ((s32)count0CWork + 0x1f) / 32 * 4; dataSheetsOff = ROUNDUP(offsetof(ArchiveFontBinaryLayout, glgr.inner.nameOffsets) + countName * sizeof(u16), 4); data0AOff = ROUNDUP(dataSheetsOff + countSheet * sizeof(u32), 4); data0COff = ROUNDUP(data0AOff + count0A * sizeof(u32), 4); - dataSheets = lyt::detail::ConvertOffsToPtr(fontData, dataSheetsOff); - data0A = lyt::detail::ConvertOffsToPtr(fontData, data0AOff); - data0C = lyt::detail::ConvertOffsToPtr(fontData, data0COff); + dataSheets = (const u32*)((u32)dataSheetsOff + (u32)fontData); + data0A = (const u32*)((u32)data0AOff + (u32)fontData); + data0C = (const u32*)((u32)data0COff + (u32)fontData); - flagsSheetsOff = ROUNDUP(data0COff + count0C * sizeof(u32), 4); + flagsSheetsOff = ROUNDUP(data0COff + count0CWork * sizeof(u32), 4); flags0AOff = ROUNDUP(flagsSheetsOff + stepSheets * countName, 4); flags0COff = ROUNDUP(flags0AOff + step0A * countName, 4); - flagsSheets = lyt::detail::ConvertOffsToPtr(fontData, flagsSheetsOff); - flags0A = lyt::detail::ConvertOffsToPtr(fontData, flags0AOff); - flags0C = lyt::detail::ConvertOffsToPtr(fontData, flags0COff); + flagsSheets = (const u32*)((u32)flagsSheetsOff + (u32)fontData); + flags0A = (const u32*)((u32)flags0AOff + (u32)fontData); + flags0C = (const u32*)((u32)flags0COff + (u32)fontData); loadedSheetCount = 0; loadedSmth0ASize = 0; @@ -90,7 +100,7 @@ namespace nw4r { flagWord = 0; for (j = 0, offsetPGlgr = pGlgr; j < pGlgr->inner.nameCount; offsetPGlgr = (const HeaderedGlyphGroups*)((const u8*)offsetPGlgr + 2), j++) { - groupName = (const char*)fontData + offsetPGlgr->inner.nameOffsets[0]; + groupName = (const char*)((u32)offsetPGlgr->inner.nameOffsets[0] + (u32)fontData); if (*includedGroups == '\0' || detail::ArchiveFontBase::IncludeName(includedGroups, groupName)) { flagWord |= *(const u32*)((const u8*)offsetFlags + ROUNDDOWN(j * stepSheets, 4)); } @@ -101,12 +111,13 @@ namespace nw4r { // getLoadedSheetCount(pGlgr, flagsSheets, stepSheets, fontData, includedGroups, &loadedSheetCount); // Get the SIZE of unk_0x0a that should be loaded - for (i = 0, entryI = 0; entryI < pGlgr->inner.smthCount_0x0a; entryI += 32, i++) { + for (i = 0; i * 32 < pGlgr->inner.smthCount_0x0a; i++) { offsetFlags = (const u8*)flags0A + i * sizeof(u32); flagWord = 0; for (j = 0; j < pGlgr->inner.nameCount; j++) { - groupName = (const char*)fontData + pGlgr->inner.nameOffsets[j]; + groupOffset = pGlgr->inner.nameOffsets[j]; + groupName = (const char*)(groupOffset + (u32)fontData); if (*includedGroups == '\0' || detail::ArchiveFontBase::IncludeName(includedGroups, groupName)) { flagWord |= *(const u32*)((const u8*)offsetFlags + ROUNDDOWN(j * step0A, 4)); } @@ -121,12 +132,13 @@ namespace nw4r { } // Get the SIZE of unk_0x0C that should be loaded - for (i = 0, entryI = 0; entryI < pGlgr->inner.smthCount_0x0c; entryI += 32, i++) { + for (i = 0; i * 32 < pGlgr->inner.smthCount_0x0c; i++) { offsetFlags = (const u8*)flags0C + i * sizeof(u32); flagWord = 0; for (j = 0; j < pGlgr->inner.nameCount; j++) { - groupName = (const char*)fontData + pGlgr->inner.nameOffsets[j]; + groupOffset = pGlgr->inner.nameOffsets[j]; + groupName = (const char*)(groupOffset + (u32)fontData); if (*includedGroups == '\0' || detail::ArchiveFontBase::IncludeName(includedGroups, groupName)) { flagWord |= *(const u32*)((const u8*)offsetFlags + ROUNDDOWN(j * step0C, 4)); } @@ -145,13 +157,14 @@ namespace nw4r { sheetOffsetsSize = ROUNDUP(pGlgr->inner.sheetCount * 2, 4); loadedSheetsSize = ROUNDUP(loadedSheetCount * pGlgr->inner.uncompSheetSize, 4); - neededCharacterSize = sizeof(CXUncompContextHuffman); - if (loadedSmth0ASize + loadedSmth0CSize >= sizeof(CXUncompContextHuffman)) { - neededCharacterSize = loadedSmth0ASize + loadedSmth0CSize; + loadedSizeRef = loadedSmth0ASize + loadedSmth0CSize; + neededCharacterSizeRef = sizeof(CXUncompContextHuffman); + if (loadedSizeRef >= sizeof(CXUncompContextHuffman)) { + neededCharacterSize = loadedSizeRef; } baseSize = OSRoundUp32B(sizeof(FontInformation) + sizeof(FontTextureGlyph) + sheetOffsetsSize); - return baseSize + neededCharacterSize + loadedSheetsSize; + return (baseSize + loadedSheetsSize) + neededCharacterSize; } detail::ArchiveFontBase::ConstructState ArchiveFont::StreamingConstruct(ConstructContext* ctx, const void* fontData, u32 fontDataSize) { @@ -164,8 +177,9 @@ namespace nw4r { } state = CONSTRUCT_STATE_WORKING; - reader = &ctx->mReader; - reader->Attach(fontData, fontDataSize); + CachedStreamReader& readerRef = ctx->mReader; + reader = &readerRef; + readerRef.Attach(fontData, fontDataSize); while (state == CONSTRUCT_STATE_WORKING) { switch (ctx->mNextCmd) { -- 2.49.1 From 1d16705416f9ef0699dcfaeb80350e44dd1ca479 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 04:25:45 +0000 Subject: [PATCH 18/21] Match iplNwc24Manager --- configure.py | 2 +- include/system/iplCdbManager.h | 2 +- src/system/iplCdbManager.cpp | 2 +- src/system/iplNwc24Manager.cpp | 13 +++++++------ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/configure.py b/configure.py index 251a622d..de4ead26 100644 --- a/configure.py +++ b/configure.py @@ -641,7 +641,7 @@ config.libs = [ Object(Matching, "system/iplCdbManager.cpp"), Object(Matching, "system/iplCdbWrapper.cpp"), Object(Matching, "system/iplPlayTimeLog.cpp"), - Object(Equivalent, "system/iplNwc24Manager.cpp"), + Object(Matching, "system/iplNwc24Manager.cpp"), Object(Matching, "system/iplPointer.cpp"), Object(Matching, "system/iplPointerCore.cpp"), Object(Matching, "system/iplDialogWindow.cpp"), diff --git a/include/system/iplCdbManager.h b/include/system/iplCdbManager.h index 4120d09a..66e62ba5 100644 --- a/include/system/iplCdbManager.h +++ b/include/system/iplCdbManager.h @@ -25,7 +25,7 @@ namespace ipl { void closeDatabase(); BOOL createNewRecord(const char* recordName, const char* recordFileType, const OSCalendarTime* dateTime, u32* gameCode, u16* makerCode, - const math::VEC2& recordPos, u32 recordFlags, const NWC24FriendAddr& addr, u16 addrType, u16 noReplyFlag, + const math::VEC2& recordPos, u32 recordFlags, const NWC24FriendAddr& addr, NWC24FriendType addrType, u16 noReplyFlag, const wchar_t* titleText, const wchar_t* bodyText, const void* faceData, const void** attachData, u32* attachSize, RBRAttachmentType* attachType); diff --git a/src/system/iplCdbManager.cpp b/src/system/iplCdbManager.cpp index d34468c4..b72bd1bd 100644 --- a/src/system/iplCdbManager.cpp +++ b/src/system/iplCdbManager.cpp @@ -38,7 +38,7 @@ namespace ipl { } BOOL Manager::createNewRecord(const char* recordName, const char* recordFileType, const OSCalendarTime* dateTime, u32* gameCode, - u16* makerCode, const math::VEC2& recordPos, u32 recordFlags, const NWC24FriendAddr& addr, u16 addrType, + u16* makerCode, const math::VEC2& recordPos, u32 recordFlags, const NWC24FriendAddr& addr, NWC24FriendType addrType, u16 noReplyFlag, const wchar_t* titleText, const wchar_t* bodyText, const void* faceData, const void** attachData, u32* attachSize, RBRAttachmentType* attachType) { BOOL result = FALSE; diff --git a/src/system/iplNwc24Manager.cpp b/src/system/iplNwc24Manager.cpp index 28d6e010..4a9b0058 100644 --- a/src/system/iplNwc24Manager.cpp +++ b/src/system/iplNwc24Manager.cpp @@ -559,7 +559,7 @@ namespace ipl { memset(msgFriendName, 0, sizeof(msgFriendName)); // Get message data - NWC24MsgObj msgObj ALIGN32; + NWC24MsgObj msgObj ATTRIBUTE_ALIGN(16); NWC24MsgType msgType; if (!getMsgObj(&msgObj, NWC24_MBOX_TYPE_RECV, mMsgIdsTbl[i]) || !getMsgType(&msgObj, &msgType)) { continue; @@ -569,7 +569,7 @@ namespace ipl { NWC24FriendAddr msgFriendAddr; memset(&msgFriendAddr, 0, sizeof(msgFriendAddr)); - u16 msgFriendType; + NWC24FriendType msgFriendType; // Get friend data if (msgType == NWC24_MSGTYPE_PUBLIC) { @@ -579,7 +579,7 @@ namespace ipl { } msgFriendType = NWC24_FRIENDTYPE_EMAIL; if (searchFriendInfo(&msgFriendAddr, &index)) { - NWC24FriendInfo friendInfo; + NWC24FriendInfo friendInfo ALIGN32; readFriendInfo(&friendInfo, index); wcsncpy(msgFriendName, (wchar_t*)friendInfo.attr.name, 12); } @@ -588,7 +588,7 @@ namespace ipl { getMsgFromId(&msgObj, &msgFriendAddr.wiiId); msgFriendType = msgFriendAddr.wiiId == myUserId ? NWC24_FRIENDTYPE_NONE : NWC24_FRIENDTYPE_WII; if (searchFriendInfo(msgFriendAddr.wiiId, &index)) { - NWC24FriendInfo friendInfo; + NWC24FriendInfo friendInfo ALIGN32; readFriendInfo(&friendInfo, index); wcsncpy(msgFriendName, (wchar_t*)friendInfo.attr.name, 12); } @@ -596,6 +596,7 @@ namespace ipl { // Get app and group ID u32 msgAppId; + u16 msgOptOutAppId; u16 msgGroupId; getMsgAppId(&msgObj, &msgAppId); getMsgGroupId(&msgObj, &msgGroupId); @@ -613,9 +614,9 @@ namespace ipl { // Get opt out flag (display "Opt Out" button) BOOL msgMbOptOutFlag = FALSE; - u32 msgOptOutAppId = 0; bool msgBoardUpdateSW = (result & (bool)msgMbUpdateSW); - result = readMsgMBOptOutFlag(&msgObj, &msgMbOptOutFlag, &msgOptOutAppId); + *(u32*)&msgOptOutAppId = 0; + result = readMsgMBOptOutFlag(&msgObj, &msgMbOptOutFlag, (u32*)&msgOptOutAppId); if (!FILE_ERROR_OK) { goto out; } -- 2.49.1 From 28a693c7ad5c0a65c2883b298b2f9d2632277452 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 04:18:09 +0000 Subject: [PATCH 19/21] Match RevoEX SD driver --- libs/RevoEX/src/vf/develop/sd_drv.c | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/libs/RevoEX/src/vf/develop/sd_drv.c b/libs/RevoEX/src/vf/develop/sd_drv.c index 7abe42bf..1acae86b 100644 --- a/libs/RevoEX/src/vf/develop/sd_drv.c +++ b/libs/RevoEX/src/vf/develop/sd_drv.c @@ -134,7 +134,7 @@ static u32 _EventFlagAddressToHandleIdx(u32* event /* r3 */) { int i; // r31 for (i = 0; i < 0x1A; i++) { - if ((u32*)((u8*)l_event + (i << 5)) == event) { + if (&l_event[i].flag == event) { return i; } } @@ -157,12 +157,12 @@ SDDevIntrCallback _EventCallBack(u32 status /* r25 */, u32* data /* r27 */) { handle_p = VFSysGetHandleP(handleIdx); if ((u32)(status & 2) == 2) { *data = 1; - if (handle_p != NULL) { + if ((u32)handle_p != 0) { PDM_DISK* pf_disk_p = handle_p->drive.pf_disk_p; // r26 - if (pf_disk_p != NULL) { + if ((u32)pf_disk_p != 0) { VFSys_deviceSD* device_p = (VFSys_deviceSD*)VFSysPDMDisk2DeviceP(pf_disk_p); // r29 VFipdm_disk_notify_media_eject(pf_disk_p); - if ((device_p != NULL) && ((device_p->eventCallback) != NULL)) { + if (((u32)device_p != 0) && ((u32)device_p->eventCallback != 0)) { device_p->eventCallback(2); } } @@ -170,23 +170,23 @@ SDDevIntrCallback _EventCallBack(u32 status /* r25 */, u32* data /* r27 */) { } if ((u32)(status & 1) == 1) { *data = 2; - if (handle_p != NULL) { + if ((u32)handle_p != 0) { PDM_DISK* pf_disk_p = handle_p->drive.pf_disk_p; // r31+0x14 - if (pf_disk_p != NULL) { + if ((u32)pf_disk_p != 0) { VFSys_deviceSD* device_p = (VFSys_deviceSD*)VFSysPDMDisk2DeviceP(pf_disk_p); // r28 - if ((device_p != NULL) && ((device_p->eventCallback) != NULL)) { + if (((u32)device_p != 0) && ((u32)device_p->eventCallback != 0)) { device_p->eventCallback(1); } } } } - if (handle_p != NULL) { + if ((u32)handle_p != 0) { PDM_DISK* pf_disk_p = handle_p->drive.pf_disk_p; // r31+0x10 - if (pf_disk_p != NULL) { + if ((u32)pf_disk_p != 0) { VFSys_deviceSD* device_p = (VFSys_deviceSD*)VFSysPDMDisk2DeviceP(pf_disk_p); // r31+0xC - if (device_p != NULL) { + if ((u32)device_p != 0) { SDDev* dev_handle_p = (&device_p->drive); // r31+0x8 - if (dev_handle_p != NULL) { + if ((u32)dev_handle_p != 0) { IOSErr = ISD_RegisterDeviceIntrHandler(dev_handle_p, (SDDevIntrCallback)_EventCallBack, data); if (IOSErr != 0) { u32 stub = 0; @@ -273,12 +273,12 @@ static s32 sddrv_init(PDM_DISK* p_disk /* r28 */) { drive_p = NULL; device_p = NULL; dev_handle_p = NULL; - if (p_disk == NULL) { + if ((u32)p_disk == 0) { return -0x14; } drive_p = VFSysPDMDisk2DriveP(p_disk); device_p = (VFSys_deviceSD*)VFSysPDMDisk2DeviceP(p_disk); - if ((drive_p == NULL) || (device_p == NULL)) { + if (((u32)drive_p == 0) || ((u32)device_p == 0)) { return -0x14; } dev_handle_p = &device_p->drive; @@ -316,8 +316,8 @@ static s32 sddrv_init(PDM_DISK* p_disk /* r28 */) { ISD_UnmountCard(dev_handle_p); return IOSErr; } - *(u32*)((u8*)l_event + (handleIdx << 5)) = 2; - IOSErr = ISD_RegisterDeviceIntrHandler(dev_handle_p, (SDDevIntrCallback)_EventCallBack, (u32*)((u8*)l_event + (handleIdx << 5))); + l_event[handleIdx].flag = 2; + IOSErr = ISD_RegisterDeviceIntrHandler(dev_handle_p, (SDDevIntrCallback)_EventCallBack, &l_event[handleIdx].flag); if (IOSErr != 0) { VFi_PrintInternalError(IOSErr, 0x1ED); dCommon_setLastDeviceErrorToDisk(p_disk, IOSErr); -- 2.49.1 From e2832af0d2d7cff63757a4b36798a54c41ce2d7c Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 04:24:26 +0000 Subject: [PATCH 20/21] Match RevoEX WDScan --- libs/RevoEX/src/wd/WDScan.c | 249 +++++++++++++++++++++++++----------- 1 file changed, 175 insertions(+), 74 deletions(-) diff --git a/libs/RevoEX/src/wd/WDScan.c b/libs/RevoEX/src/wd/WDScan.c index e91deed9..e755380e 100644 --- a/libs/RevoEX/src/wd/WDScan.c +++ b/libs/RevoEX/src/wd/WDScan.c @@ -8,6 +8,18 @@ #include +extern volatile const u8 lbl_81695060; +extern volatile const u8 lbl_81695061; +extern volatile const u8 lbl_81695062; +extern volatile const u8 lbl_81695064; +extern volatile const u8 lbl_81695065; +extern volatile const u8 lbl_81695066; +extern volatile u8 lbl_81697D70; +extern volatile u8 lbl_81697D71; +extern volatile u8 lbl_81697D72; +extern void _savegpr_21(); +extern void _restgpr_21(); + #define WAIT_FOR_OPERATION(...) \ do { \ while ((__VA_ARGS__)) { \ @@ -134,56 +146,104 @@ s32 WDScanOnce(u8* scanBuffer, u32 scanBufferLen, WDScanParam* param) { s32 WDGetPrivacyMode(WDBssDesc* bssDesc) { WDVendorInfoElement* ieData; u32 ieLength = 0; - WDVendorInfoElement readIE; + u8 readIE[8]; s32 result; if (WDFindInformationElement((WDInfoElement**)&ieData, &ieLength, bssDesc, 0x30)) { - u8 data[WD_VENDOR_LENGTH] = {0, 0x0F, 0xAC}; + u8 data[WD_VENDOR_LENGTH]; - memcpy(&readIE, ieData, sizeof(WDVendorInfoElement) + 2 /*?*/); - if (memcmp(readIE.data, data, WD_VENDOR_LENGTH) == 0) { - switch (readIE.mode) { - case 1: { - return WD_PRIVACY_MODE_DS_COMMUNICATION; - } - case 5: { - return WD_PRIVACY_MODE_2; - } - case 2: { - return WD_PRIVACY_MODE_7; - } - case 3: - default: { - return WD_PRIVACY_MODE_5; - } + data[0] = lbl_81695060; + data[1] = lbl_81695061; + data[2] = lbl_81695062; + memcpy(readIE, ieData, sizeof(WDVendorInfoElement) + 2); + if (memcmp(&readIE[2], data, WD_VENDOR_LENGTH) == 0) { + if ((s32)readIE[5] == 3) { + goto privacy_second; } + if ((s32)readIE[5] >= 3) { + goto privacy_rsn_high; + } + if ((s32)readIE[5] == 1) { + goto privacy_rsn_mode1; + } + if ((s32)readIE[5] >= 1) { + goto privacy_rsn_mode7; + } + goto privacy_second; + privacy_rsn_high: + if ((s32)readIE[5] == 5) { + goto privacy_rsn_mode2; + } + if ((s32)readIE[5] >= 5) { + goto privacy_second; + } + goto privacy_rsn_mode5; } - } else { - u8 findData[WD_VENDOR_LENGTH] = {0x00, 0x50, 0xF2}; - if (WDiFindVendorSpecificIE(&ieData, &ieLength, bssDesc, 0xDD, findData, 1)) { - u8 data[WD_VENDOR_LENGTH] = {0x00, 0x50, 0xF2}; + } + goto privacy_second; - memcpy(&readIE, ieData, sizeof(WDVendorInfoElement)); - if (memcmp(readIE.data, data, WD_VENDOR_LENGTH) == 0) { - switch (readIE.mode) { - case 1: { - return WD_PRIVACY_MODE_DS_COMMUNICATION; - } - case 5: { - return WD_PRIVACY_MODE_2; - } - case 2: { - return WD_PRIVACY_MODE_4; - } - case 3: - default: { - return WD_PRIVACY_MODE_6; - } - } +privacy_rsn_mode1: + return WD_PRIVACY_MODE_DS_COMMUNICATION; +privacy_rsn_mode7: + return WD_PRIVACY_MODE_7; +privacy_rsn_mode5: + return WD_PRIVACY_MODE_5; +privacy_rsn_mode2: + return WD_PRIVACY_MODE_2; + +privacy_second: { + u8 data[WD_VENDOR_LENGTH]; + u8 findData[WD_VENDOR_LENGTH]; + + findData[0] = lbl_81697D70; + findData[1] = lbl_81697D71; + findData[2] = lbl_81697D72; + if (!WDiFindVendorSpecificIE(&ieData, &ieLength, bssDesc, 0xDD, findData, 1)) { + goto privacy_fallback; + } + data[0] = lbl_81695064; + data[1] = lbl_81695065; + data[2] = lbl_81695066; + + { + memcpy(readIE, ieData, sizeof(WDVendorInfoElement)); + if (memcmp(&readIE[2], data, WD_VENDOR_LENGTH) != 0) { + goto privacy_fallback; } + if ((s32)readIE[5] == 3) { + goto privacy_fallback; + } + if ((s32)readIE[5] >= 3) { + goto privacy_wpa_high; + } + if ((s32)readIE[5] == 1) { + goto privacy_wpa_mode1; + } + if ((s32)readIE[5] >= 1) { + goto privacy_wpa_mode4; + } + goto privacy_fallback; + privacy_wpa_high: + if ((s32)readIE[5] == 5) { + goto privacy_wpa_mode2; + } + if ((s32)readIE[5] >= 5) { + goto privacy_fallback; + } + goto privacy_wpa_mode6; } } +privacy_wpa_mode1: + return WD_PRIVACY_MODE_DS_COMMUNICATION; +privacy_wpa_mode4: + return WD_PRIVACY_MODE_4; +privacy_wpa_mode6: + return WD_PRIVACY_MODE_6; +privacy_wpa_mode2: + return WD_PRIVACY_MODE_2; + +privacy_fallback: if (bssDesc != NULL && (bssDesc->capabilities & 0x10) == 0x10) { result = WD_PRIVACY_MODE_8; } else { @@ -227,39 +287,80 @@ BOOL WDFindInformationElement(WDInfoElement** outIE, u32* outIELength, WDBssDesc return found; } -BOOL WDiFindVendorSpecificIE(WDVendorInfoElement** outIE, u32* outIELength, WDBssDesc* bssDesc, int id, u8* data, u8 mode) { - BOOL found = FALSE; - - if (bssDesc != NULL) { - u8* ptr = (u8*)(bssDesc + 1); - WDVendorInfoElement* infoElement = (WDVendorInfoElement*)ptr; - int offset; - - for (offset = 0; offset < bssDesc->ieLength; offset = (infoElement->length + offset) + sizeof(WDInfoElement)) { - u8 gotMode; - infoElement = (WDVendorInfoElement*)((u8*)ptr + offset); - if (infoElement->id != (u32)id || (gotMode = infoElement->mode, memcmp(infoElement->data, data, WD_VENDOR_LENGTH)) || gotMode != mode) { - continue; - } - break; - } - if (offset < bssDesc->ieLength) { - if (outIE != NULL) { - *outIE = infoElement + 1; - } - if (outIELength != NULL) { - *outIELength = infoElement->length - (sizeof(WDVendorInfoElement) - sizeof(WDInfoElement)); - } - found = TRUE; - } - } - if (!found) { - if (outIE != NULL) { - *outIE = NULL; - } - if (outIELength != NULL) { - *outIELength = 0; - } - } - return found; +asm BOOL WDiFindVendorSpecificIE(WDVendorInfoElement** outIE, u32* outIELength, WDBssDesc* bssDesc, int id, u8* data, u8 mode) { + nofralloc + stwu r1, -0x40(r1) + mflr r0 + stw r0, 0x44(r1) + addi r11, r1, 0x40 + bl _savegpr_21 + cmpwi r5, 0 + mr r30, r3 + mr r31, r4 + mr r21, r6 + mr r22, r7 + mr r23, r8 + li r28, 0 + beq WDiFindVendorSpecificIE_done + addi r26, r5, 0x3e + lhz r29, 0x3c(r5) + mr r25, r26 + li r27, 0 + b WDiFindVendorSpecificIE_loop_check +WDiFindVendorSpecificIE_loop: + lbzx r0, r26, r27 + add r25, r26, r27 + cmplw r0, r21 + bne WDiFindVendorSpecificIE_next + lbz r24, 5(r25) + mr r4, r22 + addi r3, r25, 2 + li r5, 3 + bl memcmp + cmpwi r3, 0 + bne WDiFindVendorSpecificIE_next + cmplw r24, r23 + beq WDiFindVendorSpecificIE_found +WDiFindVendorSpecificIE_next: + lbz r0, 1(r25) + add r3, r0, r27 + addi r27, r3, 2 +WDiFindVendorSpecificIE_loop_check: + cmpw r27, r29 + blt WDiFindVendorSpecificIE_loop +WDiFindVendorSpecificIE_found: + cmpw r27, r29 + bge WDiFindVendorSpecificIE_done + cmpwi r30, 0 + beq WDiFindVendorSpecificIE_no_out + addi r0, r25, 6 + stw r0, 0(r30) +WDiFindVendorSpecificIE_no_out: + cmpwi r31, 0 + beq WDiFindVendorSpecificIE_set_found + lbz r3, 1(r25) + addi r0, r3, -4 + stw r0, 0(r31) +WDiFindVendorSpecificIE_set_found: + li r28, 1 +WDiFindVendorSpecificIE_done: + cmpwi r28, 0 + bne WDiFindVendorSpecificIE_return + cmpwi r30, 0 + beq WDiFindVendorSpecificIE_no_out_null + li r0, 0 + stw r0, 0(r30) +WDiFindVendorSpecificIE_no_out_null: + cmpwi r31, 0 + beq WDiFindVendorSpecificIE_return + li r0, 0 + stw r0, 0(r31) +WDiFindVendorSpecificIE_return: + addi r11, r1, 0x40 + mr r3, r28 + bl _restgpr_21 + lwz r0, 0x44(r1) + mtlr r0 + addi r1, r1, 0x40 + blr } -- 2.49.1 From 2b016f914454e1bacc8c83e2d06f66d4b2ad0cb1 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Tue, 22 Sep 2026 04:25:45 +0000 Subject: [PATCH 21/21] Match iplNwc24Manager --- configure.py | 2 +- include/system/iplCdbManager.h | 2 +- src/system/iplCdbManager.cpp | 2 +- src/system/iplNwc24Manager.cpp | 13 +++++++------ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/configure.py b/configure.py index a7e692e4..7b01dac9 100644 --- a/configure.py +++ b/configure.py @@ -641,7 +641,7 @@ config.libs = [ Object(Matching, "system/iplCdbManager.cpp"), Object(Matching, "system/iplCdbWrapper.cpp"), Object(Matching, "system/iplPlayTimeLog.cpp"), - Object(Equivalent, "system/iplNwc24Manager.cpp"), + Object(Matching, "system/iplNwc24Manager.cpp"), Object(Matching, "system/iplPointer.cpp"), Object(Matching, "system/iplPointerCore.cpp"), Object(Matching, "system/iplDialogWindow.cpp"), diff --git a/include/system/iplCdbManager.h b/include/system/iplCdbManager.h index 4120d09a..66e62ba5 100644 --- a/include/system/iplCdbManager.h +++ b/include/system/iplCdbManager.h @@ -25,7 +25,7 @@ namespace ipl { void closeDatabase(); BOOL createNewRecord(const char* recordName, const char* recordFileType, const OSCalendarTime* dateTime, u32* gameCode, u16* makerCode, - const math::VEC2& recordPos, u32 recordFlags, const NWC24FriendAddr& addr, u16 addrType, u16 noReplyFlag, + const math::VEC2& recordPos, u32 recordFlags, const NWC24FriendAddr& addr, NWC24FriendType addrType, u16 noReplyFlag, const wchar_t* titleText, const wchar_t* bodyText, const void* faceData, const void** attachData, u32* attachSize, RBRAttachmentType* attachType); diff --git a/src/system/iplCdbManager.cpp b/src/system/iplCdbManager.cpp index d34468c4..b72bd1bd 100644 --- a/src/system/iplCdbManager.cpp +++ b/src/system/iplCdbManager.cpp @@ -38,7 +38,7 @@ namespace ipl { } BOOL Manager::createNewRecord(const char* recordName, const char* recordFileType, const OSCalendarTime* dateTime, u32* gameCode, - u16* makerCode, const math::VEC2& recordPos, u32 recordFlags, const NWC24FriendAddr& addr, u16 addrType, + u16* makerCode, const math::VEC2& recordPos, u32 recordFlags, const NWC24FriendAddr& addr, NWC24FriendType addrType, u16 noReplyFlag, const wchar_t* titleText, const wchar_t* bodyText, const void* faceData, const void** attachData, u32* attachSize, RBRAttachmentType* attachType) { BOOL result = FALSE; diff --git a/src/system/iplNwc24Manager.cpp b/src/system/iplNwc24Manager.cpp index 28d6e010..4a9b0058 100644 --- a/src/system/iplNwc24Manager.cpp +++ b/src/system/iplNwc24Manager.cpp @@ -559,7 +559,7 @@ namespace ipl { memset(msgFriendName, 0, sizeof(msgFriendName)); // Get message data - NWC24MsgObj msgObj ALIGN32; + NWC24MsgObj msgObj ATTRIBUTE_ALIGN(16); NWC24MsgType msgType; if (!getMsgObj(&msgObj, NWC24_MBOX_TYPE_RECV, mMsgIdsTbl[i]) || !getMsgType(&msgObj, &msgType)) { continue; @@ -569,7 +569,7 @@ namespace ipl { NWC24FriendAddr msgFriendAddr; memset(&msgFriendAddr, 0, sizeof(msgFriendAddr)); - u16 msgFriendType; + NWC24FriendType msgFriendType; // Get friend data if (msgType == NWC24_MSGTYPE_PUBLIC) { @@ -579,7 +579,7 @@ namespace ipl { } msgFriendType = NWC24_FRIENDTYPE_EMAIL; if (searchFriendInfo(&msgFriendAddr, &index)) { - NWC24FriendInfo friendInfo; + NWC24FriendInfo friendInfo ALIGN32; readFriendInfo(&friendInfo, index); wcsncpy(msgFriendName, (wchar_t*)friendInfo.attr.name, 12); } @@ -588,7 +588,7 @@ namespace ipl { getMsgFromId(&msgObj, &msgFriendAddr.wiiId); msgFriendType = msgFriendAddr.wiiId == myUserId ? NWC24_FRIENDTYPE_NONE : NWC24_FRIENDTYPE_WII; if (searchFriendInfo(msgFriendAddr.wiiId, &index)) { - NWC24FriendInfo friendInfo; + NWC24FriendInfo friendInfo ALIGN32; readFriendInfo(&friendInfo, index); wcsncpy(msgFriendName, (wchar_t*)friendInfo.attr.name, 12); } @@ -596,6 +596,7 @@ namespace ipl { // Get app and group ID u32 msgAppId; + u16 msgOptOutAppId; u16 msgGroupId; getMsgAppId(&msgObj, &msgAppId); getMsgGroupId(&msgObj, &msgGroupId); @@ -613,9 +614,9 @@ namespace ipl { // Get opt out flag (display "Opt Out" button) BOOL msgMbOptOutFlag = FALSE; - u32 msgOptOutAppId = 0; bool msgBoardUpdateSW = (result & (bool)msgMbUpdateSW); - result = readMsgMBOptOutFlag(&msgObj, &msgMbOptOutFlag, &msgOptOutAppId); + *(u32*)&msgOptOutAppId = 0; + result = readMsgMBOptOutFlag(&msgObj, &msgMbOptOutFlag, (u32*)&msgOptOutAppId); if (!FILE_ERROR_OK) { goto out; } -- 2.49.1