diff --git a/include/JSystem/JKernel/JKRAram.h b/include/JSystem/JKernel/JKRAram.h index 039641f1c7c..03063ae07d8 100644 --- a/include/JSystem/JKernel/JKRAram.h +++ b/include/JSystem/JKernel/JKRAram.h @@ -10,7 +10,7 @@ class JKRAMCommand; class JKRAramBlock; class JKRAram : public JKRThread { private: - JKRAram(u32, u32, long); + JKRAram(u32, u32, s32); virtual ~JKRAram(); /* vt[03] */ void* run(void); /* override */ @@ -33,7 +33,7 @@ public: /* 0x98 */ u32 mStackArray[3]; public: - static JKRAram* create(u32, u32, long, long, long); + 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*); @@ -67,7 +67,7 @@ private: static JSUList sAramCommandList; }; -inline void* JKRAllocFromAram(u32 size, JKRAramHeap::EAllocMode allocMode) { +inline JKRAramBlock* JKRAllocFromAram(u32 size, JKRAramHeap::EAllocMode allocMode) { return JKRAram::getAramHeap()->alloc(size, allocMode); } diff --git a/include/JSystem/JKernel/JKRAramStream.h b/include/JSystem/JKernel/JKRAramStream.h index cc42bd6095c..9d815b300d6 100644 --- a/include/JSystem/JKernel/JKRAramStream.h +++ b/include/JSystem/JKernel/JKRAramStream.h @@ -37,13 +37,13 @@ public: class JKRAramStream : public JKRThread { private: - JKRAramStream(long); + JKRAramStream(s32); virtual ~JKRAramStream(); /* vt[03] */ void* run(void); /* override */ public: - static JKRAramStream* create(long); + static JKRAramStream* create(s32); static s32 readFromAram(void); static s32 writeToAram(JKRAramStreamCommand*); @@ -61,8 +61,12 @@ private: static JKRHeap* transHeap; }; -inline JKRAramStream* JKRCreateAramStreamManager(long priority) { +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); +} + #endif /* JKRARAMSTREAM_H */ diff --git a/include/JSystem/JKernel/JKRArchive.h b/include/JSystem/JKernel/JKRArchive.h index 2d839562380..ecd5e2b1b29 100644 --- a/include/JSystem/JKernel/JKRArchive.h +++ b/include/JSystem/JKernel/JKRArchive.h @@ -40,10 +40,6 @@ inline u16 read_big_endian_u16(void* ptr) { return ((u16)uptr[0] << 8) | ((u16)uptr[1]); } -inline u32 JKRDecompExpandSize(u8 * pBuf) { - return (pBuf[4] << 0x18) | (pBuf[5] << 0x10) | (pBuf[6] << 8) | pBuf[7]; -} - extern u32 sCurrentDirID__10JKRArchive; // JKRArchive::sCurrentDirID class JKRArchive : public JKRFileLoader { diff --git a/include/JSystem/JKernel/JKRAssertHeap.h b/include/JSystem/JKernel/JKRAssertHeap.h index 48a79d95e50..d0e8d876c72 100644 --- a/include/JSystem/JKernel/JKRAssertHeap.h +++ b/include/JSystem/JKernel/JKRAssertHeap.h @@ -5,7 +5,7 @@ class JKRAssertHeap : public JKRHeap { protected: - JKRAssertHeap(void*, unsigned long, JKRHeap*, bool); + JKRAssertHeap(void*, u32, JKRHeap*, bool); virtual ~JKRAssertHeap(); public: diff --git a/include/JSystem/JKernel/JKRDecomp.h b/include/JSystem/JKernel/JKRDecomp.h index 539695d2a60..161a667e18d 100644 --- a/include/JSystem/JKernel/JKRDecomp.h +++ b/include/JSystem/JKernel/JKRDecomp.h @@ -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); @@ -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); } @@ -69,4 +69,8 @@ inline JKRCompression JKRCheckCompressed_noASR(u8 *pBuf) { return compression; } +inline u32 JKRDecompExpandSize(u8* pBuf) { + return (pBuf[4] << 0x18) | (pBuf[5] << 0x10) | (pBuf[6] << 8) | pBuf[7]; +} + #endif /* JKRDECOMP_H */ diff --git a/include/JSystem/JKernel/JKRDvdAramRipper.h b/include/JSystem/JKernel/JKRDvdAramRipper.h index 201de6be4f0..15d133e58f9 100644 --- a/include/JSystem/JKernel/JKRDvdAramRipper.h +++ b/include/JSystem/JKernel/JKRDvdAramRipper.h @@ -20,10 +20,10 @@ public: /* 0x20 */ int field_0x20; /* 0x24 */ int field_0x24; /* 0x28 */ JKRDvdFile* mDvdFile; - /* 0x2C */ u32 field_0x2c; + /* 0x2C */ u32 mAddress; /* 0x30 */ JKRAramBlock* mBlock; - /* 0x34 */ int field_0x34; - /* 0x38 */ void (*field_0x38)(u32); + /* 0x34 */ JKRExpandSwitch mExpandSwitch; + /* 0x38 */ void (*mCallback)(u32); /* 0x3C */ u32 field_0x3c; /* 0x40 */ u32 field_0x40; /* 0x44 */ u32* field_0x44; @@ -35,7 +35,7 @@ public: class JKRDvdFile; class JKRDvdAramRipper { public: - static JKRAramBlock* loadToAram(long, u32, JKRExpandSwitch, u32, u32, u32*); + 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*); diff --git a/include/JSystem/JKernel/JKRDvdFile.h b/include/JSystem/JKernel/JKRDvdFile.h index 9fe03fda673..442ef026c68 100644 --- a/include/JSystem/JKernel/JKRDvdFile.h +++ b/include/JSystem/JKernel/JKRDvdFile.h @@ -15,7 +15,7 @@ class JKRDvdFile : public JKRFile { public: JKRDvdFile(); JKRDvdFile(const char*); - JKRDvdFile(long); + JKRDvdFile(s32); virtual ~JKRDvdFile(); void initiate(void); @@ -52,7 +52,7 @@ public: /* 0xF4 */ OSThread* mOSThread; public: - static void doneProcess(long, DVDFileInfo*); + static void doneProcess(s32, DVDFileInfo*); static JSUList& getDvdList() { return sDvdList; } diff --git a/include/JSystem/JKernel/JKRDvdRipper.h b/include/JSystem/JKernel/JKRDvdRipper.h index d5991e684b1..3e3d91b5d30 100644 --- a/include/JSystem/JKernel/JKRDvdRipper.h +++ b/include/JSystem/JKernel/JKRDvdRipper.h @@ -37,7 +37,7 @@ public: static void* loadToMainRAM(char const*, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection, u32, JKRCompression*, u32*); - static void* loadToMainRAM(long, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection, 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*); diff --git a/include/JSystem/JKernel/JKRFile.h b/include/JSystem/JKernel/JKRFile.h index 4e1be4db8a6..ed9d35a2c1c 100644 --- a/include/JSystem/JKernel/JKRFile.h +++ b/include/JSystem/JKernel/JKRFile.h @@ -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; } diff --git a/include/JSystem/JKernel/JKRFileLoader.h b/include/JSystem/JKernel/JKRFileLoader.h index c02dedc1043..9e05be16ab6 100644 --- a/include/JSystem/JKernel/JKRFileLoader.h +++ b/include/JSystem/JKernel/JKRFileLoader.h @@ -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; } diff --git a/libs/JSystem/JKernel/JKRAram.cpp b/libs/JSystem/JKernel/JKRAram.cpp index bb09b6f5672..fe4cbc77e8d 100644 --- a/libs/JSystem/JKernel/JKRAram.cpp +++ b/libs/JSystem/JKernel/JKRAram.cpp @@ -8,7 +8,6 @@ #include "JSystem/JKernel/JKRAramStream.h" #include "JSystem/JKernel/JKRDecomp.h" #include "JSystem/JKernel/JKRExpHeap.h" -#include "JSystem/JKernel/JKRArchive.h" #include "JSystem/JUtility/JUTException.h" #include "MSL_C/string.h" #include "dolphin/ar/ar.h" @@ -41,7 +40,7 @@ JKRAram* JKRAram::sAramObject; /* 802D1FA4-802D2040 2CC8E4 009C+00 0/0 1/1 0/0 .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) { + 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); @@ -66,7 +65,7 @@ OSMessage JKRAram::sMessageBuffer[4] = { OSMessageQueue JKRAram::sMessageQueue = {0}; /* 802D2040-802D214C 2CC980 010C+00 1/1 0/0 0/0 .text __ct__7JKRAramFUlUll */ -JKRAram::JKRAram(u32 audio_buffer_size, u32 audio_graph_size, long priority) +JKRAram::JKRAram(u32 audio_buffer_size, u32 audio_graph_size, s32 priority) : JKRThread(0xC00, 0x10, priority) { u32 aramBase = ARInit(mStackArray, ARRAY_SIZE(mStackArray)); ARQInit(); @@ -125,11 +124,11 @@ void* JKRAram::run(void) { * checkOkAddress__7JKRAramFPUcUlP12JKRAramBlockUl */ void JKRAram::checkOkAddress(u8* addr, u32 size, JKRAramBlock* block, u32 param_4) { if (!IS_ALIGNED((u32)addr, 0x20) && !IS_ALIGNED(size, 0x20)) { - JUTException::panic_f(__FILE__, 219, "%s", ":::address not 32Byte aligned."); + JUTException::panic(__FILE__, 219, ":::address not 32Byte aligned."); } if (block && !IS_ALIGNED((u32)block->getAddress() + param_4, 0x20)) { - JUTException::panic_f(__FILE__, 227, "%s", ":::address not 32Byte aligned."); + JUTException::panic(__FILE__, 227, ":::address not 32Byte aligned."); } } diff --git a/libs/JSystem/JKernel/JKRAramArchive.cpp b/libs/JSystem/JKernel/JKRAramArchive.cpp index d8d6670e17e..dc1c660f221 100644 --- a/libs/JSystem/JKernel/JKRAramArchive.cpp +++ b/libs/JSystem/JKernel/JKRAramArchive.cpp @@ -5,6 +5,7 @@ #include "JSystem/JKernel/JKRAramArchive.h" #include "JSystem/JKernel/JKRAram.h" +#include "JSystem/JKernel/JKRDecomp.h" #include "JSystem/JKernel/JKRDvdAramRipper.h" #include "JSystem/JKernel/JKRDvdFile.h" #include "JSystem/JUtility/JUTAssert.h" diff --git a/libs/JSystem/JKernel/JKRAramPiece.cpp b/libs/JSystem/JKernel/JKRAramPiece.cpp index 817628febe8..8e0929bc738 100644 --- a/libs/JSystem/JKernel/JKRAramPiece.cpp +++ b/libs/JSystem/JKernel/JKRAramPiece.cpp @@ -47,7 +47,7 @@ JKRAMCommand* JKRAramPiece::orderAsync(int direction, u32 source, u32 destinatio OSReport("source = %x\n", source); OSReport("destination = %x\n", destination); OSReport("length = %x\n", length); - JUTException::panic_f(__FILE__, 108, "%s", "illegal address. abort."); + JUTException::panic(__FILE__, 108, "illegal address. abort."); } Message* message = new (JKRHeap::getSystemHeap(), -4) Message(); diff --git a/libs/JSystem/JKernel/JKRAramStream.cpp b/libs/JSystem/JKernel/JKRAramStream.cpp index b79a1fe3e82..13a126be598 100644 --- a/libs/JSystem/JKernel/JKRAramStream.cpp +++ b/libs/JSystem/JKernel/JKRAramStream.cpp @@ -15,7 +15,7 @@ JKRAramStream* JKRAramStream::sAramStreamObject; /* 802D3B48-802D3BB8 2CE488 0070+00 0/0 1/1 0/0 .text create__13JKRAramStreamFl */ -JKRAramStream* JKRAramStream::create(long priority) { +JKRAramStream* JKRAramStream::create(s32 priority) { if (!sAramStreamObject) { sAramStreamObject = new (JKRGetSystemHeap(), 0) JKRAramStream(priority); setTransBuffer(NULL, 0, NULL); @@ -37,7 +37,7 @@ void* JKRAramStream::sMessageBuffer[4] = { OSMessageQueue JKRAramStream::sMessageQueue = {0}; /* 802D3BB8-802D3C08 2CE4F8 0050+00 1/1 0/0 0/0 .text __ct__13JKRAramStreamFl */ -JKRAramStream::JKRAramStream(long priority) : JKRThread(0xc00, 0x10, priority) { +JKRAramStream::JKRAramStream(s32 priority) : JKRThread(0xc00, 0x10, priority) { resume(); } @@ -107,7 +107,7 @@ s32 JKRAramStream::writeToAram(JKRAramStreamCommand* command) { heap->dump(); } - JUTException::panic_f(__FILE__, 172, "%s", ":::Cannot alloc memory\n"); + JUTException::panic(__FILE__, 172, ":::Cannot alloc memory\n"); } if (buffer) { diff --git a/libs/JSystem/JKernel/JKRDecomp.cpp b/libs/JSystem/JKernel/JKRDecomp.cpp index f73947751e8..3235ce13a8c 100644 --- a/libs/JSystem/JKernel/JKRDecomp.cpp +++ b/libs/JSystem/JKernel/JKRDecomp.cpp @@ -53,7 +53,7 @@ extern "C" u8 sSystemHeap__7JKRHeap[4]; /* 804514B0-804514B8 0009B0 0004+04 1/1 0/0 0/0 .sbss sDecompObject__9JKRDecomp */ JKRDecomp* JKRDecomp::sDecompObject; -JKRDecomp* JKRDecomp::create(long priority) { +JKRDecomp* JKRDecomp::create(s32 priority) { if (!sDecompObject) { sDecompObject = new (JKRHeap::getSystemHeap(), 0) JKRDecomp(priority); } @@ -69,7 +69,7 @@ OSMessage JKRDecomp::sMessageBuffer[8] = {0}; OSMessageQueue JKRDecomp::sMessageQueue = {0}; /* 802DB6E0-802DB730 2D6020 0050+00 1/1 0/0 0/0 .text __ct__9JKRDecompFl */ -JKRDecomp::JKRDecomp(long priority) : JKRThread(0x800, 0x10, priority) { +JKRDecomp::JKRDecomp(s32 priority) : JKRThread(0x800, 0x10, priority) { resume(); } diff --git a/libs/JSystem/JKernel/JKRDvdAramRipper.cpp b/libs/JSystem/JKernel/JKRDvdAramRipper.cpp index 8f5f39ae756..555c033fbbf 100644 --- a/libs/JSystem/JKernel/JKRDvdAramRipper.cpp +++ b/libs/JSystem/JKernel/JKRDvdAramRipper.cpp @@ -4,8 +4,11 @@ // #include "JSystem/JKernel/JKRDvdAramRipper.h" +#include "JSystem/JKernel/JKRAram.h" #include "JSystem/JKernel/JKRAramStream.h" +#include "JSystem/JKernel/JKRDecomp.h" #include "JSystem/JKernel/JKRDvdFile.h" +#include "JSystem/JSupport/JSUFileStream.h" #include "dol2asm.h" #include "dolphin/os/OSCache.h" #include "dolphin/os/OSInterrupt.h" @@ -90,23 +93,23 @@ extern "C" u8 sAramObject__7JKRAram[4]; /* 802DA874-802DA918 2D51B4 00A4+00 0/0 3/3 0/0 .text * loadToAram__16JKRDvdAramRipperFlUl15JKRExpandSwitchUlUlPUl */ -JKRAramBlock* JKRDvdAramRipper::loadToAram(s32 entryNumber, u32 param_1, JKRExpandSwitch param_2, +JKRAramBlock* JKRDvdAramRipper::loadToAram(s32 entryNumber, u32 address, JKRExpandSwitch expandSwitch, u32 param_3, u32 param_4, u32* param_5) { JKRDvdFile dvdFile; if (!dvdFile.open(entryNumber)) { return NULL; } else { - return loadToAram(&dvdFile, param_1, param_2, param_3, param_4, param_5); + return loadToAram(&dvdFile, address, expandSwitch, param_3, param_4, param_5); } } /* 802DA918-802DA9C0 2D5258 00A8+00 1/1 0/0 0/0 .text * loadToAram__16JKRDvdAramRipperFP10JKRDvdFileUl15JKRExpandSwitchUlUlPUl */ -JKRAramBlock* JKRDvdAramRipper::loadToAram(JKRDvdFile* dvdFile, u32 param_1, - JKRExpandSwitch param_2, u32 param_3, u32 param_4, +JKRAramBlock* JKRDvdAramRipper::loadToAram(JKRDvdFile* dvdFile, u32 address, + JKRExpandSwitch expandSwitch, u32 param_3, u32 param_4, u32* param_5) { JKRADCommand* command = - loadToAram_Async(dvdFile, param_1, param_2, NULL, param_3, param_4, param_5); + loadToAram_Async(dvdFile, address, expandSwitch, NULL, param_3, param_4, param_5); syncAram(command, 0); if (command->field_0x48 < 0) { @@ -114,7 +117,7 @@ JKRAramBlock* JKRDvdAramRipper::loadToAram(JKRDvdFile* dvdFile, u32 param_1, return NULL; } - if (param_1) { + if (address) { delete command; return (JKRAramBlock*)-1; } @@ -126,15 +129,15 @@ JKRAramBlock* JKRDvdAramRipper::loadToAram(JKRDvdFile* dvdFile, u32 param_1, /* 802DA9C0-802DAA74 2D5300 00B4+00 1/1 0/0 0/0 .text * loadToAram_Async__16JKRDvdAramRipperFP10JKRDvdFileUl15JKRExpandSwitchPFUl_vUlUlPUl */ -JKRADCommand* JKRDvdAramRipper::loadToAram_Async(JKRDvdFile* dvdFile, u32 param_1, - JKRExpandSwitch param_2, void (*param_3)(u32), +JKRADCommand* JKRDvdAramRipper::loadToAram_Async(JKRDvdFile* dvdFile, u32 address, + JKRExpandSwitch expandSwitch, void (*callback)(u32), u32 param_4, u32 param_5, u32* param_6) { JKRADCommand* command = new (JKRHeap::sSystemHeap, -4) JKRADCommand(); command->mDvdFile = dvdFile; - command->field_0x2c = param_1; + command->mAddress = address; command->mBlock = NULL; - command->field_0x34 = param_2; - command->field_0x38 = param_3; + command->mExpandSwitch = expandSwitch; + command->mCallback = callback; command->field_0x3c = param_4; command->field_0x40 = param_5; command->field_0x44 = param_6; @@ -161,10 +164,11 @@ SECTION_SDATA static u8 data_804508D0 = 0x01; * callCommand_Async__16JKRDvdAramRipperFP12JKRADCommand */ #ifdef NONMATCHING JKRADCommand* JKRDvdAramRipper::callCommand_Async(JKRADCommand* command) { + s32 compression; s32 uncompressedSize; bool bVar1 = true; JKRDvdFile* dvdFile = command->mDvdFile; - s32 compression = 0; + compression = 0; OSLockMutex(&dvdFile->mMutex2); if (command->field_0x44) { *command->field_0x44 = 0; @@ -174,18 +178,18 @@ JKRADCommand* JKRDvdAramRipper::callCommand_Async(JKRADCommand* command) { bVar1 = false; } else { dvdFile->field_0x50 = OSGetCurrentThread(); - JSUFileInputStream* stream = new (JKRHeap::sSystemHeap, -4) JSUFileInputStream(dvdFile); + JSUFileInputStream* stream = new (JKRGetSystemHeap(), -4) JSUFileInputStream(dvdFile); dvdFile->mFileStream = stream; u32 fileSize = dvdFile->getFileSize(); if (command->field_0x40 && fileSize > command->field_0x40) { fileSize = command->field_0x40; } fileSize = ALIGN_NEXT(fileSize, 0x20); - if (command->field_0x34 == 1) { + if (command->mExpandSwitch == 1) { u8 buffer[0x40]; u8* bufPtr = (u8*)ALIGN_NEXT((u32)&buffer, 0x20); while (true) { - if (DVDReadPrio(&dvdFile->mFileInfo, bufPtr, 0x20, 0, 2) >= 0) { + if (DVDReadPrio(dvdFile->getFileInfo(), bufPtr, 0x20, 0, 2) >= 0) { break; } @@ -197,76 +201,68 @@ JKRADCommand* JKRDvdAramRipper::callCommand_Async(JKRADCommand* command) { VIWaitForRetrace(); } DCInvalidateRange(bufPtr, 0x20); - JKRCompression tmpCompression = JKRDecomp::checkCompressed(bufPtr); - - if (tmpCompression == 3) { - tmpCompression = 0; - } - - compression = tmpCompression; - uncompressedSize = - bufPtr[4] << 0x18 | bufPtr[5] << 0x10 | bufPtr[6] << 0x08 | bufPtr[7]; - if (command->field_0x40 && command->field_0x40 < uncompressedSize) { + compression = JKRCheckCompressed_noASR(bufPtr); + uncompressedSize = JKRDecompExpandSize(bufPtr); + if (command->field_0x40 && uncompressedSize > command->field_0x40) { uncompressedSize = command->field_0x40; } } if (compression == 0) { - command->field_0x34 = 0; + command->mExpandSwitch = EXPAND_SWITCH_UNKNOWN0; } - if (command->field_0x34 == 1) { - if (command->field_0x2c == 0 && command->mBlock == NULL) { - command->mBlock = - JKRAram::getAramHeap()->alloc(uncompressedSize, JKRAramHeap::HEAD); + if (command->mExpandSwitch == EXPAND_SWITCH_UNKNOWN1) { + if (command->mAddress == 0 && command->mBlock == NULL) { + command->mBlock = JKRAllocFromAram(uncompressedSize, JKRAramHeap::HEAD); if (command->mBlock) { - command->field_0x2c = command->mBlock->mAddress; + command->mAddress = command->mBlock->getAddress(); } dvdFile->mBlock = command->mBlock; } if (command->mBlock) { - command->field_0x2c = command->mBlock->mAddress; + command->mAddress = command->mBlock->getAddress(); } - if (command->field_0x2c == 0) { + if (command->mAddress == 0) { dvdFile->field_0x50 = NULL; return NULL; } } else { - if (command->field_0x2c == 0 && !command->mBlock) { - command->mBlock = JKRAram::getAramHeap()->alloc(fileSize, JKRAramHeap::HEAD); + if (command->mAddress == 0 && !command->mBlock) { + command->mBlock = JKRAllocFromAram(fileSize, JKRAramHeap::HEAD); } if (command->mBlock) { - command->field_0x2c = command->mBlock->mAddress; + command->mAddress = command->mBlock->getAddress(); } - if (command->field_0x2c == 0) { + if (command->mAddress == 0) { dvdFile->field_0x50 = NULL; return NULL; } } if (compression == 0) { - command->mStreamCommand = JKRAramStream::write_StreamToAram_Async( - stream, command->field_0x2c, fileSize - command->field_0x3c, command->field_0x3c, - command->field_0x44); + command->mStreamCommand = + JKRStreamToAram_Async(stream, command->mAddress, fileSize - command->field_0x3c, + command->field_0x3c, NULL, command->field_0x44); } else if (compression == 1) { - command->mStreamCommand = JKRAramStream::write_StreamToAram_Async( - stream, command->field_0x2c, fileSize - command->field_0x3c, command->field_0x3c, - command->field_0x44); + command->mStreamCommand = + JKRStreamToAram_Async(stream, command->mAddress, fileSize - command->field_0x3c, + command->field_0x3c, NULL, command->field_0x44); } else if (compression == 2) { command->mStreamCommand = NULL; - JKRDecompressFromDVDToAram(command->mDvdFile, command->field_0x2c, fileSize, + JKRDecompressFromDVDToAram(command->mDvdFile, command->mAddress, fileSize, uncompressedSize, command->field_0x3c, 0, command->field_0x44); } - if (!command->field_0x38) { + if (!command->mCallback) { (*((JSUList*)&sDvdAramAsyncList)).append(&command->mLink); } else { - command->field_0x38((u32)command); + command->mCallback((u32)command); } } @@ -422,12 +418,12 @@ int JKRDecompressFromDVDToAram(JKRDvdFile* dvdFile, u32 param_1, u32 fileSize, u OSRestoreInterrupts(level); OSLockMutex(&decompMutex); u32 bufferSize = JKRDvdAramRipper::sSZSBufferSize; - szpBuf = (u8*)JKRHeap::sSystemHeap->alloc(bufferSize, 0x20); + szpBuf = (u8*)JKRAllocFromSysHeap(bufferSize, 0x20); szpEnd = szpBuf + bufferSize; - refBuf = (u8*)JKRHeap::sSystemHeap->alloc(0x1120, 0); + refBuf = (u8*)JKRAllocFromSysHeap(0x1120, 0); refEnd = refBuf + 0x1120; refCurrent = refBuf; - dmaBuf = (u8*)JKRHeap::sSystemHeap->alloc(0x100, 0x20); + dmaBuf = (u8*)JKRAllocFromSysHeap(0x100, 0x20); dmaEnd = dmaBuf + 0x100; dmaCurrent = dmaBuf; srcFile = dvdFile; diff --git a/libs/JSystem/JKernel/JKRDvdArchive.cpp b/libs/JSystem/JKernel/JKRDvdArchive.cpp index 0a0f682d423..4328aea2469 100644 --- a/libs/JSystem/JKernel/JKRDvdArchive.cpp +++ b/libs/JSystem/JKernel/JKRDvdArchive.cpp @@ -4,6 +4,7 @@ // #include "JSystem/JKernel/JKRDvdArchive.h" +#include "JSystem/JKernel/JKRDecomp.h" #include "JSystem/JKernel/JKRDvdFile.h" #include "JSystem/JKernel/JKRDvdRipper.h" #include "JSystem/JUtility/JUTAssert.h" diff --git a/libs/JSystem/JKernel/JKRDvdFile.cpp b/libs/JSystem/JKernel/JKRDvdFile.cpp index 2c43bd980b2..586f1c648b0 100644 --- a/libs/JSystem/JKernel/JKRDvdFile.cpp +++ b/libs/JSystem/JKernel/JKRDvdFile.cpp @@ -11,12 +11,12 @@ JSUList JKRDvdFile::sDvdList; /* 802D9584-802D95F8 2D3EC4 0074+00 0/0 3/3 0/0 .text __ct__10JKRDvdFileFv */ -JKRDvdFile::JKRDvdFile() : JKRFile(), mDvdLink(this) { +JKRDvdFile::JKRDvdFile() : mDvdLink(this) { initiate(); } /* 802D95F8-802D96A0 2D3F38 00A8+00 0/0 2/2 0/0 .text __ct__10JKRDvdFileFPCc */ -JKRDvdFile::JKRDvdFile(const char* name) : JKRFile(), mDvdLink(this) { +JKRDvdFile::JKRDvdFile(const char* name) : mDvdLink(this) { initiate(); bool result = open(name); mIsAvailable = result; @@ -28,7 +28,7 @@ JKRDvdFile::JKRDvdFile(const char* name) : JKRFile(), mDvdLink(this) { } /* 802D96A0-802D9748 2D3FE0 00A8+00 0/0 3/3 0/0 .text __ct__10JKRDvdFileFl */ -JKRDvdFile::JKRDvdFile(long entryNum) : JKRFile(), mDvdLink(this) { +JKRDvdFile::JKRDvdFile(s32 entryNum) : mDvdLink(this) { initiate(); bool result = open(entryNum); mIsAvailable = result; @@ -57,9 +57,9 @@ void JKRDvdFile::initiate(void) { } /* 802D9850-802D98C4 2D4190 0074+00 1/0 1/1 0/0 .text open__10JKRDvdFileFPCc */ -bool JKRDvdFile::open(const char* param_1) { +bool JKRDvdFile::open(const char* name) { if (!mIsAvailable) { - mIsAvailable = DVDOpen(param_1, &mFileInfo); + mIsAvailable = DVDOpen(name, &mFileInfo); if (mIsAvailable) { getDvdList().append(&mDvdLink); getStatus(); @@ -69,7 +69,7 @@ bool JKRDvdFile::open(const char* param_1) { } /* 802D98C4-802D9938 2D4204 0074+00 1/0 2/2 0/0 .text open__10JKRDvdFileFl */ -bool JKRDvdFile::open(long entryNum) { +bool JKRDvdFile::open(s32 entryNum) { if (!mIsAvailable) { mIsAvailable = DVDFastOpen(entryNum, &mFileInfo); if (mIsAvailable) { @@ -88,13 +88,13 @@ void JKRDvdFile::close() { mIsAvailable = false; getDvdList().remove(&mDvdLink); } else { - JUTException::panic_f(__FILE__, 213, "%s", "cannot close DVD file\n"); + JUTException::panic(__FILE__, 213, "cannot close DVD file\n"); } } } /* 802D99B4-802D9A68 2D42F4 00B4+00 1/0 0/0 0/0 .text readData__10JKRDvdFileFPvll */ -s32 JKRDvdFile::readData(void* param_1, long length, long param_3) { +s32 JKRDvdFile::readData(void* param_1, s32 length, s32 param_3) { /* clang-format off */ // The assert condition gets stringified as "( length & 0x1f ) == 0", // with out disabling clang-format the spaces in the condition will @@ -125,6 +125,9 @@ s32 JKRDvdFile::readData(void* param_1, long length, long param_3) { /* 802D9A68-802D9A70 2D43A8 0008+00 1/0 0/0 0/0 .text writeData__10JKRDvdFileFPCvll */ s32 JKRDvdFile::writeData(void const* param_0, s32 param_1, s32 param_2) { + /* clang-format off */ + JUT_ASSERT(344, ( length & 0x1f ) == 0); + /* clang-format on */ return -1; } @@ -139,7 +142,7 @@ s32 JKRDvdFile::sync(void) { } /* 802D9AC4-802D9AF8 2D4404 0034+00 1/1 0/0 0/0 .text doneProcess__10JKRDvdFileFlP11DVDFileInfo */ -void JKRDvdFile::doneProcess(long id, DVDFileInfo* fileInfo) { +void JKRDvdFile::doneProcess(s32 id, DVDFileInfo* fileInfo) { // fileInfo->field_0x3c looks like some kind of user pointer? JKRDvdFile* dvdFile = *(JKRDvdFile**)((u8*)fileInfo + 0x3c); OSSendMessage(&dvdFile->mMessageQueue2, (OSMessage)id, OS_MESSAGE_NOBLOCK); diff --git a/libs/JSystem/JKernel/JKRDvdRipper.cpp b/libs/JSystem/JKernel/JKRDvdRipper.cpp index c0caab11aa8..8d551690b3b 100644 --- a/libs/JSystem/JKernel/JKRDvdRipper.cpp +++ b/libs/JSystem/JKernel/JKRDvdRipper.cpp @@ -211,7 +211,7 @@ void* JKRDvdRipper::loadToMainRAM(JKRDvdFile* dvdFile, u8* dst, JKRExpandSwitch { JKRDecompressFromDVD(dvdFile, dst, fileSizeAligned, dstLength, 0, offset, param_8); } else { - JUTException::panic_f(__FILE__, 0x143, "%s", "Sorry, not applied for SZP archive."); + JUTException::panic(__FILE__, 0x143, "Sorry, not applied for SZP archive."); } return dst; } @@ -221,7 +221,7 @@ void* JKRDvdRipper::loadToMainRAM(JKRDvdFile* dvdFile, u8* dst, JKRExpandSwitch // s32 readoffset = startOffset; if (offset != 0) { - JUTException::panic_f(__FILE__, 0x14d, "%s", "Not support SZP with offset read"); + JUTException::panic(__FILE__, 0x14d, "Not support SZP with offset read"); } while (true) { diff --git a/libs/JSystem/JKernel/JKRExpHeap.cpp b/libs/JSystem/JKernel/JKRExpHeap.cpp index f30bc1d86e0..55be7f84f43 100644 --- a/libs/JSystem/JKernel/JKRExpHeap.cpp +++ b/libs/JSystem/JKernel/JKRExpHeap.cpp @@ -680,7 +680,7 @@ s32 JKRExpHeap::getTotalUsedSize() const { * appendUsedList__10JKRExpHeapFPQ210JKRExpHeap9CMemBlock */ void JKRExpHeap::appendUsedList(JKRExpHeap::CMemBlock* newblock) { if (!newblock) { - JUTException::panic_f(__FILE__, 1568, "%s", "bad appendUsedList\n"); + JUTException::panic(__FILE__, 1568, "bad appendUsedList\n"); } CMemBlock* block = mTailUsedList; @@ -824,7 +824,7 @@ void JKRExpHeap::joinTwoBlocks(CMemBlock* block) { if (endAddr > nextAddr) { JUTWarningConsole_f(":::Heap may be broken. (block = %x)", block); JKRGetCurrentHeap()->dump(); - JUTException::panic_f(__FILE__, 1820, "%s", "Bad Block\n"); + JUTException::panic(__FILE__, 1820, "Bad Block\n"); } if (endAddr == nextAddr) { diff --git a/libs/JSystem/JKernel/JKRFile.cpp b/libs/JSystem/JKernel/JKRFile.cpp index ab585d65868..9d6c51dcc69 100644 --- a/libs/JSystem/JKernel/JKRFile.cpp +++ b/libs/JSystem/JKernel/JKRFile.cpp @@ -7,7 +7,7 @@ #include "dolphin/vi/vi.h" /* 802D9518-802D9584 2D3E58 006C+00 0/0 2/2 0/0 .text read__7JKRFileFPvll */ -s32 JKRFile::read(void* data, s32 size, long offset) { +s32 JKRFile::read(void* data, s32 size, s32 offset) { while (true) { s32 result = readData(data, size, offset); if (size != result) diff --git a/libs/JSystem/JKernel/JKRFileCache.cpp b/libs/JSystem/JKernel/JKRFileCache.cpp index d77e26ddcde..91c6015c420 100644 --- a/libs/JSystem/JKernel/JKRFileCache.cpp +++ b/libs/JSystem/JKernel/JKRFileCache.cpp @@ -7,6 +7,7 @@ #include "JSystem/JKernel/JKRDvdFile.h" #include "JSystem/JKernel/JKRFileFinder.h" #include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JUtility/JUTAssert.h" #include "MSL_C/MSL_Common/Src/ctype.h" #include "MSL_C/string.h" #include "global.h" @@ -40,7 +41,7 @@ JKRFileCache* JKRFileCache::mount(const char* path, JKRHeap* heap, const char* p } /* 802D4AB4-802D4C70 2CF3F4 01BC+00 1/1 0/0 0/0 .text __ct__12JKRFileCacheFPCcPCc */ -JKRFileCache::JKRFileCache(const char* path, const char* volume) : mCacheBlockList() { +JKRFileCache::JKRFileCache(const char* path, const char* volume) { mParentHeap = JKRHeap::findFromRoot(this); mMountCount = 1; mVolumeType = 'CASH'; @@ -119,7 +120,7 @@ bool JKRFileCache::becomeCurrent(const char* path) { /* 802D4DD8-802D4EDC 2CF718 0104+00 1/0 0/0 0/0 .text getResource__12JKRFileCacheFPCc */ void* JKRFileCache::getResource(const char* path) { - ASSERT(isMounted()); + JUT_ASSERT(237, isMounted()); void* buffer = NULL; char* name = getDvdPathName(path); @@ -151,7 +152,7 @@ void* JKRFileCache::getResource(const char* path) { /* 802D4EDC-802D4F64 2CF81C 0088+00 1/0 0/0 0/0 .text getResource__12JKRFileCacheFUlPCc */ void* JKRFileCache::getResource(u32, const char* path) { - ASSERT(isMounted()); + JUT_ASSERT(303, isMounted()); char finalPath[256]; u32 rootLength = strlen(mRootPath); @@ -167,7 +168,7 @@ void* JKRFileCache::getResource(u32, const char* path) { /* 802D4F64-802D503C 2CF8A4 00D8+00 1/0 0/0 0/0 .text readResource__12JKRFileCacheFPvUlPCc */ u32 JKRFileCache::readResource(void* dst, u32 dstLength, const char* path) { - ASSERT(isMounted()); + JUT_ASSERT(412, isMounted()); char* name = getDvdPathName(path); JKRDvdFile dvdFile(name); @@ -176,8 +177,10 @@ u32 JKRFileCache::readResource(void* dst, u32 dstLength, const char* path) { // !@bug: (maybe?) Infinite Loop: Because dvdFile.isAvailable() is never updated in the loop-body // will would never exit the loop. -loop: - if (dvdFile.isAvailable()) { + while (true) { + if (!dvdFile.isAvailable()) { + break; + } u32 fileSize = dvdFile.getFileInfo()->length; resourceSize = ALIGN_NEXT(fileSize, 0x20); dstLength = ALIGN_PREV(dstLength, 0x20); @@ -191,7 +194,6 @@ loop: } else { memcpy(dst, cacheBlock->mMemoryPtr, resourceSize); } - goto loop; } JKRFreeToSysHeap(name); @@ -200,7 +202,7 @@ loop: /* 802D503C-802D50D4 2CF97C 0098+00 1/0 0/0 0/0 .text readResource__12JKRFileCacheFPvUlUlPCc */ u32 JKRFileCache::readResource(void* dst, u32 dstLength, u32, const char* path) { - ASSERT(isMounted()); + JUT_ASSERT(344, isMounted()); char finalPath[256]; u32 rootLength = strlen(mRootPath); @@ -217,7 +219,7 @@ u32 JKRFileCache::readResource(void* dst, u32 dstLength, u32, const char* path) /* 802D50D4-802D5164 2CFA14 0090+00 1/0 0/0 0/0 .text removeResourceAll__12JKRFileCacheFv */ void JKRFileCache::removeResourceAll(void) { - ASSERT(isMounted()); + JUT_ASSERT(412, isMounted()); JSUListIterator iterator; iterator = mCacheBlockList.getFirst(); @@ -232,7 +234,7 @@ void JKRFileCache::removeResourceAll(void) { /* 802D5164-802D51F8 2CFAA4 0094+00 1/0 0/0 0/0 .text removeResource__12JKRFileCacheFPv */ bool JKRFileCache::removeResource(void* resource) { - ASSERT(isMounted()); + JUT_ASSERT(463, isMounted()); CCacheBlock* cacheBlock = findCacheBlock(resource); if (!cacheBlock) @@ -252,7 +254,7 @@ bool JKRFileCache::removeResource(void* resource) { /* 802D51F8-802D526C 2CFB38 0074+00 1/0 0/0 0/0 .text detachResource__12JKRFileCacheFPv */ bool JKRFileCache::detachResource(void* resource) { - ASSERT(isMounted()); + JUT_ASSERT(490, isMounted()); CCacheBlock* cacheBlock = findCacheBlock(resource); if (!cacheBlock) @@ -265,8 +267,6 @@ bool JKRFileCache::detachResource(void* resource) { /* 802D526C-802D52A0 2CFBAC 0034+00 1/0 0/0 0/0 .text getResSize__12JKRFileCacheCFPCv */ u32 JKRFileCache::getResSize(const void* resource) const { - ASSERT(isMounted()); - CCacheBlock* cacheBlock = findCacheBlock(resource); if (cacheBlock == NULL) { return -1; @@ -277,8 +277,6 @@ u32 JKRFileCache::getResSize(const void* resource) const { /* 802D52A0-802D531C 2CFBE0 007C+00 1/0 0/0 0/0 .text countFile__12JKRFileCacheCFPCc */ u32 JKRFileCache::countFile(const char* path) const { - ASSERT(isMounted()); - DVDDirectory dir; DVDDirectoryEntry dirEntry; diff --git a/libs/JSystem/JKernel/JKRFileLoader.cpp b/libs/JSystem/JKernel/JKRFileLoader.cpp index 48bfba94388..0cf77638ee6 100644 --- a/libs/JSystem/JKernel/JKRFileLoader.cpp +++ b/libs/JSystem/JKernel/JKRFileLoader.cpp @@ -146,7 +146,7 @@ JKRFileLoader* JKRFileLoader::findVolume(const char** volumeName) { static char rootPath[2] = "/"; /* 802D44C4-802D45A0 2CEE04 00DC+00 1/1 0/0 0/0 .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;