Added a check for TMEM overflows while preloading textures. Thanks to NeoBrainX for the tip.
This commit is contained in:
parent
fa2b4cd8fc
commit
f30aebf8d7
|
@ -62,7 +62,7 @@
|
||||||
#define BPMEM_COPYFILTER1 0x54
|
#define BPMEM_COPYFILTER1 0x54
|
||||||
#define BPMEM_CLEARBBOX1 0x55
|
#define BPMEM_CLEARBBOX1 0x55
|
||||||
#define BPMEM_CLEARBBOX2 0x56
|
#define BPMEM_CLEARBBOX2 0x56
|
||||||
#define BPMEM_UNKOWN_57 0x57
|
#define BPMEM_UNKNOWN_57 0x57
|
||||||
#define BPMEM_REVBITS 0x58
|
#define BPMEM_REVBITS 0x58
|
||||||
#define BPMEM_SCISSOROFFSET 0x59
|
#define BPMEM_SCISSOROFFSET 0x59
|
||||||
#define BPMEM_PRELOAD_ADDR 0x60
|
#define BPMEM_PRELOAD_ADDR 0x60
|
||||||
|
|
|
@ -463,8 +463,8 @@ void BPWritten(const BPCmd& bp)
|
||||||
case BPMEM_REVBITS: // Always set to 0x0F when GX_InitRevBits() is called.
|
case BPMEM_REVBITS: // Always set to 0x0F when GX_InitRevBits() is called.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BPMEM_UNKOWN_57: // Sunshine alternates this register between values 0x000 and 0xAAA
|
case BPMEM_UNKNOWN_57: // Sunshine alternates this register between values 0x000 and 0xAAA
|
||||||
DEBUG_LOG(VIDEO, "Uknown BP Reg 0x57: %08x", bp.newvalue);
|
DEBUG_LOG(VIDEO, "Unknown BP Reg 0x57: %08x", bp.newvalue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BPMEM_PRELOAD_ADDR:
|
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 this is different from 0, manual TMEM management is used.
|
||||||
if (bp.newvalue != 0)
|
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;
|
BPS_TmemConfig& tmem_cfg = bpmem.tmem_config;
|
||||||
u8* ram_ptr = Memory::GetPointer(tmem_cfg.preload_addr << 5);
|
u8* ram_ptr = Memory::GetPointer(tmem_cfg.preload_addr << 5);
|
||||||
u32 tmem_addr = 0;
|
u32 tmem_addr = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE;
|
||||||
|
|
||||||
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 size = tmem_cfg.preload_tile_info.count * 32;
|
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);
|
memcpy(texMem + tmem_addr, ram_ptr, size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue