more various JSystem work (#2046)

* most of J3DAnmLoader done

* J3D / JKernel / JUTConsole work

* remove asm

* fix build

* dol 50%
This commit is contained in:
TakaRikka
2024-01-24 04:00:46 -08:00
committed by GitHub
parent b2310b84b6
commit ba44ade90c
122 changed files with 2330 additions and 5261 deletions
+56 -82
View File
@@ -1,46 +1,27 @@
//
// Generated By: dol2asm
// Translation Unit: JKRAram
//
#include "JSystem/JKernel/JKRAram.h"
#include "JSystem/JKernel/JKRAramPiece.h"
#include "JSystem/JKernel/JKRAramStream.h"
#include "JSystem/JKernel/JKRDecomp.h"
#include "JSystem/JKernel/JKRExpHeap.h"
#include "JSystem/JUtility/JUTException.h"
#include "string.h"
#include "dolphin/ar.h"
#include "dolphin/os/OSCache.h"
#include "dolphin/os/OSInterrupt.h"
#include "global.h"
//
// Forward References:
//
#include "string.h"
static u8* firstSrcData();
static u8* nextSrcData(u8* param_0);
static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32 dstLength, u32 offset,
u32* resourceSize);
int decompSZS_subroutine(u8 *src, u8 *dest);
static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32 dstLength,
u32 offset, u32* resourceSize);
int decompSZS_subroutine(u8* src, u8* dest);
//
// External References:
//
//
// Declarations:
//
/* ############################################################################################## */
/* 804513C8-804513CC 0008C8 0004+00 3/3 9/9 0/0 .sbss sAramObject__7JKRAram */
JKRAram* JKRAram::sAramObject;
/* 802D1FA4-802D2040 2CC8E4 009C+00 0/0 1/1 0/0 .text create__7JKRAramFUlUllll */
JKRAram* JKRAram::create(u32 aram_audio_buffer_size, u32 aram_audio_graph_size,
s32 stream_priority, s32 decomp_priority, s32 piece_priority) {
JKRAram* JKRAram::create(u32 aram_audio_buffer_size, u32 aram_audio_graph_size, s32 stream_priority,
s32 decomp_priority, s32 piece_priority) {
if (!sAramObject) {
sAramObject = new (JKRHeap::getSystemHeap(), 0)
JKRAram(aram_audio_buffer_size, aram_audio_graph_size, piece_priority);
@@ -144,11 +125,15 @@ void JKRAram::changeGroupIdIfNeed(u8* data, int groupId) {
/* 802D233C-802D25B4 2CCC7C 0278+00 0/0 3/3 0/0 .text
* mainRamToAram__7JKRAramFPUcUlUl15JKRExpandSwitchUlP7JKRHeapiPUl */
JKRAramBlock *JKRAram::mainRamToAram(u8 *buf, u32 bufSize, u32 alignedSize, JKRExpandSwitch expandSwitch, u32 fileSize, JKRHeap *heap, int id, u32 *pSize) {
JKRAramBlock *block = NULL;
JKRAramBlock* JKRAram::mainRamToAram(u8* buf, u32 bufSize, u32 alignedSize,
JKRExpandSwitch expandSwitch, u32 fileSize, JKRHeap* heap,
int id, u32* pSize) {
JKRAramBlock* block = NULL;
checkOkAddress(buf, bufSize, NULL, 0);
if (expandSwitch == EXPAND_SWITCH_UNKNOWN1) {
expandSwitch = (JKRCheckCompressed_noASR(buf) == COMPRESSION_NONE) ? EXPAND_SWITCH_UNKNOWN0 : EXPAND_SWITCH_UNKNOWN1;
expandSwitch = (JKRCheckCompressed_noASR(buf) == COMPRESSION_NONE) ?
EXPAND_SWITCH_UNKNOWN0 :
EXPAND_SWITCH_UNKNOWN1;
}
if (expandSwitch == EXPAND_SWITCH_UNKNOWN1) {
u32 expandSize = JKRDecompExpandSize(buf);
@@ -156,7 +141,8 @@ JKRAramBlock *JKRAram::mainRamToAram(u8 *buf, u32 bufSize, u32 alignedSize, JKRE
fileSize = ALIGN_NEXT(expandSize, 32);
}
if (bufSize == 0) {
JKRAramBlock* allocatedBlock = (JKRAramBlock*)JKRAllocFromAram(fileSize, JKRAramHeap::HEAD);
JKRAramBlock* allocatedBlock =
(JKRAramBlock*)JKRAllocFromAram(fileSize, JKRAramHeap::HEAD);
block = (JKRAramBlock*)allocatedBlock;
if (allocatedBlock == NULL)
return NULL;
@@ -170,29 +156,27 @@ JKRAramBlock *JKRAram::mainRamToAram(u8 *buf, u32 bufSize, u32 alignedSize, JKRE
if (alignedSize > fileSize)
alignedSize = fileSize;
void *allocatedMem = JKRAllocFromHeap(heap, fileSize, -32);
void* allocatedMem = JKRAllocFromHeap(heap, fileSize, -32);
if (allocatedMem == NULL) {
if (block != NULL) {
JKRFreeToAram(block);
}
block = NULL;
}
else {
JKRDecompress(buf, (u8 *)allocatedMem, fileSize, 0);
} else {
JKRDecompress(buf, (u8*)allocatedMem, fileSize, 0);
JKRAramPcs(0, (u32)allocatedMem, bufSize, alignedSize, block);
JKRFreeToHeap(heap, allocatedMem);
block = block == NULL ? (JKRAramBlock *)-1 : block;
block = block == NULL ? (JKRAramBlock*)-1 : block;
if (pSize != NULL) {
*pSize = alignedSize;
}
}
}
else {
} else {
if (fileSize != 0 && alignedSize > fileSize)
alignedSize = fileSize;
if (bufSize == 0) {
JKRAramBlock* allocatedBlock = (JKRAramBlock*)JKRAllocFromAram(alignedSize, JKRAramHeap::HEAD);
JKRAramBlock* allocatedBlock =
(JKRAramBlock*)JKRAllocFromAram(alignedSize, JKRAramHeap::HEAD);
block = allocatedBlock;
block->newGroupID(decideAramGroupId(id));
if (block == NULL)
@@ -202,7 +186,7 @@ JKRAramBlock *JKRAram::mainRamToAram(u8 *buf, u32 bufSize, u32 alignedSize, JKRE
}
JKRAramPcs(0, (u32)buf, bufSize, alignedSize, block);
block = block == NULL ? (JKRAramBlock *)-1 : block;
block = block == NULL ? (JKRAramBlock*)-1 : block;
if (pSize != NULL)
*pSize = alignedSize;
}
@@ -211,7 +195,8 @@ JKRAramBlock *JKRAram::mainRamToAram(u8 *buf, u32 bufSize, u32 alignedSize, JKRE
/* 802D25B4-802D2830 2CCEF4 027C+00 0/0 6/6 0/0 .text
* aramToMainRam__7JKRAramFUlPUcUl15JKRExpandSwitchUlP7JKRHeapiPUl */
u8 *JKRAram::aramToMainRam(u32 address, u8 *buf, u32 p3, JKRExpandSwitch expandSwitch, u32 p5, JKRHeap *heap, int id, u32 *pSize) {
u8* JKRAram::aramToMainRam(u32 address, u8* buf, u32 p3, JKRExpandSwitch expandSwitch, u32 p5,
JKRHeap* heap, int id, u32* pSize) {
JKRCompression compression = COMPRESSION_NONE;
if (pSize != NULL)
*pSize = 0;
@@ -221,18 +206,19 @@ u8 *JKRAram::aramToMainRam(u32 address, u8 *buf, u32 p3, JKRExpandSwitch expandS
u32 expandSize;
if (expandSwitch == EXPAND_SWITCH_UNKNOWN1) {
u8 buffer[64];
u8 *bufPtr = (u8 *)ALIGN_NEXT((u32)buffer, 32);
JKRAramPcs(1, address, (u32)bufPtr, sizeof(buffer) / 2, NULL); // probably change sizeof(buffer) / 2 to 32
u8* bufPtr = (u8*)ALIGN_NEXT((u32)buffer, 32);
JKRAramPcs(1, address, (u32)bufPtr, sizeof(buffer) / 2,
NULL); // probably change sizeof(buffer) / 2 to 32
compression = JKRCheckCompressed_noASR(bufPtr);
expandSize = JKRDecompExpandSize(bufPtr);
}
if (compression == COMPRESSION_YAZ0) { // SZS
if (compression == COMPRESSION_YAZ0) { // SZS
if (p5 != 0 && p5 < expandSize)
expandSize = p5;
if (buf == NULL)
buf = (u8 *)JKRAllocFromHeap(heap, expandSize, 32);
buf = (u8*)JKRAllocFromHeap(heap, expandSize, 32);
if (buf == NULL)
return NULL;
else {
@@ -240,20 +226,18 @@ u8 *JKRAram::aramToMainRam(u32 address, u8 *buf, u32 p3, JKRExpandSwitch expandS
JKRDecompressFromAramToMainRam(address, buf, p3, expandSize, 0, pSize);
return buf;
}
}
else if (compression == COMPRESSION_YAY0) { // SZP
u8 *szpSpace = (u8 *)JKRAllocFromHeap(heap, p3, -32);
} else if (compression == COMPRESSION_YAY0) { // SZP
u8* szpSpace = (u8*)JKRAllocFromHeap(heap, p3, -32);
if (szpSpace == NULL) {
return NULL;
}
else {
} else {
JKRAramPcs(1, address, (u32)szpSpace, p3, NULL);
if (p5 != 0 && p5 < expandSize)
expandSize = p5;
u8* rv;
if (buf == NULL) {
rv = (u8 *)JKRAllocFromHeap(heap, expandSize, 32);
rv = (u8*)JKRAllocFromHeap(heap, expandSize, 32);
} else {
rv = buf;
}
@@ -261,8 +245,7 @@ u8 *JKRAram::aramToMainRam(u32 address, u8 *buf, u32 p3, JKRExpandSwitch expandS
if (rv == NULL) {
i_JKRFree(szpSpace);
return NULL;
}
else {
} else {
changeGroupIdIfNeed(rv, id);
JKRDecompress(szpSpace, rv, expandSize, 0);
JKRFreeToHeap(heap, szpSpace);
@@ -272,14 +255,12 @@ u8 *JKRAram::aramToMainRam(u32 address, u8 *buf, u32 p3, JKRExpandSwitch expandS
return rv;
}
}
}
else { // Not compressed or ASR
} else { // Not compressed or ASR
if (buf == NULL)
buf = (u8 *)JKRAllocFromHeap(heap, p3, 32);
buf = (u8*)JKRAllocFromHeap(heap, p3, 32);
if (buf == NULL) {
return NULL;
}
else {
} else {
changeGroupIdIfNeed(buf, id);
JKRAramPcs(1, address, (u32)buf, p3, NULL);
if (pSize != NULL) {
@@ -346,8 +327,8 @@ static u32 tsArea;
/* 802D2830-802D29A0 2CD170 0170+00 1/1 0/0 0/0 .text
* JKRDecompressFromAramToMainRam__FUlPvUlUlUlPUl */
static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32 dstLength, u32 offset,
u32* resourceSize) {
static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32 dstLength,
u32 offset, u32* resourceSize) {
BOOL interrupts = OSDisableInterrupts();
if (s_is_decompress_mutex_initialized == false) {
OSInitMutex(&decompMutex);
@@ -357,15 +338,14 @@ static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32
OSLockMutex(&decompMutex);
u32 szsBufferSize = JKRAram::getSZSBufferSize();
szpBuf = (u8 *)JKRAllocFromSysHeap(szsBufferSize, 32);
szpBuf = (u8*)JKRAllocFromSysHeap(szsBufferSize, 32);
szpEnd = szpBuf + szsBufferSize;
if (offset != 0) {
refBuf = (u8 *)JKRAllocFromSysHeap(0x1120, 0);
refBuf = (u8*)JKRAllocFromSysHeap(0x1120, 0);
refEnd = refBuf + 0x1120;
refCurrent = refBuf;
}
else {
} else {
refBuf = NULL;
}
srcAddress = src;
@@ -377,7 +357,7 @@ static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32
tsPtr = (resourceSize != 0) ? resourceSize : &tsArea;
*tsPtr = 0;
decompSZS_subroutine(firstSrcData(), (u8 *)dst);
decompSZS_subroutine(firstSrcData(), (u8*)dst);
i_JKRFree(szpBuf);
if (refBuf) {
i_JKRFree(refBuf);
@@ -390,8 +370,8 @@ static int JKRDecompressFromAramToMainRam(u32 src, void* dst, u32 srcLength, u32
}
/* 802D29A0-802D2C40 2CD2E0 02A0+00 1/1 0/0 0/0 .text decompSZS_subroutine__FPUcPUc */
int decompSZS_subroutine(u8 *src, u8 *dest) {
u8 *endPtr;
int decompSZS_subroutine(u8* src, u8* dest) {
u8* endPtr;
s32 validBitCount = 0;
s32 currCodeByte = 0;
u32 ts = 0;
@@ -400,7 +380,7 @@ int decompSZS_subroutine(u8 *src, u8 *dest) {
return -1;
}
SYaz0Header *header = (SYaz0Header *)src;
SYaz0Header* header = (SYaz0Header*)src;
endPtr = dest + (header->length - fileOffset);
if (endPtr > dest + maxDest) {
endPtr = dest + maxDest;
@@ -422,8 +402,7 @@ int decompSZS_subroutine(u8 *src, u8 *dest) {
*dest = *src;
dest++;
ts++;
if (dest == endPtr)
{
if (dest == endPtr) {
break;
}
}
@@ -432,8 +411,7 @@ int decompSZS_subroutine(u8 *src, u8 *dest) {
refCurrent = refBuf;
}
src++;
}
else {
} else {
*dest = *src;
dest++;
src++;
@@ -443,26 +421,23 @@ int decompSZS_subroutine(u8 *src, u8 *dest) {
}
}
readCount++;
}
else {
} else {
u32 dist = ((src[0] & 0x0f) << 8) | src[1];
s32 numBytes = src[0] >> 4;
src += 2;
u8 *copySource;
u8* copySource;
if (fileOffset != 0) {
copySource = refCurrent - dist - 1;
if (copySource < refBuf) {
copySource += refEnd - refBuf;
}
}
else {
} else {
copySource = dest - dist - 1;
}
if (numBytes == 0) {
numBytes = *src + 0x12;
src += 1;
}
else {
} else {
numBytes += 2;
}
if (fileOffset != 0) {
@@ -486,8 +461,7 @@ int decompSZS_subroutine(u8 *src, u8 *dest) {
readCount++;
numBytes--;
} while (numBytes != 0);
}
else {
} else {
do {
*dest = *copySource;
dest++;
@@ -536,8 +510,8 @@ static u8* firstSrcData() {
}
/* 802D2CE4-802D2DAC 2CD624 00C8+00 1/1 0/0 0/0 .text nextSrcData__FPUc */
static u8 *nextSrcData(u8 *current) {
u8 *dest;
static u8* nextSrcData(u8* current) {
u8* dest;
u32 left = (u32)(szpEnd - current);
if (IS_NOT_ALIGNED(left, 0x20))
dest = szpBuf + 0x20 - (left & (0x20 - 1));