Enable extension of IOP RAM to devkit spec (8MB)

This commit is contained in:
Ziemas 2025-12-09 14:04:32 +01:00
parent fe9915cbd0
commit a3ffe295cc
11 changed files with 53 additions and 30 deletions

View File

@ -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; <b>modifying this setting when a game is not having a visible problem will cause stability issues and/or crashes.</b>"));

View File

@ -176,7 +176,7 @@
<item row="3" column="0">
<widget class="QCheckBox" name="extraMemory">
<property name="text">
<string>Enable 128MB RAM (Dev Console)</string>
<string>Enable Extended RAM (Dev Console)</string>
</property>
</widget>
</item>

View File

@ -1039,7 +1039,7 @@ bool R3000DebugInterface::isValidAddress(u32 addr)
return true;
}
if (addr < 0x200000)
if (addr < Ps2MemSize::ExposedIopRam)
{
return true;
}

View File

@ -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.

View File

@ -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]

View File

@ -45,6 +45,7 @@ BIOS
namespace Ps2MemSize
{
u32 ExposedRam = MainRam;
u32 ExposedIopRam = IopRam;
} // namespace Ps2MemSize
namespace SysMemory
@ -305,6 +306,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() {

View File

@ -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)
};

View File

@ -536,7 +536,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

View File

@ -3276,7 +3276,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)
{

View File

@ -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++)

View File

@ -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)