From 87a74c0b480ea79552c2e2081c0ff0b9b4066beb Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 16 Oct 2022 13:54:59 -0700 Subject: [PATCH] CGBASupport: Add version differences for korean release --- src/MetroidPrime/CGBASupport.cpp | 47 ++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/MetroidPrime/CGBASupport.cpp b/src/MetroidPrime/CGBASupport.cpp index f9127718..aecb3bd6 100644 --- a/src/MetroidPrime/CGBASupport.cpp +++ b/src/MetroidPrime/CGBASupport.cpp @@ -8,13 +8,20 @@ #include "rstl/math.hpp" void joyboot_callback(s32 chan, s32 ret) {} - +#if VERSION < 2 const uint MAGIC = 0x414d5445; +#endif static CGBASupport* g_GBA; +inline bool GetFontEncoding() { return OSGetFontEncode() == 1; } + CGBASupport::CGBASupport() +#if VERSION >= 2 +: x0_file(GetFontEncoding() ? "client_jap.bin" : "client_pad.bin") +#else : x0_file("client_pad.bin") +#endif , x28_fileSize(OSRoundUp32B(x0_file.Length())) , x2c_buffer((uchar*)CMemory::Alloc(x28_fileSize, IAllocator::kHI_RoundUpLen)) , x30_dvdReq(x0_file.SyncRead(x2c_buffer.get(), x28_fileSize)) @@ -26,6 +33,9 @@ CGBASupport::CGBASupport() , x45_fusionBeat(false) { GBAInit(); g_GBA = this; +#if VERSION >= 2 + OSGetFontEncode(); +#endif } CGBASupport::~CGBASupport() { g_GBA = nullptr; } @@ -56,8 +66,18 @@ inline bool CGBASupport::CheckReadyStatus() { buff[0xc9] = (tick >> 8); buff[0xca] = (tick >> 16); buff[0xcb] = (tick >> 24); +#if VERSION < 2 buff[0xaf] = 'E'; // set region to 'E' instead of 'J' buff[0xbd] = 0xc9; +#else + if (GetFontEncoding()) { + buff[0xaf] = 'J'; // set region to 'E' instead of 'J' + buff[0xbd] = 0xc4; + } else { + buff[0xaf] = 'E'; // set region to 'E' instead of 'J' + buff[0xbd] = 0xc9; + } +#endif return true; } return false; @@ -97,8 +117,8 @@ void CGBASupport::Update(float dt) { case kP_StartJoyBusBoot: x34_phase = kP_PollJoyBusBoot; - GBAJoyBootAsync(x40_siChan, x40_siChan << 1, 2, x2c_buffer.get(), x0_file.Length(), - &x3c_status, &joyboot_callback); + GBAJoyBootAsync(x40_siChan, x40_siChan << 1, 2, x2c_buffer.get(), x0_file.Length(), &x3c_status, + &joyboot_callback); break; case kP_PollJoyBusBoot: @@ -161,22 +181,39 @@ bool CGBASupport::PollResponse() { if (gbaStatus != 0x28) { return false; } + +#if VERSION >= 2 + const uint targetMagic = GetFontEncoding() ? 0x414D544A : 0x414D5445; +#endif + uint magic; - if (GBARead(x40_siChan, reinterpret_cast(&magic), &gbaStatus) == GBA_NOT_READY) { + if (GBARead(x40_siChan, (u8*)(&magic), &gbaStatus) == GBA_NOT_READY) { return false; } +#if VERSION < 2 if (magic != 0x414d5445) { // "AMTE" return false; } +#else + if (magic != targetMagic) { // "AMTE" + return false; + } +#endif if (GBAGetStatus(x40_siChan, &gbaStatus) == GBA_NOT_READY) { return false; } if (gbaStatus != 0x20) { return false; } +#if VERSION < 2 if (GBAWrite(x40_siChan, (u8*)(&MAGIC), &gbaStatus) == GBA_NOT_READY) { return false; } +#else + if (GBAWrite(x40_siChan, (u8*)(&targetMagic), &gbaStatus) == GBA_NOT_READY) { + return false; + } +#endif if (GBAGetStatus(x40_siChan, &gbaStatus) == GBA_NOT_READY) { return false; } @@ -194,7 +231,7 @@ bool CGBASupport::PollResponse() { uint read; uchar fusionStatus[4]; - if (GBARead(x40_siChan, reinterpret_cast(&read), &gbaStatus) != GBA_READY) { + if (GBARead(x40_siChan, reinterpret_cast< uchar* >(&read), &gbaStatus) != GBA_READY) { return false; } fusionStatus[0] = read >> 24;