From f30aebf8d7bac892d08ef5585c2e858cf6d3f50b Mon Sep 17 00:00:00 2001 From: skidau Date: Sun, 25 Mar 2012 21:35:57 +1100 Subject: [PATCH] Added a check for TMEM overflows while preloading textures. Thanks to NeoBrainX for the tip. --- Source/Core/VideoCommon/Src/BPMemory.h | 2 +- Source/Core/VideoCommon/Src/BPStructs.cpp | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Source/Core/VideoCommon/Src/BPMemory.h b/Source/Core/VideoCommon/Src/BPMemory.h index 0bb2bf9013..de5c616f0f 100644 --- a/Source/Core/VideoCommon/Src/BPMemory.h +++ b/Source/Core/VideoCommon/Src/BPMemory.h @@ -62,7 +62,7 @@ #define BPMEM_COPYFILTER1 0x54 #define BPMEM_CLEARBBOX1 0x55 #define BPMEM_CLEARBBOX2 0x56 -#define BPMEM_UNKOWN_57 0x57 +#define BPMEM_UNKNOWN_57 0x57 #define BPMEM_REVBITS 0x58 #define BPMEM_SCISSOROFFSET 0x59 #define BPMEM_PRELOAD_ADDR 0x60 diff --git a/Source/Core/VideoCommon/Src/BPStructs.cpp b/Source/Core/VideoCommon/Src/BPStructs.cpp index 01b09e351b..d59523e117 100644 --- a/Source/Core/VideoCommon/Src/BPStructs.cpp +++ b/Source/Core/VideoCommon/Src/BPStructs.cpp @@ -463,8 +463,8 @@ void BPWritten(const BPCmd& bp) case BPMEM_REVBITS: // Always set to 0x0F when GX_InitRevBits() is called. break; - case BPMEM_UNKOWN_57: // Sunshine alternates this register between values 0x000 and 0xAAA - DEBUG_LOG(VIDEO, "Uknown BP Reg 0x57: %08x", bp.newvalue); + case BPMEM_UNKNOWN_57: // Sunshine alternates this register between values 0x000 and 0xAAA + DEBUG_LOG(VIDEO, "Unknown BP Reg 0x57: %08x", bp.newvalue); break; case BPMEM_PRELOAD_ADDR: @@ -476,16 +476,18 @@ void BPWritten(const BPCmd& bp) // if this is different from 0, manual TMEM management is used. if (bp.newvalue != 0) { + // NOTE(neobrain): Apparently tmemodd doesn't affect hardware behavior at all (libogc uses it just as a buffer and switches its contents with tmemeven whenever this is called) BPS_TmemConfig& tmem_cfg = bpmem.tmem_config; u8* ram_ptr = Memory::GetPointer(tmem_cfg.preload_addr << 5); - u32 tmem_addr = 0; - - if (bp.newvalue >> 16) - tmem_addr = tmem_cfg.preload_tmem_odd * TMEM_LINE_SIZE; - else - tmem_addr = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE; - + u32 tmem_addr = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE; u32 size = tmem_cfg.preload_tile_info.count * 32; + + // Check if the game has overflowed TMEM, and copy up to the limit. + // Paper Mario does this when entering the Great Boogly Tree (Chap 2) + // TODO: Does this wrap? + if ((tmem_addr + size) > TMEM_SIZE) + size = TMEM_SIZE - tmem_addr; + memcpy(texMem + tmem_addr, ram_ptr, size); } break;