OS threading, DVD I/O, Endianness fixes, ARAM emulation, GX vertex fix

Major changes:

- Implement Big-Endian to Little-Endian byte-swapping for all RARC archive
  types (JKRCompArchive, JKRMemArchive, JKRDvdArchive, JKRAramArchive)
- Implement DVD file I/O via DvdEmu (DVDOpen, DVDFastOpen, DVDReadPrio,
  DVDReadAsyncPrio, DVDConvertPathToEntrynum)
- Fix YAZ0 decompression endianness in JKRDvdRipper, JKRDecomp, JKRAram,
  and JKRDvdAramRipper (use JKRDecompExpandSize instead of direct header read)
- Emulate ARAM with 16MB malloc buffer and synchronous memcpy in ARQPostRequest
  instead of hardware DMA transfers that hang on PC
- Add real OS threading implementation (OSContext, OSThread, OSMutex) using
  native Windows threads with side-table pattern for GC struct compatibility
- Fix font endianness for JUTResFont and JUTCacheFont
- Redirect GXVert.h to Aurora's PC implementation to prevent FIFO writes to
  the GameCube hardware address 0xCC008000
- Add Z-buffer texture format support (GX_TF_Z24X8, GX_TF_Z16, GX_TF_Z8)
  in Aurora's texture converter
This commit is contained in:
Lurs
2026-02-19 10:35:42 +01:00
parent 43847d81b1
commit 8020eb64ba
17 changed files with 1509 additions and 399 deletions
+75 -39
View File
@@ -7,6 +7,19 @@
#include "JSystem/JUtility/JUTConsole.h"
#include <dolphin/gx.h>
#ifdef TARGET_PC
#include "dusk/endian.h"
// Font resource data is embedded as Big-Endian (GameCube format).
// Wrap all multi-byte field accesses through these helpers.
static inline u32 R32(u32 v) { return be32(v); }
static inline u16 R16(u16 v) { return be16(v); }
static inline s16 RS16(s16 v) { return be16s(v); }
#else
static inline u32 R32(u32 v) { return v; }
static inline u16 R16(u16 v) { return v; }
static inline s16 RS16(s16 v) { return v; }
#endif
JUTResFont::JUTResFont() {
initialize_state();
JUTFont::initialize_state();
@@ -90,8 +103,8 @@ void JUTResFont::countBlock() {
mMap1BlockNum = 0;
u8* pData = (u8*)&mResFont->data;
for (u32 i = 0; i < mResFont->numBlocks; i++, pData += ((BlockHeader*)pData)->size) {
int magic = ((BlockHeader*)pData)->magic;
for (u32 i = 0; i < R32(mResFont->numBlocks); i++, pData += R32(((BlockHeader*)pData)->size)) {
u32 magic = R32(((BlockHeader*)pData)->magic);
switch (magic) {
case 'WID1':
mWid1BlockNum++;
@@ -124,11 +137,13 @@ void JUTResFont::setBlock() {
mMaxCode = -1;
BlockHeader* data = (BlockHeader*)mResFont->data;
for (u32 i = 0; i < mResFont->numBlocks; data = (BlockHeader*)data->getNext(), i++) {
switch (data->magic) {
for (u32 i = 0; i < R32(mResFont->numBlocks);
data = (BlockHeader*)((u8*)data + R32(data->size)), i++) {
u32 magic = R32(data->magic);
switch (magic) {
case 'INF1': {
mInf1Ptr = (ResFONT::INF1*)data;
u32 u = mInf1Ptr->fontType;
u32 u = R16(mInf1Ptr->fontType);
JUT_ASSERT(244, u < suAboutEncoding_);
mIsLeadByte = &saoAboutEncoding_[u];
break;
@@ -146,8 +161,8 @@ void JUTResFont::setBlock() {
case 'MAP1':
mpMapBlocks[mapNum] = (ResFONT::MAP1*)data;
if (mMaxCode > mpMapBlocks[mapNum]->startCode) {
mMaxCode = mpMapBlocks[mapNum]->startCode;
if (mMaxCode > R16(mpMapBlocks[mapNum]->startCode)) {
mMaxCode = R16(mpMapBlocks[mapNum]->startCode);
}
mapNum++;
break;
@@ -236,10 +251,14 @@ f32 JUTResFont::drawChar_scale(f32 pos_x, f32 pos_y, f32 scale_x, f32 scale_y, i
y1 = pos_y - getAscent() * (scale_y / getHeight());
f32 y2 = getDescent() * (scale_y / getHeight()) + pos_y;
s32 u1 = (mWidth * 0x8000) / mpGlyphBlocks[field_0x66]->textureWidth;
s32 v1 = (mHeight * 0x8000) / mpGlyphBlocks[field_0x66]->textureHeight;
s32 u2 = ((mWidth + mpGlyphBlocks[field_0x66]->cellWidth) * 0x8000) / mpGlyphBlocks[field_0x66]->textureWidth;
s32 v2 = ((mHeight + mpGlyphBlocks[field_0x66]->cellHeight) * 0x8000) / mpGlyphBlocks[field_0x66]->textureHeight;
u16 texW = R16(mpGlyphBlocks[field_0x66]->textureWidth);
u16 texH = R16(mpGlyphBlocks[field_0x66]->textureHeight);
u16 cellW = R16(mpGlyphBlocks[field_0x66]->cellWidth);
u16 cellH = R16(mpGlyphBlocks[field_0x66]->cellHeight);
s32 u1 = (mWidth * 0x8000) / texW;
s32 v1 = (mHeight * 0x8000) / texH;
s32 u2 = ((mWidth + cellW) * 0x8000) / texW;
s32 v2 = ((mHeight + cellH) * 0x8000) / texH;
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GXBegin(GX_QUADS, GX_VTXFMT0, 4);
@@ -282,11 +301,14 @@ void JUTResFont::loadFont(int code, GXTexMapID texMapID, JUTFont::TWidth* pDstWi
void JUTResFont::getWidthEntry(int code, JUTFont::TWidth* i_width) const {
int fontCode = getFontCode(code);
i_width->field_0x0 = 0;
i_width->field_0x1 = mInf1Ptr->width;
i_width->field_0x1 = R16(mInf1Ptr->width);
for (int i = 0; i < mWid1BlockNum; i++) {
if (mpWidthBlocks[i]->startCode <= fontCode && fontCode <= mpWidthBlocks[i]->endCode) {
*i_width = *(JUTFont::TWidth*)&mpWidthBlocks[i]->mChunkNum[(fontCode - mpWidthBlocks[i]->startCode) * 2];
u16 sc = R16(mpWidthBlocks[i]->startCode);
u16 ec = R16(mpWidthBlocks[i]->endCode);
if (sc <= fontCode && fontCode <= ec) {
// TWidth is two u8 fields, no byte-swap needed
*i_width = *(JUTFont::TWidth*)&mpWidthBlocks[i]->mChunkNum[(fontCode - sc) * 2];
break;
}
}
@@ -295,7 +317,7 @@ void JUTResFont::getWidthEntry(int code, JUTFont::TWidth* i_width) const {
s32 JUTResFont::getCellWidth() const {
if (mpGlyphBlocks) {
if (mpGlyphBlocks[0]) {
return mpGlyphBlocks[0]->cellWidth;
return R16(mpGlyphBlocks[0]->cellWidth);
}
}
@@ -305,7 +327,7 @@ s32 JUTResFont::getCellWidth() const {
s32 JUTResFont::getCellHeight() const {
if (mpGlyphBlocks) {
if (mpGlyphBlocks[0]) {
return mpGlyphBlocks[0]->cellHeight;
return R16(mpGlyphBlocks[0]->cellHeight);
}
}
@@ -328,43 +350,46 @@ int JUTResFont::getFontCode(int chr) const {
0x8294, 0x8295, 0x8296, 0x8297, 0x8298, 0x8299, 0x829A, 0x816F, 0x8162, 0x8170, 0x8160,
};
int ret = mInf1Ptr->defaultCode;
int ret = R16(mInf1Ptr->defaultCode);
if ((getFontType() == 2) && (mMaxCode >= 0x8000U) && (chr >= 0x20) && (chr < 0x7FU)) {
chr = halftofull[chr - 32];
}
for (int i = 0; i < mMap1BlockNum; i++) {
if ((mpMapBlocks[i]->startCode <= chr) && (chr <= mpMapBlocks[i]->endCode)) {
if (mpMapBlocks[i]->mappingMethod == 0) {
ret = chr - mpMapBlocks[i]->startCode;
u16 sc = R16(mpMapBlocks[i]->startCode);
u16 ec = R16(mpMapBlocks[i]->endCode);
u16 mm = R16(mpMapBlocks[i]->mappingMethod);
if ((sc <= chr) && (chr <= ec)) {
if (mm == 0) {
ret = chr - sc;
break;
} else if (mpMapBlocks[i]->mappingMethod == 2) {
} else if (mm == 2) {
u16* leading_temp = &mpMapBlocks[i]->mLeading;
ret = leading_temp[chr - mpMapBlocks[i]->startCode];
ret = R16(leading_temp[chr - sc]);
break;
} else if (mpMapBlocks[i]->mappingMethod == 3) {
} else if (mm == 3) {
u16* leading_temp = &mpMapBlocks[i]->mLeading;
int phi_r5 = 0;
int phi_r6_2 = mpMapBlocks[i]->numEntries - 1;
int phi_r6_2 = R16(mpMapBlocks[i]->numEntries) - 1;
while (phi_r6_2 >= phi_r5) {
int temp_r7 = (phi_r6_2 + phi_r5) / 2;
if (chr < leading_temp[temp_r7 * 2]) {
if (chr < R16(leading_temp[temp_r7 * 2])) {
phi_r6_2 = temp_r7 - 1;
continue;
}
if (chr > leading_temp[temp_r7 * 2]) {
if (chr > R16(leading_temp[temp_r7 * 2])) {
phi_r5 = temp_r7 + 1;
continue;
}
ret = leading_temp[temp_r7 * 2 + 1];
ret = R16(leading_temp[temp_r7 * 2 + 1]);
break;
}
} else if (mpMapBlocks[i]->mappingMethod == 1) {
} else if (mm == 1) {
u16* phi_r5_2 = NULL;
if (mpMapBlocks[i]->numEntries == 1) {
if (R16(mpMapBlocks[i]->numEntries) == 1) {
phi_r5_2 = &mpMapBlocks[i]->mLeading;
}
ret = convertSjis(chr, phi_r5_2);
@@ -380,26 +405,37 @@ void JUTResFont::loadImage(int code, GXTexMapID id){
int i = 0;
for (; i < mGly1BlockNum; i++)
{
if (mpGlyphBlocks[i]->startCode <= code && code <= mpGlyphBlocks[i]->endCode)
u16 sc = R16(mpGlyphBlocks[i]->startCode);
u16 ec = R16(mpGlyphBlocks[i]->endCode);
if (sc <= code && code <= ec)
{
code -= mpGlyphBlocks[i]->startCode;
code -= sc;
break;
}
}
if (i != mGly1BlockNum) {
s32 pageNumCells = mpGlyphBlocks[i]->numRows * mpGlyphBlocks[i]->numColumns;
u16 numRows = R16(mpGlyphBlocks[i]->numRows);
u16 numCols = R16(mpGlyphBlocks[i]->numColumns);
u16 cellW = R16(mpGlyphBlocks[i]->cellWidth);
u16 cellH = R16(mpGlyphBlocks[i]->cellHeight);
u32 texSize = R32(mpGlyphBlocks[i]->textureSize);
u16 texW = R16(mpGlyphBlocks[i]->textureWidth);
u16 texH = R16(mpGlyphBlocks[i]->textureHeight);
u16 texFmt = R16(mpGlyphBlocks[i]->textureFormat);
s32 pageNumCells = numRows * numCols;
s32 pageIdx = code / pageNumCells;
s32 cellIdxInPage = code - pageIdx * pageNumCells;
s32 cellRow = (cellIdxInPage / mpGlyphBlocks[i]->numRows);
s32 cellCol = (cellIdxInPage - cellRow * mpGlyphBlocks[i]->numRows);
mWidth = cellCol * mpGlyphBlocks[i]->cellWidth;
mHeight = cellRow * mpGlyphBlocks[i]->cellHeight;
s32 cellRow = (cellIdxInPage / numRows);
s32 cellCol = (cellIdxInPage - cellRow * numRows);
mWidth = cellCol * cellW;
mHeight = cellRow * cellH;
if (pageIdx != mTexPageIdx || i != field_0x66)
{
GXInitTexObj(&mTexObj, &mpGlyphBlocks[i]->data[pageIdx * mpGlyphBlocks[i]->textureSize], mpGlyphBlocks[i]->textureWidth,
mpGlyphBlocks[i]->textureHeight, (GXTexFmt)mpGlyphBlocks[i]->textureFormat, GX_CLAMP, GX_CLAMP, 0);
GXInitTexObj(&mTexObj, &mpGlyphBlocks[i]->data[pageIdx * texSize], texW,
texH, (GXTexFmt)texFmt, GX_CLAMP, GX_CLAMP, 0);
GXInitTexObjLOD(&mTexObj, GX_LINEAR, GX_LINEAR, 0.0f, 0.0f, 0.0f, 0U, 0U, GX_ANISO_1);
mTexPageIdx = pageIdx;
@@ -422,7 +458,7 @@ int JUTResFont::convertSjis(int inChr, u16* inLead) const {
u16 lead = 0x31c;
if (inLead) {
lead = *inLead;
lead = R16(*inLead);
}
r29 = tmp2 + (tmp - 0x88) * 0xbc + -0x5e + lead;