merge cuyler's PR

This commit is contained in:
Prakxo
2023-03-13 07:15:03 +00:00
parent cf13cc2139
commit 3dd5dbcf59
48 changed files with 3102 additions and 215 deletions
+177
View File
@@ -0,0 +1,177 @@
#ifndef JKRARAM_H
#define JKRARAM_H
#include "types.h"
#include "dolphin/ar.h"
#include "dolphin/os/OSMessage.h"
#include "JSystem/JKernel/JKRDisposer.h"
#include "JSystem/JKernel/JKRHeap.h"
#include "JSystem/JKernel/JKRThread.h"
#include "JSystem/JSupport/JSUList.h"
#define ALIGN_PREV(u, align) (u & (~(align-1)))
#define ALIGN_NEXT(u, align) ((u + (align-1)) & (~(align-1)))
#define ARAM_GROUP_ID_ALL 0
#define ARAM_GROUP_ID_DEFAULT 0xFF
#define ARAM_MESGBUF_COUNT 4
#define ARAMPIECE_DONE_CALLBACK 0
#define ARAMPIECE_DONE_NONE 1
#define ARAMPIECE_DONE_DECOMPRESS 2
class JKRAramHeap;
class JKRDecompCommand;
class JKRAMCommand;
class JKRAramBlock {
JKRAramBlock(u32 address, u32 size, u32 freeSize, u8 groupID, bool tempMemory);
virtual ~JKRAramBlock();
JKRAramBlock* allocHead(u32 size, u8 groupID, JKRAramHeap* heap);
JKRAramBlock* allocTail(u32 size, u8 groupID, JKRAramHeap* heap);
u32 getAddress() const { return this->mAddress; }
u32 getSize() const { return this->mSize; }
u32 getFreeSize() const { return this->mFreeSize; }
bool isTempMemory() const { return this->mIsTempMemory; }
void newGroupID(u8 groupID) { this->mGroupID = groupID; }
JSULink<JKRAramBlock> mLink;
u32 mAddress;
u32 mSize;
u32 mFreeSize;
u8 mGroupID;
bool mIsTempMemory;
friend class JKRAramHeap;
};
class JKRAram : public JKRThread {
public:
JKRAram(u32, u32, s32);
virtual ~JKRAram();
virtual void* run();
static JKRAram* sAramObject;
static const OSMessageQueue sMessageQueue;
static JSUList<JKRAMCommand> sAramCommandList;
static u32 sSZSBufferSize;
static OSMessage sMessageBuffer[ARAM_MESGBUF_COUNT];
private:
u32 mAudioMemoryPtr;
u32 mAudioMemorySize;
u32 mGraphMemoryPtr;
u32 mGraphMemorySize;
u32 mAramMemoryPtr;
u32 mAramMemorySize;
JKRAramHeap* mAramHeap;
u32 mBlockLength;
u8 _9C[4];
};
class JKRAramHeap : public JKRDisposer {
enum EAllocMode {
Head = 0,
Tail = 1
};
JKRAramHeap(u32 baseAddress, u32 size);
virtual ~JKRAramHeap();
JKRAramBlock* alloc(u32 size, EAllocMode mode);
void free(JKRAramBlock* block);
JKRAramBlock* allocFromHead(u32 size);
JKRAramBlock* allocFromTail(u32 size);
u32 getFreeSize();
u32 getTotalFreeSize();
u32 getUsedSize(u8 groupID);
void dump();
u8 getCurrentGroupID() const { return this->mGroupID; }
JKRHeap* getMgrHeap() const { return this->mHeap; }
void lock() { OSLockMutex(&this->mMutex); }
void unlock() { OSUnlockMutex(&this->mMutex); }
static JSUList<JKRAramBlock> sAramList;
OSMutex mMutex;
JKRHeap* mHeap;
u32 mHeadAddress;
u32 mTailAddress;
u32 mSize;
u8 mGroupID;
friend class JKRAramBlock;
};
class JKRAMCommand : public ARQRequest {
public:
typedef void (*AMCommandCallback)(u32);
JKRAMCommand();
~JKRAMCommand();
JSULink<JKRAMCommand> mAramPieceCommandLink;
JSULink<JKRAMCommand> mLink30;
s32 mDirection;
u32 mLength;
u32 mSource;
u32 mDestination;
JKRAramBlock* mAramBlock;
u8 _54[4];
AMCommandCallback mCallback;
OSMessageQueue* mCompletedMesgQueue;
s32 mCallbackType;
JKRDecompCommand* mDecompCommand;
OSMessageQueue mMesgQueue;
OSMessage mMesgBuffer[1];
void* _8C;
void* _90;
void* _94;
};
class JKRAramCommand {
public:
inline void setting(BOOL active, void* arg) {
this->mActive = active;
this->mArg = arg;
}
BOOL mActive;
void* mArg;
};
class JKRAramPiece {
public:
static JKRAMCommand* prepareCommand(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock, JKRAMCommand::AMCommandCallback callback);
static void sendCommand(JKRAMCommand* cmd);
static JKRAMCommand* orderAsync(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock, JKRAMCommand::AMCommandCallback callback);
static bool sync(JKRAMCommand* cmd, BOOL noBlock);
static bool orderSync(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* aramBlock);
static void startDMA(JKRAMCommand* cmd);
static void doneDMA(u32 arg);
static OSMutex mMutex;
static JSUList<JKRAMCommand> sAramPieceCommandList;
private:
static void lock() { OSLockMutex(&mMutex); }
static void unlock() { OSUnlockMutex(&mMutex); }
};
inline bool JKRAramPcs(int direction, u32 source, u32 destination, u32 length, JKRAramBlock* block) {
return JKRAramPiece::orderSync(direction, source, destination, length, block);
}
inline void JKRAramPcs_SendCommand(JKRAMCommand* cmd) {
JKRAramPiece::sendCommand(cmd);
}
#endif
+93
View File
@@ -0,0 +1,93 @@
#ifndef JKRDECOMP_H
#define JKRDECOMP_H
#include "types.h"
#include "dolphin/os/OSMessage.h"
#include "JSystem/JKernel/JKRThread.h"
#include "JSystem/JKernel/JKRAram.h"
#define JKRDECOMP_MSG_BUF_COUNT 4
#define JKRDECOMP_STACK_SIZE 0x4000
#define JKRDECOMP_THREAD_MSG_BUF_COUNT 16
#define JKRDECOMP_READU32BE(ptr, offset) (((u32)ptr[offset] << 24) | ((u32)ptr[offset + 1] << 16) | ((u32)ptr[offset + 2] << 8) | (u32)ptr[offset + 3])
#define SZ_MIN_BACKSIZE 3
#define SZ_DEFAULT_BACKSIZE 15 + SZ_MIN_BACKSIZE
#define SZP_GETBACKOFS(buf) (((*((u8*)buf) & 0xF) << 8) | (*(((u8*)buf)+1)))
#define SZP_GETCOUNT(buf) (*((u16*)buf) >> 12)
typedef void DecompCallback(u32);
class JKRDecompCommand {
public:
enum TransferType {
MRAM = 0,
ARAM = 1
};
JKRDecompCommand();
~JKRDecompCommand();
u8 _00[4];
u8* mSrcBuffer;
u8* mDstBuffer;
u32 mSrcLength;
u32 mSkipCount;
DecompCallback* mCallback;
JKRDecompCommand* mCmd;
OSMessageQueue* pMesgQueue1C;
TransferType transferType;
JKRAMCommand* mAMCommand;
OSMessageQueue mMesgQueue;
OSMessage mMesgBuffer[1];
};
class JKRDecomp : public JKRThread {
public:
enum CompressionMode {
NONE = 0,
SZP = 1,
SZS = 2
};
JKRDecomp(s32 decompPriority);
virtual ~JKRDecomp();
virtual void* run();
static JKRDecompCommand* prepareCommand(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount, DecompCallback* callback);
static CompressionMode checkCompressed(u8* buf);
static JKRDecomp* create(s32 decompPriority);
static void decode(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount);
static void decodeSZP(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount);
static void decodeSZS(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount);
static bool orderSync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount);
static JKRDecompCommand* orderAsync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 skipCount, DecompCallback* callback);
static bool sync(JKRDecompCommand* cmd, BOOL noBlock);
static BOOL sendCommand(JKRDecompCommand* cmd);
static OSMessageQueue sMessageQueue;
static OSMessage sMessageBuffer[JKRDECOMP_MSG_BUF_COUNT];
static JKRDecomp* sDecompObject;
};
inline JKRDecomp* JKRCreateDecompManager(s32 priority) {
return JKRDecomp::create(priority);
}
inline JKRDecomp::CompressionMode JKRCheckCompressed(u8* buf) {
return JKRDecomp::checkCompressed(buf);
}
inline u32 JKRDecompExpandSize(u8* buf) {
return (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
}
inline void JKRDecompress(u8* src, u8* dst, u32 srcLength, u32 skipCount) {
JKRDecomp::orderSync(src, dst, srcLength, skipCount);
}
#endif
+79
View File
@@ -0,0 +1,79 @@
#ifndef JKRDVDFILE_H
#define JKRDVDFILE_H
#include "JSystem/JKernel/JKRFile.h"
#include "JSystem/JSupport/JSUStream.h"
class JKRDvdFile;
struct JKRDvdFileInfo : public DVDFileInfo {
JKRDvdFile* mFile;
};
class JKRDvdFile : public JKRFile {
public:
JKRDvdFile();
JKRDvdFile(const char* filename);
JKRDvdFile(s32 entrynum);
virtual ~JKRDvdFile();
virtual bool open(const char* filename);
virtual bool close();
virtual int readData(void* data, s32 length, s32 ofs);
virtual int writeData(const void* data, s32 length, s32 ofs);
virtual u32 getFileSize() const { return this->mDvdFileInfo.length; }
virtual bool open(s32 entrynum);
inline DVDFileInfo* getFileInfo() {
return &this->mDvdFileInfo;
}
inline int readDataAsync(void* addr, s32 length, s32 offset) {
OSLockMutex(&this->mMutex1);
s32 retAddr;
if (this->mThread2 != nullptr) {
OSUnlockMutex(&this->mMutex1);
retAddr = -1;
}
else {
this->mThread2 = OSGetCurrentThread();
retAddr = -1;
if (DVDReadAsync(&this->mDvdFileInfo, addr, length, offset, JKRDvdFile::doneProcess)) {
retAddr = this->sync();
}
this->mThread2 = nullptr;
OSUnlockMutex(&this->mMutex1);
}
return retAddr;
}
inline int writeDataAsync(const void* data, s32 length, s32 offset) { return -1; }
void initiate();
s32 sync();
static void doneProcess(s32 result, DVDFileInfo* info);
static JSUList<JKRDvdFile> sDvdList;
protected:
OSMutex mMutex1;
OSMutex mMutex2;
JKRAramBlock* mAramBlock;
OSThread* mThread1;
JSUFileInputStream* mInputStream;
u32 _58;
JKRDvdFileInfo mDvdFileInfo;
OSMessageQueue mMessageQueue1;
OSMessage mMsg1;
OSMessageQueue mMessageQueue2;
OSMessage mMsg2;
JSULink<JKRDvdFile> mLink;
OSThread* mThread2;
};
#endif
+47
View File
@@ -0,0 +1,47 @@
#ifndef JKRDVDRIPPER_H
#define JKRDVDRIPPER_H
#include "types.h"
#include "JSystem/JKernel/JKRDvdFile.h"
#define SZP_BUFFERSIZE 1024
#define REF_BUFFERSIZE 0x1120
enum JKRExpandSwitch {
EXPAND_SWITCH_DEFAULT, /* Do nothing? treated same as 2 */
EXPAND_SWITCH_DECOMPRESS, /* Check for compression and decompress */
EXPAND_SWITCH_NONE /* Do nothing */
};
struct SZPHeader {
u32 magic;
u32 decompSize;
};
class JKRDMCommand {
JKRDMCommand();
~JKRDMCommand();
};
class JKRDvdRipper {
public:
enum EAllocDirection {
ALLOC_DIR_DEFAULT = 0,
ALLOC_DIR_TOP = 1,
ALLOC_DIR_BOTTOM = 2
};
static void* loadToMainRAM(const char* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, EAllocDirection allocDir, u32 offset, int* compressMode);
static void* loadToMainRAM(s32 entrynum, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, EAllocDirection allocDir, u32 offset, int* compressMode);
static void* loadToMainRAM(JKRDvdFile* file, u8* buf, JKRExpandSwitch expandSwitch, u32 maxDest, JKRHeap* heap, EAllocDirection allocDir, u32 offset, int* compressMode);
static inline bool isErrorRetry() { return JKRDvdRipper::errorRetry; }
static JSUList<JKRDMCommand> sDvdAsyncList;
static bool errorRetry;
};
static int JKRDecompressFromDVD(JKRDvdFile* srcFile, void* buf, u32 size, u32 maxDest, u32 fileOffset, u32 srcOffset);
#endif
+34
View File
@@ -0,0 +1,34 @@
#ifndef JKRFILE_H
#define JKRFILE_H
#include "types.h"
#include "dolphin/dvd.h"
#include "dolphin/os.h"
#include "JSystem/JSupport/JSUList.h"
#include "JSystem/JKernel/JKRAram.h"
#include "JSystem/JKernel/JKRDisposer.h"
#include "JSystem/JKernel/JKRMacro.h"
class JKRFile : public JKRDisposer {
public:
inline JKRFile()
: JKRDisposer()
, mFileOpen(false)
{
}
virtual ~JKRFile() { }
virtual bool open(const char* path) = 0;
virtual bool close() = 0;
virtual int readData(void* data, s32 length, s32 ofs) = 0;
virtual int writeData(const void* data, s32 length, s32 ofs) = 0;
virtual u32 getFileSize() const = 0;
void read(void* data, s32 length, s32 ofs);
bool isAvailable() { return this->mFileOpen; }
protected:
bool mFileOpen;
};
#endif
+13
View File
@@ -0,0 +1,13 @@
#ifndef JKRMARCO_H
#define JKRMACRO_H
#define JKR_ISALIGNED(addr, alignment) ((((u32)addr) & (((u32)alignment)-1)) == 0)
#define JKR_ISALIGNED32(addr) (JKR_ISALIGNED(addr, 32))
#define JKR_ISNOTALIGNED(addr, alignment) ((((u32)addr) & (((u32)alignment)-1)) != 0)
#define JKR_ISNOTALIGNED32(addr) (JKR_ISNOTALIGNED(addr, 32))
#define JKR_ALIGN(addr, alignment) (((u32)addr) & (~(((u32)alignment)-1)))
#define JKR_ALIGN32(addr) (JKR_ALIGN(addr, 32))
#endif
+58
View File
@@ -0,0 +1,58 @@
#ifndef JKRTHREAD_H
#define JKRTHREAD_H
#include "types.h"
#include "dolphin/os/OSMessage.h"
#include "dolphin/os/OSThread.h"
#include "dolphin/os/OSTime.h"
#include "JSystem/JSupport/JSUList.h"
#include "JSystem/JKernel/JKRHeap.h"
#include "JSystem/JKernel/JKRDisposer.h"
class JKRThread : public JKRDisposer {
public:
JKRThread(u32 stackSize, int msgCount, int threadPrio);
JKRThread(OSThread* osThread, int msgCount);
virtual ~JKRThread();
__declspec(weak) virtual void* run();
static void* start(void* param);
static JSUList<JKRThread>* getList() { return &JKRThread::sThreadList; }
OSThread* getThreadRecord() const { return this->mThreadRecord; }
void* getStack() const { return this->mStackMemory; }
void resume() { OSResumeThread(this->mThreadRecord); }
void jamMessageBlock(OSMessage msg) { OSJamMessage(&this->mMesgQueue, msg, OS_MESSAGE_BLOCK); }
void sendMessage(OSMessage msg) { OSSendMessage(&this->mMesgQueue, msg, OS_MESSAGE_NOBLOCK); }
OSMessage waitMessage(int* received) {
OSMessage mesg;
BOOL retrieved = OSReceiveMessage(&this->mMesgQueue, &mesg, OS_MESSAGE_NOBLOCK);
if (received != nullptr) {
*received = retrieved;
}
return mesg;
}
OSMessage waitMeessageBlock() {
OSMessage mesg;
OSReceiveMessage(&this->mMesgQueue, &mesg, OS_MESSAGE_BLOCK);
return mesg;
}
static JSUList<JKRThread> sThreadList;
protected:
JSULink<JKRThread> mLink;
JKRHeap* mHeap;
OSThread* mThreadRecord;
OSMessageQueue mMesgQueue;
OSMessage* mMesgBuffer;
int mMesgCount;
void* mStackMemory;
u32 mStackSize;
};
#endif