summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Ascencio <empressglatia@gmail.com>2023-09-16 18:13:11 -0400
committerDylan Ascencio <empressglatia@gmail.com>2023-09-16 18:13:11 -0400
commite940e4f4e0961aaa01c687dbfd96fdb6dec02cfe (patch)
treed22f3e7228cf89ac7152517c98149b4778c6db04
parent331847e88ff809875cb2b643e8434a3a10b7446e (diff)
parentf0cc6a9bef1422bb5d63cfe452772a76499ea0fd (diff)
Merge remote-tracking branch 'upstream/main'
-rw-r--r--configure.py12
-rw-r--r--include/JSystem/JKernel/JKRAramArchive.h2
-rw-r--r--include/JSystem/JKernel/JKRArchive.h9
-rw-r--r--include/JSystem/JKernel/JKRCompArchive.h2
-rw-r--r--include/JSystem/JKernel/JKRDvdArchive.h2
-rw-r--r--include/JSystem/JKernel/JKRExpHeap.h7
-rw-r--r--include/JSystem/JKernel/JKRHeap.h2
-rw-r--r--include/JSystem/JKernel/JKRMemArchive.h2
-rw-r--r--include/JSystem/JKernel/JKRSolidHeap.h2
-rw-r--r--include/JSystem/JKernel/JKRThread.h57
-rw-r--r--include/d/actor/d_a_mgameboard.h69
-rw-r--r--include/d/d_a_obj.h5
-rw-r--r--include/d/d_lib.h41
-rw-r--r--include/d/d_seafightgame.h32
-rw-r--r--include/f_op/f_op_actor_mng.h270
-rw-r--r--include/m_Do/m_Do_DVDError.h8
-rw-r--r--include/m_Do/m_Do_Reset.h44
-rw-r--r--include/m_Do/m_Do_audio.h1
-rw-r--r--include/m_Do/m_Do_machine_exception.h16
-rw-r--r--src/JSystem/JKernel/JKRArchivePri.cpp219
-rw-r--r--src/JSystem/JKernel/JKRArchivePub.cpp341
-rw-r--r--src/JSystem/JKernel/JKRExpHeap.cpp952
-rw-r--r--src/JSystem/JKernel/JKRFileLoader.cpp145
-rw-r--r--src/JSystem/JKernel/JKRThread.cpp131
-rw-r--r--src/d/actor/d_a_mgameboard.cpp2
-rw-r--r--src/d/actor/d_a_obj_Ygush00.cpp2
-rw-r--r--src/d/actor/d_a_obj_movebox.cpp12
-rw-r--r--src/d/d_seafightgame.cpp122
-rw-r--r--src/m_Do/m_Do_DVDError.cpp50
-rw-r--r--src/m_Do/m_Do_Reset.cpp106
-rw-r--r--src/m_Do/m_Do_machine_exception.cpp92
31 files changed, 2223 insertions, 534 deletions
diff --git a/configure.py b/configure.py
index 8a558879..46395c26 100644
--- a/configure.py
+++ b/configure.py
@@ -252,13 +252,13 @@ config.libs = [
Object(NonMatching, "m_Do/m_Do_ext.cpp"),
Object(NonMatching, "m_Do/m_Do_lib.cpp"),
Object(Matching, "m_Do/m_Do_hostIO.cpp"),
- Object(NonMatching, "m_Do/m_Do_Reset.cpp"),
+ Object(Matching, "m_Do/m_Do_Reset.cpp"),
Object(NonMatching, "m_Do/m_Do_dvd_thread.cpp"),
- Object(NonMatching, "m_Do/m_Do_DVDError.cpp"),
+ Object(Matching, "m_Do/m_Do_DVDError.cpp"),
Object(NonMatching, "m_Do/m_Do_MemCard.cpp"),
Object(NonMatching, "m_Do/m_Do_MemCardRWmng.cpp"),
Object(NonMatching, "m_Do/m_Do_gba_com.cpp"),
- Object(NonMatching, "m_Do/m_Do_machine_exception.cpp"),
+ Object(Matching, "m_Do/m_Do_machine_exception.cpp"),
# c
Object(NonMatching, "c/c_damagereaction.cpp"),
@@ -395,7 +395,7 @@ config.libs = [
Object(NonMatching, "d/d_wood.cpp"),
Object(NonMatching, "d/d_flower.cpp"),
Object(NonMatching, "d/d_item_data.cpp"),
- Object(NonMatching, "d/d_seafightgame.cpp"),
+ Object(Matching, "d/d_seafightgame.cpp"),
Object(NonMatching, "d/d_spline_path.cpp"),
Object(NonMatching, "d/d_s_actor_data_mng.cpp"),
Object(NonMatching, "d/d_item.cpp"),
@@ -760,13 +760,13 @@ config.libs = [
Object(NonMatching, "JSystem/JKernel/JKRExpHeap.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRSolidHeap.cpp"),
Object(Matching, "JSystem/JKernel/JKRDisposer.cpp"),
- Object(NonMatching, "JSystem/JKernel/JKRThread.cpp"),
+ Object(Matching, "JSystem/JKernel/JKRThread.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRAram.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRAramHeap.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRAramBlock.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRAramPiece.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRAramStream.cpp"),
- Object(NonMatching, "JSystem/JKernel/JKRFileLoader.cpp"),
+ Object(Matching, "JSystem/JKernel/JKRFileLoader.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRFileFinder.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRFileCache.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRArchivePub.cpp"),
diff --git a/include/JSystem/JKernel/JKRAramArchive.h b/include/JSystem/JKernel/JKRAramArchive.h
index 4c638dbd..5f8d2841 100644
--- a/include/JSystem/JKernel/JKRAramArchive.h
+++ b/include/JSystem/JKernel/JKRAramArchive.h
@@ -27,8 +27,6 @@ public:
private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRArchive
- /* 0x5C */ JKRCompression mCompression;
- /* 0x60 */ EMountDirection mMountDirection;
/* 0x64 */ JKRAramBlock* mBlock;
/* 0x68 */ JKRDvdFile* mDvdFile;
}; // Size = 0x6C
diff --git a/include/JSystem/JKernel/JKRArchive.h b/include/JSystem/JKernel/JKRArchive.h
index 4211d3ed..8ef03c41 100644
--- a/include/JSystem/JKernel/JKRArchive.h
+++ b/include/JSystem/JKernel/JKRArchive.h
@@ -5,6 +5,7 @@
#include "JSystem/JKernel/JKRFileLoader.h"
#include "global.h"
+class JKRArcFinder;
class JKRHeap;
struct SArcHeader {
@@ -129,7 +130,8 @@ public:
void* getResource(u16);
u32 readIdxResource(void*, u32, u32);
u32 readResource(void*, u32, u16);
- u32 countResource(void) const;
+ u32 countResource(u32) const;
+ JKRArcFinder* getFirstResource(u32) const;
u32 getFileAttribute(u32) const;
SDIFileEntry* findNameResource(const char*) const;
@@ -182,13 +184,16 @@ public:
protected:
/* 0x58 */ u32 field_0x58;
+ /* 0x5C */ JKRCompression mCompression;
+ /* 0x60 */ EMountDirection mMountDirection;
public:
- static JKRArchive* check_mount_already(s32, JKRHeap*);
+ static JKRArchive* check_mount_already(s32);
static JKRArchive* mount(const char*, EMountMode, JKRHeap*, EMountDirection);
static JKRArchive* mount(void*, JKRHeap*, EMountDirection);
static JKRArchive* mount(s32, EMountMode, JKRHeap*, EMountDirection);
static void* getGlbResource(u32, const char*, JKRArchive*);
+ static void readTypeResource(void*, u32, u32, const char*, JKRArchive*);
static JKRCompression convertAttrToCompressionType(u32 attr) {
#define JKRARCHIVE_ATTR_COMPRESSION 0x04
diff --git a/include/JSystem/JKernel/JKRCompArchive.h b/include/JSystem/JKernel/JKRCompArchive.h
index 98da6327..338332fb 100644
--- a/include/JSystem/JKernel/JKRCompArchive.h
+++ b/include/JSystem/JKernel/JKRCompArchive.h
@@ -24,8 +24,6 @@ public:
private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRArchive
- /* 0x5C */ int mCompression;
- /* 0x60 */ EMountDirection mMountDirection;
/* 0x64 */ int field_0x64;
/* 0x68 */ JKRAramBlock* mAramPart;
/* 0x6C */ int field_0x6c;
diff --git a/include/JSystem/JKernel/JKRDvdArchive.h b/include/JSystem/JKernel/JKRDvdArchive.h
index e2e6b408..fe72cd8f 100644
--- a/include/JSystem/JKernel/JKRDvdArchive.h
+++ b/include/JSystem/JKernel/JKRDvdArchive.h
@@ -23,8 +23,6 @@ public:
private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRArchive
- /* 0x5C */ JKRCompression mCompression;
- /* 0x60 */ EMountDirection mMountDirection;
/* 0x64 */ s32 field_0x64;
/* 0x68 */ JKRDvdFile* mDvdFile;
};
diff --git a/include/JSystem/JKernel/JKRExpHeap.h b/include/JSystem/JKernel/JKRExpHeap.h
index 3d566c03..6a89271e 100644
--- a/include/JSystem/JKernel/JKRExpHeap.h
+++ b/include/JSystem/JKernel/JKRExpHeap.h
@@ -56,11 +56,12 @@ protected:
void removeUsedBlock(CMemBlock* block);
void recycleFreeBlock(CMemBlock* block);
void joinTwoBlocks(CMemBlock* block);
+ bool dump_sort_by_address();
public:
s32 getUsedSize(u8 groupId) const;
s32 getTotalUsedSize(void) const;
-
+
CMemBlock* getHeadUsedList() const { return mHeadUsedList; }
void setAllocationMode(EAllocMode mode) {
mAllocMode = mode;
@@ -76,7 +77,7 @@ public:
/* vt[10] */ virtual void do_free(void* ptr); /* override */
/* vt[11] */ virtual void do_freeAll(); /* override */
/* vt[12] */ virtual void do_freeTail(); /* override */
- /* vt[13] */ virtual void do_fillFreeArea(); /* override */
+ /* vt[13] */ virtual void do_freeFill(); /* override */
/* vt[14] */ virtual s32 do_resize(void* ptr, u32 size); /* override */
/* vt[15] */ virtual s32 do_getSize(void* ptr); /* override */
/* vt[16] */ virtual s32 do_getFreeSize(); /* override */
@@ -84,7 +85,7 @@ public:
/* vt[18] */ virtual s32 do_getTotalFreeSize(); /* override */
/* vt[19] */ virtual s32 do_changeGroupID(u8 newGroupID); /* override */
/* vt[20] */ virtual u8 do_getCurrentGroupId(); /* override */
- /* vt[21] */ virtual u32 state_register(JKRHeap::TState* p, u32 id) const; /* override */
+ /* vt[21] */ virtual void state_register(JKRHeap::TState* p, u32 id) const; /* override */
/* vt[22] */ virtual bool state_compare(JKRHeap::TState const& r1,
JKRHeap::TState const& r2) const; /* override */
diff --git a/include/JSystem/JKernel/JKRHeap.h b/include/JSystem/JKernel/JKRHeap.h
index f8703af8..be6ea956 100644
--- a/include/JSystem/JKernel/JKRHeap.h
+++ b/include/JSystem/JKernel/JKRHeap.h
@@ -67,7 +67,7 @@ public:
/* vt[10] */ virtual void do_free(void* ptr) = 0;
/* vt[11] */ virtual void do_freeAll() = 0;
/* vt[12] */ virtual void do_freeTail() = 0;
- /* vt[13] */ virtual void do_fillFreeArea() = 0;
+ /* vt[13] */ virtual void do_freeFill() = 0;
/* vt[14] */ virtual s32 do_resize(void* ptr, u32 size) = 0;
/* vt[15] */ virtual s32 do_getSize(void* ptr) = 0;
/* vt[16] */ virtual s32 do_getFreeSize() = 0;
diff --git a/include/JSystem/JKernel/JKRMemArchive.h b/include/JSystem/JKernel/JKRMemArchive.h
index ba76ab1e..eb09c0b2 100644
--- a/include/JSystem/JKernel/JKRMemArchive.h
+++ b/include/JSystem/JKernel/JKRMemArchive.h
@@ -31,8 +31,6 @@ public:
private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRArchive
- /* 0x5C */ JKRCompression mCompression;
- /* 0x60 */ EMountDirection mMountDirection;
/* 0x64 */ SArcHeader* mArcHeader;
/* 0x68 */ u8* mArchiveData;
/* 0x6C */ bool mIsOpen;
diff --git a/include/JSystem/JKernel/JKRSolidHeap.h b/include/JSystem/JKernel/JKRSolidHeap.h
index 069b87ea..83a6e918 100644
--- a/include/JSystem/JKernel/JKRSolidHeap.h
+++ b/include/JSystem/JKernel/JKRSolidHeap.h
@@ -32,7 +32,7 @@ public:
/* vt[10] */ virtual void do_free(void*); /* override */
/* vt[11] */ virtual void do_freeAll(void); /* override */
/* vt[12] */ virtual void do_freeTail(void); /* override */
- /* vt[13] */ virtual void do_fillFreeArea(void); /* override */
+ /* vt[13] */ virtual void do_freeFill(void); /* override */
/* vt[14] */ virtual s32 do_resize(void*, u32); /* override */
/* vt[15] */ virtual s32 do_getSize(void*); /* override */
/* vt[16] */ virtual s32 do_getFreeSize(void); /* override */
diff --git a/include/JSystem/JKernel/JKRThread.h b/include/JSystem/JKernel/JKRThread.h
index f56a9231..ca4e8567 100644
--- a/include/JSystem/JKernel/JKRThread.h
+++ b/include/JSystem/JKernel/JKRThread.h
@@ -14,53 +14,11 @@ struct JKRThreadName_ {
class JUTConsole;
class JKRThread : JKRDisposer {
public:
- class TLoad {
- public:
- TLoad() {
- clear();
- mValid = false;
- mThreadId = 0;
- }
-
- bool isValid() const { return mValid; }
- u32 getCost() const { return mCost; }
- u32 getCount() const { return mSwitchCount; }
- s32 getId() const { return mThreadId; }
-
- void setValid(bool valid) { mValid = valid; }
- void setId(s32 id) { mThreadId = id; }
- void setCurrentTime() { mLastTick = OSGetTick(); }
-
- void resetCost() { mCost = 0; }
- void resetCount() { mSwitchCount = 0; }
-
- void incCount() { mSwitchCount++; }
- void addCurrentCost() { mCost = mCost + (OSGetTick() - mLastTick); }
-
- void clear() {
- resetCount();
- resetCost();
- mLastTick = 0;
- }
-
- private:
- /* 0x00 */ bool mValid;
- /* 0x01 */ u8 padding_0x61[3];
- /* 0x04 */ u32 mCost;
- /* 0x08 */ u32 mSwitchCount;
- /* 0x0C */ OSTick mLastTick;
- /* 0x10 */ s32 mThreadId;
- };
-
JKRThread(u32 stack_size, int message_count, int param_3);
- JKRThread(JKRHeap* heap, u32 stack_size, int message_count, int param_4);
JKRThread(OSThread* thread, int message_count);
virtual ~JKRThread();
- /* vt[03] */ virtual void* run();
-
- void setCommon_mesgQueue(JKRHeap* heap, int message_count);
- void setCommon_heapSpecified(JKRHeap* heap, u32 stack_size, int param_3);
+ /* vt[03] */ virtual void* run() { return NULL; }
OSThread* getThreadRecord() const { return mThreadRecord; }
void* getStack() const { return mStackMemory; }
@@ -122,9 +80,6 @@ typedef void (*JKRThreadSwitch_PostCallback)(OSThread* current, OSThread* next);
class JKRThreadSwitch {
public:
JKRThreadSwitch(JKRHeap*);
- virtual void draw(JKRThreadName_* param_1, JUTConsole* param_2);
- virtual void draw(JKRThreadName_* param_1);
- virtual ~JKRThreadSwitch();
static JKRThreadSwitch* createManager(JKRHeap* heap);
@@ -145,13 +100,9 @@ private:
/* 0x00 */ // vtable
/* 0x04 */ JKRHeap* mHeap;
/* 0x08 */ bool mSetNextHeap;
- /* 0x09 */ u8 field_0x9[3];
- /* 0x0C */ u32 field_0xC;
- /* 0x10 */ u32 field_0x10;
- /* 0x14 */ u8 field_0x14[4];
- /* 0x18 */ s64 field_0x18;
- /* 0x20 */ u32 field_0x20;
- /* 0x24 */ u32 field_0x24;
+
+public:
+ virtual ~JKRThreadSwitch() {}
};
struct JKRTask {
diff --git a/include/d/actor/d_a_mgameboard.h b/include/d/actor/d_a_mgameboard.h
new file mode 100644
index 00000000..623d62e9
--- /dev/null
+++ b/include/d/actor/d_a_mgameboard.h
@@ -0,0 +1,69 @@
+#ifndef D_A_MGAMEBOARD_H
+#define D_A_MGAMEBOARD_H
+
+#include "f_op/f_op_actor_mng.h"
+#include "d/d_seafightgame.h"
+#include "d/d_lib.h"
+
+class dDlst_2DNumber_c;
+class dDlst_2DMinigame_c;
+class dDlst_2DObject_c;
+
+class daMgBoard_c : public fopAc_ac_c {
+public:
+ void checkClearGame();
+ void getScore();
+ void reqStartGame();
+ void checkEndGame();
+ void setGInfoDraw();
+ void clrGInfoDraw();
+ void CreateHeap();
+ void set_2dposition();
+ void CreateInit();
+ void MiniGameInit();
+ void set_mtx();
+ void _execute();
+ void execGameMain();
+ void execEndGame();
+ void MinigameMain();
+ void CursorMove();
+ void _draw();
+
+ /* 0x290 */ request_of_phase_process_class mPhase;
+ /* 0x298 */ J3DModel* mpBoardModel;
+ /* 0x29C */ J3DModel* mpCursorModel;
+ /* 0x2A0 */ J3DModel* mpHitModel[20];
+ /* 0x2F0 */ J3DModel* mpMissModel[32];
+ /* 0x370 */ J3DModel* mpShip2Model[2];
+ /* 0x378 */ J3DModel* mpShip3Model[2];
+ /* 0x380 */ J3DModel* mpShip4Model;
+ /* 0x384 */ u8 field_0x384[0x468 - 0x384];
+ /* 0x468 */ u8 mBoardPosX;
+ /* 0x469 */ u8 mBoardPosY;
+ /* 0x46A */ u8 field_0x46A[0x46C - 0x46A];
+ /* 0x46C */ int mLastFirePosX;
+ /* 0x470 */ int mLastFirePosY;
+ /* 0x474 */ u8 field_0x474[0x47C - 0x474];
+ /* 0x47C */ dSeaFightGame_info_c mSeaFightGame;
+ /* 0x57C */ u8 field_0x57C[0x580 - 0x57C];
+ /* 0x580 */ int mMissModelCount;
+ /* 0x584 */ int mHitModelCount;
+ /* 0x588 */ s16 mMinigameStartIdx;
+ /* 0x58A */ s16 mMinigameEndIdx;
+ /* 0x58C */ STControl mStickControl;
+ /* 0x5B4 */ cXyz mNPCPos;
+ /* 0x5C0 */ dDlst_2DNumber_c* mpNumber0;
+ /* 0x5C4 */ dDlst_2DNumber_c* mpNumber1;
+ /* 0x5C8 */ dDlst_2DMinigame_c* mpMinigameDList;
+ /* 0x5CC */ dDlst_2DObject_c* mpSquidIcon[3];
+ /* 0x5D8 */ u8 mpBombIcons;
+ /* 0x5D9 */ u8 field_0x5D9[0x638 - 0x5D9];
+ /* 0x638 */ int mState;
+ /* 0x63C */ u8 mbDraw;
+ /* 0x63D */ u8 mbStartGame;
+ /* 0x63E */ u8 mbEndGame;
+ /* 0x63F */ u8 mbForceEnd;
+ /* 0x640 */ u8 mTimer;
+};
+
+#endif /* D_A_MGAMEBOARD_H */ \ No newline at end of file
diff --git a/include/d/d_a_obj.h b/include/d/d_a_obj.h
index de62a190..468079e4 100644
--- a/include/d/d_a_obj.h
+++ b/include/d/d_a_obj.h
@@ -4,10 +4,13 @@
#include "f_op/f_op_actor_mng.h"
#include "d/d_cc_d.h"
+class dBgS_GndChk;
+class cBgS_PolyInfo;
+
namespace daObj {
template <typename T>
int PrmAbstract(const fopAc_ac_c* actor, T width, T shift) {
- u32 param = fopAcM_GetParam(actor);
+ u32 param = fopAcM_GetParam((fopAc_ac_c*)actor);
return ((1 << width) - 1) & (param >> shift);
}
diff --git a/include/d/d_lib.h b/include/d/d_lib.h
new file mode 100644
index 00000000..99494710
--- /dev/null
+++ b/include/d/d_lib.h
@@ -0,0 +1,41 @@
+#ifndef D_LIB_H
+#define D_LIB_H
+
+#include "dolphin/types.h"
+
+class STControl {
+public:
+ void STControl(s16, s16, s16, s16, f32, f32, s16, s16);
+ void setWaitParm(s16, s16, s16, s16, f32, f32, s16, s16);
+ void init();
+ void Xinit();
+ void Yinit();
+ void getValueStick();
+ void getAngleStick();
+ void checkTrigger();
+ void checkLeftTrigger();
+ void checkRightTrigger();
+ void checkUpTrigger();
+ void checkDownTrigger();
+
+ /* 0x00 */ void* vtbl;
+ /* 0x04 */ f32 field_0x04;
+ /* 0x08 */ f32 field_0x08;
+ /* 0x0C */ u8 field_0x0c;
+ /* 0x0D */ u8 field_0x0d;
+ /* 0x0E */ u16 field_0x0e;
+ /* 0x10 */ u16 field_0x10;
+ /* 0x12 */ u16 field_0x12;
+ /* 0x14 */ s16 field_0x14;
+ /* 0x16 */ s16 field_0x16;
+ /* 0x18 */ u16 field_0x18;
+ /* 0x1A */ u16 field_0x1a;
+ /* 0x1C */ u16 field_0x1c;
+ /* 0x1E */ u16 field_0x1e;
+ /* 0x20 */ u16 field_0x20;
+ /* 0x22 */ u16 field_0x22;
+ /* 0x24 */ s16 field_0x24;
+ /* 0x26 */ s16 field_0x26;
+};
+
+#endif /* D_LIB_H */ \ No newline at end of file
diff --git a/include/d/d_seafightgame.h b/include/d/d_seafightgame.h
new file mode 100644
index 00000000..f141cb48
--- /dev/null
+++ b/include/d/d_seafightgame.h
@@ -0,0 +1,32 @@
+#ifndef D_SEAFIGHTGAME_H
+#define D_SEAFIGHTGAME_H
+
+#include "dolphin/types.h"
+
+struct dSeaFightGame_ship_data {
+ /* 0x0 */ u8 m_pos[4][2];
+ /* 0x8 */ u8 field_0x8;
+ /* 0x9 */ u8 field_0x9;
+ /* 0xA */ u8 field_0xa;
+ /* 0xB */ u8 field_0xb;
+ /* 0xC */ u8 field_0xc;
+ /* 0xD */ u8 field_0xd;
+ /* 0xE */ u8 field_0xe;
+};
+
+class dSeaFightGame_info_c {
+public:
+ int init(int, int);
+ int put_ship(u8, u8);
+ bool checkPutShip(int, int, int, int);
+ int attack(u8, u8);
+
+ /* 0x00 */ u8 mGrid[8][8];
+ /* 0x40 */ dSeaFightGame_ship_data mShips[4];
+ /* 0x7C */ u8 mAliveShipNum;
+ /* 0x7D */ u8 mBulletNum;
+ /* 0x7E */ u8 mScore;
+ /* 0x80 */ int mDeadShipNum;
+};
+
+#endif /* D_SEAFIGHTGAME_H */ \ No newline at end of file
diff --git a/include/f_op/f_op_actor_mng.h b/include/f_op/f_op_actor_mng.h
index ab264fba..4e6e7054 100644
--- a/include/f_op/f_op_actor_mng.h
+++ b/include/f_op/f_op_actor_mng.h
@@ -58,52 +58,7 @@ struct fopAcM_search_prm {
/* 0x0A */ s8 mSubType;
};
-class dBgS_LinChk;
-class fopAcM_lc_c {
-public:
- static dBgS_LinChk* getLineCheck() { return (dBgS_LinChk*)&mLineCheck; }
- static bool lineCheck(const cXyz*, const cXyz*, const fopAc_ac_c*);
- static u8 mLineCheck[112];
-};
-
-class dBgS_RoofChk;
-class fopAcM_rc_c {
-public:
- static dBgS_RoofChk* getRoofCheck() { return (dBgS_RoofChk*)&mRoofCheck; }
- static bool roofCheck(const cXyz*);
- static u8 mRoofCheck[80];
- static f32 mRoofY;
-};
-
-class dBgS_GndChk;
-class fopAcM_gc_c {
-public:
- static dBgS_GndChk* getGroundCheck() { return (dBgS_GndChk*)&mGndCheck; }
- static bool gndCheck(const cXyz*);
- static u8 mGndCheck[84]; // this is dBgS_GndChk but all static data in the TU probably needs to be setup first (otherwise causes a reordering problem with the __sinit function)
- static f32 mGroundY;
-
- // strange issue where f_op_actor_mng.h can't find the dComIfG_Bgsp() inline even when you include the header
- // static bool getTriPla(cM3dGPla* pPlane) {
- // return dComIfG_Bgsp().GetTriPla(mGndCheck,pPlane);
- // }
-
- static f32 getGroundY() { return mGroundY; }
-};
-
-class dBgS_WtrChk;
-class fopAcM_wt_c {
-public:
- static dBgS_WtrChk* getWaterCheck() { return (dBgS_WtrChk*)&mWaterCheck; }
- static f32 getWaterY() { return mWaterY[0]; }
-
- static bool waterCheck(const cXyz*);
- static u8 mWaterCheck[84 + 4 /* padding */];
- static f32 mWaterY[1 + 1 /* padding */];
-};
-
class dKy_tevstr_c;
-class cBgS_PolyInfo;
typedef int (*heapCallbackFunc)(fopAc_ac_c*);
typedef int (*createFunc)(void*);
@@ -111,11 +66,11 @@ struct DOUBLE_POS {
double x, y, z;
};
-inline const s8 fopAcM_GetRoomNo(const fopAc_ac_c* pActor) {
+inline s8 fopAcM_GetRoomNo(fopAc_ac_c* pActor) {
return pActor->current.roomNo;
}
-inline u32 fopAcM_GetID(const void* pActor) {
+inline u32 fopAcM_GetID(void* pActor) {
return fpcM_GetID(pActor);
}
@@ -123,7 +78,7 @@ inline s16 fopAcM_GetName(void* pActor) {
return fpcM_GetName(pActor);
}
-inline MtxP fopAcM_GetMtx(const fopAc_ac_c* pActor) {
+inline MtxP fopAcM_GetMtx(fopAc_ac_c* pActor) {
return pActor->mCullMtx;
}
@@ -152,7 +107,7 @@ inline u32 fopAcM_checkHookCarryNow(fopAc_ac_c* pActor) {
return fopAcM_checkStatus(pActor, 0x100000);
}
-inline u32 fopAcM_GetParam(const void* pActor) {
+inline u32 fopAcM_GetParam(void* pActor) {
return fpcM_GetParam(pActor);
}
@@ -168,11 +123,11 @@ inline void fopAcM_SetJntCol(fopAc_ac_c* i_actorP, dJntCol_c* i_jntColP) {
i_actorP->mJntCol = i_jntColP;
}
-inline s16 fopAcM_GetProfName(const void* pActor) {
+inline s16 fopAcM_GetProfName(void* pActor) {
return fpcM_GetProfName(pActor);
}
-inline u8 fopAcM_GetGroup(const fopAc_ac_c* p_actor) {
+inline u8 fopAcM_GetGroup(fopAc_ac_c* p_actor) {
return p_actor->mGroup;
}
@@ -244,7 +199,7 @@ inline void fopAcM_cancelHookCarryNow(fopAc_ac_c* actor) {
fopAcM_OffStatus(actor, 0x100000);
}
-inline s8 fopAcM_GetHomeRoomNo(const fopAc_ac_c* pActor) {
+inline s8 fopAcM_GetHomeRoomNo(fopAc_ac_c* pActor) {
return pActor->orig.roomNo;
}
@@ -284,26 +239,18 @@ inline BOOL fopAcM_IsExecuting(unsigned int id) {
return fpcM_IsExecuting(id);
}
-inline f32 fopAcM_GetSpeedF(const fopAc_ac_c* p_actor) {
+inline f32 fopAcM_GetSpeedF(fopAc_ac_c* p_actor) {
return p_actor->speedF;
}
-inline f32 fopAcM_GetGravity(const fopAc_ac_c* p_actor) {
+inline f32 fopAcM_GetGravity(fopAc_ac_c* p_actor) {
return p_actor->mGravity;
}
-inline f32 fopAcM_GetMaxFallSpeed(const fopAc_ac_c* p_actor) {
+inline f32 fopAcM_GetMaxFallSpeed(fopAc_ac_c* p_actor) {
return p_actor->mMaxFallSpeed;
}
-inline const cXyz& fopAcM_GetSpeed_p(const fopAc_ac_c* p_actor) {
- return p_actor->speed;
-}
-
-inline const cXyz& fopAcM_GetPosition_p(const fopAc_ac_c* p_actor) {
- return p_actor->current.pos;
-}
-
inline dJntCol_c* fopAcM_GetJntCol(fopAc_ac_c* i_actor) {
return i_actor->mJntCol;
}
@@ -312,11 +259,11 @@ inline void fopAcM_setCullSizeFar(fopAc_ac_c* i_actor, f32 i_far) {
i_actor->mCullSizeFar = i_far;
}
-inline f32 fopAcM_getCullSizeFar(const fopAc_ac_c* i_actor) {
+inline f32 fopAcM_getCullSizeFar(fopAc_ac_c* i_actor) {
return i_actor->mCullSizeFar;
}
-inline int fopAcM_GetCullSize(const fopAc_ac_c* i_actor) {
+inline int fopAcM_GetCullSize(fopAc_ac_c* i_actor) {
return i_actor->mCullType;
}
@@ -324,11 +271,11 @@ inline BOOL fopAcM_CULLSIZE_IS_BOX(int i_culltype) {
return (i_culltype >= 0 && i_culltype < 14) || i_culltype == 14;
}
-inline Vec fopAcM_getCullSizeSphereCenter(const fopAc_ac_c* i_actor) {
+inline Vec fopAcM_getCullSizeSphereCenter(fopAc_ac_c* i_actor) {
return i_actor->mCull.mSphere.mCenter;
}
-inline f32 fopAcM_getCullSizeSphereR(const fopAc_ac_c* i_actor) {
+inline f32 fopAcM_getCullSizeSphereR(fopAc_ac_c* i_actor) {
return i_actor->mCull.mSphere.mRadius;
}
@@ -337,43 +284,43 @@ inline void dComIfGs_offSwitch(int i_no, int i_roomNo);
inline BOOL dComIfGs_isSwitch(s32 i_no, s32 i_roomNo);
inline void dComIfGs_offActor(int i_no, int i_roomNo);
-inline void fopAcM_onSwitch(const fopAc_ac_c* pActor, int sw) {
- return dComIfGs_onSwitch(sw, pActor->orig.roomNo); // Should use fopAcM_GetHomeRoomNo, but that breaks regalloc?
+inline void fopAcM_onSwitch(fopAc_ac_c* pActor, int sw) {
+ return dComIfGs_onSwitch(sw, fopAcM_GetHomeRoomNo(pActor));
}
-inline void fopAcM_offSwitch(const fopAc_ac_c* pActor, int sw) {
- return dComIfGs_offSwitch(sw, pActor->orig.roomNo); // Should use fopAcM_GetHomeRoomNo, but that breaks regalloc?
+inline void fopAcM_offSwitch(fopAc_ac_c* pActor, int sw) {
+ return dComIfGs_offSwitch(sw, fopAcM_GetHomeRoomNo(pActor));
}
-inline BOOL fopAcM_isSwitch(const fopAc_ac_c* pActor, int sw) {
- return dComIfGs_isSwitch(sw, pActor->orig.roomNo); // Should use fopAcM_GetHomeRoomNo, but that breaks regalloc?
+inline BOOL fopAcM_isSwitch(fopAc_ac_c* pActor, int sw) {
+ return dComIfGs_isSwitch(sw, fopAcM_GetHomeRoomNo(pActor));
}
-inline fopAc_ac_c* i_fopAcM_SearchByName(s16 proc_id) {
+inline fopAc_ac_c* fopAcM_SearchByName(s16 proc_id) {
return (fopAc_ac_c*)fopAcIt_Judge(fpcSch_JudgeForPName, &proc_id);
}
inline void dComIfGs_onItem(int bitNo, int roomNo);
-inline void fopAcM_onItem(const fopAc_ac_c* item, int bitNo) {
+inline void fopAcM_onItem(fopAc_ac_c* item, int bitNo) {
dComIfGs_onItem(bitNo, fopAcM_GetHomeRoomNo(item));
}
inline bool dComIfGs_isItem(int bitNo, int roomNo);
-inline bool fopAcM_isItem(const fopAc_ac_c* item, int bitNo) {
+inline bool fopAcM_isItem(fopAc_ac_c* item, int bitNo) {
return dComIfGs_isItem(bitNo, fopAcM_GetHomeRoomNo(item));
}
-inline f32 fopAcM_searchActorDistanceY(const fopAc_ac_c* actorA, const fopAc_ac_c* actorB) {
+inline f32 fopAcM_searchActorDistanceY(fopAc_ac_c* actorA, fopAc_ac_c* actorB) {
return actorB->current.pos.y - actorA->current.pos.y;
}
-inline u16 fopAcM_GetSetId(const fopAc_ac_c* p_actor) {
+inline u16 fopAcM_GetSetId(fopAc_ac_c* p_actor) {
return p_actor->mSetID;
}
inline void dComIfGs_onActor(int bitNo, int roomNo);
-inline void fopAcM_onActor(const fopAc_ac_c* p_actor) {
+inline void fopAcM_onActor(fopAc_ac_c* p_actor) {
int setId = fopAcM_GetSetId(p_actor);
dComIfGs_onActor(setId, fopAcM_GetHomeRoomNo(p_actor));
}
@@ -392,37 +339,37 @@ s32 fopAcM_SearchByName(s16 procName, fopAc_ac_c** p_actor);
fopAcM_prm_class* fopAcM_CreateAppend();
-fopAcM_prm_class* createAppend(u16 enemyNo, u32 parameters, const cXyz* p_pos, int roomNo,
- const csXyz* p_angle, const cXyz* p_scale, s8 subType,
+fopAcM_prm_class* createAppend(u16 enemyNo, u32 parameters, cXyz* p_pos, int roomNo,
+ csXyz* p_angle, cXyz* p_scale, s8 subType,
unsigned int parentPId);
-void fopAcM_Log(fopAc_ac_c const* p_actor, char const* str);
+void fopAcM_Log(fopAc_ac_c* p_actor, char* str);
void fopAcM_delete(fopAc_ac_c* p_actor);
s32 fopAcM_delete(unsigned int actorID);
-s32 fopAcM_create(s16 procName, u16 enemyNo, u32 parameter, const cXyz* p_pos, int roomNo,
- const csXyz* p_angle, const cXyz* p_scale, s8 subType, createFunc p_createFunc);
+s32 fopAcM_create(s16 procName, u16 enemyNo, u32 parameter, cXyz* p_pos, int roomNo,
+ csXyz* p_angle, cXyz* p_scale, s8 subType, createFunc p_createFunc);
-s32 fopAcM_create(s16 procName, u32 parameter, const cXyz* p_pos, int roomNo, const csXyz* p_angle,
- const cXyz* p_scale, s8 subType);
+s32 fopAcM_create(s16 procName, u32 parameter, cXyz* p_pos, int roomNo, csXyz* p_angle,
+ cXyz* p_scale, s8 subType);
-void* fopAcM_fastCreate(s16 procName, u32 parameter, const cXyz* p_pos, int roomNo,
- const csXyz* p_angle, const cXyz* p_scale, s8 subType,
+void* fopAcM_fastCreate(s16 procName, u32 parameter, cXyz* p_pos, int roomNo,
+ csXyz* p_angle, cXyz* p_scale, s8 subType,
createFunc p_createFunc, void* p_createFuncData);
-void* fopAcM_fastCreate(const char* p_actorName, u32 parameter, const cXyz* pActorPos, int roomNo,
- const csXyz* p_angle, const cXyz* p_scale, createFunc p_createFunc,
+void* fopAcM_fastCreate(char* p_actorName, u32 parameter, cXyz* pActorPos, int roomNo,
+ csXyz* p_angle, cXyz* p_scale, createFunc p_createFunc,
void* p_createFuncData);
-s32 fopAcM_createChild(s16 procName, unsigned int parentPId, u32 parameters, const cXyz* p_pos,
- int roomNo, const csXyz* p_angle, const cXyz* p_scale, s8 subType,
+s32 fopAcM_createChild(s16 procName, unsigned int parentPId, u32 parameters, cXyz* p_pos,
+ int roomNo, csXyz* p_angle, cXyz* p_scale, s8 subType,
createFunc p_createFunc);
s32 fopAcM_createChildFromOffset(s16 procName, unsigned int parentProcID, u32 actorParams,
- const cXyz* p_pos, int roomNo, const csXyz* p_angle,
- const cXyz* p_scale, s8 subType, createFunc p_createFunc);
+ cXyz* p_pos, int roomNo, csXyz* p_angle,
+ cXyz* p_scale, s8 subType, createFunc p_createFunc);
void fopAcM_DeleteHeap(fopAc_ac_c* p_actor);
@@ -451,31 +398,29 @@ void fopAcM_posMove(fopAc_ac_c* p_actor, const cXyz* p_movePos);
void fopAcM_posMoveF(fopAc_ac_c* p_actor, const cXyz* p_movePos);
-s16 fopAcM_searchActorAngleY(const fopAc_ac_c* p_actorA, const fopAc_ac_c* p_actorB);
+s16 fopAcM_searchActorAngleY(fopAc_ac_c* p_actorA, fopAc_ac_c* p_actorB);
-s16 fopAcM_searchActorAngleX(const fopAc_ac_c* p_actorA, const fopAc_ac_c* p_actorB);
+s32 fopAcM_seenActorAngleY(fopAc_ac_c*, fopAc_ac_c*);
-s32 fopAcM_seenActorAngleY(const fopAc_ac_c*, const fopAc_ac_c*);
+f32 fopAcM_searchActorDistance(fopAc_ac_c* p_actorA, fopAc_ac_c* p_actorB);
-f32 fopAcM_searchActorDistance(const fopAc_ac_c* p_actorA, const fopAc_ac_c* p_actorB);
+f32 fopAcM_searchActorDistance2(fopAc_ac_c* p_actorA, fopAc_ac_c* p_actorB);
-f32 fopAcM_searchActorDistance2(const fopAc_ac_c* p_actorA, const fopAc_ac_c* p_actorB);
+f32 fopAcM_searchActorDistanceXZ(fopAc_ac_c* p_actorA, fopAc_ac_c* p_actorB);
-f32 fopAcM_searchActorDistanceXZ(const fopAc_ac_c* p_actorA, const fopAc_ac_c* p_actorB);
+f32 fopAcM_searchActorDistanceXZ2(fopAc_ac_c* p_actorA, fopAc_ac_c* p_actorB);
-f32 fopAcM_searchActorDistanceXZ2(const fopAc_ac_c* p_actorA, const fopAc_ac_c* p_actorB);
-
-s32 fopAcM_rollPlayerCrash(const fopAc_ac_c*, f32, u32, f32, f32, int, f32);
+s32 fopAcM_rollPlayerCrash(fopAc_ac_c*, f32, u32, f32, f32, int, f32);
s32 fopAcM_checkCullingBox(f32[3][4], f32, f32, f32, f32, f32, f32);
-s32 fopAcM_cullingCheck(const fopAc_ac_c*);
+s32 fopAcM_cullingCheck(fopAc_ac_c*);
void* event_second_actor(u16);
s32 fopAcM_orderTalkEvent(fopAc_ac_c*, fopAc_ac_c*, u16, u16);
s32 fopAcM_orderTalkItemBtnEvent(u16, fopAc_ac_c*, fopAc_ac_c*, u16, u16);
s32 fopAcM_orderSpeakEvent(fopAc_ac_c* i_actor, u16 i_priority, u16 i_flag);
s32 fopAcM_orderDoorEvent(fopAc_ac_c*, fopAc_ac_c*, u16, u16);
s32 fopAcM_orderCatchEvent(fopAc_ac_c*, fopAc_ac_c*, u16, u16);
-s32 fopAcM_orderOtherEvent(fopAc_ac_c*, const char*, u16, u16, u16);
-s32 fopAcM_orderOtherEvent(fopAc_ac_c*, fopAc_ac_c*, const char*, u16, u16, u16);
+s32 fopAcM_orderOtherEvent(fopAc_ac_c*, char*, u16, u16, u16);
+s32 fopAcM_orderOtherEvent(fopAc_ac_c*, fopAc_ac_c*, char*, u16, u16, u16);
s32 fopAcM_orderChangeEventId(fopAc_ac_c*, s16, u16, u16);
s32 fopAcM_orderOtherEventId(fopAc_ac_c* actor, s16 eventID, u8 mapToolID, u16 param_3,
u16 priority, u16 flag);
@@ -484,88 +429,77 @@ s32 fopAcM_orderMapToolAutoNextEvent(fopAc_ac_c*, u8, s16, u16, u16, u16);
s32 fopAcM_orderPotentialEvent(fopAc_ac_c*, u16, u16, u16);
s32 fopAcM_orderItemEvent(fopAc_ac_c*, u16, u16);
s32 fopAcM_orderTreasureEvent(fopAc_ac_c*, fopAc_ac_c*, u16, u16);
-fopAc_ac_c* fopAcM_getTalkEventPartner(const fopAc_ac_c*);
-fopAc_ac_c* fopAcM_getItemEventPartner(const fopAc_ac_c*);
-fopAc_ac_c* fopAcM_getEventPartner(const fopAc_ac_c*);
+fopAc_ac_c* fopAcM_getTalkEventPartner(fopAc_ac_c*);
+fopAc_ac_c* fopAcM_getItemEventPartner(fopAc_ac_c*);
+fopAc_ac_c* fopAcM_getEventPartner(fopAc_ac_c*);
-s32 fopAcM_createItemForPresentDemo(cXyz const* p_pos, int i_itemNo, u8 param_2, int i_itemBitNo,
- int i_roomNo, csXyz const* p_angle, cXyz const* p_scale);
+s32 fopAcM_createItemForPresentDemo(cXyz* p_pos, int i_itemNo, u8 param_2, int i_itemBitNo,
+ int i_roomNo, csXyz* p_angle, cXyz* p_scale);
-s32 fopAcM_createItemForTrBoxDemo(cXyz const* p_pos, int i_itemNo, int i_itemBitNo, int i_roomNo,
- csXyz const* p_angle, cXyz const* p_scale);
+s32 fopAcM_createItemForTrBoxDemo(cXyz* p_pos, int i_itemNo, int i_itemBitNo, int i_roomNo,
+ csXyz* p_angle, cXyz* p_scale);
u8 fopAcM_getItemNoFromTableNo(u8 i_tableNo);
-s32 fopAcM_createItemFromEnemyID(u8 i_enemyID, cXyz const* p_pos, int i_itemBitNo, int i_roomNo,
- csXyz const* p_angle, cXyz const* p_scale, f32* speedF,
+s32 fopAcM_createItemFromEnemyID(u8 i_enemyID, cXyz* p_pos, int i_itemBitNo, int i_roomNo,
+ csXyz * p_angle, cXyz * p_scale, f32* speedF,
f32* speedY);
-s32 fopAcM_createItemFromTable(cXyz const* p_pos, int i_tableNo, int i_itemBitNo, int i_roomNo,
- csXyz const* p_angle, int param_5, cXyz const* p_scale, f32* speedF,
+s32 fopAcM_createItemFromTable(cXyz* p_pos, int i_tableNo, int i_itemBitNo, int i_roomNo,
+ csXyz* p_angle, int param_5, cXyz * p_scale, f32* speedF,
f32* speedY, bool createDirect);
-s32 fopAcM_createDemoItem(const cXyz* p_pos, int itemNo, int itemBitNo, const csXyz* p_angle,
- int roomNo, const cXyz* scale, u8 param_7);
+s32 fopAcM_createDemoItem(cXyz* p_pos, int itemNo, int itemBitNo, csXyz* p_angle,
+ int roomNo, cXyz* scale, u8 param_7);
s32 fopAcM_createItemForBoss(cXyz* p_pos, int param_2, int roomNo, csXyz* p_angle,
cXyz* p_scale, int param_8);
-s32 fopAcM_createItemForMidBoss(const cXyz* p_pos, int i_itemNo, int i_roomNo, const csXyz* p_angle,
- const cXyz* p_scale, int param_6, int param_7);
+s32 fopAcM_createItemForMidBoss(cXyz* p_pos, int i_itemNo, int i_roomNo, csXyz* p_angle,
+ cXyz* p_scale, int param_6, int param_7);
-void* fopAcM_createItemForDirectGet(const cXyz* p_pos, int i_itemNo, int i_roomNo,
- const csXyz* p_angle, const cXyz* p_scale, f32 speedF,
+void* fopAcM_createItemForDirectGet(cXyz* p_pos, int i_itemNo, int i_roomNo,
+ csXyz* p_angle, cXyz* p_scale, f32 speedF,
f32 speedY);
-void* fopAcM_createItemForSimpleDemo(const cXyz* p_pos, int i_itemNo, int i_roomNo,
- const csXyz* p_angle, const cXyz* p_scale, f32 speedF,
+void* fopAcM_createItemForSimpleDemo(cXyz* p_pos, int i_itemNo, int i_roomNo,
+ csXyz* p_angle, cXyz* p_scale, f32 speedF,
f32 speedY);
-s32 fopAcM_createItem(const cXyz* p_pos, int itemNo, int param_3, int roomNo, const csXyz* p_angle,
- const cXyz* p_scale, int param_7);
+s32 fopAcM_createItem(cXyz* p_pos, int itemNo, int param_3, int roomNo, csXyz* p_angle,
+ cXyz* p_scale, int param_7);
-void* fopAcM_fastCreateItem2(const cXyz* p_pos, int itemNo, int param_3, int roomNo, int param_5,
- const csXyz* p_angle, const cXyz* p_scale);
+void* fopAcM_fastCreateItem2(cXyz* p_pos, int itemNo, int param_3, int roomNo, int param_5,
+ csXyz* p_angle, cXyz* p_scale);
-void* fopAcM_fastCreateItem(const cXyz* p_pos, int i_itemNo, int i_roomNo, const csXyz* p_angle,
- const cXyz* p_scale, f32* p_speedF, f32* p_speedY, int param_8,
+void* fopAcM_fastCreateItem(cXyz* p_pos, int i_itemNo, int i_roomNo, csXyz* p_angle,
+ cXyz* p_scale, f32* p_speedF, f32* p_speedY, int param_8,
int param_9, createFunc p_createFunc);
-s32 fopAcM_createBokkuri(u16, const cXyz*, int, int, int, const cXyz*, int, int);
-s32 fopAcM_createWarpHole(const cXyz*, const csXyz*, int, u8, u8, u8);
+s32 fopAcM_createBokkuri(u16, cXyz*, int, int, int, cXyz*, int, int);
+s32 fopAcM_createWarpHole(cXyz*, csXyz*, int, u8, u8, u8);
fopAc_ac_c* fopAcM_myRoomSearchEnemy(s8 roomNo);
-s32 fopAcM_createDisappear(const fopAc_ac_c*, const cXyz*, u8, u8, u8);
+s32 fopAcM_createDisappear(fopAc_ac_c*, cXyz*, u8, u8, u8);
void fopAcM_setCarryNow(fopAc_ac_c*, int);
void fopAcM_cancelCarryNow(fopAc_ac_c*);
-s32 fopAcM_otoCheck(const fopAc_ac_c*, f32);
-s32 fopAcM_otherBgCheck(const fopAc_ac_c*, const fopAc_ac_c*);
-s32 fopAcM_wayBgCheck(const fopAc_ac_c*, f32, f32);
-s32 fopAcM_plAngleCheck(const fopAc_ac_c*, s16);
-void fopAcM_effSmokeSet1(u32*, u32*, const cXyz*, const csXyz*, f32, const dKy_tevstr_c*, int);
-void fopAcM_effHamonSet(u32*, const cXyz*, f32, f32);
-s32 fopAcM_riverStream(cXyz*, s16*, f32*, f32);
-s32 fopAcM_carryOffRevise(fopAc_ac_c*);
-// void vectle_calc(const DOUBLE_POS*, cXyz*);
-// void get_vectle_calc(const cXyz*, const cXyz*, cXyz*);
-void fopAcM_setEffectMtx(const fopAc_ac_c*, const J3DModelData*);
+s32 fopAcM_otoCheck(fopAc_ac_c*, f32);
+// void vectle_calc(DOUBLE_POS*, cXyz*);
+// void get_vectle_calc(cXyz*, cXyz*, cXyz*);
-static const char* fopAcM_getProcNameString(const fopAc_ac_c* p_actor);
+static const char* fopAcM_getProcNameString(fopAc_ac_c* p_actor);
-static const fopAc_ac_c* fopAcM_findObjectCB(fopAc_ac_c const* p_actor, void* p_data);
+static fopAc_ac_c* fopAcM_findObjectCB(fopAc_ac_c* p_actor, void* p_data);
-fopAc_ac_c* fopAcM_searchFromName(char const* name, u32 param0, u32 param1);
+fopAc_ac_c* fopAcM_searchFromName(char* name, u32 param0, u32 param1);
fopAc_ac_c* fopAcM_findObject4EventCB(fopAc_ac_c* p_actor, void* p_data);
-fopAc_ac_c* fopAcM_searchFromName4Event(char const* name, s16 eventID);
+fopAc_ac_c* fopAcM_searchFromName4Event(char* name, s16 eventID);
s32 fopAcM_getWaterY(const cXyz*, f32*);
-void fpoAcM_relativePos(fopAc_ac_c const* actor, cXyz const* p_inPos, cXyz* p_outPos);
-s32 fopAcM_getWaterStream(const cXyz*, const cBgS_PolyInfo&, cXyz*, int*, int);
-s16 fopAcM_getPolygonAngle(const cBgS_PolyInfo&, s16);
-s16 fopAcM_getPolygonAngle(cM3dGPla const* param_0, s16 param_1);
+void fpoAcM_relativePos(fopAc_ac_c* actor, cXyz* p_inPos, cXyz* p_outPos);
inline void make_prm_warp_hole(u32* actorParams, u8 p1, u8 p2, u8 p3) {
u32 pp1 = (p3 << 0x8);
@@ -582,23 +516,23 @@ inline void make_prm_bokkuri(u32* pActorParams, csXyz* p_angle, u8 param_2, u8 p
inline fopAc_ac_c* dComIfGp_getPlayer(int);
-inline s16 fopAcM_searchPlayerAngleY(const fopAc_ac_c* actor) {
+inline s16 fopAcM_searchPlayerAngleY(fopAc_ac_c* actor) {
return fopAcM_searchActorAngleY(actor, (fopAc_ac_c*)dComIfGp_getPlayer(0));
}
-inline f32 fopAcM_searchPlayerDistanceY(const fopAc_ac_c* actor) {
+inline f32 fopAcM_searchPlayerDistanceY(fopAc_ac_c* actor) {
return fopAcM_searchActorDistanceY(actor, (fopAc_ac_c*)dComIfGp_getPlayer(0));
}
-inline f32 fopAcM_searchPlayerDistanceXZ2(const fopAc_ac_c* actor) {
+inline f32 fopAcM_searchPlayerDistanceXZ2(fopAc_ac_c* actor) {
return fopAcM_searchActorDistanceXZ2(actor, (fopAc_ac_c*)dComIfGp_getPlayer(0));
}
-inline f32 fopAcM_searchPlayerDistanceXZ(const fopAc_ac_c* actor) {
+inline f32 fopAcM_searchPlayerDistanceXZ(fopAc_ac_c* actor) {
return fopAcM_searchActorDistanceXZ(actor, (fopAc_ac_c*)dComIfGp_getPlayer(0));
}
-inline f32 fopAcM_searchPlayerDistance(const fopAc_ac_c* actor) {
+inline f32 fopAcM_searchPlayerDistance(fopAc_ac_c* actor) {
return fopAcM_searchActorDistance(actor, (fopAc_ac_c*)dComIfGp_getPlayer(0));
}
@@ -609,29 +543,11 @@ inline void fopAcM_seStartCurrent(fopAc_ac_c* actor, u32 sfxID, u32 param_2) {
mDoAud_seStart(sfxID, &actor->current.pos, param_2, dComIfGp_getReverb(roomNo));
}
-inline void fopAcM_seStart(const fopAc_ac_c* actor, u32 sfxID, u32 param_2) {
+inline void fopAcM_seStart(fopAc_ac_c* actor, u32 sfxID, u32 param_2) {
s8 roomNo = fopAcM_GetRoomNo(actor);
// mDoAud_seStart(sfxID, &actor->mEyePos, param_2, dComIfGp_getReverb(roomNo));
}
-inline void fopAcM_seStartLevel(const fopAc_ac_c* actor, u32 sfxID, u32 param_2) {
- s8 roomNo = fopAcM_GetRoomNo(actor);
- // i_mDoAud_seStartLevel(sfxID, &actor->mEyePos, param_2, dComIfGp_getReverb(roomNo));
-}
-
-inline void fopAcM_seStartCurrentLevel(const fopAc_ac_c* actor, u32 sfxID, u32 param_2) {
- s8 roomNo = fopAcM_GetRoomNo(actor);
- // i_mDoAud_seStartLevel(sfxID, &actor->current.pos, param_2, dComIfGp_getReverb(roomNo));
-}
-
-inline void fopAcM_offActor(fopAc_ac_c* pActor, u32 flag) {
- dComIfGs_offActor(flag,fopAcM_GetHomeRoomNo(pActor));
-}
-
-inline void fopAcM_OnCarryType(fopAc_ac_c* pActor, fopAcM_CARRY param_2) {
- pActor->mCarryType |= param_2;
-}
-
extern "C" {
void fopAcM_initManager__Fv(void);
void fopAcM_CreateAppend__Fv(void);
diff --git a/include/m_Do/m_Do_DVDError.h b/include/m_Do/m_Do_DVDError.h
new file mode 100644
index 00000000..784ab1f3
--- /dev/null
+++ b/include/m_Do/m_Do_DVDError.h
@@ -0,0 +1,8 @@
+#ifndef M_DO_M_DO_DVD_ERROR_H
+#define M_DO_M_DO_DVD_ERROR_H
+
+#include "dolphin/types.h"
+
+void mDoDvdErr_ThdCleanup();
+
+#endif /* M_DO_M_DO_DVD_ERROR_H */
diff --git a/include/m_Do/m_Do_Reset.h b/include/m_Do/m_Do_Reset.h
index 325982ee..905fdb8f 100644
--- a/include/m_Do/m_Do_Reset.h
+++ b/include/m_Do/m_Do_Reset.h
@@ -13,22 +13,11 @@ struct mDoRstData {
/* 0x04 */ int mResetPrepare;
/* 0x08 */ int m3ButtonReset;
/* 0x0C */ int m3ButtonResetPort;
- /* 0x10 */ bool mShutdown;
- /* 0x11 */ bool mReturnToMenu;
- /* 0x12 */ u8 mLogoScnFlag;
- /* 0x13 */ u8 mProgSeqFlag;
- /* 0x14 */ u8 mProgChgFlag;
- /* 0x15 */ u8 mWarningDispFlag;
-}; // Size = 0x18
+}; // Size = 0x10
class mDoRst {
public:
- static void offReturnToMenu() { mResetData->mReturnToMenu = false; }
- static void offShutdown() { mResetData->mShutdown = false; }
- static void setWarningDispFlag(u8 flag) { mResetData->mWarningDispFlag = flag; }
- static void setProgChgFlag(u8 flag) { mResetData->mProgChgFlag = flag; }
- static void setProgSeqFlag(u8 flag) { mResetData->mProgSeqFlag = flag; }
- static void setLogoScnFlag(u8 flag) { mResetData->mLogoScnFlag = flag; }
+#if VERSION != VERSION_JP
static void set3ButtonResetPort(int port) { mResetData->m3ButtonResetPort = port; }
static void off3ButtonReset() { mResetData->m3ButtonReset = 0; }
static void offResetPrepare() { mResetData->mResetPrepare = 0; }
@@ -36,24 +25,35 @@ public:
mResetData->mReset = 0;
mResetData->mResetPrepare = 0;
}
- static u8 getLogoScnFlag() { return mResetData->mLogoScnFlag; }
- static u8 getProgSeqFlag() { return mResetData->mProgSeqFlag; }
- static u8 getWarningDispFlag() { return mResetData->mWarningDispFlag; }
- static BOOL isReturnToMenu() { return mResetData->mReturnToMenu; }
- static BOOL isShutdown() { return mResetData->mShutdown; }
static int isReset() { return mResetData->mReset; }
static int get3ButtonResetPort() { return mResetData->m3ButtonResetPort; }
static int is3ButtonReset() { return mResetData->m3ButtonReset; }
static void onReset() { mResetData->mReset = 1; }
- static void onReturnToMenu() { mResetData->mReturnToMenu = true; }
static void on3ButtonReset() { mResetData->m3ButtonReset = 1; }
- static void onShutdown() { mResetData->mShutdown = true; }
- static mDoRstData* getResetData();
- static mDoRstData* i_getResetData() { return mResetData; }
+ static mDoRstData* getResetData() { return mResetData; }
static void setResetData(mDoRstData* rstData) { mResetData = rstData; }
static mDoRstData* mResetData;
+#else
+ static void set3ButtonResetPort(int port) { m3ButtonResetPort = port; }
+ static void off3ButtonReset() { m3ButtonResetFlag = 0; }
+ static void offResetPrepare() { mResetPrepare = 0; }
+ static void offReset() {
+ mResetFlag = 0;
+ mResetPrepare = 0;
+ }
+ static int isReset() { return mResetFlag; }
+ static int get3ButtonResetPort() { return m3ButtonResetPort; }
+ static int is3ButtonReset() { return m3ButtonResetFlag; }
+ static void onReset() { mResetFlag = 1; }
+ static void on3ButtonReset() { m3ButtonResetFlag = 1; }
+
+ static int mResetPrepare;
+ static int mResetFlag;
+ static int m3ButtonResetFlag;
+ static int m3ButtonResetPort;
+#endif
};
extern bool mDoDvdErr_initialized;
diff --git a/include/m_Do/m_Do_audio.h b/include/m_Do/m_Do_audio.h
index 1b6445b5..ffdfdde2 100644
--- a/include/m_Do/m_Do_audio.h
+++ b/include/m_Do/m_Do_audio.h
@@ -16,6 +16,7 @@ public:
static void offResetFlag() { mResetFlag = false; }
static bool isInitFlag() { return mInitFlag; }
+ static void offInitFlag() { mInitFlag = false; }
static bool isBgmSet() { return mBgmSet; }
static void offBgmSet() { mBgmSet = false; }
diff --git a/include/m_Do/m_Do_machine_exception.h b/include/m_Do/m_Do_machine_exception.h
new file mode 100644
index 00000000..f3a69357
--- /dev/null
+++ b/include/m_Do/m_Do_machine_exception.h
@@ -0,0 +1,16 @@
+#ifndef M_DO_M_DO_MACHINE_EXCEPTION_H
+#define M_DO_M_DO_MACHINE_EXCEPTION_H
+
+#include "dolphin/types.h"
+
+class JUTConsole;
+
+void print_f(char const*, ...);
+void print(char const*);
+void dispHeapInfo();
+void dispGameInfo();
+void dispDateInfo();
+void dispConsoleToTerminal();
+void exception_addition(JUTConsole* pConsole);
+
+#endif /* M_DO_M_DO_MACHINE_EXCEPTION_H */ \ No newline at end of file
diff --git a/src/JSystem/JKernel/JKRArchivePri.cpp b/src/JSystem/JKernel/JKRArchivePri.cpp
index 48f232b2..133fbb8c 100644
--- a/src/JSystem/JKernel/JKRArchivePri.cpp
+++ b/src/JSystem/JKernel/JKRArchivePri.cpp
@@ -3,85 +3,238 @@
// Translation Unit: JKRArchivePri.cpp
//
-#include "JSystem/JKernel/JKRArchivePri.h"
+#include "JSystem/JKernel/JKRArchive.h"
+#include "JSystem/JKernel/JKRHeap.h"
+#include "MSL_C/MSL_Common/Src/ctype.h"
+#include "MSL_C/string.h"
#include "dolphin/types.h"
+u32 JKRArchive::sCurrentDirID;
+
/* 802B8DFC-802B8E48 .text __ct__10JKRArchiveFv */
JKRArchive::JKRArchive() {
- /* Nonmatching */
+ mIsMounted = false;
+ mMountDirection = MOUNT_DIRECTION_HEAD;
}
/* 802B8E48-802B8EE8 .text __ct__10JKRArchiveFlQ210JKRArchive10EMountMode */
-JKRArchive::JKRArchive(long, JKRArchive::EMountMode) {
- /* Nonmatching */
+JKRArchive::JKRArchive(s32 entryNumber, JKRArchive::EMountMode mountMode) {
+ mIsMounted = false;
+ mMountMode = mountMode;
+ mMountCount = 1;
+ field_0x58 = 1;
+
+ mHeap = JKRHeap::findFromRoot(this);
+ if (mHeap == NULL) {
+ mHeap = JKRHeap::getCurrentHeap();
+ }
+
+ mEntryNum = entryNumber;
+ if (getCurrentVolume() == NULL) {
+ setCurrentVolume(this);
+ setCurrentDirID(0);
+ }
}
/* 802B8EE8-802B8F48 .text __dt__10JKRArchiveFv */
-JKRArchive::~JKRArchive() {
- /* Nonmatching */
-}
+JKRArchive::~JKRArchive() {}
/* 802B8F48-802B8F94 .text isSameName__10JKRArchiveCFRQ210JKRArchive8CArcNameUlUs */
-void JKRArchive::isSameName(JKRArchive::CArcName&, unsigned long, unsigned short) const {
- /* Nonmatching */
+bool JKRArchive::isSameName(JKRArchive::CArcName& name, u32 nameOffset, u16 nameHash) const {
+ u16 hash = name.getHash();
+ if (hash != nameHash)
+ return false;
+ return strcmp(mStringTable + nameOffset, name.getString()) == 0;
}
/* 802B8F94-802B8FD0 .text findResType__10JKRArchiveCFUl */
-void JKRArchive::findResType(unsigned long) const {
- /* Nonmatching */
+JKRArchive::SDIDirEntry* JKRArchive::findResType(u32 type) const {
+ SDIDirEntry* node = mNodes;
+ u32 count = 0;
+ while (count < mArcInfoBlock->num_nodes) {
+ if (node->type == type) {
+ return node;
+ }
+
+ node++;
+ count++;
+ }
+
+ return NULL;
}
/* 802B8FD0-802B90A8 .text findDirectory__10JKRArchiveCFPCcUl */
-void JKRArchive::findDirectory(const char*, unsigned long) const {
- /* Nonmatching */
+JKRArchive::SDIDirEntry* JKRArchive::findDirectory(const char* name, u32 directoryId) const {
+ if (name == NULL) {
+ return mNodes + directoryId;
+ }
+
+ CArcName arcName(&name, '/');
+ SDIDirEntry* dirEntry = mNodes + directoryId;
+ SDIFileEntry* fileEntry = mFiles + dirEntry->first_file_index;
+
+ for (int i = 0; i < dirEntry->num_entries; fileEntry++, i++) {
+ if (isSameName(arcName, fileEntry->getNameOffset(), fileEntry->name_hash)) {
+ if (fileEntry->isDirectory()) {
+ return findDirectory(name, fileEntry->data_offset);
+ }
+ break;
+ }
+ }
+
+ return NULL;
}
/* 802B90A8-802B9158 .text findTypeResource__10JKRArchiveCFUlPCc */
-void JKRArchive::findTypeResource(unsigned long, const char*) const {
- /* Nonmatching */
+JKRArchive::SDIFileEntry* JKRArchive::findTypeResource(u32 type, const char* name) const {
+ if (type) {
+ CArcName arcName(name);
+ SDIDirEntry* dirEntry = findResType(type);
+
+ if (dirEntry) {
+ SDIFileEntry* fileEntry = mFiles + dirEntry->first_file_index;
+ for (int i = 0; i < dirEntry->num_entries; fileEntry++, i++) {
+ if (isSameName(arcName, fileEntry->getNameOffset(), fileEntry->getNameHash())) {
+ return fileEntry;
+ }
+ }
+ }
+ }
+
+ return NULL;
}
/* 802B9158-802B9238 .text findFsResource__10JKRArchiveCFPCcUl */
-void JKRArchive::findFsResource(const char*, unsigned long) const {
- /* Nonmatching */
+JKRArchive::SDIFileEntry* JKRArchive::findFsResource(const char* name, u32 directoryId) const {
+ if (name) {
+ CArcName arcName(&name, '/');
+ SDIDirEntry* dirEntry = mNodes + directoryId;
+ SDIFileEntry* fileEntry = mFiles + dirEntry->first_file_index;
+
+ for (int i = 0; i < dirEntry->num_entries; fileEntry++, i++) {
+ if (isSameName(arcName, fileEntry->getNameOffset(), fileEntry->name_hash)) {
+ if (fileEntry->isDirectory()) {
+ return findFsResource(name, fileEntry->data_offset);
+ }
+
+ if (name == NULL) {
+ return fileEntry;
+ }
+
+ return NULL;
+ }
+ }
+ }
+
+ return NULL;
}
/* 802B9238-802B9260 .text findIdxResource__10JKRArchiveCFUl */
-void JKRArchive::findIdxResource(unsigned long) const {
- /* Nonmatching */
+JKRArchive::SDIFileEntry* JKRArchive::findIdxResource(u32 fileIndex) const {
+ if (fileIndex < mArcInfoBlock->num_file_entries) {
+ return mFiles + fileIndex;
+ }
+
+ return NULL;
}
/* 802B9260-802B92E8 .text findNameResource__10JKRArchiveCFPCc */
-void JKRArchive::findNameResource(const char*) const {
- /* Nonmatching */
+JKRArchive::SDIFileEntry* JKRArchive::findNameResource(const char* name) const {
+ SDIFileEntry* fileEntry = mFiles;
+
+ CArcName arcName(name);
+ for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
+ if (isSameName(arcName, fileEntry->getNameOffset(), fileEntry->getNameHash())) {
+ return fileEntry;
+ }
+ }
+
+ return NULL;
}
/* 802B92E8-802B9324 .text findPtrResource__10JKRArchiveCFPCv */
-void JKRArchive::findPtrResource(const void*) const {
- /* Nonmatching */
+JKRArchive::SDIFileEntry* JKRArchive::findPtrResource(const void* resource) const {
+ SDIFileEntry* fileEntry = mFiles;
+ for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
+ if (fileEntry->data == resource) {
+ return fileEntry;
+ }
+ }
+
+ return NULL;
}
/* 802B9324-802B93A4 .text findIdResource__10JKRArchiveCFUs */
-void JKRArchive::findIdResource(unsigned short) const {
- /* Nonmatching */
+JKRArchive::SDIFileEntry* JKRArchive::findIdResource(u16 id) const {
+ if (id != 0xFFFF) {
+ SDIFileEntry* fileEntry = mFiles + id;
+ if (fileEntry->file_id == id && fileEntry->isUnknownFlag1()) {
+ return fileEntry;
+ }
+
+ fileEntry = mFiles;
+ for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
+ if (fileEntry->file_id == id && fileEntry->isUnknownFlag1()) {
+ return fileEntry;
+ }
+ }
+ }
+
+ return NULL;
}
/* 802B93A4-802B9434 .text store__Q210JKRArchive8CArcNameFPCc */
-void JKRArchive::CArcName::store(const char*) {
- /* Nonmatching */
+void JKRArchive::CArcName::store(const char* name) {
+ mHash = 0;
+ s32 length = 0;
+ while (*name) {
+ s32 ch = tolower(*name);
+ mHash = ch + mHash * 3;
+ if (length < (s32)ARRAY_SIZE(mData)) {
+ mData[length++] = ch;
+ }
+ name++;
+ }
+
+ mLength = (u16)length;
+ mData[length] = 0;
}
/* 802B9434-802B94EC .text store__Q210JKRArchive8CArcNameFPCcc */
-void JKRArchive::CArcName::store(const char*, char) {
- /* Nonmatching */
+const char* JKRArchive::CArcName::store(const char* name, char endChar) {
+ mHash = 0;
+ s32 length = 0;
+ while (*name && *name != endChar) {
+ s32 lch = tolower((int)*name);
+ mHash = lch + mHash * 3;
+ if (length < (s32)ARRAY_SIZE(mData)) {
+ mData[length++] = lch;
+ }
+ name++;
+ }
+
+ mLength = (u16)length;
+ mData[length] = 0;
+
+ if (*name == 0)
+ return NULL;
+ return name + 1;
}
/* 802B94EC-802B9528 .text setExpandSize__10JKRArchiveFPQ210JKRArchive12SDIFileEntryUl */
-void JKRArchive::setExpandSize(JKRArchive::SDIFileEntry*, unsigned long) {
- /* Nonmatching */
+void JKRArchive::setExpandSize(SDIFileEntry* fileEntry, u32 expandSize) {
+ int index = fileEntry - mFiles;
+ if (!mExpandedSize || index >= mArcInfoBlock->num_file_entries)
+ return;
+
+ mExpandedSize[index] = expandSize;
}
/* 802B9528-802B9568 .text getExpandSize__10JKRArchiveCFPQ210JKRArchive12SDIFileEntry */
-void JKRArchive::getExpandSize(JKRArchive::SDIFileEntry*) const {
- /* Nonmatching */
+u32 JKRArchive::getExpandSize(SDIFileEntry* fileEntry) const {
+ int index = fileEntry - mFiles;
+ if (!mExpandedSize || index >= mArcInfoBlock->num_file_entries)
+ return 0;
+
+ return mExpandedSize[index];
}
diff --git a/src/JSystem/JKernel/JKRArchivePub.cpp b/src/JSystem/JKernel/JKRArchivePub.cpp
index edcaf067..f080e84a 100644
--- a/src/JSystem/JKernel/JKRArchivePub.cpp
+++ b/src/JSystem/JKernel/JKRArchivePub.cpp
@@ -3,115 +3,368 @@
// Translation Unit: JKRArchivePub.cpp
//
-#include "JSystem/JKernel/JKRArchivePub.h"
-#include "dolphin/types.h"
+#include "JSystem/JKernel/JKRArchive.h"
+#include "JSystem/JKernel/JKRAramArchive.h"
+#include "JSystem/JKernel/JKRCompArchive.h"
+#include "JSystem/JKernel/JKRDvdArchive.h"
+#include "JSystem/JKernel/JKRFileFinder.h"
+#include "JSystem/JKernel/JKRHeap.h"
+#include "JSystem/JKernel/JKRMemArchive.h"
+#include "JSystem/JUtility/JUTAssert.h"
+#include "dolphin/dvd/dvd.h"
/* 802B7FB4-802B8008 .text check_mount_already__10JKRArchiveFl */
-void JKRArchive::check_mount_already(long) {
- /* Nonmatching */
+JKRArchive* JKRArchive::check_mount_already(s32 entryNum) {
+ JSUList<JKRFileLoader>& volumeList = getVolumeList();
+ JSUListIterator<JKRFileLoader> iterator;
+ for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
+ if (iterator->getVolumeType() == 'RARC') {
+ JKRArchive* archive = (JKRArchive*)iterator.getObject();
+ if (archive->mEntryNum == entryNum) {
+ archive->mMountCount++;
+ return archive;
+ }
+ }
+ }
+
+ return NULL;
}
/* 802B8008-802B8064 .text mount__10JKRArchiveFPCcQ210JKRArchive10EMountModeP7JKRHeapQ210JKRArchive15EMountDirection */
-void JKRArchive::mount(const char*, JKRArchive::EMountMode, JKRHeap*, JKRArchive::EMountDirection) {
- /* Nonmatching */
+JKRArchive* JKRArchive::mount(const char* path, JKRArchive::EMountMode mountMode, JKRHeap* heap, JKRArchive::EMountDirection mountDirection) {
+ s32 entryNum = DVDConvertPathToEntrynum(path);
+ if (entryNum < 0)
+ return NULL;
+
+ return mount(entryNum, mountMode, heap, mountDirection);
}
/* 802B8064-802B81D0 .text mount__10JKRArchiveFlQ210JKRArchive10EMountModeP7JKRHeapQ210JKRArchive15EMountDirection */
-void JKRArchive::mount(long, JKRArchive::EMountMode, JKRHeap*, JKRArchive::EMountDirection) {
- /* Nonmatching */
+JKRArchive* JKRArchive::mount(s32 entryNum, JKRArchive::EMountMode mountMode, JKRHeap* heap, JKRArchive::EMountDirection mountDirection) {
+ JKRArchive* archive = check_mount_already(entryNum);
+ if (archive != NULL) {
+ return archive;
+ } else {
+ int alignment;
+ if (mountDirection == JKRArchive::MOUNT_DIRECTION_HEAD) {
+ alignment = 4;
+ } else {
+ alignment = -4;
+ }
+
+ JKRArchive* archive;
+ switch (mountMode) {
+ case JKRArchive::MOUNT_MEM:
+ archive = new (heap, alignment) JKRMemArchive(entryNum, mountDirection);
+ break;
+ case JKRArchive::MOUNT_ARAM:
+ archive = new (heap, alignment) JKRAramArchive(entryNum, mountDirection);
+ break;
+ case JKRArchive::MOUNT_DVD:
+ archive = new (heap, alignment) JKRDvdArchive(entryNum, mountDirection);
+ break;
+ case JKRArchive::MOUNT_COMP:
+ archive = new (heap, alignment) JKRCompArchive(entryNum, mountDirection);
+ break;
+ }
+
+ if (archive && archive->getMountMode() == JKRArchive::UNKNOWN_MOUNT_MODE) {
+ delete archive;
+ archive = NULL;
+ }
+
+ return archive;
+ }
}
/* 802B81D0-802B8258 .text becomeCurrent__10JKRArchiveFPCc */
-void JKRArchive::becomeCurrent(const char*) {
- /* Nonmatching */
+bool JKRArchive::becomeCurrent(const char* path) {
+ SDIDirEntry* dirEntry;
+ if (*path == '/') {
+ path++;
+
+ if (*path == '\0')
+ path = NULL;
+ dirEntry = findDirectory(path, 0);
+ } else {
+ dirEntry = findDirectory(path, getCurrentDirID());
+ }
+
+ bool found = dirEntry != NULL;
+ if (found) {
+ setCurrentVolume(this);
+ setCurrentDirID(dirEntry - mNodes);
+ }
+
+ return found;
}
/* 802B8258-802B82D0 .text getDirEntry__10JKRArchiveCFPQ210JKRArchive9SDirEntryUl */
-void JKRArchive::getDirEntry(JKRArchive::SDirEntry*, unsigned long) const {
- /* Nonmatching */
+bool JKRArchive::getDirEntry(SDirEntry* dirEntry, u32 index) const {
+ SDIFileEntry* fileEntry = findIdxResource(index);
+ if (!fileEntry) {
+ return false;
+ }
+
+ dirEntry->flags = fileEntry->getFlags();
+ dirEntry->id = fileEntry->getFileID();
+ dirEntry->name = mStringTable + fileEntry->getNameOffset();
+ return true;
}
/* 802B82D0-802B8380 .text getGlbResource__10JKRArchiveFUlPCcP10JKRArchive */
-void JKRArchive::getGlbResource(unsigned long, const char*, JKRArchive*) {
- /* Nonmatching */
+void* JKRArchive::getGlbResource(u32 param_0, const char* path, JKRArchive* archive) {
+ void* resource = NULL;
+ if (archive) {
+ return archive->getResource(param_0, path);
+ }
+
+ JSUList<JKRFileLoader>& volumeList = getVolumeList();
+ JSUListIterator<JKRFileLoader> iterator;
+ for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
+ if (iterator->getVolumeType() == 'RARC') {
+ resource = iterator->getResource(param_0, path);
+ if (resource)
+ break;
+ }
+ }
+
+ return resource;
}
/* 802B8380-802B8450 .text getResource__10JKRArchiveFPCc */
-void JKRArchive::getResource(const char*) {
- /* Nonmatching */
+void* JKRArchive::getResource(const char* path) {
+ JUT_ASSERT(285, isMounted());
+ SDIFileEntry* fileEntry;
+ if (*path == '/') {
+ fileEntry = findFsResource(path + 1, 0);
+ } else {
+ fileEntry = findFsResource(path, getCurrentDirID());
+ }
+
+ if (fileEntry) {
+ return fetchResource(fileEntry, NULL);
+ }
+
+ return NULL;
}
/* 802B8450-802B8528 .text getResource__10JKRArchiveFUlPCc */
-void JKRArchive::getResource(unsigned long, const char*) {
- /* Nonmatching */
+void* JKRArchive::getResource(u32 type, const char* path) {
+ JUT_ASSERT(332, isMounted());
+ SDIFileEntry* fileEntry;
+ if (type == 0 || type == '????') {
+ fileEntry = findNameResource(path);
+ } else {
+ fileEntry = findTypeResource(type, path);
+ }
+
+ if (fileEntry) {
+ return fetchResource(fileEntry, NULL);
+ }
+
+ return NULL;
}
/* 802B8528-802B85F0 .text readTypeResource__10JKRArchiveFPvUlUlPCcP10JKRArchive */
-void JKRArchive::readTypeResource(void*, unsigned long, unsigned long, const char*, JKRArchive*) {
+// missing instructions
+void JKRArchive::readTypeResource(void* buffer, u32 bufferSize, u32 type, const char* path, JKRArchive* archive) {
/* Nonmatching */
+ if (archive) {
+ archive->readResource(buffer, bufferSize, type, path);
+ return;
+ }
+ JSUListIterator<JKRFileLoader> iterator;
+ for (iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); iterator++) {
+ if (iterator->getVolumeType() == 'RARC') {
+ u32 result = iterator->readResource(buffer, bufferSize, type, path);
+ if (result != 0) {
+ return;
+ }
+ }
+ }
}
/* 802B85F0-802B86DC .text readResource__10JKRArchiveFPvUlUlPCc */
-void JKRArchive::readResource(void*, unsigned long, unsigned long, const char*) {
- /* Nonmatching */
+u32 JKRArchive::readResource(void* buffer, u32 bufferSize, u32 type, const char* path) {
+ JUT_ASSERT(491, isMounted());
+ SDIFileEntry* fileEntry;
+ if (type == 0 || type == '????') {
+ fileEntry = findNameResource(path);
+ } else {
+ fileEntry = findTypeResource(type, path);
+ }
+
+ if (fileEntry) {
+ u32 resourceSize;
+ fetchResource(buffer, bufferSize, fileEntry, &resourceSize);
+ return resourceSize;
+ }
+
+ return 0;
}
/* 802B86DC-802B87C0 .text readResource__10JKRArchiveFPvUlPCc */
-void JKRArchive::readResource(void*, unsigned long, const char*) {
- /* Nonmatching */
+u32 JKRArchive::readResource(void* buffer, u32 bufferSize, const char* path) {
+ JUT_ASSERT(537, isMounted());
+ SDIFileEntry* fileEntry;
+ if (*path == '/') {
+ fileEntry = findFsResource(path + 1, 0);
+ } else {
+ fileEntry = findFsResource(path, getCurrentDirID());
+ }
+
+ if (fileEntry) {
+ u32 resourceSize;
+ fetchResource(buffer, bufferSize, fileEntry, &resourceSize);
+ return resourceSize;
+ }
+
+ return 0;
}
/* 802B87C0-802B8878 .text readIdxResource__10JKRArchiveFPvUlUl */
-void JKRArchive::readIdxResource(void*, unsigned long, unsigned long) {
- /* Nonmatching */
+u32 JKRArchive::readIdxResource(void* buffer, u32 bufferSize, u32 index) {
+ JUT_ASSERT(593, isMounted());
+ SDIFileEntry* fileEntry = findIdxResource(index);
+ if (fileEntry) {
+ u32 resourceSize;
+ fetchResource(buffer, bufferSize, fileEntry, &resourceSize);
+ return resourceSize;
+ }
+
+ return 0;
}
/* 802B8878-802B8930 .text readResource__10JKRArchiveFPvUlUs */
-void JKRArchive::readResource(void*, unsigned long, unsigned short) {
- /* Nonmatching */
+u32 JKRArchive::readResource(void* buffer, u32 bufferSize, u16 id) {
+ JUT_ASSERT(627, isMounted());
+ SDIFileEntry* fileEntry = findIdResource(id);
+ if (fileEntry) {
+ u32 resourceSize;
+ fetchResource(buffer, bufferSize, fileEntry, &resourceSize);
+ return resourceSize;
+ }
+
+ return 0;
}
/* 802B8930-802B89B8 .text removeResourceAll__10JKRArchiveFv */
void JKRArchive::removeResourceAll() {
- /* Nonmatching */
+ if (mArcInfoBlock && mMountMode != MOUNT_MEM) {
+ SDIFileEntry* fileEntry = mFiles;
+ for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
+ if (fileEntry->data) {
+ JKRFreeToHeap(mHeap, fileEntry->data);
+ fileEntry->data = NULL;
+ }
+ }
+ }
}
/* 802B89B8-802B8A54 .text removeResource__10JKRArchiveFPv */
-void JKRArchive::removeResource(void*) {
- /* Nonmatching */
+bool JKRArchive::removeResource(void* resource) {
+ JUT_ASSERT(687, resource != 0);
+ SDIFileEntry* fileEntry = findPtrResource(resource);
+ if (fileEntry == NULL)
+ return false;
+
+ fileEntry->data = NULL;
+ JKRFreeToHeap(mHeap, resource);
+ return true;
}
/* 802B8A54-802B8AE4 .text detachResource__10JKRArchiveFPv */
-void JKRArchive::detachResource(void*) {
- /* Nonmatching */
+bool JKRArchive::detachResource(void* resource) {
+ JUT_ASSERT(719, resource != 0);
+ SDIFileEntry* fileEntry = findPtrResource(resource);
+ if (fileEntry == NULL)
+ return false;
+
+ fileEntry->data = NULL;
+ return true;
}
/* 802B8AE4-802B8B6C .text getResSize__10JKRArchiveCFPCv */
-void JKRArchive::getResSize(const void*) const {
- /* Nonmatching */
+u32 JKRArchive::getResSize(const void* resource) const {
+ JUT_ASSERT(746, resource != 0);
+ SDIFileEntry* fileEntry = findPtrResource(resource);
+ if (fileEntry == NULL)
+ return -1;
+
+ return fileEntry->data_size;
}
/* 802B8B6C-802B8BF0 .text countResource__10JKRArchiveCFUl */
-void JKRArchive::countResource(unsigned long) const {
- /* Nonmatching */
+u32 JKRArchive::countResource(u32 type) const {
+ SDIDirEntry* dirEntry = findResType(type);
+ if (dirEntry) {
+ int count = 0;
+ for (int i = dirEntry->first_file_index; i < dirEntry->first_file_index + dirEntry->num_entries; i++) {
+ if (mFiles[i].isUnknownFlag1()) {
+ count++;
+ }
+ }
+ return count;
+ }
+ return 0;
}
/* 802B8BF0-802B8C50 .text countFile__10JKRArchiveCFPCc */
-void JKRArchive::countFile(const char*) const {
- /* Nonmatching */
+u32 JKRArchive::countFile(const char* path) const {
+ SDIDirEntry* dirEntry;
+ if (*path == '/') {
+ path++;
+
+ if (*path == '\0')
+ path = NULL;
+ dirEntry = findDirectory(path, 0);
+ } else {
+ dirEntry = findDirectory(path, sCurrentDirID);
+ }
+
+ if (dirEntry) {
+ return dirEntry->num_entries;
+ }
+
+ return 0;
}
/* 802B8C50-802B8CFC .text getFirstFile__10JKRArchiveCFPCc */
-void JKRArchive::getFirstFile(const char*) const {
- /* Nonmatching */
+JKRFileFinder* JKRArchive::getFirstFile(const char* path) const {
+ SDIDirEntry* dirEntry;
+ if (*path == '/') {
+ path++;
+
+ if (*path == '\0')
+ path = NULL;
+ dirEntry = findDirectory(path, 0);
+ } else {
+ dirEntry = findDirectory(path, sCurrentDirID);
+ }
+
+ if (dirEntry) {
+ return new (JKRHeap::sSystemHeap, 0) JKRArcFinder((JKRArchive*)this, dirEntry->first_file_index, dirEntry->num_entries);
+ }
+
+ return NULL;
}
/* 802B8CFC-802B8DC4 .text getFirstResource__10JKRArchiveCFUl */
-void JKRArchive::getFirstResource(unsigned long) const {
- /* Nonmatching */
+JKRArcFinder* JKRArchive::getFirstResource(u32 type) const {
+ SDIDirEntry* dirEntry = findResType(type);
+ if (dirEntry && (getFileAttribute(dirEntry->first_file_index) & 1)) {
+ return new (JKRHeap::sSystemHeap, 0) JKRArcFinder((JKRArchive*)this, dirEntry->first_file_index, countResource(type));
+ }
+ return new (JKRHeap::sSystemHeap, 0) JKRArcFinder((JKRArchive*)this, 0, 0);
}
/* 802B8DC4-802B8DFC .text getFileAttribute__10JKRArchiveCFUl */
-void JKRArchive::getFileAttribute(unsigned long) const {
- /* Nonmatching */
+u32 JKRArchive::getFileAttribute(u32 index) const {
+ SDIFileEntry* fileEntry = findIdxResource(index);
+ if (fileEntry) {
+ return fileEntry->getFlags();
+ }
+
+ return 0;
}
diff --git a/src/JSystem/JKernel/JKRExpHeap.cpp b/src/JSystem/JKernel/JKRExpHeap.cpp
index e09b0383..7cbc894e 100644
--- a/src/JSystem/JKernel/JKRExpHeap.cpp
+++ b/src/JSystem/JKernel/JKRExpHeap.cpp
@@ -4,209 +4,1001 @@
//
#include "JSystem/JKernel/JKRExpHeap.h"
+#include "JSystem/JSupport/JSupport.h"
+#include "JSystem/JUtility/JUTAssert.h"
+#include "JSystem/JUtility/JUTConsole.h"
+#include "JSystem/JUtility/JUTException.h"
+#include "dolphin/os/OS.h"
#include "dolphin/types.h"
/* 802B1558-802B15D0 .text createRoot__10JKRExpHeapFib */
-void JKRExpHeap::createRoot(int, bool) {
- /* Nonmatching */
+JKRExpHeap* JKRExpHeap::createRoot(int maxHeaps, bool errorFlag) {
+ JKRExpHeap* heap = NULL;
+ if (!sRootHeap) {
+ void* memory;
+ u32 memorySize;
+ initArena((char**)&memory, &memorySize, maxHeaps);
+ u8* start = (u8*)memory + OSRoundUp(sizeof(JKRExpHeap), 0x10);
+ u32 alignedSize = memorySize - OSRoundUp(sizeof(JKRExpHeap), 0x10);
+ heap = new (memory) JKRExpHeap(start, alignedSize, NULL, errorFlag);
+ sRootHeap = heap;
+ }
+ heap->field_0x6e = true;
+ return heap;
}
/* 802B15D0-802B16A4 .text create__10JKRExpHeapFUlP7JKRHeapb */
-void JKRExpHeap::create(unsigned long, JKRHeap*, bool) {
- /* Nonmatching */
+JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) {
+ if (!parent) {
+ parent = sRootHeap;
+ }
+
+ if (size == 0xffffffff) {
+ size = parent->getMaxAllocatableSize(0x10);
+ }
+
+ u32 alignedSize = OSRoundDown(size, 0x10);
+ u32 expHeapSize = OSRoundUp(sizeof(JKRExpHeap), 0x10);
+ if (alignedSize < 0xa0)
+ return NULL;
+
+ u8* memory = (u8*)JKRAllocFromHeap(parent, alignedSize, 0x10);
+ u8* dataPtr = (memory + expHeapSize);
+ if (!memory) {
+ return NULL;
+ }
+
+ JKRExpHeap* newHeap =
+ new (memory) JKRExpHeap(dataPtr, alignedSize - expHeapSize, parent, errorFlag);
+
+ if (newHeap == NULL) {
+ i_JKRFree(memory);
+ return NULL;
+ }
+
+ newHeap->field_0x6e = false;
+ return newHeap;
}
/* 802B16A4-802B1728 .text do_destroy__10JKRExpHeapFv */
void JKRExpHeap::do_destroy() {
- /* Nonmatching */
+ if (!field_0x6e) {
+ JKRHeap* heap = mChildTree.getParent()->getObject();
+ if (heap) {
+ this->~JKRExpHeap();
+ JKRHeap::free(this, heap);
+ }
+ } else {
+ this->~JKRExpHeap();
+ }
}
/* 802B1728-802B17B8 .text __ct__10JKRExpHeapFPvUlP7JKRHeapb */
-JKRExpHeap::JKRExpHeap(void*, unsigned long, JKRHeap*, bool) {
- /* Nonmatching */
+JKRExpHeap::JKRExpHeap(void* data, u32 size, JKRHeap* parent, bool errorFlag) : JKRHeap(data, size, parent, errorFlag) {
+ mAllocMode = 0;
+ mCurrentGroupId = 0xff;
+ mHeadFreeList = (CMemBlock*)data;
+ mTailFreeList = mHeadFreeList;
+ mHeadFreeList->initiate(NULL, NULL, size - sizeof(CMemBlock), 0, 0);
+ mHeadUsedList = NULL;
+ mTailUsedList = NULL;
}
/* 802B17B8-802B1820 .text __dt__10JKRExpHeapFv */
JKRExpHeap::~JKRExpHeap() {
- /* Nonmatching */
+ dispose();
}
/* 802B1820-802B192C .text do_alloc__10JKRExpHeapFUli */
-void JKRExpHeap::do_alloc(unsigned long, int) {
- /* Nonmatching */
-}
+void* JKRExpHeap::do_alloc(u32 size, int alignment) {
+ void* ptr;
+
+ lock();
+ if (size < 4) {
+ size = 4;
+ }
+
+ if (alignment >= 0) {
+ if (alignment <= 4) {
+ ptr = allocFromHead(size);
+ } else {
+ ptr = allocFromHead(size, alignment);
+ }
+ } else {
+ if (-alignment <= 4) {
+ ptr = allocFromTail(size);
+ } else {
+ ptr = allocFromTail(size, -alignment);
+ }
+ }
+
+ if (ptr == NULL) {
+ JUTWarningConsole_f(":::cannot alloc memory (0x%x byte).\n", size);
+ if (mErrorFlag == true) {
+ callErrorHandler(this, size, alignment);
+ }
+ }
+ unlock();
+
+ return ptr;
+}
+
+static u32 DBfoundSize;
+static u32 DBfoundOffset;
+static JKRExpHeap::CMemBlock* DBfoundBlock;
+static JKRExpHeap::CMemBlock* DBnewFreeBlock;
+static JKRExpHeap::CMemBlock* DBnewUsedBlock;
/* 802B192C-802B1B88 .text allocFromHead__10JKRExpHeapFUli */
-void JKRExpHeap::allocFromHead(unsigned long, int) {
- /* Nonmatching */
+// wrong register at end
+void* JKRExpHeap::allocFromHead(u32 size, int align) {
+ /* Nonmatching */
+ u32 foundOffset;
+ int foundSize;
+ CMemBlock* newFreeBlock;
+ CMemBlock* newUsedBlock;
+ CMemBlock* foundBlock;
+
+ size = ALIGN_NEXT(size, 4);
+ foundSize = -1;
+ foundOffset = 0;
+ foundBlock = NULL;
+
+ for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
+ u32 offset =
+ ALIGN_PREV(align - 1 + (u32)block->getContent(), align) - (u32)block->getContent();
+ if (block->size < size + offset) {
+ continue;
+ }
+
+ if (foundSize <= (u32)block->size) {
+ continue;
+ }
+
+ foundSize = block->size;
+ foundBlock = block;
+ foundOffset = offset;
+ if (mAllocMode != 0) {
+ break;
+ }
+
+ u32 blockSize = block->size;
+ if (blockSize == size) {
+ break;
+ }
+ }
+
+ DBfoundSize = foundSize;
+ DBfoundOffset = foundOffset;
+ DBfoundBlock = foundBlock;
+
+ if (foundBlock) {
+ if (foundOffset >= sizeof(CMemBlock)) {
+ CMemBlock* prev = foundBlock->mPrev;
+ CMemBlock* next = foundBlock->mNext;
+ newUsedBlock = foundBlock->allocFore(foundOffset - sizeof(CMemBlock), 0, 0, 0, 0);
+
+ if (newUsedBlock) {
+ newFreeBlock = newUsedBlock->allocFore(size, mCurrentGroupId, 0, 0, 0);
+ } else {
+ newFreeBlock = NULL;
+ }
+
+ if (newFreeBlock) {
+ setFreeBlock(foundBlock, prev, newFreeBlock);
+ } else {
+ setFreeBlock(foundBlock, prev, next);
+ }
+
+ if (newFreeBlock) {
+ setFreeBlock(newFreeBlock, foundBlock, next);
+ }
+
+ appendUsedList(newUsedBlock);
+ DBnewFreeBlock = newFreeBlock;
+ DBnewUsedBlock = newUsedBlock;
+ return newUsedBlock->getContent();
+ } else {
+ if (foundOffset != 0) {
+ CMemBlock* prev = foundBlock->mPrev;
+ CMemBlock* next = foundBlock->mNext;
+ removeFreeBlock(foundBlock);
+ newUsedBlock = (CMemBlock*)((u32)foundBlock + foundOffset);
+ newUsedBlock->size = foundBlock->size - foundOffset;
+ newFreeBlock =
+ newUsedBlock->allocFore(size, mCurrentGroupId, (u8)foundOffset, 0, 0);
+ if (newFreeBlock) {
+ setFreeBlock(newFreeBlock, prev, next);
+ }
+ appendUsedList(newUsedBlock);
+ return newUsedBlock->getContent();
+ } else {
+ CMemBlock* prev = foundBlock->mPrev;
+ CMemBlock* next = foundBlock->mNext;
+ // Works but very fake match
+ /*size = (u32)foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0);
+ removeFreeBlock(foundBlock);
+ if (size) {
+ setFreeBlock((CMemBlock*)size, prev, next);
+ }*/
+ newFreeBlock = foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0);
+ removeFreeBlock(foundBlock);
+ if (newFreeBlock) {
+ setFreeBlock(newFreeBlock, prev, next);
+ }
+ appendUsedList(foundBlock);
+ return foundBlock->getContent();
+ }
+ }
+ }
+
+ return NULL;
}
/* 802B1B88-802B1C6C .text allocFromHead__10JKRExpHeapFUl */
-void JKRExpHeap::allocFromHead(unsigned long) {
- /* Nonmatching */
+void* JKRExpHeap::allocFromHead(u32 size) {
+ size = ALIGN_NEXT(size, 4);
+ s32 foundSize = -1;
+ CMemBlock* foundBlock = NULL;
+ for (CMemBlock* block = mHeadFreeList; block; block = block->getNextBlock()) {
+ if (block->getSize() < size) {
+ continue;
+ }
+
+ if (foundSize <= block->getSize()) {
+ continue;
+ }
+
+ foundSize = block->getSize();
+ foundBlock = block;
+ if (mAllocMode != 0) {
+ break;
+ }
+
+ if (foundSize == size) {
+ break;
+ }
+ }
+
+ if (foundBlock) {
+ CMemBlock* newblock = foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0);
+ if (newblock) {
+ setFreeBlock(newblock, foundBlock->getPrevBlock(), foundBlock->getNextBlock());
+ } else {
+ removeFreeBlock(foundBlock);
+ }
+ appendUsedList(foundBlock);
+ return foundBlock->getContent();
+ }
+ return NULL;
}
/* 802B1C6C-802B1DCC .text allocFromTail__10JKRExpHeapFUli */
-void JKRExpHeap::allocFromTail(unsigned long, int) {
- /* Nonmatching */
+void* JKRExpHeap::allocFromTail(u32 size, int align) {
+ u32 offset = 0;
+ CMemBlock* foundBlock = NULL;
+ CMemBlock* newBlock = NULL;
+ u32 usedSize;
+ u32 start;
+
+ for (CMemBlock* block = mTailFreeList; block; block = block->mPrev) {
+ start = ALIGN_PREV((u32)block->getContent() + block->size - size, align);
+ usedSize = (u32)block->getContent() + block->size - start;
+ if (block->size >= usedSize) {
+ foundBlock = block;
+ offset = block->size - usedSize;
+ newBlock = (CMemBlock*)start - 1;
+ break;
+ }
+ }
+
+ if (foundBlock != NULL) {
+ if (offset >= sizeof(CMemBlock)) {
+ newBlock->initiate(NULL, NULL, usedSize, mCurrentGroupId, -0x80);
+ foundBlock->size = foundBlock->size - usedSize - sizeof(CMemBlock);
+ appendUsedList(newBlock);
+ return newBlock->getContent();
+ } else {
+ if (offset != 0) {
+ removeFreeBlock(foundBlock);
+ newBlock->initiate(NULL, NULL, usedSize, mCurrentGroupId, offset | 0x80);
+ appendUsedList(newBlock);
+ return newBlock->getContent();
+ } else {
+ removeFreeBlock(foundBlock);
+ newBlock->initiate(NULL, NULL, usedSize, mCurrentGroupId, -0x80);
+ appendUsedList(newBlock);
+ return newBlock->getContent();
+ }
+ }
+ }
+
+ return NULL;
}
/* 802B1DCC-802B1EA4 .text allocFromTail__10JKRExpHeapFUl */
-void JKRExpHeap::allocFromTail(unsigned long) {
- /* Nonmatching */
+void* JKRExpHeap::allocFromTail(u32 size) {
+ u32 size2 = ALIGN_NEXT(size, 4);
+ CMemBlock* foundBlock = NULL;
+ for (CMemBlock* block = mTailFreeList; block; block = block->getPrevBlock()) {
+ if (block->getSize() >= size2) {
+ foundBlock = block;
+ break;
+ }
+ }
+
+ if (foundBlock != NULL) {
+ CMemBlock* usedBlock = foundBlock->allocBack(size2, 0, 0, mCurrentGroupId, 0);
+ CMemBlock* freeBlock;
+ if (usedBlock) {
+ freeBlock = foundBlock;
+ } else {
+ removeFreeBlock(foundBlock);
+ usedBlock = foundBlock;
+ freeBlock = NULL;
+ }
+
+ if (freeBlock) {
+ setFreeBlock(freeBlock, foundBlock->getPrevBlock(), foundBlock->getNextBlock());
+ }
+ appendUsedList(usedBlock);
+ return usedBlock->getContent();
+ }
+ return NULL;
}
/* 802B1EA4-802B1F44 .text do_free__10JKRExpHeapFPv */
-void JKRExpHeap::do_free(void*) {
- /* Nonmatching */
+void JKRExpHeap::do_free(void* ptr) {
+ lock();
+ if (getStartAddr() <= ptr && ptr <= getEndAddr()) {
+ CMemBlock* block = CMemBlock::getHeapBlock(ptr);
+ if (block) {
+ block->free(this);
+ }
+ } else {
+ JUT_WARN(888, "free: memblock %x not in heap %x", ptr, this);
+ }
+ unlock();
}
/* 802B1F44-802B1FC0 .text do_freeAll__10JKRExpHeapFv */
void JKRExpHeap::do_freeAll() {
- /* Nonmatching */
+ lock();
+ JKRHeap::callAllDisposer();
+ mHeadFreeList = (CMemBlock*)getStartAddr();
+ mTailFreeList = mHeadFreeList;
+ mHeadFreeList->initiate(NULL, NULL, getSize() - 0x10, 0, 0);
+ mHeadUsedList = NULL;
+ mTailUsedList = NULL;
+ unlock();
}
/* 802B1FC0-802B2048 .text do_freeTail__10JKRExpHeapFv */
void JKRExpHeap::do_freeTail() {
- /* Nonmatching */
+ lock();
+ for (CMemBlock* block = mHeadUsedList; block != NULL;) {
+ if ((block->mFlags & 0x80) != 0) {
+ dispose(block + 1, block->size);
+ CMemBlock* temp = block->mNext;
+ block->free(this);
+ block = temp;
+ } else {
+ block = block->mNext;
+ }
+ }
+ unlock();
}
/* 802B2048-802B2098 .text do_changeGroupID__10JKRExpHeapFUc */
-void JKRExpHeap::do_changeGroupID(unsigned char) {
- /* Nonmatching */
+s32 JKRExpHeap::do_changeGroupID(u8 groupId) {
+ lock();
+ u8 prev = mCurrentGroupId;
+ mCurrentGroupId = groupId;
+ unlock();
+ return prev;
}
/* 802B2098-802B2244 .text do_resize__10JKRExpHeapFPvUl */
-void JKRExpHeap::do_resize(void*, unsigned long) {
- /* Nonmatching */
+s32 JKRExpHeap::do_resize(void* ptr, u32 size) {
+ lock();
+ CMemBlock* block = CMemBlock::getHeapBlock(ptr);
+ if (block == NULL || ptr < mStart || mEnd < ptr) {
+ unlock();
+ return -1;
+ }
+
+ size = ALIGN_NEXT(size, 4);
+ if (size == block->size) {
+ unlock();
+ return size;
+ }
+
+ if (size > block->size) {
+ CMemBlock* foundBlock = NULL;
+ for (CMemBlock* freeBlock = mHeadFreeList; freeBlock; freeBlock = freeBlock->mNext) {
+ if (freeBlock == (CMemBlock*)((u32)(block + 1) + block->size)) {
+ foundBlock = freeBlock;
+ break;
+ }
+ }
+
+ if (foundBlock == NULL) {
+ unlock();
+ return -1;
+ }
+
+ if (size > block->size + sizeof(CMemBlock) + foundBlock->size) {
+ unlock();
+ return -1;
+ }
+
+ removeFreeBlock(foundBlock);
+ block->size += foundBlock->size + sizeof(CMemBlock);
+ if (block->size - size > sizeof(CMemBlock)) {
+ CMemBlock* newBlock = block->allocFore(size, block->mGroupId, block->mFlags, 0, 0);
+ if (newBlock) {
+ recycleFreeBlock(newBlock);
+ }
+ }
+ } else {
+ if (block->size - size > sizeof(CMemBlock)) {
+ CMemBlock* freeBlock = block->allocFore(size, block->mGroupId, block->mFlags, 0, 0);
+ if (freeBlock) {
+ recycleFreeBlock(freeBlock);
+ }
+ }
+ }
+
+ unlock();
+ return block->size;
}
/* 802B2244-802B22C4 .text do_getSize__10JKRExpHeapFPv */
-void JKRExpHeap::do_getSize(void*) {
- /* Nonmatching */
+s32 JKRExpHeap::do_getSize(void* ptr) {
+ lock();
+ CMemBlock* block = CMemBlock::getHeapBlock(ptr);
+ if (!block || ptr < getStartAddr() || getEndAddr() < ptr) {
+ unlock();
+ return -1;
+ }
+ unlock();
+ return block->getSize();
}
/* 802B22C4-802B2330 .text do_getFreeSize__10JKRExpHeapFv */
-void JKRExpHeap::do_getFreeSize() {
- /* Nonmatching */
+s32 JKRExpHeap::do_getFreeSize() {
+ lock();
+ s32 size = 0;
+ for (CMemBlock* block = mHeadFreeList; block; block = block->getNextBlock()) {
+ if (size < (s32)block->getSize()) {
+ size = block->getSize();
+ }
+ }
+ unlock();
+ return size;
}
/* 802B2330-802B23A4 .text do_getMaxFreeBlock__10JKRExpHeapFv */
-void JKRExpHeap::do_getMaxFreeBlock() {
- /* Nonmatching */
+void* JKRExpHeap::do_getMaxFreeBlock() {
+ lock();
+ s32 size = 0;
+ CMemBlock* res = NULL;
+ for (CMemBlock* block = mHeadFreeList; block; block = block->getNextBlock()) {
+ if (size < (s32)block->getSize()) {
+ size = block->getSize();
+ res = block;
+ }
+ }
+ unlock();
+ return res;
}
/* 802B23A4-802B2408 .text do_getTotalFreeSize__10JKRExpHeapFv */
-void JKRExpHeap::do_getTotalFreeSize() {
- /* Nonmatching */
+s32 JKRExpHeap::do_getTotalFreeSize() {
+ u32 size = 0;
+ lock();
+ for (CMemBlock* block = mHeadFreeList; block; block = block->getNextBlock()) {
+ size += block->getSize();
+ }
+ unlock();
+ return size;
}
/* 802B2408-802B2484 .text getUsedSize__10JKRExpHeapCFUc */
-void JKRExpHeap::getUsedSize(unsigned char) const {
- /* Nonmatching */
+s32 JKRExpHeap::getUsedSize(u8 groupId) const {
+ JKRExpHeap* this2 = const_cast<JKRExpHeap*>(this);
+ this2->lock();
+ u32 size = 0;
+
+ for (CMemBlock* block = mHeadUsedList; block; block = block->getNextBlock()) {
+ u8 blockGroupId = block->getGroupId();
+ if (blockGroupId == groupId) {
+ size += block->getSize() + sizeof(CMemBlock);
+ }
+ }
+
+ this2->unlock();
+ return size;
}
/* 802B2484-802B24EC .text getTotalUsedSize__10JKRExpHeapCFv */
-void JKRExpHeap::getTotalUsedSize() const {
- /* Nonmatching */
+s32 JKRExpHeap::getTotalUsedSize() const {
+ JKRExpHeap* this2 = const_cast<JKRExpHeap*>(this);
+ this2->lock();
+ u32 size = 0;
+
+ for (CMemBlock* block = mHeadUsedList; block; block = block->getNextBlock()) {
+ size += block->getSize() + sizeof(CMemBlock);
+ }
+
+ this2->unlock();
+ return size;
+}
+
+static void dummy1() {
+ OSReport("newSize > 0");
+ OSReport("Halt");
}
/* 802B24EC-802B2584 .text appendUsedList__10JKRExpHeapFPQ210JKRExpHeap9CMemBlock */
-void JKRExpHeap::appendUsedList(JKRExpHeap::CMemBlock*) {
- /* Nonmatching */
+void JKRExpHeap::appendUsedList(CMemBlock* newblock) {
+ if (!newblock) {
+ OSPanic(__FILE__, 1466, ":::ERROR! appendUsedList\n");
+ }
+
+ CMemBlock* block = mTailUsedList;
+ newblock->mMagic = 'HM';
+
+ if (block) {
+ block->mNext = newblock;
+ newblock->mPrev = block;
+ } else {
+ newblock->mPrev = NULL;
+ }
+
+ mTailUsedList = newblock;
+ if (!mHeadUsedList) {
+ mHeadUsedList = newblock;
+ }
+ newblock->mNext = NULL;
}
/* 802B2584-802B25D0 .text setFreeBlock__10JKRExpHeapFPQ210JKRExpHeap9CMemBlockPQ210JKRExpHeap9CMemBlockPQ210JKRExpHeap9CMemBlock */
-void JKRExpHeap::setFreeBlock(JKRExpHeap::CMemBlock*, JKRExpHeap::CMemBlock*, JKRExpHeap::CMemBlock*) {
- /* Nonmatching */
+void JKRExpHeap::setFreeBlock(CMemBlock* block, CMemBlock* prev, CMemBlock* next) {
+ if (prev == NULL) {
+ mHeadFreeList = block;
+ block->mPrev = NULL;
+ } else {
+ prev->mNext = block;
+ block->mPrev = prev;
+ }
+
+ if (next == NULL) {
+ mTailFreeList = block;
+ block->mNext = NULL;
+ } else {
+ next->mPrev = block;
+ block->mNext = next;
+ }
+
+ block->mMagic = 0;
}
/* 802B25D0-802B2604 .text removeFreeBlock__10JKRExpHeapFPQ210JKRExpHeap9CMemBlock */
-void JKRExpHeap::removeFreeBlock(JKRExpHeap::CMemBlock*) {
- /* Nonmatching */
+void JKRExpHeap::removeFreeBlock(CMemBlock* block) {
+ CMemBlock* prev = block->mPrev;
+ CMemBlock* next = block->mNext;
+
+ if (prev == NULL) {
+ mHeadFreeList = next;
+ } else {
+ prev->mNext = next;
+ }
+
+ if (next == NULL) {
+ mTailFreeList = prev;
+ } else {
+ next->mPrev = prev;
+ }
}
/* 802B2604-802B2638 .text removeUsedBlock__10JKRExpHeapFPQ210JKRExpHeap9CMemBlock */
-void JKRExpHeap::removeUsedBlock(JKRExpHeap::CMemBlock*) {
- /* Nonmatching */
+void JKRExpHeap::removeUsedBlock(CMemBlock* block) {
+ CMemBlock* prev = block->mPrev;
+ CMemBlock* next = block->mNext;
+
+ if (prev == NULL) {
+ mHeadUsedList = next;
+ } else {
+ prev->mNext = next;
+ }
+
+ if (next == NULL) {
+ mTailUsedList = prev;
+ } else {
+ next->mPrev = prev;
+ }
}
/* 802B2638-802B27D0 .text recycleFreeBlock__10JKRExpHeapFPQ210JKRExpHeap9CMemBlock */
-void JKRExpHeap::recycleFreeBlock(JKRExpHeap::CMemBlock*) {
- /* Nonmatching */
+void JKRExpHeap::recycleFreeBlock(CMemBlock* block) {
+ JKRExpHeap::CMemBlock* newBlock = block;
+ int size = block->size;
+ void* blockEnd = (u8*)block + size;
+ block->mMagic = 0;
+
+ if ((block->mFlags & 0x7f) != 0) {
+ newBlock = (CMemBlock*)((u8*)block - (block->mFlags & 0x7f));
+ size += (block->mFlags & 0x7f);
+ blockEnd = (u8*)newBlock + size;
+ newBlock->mGroupId = 0;
+ newBlock->mFlags = 0;
+ newBlock->size = size;
+ }
+
+ if (!mHeadFreeList) {
+ newBlock->initiate(NULL, NULL, size, 0, 0);
+ mHeadFreeList = newBlock;
+ mTailFreeList = newBlock;
+ setFreeBlock(newBlock, NULL, NULL);
+ return;
+ }
+
+ if (mHeadFreeList >= blockEnd) {
+ newBlock->initiate(NULL, NULL, size, 0, 0);
+ setFreeBlock(newBlock, NULL, mHeadFreeList);
+ joinTwoBlocks(newBlock);
+ return;
+ }
+
+ if (mTailFreeList <= newBlock) {
+ newBlock->initiate(NULL, NULL, size, 0, 0);
+ setFreeBlock(newBlock, mTailFreeList, NULL);
+ joinTwoBlocks(newBlock->mPrev);
+ return;
+ }
+
+ for (CMemBlock* freeBlock = mHeadFreeList; freeBlock; freeBlock = freeBlock->mNext) {
+ if (freeBlock >= newBlock || newBlock >= freeBlock->mNext) {
+ continue;
+ }
+ newBlock->mNext = freeBlock->mNext;
+ newBlock->mPrev = freeBlock;
+ freeBlock->mNext = newBlock;
+ newBlock->mNext->mPrev = newBlock;
+ newBlock->mGroupId = 0;
+ joinTwoBlocks(newBlock);
+ joinTwoBlocks(freeBlock);
+ return;
+ }
}
/* 802B27D0-802B291C .text joinTwoBlocks__10JKRExpHeapFPQ210JKRExpHeap9CMemBlock */
-void JKRExpHeap::joinTwoBlocks(JKRExpHeap::CMemBlock*) {
- /* Nonmatching */
+// regalloc
+void JKRExpHeap::joinTwoBlocks(CMemBlock* block) {
+ /* Nonmatching */
+ u32 endAddr = (u32)(block + 1) + block->size;
+ CMemBlock* next = block->mNext;
+ u32 nextAddr = (u32)next - (next->mFlags & 0x7f);
+ if (endAddr > nextAddr) {
+ JUTWarningConsole_f(":::Heap may be broken. (block = %x)", block);
+ OSReport(":::block = %x\n", block);
+ OSReport(":::joinTwoBlocks [%x %x %x][%x %x %x]\n", block, block->mFlags, block->size, block->mNext, block->mNext->mFlags, block->mNext->size);
+ OSReport(":::: endAddr = %x\n", endAddr);
+ OSReport(":::: nextAddr = %x\n", nextAddr);
+ JKRGetCurrentHeap()->dump();
+ OSPanic(__FILE__, 1718, ":::: Bad Block\n");
+ }
+
+ if (endAddr == nextAddr) {
+ block->size = next->size + sizeof(CMemBlock) + next->getAlignment() + block->size;
+ setFreeBlock(block, block->mPrev, next->mNext);
+ }
}
/* 802B291C-802B2B44 .text check__10JKRExpHeapFv */
-void JKRExpHeap::check() {
- /* Nonmatching */
+bool JKRExpHeap::check() {
+ lock();
+ int totalBytes = 0;
+ bool ok = true;
+ for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) {
+ if (!block->isValid()) {
+ ok = false;
+ JUTWarningConsole_f(":::addr %08x: bad heap signature. (%c%c)\n", block,
+ JSUHiByte(block->mMagic), JSULoByte(block->mMagic));
+ }
+
+ if (block->mNext) {
+ if (!block->mNext->isValid()) {
+ ok = false;
+ JUTWarningConsole_f(":::addr %08x: bad next pointer (%08x)\nabort\n", block,
+ block->mNext);
+ break;
+ }
+ if (block->mNext->mPrev != block) {
+ ok = false;
+ JUTWarningConsole_f(":::addr %08x: bad previous pointer (%08x)\n", block->mNext,
+ block->mNext->mPrev);
+ }
+ } else {
+ if (mTailUsedList != block) {
+ ok = false;
+ JUTWarningConsole_f(":::addr %08x: bad used list(REV) (%08x)\n", block,
+ mTailUsedList);
+ }
+ }
+ totalBytes += sizeof(CMemBlock) + block->size + block->getAlignment();
+ }
+
+ for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
+ totalBytes += block->size + sizeof(CMemBlock);
+ if (block->mNext) {
+ if (block->mNext->mPrev != block) {
+ ok = false;
+ JUTWarningConsole_f(":::addr %08x: bad previous pointer (%08x)\n", block->mNext,
+ block->mNext->mPrev);
+ }
+
+ if ((u32)block + block->size + sizeof(CMemBlock) > (u32)block->mNext) {
+ ok = false;
+ JUTWarningConsole_f(":::addr %08x: bad block size (%08x)\n", block, block->size);
+ }
+ } else {
+ if (mTailFreeList != block) {
+ ok = false;
+ JUTWarningConsole_f(":::addr %08x: bad used list(REV) (%08x)\n", block,
+ mTailFreeList);
+ }
+ }
+ }
+
+ if (totalBytes != mSize) {
+ ok = false;
+ JUTWarningConsole_f(":::bad total memory block size (%08X, %08X)\n", mSize, totalBytes);
+ }
+
+ if (!ok) {
+ JUTWarningConsole(":::there is some error in this heap!\n");
+ }
+
+ unlock();
+ return ok;
}
/* 802B2B44-802B2B48 .text do_freeFill__10JKRExpHeapFv */
-void JKRExpHeap::do_freeFill() {
- /* Nonmatching */
-}
+void JKRExpHeap::do_freeFill() {}
/* 802B2B48-802B2D5C .text dump__10JKRExpHeapFv */
-void JKRExpHeap::dump() {
- /* Nonmatching */
+bool JKRExpHeap::dump() {
+ lock();
+ bool result = check();
+ u32 usedBytes = 0;
+ u32 usedCount = 0;
+ u32 freeCount = 0;
+
+ JUTReportConsole(" attr address: size gid aln prev_ptr next_ptr\n");
+ JUTReportConsole("(Used Blocks)\n");
+ if (!mHeadUsedList) {
+ JUTReportConsole(" NONE\n");
+ }
+
+ for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) {
+ if (!block->isValid()) {
+ JUTReportConsole_f("xxxxx %08x: -------- --- --- (-------- --------)\nabort\n",
+ block);
+ break;
+ }
+
+ JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n",
+ block->_isTempMemBlock() ? " temp" : "alloc", block->getContent(),
+ block->size, block->mGroupId, block->getAlignment(), block->mPrev,
+ block->mNext);
+ usedBytes += sizeof(CMemBlock) + block->size + block->getAlignment();
+ usedCount++;
+ }
+
+ JUTReportConsole("(Free Blocks)\n");
+ if (!mHeadFreeList) {
+ JUTReportConsole(" NONE\n");
+ }
+
+ for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
+ JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", " free", block->getContent(),
+ block->size, block->mGroupId, block->getAlignment(), block->mPrev,
+ block->mNext);
+ freeCount++;
+ }
+
+ float percent = ((float)usedBytes / (float)mSize) * 100.0f;
+ JUTReportConsole_f("%d / %d bytes (%6.2f%%) used (U:%d F:%d)\n", usedBytes, mSize, percent,
+ usedCount, freeCount);
+ unlock();
+ return result;
}
/* 802B2D5C-802B2F5C .text dump_sort_by_address__10JKRExpHeapFv */
-void JKRExpHeap::dump_sort_by_address() {
- /* Nonmatching */
+// regalloc, stack
+bool JKRExpHeap::dump_sort_by_address() {
+ /* Nonmatching */
+ lock();
+ bool result = check();
+ u32 usedBytes = 0;
+ u32 usedCount = 0;
+ u32 freeCount = 0;
+ JUTReportConsole(" attr address: size gid aln prev_ptr next_ptr\n");
+
+ CMemBlock* block;
+ for (CMemBlock* var1 = NULL; true; var1 = block) {
+ CMemBlock* block = (CMemBlock*)0xffffffff;
+ for (CMemBlock* iterBlock = mHeadFreeList; iterBlock; iterBlock = iterBlock->getNextBlock()) {
+ if (var1 < iterBlock && iterBlock < block) {
+ block = iterBlock;
+ }
+ }
+
+ for (CMemBlock* iterBlock = mHeadUsedList; iterBlock; iterBlock = iterBlock->getNextBlock()) {
+ if (var1 < iterBlock && iterBlock < block) {
+ block = iterBlock;
+ }
+ }
+
+ if (block == (CMemBlock*)0xffffffff) {
+ break;
+ }
+
+ if (block->mMagic == 0) {
+ JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", " free", block->getContent(), block->getSize(), block->getGroupId(), block->getAlignment(), block->getPrevBlock(), block->getNextBlock());
+ freeCount += 1;
+ continue;
+ }
+
+ if (!block->isValid()) {
+ JUTReportConsole_f("xxxxx %08x: -------- --- --- (-------- --------)\nabort\n");
+ break;
+ }
+
+ int offset = block->getAlignment();
+ void* content = block->getContent();
+ const char* type = block->_isTempMemBlock() ? " temp" : "alloc";
+ JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", type, content, block->getSize(),
+ block->getGroupId(), offset, block->getPrevBlock(), block->getNextBlock());
+ usedBytes += sizeof(CMemBlock) + block->size + block->getAlignment();
+ usedCount++;
+ }
+
+ float percent = ((float)usedBytes / (float)mSize) * 100.0f;
+ JUTReportConsole_f("%d / %d bytes (%6.2f%%) used (U:%d F:%d)\n", usedBytes, mSize, percent,
+ usedCount, freeCount);
+ unlock();
+ return result;
}
/* 802B2F5C-802B2F7C .text dump_sort__10JKRExpHeapFv */
-void JKRExpHeap::dump_sort() {
- /* Nonmatching */
+bool JKRExpHeap::dump_sort() {
+ return dump_sort_by_address();
}
/* 802B2F7C-802B2F9C .text initiate__Q210JKRExpHeap9CMemBlockFPQ210JKRExpHeap9CMemBlockPQ210JKRExpHeap9CMemBlockUlUcUc */
-void JKRExpHeap::CMemBlock::initiate(JKRExpHeap::CMemBlock*, JKRExpHeap::CMemBlock*, unsigned long, unsigned char, unsigned char) {
- /* Nonmatching */
+void JKRExpHeap::CMemBlock::initiate(CMemBlock* prev, CMemBlock* next, u32 size, u8 groupId, u8 alignment) {
+ mMagic = 'HM';
+ mFlags = alignment;
+ mGroupId = groupId;
+ this->size = size;
+ mPrev = prev;
+ mNext = next;
}
/* 802B2F9C-802B2FE0 .text allocFore__Q210JKRExpHeap9CMemBlockFUlUcUcUcUc */
-void JKRExpHeap::CMemBlock::allocFore(unsigned long, unsigned char, unsigned char, unsigned char, unsigned char) {
- /* Nonmatching */
+JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocFore(u32 size, u8 groupId1, u8 alignment1, u8 groupId2, u8 alignment2) {
+ CMemBlock* block = NULL;
+ mGroupId = groupId1;
+ mFlags = alignment1;
+ if (getSize() >= size + sizeof(CMemBlock)) {
+ block = (CMemBlock*)(size + (u32)this);
+ block[1].mGroupId = groupId2;
+ block[1].mFlags = alignment2;
+ block[1].size = this->size - (size + sizeof(CMemBlock));
+ this->size = size;
+ block = block + 1;
+ }
+ return block;
}
/* 802B2FE0-802B3038 .text allocBack__Q210JKRExpHeap9CMemBlockFUlUcUcUcUc */
-void JKRExpHeap::CMemBlock::allocBack(unsigned long, unsigned char, unsigned char, unsigned char, unsigned char) {
- /* Nonmatching */
+JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocBack(u32 size, u8 groupId1, u8 alignment1, u8 groupId2, u8 alignment2) {
+ CMemBlock* newblock = NULL;
+ if (getSize() >= size + sizeof(CMemBlock)) {
+ newblock = (CMemBlock*)((u32)this + getSize() - size);
+ newblock->mGroupId = groupId2;
+ newblock->mFlags = alignment2 | 0x80;
+ newblock->size = size;
+ mGroupId = groupId1;
+ mFlags = alignment1;
+ this->size -= size + sizeof(CMemBlock);
+ } else {
+ mGroupId = groupId2;
+ mFlags = 0x80;
+ }
+ return newblock;
}
/* 802B3038-802B3088 .text free__Q210JKRExpHeap9CMemBlockFP10JKRExpHeap */
-void JKRExpHeap::CMemBlock::free(JKRExpHeap*) {
- /* Nonmatching */
+int JKRExpHeap::CMemBlock::free(JKRExpHeap* heap) {
+ heap->removeUsedBlock(this);
+ heap->recycleFreeBlock(this);
+ return 0;
}
/* 802B3088-802B30A4 .text getHeapBlock__Q210JKRExpHeap9CMemBlockFPv */
-void JKRExpHeap::CMemBlock::getHeapBlock(void*) {
- /* Nonmatching */
+JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::getHeapBlock(void* ptr) {
+ if (ptr) {
+ CMemBlock* block = (CMemBlock*)ptr - 1;
+ if (block->isValid()) {
+ return block;
+ }
+ }
+ return NULL;
+}
+
+static void dummy2() {
+ OSReport("+---------------JKRExpHeap\n");
+ OSReport("| Align Group size ( prev , next )\n");
+ OSReport("| ---- FreeFirst\n");
+ OSReport("| %08x ");
+ OSReport("%2x %3d %6x (%08x %08x)\n");
+ OSReport("| ---- FreeLast\n");
+ OSReport("| ---- UsedFirst\n");
+ OSReport("| ---- UsedLast\n");
+ OSReport("+---------------End\n");
}
/* 802B30A4-802B31D4 .text state_register__10JKRExpHeapCFPQ27JKRHeap6TStateUl */
-void JKRExpHeap::state_register(JKRHeap::TState*, unsigned long) const {
- /* Nonmatching */
+void JKRExpHeap::state_register(TState* p, u32 param_1) const {
+ JUT_ASSERT(2423, p != 0);
+ JUT_ASSERT(2424, p->getHeap() == this);
+ p->mId = param_1;
+ if (param_1 <= 0xff) {
+ p->mUsedSize = getUsedSize(param_1);
+ } else {
+ s32 freeSize = const_cast<JKRExpHeap*>(this)->getTotalFreeSize();
+ p->mUsedSize = getSize() - freeSize;
+ }
+
+ u32 checkCode = 0;
+ for (CMemBlock* block = mHeadUsedList; block; block = block->getNextBlock()) {
+ if (param_1 <= 0xff) {
+ u8 groupId = block->getGroupId();
+ if (groupId == param_1) {
+ checkCode += (u32)block * 3;
+ }
+ } else {
+ checkCode += (u32)block * 3;
+ }
+ }
+ p->mCheckCode = checkCode;
}
/* 802B31D4-802B327C .text state_compare__10JKRExpHeapCFRCQ27JKRHeap6TStateRCQ27JKRHeap6TState */
-void JKRExpHeap::state_compare(const JKRHeap::TState&, const JKRHeap::TState&) const {
- /* Nonmatching */
+bool JKRExpHeap::state_compare(const JKRHeap::TState& r1, const JKRHeap::TState& r2) const {
+ JUT_ASSERT(2471, r1.getHeap() == r2.getHeap());
+ bool result = true;
+ if (r1.mCheckCode != r2.mCheckCode) {
+ result = false;
+ }
+
+ if (r1.mUsedSize != r2.mUsedSize) {
+ result = false;
+ }
+
+ return result;
}
/* 802B327C-802B3288 .text getHeapType__10JKRExpHeapFv */
-void JKRExpHeap::getHeapType() {
- /* Nonmatching */
+u32 JKRExpHeap::getHeapType() {
+ return 'EXPH';
}
/* 802B3288-802B3290 .text do_getCurrentGroupId__10JKRExpHeapFv */
-void JKRExpHeap::do_getCurrentGroupId() {
- /* Nonmatching */
+u8 JKRExpHeap::do_getCurrentGroupId() {
+ return mCurrentGroupId;
}
diff --git a/src/JSystem/JKernel/JKRFileLoader.cpp b/src/JSystem/JKernel/JKRFileLoader.cpp
index a3d027f3..397d3e3f 100644
--- a/src/JSystem/JKernel/JKRFileLoader.cpp
+++ b/src/JSystem/JKernel/JKRFileLoader.cpp
@@ -4,54 +4,157 @@
//
#include "JSystem/JKernel/JKRFileLoader.h"
-#include "dolphin/types.h"
+#include "MSL_C/string.h"
+#include "MSL_C/MSL_Common/Src/ctype.h"
+#include "global.h"
+
+JKRFileLoader* JKRFileLoader::sCurrentVolume;
+JSUList<JKRFileLoader> JKRFileLoader::sVolumeList;
/* 802B6770-802B67C8 .text __ct__13JKRFileLoaderFv */
-JKRFileLoader::JKRFileLoader() {
- /* Nonmatching */
+JKRFileLoader::JKRFileLoader() : mFileLoaderLink(this) {
+ mVolumeName = NULL;
+ mVolumeType = 0;
+ mMountCount = 0;
}
/* 802B67C8-802B6854 .text __dt__13JKRFileLoaderFv */
JKRFileLoader::~JKRFileLoader() {
- /* Nonmatching */
+ if (getCurrentVolume() == this) {
+ setCurrentVolume(NULL);
+ }
}
/* 802B6854-802B68A4 .text unmount__13JKRFileLoaderFv */
void JKRFileLoader::unmount() {
- /* Nonmatching */
+ s32 count = mMountCount;
+ if (mMountCount != 0) {
+ count--;
+ mMountCount = count;
+ if (count == 0) {
+ delete this;
+ }
+ }
}
/* 802B68A4-802B68F0 .text getGlbResource__13JKRFileLoaderFPCc */
-void JKRFileLoader::getGlbResource(const char*) {
- /* Nonmatching */
+void* JKRFileLoader::getGlbResource(const char* name) {
+ const char* name_reference[1];
+ name_reference[0] = name;
+
+ JKRFileLoader* fileLoader = findVolume(name_reference);
+ void* resource;
+ if (fileLoader == NULL) {
+ resource = NULL;
+ } else {
+ resource = fileLoader->getResource(name_reference[0]);
+ }
+
+ return resource;
}
/* 802B68F0-802B6988 .text getGlbResource__13JKRFileLoaderFPCcP13JKRFileLoader */
-void JKRFileLoader::getGlbResource(const char*, JKRFileLoader*) {
- /* Nonmatching */
+void* JKRFileLoader::getGlbResource(const char* name, JKRFileLoader* fileLoader) {
+ void* resource = NULL;
+ if (fileLoader) {
+ return fileLoader->getResource(0, name);
+ }
+
+ JSUList<JKRFileLoader>& volumeList = getVolumeList();
+ JSUListIterator<JKRFileLoader> iterator;
+ for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
+ resource = iterator->getResource(0, name);
+ if (resource)
+ break;
+ }
+ return resource;
}
/* 802B6988-802B6A20 .text removeResource__13JKRFileLoaderFPvP13JKRFileLoader */
-void JKRFileLoader::removeResource(void*, JKRFileLoader*) {
- /* Nonmatching */
+bool JKRFileLoader::removeResource(void* resource, JKRFileLoader* fileLoader) {
+ if (fileLoader) {
+ return fileLoader->removeResource(resource);
+ }
+
+ JSUList<JKRFileLoader>& volumeList = getVolumeList();
+ JSUListIterator<JKRFileLoader> iterator;
+ for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
+ if (iterator->removeResource(resource)) {
+ return true;
+ }
+ }
+
+ return false;
}
/* 802B6A20-802B6AB8 .text detachResource__13JKRFileLoaderFPvP13JKRFileLoader */
-void JKRFileLoader::detachResource(void*, JKRFileLoader*) {
- /* Nonmatching */
+bool JKRFileLoader::detachResource(void* resource, JKRFileLoader* fileLoader) {
+ if (fileLoader) {
+ return fileLoader->detachResource(resource);
+ }
+
+ JSUList<JKRFileLoader>& volumeList = getVolumeList();
+ JSUListIterator<JKRFileLoader> iterator;
+ for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
+ if (iterator->detachResource(resource)) {
+ return true;
+ }
+ }
+
+ return false;
}
/* 802B6AB8-802B6B44 .text findVolume__13JKRFileLoaderFPPCc */
-void JKRFileLoader::findVolume(const char**) {
- /* Nonmatching */
+JKRFileLoader* JKRFileLoader::findVolume(const char** volumeName) {
+ if (*volumeName[0] != '/') {
+ return getCurrentVolume();
+ }
+
+ char volumeNameBuffer[0x101];
+ *volumeName = fetchVolumeName(volumeNameBuffer, ARRAY_SIZE(volumeNameBuffer), *volumeName);
+
+ JSUList<JKRFileLoader>& volumeList = getVolumeList();
+ JSUListIterator<JKRFileLoader> iterator;
+ for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
+ if (strcmp(volumeNameBuffer, iterator->mVolumeName) == 0) {
+ return iterator.getObject();
+ }
+ }
+
+ return NULL;
}
+static char rootPath[2] = "/";
+
/* 802B6B44-802B6C20 .text fetchVolumeName__13JKRFileLoaderFPclPCc */
-void JKRFileLoader::fetchVolumeName(char*, long, const char*) {
- /* Nonmatching */
-}
+const char* JKRFileLoader::fetchVolumeName(char* buffer, long bufferSize, const char* path) {
+ if (strcmp(path, "/") == 0) {
+ strcpy(buffer, rootPath);
+ return rootPath;
+ }
+
+ path++;
+ while (*path != 0 && *path != '/') {
+ if (1 < bufferSize) {
+ int lower_char;
+ int ch = (int)*path;
+ if (ch == -1) {
+ lower_char = -1;
+ } else {
+ lower_char = __lower_map[ch & 0xFF];
+ }
+
+ *buffer = lower_char;
+ buffer++;
+ bufferSize--;
+ }
+ path++;
+ }
+
+ *buffer = '\0';
+ if (*path == '\0') {
+ path = rootPath;
+ }
-/* 802B6C64-802B6CB8 .text __dt__24JSUList<13JKRFileLoader>Fv */
-JSUList<JKRFileLoader>::~JSUList() {
- /* Nonmatching */
+ return path;
}
diff --git a/src/JSystem/JKernel/JKRThread.cpp b/src/JSystem/JKernel/JKRThread.cpp
index cf539ab9..a8465bec 100644
--- a/src/JSystem/JKernel/JKRThread.cpp
+++ b/src/JSystem/JKernel/JKRThread.cpp
@@ -4,54 +4,135 @@
//
#include "JSystem/JKernel/JKRThread.h"
+#include "JSystem/JUtility/JUTAssert.h"
#include "dolphin/types.h"
+JSUList<JKRThread> JKRThread::sThreadList;
+JKRThreadSwitch* JKRThreadSwitch::sManager;
+OSThread* preEnd;
+JKRThreadSwitch_PreCallback JKRThreadSwitch::mUserPreCallback;
+JKRThreadSwitch_PostCallback JKRThreadSwitch::mUserPostCallback;
+
/* 802B3D1C-802B3E38 .text __ct__9JKRThreadFUlii */
-JKRThread::JKRThread(unsigned long, int, int) {
- /* Nonmatching */
+JKRThread::JKRThread(u32 stack_size, int message_count, int param_3) : mThreadListLink(this) {
+ mHeap = JKRHeap::findFromRoot(this);
+ if (mHeap == NULL) {
+ mHeap = JKRGetSystemHeap();
+ }
+
+ mStackSize = stack_size & 0xffffffe0;
+ mStackMemory = JKRAllocFromHeap(mHeap, mStackSize, 0x20);
+ mThreadRecord = (OSThread*)JKRAllocFromHeap(mHeap, sizeof(OSThread), 0x20);
+
+ void* stackBase = (void*)((int)mStackMemory + mStackSize);
+ OSCreateThread(mThreadRecord, start, this, stackBase, mStackSize, param_3, 1);
+
+ mMessageCount = message_count;
+ mMessages = (OSMessage*)JKRAllocFromHeap(mHeap, mMessageCount * sizeof(OSMessage), 0);
+
+ OSInitMessageQueue(&mMessageQueue, mMessages, mMessageCount);
+ getList().append(&mThreadListLink);
+
+ mCurrentHeap = NULL;
+ mCurrentHeapError = NULL;
}
/* 802B3E38-802B3EFC .text __ct__9JKRThreadFP8OSThreadi */
-JKRThread::JKRThread(OSThread*, int) {
- /* Nonmatching */
+JKRThread::JKRThread(OSThread* thread, int message_count) : mThreadListLink(this) {
+ mHeap = NULL;
+ mThreadRecord = thread;
+ mStackSize = (u32)thread->stack_end - (u32)thread->stack_base;
+ mStackMemory = thread->stack_base;
+
+ mMessageCount = message_count;
+ mMessages = (OSMessage*)JKRGetSystemHeap()->alloc(mMessageCount * sizeof(OSMessage), 4);
+
+ OSInitMessageQueue(&mMessageQueue, mMessages, mMessageCount);
+ getList().append(&mThreadListLink);
+
+ mCurrentHeap = NULL;
+ mCurrentHeapError = NULL;
}
/* 802B3EFC-802B3FD4 .text __dt__9JKRThreadFv */
JKRThread::~JKRThread() {
- /* Nonmatching */
+ getList().remove(&mThreadListLink);
+
+ if (mHeap) {
+ BOOL result = OSIsThreadTerminated(mThreadRecord);
+ if (result == FALSE) {
+ OSDetachThread(mThreadRecord);
+ OSCancelThread(mThreadRecord);
+ }
+ JKRFreeToHeap(mHeap, mStackMemory);
+ JKRFreeToHeap(mHeap, mThreadRecord);
+ }
+ i_JKRFree(mMessages);
}
/* 802B3FD4-802B4000 .text start__9JKRThreadFPv */
-void JKRThread::start(void*) {
- /* Nonmatching */
+void* JKRThread::start(void* param) {
+ JKRThread* thread = (JKRThread*)param;
+ return thread->run();
}
/* 802B4000-802B4050 .text __ct__15JKRThreadSwitchFP7JKRHeap */
-JKRThreadSwitch::JKRThreadSwitch(JKRHeap*) {
- /* Nonmatching */
+JKRThreadSwitch::JKRThreadSwitch(JKRHeap* param_0) {
+ mHeap = param_0;
+ OSSetSwitchThreadCallback(JKRThreadSwitch::callback);
+ mSetNextHeap = true;
}
/* 802B4050-802B40EC .text createManager__15JKRThreadSwitchFP7JKRHeap */
-void JKRThreadSwitch::createManager(JKRHeap*) {
- /* Nonmatching */
+JKRThreadSwitch* JKRThreadSwitch::createManager(JKRHeap* heap) {
+ JUT_ASSERT(184, sManager == 0);
+
+ if (!heap) {
+ heap = JKRGetCurrentHeap();
+ }
+
+ sManager = new (heap, 0) JKRThreadSwitch(heap);
+ return sManager;
}
/* 802B40EC-802B41DC .text callback__15JKRThreadSwitchFP8OSThreadP8OSThread */
-void JKRThreadSwitch::callback(OSThread*, OSThread*) {
- /* Nonmatching */
-}
+void JKRThreadSwitch::callback(OSThread* current, OSThread* next) {
+ if (mUserPreCallback) {
+ (*mUserPreCallback)(current, next);
+ }
-/* 802B41DC-802B41E4 .text run__9JKRThreadFv */
-void JKRThread::run() {
- /* Nonmatching */
-}
+ if (!current && !next) {
+ preEnd = current;
+ current = NULL;
+ }
-/* 802B41E4-802B422C .text __dt__15JKRThreadSwitchFv */
-JKRThreadSwitch::~JKRThreadSwitch() {
- /* Nonmatching */
-}
+ if (!current && !next) {
+ current = preEnd;
+ preEnd = NULL;
+ }
-/* 802B4270-802B42C4 .text __dt__19JSUList<9JKRThread>Fv */
-JSUList<JKRThread>::~JSUList() {
- /* Nonmatching */
+ JSUList<JKRThread>& threadList = JKRThread::getList();
+ JSUListIterator<JKRThread> iterator;
+ for (iterator = threadList.getFirst(); iterator != threadList.getEnd(); ++iterator) {
+ JKRThread* thread = iterator.getObject();
+
+ if (thread->getThreadRecord() == current) {
+ thread->setCurrentHeap(JKRHeap::getCurrentHeap());
+ }
+
+ if (thread->getThreadRecord() == next) {
+ if (sManager->mSetNextHeap) {
+ thread->getCurrentHeap()->becomeCurrentHeap();
+ }
+ }
+ }
+
+ if (mUserPostCallback) {
+ (*mUserPostCallback)(current, next);
+ }
}
+
+static void dummy() {
+ OSReport("Cannot create JKRTask Manager.");
+ OSReport("sManager != 0");
+} \ No newline at end of file
diff --git a/src/d/actor/d_a_mgameboard.cpp b/src/d/actor/d_a_mgameboard.cpp
index 5c61997f..42f1c0a4 100644
--- a/src/d/actor/d_a_mgameboard.cpp
+++ b/src/d/actor/d_a_mgameboard.cpp
@@ -3,7 +3,7 @@
// Translation Unit: d_a_mgameboard.cpp
//
-#include "d_a_mgameboard.h"
+#include "d/actor/d_a_mgameboard.h"
#include "dolphin/types.h"
/* 000000EC-0000010C .text CheckCreateHeap__FP10fopAc_ac_c */
diff --git a/src/d/actor/d_a_obj_Ygush00.cpp b/src/d/actor/d_a_obj_Ygush00.cpp
index de58d71f..f7359fe7 100644
--- a/src/d/actor/d_a_obj_Ygush00.cpp
+++ b/src/d/actor/d_a_obj_Ygush00.cpp
@@ -128,7 +128,7 @@ bool daObjYgush00_c::_execute() {
fopAcM_seStartCurrent(this, 0x61fe, 0);
}
} else {
- mpGryw00 = (daObjGryw00_c*)i_fopAcM_SearchByName(PROC_Obj_Gryw00);
+ mpGryw00 = (daObjGryw00_c*)fopAcM_SearchByName(PROC_Obj_Gryw00);
}
} else {
fopAcM_seStartCurrent(this, 0x61fe, 0);
diff --git a/src/d/actor/d_a_obj_movebox.cpp b/src/d/actor/d_a_obj_movebox.cpp
index 9c2a226f..4f64281d 100644
--- a/src/d/actor/d_a_obj_movebox.cpp
+++ b/src/d/actor/d_a_obj_movebox.cpp
@@ -127,12 +127,12 @@ namespace daObjMovebox {
s32 prm_get_buoy() const { return daObj::PrmAbstract(this, PRM_BUOY_W, PRM_BUOY_S); }
s32 prm_get_dmy() const; // Unused?
- BOOL is_switch1() const { return fopAcM_isSwitch(this, prm_get_swSave1()); };
- BOOL is_switch2() const { return fopAcM_isSwitch(this, prmZ_get_swSave2()); };
- void on_switch1() const { fopAcM_onSwitch(this, prm_get_swSave1()); };
- void on_switch2() const { fopAcM_onSwitch(this, prmZ_get_swSave2()); };
- void off_switch1() const { fopAcM_offSwitch(this, prm_get_swSave1()); };
- void off_switch2() const { fopAcM_offSwitch(this, prmZ_get_swSave2()); };
+ BOOL is_switch1() const { return fopAcM_isSwitch((Act_c*)this, prm_get_swSave1()); };
+ BOOL is_switch2() const { return fopAcM_isSwitch((Act_c*)this, prmZ_get_swSave2()); };
+ void on_switch1() const { fopAcM_onSwitch((Act_c*)this, prm_get_swSave1()); };
+ void on_switch2() const { fopAcM_onSwitch((Act_c*)this, prmZ_get_swSave2()); };
+ void off_switch1() const { fopAcM_offSwitch((Act_c*)this, prm_get_swSave1()); };
+ void off_switch2() const { fopAcM_offSwitch((Act_c*)this, prmZ_get_swSave2()); };
void prmZ_init();
void prmX_init();
diff --git a/src/d/d_seafightgame.cpp b/src/d/d_seafightgame.cpp
index 6ce5faf5..a3127abf 100644
--- a/src/d/d_seafightgame.cpp
+++ b/src/d/d_seafightgame.cpp
@@ -3,26 +3,126 @@
// Translation Unit: d_seafightgame.cpp
//
-#include "d_seafightgame.h"
-#include "dolphin/types.h"
+#include "d/d_seafightgame.h"
+#include "SSystem/SComponent/c_math.h"
/* 800C1F90-800C20B0 .text init__20dSeaFightGame_info_cFii */
-void dSeaFightGame_info_c::init(int, int) {
- /* Nonmatching */
+int dSeaFightGame_info_c::init(int i_bulletNum, int i_scenario) {
+ for (int i = 0; i < 8; i++) {
+ for (int j = 0; j < 8; j++) {
+ mGrid[i][j] = 0;
+ }
+ }
+
+ mBulletNum = i_bulletNum;
+ mScore = 0;
+
+ switch (i_scenario) {
+ case 1:
+ mAliveShipNum = 1;
+ put_ship(0, 2);
+ break;
+ case 2:
+ mAliveShipNum = 2;
+ put_ship(0, 2);
+ put_ship(1, 3);
+ break;
+ case 3:
+ mAliveShipNum = 3;
+ put_ship(0, 2);
+ put_ship(1, 3);
+ put_ship(2, 4);
+ break;
+ }
+
+ mDeadShipNum = 0;
+ return 1;
}
/* 800C20B0-800C225C .text put_ship__20dSeaFightGame_info_cFUcUc */
-void dSeaFightGame_info_c::put_ship(unsigned char, unsigned char) {
- /* Nonmatching */
+int dSeaFightGame_info_c::put_ship(u8 i_shipNo, u8 i_shipSize) {
+ u8 y;
+ u8 x;
+ u8 direction;
+
+ do {
+ direction = (s16)cM_rndF(1000.0f) % 2;
+ y = (int)cM_rndF(8.0f);
+ x = (int)cM_rndF(8.0f);
+ } while (!checkPutShip(y, x, i_shipSize, direction));
+
+ if (direction == 0) {
+ for (int i = 0; i < i_shipSize; i++) {
+ mShips[i_shipNo].m_pos[i][0] = y;
+ mShips[i_shipNo].m_pos[i][1] = x + i;
+ mGrid[y][x + i] = i_shipNo + 102;
+ }
+
+ mShips[i_shipNo].field_0xb = y;
+ mShips[i_shipNo].field_0xc = x;
+ mShips[i_shipNo].field_0xd = 0;
+ mShips[i_shipNo].field_0xe = i_shipSize;
+ } else {
+ for (int i = 0; i < i_shipSize; i++) {
+ mShips[i_shipNo].m_pos[i][0] = y + i;
+ mShips[i_shipNo].m_pos[i][1] = x;
+ mGrid[y + i][x] = i_shipNo + 102;
+ }
+
+ mShips[i_shipNo].field_0xb = y;
+ mShips[i_shipNo].field_0xc = x;
+ mShips[i_shipNo].field_0xd = i_shipSize;
+ mShips[i_shipNo].field_0xe = 0;
+ }
+
+ mShips[i_shipNo].field_0x8 = i_shipSize;
+ mShips[i_shipNo].field_0x9 = i_shipSize;
+ return 1;
}
/* 800C225C-800C22FC .text checkPutShip__20dSeaFightGame_info_cFiiii */
-void dSeaFightGame_info_c::checkPutShip(int, int, int, int) {
- /* Nonmatching */
+bool dSeaFightGame_info_c::checkPutShip(int i_y, int i_x, int i_shipSize, int i_direction) {
+ if (i_direction == 0) {
+ for (int i = 0; i < i_shipSize; i++) {
+ if (i_y > 7 || i_x > 7 || mGrid[i_y][i_x] > 100) {
+ return false;
+ }
+ i_x++;
+ }
+ } else {
+ for (int i = 0; i < i_shipSize; i++) {
+ if (i_y > 7 || i_x > 7 || mGrid[i_y][i_x] > 100) {
+ return false;
+ }
+ i_y++;
+ }
+ }
+
+ return true;
}
/* 800C22FC-800C239C .text attack__20dSeaFightGame_info_cFUcUc */
-void dSeaFightGame_info_c::attack(unsigned char, unsigned char) {
- /* Nonmatching */
-}
+int dSeaFightGame_info_c::attack(u8 i_y, u8 i_x) {
+ int rt = -1;
+
+ u8 uvar1 = mGrid[i_y][i_x];
+ if (uvar1 == 0) {
+ mGrid[i_y][i_x] = 1;
+ } else if (uvar1 > 100) {
+ rt = uvar1 - 102;
+ mShips[rt].field_0x9--;
+ if (mShips[rt].field_0x9 == 0) {
+ mAliveShipNum--;
+ mDeadShipNum++;
+ }
+
+ mGrid[i_y][i_x] = 3;
+ } else {
+ return -2;
+ }
+
+ mBulletNum--;
+ mScore++;
+ return rt;
+}
diff --git a/src/m_Do/m_Do_DVDError.cpp b/src/m_Do/m_Do_DVDError.cpp
index 325eead4..204bb8e8 100644
--- a/src/m_Do/m_Do_DVDError.cpp
+++ b/src/m_Do/m_Do_DVDError.cpp
@@ -4,24 +4,64 @@
//
#include "m_Do/m_Do_DVDError.h"
-#include "dolphin/types.h"
+#include "JSystem/JKernel/JKRThread.h"
+#include "dolphin/os/OS.h"
+#include "m_Do/m_Do_dvd_thread.h"
+#include "m_Do/m_Do_ext.h"
+
+OSThread DvdErr_thread;
+u8 DvdErr_stack[0x1000] __attribute__((aligned(16)));
+
+static OSAlarm Alarm;
+bool mDoDvdErr_initialized;
+
+void mDoDvdErr_Watch(void*);
+void AlarmHandler(OSAlarm*, OSContext*);
/* 80018BE0-80018CA0 .text mDoDvdErr_ThdInit__Fv */
void mDoDvdErr_ThdInit() {
- /* Nonmatching */
+ if (!mDoDvdErr_initialized) {
+ OSTime time = OSGetTime();
+ OSThread* curThread = OSGetCurrentThread();
+ s32 priority = OSGetThreadPriority(curThread);
+
+ OSCreateThread(&DvdErr_thread, mDoDvdErr_Watch, NULL, DvdErr_stack + sizeof(DvdErr_stack),
+ sizeof(DvdErr_stack), priority - 3, 1);
+ OSResumeThread(&DvdErr_thread);
+ OSCreateAlarm(&Alarm);
+ OSSetPeriodicAlarm(&Alarm, time, OS_BUS_CLOCK / 4, AlarmHandler);
+
+ mDoDvdErr_initialized = true;
+ }
}
/* 80018CA0-80018CE8 .text mDoDvdErr_ThdCleanup__Fv */
void mDoDvdErr_ThdCleanup() {
- /* Nonmatching */
+ if (mDoDvdErr_initialized) {
+ OSCancelThread(&DvdErr_thread);
+ OSCancelAlarm(&Alarm);
+ mDoDvdErr_initialized = false;
+ }
}
/* 80018CE8-80018D44 .text mDoDvdErr_Watch__FPv */
void mDoDvdErr_Watch(void*) {
- /* Nonmatching */
+ {
+ JKRThread thread(OSGetCurrentThread(), 0);
+ }
+
+ JKRHeap* heap = NULL;
+ heap->becomeCurrentHeap();
+
+ do {
+ if (DVDGetDriveStatus() == DVD_STATE_FATAL_ERROR) {
+ mDoDvdThd::suspend();
+ }
+ OSSuspendThread(&DvdErr_thread);
+ } while (true);
}
/* 80018D44-80018D6C .text AlarmHandler__FP7OSAlarmP9OSContext */
void AlarmHandler(OSAlarm*, OSContext*) {
- /* Nonmatching */
+ OSResumeThread(&DvdErr_thread);
}
diff --git a/src/m_Do/m_Do_Reset.cpp b/src/m_Do/m_Do_Reset.cpp
index fb4de5b1..65be5c53 100644
--- a/src/m_Do/m_Do_Reset.cpp
+++ b/src/m_Do/m_Do_Reset.cpp
@@ -1,32 +1,102 @@
-//
-// Generated by dtk
-// Translation Unit: m_Do_Reset.cpp
-//
+/**
+ * m_Do_Reset.cpp
+ * Game Reset Management
+ */
#include "m_Do/m_Do_Reset.h"
-#include "dolphin/types.h"
+#include "JSystem/JUtility/JUTGamePad.h"
+#include "JSystem/JUtility/JUTXfb.h"
+#include "dolphin/gx/GX.h"
+#include "dolphin/os/OS.h"
+#include "m_Do/m_Do_DVDError.h"
+#include "m_Do/m_Do_audio.h"
/* 80017D40-80017D44 .text my_OSCancelAlarmAll__Fv */
-void my_OSCancelAlarmAll() {
- /* Nonmatching */
-}
+static void my_OSCancelAlarmAll() {}
/* 80017D44-80017D7C .text destroyVideo__Fv */
void destroyVideo() {
- /* Nonmatching */
+ JUTVideo::destroyManager();
+ GXSetDrawDoneCallback(NULL);
+ VISetBlack(1);
+ VIFlush();
+ VIWaitForRetrace();
}
+#if VERSION == VERSION_JP
+int mDoRst::mResetFlag;
+int mDoRst::mResetPrepare;
+int mDoRst::m3ButtonResetFlag;
+int mDoRst::m3ButtonResetPort = -1;
+#else
+mDoRstData* mDoRst::mResetData;
+#endif
+
/* 80017D7C-80017E40 .text mDoRst_reset__FiUli */
-void mDoRst_reset(int, unsigned long, int) {
- /* Nonmatching */
-}
+void mDoRst_reset(int param_0, unsigned long param_1, int param_2) {
+ if (DVDGetDriveStatus() == DVD_STATE_FATAL_ERROR) {
+ do {
+ } while (true);
+ }
-/* 80017E40-80017EF0 .text mDoRst_resetCallBack__FiPv */
-void mDoRst_resetCallBack(int, void*) {
- /* Nonmatching */
+ JUTXfb::getManager()->clearIndex();
+ mDoDvdErr_ThdCleanup();
+ JUTGamePad::clearForReset();
+ mDoAud_zelAudio_c::offInitFlag();
+
+#if VERSION != VERSION_JP
+ VIWaitForRetrace();
+ VIWaitForRetrace();
+#endif
+
+ OSThread* gxThread = GXGetCurrentGXThread();
+ s32 enable = OSDisableInterrupts();
+
+ if (gxThread != OSGetCurrentThread()) {
+ OSCancelThread(gxThread);
+ GXSetCurrentGXThread();
+ }
+
+ GXFlush();
+ GXAbortFrame();
+ GXDrawDone();
+ OSRestoreInterrupts(enable);
+ destroyVideo();
+ my_OSCancelAlarmAll();
+ LCDisable();
+#if VERSION != VERSION_JP
+ OSSetSaveRegion(mDoRst::mResetData, (u8*)&mDoRst::getResetData + 0x10);
+#endif
+ OSResetSystem(param_0, param_1, param_2);
+
+ do {
+ VIWaitForRetrace();
+ } while (true);
}
-/* 80017EF0-80017EF8 .text getResetData__6mDoRstFv */
-void mDoRst::getResetData() {
- /* Nonmatching */
+/* 80017E40-80017EF0 .text mDoRst_resetCallBack__FiPv */
+void mDoRst_resetCallBack(int port, void*) {
+ if (!mDoRst::isReset()) {
+ if (port == -1) {
+ JUTGamePad::clearForReset();
+ JUTGamePad::CRumble::setEnabled(0xF0000000);
+ } else {
+ if (mDoRst::is3ButtonReset()) {
+ JUTGamePad::C3ButtonReset::sResetOccurred = false;
+ JUTGamePad::C3ButtonReset::sCallback = mDoRst_resetCallBack;
+ JUTGamePad::C3ButtonReset::sCallbackArg = NULL;
+ return;
+ }
+ mDoRst::on3ButtonReset();
+ mDoRst::set3ButtonResetPort(port);
+ JUTGamePad::clearForReset();
+ JUTGamePad::CRumble::setEnabled(0xF0000000);
+ }
+#if VERSION != VERSION_JP
+ if (DVDCheckDisk() == 0) {
+ mDoRst_reset(1, 0x80000000, 0);
+ }
+#endif
+ mDoRst::onReset();
+ }
}
diff --git a/src/m_Do/m_Do_machine_exception.cpp b/src/m_Do/m_Do_machine_exception.cpp
index 906f76d6..ebeb36b0 100644
--- a/src/m_Do/m_Do_machine_exception.cpp
+++ b/src/m_Do/m_Do_machine_exception.cpp
@@ -1,42 +1,104 @@
-//
-// Generated by dtk
-// Translation Unit: m_Do_machine_exception.cpp
-//
+/**
+ * m_Do_machine_exception.cpp
+ * Exception Print Functions
+ */
#include "m_Do/m_Do_machine_exception.h"
-#include "dolphin/types.h"
+#include "DynamicLink.h"
+#include "JSystem/JFramework/JFWSystem.h"
+#include "JSystem/JKernel/JKRAram.h"
+#include "JSystem/JUtility/JUTConsole.h"
+#include "d/d_com_inf_game.h"
+#include "m_Do/m_Do_ext.h"
+#include "m_Do/m_Do_main.h"
+
+static JUTConsole* sConsole;
/* 8001BADC-8001BB68 .text print_f__FPCce */
-void print_f(const char*, ...) {
- /* Nonmatching */
+void print_f(const char* fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ JUTConsole_print_f_va_(sConsole, fmt, args);
+ va_end(args);
}
/* 8001BB68-8001BB90 .text print__FPCc */
-void print(const char*) {
- /* Nonmatching */
+void print(const char* string) {
+ sConsole->print(string);
}
+static const char* unused_803396f8 = "--------------------------------------\n";
+
/* 8001BB90-8001BCEC .text dispHeapInfo__Fv */
void dispHeapInfo() {
- /* Nonmatching */
+ JKRExpHeap* zelda = zeldaHeap;
+ JKRExpHeap* game = gameHeap;
+ JKRExpHeap* archive = archiveHeap;
+
+ u32 zeldaFree = zelda->getFreeSize();
+ u32 gameFree = game->getFreeSize();
+ u32 archiveFree = archive->getFreeSize();
+ u32 zeldaTotal = zelda->getTotalFreeSize();
+ u32 gameTotal = game->getTotalFreeSize();
+ u32 archiveTotal = archive->getTotalFreeSize();
+
+ print("-- Heap Free / TotalFree (KB) --\n");
+ print_f(" Zelda %5d / %5d\n", zeldaFree / 1024, zeldaTotal / 1024);
+ print_f(" Game %5d / %5d\n", gameFree / 1024, gameTotal / 1024);
+ print_f("Archive %5d / %5d\n", archiveFree / 1024, archiveTotal / 1024);
+ print("--------------------------------\n");
+
+ if (JKRAram::getAramHeap()) {
+ JKRAram::getAramHeap()->dump();
+ }
+ DynamicModuleControlBase::dump();
+ g_dComIfG_gameInfo.mResControl.dump();
+
+ zelda->dump_sort();
+ game->dump_sort();
+ archive->dump_sort();
}
/* 8001BCEC-8001BD30 .text dispGameInfo__Fv */
void dispGameInfo() {
- /* Nonmatching */
+ print_f("Start StageName:RoomNo [%s:%d]\n", dComIfGp_getStartStageName(),
+ dComIfGp_getStartStageRoomNo());
}
/* 8001BD30-8001BE84 .text dispDateInfo__Fv */
void dispDateInfo() {
- /* Nonmatching */
+ print("------------- Date Infomation ---------\n");
+ print(" FINAL VERSION\n");
+ print("COMPILE USER: FINAL\n");
+ print_f("COPYDATE : %17s\n", mDoMain::COPYDATE_STRING);
+
+ OSCalendarTime time;
+ OSTicksToCalendarTime(mDoMain::sPowerOnTime, &time);
+ print_f("PowerOnTime: %04d/%2d/%2d %2d:%2d:%2d`%03d\"%03d\n", time.year, time.month,
+ time.day_of_month, time.hours, time.minutes, time.seconds, time.milliseconds,
+ time.microseconds);
+
+ OSTicksToCalendarTime(mDoMain::sHungUpTime, &time);
+ print_f("HungUpTime : %04d/%2d/%2d %2d:%2d:%2d`%03d\"%03d\n", time.year, time.month,
+ time.day_of_month, time.hours, time.minutes, time.seconds, time.milliseconds,
+ time.microseconds);
+
+ OSTicksToCalendarTime(mDoMain::sHungUpTime - mDoMain::sPowerOnTime, &time);
+ print_f("PlayTime : %4d days, %2d:%2d:%2d`%03d\"%03d\n", time.year_day, time.hours,
+ time.minutes, time.seconds, time.milliseconds, time.microseconds);
+ print("---------------------------------------\n");
}
/* 8001BE84-8001BEAC .text dispConsoleToTerminal__Fv */
void dispConsoleToTerminal() {
- /* Nonmatching */
+ JFWSystem::getSystemConsole()->dumpToTerminal(0xFFFFFFFF);
}
/* 8001BEAC-8001BEDC .text exception_addition__FP10JUTConsole */
-void exception_addition(JUTConsole*) {
- /* Nonmatching */
+void exception_addition(JUTConsole* pConsole) {
+ sConsole = pConsole;
+ dispHeapInfo();
+ dispDateInfo();
+ dispConsoleToTerminal();
+ dispGameInfo();
}