From bab9581901dbf915cd2fda0b22c5ff604b781df5 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Mar 2021 19:42:29 -0700 Subject: [PATCH] Core: Unbreak ValidSize limits. Broken in bdd2029. --- Core/MemMap.h | 8 ++++---- unittest/UnitTest.cpp | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Core/MemMap.h b/Core/MemMap.h index 465802fb32..b9afe2ea35 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -313,13 +313,13 @@ inline bool IsValidAddress(const u32 address) { inline u32 ValidSize(const u32 address, const u32 requested_size) { u32 max_size; if ((address & 0x3E000000) == 0x08000000) { - max_size = 0x08000000 + g_MemorySize - (address & 0x3E000000); + max_size = 0x08000000 + g_MemorySize - (address & 0x3FFFFFFF); } else if ((address & 0x3F800000) == 0x04000000) { - max_size = 0x04800000 - (address & 0x3F800000); + max_size = 0x04800000 - (address & 0x3FFFFFFF); } else if ((address & 0xBFFF0000) == 0x00010000) { - max_size = 0x00014000 - (address & 0xBFFF0000); + max_size = 0x00014000 - (address & 0xBFFFFFFF); } else if ((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize) { - max_size = 0x08000000 + g_MemorySize - (address & 0x3F000000); + max_size = 0x08000000 + g_MemorySize - (address & 0x3FFFFFFF); } else { max_size = 0; } diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index 65447c27f0..1e0310991b 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -567,6 +567,8 @@ static bool TestMemMap() { EXPECT_EQ_HEX(Memory::ValidSize(base, 0x40000001), range.size); EXPECT_EQ_HEX(Memory::ValidSize(base, 0x20000001), range.size); EXPECT_EQ_HEX(Memory::ValidSize(base, 0x10000001), range.size); + + EXPECT_EQ_HEX(Memory::ValidSize(base + range.size - 0x10, 0x20000001), 0x10); } } @@ -607,6 +609,7 @@ TestItem availableTests[] = { TEST_ITEM(ParseLBN), TEST_ITEM(QuickTexHash), TEST_ITEM(CLZ), + TEST_ITEM(MemMap), TEST_ITEM(ShaderGenerators), };