From ed3a4aaaae296ad94a2d9186d96278c9ceac304d Mon Sep 17 00:00:00 2001 From: William Carter Date: Sun, 15 Mar 2026 19:08:33 -0400 Subject: [PATCH 1/4] Get __THPReadHuffmanTableSpecification closer to match --- extern/dolphin/include/dolphin/thp/thp.h | 11 ++++++----- extern/dolphin/src/dolphin/thp/THPDec.c | 13 +++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/extern/dolphin/include/dolphin/thp/thp.h b/extern/dolphin/include/dolphin/thp/thp.h index 5472a637c9..7aa19ffd8a 100644 --- a/extern/dolphin/include/dolphin/thp/thp.h +++ b/extern/dolphin/include/dolphin/thp/thp.h @@ -21,7 +21,8 @@ typedef struct _THPHuffmanTab { u8* bits; u32 pad3; u32* codetab; - u32 pad2[2]; + u32 pad2; + u16 num_Vij; } THPHuffmanTab; typedef struct _THPComponent { @@ -55,14 +56,13 @@ typedef struct _THPFileInfo { THPComponent components[3]; } THPFileInfo; -typedef struct { +typedef struct { s32 val0; u16 val1; u16 _pad; - u8 val2; + u8 val2; } THPDec_8032FD40_Data; - static u8 __THPSetupBuffers(THPFileInfo*); static u8 __THPReadFrameHeader(void); static u8 __THPReadScaneHeader(THPFileInfo*); @@ -84,7 +84,8 @@ static void __THPHuffDecodeDCTCompY(THPFileInfo*, THPCoeff*); static void __THPHuffDecodeDCTCompU(THPFileInfo*, THPCoeff*); static void __THPHuffDecodeDCTCompV(THPFileInfo*, THPCoeff*); -s32 THPVideoDecode(void* file, void* tileY, void* tileU, void* tileV, void* work); +s32 THPVideoDecode(void* file, void* tileY, void* tileU, void* tileV, + void* work); s32 THPDec_803302EC(u8** data); s32 THPDec_8032FD40(THPDec_8032FD40_Data* arg0, u16 arg1); void THPDec_803300E0(u32* data); diff --git a/extern/dolphin/src/dolphin/thp/THPDec.c b/extern/dolphin/src/dolphin/thp/THPDec.c index a5a40d3c69..19ae1cf2d3 100644 --- a/extern/dolphin/src/dolphin/thp/THPDec.c +++ b/extern/dolphin/src/dolphin/thp/THPDec.c @@ -240,7 +240,8 @@ s32 THPVideoDecode(void* file, void* tileY, void* tileU, void* tileV, } } - else { + else + { goto _err_unsupported_marker; } } @@ -493,7 +494,7 @@ static u8 __THPReadHuffmanTableSpecification(THPFileInfo* info) info->huffmanTabs[tab_index].bits = huffmanBits; info->huffmanTabs[tab_index].Vij = info->file; - info->huffmanTabs[tab_index].pad2[1] = num_Vij; + info->huffmanTabs[tab_index].num_Vij = num_Vij; info->file += num_Vij; result = __THPHuffGenerateSizeTable(info, tab_index, (int) huffmanBits); @@ -1760,8 +1761,7 @@ static void __THPHuffDecodeDCTCompY(register THPFileInfo* info, } #endif // clang-format on - for (k = 1; k < 64; k++) - { + for (k = 1; k < 64; k++) { register s32 ssss; register s32 rrrr; @@ -2174,7 +2174,8 @@ static void __THPHuffDecodeDCTCompU(register THPFileInfo* info, block[__THPJpegNaturalOrder[k]] = (s16) rrrr; } - else { + else + { if (rrrr != 15) { break; } @@ -2376,4 +2377,4 @@ BOOL THPInit(void) __THPInitFlag = TRUE; return TRUE; -} \ No newline at end of file +} From 98ad5a63477372369880f64de111e3a6f191774e Mon Sep 17 00:00:00 2001 From: William Carter Date: Sun, 15 Mar 2026 19:18:14 -0400 Subject: [PATCH 2/4] THPInit cleanup --- extern/dolphin/include/dolphin/thp/thp.h | 4 ++-- extern/dolphin/src/dolphin/thp/THPDec.c | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/extern/dolphin/include/dolphin/thp/thp.h b/extern/dolphin/include/dolphin/thp/thp.h index 7aa19ffd8a..1f8e1615d7 100644 --- a/extern/dolphin/include/dolphin/thp/thp.h +++ b/extern/dolphin/include/dolphin/thp/thp.h @@ -52,7 +52,7 @@ typedef struct _THPFileInfo { u16 nMCU; u16 currMCU; u8* dLC[3]; - u32 pad2[(0x83d - 0x756) / 4]; + u8 pad2[0x83d - 0x756]; THPComponent components[3]; } THPFileInfo; @@ -89,7 +89,7 @@ s32 THPVideoDecode(void* file, void* tileY, void* tileU, void* tileV, s32 THPDec_803302EC(u8** data); s32 THPDec_8032FD40(THPDec_8032FD40_Data* arg0, u16 arg1); void THPDec_803300E0(u32* data); -BOOL THPInit(void); +void THPInit(void); #ifdef __cplusplus } diff --git a/extern/dolphin/src/dolphin/thp/THPDec.c b/extern/dolphin/src/dolphin/thp/THPDec.c index 19ae1cf2d3..96c072f6ee 100644 --- a/extern/dolphin/src/dolphin/thp/THPDec.c +++ b/extern/dolphin/src/dolphin/thp/THPDec.c @@ -2352,10 +2352,14 @@ static inline void OSInitFastCast(void) { // clang-format off -BOOL THPInit(void) +void THPInit(void) { u8* base; - //OSRegisterVersion(__THPVersion); + + if (!(PPCMfhid2() & 0x10000000)) { + DCInvalidateRange((u8*)(0xE0000000), 0x4000); + LCEnable(); + } base = (u8*)(0xE000 << 16); __THPLCWork512[0] = base; @@ -2367,14 +2371,13 @@ BOOL THPInit(void) base = (u8*)(0xE000 << 16); __THPLCWork672[0] = base; - base += 0x2A00; + base += 0x2800; __THPLCWork672[1] = base; - base += 0xA80; + base += 0xA00; __THPLCWork672[2] = base; base += 0xA80; - //OSInitFastCast(); + OSInitFastCast(); - __THPInitFlag = TRUE; - return TRUE; + return; } From 32dd32e3329768947d3e59dfbb9bd62a983adf6f Mon Sep 17 00:00:00 2001 From: William Carter Date: Sun, 15 Mar 2026 19:28:35 -0400 Subject: [PATCH 3/4] Change __THPDecompressiMCURowNxN declaration --- extern/dolphin/include/dolphin/thp/thp.h | 2 +- extern/dolphin/src/dolphin/thp/THPDec.c | 48 ++++++++++++------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/extern/dolphin/include/dolphin/thp/thp.h b/extern/dolphin/include/dolphin/thp/thp.h index 1f8e1615d7..a1f3818e5d 100644 --- a/extern/dolphin/include/dolphin/thp/thp.h +++ b/extern/dolphin/include/dolphin/thp/thp.h @@ -76,7 +76,7 @@ static u8 __THPRestartDefinition(THPFileInfo*); static void __THPPrepBitStream(THPFileInfo*); static void __THPDecompressYUV(void*, void*, void*); static void __THPGQRRestore(void); -static void __THPDecompressiMCURow512x448(void); +static void __THPDecompressiMCURow512x448(THPFileInfo*); static void __THPDecompressiMCURow640x480(void); static void __THPDecompressiMCURowNxN(void); static void __THPInverseDCTNoYPos(THPCoeff*, u32); diff --git a/extern/dolphin/src/dolphin/thp/THPDec.c b/extern/dolphin/src/dolphin/thp/THPDec.c index 96c072f6ee..cef333259a 100644 --- a/extern/dolphin/src/dolphin/thp/THPDec.c +++ b/extern/dolphin/src/dolphin/thp/THPDec.c @@ -151,7 +151,7 @@ static void __THPDecompressYUV(void* tileY, void* tileU, void* tileV) if (__THPInfo->xPixelSize == 512 && targetY == 448) { while (currentY < targetY) { - __THPDecompressiMCURow512x448(); + __THPDecompressiMCURow512x448(__THPInfo); currentY += 16; } } else if (__THPInfo->xPixelSize == 640 && targetY == 480) { @@ -1230,7 +1230,7 @@ inline void __THPInverseDCTY8(register THPCoeff* in, register u32 xPos) } } -static void __THPDecompressiMCURow512x448(void) +static void __THPDecompressiMCURow512x448(THPFileInfo* info) { u8 cl_num; u32 x_pos; @@ -1238,47 +1238,47 @@ static void __THPDecompressiMCURow512x448(void) LCQueueWait(3); - for (cl_num = 0; cl_num < __THPInfo->MCUsPerRow; cl_num++) { - __THPHuffDecodeDCTCompY(__THPInfo, __THPMCUBuffer[0]); - __THPHuffDecodeDCTCompY(__THPInfo, __THPMCUBuffer[1]); - __THPHuffDecodeDCTCompY(__THPInfo, __THPMCUBuffer[2]); - __THPHuffDecodeDCTCompY(__THPInfo, __THPMCUBuffer[3]); - __THPHuffDecodeDCTCompU(__THPInfo, __THPMCUBuffer[4]); - __THPHuffDecodeDCTCompV(__THPInfo, __THPMCUBuffer[5]); + for (cl_num = 0; cl_num < info->MCUsPerRow; cl_num++) { + __THPHuffDecodeDCTCompY(info, __THPMCUBuffer[0]); + __THPHuffDecodeDCTCompY(info, __THPMCUBuffer[1]); + __THPHuffDecodeDCTCompY(info, __THPMCUBuffer[2]); + __THPHuffDecodeDCTCompY(info, __THPMCUBuffer[3]); + __THPHuffDecodeDCTCompU(info, __THPMCUBuffer[4]); + __THPHuffDecodeDCTCompV(info, __THPMCUBuffer[5]); - comp = &__THPInfo->components[0]; + comp = &info->components[0]; Gbase = __THPLCWork512[0]; Gwid = 512; - Gq = __THPInfo->quantTabs[comp->quantizationTableSelector]; + Gq = info->quantTabs[comp->quantizationTableSelector]; x_pos = (u32) (cl_num * 16); __THPInverseDCTNoYPos(__THPMCUBuffer[0], x_pos); __THPInverseDCTNoYPos(__THPMCUBuffer[1], x_pos + 8); __THPInverseDCTY8(__THPMCUBuffer[2], x_pos); __THPInverseDCTY8(__THPMCUBuffer[3], x_pos + 8); - comp = &__THPInfo->components[1]; + comp = &info->components[1]; Gbase = __THPLCWork512[1]; Gwid = 256; - Gq = __THPInfo->quantTabs[comp->quantizationTableSelector]; + Gq = info->quantTabs[comp->quantizationTableSelector]; x_pos /= 2; __THPInverseDCTNoYPos(__THPMCUBuffer[4], x_pos); - comp = &__THPInfo->components[2]; + comp = &info->components[2]; Gbase = __THPLCWork512[2]; - Gq = __THPInfo->quantTabs[comp->quantizationTableSelector]; + Gq = info->quantTabs[comp->quantizationTableSelector]; __THPInverseDCTNoYPos(__THPMCUBuffer[5], x_pos); - if (__THPInfo->RST != 0) { - if ((--__THPInfo->currMCU) == 0) { - __THPInfo->currMCU = __THPInfo->nMCU; - __THPInfo->cnt = 1 + ((__THPInfo->cnt + 6) & 0xFFFFFFF8); + if (info->RST != 0) { + if ((--info->currMCU) == 0) { + info->currMCU = info->nMCU; + info->cnt = 1 + ((info->cnt + 6) & 0xFFFFFFF8); - if (__THPInfo->cnt > 33) { - __THPInfo->cnt = 33; + if (info->cnt > 33) { + info->cnt = 33; } - __THPInfo->components[0].predDC = 0; - __THPInfo->components[1].predDC = 0; - __THPInfo->components[2].predDC = 0; + info->components[0].predDC = 0; + info->components[1].predDC = 0; + info->components[2].predDC = 0; } } } From 076bbfe9d2c84997c676bd9b17ad6400e38c288a Mon Sep 17 00:00:00 2001 From: William Carter Date: Sun, 15 Mar 2026 19:31:08 -0400 Subject: [PATCH 4/4] Add padding to match __THPHuffDecodeDCTCompY --- extern/dolphin/include/dolphin/thp/thp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/extern/dolphin/include/dolphin/thp/thp.h b/extern/dolphin/include/dolphin/thp/thp.h index a1f3818e5d..58a873fc6c 100644 --- a/extern/dolphin/include/dolphin/thp/thp.h +++ b/extern/dolphin/include/dolphin/thp/thp.h @@ -26,6 +26,7 @@ typedef struct _THPHuffmanTab { } THPHuffmanTab; typedef struct _THPComponent { + u8 _; THPCoeff predDC; u8 pad; u8 quantizationTableSelector;