diff --git a/pcsx2-qt/Settings/AdvancedSettingsWidget.cpp b/pcsx2-qt/Settings/AdvancedSettingsWidget.cpp
index 7a105cc01d..0c99638889 100644
--- a/pcsx2-qt/Settings/AdvancedSettingsWidget.cpp
+++ b/pcsx2-qt/Settings/AdvancedSettingsWidget.cpp
@@ -100,8 +100,8 @@ AdvancedSettingsWidget::AdvancedSettingsWidget(SettingsWindow* settings_dialog,
"end of the block, not on the instruction which caused the exception. Refer to the console to see the address where the invalid "
"access occurred."));
- dialog()->registerWidgetHelp(m_ui.extraMemory, tr("Enable 128MB RAM (Dev Console)"), tr("Unchecked"),
- tr("Exposes an additional 96MB of memory to the virtual machine."));
+ dialog()->registerWidgetHelp(m_ui.extraMemory, tr("Enable Extended RAM (Dev Console)"), tr("Unchecked"),
+ tr("Exposes additional memory to the virtual machine, expanding the EE and IOP memory to 128MB and 8MB respectively."));
dialog()->registerWidgetHelp(m_ui.vu0RoundingMode, tr("VU0 Rounding Mode"), tr("Chop/Zero (Default)"), tr("Changes how PCSX2 handles rounding while emulating the Emotion Engine's Vector Unit 0 (EE VU0). "
"The default value handles the vast majority of games; modifying this setting when a game is not having a visible problem will cause stability issues and/or crashes."));
diff --git a/pcsx2-qt/Settings/AdvancedSettingsWidget.ui b/pcsx2-qt/Settings/AdvancedSettingsWidget.ui
index e5cd7b2b13..6992e77364 100644
--- a/pcsx2-qt/Settings/AdvancedSettingsWidget.ui
+++ b/pcsx2-qt/Settings/AdvancedSettingsWidget.ui
@@ -176,7 +176,7 @@
-
- Enable 128MB RAM (Dev Console)
+ Enable Extended RAM (Dev Console)
diff --git a/pcsx2/DebugTools/DebugInterface.cpp b/pcsx2/DebugTools/DebugInterface.cpp
index 91cc1cbaf4..06167dbb48 100644
--- a/pcsx2/DebugTools/DebugInterface.cpp
+++ b/pcsx2/DebugTools/DebugInterface.cpp
@@ -1039,7 +1039,7 @@ bool R3000DebugInterface::isValidAddress(u32 addr)
return true;
}
- if (addr < 0x200000)
+ if (addr < Ps2MemSize::ExposedIopRam)
{
return true;
}
diff --git a/pcsx2/IopMem.cpp b/pcsx2/IopMem.cpp
index a6313666a1..3bb853bb79 100644
--- a/pcsx2/IopMem.cpp
+++ b/pcsx2/IopMem.cpp
@@ -52,10 +52,11 @@ void iopMemReset()
// at 0x0, 0x8000, and 0xa000:
for (int i = 0; i < 0x0080; i++)
{
- psxMemWLUT[i + 0x0000] = (uptr)&iopMem->Main[(i & 0x1f) << 16];
+ u32 mask = (Ps2MemSize::ExposedIopRam / _64kb) - 1;
+ psxMemWLUT[i + 0x0000] = (uptr)&iopMem->Main[(i & mask) << 16];
// RLUTs, accessed through WLUT.
- psxMemWLUT[i + 0x2000] = (uptr)&iopMem->Main[(i & 0x1f) << 16];
+ psxMemWLUT[i + 0x2000] = (uptr)&iopMem->Main[(i & mask) << 16];
}
// A few single-page allocations for things we store in special locations.
diff --git a/pcsx2/IopMem.h b/pcsx2/IopMem.h
index a2ed32ff41..54bd947852 100644
--- a/pcsx2/IopMem.h
+++ b/pcsx2/IopMem.h
@@ -37,7 +37,7 @@ static __fi const T* iopVirtMemR( u32 mem )
// Obtains a pointer to the IOP's physical mapping (bypasses the TLB)
static __fi u8* iopPhysMem( u32 addr )
{
- return &iopMem->Main[addr & 0x1fffff];
+ return &iopMem->Main[addr & (Ps2MemSize::ExposedIopRam - 1)];
}
#define psxSs8(mem) iopMem->Sif[(mem) & 0x00ff]
diff --git a/pcsx2/Memory.cpp b/pcsx2/Memory.cpp
index c65f19beac..79468f1a75 100644
--- a/pcsx2/Memory.cpp
+++ b/pcsx2/Memory.cpp
@@ -45,6 +45,7 @@ BIOS
namespace Ps2MemSize
{
u32 ExposedRam = MainRam;
+ u32 ExposedIopRam = IopRam;
} // namespace Ps2MemSize
namespace SysMemory
@@ -310,6 +311,7 @@ void memSetExtraMemMode(bool mode)
// update the amount of RAM exposed to the VM
Ps2MemSize::ExposedRam = mode ? Ps2MemSize::TotalRam : Ps2MemSize::MainRam;
+ Ps2MemSize::ExposedIopRam = mode ? Ps2MemSize::TotalIopRam: Ps2MemSize::IopRam;
}
void memSetKernelMode() {
diff --git a/pcsx2/MemoryTypes.h b/pcsx2/MemoryTypes.h
index 0d41f1d343..e64f43f1d7 100644
--- a/pcsx2/MemoryTypes.h
+++ b/pcsx2/MemoryTypes.h
@@ -16,11 +16,14 @@ namespace Ps2MemSize
static constexpr u32 Scratch = _16kb;
static constexpr u32 IopRam = _1mb * 2; // 2MB main ram on the IOP.
+ static constexpr u32 ExtraIopRam = _1mb * 6; // 2MB main ram on the IOP.
+ static constexpr u32 TotalIopRam = _8mb; // 2MB main ram on the IOP.
static constexpr u32 IopHardware = _64kb;
static constexpr u32 GSregs = 0x00002000; // 8k for the GS registers and stuff.
extern u32 ExposedRam;
+ extern u32 ExposedIopRam;
} // namespace Ps2MemSize
typedef u8 mem8_t;
@@ -51,9 +54,10 @@ struct EEVM_MemoryAllocMess
// Needs to fit within IOPmemSize of Memory.h
struct IopVM_MemoryAllocMess
{
- u8 Main[Ps2MemSize::IopRam]; // Main memory (hard-wired to 2MB)
- u8 P[_64kb]; // I really have no idea what this is... --air
- u8 Sif[0x100]; // a few special SIF/SBUS registers (likely not needed)
+ u8 Main[Ps2MemSize::IopRam]; // Main memory (hard-wired to 2MB)
+ u8 ExtraMemory[Ps2MemSize::ExtraIopRam]; // Extended memory to 16mb
+ u8 P[_64kb]; // I really have no idea what this is... --air
+ u8 Sif[0x100]; // a few special SIF/SBUS registers (likely not needed)
};
diff --git a/pcsx2/SaveState.cpp b/pcsx2/SaveState.cpp
index 239bc42add..324c312854 100644
--- a/pcsx2/SaveState.cpp
+++ b/pcsx2/SaveState.cpp
@@ -537,7 +537,7 @@ public:
const char* GetFilename() const override { return "iopMemory.bin"; }
u8* GetDataPtr() const override { return iopMem->Main; }
- uint GetDataSize() const override { return sizeof(iopMem->Main); }
+ uint GetDataSize() const override { return Ps2MemSize::ExposedIopRam; }
};
class SavestateEntry_HwRegs final : public MemorySavestateEntry
diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp
index 273088bbea..c9f01c143a 100644
--- a/pcsx2/VMManager.cpp
+++ b/pcsx2/VMManager.cpp
@@ -3328,7 +3328,7 @@ void VMManager::WarnAboutUnsafeSettings()
if (EmuConfig.Cpu.ExtraMemory)
{
append(ICON_PF_MICROCHIP,
- TRANSLATE_SV("VMManager", "128MB RAM is enabled. Compatibility with some games may be affected."));
+ TRANSLATE_SV("VMManager", "Extended RAM is enabled. Compatibility with some games may be affected."));
}
if (!EmuConfig.EnableGameFixes)
{
diff --git a/pcsx2/x86/iR3000A.cpp b/pcsx2/x86/iR3000A.cpp
index d157041106..ebe74d134b 100644
--- a/pcsx2/x86/iR3000A.cpp
+++ b/pcsx2/x86/iR3000A.cpp
@@ -841,36 +841,44 @@ void psxRecompileCodeConst3(R3000AFNPTR constcode, R3000AFNPTR_INFO constscode,
}
static u8* m_recBlockAlloc = NULL;
+static bool extraRam = false;
-static const uint m_recBlockAllocSize =
- (((Ps2MemSize::IopRam + Ps2MemSize::Rom + Ps2MemSize::Rom1 + Ps2MemSize::Rom2) / 4) * sizeof(BASEBLOCK));
-
-static void recReserve()
+static void recReserveRAM()
{
- recPtr = SysMemory::GetIOPRec();
- recPtrEnd = SysMemory::GetIOPRecEnd() - _64kb;
+ uint m_recBlockAllocSize =
+ (((Ps2MemSize::ExposedIopRam + Ps2MemSize::Rom + Ps2MemSize::Rom1 + Ps2MemSize::Rom2) / 4) * sizeof(BASEBLOCK));
// Goal: Allocate BASEBLOCKs for every possible branch target in IOP memory.
// Any 4-byte aligned address makes a valid branch target as per MIPS design (all instructions are
// always 4 bytes long).
- if (!m_recBlockAlloc)
+ if (m_recBlockAlloc)
{
- // We're on 64-bit, if these memory allocations fail, we're in real trouble.
- m_recBlockAlloc = (u8*)_aligned_malloc(m_recBlockAllocSize, 4096);
- if (!m_recBlockAlloc)
- pxFailRel("Failed to allocate R3000A BASEBLOCK lookup tables");
+ _aligned_free(m_recBlockAlloc);
}
+ // We're on 64-bit, if these memory allocations fail, we're in real trouble.
+ m_recBlockAlloc = (u8*)_aligned_malloc(m_recBlockAllocSize, 4096);
+ if (!m_recBlockAlloc)
+ pxFailRel("Failed to allocate R3000A BASEBLOCK lookup tables");
+
u8* curpos = m_recBlockAlloc;
recRAM = (BASEBLOCK*)curpos;
- curpos += (Ps2MemSize::IopRam / 4) * sizeof(BASEBLOCK);
+ curpos += (Ps2MemSize::ExposedIopRam / 4) * sizeof(BASEBLOCK);
recROM = (BASEBLOCK*)curpos;
curpos += (Ps2MemSize::Rom / 4) * sizeof(BASEBLOCK);
recROM1 = (BASEBLOCK*)curpos;
curpos += (Ps2MemSize::Rom1 / 4) * sizeof(BASEBLOCK);
recROM2 = (BASEBLOCK*)curpos;
curpos += (Ps2MemSize::Rom2 / 4) * sizeof(BASEBLOCK);
+}
+
+static void recReserve()
+{
+ recPtr = SysMemory::GetIOPRec();
+ recPtrEnd = SysMemory::GetIOPRecEnd() - _64kb;
+
+ recReserveRAM();
pxAssertRel(!s_pInstCache, "InstCache not allocated");
s_nInstCacheSize = 128;
@@ -883,12 +891,18 @@ void recResetIOP()
{
DevCon.WriteLn("iR3000A Recompiler reset.");
+ if (CHECK_EXTRAMEM != extraRam)
+ {
+ recReserveRAM();
+ extraRam = !extraRam;
+ }
+
xSetPtr(SysMemory::GetIOPRec());
_DynGen_Dispatchers();
recPtr = xGetPtr();
iopClearRecLUT((BASEBLOCK*)m_recBlockAlloc,
- (((Ps2MemSize::IopRam + Ps2MemSize::Rom + Ps2MemSize::Rom1 + Ps2MemSize::Rom2) / 4)));
+ (((Ps2MemSize::ExposedIopRam + Ps2MemSize::Rom + Ps2MemSize::Rom1 + Ps2MemSize::Rom2) / 4)));
for (int i = 0; i < 0x10000; i++)
recLUT_SetPage(psxRecLUT, 0, 0, 0, i, 0);
@@ -899,13 +913,15 @@ void recResetIOP()
// the pc indexer into it's lower common denominator.
// We're only mapping 20 pages here in 4 places.
- // 0x80 comes from : (Ps2MemSize::IopRam / 0x10000) * 4
+ // 0x80 comes from : (Ps2MemSize::IopRam / _64kb) * 4
for (int i = 0; i < 0x80; i++)
{
- recLUT_SetPage(psxRecLUT, psxhwLUT, recRAM, 0x0000, i, i & 0x1f);
- recLUT_SetPage(psxRecLUT, psxhwLUT, recRAM, 0x8000, i, i & 0x1f);
- recLUT_SetPage(psxRecLUT, psxhwLUT, recRAM, 0xa000, i, i & 0x1f);
+ u32 mask = (Ps2MemSize::ExposedIopRam / _64kb) - 1;
+
+ recLUT_SetPage(psxRecLUT, psxhwLUT, recRAM, 0x0000, i, i & mask);
+ recLUT_SetPage(psxRecLUT, psxhwLUT, recRAM, 0x8000, i, i & mask);
+ recLUT_SetPage(psxRecLUT, psxhwLUT, recRAM, 0xa000, i, i & mask);
}
for (int i = 0x1fc0; i < 0x2000; i++)
diff --git a/pcsx2/x86/iR3000Atables.cpp b/pcsx2/x86/iR3000Atables.cpp
index 47cadc61ce..3aea4070e0 100644
--- a/pcsx2/x86/iR3000Atables.cpp
+++ b/pcsx2/x86/iR3000Atables.cpp
@@ -1115,7 +1115,7 @@ static void rpsxLoad(int size, bool sign)
is_ram_read.SetTarget();
// read from psM directly
- xAND(arg1regd, 0x1fffff);
+ xAND(arg1regd, Ps2MemSize::ExposedIopRam - 1);
auto addr = xComplexAddress(rax, iopMem->Main, arg1reg);
switch (size)