mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-06-27 00:45:10 -04:00
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:
@@ -351,7 +351,8 @@ int decompSZS_subroutine(u8* src, u8* dest) {
|
||||
}
|
||||
|
||||
SYaz0Header* header = (SYaz0Header*)src;
|
||||
endPtr = dest + (header->length - fileOffset);
|
||||
u32 decompressedLength = JKRDecompExpandSize(src);
|
||||
endPtr = dest + (decompressedLength - fileOffset);
|
||||
if (endPtr > dest + maxDest) {
|
||||
endPtr = dest + maxDest;
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@ bool JKRAramArchive::open(s32 entryNum) {
|
||||
JKRDvdToMainRam(entryNum, (u8*)mem, EXPAND_SWITCH_UNKNOWN1, 32, NULL,
|
||||
JKRDvdRipper::ALLOC_DIRECTION_FORWARD, 0, &mCompression, NULL);
|
||||
DCInvalidateRange(mem, 32);
|
||||
JKRSwapArcHeader(mem);
|
||||
int alignment = mMountDirection == MOUNT_DIRECTION_HEAD ? 32 : -32;
|
||||
u32 alignedSize = ALIGN_NEXT(mem->file_data_offset, 32);
|
||||
mArcInfoBlock = (SArcDataInfo*)JKRAllocFromHeap(mHeap, alignedSize, alignment);
|
||||
@@ -130,6 +131,7 @@ bool JKRAramArchive::open(s32 entryNum) {
|
||||
JKRDvdToMainRam(entryNum, (u8*)mArcInfoBlock, EXPAND_SWITCH_UNKNOWN1, alignedSize, NULL,
|
||||
JKRDvdRipper::ALLOC_DIRECTION_FORWARD, 32, NULL, NULL);
|
||||
DCInvalidateRange(mArcInfoBlock, alignedSize);
|
||||
JKRSwapArchiveMemory(mArcInfoBlock);
|
||||
|
||||
mNodes = (SDIDirEntry*)((u8*)mArcInfoBlock + mArcInfoBlock->node_offset);
|
||||
mFiles = (SDIFileEntry*)((u8*)mArcInfoBlock + mArcInfoBlock->file_entry_offset);
|
||||
|
||||
@@ -88,6 +88,7 @@ bool JKRCompArchive::open(s32 entryNum) {
|
||||
|
||||
JKRDvdToMainRam(entryNum, (u8 *)arcHeader, EXPAND_SWITCH_UNKNOWN1, 32, NULL, JKRDvdRipper::ALLOC_DIRECTION_FORWARD, 0, &mCompression, NULL);
|
||||
DCInvalidateRange(arcHeader, 32);
|
||||
JKRSwapArcHeader(arcHeader);
|
||||
|
||||
mSizeOfMemPart = arcHeader->field_0x14;
|
||||
mSizeOfAramPart = arcHeader->field_0x18;
|
||||
@@ -108,6 +109,7 @@ bool JKRCompArchive::open(s32 entryNum) {
|
||||
JKRDvdToMainRam(entryNum, (u8 *)mArcInfoBlock, EXPAND_SWITCH_UNKNOWN1, (uintptr_t)arcHeader->file_data_offset + mSizeOfMemPart,
|
||||
NULL, JKRDvdRipper::ALLOC_DIRECTION_FORWARD, 0x20, NULL, NULL);
|
||||
DCInvalidateRange(mArcInfoBlock, (uintptr_t)arcHeader->file_data_offset + mSizeOfMemPart);
|
||||
JKRSwapArchiveMemory(mArcInfoBlock);
|
||||
field_0x64 = (uintptr_t)mArcInfoBlock + arcHeader->file_data_offset;
|
||||
|
||||
if (mSizeOfAramPart != 0) {
|
||||
@@ -156,6 +158,7 @@ bool JKRCompArchive::open(s32 entryNum) {
|
||||
else {
|
||||
// arcHeader + 1 should lead to 0x20, which is the data after the header
|
||||
JKRHeap::copyMemory((u8 *)mArcInfoBlock, arcHeader + 1, (arcHeader->file_data_offset + mSizeOfMemPart));
|
||||
JKRSwapArchiveMemory(mArcInfoBlock);
|
||||
field_0x64 = (uintptr_t)mArcInfoBlock + arcHeader->file_data_offset;
|
||||
if (mSizeOfAramPart != 0) {
|
||||
mAramPart = (JKRAramBlock*)JKRAllocFromAram(mSizeOfAramPart, JKRAramHeap::HEAD);
|
||||
|
||||
@@ -206,7 +206,7 @@ void JKRDecomp::decodeSZS(u8* src_buffer, u8* dst_buffer, u32 srcSize, u32 dstSi
|
||||
s32 chunkBitsLeft = 0;
|
||||
s32 chunkBits;
|
||||
|
||||
decompEnd = dst_buffer + *(int*)(src_buffer + 4) - dstSize;
|
||||
decompEnd = dst_buffer + JKRDecompExpandSize(src_buffer) - dstSize;
|
||||
|
||||
if (srcSize == 0) {
|
||||
return;
|
||||
|
||||
@@ -329,7 +329,8 @@ static int decompSZS_subroutine(u8* src, u32 dest) {
|
||||
}
|
||||
|
||||
SYaz0Header* header = (SYaz0Header*)src;
|
||||
endAddr = dest + (header->length - fileOffset);
|
||||
u32 decompressedLength = JKRDecompExpandSize(src);
|
||||
endAddr = dest + (decompressedLength - fileOffset);
|
||||
if (endAddr > dest + maxDest) {
|
||||
endAddr = dest + maxDest;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ bool JKRDvdArchive::open(s32 entryNum) {
|
||||
JKRDvdToMainRam(entryNum, (u8*)arcHeader, EXPAND_SWITCH_UNKNOWN1, sizeof(SArcHeader), NULL,
|
||||
JKRDvdRipper::ALLOC_DIRECTION_FORWARD, 0, &mCompression, NULL);
|
||||
DCInvalidateRange(arcHeader, sizeof(SArcHeader));
|
||||
JKRSwapArcHeader(arcHeader);
|
||||
|
||||
int alignment;
|
||||
alignment = mMountDirection == MOUNT_DIRECTION_HEAD ? 0x20 : -0x20;
|
||||
@@ -90,6 +91,7 @@ bool JKRDvdArchive::open(s32 entryNum) {
|
||||
arcHeader->file_data_offset, NULL, JKRDvdRipper::ALLOC_DIRECTION_FORWARD,
|
||||
sizeof(SArcHeader), NULL, NULL);
|
||||
DCInvalidateRange(mArcInfoBlock, arcHeader->file_data_offset);
|
||||
JKRSwapArchiveMemory(mArcInfoBlock);
|
||||
|
||||
mNodes = (SDIDirEntry*)((intptr_t)&mArcInfoBlock->num_nodes + mArcInfoBlock->node_offset);
|
||||
mFiles = (SDIFileEntry*)((intptr_t)&mArcInfoBlock->num_nodes + mArcInfoBlock->file_entry_offset);
|
||||
|
||||
@@ -329,7 +329,8 @@ int decompSZS_subroutine(u8* src, u8* dest) {
|
||||
}
|
||||
|
||||
SYaz0Header* header = (SYaz0Header*)src;
|
||||
endPtr = dest + (header->length - fileOffset);
|
||||
u32 decompressedLength = JKRDecompExpandSize(src);
|
||||
endPtr = dest + (decompressedLength - fileOffset);
|
||||
if (endPtr > dest + maxDest) {
|
||||
endPtr = dest + maxDest;
|
||||
}
|
||||
|
||||
@@ -89,8 +89,10 @@ bool JKRMemArchive::open(s32 entryNum, JKRArchive::EMountDirection mountDirectio
|
||||
mMountMode = UNKNOWN_MOUNT_MODE;
|
||||
}
|
||||
else {
|
||||
JKRSwapArcHeader(mArcHeader);
|
||||
JUT_ASSERT(438, mArcHeader->signature == 'RARC');
|
||||
mArcInfoBlock = (SArcDataInfo *)((u8 *)mArcHeader + mArcHeader->header_length);
|
||||
JKRSwapArchiveMemory(mArcInfoBlock);
|
||||
mNodes = (SDIDirEntry *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->node_offset);
|
||||
mFiles = (SDIFileEntry *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->file_entry_offset);
|
||||
mStringTable = (char *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->string_table_offset);
|
||||
@@ -111,8 +113,10 @@ bool JKRMemArchive::open(s32 entryNum, JKRArchive::EMountDirection mountDirectio
|
||||
|
||||
bool JKRMemArchive::open(void* buffer, u32 bufferSize, JKRMemBreakFlag flag) {
|
||||
mArcHeader = (SArcHeader *)buffer;
|
||||
JKRSwapArcHeader(mArcHeader);
|
||||
JUT_ASSERT(491, mArcHeader->signature == 'RARC');
|
||||
mArcInfoBlock = (SArcDataInfo *)((u8 *)mArcHeader + mArcHeader->header_length);
|
||||
JKRSwapArchiveMemory(mArcInfoBlock);
|
||||
mNodes = (SDIDirEntry *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->node_offset);
|
||||
mFiles = (SDIFileEntry *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->file_entry_offset);
|
||||
mStringTable = (char *)((u8 *)&mArcInfoBlock->num_nodes + mArcInfoBlock->string_table_offset);
|
||||
|
||||
@@ -8,6 +8,15 @@
|
||||
#include <dolphin/gx.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef TARGET_PC
|
||||
#include "dusk/endian.h"
|
||||
static inline u32 R32(u32 v) { return be32(v); }
|
||||
static inline u16 R16(u16 v) { return be16(v); }
|
||||
#else
|
||||
static inline u32 R32(u32 v) { return v; }
|
||||
static inline u16 R16(u16 v) { return v; }
|
||||
#endif
|
||||
|
||||
JUTCacheFont::JUTCacheFont(ResFONT const* p_fontRes, u32 cacheSize, JKRHeap* p_heap) {
|
||||
initialize_state();
|
||||
JUTResFont::initialize_state();
|
||||
@@ -73,24 +82,26 @@ int JUTCacheFont::getMemorySize(ResFONT const* p_font, u16* o_widCount, u32* o_w
|
||||
u32 glyTexSize;
|
||||
|
||||
u8* fontInf = (u8*)p_font->data;
|
||||
for (int i = 0; i < p_font->numBlocks; i++) {
|
||||
switch (((BlockHeader*)fontInf)->magic) {
|
||||
for (int i = 0; i < (int)R32(p_font->numBlocks); i++) {
|
||||
u32 blkMagic = R32(((BlockHeader*)fontInf)->magic);
|
||||
u32 blkSize = R32(((BlockHeader*)fontInf)->size);
|
||||
switch (blkMagic) {
|
||||
case 'INF1':
|
||||
break;
|
||||
case 'WID1':
|
||||
totalWidSize += ((BlockHeader*)fontInf)->size;
|
||||
totalWidSize += blkSize;
|
||||
widBlockCount++;
|
||||
break;
|
||||
case 'GLY1':
|
||||
totalGlySize += ((BlockHeader*)fontInf)->size;
|
||||
glyTexSize = ((ResFONT::GLY1*)fontInf)->textureSize;
|
||||
totalGlySize += blkSize;
|
||||
glyTexSize = R32(((ResFONT::GLY1*)fontInf)->textureSize);
|
||||
glyBlockCount++;
|
||||
if (glyTexSize > maxGlyTexSize) {
|
||||
maxGlyTexSize = glyTexSize;
|
||||
}
|
||||
break;
|
||||
case 'MAP1':
|
||||
totalMapSize += ((BlockHeader*)fontInf)->size;
|
||||
totalMapSize += blkSize;
|
||||
mapBlockCount++;
|
||||
break;
|
||||
default:
|
||||
@@ -98,7 +109,7 @@ int JUTCacheFont::getMemorySize(ResFONT const* p_font, u16* o_widCount, u32* o_w
|
||||
break;
|
||||
}
|
||||
|
||||
fontInf += ((BlockHeader*)fontInf)->size;
|
||||
fontInf += blkSize;
|
||||
}
|
||||
|
||||
if (o_widCount != NULL) {
|
||||
@@ -257,56 +268,59 @@ void JUTCacheFont::setBlock() {
|
||||
ResFONT::MAP1* pMap = (ResFONT::MAP1*)field_0x84;
|
||||
u32 aramAddress = field_0xac->getAddress();
|
||||
mMaxCode = 0xffff;
|
||||
const int* pData = (int*)mResFont->data;
|
||||
const u8* pData = (const u8*)mResFont->data;
|
||||
|
||||
for (int i = 0; i < mResFont->numBlocks; i++) {
|
||||
for (int i = 0; i < (int)R32(mResFont->numBlocks); i++) {
|
||||
u32 blkMagic = R32(((BlockHeader*)pData)->magic);
|
||||
u32 blkSize = R32(((BlockHeader*)pData)->size);
|
||||
u32 u;
|
||||
switch (*pData) {
|
||||
switch (blkMagic) {
|
||||
case 'INF1':
|
||||
memcpy(mInf1Ptr, pData, 0x20);
|
||||
u = mInf1Ptr->fontType;
|
||||
u = R16(mInf1Ptr->fontType);
|
||||
JUT_ASSERT(448, u < suAboutEncoding_);
|
||||
mIsLeadByte = &JUTResFont::saoAboutEncoding_[u];
|
||||
break;
|
||||
case 'WID1':
|
||||
memcpy(pWidth, pData, pData[1]);
|
||||
memcpy(pWidth, pData, blkSize);
|
||||
mpWidthBlocks[widthNum] = (ResFONT::WID1*)pWidth;
|
||||
widthNum++;
|
||||
pWidth += pData[1];
|
||||
pWidth += blkSize;
|
||||
break;
|
||||
case 'GLY1':
|
||||
case 'GLY1': {
|
||||
memcpy(piVar5, pData, 0x20);
|
||||
JKRAramBlock* iVar1;
|
||||
iVar1 = JKRMainRamToAram((u8*)pData + 0x20, aramAddress, pData[1] - 0x20,
|
||||
iVar1 = JKRMainRamToAram((u8*)pData + 0x20, aramAddress, blkSize - 0x20,
|
||||
EXPAND_SWITCH_UNKNOWN0, 0, NULL, 0xffffffff, NULL);
|
||||
if (iVar1 == NULL) {
|
||||
JUTException::panic("JUTCacheFont.cpp", 0x1dd,
|
||||
"trouble occurred in JKRMainRamToAram.");
|
||||
}
|
||||
piVar5->magic = aramAddress;
|
||||
if (piVar5->textureSize > mMaxSheetSize) {
|
||||
mMaxSheetSize = piVar5->textureSize;
|
||||
if (R32(piVar5->textureSize) > mMaxSheetSize) {
|
||||
mMaxSheetSize = R32(piVar5->textureSize);
|
||||
}
|
||||
mpGlyphBlocks[gylphNum] = piVar5;
|
||||
gylphNum++;
|
||||
piVar5++;
|
||||
aramAddress += pData[1] - 0x20;
|
||||
aramAddress += blkSize - 0x20;
|
||||
break;
|
||||
}
|
||||
case 'MAP1':
|
||||
memcpy(pMap, pData, pData[1]);
|
||||
memcpy(pMap, pData, blkSize);
|
||||
mpMapBlocks[mapNum] = pMap;
|
||||
if (mMaxCode > mpMapBlocks[mapNum]->startCode) {
|
||||
mMaxCode = mpMapBlocks[mapNum]->startCode;
|
||||
if (mMaxCode > R16(mpMapBlocks[mapNum]->startCode)) {
|
||||
mMaxCode = R16(mpMapBlocks[mapNum]->startCode);
|
||||
}
|
||||
mapNum++;
|
||||
pMap = (ResFONT::MAP1*)((u8*)pMap + pData[1]);
|
||||
pMap = (ResFONT::MAP1*)((u8*)pMap + blkSize);
|
||||
break;
|
||||
default:
|
||||
JUTReportConsole("Unknown data block\n");
|
||||
break;
|
||||
}
|
||||
|
||||
pData = (int*)((u8*)pData + pData[1]);
|
||||
pData = pData + blkSize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,8 +404,8 @@ JUTCacheFont::TCachePage* JUTCacheFont::loadCache_char_subroutine(int* param_0,
|
||||
rv = NULL;
|
||||
int i = 0;
|
||||
for (; i < mGly1BlockNum; i++) {
|
||||
if (mpGlyphBlocks[i]->startCode <= *r29 && *r29 <= mpGlyphBlocks[i]->endCode) {
|
||||
*r29 -= mpGlyphBlocks[i]->startCode;
|
||||
if (R16(mpGlyphBlocks[i]->startCode) <= *r29 && *r29 <= R16(mpGlyphBlocks[i]->endCode)) {
|
||||
*r29 -= R16(mpGlyphBlocks[i]->startCode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -461,23 +475,23 @@ ResFONT* JUTResFont::getResFont() const {
|
||||
}
|
||||
|
||||
int JUTResFont::getFontType() const {
|
||||
return mInf1Ptr->fontType;
|
||||
return R16(mInf1Ptr->fontType);
|
||||
}
|
||||
|
||||
int JUTResFont::getLeading() const {
|
||||
return mInf1Ptr->leading;
|
||||
return R16(mInf1Ptr->leading);
|
||||
}
|
||||
|
||||
s32 JUTResFont::getWidth() const {
|
||||
return mInf1Ptr->width;
|
||||
return R16(mInf1Ptr->width);
|
||||
}
|
||||
|
||||
s32 JUTResFont::getAscent() const {
|
||||
return mInf1Ptr->ascent;
|
||||
return R16(mInf1Ptr->ascent);
|
||||
}
|
||||
|
||||
s32 JUTResFont::getDescent() const {
|
||||
return mInf1Ptr->descent;
|
||||
return R16(mInf1Ptr->descent);
|
||||
}
|
||||
|
||||
s32 JUTResFont::getHeight() const {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user