Merge pull request #76 from Jcw87/JKRDecomp

JKRDecomp
This commit is contained in:
Jasper St. Pierre
2023-09-24 15:56:33 -07:00
committed by GitHub
20 changed files with 274 additions and 62 deletions
+1 -1
View File
@@ -779,7 +779,7 @@ config.libs = [
Object(NonMatching, "JSystem/JKernel/JKRDvdFile.cpp"),
Object(Matching, "JSystem/JKernel/JKRDvdRipper.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRDvdAramRipper.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRDecomp.cpp"),
Object(Matching, "JSystem/JKernel/JKRDecomp.cpp"),
],
),
JSystemLib(
+1 -1
View File
@@ -33,7 +33,7 @@ public:
/* 0x84 */ u32 mStackArray[3];
public:
static JKRAram* create(u32, u32, long, long, long);
static JKRAram* create(u32, u32, s32, s32, s32);
static bool checkOkAddress(u8*, u32, JKRAramBlock*, u32);
static void changeGroupIdIfNeed(u8*, int);
static JKRAramBlock* mainRamToAram(u8*, u32, u32, JKRExpandSwitch, u32, JKRHeap*, int);
+2 -2
View File
@@ -9,10 +9,10 @@ class JKRDvdFile;
class JKRAramArchive : public JKRArchive {
public:
JKRAramArchive(long, JKRArchive::EMountDirection);
JKRAramArchive(s32, JKRArchive::EMountDirection);
virtual ~JKRAramArchive();
bool open(long);
bool open(s32);
u32 getAramAddress_Entry(SDIFileEntry*);
u32 getAramAddress(char const*);
+2 -2
View File
@@ -42,7 +42,7 @@ private:
/* vt[03] */ void* run(void); /* override */
public:
static JKRAramStream* create(long);
static JKRAramStream* create(s32);
static s32 readFromAram(void);
static s32 writeToAram(JKRAramStreamCommand*);
@@ -60,7 +60,7 @@ private:
static JKRHeap* transHeap;
};
inline JKRAramStream* JKRCreateAramStreamManager(long priority) {
inline JKRAramStream* JKRCreateAramStreamManager(s32 priority) {
return JKRAramStream::create(priority);
}
+1 -1
View File
@@ -115,7 +115,7 @@ public:
protected:
JKRArchive();
JKRArchive(long, EMountMode);
JKRArchive(s32, EMountMode);
public:
bool getDirEntry(SDirEntry*, u32) const;
+1 -1
View File
@@ -5,7 +5,7 @@
class JKRAssertHeap : public JKRHeap {
protected:
JKRAssertHeap(void*, unsigned long, JKRHeap*, bool);
JKRAssertHeap(void*, u32, JKRHeap*, bool);
virtual ~JKRAssertHeap();
public:
+2 -2
View File
@@ -8,10 +8,10 @@ class JKRDvdFile;
class JKRCompArchive : public JKRArchive {
public:
JKRCompArchive(long, JKRArchive::EMountDirection);
JKRCompArchive(s32, JKRArchive::EMountDirection);
virtual ~JKRCompArchive();
bool open(long);
bool open(s32);
/* vt[09] */ void removeResourceAll(void); /* override */
/* vt[10] */ bool removeResource(void*); /* override */
+4 -4
View File
@@ -32,13 +32,13 @@ public:
class JKRDecomp : public JKRThread {
private:
JKRDecomp(long);
JKRDecomp(s32);
virtual ~JKRDecomp();
/* vt[03] */ virtual void* run(); /* override */
public:
static JKRDecomp* create(long);
static JKRDecomp* create(s32);
static JKRDecompCommand* prepareCommand(u8*, u8*, u32, u32, JKRDecompCommand::AsyncCallback);
static void sendCommand(JKRDecompCommand*);
static bool sync(JKRDecompCommand*, int);
@@ -50,7 +50,7 @@ public:
static JKRCompression checkCompressed(u8*);
static JKRDecomp* sDecompObject;
static OSMessage sMessageBuffer[8];
static OSMessage sMessageBuffer[4];
static OSMessageQueue sMessageQueue;
};
@@ -58,7 +58,7 @@ inline void JKRDecompress(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 dstLe
JKRDecomp::orderSync(srcBuffer, dstBuffer, srcLength, dstLength);
}
inline JKRDecomp* JKRCreateDecompManager(long priority) {
inline JKRDecomp* JKRCreateDecompManager(s32 priority) {
return JKRDecomp::create(priority);
}
+1 -1
View File
@@ -34,7 +34,7 @@ public:
class JKRDvdFile;
class JKRDvdAramRipper {
public:
static JKRAramBlock* loadToAram(long, u32, JKRExpandSwitch, u32, u32);
static JKRAramBlock* loadToAram(s32, u32, JKRExpandSwitch, u32, u32);
static JKRAramBlock* loadToAram(JKRDvdFile*, u32, JKRExpandSwitch, u32, u32);
static JKRADCommand* loadToAram_Async(JKRDvdFile*, u32, JKRExpandSwitch, void (*)(u32), u32,
u32);
+1 -1
View File
@@ -52,7 +52,7 @@ public:
/* 0xF4 */ OSThread* mOSThread;
public:
static void doneProcess(long, DVDFileInfo*);
static void doneProcess(s32, DVDFileInfo*);
static JSUList<JKRDvdFile>& getDvdList() { return sDvdList; }
+1 -1
View File
@@ -38,7 +38,7 @@ public:
static void* loadToMainRAM(char const*, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection,
u32, int*);
static void* loadToMainRAM(long, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection, u32,
static void* loadToMainRAM(s32, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection, u32,
int*);
static void* loadToMainRAM(JKRDvdFile*, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection,
u32, int*);
+1 -1
View File
@@ -8,7 +8,7 @@ public:
JKRFile() : mIsAvailable(false) {}
virtual ~JKRFile() {}
s32 read(void*, long, long);
s32 read(void*, s32, s32);
bool isAvailable() const { return mIsAvailable; }
+1 -1
View File
@@ -43,7 +43,7 @@ public:
static bool removeResource(void*, JKRFileLoader*);
static bool detachResource(void*, JKRFileLoader*);
static JKRFileLoader* findVolume(const char**);
static const char* fetchVolumeName(char*, long, const char*);
static const char* fetchVolumeName(char*, s32, const char*);
static JKRFileLoader* getCurrentVolume() { return sCurrentVolume; }
static void setCurrentVolume(JKRFileLoader* fileLoader) { sCurrentVolume = fileLoader; }
+2 -2
View File
@@ -11,13 +11,13 @@ enum JKRMemBreakFlag {
class JKRMemArchive : public JKRArchive {
public:
JKRMemArchive();
JKRMemArchive(long, JKRArchive::EMountDirection);
JKRMemArchive(s32, JKRArchive::EMountDirection);
virtual ~JKRMemArchive();
void fixedInit(s32);
bool mountFixed(void*, JKRMemBreakFlag);
void unmountFixed();
bool open(long, JKRArchive::EMountDirection);
bool open(s32, JKRArchive::EMountDirection);
bool open(void*, u32, JKRMemBreakFlag);
/* vt[09] */ void removeResourceAll(void); /* override */
+5 -5
View File
@@ -24,7 +24,7 @@ static u8* nextSrcData(u8*);
JKRAram* JKRAram::sAramObject;
/* 802B42C4-802B4360 .text create__7JKRAramFUlUllll */
JKRAram* JKRAram::create(u32 aram_audio_buffer_size, u32 aram_audio_graph_size, long stream_priority, long decomp_priority, long piece_priority) {
JKRAram* JKRAram::create(u32 aram_audio_buffer_size, u32 aram_audio_graph_size, s32 stream_priority, s32 decomp_priority, s32 piece_priority) {
if (!sAramObject) {
sAramObject = new (JKRHeap::getSystemHeap(), 0)
JKRAram(aram_audio_buffer_size, aram_audio_graph_size, piece_priority);
@@ -40,7 +40,7 @@ OSMessage JKRAram::sMessageBuffer[4] = { NULL, NULL, NULL, NULL };
OSMessageQueue JKRAram::sMessageQueue = {0};
/* 802B4360-802B44D8 .text __ct__7JKRAramFUlUll */
JKRAram::JKRAram(u32 audio_buffer_size, u32 audio_graph_size, long priority) : JKRThread(0x4000, 0x10, priority) {
JKRAram::JKRAram(u32 audio_buffer_size, u32 audio_graph_size, s32 priority) : JKRThread(0x4000, 0x10, priority) {
u32 aramBase = ARInit(mStackArray, ARRAY_SIZE(mStackArray));
ARQInit();
@@ -323,14 +323,14 @@ static u32 srcAddress;
static u32 fileOffset;
static u32 readCount;
static u32 maxDest;
static bool sIsInitMutex;
static bool isInitMutex;
/* 802B4D4C-802B4F20 .text JKRDecompressFromAramToMainRam__FUlPvUlUlUl */
static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32 dstLength, u32 offset) {
BOOL interrupts = OSDisableInterrupts();
if (sIsInitMutex == false) {
if (isInitMutex == false) {
OSInitMutex(&decompMutex);
sIsInitMutex = true;
isInitMutex = true;
}
OSRestoreInterrupts(interrupts);
OSLockMutex(&decompMutex);
+243 -31
View File
@@ -4,79 +4,291 @@
//
#include "JSystem/JKernel/JKRDecomp.h"
#include "JSystem/JKernel/JKRAramPiece.h"
#include "dolphin/types.h"
JKRDecomp* JKRDecomp::sDecompObject;
/* 802BE890-802BE8F0 .text create__9JKRDecompFl */
void JKRDecomp::create(long) {
/* Nonmatching */
JKRDecomp* JKRDecomp::create(s32 priority) {
if (!sDecompObject) {
sDecompObject = new (JKRHeap::getSystemHeap(), 0) JKRDecomp(priority);
}
return sDecompObject;
}
OSMessage JKRDecomp::sMessageBuffer[4] = {NULL};
OSMessageQueue JKRDecomp::sMessageQueue = {0};
/* 802BE8F0-802BE940 .text __ct__9JKRDecompFl */
JKRDecomp::JKRDecomp(long) {
/* Nonmatching */
JKRDecomp::JKRDecomp(s32 priority) : JKRThread(0x4000, 0x10, priority) {
resume();
}
/* 802BE940-802BE9A0 .text __dt__9JKRDecompFv */
JKRDecomp::~JKRDecomp() {
/* Nonmatching */
}
JKRDecomp::~JKRDecomp() {}
/* 802BE9A0-802BEA68 .text run__9JKRDecompFv */
void JKRDecomp::run() {
/* Nonmatching */
void* JKRDecomp::run() {
OSInitMessageQueue(&sMessageQueue, sMessageBuffer, 4);
while (true) {
OSMessage message;
OSReceiveMessage(&sMessageQueue, &message, OS_MESSAGE_BLOCK);
JKRDecompCommand* command = (JKRDecompCommand*)message;
decode(command->mSrcBuffer, command->mDstBuffer, command->mSrcLength, command->mDstLength);
if (command->field_0x20 != 0) {
if (command->field_0x20 == 1) {
JKRAramPiece::sendCommand(command->mAMCommand);
}
continue;
}
if (command->mCallback) {
(*command->mCallback)((u32)command);
continue;
}
if (command->field_0x1c) {
OSSendMessage(command->field_0x1c, (OSMessage)1, OS_MESSAGE_NOBLOCK);
} else {
OSSendMessage(&command->mMessageQueue, (OSMessage)1, OS_MESSAGE_NOBLOCK);
}
}
}
/* 802BEA68-802BEAE0 .text prepareCommand__9JKRDecompFPUcPUcUlUlPFUl_v */
void JKRDecomp::prepareCommand(unsigned char*, unsigned char*, unsigned long, unsigned long, void (*)(unsigned long)) {
/* Nonmatching */
JKRDecompCommand* JKRDecomp::prepareCommand(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 dstLength, JKRDecompCommand::AsyncCallback callback) {
JKRDecompCommand* command = new (JKRHeap::getSystemHeap(), -4) JKRDecompCommand();
command->mSrcBuffer = srcBuffer;
command->mDstBuffer = dstBuffer;
command->mSrcLength = srcLength;
command->mDstLength = dstLength;
command->mCallback = callback;
return command;
}
/* 802BEAE0-802BEB10 .text sendCommand__9JKRDecompFP16JKRDecompCommand */
void JKRDecomp::sendCommand(JKRDecompCommand*) {
/* Nonmatching */
void JKRDecomp::sendCommand(JKRDecompCommand* command) {
OSSendMessage(&sMessageQueue, command, OS_MESSAGE_BLOCK);
}
/* 802BEB10-802BEB44 .text orderAsync__9JKRDecompFPUcPUcUlUlPFUl_v */
void JKRDecomp::orderAsync(unsigned char*, unsigned char*, unsigned long, unsigned long, void (*)(unsigned long)) {
/* Nonmatching */
JKRDecompCommand* JKRDecomp::orderAsync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 dstLength, JKRDecompCommand::AsyncCallback callback) {
JKRDecompCommand* command =
prepareCommand(srcBuffer, dstBuffer, srcLength, dstLength, callback);
sendCommand(command);
return command;
}
/* 802BEB44-802BEB98 .text sync__9JKRDecompFP16JKRDecompCommandi */
void JKRDecomp::sync(JKRDecompCommand*, int) {
/* Nonmatching */
bool JKRDecomp::sync(JKRDecompCommand* command, int isNonBlocking) {
OSMessage message;
bool result;
if (isNonBlocking == JKRDECOMP_SYNC_BLOCKING) {
OSReceiveMessage(&command->mMessageQueue, &message, OS_MESSAGE_BLOCK);
result = true;
} else {
result =
OSReceiveMessage(&command->mMessageQueue, &message, OS_MESSAGE_NOBLOCK) != FALSE;
}
return result;
}
/* 802BEB98-802BEBEC .text orderSync__9JKRDecompFPUcPUcUlUl */
void JKRDecomp::orderSync(unsigned char*, unsigned char*, unsigned long, unsigned long) {
/* Nonmatching */
bool JKRDecomp::orderSync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 dstLength) {
JKRDecompCommand* command = orderAsync(srcBuffer, dstBuffer, srcLength, dstLength, NULL);
bool result = sync(command, JKRDECOMP_SYNC_BLOCKING);
delete command;
return result;
}
/* 802BEBEC-802BEC68 .text decode__9JKRDecompFPUcPUcUlUl */
void JKRDecomp::decode(unsigned char*, unsigned char*, unsigned long, unsigned long) {
/* Nonmatching */
void JKRDecomp::decode(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 dstLength) {
JKRCompression compression = checkCompressed(srcBuffer);
if (compression == COMPRESSION_YAY0) {
decodeSZP(srcBuffer, dstBuffer, srcLength, dstLength);
} else if (compression == COMPRESSION_YAZ0) {
decodeSZS(srcBuffer, dstBuffer, srcLength, dstLength);
}
}
/* 802BEC68-802BEE24 .text decodeSZP__9JKRDecompFPUcPUcUlUl */
void JKRDecomp::decodeSZP(unsigned char*, unsigned char*, unsigned long, unsigned long) {
/* Nonmatching */
void JKRDecomp::decodeSZP(u8* src, u8* dst, u32 srcLength, u32 dstLength) {
int srcChunkOffset;
int count;
int dstOffset;
u32 length = srcLength;
int linkInfo;
int offset;
int i;
int decodedSize = READU32_BE(src, 4);
int linkTableOffset = READU32_BE(src, 8);
int srcDataOffset = READU32_BE(src, 12);
dstOffset = 0;
u32 counter = 0;
srcChunkOffset = 16;
u32 chunkBits;
if (srcLength == 0)
return;
if (dstLength > decodedSize)
return;
do
{
if (counter == 0)
{
chunkBits = READU32_BE(src, srcChunkOffset);
srcChunkOffset += sizeof(u32);
counter = sizeof(u32) * 8;
}
if (chunkBits & 0x80000000)
{
if (dstLength == 0)
{
dst[dstOffset] = src[srcDataOffset];
length--;
if (length == 0)
return;
}
else
{
dstLength--;
}
dstOffset++;
srcDataOffset++;
}
else
{
linkInfo = src[linkTableOffset] << 8 | src[linkTableOffset + 1];
linkTableOffset += sizeof(u16);
offset = dstOffset - (linkInfo & 0xFFF);
count = (linkInfo >> 12);
if (count == 0)
{
count = (u32)src[srcDataOffset++] + 0x12;
}
else
count += 2;
if (count > decodedSize - dstOffset)
count = decodedSize - dstOffset;
for (i = 0; i < count; i++, dstOffset++, offset++)
{
if (dstLength == 0)
{
dst[dstOffset] = dst[offset - 1];
length--;
if (length == 0)
return;
}
else
dstLength--;
}
}
chunkBits <<= 1;
counter--;
} while (dstOffset < decodedSize);
}
/* 802BEE24-802BEF08 .text decodeSZS__9JKRDecompFPUcPUcUlUl */
void JKRDecomp::decodeSZS(unsigned char*, unsigned char*, unsigned long, unsigned long) {
/* Nonmatching */
void JKRDecomp::decodeSZS(u8* src_buffer, u8* dst_buffer, u32 srcSize, u32 dstSize) {
u8* decompEnd;
u8* copyStart;
s32 copyByteCount;
s32 chunkBitsLeft = 0;
s32 chunkBits;
decompEnd = dst_buffer + *(int*)(src_buffer + 4) - dstSize;
if (srcSize == 0) {
return;
}
if (dstSize > *(u32*)src_buffer) {
return;
}
u8* curSrcPos = src_buffer + 0x10;
do {
if (chunkBitsLeft == 0) {
chunkBits = curSrcPos[0];
chunkBitsLeft = 8;
curSrcPos++;
}
if ((chunkBits & 0x80) != 0) {
if (dstSize == 0) {
dst_buffer[0] = curSrcPos[0];
srcSize--;
dst_buffer++;
if (srcSize == 0)
return;
} else {
dstSize--;
}
curSrcPos++;
} else {
u32 local_28 = curSrcPos[1] | (curSrcPos[0] & 0xF) << 8;
u32 r31 = curSrcPos[0] >> 4;
curSrcPos += 2;
copyStart = dst_buffer - local_28;
if (r31 == 0) {
copyByteCount = curSrcPos[0] + 0x12;
curSrcPos++;
} else {
copyByteCount = r31 + 2;
}
do {
if (dstSize == 0) {
dst_buffer[0] = copyStart[-1];
srcSize--;
dst_buffer++;
if (srcSize == 0)
return;
} else {
dstSize--;
}
copyByteCount--;
copyStart++;
} while (copyByteCount != 0);
}
chunkBits <<= 1;
chunkBitsLeft--;
} while (dst_buffer != decompEnd);
}
/* 802BEF08-802BEF58 .text checkCompressed__9JKRDecompFPUc */
void JKRDecomp::checkCompressed(unsigned char*) {
/* Nonmatching */
JKRCompression JKRDecomp::checkCompressed(u8* src) {
if ((src[0] == 'Y') && (src[1] == 'a') && (src[3] == '0')) {
if (src[2] == 'y') {
return COMPRESSION_YAY0;
}
if (src[2] == 'z') {
return COMPRESSION_YAZ0;
}
}
return COMPRESSION_NONE;
}
/* 802BEF58-802BEFA8 .text __ct__16JKRDecompCommandFv */
JKRDecompCommand::JKRDecompCommand() {
/* Nonmatching */
OSInitMessageQueue(&mMessageQueue, &mMessage, 1);
mCallback = NULL;
field_0x1c = NULL;
mThis = this;
field_0x20 = 0;
}
/* 802BEFA8-802BEFE4 .text __dt__16JKRDecompCommandFv */
JKRDecompCommand::~JKRDecompCommand() {
/* Nonmatching */
}
JKRDecompCommand::~JKRDecompCommand() {}
+1 -1
View File
@@ -8,7 +8,7 @@
#include "dolphin/vi/vi.h"
/* 802BC610-802BC6B4 .text read__7JKRFileFPvll */
s32 JKRFile::read(void* data, s32 length, long offset) {
s32 JKRFile::read(void* data, s32 length, s32 offset) {
JUT_ASSERT(34, ( length & 0x1f ) == 0);
while (true) {
s32 result = readData(data, length, offset);
+1 -1
View File
@@ -149,7 +149,7 @@ void* JKRFileCache::getResource(const char* path) {
}
/* 802B7564-802B7630 .text getResource__12JKRFileCacheFUlPCc */
void* JKRFileCache::getResource(unsigned long, const char* path) {
void* JKRFileCache::getResource(u32, const char* path) {
JUT_ASSERT(303, isMounted());
char finalPath[256];
+1 -1
View File
@@ -127,7 +127,7 @@ JKRFileLoader* JKRFileLoader::findVolume(const char** volumeName) {
static char rootPath[2] = "/";
/* 802B6B44-802B6C20 .text fetchVolumeName__13JKRFileLoaderFPclPCc */
const char* JKRFileLoader::fetchVolumeName(char* buffer, long bufferSize, const char* path) {
const char* JKRFileLoader::fetchVolumeName(char* buffer, s32 bufferSize, const char* path) {
if (strcmp(path, "/") == 0) {
strcpy(buffer, rootPath);
return rootPath;
+2 -2
View File
@@ -56,10 +56,10 @@ void JKRMemArchive::fixedInit(s32 param_1) {
/* 802B9740-802B9810 .text mountFixed__13JKRMemArchiveFPv15JKRMemBreakFlag */
bool JKRMemArchive::mountFixed(void* param_1, JKRMemBreakFlag param_2) {
if (check_mount_already((long)param_1)) {
if (check_mount_already((s32)param_1)) {
return false;
}
fixedInit((long)param_1);
fixedInit((s32)param_1);
if (!open(param_1, 0xffff, param_2)) {
return false;
}