Reorganize library code into libs/ (#3119)

* Reorganize files into libs/{dolphin,JSystem,PowerPC_EABI_Support,revolution,TRK_MINNOW_DOLPHIN}

* Update configure.py and project.py for new libs structure

* Refactor `#include <dolphin/x.h>` -> `<x.h>`

* Remove `__REVOLUTION_SDK__` forwards from dolphin

* Fix dolphin/ references in revolution

* Wrap `#include <dolphin.h>` in `!__REVOLUTION_SDK__`

* Always build TRK against dolphin headers

* Resolve revolution SDK header resolution issues
This commit is contained in:
Luke Street
2026-03-01 15:35:36 -07:00
committed by GitHub
parent c9a46bd65b
commit 4df8ccc871
1740 changed files with 583 additions and 825 deletions
@@ -0,0 +1,105 @@
#ifndef JKRARAM_H
#define JKRARAM_H
#include "JSystem/JKernel/JKRAramHeap.h"
#include "JSystem/JKernel/JKRDvdRipper.h"
#include "JSystem/JKernel/JKRThread.h"
class JKRHeap;
class JKRAMCommand;
class JKRAramBlock;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRAram : public JKRThread {
private:
JKRAram(u32, u32, s32);
virtual ~JKRAram();
/* vt[03] */ void* run(void); /* override */
public:
u32 getAudioMemory() const { return mAudioMemoryPtr; }
u32 getAudioMemSize() const { return mAudioMemorySize; }
u32 getGraphMemory() const { return mGraphMemoryPtr; }
u32 getGraphMemSize() const { return mGraphMemorySize; }
//private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRThread
/* 0x7C */ u32 mAudioMemoryPtr;
/* 0x80 */ u32 mAudioMemorySize;
/* 0x84 */ u32 mGraphMemoryPtr;
/* 0x88 */ u32 mGraphMemorySize;
/* 0x8C */ u32 mAramMemoryPtr;
/* 0x90 */ u32 mAramMemorySize;
/* 0x94 */ JKRAramHeap* mAramHeap;
/* 0x98 */ u32 mStackArray[3];
public:
static JKRAram* create(u32, u32, s32, s32, s32);
static void checkOkAddress(u8*, u32, JKRAramBlock*, u32);
static void changeGroupIdIfNeed(u8*, int);
static JKRAramBlock* mainRamToAram(u8*, u32, u32, JKRExpandSwitch, u32, JKRHeap*, int, u32*);
static u8* aramToMainRam(u32, u8*, u32, JKRExpandSwitch, u32, JKRHeap*, int, u32*);
static void dump(void);
static JKRAram* getManager() { return sAramObject; }
static JKRAramHeap* getAramHeap() { return sAramObject->mAramHeap; }
static JSUList<JKRAMCommand>& getCommandList() { return sAramCommandList; }
static u8 decideAramGroupId(int groupId) {
u8 finalGroupId;
if (groupId < 0) {
finalGroupId = getAramHeap()->getCurrentGroupID();
} else {
finalGroupId = groupId;
}
return finalGroupId;
}
static u32 getSZSBufferSize() { return sSZSBufferSize; }
static void setSZSBufferSize(u32 size) { sSZSBufferSize = size; }
static OSMessageQueue sMessageQueue;
private:
static JKRAram* sAramObject;
static u32 sSZSBufferSize;
static OSMessage sMessageBuffer[4];
static JSUList<JKRAMCommand> sAramCommandList;
};
inline JKRAramBlock* JKRAllocFromAram(u32 size, JKRAramHeap::EAllocMode allocMode) {
return JKRAram::getAramHeap()->alloc(size, allocMode);
}
inline void JKRFreeToAram(JKRAramBlock* block) {
JKRAram::getAramHeap()->free(block);
}
inline u8* JKRAramToMainRam(u32 p1, u8* p2, u32 p3, JKRExpandSwitch p4, u32 p5, JKRHeap* p6,
int p7, u32* p8) {
return JKRAram::aramToMainRam(p1, p2, p3, p4, p5, p6, p7, p8);
}
inline JKRAramBlock* JKRMainRamToAram(u8 *buf, u32 bufSize, u32 alignedSize, JKRExpandSwitch expandSwitch, u32 fileSize, JKRHeap *heap, int id, u32 *pSize) {
return JKRAram::mainRamToAram(buf, bufSize, alignedSize, expandSwitch, fileSize, heap, id, pSize);
}
inline u32 JKRGetAramTotalFreeSize() {
return JKRAram::getAramHeap()->getTotalFreeSize();
}
inline u32 JKRGetAramFreeSize() {
return JKRAram::getAramHeap()->getFreeSize();
}
inline u32 JKRGetAramUsedSize(u8 param_0) {
return JKRAram::getAramHeap()->getUsedSize(param_0);
}
// void JKRDecompressFromAramToMainRam(u32, void*, u32, u32, u32, u32*);
#endif /* JKRARAM_H */
@@ -0,0 +1,39 @@
#ifndef JKRARAMARCHIVE_H
#define JKRARAMARCHIVE_H
#include "JSystem/JKernel/JKRArchive.h"
class JKRAramBlock;
class JKRFile;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRAramArchive : public JKRArchive {
public:
JKRAramArchive();
JKRAramArchive(s32, JKRArchive::EMountDirection);
virtual ~JKRAramArchive();
void fixedInit(s32, JKRArchive::EMountDirection);
BOOL mountFixed(s32, JKRArchive::EMountDirection);
bool open(s32);
u32 getAramAddress_Entry(SDIFileEntry*);
u32 getAramAddress(char const*);
/* vt[15] */ u32 getExpandedResSize(const void*) const; /* override */
/* vt[16] */ void* fetchResource(SDIFileEntry*, u32*); /* override */
/* vt[17] */ void* fetchResource(void*, u32, SDIFileEntry*, u32*); /* override */
public:
static u32 fetchResource_subroutine(u32, u32, u8*, u32, int);
static u32 fetchResource_subroutine(u32, u32, JKRHeap*, int, u8**);
/* 0x00 */ // vtable
/* 0x04 */ // JKRArchive
/* 0x64 */ JKRAramBlock* mBlock;
/* 0x68 */ JKRFile* mDvdFile;
}; // Size = 0x6C
#endif /* JKRARAMARCHIVE_H */
@@ -0,0 +1,41 @@
#ifndef JKRARAMBLOCK_H
#define JKRARAMBLOCK_H
#include "JSystem/JSupport/JSUList.h"
class JKRAramHeap;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRAramBlock {
public:
JKRAramBlock(u32, u32, u32, u8, bool);
virtual ~JKRAramBlock();
JKRAramBlock* allocHead(u32, u8, JKRAramHeap*);
JKRAramBlock* allocTail(u32, u8, JKRAramHeap*);
u32 getAddress() const { return mAddress; }
u32 getSize() const { return mSize; }
u32 getFreeSize() const { return mFreeSize; }
bool isTempMemory() const { return mIsTempMemory; }
void newGroupID(u8 groupId) { mGroupId = groupId; }
public:
/* 0x00 */ // vtable
/* 0x04 */ JSULink<JKRAramBlock> mBlockLink;
/* 0x14 */ u32 mAddress;
/* 0x18 */ u32 mSize;
/* 0x1C */ u32 mFreeSize;
/* 0x20 */ u8 mGroupId;
/* 0x21 */ bool mIsTempMemory;
/* 0x22 */ u8 padding[2];
};
#endif /* JKRARAMBLOCK_H */
@@ -0,0 +1,57 @@
#ifndef JKRARAMHEAP_H
#define JKRARAMHEAP_H
#include "JSystem/JKernel/JKRAramBlock.h"
#include "JSystem/JKernel/JKRDisposer.h"
#include <os.h>
/**
* @ingroup jsystem-jkernel
*
*/
class JKRAramHeap : public JKRDisposer {
public:
enum EAllocMode {
HEAD = 0,
TAIL = 1,
};
public:
static JSUList<JKRAramBlock> sAramList;
JKRAramHeap(u32, u32);
virtual ~JKRAramHeap();
JKRAramBlock* alloc(u32, EAllocMode);
JKRAramBlock* allocFromHead(u32);
JKRAramBlock* allocFromTail(u32);
u32 getFreeSize();
u32 getTotalFreeSize();
u32 getUsedSize(u8);
void dump();
void free(JKRAramBlock *block) {
delete block;
}
u8 getCurrentGroupID() const { return mGroupId; }
JKRHeap* getMgrHeap() const { return mHeap; }
private:
void lock() { OSLockMutex(&mMutex); }
void unlock() { OSUnlockMutex(&mMutex); }
public:
/* 0x00 */ // vtable
/* 0x04 */ // JKRDisposer
/* 0x18 */ OSMutex mMutex;
/* 0x30 */ JKRHeap* mHeap;
/* 0x34 */ u32 mHeadAddress;
/* 0x38 */ u32 mTailAddress;
/* 0x3C */ u32 mSize;
/* 0x40 */ u8 mGroupId;
/* 0x41 */ u8 padding_0x41[3];
};
#endif /* JKRARAMHEAP_H */
@@ -0,0 +1,94 @@
#ifndef JKRARAMPIECE_H
#define JKRARAMPIECE_H
#include "JSystem/JSupport/JSUList.h"
#ifdef __REVOLUTION_SDK__
#include <revolution/aralt.h>
#include <revolution/os.h>
#else
#include <dolphin/ar.h>
#include <dolphin/os.h>
#endif
class JKRAramBlock;
class JKRDecompCommand;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRAMCommand {
public:
typedef void (*AsyncCallback)(u32);
JKRAMCommand();
~JKRAMCommand();
public:
/* 0x00 */ ARQRequest mRequest;
/* 0x20 */ JSULink<JKRAMCommand> mPieceLink;
/* 0x30 */ JSULink<JKRAMCommand> field_0x30;
/* 0x40 */ s32 mTransferDirection;
/* 0x44 */ u32 mDataLength;
/* 0x48 */ u32 mSrc;
/* 0x4C */ u32 mDst;
/* 0x50 */ JKRAramBlock* mAramBlock;
/* 0x54 */ u32 field_0x54;
/* 0x58 */ AsyncCallback mCallback;
/* 0x5C */ OSMessageQueue* field_0x5C;
/* 0x60 */ s32 field_0x60;
/* 0x64 */ JKRDecompCommand* mDecompCommand;
/* 0x68 */ OSMessageQueue mMessageQueue;
/* 0x88 */ OSMessage mMessage;
/* 0x8C */ void* field_0x8C;
/* 0x90 */ void* field_0x90;
/* 0x94 */ void* field_0x94;
};
struct JKRAramCommand {
s32 field_0x00;
void* command;
void setting(int param_1, void* param_2) {
field_0x00 = param_1;
command = param_2;
}
};
/**
* @ingroup jsystem-jkernel
*
*/
class JKRAramPiece {
public:
static OSMutex mMutex;
// TODO: fix type
static JSUList<JKRAMCommand> sAramPieceCommandList;
public:
static JKRAMCommand* prepareCommand(int, u32, u32, u32, JKRAramBlock*,
JKRAMCommand::AsyncCallback);
static void sendCommand(JKRAMCommand*);
static JKRAMCommand* orderAsync(int, u32, u32, u32, JKRAramBlock*, JKRAMCommand::AsyncCallback);
static BOOL sync(JKRAMCommand*, int);
static BOOL orderSync(int, u32, u32, u32, JKRAramBlock*);
static void startDMA(JKRAMCommand*);
static void doneDMA(u32);
private:
static void lock() { OSLockMutex(&mMutex); }
static void unlock() { OSUnlockMutex(&mMutex); }
};
inline void JKRAramPcs_SendCommand(JKRAMCommand* command) {
JKRAramPiece::sendCommand(command);
}
inline BOOL JKRAramPcs(int direction, u32 source, u32 destination, u32 length,
JKRAramBlock* block) {
return JKRAramPiece::orderSync(direction, source, destination, length, block);
}
#endif /* JKRARAMPIECE_H */
@@ -0,0 +1,92 @@
#ifndef JKRARAMSTREAM_H
#define JKRARAMSTREAM_H
#include "JSystem/JKernel/JKRThread.h"
class JSUFileInputStream;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRAramStreamCommand {
public:
enum Type {
UNKNOWN = 0,
READ = 1,
WRITE = 2,
};
JKRAramStreamCommand();
public:
/* 0x00 */ Type mType;
/* 0x04 */ u32 mAddress;
/* 0x08 */ u32 mSize;
/* 0x0C */ u32 field_0x0c;
/* 0x10 */ JSUFileInputStream* mStream;
/* 0x14 */ u32 mOffset;
/* 0x18 */ u32* mReturnSize;
/* 0x1C */ u8* mTransferBuffer;
/* 0x20 */ u32 mTransferBufferSize;
/* 0x24 */ JKRHeap* mHeap;
/* 0x28 */ bool mAllocatedTransferBuffer;
/* 0x29 */ u8 padding_0x29[3];
/* 0x2C */ u32 field_0x2c;
/* 0x30 */ OSMessageQueue mMessageQueue;
/* 0x50 */ OSMessage mMessage;
/* 0x54 */ u32 field_0x54;
/* 0x58 */ u32 field_0x58;
};
/**
* @ingroup jsystem-jkernel
*
*/
class JKRAramStream : public JKRThread {
private:
JKRAramStream(s32);
virtual ~JKRAramStream();
/* vt[03] */ void* run(void); /* override */
public:
static JKRAramStream* create(s32);
static s32 readFromAram(void);
static s32 writeToAram(JKRAramStreamCommand*);
static JKRAramStreamCommand* write_StreamToAram_Async(JSUFileInputStream*, u32, u32, u32, u32*);
static JKRAramStreamCommand* sync(JKRAramStreamCommand*, BOOL);
static void setTransBuffer(u8*, u32, JKRHeap*);
private:
static JKRAramStream* sAramStreamObject;
static OSMessage sMessageBuffer[4];
static OSMessageQueue sMessageQueue;
static u8* transBuffer;
static u32 transSize;
static JKRHeap* transHeap;
};
inline JKRAramStream* JKRCreateAramStreamManager(s32 priority) {
return JKRAramStream::create(priority);
}
inline JKRAramStreamCommand* JKRStreamToAram_Async(JSUFileInputStream *stream, u32 addr, u32 size, u32 offset, void (*callback)(u32), u32* returnSize) {
return JKRAramStream::write_StreamToAram_Async(stream, addr, size, offset, returnSize);
}
inline JKRAramStreamCommand* JKRStreamToAram_Sync(JKRAramStreamCommand* command, BOOL isNonBlocking) {
return JKRAramStream::sync(command, isNonBlocking);
}
inline void JKRSetAramTransferBuffer(u8* buffer, u32 bufferSize, JKRHeap* heap) {
JKRAramStream::setTransBuffer(buffer, bufferSize, heap);
}
inline void JKRResetAramTransferBuffer() {
JKRAramStream::setTransBuffer(NULL, 0, NULL);
}
#endif /* JKRARAMSTREAM_H */
@@ -0,0 +1,252 @@
#ifndef JKRARCHIVE_H
#define JKRARCHIVE_H
#include "JSystem/JKernel/JKRCompression.h"
#include "JSystem/JKernel/JKRFileLoader.h"
#include "global.h"
class JKRHeap;
/**
* @ingroup jsystem-jkernel
*
*/
struct SArcHeader {
/* 0x00 */ u32 signature;
/* 0x04 */ u32 file_length;
/* 0x08 */ u32 header_length;
/* 0x0C */ u32 file_data_offset;
/* 0x10 */ u32 file_data_length;
/* 0x14 */ u32 field_0x14;
/* 0x18 */ u32 field_0x18;
/* 0x1C */ u32 field_0x1c;
};
/**
* @ingroup jsystem-jkernel
*
*/
struct SArcDataInfo {
/* 0x00 */ u32 num_nodes;
/* 0x04 */ u32 node_offset;
/* 0x08 */ u32 num_file_entries;
/* 0x0C */ u32 file_entry_offset;
/* 0x10 */ u32 string_table_length;
/* 0x14 */ u32 string_table_offset;
/* 0x18 */ u16 next_free_file_id;
/* 0x1A */ bool sync_file_ids_and_indices;
/* 0x1B */ u8 field_1b[5];
};
inline u32 read_big_endian_u32(void* ptr) {
u8* uptr = (u8*)ptr;
return ((u32)uptr[0] << 0x18) | ((u32)uptr[1] << 0x10) | ((u32)uptr[2] << 8) | (u32)uptr[3];
}
inline u16 read_big_endian_u16(void* ptr) {
u8* uptr = (u8*)ptr;
return ((u16)uptr[0] << 8) | ((u16)uptr[1]);
}
extern u32 sCurrentDirID__10JKRArchive; // JKRArchive::sCurrentDirID
/**
* @ingroup jsystem-jkernel
*
*/
class JKRArchive : public JKRFileLoader {
public:
struct SDirEntry {
u8 flags;
u8 padding;
u16 id;
const char* name;
};
struct SDIDirEntry {
u32 type;
u32 name_offset;
u16 field_0x8;
u16 num_entries;
u32 first_file_index;
};
struct SDIFileEntry {
u16 file_id;
u16 name_hash;
u32 type_flags_and_name_offset;
u32 data_offset;
u32 data_size;
void* data;
u32 getNameOffset() const { return type_flags_and_name_offset & 0xFFFFFF; }
u16 getNameHash() const { return name_hash; }
u32 getFlags() const { return type_flags_and_name_offset >> 24; }
u32 getAttr() const { return getFlags(); }
u16 getFileID() const { return file_id; }
bool isDirectory() const { return (getFlags() & 0x02) != 0; }
bool isUnknownFlag1() const { return (getFlags() & 0x01) != 0; }
bool isCompressed() const { return (getFlags() & 0x04) != 0; }
// was needed for open__14JKRAramArchiveFl
u8 getCompressFlag() const { return (getFlags() & 0x04); }
bool isYAZ0Compressed() const { return (getFlags() & 0x80) != 0; }
u32 getSize() const { return data_size; }
};
enum EMountMode {
UNKNOWN_MOUNT_MODE = 0,
MOUNT_MEM = 1,
MOUNT_ARAM = 2,
MOUNT_DVD = 3,
MOUNT_COMP = 4,
};
enum EMountDirection {
UNKNOWN_MOUNT_DIRECTION = 0,
MOUNT_DIRECTION_HEAD = 1,
MOUNT_DIRECTION_TAIL = 2,
};
class CArcName {
public:
CArcName() {}
CArcName(char const* data) { this->store(data); }
CArcName(char const** data, char endChar) { *data = this->store(*data, endChar); }
void store(char const* data);
const char* store(char const* data, char endChar);
u16 getHash() const { return mHash; }
const char* getString() const { return mData; }
private:
u16 mHash;
u16 mLength;
char mData[256];
};
protected:
JKRArchive();
JKRArchive(s32, EMountMode);
public:
bool getDirEntry(SDirEntry*, u32) const;
void* getIdxResource(u32);
void* getResource(u16);
u32 readIdxResource(void*, u32, u32);
u32 readResource(void*, u32, u16);
u32 countResource(void) const;
u8 getFileAttribute(u32) const;
SDIFileEntry* findNameResource(const char*) const;
bool isSameName(CArcName&, u32, u16) const;
SDIDirEntry* findResType(u32) const;
SDIDirEntry* findDirectory(const char*, u32) const;
SDIFileEntry* findTypeResource(u32, const char*) const;
SDIFileEntry* findFsResource(const char*, u32) const;
SDIFileEntry* findIdxResource(u32) const;
SDIFileEntry* findPtrResource(const void*) const;
SDIFileEntry* findIdResource(u16) const;
public:
/* vt[04] */ virtual bool becomeCurrent(const char*); /* override */
/* vt[05] */ virtual void* getResource(const char*); /* override */
/* vt[06] */ virtual void* getResource(u32, const char*); /* override */
/* vt[07] */ virtual u32 readResource(void*, u32, const char*); /* override */
/* vt[08] */ virtual u32 readResource(void*, u32, u32, const char*); /* override */
/* vt[09] */ virtual void removeResourceAll(void); /* override */
/* vt[10] */ virtual bool removeResource(void*); /* override */
/* vt[11] */ virtual bool detachResource(void*); /* override */
/* vt[12] */ virtual u32 getResSize(const void*) const; /* override */
/* vt[13] */ virtual u32 countFile(const char*) const; /* override */
/* vt[14] */ virtual JKRFileFinder* getFirstFile(const char*) const; /* override */
/* vt[15] */ virtual u32 getExpandedResSize(const void* res) const { return getResSize(res); }
/* vt[16] */ virtual void* fetchResource(SDIFileEntry*, u32*) = 0;
/* vt[17] */ virtual void* fetchResource(void*, u32, SDIFileEntry*, u32*) = 0;
/* vt[18] */ virtual void setExpandSize(SDIFileEntry*, u32);
/* vt[19] */ virtual u32 getExpandSize(SDIFileEntry*) const;
virtual ~JKRArchive();
u32 countFile() const { return mArcInfoBlock->num_file_entries; }
s32 countDirectory() const { return mArcInfoBlock->num_nodes; }
u8 getMountMode() const { return mMountMode; }
bool isFileEntry(u32 param_0) const {
return getFileAttribute(param_0) & 1;
}
public:
/* 0x00 */ // vtable
/* 0x04 */ // JKRFileLoader
/* 0x38 */ JKRHeap* mHeap;
/* 0x3C */ u8 mMountMode;
/* 0x3D */ u8 field_0x3d[3];
/* 0x40 */ s32 mEntryNum;
/* 0x44 */ SArcDataInfo* mArcInfoBlock;
/* 0x48 */ SDIDirEntry* mNodes;
/* 0x4C */ SDIFileEntry* mFiles;
/* 0x50 */ s32* mExpandedSize;
/* 0x54 */ const char* mStringTable;
protected:
/* 0x58 */ u32 field_0x58;
/* 0x5C */ JKRCompression mCompression;
/* 0x60 */ EMountDirection mMountDirection;
public:
static JKRArchive* check_mount_already(s32, JKRHeap*);
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 JKRCompression convertAttrToCompressionType(int attr) {
#define JKRARCHIVE_ATTR_COMPRESSION 0x04
#define JKRARCHIVE_ATTR_YAZ0 0x80
if (!(attr & JKRARCHIVE_ATTR_COMPRESSION)) {
return COMPRESSION_NONE;
} else if (attr & JKRARCHIVE_ATTR_YAZ0) {
return COMPRESSION_YAZ0;
} else {
return COMPRESSION_YAY0;
}
}
static u32 getCurrentDirID() { return sCurrentDirID; }
static void setCurrentDirID(u32 dirID) { sCurrentDirID = dirID; }
protected:
static u32 sCurrentDirID;
};
inline JKRCompression JKRConvertAttrToCompressionType(int attr) {
return JKRArchive::convertAttrToCompressionType(attr);
}
inline void* JKRGetResource(u32 node, const char* path, JKRArchive* archive) {
return JKRArchive::getGlbResource(node, path, archive);
}
inline void* JKRGetTypeResource(u32 tag, const char* name, JKRArchive* arc) {
return JKRArchive::getGlbResource(tag, name, arc);
}
inline bool JKRRemoveResource(void* resource, JKRFileLoader* fileLoader) {
return JKRFileLoader::removeResource(resource, fileLoader);
}
inline JKRArchive* JKRMountArchive(void* ptr, JKRHeap* heap,
JKRArchive::EMountDirection mountDirection) {
return JKRArchive::mount(ptr, heap, mountDirection);
}
inline void JKRUnmountArchive(JKRArchive* arc) {
arc->unmount();
}
inline u32 JKRReadIdxResource(void* buffer, u32 bufsize, u32 resIdx, JKRArchive* archive) {
return archive->readIdxResource(buffer, bufsize, resIdx);
}
#endif
@@ -0,0 +1,40 @@
#ifndef JKRASSERTHEAP_H
#define JKRASSERTHEAP_H
#include "JSystem/JKernel/JKRHeap.h"
#include "JSystem/JUtility/JUTAssert.h"
/**
* @ingroup jsystem-jkernel
*
*/
class JKRAssertHeap : public JKRHeap {
protected:
JKRAssertHeap(void*, u32, JKRHeap*, bool);
virtual ~JKRAssertHeap();
public:
/* vt[04] */ virtual u32 getHeapType(void); /* override */
/* vt[05] */ virtual bool check(void); /* override */
/* vt[06] */ virtual bool dump_sort(void); /* override */
/* vt[07] */ virtual bool dump(void); /* override */
/* vt[08] */ virtual void do_destroy(void); /* override */
/* vt[19] */ virtual s32 do_changeGroupID(u8) { JUT_ASSERT(41, 0&& "illegal changeGroupID()"); return 0; }
/* vt[20] */ virtual u8 do_getCurrentGroupId(void) { return 0; }
/* vt[09] */ virtual void* do_alloc(u32, int alignment) { UNUSED(alignment); JUT_ASSERT(47, 0&& "illegal alloc"); return NULL; }
/* vt[10] */ virtual void do_free(void*) { JUT_ASSERT(51, 0&& "illegal free"); }
/* vt[11] */ virtual void do_freeAll(void) { JUT_ASSERT(53, 0&& "illegal freeAll()"); }
/* vt[12] */ virtual void do_freeTail(void) { JUT_ASSERT(55, 0&& "illegal freeTail()"); }
/* vt[13] */ virtual void do_fillFreeArea(void) {}
/* vt[14] */ virtual s32 do_resize(void*, u32) { JUT_ASSERT(61, 0&& "illegal resize"); return 0; }
/* vt[15] */ virtual s32 do_getSize(void*) { return 0; }
/* vt[16] */ virtual s32 do_getFreeSize(void) { return 0; }
/* vt[17] */ virtual void* do_getMaxFreeBlock(void) { return 0; }
/* vt[18] */ virtual s32 do_getTotalFreeSize(void) { return 0; }
public:
static JKRAssertHeap* create(JKRHeap*);
};
#endif /* JKRASSERTHEAP_H */
@@ -0,0 +1,40 @@
#ifndef JKRCOMPARCHIVE_H
#define JKRCOMPARCHIVE_H
#include "JSystem/JKernel/JKRArchive.h"
class JKRAramBlock;
class JKRDvdFile;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRCompArchive : public JKRArchive {
public:
JKRCompArchive(s32, JKRArchive::EMountDirection);
virtual ~JKRCompArchive();
bool open(s32);
/* vt[09] */ void removeResourceAll(void); /* override */
/* vt[10] */ bool removeResource(void*); /* override */
/* vt[15] */ u32 getExpandedResSize(const void*) const; /* override */
/* vt[16] */ void* fetchResource(SDIFileEntry*, u32*); /* override */
/* vt[17] */ void* fetchResource(void*, u32, SDIFileEntry*, u32*); /* override */
public:
private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRArchive
/* 0x64 */ int field_0x64;
/* 0x68 */ JKRAramBlock* mAramPart;
/* 0x6C */ int field_0x6c;
/* 0x70 */ JKRDvdFile* mDvdFile;
/* 0x74 */ u32 mSizeOfMemPart;
/* 0x78 */ u32 mSizeOfAramPart;
/* 0x7C */ int field_0x7c;
};
#endif /* JKRCOMPARCHIVE_H */
@@ -0,0 +1,10 @@
#ifndef JKRCOMPREESION_H_
#define JKRCOMPREESION_H_
typedef int JKRCompression;
const JKRCompression COMPRESSION_NONE = 0;
const JKRCompression COMPRESSION_YAY0 = 1;
const JKRCompression COMPRESSION_YAZ0 = 2;
const JKRCompression COMPRESSION_ASR = 3;
#endif
@@ -0,0 +1,89 @@
#ifndef JKRDECOMP_H
#define JKRDECOMP_H
#include "JSystem/JKernel/JKRCompression.h"
#include "JSystem/JKernel/JKRThread.h"
class JKRAMCommand;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRDecompCommand {
public:
typedef void (*AsyncCallback)(u32);
JKRDecompCommand();
~JKRDecompCommand();
public:
/* 0x00 */ u32 field_0x0;
/* 0x04 */ u8* mSrcBuffer;
/* 0x08 */ u8* mDstBuffer;
/* 0x0C */ u32 mSrcLength;
/* 0x10 */ u32 mDstLength;
/* 0x14 */ AsyncCallback mCallback;
/* 0x18 */ JKRDecompCommand* mThis;
/* 0x1C */ OSMessageQueue* field_0x1c;
/* 0x20 */ s32 field_0x20;
/* 0x24 */ JKRAMCommand* mAMCommand;
/* 0x28 */ OSMessageQueue mMessageQueue;
/* 0x48 */ OSMessage mMessage;
};
#define JKRDECOMP_SYNC_BLOCKING 0
#define JKRDECOMP_SYNC_NON_BLOCKING 1
/**
* @ingroup jsystem-jkernel
*
*/
class JKRDecomp : public JKRThread {
private:
JKRDecomp(s32);
virtual ~JKRDecomp();
/* vt[03] */ virtual void* run(); /* override */
public:
static JKRDecomp* create(s32);
static JKRDecompCommand* prepareCommand(u8*, u8*, u32, u32, JKRDecompCommand::AsyncCallback);
static void sendCommand(JKRDecompCommand*);
static bool sync(JKRDecompCommand*, int);
static JKRDecompCommand* orderAsync(u8*, u8*, u32, u32, JKRDecompCommand::AsyncCallback);
static bool orderSync(u8*, u8*, u32, u32);
static void decode(u8*, u8*, u32, u32);
static void decodeSZP(u8*, u8*, u32, u32);
static void decodeSZS(u8*, u8*, u32, u32);
static JKRCompression checkCompressed(u8*);
static JKRDecomp* sDecompObject;
static OSMessage sMessageBuffer[8];
static OSMessageQueue sMessageQueue;
};
inline void JKRDecompress(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 dstLength) {
JKRDecomp::orderSync(srcBuffer, dstBuffer, srcLength, dstLength);
}
inline JKRDecomp* JKRCreateDecompManager(s32 priority) {
return JKRDecomp::create(priority);
}
inline JKRCompression JKRCheckCompressed_noASR(u8 *pBuf) {
JKRCompression compression = JKRDecomp::checkCompressed(pBuf);
if (compression == COMPRESSION_ASR) // ternary i had before was either incorrect, or was not a ternary at all
compression = COMPRESSION_NONE;
return compression;
}
inline u32 JKRDecompExpandSize(u8* pBuf) {
return (pBuf[4] << 0x18) | (pBuf[5] << 0x10) | (pBuf[6] << 8) | pBuf[7];
}
inline void JKRDecompress_SendCommand(JKRDecompCommand* command) {
JKRDecomp::sendCommand(command);
}
#endif /* JKRDECOMP_H */
@@ -0,0 +1,24 @@
#ifndef JKRDISPOSER_H
#define JKRDISPOSER_H
#include "JSystem/JSupport/JSUList.h"
class JKRHeap;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRDisposer {
public:
JKRDisposer();
virtual ~JKRDisposer();
public:
/* 0x00 */ // vtable
/* 0x04 */ JKRHeap* mHeap;
/* 0x08 */ JSULink<JKRDisposer> mLink;
/* 0x18 */
};
#endif /* JKRDISPOSER_H */
@@ -0,0 +1,67 @@
#ifndef JKRDVDARAMRIPPER_H
#define JKRDVDARAMRIPPER_H
#include "JSystem/JKernel/JKRDvdRipper.h"
class JKRAramBlock;
class JKRAramStreamCommand;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRADCommand {
public:
JKRADCommand();
~JKRADCommand();
/* 0x00 */ JSULink<JKRADCommand> mLink;
/* 0x10 */ int field_0x10;
/* 0x14 */ int field_0x14;
/* 0x18 */ int field_0x18;
/* 0x1C */ int field_0x1c;
/* 0x20 */ int field_0x20;
/* 0x24 */ int field_0x24;
/* 0x28 */ JKRDvdFile* mDvdFile;
/* 0x2C */ u32 mAddress;
/* 0x30 */ JKRAramBlock* mBlock;
/* 0x34 */ JKRExpandSwitch mExpandSwitch;
/* 0x38 */ void (*mCallback)(u32);
/* 0x3C */ u32 field_0x3c;
/* 0x40 */ u32 field_0x40;
/* 0x44 */ u32* field_0x44;
/* 0x48 */ int field_0x48;
/* 0x4C */ u8 field_0x4c;
/* 0x50 */ JKRAramStreamCommand* mStreamCommand;
};
class JKRDvdFile;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRDvdAramRipper {
public:
static JKRAramBlock* loadToAram(s32, u32, JKRExpandSwitch, u32, u32, u32*);
static JKRAramBlock* loadToAram(JKRDvdFile*, u32, JKRExpandSwitch, u32, u32, u32*);
static JKRADCommand* loadToAram_Async(JKRDvdFile*, u32, JKRExpandSwitch, void (*)(u32), u32,
u32, u32*);
static JKRADCommand* callCommand_Async(JKRADCommand*);
static bool syncAram(JKRADCommand*, int);
static u32 getSZSBufferSize() { return sSZSBufferSize; }
static void setSZSBufferSize(u32 size) { sSZSBufferSize = size; }
static bool isErrorRetry() { return errorRetry; }
// TODO: fix type
static JSUList<JKRADCommand> sDvdAramAsyncList;
static u32 sSZSBufferSize;
static bool errorRetry;
};
inline JKRAramBlock *JKRDvdToAram(s32 entrynum, u32 p2, JKRExpandSwitch expSwitch, u32 p4, u32 p5, u32 *p6) {
return JKRDvdAramRipper::loadToAram(entrynum, p2, expSwitch, p4, p5, p6);
}
#endif /* JKRDVDARAMRIPPER_H */
@@ -0,0 +1,35 @@
#ifndef JKRDVDARCHIVE_H
#define JKRDVDARCHIVE_H
#include "JSystem/JKernel/JKRArchive.h"
class JKRDvdFile;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRDvdArchive : public JKRArchive {
public:
JKRDvdArchive(s32, JKRArchive::EMountDirection);
virtual ~JKRDvdArchive();
bool open(s32);
/* vt[15] */ virtual u32 getExpandedResSize(const void*) const; /* override */
/* vt[16] */ virtual void* fetchResource(SDIFileEntry*, u32*); /* override */
/* vt[17] */ virtual void* fetchResource(void*, u32, SDIFileEntry*, u32*); /* override */
public:
static u32 fetchResource_subroutine(s32, u32, u32, u8*, u32, JKRCompression, JKRCompression);
static u32 fetchResource_subroutine(s32, u32, u32, JKRHeap*, JKRCompression, JKRCompression,
u8**);
private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRArchive
/* 0x64 */ s32 mDataOffset;
/* 0x68 */ JKRDvdFile* mDvdFile;
};
#endif /* JKRDVDARCHIVE_H */
@@ -0,0 +1,68 @@
#ifndef JKRDVDFILE_H
#define JKRDVDFILE_H
#include "JSystem/JKernel/JKRFile.h"
#include <dvd.h>
#include <os.h>
#include <os.h>
struct OSThread;
class JKRADCommand;
class JKRAramBlock;
class JSUFileInputStream;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRDvdFile : public JKRFile {
public:
JKRDvdFile();
JKRDvdFile(const char*);
JKRDvdFile(s32);
virtual ~JKRDvdFile();
void initiate(void);
s32 sync(void);
u32 getFileID() const { return mFileInfo.startAddr; }
DVDFileInfo* getFileInfo() { return &mFileInfo; }
int getStatus() const { return DVDGetCommandBlockStatus(&mFileInfo.cb); }
public:
/* vt[03] */ virtual bool open(const char*); /* override */
/* vt[04] */ virtual void close(void); /* override */
/* vt[05] */ virtual s32 readData(void*, s32, s32); /* override */
/* vt[06] */ virtual s32 writeData(const void*, s32, s32); /* override */
/* vt[07] */ virtual s32 getFileSize(void) const; /* override */
/* vt[08] */ virtual bool open(s32);
// private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRFile
/* 0x1C */ OSMutex mMutex1;
/* 0x34 */ OSMutex mMutex2;
/* 0x4C */ JKRAramBlock* mBlock;
/* 0x50 */ OSThread* field_0x50;
/* 0x54 */ JSUFileInputStream* mFileStream;
/* 0x58 */ u32 field_0x58;
/* 0x5C */ DVDFileInfo mFileInfo;
/* 0x98 */ JKRDvdFile* mDvdFile;
/* 0x9C */ OSMessageQueue mMessageQueue1;
/* 0xBC */ OSMessage mMessage1;
/* 0xC0 */ OSMessageQueue mMessageQueue2;
/* 0xE0 */ OSMessage mMessage2;
/* 0xE4 */ JSULink<JKRDvdFile> mDvdLink;
/* 0xF4 */ OSThread* mOSThread;
public:
static void doneProcess(s32, DVDFileInfo*);
static JSUList<JKRDvdFile>& getDvdList() { return sDvdList; }
private:
static JSUList<JKRDvdFile> sDvdList;
};
#endif /* JKRDVDFILE_H */
@@ -0,0 +1,83 @@
#ifndef JKRDVDRIPPER_H
#define JKRDVDRIPPER_H
#include "JSystem/JKernel/JKRCompression.h"
#include "JSystem/JSupport/JSUList.h"
enum JKRExpandSwitch {
EXPAND_SWITCH_UNKNOWN0 = 0,
EXPAND_SWITCH_UNKNOWN1 = 1,
EXPAND_SWITCH_UNKNOWN2 = 2,
};
struct SYaz0Header {
u32 signature;
u32 length;
};
/**
* @ingroup jsystem-jkernel
*
*/
class JKRDMCommand {
JKRDMCommand();
~JKRDMCommand();
};
class JKRHeap;
class JKRDvdFile;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRDvdRipper {
public:
static JSUList<JKRDMCommand> sDvdAsyncList;
static u32 sSZSBufferSize;
static bool errorRetry;
enum EAllocDirection {
UNKNOWN_EALLOC_DIRECTION = 0,
ALLOC_DIRECTION_FORWARD = 1,
ALLOC_DIRECTION_BACKWARD = 2,
};
static void setSZSBufferSize(u32 size) { sSZSBufferSize = size; }
static void* loadToMainRAM(char const*, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection,
u32, JKRCompression*, u32*);
static void* loadToMainRAM(s32, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection, u32,
JKRCompression*, u32*);
static void* loadToMainRAM(JKRDvdFile*, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection,
u32, JKRCompression*, u32*);
static bool isErrorRetry(void) { return errorRetry; }
inline static u32 getSZSBufferSize() { return sSZSBufferSize; }
};
// void JKRDecompressFromDVD(JKRDvdFile*, void*, u32, u32, u32, u32, u32*);
inline void* JKRDvdToMainRam(JKRDvdFile* file, u8* dst, JKRExpandSwitch expandSwitch, u32 dstLength,
JKRHeap* heap, JKRDvdRipper::EAllocDirection allocDirection,
u32 offset, JKRCompression* compression, u32* returnSize) {
return JKRDvdRipper::loadToMainRAM(file, dst, expandSwitch, dstLength, heap, allocDirection,
offset, compression, returnSize);
}
inline void* JKRDvdToMainRam(s32 entryNum, u8* dst, JKRExpandSwitch expandSwitch, u32 dstLength,
JKRHeap* heap, JKRDvdRipper::EAllocDirection allocDirection,
u32 offset, JKRCompression* compression, u32* returnSize) {
return JKRDvdRipper::loadToMainRAM(entryNum, dst, expandSwitch, dstLength, heap, allocDirection,
offset, compression, returnSize);
}
inline void* JKRDvdToMainRam(const char* name, u8* dst, JKRExpandSwitch expandSwitch, u32 dstLength,
JKRHeap* heap, JKRDvdRipper::EAllocDirection allocDirection,
u32 offset, JKRCompression* compression, u32* returnSize) {
return JKRDvdRipper::loadToMainRAM(name, dst, expandSwitch, dstLength, heap, allocDirection,
offset, compression, returnSize);
}
#endif /* JKRDVDRIPPER_H */
@@ -0,0 +1,126 @@
#ifndef JKREXPHEAP_H
#define JKREXPHEAP_H
#include "JSystem/JKernel/JKRHeap.h"
#include <stdint.h>
/**
* @ingroup jsystem-jkernel
*
*/
class JKRExpHeap : public JKRHeap {
public:
enum EAllocMode {
ALLOC_MODE_1 = 1,
};
class CMemBlock {
friend class JKRExpHeap;
public:
void initiate(CMemBlock* prev, CMemBlock* next, u32 size, u8 groupId, u8 alignment);
JKRExpHeap::CMemBlock* allocFore(u32 size, u8 groupId1, u8 alignment1, u8 groupId2,
u8 alignment2);
JKRExpHeap::CMemBlock* allocBack(u32 size, u8 groupId1, u8 alignment1, u8 groupId2,
u8 alignment2);
int free(JKRExpHeap* heap);
static CMemBlock* getHeapBlock(void* ptr);
void newGroupId(u8 groupId) { mGroupId = groupId; }
bool isValid() const { return mMagic == 'HM'; }
bool isTempMemBlock() const { return mFlags & 0x80; }
int getAlignment() const { return mFlags & 0x7f; }
void* getContent() const { return (void*)(this + 1); }
CMemBlock* getPrevBlock() const { return mPrev; }
CMemBlock* getNextBlock() const { return mNext; }
u32 getSize() const { return size; }
u8 getGroupId() const { return mGroupId; }
static CMemBlock* getBlock(void* data) { return (CMemBlock*)((uintptr_t)data + -0x10); }
private:
/* 0x0 */ u16 mMagic;
/* 0x2 */ u8 mFlags; // a|bbbbbbb a=temporary b=alignment
/* 0x3 */ u8 mGroupId;
/* 0x4 */ u32 size;
/* 0x8 */ CMemBlock* mPrev;
/* 0xC */ CMemBlock* mNext;
}; // Size: 0x10
friend class CMemBlock;
protected:
JKRExpHeap(void* data, u32 size, JKRHeap* parent, bool errorFlag);
virtual ~JKRExpHeap();
void* allocFromHead(u32 size, int align);
void* allocFromHead(u32 size);
void* allocFromTail(u32 size, int align);
void* allocFromTail(u32 size);
void appendUsedList(CMemBlock* newblock);
void setFreeBlock(CMemBlock* block, CMemBlock* prev, CMemBlock* next);
void removeFreeBlock(CMemBlock* block);
void removeUsedBlock(CMemBlock* block);
void recycleFreeBlock(CMemBlock* block);
void joinTwoBlocks(CMemBlock* block);
public:
BOOL isEmpty();
s32 getUsedSize(u8 groupId) const;
s32 getTotalUsedSize(void) const;
CMemBlock* getUsedFirst() { return mHeadUsedList; }
void setAllocationMode(EAllocMode mode) {
mAllocMode = mode;
}
public:
/* vt[04] */ virtual u32 getHeapType(); /* override */
/* vt[05] */ virtual bool check(); /* override */
/* vt[06] */ virtual bool dump_sort(); /* override */
/* vt[07] */ virtual bool dump(); /* override */
/* vt[08] */ virtual void do_destroy(); /* override */
/* vt[09] */ virtual void* do_alloc(u32 size, int alignment); /* override */
/* 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[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 */
/* vt[17] */ virtual void* do_getMaxFreeBlock(); /* override */
/* 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 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 */
/* 0x6C */ u8 mAllocMode;
/* 0x6D */ u8 mCurrentGroupId;
/* 0x6E */ bool field_0x6e;
private:
/* 0x70 */ void* field_0x70;
/* 0x74 */ u32 field_0x74;
/* 0x78 */ CMemBlock* mHeadFreeList;
/* 0x7C */ CMemBlock* mTailFreeList;
/* 0x80 */ CMemBlock* mHeadUsedList;
/* 0x84 */ CMemBlock* mTailUsedList;
public:
static JKRExpHeap* createRoot(int maxHeaps, bool errorFlag);
static JKRExpHeap* create(u32 size, JKRHeap* parent, bool errorFlag);
static JKRExpHeap* create(void* ptr, u32 size, JKRHeap* parent, bool errorFlag);
static s32 getUsedSize_(JKRExpHeap* heap) { return heap->mSize - heap->getTotalFreeSize(); }
static void* getState_(TState* state) { return getState_buf_(state); }
};
inline JKRExpHeap* JKRCreateExpHeap(u32 size, JKRHeap* parent, bool errorFlag) {
return JKRExpHeap::create(size, parent, errorFlag);
}
inline void JKRDestroyExpHeap(JKRExpHeap* heap) {
heap->destroy();
}
#endif /* JKREXPHEAP_H */
@@ -0,0 +1,33 @@
#ifndef JKRFILE_H
#define JKRFILE_H
#include "JSystem/JKernel/JKRDisposer.h"
/**
* @ingroup jsystem-jkernel
*
*/
class JKRFile : public JKRDisposer {
public:
JKRFile() : mIsAvailable(false) {}
virtual ~JKRFile() {}
void read(void*, s32, s32);
bool isAvailable() const { return mIsAvailable; }
public:
/* vt[03] */ virtual bool open(const char*) = 0;
/* vt[04] */ virtual void close() = 0;
/* vt[05] */ virtual s32 readData(void*, s32, s32) = 0;
/* vt[06] */ virtual s32 writeData(const void*, s32, s32) = 0;
/* vt[07] */ virtual s32 getFileSize() const = 0;
protected:
/* 0x00 */ // vtable
/* 0x04 */ // JKRDisposer
/* 0x18 */ bool mIsAvailable;
/* 0x19 */ u8 field_0x19[3];
};
#endif /* JKRFILE_H */
@@ -0,0 +1,75 @@
#ifndef JKRFILECACHE_H
#define JKRFILECACHE_H
#include "JSystem/JKernel/JKRFileLoader.h"
class JKRHeap;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRFileCache : public JKRFileLoader {
public:
class CCacheBlock {
public:
CCacheBlock(u32, u32, const void*);
~CCacheBlock() {}
public:
/* 0x00 */ JSULink<CCacheBlock> mCacheBlockLink;
/* 0x10 */ u32 mReferenceCount;
/* 0x14 */ u32 mFileId;
/* 0x18 */ u32 mFileSize;
/* 0x1C */ void* mMemoryPtr;
};
protected:
JKRFileCache(const char*, const char*);
virtual ~JKRFileCache();
CCacheBlock* findCacheBlock(const void*) const;
CCacheBlock* findCacheBlock(u32) const;
bool findFile(char*, const char*) const;
char* getDvdPathName(const char*) const;
void convStrLower(char*) const;
public:
/* vt[04] */ virtual bool becomeCurrent(const char*); /* override */
/* vt[05] */ virtual void* getResource(const char*); /* override */
/* vt[06] */ virtual void* getResource(u32, const char*); /* override */
/* vt[07] */ virtual u32 readResource(void*, u32, const char*); /* override */
/* vt[08] */ virtual u32 readResource(void*, u32, u32, const char*); /* override */
/* vt[09] */ virtual void removeResourceAll(void); /* override */
/* vt[10] */ virtual bool removeResource(void*); /* override */
/* vt[11] */ virtual bool detachResource(void*); /* override */
/* vt[12] */ virtual u32 getResSize(const void*) const; /* override */
/* vt[13] */ virtual u32 countFile(const char*) const; /* override */
/* vt[14] */ virtual JKRFileFinder* getFirstFile(const char*) const; /* override */
/* vt[15] */ virtual void* getFsResource(const char*);
/* vt[16] */ virtual void* getNameResource(u32, const char*);
/* vt[17] */ virtual u32 readFsResource(void*, u32, const char*);
/* vt[18] */ virtual u32 readNameResource(void*, u32, u32, const char*);
private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRFileLoader
/* 0x38 */ JKRHeap* mParentHeap;
/* 0x3C */ JSUList<CCacheBlock> mCacheBlockList;
/* 0x48 */ char* mRootPath;
/* 0x4C */ char* mCurrentPath;
/* 0x50 */ char* mVolumePath;
public:
static JKRFileCache* mount(const char*, JKRHeap*, const char*);
};
inline JKRFileCache* JKRMountDvdDrive(const char* path, JKRHeap* heap, const char* param_2) {
return JKRFileCache::mount(path, heap, param_2);
}
inline void JKRUnmountDvdDrive(JKRFileCache* filecache) {
filecache->unmount();
}
#endif /* JKRFILECACHE_H */
@@ -0,0 +1,77 @@
#ifndef JKRFILEFINDER_H
#define JKRFILEFINDER_H
#include <dvd.h>
/**
* @ingroup jsystem-jkernel
*
*/
class JKRFileFinder {
public:
JKRFileFinder() {
mIsAvailable = false;
mIsFileOrDirectory = false;
}
bool isAvailable() const { return mIsAvailable; }
bool isFile() const { return mIsFileOrDirectory; }
bool isDirectory() const { return mIsFileOrDirectory; }
protected:
/* 0x00 */ const char* mEntryName;
/* 0x04 */ s32 mEntryFileIndex;
/* 0x08 */ u16 mEntryId;
/* 0x0A */ u16 mEntryTypeFlags;
/* 0x0C */ // vtable
public:
/* vt[2] */ virtual ~JKRFileFinder() {};
/* vt[3] */ virtual bool findNextFile(void) = 0;
protected:
/* 0x10 */ bool mIsAvailable;
/* 0x11 */ bool mIsFileOrDirectory;
/* 0x12 */ u8 field_0x12[2];
};
class JKRArchive;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRArcFinder : public JKRFileFinder {
public:
JKRArcFinder(JKRArchive*, s32, s32);
inline virtual ~JKRArcFinder() {}
public:
/* vt[3] */ virtual bool findNextFile(void); /* override */
private:
/* 0x00 */ // JKRFileFinder_UnknownBase
/* 0x0C */ // vtable
/* 0x10 */ // JKRFileFinder
/* 0x14 */ JKRArchive* mArchive;
/* 0x18 */ s32 mStartIndex;
/* 0x1C */ s32 mEndIndex;
/* 0x20 */ s32 mNextIndex;
};
class JKRDvdFinder : public JKRFileFinder {
public:
JKRDvdFinder(const char*);
virtual ~JKRDvdFinder();
public:
/* vt[3] */ virtual bool findNextFile(void); /* override */
private:
/* 0x00 */ // JKRFileFinder_UnknownBase
/* 0x0C */ // vtable
/* 0x10 */ // JKRFileFinder
/* 0x14 */ DVDDir mDvdDirectory;
/* 0x20 */ bool mDvdIsOpen;
/* 0x21 */ u8 field_0x21[3];
};
#endif /* JKRFILEFINDER_H */
@@ -0,0 +1,72 @@
#ifndef JKRFILELOADER_H
#define JKRFILELOADER_H
#include "JSystem/JKernel/JKRDisposer.h"
class JKRFileFinder;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRFileLoader : public JKRDisposer {
public:
JKRFileLoader(void);
virtual ~JKRFileLoader();
bool isMounted() { return this->mIsMounted; }
u32 getVolumeType() { return this->mVolumeType; }
public:
/* vt[03] */ virtual void unmount(void);
/* vt[04] */ virtual bool becomeCurrent(const char*) = 0;
/* vt[05] */ virtual void* getResource(const char*) = 0;
/* vt[06] */ virtual void* getResource(u32, const char*) = 0;
/* vt[07] */ virtual u32 readResource(void*, u32, const char*) = 0;
/* vt[08] */ virtual u32 readResource(void*, u32, u32, const char*) = 0;
/* vt[09] */ virtual void removeResourceAll(void) = 0;
/* vt[10] */ virtual bool removeResource(void*) = 0;
/* vt[11] */ virtual bool detachResource(void*) = 0;
/* vt[12] */ virtual u32 getResSize(const void*) const = 0;
/* vt[13] */ virtual u32 countFile(const char*) const = 0;
/* vt[14] */ virtual JKRFileFinder* getFirstFile(const char*) const = 0;
protected:
/* 0x00 */ // vtable
/* 0x04 */ // JKRDisposer
/* 0x18 */ JSULink<JKRFileLoader> mFileLoaderLink;
/* 0x28 */ const char* mVolumeName;
/* 0x2C */ u32 mVolumeType;
/* 0x30 */ bool mIsMounted;
/* 0x31 */ u8 field_0x31[3];
/* 0x34 */ u32 mMountCount;
public:
static void* getGlbResource(const char*);
static void* getGlbResource(const char*, JKRFileLoader*);
static bool removeResource(void*, JKRFileLoader*);
static bool detachResource(void*, JKRFileLoader*);
static JKRFileLoader* findVolume(const char**);
static const char* fetchVolumeName(char*, s32, const char*);
static JKRFileLoader* getCurrentVolume() { return sCurrentVolume; }
static void setCurrentVolume(JKRFileLoader* fileLoader) { sCurrentVolume = fileLoader; }
static JSUList<JKRFileLoader>& getVolumeList() { return sVolumeList; }
static JKRFileLoader* sCurrentVolume;
static JSUList<JKRFileLoader> sVolumeList;
};
inline bool JKRDetachResource(void* resource, JKRFileLoader* fileLoader) {
return JKRFileLoader::detachResource(resource, fileLoader);
}
inline void* JKRGetNameResource(const char* name, JKRFileLoader* loader) {
return JKRFileLoader::getGlbResource(name, loader);
}
inline void* JKRGetResource(const char* name) {
return JKRFileLoader::getGlbResource(name);
}
#endif /* JKRFILELOADER_H */
@@ -0,0 +1,289 @@
#ifndef JKRHEAP_H
#define JKRHEAP_H
#include "JSystem/JKernel/JKRDisposer.h"
#include <os.h>
#include "global.h"
#include <new>
#include <cstdint>
class JKRHeap;
typedef void (*JKRErrorHandler)(void*, u32, int);
extern u8 JKRValue_DEBUGFILL_NOTUSE;
extern u8 JKRValue_DEBUGFILL_NEW;
extern u8 JKRValue_DEBUGFILL_DELETE;
extern s32 fillcheck_dispcount;
extern bool data_8074A8D0_debug;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRHeap : public JKRDisposer {
public:
typedef void (*JKRAllocCallback)(u32, int, JKRHeap*, void*);
typedef void (*JKRFreeCallback)(void*, JKRHeap*);
class TState {
public:
/* 0x00 */ u32 mUsedSize;
/* 0x04 */ u32 mCheckCode;
/* 0x08 */ u32 mBuf;
/* 0x0C */ u32 field_0xc;
/* 0x10 */ JKRHeap* mHeap;
/* 0x14 */ u32 mId;
public:
u32 getUsedSize() const { return mUsedSize; }
u32 getCheckCode() const { return mCheckCode; }
JKRHeap* getHeap() const { return mHeap; }
u32 getId() const { return mId; }
};
public:
JKRHeap(u32 size, JKRHeap* parent, bool errorFlag);
JKRHeap(void* data, u32 size, JKRHeap* parent, bool errorFlag);
virtual ~JKRHeap();
JKRHeap* becomeSystemHeap();
JKRHeap* becomeCurrentHeap();
void destroy();
void* alloc(u32 size, int alignment);
void free(void* ptr);
void freeAll();
void freeTail();
s32 resize(void* ptr, u32 size);
s32 getSize(void* ptr);
s32 getFreeSize();
void* getMaxFreeBlock();
s32 getTotalFreeSize();
s32 changeGroupID(u8 newGroupId);
u8 getCurrentGroupId();
u32 getMaxAllocatableSize(int alignment);
JKRHeap* find(void* ptr) const;
JKRHeap* findAllHeap(void* ptr) const;
void dispose_subroutine(uintptr_t start, uintptr_t end);
bool dispose(void* ptr, u32 size);
void dispose(void* begin, void* end);
void dispose();
bool setErrorFlag(bool errorFlag);
bool isSubHeap(JKRHeap* heap) const;
void* getAltAramStartAdr();
/* vt[03] */ virtual void callAllDisposer();
/* vt[04] */ virtual u32 getHeapType() = 0;
/* vt[05] */ virtual bool check() = 0;
/* vt[06] */ virtual bool dump_sort();
/* vt[07] */ virtual bool dump() = 0;
/* vt[08] */ virtual void do_destroy() = 0;
/* vt[09] */ virtual void* do_alloc(u32 size, int alignment) = 0;
/* 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[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;
/* vt[17] */ virtual void* do_getMaxFreeBlock() = 0;
/* vt[18] */ virtual s32 do_getTotalFreeSize() = 0;
/* vt[19] */ virtual s32 do_changeGroupID(u8 newGroupID);
/* vt[20] */ virtual u8 do_getCurrentGroupId();
/* vt[21] */ virtual void state_register(JKRHeap::TState* p, u32 id) const;
/* vt[22] */ virtual bool state_compare(JKRHeap::TState const& r1, JKRHeap::TState const& r2) const;
/* vt[23] */ virtual void state_dump(JKRHeap::TState const& p) const;
void setDebugFill(bool debugFill) { mDebugFill = debugFill; }
bool getDebugFill() const { return mDebugFill; }
void* getStartAddr() { return (void*)mStart; }
void* getEndAddr() { return (void*)mEnd; }
u32 getSize() const { return mSize; }
bool getErrorFlag() const { return mErrorFlag; }
void callErrorHandler(void* heap, u32 size, int alignment) {
if (mErrorHandler) {
(*mErrorHandler)(heap, size, alignment);
}
}
JKRHeap* getParent() { return mChildTree.getParent()->getObject(); }
JSUTree<JKRHeap>& getHeapTree() { return mChildTree; }
void appendDisposer(JKRDisposer* disposer) { mDisposerList.append(&disposer->mLink); }
void removeDisposer(JKRDisposer* disposer) { mDisposerList.remove(&disposer->mLink); }
void lock() const { OSLockMutex(const_cast<OSMutex*>(&mMutex)); }
void unlock() const { OSUnlockMutex(const_cast<OSMutex*>(&mMutex)); }
u32 getHeapSize() { return mSize; }
protected:
/* 0x00 */ // vtable
/* 0x04 */ // JKRDisposer
/* 0x18 */ OSMutex mMutex;
/* 0x30 */ u8* mStart;
/* 0x34 */ u8* mEnd;
/* 0x38 */ u32 mSize;
/* 0x3C */ bool mDebugFill;
/* 0x3D */ bool mCheckMemoryFilled;
/* 0x3E */ u8 mAllocationMode; // EAllocMode?
/* 0x3F */ u8 mGroupId;
/* 0x40 */ JSUTree<JKRHeap> mChildTree;
/* 0x5C */ JSUList<JKRDisposer> mDisposerList;
/* 0x68 */ bool mErrorFlag;
/* 0x69 */ bool mInitFlag;
public:
static bool initArena(char** memory, u32* size, int maxHeaps);
static bool initArena2(char** memory, u32* size, int maxHeaps);
static void* alloc(u32 size, int alignment, JKRHeap* heap);
static void free(void* ptr, JKRHeap* heap);
static s32 resize(void* ptr, u32 size, JKRHeap* heap);
static s32 getSize(void* ptr, JKRHeap* heap);
static JKRHeap* findFromRoot(void* ptr);
static void copyMemory(void* dst, void* src, u32 size);
static void fillMemory(void* dst, u32 size, u8 value); // NOTE: never used
static bool checkMemoryFilled(void* src, u32 size, u8 value);
static JKRErrorHandler setErrorHandler(JKRErrorHandler errorHandler);
static void fillMemory(u8*, u32, u8);
static bool checkMemoryFilled(u8*, u32, u8);
static bool isDefaultDebugFill() { return sDefaultFillFlag; }
static void setDefaultDebugFill(bool status) { sDefaultFillFlag = status; }
static void* getCodeStart(void) { return mCodeStart; }
static void* getCodeEnd(void) { return mCodeEnd; }
static void* getUserRamStart(void) { return mUserRamStart; }
static void* getUserRamEnd(void) { return mUserRamEnd; }
static u32 getMemorySize(void) { return mMemorySize; }
static JKRHeap* getRootHeap() { return sRootHeap; }
static JKRHeap* getRootHeap2() { return sRootHeap2; }
static JKRHeap* getSystemHeap() { return sSystemHeap; }
static JKRHeap* getCurrentHeap() { return sCurrentHeap; }
static void setSystemHeap(JKRHeap* heap) { sSystemHeap = heap; }
static void setCurrentHeap(JKRHeap* heap) { sCurrentHeap = heap; }
static void setState_u32ID_(TState* state, u32 id) { state->mId = id; }
static void setState_uUsedSize_(TState* state, u32 usedSize) { state->mUsedSize = usedSize; }
static void setState_u32CheckCode_(TState* state, u32 checkCode) {
state->mCheckCode = checkCode;
}
static void* getState_buf_(TState* state) { return &state->mBuf; }
static void* mCodeStart;
static void* mCodeEnd;
static void* mUserRamStart;
static void* mUserRamEnd;
static u32 mMemorySize;
static JKRAllocCallback sAllocCallback;
static JKRFreeCallback sFreeCallback;
static bool sDefaultFillFlag;
static JKRHeap* sRootHeap;
static JKRHeap* sRootHeap2;
static JKRHeap* sSystemHeap;
static JKRHeap* sCurrentHeap;
static JKRErrorHandler mErrorHandler;
};
void* operator new(size_t size);
void* operator new(size_t size, int alignment);
void* operator new(size_t size, JKRHeap* heap, int alignment);
void* operator new[](size_t size);
void* operator new[](size_t size, int alignment);
void* operator new[](size_t size, JKRHeap* heap, int alignment);
void operator delete(void* ptr);
void operator delete[](void* ptr);
void JKRDefaultMemoryErrorRoutine(void* heap, u32 size, int alignment);
inline void* JKRAllocFromHeap(JKRHeap* heap, u32 size, int alignment) {
return JKRHeap::alloc(size, alignment, heap);
}
inline void* JKRAllocFromSysHeap(u32 size, int alignment) {
return JKRHeap::getSystemHeap()->alloc(size, alignment);
}
inline void JKRFreeToHeap(JKRHeap* heap, void* ptr) {
JKRHeap::free(ptr, heap);
}
inline void JKRFreeToSysHeap(void* ptr) {
JKRHeap::getSystemHeap()->free(ptr);
}
inline void JKRFree(void* ptr) {
JKRHeap::free(ptr, NULL);
}
inline void JKRFillMemory(u8* dst, u32 size, u8 val) {
JKRHeap::fillMemory(dst, size, val);
}
inline JKRHeap* JKRGetSystemHeap() {
return JKRHeap::getSystemHeap();
}
inline JKRHeap* JKRGetCurrentHeap() {
return JKRHeap::getCurrentHeap();
}
inline JKRHeap* JKRSetCurrentHeap(JKRHeap* heap) {
return heap->becomeCurrentHeap();
}
inline u32 JKRGetMemBlockSize(JKRHeap* heap, void* block) {
return JKRHeap::getSize(block, heap);
}
inline u32 JKRGetFreeSize(JKRHeap* heap) {
return heap->getFreeSize();
}
inline void* JKRAlloc(u32 size, int alignment) {
return JKRHeap::alloc(size, alignment, NULL);
}
inline s32 JKRResizeMemBlock(JKRHeap* heap, void* ptr, u32 size) {
return JKRHeap::resize(ptr, size, heap);
}
inline JKRHeap* JKRFindHeap(void* ptr) {
return JKRHeap::findFromRoot(ptr);
}
inline JKRHeap* JKRGetRootHeap() {
return JKRHeap::getRootHeap();
}
inline JKRErrorHandler JKRSetErrorHandler(JKRErrorHandler errorHandler) {
return JKRHeap::setErrorHandler(errorHandler);
}
inline bool JKRSetErrorFlag(JKRHeap* heap, bool flag) {
return heap->setErrorFlag(flag);
}
inline JKRHeap* JKRGetRootHeap2() {
return JKRHeap::getRootHeap2();
}
#if DEBUG
inline void JKRSetDebugFillNotuse(u8 status) { JKRValue_DEBUGFILL_NOTUSE = status; }
inline void JKRSetDebugFillNew(u8 status) { JKRValue_DEBUGFILL_NEW = status; }
inline void JKRSetDebugFillDelete(u8 status) { JKRValue_DEBUGFILL_DELETE = status; }
#endif
#endif /* JKRHEAP_H */
@@ -0,0 +1,44 @@
#ifndef JKRMEMARCHIVE_H
#define JKRMEMARCHIVE_H
#include "JSystem/JKernel/JKRArchive.h"
enum JKRMemBreakFlag {
JKRMEMBREAK_FLAG_UNKNOWN0 = 0,
JKRMEMBREAK_FLAG_UNKNOWN1 = 1,
};
/**
* @ingroup jsystem-jkernel
*
*/
class JKRMemArchive : public JKRArchive {
public:
JKRMemArchive(s32, JKRArchive::EMountDirection);
JKRMemArchive(void*, u32, JKRMemBreakFlag);
virtual ~JKRMemArchive();
bool open(s32, JKRArchive::EMountDirection);
bool open(void*, u32, JKRMemBreakFlag);
/* vt[09] */ void removeResourceAll(void); /* override */
/* vt[10] */ bool removeResource(void*); /* override */
/* vt[15] */ u32 getExpandedResSize(const void*) const; /* override */
/* vt[16] */ void* fetchResource(SDIFileEntry*, u32*); /* override */
/* vt[17] */ void* fetchResource(void*, u32, SDIFileEntry*, u32*); /* override */
public:
static u32 fetchResource_subroutine(u8*, u32, u8*, u32, JKRCompression);
SArcHeader* getArcHeader() { return mArcHeader; }
public:
/* 0x00 */ // vtable
/* 0x04 */ // JKRArchive
/* 0x64 */ SArcHeader* mArcHeader;
/* 0x68 */ u8* mArchiveData;
/* 0x6C */ bool mIsOpen;
/* 0x6D */ u8 field_0x6d[3];
};
#endif /* JKRMEMARCHIVE_H */
@@ -0,0 +1,74 @@
#ifndef JKRSOLIDHEAP_H
#define JKRSOLIDHEAP_H
#include "JSystem/JKernel/JKRHeap.h"
/**
* @ingroup jsystem-jkernel
*
*/
class JKRSolidHeap : public JKRHeap {
public:
struct Unknown {
u32 field_0x0;
u32 field_0x4;
u32 field_0x8;
void* field_0xc;
Unknown* mNext;
};
protected:
JKRSolidHeap(void*, u32, JKRHeap*, bool);
virtual ~JKRSolidHeap();
void* allocFromHead(u32, int);
void* allocFromTail(u32, int);
static s32 getUsedSize(JKRSolidHeap* heap) { return heap->mSize - heap->getTotalFreeSize(); }
public:
/* vt[04] */ virtual u32 getHeapType(void); /* override */
/* vt[05] */ virtual bool check(void); /* override */
/* vt[07] */ virtual bool dump(void); /* override */
/* vt[08] */ virtual void do_destroy(void); /* override */
/* vt[09] */ virtual void* do_alloc(u32, int); /* override */
/* 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[14] */ virtual s32 do_resize(void*, u32); /* override */
/* vt[15] */ virtual s32 do_getSize(void*); /* override */
/* vt[16] */ virtual s32 do_getFreeSize(void); /* override */
/* vt[17] */ virtual void* do_getMaxFreeBlock(void); /* override */
/* vt[18] */ virtual s32 do_getTotalFreeSize(void); /* override */
/* vt[21] */ virtual void state_register(JKRHeap::TState*, u32) const; /* override */
/* vt[22] */ virtual bool state_compare(JKRHeap::TState const&,
JKRHeap::TState const&) const; /* override */
private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRHeap
/* 0x6C */ u32 mFreeSize;
/* 0x70 */ u8* mSolidHead;
/* 0x74 */ u8* mSolidTail;
/* 0x78 */ Unknown* field_0x78;
public:
s32 adjustSize(void);
static JKRSolidHeap* create(u32, JKRHeap*, bool);
static void* getState_(TState* state) { return getState_buf_(state); }
};
inline JKRSolidHeap* JKRCreateSolidHeap(u32 param_0, JKRHeap* heap, bool param_2) {
return JKRSolidHeap::create(param_0, heap, param_2);
}
inline void JKRDestroySolidHeap(JKRSolidHeap* heap) {
heap->destroy();
}
#endif /* JKRSOLIDHEAP_H */
@@ -0,0 +1,203 @@
#ifndef JKRTHREAD_H
#define JKRTHREAD_H
#include "JSystem/JKernel/JKRHeap.h"
#include <os.h>
#include <os.h>
/**
* @ingroup jsystem-jkernel
*
*/
struct JKRThreadName_ {
s32 id;
char* name;
};
class JUTConsole;
/**
* @ingroup jsystem-jkernel
*
*/
class JKRThread : public 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() { return NULL; }
void setCommon_mesgQueue(JKRHeap* heap, int message_count);
void setCommon_heapSpecified(JKRHeap* heap, u32 stack_size, int param_3);
OSThread* getThreadRecord() const { return mThreadRecord; }
void* getStack() const { return mStackMemory; }
TLoad* getLoadInfo() { return &mLoadInfo; }
JKRHeap* getCurrentHeap() const { return mCurrentHeap; }
s32 getCurrentHeapError() const { return mCurrentHeapError; }
void setCurrentHeap(JKRHeap* heap) {
mCurrentHeap = heap ? heap : JKRHeap::getCurrentHeap();
}
void resume() { OSResumeThread(mThreadRecord); }
BOOL sendMessage(OSMessage message) {
return OSSendMessage(&mMessageQueue, message, OS_MESSAGE_NOBLOCK);
}
void sendMessageBlock(OSMessage message) {
OSSendMessage(&mMessageQueue, message, OS_MESSAGE_BLOCK);
}
OSMessage waitMessage() {
OSMessage message;
OSReceiveMessage(&mMessageQueue, &message, OS_MESSAGE_NOBLOCK);
return message;
}
OSMessage waitMessage(BOOL* received) {
OSMessage message;
BOOL rv = OSReceiveMessage(&mMessageQueue, &message, OS_MESSAGE_NOBLOCK);
if (received) {
*received = rv;
}
return message;
}
OSMessage waitMessageBlock() {
OSMessage message;
OSReceiveMessage(&mMessageQueue, &message, OS_MESSAGE_BLOCK);
return message;
}
void jamMessageBlock(OSMessage message) {
OSJamMessage(&mMessageQueue, message, OS_MESSAGE_BLOCK);
}
private:
/* 0x00 */ // vtable
/* 0x04 */ // JKRDisposer
/* 0x18 */ JSULink<JKRThread> mThreadListLink;
/* 0x28 */ JKRHeap* mHeap;
/* 0x2C */ OSThread* mThreadRecord;
/* 0x30 */ OSMessageQueue mMessageQueue;
/* 0x50 */ OSMessage* mMesgBuffer;
/* 0x54 */ s32 mMessageCount;
/* 0x58 */ void* mStackMemory;
/* 0x5C */ u32 mStackSize;
/* 0x60 */ TLoad mLoadInfo;
/* 0x74 */ JKRHeap* mCurrentHeap;
/* 0x78 */ s32 mCurrentHeapError;
public:
static void* start(void* param_1);
static JKRThread* searchThread(OSThread* thread);
static JSUList<JKRThread>& getList() { return (JSUList<JKRThread>&)sThreadList; }
static JSUList<JKRThread> sThreadList;
// static u8 sThreadList[12];
};
class JKRIdleThread : public JKRThread {
public:
virtual void destroy() {}
virtual ~JKRIdleThread() { sThread = NULL; }
virtual void* run() { while (true); }
static void* sThread;
};
typedef void (*JKRThreadSwitch_PreCallback)(OSThread* current, OSThread* next);
typedef void (*JKRThreadSwitch_PostCallback)(OSThread* current, OSThread* next);
/**
* @ingroup jsystem-jkernel
*
*/
class JKRThreadSwitch {
public:
JKRThreadSwitch(JKRHeap*);
virtual void draw(JKRThreadName_* param_1, JUTConsole* param_2);
virtual void draw(JKRThreadName_* thread_name_list) { draw(thread_name_list, NULL); }
virtual ~JKRThreadSwitch() {}
static JKRThreadSwitch* createManager(JKRHeap* heap);
JKRThread* enter(JKRThread* param_1, int param_2);
static void callback(OSThread* param_1, OSThread* param_2);
static JKRThreadSwitch* getManager() { return sManager; }
static u32 getTotalCount() { return sTotalCount; }
private:
static JKRThreadSwitch* sManager;
static u32 sTotalCount;
static u64 sTotalStart;
static JKRThreadSwitch_PreCallback mUserPreCallback;
static JKRThreadSwitch_PostCallback mUserPostCallback;
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;
};
class JKRTask : public JKRThread {
public:
virtual ~JKRTask();
virtual void* run();
int check();
static JSUList<JKRTask> sTaskList;
static u8 sEndMesgQueue[32];
/* 0x7C */ JSULink<JKRTask> mTaskLink;
/* 0x8C */ u8 field_0x8c[0x94 - 0x8C];
/* 0x94 */ OSMessageQueue* field_0x94;
};
#endif /* JKRTHREAD_H */