diff --git a/configure.py b/configure.py index 364480f3e..d71dd1588 100644 --- a/configure.py +++ b/configure.py @@ -313,6 +313,7 @@ LIBS = [ Matching ("f_pc/f_pc_stdcreate_req.cpp"), # machine + NonMatching("m_Do/m_Do_main.cpp"), NonMatching("m_Do/m_Do_controller_pad.cpp"), # dolzel diff --git a/include/JSystem/JUtility/JUTGamePad.h b/include/JSystem/JUtility/JUTGamePad.h index 5e326217d..5f3304aed 100644 --- a/include/JSystem/JUtility/JUTGamePad.h +++ b/include/JSystem/JUtility/JUTGamePad.h @@ -105,8 +105,10 @@ public: u8 getAnalogB() const { return mButton.mAnalogB; } u8 getAnalogL() const { return mButton.mAnalogL; } + f32 getAnalogLf() const { return mButton.mAnalogLf; } u8 getAnalogR() const { return mButton.mAnalogR; } + f32 getAnalogRf() const { return mButton.mAnalogRf; } s8 getErrorStatus() const { return mErrorStatus; } @@ -225,8 +227,7 @@ public: /* 0x04 */ u32 field_0x4; /* 0x08 */ u8* field_0x8; /* 0x0C */ u32 field_0xc; - /* 0x10 */ u8* field_0x10; - }; // Size: 0x14 + }; // Size: 0x10 void startMotorWave(void* param_2, CRumble::ERumble rumble, u32 param_4) { mRumble.startPatternedRumble(param_2, rumble, param_4); @@ -236,15 +237,15 @@ public: /* 0x48 */ CStick mMainStick; /* 0x58 */ CStick mSubStick; /* 0x68 */ CRumble mRumble; - /* 0x7C */ s16 mPortNum; - /* 0x7E */ s8 mErrorStatus; - /* 0x80 */ JSULink mLink; - /* 0x90 */ JUTGamePadRecordBase* mPadRecord; - /* 0x94 */ JUTGamePadRecordBase* mPadReplay; - /* 0x98 */ C3ButtonReset mButtonReset; - /* 0x9C */ u8 field_0x9c[4]; - /* 0xA0 */ OSTime mResetTime; - /* 0xA8 */ u8 field_0xa8; + /* 0x78 */ s16 mPortNum; + /* 0x7A */ s8 mErrorStatus; + /* 0x7C */ JSULink mLink; + /* 0x8C */ JUTGamePadRecordBase* mPadRecord; + /* 0x90 */ JUTGamePadRecordBase* mPadReplay; + /* 0x94 */ C3ButtonReset mButtonReset; + /* 0x98 */ u8 field_0x98[4]; + /* 0x9C */ OSTime mResetTime; + /* 0xA4 */ u8 field_0xa4; static JSUList mPadList; static bool mListInitialized; diff --git a/include/f_ap/f_ap_game.h b/include/f_ap/f_ap_game.h index e082e397b..66e4fa6ca 100644 --- a/include/f_ap/f_ap_game.h +++ b/include/f_ap/f_ap_game.h @@ -12,8 +12,22 @@ public: /* 80018944 */ fapGm_HIO_c(); /* 80018AE0 */ virtual ~fapGm_HIO_c(); - u32 pad[0x58]; -}; // Size: 0x40 + /* 0x04 */ u8 field_0x04[0x06 - 0x04]; + /* 0x06 */ u8 mDisplayMeter; + /* 0x07 */ u8 field_0x07[0x0C - 0x07]; + /* 0x0C */ f32 field_0x0c; + /* 0x10 */ u8 field_0x10[0x24 - 0x10]; + /* 0x24 */ f32 mTriggerThreshLo; + /* 0x28 */ f32 mTriggerThreshHi; + /* 0x2C */ u16 field_0x2c; + /* 0x2E */ u16 field_0x2e; + /* 0x30 */ u8 field_0x30[0x4C - 0x30]; + /* 0x4C */ u16 field_0x4c; + /* 0x4E */ u16 field_0x4e; + /* 0x50 */ u16 field_0x50; + /* 0x52 */ u16 field_0x52; + /* 0x54 */ u16 field_0x54; +}; // Size: 0x58 extern fapGm_HIO_c g_HIO; diff --git a/include/m_Do/m_Do_MemCard.h b/include/m_Do/m_Do_MemCard.h new file mode 100644 index 000000000..a32ad8e31 --- /dev/null +++ b/include/m_Do/m_Do_MemCard.h @@ -0,0 +1,69 @@ +#ifndef M_DO_M_DO_MEMCARD_H +#define M_DO_M_DO_MEMCARD_H + +#include "dolphin/os/OSMutex.h" +#include "global.h" + +class mDoMemCd_Ctrl_c { +public: + enum CardCommand { + CARD_NO_COMMAND, + CARD_RESTORE, + CARD_STORE, + CARD_FORMAT, + CARD_ATTACH, + CARD_DETACH, + }; + + /* 8001672C */ mDoMemCd_Ctrl_c(); + /* 80016730 */ void ThdInit(); + /* 800167D0 */ void main(); + /* 80016894 */ void update(); + /* 800169B4 */ void load(); + /* 80016A0C */ void restore(); + /* 80016AB0 */ s32 LoadSync(void*, u32, u32); + /* 80016B58 */ void save(void*, u32, u32); + /* 80016BD4 */ void store(); + /* 80016CE0 */ s32 SaveSync(); + /* 80016D74 */ u32 getStatus(u32); + /* 80016E58 */ void command_format(); + /* 80016EA8 */ void format(); + /* 80016F2C */ s32 FormatSync(); + /* 80016FB8 */ void attach(); + /* 800170B8 */ void command_attach(); + /* 80017110 */ void detach(); + /* 80017148 */ s32 mount(); + /* 80017274 */ s32 loadfile(); + /* 800172D4 */ s32 checkspace(); + /* 80017360 */ void setCardState(s32); + + bool isCardCommNone() { return mCardCommand == CARD_NO_COMMAND; } + + /* 0x0000 */ u8 mData[0x1650]; + /* 0x1650 */ s32 mCardCommand; + /* 0x1654 */ s32 mCardState; + /* 0x1658 */ s32 field_0x1658; + /* 0x165C */ s32 field_0x165c; + /* 0x1660 */ s32 field_0x1660; + /* 0x1664 */ OSMutex mMutex; +}; // Size: 0x167C + +STATIC_ASSERT(sizeof(mDoMemCd_Ctrl_c) == 0x167C); + +static int mDoMemCd_main(void*); + +extern mDoMemCd_Ctrl_c g_mDoMemCd_control; + +inline bool mDoMemCd_isCardCommNone() { + return g_mDoMemCd_control.isCardCommNone(); +} + +inline void mDoMemCd_ThdInit() { + g_mDoMemCd_control.ThdInit(); +} + +inline void mDoMemCd_save(void* i_data, u32 param_1, u32 param_2) { + g_mDoMemCd_control.save(i_data,param_1,param_2); +} + +#endif /* M_DO_M_DO_MEMCARD_H */ \ No newline at end of file diff --git a/include/m_Do/m_Do_Reset.h b/include/m_Do/m_Do_Reset.h index 3898fe6db..325982ee5 100644 --- a/include/m_Do/m_Do_Reset.h +++ b/include/m_Do/m_Do_Reset.h @@ -6,7 +6,6 @@ void mDoRst_reset(int, u32, int); void mDoRst_resetCallBack(int, void*); -extern bool SyncWidthSound; extern u8 sDefaultDirection; struct mDoRstData { diff --git a/include/m_Do/m_Do_audio.h b/include/m_Do/m_Do_audio.h index ddfbc9444..70abfb98d 100644 --- a/include/m_Do/m_Do_audio.h +++ b/include/m_Do/m_Do_audio.h @@ -2,5 +2,9 @@ #define M_DO_AUDIO_H void mDoAud_setSceneName(const char*, s32, s32); +void mDoAud_Execute(); + +class JKRSolidHeap; +extern JKRSolidHeap* g_mDoAud_audioHeap; #endif /* M_DO_AUDIO_H */ diff --git a/include/m_Do/m_Do_controller_pad.h b/include/m_Do/m_Do_controller_pad.h index c6619acd0..713044485 100644 --- a/include/m_Do/m_Do_controller_pad.h +++ b/include/m_Do/m_Do_controller_pad.h @@ -1,4 +1,13 @@ #ifndef M_DO_CONTROLLER_PAD_H #define M_DO_CONTROLLER_PAD_H +#include "JSystem/JUtility/JUTGamePad.h" +#include "SSystem/SComponent/c_API_controller_pad.h" + +extern JUTGamePad* g_mDoCPd_gamePad[4]; +extern interface_of_controller_pad g_mDoCPd_cpadInfo[4]; + +void mDoCPd_Create(); +void mDoCPd_Read(); + #endif diff --git a/include/m_Do/m_Do_dvd_thread.h b/include/m_Do/m_Do_dvd_thread.h index 8922ca7f3..f118bde03 100644 --- a/include/m_Do/m_Do_dvd_thread.h +++ b/include/m_Do/m_Do_dvd_thread.h @@ -117,6 +117,7 @@ struct mDoDvdThd { static OSThread l_thread; static mDoDvdThdStack l_threadStack; static mDoDvdThd_param_c l_param; + static bool SyncWidthSound; }; #endif /* M_DO_M_DO_DVD_THREAD_H */ diff --git a/include/m_Do/m_Do_ext.h b/include/m_Do/m_Do_ext.h index f12c42bdf..cf5231bd5 100644 --- a/include/m_Do/m_Do_ext.h +++ b/include/m_Do/m_Do_ext.h @@ -255,4 +255,13 @@ void mDoExt_modelUpdate(J3DModel* i_model); void mDoExt_modelUpdateDL(J3DModel* i_model); void mDoExt_modelEntryDL(J3DModel* i_model); +JKRExpHeap* mDoExt_getCommandHeap(); +JKRExpHeap* mDoExt_getZeldaHeap(); +JKRExpHeap* mDoExt_getGameHeap(); +JKRExpHeap* mDoExt_getArchiveHeap(); + +extern JKRExpHeap* zeldaHeap; +extern JKRExpHeap* gameHeap; +extern JKRExpHeap* archiveHeap; + #endif diff --git a/include/m_Do/m_Do_graphic.h b/include/m_Do/m_Do_graphic.h new file mode 100644 index 000000000..c0ceefe7e --- /dev/null +++ b/include/m_Do/m_Do_graphic.h @@ -0,0 +1,6 @@ +#ifndef M_DO_M_DO_GRAPHIC_H +#define M_DO_M_DO_GRAPHIC_H + +void mDoGph_Create(); + +#endif /* M_DO_M_DO_GRAPHIC_H */ \ No newline at end of file diff --git a/include/m_Do/m_Do_machine.h b/include/m_Do/m_Do_machine.h new file mode 100644 index 000000000..0c53e162a --- /dev/null +++ b/include/m_Do/m_Do_machine.h @@ -0,0 +1,7 @@ +#ifndef M_DO_M_DO_MACHINE_H +#define M_DO_M_DO_MACHINE_H + +void mDoMch_Create(); +void mDoMch_HeapCheckAll(); + +#endif /* M_DO_M_DO_MACHINE_H */ \ No newline at end of file diff --git a/include/m_Do/m_Do_main.h b/include/m_Do/m_Do_main.h index 64468c50e..9caea01ed 100644 --- a/include/m_Do/m_Do_main.h +++ b/include/m_Do/m_Do_main.h @@ -9,17 +9,13 @@ class JKRExpHeap; void version_check(); s32 LOAD_COPYDATE(void*); +#define HeapCheckTableNum 6 + class HeapCheck { public: - HeapCheck(JKRExpHeap* heap, const char* name, const char* jName) { - mName = name; - mJName = jName; - setHeap(heap); - } - - void CheckHeap1(void); - s32 getUsedCount(void) const; - void heapDisplay(void) const; + void CheckHeap1(); + s32 getUsedCount() const; + void heapDisplay(); u32& getUsedCountRef() { return mUsedCount; } u32& getTotalUsedSizeRef() { return mTotalUsedSize; } @@ -37,23 +33,20 @@ public: u32 getRelUsedCount() const { return getUsedCount() - mUsedCount; } u32 getRelTotalUsedSize() const { return mHeap->getTotalUsedSize() - mTotalUsedSize; } -private: /* 0x00 */ const char* mName; - /* 0x04 */ const char* mJName; - /* 0x08 */ JKRExpHeap* mHeap; - /* 0x0C */ s32 mMaxTotalUsedSize; - /* 0x10 */ s32 mMaxTotalFreeSize; + /* 0x04 */ JKRExpHeap* mHeap; + /* 0x08 */ s32 mMaxTotalUsedSize; + /* 0x0C */ s32 mMaxTotalFreeSize; + /* 0x10 */ s32 field_0x10; /* 0x14 */ s32 field_0x14; - /* 0x18 */ s32 field_0x18; - /* 0x1C */ u32 mTargetHeapSize; - /* 0x20 */ u32 mUsedCount; - /* 0x24 */ u32 mTotalUsedSize; + /* 0x18 */ u32 mTargetHeapSize; + /* 0x1C */ u32 mUsedCount; + /* 0x20 */ u32 mTotalUsedSize; }; struct mDoMain { static char COPYDATE_STRING[18]; static u32 memMargin; - static u8 mHeapBriefType; static OSTime sPowerOnTime; static OSTime sHungUpTime; static s8 developmentMode; diff --git a/src/m_Do/m_Do_controller_pad.cpp b/src/m_Do/m_Do_controller_pad.cpp index 2290e68a9..629c8070f 100644 --- a/src/m_Do/m_Do_controller_pad.cpp +++ b/src/m_Do/m_Do_controller_pad.cpp @@ -4,9 +4,7 @@ // #include "m_Do/m_Do_controller_pad.h" -#include "SSystem/SComponent/c_API_controller_pad.h" #include "SSystem/SComponent/c_lib.h" -#include "JSystem/JUtility/JUTGamePad.h" #include "m_Do/m_Do_main.h" #include "m_Do/m_Do_Reset.h" diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 9bf924028..ba7630bab 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -1,72 +1,490 @@ -// -// Generated by dtk -// Translation Unit: m_Do_main.cpp -// +/** + * m_Do_main.cpp + * Main Initialization + */ #include "m_Do/m_Do_main.h" -#include "dolphin/types.h" +#include "DynamicLink.h" +#include "JSystem/JFramework/JFWSystem.h" +#include "JSystem/JKernel/JKRAram.h" +#include "JSystem/JKernel/JKRSolidHeap.h" +#include "JSystem/JUtility/JUTAssert.h" +#include "JSystem/JUtility/JUTConsole.h" +#include "JSystem/JUtility/JUTGamePad.h" +#include "JSystem/JUtility/JUTReport.h" +#include "MSL_C/string.h" +#include "c/c_dylink.h" +#include "d/d_com_inf_game.h" +#include "dolphin/os/OS.h" +#include "f_ap/f_ap_game.h" +#include "m_Do/m_Do_MemCard.h" +#include "m_Do/m_Do_Reset.h" +#include "m_Do/m_Do_audio.h" +#include "m_Do/m_Do_controller_pad.h" +#include "m_Do/m_Do_dvd_thread.h" +#include "m_Do/m_Do_graphic.h" +#include "m_Do/m_Do_machine.h" + +class JUTGamePad; /* 800056E0-80005748 .text version_check__Fv */ void version_check() { - /* Nonmatching */ + if (strcmp("05Sep2002", "05Sep2002") == 0 && strcmp("", "") == 0) { + return; + } + + OSReport_Error("SDKのバージョンが一致しません。停止します\n"); + while (true) { + } } /* 80005748-800057AC .text CheckHeap1__9HeapCheckFv */ void HeapCheck::CheckHeap1() { - /* Nonmatching */ + s32 totalUsedSize = mHeap->getTotalUsedSize(); + s32 freeSize = mHeap->getFreeSize(); + + if (mMaxTotalUsedSize < totalUsedSize) + mMaxTotalUsedSize = totalUsedSize; + + if (mMaxTotalFreeSize > freeSize) + mMaxTotalFreeSize = freeSize; } +// unused data? +static u32 lit_2100[] = {0x3F800000, 0x3F800000, 0x3F800000, 0x3F800000, 0x3F800000, 0x3F800000}; + +char mDoMain::COPYDATE_STRING[18] = "??/??/?? ??:??:??"; + +static HeapCheck RootHeapCheck = { + "Root", NULL, 0, 0x7FFFFFFF, 0x1400000, 0x140, 0x10000, 0, 0, +}; + +static HeapCheck SystemHeapCheck = { + "System", NULL, 0, 0x7FFFFFFF, 0x870000, 0x87, 0x10000, 0, 0, +}; + +static HeapCheck ZeldaHeapCheck = { + "Zelda", NULL, 0, 0x7FFFFFFF, 0x7C0000, 0x7C, 0x10000, 0, 0, +}; + +static HeapCheck GameHeapCheck = { + "Game", NULL, 0, 0x7FFFFFFF, 0x300000, 0x30, 0x10000, 0, 0, +}; + +static HeapCheck ArchiveHeapCheck = { + "Archive", NULL, 0, 0x7FFFFFFF, 0x880000, 0x88, 0x10000, 0, 0, +}; + +static HeapCheck CommandHeapCheck = { + "Command", NULL, 0, 0x7FFFFFFF, 0x1000, 0x10, 0x100, 0, 0, +}; + +static HeapCheck* HeapCheckTable[HeapCheckTableNum] = { + &RootHeapCheck, &SystemHeapCheck, &ZeldaHeapCheck, + &GameHeapCheck, &ArchiveHeapCheck, &CommandHeapCheck, +}; + /* 800057AC-80005858 .text CheckHeap__FP10JUTGamePad */ -void CheckHeap(JUTGamePad*) { - /* Nonmatching */ +void CheckHeap(JUTGamePad* i_pad) { + mDoMch_HeapCheckAll(); + OSCheckActiveThreads(); + + bool comboCheck = false; + + // if L + R + Z is pressed + if ((i_pad->getButton() & ~CButton::Z) == (CButton::L + CButton::R) && + i_pad->getTrigger() & CButton::Z) + { + comboCheck = true; + } + + int saveRel = comboCheck; + for (int i = 0; i < HeapCheckTableNum; i++) { + HeapCheckTable[i]->CheckHeap1(); + if (saveRel) { + HeapCheckTable[i]->saveRelBase(); + } + } } /* 80005858-800058B0 .text countUsed__FP10JKRExpHeap */ -void countUsed(JKRExpHeap*) { - /* Nonmatching */ +static int countUsed(JKRExpHeap* heap) { + OSDisableScheduler(); + int counter = 0; + JKRExpHeap::CMemBlock* used_blocks_head = heap->getHeadUsedList(); + + while (used_blocks_head) { + used_blocks_head = used_blocks_head->getNextBlock(); + counter++; + }; + + OSEnableScheduler(); + return counter; } /* 800058B0-800058D4 .text getUsedCount__9HeapCheckCFv */ -void HeapCheck::getUsedCount() const { - /* Nonmatching */ +s32 HeapCheck::getUsedCount() const { + return countUsed(mHeap); } /* 800058D4-80005B28 .text heapDisplay__9HeapCheckFv */ void HeapCheck::heapDisplay() { - /* Nonmatching */ + s32 heap_size = mHeap->getSize(); + s32 used_count = field_0x14 * mTargetHeapSize; + + field_0x10 = used_count; + used_count = heap_size - used_count; + + s32 total_used = mHeap->getTotalUsedSize(); + s32 total_free = mHeap->getTotalFreeSize(); + s32 heap_free = mHeap->getFreeSize(); + + JUTReport(100, 212, "[%sName]", mName); + JUTReport(100, 227, "HeapSize %8ld", heap_size); + + int target_size = field_0x14 * mTargetHeapSize; + field_0x10 = target_size; + + JUTReport(100, 240, "TargetHeapSize %8ld", target_size); + JUTReport(100, 253, "TotalFree %8ld", total_free - used_count); + JUTReport(100, 266, "FreeSize %8ld", heap_free - used_count); + JUTReport(100, 279, "TotalUsedSize %8ld", total_used); + + target_size = field_0x14 * mTargetHeapSize; + field_0x10 = target_size; + + JUTReport(100, 292, "TotalUsedRate %3ld%%", (int)(total_used * 100) / target_size); + JUTReport(100, 305, "MaxTotalUsedSize %8ld", mMaxTotalUsedSize); + + target_size = field_0x14 * mTargetHeapSize; + field_0x10 = target_size; + + JUTReport(100, 318, "MaxTotalUsedRate %3ld%%", (mMaxTotalUsedSize * 100) / target_size); + JUTReport(100, 331, "MinFreeSize %8ld", mMaxTotalFreeSize - used_count); + + target_size = field_0x14 * mTargetHeapSize; + field_0x10 = target_size; + + JUTReport(100, 344, "MinFreeRate %3ld%%", + ((mMaxTotalFreeSize - used_count) * 100) / target_size); + used_count = countUsed(mHeap); + JUTReport(100, 357, "UsedCount %3ld%", used_count); } +s8 mDoMain::developmentMode = -1; + +u32 mDoMain::memMargin = 0xFFFFFFFF; + +u8 mHeapBriefType = 4; + +static u8 fillcheck_check_frame; + +OSTime mDoMain::sPowerOnTime; +OSTime mDoMain::sHungUpTime; + +static bool mDisplayHeapSize; + +static u8 mSelectHeapBar; + +static bool mCheckHeap; + /* 80005B28-80005DE0 .text debugDisplay__Fv */ void debugDisplay() { - /* Nonmatching */ + static const char* desc1[5] = { + "", "TotalFree", "MaxUsed ", "Used ", "RelUsed ", + }; + + static const char* desc2[5] = { + "", "/ MaxFree", "/HeapSize", "Blk/Bytes", "Blk/Bytes", + }; + + if (mSelectHeapBar >= 1 && mSelectHeapBar <= 6) { + HeapCheckTable[mSelectHeapBar - 1]->heapDisplay(); + } + + if (mHeapBriefType == 5) { + JKRAramHeap* heap = JKRAram::getAramHeap(); + if (heap) { + JUTReport(500, 100, "ARAM Free"); + JUTReport(500, 114, "%d", heap->getFreeSize()); + JUTReport(500, 128, "TotalFree"); + JUTReport(500, 142, "%d", heap->getTotalFreeSize()); + return; + } + } else if (mHeapBriefType != 0) { + JUT_ASSERT(531, mHeapBriefType < HeapCheckTableNum); + + JUTReport(500, 100, "%s", desc1[mHeapBriefType]); + JUTReport(500, 114, "%s", desc2[mHeapBriefType]); + + for (int i = 0; i < HeapCheckTableNum; i++) { + HeapCheck* heap_check = HeapCheckTable[i]; + + s32 check1; + s32 check2; + switch (mHeapBriefType) { + case 1: + check1 = heap_check->getHeap()->getTotalFreeSize(); + check2 = heap_check->getHeap()->getFreeSize(); + break; + case 2: + check1 = heap_check->getMaxTotalUsedSize(); + check2 = heap_check->getHeap()->getHeapSize(); + break; + case 3: + check1 = heap_check->getUsedCount(); + check2 = heap_check->getHeap()->getTotalUsedSize(); + break; + case 4: + check1 = heap_check->getRelUsedCount(); + check2 = heap_check->getRelTotalUsedSize(); + break; + } + + JUTReport(500, (i * 44) + 150, " [%s]", heap_check->getName()); + JUTReport(500, (i * 44) + 164, "%10d", check1); + JUTReport(500, (i * 44) + 178, "%10d", check2); + } + } } /* 80005DE0-800061E0 .text Debug_console__FP10JUTGamePad */ -void Debug_console(JUTGamePad*) { - /* Nonmatching */ +bool Debug_console(JUTGamePad* i_pad) { + JUTConsole* console = JFWSystem::getSystemConsole(); + if (console) { + static f32 console_position_x = 20.0f; + static f32 console_position_y = 30.0f; + static f32 console_scroll = 0.0f; + + if ((i_pad->getTrigger() & CButton::Z) && !(i_pad->getButton() & ~CButton::Z)) { + console->setVisible(console->isVisible() == false); + JUTAssertion::setMessageCount(0); + } + + if (console->isVisible()) { + u32 holdButtons = i_pad->getButton(); + if ((holdButtons & CButton::L && holdButtons & CButton::R) || + ((i_pad->getAnalogL() != 0 && i_pad->getAnalogR() != 0))) + { + f32 stick_x = i_pad->getMainStickX(); + f32 stick_y = i_pad->getMainStickY(); + + if ((holdButtons & CButton::X) && (holdButtons & CButton::Y) && + i_pad->getTrigger() & CButton::START) + { + console->clear(); + } + + if (!(i_pad->getButton() & CButton::X) && !(i_pad->getButton() & CButton::Y)) { + console_scroll -= stick_y; + + int scrollAmount; + if (console_scroll > 1.0f) { + scrollAmount = console_scroll; + } else if (console_scroll < -1.0f) { + scrollAmount = -(int)-console_scroll; + } else { + scrollAmount = 0; + } + + if (scrollAmount != 0) { + console_scroll -= scrollAmount; + console->scroll(scrollAmount); + } + } else { + if (i_pad->getButton() & CButton::X) { + console_position_x += stick_x; + } + + if (i_pad->getButton() & CButton::Y) { + console_position_y -= stick_y; + } + } + + if (i_pad->getTrigger() & CButton::A) { + console->dumpToTerminal(0xFFFFFFFF); + console->setOutput(JUTConsole::OUTPUT_OSREPORT | JUTConsole::OUTPUT_CONSOLE); + } + + JUTReport(30, 390, 1, "Press X+Y+START to CLEAR console."); + JUTReport(30, 400, 1, "3DStick UP/Down to scroll"); + JUTReport(30, 410, 1, "Press A to output terminal from console."); + JUTReport(30, 420, 1, "SCROLL:%3d %3d %3d Output=%1x", console->getLineOffset(), + console->getPositionX(), console->getPositionY(), console->getOutput()); + } else { + if (i_pad->getTrigger() & CButton::DPAD_DOWN) { + g_HIO.mDisplayMeter ^= 1; + } + + if (i_pad->getTrigger() & CButton::DPAD_LEFT) { + if (JKRAram::getAramHeap()) { + JKRAram::getAramHeap()->dump(); + } + + DynamicModuleControlBase::dump(); + g_dComIfG_gameInfo.mResControl.dump(); + } + + if (i_pad->getTrigger() & CButton::DPAD_RIGHT) { + JKRHeap::getSystemHeap()->dump_sort(); + } + + if (i_pad->getTrigger() & CButton::DPAD_UP) { + zeldaHeap->dump_sort(); + gameHeap->dump_sort(); + archiveHeap->dump_sort(); + } + JUTReport(30, 440, 1, "Press L+R trigger to control console."); + JUTReport(30, 450, 1, "Press [Z] trigger to close this window."); + } + console->setPosition(console_position_x, console_position_y); + return 1; + } + } + return 0; } /* 800061E0-800061E8 .text dump_sort__7JKRHeapFv */ -void JKRHeap::dump_sort() { - /* Nonmatching */ +bool JKRHeap::dump_sort() { + return 1; } /* 800061E8-80006264 .text LOAD_COPYDATE__FPv */ -void LOAD_COPYDATE(void*) { - /* Nonmatching */ +s32 LOAD_COPYDATE(void*) { + s32 status; + + DVDFileInfo __attribute__((aligned(0x20))) fileInfo; + u8 buffer[0x20]; + status = DVDOpen("/COPYDATE", &fileInfo); + + if (status) { + DVDReadPrio(&fileInfo, &buffer, 32, 0, 2); + memcpy(mDoMain::COPYDATE_STRING, buffer, 17); + status = DVDClose(&fileInfo); + } + return status; } /* 80006264-80006338 .text debug__Fv */ void debug() { - /* Nonmatching */ + if (mDoMain::developmentMode) { + if (mCheckHeap) { + CheckHeap(g_mDoCPd_gamePad[2]); + } + + if ((g_mDoCPd_gamePad[2]->getButton() & ~CButton::Z) == CButton::R && + g_mDoCPd_gamePad[2]->testTrigger(CButton::Z)) + { + mDisplayHeapSize ^= 1; + } + + if (mDisplayHeapSize) { + if ((g_mDoCPd_gamePad[2]->getButton() & ~CButton::Z) == CButton::L && + g_mDoCPd_gamePad[2]->testTrigger(CButton::Z)) + { + mHeapBriefType < 5 ? mHeapBriefType++ : mHeapBriefType = 1; + } + + debugDisplay(); + } + + Debug_console(g_mDoCPd_gamePad[2]); + } } /* 80006338-80006464 .text main01__Fv */ void main01() { - /* Nonmatching */ + static u32 frame; + + // Setup heaps, setup exception manager, set RNG seed, setup DVDError Thread, setup Memory card + // Thread + mDoMch_Create(); + + // setup FrameBuffer and ZBuffer, init display lists + mDoGph_Create(); + + // Setup control pad + mDoCPd_Create(); + + RootHeapCheck.setHeap((JKRExpHeap*)JKRHeap::getRootHeap()); + SystemHeapCheck.setHeap((JKRExpHeap*)JKRHeap::getSystemHeap()); + ZeldaHeapCheck.setHeap(mDoExt_getZeldaHeap()); + GameHeapCheck.setHeap(mDoExt_getGameHeap()); + ArchiveHeapCheck.setHeap(mDoExt_getArchiveHeap()); + CommandHeapCheck.setHeap(mDoExt_getCommandHeap()); + + JUTConsole* console = JFWSystem::getSystemConsole(); + console->setOutput(mDoMain::developmentMode ? JUTConsole::OUTPUT_OSR_AND_CONSOLE : + JUTConsole::OUTPUT_NONE); + console->setPosition(32, 42); + + mDoDvdThd_callback_c::create((mDoDvdThd_callback_func)LOAD_COPYDATE, NULL); + fapGm_Create(); // init framework + mDisplayHeapSize = 0; + cDyl_InitAsync(); // init RELs + + g_mDoAud_audioHeap = JKRSolidHeap::create(0x166800, JKRHeap::getCurrentHeap(), false); + + do { + frame++; + if (fillcheck_check_frame != 0 && frame % fillcheck_check_frame == 0) { + mDoMch_HeapCheckAll(); + } + + if (mDoDvdThd::SyncWidthSound) { + g_mDoMemCd_control.update(); + } + + mDoCPd_Read(); // read controller input + mDoAud_Execute(); // handle audio execution + fapGm_Execute(); // handle game execution + debug(); // run debugger + } while (true); } +static OSThread mainThread; + /* 80006464-800065DC .text main */ -void main { - /* Nonmatching */ +void main() { + OSThread* current_thread = OSGetCurrentThread(); + u8 __attribute__((aligned(0x20))) stack[0xF000]; + + mDoMain::sPowerOnTime = OSGetTime(); + OSReportInit__Fv(); + version_check(); + mDoRstData* reset_data = (mDoRstData*)OSAllocFromArenaLo(0x10, 4); + mDoRst::setResetData(reset_data); + + if (!mDoRst::i_getResetData()) { + do { + } while (true); + } + + if (OSGetResetCode() == 0) { + mDoRst::offReset(); + mDoRst::offResetPrepare(); + mDoRst::off3ButtonReset(); + mDoRst::set3ButtonResetPort(-1); + } + + g_dComIfG_gameInfo.ct(); + + if (mDoMain::developmentMode < 0) { + DVDDiskID* disk_id = DVDGetCurrentDiskID(); + + if (disk_id->game_version > 0x90) { + mDoMain::developmentMode = 1; + } else if (disk_id->game_version > 0x80) { + u32 consoleType = OSGetConsoleType(); + mDoMain::developmentMode = (consoleType >> 0x1C) & 1; + } else { + mDoMain::developmentMode = 0; + } + } + + s32 priority = OSGetThreadPriority(current_thread); + OSCreateThread(&mainThread, main01, 0, stack + sizeof(stack), sizeof(stack), priority, 0); + OSResumeThread(&mainThread); + OSSetThreadPriority(current_thread, 0x1F); + OSSuspendThread(current_thread); }