Merge pull request #1428 from phire/fixPaletteCpy

Fix Invalid Palette Pointer error.
This commit is contained in:
skidau 2014-10-29 12:25:57 +11:00
commit 049afc4315
2 changed files with 22 additions and 11 deletions

View File

@ -214,13 +214,30 @@ u32 Read_Instruction(const u32 em_address)
return inst.hex;
}
static inline bool ValidCopyRange(u32 address, size_t size)
{
return (GetPointer(address) != nullptr &&
GetPointer(address + u32(size)) != nullptr &&
size < EXRAM_SIZE); // Make sure we don't have a range spanning seperate 2 banks
}
void CopyFromEmu(void* data, u32 address, size_t size)
{
if (!ValidCopyRange(address, size))
{
PanicAlert("Invalid range in CopyFromEmu. %lx bytes from 0x%08x", size, address);
return;
}
memcpy(data, GetPointer(address), size);
}
void CopyToEmu(u32 address, const void* data, size_t size)
{
if (!ValidCopyRange(address, size))
{
PanicAlert("Invalid range in CopyToEmu. %lx bytes to 0x%08x", size, address);
return;
}
memcpy(GetPointer(address), data, size);
}

View File

@ -269,19 +269,13 @@ static void BPWritten(const BPCmd& bp)
{
u32 tlutTMemAddr = (bp.newvalue & 0x3FF) << 9;
u32 tlutXferCount = (bp.newvalue & 0x1FFC00) >> 5;
u32 addr = bpmem.tmem_config.tlut_src << 5;
u32 addr = 0;
// The GameCube ignores the upper bits of this address. Some games (WW, MKDD) set them.
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
addr = addr & 0x01FFFFFF;
// TODO - figure out a cleaner way.
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
addr = bpmem.tmem_config.tlut_src << 5;
else
addr = (bpmem.tmem_config.tlut_src & 0xFFFFF) << 5;
if (addr)
Memory::CopyFromEmu(texMem + tlutTMemAddr, addr, tlutXferCount);
else
PanicAlert("Invalid palette pointer %08x %08x %08x", bpmem.tmem_config.tlut_src, bpmem.tmem_config.tlut_src << 5, (bpmem.tmem_config.tlut_src & 0xFFFFF)<< 5);
Memory::CopyFromEmu(texMem + tlutTMemAddr, addr, tlutXferCount);
return;
}