diff --git a/configure.py b/configure.py index d7c01b541..24189e188 100755 --- a/configure.py +++ b/configure.py @@ -355,7 +355,7 @@ config.libs = [ Object(Matching, "m_Do/m_Do_hostIO.cpp"), Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "m_Do/m_Do_Reset.cpp"), Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "m_Do/m_Do_dvd_thread.cpp"), - Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "m_Do/m_Do_DVDError.cpp"), + Object(Matching, "m_Do/m_Do_DVDError.cpp"), Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "m_Do/m_Do_MemCard.cpp"), Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "m_Do/m_Do_MemCardRWmng.cpp"), Object(MatchingFor("GZLJ01", "GZLE01", "GZLP01"), "m_Do/m_Do_gba_com.cpp"), diff --git a/include/m_Do/m_Do_main.h b/include/m_Do/m_Do_main.h index 1fa288c27..86ea4179c 100644 --- a/include/m_Do/m_Do_main.h +++ b/include/m_Do/m_Do_main.h @@ -47,6 +47,11 @@ public: }; struct mDoMain { +#if VERSION == VERSION_DEMO + static int argument; + static int gameHeapSize; + static int archiveHeapSize; +#endif static char COPYDATE_STRING[18]; static u32 memMargin; static OSTime sPowerOnTime; diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/scanf.h b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/scanf.h index ca142dc1c..a251dfebf 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/scanf.h +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/scanf.h @@ -35,6 +35,7 @@ typedef struct { } __wInStrCtrl; int __StringRead(void* str, int ch, int behavior); +int sscanf(const char* buffer, const char* format, ...); #ifdef __cplusplus } diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/stdio.h b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/stdio.h index bc0cd4ada..d5c6a23f7 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/stdio.h +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/stdio.h @@ -5,6 +5,7 @@ #include "file_io.h" // IWYU pragma: export #include "printf.h" // IWYU pragma: export #include "extras.h" // IWYU pragma: export +#include "scanf.h" // IWYU pragma: export #define stdin (&__files._stdin) #define stdout (&__files._stdout) diff --git a/src/d/d_demo.cpp b/src/d/d_demo.cpp index 0f493f74b..4df413e59 100644 --- a/src/d/d_demo.cpp +++ b/src/d/d_demo.cpp @@ -582,7 +582,7 @@ void* dDemo_system_c::JSGFindObject(const char* name, JStage::TEObject type) con if (type == JStage::TOBJ_ACTOR || type == JStage::TOBJ_ACTOR_UNK) { fopAc_ac_c* ac = fopAcM_searchFromName((char*)name, 0, 0); if (ac == NULL) { - if (type == JStage::TOBJ_ACTOR && strncmp(name, "d_act", 5) == 0) { + if (type == JStage::TOBJ_ACTOR && strncmp(name, "d_act", sizeof("d_act")-1) == 0) { ac = (fopAc_ac_c*)fopAcM_fastCreate((char*)name, 0); if (ac == NULL) return NULL; diff --git a/src/d/d_grass.cpp b/src/d/d_grass.cpp index 91ec58e76..2c7befe74 100644 --- a/src/d/d_grass.cpp +++ b/src/d/d_grass.cpp @@ -144,8 +144,15 @@ static bool l_CutSoundFlag; /* 80077048-8007712C .text setBatta__FP4cXyzP8_GXColor */ void setBatta(cXyz* pos, GXColor* color) { - if (!dKy_rain_check() && !dComIfGp_event_runCheck() && strncmp(dComIfGp_getStartStageName(), "kin", 3) != 0 && strcmp(dComIfGp_getStartStageName(), "Xboss1") != 0 && cM_rnd() > 0.99f) + if ( + !dKy_rain_check() && + !dComIfGp_event_runCheck() && + strncmp(dComIfGp_getStartStageName(), "kin", sizeof("kin")-1) != 0 && + strcmp(dComIfGp_getStartStageName(), "Xboss1") != 0 && + cM_rnd() > 0.99f + ) { dComIfGp_particle_set(dPa_name::ID_COMMON_0453, pos, NULL, NULL, 0xFF, NULL, -1, color, color); + } } /* 8007712C-8007734C .text WorkCo__13dGrass_data_cFP10fopAc_ac_cUli */ @@ -313,7 +320,7 @@ dGrass_packet_c::dGrass_packet_c() { s16 angle = 0; for (s32 i = 0; i < 8; i++, angle += 0x2000) setAnm(i, angle); - if (strncmp(dComIfGp_getStartStageName(), "kin", 3) == 0 || strcmp(dComIfGp_getStartStageName(), "Xboss1") == 0) { + if (strncmp(dComIfGp_getStartStageName(), "kin", sizeof("kin")-1) == 0 || strcmp(dComIfGp_getStartStageName(), "Xboss1") == 0) { mpPosArr = (f32*)l_Vmori_pos; mpColorArr = l_Vmori_color; mpTexCoordArr = (f32*)l_Vmori_texCoord; diff --git a/src/m_Do/m_Do_DVDError.cpp b/src/m_Do/m_Do_DVDError.cpp index 6f4d568e3..96ff06999 100644 --- a/src/m_Do/m_Do_DVDError.cpp +++ b/src/m_Do/m_Do_DVDError.cpp @@ -47,12 +47,14 @@ void mDoDvdErr_ThdCleanup() { /* 80018CE8-80018D44 .text mDoDvdErr_Watch__FPv */ void mDoDvdErr_Watch(void*) { +#if VERSION > VERSION_DEMO { JKRThread thread(OSGetCurrentThread(), 0); } JKRHeap* heap = NULL; heap->becomeCurrentHeap(); +#endif do { if (DVDGetDriveStatus() == DVD_STATE_FATAL_ERROR) { diff --git a/src/m_Do/m_Do_MemCardRWmng.cpp b/src/m_Do/m_Do_MemCardRWmng.cpp index 60596c219..c4802656e 100644 --- a/src/m_Do/m_Do_MemCardRWmng.cpp +++ b/src/m_Do/m_Do_MemCardRWmng.cpp @@ -83,6 +83,11 @@ s32 mDoMemCdRWm_Store(CARDFileInfo* card, void* data, u32 size) { if (ret != CARD_ERROR_READY) return ret; ret = CARDRead(card, sTmpBuf, sizeof(card_pictdata), (slot + i) * sizeof(card_pictdata)); if (ret != CARD_ERROR_READY) return ret; +#if VERSION == VERSION_DEMO + if (!mDoMemCdRWm_TestCheckSumPictData(sTmpBuf)) { + return ret; + } +#endif } } } diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index df61582f1..b891d85d2 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -25,8 +25,9 @@ #include "m_Do/m_Do_graphic.h" #include "m_Do/m_Do_machine.h" #include "m_Do/m_Do_printf.h" +#include -#include "weak_data_1811.h" // IWYU pragma: keep +#include "weak_data_2100_2080.h" // IWYU pragma: keep /* 800056E0-80005748 .text version_check__Fv */ void version_check() { @@ -166,13 +167,24 @@ void HeapCheck::heapDisplay() { JUTReport(100, 357, "UsedCount %3ld%", used_count); } +#if VERSION == VERSION_DEMO +int mDoMain::argument = -1; +#endif + s8 mDoMain::developmentMode = -1; -u32 mDoMain::memMargin = 0xFFFFFFFF; +#if VERSION == VERSION_DEMO +int mDoMain::gameHeapSize = -1; +int mDoMain::archiveHeapSize = -1; +#endif + +u32 mDoMain::memMargin = -1; u8 mHeapBriefType = 4; +#if VERSION > VERSION_DEMO static u8 fillcheck_check_frame; +#endif OSTime mDoMain::sPowerOnTime; OSTime mDoMain::sHungUpTime; @@ -181,7 +193,12 @@ static bool mDisplayHeapSize; static u8 mSelectHeapBar; -static bool mCheckHeap; +#if VERSION == VERSION_DEMO +static bool mCheckHeap = true; +#else +static bool mCheckHeap = false; + +#endif /* 80005B28-80005DE0 .text debugDisplay__Fv */ void debugDisplay() { @@ -219,16 +236,16 @@ void debugDisplay() { s32 check2; switch (mHeapBriefType) { case 1: - check1 = heap_check->getHeap()->getTotalFreeSize(); - check2 = heap_check->getHeap()->getFreeSize(); + check1 = heap_check->mHeap->getTotalFreeSize(); + check2 = heap_check->mHeap->getFreeSize(); break; case 2: check1 = heap_check->getMaxTotalUsedSize(); - check2 = heap_check->getHeap()->getHeapSize(); + check2 = heap_check->mHeap->getHeapSize(); break; case 3: check1 = heap_check->getUsedCount(); - check2 = heap_check->getHeap()->getTotalUsedSize(); + check2 = heap_check->mHeap->getTotalUsedSize(); break; case 4: check1 = heap_check->getRelUsedCount(); @@ -236,7 +253,7 @@ void debugDisplay() { break; } - JUTReport(500, (i * 44) + 150, " [%s]", heap_check->getName()); + JUTReport(500, (i * 44) + 150, " [%s]", heap_check->mName); JUTReport(500, (i * 44) + 164, "%10d", check1); JUTReport(500, (i * 44) + 178, "%10d", check2); } @@ -362,6 +379,7 @@ s32 LOAD_COPYDATE(void*) { return status; } +#if VERSION > VERSION_DEMO /* 80006264-80006338 .text debug__Fv */ void debug() { if (mDoMain::developmentMode) { @@ -373,8 +391,13 @@ void debug() { mDisplayHeapSize ^= 1; if (mDisplayHeapSize) { - if (g_mDoCPd_gamePad[2]->testButton(~CButton::Z) == CButton::L && g_mDoCPd_gamePad[2]->testTrigger(CButton::Z)) - mHeapBriefType < 5 ? mHeapBriefType++ : mHeapBriefType = 1; + if (g_mDoCPd_gamePad[2]->testButton(~CButton::Z) == CButton::L && g_mDoCPd_gamePad[2]->testTrigger(CButton::Z)) { + if (mHeapBriefType < 5) { + mHeapBriefType++; + } else { + mHeapBriefType = 1; + } + } debugDisplay(); } @@ -382,11 +405,10 @@ void debug() { Debug_console(g_mDoCPd_gamePad[2]); } } +#endif /* 80006338-80006464 .text main01__Fv */ void main01() { - static u32 frame; - // Setup heaps, setup exception manager, set RNG seed, setup DVDError Thread, setup Memory card // Thread mDoMch_Create(); @@ -405,27 +427,42 @@ void main01() { CommandHeapCheck.setHeap(mDoExt_getCommandHeap()); JUTConsole* console = JFWSystem::getSystemConsole(); +#if VERSION == VERSION_DEMO + console->setOutput(JUTConsole::OUTPUT_OSR_AND_CONSOLE); +#else console->setOutput(mDoMain::developmentMode ? JUTConsole::OUTPUT_OSR_AND_CONSOLE : JUTConsole::OUTPUT_NONE); +#endif console->setPosition(32, 42); +#if VERSION == VERSION_DEMO + console->print("JUTConsole START\n"); +#endif + mDoDvdThd_callback_c::create((mDoDvdThd_callback_func)LOAD_COPYDATE, NULL); fapGm_Create(); // init framework +#if VERSION > VERSION_DEMO #if VERSION <= VERSION_JPN mDisplayHeapSize = 1; #else mDisplayHeapSize = 0; +#endif #endif cDyl_InitAsync(); // init RELs +#if VERSION > VERSION_DEMO g_mDoAud_audioHeap = JKRSolidHeap::create(0x166800, JKRHeap::getCurrentHeap(), false); + static u32 frame; +#endif + do { +#if VERSION > VERSION_DEMO frame++; if (fillcheck_check_frame != 0 && frame % fillcheck_check_frame == 0) { mDoMch_HeapCheckAll(); } - +#endif if (mDoDvdThd::SyncWidthSound) { mDoMemCd_UpDate(); } @@ -433,14 +470,78 @@ void main01() { mDoCPd_Read(); // read controller input mDoAud_Execute(); // handle audio execution fapGm_Execute(); // handle game execution + +#if VERSION == VERSION_DEMO + if (mCheckHeap) { + CheckHeap(g_mDoCPd_gamePad[2]); + } + + if (g_mDoCPd_gamePad[2]->testButton(~CButton::Z) == CButton::R && g_mDoCPd_gamePad[2]->testTrigger(CButton::Z)) + mDisplayHeapSize ^= 1; + + if (mDisplayHeapSize) { + if (g_mDoCPd_gamePad[2]->testButton(~CButton::Z) == CButton::L && g_mDoCPd_gamePad[2]->testTrigger(CButton::Z)) { + if (mHeapBriefType < 5) { + mHeapBriefType++; + } else { + if (JKRAram::getAramHeap()) { + JKRAram::getAramHeap()->dump(); + } + mHeapBriefType = 1; + } + } + + debugDisplay(); + } + + Debug_console(g_mDoCPd_gamePad[2]); +#else debug(); // run debugger +#endif } while (true); } +#if VERSION == VERSION_DEMO +void parse_args(int argc, const char* argv[]) { + for (int i = 0; i < argc; i++) { + } + + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "--noprint") == 0) { + OSReportDisable(); + } else if (strcmp(argv[i], "--develop") == 0) { + mDoMain::developmentMode = 1; + } else if (strcmp(argv[i], "--nodevelop") == 0) { + mDoMain::developmentMode = 0; + } else if (strncmp(argv[i], "--e3argument=", sizeof("--e3argument=")-1) == 0) { + sscanf(argv[i] + sizeof("--e3argument=")-1, "%d", &mDoMain::argument); + } else if (strncmp(argv[i], "--gameheapsize=0x", sizeof("--gameheapsize=0x")-1) == 0) { + sscanf(argv[i] + sizeof("--gameheapsize=0x")-1, "%x", &mDoMain::gameHeapSize); + } else if (strncmp(argv[i], "--archiveheapsize=0x", sizeof("--archiveheapsize=0x")-1) == 0) { + sscanf(argv[i] + sizeof("--archiveheapsize=0x")-1, "%x", &mDoMain::archiveHeapSize); + } else if (strncmp(argv[i], "--memmargin=0x", sizeof("--memmargin=0x")-1) == 0) { + sscanf(argv[i] + sizeof("--memmargin=0x")-1, "%x", &mDoMain::memMargin); + } else { + OSReport_Error("unknown argument %d, %s\n", i, argv[i]); + } + } + + if (mDoMain::developmentMode < 0) { + mDoMain::developmentMode = (OSGetConsoleType() & 0x10000000) ? 1 : 0; + } +} +#endif + +#if VERSION > VERSION_DEMO OSThread mainThread; +#endif /* 80006464-800065DC .text main */ -int main() { +int main(int argc, const char* argv[]) { +#if VERSION == VERSION_DEMO + OSThread mainThread; +#endif + OSThread* current_thread = OSGetCurrentThread(); u8 ALIGN_DECL(0x20) stack[0xF000]; @@ -466,6 +567,7 @@ int main() { g_dComIfG_gameInfo.ct(); #endif +#if VERSION > VERSION_DEMO if (mDoMain::developmentMode < 0) { DVDDiskID* disk_id = DVDGetCurrentDiskID(); @@ -478,6 +580,11 @@ int main() { mDoMain::developmentMode = 0; } } +#endif + +#if VERSION == VERSION_DEMO + parse_args(argc, argv); +#endif OSPriority priority = OSGetThreadPriority(current_thread); OSCreateThread(&mainThread, (void*)main01, 0, stack + sizeof(stack), sizeof(stack), priority, 0);