mirror of
https://github.com/zeldaret/tp
synced 2026-05-23 06:54:28 -04:00
JKernel debug (#3012)
This commit is contained in:
@@ -21530,10 +21530,10 @@ sStickHigh = .sdata:0x80450898; // type:object size:0x4 scope:local align:4 data
|
||||
sStickCenter = .sdata:0x8045089C; // type:object size:0x4 scope:local align:4 data:float
|
||||
sHowlTobikusa = .sdata:0x804508A0; // type:object size:0x8 scope:local align:4
|
||||
cm2hw$539 = .sdata:0x804508A8; // type:object size:0x4 scope:local align:4
|
||||
data_804508B0 = .sdata:0x804508B0; // type:object size:0x1 scope:global align:4 data:byte
|
||||
sDefaultFillFlag__7JKRHeap = .sdata:0x804508B0; // type:object size:0x1 scope:global align:4 data:byte
|
||||
sSZSBufferSize__7JKRAram = .sdata:0x804508B8; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
rootPath = .sdata:0x804508C0; // type:object size:0x2 scope:local align:4 data:string
|
||||
errorRetry = .sdata:0x804508C8; // type:object size:0x1 scope:local align:1 data:byte
|
||||
errorRetry__12JKRDvdRipper = .sdata:0x804508C8; // type:object size:0x1 scope:local align:1 data:byte
|
||||
sSZSBufferSize__12JKRDvdRipper = .sdata:0x804508CC; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
errorRetry__16JKRDvdAramRipper = .sdata:0x804508D0; // type:object size:0x1 scope:global align:1 data:byte
|
||||
sSZSBufferSize__16JKRDvdAramRipper = .sdata:0x804508D4; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
@@ -22145,8 +22145,7 @@ DBnewFreeBlock = .sbss:0x804513A4; // type:object size:0x4 scope:local align:4 d
|
||||
DBnewUsedBlock = .sbss:0x804513A8; // type:object size:0x4 scope:local align:4 data:4byte
|
||||
sManager__15JKRThreadSwitch = .sbss:0x804513B0; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sTotalCount__15JKRThreadSwitch = .sbss:0x804513B4; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sTotalStart__15JKRThreadSwitch = .sbss:0x804513B8; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
data_804513BC = .sbss:0x804513BC; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sTotalStart__15JKRThreadSwitch = .sbss:0x804513B8; // type:object size:0x8 scope:global align:8 data:4byte
|
||||
mUserPreCallback__15JKRThreadSwitch = .sbss:0x804513C0; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
mUserPostCallback__15JKRThreadSwitch = .sbss:0x804513C4; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sAramObject__7JKRAram = .sbss:0x804513C8; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
|
||||
@@ -21559,10 +21559,10 @@ sStickHigh = .sdata:0x8044A9D8; // type:object size:0x4 scope:local align:4 data
|
||||
sStickCenter = .sdata:0x8044A9DC; // type:object size:0x4 scope:local align:4 data:float
|
||||
sHowlTobikusa = .sdata:0x8044A9E0; // type:object size:0x8 scope:local align:4
|
||||
cm2hw$539 = .sdata:0x8044A9E8; // type:object size:0x4 scope:local align:4
|
||||
data_804508B0 = .sdata:0x8044A9F0; // type:object size:0x1 data:byte
|
||||
sDefaultFillFlag__7JKRHeap = .sdata:0x8044A9F0; // type:object size:0x1 data:byte
|
||||
sSZSBufferSize__7JKRAram = .sdata:0x8044A9F8; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
rootPath = .sdata:0x8044AA00; // type:object size:0x2 scope:local align:4 data:string
|
||||
errorRetry = .sdata:0x8044AA08; // type:object size:0x1 scope:local data:byte
|
||||
errorRetry__12JKRDvdRipper = .sdata:0x8044AA08; // type:object size:0x1 scope:local data:byte
|
||||
sSZSBufferSize__12JKRDvdRipper = .sdata:0x8044AA0C; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
errorRetry__16JKRDvdAramRipper = .sdata:0x8044AA10; // type:object size:0x1 data:byte
|
||||
sSZSBufferSize__16JKRDvdAramRipper = .sdata:0x8044AA14; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
@@ -22174,8 +22174,7 @@ DBnewFreeBlock = .sbss:0x8044B4E4; // type:object size:0x4 scope:local align:4 d
|
||||
DBnewUsedBlock = .sbss:0x8044B4E8; // type:object size:0x4 scope:local align:4 data:4byte
|
||||
sManager__15JKRThreadSwitch = .sbss:0x8044B4F0; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sTotalCount__15JKRThreadSwitch = .sbss:0x8044B4F4; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sTotalStart__15JKRThreadSwitch = .sbss:0x8044B4F8; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
data_804513BC = .sbss:0x8044B4FC; // type:object size:0x4 scope:local data:4byte
|
||||
sTotalStart__15JKRThreadSwitch = .sbss:0x8044B4F8; // type:object size:0x8 scope:global align:8 data:4byte
|
||||
mUserPreCallback__15JKRThreadSwitch = .sbss:0x8044B500; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
mUserPostCallback__15JKRThreadSwitch = .sbss:0x8044B504; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sAramObject__7JKRAram = .sbss:0x8044B508; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
|
||||
@@ -21571,10 +21571,10 @@ sStickHigh = .sdata:0x80452858; // type:object size:0x4 scope:local align:4 data
|
||||
sStickCenter = .sdata:0x8045285C; // type:object size:0x4 scope:local align:4 data:float
|
||||
sHowlTobikusa = .sdata:0x80452860; // type:object size:0x8 scope:local align:4
|
||||
cm2hw$539 = .sdata:0x80452868; // type:object size:0x4 scope:local align:4
|
||||
data_804508B0 = .sdata:0x80452870; // type:object size:0x1 data:byte
|
||||
sDefaultFillFlag__7JKRHeap = .sdata:0x80452870; // type:object size:0x1 data:byte
|
||||
sSZSBufferSize__7JKRAram = .sdata:0x80452878; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
rootPath = .sdata:0x80452880; // type:object size:0x2 scope:local align:4 data:string
|
||||
errorRetry = .sdata:0x80452888; // type:object size:0x1 scope:local data:byte
|
||||
errorRetry__12JKRDvdRipper = .sdata:0x80452888; // type:object size:0x1 scope:local data:byte
|
||||
sSZSBufferSize__12JKRDvdRipper = .sdata:0x8045288C; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
errorRetry__16JKRDvdAramRipper = .sdata:0x80452890; // type:object size:0x1 data:byte
|
||||
sSZSBufferSize__16JKRDvdAramRipper = .sdata:0x80452894; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
@@ -22187,8 +22187,7 @@ DBnewFreeBlock = .sbss:0x8045336C; // type:object size:0x4 scope:local align:4 d
|
||||
DBnewUsedBlock = .sbss:0x80453370; // type:object size:0x4 scope:local align:4 data:4byte
|
||||
sManager__15JKRThreadSwitch = .sbss:0x80453378; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sTotalCount__15JKRThreadSwitch = .sbss:0x8045337C; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sTotalStart__15JKRThreadSwitch = .sbss:0x80453380; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
data_804513BC = .sbss:0x80453384; // type:object size:0x4 scope:local align:4 data:4byte
|
||||
sTotalStart__15JKRThreadSwitch = .sbss:0x80453380; // type:object size:0x8 scope:global align:8 data:4byte
|
||||
mUserPreCallback__15JKRThreadSwitch = .sbss:0x80453388; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
mUserPostCallback__15JKRThreadSwitch = .sbss:0x8045338C; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
sAramObject__7JKRAram = .sbss:0x80453390; // type:object size:0x4 scope:global align:4 data:4byte
|
||||
|
||||
@@ -3151,7 +3151,7 @@ Z2AudioCSD/Z2AudioCS.cpp:
|
||||
|
||||
revolution/gf/GFGeometry.cpp:
|
||||
.text start:0x804F8AE0 end:0x804F8CB0
|
||||
.sdata start:0x8074A8B0 end:0x8074A8BC
|
||||
.sdata start:0x8074A8B0 end:0x8074A8B8
|
||||
|
||||
revolution/gf/GFLight.cpp:
|
||||
.text start:0x804F8CB0 end:0x804F8D20
|
||||
@@ -3167,7 +3167,7 @@ revolution/gf/GFTev.cpp:
|
||||
JSystem/JKernel/JKRHeap.cpp:
|
||||
.text start:0x804F91A0 end:0x804FB0C0
|
||||
.data start:0x8070CF60 end:0x8070D2C0
|
||||
.sdata start:0x8074A8BC end:0x8074A8F8
|
||||
.sdata start:0x8074A8B8 end:0x8074A8F8
|
||||
.sbss start:0x8074CE20 end:0x8074CE58
|
||||
|
||||
JSystem/JKernel/JKRStdHeap.cpp:
|
||||
@@ -3294,7 +3294,7 @@ JSystem/JKernel/JKRDvdFile.cpp:
|
||||
.text start:0x8050B7F0 end:0x8050C090
|
||||
.ctors start:0x8062F9BC end:0x8062F9C0
|
||||
.data start:0x8070E8D0 end:0x8070E988
|
||||
.sdata start:0x8074AAA0 end:0x8074AAC4
|
||||
.sdata start:0x8074AAA0 end:0x8074AAC0
|
||||
.bss start:0x807E2000 end:0x807E2018
|
||||
|
||||
JSystem/JKernel/JKRRelocation.cpp:
|
||||
@@ -3304,7 +3304,7 @@ JSystem/JKernel/JKRDvdRipper.cpp:
|
||||
.text start:0x8050C100 end:0x8050D0B0
|
||||
.ctors start:0x8062F9C0 end:0x8062F9C4
|
||||
.data start:0x8070E988 end:0x8070EA10
|
||||
.sdata start:0x8074AAC4 end:0x8074AAD4
|
||||
.sdata start:0x8074AAC0 end:0x8074AAD0
|
||||
.sbss start:0x8074CEF0 end:0x8074CF30
|
||||
.bss start:0x807E2018 end:0x807E2048
|
||||
|
||||
@@ -3312,7 +3312,7 @@ JSystem/JKernel/JKRDvdAramRipper.cpp:
|
||||
.text start:0x8050D0B0 end:0x8050E3E0
|
||||
.ctors start:0x8062F9C4 end:0x8062F9C8
|
||||
.data start:0x8070EA10 end:0x8070EA60
|
||||
.sdata start:0x8074AAD4 end:0x8074AAE0
|
||||
.sdata start:0x8074AAD0 end:0x8074AAE0
|
||||
.sbss start:0x8074CF30 end:0x8074CF78
|
||||
.bss start:0x807E2048 end:0x807E2078
|
||||
|
||||
|
||||
@@ -63199,10 +63199,10 @@ __RTTI__11Z2TrackView = .sdata:0x8074A798; // type:object size:0x8 scope:global
|
||||
@STRING@getName__8SpkTableFl@6 = .sdata:0x8074A89C; // type:object size:0x5 scope:local data:string hash:0x137611D3 dhash:0x073DA070
|
||||
@STRING@getName__8SpkTableFl@2 = .sdata:0x8074A8A4; // type:object size:0x5 scope:local data:string hash:0x137611D7 dhash:0x073DA070
|
||||
@LOCAL@GFSetGenMode2__FUcUcUcUc11_GXCullMode@cm2hw = .sdata:0x8074A8B0; // type:object size:0x4 scope:local hash:0x2556FA26 dhash:0x539006AE
|
||||
lbl_8074A8B8 = .sdata:0x8074A8B8; // type:object size:0x1 data:byte hash:0xE5885B95
|
||||
lbl_8074A8B9 = .sdata:0x8074A8B9; // type:object size:0x1 data:byte hash:0xA67FA7FF
|
||||
lbl_8074A8BA = .sdata:0x8074A8BA; // type:object size:0x1 data:byte hash:0xE1465DBA
|
||||
lbl_8074A8BB = .sdata:0x8074A8BB; // type:object size:0x1 data:byte hash:0x945B0366 dhash:0x9612ACB1
|
||||
JKRValue_DEBUGFILL_NOTUSE = .sdata:0x8074A8B8; // type:object size:0x1 data:byte hash:0xE5885B95
|
||||
JKRValue_DEBUGFILL_NEW = .sdata:0x8074A8B9; // type:object size:0x1 data:byte hash:0xA67FA7FF
|
||||
JKRValue_DEBUGFILL_DELETE = .sdata:0x8074A8BA; // type:object size:0x1 data:byte hash:0xE1465DBA
|
||||
sDefaultFillFlag__7JKRHeap = .sdata:0x8074A8BB; // type:object size:0x1 data:byte hash:0x945B0366 dhash:0x9612ACB1
|
||||
@14089 = .sdata:0x8074A8BC; // type:object size:0x5 scope:local data:string hash:0xA05FF031
|
||||
@14456 = .sdata:0x8074A8C4; // type:object size:0x7 scope:local data:string hash:0xA05FFF97
|
||||
fillcheck_dispcount = .sdata:0x8074A8CC; // type:object size:0x4 scope:global data:4byte hash:0x731C7E5E
|
||||
@@ -63271,10 +63271,10 @@ __RTTI__14JKRCompArchive = .sdata:0x8074AA90; // type:object size:0x8 scope:glob
|
||||
__RTTI__10JKRDvdFile = .sdata:0x8074AAA8; // type:object size:0x8 scope:global hash:0xA39B169C dhash:0x1A927B5D
|
||||
@21252 = .sdata:0x8074AAB0; // type:object size:0x8 scope:local data:string hash:0xA0B9E533
|
||||
__RTTI__7JKRFile = .sdata:0x8074AAB8; // type:object size:0x8 scope:global hash:0x8C1DDA5C dhash:0x58EDFE0B
|
||||
lbl_8074AAC0 = .sdata:0x8074AAC0; // type:object size:0x1 data:byte hash:0x9B09263F dhash:0xB4D2E83C
|
||||
errorRetry__12JKRDvdRipper = .sdata:0x8074AAC0; // type:object size:0x1 data:byte hash:0x9B09263F dhash:0xB4D2E83C
|
||||
sSZSBufferSize__12JKRDvdRipper = .sdata:0x8074AAC4; // type:object size:0x4 scope:global data:4byte hash:0x2ED3E403 dhash:0xB48264C0
|
||||
@14372 = .sdata:0x8074AAC8; // type:object size:0x5 scope:local data:string hash:0xA0600416
|
||||
lbl_8074AAD0 = .sdata:0x8074AAD0; // type:object size:0x1 data:byte hash:0xBB6B9A04 dhash:0x9C59CC43
|
||||
errorRetry__16JKRDvdAramRipper = .sdata:0x8074AAD0; // type:object size:0x1 data:byte hash:0xBB6B9A04 dhash:0x9C59CC43
|
||||
sSZSBufferSize__16JKRDvdAramRipper = .sdata:0x8074AAD4; // type:object size:0x4 scope:global data:4byte hash:0xBC3A40B8 dhash:0xE4EAFC7F
|
||||
@5746 = .sdata:0x8074AAD8; // type:object size:0x5 scope:local data:string hash:0x0C9C0385
|
||||
@4000 = .sdata:0x8074AAE0; // type:object size:0x5 scope:local data:string hash:0x0C9D8B61
|
||||
|
||||
@@ -50,14 +50,13 @@ public:
|
||||
static JSUList<JKRAMCommand>& getCommandList() { return sAramCommandList; }
|
||||
|
||||
static u8 decideAramGroupId(int groupId) {
|
||||
JKRAramHeap* heap;
|
||||
u8 finalGroupId;
|
||||
|
||||
if (groupId < 0) {
|
||||
return getAramHeap()->getCurrentGroupID();
|
||||
finalGroupId = getAramHeap()->getCurrentGroupID();
|
||||
} else {
|
||||
finalGroupId = groupId;
|
||||
}
|
||||
|
||||
return (u8)groupId;
|
||||
return finalGroupId;
|
||||
}
|
||||
|
||||
static u32 getSZSBufferSize() { return sSZSBufferSize; }
|
||||
|
||||
@@ -12,9 +12,12 @@ class JKRFile;
|
||||
*/
|
||||
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*);
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
/* 0x18 */ u32 mSize;
|
||||
/* 0x1C */ u32 mFreeSize;
|
||||
/* 0x20 */ u8 mGroupId;
|
||||
/* 0x21 */ u8 mIsTempMemory;
|
||||
/* 0x21 */ bool mIsTempMemory;
|
||||
/* 0x22 */ u8 padding[2];
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
// TODO: fix type
|
||||
static JSUList<JKRAramBlock> sAramList;
|
||||
|
||||
JKRAramHeap(u32, u32);
|
||||
|
||||
@@ -42,6 +42,16 @@ public:
|
||||
/* 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
|
||||
*
|
||||
@@ -52,12 +62,6 @@ public:
|
||||
// TODO: fix type
|
||||
static JSUList<JKRAMCommand> sAramPieceCommandList;
|
||||
|
||||
public:
|
||||
struct Message {
|
||||
s32 field_0x00;
|
||||
JKRAMCommand* command;
|
||||
};
|
||||
|
||||
public:
|
||||
static JKRAMCommand* prepareCommand(int, u32, u32, u32, JKRAramBlock*,
|
||||
JKRAMCommand::AsyncCallback);
|
||||
@@ -74,6 +78,10 @@ private:
|
||||
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);
|
||||
|
||||
@@ -77,8 +77,16 @@ inline JKRAramStreamCommand* JKRStreamToAram_Async(JSUFileInputStream *stream, u
|
||||
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 */
|
||||
|
||||
@@ -186,7 +186,7 @@ public:
|
||||
/* 0x48 */ SDIDirEntry* mNodes;
|
||||
/* 0x4C */ SDIFileEntry* mFiles;
|
||||
/* 0x50 */ s32* mExpandedSize;
|
||||
/* 0x54 */ char* mStringTable;
|
||||
/* 0x54 */ const char* mStringTable;
|
||||
|
||||
protected:
|
||||
/* 0x58 */ u32 field_0x58;
|
||||
@@ -200,29 +200,27 @@ public:
|
||||
static JKRArchive* mount(s32, EMountMode, JKRHeap*, EMountDirection);
|
||||
static void* getGlbResource(u32, const char*, JKRArchive*);
|
||||
|
||||
static JKRCompression convertAttrToCompressionType(u32 attr) {
|
||||
static JKRCompression convertAttrToCompressionType(int attr) {
|
||||
#define JKRARCHIVE_ATTR_COMPRESSION 0x04
|
||||
#define JKRARCHIVE_ATTR_YAZ0 0x80
|
||||
|
||||
JKRCompression compression;
|
||||
if (!(attr & JKRARCHIVE_ATTR_COMPRESSION)) {
|
||||
compression = COMPRESSION_NONE;
|
||||
return COMPRESSION_NONE;
|
||||
} else if (attr & JKRARCHIVE_ATTR_YAZ0) {
|
||||
compression = COMPRESSION_YAZ0;
|
||||
return COMPRESSION_YAZ0;
|
||||
} else {
|
||||
compression = COMPRESSION_YAY0;
|
||||
return COMPRESSION_YAY0;
|
||||
}
|
||||
return compression;
|
||||
}
|
||||
|
||||
static u32 getCurrentDirID() { return sCurrentDirID; }
|
||||
static void setCurrentDirID(u32 dirID) { sCurrentDirID = dirID; }
|
||||
|
||||
private:
|
||||
protected:
|
||||
static u32 sCurrentDirID;
|
||||
};
|
||||
|
||||
inline JKRCompression JKRConvertAttrToCompressionType(u32 attr) {
|
||||
inline JKRCompression JKRConvertAttrToCompressionType(int attr) {
|
||||
return JKRArchive::convertAttrToCompressionType(attr);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define JKRASSERTHEAP_H
|
||||
|
||||
#include "JSystem/JKernel/JKRHeap.h"
|
||||
#include "JSystem/JUtility/JUTAssert.h"
|
||||
|
||||
/**
|
||||
* @ingroup jsystem-jkernel
|
||||
@@ -18,18 +19,19 @@ public:
|
||||
/* vt[06] */ virtual bool dump_sort(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[19] */ virtual s32 do_changeGroupID(u8 param_1); /* override */
|
||||
/* vt[20] */ virtual u8 do_getCurrentGroupId(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*);
|
||||
|
||||
@@ -82,4 +82,8 @@ 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 */
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
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; }
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
u32 getFileID() const { return mFileInfo.startAddr; }
|
||||
DVDFileInfo* getFileInfo() { return &mFileInfo; }
|
||||
int getStatus() { return DVDGetCommandBlockStatus(&mFileInfo.cb); }
|
||||
int getStatus() const { return DVDGetCommandBlockStatus(&mFileInfo.cb); }
|
||||
|
||||
public:
|
||||
/* vt[03] */ virtual bool open(const char*); /* override */
|
||||
|
||||
@@ -35,6 +35,7 @@ class JKRDvdRipper {
|
||||
public:
|
||||
static JSUList<JKRDMCommand> sDvdAsyncList;
|
||||
static u32 sSZSBufferSize;
|
||||
static bool errorRetry;
|
||||
|
||||
enum EAllocDirection {
|
||||
UNKNOWN_EALLOC_DIRECTION = 0,
|
||||
@@ -51,12 +52,20 @@ public:
|
||||
static void* loadToMainRAM(JKRDvdFile*, u8*, JKRExpandSwitch, u32, JKRHeap*, EAllocDirection,
|
||||
u32, JKRCompression*, u32*);
|
||||
|
||||
static u8 isErrorRetry(void);
|
||||
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) {
|
||||
|
||||
@@ -63,7 +63,7 @@ protected:
|
||||
void joinTwoBlocks(CMemBlock* block);
|
||||
|
||||
public:
|
||||
s32 isEmpty();
|
||||
BOOL isEmpty();
|
||||
s32 getUsedSize(u8 groupId) const;
|
||||
s32 getTotalUsedSize(void) const;
|
||||
|
||||
@@ -110,6 +110,9 @@ 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) {
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
JKRFile() : mIsAvailable(false) {}
|
||||
virtual ~JKRFile() {}
|
||||
|
||||
s32 read(void*, s32, s32);
|
||||
void read(void*, s32, s32);
|
||||
|
||||
bool isAvailable() const { return mIsAvailable; }
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ public:
|
||||
JKRFileLoader(void);
|
||||
virtual ~JKRFileLoader();
|
||||
|
||||
bool isMounted() const { return this->mIsMounted; }
|
||||
u32 getVolumeType() const { return this->mVolumeType; }
|
||||
bool isMounted() { return this->mIsMounted; }
|
||||
u32 getVolumeType() { return this->mVolumeType; }
|
||||
|
||||
public:
|
||||
/* vt[03] */ virtual void unmount(void);
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
class JKRHeap;
|
||||
typedef void (*JKRErrorHandler)(void*, u32, int);
|
||||
|
||||
extern bool data_804508B0;
|
||||
extern u8 data_804508B1;
|
||||
extern u8 data_804508B2;
|
||||
extern u8 data_804508B3;
|
||||
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
|
||||
@@ -19,6 +21,9 @@ extern u8 data_804508B3;
|
||||
*/
|
||||
class JKRHeap : public JKRDisposer {
|
||||
public:
|
||||
typedef void (*JKRAllocCallback)(u32, int, JKRHeap*, void*);
|
||||
typedef void (*JKRFreeCallback)(void*, JKRHeap*);
|
||||
|
||||
class TState {
|
||||
public:
|
||||
/* 0x00 */ u32 mUsedSize;
|
||||
@@ -54,6 +59,7 @@ public:
|
||||
void* getMaxFreeBlock();
|
||||
s32 getTotalFreeSize();
|
||||
s32 changeGroupID(u8 newGroupId);
|
||||
u8 getCurrentGroupId();
|
||||
u32 getMaxAllocatableSize(int alignment);
|
||||
|
||||
JKRHeap* find(void* ptr) const;
|
||||
@@ -96,13 +102,13 @@ public:
|
||||
void* getEndAddr() { return (void*)mEnd; }
|
||||
u32 getSize() const { return mSize; }
|
||||
bool getErrorFlag() const { return mErrorFlag; }
|
||||
void callErrorHandler(JKRHeap* heap, u32 size, int alignment) {
|
||||
void callErrorHandler(void* heap, u32 size, int alignment) {
|
||||
if (mErrorHandler) {
|
||||
(*mErrorHandler)(heap, size, alignment);
|
||||
}
|
||||
}
|
||||
|
||||
JKRHeap* getParent() const {
|
||||
JKRHeap* getParent() {
|
||||
JSUTree<JKRHeap>* parent = mChildTree.getParent();
|
||||
return parent->getObject();
|
||||
}
|
||||
@@ -110,8 +116,8 @@ public:
|
||||
JSUTree<JKRHeap>& getHeapTree() { return mChildTree; }
|
||||
void appendDisposer(JKRDisposer* disposer) { mDisposerList.append(&disposer->mLink); }
|
||||
void removeDisposer(JKRDisposer* disposer) { mDisposerList.remove(&disposer->mLink); }
|
||||
void lock() { OSLockMutex(&mMutex); }
|
||||
void unlock() { OSUnlockMutex(&mMutex); }
|
||||
void lock() const { OSLockMutex(const_cast<OSMutex*>(&mMutex)); }
|
||||
void unlock() const { OSUnlockMutex(const_cast<OSMutex*>(&mMutex)); }
|
||||
u32 getHeapSize() { return mSize; }
|
||||
u8 getCurrentGroupId() { return 0; }
|
||||
|
||||
@@ -133,6 +139,7 @@ protected:
|
||||
|
||||
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);
|
||||
@@ -144,8 +151,11 @@ public:
|
||||
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 void setDefaultDebugFill(bool status) { data_804508B0 = status; }
|
||||
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; }
|
||||
@@ -166,13 +176,16 @@ public:
|
||||
state->mCheckCode = checkCode;
|
||||
}
|
||||
static void* getState_buf_(TState* state) { return &state->mBuf; }
|
||||
static void* getState_(TState* state) { return getState_buf_(state); }
|
||||
|
||||
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;
|
||||
|
||||
@@ -206,8 +219,7 @@ inline void* JKRAllocFromHeap(JKRHeap* heap, u32 size, int alignment) {
|
||||
}
|
||||
|
||||
inline void* JKRAllocFromSysHeap(u32 size, int alignment) {
|
||||
JKRHeap* systemHeap = JKRHeap::getSystemHeap();
|
||||
return systemHeap->alloc(size, alignment);
|
||||
return JKRHeap::getSystemHeap()->alloc(size, alignment);
|
||||
}
|
||||
|
||||
inline void JKRFreeToHeap(JKRHeap* heap, void* ptr) {
|
||||
@@ -215,14 +227,17 @@ inline void JKRFreeToHeap(JKRHeap* heap, void* ptr) {
|
||||
}
|
||||
|
||||
inline void JKRFreeToSysHeap(void* ptr) {
|
||||
JKRHeap* systemHeap = JKRHeap::getSystemHeap();
|
||||
systemHeap->free(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();
|
||||
}
|
||||
@@ -268,9 +283,9 @@ inline JKRHeap* JKRGetRootHeap2() {
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
inline void JKRSetDebugFillNotuse(u8 status) { data_804508B1 = status; }
|
||||
inline void JKRSetDebugFillNew(u8 status) { data_804508B2 = status; }
|
||||
inline void JKRSetDebugFillDelete(u8 status) { data_804508B3 = status; }
|
||||
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 */
|
||||
|
||||
@@ -59,6 +59,8 @@ 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) {
|
||||
|
||||
@@ -117,7 +117,7 @@ private:
|
||||
/* 0x28 */ JKRHeap* mHeap;
|
||||
/* 0x2C */ OSThread* mThreadRecord;
|
||||
/* 0x30 */ OSMessageQueue mMessageQueue;
|
||||
/* 0x50 */ OSMessage* mMessages;
|
||||
/* 0x50 */ OSMessage* mMesgBuffer;
|
||||
/* 0x54 */ s32 mMessageCount;
|
||||
/* 0x58 */ void* mStackMemory;
|
||||
/* 0x5C */ u32 mStackSize;
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
private:
|
||||
static JKRThreadSwitch* sManager;
|
||||
static u32 sTotalCount;
|
||||
static u32 sTotalStart;
|
||||
static u64 sTotalStart;
|
||||
static JKRThreadSwitch_PreCallback mUserPreCallback;
|
||||
static JKRThreadSwitch_PostCallback mUserPostCallback;
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
T* getObject() { return this->mLink->getObject(); }
|
||||
T* getObject() const { return this->mLink->getObject(); }
|
||||
|
||||
bool operator==(JSULink<T> const* other) const { return this->mLink == other; }
|
||||
bool operator!=(JSULink<T> const* other) const { return this->mLink != other; }
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
#include <dolphin/os.h>
|
||||
#include "string.h"
|
||||
|
||||
#if PLATFORM_GCN
|
||||
const u32 stack_size = 0xc00;
|
||||
#else
|
||||
const u32 stack_size = 0x4000;
|
||||
#endif
|
||||
|
||||
static u8* firstSrcData();
|
||||
static u8* nextSrcData(u8* param_0);
|
||||
static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32 dstLength,
|
||||
@@ -21,7 +27,7 @@ JKRAram* JKRAram::sAramObject;
|
||||
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)
|
||||
sAramObject = new (JKRGetSystemHeap(), 0)
|
||||
JKRAram(aram_audio_buffer_size, aram_audio_graph_size, piece_priority);
|
||||
}
|
||||
|
||||
@@ -41,11 +47,12 @@ OSMessage JKRAram::sMessageBuffer[4] = {
|
||||
OSMessageQueue JKRAram::sMessageQueue = {0};
|
||||
|
||||
JKRAram::JKRAram(u32 audio_buffer_size, u32 audio_graph_size, s32 priority)
|
||||
: JKRThread(0xC00, 0x10, priority) {
|
||||
: JKRThread(stack_size, 0x10, priority) {
|
||||
u32 aramBase = ARInit(mStackArray, ARRAY_SIZEU(mStackArray));
|
||||
ARQInit();
|
||||
|
||||
u32 aramSize = ARGetSize();
|
||||
OS_REPORT("ARAM size = %08x\n", aramSize);
|
||||
|
||||
mAudioMemorySize = audio_buffer_size;
|
||||
if (audio_graph_size == 0xFFFFFFFF) {
|
||||
@@ -65,7 +72,11 @@ JKRAram::JKRAram(u32 audio_buffer_size, u32 audio_graph_size, s32 priority)
|
||||
mAramMemoryPtr = NULL;
|
||||
}
|
||||
|
||||
mAramHeap = new (JKRHeap::getSystemHeap(), 0) JKRAramHeap(mGraphMemoryPtr, mGraphMemorySize);
|
||||
OS_REPORT("ARAM audio area %08x: %08x\n", mAudioMemoryPtr, mAudioMemorySize);
|
||||
OS_REPORT("ARAM graph area %08x: %08x\n", mGraphMemoryPtr, mGraphMemorySize);
|
||||
OS_REPORT("ARAM user area %08x: %08x\n", mAramMemoryPtr, mAramMemorySize);
|
||||
|
||||
mAramHeap = new (JKRGetSystemHeap(), 0) JKRAramHeap(mGraphMemoryPtr, mGraphMemorySize);
|
||||
}
|
||||
|
||||
JKRAram::~JKRAram() {
|
||||
@@ -75,14 +86,13 @@ JKRAram::~JKRAram() {
|
||||
}
|
||||
|
||||
void* JKRAram::run(void) {
|
||||
int result;
|
||||
JKRAMCommand* command;
|
||||
JKRAramPiece::Message* message;
|
||||
OSInitMessageQueue(&sMessageQueue, sMessageBuffer, 4);
|
||||
do {
|
||||
OSReceiveMessage(&sMessageQueue, (OSMessage*)&message, OS_MESSAGE_BLOCK);
|
||||
result = message->field_0x00;
|
||||
command = message->command;
|
||||
OSMessage msg;
|
||||
OSReceiveMessage(&sMessageQueue, &msg, OS_MESSAGE_BLOCK);
|
||||
JKRAramCommand* message = (JKRAramCommand*)msg;
|
||||
int result = message->field_0x00;
|
||||
JKRAMCommand* command = (JKRAMCommand*)message->command;
|
||||
delete message;
|
||||
|
||||
switch (result) {
|
||||
@@ -104,9 +114,9 @@ void JKRAram::checkOkAddress(u8* addr, u32 size, JKRAramBlock* block, u32 param_
|
||||
}
|
||||
|
||||
void JKRAram::changeGroupIdIfNeed(u8* data, int groupId) {
|
||||
JKRHeap* currentHeap = JKRHeap::getCurrentHeap();
|
||||
JKRHeap* currentHeap = JKRGetCurrentHeap();
|
||||
if (currentHeap->getHeapType() == 'EXPH' && groupId >= 0) {
|
||||
JKRExpHeap::CMemBlock* block = JKRExpHeap::CMemBlock::getBlock(data);
|
||||
JKRExpHeap::CMemBlock* block = (JKRExpHeap::CMemBlock*)(data - sizeof(JKRExpHeap::CMemBlock));
|
||||
block->newGroupId(groupId);
|
||||
}
|
||||
}
|
||||
@@ -127,54 +137,55 @@ JKRAramBlock* JKRAram::mainRamToAram(u8* buf, u32 bufSize, u32 alignedSize,
|
||||
fileSize = ALIGN_NEXT(expandSize, 32);
|
||||
}
|
||||
if (bufSize == 0) {
|
||||
JKRAramBlock* allocatedBlock =
|
||||
(JKRAramBlock*)JKRAllocFromAram(fileSize, JKRAramHeap::HEAD);
|
||||
block = (JKRAramBlock*)allocatedBlock;
|
||||
if (allocatedBlock == NULL)
|
||||
block = JKRAllocFromAram(fileSize, JKRAramHeap::HEAD);
|
||||
if (block == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
allocatedBlock->newGroupID(decideAramGroupId(id));
|
||||
bufSize = allocatedBlock->getAddress();
|
||||
block->newGroupID(decideAramGroupId(id));
|
||||
bufSize = block->getAddress();
|
||||
}
|
||||
if (alignedSize == 0 || alignedSize > expandSize)
|
||||
if (alignedSize == 0 || alignedSize > expandSize) {
|
||||
alignedSize = ALIGN_NEXT(expandSize, 32);
|
||||
}
|
||||
|
||||
if (alignedSize > fileSize)
|
||||
if (alignedSize > fileSize) {
|
||||
alignedSize = fileSize;
|
||||
}
|
||||
|
||||
void* allocatedMem = JKRAllocFromHeap(heap, fileSize, -32);
|
||||
if (allocatedMem == NULL) {
|
||||
if (block != NULL) {
|
||||
JKRFreeToAram(block);
|
||||
}
|
||||
block = NULL;
|
||||
} else {
|
||||
JKRDecompress(buf, (u8*)allocatedMem, fileSize, 0);
|
||||
JKRAramPcs(0, (uintptr_t)allocatedMem, bufSize, alignedSize, block);
|
||||
JKRFreeToHeap(heap, allocatedMem);
|
||||
block = block == NULL ? (JKRAramBlock*)-1 : block;
|
||||
if (pSize != NULL) {
|
||||
*pSize = alignedSize;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (fileSize != 0 && alignedSize > fileSize)
|
||||
alignedSize = fileSize;
|
||||
if (bufSize == 0) {
|
||||
JKRAramBlock* allocatedBlock =
|
||||
(JKRAramBlock*)JKRAllocFromAram(alignedSize, JKRAramHeap::HEAD);
|
||||
block = allocatedBlock;
|
||||
block->newGroupID(decideAramGroupId(id));
|
||||
if (block == NULL)
|
||||
return NULL;
|
||||
|
||||
bufSize = allocatedBlock->getAddress();
|
||||
}
|
||||
|
||||
JKRAramPcs(0, (uintptr_t)buf, bufSize, alignedSize, block);
|
||||
JKRDecompress(buf, (u8*)allocatedMem, fileSize, 0);
|
||||
JKRAramPcs(0, (uintptr_t)allocatedMem, bufSize, alignedSize, block);
|
||||
JKRFreeToHeap(heap, allocatedMem);
|
||||
block = block == NULL ? (JKRAramBlock*)-1 : block;
|
||||
if (pSize != NULL)
|
||||
if (pSize != NULL) {
|
||||
*pSize = alignedSize;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
if (fileSize != 0 && alignedSize > fileSize) {
|
||||
alignedSize = fileSize;
|
||||
}
|
||||
if (bufSize == 0) {
|
||||
block = JKRAllocFromAram(alignedSize, JKRAramHeap::HEAD);
|
||||
block->newGroupID(decideAramGroupId(id));
|
||||
if (block == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bufSize = block->getAddress();
|
||||
}
|
||||
|
||||
JKRAramPcs(0, (uintptr_t)buf, bufSize, alignedSize, block);
|
||||
block = block == NULL ? (JKRAramBlock*)-1 : block;
|
||||
if (pSize != NULL) {
|
||||
*pSize = alignedSize;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
@@ -201,14 +212,13 @@ u8* JKRAram::aramToMainRam(u32 address, u8* buf, u32 p3, JKRExpandSwitch expandS
|
||||
if (p5 != 0 && p5 < expandSize)
|
||||
expandSize = p5;
|
||||
|
||||
if (buf == NULL)
|
||||
buf = (u8*)JKRAllocFromHeap(heap, expandSize, 32);
|
||||
if (buf == NULL)
|
||||
u8* r26 = !buf ? (u8*)JKRAllocFromHeap(heap, expandSize, 32) : buf;
|
||||
if (r26 == NULL)
|
||||
return NULL;
|
||||
else {
|
||||
changeGroupIdIfNeed(buf, id);
|
||||
JKRDecompressFromAramToMainRam(address, buf, p3, expandSize, 0, pSize);
|
||||
return buf;
|
||||
changeGroupIdIfNeed(r26, id);
|
||||
JKRDecompressFromAramToMainRam(address, r26, p3, expandSize, 0, pSize);
|
||||
return r26;
|
||||
}
|
||||
} else if (compression == COMPRESSION_YAY0) { // SZP
|
||||
u8* szpSpace = (u8*)JKRAllocFromHeap(heap, p3, -32);
|
||||
@@ -219,12 +229,7 @@ u8* JKRAram::aramToMainRam(u32 address, u8* buf, u32 p3, JKRExpandSwitch expandS
|
||||
if (p5 != 0 && p5 < expandSize)
|
||||
expandSize = p5;
|
||||
|
||||
u8* rv;
|
||||
if (buf == NULL) {
|
||||
rv = (u8*)JKRAllocFromHeap(heap, expandSize, 32);
|
||||
} else {
|
||||
rv = buf;
|
||||
}
|
||||
u8* rv = !buf ? (u8*)JKRAllocFromHeap(heap, expandSize, 32) : buf;
|
||||
|
||||
if (rv == NULL) {
|
||||
JKRFree(szpSpace);
|
||||
@@ -240,17 +245,16 @@ u8* JKRAram::aramToMainRam(u32 address, u8* buf, u32 p3, JKRExpandSwitch expandS
|
||||
}
|
||||
}
|
||||
} else { // Not compressed or ASR
|
||||
if (buf == NULL)
|
||||
buf = (u8*)JKRAllocFromHeap(heap, p3, 32);
|
||||
if (buf == NULL) {
|
||||
u8* r24 = !buf ? (u8*)JKRAllocFromHeap(heap, p3, 32) : buf;
|
||||
if (r24 == NULL) {
|
||||
return NULL;
|
||||
} else {
|
||||
changeGroupIdIfNeed(buf, id);
|
||||
JKRAramPcs(1, address, (uintptr_t)buf, p3, NULL);
|
||||
changeGroupIdIfNeed(r24, id);
|
||||
JKRAramPcs(1, address, (uintptr_t)r24, p3, NULL);
|
||||
if (pSize != NULL) {
|
||||
*pSize = p3;
|
||||
}
|
||||
return buf;
|
||||
return r24;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -303,10 +307,12 @@ static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32
|
||||
|
||||
u32 szsBufferSize = JKRAram::getSZSBufferSize();
|
||||
szpBuf = (u8*)JKRAllocFromSysHeap(szsBufferSize, 32);
|
||||
JUT_ASSERT(1114, szpBuf != NULL);
|
||||
|
||||
szpEnd = szpBuf + szsBufferSize;
|
||||
if (offset != 0) {
|
||||
refBuf = (u8*)JKRAllocFromSysHeap(0x1120, 0);
|
||||
JUT_ASSERT(1123, refBuf != NULL)
|
||||
refEnd = refBuf + 0x1120;
|
||||
refCurrent = refBuf;
|
||||
} else {
|
||||
@@ -321,7 +327,8 @@ static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32
|
||||
tsPtr = (resourceSize != 0) ? resourceSize : &tsArea;
|
||||
*tsPtr = 0;
|
||||
|
||||
decompSZS_subroutine(firstSrcData(), (u8*)dst);
|
||||
u8* first = firstSrcData();
|
||||
int r25 = decompSZS_subroutine(first, (u8*)dst);
|
||||
JKRFree(szpBuf);
|
||||
if (refBuf) {
|
||||
JKRFree(refBuf);
|
||||
@@ -350,14 +357,17 @@ int decompSZS_subroutine(u8* src, u8* dest) {
|
||||
}
|
||||
|
||||
src += 0x10;
|
||||
s32 b1;
|
||||
u32 dist;
|
||||
s32 numBytes;
|
||||
u8* copySource;
|
||||
do {
|
||||
if (validBitCount == 0) {
|
||||
if ((src > srcLimit) && transLeft) {
|
||||
src = nextSrcData(src);
|
||||
}
|
||||
currCodeByte = *src;
|
||||
currCodeByte = *src++;
|
||||
validBitCount = 8;
|
||||
src++;
|
||||
}
|
||||
if (currCodeByte & 0x80) {
|
||||
if (fileOffset != 0) {
|
||||
@@ -375,9 +385,7 @@ int decompSZS_subroutine(u8* src, u8* dest) {
|
||||
}
|
||||
src++;
|
||||
} else {
|
||||
*dest = *src;
|
||||
dest++;
|
||||
src++;
|
||||
*dest++ = *src++;
|
||||
ts++;
|
||||
if (dest == endPtr) {
|
||||
break;
|
||||
@@ -385,10 +393,10 @@ int decompSZS_subroutine(u8* src, u8* dest) {
|
||||
}
|
||||
readCount++;
|
||||
} else {
|
||||
u32 dist = ((src[0] & 0x0f) << 8) | src[1];
|
||||
s32 numBytes = src[0] >> 4;
|
||||
b1 = src[0];
|
||||
dist = src[1] | ((b1 & 0x0f) << 8);
|
||||
numBytes = b1 >> 4;
|
||||
src += 2;
|
||||
u8* copySource;
|
||||
if (fileOffset != 0) {
|
||||
copySource = refCurrent - dist - 1;
|
||||
if (copySource < refBuf) {
|
||||
@@ -398,8 +406,7 @@ int decompSZS_subroutine(u8* src, u8* dest) {
|
||||
copySource = dest - dist - 1;
|
||||
}
|
||||
if (numBytes == 0) {
|
||||
numBytes = *src + 0x12;
|
||||
src += 1;
|
||||
numBytes = (*src++) + 0x12;
|
||||
} else {
|
||||
numBytes += 2;
|
||||
}
|
||||
@@ -432,9 +439,9 @@ int decompSZS_subroutine(u8* src, u8* dest) {
|
||||
if (dest == endPtr) {
|
||||
break;
|
||||
}
|
||||
copySource++;
|
||||
readCount++;
|
||||
numBytes--;
|
||||
copySource++;
|
||||
} while (numBytes != 0);
|
||||
}
|
||||
}
|
||||
@@ -449,18 +456,10 @@ static u8* firstSrcData() {
|
||||
srcLimit = szpEnd - 0x19;
|
||||
u8* buffer = szpBuf;
|
||||
|
||||
u32 length;
|
||||
u32 size = szpEnd - szpBuf;
|
||||
if (transLeft < size) {
|
||||
length = transLeft;
|
||||
} else {
|
||||
length = size;
|
||||
}
|
||||
u32 size = szpEnd - buffer;
|
||||
u32 length = transLeft < size ? transLeft : size;
|
||||
|
||||
u32 src = (uintptr_t)(srcAddress + srcOffset);
|
||||
u32 dst = (uintptr_t)buffer;
|
||||
u32 alignedLength = ALIGN_NEXT(length, 0x20);
|
||||
JKRAramPcs(1, src, dst, alignedLength, NULL);
|
||||
JKRAramPcs(1, srcAddress + srcOffset, uintptr_t(buffer), ALIGN_NEXT(length, 0x20), NULL);
|
||||
|
||||
srcOffset += length;
|
||||
transLeft -= length;
|
||||
@@ -474,16 +473,18 @@ static u8* firstSrcData() {
|
||||
static u8* nextSrcData(u8* current) {
|
||||
u8* dest;
|
||||
u32 left = (uintptr_t)(szpEnd - current);
|
||||
if (IS_NOT_ALIGNED(left, 0x20))
|
||||
if (IS_NOT_ALIGNED(left, 0x20)) {
|
||||
dest = szpBuf + 0x20 - (left & (0x20 - 1));
|
||||
else
|
||||
} else {
|
||||
dest = szpBuf;
|
||||
}
|
||||
|
||||
memcpy(dest, current, left);
|
||||
u32 transSize = (uintptr_t)(szpEnd - (dest + left));
|
||||
if (transSize > transLeft)
|
||||
transSize = transLeft;
|
||||
|
||||
JUT_ASSERT(1403, transSize > 0);
|
||||
JKRAramPcs(1, (uintptr_t)(srcAddress + srcOffset), ((uintptr_t)dest + left), ALIGN_NEXT(transSize, 0x20),
|
||||
NULL);
|
||||
srcOffset += transSize;
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <math.h>
|
||||
#include "string.h"
|
||||
|
||||
JKRAramArchive::JKRAramArchive() {}
|
||||
|
||||
JKRAramArchive::JKRAramArchive(s32 entryNumber, JKRArchive::EMountDirection mountDirection)
|
||||
: JKRArchive(entryNumber, MOUNT_ARAM) {
|
||||
mMountDirection = mountDirection;
|
||||
@@ -28,10 +30,11 @@ JKRAramArchive::~JKRAramArchive() {
|
||||
if (mIsMounted == true) {
|
||||
if (mArcInfoBlock != NULL) {
|
||||
SDIFileEntry* entry = mFiles;
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; entry++, i++) {
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) {
|
||||
if (entry->data != NULL) {
|
||||
JKRFreeToHeap(mHeap, entry->data);
|
||||
}
|
||||
entry++;
|
||||
}
|
||||
|
||||
JKRFreeToHeap(mHeap, mArcInfoBlock);
|
||||
@@ -56,8 +59,42 @@ JKRAramArchive::~JKRAramArchive() {
|
||||
}
|
||||
}
|
||||
|
||||
inline u32 alignNext(u32 var, u32 align) {
|
||||
return (var + align - 1) & ~(align - 1);
|
||||
void JKRAramArchive::fixedInit(s32 entryNumber, JKRArchive::EMountDirection mountDirection) {
|
||||
mIsMounted = false;
|
||||
mMountDirection = mountDirection;
|
||||
mMountMode = 2;
|
||||
mMountCount = 1;
|
||||
field_0x58 = 2;
|
||||
mHeap = JKRHeap::getCurrentHeap();
|
||||
mEntryNum = entryNumber;
|
||||
if (sCurrentVolume == NULL) {
|
||||
sCurrentVolume = this;
|
||||
sCurrentDirID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL JKRAramArchive::mountFixed(s32 entryNumber, JKRArchive::EMountDirection mountDirection) {
|
||||
if (entryNumber < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
if (check_mount_already(entryNumber, JKRGetCurrentHeap())) {
|
||||
return FALSE;
|
||||
}
|
||||
fixedInit(entryNumber, mountDirection);
|
||||
if (!open(entryNumber)) {
|
||||
return FALSE;
|
||||
}
|
||||
mVolumeType = 'RARC';
|
||||
mVolumeName = mStringTable + mNodes->name_offset;
|
||||
sVolumeList.prepend(&mFileLoaderLink);
|
||||
mIsMounted = true;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void dummy() {
|
||||
OS_REPORT(__FILE__);
|
||||
OS_REPORT("isMounted()");
|
||||
OS_REPORT("mMountCount == 1");
|
||||
}
|
||||
|
||||
bool JKRAramArchive::open(s32 entryNum) {
|
||||
@@ -76,7 +113,8 @@ bool JKRAramArchive::open(s32 entryNum) {
|
||||
|
||||
// NOTE: a different struct is used here for sure, unfortunately i can't get any hits on this
|
||||
// address, so gonna leave it like this for now
|
||||
SArcHeader* mem = (SArcHeader*)JKRAllocFromSysHeap(32, -32);
|
||||
SArcHeader* mem = NULL;
|
||||
mem = (SArcHeader*)JKRAllocFromSysHeap(32, -32);
|
||||
if (mem == NULL) {
|
||||
mMountMode = 0;
|
||||
} else {
|
||||
@@ -104,7 +142,7 @@ bool JKRAramArchive::open(s32 entryNum) {
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) {
|
||||
u8 flag = fileEntry->type_flags_and_name_offset >> 24;
|
||||
if ((flag & 1)) {
|
||||
compressedFiles |= (flag & JKRARCHIVE_ATTR_COMPRESSION);
|
||||
compressedFiles |= u8(flag & JKRARCHIVE_ATTR_COMPRESSION);
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
@@ -160,7 +198,7 @@ void* JKRAramArchive::fetchResource(SDIFileEntry* pEntry, u32* pOutSize) {
|
||||
pOutSize = &outSize;
|
||||
}
|
||||
|
||||
JKRCompression compression = JKRConvertAttrToCompressionType(pEntry->getFlags());
|
||||
JKRCompression compression = JKRConvertAttrToCompressionType(u8(pEntry->type_flags_and_name_offset >> 24));
|
||||
if (pEntry->data == NULL) {
|
||||
u32 size = JKRAramArchive::fetchResource_subroutine(
|
||||
pEntry->data_offset + mBlock->getAddress(), pEntry->data_size, mHeap, compression,
|
||||
@@ -194,7 +232,7 @@ void* JKRAramArchive::fetchResource(void* buffer, u32 bufferSize, SDIFileEntry*
|
||||
size = bufferSize;
|
||||
}
|
||||
|
||||
JKRCompression compression = JKRConvertAttrToCompressionType(pEntry->getFlags());
|
||||
JKRCompression compression = JKRConvertAttrToCompressionType(u8(pEntry->type_flags_and_name_offset >> 24));
|
||||
if (pEntry->data == NULL) {
|
||||
bufferSize = (s32)ALIGN_PREV(bufferSize, 0x20);
|
||||
size = JKRAramArchive::fetchResource_subroutine(pEntry->data_offset + mBlock->getAddress(),
|
||||
@@ -228,12 +266,13 @@ u32 JKRAramArchive::getAramAddress_Entry(SDIFileEntry* pEntry) {
|
||||
}
|
||||
|
||||
u32 JKRAramArchive::getAramAddress(char const* name) {
|
||||
return JKRAramArchive::getAramAddress_Entry(this->findFsResource(name, 0));
|
||||
SDIFileEntry* entry = this->findFsResource(name, 0);
|
||||
return JKRAramArchive::getAramAddress_Entry(entry);
|
||||
}
|
||||
|
||||
u32 JKRAramArchive::fetchResource_subroutine(u32 srcAram, u32 srcLength, u8* dst, u32 dstLength,
|
||||
int compression) {
|
||||
JUT_ASSERT(628, (srcAram & 0x1f) == 0);
|
||||
JUT_ASSERT(628, ( srcAram & 0x1f ) == 0);
|
||||
u32 outLen;
|
||||
u32 srcSize = ALIGN_NEXT(srcLength, 0x20);
|
||||
u32 dstSize = ALIGN_PREV(dstLength, 0x20);
|
||||
@@ -299,7 +338,8 @@ u32 JKRAramArchive::getExpandedResSize(const void* ptr) const {
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
if (entry->getCompressFlag() == 0) {
|
||||
u8 flags = entry->type_flags_and_name_offset >> 24;
|
||||
if ((flags & 4) == 0) {
|
||||
return this->getResSize(ptr);
|
||||
}
|
||||
|
||||
@@ -312,8 +352,8 @@ u32 JKRAramArchive::getExpandedResSize(const void* ptr) const {
|
||||
u8* buf = (u8*)ALIGN_PREV((s32)&tmpBuf[0x1F], 0x20);
|
||||
JKRAramToMainRam(entry->data_offset + mBlock->getAddress(), buf, 0x20, EXPAND_SWITCH_UNKNOWN0,
|
||||
0, NULL, -1, NULL);
|
||||
expandSize = JKRDecompExpandSize(buf);
|
||||
u32 expandSize2 = JKRDecompExpandSize(buf);
|
||||
// ??? casting away const?
|
||||
((JKRArchive*)this)->setExpandSize(entry, expandSize);
|
||||
return expandSize;
|
||||
((JKRArchive*)this)->setExpandSize(entry, expandSize2);
|
||||
return expandSize2;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ JKRAramBlock::~JKRAramBlock() {
|
||||
JSULink<JKRAramBlock>* prev = mBlockLink.getPrev();
|
||||
|
||||
if (prev) {
|
||||
JKRAramBlock* block = prev->getObject();
|
||||
block->mFreeSize = mSize + mFreeSize + block->mFreeSize;
|
||||
prev->getObject()->mFreeSize += mSize + mFreeSize;
|
||||
list->remove(&mBlockLink);
|
||||
} else {
|
||||
mFreeSize = mFreeSize + mSize;
|
||||
@@ -28,35 +27,24 @@ JKRAramBlock::~JKRAramBlock() {
|
||||
}
|
||||
|
||||
JKRAramBlock* JKRAramBlock::allocHead(u32 size, u8 groupId, JKRAramHeap* aramHeap) {
|
||||
u32 address = mAddress;
|
||||
u32 usedSize = mSize;
|
||||
u32 nextAddress = address + usedSize;
|
||||
u32 freeSize = mFreeSize;
|
||||
u32 nextFreeSize = freeSize - size;
|
||||
u32 nextAddress = mAddress + mSize;
|
||||
u32 nextFreeSize = mFreeSize - size;
|
||||
|
||||
JKRAramBlock* block = new (aramHeap->getMgrHeap(), 0)
|
||||
JKRAramBlock(nextAddress, size, nextFreeSize, groupId, false);
|
||||
|
||||
mFreeSize = 0;
|
||||
JSULink<JKRAramBlock>* next = mBlockLink.getNext();
|
||||
JSUList<JKRAramBlock>* list = mBlockLink.getSupervisor();
|
||||
list->insert(next, &block->mBlockLink);
|
||||
mBlockLink.getSupervisor()->insert(mBlockLink.getNext(), &block->mBlockLink);
|
||||
return block;
|
||||
}
|
||||
|
||||
JKRAramBlock* JKRAramBlock::allocTail(u32 size, u8 groupId, JKRAramHeap* aramHeap) {
|
||||
u32 freeSize = mFreeSize;
|
||||
u32 address = mAddress;
|
||||
u32 usedSize = mSize;
|
||||
u32 endAddress = address + usedSize + freeSize;
|
||||
u32 tailAddress = endAddress - size;
|
||||
u32 tailAddress = mAddress + mSize + mFreeSize - size;
|
||||
|
||||
JKRAramBlock* block =
|
||||
new (aramHeap->getMgrHeap(), 0) JKRAramBlock(tailAddress, size, 0, groupId, true);
|
||||
|
||||
mFreeSize -= size;
|
||||
JSULink<JKRAramBlock>* next = mBlockLink.getNext();
|
||||
JSUList<JKRAramBlock>* list = mBlockLink.getSupervisor();
|
||||
list->insert(next, &block->mBlockLink);
|
||||
mBlockLink.getSupervisor()->insert(mBlockLink.getNext(), &block->mBlockLink);
|
||||
return block;
|
||||
}
|
||||
|
||||
@@ -21,11 +21,7 @@ JKRAramHeap::JKRAramHeap(u32 startAddress, u32 size) {
|
||||
}
|
||||
|
||||
JKRAramHeap::~JKRAramHeap() {
|
||||
JSUListIterator<JKRAramBlock> iterator(sAramList.getFirst());
|
||||
while (iterator != sAramList.getEnd())
|
||||
{
|
||||
delete (iterator++).getObject();
|
||||
}
|
||||
for (JSUListIterator<JKRAramBlock> iterator = sAramList.getFirst(); iterator != sAramList.getEnd(); delete (iterator++).getObject()) {}
|
||||
}
|
||||
|
||||
JKRAramBlock* JKRAramHeap::alloc(u32 size, JKRAramHeap::EAllocMode allocationMode) {
|
||||
@@ -47,18 +43,19 @@ JKRAramBlock* JKRAramHeap::allocFromHead(u32 size) {
|
||||
u32 bestFreeSize = UINT_MAX;
|
||||
JKRAramBlock* bestBlock = NULL;
|
||||
|
||||
JSUList<JKRAramBlock>* list = &sAramList;
|
||||
for (JSUListIterator<JKRAramBlock> iterator = list; iterator != list->getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRAramBlock> iterator = sAramList.getFirst(); iterator != sAramList.getEnd(); ++iterator) {
|
||||
JKRAramBlock* block = iterator.getObject();
|
||||
if (block->mFreeSize < alignedSize)
|
||||
if (block->mFreeSize < alignedSize) {
|
||||
continue;
|
||||
if (bestFreeSize <= block->mFreeSize)
|
||||
}
|
||||
if (bestFreeSize <= block->mFreeSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bestFreeSize = block->mFreeSize;
|
||||
bestBlock = block;
|
||||
|
||||
if (block->mFreeSize == alignedSize) {
|
||||
if (bestFreeSize == alignedSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -74,9 +71,7 @@ JKRAramBlock* JKRAramHeap::allocFromTail(u32 size) {
|
||||
u32 alignedSize = ALIGN_NEXT(size, 0x20);
|
||||
JKRAramBlock* tailBlock = NULL;
|
||||
|
||||
JSUList<JKRAramBlock>* list = &sAramList;
|
||||
JSUListIterator<JKRAramBlock> iterator = list->getLast();
|
||||
for (; iterator != list->getEnd(); --iterator) {
|
||||
for (JSUListIterator<JKRAramBlock> iterator = sAramList.getLast(); iterator != sAramList.getEnd(); --iterator) {
|
||||
JKRAramBlock* block = iterator.getObject();
|
||||
if (block->mFreeSize >= alignedSize) {
|
||||
tailBlock = block;
|
||||
@@ -96,9 +91,7 @@ u32 JKRAramHeap::getFreeSize(void) {
|
||||
|
||||
lock();
|
||||
|
||||
JSUList<JKRAramBlock>* list = &sAramList;
|
||||
JSUListIterator<JKRAramBlock> iterator = list;
|
||||
for (; iterator != list->getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRAramBlock> iterator = sAramList.getFirst(); iterator != sAramList.getEnd(); ++iterator) {
|
||||
if (iterator->mFreeSize > maxFreeSize) {
|
||||
maxFreeSize = iterator->mFreeSize;
|
||||
}
|
||||
@@ -113,9 +106,7 @@ u32 JKRAramHeap::getTotalFreeSize(void) {
|
||||
|
||||
lock();
|
||||
|
||||
JSUList<JKRAramBlock>* list = &sAramList;
|
||||
JSUListIterator<JKRAramBlock> iterator = list;
|
||||
for (; iterator != list->getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRAramBlock> iterator = sAramList.getFirst(); iterator != sAramList.getEnd(); ++iterator) {
|
||||
totalFreeSize += iterator->mFreeSize;
|
||||
}
|
||||
|
||||
@@ -126,9 +117,21 @@ u32 JKRAramHeap::getTotalFreeSize(void) {
|
||||
void JKRAramHeap::dump(void) {
|
||||
lock();
|
||||
|
||||
JSUList<JKRAramBlock>* list = &sAramList;
|
||||
JSUListIterator<JKRAramBlock> iterator = list;
|
||||
for (; iterator != list->getEnd(); ++iterator) {}
|
||||
OS_REPORT("\nJKRAramHeap dump\n");
|
||||
OS_REPORT(" attr address: size gid\n");
|
||||
|
||||
u32 usedBytes = 0;
|
||||
for (JSUListIterator<JKRAramBlock> it = sAramList.getFirst(); it != sAramList.getEnd(); ++it) {
|
||||
if (it->mSize) {
|
||||
OS_REPORT("%s %08x: %08x %3d\n", it->isTempMemory() ? " temp" : "alloc", it->mAddress, it->mSize, it->mGroupId);
|
||||
}
|
||||
if (it->mFreeSize) {
|
||||
OS_REPORT(" free %08x: %08x 0\n", it->mAddress + it->mSize, it->mFreeSize);
|
||||
}
|
||||
usedBytes += it->mSize;
|
||||
}
|
||||
|
||||
OS_REPORT("%d / %d bytes (%6.2f%%) used\n", usedBytes, mSize, f32(usedBytes) / f32(mSize) * 100.0f);
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
JKRAMCommand* JKRAramPiece::prepareCommand(int direction, u32 src, u32 dst, u32 length,
|
||||
JKRAramBlock* block,
|
||||
JKRAMCommand::AsyncCallback callback) {
|
||||
JKRAMCommand* command = new (JKRHeap::getSystemHeap(), -4) JKRAMCommand();
|
||||
JKRAMCommand* command = new (JKRGetSystemHeap(), -4) JKRAMCommand();
|
||||
command->mTransferDirection = direction;
|
||||
command->mSrc = src;
|
||||
command->mDst = dst;
|
||||
@@ -23,7 +23,6 @@ void JKRAramPiece::sendCommand(JKRAMCommand* command) {
|
||||
startDMA(command);
|
||||
}
|
||||
|
||||
// JSUList<JKRAMCommand> JKRAramPiece::sAramPieceCommandList;
|
||||
JSUList<JKRAMCommand> JKRAramPiece::sAramPieceCommandList;
|
||||
|
||||
OSMutex JKRAramPiece::mMutex;
|
||||
@@ -39,11 +38,10 @@ JKRAMCommand* JKRAramPiece::orderAsync(int direction, u32 source, u32 destinatio
|
||||
JUTException::panic(__FILE__, 108, "illegal address. abort.");
|
||||
}
|
||||
|
||||
Message* message = new (JKRHeap::getSystemHeap(), -4) Message();
|
||||
JKRAramCommand* message = new (JKRGetSystemHeap(), -4) JKRAramCommand();
|
||||
JKRAMCommand* command =
|
||||
JKRAramPiece::prepareCommand(direction, source, destination, length, block, callback);
|
||||
message->field_0x00 = 1;
|
||||
message->command = command;
|
||||
message->setting(1, command);
|
||||
|
||||
OSSendMessage(&JKRAram::sMessageQueue, message, OS_MESSAGE_BLOCK);
|
||||
if (command->mCallback != NULL) {
|
||||
@@ -65,8 +63,7 @@ BOOL JKRAramPiece::sync(JKRAMCommand* command, int is_non_blocking) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL result = OSReceiveMessage(&command->mMessageQueue, &message, OS_MESSAGE_NOBLOCK);
|
||||
if (!result) {
|
||||
if (!OSReceiveMessage(&command->mMessageQueue, &message, OS_MESSAGE_NOBLOCK)) {
|
||||
unlock();
|
||||
return FALSE;
|
||||
}
|
||||
@@ -109,7 +106,7 @@ void JKRAramPiece::doneDMA(u32 requestAddress) {
|
||||
|
||||
if (command->field_0x60 != 0) {
|
||||
if (command->field_0x60 == 2) {
|
||||
JKRDecomp::sendCommand(command->mDecompCommand);
|
||||
JKRDecompress_SendCommand(command->mDecompCommand);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -140,5 +137,5 @@ JKRAMCommand::~JKRAMCommand() {
|
||||
delete field_0x90;
|
||||
|
||||
if (field_0x94)
|
||||
JKRHeap::free(field_0x94, NULL);
|
||||
JKRFree(field_0x94);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,18 @@
|
||||
#include "JSystem/JUtility/JUTException.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#if PLATFORM_GCN
|
||||
const u32 stack_size = 0xc00;
|
||||
#else
|
||||
const u32 stack_size = 0x4000;
|
||||
#endif
|
||||
|
||||
JKRAramStream* JKRAramStream::sAramStreamObject;
|
||||
|
||||
JKRAramStream* JKRAramStream::create(s32 priority) {
|
||||
if (!sAramStreamObject) {
|
||||
sAramStreamObject = new (JKRGetSystemHeap(), 0) JKRAramStream(priority);
|
||||
setTransBuffer(NULL, 0, NULL);
|
||||
JKRResetAramTransferBuffer();
|
||||
}
|
||||
|
||||
return sAramStreamObject;
|
||||
@@ -26,7 +32,7 @@ void* JKRAramStream::sMessageBuffer[4] = {
|
||||
|
||||
OSMessageQueue JKRAramStream::sMessageQueue = {0};
|
||||
|
||||
JKRAramStream::JKRAramStream(s32 priority) : JKRThread(0xc00, 0x10, priority) {
|
||||
JKRAramStream::JKRAramStream(s32 priority) : JKRThread(stack_size, 0x10, priority) {
|
||||
resume();
|
||||
}
|
||||
|
||||
@@ -65,12 +71,12 @@ s32 JKRAramStream::writeToAram(JKRAramStreamCommand* command) {
|
||||
JKRHeap* heap = command->mHeap;
|
||||
|
||||
if (buffer) {
|
||||
bufferSize = (bufferSize) ? bufferSize : 0x8000;
|
||||
bufferSize = bufferSize == 0 ? 0x8000 : bufferSize;
|
||||
|
||||
command->mTransferBufferSize = bufferSize;
|
||||
command->mAllocatedTransferBuffer = false;
|
||||
} else {
|
||||
bufferSize = (bufferSize) ? bufferSize : 0x8000;
|
||||
bufferSize = bufferSize == 0 ? 0x8000 : bufferSize;
|
||||
|
||||
if (heap) {
|
||||
buffer = (u8*)JKRAllocFromHeap(heap, bufferSize, -0x20);
|
||||
@@ -107,6 +113,7 @@ s32 JKRAramStream::writeToAram(JKRAramStreamCommand* command) {
|
||||
|
||||
JKRAramPcs(0, (uintptr_t)buffer, destination, length, NULL);
|
||||
dstSize -= length;
|
||||
offset += length;
|
||||
writtenLength += length;
|
||||
destination += length;
|
||||
|
||||
@@ -159,20 +166,15 @@ JKRAramStreamCommand* JKRAramStream::sync(JKRAramStreamCommand* command, BOOL is
|
||||
if (isNonBlocking == 0) {
|
||||
OSReceiveMessage(&command->mMessageQueue, &message, OS_MESSAGE_BLOCK);
|
||||
if (message == NULL) {
|
||||
command = NULL;
|
||||
return command;
|
||||
return NULL;
|
||||
} else {
|
||||
return command;
|
||||
}
|
||||
} else {
|
||||
BOOL receiveResult =
|
||||
OSReceiveMessage(&command->mMessageQueue, &message, OS_MESSAGE_NOBLOCK);
|
||||
if (receiveResult == FALSE) {
|
||||
command = NULL;
|
||||
return command;
|
||||
if (OSReceiveMessage(&command->mMessageQueue, &message, OS_MESSAGE_NOBLOCK) == FALSE) {
|
||||
return NULL;
|
||||
} else if (message == NULL) {
|
||||
command = NULL;
|
||||
return command;
|
||||
return NULL;
|
||||
} else {
|
||||
return command;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
|
||||
u32 JKRArchive::sCurrentDirID;
|
||||
|
||||
JKRArchive::JKRArchive() {
|
||||
mIsMounted = false;
|
||||
mMountDirection = MOUNT_DIRECTION_HEAD;
|
||||
}
|
||||
|
||||
JKRArchive::JKRArchive(s32 entryNumber, JKRArchive::EMountMode mountMode) {
|
||||
mIsMounted = false;
|
||||
mMountMode = mountMode;
|
||||
@@ -19,9 +24,9 @@ JKRArchive::JKRArchive(s32 entryNumber, JKRArchive::EMountMode mountMode) {
|
||||
}
|
||||
|
||||
mEntryNum = entryNumber;
|
||||
if (getCurrentVolume() == NULL) {
|
||||
setCurrentVolume(this);
|
||||
setCurrentDirID(0);
|
||||
if (sCurrentVolume == NULL) {
|
||||
sCurrentVolume = this;
|
||||
sCurrentDirID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,14 +41,12 @@ bool JKRArchive::isSameName(JKRArchive::CArcName& name, u32 nameOffset, u16 name
|
||||
|
||||
JKRArchive::SDIDirEntry* JKRArchive::findResType(u32 type) const {
|
||||
SDIDirEntry* node = mNodes;
|
||||
u32 count = 0;
|
||||
while (count < mArcInfoBlock->num_nodes) {
|
||||
for (u32 count = 0; count < mArcInfoBlock->num_nodes; count++) {
|
||||
if (node->type == type) {
|
||||
return node;
|
||||
}
|
||||
|
||||
node++;
|
||||
count++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -58,13 +61,14 @@ JKRArchive::SDIDirEntry* JKRArchive::findDirectory(const char* name, u32 directo
|
||||
SDIDirEntry* dirEntry = mNodes + directoryId;
|
||||
SDIFileEntry* fileEntry = mFiles + dirEntry->first_file_index;
|
||||
|
||||
for (int i = 0; i < dirEntry->num_entries; fileEntry++, i++) {
|
||||
if (isSameName(arcName, fileEntry->getNameOffset(), fileEntry->name_hash)) {
|
||||
if (fileEntry->isDirectory()) {
|
||||
for (int i = 0; i < dirEntry->num_entries; i++) {
|
||||
if (isSameName(arcName, fileEntry->type_flags_and_name_offset & 0xFFFFFF, fileEntry->name_hash)) {
|
||||
if ((fileEntry->type_flags_and_name_offset >> 24) & 2) {
|
||||
return findDirectory(name, fileEntry->data_offset);
|
||||
}
|
||||
break;
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -77,10 +81,11 @@ JKRArchive::SDIFileEntry* JKRArchive::findTypeResource(u32 type, const char* nam
|
||||
|
||||
if (dirEntry) {
|
||||
SDIFileEntry* fileEntry = mFiles + dirEntry->first_file_index;
|
||||
for (int i = 0; i < dirEntry->num_entries; fileEntry++, i++) {
|
||||
if (isSameName(arcName, fileEntry->getNameOffset(), fileEntry->getNameHash())) {
|
||||
for (int i = 0; i < dirEntry->num_entries; i++) {
|
||||
if (isSameName(arcName, fileEntry->type_flags_and_name_offset & 0xFFFFFF, fileEntry->name_hash)) {
|
||||
return fileEntry;
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,9 +99,9 @@ JKRArchive::SDIFileEntry* JKRArchive::findFsResource(const char* name, u32 direc
|
||||
SDIDirEntry* dirEntry = mNodes + directoryId;
|
||||
SDIFileEntry* fileEntry = mFiles + dirEntry->first_file_index;
|
||||
|
||||
for (int i = 0; i < dirEntry->num_entries; fileEntry++, i++) {
|
||||
if (isSameName(arcName, fileEntry->getNameOffset(), fileEntry->name_hash)) {
|
||||
if (fileEntry->isDirectory()) {
|
||||
for (int i = 0; i < dirEntry->num_entries; i++) {
|
||||
if (isSameName(arcName, fileEntry->type_flags_and_name_offset & 0xFFFFFF, fileEntry->name_hash)) {
|
||||
if ((fileEntry->type_flags_and_name_offset >> 24) & 2) {
|
||||
return findFsResource(name, fileEntry->data_offset);
|
||||
}
|
||||
|
||||
@@ -106,6 +111,7 @@ JKRArchive::SDIFileEntry* JKRArchive::findFsResource(const char* name, u32 direc
|
||||
|
||||
return NULL;
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,10 +130,11 @@ JKRArchive::SDIFileEntry* JKRArchive::findNameResource(const char* name) const {
|
||||
SDIFileEntry* fileEntry = mFiles;
|
||||
|
||||
CArcName arcName(name);
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
|
||||
if (isSameName(arcName, fileEntry->getNameOffset(), fileEntry->getNameHash())) {
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) {
|
||||
if (isSameName(arcName, fileEntry->type_flags_and_name_offset & 0xFFFFFF, fileEntry->name_hash)) {
|
||||
return fileEntry;
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -135,10 +142,11 @@ JKRArchive::SDIFileEntry* JKRArchive::findNameResource(const char* name) const {
|
||||
|
||||
JKRArchive::SDIFileEntry* JKRArchive::findPtrResource(const void* resource) const {
|
||||
SDIFileEntry* fileEntry = mFiles;
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) {
|
||||
if (fileEntry->data == resource) {
|
||||
return fileEntry;
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -146,18 +154,20 @@ JKRArchive::SDIFileEntry* JKRArchive::findPtrResource(const void* resource) cons
|
||||
|
||||
JKRArchive::SDIFileEntry* JKRArchive::findIdResource(u16 id) const {
|
||||
if (id != 0xFFFF) {
|
||||
SDIFileEntry* fileEntry;
|
||||
if (id < mArcInfoBlock->num_file_entries) {
|
||||
SDIFileEntry* fileEntry = mFiles + id;
|
||||
if (fileEntry->file_id == id && fileEntry->isUnknownFlag1()) {
|
||||
fileEntry = mFiles + id;
|
||||
if (fileEntry->file_id == id && ((fileEntry->type_flags_and_name_offset >> 24) & 1)) {
|
||||
return fileEntry;
|
||||
}
|
||||
}
|
||||
|
||||
SDIFileEntry* fileEntry = mFiles;
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
|
||||
if (fileEntry->file_id == id && fileEntry->isUnknownFlag1()) {
|
||||
fileEntry = mFiles;
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) {
|
||||
if (fileEntry->file_id == id && ((fileEntry->type_flags_and_name_offset >> 24) & 1)) {
|
||||
return fileEntry;
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,9 @@ JKRArchive* JKRArchive::check_mount_already(s32 entryNum, JKRHeap* heap) {
|
||||
heap = JKRGetCurrentHeap();
|
||||
}
|
||||
|
||||
JSUList<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> iterator;
|
||||
for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRFileLoader> iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) {
|
||||
if (iterator->getVolumeType() == 'RARC') {
|
||||
JKRArchive* archive = (JKRArchive*)iterator.getObject();
|
||||
JKRArchive* archive = (JKRArchive*)iterator.operator->();
|
||||
if (archive->mEntryNum == entryNum && archive->mHeap == heap) {
|
||||
archive->mMountCount++;
|
||||
return archive;
|
||||
@@ -41,60 +39,50 @@ JKRArchive* JKRArchive::mount(const char* path, EMountMode mountMode, JKRHeap* h
|
||||
JKRArchive* JKRArchive::mount(void* ptr, JKRHeap* heap,
|
||||
EMountDirection mountDirection) {
|
||||
JKRArchive* archive = check_mount_already((s32)ptr, heap);
|
||||
if (archive)
|
||||
if (archive) {
|
||||
return archive;
|
||||
|
||||
int alignment;
|
||||
if (mountDirection == MOUNT_DIRECTION_HEAD) {
|
||||
alignment = 4;
|
||||
} else {
|
||||
alignment = -4;
|
||||
}
|
||||
|
||||
archive = new (heap, alignment) JKRMemArchive(ptr, 0xFFFF, JKRMEMBREAK_FLAG_UNKNOWN0);
|
||||
return archive;
|
||||
int alignment = mountDirection == MOUNT_DIRECTION_HEAD ? 4 : -4;
|
||||
|
||||
JKRArchive* newArchive = new (heap, alignment) JKRMemArchive(ptr, 0xFFFF, JKRMEMBREAK_FLAG_UNKNOWN0);
|
||||
return newArchive;
|
||||
}
|
||||
|
||||
JKRArchive* JKRArchive::mount(s32 entryNum, JKRArchive::EMountMode mountMode, JKRHeap* heap,
|
||||
JKRArchive::EMountDirection mountDirection) {
|
||||
JKRArchive* archive = check_mount_already(entryNum, heap);
|
||||
if (archive != NULL) {
|
||||
return archive;
|
||||
} else {
|
||||
int alignment;
|
||||
if (mountDirection == JKRArchive::MOUNT_DIRECTION_HEAD) {
|
||||
alignment = 4;
|
||||
} else {
|
||||
alignment = -4;
|
||||
}
|
||||
|
||||
JKRArchive* archive;
|
||||
switch (mountMode) {
|
||||
case JKRArchive::MOUNT_MEM:
|
||||
archive = new (heap, alignment) JKRMemArchive(entryNum, mountDirection);
|
||||
break;
|
||||
case JKRArchive::MOUNT_ARAM:
|
||||
archive = new (heap, alignment) JKRAramArchive(entryNum, mountDirection);
|
||||
break;
|
||||
case JKRArchive::MOUNT_DVD:
|
||||
archive = new (heap, alignment) JKRDvdArchive(entryNum, mountDirection);
|
||||
break;
|
||||
case JKRArchive::MOUNT_COMP:
|
||||
archive = new (heap, alignment) JKRCompArchive(entryNum, mountDirection);
|
||||
break;
|
||||
}
|
||||
|
||||
if (archive && archive->getMountMode() == JKRArchive::UNKNOWN_MOUNT_MODE) {
|
||||
delete archive;
|
||||
archive = NULL;
|
||||
}
|
||||
|
||||
return archive;
|
||||
}
|
||||
int alignment = mountDirection == MOUNT_DIRECTION_HEAD ? 4 : -4;
|
||||
|
||||
JKRArchive* newArchive;
|
||||
switch (mountMode) {
|
||||
case JKRArchive::MOUNT_MEM:
|
||||
newArchive = new (heap, alignment) JKRMemArchive(entryNum, mountDirection);
|
||||
break;
|
||||
case JKRArchive::MOUNT_ARAM:
|
||||
newArchive = new (heap, alignment) JKRAramArchive(entryNum, mountDirection);
|
||||
break;
|
||||
case JKRArchive::MOUNT_DVD:
|
||||
newArchive = new (heap, alignment) JKRDvdArchive(entryNum, mountDirection);
|
||||
break;
|
||||
case JKRArchive::MOUNT_COMP:
|
||||
newArchive = new (heap, alignment) JKRCompArchive(entryNum, mountDirection);
|
||||
break;
|
||||
}
|
||||
|
||||
if (newArchive && newArchive->mMountMode == JKRArchive::UNKNOWN_MOUNT_MODE) {
|
||||
delete newArchive;
|
||||
newArchive = NULL;
|
||||
}
|
||||
|
||||
return newArchive;
|
||||
}
|
||||
|
||||
bool JKRArchive::becomeCurrent(const char* path) {
|
||||
SDIDirEntry* dirEntry;
|
||||
SDIDirEntry* dirEntry = NULL;
|
||||
if (*path == '/') {
|
||||
path++;
|
||||
|
||||
@@ -102,13 +90,13 @@ bool JKRArchive::becomeCurrent(const char* path) {
|
||||
path = NULL;
|
||||
dirEntry = findDirectory(path, 0);
|
||||
} else {
|
||||
dirEntry = findDirectory(path, getCurrentDirID());
|
||||
dirEntry = findDirectory(path, sCurrentDirID);
|
||||
}
|
||||
|
||||
bool found = dirEntry != NULL;
|
||||
if (found) {
|
||||
setCurrentVolume(this);
|
||||
setCurrentDirID(dirEntry - mNodes);
|
||||
sCurrentVolume = this;
|
||||
sCurrentDirID = dirEntry - mNodes;
|
||||
}
|
||||
|
||||
return found;
|
||||
@@ -119,9 +107,9 @@ bool JKRArchive::getDirEntry(SDirEntry* dirEntry, u32 index) const {
|
||||
if (!fileEntry)
|
||||
return false;
|
||||
|
||||
dirEntry->flags = fileEntry->getFlags();
|
||||
dirEntry->id = fileEntry->getFileID();
|
||||
dirEntry->name = mStringTable + fileEntry->getNameOffset();
|
||||
dirEntry->flags = fileEntry->type_flags_and_name_offset >> 24;
|
||||
dirEntry->id = fileEntry->file_id;
|
||||
dirEntry->name = mStringTable + (fileEntry->type_flags_and_name_offset & 0xFFFFFF);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -131,13 +119,13 @@ void* JKRArchive::getGlbResource(u32 param_1, const char* path, JKRArchive* arch
|
||||
return archive->getResource(param_1, path);
|
||||
}
|
||||
|
||||
JSUList<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> iterator;
|
||||
for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRFileLoader> iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) {
|
||||
if (iterator->getVolumeType() == 'RARC') {
|
||||
resource = iterator->getResource(param_1, path);
|
||||
if (resource)
|
||||
JKRFileLoader* fileLoader = iterator.operator->();
|
||||
resource = fileLoader->getResource(param_1, path);
|
||||
if (resource) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,11 +134,11 @@ void* JKRArchive::getGlbResource(u32 param_1, const char* path, JKRArchive* arch
|
||||
|
||||
void* JKRArchive::getResource(const char* path) {
|
||||
JUT_ASSERT(303, isMounted());
|
||||
SDIFileEntry* fileEntry;
|
||||
SDIFileEntry* fileEntry = NULL;
|
||||
if (*path == '/') {
|
||||
fileEntry = findFsResource(path + 1, 0);
|
||||
} else {
|
||||
fileEntry = findFsResource(path, getCurrentDirID());
|
||||
fileEntry = findFsResource(path, sCurrentDirID);
|
||||
}
|
||||
|
||||
if (fileEntry) {
|
||||
@@ -216,11 +204,11 @@ u32 JKRArchive::readResource(void* buffer, u32 bufferSize, u32 type, const char*
|
||||
|
||||
u32 JKRArchive::readResource(void* buffer, u32 bufferSize, const char* path) {
|
||||
JUT_ASSERT(539, isMounted());
|
||||
SDIFileEntry* fileEntry;
|
||||
SDIFileEntry* fileEntry = NULL;
|
||||
if (*path == '/') {
|
||||
fileEntry = findFsResource(path + 1, 0);
|
||||
} else {
|
||||
fileEntry = findFsResource(path, getCurrentDirID());
|
||||
fileEntry = findFsResource(path, sCurrentDirID);
|
||||
}
|
||||
|
||||
if (fileEntry) {
|
||||
@@ -259,11 +247,12 @@ u32 JKRArchive::readResource(void* buffer, u32 bufferSize, u16 id) {
|
||||
void JKRArchive::removeResourceAll() {
|
||||
if (mArcInfoBlock && mMountMode != MOUNT_MEM) {
|
||||
SDIFileEntry* fileEntry = mFiles;
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) {
|
||||
if (fileEntry->data) {
|
||||
JKRFreeToHeap(mHeap, fileEntry->data);
|
||||
fileEntry->data = NULL;
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,7 +290,7 @@ u32 JKRArchive::getResSize(const void* resource) const {
|
||||
u32 JKRArchive::countResource() const {
|
||||
u32 count = 0;
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) {
|
||||
if (mFiles[i].isUnknownFlag1()) {
|
||||
if ((mFiles[i].type_flags_and_name_offset >> 24) & 1) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -309,7 +298,7 @@ u32 JKRArchive::countResource() const {
|
||||
}
|
||||
|
||||
u32 JKRArchive::countFile(const char* path) const {
|
||||
SDIDirEntry* dirEntry;
|
||||
SDIDirEntry* dirEntry = NULL;
|
||||
if (*path == '/') {
|
||||
path++;
|
||||
|
||||
@@ -317,7 +306,7 @@ u32 JKRArchive::countFile(const char* path) const {
|
||||
path = NULL;
|
||||
dirEntry = findDirectory(path, 0);
|
||||
} else {
|
||||
dirEntry = findDirectory(path, getCurrentDirID());
|
||||
dirEntry = findDirectory(path, sCurrentDirID);
|
||||
}
|
||||
|
||||
if (dirEntry) {
|
||||
@@ -328,7 +317,7 @@ u32 JKRArchive::countFile(const char* path) const {
|
||||
}
|
||||
|
||||
JKRFileFinder* JKRArchive::getFirstFile(const char* path) const {
|
||||
SDIDirEntry* dirEntry;
|
||||
SDIDirEntry* dirEntry = NULL;
|
||||
if (*path == '/') {
|
||||
path++;
|
||||
|
||||
@@ -336,12 +325,12 @@ JKRFileFinder* JKRArchive::getFirstFile(const char* path) const {
|
||||
path = NULL;
|
||||
dirEntry = findDirectory(path, 0);
|
||||
} else {
|
||||
dirEntry = findDirectory(path, getCurrentDirID());
|
||||
dirEntry = findDirectory(path, sCurrentDirID);
|
||||
}
|
||||
|
||||
if (dirEntry) {
|
||||
// don't know what is correct here... for now we're casting away const
|
||||
return new (JKRHeap::getSystemHeap(), 0)
|
||||
return new (JKRGetSystemHeap(), 0)
|
||||
JKRArcFinder((JKRArchive*)this, dirEntry->first_file_index, (u32)dirEntry->num_entries);
|
||||
}
|
||||
|
||||
@@ -351,7 +340,7 @@ JKRFileFinder* JKRArchive::getFirstFile(const char* path) const {
|
||||
u32 JKRArchive::getFileAttribute(u32 index) const {
|
||||
SDIFileEntry* fileEntry = findIdxResource(index);
|
||||
if (fileEntry) {
|
||||
return fileEntry->getFlags();
|
||||
return u8(fileEntry->type_flags_and_name_offset >> 24);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -11,18 +11,17 @@ JKRAssertHeap::~JKRAssertHeap() {
|
||||
|
||||
JKRAssertHeap* JKRAssertHeap::create(JKRHeap* parent) {
|
||||
if (!parent) {
|
||||
parent = JKRHeap::getRootHeap();
|
||||
parent = sRootHeap;
|
||||
}
|
||||
|
||||
// 0x70 is sizeof(JKRAssertHeap) aligned to 16 bytes
|
||||
u32 size = 0x70;
|
||||
int alignment = 16;
|
||||
u32 size = ALIGN_NEXT(sizeof(JKRAssertHeap), 16);
|
||||
|
||||
void* ptr = JKRHeap::alloc(size, alignment, parent);
|
||||
void* ptr = JKRAllocFromHeap(parent, size, 16);
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
|
||||
return new (ptr) JKRAssertHeap(NULL, 0, parent, false);
|
||||
JKRAssertHeap* heap = new (ptr) JKRAssertHeap(NULL, 0, parent, false);
|
||||
return heap;
|
||||
}
|
||||
|
||||
void JKRAssertHeap::do_destroy() {
|
||||
@@ -44,44 +43,3 @@ bool JKRAssertHeap::dump() {
|
||||
bool JKRAssertHeap::dump_sort() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
s32 JKRAssertHeap::do_changeGroupID(u8) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 JKRAssertHeap::do_getCurrentGroupId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* JKRAssertHeap::do_alloc(u32, int) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void JKRAssertHeap::do_free(void* param_0) {}
|
||||
|
||||
void JKRAssertHeap::do_freeAll() {}
|
||||
|
||||
void JKRAssertHeap::do_freeTail() {}
|
||||
|
||||
void JKRAssertHeap::do_fillFreeArea() {}
|
||||
|
||||
s32 JKRAssertHeap::do_resize(void*, u32) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 JKRAssertHeap::do_getSize(void*) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 JKRAssertHeap::do_getFreeSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* JKRAssertHeap::do_getMaxFreeBlock() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s32 JKRAssertHeap::do_getTotalFreeSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ JKRCompArchive::~JKRCompArchive() {
|
||||
if (mArcInfoBlock != NULL) {
|
||||
SDIFileEntry* file = mFiles;
|
||||
for (int i = 0; i < mArcInfoBlock->num_file_entries; i++) {
|
||||
if (!((file->type_flags_and_name_offset >> 0x18) & 0x10) && file->data != NULL) {
|
||||
u32 flags = file->type_flags_and_name_offset >> 24;
|
||||
if ((flags & 16) == 0 && file->data != NULL) {
|
||||
JKRFreeToHeap(mHeap, file->data);
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ JKRCompArchive::~JKRCompArchive() {
|
||||
}
|
||||
|
||||
if (mAramPart != NULL) {
|
||||
delete mAramPart;
|
||||
JKRFreeToAram(mAramPart);
|
||||
}
|
||||
|
||||
if (mExpandedSize != NULL) {
|
||||
@@ -77,7 +78,8 @@ bool JKRCompArchive::open(s32 entryNum) {
|
||||
mMountMode = 0;
|
||||
return 0;
|
||||
}
|
||||
SArcHeader *arcHeader = (SArcHeader *)JKRAllocFromSysHeap(sizeof(SArcHeader), -32); // NOTE: unconfirmed if this struct is used
|
||||
SArcHeader *arcHeader = NULL;
|
||||
arcHeader = (SArcHeader *)JKRAllocFromSysHeap(sizeof(SArcHeader), -32); // NOTE: unconfirmed if this struct is used
|
||||
if(arcHeader == NULL) {
|
||||
mMountMode = 0;
|
||||
}
|
||||
@@ -182,7 +184,7 @@ bool JKRCompArchive::open(s32 entryNum) {
|
||||
u8 flag = fileEntry->type_flags_and_name_offset >> 0x18;
|
||||
if (((flag & 0x1) != 0) && (((flag)&0x10) == 0))
|
||||
{
|
||||
compressedFiles = compressedFiles | (flag & 4);
|
||||
compressedFiles |= (flag & 4);
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
@@ -221,7 +223,7 @@ void* JKRCompArchive::fetchResource(SDIFileEntry *fileEntry, u32 *pSize) {
|
||||
JUT_ASSERT(597, isMounted());
|
||||
u32 ptrSize;
|
||||
u32 size = fileEntry->data_size;
|
||||
int compression = JKRConvertAttrToCompressionType(fileEntry->type_flags_and_name_offset >> 0x18);
|
||||
int compression = JKRConvertAttrToCompressionType(u8(fileEntry->type_flags_and_name_offset >> 0x18));
|
||||
|
||||
if(pSize == NULL) {
|
||||
pSize = &ptrSize; // this makes barely any sense but ok
|
||||
@@ -235,7 +237,8 @@ void* JKRCompArchive::fetchResource(SDIFileEntry *fileEntry, u32 *pSize) {
|
||||
}
|
||||
else if (flag & 0x20) {
|
||||
u8 *data;
|
||||
*pSize = JKRAramArchive::fetchResource_subroutine(fileEntry->data_offset + mAramPart->getAddress() - mSizeOfMemPart, size, mHeap, compression, &data);
|
||||
size = JKRAramArchive::fetchResource_subroutine(fileEntry->data_offset + mAramPart->getAddress() - mSizeOfMemPart, size, mHeap, compression, &data);
|
||||
*pSize = size;
|
||||
fileEntry->data = data;
|
||||
if(compression == COMPRESSION_YAZ0) {
|
||||
setExpandSize(fileEntry, *pSize);
|
||||
@@ -269,7 +272,7 @@ void *JKRCompArchive::fetchResource(void *data, u32 compressedSize, SDIFileEntry
|
||||
u32 fileSize = fileEntry->data_size;
|
||||
u32 alignedSize = ALIGN_NEXT(fileSize, 32);
|
||||
u32 fileFlag = fileEntry->type_flags_and_name_offset >> 0x18;
|
||||
int compression = JKRConvertAttrToCompressionType(fileFlag);
|
||||
int compression = JKRConvertAttrToCompressionType(u8(fileFlag));
|
||||
|
||||
if(fileEntry->data != NULL) {
|
||||
if (compression == COMPRESSION_YAZ0) {
|
||||
@@ -323,6 +326,7 @@ void JKRCompArchive::removeResourceAll() {
|
||||
fileEntry->data = NULL;
|
||||
}
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +335,8 @@ bool JKRCompArchive::removeResource(void* resource) {
|
||||
if (!fileEntry)
|
||||
return false;
|
||||
|
||||
if (!((fileEntry->type_flags_and_name_offset >> 0x18) & 0x10)) {
|
||||
u32 flags = fileEntry->type_flags_and_name_offset >> 24;
|
||||
if ((flags & 0x10) == 0) {
|
||||
JKRFreeToHeap(mHeap, resource);
|
||||
}
|
||||
|
||||
@@ -357,15 +362,14 @@ u32 JKRCompArchive::getExpandedResSize(const void *resource) const
|
||||
}
|
||||
|
||||
if ((flags & 0x10) != 0) {
|
||||
return JKRDecompExpandSize((u8 *)resource);
|
||||
u32 expandSize = JKRDecompExpandSize((u8*)resource);
|
||||
return expandSize;
|
||||
}
|
||||
|
||||
u8 buf[64];
|
||||
u8 *bufPtr = (u8 *)ALIGN_NEXT((uintptr_t)buf, 32);
|
||||
if ((flags & 0x20) != 0) {
|
||||
u32 addr = mAramPart->mAddress;
|
||||
addr = fileEntry->data_offset + addr;
|
||||
JKRAramToMainRam(addr, bufPtr, sizeof(buf) / 2, EXPAND_SWITCH_UNKNOWN0, 0, NULL, -1, NULL);
|
||||
JKRAramToMainRam(fileEntry->data_offset + mAramPart->getAddress(), bufPtr, sizeof(buf) / 2, EXPAND_SWITCH_UNKNOWN0, 0, NULL, -1, NULL);
|
||||
DCInvalidateRange(bufPtr, sizeof(buf) / 2);
|
||||
}
|
||||
else if ((flags & 0x40) != 0) {
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
#include "JSystem/JKernel/JKRAramPiece.h"
|
||||
#include "global.h"
|
||||
|
||||
#if PLATFORM_GCN
|
||||
const u32 stack_size = 0x800;
|
||||
#else
|
||||
const u32 stack_size = 0x4000;
|
||||
#endif
|
||||
|
||||
JKRDecomp* JKRDecomp::sDecompObject;
|
||||
|
||||
JKRDecomp* JKRDecomp::create(s32 priority) {
|
||||
if (!sDecompObject) {
|
||||
sDecompObject = new (JKRHeap::getSystemHeap(), 0) JKRDecomp(priority);
|
||||
sDecompObject = new (JKRGetSystemHeap(), 0) JKRDecomp(priority);
|
||||
}
|
||||
|
||||
return sDecompObject;
|
||||
@@ -18,7 +24,7 @@ OSMessage JKRDecomp::sMessageBuffer[8] = {0};
|
||||
|
||||
OSMessageQueue JKRDecomp::sMessageQueue = {0};
|
||||
|
||||
JKRDecomp::JKRDecomp(s32 priority) : JKRThread(0x800, 0x10, priority) {
|
||||
JKRDecomp::JKRDecomp(s32 priority) : JKRThread(stack_size, 0x10, priority) {
|
||||
resume();
|
||||
}
|
||||
|
||||
@@ -35,7 +41,7 @@ void* JKRDecomp::run() {
|
||||
|
||||
if (command->field_0x20 != 0) {
|
||||
if (command->field_0x20 == 1) {
|
||||
JKRAramPiece::sendCommand(command->mAMCommand);
|
||||
JKRAramPcs_SendCommand(command->mAMCommand);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -56,7 +62,7 @@ void* JKRDecomp::run() {
|
||||
JKRDecompCommand* JKRDecomp::prepareCommand(u8* srcBuffer, u8* dstBuffer, u32 srcLength,
|
||||
u32 dstLength,
|
||||
JKRDecompCommand::AsyncCallback callback) {
|
||||
JKRDecompCommand* command = new (JKRHeap::getSystemHeap(), -4) JKRDecompCommand();
|
||||
JKRDecompCommand* command = new (JKRGetSystemHeap(), -4) JKRDecompCommand();
|
||||
command->mSrcBuffer = srcBuffer;
|
||||
command->mDstBuffer = dstBuffer;
|
||||
command->mSrcLength = srcLength;
|
||||
@@ -66,7 +72,8 @@ JKRDecompCommand* JKRDecomp::prepareCommand(u8* srcBuffer, u8* dstBuffer, u32 sr
|
||||
}
|
||||
|
||||
void JKRDecomp::sendCommand(JKRDecompCommand* command) {
|
||||
OSSendMessage(&sMessageQueue, command, OS_MESSAGE_NOBLOCK);
|
||||
int result = OSSendMessage(&sMessageQueue, command, OS_MESSAGE_NOBLOCK);
|
||||
JUT_ASSERT_MSG(142, result, "Decomp MesgBuf FULL!");
|
||||
}
|
||||
|
||||
JKRDecompCommand* JKRDecomp::orderAsync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 dstLength,
|
||||
@@ -79,15 +86,16 @@ JKRDecompCommand* JKRDecomp::orderAsync(u8* srcBuffer, u8* dstBuffer, u32 srcLen
|
||||
|
||||
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 true;
|
||||
}
|
||||
bool result;
|
||||
if (!OSReceiveMessage(&command->mMessageQueue, &message, OS_MESSAGE_NOBLOCK)) {
|
||||
result = false;
|
||||
} else {
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@ JKRDisposer::JKRDisposer() : mLink(this) {
|
||||
}
|
||||
|
||||
JKRDisposer::~JKRDisposer() {
|
||||
JKRHeap* heap = mHeap;
|
||||
if (heap) {
|
||||
heap->removeDisposer(this);
|
||||
if (mHeap) {
|
||||
mHeap->removeDisposer(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ JKRADCommand* JKRDvdAramRipper::loadToAram_Async(JKRDvdFile* dvdFile, u32 addres
|
||||
JKRExpandSwitch expandSwitch,
|
||||
void (*callback)(u32), u32 param_4, u32 param_5,
|
||||
u32* param_6) {
|
||||
JKRADCommand* command = new (JKRHeap::sSystemHeap, -4) JKRADCommand();
|
||||
JKRADCommand* command = new (JKRGetSystemHeap(), -4) JKRADCommand();
|
||||
command->mDvdFile = dvdFile;
|
||||
command->mAddress = address;
|
||||
command->mBlock = NULL;
|
||||
@@ -66,7 +66,8 @@ JKRADCommand* JKRDvdAramRipper::loadToAram_Async(JKRDvdFile* dvdFile, u32 addres
|
||||
command->field_0x40 = param_5;
|
||||
command->field_0x44 = param_6;
|
||||
|
||||
if (!callCommand_Async(command)) {
|
||||
JKRADCommand* cmd2 = callCommand_Async(command);
|
||||
if (!cmd2) {
|
||||
delete command;
|
||||
return NULL;
|
||||
}
|
||||
@@ -104,7 +105,8 @@ JKRADCommand* JKRDvdAramRipper::callCommand_Async(JKRADCommand* command) {
|
||||
u8 buffer[0x40];
|
||||
u8* bufPtr = (u8*)ALIGN_NEXT((u32)&buffer, 0x20);
|
||||
while (true) {
|
||||
if (DVDReadPrio(dvdFile->getFileInfo(), bufPtr, 0x20, 0, 2) >= 0) {
|
||||
s32 result = DVDReadPrio(dvdFile->getFileInfo(), bufPtr, 0x20, 0, 2);
|
||||
if (result >= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -193,8 +195,8 @@ bool JKRDvdAramRipper::syncAram(JKRADCommand* command, int param_1) {
|
||||
OSLockMutex(&dvdFile->mMutex2);
|
||||
|
||||
if (command->mStreamCommand) {
|
||||
JKRAramStreamCommand* var1 = JKRAramStream::sync(command->mStreamCommand, param_1);
|
||||
command->field_0x48 = -(var1 == NULL);
|
||||
JKRAramStreamCommand* var1 = JKRStreamToAram_Sync(command->mStreamCommand, param_1);
|
||||
command->field_0x48 = (var1) ? 0 : -1;
|
||||
|
||||
if (param_1 != 0 && var1 == NULL) {
|
||||
OSUnlockMutex(&dvdFile->mMutex2);
|
||||
@@ -274,29 +276,36 @@ int JKRDecompressFromDVDToAram(JKRDvdFile* dvdFile, u32 param_1, u32 fileSize, u
|
||||
|
||||
OSRestoreInterrupts(level);
|
||||
OSLockMutex(&decompMutex);
|
||||
u32 bufferSize = JKRDvdAramRipper::sSZSBufferSize;
|
||||
int result = 0;
|
||||
u32 bufferSize = JKRDvdAramRipper::getSZSBufferSize();
|
||||
szpBuf = (u8*)JKRAllocFromSysHeap(bufferSize, 0x20);
|
||||
JUT_ASSERT(755, szpBuf);
|
||||
szpEnd = szpBuf + bufferSize;
|
||||
refBuf = (u8*)JKRAllocFromSysHeap(0x1120, 0);
|
||||
JUT_ASSERT(763, refBuf);
|
||||
refEnd = refBuf + 0x1120;
|
||||
refCurrent = refBuf;
|
||||
dmaBuf = (u8*)JKRAllocFromSysHeap(0x100, 0x20);
|
||||
JUT_ASSERT(772, dmaBuf);
|
||||
dmaEnd = dmaBuf + 0x100;
|
||||
dmaCurrent = dmaBuf;
|
||||
srcFile = dvdFile;
|
||||
srcOffset = param_5;
|
||||
transLeft = fileSize - param_5;
|
||||
transLeft = fileSize - srcOffset;
|
||||
fileOffset = param_4;
|
||||
readCount = 0;
|
||||
maxDest = uncompressedSize;
|
||||
param_6 = param_6 ? param_6 : &tsArea;
|
||||
tsPtr = param_6;
|
||||
*param_6 = 0;
|
||||
tsPtr = param_6 ? param_6 : &tsArea;
|
||||
*tsPtr = 0;
|
||||
u8* first = firstSrcData();
|
||||
int result = first ? decompSZS_subroutine(first, param_1) : -1;
|
||||
JKRHeap::free(szpBuf, 0);
|
||||
JKRHeap::free(refBuf, 0);
|
||||
JKRHeap::free(dmaBuf, 0);
|
||||
if (first) {
|
||||
result = decompSZS_subroutine(first, param_1);
|
||||
} else {
|
||||
result = -1;
|
||||
}
|
||||
JKRFree(szpBuf);
|
||||
JKRFree(refBuf);
|
||||
JKRFree(dmaBuf);
|
||||
OSUnlockMutex(&decompMutex);
|
||||
return result;
|
||||
}
|
||||
@@ -326,6 +335,8 @@ static int decompSZS_subroutine(u8* src, u32 dest) {
|
||||
}
|
||||
|
||||
src += 0x10;
|
||||
s32 b1;
|
||||
u32 dist;
|
||||
do {
|
||||
if (validBitCount == 0) {
|
||||
if ((src > srcLimit) && transLeft) {
|
||||
@@ -354,8 +365,9 @@ static int decompSZS_subroutine(u8* src, u32 dest) {
|
||||
src++;
|
||||
readCount++;
|
||||
} else {
|
||||
u32 dist = ((src[0] & 0x0F) << 8) | src[1];
|
||||
numBytes = src[0] >> 4;
|
||||
b1 = src[0];
|
||||
dist = src[1] | ((b1 & 0x0f) << 8);
|
||||
numBytes = b1 >> 4;
|
||||
src += 2;
|
||||
copySource = refCurrent - dist - 1;
|
||||
if (copySource < refBuf) {
|
||||
@@ -406,11 +418,11 @@ static u8* firstSrcData() {
|
||||
u32 bufSize = szpEnd - buffer;
|
||||
u32 length = transLeft < bufSize ? transLeft : bufSize;
|
||||
while (true) {
|
||||
int result = DVDReadPrio(&srcFile->mFileInfo, buffer, length, 0, 2);
|
||||
int result = DVDReadPrio(srcFile->getFileInfo(), buffer, length, 0, 2);
|
||||
if (result >= 0) {
|
||||
break;
|
||||
}
|
||||
if (JKRDvdAramRipper::errorRetry == 0) {
|
||||
if (!JKRDvdAramRipper::isErrorRetry()) {
|
||||
return NULL;
|
||||
}
|
||||
VIWaitForRetrace();
|
||||
@@ -428,11 +440,13 @@ static u8* nextSrcData(u8* src) {
|
||||
} else {
|
||||
dest = szpBuf;
|
||||
}
|
||||
|
||||
memcpy(dest, src, size);
|
||||
u32 transSize = szpEnd - (dest + size);
|
||||
if (transSize > transLeft) {
|
||||
transSize = transLeft;
|
||||
}
|
||||
JUT_ASSERT(1036, transSize > 0);
|
||||
|
||||
while (true) {
|
||||
s32 result = DVDReadPrio(srcFile->getFileInfo(), dest + size, transSize, srcOffset, 2);
|
||||
@@ -457,7 +471,7 @@ static u32 dmaBufferFlush(u32 param_1) {
|
||||
return 0;
|
||||
}
|
||||
u32 size = ALIGN_NEXT(dmaCurrent - dmaBuf, 0x20);
|
||||
JKRAramPiece::orderSync(0, (u32)dmaBuf, param_1, size, NULL);
|
||||
JKRAramPcs(0, (u32)dmaBuf, param_1, size, NULL);
|
||||
dmaCurrent = dmaBuf;
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ JKRDvdArchive::JKRDvdArchive(s32 entryNum, JKRArchive::EMountDirection mountDire
|
||||
|
||||
mVolumeType = 'RARC';
|
||||
mVolumeName = mStringTable + mNodes->name_offset;
|
||||
getVolumeList().prepend(&mFileLoaderLink);
|
||||
sVolumeList.prepend(&mFileLoaderLink);
|
||||
mIsMounted = true;
|
||||
}
|
||||
|
||||
@@ -28,10 +28,11 @@ JKRDvdArchive::~JKRDvdArchive() {
|
||||
if (mArcInfoBlock) {
|
||||
SDIFileEntry* fileEntry = mFiles;
|
||||
int i = 0;
|
||||
for (; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
|
||||
for (; i < mArcInfoBlock->num_file_entries; i++) {
|
||||
if (fileEntry->data) {
|
||||
JKRFreeToHeap(mHeap, fileEntry->data);
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
|
||||
JKRFreeToHeap(mHeap, mArcInfoBlock);
|
||||
@@ -47,7 +48,7 @@ JKRDvdArchive::~JKRDvdArchive() {
|
||||
delete mDvdFile;
|
||||
}
|
||||
|
||||
getVolumeList().remove(&mFileLoaderLink);
|
||||
sVolumeList.remove(&mFileLoaderLink);
|
||||
mIsMounted = false;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +66,8 @@ bool JKRDvdArchive::open(s32 entryNum) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SArcHeader* arcHeader = (SArcHeader*)JKRAllocFromSysHeap(sizeof(SArcHeader), 0x20);
|
||||
SArcHeader* arcHeader = NULL;
|
||||
arcHeader = (SArcHeader*)JKRAllocFromSysHeap(sizeof(SArcHeader), 0x20);
|
||||
if (!arcHeader) {
|
||||
mMountMode = UNKNOWN_MOUNT_MODE;
|
||||
goto cleanup;
|
||||
@@ -98,9 +100,10 @@ bool JKRDvdArchive::open(s32 entryNum) {
|
||||
useCompression = 0;
|
||||
SDIFileEntry* fileEntry;
|
||||
fileEntry = mFiles;
|
||||
for (u32 i = 0; i < mArcInfoBlock->num_file_entries; fileEntry++, i++) {
|
||||
if (fileEntry->isUnknownFlag1()) {
|
||||
useCompression |= fileEntry->getCompressFlag();
|
||||
for (u32 i = 0; i < mArcInfoBlock->num_file_entries; i++, fileEntry++) {
|
||||
u8 flags = fileEntry->type_flags_and_name_offset >> 24;
|
||||
if (flags & 1) {
|
||||
useCompression |= u8(flags & 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +147,7 @@ void* JKRDvdArchive::fetchResource(SDIFileEntry* fileEntry, u32* returnSize) {
|
||||
returnSize = &tempReturnSize;
|
||||
}
|
||||
|
||||
JKRCompression fileCompression = JKRConvertAttrToCompressionType(fileEntry->getAttr());
|
||||
JKRCompression fileCompression = JKRConvertAttrToCompressionType(u8(fileEntry->type_flags_and_name_offset >> 24));
|
||||
if (!fileEntry->data) {
|
||||
u8* resourcePtr;
|
||||
u32 resourceSize = fetchResource_subroutine(
|
||||
@@ -161,8 +164,7 @@ void* JKRDvdArchive::fetchResource(SDIFileEntry* fileEntry, u32* returnSize) {
|
||||
}
|
||||
} else {
|
||||
if (fileCompression == COMPRESSION_YAZ0) {
|
||||
u32 resourceSize = getExpandSize(fileEntry);
|
||||
*returnSize = resourceSize;
|
||||
*returnSize = getExpandSize(fileEntry);
|
||||
} else {
|
||||
*returnSize = fileEntry->data_size;
|
||||
}
|
||||
@@ -174,9 +176,8 @@ void* JKRDvdArchive::fetchResource(SDIFileEntry* fileEntry, u32* returnSize) {
|
||||
void* JKRDvdArchive::fetchResource(void* buffer, u32 bufferSize, SDIFileEntry* fileEntry,
|
||||
u32* returnSize) {
|
||||
JUT_ASSERT(504, isMounted());
|
||||
u32 expandSize;
|
||||
u32 size = fileEntry->data_size;
|
||||
JKRCompression fileCompression = JKRConvertAttrToCompressionType(fileEntry->getAttr());
|
||||
JKRCompression fileCompression = JKRConvertAttrToCompressionType(u8(fileEntry->type_flags_and_name_offset >> 24));
|
||||
|
||||
if (!fileEntry->data) {
|
||||
bufferSize = (s32)ALIGN_PREV(bufferSize, 0x20);
|
||||
@@ -185,7 +186,7 @@ void* JKRDvdArchive::fetchResource(void* buffer, u32 bufferSize, SDIFileEntry* f
|
||||
mCompression);
|
||||
} else {
|
||||
if (fileCompression == COMPRESSION_YAZ0) {
|
||||
expandSize = getExpandSize(fileEntry);
|
||||
u32 expandSize = getExpandSize(fileEntry);
|
||||
if (expandSize) {
|
||||
size = expandSize;
|
||||
}
|
||||
@@ -343,7 +344,8 @@ u32 JKRDvdArchive::getExpandedResSize(const void* resource) const {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!fileEntry->isCompressed()) {
|
||||
u8 flags = fileEntry->type_flags_and_name_offset >> 24;
|
||||
if ((flags & 4) == 0) {
|
||||
return getResSize(resource);
|
||||
}
|
||||
|
||||
@@ -361,9 +363,9 @@ u32 JKRDvdArchive::getExpandedResSize(const void* resource) const {
|
||||
mDataOffset + fileEntry->data_offset, NULL, NULL);
|
||||
DCInvalidateRange(arcHeader, sizeof(SArcHeader));
|
||||
|
||||
resourceSize = JKRDecompExpandSize(arcHeader);
|
||||
u32 expandSize = JKRDecompExpandSize(arcHeader);
|
||||
// ???
|
||||
((JKRDvdArchive*)this)->setExpandSize(fileEntry, resourceSize);
|
||||
((JKRDvdArchive*)this)->setExpandSize(fileEntry, expandSize);
|
||||
|
||||
return resourceSize;
|
||||
return expandSize;
|
||||
}
|
||||
|
||||
@@ -13,10 +13,9 @@ JKRDvdFile::JKRDvdFile() : mDvdLink(this) {
|
||||
|
||||
JKRDvdFile::JKRDvdFile(const char* name) : mDvdLink(this) {
|
||||
initiate();
|
||||
bool result = open(name);
|
||||
mIsAvailable = result;
|
||||
mIsAvailable = open(name);
|
||||
// weird code. doesn't match without this, maybe remains from assert or something?
|
||||
if (mIsAvailable)
|
||||
if (!mIsAvailable)
|
||||
return;
|
||||
else
|
||||
return;
|
||||
@@ -24,10 +23,9 @@ JKRDvdFile::JKRDvdFile(const char* name) : mDvdLink(this) {
|
||||
|
||||
JKRDvdFile::JKRDvdFile(s32 entryNum) : mDvdLink(this) {
|
||||
initiate();
|
||||
bool result = open(entryNum);
|
||||
mIsAvailable = result;
|
||||
mIsAvailable = open(entryNum);
|
||||
// weird code. doesn't match without this, maybe remains from assert or something?
|
||||
if (mIsAvailable)
|
||||
if (!mIsAvailable)
|
||||
return;
|
||||
else
|
||||
return;
|
||||
@@ -52,7 +50,7 @@ bool JKRDvdFile::open(const char* name) {
|
||||
if (!mIsAvailable) {
|
||||
mIsAvailable = DVDOpen(name, &mFileInfo);
|
||||
if (mIsAvailable) {
|
||||
getDvdList().append(&mDvdLink);
|
||||
sDvdList.append(&mDvdLink);
|
||||
getStatus();
|
||||
}
|
||||
}
|
||||
@@ -63,7 +61,7 @@ bool JKRDvdFile::open(s32 entryNum) {
|
||||
if (!mIsAvailable) {
|
||||
mIsAvailable = DVDFastOpen(entryNum, &mFileInfo);
|
||||
if (mIsAvailable) {
|
||||
getDvdList().append(&mDvdLink);
|
||||
sDvdList.append(&mDvdLink);
|
||||
getStatus();
|
||||
}
|
||||
}
|
||||
@@ -72,10 +70,9 @@ bool JKRDvdFile::open(s32 entryNum) {
|
||||
|
||||
void JKRDvdFile::close() {
|
||||
if (mIsAvailable) {
|
||||
s32 result = DVDClose(&mFileInfo);
|
||||
if (result != 0) {
|
||||
if (DVDClose(&mFileInfo) != 0) {
|
||||
mIsAvailable = false;
|
||||
getDvdList().remove(&mDvdLink);
|
||||
sDvdList.remove(&mDvdLink);
|
||||
} else {
|
||||
JUTException::panic(__FILE__, 213, "cannot close DVD file\n");
|
||||
}
|
||||
@@ -99,9 +96,7 @@ s32 JKRDvdFile::readData(void* param_1, s32 length, s32 param_3) {
|
||||
mOSThread = OSGetCurrentThread();
|
||||
|
||||
s32 result = -1;
|
||||
s32 readAsyncResult =
|
||||
DVDReadAsyncPrio(&mFileInfo, param_1, length, param_3, JKRDvdFile::doneProcess, 2);
|
||||
if (readAsyncResult) {
|
||||
if (DVDReadAsyncPrio(&mFileInfo, param_1, length, param_3, JKRDvdFile::doneProcess, 2)) {
|
||||
result = sync();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ void* JKRDvdRipper::loadToMainRAM(char const* name, u8* dst, JKRExpandSwitch exp
|
||||
if (!file.open(name)) {
|
||||
return NULL;
|
||||
}
|
||||
return loadToMainRAM(&file, dst, expandSwitch, dstLength, heap, allocDirection, offset,
|
||||
return JKRDvdToMainRam(&file, dst, expandSwitch, dstLength, heap, allocDirection, offset,
|
||||
pCompression, param_8);
|
||||
}
|
||||
|
||||
@@ -38,11 +38,11 @@ void* JKRDvdRipper::loadToMainRAM(s32 entryNumber, u8* dst, JKRExpandSwitch expa
|
||||
if (!file.open(entryNumber)) {
|
||||
return NULL;
|
||||
}
|
||||
return loadToMainRAM(&file, dst, expandSwitch, dstLength, heap, allocDirection, offset,
|
||||
return JKRDvdToMainRam(&file, dst, expandSwitch, dstLength, heap, allocDirection, offset,
|
||||
pCompression, param_8);
|
||||
}
|
||||
|
||||
static u8 errorRetry = 0x01;
|
||||
bool JKRDvdRipper::errorRetry = true;
|
||||
|
||||
void* JKRDvdRipper::loadToMainRAM(JKRDvdFile* dvdFile, u8* dst, JKRExpandSwitch expandSwitch,
|
||||
u32 dstLength, JKRHeap* heap,
|
||||
@@ -215,7 +215,8 @@ void* JKRDvdRipper::loadToMainRAM(JKRDvdFile* dvdFile, u8* dst, JKRExpandSwitch
|
||||
}
|
||||
else if (compression == COMPRESSION_YAZ0)
|
||||
{
|
||||
if (JKRDecompressFromDVD(dvdFile, dst, fileSizeAligned, expandSize, offset, 0, param_8) != 0u)
|
||||
u32 result = JKRDecompressFromDVD(dvdFile, dst, fileSizeAligned, expandSize, offset, 0, param_8);
|
||||
if (result != 0u)
|
||||
{
|
||||
if (hasAllocated)
|
||||
JKRFree(dst);
|
||||
@@ -279,37 +280,34 @@ static int JKRDecompressFromDVD(JKRDvdFile* dvdFile, void* dst, u32 fileSize, u3
|
||||
}
|
||||
OSRestoreInterrupts(interrupts);
|
||||
OSLockMutex(&decompMutex);
|
||||
int bufSize = JKRDvdRipper::getSZSBufferSize();
|
||||
szpBuf = (u8 *)JKRAllocFromSysHeap(bufSize, -0x20);
|
||||
u32 result = 0;
|
||||
u32 szsBufferSize = JKRDvdRipper::getSZSBufferSize();
|
||||
szpBuf = (u8 *)JKRAllocFromSysHeap(szsBufferSize, -0x20);
|
||||
JUT_ASSERT(909, szpBuf != NULL);
|
||||
|
||||
szpEnd = szpBuf + bufSize;
|
||||
if (inFileOffset != 0)
|
||||
{
|
||||
szpEnd = szpBuf + szsBufferSize;
|
||||
if (inFileOffset != 0) {
|
||||
refBuf = (u8 *)JKRAllocFromSysHeap(0x1120, -4);
|
||||
JUT_ASSERT(918, refBuf != NULL);
|
||||
refEnd = refBuf + 0x1120;
|
||||
refCurrent = refBuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
refBuf = NULL;
|
||||
}
|
||||
srcFile = dvdFile;
|
||||
srcOffset = inSrcOffset;
|
||||
transLeft = fileSize - inSrcOffset;
|
||||
transLeft = fileSize - srcOffset;
|
||||
fileOffset = inFileOffset;
|
||||
readCount = 0;
|
||||
maxDest = inMaxDest;
|
||||
if (!inTsPtr)
|
||||
{
|
||||
tsPtr = &tsArea;
|
||||
}
|
||||
else
|
||||
{
|
||||
tsPtr = inTsPtr;
|
||||
}
|
||||
tsPtr = inTsPtr ? inTsPtr : &tsArea;
|
||||
*tsPtr = 0;
|
||||
u8 *data = firstSrcData();
|
||||
u32 result = (data != NULL) ? decompSZS_subroutine(data, (u8 *)dst) : -1; // figure out correct datatypes
|
||||
if (data != NULL) {
|
||||
result = decompSZS_subroutine(data, (u8 *)dst);
|
||||
} else {
|
||||
result = -1;
|
||||
}
|
||||
JKRFree(szpBuf);
|
||||
if (refBuf)
|
||||
{
|
||||
@@ -321,143 +319,110 @@ static int JKRDecompressFromDVD(JKRDvdFile* dvdFile, void* dst, u32 fileSize, u3
|
||||
}
|
||||
|
||||
int decompSZS_subroutine(u8* src, u8* dest) {
|
||||
u8 *endPtr;
|
||||
u8* endPtr;
|
||||
s32 validBitCount = 0;
|
||||
s32 currCodeByte = 0;
|
||||
u32 ts = 0;
|
||||
|
||||
if (src[0] != 'Y' || src[1] != 'a' || src[2] != 'z' || src[3] != '0')
|
||||
{
|
||||
if (src[0] != 'Y' || src[1] != 'a' || src[2] != 'z' || src[3] != '0') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SYaz0Header *header = (SYaz0Header *)src;
|
||||
SYaz0Header* header = (SYaz0Header*)src;
|
||||
endPtr = dest + (header->length - fileOffset);
|
||||
if (endPtr > dest + maxDest)
|
||||
{
|
||||
if (endPtr > dest + maxDest) {
|
||||
endPtr = dest + maxDest;
|
||||
}
|
||||
|
||||
src += 0x10;
|
||||
do
|
||||
{
|
||||
if (validBitCount == 0)
|
||||
{
|
||||
if ((src > srcLimit) && transLeft)
|
||||
{
|
||||
s32 b1;
|
||||
u32 dist;
|
||||
s32 numBytes;
|
||||
u8* copySource;
|
||||
do {
|
||||
if (validBitCount == 0) {
|
||||
if ((src > srcLimit) && transLeft) {
|
||||
src = nextSrcData(src);
|
||||
if (!src)
|
||||
{
|
||||
if (!src) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
currCodeByte = *src;
|
||||
currCodeByte = *src++;
|
||||
validBitCount = 8;
|
||||
src++;
|
||||
}
|
||||
if (currCodeByte & 0x80)
|
||||
{
|
||||
if (fileOffset != 0)
|
||||
{
|
||||
if (readCount >= fileOffset)
|
||||
{
|
||||
if (currCodeByte & 0x80) {
|
||||
if (fileOffset != 0) {
|
||||
if (readCount >= fileOffset) {
|
||||
*dest = *src;
|
||||
dest++;
|
||||
ts++;
|
||||
if (dest == endPtr)
|
||||
{
|
||||
if (dest == endPtr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*(refCurrent++) = *src;
|
||||
if (refCurrent == refEnd)
|
||||
{
|
||||
if (refCurrent == refEnd) {
|
||||
refCurrent = refBuf;
|
||||
}
|
||||
src++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dest = *src;
|
||||
dest++;
|
||||
src++;
|
||||
} else {
|
||||
*dest++ = *src++;
|
||||
ts++;
|
||||
if (dest == endPtr)
|
||||
{
|
||||
if (dest == endPtr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
readCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 dist = ((src[0] & 0x0f) << 8) | src[1];
|
||||
s32 numBytes = src[0] >> 4;
|
||||
} else {
|
||||
b1 = src[0];
|
||||
dist = src[1] | ((b1 & 0x0f) << 8);
|
||||
numBytes = b1 >> 4;
|
||||
src += 2;
|
||||
u8 *copySource;
|
||||
if (fileOffset != 0)
|
||||
{
|
||||
if (fileOffset != 0) {
|
||||
copySource = refCurrent - dist - 1;
|
||||
if (copySource < refBuf)
|
||||
{
|
||||
if (copySource < refBuf) {
|
||||
copySource += refEnd - refBuf;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
copySource = dest - dist - 1;
|
||||
}
|
||||
if (numBytes == 0)
|
||||
{
|
||||
numBytes = *src + 0x12;
|
||||
src += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (numBytes == 0) {
|
||||
numBytes = (*src++) + 0x12;
|
||||
} else {
|
||||
numBytes += 2;
|
||||
}
|
||||
if (fileOffset != 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (readCount >= fileOffset)
|
||||
{
|
||||
if (fileOffset != 0) {
|
||||
do {
|
||||
if (readCount >= fileOffset) {
|
||||
*dest = *copySource;
|
||||
dest++;
|
||||
ts++;
|
||||
if (dest == endPtr)
|
||||
{
|
||||
if (dest == endPtr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*(refCurrent++) = *copySource;
|
||||
if (refCurrent == refEnd)
|
||||
{
|
||||
if (refCurrent == refEnd) {
|
||||
refCurrent = refBuf;
|
||||
}
|
||||
copySource++;
|
||||
if (copySource == refEnd)
|
||||
{
|
||||
if (copySource == refEnd) {
|
||||
copySource = refBuf;
|
||||
}
|
||||
readCount++;
|
||||
numBytes--;
|
||||
} while (numBytes != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
} else {
|
||||
do {
|
||||
*dest = *copySource;
|
||||
dest++;
|
||||
ts++;
|
||||
if (dest == endPtr)
|
||||
{
|
||||
if (dest == endPtr) {
|
||||
break;
|
||||
}
|
||||
copySource++;
|
||||
readCount++;
|
||||
numBytes--;
|
||||
copySource++;
|
||||
} while (numBytes != 0);
|
||||
}
|
||||
}
|
||||
@@ -480,7 +445,7 @@ static u8* firstSrcData() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (result == -3 || !errorRetry) {
|
||||
if (result == -3 || !JKRDvdRipper::isErrorRetry()) {
|
||||
return NULL;
|
||||
}
|
||||
VIWaitForRetrace();
|
||||
@@ -494,19 +459,23 @@ static u8* firstSrcData() {
|
||||
|
||||
static u8* nextSrcData(u8* src) {
|
||||
u32 limit = szpEnd - src;
|
||||
u8 *buf;
|
||||
if (IS_NOT_ALIGNED(limit, 0x20))
|
||||
buf = szpBuf + 0x20 - (limit & (0x20 - 1));
|
||||
else
|
||||
buf = szpBuf;
|
||||
u8 *dest;
|
||||
if (IS_NOT_ALIGNED(limit, 0x20)) {
|
||||
dest = szpBuf + 0x20 - (limit & (0x20 - 1));
|
||||
} else {
|
||||
dest = szpBuf;
|
||||
}
|
||||
|
||||
memcpy(buf, src, limit);
|
||||
u32 transSize = (uintptr_t)(szpEnd - (buf + limit));
|
||||
if (transSize > transLeft)
|
||||
memcpy(dest, src, limit);
|
||||
u32 transSize = (uintptr_t)(szpEnd - (dest + limit));
|
||||
if (transSize > transLeft) {
|
||||
transSize = transLeft;
|
||||
}
|
||||
JUT_ASSERT(1208, transSize > 0);
|
||||
|
||||
while (true)
|
||||
{
|
||||
s32 result = DVDReadPrio(srcFile->getFileInfo(), (buf + limit), transSize, srcOffset, 2);
|
||||
s32 result = DVDReadPrio(srcFile->getFileInfo(), (dest + limit), transSize, srcOffset, 2);
|
||||
if (result >= 0)
|
||||
break;
|
||||
// bug: supposed to call isErrorRetry, but didn't
|
||||
@@ -515,15 +484,11 @@ static u8* nextSrcData(u8* src) {
|
||||
|
||||
VIWaitForRetrace();
|
||||
}
|
||||
DCInvalidateRange((buf + limit), transSize);
|
||||
DCInvalidateRange((dest + limit), transSize);
|
||||
srcOffset += transSize;
|
||||
transLeft -= transSize;
|
||||
if (transLeft == 0)
|
||||
srcLimit = transSize + (buf + limit);
|
||||
srcLimit = transSize + (dest + limit);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
u8 JKRDvdRipper::isErrorRetry() {
|
||||
return errorRetry;
|
||||
return dest;
|
||||
}
|
||||
|
||||
+258
-126
@@ -5,19 +5,51 @@
|
||||
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
||||
|
||||
#include "JSystem/JKernel/JKRExpHeap.h"
|
||||
#include "JSystem/JGadget/binary.h"
|
||||
#include "JSystem/JSupport/JSupport.h"
|
||||
#include "JSystem/JUtility/JUTConsole.h"
|
||||
#include "JSystem/JUtility/JUTException.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
JKRExpHeap* JKRExpHeap::createRoot(int maxHeaps, bool errorFlag) {
|
||||
JKRExpHeap* heap = NULL;
|
||||
if (!sRootHeap) {
|
||||
void* memory;
|
||||
u32 memorySize;
|
||||
initArena((char**)&memory, &memorySize, maxHeaps);
|
||||
u8* start = (u8*)memory + ALIGN_NEXT(sizeof(JKRExpHeap), 0x10);
|
||||
u32 alignedSize = memorySize - ALIGN_NEXT(sizeof(JKRExpHeap), 0x10);
|
||||
heap = new (memory) JKRExpHeap(start, alignedSize, NULL, errorFlag);
|
||||
#if !PLATFORM_GCN
|
||||
u8* mem2;
|
||||
u32 mem2Size;
|
||||
initArena2((char**)&mem2, &mem2Size, 1);
|
||||
u32 local_1c = ALIGN_NEXT(sizeof(JKRExpHeap), 0x10);
|
||||
u8* local_20 = mem2 + local_1c;
|
||||
u32 local_24 = mem2Size - local_1c;
|
||||
#if DEBUG
|
||||
if (local_20) {
|
||||
u8* local_28 = local_20;
|
||||
u32 local_2c = local_24;
|
||||
if (isDefaultDebugFill()) {
|
||||
JKRFillMemory(local_28, local_2c, JKRValue_DEBUGFILL_NOTUSE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
JKRExpHeap* heap2 = new (mem2) JKRExpHeap(local_20, local_24, NULL, errorFlag);
|
||||
sRootHeap2 = heap2;
|
||||
heap2->field_0x6e = true;
|
||||
#endif
|
||||
void* mem1;
|
||||
u32 mem1Size;
|
||||
initArena((char**)&mem1, &mem1Size, maxHeaps);
|
||||
u32 local_3c = ALIGN_NEXT(sizeof(JKRExpHeap), 0x10);
|
||||
u8* start1 = (u8*)mem1 + local_3c;
|
||||
u32 alignedSize = mem1Size - local_3c;
|
||||
#if DEBUG
|
||||
if (start1) {
|
||||
u8* local_4c = start1;
|
||||
u32 local_48 = alignedSize;
|
||||
if (isDefaultDebugFill()) {
|
||||
JKRFillMemory(local_4c, local_48, JKRValue_DEBUGFILL_NOTUSE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
heap = new (mem1) JKRExpHeap(start1, alignedSize, NULL, errorFlag);
|
||||
sRootHeap = heap;
|
||||
}
|
||||
heap->field_0x6e = true;
|
||||
@@ -25,17 +57,20 @@ JKRExpHeap* JKRExpHeap::createRoot(int maxHeaps, bool errorFlag) {
|
||||
}
|
||||
|
||||
JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) {
|
||||
JKRExpHeap* newHeap = NULL;
|
||||
if (!parent) {
|
||||
parent = sRootHeap;
|
||||
}
|
||||
u32 expHeapSize = ALIGN_NEXT(sizeof(JKRExpHeap), 0x10);
|
||||
u32 blockSize = sizeof(CMemBlock);
|
||||
|
||||
if (size == 0xffffffff) {
|
||||
size = parent->getMaxAllocatableSize(0x10);
|
||||
}
|
||||
|
||||
u32 alignedSize = ALIGN_PREV(size, 0x10);
|
||||
u32 expHeapSize = ALIGN_NEXT(sizeof(JKRExpHeap), 0x10);
|
||||
if (alignedSize < 0xa0)
|
||||
|
||||
if (alignedSize < expHeapSize + blockSize)
|
||||
return NULL;
|
||||
|
||||
u8* memory = (u8*)JKRAllocFromHeap(parent, alignedSize, 0x10);
|
||||
@@ -44,14 +79,21 @@ JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JKRExpHeap* newHeap =
|
||||
new (memory) JKRExpHeap(dataPtr, alignedSize - expHeapSize, parent, errorFlag);
|
||||
newHeap = new (memory) JKRExpHeap(dataPtr, alignedSize - expHeapSize, parent, errorFlag);
|
||||
|
||||
if (newHeap == NULL) {
|
||||
JKRFree(memory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
if (newHeap) {
|
||||
u8* local_30 = dataPtr + sizeof(CMemBlock);
|
||||
u32 local_34 = newHeap->mHeadFreeList->size;
|
||||
if (isDefaultDebugFill()) {
|
||||
JKRFillMemory(local_30, local_34, JKRValue_DEBUGFILL_NOTUSE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
newHeap->field_0x6e = false;
|
||||
return newHeap;
|
||||
}
|
||||
@@ -59,7 +101,7 @@ JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) {
|
||||
JKRExpHeap* JKRExpHeap::create(void* ptr, u32 size, JKRHeap* parent, bool errorFlag) {
|
||||
JKRHeap* parent2;
|
||||
if (parent == NULL) {
|
||||
parent2 = sRootHeap->find(ptr);
|
||||
parent2 = getRootHeap()->find(ptr);
|
||||
if (!parent2)
|
||||
return NULL;
|
||||
} else {
|
||||
@@ -71,12 +113,21 @@ JKRExpHeap* JKRExpHeap::create(void* ptr, u32 size, JKRHeap* parent, bool errorF
|
||||
if (size < expHeapSize)
|
||||
return NULL;
|
||||
|
||||
void* dataPtr = (u8*)ptr + expHeapSize;
|
||||
u8* r28 = (u8*)ptr;
|
||||
u8* dataPtr = r28 + expHeapSize;
|
||||
u32 alignedSize = ALIGN_PREV((uintptr_t)ptr + size - (uintptr_t)dataPtr, 0x10);
|
||||
if (ptr) {
|
||||
newHeap = new (ptr) JKRExpHeap(dataPtr, alignedSize, parent2, errorFlag);
|
||||
if (r28) {
|
||||
newHeap = new (r28) JKRExpHeap(dataPtr, alignedSize, parent2, errorFlag);
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
if (newHeap) {
|
||||
u8* local_30 = dataPtr + sizeof(CMemBlock);
|
||||
u32 local_34 = newHeap->mHeadFreeList->size;
|
||||
if (isDefaultDebugFill()) {
|
||||
JKRFillMemory(local_30, local_34, JKRValue_DEBUGFILL_NOTUSE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
newHeap->field_0x6e = true;
|
||||
newHeap->field_0x70 = ptr;
|
||||
newHeap->field_0x74 = size;
|
||||
@@ -85,13 +136,20 @@ JKRExpHeap* JKRExpHeap::create(void* ptr, u32 size, JKRHeap* parent, bool errorF
|
||||
|
||||
void JKRExpHeap::do_destroy() {
|
||||
if (!field_0x6e) {
|
||||
JKRHeap* heap = mChildTree.getParent()->getObject();
|
||||
JKRHeap* heap = getParent();
|
||||
if (heap) {
|
||||
this->~JKRExpHeap();
|
||||
JKRHeap::free(this, heap);
|
||||
JKRFreeToHeap(heap, this);
|
||||
}
|
||||
} else {
|
||||
u8* r28 = (u8*)field_0x70;
|
||||
u32 r27 = field_0x74;
|
||||
this->~JKRExpHeap();
|
||||
#if DEBUG
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory(r28, r27, JKRValue_DEBUGFILL_NOTUSE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,13 +169,21 @@ JKRExpHeap::~JKRExpHeap() {
|
||||
}
|
||||
|
||||
void* JKRExpHeap::do_alloc(u32 size, int alignment) {
|
||||
void* ptr;
|
||||
#if DEBUG
|
||||
if (alignment) {
|
||||
u32 u = abs(alignment);
|
||||
JUT_CONFIRM(356, u < 0x80);
|
||||
JUT_CONFIRM(357, JGadget::binary::isPower2( u ));
|
||||
}
|
||||
#endif
|
||||
|
||||
lock();
|
||||
if (size < 4) {
|
||||
size = 4;
|
||||
}
|
||||
|
||||
void* ptr = NULL;
|
||||
|
||||
if (alignment >= 0) {
|
||||
if (alignment <= 4) {
|
||||
ptr = allocFromHead(size);
|
||||
@@ -131,10 +197,24 @@ void* JKRExpHeap::do_alloc(u32 size, int alignment) {
|
||||
ptr = allocFromTail(size, -alignment);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
if (ptr) {
|
||||
CMemBlock* block = (CMemBlock*)((u8*)ptr - sizeof(CMemBlock));
|
||||
if (mCheckMemoryFilled) {
|
||||
JKRHeap::checkMemoryFilled((u8*)ptr, block->size, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory((u8*)ptr, block->size, JKRValue_DEBUGFILL_NEW);
|
||||
}
|
||||
if (block->getAlignment() && mDebugFill) {
|
||||
JKRFillMemory((u8*)ptr - sizeof(CMemBlock) - block->getAlignment(), block->getAlignment(), JKRValue_DEBUGFILL_NEW);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ptr == NULL) {
|
||||
JUTWarningConsole_f(":::cannot alloc memory (0x%x byte).\n", size);
|
||||
if (mErrorFlag == true) {
|
||||
if (getErrorFlag() == true) {
|
||||
callErrorHandler(this, size, alignment);
|
||||
}
|
||||
}
|
||||
@@ -156,14 +236,13 @@ static JKRExpHeap::CMemBlock* DBnewUsedBlock;
|
||||
void* JKRExpHeap::allocFromHead(u32 size, int align) {
|
||||
u32 foundOffset;
|
||||
int foundSize;
|
||||
CMemBlock* newFreeBlock;
|
||||
CMemBlock* newUsedBlock;
|
||||
CMemBlock* foundBlock;
|
||||
|
||||
size = ALIGN_NEXT(size, 4);
|
||||
foundSize = -1;
|
||||
foundOffset = 0;
|
||||
foundBlock = NULL;
|
||||
CMemBlock* foundBlock = NULL;
|
||||
CMemBlock* newFreeBlock = NULL;
|
||||
CMemBlock* newUsedBlock = NULL;
|
||||
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
|
||||
u32 offset =
|
||||
@@ -183,8 +262,7 @@ void* JKRExpHeap::allocFromHead(u32 size, int align) {
|
||||
break;
|
||||
}
|
||||
|
||||
u32 blockSize = block->size;
|
||||
if (blockSize == size) {
|
||||
if (foundSize == size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -236,17 +314,12 @@ void* JKRExpHeap::allocFromHead(u32 size, int align) {
|
||||
} else {
|
||||
CMemBlock* prev = foundBlock->mPrev;
|
||||
CMemBlock* next = foundBlock->mNext;
|
||||
// Works but very fake match
|
||||
size = (uintptr_t)foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0);
|
||||
|
||||
newFreeBlock = foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0);
|
||||
removeFreeBlock(foundBlock);
|
||||
if (size) {
|
||||
setFreeBlock((CMemBlock*)size, prev, next);
|
||||
if (newFreeBlock) {
|
||||
setFreeBlock(newFreeBlock, prev, next);
|
||||
}
|
||||
// newFreeBlock = foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0);
|
||||
// removeFreeBlock(foundBlock);
|
||||
// if (newFreeBlock) {
|
||||
// setFreeBlock(newFreeBlock, prev, next);
|
||||
// }
|
||||
appendUsedList(foundBlock);
|
||||
return foundBlock->getContent();
|
||||
}
|
||||
@@ -260,16 +333,17 @@ void* JKRExpHeap::allocFromHead(u32 size) {
|
||||
size = ALIGN_NEXT(size, 4);
|
||||
s32 foundSize = -1;
|
||||
CMemBlock* foundBlock = NULL;
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->getNextBlock()) {
|
||||
if (block->getSize() < size) {
|
||||
CMemBlock* newblock = NULL;
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
|
||||
if (block->size < size) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (foundSize <= block->getSize()) {
|
||||
if (foundSize <= block->size) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foundSize = block->getSize();
|
||||
foundSize = block->size;
|
||||
foundBlock = block;
|
||||
if (mAllocMode != 0) {
|
||||
break;
|
||||
@@ -281,9 +355,9 @@ void* JKRExpHeap::allocFromHead(u32 size) {
|
||||
}
|
||||
|
||||
if (foundBlock) {
|
||||
CMemBlock* newblock = foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0);
|
||||
newblock = foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0);
|
||||
if (newblock) {
|
||||
setFreeBlock(newblock, foundBlock->getPrevBlock(), foundBlock->getNextBlock());
|
||||
setFreeBlock(newblock, foundBlock->mPrev, foundBlock->mNext);
|
||||
} else {
|
||||
removeFreeBlock(foundBlock);
|
||||
}
|
||||
@@ -294,6 +368,7 @@ void* JKRExpHeap::allocFromHead(u32 size) {
|
||||
}
|
||||
|
||||
void* JKRExpHeap::allocFromTail(u32 size, int align) {
|
||||
u32 local_2c = 0;
|
||||
u32 offset = 0;
|
||||
CMemBlock* foundBlock = NULL;
|
||||
CMemBlock* newBlock = NULL;
|
||||
@@ -304,6 +379,7 @@ void* JKRExpHeap::allocFromTail(u32 size, int align) {
|
||||
start = ALIGN_PREV((uintptr_t)block->getContent() + block->size - size, align);
|
||||
usedSize = (uintptr_t)block->getContent() + block->size - start;
|
||||
if (block->size >= usedSize) {
|
||||
local_2c = usedSize;
|
||||
foundBlock = block;
|
||||
offset = block->size - usedSize;
|
||||
newBlock = (CMemBlock*)start - 1;
|
||||
@@ -336,18 +412,19 @@ void* JKRExpHeap::allocFromTail(u32 size, int align) {
|
||||
}
|
||||
|
||||
void* JKRExpHeap::allocFromTail(u32 size) {
|
||||
u32 size2 = ALIGN_NEXT(size, 4);
|
||||
size = ALIGN_NEXT(size, 4);
|
||||
CMemBlock* foundBlock = NULL;
|
||||
for (CMemBlock* block = mTailFreeList; block; block = block->getPrevBlock()) {
|
||||
if (block->getSize() >= size2) {
|
||||
CMemBlock* freeBlock = NULL;
|
||||
CMemBlock* usedBlock = NULL;
|
||||
for (CMemBlock* block = mTailFreeList; block; block = block->mPrev) {
|
||||
if (block->size >= size) {
|
||||
foundBlock = block;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundBlock != NULL) {
|
||||
CMemBlock* usedBlock = foundBlock->allocBack(size2, 0, 0, mCurrentGroupId, 0);
|
||||
CMemBlock* freeBlock;
|
||||
usedBlock = foundBlock->allocBack(size, 0, 0, mCurrentGroupId, 0);
|
||||
if (usedBlock) {
|
||||
freeBlock = foundBlock;
|
||||
} else {
|
||||
@@ -357,7 +434,7 @@ void* JKRExpHeap::allocFromTail(u32 size) {
|
||||
}
|
||||
|
||||
if (freeBlock) {
|
||||
setFreeBlock(freeBlock, foundBlock->getPrevBlock(), foundBlock->getNextBlock());
|
||||
setFreeBlock(freeBlock, foundBlock->mPrev, foundBlock->mNext);
|
||||
}
|
||||
appendUsedList(usedBlock);
|
||||
return usedBlock->getContent();
|
||||
@@ -367,31 +444,42 @@ void* JKRExpHeap::allocFromTail(u32 size) {
|
||||
|
||||
void JKRExpHeap::do_free(void* ptr) {
|
||||
lock();
|
||||
if (getStartAddr() <= ptr && ptr <= getEndAddr()) {
|
||||
if (mStart <= ptr && ptr <= mEnd) {
|
||||
CMemBlock* block = CMemBlock::getHeapBlock(ptr);
|
||||
if (block) {
|
||||
block->free(this);
|
||||
}
|
||||
} else {
|
||||
JUT_WARN(921, "free: memblock %x not in heap %x", ptr, this);
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
static void dummy() {
|
||||
OS_REPORT("newSize > 0");
|
||||
}
|
||||
|
||||
void JKRExpHeap::do_freeAll() {
|
||||
lock();
|
||||
JKRHeap::callAllDisposer();
|
||||
mHeadFreeList = (CMemBlock*)getStartAddr();
|
||||
mHeadFreeList = (CMemBlock*)mStart;
|
||||
mTailFreeList = mHeadFreeList;
|
||||
mHeadFreeList->initiate(NULL, NULL, getSize() - 0x10, 0, 0);
|
||||
mHeadFreeList->initiate(NULL, NULL, mSize - 0x10, 0, 0);
|
||||
mHeadUsedList = NULL;
|
||||
mTailUsedList = NULL;
|
||||
#if DEBUG
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory((u8*)(mHeadFreeList + 1), mHeadFreeList->size, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
#endif
|
||||
unlock();
|
||||
}
|
||||
|
||||
void JKRExpHeap::do_freeTail() {
|
||||
lock();
|
||||
for (CMemBlock* block = mHeadUsedList; block != NULL;) {
|
||||
if ((block->mFlags & 0x80) != 0) {
|
||||
dispose(block + 1, block->size);
|
||||
if (block->isTempMemBlock()) {
|
||||
dispose(block->getContent(), block->size);
|
||||
CMemBlock* temp = block->mNext;
|
||||
block->free(this);
|
||||
block = temp;
|
||||
@@ -402,7 +490,15 @@ void JKRExpHeap::do_freeTail() {
|
||||
unlock();
|
||||
}
|
||||
|
||||
void JKRExpHeap::do_fillFreeArea() {}
|
||||
void JKRExpHeap::do_fillFreeArea() {
|
||||
#if DEBUG
|
||||
lock();
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
|
||||
JKRFillMemory((u8*)block->getContent(), block->size, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
s32 JKRExpHeap::do_changeGroupID(u8 param_0) {
|
||||
lock();
|
||||
@@ -445,6 +541,7 @@ s32 JKRExpHeap::do_resize(void* ptr, u32 size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
u32 local_24 = block->size;
|
||||
removeFreeBlock(foundBlock);
|
||||
block->size += foundBlock->size + sizeof(CMemBlock);
|
||||
if (block->size - size > sizeof(CMemBlock)) {
|
||||
@@ -453,6 +550,11 @@ s32 JKRExpHeap::do_resize(void* ptr, u32 size) {
|
||||
recycleFreeBlock(newBlock);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory((u8*)ptr + local_24, block->size - local_24, JKRValue_DEBUGFILL_NEW);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
if (block->size - size > sizeof(CMemBlock)) {
|
||||
CMemBlock* freeBlock = block->allocFore(size, block->mGroupId, block->mFlags, 0, 0);
|
||||
@@ -469,20 +571,20 @@ s32 JKRExpHeap::do_resize(void* ptr, u32 size) {
|
||||
s32 JKRExpHeap::do_getSize(void* ptr) {
|
||||
lock();
|
||||
CMemBlock* block = CMemBlock::getHeapBlock(ptr);
|
||||
if (!block || ptr < getStartAddr() || getEndAddr() < ptr) {
|
||||
if (!block || ptr < mStart || mEnd < ptr) {
|
||||
unlock();
|
||||
return -1;
|
||||
}
|
||||
unlock();
|
||||
return block->getSize();
|
||||
return block->size;
|
||||
}
|
||||
|
||||
s32 JKRExpHeap::do_getFreeSize() {
|
||||
lock();
|
||||
s32 size = 0;
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->getNextBlock()) {
|
||||
if (size < (s32)block->getSize()) {
|
||||
size = block->getSize();
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
|
||||
if (size < (s32)block->size) {
|
||||
size = block->size;
|
||||
}
|
||||
}
|
||||
unlock();
|
||||
@@ -493,9 +595,9 @@ void* JKRExpHeap::do_getMaxFreeBlock() {
|
||||
lock();
|
||||
s32 size = 0;
|
||||
CMemBlock* res = NULL;
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->getNextBlock()) {
|
||||
if (size < (s32)block->getSize()) {
|
||||
size = block->getSize();
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
|
||||
if (size < (s32)block->size) {
|
||||
size = block->size;
|
||||
res = block;
|
||||
}
|
||||
}
|
||||
@@ -506,42 +608,46 @@ void* JKRExpHeap::do_getMaxFreeBlock() {
|
||||
s32 JKRExpHeap::do_getTotalFreeSize() {
|
||||
u32 size = 0;
|
||||
lock();
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->getNextBlock()) {
|
||||
size += block->getSize();
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
|
||||
size += block->size;
|
||||
}
|
||||
unlock();
|
||||
return size;
|
||||
}
|
||||
|
||||
s32 JKRExpHeap::getUsedSize(u8 groupId) const {
|
||||
JKRExpHeap* this2 = const_cast<JKRExpHeap*>(this);
|
||||
this2->lock();
|
||||
lock();
|
||||
u32 size = 0;
|
||||
|
||||
for (CMemBlock* block = mHeadUsedList; block; block = block->getNextBlock()) {
|
||||
u8 blockGroupId = block->getGroupId();
|
||||
if (blockGroupId == groupId) {
|
||||
size += block->getSize() + sizeof(CMemBlock);
|
||||
for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) {
|
||||
if (block->mGroupId == groupId) {
|
||||
size += block->size + sizeof(CMemBlock);
|
||||
}
|
||||
}
|
||||
|
||||
this2->unlock();
|
||||
unlock();
|
||||
return size;
|
||||
}
|
||||
|
||||
s32 JKRExpHeap::getTotalUsedSize() const {
|
||||
JKRExpHeap* this2 = const_cast<JKRExpHeap*>(this);
|
||||
this2->lock();
|
||||
lock();
|
||||
u32 size = 0;
|
||||
|
||||
for (CMemBlock* block = mHeadUsedList; block; block = block->getNextBlock()) {
|
||||
size += block->getSize() + sizeof(CMemBlock);
|
||||
for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) {
|
||||
size += block->size + sizeof(CMemBlock);
|
||||
}
|
||||
|
||||
this2->unlock();
|
||||
unlock();
|
||||
return size;
|
||||
}
|
||||
|
||||
BOOL JKRExpHeap::isEmpty() {
|
||||
lock();
|
||||
BOOL result = !mHeadUsedList ? TRUE : FALSE;
|
||||
unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
void JKRExpHeap::appendUsedList(JKRExpHeap::CMemBlock* newblock) {
|
||||
if (!newblock) {
|
||||
JUTException::panic(__FILE__, 1568, "bad appendUsedList\n");
|
||||
@@ -621,18 +727,24 @@ void JKRExpHeap::removeUsedBlock(JKRExpHeap::CMemBlock* block) {
|
||||
void JKRExpHeap::recycleFreeBlock(JKRExpHeap::CMemBlock* block) {
|
||||
JKRExpHeap::CMemBlock* newBlock = block;
|
||||
int size = block->size;
|
||||
void* blockEnd = (u8*)block + size;
|
||||
void* blockEnd = (u8*)newBlock + size;
|
||||
block->mMagic = 0;
|
||||
|
||||
if ((block->mFlags & 0x7f) != 0) {
|
||||
newBlock = (CMemBlock*)((u8*)block - (block->mFlags & 0x7f));
|
||||
newBlock = (CMemBlock*)((u8*)newBlock - (block->mFlags & 0x7f));
|
||||
size += (block->mFlags & 0x7f);
|
||||
blockEnd = (u8*)newBlock + size;
|
||||
newBlock->mGroupId = 0;
|
||||
newBlock->mFlags = 0;
|
||||
newBlock->size = size;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
u8* local_24 = (u8*)(newBlock + 1);
|
||||
u32 local_28 = newBlock->size;
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory(local_24, local_28, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
#endif
|
||||
if (!mHeadFreeList) {
|
||||
newBlock->initiate(NULL, NULL, size, 0, 0);
|
||||
mHeadFreeList = newBlock;
|
||||
@@ -676,13 +788,26 @@ void JKRExpHeap::joinTwoBlocks(CMemBlock* block) {
|
||||
u32 nextAddr = (uintptr_t)next - (next->mFlags & 0x7f);
|
||||
if (endAddr > nextAddr) {
|
||||
JUTWarningConsole_f(":::Heap may be broken. (block = %x)", block);
|
||||
JKRGetCurrentHeap()->dump();
|
||||
OS_REPORT(":::block = %x\n", block);
|
||||
OS_REPORT(":::joinTwoBlocks [%x %x %x][%x %x %x]\n", block, block->mFlags, block->size, block->mNext, block->mNext->mFlags, block->mNext->size);
|
||||
OS_REPORT(":::: endAddr = %x\n", endAddr);
|
||||
OS_REPORT(":::: nextAddr = %x\n", nextAddr);
|
||||
JKRHeap* heap = JKRGetCurrentHeap();
|
||||
heap->dump();
|
||||
JUTException::panic(__FILE__, 1820, "Bad Block\n");
|
||||
}
|
||||
|
||||
if (endAddr == nextAddr) {
|
||||
block->size = next->size + sizeof(CMemBlock) + next->getAlignment() + block->size;
|
||||
setFreeBlock(block, block->mPrev, next->mNext);
|
||||
block->size = next->size + sizeof(CMemBlock) + (next->mFlags & 0x7f) + block->size;
|
||||
CMemBlock* local_30 = next->mNext;
|
||||
#if DEBUG
|
||||
u8* local_34 = (u8*)next;
|
||||
u32 local_38 = sizeof(CMemBlock);
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory(local_34, local_38, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
#endif
|
||||
setFreeBlock(block, block->mPrev, local_30);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,14 +816,14 @@ bool JKRExpHeap::check() {
|
||||
int totalBytes = 0;
|
||||
bool ok = true;
|
||||
for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) {
|
||||
if (!block->isValid()) {
|
||||
if (block->mMagic != 'HM') {
|
||||
ok = false;
|
||||
JUTWarningConsole_f(":::addr %08x: bad heap signature. (%c%c)\n", block,
|
||||
JSUHiByte(block->mMagic), JSULoByte(block->mMagic));
|
||||
}
|
||||
|
||||
if (block->mNext) {
|
||||
if (!block->mNext->isValid()) {
|
||||
if (block->mNext->mMagic != 'HM') {
|
||||
ok = false;
|
||||
JUTWarningConsole_f(":::addr %08x: bad next pointer (%08x)\nabort\n", block,
|
||||
block->mNext);
|
||||
@@ -739,6 +864,13 @@ bool JKRExpHeap::check() {
|
||||
mTailFreeList);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
if (mCheckMemoryFilled) {
|
||||
u8* local_34 = (u8*)block->getContent();
|
||||
u32 local_38 = block->size;
|
||||
ok = JKRHeap::checkMemoryFilled(local_34, local_38, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (totalBytes != mSize) {
|
||||
@@ -768,7 +900,7 @@ bool JKRExpHeap::dump() {
|
||||
}
|
||||
|
||||
for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) {
|
||||
if (!block->isValid()) {
|
||||
if (block->mMagic != 'HM') {
|
||||
JUTReportConsole_f("xxxxx %08x: -------- --- --- (-------- --------)\nabort\n",
|
||||
block);
|
||||
break;
|
||||
@@ -794,8 +926,7 @@ bool JKRExpHeap::dump() {
|
||||
freeCount++;
|
||||
}
|
||||
|
||||
float percent = ((float)usedBytes / (float)mSize) * 100.0f;
|
||||
JUTReportConsole_f("%d / %d bytes (%6.2f%%) used (U:%d F:%d)\n", usedBytes, mSize, percent,
|
||||
JUTReportConsole_f("%d / %d bytes (%6.2f%%) used (U:%d F:%d)\n", usedBytes, mSize, (f32(usedBytes) / f32(mSize)) * 100.0f,
|
||||
usedCount, freeCount);
|
||||
unlock();
|
||||
return result;
|
||||
@@ -822,21 +953,18 @@ bool JKRExpHeap::dump_sort() {
|
||||
}
|
||||
}
|
||||
|
||||
if (block == (CMemBlock*)0xffffffff) {
|
||||
if (uintptr_t(block) == 0xffffffff) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!block->isValid()) {
|
||||
if (block->mMagic != 'HM') {
|
||||
JUTReportConsole_f("xxxxx %08x: -------- --- --- (-------- --------)\nabort\n",
|
||||
var1);
|
||||
break;
|
||||
}
|
||||
|
||||
int offset = block->getAlignment();
|
||||
void* content = block->getContent();
|
||||
const char* type = block->isTempMemBlock() ? " temp" : "alloc";
|
||||
JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", type, content, block->size,
|
||||
block->getGroupId(), offset, block->mPrev, block->mNext);
|
||||
JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", block->isTempMemBlock() ? " temp" : "alloc", block->getContent(), block->size,
|
||||
block->mGroupId, block->getAlignment(), block->mPrev, block->mNext);
|
||||
usedBytes += sizeof(CMemBlock) + block->size + block->getAlignment();
|
||||
usedCount++;
|
||||
var1 = block;
|
||||
@@ -850,13 +978,12 @@ bool JKRExpHeap::dump_sort() {
|
||||
|
||||
for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) {
|
||||
JUTReportConsole_f("%s %08x: %08x %3d %3d (%08x %08x)\n", " free", block->getContent(),
|
||||
block->size, block->getGroupId(), block->getAlignment(), block->mPrev,
|
||||
block->size, block->mGroupId, block->getAlignment(), block->mPrev,
|
||||
block->mNext);
|
||||
freeCount++;
|
||||
}
|
||||
|
||||
float percent = ((float)usedBytes / (float)mSize) * 100.0f;
|
||||
JUTReportConsole_f("%d / %d bytes (%6.2f%%) used (U:%d F:%d)\n", usedBytes, mSize, percent,
|
||||
JUTReportConsole_f("%d / %d bytes (%6.2f%%) used (U:%d F:%d)\n", usedBytes, mSize, (f32(usedBytes) / f32(mSize)) * 100.0f,
|
||||
usedCount, freeCount);
|
||||
unlock();
|
||||
return result;
|
||||
@@ -872,33 +999,33 @@ void JKRExpHeap::CMemBlock::initiate(JKRExpHeap::CMemBlock* prev, JKRExpHeap::CM
|
||||
mNext = next;
|
||||
}
|
||||
|
||||
JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocFore(u32 size, u8 groupId1, u8 alignment1,
|
||||
JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocFore(u32 size1, u8 groupId1, u8 alignment1,
|
||||
u8 groupId2, u8 alignment2) {
|
||||
CMemBlock* block = NULL;
|
||||
mGroupId = groupId1;
|
||||
mFlags = alignment1;
|
||||
if (getSize() >= size + sizeof(CMemBlock)) {
|
||||
block = (CMemBlock*)(size + (uintptr_t)this);
|
||||
if (size >= size1 + sizeof(CMemBlock)) {
|
||||
block = (CMemBlock*)(size1 + (uintptr_t)this);
|
||||
block[1].mGroupId = groupId2;
|
||||
block[1].mFlags = alignment2;
|
||||
block[1].size = this->size - (size + sizeof(CMemBlock));
|
||||
this->size = size;
|
||||
block[1].size = size - (size1 + sizeof(CMemBlock));
|
||||
size = size1;
|
||||
block = block + 1;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocBack(u32 size, u8 groupId1, u8 alignment1,
|
||||
JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocBack(u32 size1, u8 groupId1, u8 alignment1,
|
||||
u8 groupId2, u8 alignment2) {
|
||||
CMemBlock* newblock = NULL;
|
||||
if (getSize() >= size + sizeof(CMemBlock)) {
|
||||
newblock = (CMemBlock*)((uintptr_t)this + getSize() - size);
|
||||
if (size >= size1 + sizeof(CMemBlock)) {
|
||||
newblock = (CMemBlock*)((uintptr_t)this + size - size1);
|
||||
newblock->mGroupId = groupId2;
|
||||
newblock->mFlags = alignment2 | 0x80;
|
||||
newblock->size = size;
|
||||
newblock->size = size1;
|
||||
mGroupId = groupId1;
|
||||
mFlags = alignment1;
|
||||
this->size -= size + sizeof(CMemBlock);
|
||||
this->size -= size1 + sizeof(CMemBlock);
|
||||
} else {
|
||||
mGroupId = groupId2;
|
||||
mFlags = 0x80;
|
||||
@@ -922,36 +1049,51 @@ JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::getHeapBlock(void* ptr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void dummy2() {
|
||||
DEAD_STRING("+---------------JKRExpHeap\n");
|
||||
DEAD_STRING("| Align Group size ( prev , next )\n");
|
||||
DEAD_STRING("| ---- FreeFirst\n");
|
||||
DEAD_STRING("| %08x ");
|
||||
DEAD_STRING("%2x %3d %6x (%08x %08x)\n");
|
||||
DEAD_STRING("| ---- FreeLast\n");
|
||||
DEAD_STRING("| ---- UsedFirst\n");
|
||||
DEAD_STRING("| ---- UsedLast\n");
|
||||
DEAD_STRING("+---------------End\n");
|
||||
}
|
||||
|
||||
void JKRExpHeap::state_register(JKRHeap::TState* p, u32 param_1) const {
|
||||
p->mId = param_1;
|
||||
JUT_ASSERT(2433, p != NULL);
|
||||
JUT_ASSERT(2434, p->getHeap() == this);
|
||||
void* r24 = getState_(p);
|
||||
u32 r25 = param_1;
|
||||
setState_u32ID_(p, param_1);
|
||||
if (param_1 <= 0xff) {
|
||||
p->mUsedSize = getUsedSize(param_1);
|
||||
setState_uUsedSize_(p, getUsedSize(r25));
|
||||
} else {
|
||||
s32 freeSize = const_cast<JKRExpHeap*>(this)->getTotalFreeSize();
|
||||
p->mUsedSize = getSize() - freeSize;
|
||||
setState_uUsedSize_(p, getUsedSize_(const_cast<JKRExpHeap*>(this)));
|
||||
}
|
||||
|
||||
u32 checkCode = 0;
|
||||
for (CMemBlock* block = mHeadUsedList; block; block = block->getNextBlock()) {
|
||||
for (CMemBlock* block = mHeadUsedList; block; block = block->mNext) {
|
||||
if (param_1 <= 0xff) {
|
||||
u8 groupId = block->getGroupId();
|
||||
if (groupId == param_1) {
|
||||
if (block->mGroupId == param_1) {
|
||||
checkCode += (uintptr_t)block * 3;
|
||||
}
|
||||
} else {
|
||||
checkCode += (uintptr_t)block * 3;
|
||||
}
|
||||
}
|
||||
p->mCheckCode = checkCode;
|
||||
setState_u32CheckCode_(p, checkCode);
|
||||
}
|
||||
|
||||
bool JKRExpHeap::state_compare(JKRHeap::TState const& r1, JKRHeap::TState const& r2) const {
|
||||
JUT_ASSERT(2481, r1.getHeap() == r2.getHeap());
|
||||
bool result = true;
|
||||
if (r1.mCheckCode != r2.mCheckCode) {
|
||||
if (r1.getCheckCode() != r2.getCheckCode()) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (r1.mUsedSize != r2.mUsedSize) {
|
||||
if (r1.getUsedSize() != r2.getUsedSize()) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
@@ -965,13 +1107,3 @@ u32 JKRExpHeap::getHeapType() {
|
||||
u8 JKRExpHeap::do_getCurrentGroupId() {
|
||||
return mCurrentGroupId;
|
||||
}
|
||||
|
||||
static char* dummyLiteral1() { return "+---------------JKRExpHeap\n"; }
|
||||
static char* dummyLiteral2() { return "| Align Group size ( prev , next )\n"; }
|
||||
static char* dummyLiteral3() { return "| ---- FreeFirst\n"; }
|
||||
static char* dummyLiteral4() { return "| %08x "; }
|
||||
static char* dummyLiteral5() { return "%2x %3d %6x (%08x %08x)\n"; }
|
||||
static char* dummyLiteral6() { return "| ---- FreeLast\n"; }
|
||||
static char* dummyLiteral7() { return "| ---- UsedFirst\n"; }
|
||||
static char* dummyLiteral8() { return "| ---- UsedLast\n"; }
|
||||
static char* dummyLiteral9() { return "+---------------End\n"; }
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
#include "JSystem/JKernel/JKRFile.h"
|
||||
#include "dolphin/vi.h"
|
||||
|
||||
s32 JKRFile::read(void* data, s32 size, s32 offset) {
|
||||
void JKRFile::read(void* data, s32 length, s32 offset) {
|
||||
JUT_ASSERT(32, ( length & 0x1f ) == 0);
|
||||
while (true) {
|
||||
s32 result = readData(data, size, offset);
|
||||
if (size != result)
|
||||
if (length != readData(data, length, offset)) {
|
||||
VIWaitForRetrace();
|
||||
else
|
||||
return result;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,9 @@ JKRFileCache* JKRFileCache::mount(const char* path, JKRHeap* heap, const char* p
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSUList<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> iterator;
|
||||
for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRFileLoader> iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) {
|
||||
if (iterator->getVolumeType() == 'CASH') {
|
||||
JKRFileCache* fileCache = (JKRFileCache*)iterator.getObject();
|
||||
JKRFileCache* fileCache = (JKRFileCache*)iterator.operator->();
|
||||
if (fileCache->mRootPath) {
|
||||
if (strcmp(fileCache->mRootPath, path) == 0) {
|
||||
fileCache->mMountCount++;
|
||||
@@ -34,7 +32,9 @@ JKRFileCache* JKRFileCache::mount(const char* path, JKRHeap* heap, const char* p
|
||||
}
|
||||
}
|
||||
|
||||
return new (heap, 0) JKRFileCache(path, param_3);
|
||||
|
||||
JKRFileCache* fileCache = new (heap, 0) JKRFileCache(path, param_3);
|
||||
return fileCache;
|
||||
}
|
||||
|
||||
JKRFileCache::JKRFileCache(const char* path, const char* volume) {
|
||||
@@ -54,30 +54,27 @@ JKRFileCache::JKRFileCache(const char* path, const char* volume) {
|
||||
strcat(mCurrentPath, "/");
|
||||
|
||||
const char* volumePath = volume;
|
||||
if (!volume) {
|
||||
volumePath = strrchr(mRootPath, '/');
|
||||
volumePath++;
|
||||
if (!volumePath) {
|
||||
volumePath = strrchr(mRootPath, '/') + 1;
|
||||
}
|
||||
|
||||
u32 volumeLength = strlen(volumePath) + 1;
|
||||
mVolumePath = (char*)JKRAllocFromSysHeap(volumeLength, 0);
|
||||
mVolumePath = (char*)JKRAllocFromSysHeap(strlen(volumePath) + 1, 0);
|
||||
strcpy(mVolumePath, volumePath);
|
||||
convStrLower(mVolumePath);
|
||||
mVolumeName = mVolumePath;
|
||||
} else {
|
||||
const char* volumePath = volume;
|
||||
if (!volume) {
|
||||
if (!volumePath) {
|
||||
volumePath = "dvd";
|
||||
}
|
||||
|
||||
u32 volumeLength = strlen(volumePath) + 1;
|
||||
mVolumePath = (char*)JKRAllocFromSysHeap(volumeLength, 0);
|
||||
mVolumePath = (char*)JKRAllocFromSysHeap(strlen(volumePath) + 1, 0);
|
||||
strcpy(mVolumePath, volumePath);
|
||||
convStrLower(mVolumePath);
|
||||
mVolumeName = mVolumePath;
|
||||
}
|
||||
|
||||
getVolumeList().prepend(&mFileLoaderLink);
|
||||
sVolumeList.prepend(&mFileLoaderLink);
|
||||
mIsMounted = true;
|
||||
}
|
||||
|
||||
@@ -90,7 +87,7 @@ JKRFileCache::~JKRFileCache() {
|
||||
if (mVolumePath)
|
||||
JKRFreeToSysHeap(mVolumePath);
|
||||
|
||||
getVolumeList().remove(&mFileLoaderLink);
|
||||
sVolumeList.remove(&mFileLoaderLink);
|
||||
}
|
||||
|
||||
bool JKRFileCache::becomeCurrent(const char* path) {
|
||||
@@ -99,13 +96,13 @@ bool JKRFileCache::becomeCurrent(const char* path) {
|
||||
bool result = DVDChangeDir(dvdPathName);
|
||||
if (result) {
|
||||
sCurrentVolume = this;
|
||||
JKRHeap::sSystemHeap->free(mCurrentPath);
|
||||
JKRFreeToSysHeap(mCurrentPath);
|
||||
mCurrentPath = dvdPathName;
|
||||
if (mCurrentPath[1] != '\0') {
|
||||
strcat(mCurrentPath, "/");
|
||||
}
|
||||
} else {
|
||||
JKRHeap::sSystemHeap->free(dvdPathName);
|
||||
JKRFreeToSysHeap(dvdPathName);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -121,13 +118,12 @@ void* JKRFileCache::getResource(const char* path) {
|
||||
if (dvdFile.isAvailable()) {
|
||||
CCacheBlock* cacheBlock = findCacheBlock(dvdFile.getFileID());
|
||||
if (!cacheBlock) {
|
||||
u32 fileSize = dvdFile.getFileInfo()->length;
|
||||
u32 alignedSize = ALIGN_NEXT(fileSize, 0x20);
|
||||
u32 alignedSize = ALIGN_NEXT(dvdFile.getFileInfo()->length, 0x20);
|
||||
buffer = JKRAllocFromHeap(mParentHeap, alignedSize, 0x20);
|
||||
if (buffer) {
|
||||
dvdFile.read(buffer, alignedSize, 0);
|
||||
|
||||
cacheBlock = new (JKRHeap::getSystemHeap(), 0)
|
||||
cacheBlock = new (JKRGetSystemHeap(), 0)
|
||||
CCacheBlock(dvdFile.getFileID(), dvdFile.getFileInfo()->length, buffer);
|
||||
mCacheBlockList.append(&cacheBlock->mCacheBlockLink);
|
||||
}
|
||||
@@ -145,19 +141,17 @@ void* JKRFileCache::getResource(u32, const char* path) {
|
||||
JUT_ASSERT(303, isMounted());
|
||||
|
||||
char finalPath[256];
|
||||
u32 rootLength = strlen(mRootPath);
|
||||
char* filePath = finalPath + rootLength;
|
||||
char* filePath = finalPath + strlen(mRootPath);
|
||||
strcpy(finalPath, mRootPath);
|
||||
|
||||
bool found = findFile(finalPath, path);
|
||||
if (!found)
|
||||
return NULL;
|
||||
|
||||
return getResource(filePath);
|
||||
if (findFile(finalPath, path)) {
|
||||
return getResource(filePath);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u32 JKRFileCache::readResource(void* dst, u32 dstLength, const char* path) {
|
||||
JUT_ASSERT(412, isMounted());
|
||||
JUT_ASSERT(344, isMounted());
|
||||
|
||||
char* name = getDvdPathName(path);
|
||||
JKRDvdFile dvdFile(name);
|
||||
@@ -170,8 +164,7 @@ u32 JKRFileCache::readResource(void* dst, u32 dstLength, const char* path) {
|
||||
if (!dvdFile.isAvailable()) {
|
||||
break;
|
||||
}
|
||||
u32 fileSize = dvdFile.getFileInfo()->length;
|
||||
resourceSize = ALIGN_NEXT(fileSize, 0x20);
|
||||
resourceSize = ALIGN_NEXT(dvdFile.getFileInfo()->length, 0x20);
|
||||
dstLength = ALIGN_PREV(dstLength, 0x20);
|
||||
if (resourceSize > dstLength) {
|
||||
resourceSize = dstLength;
|
||||
@@ -190,30 +183,26 @@ u32 JKRFileCache::readResource(void* dst, u32 dstLength, const char* path) {
|
||||
}
|
||||
|
||||
u32 JKRFileCache::readResource(void* dst, u32 dstLength, u32, const char* path) {
|
||||
JUT_ASSERT(344, isMounted());
|
||||
JUT_ASSERT(412, isMounted());
|
||||
|
||||
char finalPath[256];
|
||||
u32 rootLength = strlen(mRootPath);
|
||||
char* filePath = finalPath + rootLength;
|
||||
char* filePath = finalPath + strlen(mRootPath);
|
||||
strcpy(finalPath, mRootPath);
|
||||
|
||||
bool found = findFile(finalPath, path);
|
||||
if (!found)
|
||||
return NULL;
|
||||
|
||||
return readResource(dst, dstLength, filePath);
|
||||
if (findFile(finalPath, path)) {
|
||||
return readResource(dst, dstLength, filePath);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void JKRFileCache::removeResourceAll(void) {
|
||||
JUT_ASSERT(412, isMounted());
|
||||
JUT_ASSERT(441, isMounted());
|
||||
|
||||
JSUListIterator<CCacheBlock> iterator;
|
||||
iterator = mCacheBlockList.getFirst();
|
||||
JSUListIterator<CCacheBlock> iterator = mCacheBlockList.getFirst();
|
||||
while (iterator != mCacheBlockList.getEnd()) {
|
||||
JKRFreeToHeap(mParentHeap, iterator->mMemoryPtr);
|
||||
mCacheBlockList.remove(&iterator.getObject()->mCacheBlockLink);
|
||||
CCacheBlock* cacheBlock = (iterator++).getObject();
|
||||
delete cacheBlock;
|
||||
delete (iterator++).getObject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,9 +213,7 @@ bool JKRFileCache::removeResource(void* resource) {
|
||||
if (!cacheBlock)
|
||||
return false;
|
||||
|
||||
u32 referenceCount = cacheBlock->mReferenceCount - 1;
|
||||
cacheBlock->mReferenceCount = referenceCount;
|
||||
if (referenceCount == 0) {
|
||||
if (--cacheBlock->mReferenceCount == 0) {
|
||||
JKRFreeToHeap(mParentHeap, resource);
|
||||
mCacheBlockList.remove(&cacheBlock->mCacheBlockLink);
|
||||
delete cacheBlock;
|
||||
@@ -257,14 +244,12 @@ u32 JKRFileCache::getResSize(const void* resource) const {
|
||||
}
|
||||
|
||||
u32 JKRFileCache::countFile(const char* path) const {
|
||||
DVDDir dir;
|
||||
DVDDirEntry dirEntry;
|
||||
|
||||
u32 count = 0;
|
||||
char* name = getDvdPathName(path);
|
||||
BOOL result = DVDOpenDir(name, &dir);
|
||||
if (result != 0) {
|
||||
while (result = DVDReadDir(&dir, &dirEntry), result != FALSE) {
|
||||
DVDDir dir;
|
||||
if (DVDOpenDir(name, &dir) != 0) {
|
||||
DVDDirEntry dirEntry;
|
||||
while (DVDReadDir(&dir, &dirEntry)) {
|
||||
count = count + 1;
|
||||
}
|
||||
|
||||
@@ -277,8 +262,7 @@ u32 JKRFileCache::countFile(const char* path) const {
|
||||
|
||||
JKRFileFinder* JKRFileCache::getFirstFile(const char* path) const {
|
||||
char* name = getDvdPathName(path);
|
||||
JKRHeap* systemHeap = JKRHeap::getSystemHeap();
|
||||
JKRDvdFinder* finder = new (systemHeap, 0) JKRDvdFinder(name);
|
||||
JKRDvdFinder* finder = new (JKRGetSystemHeap(), 0) JKRDvdFinder(name);
|
||||
JKRFreeToSysHeap(name);
|
||||
|
||||
if (finder->isAvailable() != true) {
|
||||
@@ -290,8 +274,7 @@ JKRFileFinder* JKRFileCache::getFirstFile(const char* path) const {
|
||||
}
|
||||
|
||||
JKRFileCache::CCacheBlock* JKRFileCache::findCacheBlock(const void* resource) const {
|
||||
JSUListIterator<CCacheBlock> iterator;
|
||||
for (iterator = mCacheBlockList.getFirst(); iterator != mCacheBlockList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<CCacheBlock> iterator = mCacheBlockList.getFirst(); iterator != mCacheBlockList.getEnd(); ++iterator) {
|
||||
if (iterator->mMemoryPtr == resource) {
|
||||
return iterator.getObject();
|
||||
}
|
||||
@@ -301,8 +284,7 @@ JKRFileCache::CCacheBlock* JKRFileCache::findCacheBlock(const void* resource) co
|
||||
}
|
||||
|
||||
JKRFileCache::CCacheBlock* JKRFileCache::findCacheBlock(u32 fileID) const {
|
||||
JSUListIterator<CCacheBlock> iterator;
|
||||
for (iterator = mCacheBlockList.getFirst(); iterator != mCacheBlockList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<CCacheBlock> iterator = mCacheBlockList.getFirst(); iterator != mCacheBlockList.getEnd(); ++iterator) {
|
||||
if (iterator->mFileId == fileID) {
|
||||
return iterator.getObject();
|
||||
}
|
||||
@@ -312,21 +294,19 @@ JKRFileCache::CCacheBlock* JKRFileCache::findCacheBlock(u32 fileID) const {
|
||||
}
|
||||
|
||||
bool JKRFileCache::findFile(char* path, const char* fileName) const {
|
||||
DVDDir dir;
|
||||
DVDDirEntry dirEntry;
|
||||
|
||||
bool result = false;
|
||||
u32 pathLength = strlen(path);
|
||||
DVDDir dir;
|
||||
if (DVDOpenDir(path, &dir)) {
|
||||
DVDDirEntry dirEntry;
|
||||
while (DVDReadDir(&dir, &dirEntry)) {
|
||||
if (dirEntry.isDir) {
|
||||
char* endOfPath = path + pathLength;
|
||||
*endOfPath = '/';
|
||||
path[pathLength] = '/';
|
||||
strcpy(path + pathLength + 1, dirEntry.name);
|
||||
result = findFile(path, fileName);
|
||||
if (result)
|
||||
break;
|
||||
*endOfPath = '\0';
|
||||
path[pathLength] = '\0';
|
||||
} else {
|
||||
result = (strcmp(fileName, dirEntry.name) == 0);
|
||||
if (result) {
|
||||
@@ -346,8 +326,7 @@ bool JKRFileCache::findFile(char* path, const char* fileName) const {
|
||||
char* JKRFileCache::getDvdPathName(const char* path) const {
|
||||
char* newPath;
|
||||
if (path[0] == '/') {
|
||||
u32 length = strlen(mRootPath) + strlen(path) + 2;
|
||||
newPath = (char*)JKRAllocFromSysHeap(length, 1);
|
||||
newPath = (char*)JKRAllocFromSysHeap(strlen(mRootPath) + strlen(path) + 2, 1);
|
||||
strcpy(newPath, mRootPath);
|
||||
if (path[1]) {
|
||||
if (mRootPath[1] == 0) {
|
||||
@@ -357,8 +336,7 @@ char* JKRFileCache::getDvdPathName(const char* path) const {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
u32 length = strlen(mCurrentPath) + strlen(path) + 2;
|
||||
newPath = (char*)JKRAllocFromSysHeap(length, 1);
|
||||
newPath = (char*)JKRAllocFromSysHeap(strlen(mCurrentPath) + strlen(path) + 2, 1);
|
||||
strcpy(newPath, mCurrentPath);
|
||||
strcat(newPath, path);
|
||||
}
|
||||
|
||||
@@ -13,17 +13,16 @@ JKRArcFinder::JKRArcFinder(JKRArchive* archive, s32 startIndex, s32 numEntries)
|
||||
}
|
||||
|
||||
bool JKRArcFinder::findNextFile(void) {
|
||||
JKRArchive::SDirEntry entry;
|
||||
|
||||
if (mIsAvailable) {
|
||||
mIsAvailable = !(mNextIndex > mEndIndex);
|
||||
if (mIsAvailable) {
|
||||
JKRArchive::SDirEntry entry;
|
||||
mIsAvailable = mArchive->getDirEntry(&entry, mNextIndex);
|
||||
mEntryName = entry.name;
|
||||
mEntryFileIndex = mNextIndex;
|
||||
mEntryId = entry.id;
|
||||
mEntryTypeFlags = entry.flags;
|
||||
mIsFileOrDirectory = (mEntryTypeFlags >> 1) & 1;
|
||||
mIsFileOrDirectory = mEntryTypeFlags & 2;
|
||||
mNextIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,49 +15,40 @@ JKRFileLoader::JKRFileLoader(void)
|
||||
: mFileLoaderLink(this), mVolumeName(NULL), mVolumeType(0), mMountCount(0) {}
|
||||
|
||||
JKRFileLoader::~JKRFileLoader() {
|
||||
if (getCurrentVolume() == this) {
|
||||
setCurrentVolume(NULL);
|
||||
if (sCurrentVolume == this) {
|
||||
sCurrentVolume = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void JKRFileLoader::unmount(void) {
|
||||
s32 count = mMountCount;
|
||||
if (mMountCount != 0) {
|
||||
count--;
|
||||
mMountCount = count;
|
||||
if (count == 0) {
|
||||
if (--mMountCount == 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void* JKRFileLoader::getGlbResource(const char* name) {
|
||||
const char* name_reference[1];
|
||||
name_reference[0] = name;
|
||||
|
||||
JKRFileLoader* fileLoader = findVolume(name_reference);
|
||||
JKRFileLoader* fileLoader = findVolume(&name);
|
||||
void* resource;
|
||||
if (fileLoader == NULL) {
|
||||
resource = NULL;
|
||||
return NULL;
|
||||
} else {
|
||||
resource = fileLoader->getResource(name_reference[0]);
|
||||
resource = fileLoader->getResource(name);
|
||||
return resource;
|
||||
}
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
void* JKRFileLoader::getGlbResource(const char* name, JKRFileLoader* fileLoader) {
|
||||
void* resource = NULL;
|
||||
if (fileLoader) {
|
||||
return fileLoader->getResource(0, name);
|
||||
}
|
||||
|
||||
JSUList<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> iterator;
|
||||
for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
|
||||
resource = iterator->getResource(0, name);
|
||||
if (resource)
|
||||
break;
|
||||
resource = fileLoader->getResource(0, name);
|
||||
} else {
|
||||
for (JSUListIterator<JKRFileLoader> iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) {
|
||||
resource = iterator->getResource(0, name);
|
||||
if (resource)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
@@ -67,9 +58,7 @@ bool JKRFileLoader::removeResource(void* resource, JKRFileLoader* fileLoader) {
|
||||
return fileLoader->removeResource(resource);
|
||||
}
|
||||
|
||||
JSUList<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> iterator;
|
||||
for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRFileLoader> iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) {
|
||||
if (iterator->removeResource(resource)) {
|
||||
return true;
|
||||
}
|
||||
@@ -83,9 +72,7 @@ bool JKRFileLoader::detachResource(void* resource, JKRFileLoader* fileLoader) {
|
||||
return fileLoader->detachResource(resource);
|
||||
}
|
||||
|
||||
JSUList<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> iterator;
|
||||
for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRFileLoader> iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) {
|
||||
if (iterator->detachResource(resource)) {
|
||||
return true;
|
||||
}
|
||||
@@ -96,15 +83,13 @@ bool JKRFileLoader::detachResource(void* resource, JKRFileLoader* fileLoader) {
|
||||
|
||||
JKRFileLoader* JKRFileLoader::findVolume(const char** volumeName) {
|
||||
if (*volumeName[0] != '/') {
|
||||
return getCurrentVolume();
|
||||
return sCurrentVolume;
|
||||
}
|
||||
|
||||
char volumeNameBuffer[0x101];
|
||||
*volumeName = fetchVolumeName(volumeNameBuffer, ARRAY_SIZEU(volumeNameBuffer), *volumeName);
|
||||
|
||||
JSUList<JKRFileLoader>& volumeList = getVolumeList();
|
||||
JSUListIterator<JKRFileLoader> iterator;
|
||||
for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRFileLoader> iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) {
|
||||
if (strcmp(volumeNameBuffer, iterator->mVolumeName) == 0) {
|
||||
return iterator.getObject();
|
||||
}
|
||||
@@ -113,10 +98,9 @@ JKRFileLoader* JKRFileLoader::findVolume(const char** volumeName) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static char rootPath[2] = "/";
|
||||
|
||||
const char* JKRFileLoader::fetchVolumeName(char* buffer, s32 bufferSize, const char* path) {
|
||||
static char rootPath[2] = "/";
|
||||
|
||||
if (strcmp(path, "/") == 0) {
|
||||
strcpy(buffer, rootPath);
|
||||
return rootPath;
|
||||
|
||||
+123
-55
@@ -9,17 +9,16 @@
|
||||
#include "JSystem/JUtility/JUTAssert.h"
|
||||
#include "JSystem/JUtility/JUTException.h"
|
||||
#include <stdint.h>
|
||||
|
||||
void* ARALT_AramStartAdr = (void*)0x90000000;
|
||||
|
||||
bool data_804508B0 = 1;
|
||||
#include <string.h>
|
||||
|
||||
#if DEBUG
|
||||
u8 data_804508B1;
|
||||
u8 data_804508B2;
|
||||
u8 data_804508B3;
|
||||
u8 JKRValue_DEBUGFILL_NOTUSE = 0xFD;
|
||||
u8 JKRValue_DEBUGFILL_NEW = 0xCD;
|
||||
u8 JKRValue_DEBUGFILL_DELETE = 0xDD;
|
||||
#endif
|
||||
|
||||
bool JKRHeap::sDefaultFillFlag = true;
|
||||
|
||||
JKRHeap* JKRHeap::sSystemHeap;
|
||||
|
||||
JKRHeap* JKRHeap::sCurrentHeap;
|
||||
@@ -47,11 +46,11 @@ JKRHeap::JKRHeap(void* data, u32 size, JKRHeap* parent, bool errorFlag)
|
||||
} else {
|
||||
parent->mChildTree.appendChild(&mChildTree);
|
||||
|
||||
if (getSystemHeap() == getRootHeap()) {
|
||||
if (sSystemHeap == sRootHeap) {
|
||||
becomeSystemHeap();
|
||||
}
|
||||
|
||||
if (getCurrentHeap() == getRootHeap()) {
|
||||
if (sCurrentHeap == sRootHeap) {
|
||||
becomeCurrentHeap();
|
||||
}
|
||||
}
|
||||
@@ -61,7 +60,7 @@ JKRHeap::JKRHeap(void* data, u32 size, JKRHeap* parent, bool errorFlag)
|
||||
mErrorHandler = JKRDefaultMemoryErrorRoutine;
|
||||
}
|
||||
|
||||
mDebugFill = data_804508B0;
|
||||
mDebugFill = sDefaultFillFlag;
|
||||
mCheckMemoryFilled = data_80451380;
|
||||
mInitFlag = false;
|
||||
}
|
||||
@@ -89,36 +88,55 @@ void* JKRHeap::mUserRamEnd;
|
||||
|
||||
u32 JKRHeap::mMemorySize;
|
||||
|
||||
bool JKRHeap::initArena(char** memory, u32* size, int maxHeaps) {
|
||||
void* ram_start;
|
||||
void* ram_end;
|
||||
void* arenaStart;
|
||||
JKRHeap::JKRAllocCallback JKRHeap::sAllocCallback;
|
||||
|
||||
JKRHeap::JKRFreeCallback JKRHeap::sFreeCallback;
|
||||
|
||||
bool JKRHeap::initArena(char** memory, u32* size, int maxHeaps) {
|
||||
void* arenaLo = OSGetArenaLo();
|
||||
void* arenaHi = OSGetArenaHi();
|
||||
OS_REPORT("original arenaLo = %p arenaHi = %p\n", arenaLo, arenaHi);
|
||||
if (arenaLo == arenaHi)
|
||||
return false;
|
||||
|
||||
arenaStart = OSInitAlloc(arenaLo, arenaHi, maxHeaps);
|
||||
ram_start = (void*)ALIGN_NEXT((uintptr_t)arenaStart, 0x20);
|
||||
ram_end = (void*)ALIGN_PREV((uintptr_t)arenaHi, 0x20);
|
||||
arenaLo = OSInitAlloc(arenaLo, arenaHi, maxHeaps);
|
||||
arenaLo = (void*)ALIGN_NEXT((uintptr_t)arenaLo, 0x20);
|
||||
arenaHi = (void*)ALIGN_PREV((uintptr_t)arenaHi, 0x20);
|
||||
|
||||
OSBootInfo* codeStart = (OSBootInfo*)OSPhysicalToCached(0);
|
||||
mCodeStart = codeStart;
|
||||
mCodeEnd = ram_start;
|
||||
mCodeEnd = arenaLo;
|
||||
|
||||
mUserRamStart = ram_start;
|
||||
mUserRamEnd = ram_end;
|
||||
mUserRamStart = arenaLo;
|
||||
mUserRamEnd = arenaHi;
|
||||
mMemorySize = codeStart->memorySize;
|
||||
|
||||
OSSetArenaLo(ram_end);
|
||||
OSSetArenaHi(ram_end);
|
||||
OSSetArenaLo(arenaHi);
|
||||
OSSetArenaHi(arenaHi);
|
||||
|
||||
*memory = (char*)ram_start;
|
||||
*size = (uintptr_t)ram_end - (uintptr_t)ram_start;
|
||||
*memory = (char*)arenaLo;
|
||||
*size = (uintptr_t)arenaHi - (uintptr_t)arenaLo;
|
||||
return true;
|
||||
}
|
||||
|
||||
#if PLATFORM_WII || PLATFORM_SHIELD
|
||||
bool JKRHeap::initArena2(char** memory, u32* size, int maxHeaps) {
|
||||
void* arenaLo = OSGetMEM2ArenaLo();
|
||||
void* arenaHi = OSGetMEM2ArenaHi();
|
||||
OS_REPORT("original arenaLo = %p arenaHi = %p\n", arenaLo, arenaHi);
|
||||
if (arenaLo == arenaHi) {
|
||||
return false;
|
||||
}
|
||||
arenaLo = (void*)0x91100000;
|
||||
arenaHi = (void*)ALIGN_PREV(uintptr_t(arenaHi), 32);
|
||||
OSSetMEM2ArenaLo(arenaHi);
|
||||
OSSetMEM2ArenaHi(arenaHi);
|
||||
*memory = (char*)arenaLo;
|
||||
*size = uintptr_t(arenaHi) - uintptr_t(arenaLo);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
JKRHeap* JKRHeap::becomeSystemHeap() {
|
||||
JKRHeap* prev = sSystemHeap;
|
||||
sSystemHeap = this;
|
||||
@@ -135,6 +153,10 @@ void JKRHeap::destroy() {
|
||||
do_destroy();
|
||||
}
|
||||
|
||||
static void dummy1(JKRHeap* heap) {
|
||||
JUT_ASSERT(0, heap != 0);
|
||||
}
|
||||
|
||||
void* JKRHeap::alloc(u32 size, int alignment, JKRHeap* heap) {
|
||||
if (heap != NULL) {
|
||||
return heap->alloc(size, alignment);
|
||||
@@ -151,7 +173,13 @@ void* JKRHeap::alloc(u32 size, int alignment) {
|
||||
if (mInitFlag) {
|
||||
JUT_WARN(393, "alloc %x byte in heap %x", size, this);
|
||||
}
|
||||
return do_alloc(size, alignment);
|
||||
void* mem = do_alloc(size, alignment);
|
||||
#if DEBUG
|
||||
if (sAllocCallback) {
|
||||
sAllocCallback(size, alignment, this, mem);
|
||||
}
|
||||
#endif
|
||||
return mem;
|
||||
}
|
||||
|
||||
void JKRHeap::free(void* ptr, JKRHeap* heap) {
|
||||
@@ -168,6 +196,11 @@ void JKRHeap::free(void* ptr) {
|
||||
if (mInitFlag) {
|
||||
JUT_WARN(441, "free %x in heap %x", ptr, this);
|
||||
}
|
||||
#if DEBUG
|
||||
if (sFreeCallback) {
|
||||
sFreeCallback(ptr, this);
|
||||
}
|
||||
#endif
|
||||
do_free(ptr);
|
||||
}
|
||||
|
||||
@@ -193,6 +226,10 @@ void JKRHeap::freeTail() {
|
||||
do_freeTail();
|
||||
}
|
||||
|
||||
static void dummy2() {
|
||||
OS_REPORT("fillFreeArea in heap %x");
|
||||
}
|
||||
|
||||
s32 JKRHeap::resize(void* ptr, u32 size, JKRHeap* heap) {
|
||||
if (!heap) {
|
||||
heap = findFromRoot(ptr);
|
||||
@@ -243,6 +280,10 @@ s32 JKRHeap::changeGroupID(u8 groupID) {
|
||||
return do_changeGroupID(groupID);
|
||||
}
|
||||
|
||||
u8 JKRHeap::getCurrentGroupId() {
|
||||
return do_getCurrentGroupId();
|
||||
}
|
||||
|
||||
u32 JKRHeap::getMaxAllocatableSize(int alignment) {
|
||||
u32 maxFreeBlock = (uintptr_t)getMaxFreeBlock();
|
||||
u32 ptrOffset = (alignment - 1) & alignment - (maxFreeBlock & 0xf);
|
||||
@@ -257,7 +298,11 @@ JKRHeap* JKRHeap::findFromRoot(void* ptr) {
|
||||
if (sRootHeap->mStart <= ptr && ptr < sRootHeap->mEnd) {
|
||||
return sRootHeap->find(ptr);
|
||||
}
|
||||
|
||||
#if PLATFORM_WII || PLATFORM_SHIELD
|
||||
if (sRootHeap2->mStart <= ptr && ptr < sRootHeap2->mEnd) {
|
||||
return sRootHeap2->find(ptr);
|
||||
}
|
||||
#endif
|
||||
return sRootHeap->findAllHeap(ptr);
|
||||
}
|
||||
|
||||
@@ -301,29 +346,24 @@ JKRHeap* JKRHeap::findAllHeap(void* ptr) const {
|
||||
}
|
||||
|
||||
void JKRHeap::dispose_subroutine(u32 begin, u32 end) {
|
||||
JSUListIterator<JKRDisposer> last_iterator;
|
||||
JSUListIterator<JKRDisposer> next_iterator;
|
||||
JSUListIterator<JKRDisposer> iterator;
|
||||
|
||||
for (iterator = mDisposerList.getFirst(); iterator != mDisposerList.getEnd();
|
||||
iterator = next_iterator)
|
||||
{
|
||||
JKRDisposer* disposer = iterator.getObject();
|
||||
JSUListIterator<JKRDisposer> next_iterator((JSULink<JKRDisposer>*)NULL);
|
||||
JSUListIterator<JKRDisposer> it = mDisposerList.getFirst();
|
||||
while (it != mDisposerList.getEnd()) {
|
||||
JKRDisposer* disposer = it.getObject();
|
||||
|
||||
if ((void*)begin <= disposer && disposer < (void*)end) {
|
||||
disposer->~JKRDisposer();
|
||||
it->~JKRDisposer();
|
||||
|
||||
if (last_iterator == NULL) {
|
||||
next_iterator = mDisposerList.getFirst();
|
||||
} else {
|
||||
next_iterator = last_iterator;
|
||||
next_iterator++;
|
||||
if (next_iterator == JSUListIterator<JKRDisposer>((JSULink<JKRDisposer>*)NULL)) {
|
||||
it = mDisposerList.getFirst();
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
last_iterator = iterator;
|
||||
next_iterator = iterator;
|
||||
next_iterator++;
|
||||
it = next_iterator;
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
next_iterator = it;
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,18 +388,19 @@ void JKRHeap::copyMemory(void* dst, void* src, u32 size) {
|
||||
|
||||
u32* dst_32 = (u32*)dst;
|
||||
u32* src_32 = (u32*)src;
|
||||
while (count > 0) {
|
||||
*dst_32 = *src_32;
|
||||
dst_32++;
|
||||
src_32++;
|
||||
count--;
|
||||
while (count-- > 0) {
|
||||
*dst_32++ = *src_32++;
|
||||
}
|
||||
}
|
||||
|
||||
void JKRDefaultMemoryErrorRoutine(void* heap, u32 size, int alignment) {
|
||||
OS_REPORT("Error: Cannot allocate memory %d(0x%x)byte in %d byte alignment from %08x\n", size,
|
||||
size, alignment, heap);
|
||||
#if PLATFORM_GCN
|
||||
JUTException::panic(__FILE__, 831, "abort\n");
|
||||
#else
|
||||
JUTException::panic(__FILE__, 912, "abort\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
bool JKRHeap::setErrorFlag(bool errorFlag) {
|
||||
@@ -371,21 +412,43 @@ bool JKRHeap::setErrorFlag(bool errorFlag) {
|
||||
JKRErrorHandler JKRHeap::setErrorHandler(JKRErrorHandler errorHandler) {
|
||||
JKRErrorHandler prev = mErrorHandler;
|
||||
|
||||
if (!errorHandler) {
|
||||
errorHandler = JKRDefaultMemoryErrorRoutine;
|
||||
}
|
||||
mErrorHandler = !errorHandler ? JKRDefaultMemoryErrorRoutine : errorHandler;
|
||||
|
||||
mErrorHandler = errorHandler;
|
||||
return prev;
|
||||
}
|
||||
|
||||
void JKRHeap::fillMemory(u8* dst, u32 size, u8 val) {
|
||||
uintptr_t ptr = uintptr_t(dst);
|
||||
memset(dst, val, size);
|
||||
DCFlushRange((void*)ALIGN_PREV(ptr, 32), ALIGN_NEXT(size, 32));
|
||||
}
|
||||
|
||||
bool JKRHeap::checkMemoryFilled(u8* mem, u32 size, u8 val) {
|
||||
void* ptr = mem;
|
||||
bool result = true;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (val == mem[i]) {
|
||||
continue;
|
||||
}
|
||||
result = false;
|
||||
if (fillcheck_dispcount <= 0) {
|
||||
continue;
|
||||
}
|
||||
fillcheck_dispcount--;
|
||||
JUT_WARN(999, "**** checkMemoryFilled:\n address %08x size %x:\n (%08x = %02x)\n", mem, size, mem + i, mem[i]);
|
||||
if (data_8074A8D0_debug) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool JKRHeap::isSubHeap(JKRHeap* heap) const {
|
||||
if (!heap)
|
||||
return false;
|
||||
|
||||
if (mChildTree.getNumChildren() != 0) {
|
||||
JSUTreeIterator<JKRHeap> iterator;
|
||||
for (iterator = mChildTree.getFirstChild(); iterator != mChildTree.getEndChild();
|
||||
for (JSUTreeIterator<JKRHeap> iterator = mChildTree.getFirstChild(); iterator != mChildTree.getEndChild();
|
||||
++iterator)
|
||||
{
|
||||
if (iterator.getObject() == heap) {
|
||||
@@ -433,6 +496,9 @@ void operator delete[](void* ptr) {
|
||||
JKRHeap::free(ptr, NULL);
|
||||
}
|
||||
|
||||
s32 fillcheck_dispcount = 100;
|
||||
bool data_8074A8D0_debug = true;
|
||||
|
||||
void JKRHeap::state_register(JKRHeap::TState* p, u32 id) const {
|
||||
JUT_ASSERT(1213, p != NULL);
|
||||
JUT_ASSERT(1214, p->getHeap() == this);
|
||||
@@ -449,6 +515,8 @@ void JKRHeap::state_dump(const JKRHeap::TState& p) const {
|
||||
JUT_LOG(1248, "used size : %u", p.getUsedSize());
|
||||
}
|
||||
|
||||
void* ARALT_AramStartAdr = (void*)0x90000000;
|
||||
|
||||
void* JKRHeap::getAltAramStartAdr() { return ARALT_AramStartAdr; }
|
||||
|
||||
s32 JKRHeap::do_changeGroupID(u8 param_0) {
|
||||
|
||||
@@ -20,7 +20,7 @@ JKRMemArchive::JKRMemArchive(s32 entryNum, JKRArchive::EMountDirection mountDire
|
||||
mVolumeType = 'RARC';
|
||||
mVolumeName = mStringTable + mNodes->name_offset;
|
||||
|
||||
getVolumeList().prepend(&mFileLoaderLink);
|
||||
sVolumeList.prepend(&mFileLoaderLink);
|
||||
mIsMounted = true;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ JKRMemArchive::JKRMemArchive(void* buffer, u32 bufferSize, JKRMemBreakFlag param
|
||||
mVolumeType = 'RARC';
|
||||
mVolumeName = mStringTable + mNodes->name_offset;
|
||||
|
||||
getVolumeList().prepend(&mFileLoaderLink);
|
||||
sVolumeList.prepend(&mFileLoaderLink);
|
||||
mIsMounted = true;
|
||||
}
|
||||
|
||||
@@ -45,11 +45,17 @@ JKRMemArchive::~JKRMemArchive() {
|
||||
JKRFreeToHeap(mHeap, mArcHeader);
|
||||
}
|
||||
|
||||
getVolumeList().remove(&mFileLoaderLink);
|
||||
sVolumeList.remove(&mFileLoaderLink);
|
||||
mIsMounted = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void dummy() {
|
||||
OS_REPORT(__FILE__);
|
||||
OS_REPORT("isMounted()");
|
||||
OS_REPORT("mMountCount == 1");
|
||||
}
|
||||
|
||||
bool JKRMemArchive::open(s32 entryNum, JKRArchive::EMountDirection mountDirection) {
|
||||
mArcHeader = NULL;
|
||||
mArcInfoBlock = NULL;
|
||||
@@ -83,7 +89,7 @@ bool JKRMemArchive::open(s32 entryNum, JKRArchive::EMountDirection mountDirectio
|
||||
mMountMode = UNKNOWN_MOUNT_MODE;
|
||||
}
|
||||
else {
|
||||
JUT_ASSERT(438, mArcHeader->signature =='RARC');
|
||||
JUT_ASSERT(438, mArcHeader->signature == 'RARC');
|
||||
mArcInfoBlock = (SArcDataInfo *)((u8 *)mArcHeader + mArcHeader->header_length);
|
||||
mNodes = (SDIDirEntry *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->node_offset);
|
||||
mFiles = (SDIFileEntry *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->file_entry_offset);
|
||||
@@ -105,7 +111,7 @@ bool JKRMemArchive::open(s32 entryNum, JKRArchive::EMountDirection mountDirectio
|
||||
|
||||
bool JKRMemArchive::open(void* buffer, u32 bufferSize, JKRMemBreakFlag flag) {
|
||||
mArcHeader = (SArcHeader *)buffer;
|
||||
JUT_ASSERT(491, mArcHeader->signature =='RARC');
|
||||
JUT_ASSERT(491, mArcHeader->signature == 'RARC');
|
||||
mArcInfoBlock = (SArcDataInfo *)((u8 *)mArcHeader + mArcHeader->header_length);
|
||||
mNodes = (SDIDirEntry *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->node_offset);
|
||||
mFiles = (SDIFileEntry *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->file_entry_offset);
|
||||
@@ -141,10 +147,10 @@ void* JKRMemArchive::fetchResource(void* buffer, u32 bufferSize, SDIFileEntry* f
|
||||
if (fileEntry->data != NULL) {
|
||||
memcpy(buffer, fileEntry->data, srcLength);
|
||||
} else {
|
||||
JKRCompression compression = JKRConvertAttrToCompressionType(fileEntry->getAttr());
|
||||
void* data = mArchiveData + fileEntry->data_offset;
|
||||
u8 flags = fileEntry->type_flags_and_name_offset >> 24;
|
||||
JKRCompression compression = JKRConvertAttrToCompressionType(flags);
|
||||
srcLength =
|
||||
fetchResource_subroutine((u8*)data, srcLength, (u8*)buffer, bufferSize, compression);
|
||||
fetchResource_subroutine(mArchiveData + fileEntry->data_offset, srcLength, (u8*)buffer, bufferSize, compression);
|
||||
}
|
||||
|
||||
if (resourceSize) {
|
||||
@@ -170,6 +176,7 @@ void JKRMemArchive::removeResourceAll(void) {
|
||||
fileEntry->data = NULL;
|
||||
}
|
||||
}
|
||||
fileEntry++;
|
||||
}
|
||||
|
||||
bool JKRMemArchive::removeResource(void* resource) {
|
||||
@@ -197,15 +204,12 @@ u32 JKRMemArchive::fetchResource_subroutine(u8* src, u32 srcLength, u8* dst, u32
|
||||
case COMPRESSION_YAY0:
|
||||
case COMPRESSION_YAZ0: {
|
||||
u32 expendedSize = JKRDecompExpandSize(src);
|
||||
#if VERSION != VERSION_SHIELD_DEBUG
|
||||
srcLength = expendedSize;
|
||||
#endif
|
||||
if (expendedSize > dstLength) {
|
||||
srcLength = dstLength;
|
||||
expendedSize = dstLength;
|
||||
}
|
||||
|
||||
JKRDecompress(src, dst, srcLength, 0);
|
||||
return srcLength;
|
||||
JKRDecompress(src, dst, expendedSize, 0);
|
||||
return expendedSize;
|
||||
}
|
||||
|
||||
default: {
|
||||
@@ -221,9 +225,10 @@ u32 JKRMemArchive::getExpandedResSize(const void* resource) const {
|
||||
if (fileEntry == NULL)
|
||||
return -1;
|
||||
|
||||
if (fileEntry->isCompressed() == false) {
|
||||
u8 flags = fileEntry->type_flags_and_name_offset >> 24;
|
||||
if ((flags & 4) == false) {
|
||||
return getResSize(resource);
|
||||
} else {
|
||||
return JKRDecompExpandSize((u8*)resource);
|
||||
}
|
||||
u32 expandSize = JKRDecompExpandSize((u8*)resource);
|
||||
return expandSize;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
||||
|
||||
#include "JSystem/JKernel/JKRSolidHeap.h"
|
||||
#include "JSystem/JGadget/binary.h"
|
||||
#include "JSystem/JUtility/JUTAssert.h"
|
||||
#include "JSystem/JUtility/JUTConsole.h"
|
||||
#include "global.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
JKRSolidHeap* JKRSolidHeap::create(u32 size, JKRHeap* heap, bool useErrorHandler) {
|
||||
if (!heap) {
|
||||
heap = getRootHeap();
|
||||
heap = sRootHeap;
|
||||
}
|
||||
u32 solidHeapSize = ALIGN_NEXT(sizeof(JKRSolidHeap), 0x10);
|
||||
|
||||
if (size == -1) {
|
||||
size = heap->getMaxAllocatableSize(0x10);
|
||||
}
|
||||
|
||||
u32 alignedSize = ALIGN_PREV(size, 0x10);
|
||||
u32 solidHeapSize = ALIGN_NEXT(sizeof(JKRSolidHeap), 0x10);
|
||||
if (alignedSize < solidHeapSize)
|
||||
return NULL;
|
||||
|
||||
JKRSolidHeap* solidHeap = (JKRSolidHeap*)JKRAllocFromHeap(heap, alignedSize, 0x10);
|
||||
void* dataPtr = (u8*)solidHeap + solidHeapSize;
|
||||
if (!solidHeap)
|
||||
u8* mem = (u8*)JKRAllocFromHeap(heap, alignedSize, 0x10);
|
||||
void* dataPtr = mem + solidHeapSize;
|
||||
if (!mem)
|
||||
return NULL;
|
||||
|
||||
solidHeap =
|
||||
new (solidHeap) JKRSolidHeap(dataPtr, alignedSize - solidHeapSize, heap, useErrorHandler);
|
||||
return solidHeap;
|
||||
return new (mem) JKRSolidHeap(dataPtr, alignedSize - solidHeapSize, heap, useErrorHandler);
|
||||
}
|
||||
|
||||
void JKRSolidHeap::do_destroy(void) {
|
||||
@@ -44,6 +44,11 @@ JKRSolidHeap::JKRSolidHeap(void* start, u32 size, JKRHeap* parent, bool useError
|
||||
mSolidHead = (u8*)mStart;
|
||||
mSolidTail = (u8*)mEnd;
|
||||
field_0x78 = NULL;
|
||||
#if DEBUG
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory(mStart, mSize, JKRValue_DEBUGFILL_NOTUSE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
JKRSolidHeap::~JKRSolidHeap(void) {
|
||||
@@ -51,12 +56,14 @@ JKRSolidHeap::~JKRSolidHeap(void) {
|
||||
}
|
||||
|
||||
s32 JKRSolidHeap::adjustSize(void) {
|
||||
int r25 = 0;
|
||||
JKRHeap* parent = getParent();
|
||||
if (parent) {
|
||||
lock();
|
||||
u32 thisSize = (uintptr_t)mStart - (uintptr_t)this;
|
||||
u32 newSize = ALIGN_NEXT(mSolidHead - mStart, 0x20);
|
||||
if (parent->resize(this, thisSize + newSize) != -1) {
|
||||
s32 r26 = parent->resize(this, thisSize + newSize);
|
||||
if (r26 != -1) {
|
||||
mFreeSize = 0;
|
||||
mSize = newSize;
|
||||
mEnd = mStart + mSize;
|
||||
@@ -74,12 +81,11 @@ s32 JKRSolidHeap::adjustSize(void) {
|
||||
|
||||
void* JKRSolidHeap::do_alloc(u32 size, int alignment) {
|
||||
#if DEBUG
|
||||
// TODO(Julgodis): JUTAssertion::setConfirmMessage
|
||||
/* if (alignment != 0) {
|
||||
int u = abs(alignment);
|
||||
JUT_ASSERT(219, u < 0x80);
|
||||
JUT_ASSERT(220, JGadget::binary::isPower2(u));
|
||||
} */
|
||||
if (alignment) {
|
||||
u32 u = abs(alignment);
|
||||
JUT_CONFIRM(219, u < 0x80);
|
||||
JUT_CONFIRM(220, JGadget::binary::isPower2( u ));
|
||||
}
|
||||
#endif
|
||||
|
||||
lock();
|
||||
@@ -92,13 +98,7 @@ void* JKRSolidHeap::do_alloc(u32 size, int alignment) {
|
||||
if (alignment >= 0) {
|
||||
ptr = allocFromHead(size, alignment < 4 ? 4 : alignment);
|
||||
} else {
|
||||
if (-alignment < 4) {
|
||||
alignment = 4;
|
||||
} else {
|
||||
alignment = -alignment;
|
||||
}
|
||||
|
||||
ptr = allocFromTail(size, alignment);
|
||||
ptr = allocFromTail(size, -alignment < 4 ? 4 : -alignment);
|
||||
}
|
||||
|
||||
unlock();
|
||||
@@ -109,9 +109,16 @@ void* JKRSolidHeap::allocFromHead(u32 size, int alignment) {
|
||||
size = ALIGN_NEXT(size, 0x4);
|
||||
void* ptr = NULL;
|
||||
u32 alignedStart = (alignment - 1 + (uintptr_t)mSolidHead) & ~(alignment - 1);
|
||||
u32 offset = alignedStart - (uintptr_t)mSolidHead;
|
||||
u32 totalSize = size + offset;
|
||||
u32 totalSize = size + (alignedStart - (uintptr_t)mSolidHead);
|
||||
if (totalSize <= mFreeSize) {
|
||||
#if DEBUG
|
||||
if (mCheckMemoryFilled) {
|
||||
checkMemoryFilled(mSolidHead, totalSize, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory(mSolidHead, totalSize, JKRValue_DEBUGFILL_NEW);
|
||||
}
|
||||
#endif
|
||||
ptr = (void*)alignedStart;
|
||||
mSolidHead += totalSize;
|
||||
mFreeSize -= totalSize;
|
||||
@@ -134,6 +141,14 @@ void* JKRSolidHeap::allocFromTail(u32 size, int alignment) {
|
||||
ptr = (void*)alignedStart;
|
||||
mSolidTail -= totalSize;
|
||||
mFreeSize -= totalSize;
|
||||
#if DEBUG
|
||||
if (mCheckMemoryFilled) {
|
||||
checkMemoryFilled((u8*)alignedStart, totalSize, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory((u8*)alignedStart, totalSize, JKRValue_DEBUGFILL_NEW);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
JUTWarningConsole_f("allocFromTail: cannot alloc memory (0x%x byte).\n", totalSize);
|
||||
if (getErrorFlag() == true) {
|
||||
@@ -155,7 +170,11 @@ void JKRSolidHeap::do_freeAll(void) {
|
||||
mSolidHead = (u8*)mStart;
|
||||
mSolidTail = (u8*)mEnd;
|
||||
field_0x78 = NULL;
|
||||
|
||||
#if DEBUG
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory(mStart, mSize, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
#endif
|
||||
unlock();
|
||||
}
|
||||
|
||||
@@ -165,14 +184,17 @@ void JKRSolidHeap::do_freeTail(void) {
|
||||
if (mSolidTail != mEnd) {
|
||||
dispose(mSolidTail, mEnd);
|
||||
}
|
||||
#if DEBUG
|
||||
if (mDebugFill) {
|
||||
JKRFillMemory(mSolidTail, mEnd - mSolidTail, JKRValue_DEBUGFILL_DELETE);
|
||||
}
|
||||
#endif
|
||||
|
||||
this->mFreeSize = ((uintptr_t)mEnd - (uintptr_t)mSolidTail + mFreeSize);
|
||||
this->mSolidTail = mEnd;
|
||||
|
||||
JKRSolidHeap::Unknown* unknown = field_0x78;
|
||||
while (unknown) {
|
||||
for (JKRSolidHeap::Unknown* unknown = field_0x78; unknown; unknown = unknown->mNext) {
|
||||
unknown->field_0xc = mEnd;
|
||||
unknown = unknown->mNext;
|
||||
}
|
||||
|
||||
unlock();
|
||||
@@ -180,7 +202,7 @@ void JKRSolidHeap::do_freeTail(void) {
|
||||
|
||||
void JKRSolidHeap::do_fillFreeArea() {
|
||||
#if DEBUG
|
||||
// fillMemory(mSolidHead, mEnd - mSolidHead, (uint)DAT_8074a8ba);
|
||||
JKRFillMemory(mSolidHead, mEnd - mSolidHead, JKRValue_DEBUGFILL_DELETE);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -198,12 +220,10 @@ bool JKRSolidHeap::check(void) {
|
||||
lock();
|
||||
|
||||
bool result = true;
|
||||
u32 calculatedSize =
|
||||
((uintptr_t)mSolidHead - (uintptr_t)mStart) + mFreeSize + ((uintptr_t)mEnd - (uintptr_t)mSolidTail);
|
||||
u32 availableSize = mSize;
|
||||
if (calculatedSize != availableSize) {
|
||||
u32 calculatedSize = (mSolidHead - mStart) + mFreeSize + (mEnd - mSolidTail);
|
||||
if (calculatedSize != mSize) {
|
||||
result = false;
|
||||
JUTWarningConsole_f("check: bad total memory block size (%08X, %08X)\n", availableSize,
|
||||
JUTWarningConsole_f("check: bad total memory block size (%08X, %08X)\n", mSize,
|
||||
calculatedSize);
|
||||
}
|
||||
|
||||
@@ -215,15 +235,10 @@ bool JKRSolidHeap::dump(void) {
|
||||
bool result = check();
|
||||
|
||||
lock();
|
||||
u32 headSize = ((uintptr_t)mSolidHead - (uintptr_t)mStart);
|
||||
u32 tailSize = ((uintptr_t)mEnd - (uintptr_t)mSolidTail);
|
||||
s32 htSize = headSize + tailSize;
|
||||
JUTReportConsole_f("head %08x: %08x\n", mStart, headSize);
|
||||
JUTReportConsole_f("tail %08x: %08x\n", mSolidTail, ((uintptr_t)mEnd - (uintptr_t)mSolidTail));
|
||||
|
||||
u32 totalSize = mSize;
|
||||
float percentage = (float)htSize / (float)totalSize * 100.0f;
|
||||
JUTReportConsole_f("%d / %d bytes (%6.2f%%) used\n", htSize, totalSize, percentage);
|
||||
s32 htSize = (mSolidHead - mStart) + (mEnd - mSolidTail);
|
||||
JUTReportConsole_f("head %08x: %08x\n", mStart, (mSolidHead - mStart));
|
||||
JUTReportConsole_f("tail %08x: %08x\n", mSolidTail, (mEnd - mSolidTail));
|
||||
JUTReportConsole_f("%d / %d bytes (%6.2f%%) used\n", htSize, mSize, f32(htSize) / f32(mSize) * 100.0f);
|
||||
unlock();
|
||||
|
||||
return result;
|
||||
@@ -232,7 +247,7 @@ void JKRSolidHeap::state_register(JKRHeap::TState* p, u32 id) const {
|
||||
JUT_ASSERT(604, p != NULL);
|
||||
JUT_ASSERT(605, p->getHeap() == this);
|
||||
|
||||
getState_(p);
|
||||
void* r28 = getState_(p);
|
||||
setState_u32ID_(p, id);
|
||||
setState_uUsedSize_(p, getUsedSize((JKRSolidHeap*)this));
|
||||
u32 r29 = (uintptr_t)mSolidHead;
|
||||
|
||||
@@ -13,9 +13,7 @@ JKRThreadSwitch* JKRThreadSwitch::sManager;
|
||||
|
||||
u32 JKRThreadSwitch::sTotalCount;
|
||||
|
||||
u32 JKRThreadSwitch::sTotalStart;
|
||||
|
||||
static u32 data_804513BC;
|
||||
u64 JKRThreadSwitch::sTotalStart;
|
||||
|
||||
JKRThreadSwitch_PreCallback JKRThreadSwitch::mUserPreCallback;
|
||||
|
||||
@@ -24,7 +22,7 @@ JKRThreadSwitch_PostCallback JKRThreadSwitch::mUserPostCallback;
|
||||
JKRThread::JKRThread(u32 stack_size, int message_count, int param_3) : mThreadListLink(this) {
|
||||
JKRHeap* heap = JKRHeap::findFromRoot(this);
|
||||
if (heap == NULL) {
|
||||
heap = JKRHeap::getSystemHeap();
|
||||
heap = JKRGetSystemHeap();
|
||||
}
|
||||
|
||||
setCommon_heapSpecified(heap, stack_size, param_3);
|
||||
@@ -34,7 +32,7 @@ JKRThread::JKRThread(u32 stack_size, int message_count, int param_3) : mThreadLi
|
||||
JKRThread::JKRThread(JKRHeap* heap, u32 stack_size, int message_count, int param_4)
|
||||
: mThreadListLink(this) {
|
||||
if (heap == NULL) {
|
||||
heap = JKRHeap::getCurrentHeap();
|
||||
heap = JKRGetCurrentHeap();
|
||||
}
|
||||
|
||||
setCommon_heapSpecified(heap, stack_size, param_4);
|
||||
@@ -47,30 +45,30 @@ JKRThread::JKRThread(OSThread* thread, int message_count) : mThreadListLink(this
|
||||
mStackSize = (uintptr_t)thread->stackEnd - (uintptr_t)thread->stackBase;
|
||||
mStackMemory = thread->stackBase;
|
||||
|
||||
setCommon_mesgQueue(JKRHeap::getSystemHeap(), message_count);
|
||||
setCommon_mesgQueue(JKRGetSystemHeap(), message_count);
|
||||
}
|
||||
|
||||
JKRThread::~JKRThread() {
|
||||
getList().remove(&mThreadListLink);
|
||||
sThreadList.remove(&mThreadListLink);
|
||||
|
||||
if (mHeap) {
|
||||
BOOL result = OSIsThreadTerminated(mThreadRecord);
|
||||
if (result == FALSE) {
|
||||
if (OSIsThreadTerminated(mThreadRecord) == FALSE) {
|
||||
OSDetachThread(mThreadRecord);
|
||||
OSCancelThread(mThreadRecord);
|
||||
}
|
||||
JKRFreeToHeap(mHeap, mStackMemory);
|
||||
JKRFreeToHeap(mHeap, mThreadRecord);
|
||||
}
|
||||
JKRFree(mMessages);
|
||||
JKRFree(mMesgBuffer);
|
||||
}
|
||||
|
||||
void JKRThread::setCommon_mesgQueue(JKRHeap* heap, int message_count) {
|
||||
mMessageCount = message_count;
|
||||
mMessages = (OSMessage*)JKRHeap::alloc(mMessageCount * sizeof(OSMessage), 0, heap);
|
||||
mMesgBuffer = (OSMessage*)JKRAllocFromHeap(heap, mMessageCount * sizeof(OSMessage), 0);
|
||||
JUT_ASSERT(130, mMesgBuffer);
|
||||
|
||||
OSInitMessageQueue(&mMessageQueue, mMessages, mMessageCount);
|
||||
getList().append(&mThreadListLink);
|
||||
OSInitMessageQueue(&mMessageQueue, mMesgBuffer, mMessageCount);
|
||||
sThreadList.append(&mThreadListLink);
|
||||
|
||||
mCurrentHeap = NULL;
|
||||
mCurrentHeapError = NULL;
|
||||
@@ -80,21 +78,19 @@ void JKRThread::setCommon_heapSpecified(JKRHeap* heap, u32 stack_size, int param
|
||||
mHeap = heap;
|
||||
mStackSize = stack_size & 0xffffffe0;
|
||||
mStackMemory = JKRAllocFromHeap(mHeap, mStackSize, 0x20);
|
||||
JUT_ASSERT(164, mStackMemory);
|
||||
mThreadRecord = (OSThread*)JKRAllocFromHeap(mHeap, sizeof(OSThread), 0x20);
|
||||
JUT_ASSERT(168, mThreadRecord);
|
||||
|
||||
void* stackBase = (void*)((intptr_t)mStackMemory + mStackSize);
|
||||
OSCreateThread(mThreadRecord, start, this, stackBase, mStackSize, param_3, 1);
|
||||
OSCreateThread(mThreadRecord, start, this, (u8*)mStackMemory + mStackSize, mStackSize, param_3, 1);
|
||||
}
|
||||
|
||||
void* JKRThread::start(void* param) {
|
||||
JKRThread* thread = (JKRThread*)param;
|
||||
return thread->run();
|
||||
void* JKRThread::start(void* thread) {
|
||||
return ((JKRThread*)thread)->run();
|
||||
}
|
||||
|
||||
JKRThread* JKRThread::searchThread(OSThread* thread) {
|
||||
JSUList<JKRThread>& threadList = getList();
|
||||
JSUListIterator<JKRThread> iterator;
|
||||
for (iterator = threadList.getFirst(); iterator != threadList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRThread> iterator = getList().getFirst(); iterator != getList().getEnd(); ++iterator) {
|
||||
if (iterator->getThreadRecord() == thread) {
|
||||
return iterator.getObject();
|
||||
}
|
||||
@@ -110,7 +106,6 @@ JKRThreadSwitch::JKRThreadSwitch(JKRHeap* param_0) {
|
||||
this->field_0x10 = 1;
|
||||
this->field_0x18 = 0;
|
||||
sTotalCount = 0;
|
||||
data_804513BC = 0;
|
||||
sTotalStart = 0;
|
||||
this->field_0x20 = 0;
|
||||
this->field_0x24 = 0;
|
||||
@@ -159,24 +154,20 @@ void JKRThreadSwitch::callback(OSThread* current, OSThread* next) {
|
||||
sTotalCount = sTotalCount + 1;
|
||||
|
||||
JKRHeap* next_heap = NULL;
|
||||
JSUList<JKRThread>& threadList = JKRThread::getList();
|
||||
JSUListIterator<JKRThread> iterator;
|
||||
for (iterator = threadList.getFirst(); iterator != threadList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRThread> iterator = JKRThread::getList().getFirst(); iterator != JKRThread::getList().getEnd(); ++iterator) {
|
||||
JKRThread* thread = iterator.getObject();
|
||||
|
||||
if (thread->getThreadRecord() == current) {
|
||||
thread->setCurrentHeap(JKRHeap::getCurrentHeap());
|
||||
JKRThread::TLoad* loadInfo = thread->getLoadInfo();
|
||||
if (loadInfo->isValid()) {
|
||||
loadInfo->addCurrentCost();
|
||||
if (thread->getLoadInfo()->isValid()) {
|
||||
thread->getLoadInfo()->addCurrentCost();
|
||||
}
|
||||
}
|
||||
|
||||
if (thread->getThreadRecord() == next) {
|
||||
JKRThread::TLoad* loadInfo = thread->getLoadInfo();
|
||||
if (loadInfo->isValid()) {
|
||||
loadInfo->setCurrentTime();
|
||||
loadInfo->incCount();
|
||||
if (thread->getLoadInfo()->isValid()) {
|
||||
thread->getLoadInfo()->setCurrentTime();
|
||||
thread->getLoadInfo()->incCount();
|
||||
}
|
||||
|
||||
if (sManager->mSetNextHeap) {
|
||||
@@ -186,7 +177,7 @@ void JKRThreadSwitch::callback(OSThread* current, OSThread* next) {
|
||||
} else if (JKRHeap::getRootHeap()->isSubHeap(next_heap)) {
|
||||
continue;
|
||||
#if PLATFORM_WII || PLATFORM_SHIELD
|
||||
} else if (!JKRHeap::getRootHeap2()->isSubHeap(next_heap)) {
|
||||
} else if (JKRHeap::getRootHeap2()->isSubHeap(next_heap)) {
|
||||
continue;
|
||||
#endif
|
||||
} else {
|
||||
@@ -223,18 +214,16 @@ void JKRThreadSwitch::draw(JKRThreadName_* thread_name_list, JUTConsole* console
|
||||
const char* print_0 = " total: switch:%3d time:%d(%df)\n";
|
||||
const char* print_1 = " -------------------------------------\n";
|
||||
|
||||
if (!console) {
|
||||
OS_REPORT(print_0, getTotalCount(), (int)this->field_0x18, this->field_0x10);
|
||||
OS_REPORT(print_1);
|
||||
} else {
|
||||
if (console) {
|
||||
console->clear();
|
||||
console->print_f(print_0, getTotalCount(), (int)this->field_0x18, this->field_0x10);
|
||||
console->print(print_1);
|
||||
} else {
|
||||
OS_REPORT(print_0, getTotalCount(), (int)this->field_0x18, this->field_0x10);
|
||||
OS_REPORT(print_1);
|
||||
}
|
||||
|
||||
JSUList<JKRThread>& threadList = JKRThread::getList();
|
||||
JSUListIterator<JKRThread> iterator;
|
||||
for (iterator = threadList.getFirst(); iterator != threadList.getEnd(); ++iterator) {
|
||||
for (JSUListIterator<JKRThread> iterator = JKRThread::getList().getFirst(); iterator != JKRThread::getList().getEnd(); ++iterator) {
|
||||
JKRThread* thread = iterator.getObject();
|
||||
JKRThread::TLoad* loadInfo = thread->getLoadInfo();
|
||||
|
||||
@@ -257,16 +246,18 @@ void JKRThreadSwitch::draw(JKRThreadName_* thread_name_list, JUTConsole* console
|
||||
}
|
||||
|
||||
u32 switch_count = loadInfo->getCount();
|
||||
float cost_per_0x18 = loadInfo->getCost() / (float)this->field_0x18;
|
||||
u32 cost = loadInfo->getCost();
|
||||
f32 cost_per_0x18 = loadInfo->getCost() / f32(this->field_0x18);
|
||||
|
||||
u32 cost_int = (u32)(cost_per_0x18 * 100.0f);
|
||||
u32 cost_float = (u32)(cost_per_0x18 * 1000.0f) % 10;
|
||||
if (!console) {
|
||||
OS_REPORT(" [%10s] switch:%5d cost:%2d.%d%%\n", thread_print_name, switch_count,
|
||||
cost_int, cost_float);
|
||||
} else {
|
||||
if (console) {
|
||||
console->print_f(" [%10s] switch:%5d cost:%2d.%d%%\n", thread_print_name,
|
||||
switch_count, cost_int, cost_float);
|
||||
} else {
|
||||
OS_REPORT(" [%10s] switch:%5d cost:%2d.%d%%\n", thread_print_name, switch_count,
|
||||
cost_int, cost_float);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@ typedef struct {
|
||||
int rem; /* remainder */
|
||||
} div_t;
|
||||
|
||||
int abs(int n);
|
||||
long int labs(long int n);
|
||||
div_t div(int numerator, int denominator);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _MSL_COMMON_ARITH_H */
|
||||
#endif /* _MSL_COMMON_ARITH_H */
|
||||
|
||||
+1
-1
@@ -488,7 +488,7 @@ void dRes_info_c::deleteArchiveRes() {
|
||||
if (mArchive->isFileEntry(fileIndex)) {
|
||||
JKRArchive::SDIFileEntry* fileEntry = mArchive->findIdxResource(fileIndex);
|
||||
u32 nameOffset = fileEntry->getNameOffset();
|
||||
char* fileName = mArchive->mStringTable + nameOffset;
|
||||
const char* fileName = mArchive->mStringTable + nameOffset;
|
||||
size_t resNameLen = strlen(fileName) - 4;
|
||||
JUT_ASSERT(0x46C, resNameLen <= NAME_MAX);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user