JKernel debug (#3012)

This commit is contained in:
Jcw87
2026-01-04 17:22:56 -08:00
committed by GitHub
parent 1400687731
commit deb7bead20
51 changed files with 1169 additions and 971 deletions
+88 -87
View File
@@ -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;
+53 -13
View File
@@ -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;
}
+6 -18
View File
@@ -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;
}
+25 -22
View File
@@ -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();
}
+6 -9
View File
@@ -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);
}
+15 -13
View File
@@ -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;
}
+32 -22
View File
@@ -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++;
}
}
+56 -67
View File
@@ -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;
+5 -47
View File
@@ -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;
}
+16 -12
View File
@@ -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) {
+19 -11
View File
@@ -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;
}
+2 -3
View File
@@ -11,8 +11,7 @@ JKRDisposer::JKRDisposer() : mLink(this) {
}
JKRDisposer::~JKRDisposer() {
JKRHeap* heap = mHeap;
if (heap) {
heap->removeDisposer(this);
if (mHeap) {
mHeap->removeDisposer(this);
}
}
+33 -19
View File
@@ -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 -17
View File
@@ -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;
}
+9 -14
View File
@@ -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();
}
+78 -113
View File
@@ -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
View File
@@ -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"; }
+6 -5
View File
@@ -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;
}
}
}
+46 -68
View File
@@ -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);
}
+2 -3
View File
@@ -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++;
}
}
+20 -36
View File
@@ -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
View File
@@ -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) {
+22 -17
View File
@@ -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;
}
+59 -44
View File
@@ -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;
+36 -45
View File
@@ -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
View File
@@ -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);