From 6794bbbd6a301ff560fa4e0abe56fd05239dc844 Mon Sep 17 00:00:00 2001 From: kozarovv <15552250+kozarovv@users.noreply.github.com> Date: Sat, 8 Aug 2020 21:59:46 +0200 Subject: [PATCH] Add rom2: support (Fix Chinese Bios) (#3439) * Add rom2 support * Add rom2 support on IOP * Valid memory range for rom2 * Add rom2 support to IopMem.cpp --- pcsx2/IopMem.cpp | 5 +++++ pcsx2/Memory.h | 16 ++++++++-------- pcsx2/x86/iR3000A.cpp | 14 ++++++++++++-- pcsx2/x86/ix86-32/iR5900-32.cpp | 13 +++++++++++-- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/pcsx2/IopMem.cpp b/pcsx2/IopMem.cpp index 8672ab8578..e45990c0fa 100644 --- a/pcsx2/IopMem.cpp +++ b/pcsx2/IopMem.cpp @@ -96,6 +96,11 @@ void iopMemoryReserve::Reset() psxMemWLUT[i + 0x2000 + 0x1e00] = (uptr)&eeMem->ROM1[i << 16]; } + for (int i = 0; i < 0x0008; i++) + { + psxMemWLUT[i + 0x2000 + 0x1e40] = (uptr)&eeMem->ROM2[i << 16]; + } + // sif!! (which is read only? (air)) psxMemWLUT[0x2000 + 0x1d00] = (uptr)iopMem->Sif; //psxMemWLUT[0x1bd00] = (uptr)iopMem->Sif; diff --git a/pcsx2/Memory.h b/pcsx2/Memory.h index 94879ac7fc..bb1487ff32 100644 --- a/pcsx2/Memory.h +++ b/pcsx2/Memory.h @@ -81,14 +81,14 @@ static __fi void ZeroQWC( u128& dest ) #define psR1u32(mem) (*(u32*)&eeMem->ROM1[(mem) & 0x3ffff]) #define psR1u64(mem) (*(u64*)&eeMem->ROM1[(mem) & 0x3ffff]) -#define psR2s8(mem) (*(s8 *)&eeMem->ROM2[(mem) & 0x3ffff]) -#define psR2s16(mem) (*(s16*)&eeMem->ROM2[(mem) & 0x3ffff]) -#define psR2s32(mem) (*(s32*)&eeMem->ROM2[(mem) & 0x3ffff]) -#define psR2s64(mem) (*(s64*)&eeMem->ROM2[(mem) & 0x3ffff]) -#define psR2u8(mem) (*(u8 *)&eeMem->ROM2[(mem) & 0x3ffff]) -#define psR2u16(mem) (*(u16*)&eeMem->ROM2[(mem) & 0x3ffff]) -#define psR2u32(mem) (*(u32*)&eeMem->ROM2[(mem) & 0x3ffff]) -#define psR2u64(mem) (*(u64*)&eeMem->ROM2[(mem) & 0x3ffff]) +#define psR2s8(mem) (*(s8 *)&eeMem->ROM2[(mem) & 0x7ffff]) +#define psR2s16(mem) (*(s16*)&eeMem->ROM2[(mem) & 0x7ffff]) +#define psR2s32(mem) (*(s32*)&eeMem->ROM2[(mem) & 0x7ffff]) +#define psR2s64(mem) (*(s64*)&eeMem->ROM2[(mem) & 0x7ffff]) +#define psR2u8(mem) (*(u8 *)&eeMem->ROM2[(mem) & 0x7ffff]) +#define psR2u16(mem) (*(u16*)&eeMem->ROM2[(mem) & 0x7ffff]) +#define psR2u32(mem) (*(u32*)&eeMem->ROM2[(mem) & 0x7ffff]) +#define psR2u64(mem) (*(u64*)&eeMem->ROM2[(mem) & 0x7ffff]) #define psERs8(mem) (*(s8 *)&eeMem->EROM[(mem) & 0x3ffff]) #define psERs16(mem) (*(s16*)&eeMem->EROM[(mem) & 0x3ffff]) diff --git a/pcsx2/x86/iR3000A.cpp b/pcsx2/x86/iR3000A.cpp index 607f66cfe5..433585100b 100644 --- a/pcsx2/x86/iR3000A.cpp +++ b/pcsx2/x86/iR3000A.cpp @@ -55,6 +55,7 @@ static RecompiledCodeReserve* recMem = NULL; static BASEBLOCK *recRAM = NULL; // and the ptr to the blocks here static BASEBLOCK *recROM = NULL; // and here static BASEBLOCK *recROM1 = NULL; // also here +static BASEBLOCK *recROM2 = NULL; // also here static BaseBlocks recBlocks; static u8 *recPtr = NULL; u32 psxpc; // recompiler psxpc @@ -622,7 +623,7 @@ static uptr m_ConfiguredCacheReserve = 32; static u8* m_recBlockAlloc = NULL; static const uint m_recBlockAllocSize = - (((Ps2MemSize::IopRam + Ps2MemSize::Rom + Ps2MemSize::Rom1) / 4) * sizeof(BASEBLOCK)); + (((Ps2MemSize::IopRam + Ps2MemSize::Rom + Ps2MemSize::Rom1 + Ps2MemSize::Rom2) / 4) * sizeof(BASEBLOCK)); static void recReserveCache() { @@ -664,6 +665,8 @@ static void recAlloc() recRAM = (BASEBLOCK*)curpos; curpos += (Ps2MemSize::IopRam / 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); + if( s_pInstCache == NULL ) { @@ -687,7 +690,7 @@ void recResetIOP() recMem->Reset(); iopClearRecLUT((BASEBLOCK*)m_recBlockAlloc, - (((Ps2MemSize::IopRam + Ps2MemSize::Rom + Ps2MemSize::Rom1) / 4))); + (((Ps2MemSize::IopRam + Ps2MemSize::Rom + Ps2MemSize::Rom1 + Ps2MemSize::Rom2) / 4))); for (int i = 0; i < 0x10000; i++) recLUT_SetPage(psxRecLUT, 0, 0, 0, i, 0); @@ -721,6 +724,13 @@ void recResetIOP() recLUT_SetPage(psxRecLUT, psxhwLUT, recROM1, 0xa000, i, i - 0x1fc0); } + for (int i = 0x1e40; i < 0x1e48; i++) + { + recLUT_SetPage(psxRecLUT, psxhwLUT, recROM2, 0x0000, i, i - 0x1fc0); + recLUT_SetPage(psxRecLUT, psxhwLUT, recROM2, 0x8000, i, i - 0x1fc0); + recLUT_SetPage(psxRecLUT, psxhwLUT, recROM2, 0xa000, i, i - 0x1fc0); + } + if( s_pInstCache ) memset( s_pInstCache, 0, sizeof(EEINST)*s_nInstCacheSize ); diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index 222168c6c1..fa10bbadf3 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -75,7 +75,7 @@ static const int RECCONSTBUF_SIZE = 16384 * 2; // 64 bit consts in 32 bit units static RecompiledCodeReserve* recMem = NULL; static u8* recRAMCopy = NULL; static u8* recLutReserve_RAM = NULL; -static const size_t recLutSize = Ps2MemSize::MainRam + Ps2MemSize::Rom + Ps2MemSize::Rom1; +static const size_t recLutSize = Ps2MemSize::MainRam + Ps2MemSize::Rom + Ps2MemSize::Rom1 + Ps2MemSize::Rom2; static uptr m_ConfiguredCacheReserve = 64; @@ -83,6 +83,7 @@ static u32* recConstBuf = NULL; // 64-bit pseudo-immediates static BASEBLOCK *recRAM = NULL; // and the ptr to the blocks here static BASEBLOCK *recROM = NULL; // and here static BASEBLOCK *recROM1 = NULL; // also here +static BASEBLOCK *recROM2 = NULL; // also here static BaseBlocks recBlocks; static u8* recPtr = NULL; @@ -515,6 +516,7 @@ static void recAlloc() recRAM = basepos; basepos += (Ps2MemSize::MainRam / 4); recROM = basepos; basepos += (Ps2MemSize::Rom / 4); recROM1 = basepos; basepos += (Ps2MemSize::Rom1 / 4); + recROM2 = basepos; basepos += (Ps2MemSize::Rom2 / 4); for (int i = 0; i < 0x10000; i++) recLUT_SetPage(recLUT, 0, 0, 0, i, 0); @@ -545,6 +547,13 @@ static void recAlloc() recLUT_SetPage(recLUT, hwLUT, recROM1, 0xa000, i, i - 0x1e00); } + for (int i = 0x1e40; i < 0x1e48; i++) + { + recLUT_SetPage(recLUT, hwLUT, recROM2, 0x0000, i, i - 0x1e40); + recLUT_SetPage(recLUT, hwLUT, recROM2, 0x8000, i, i - 0x1e40); + recLUT_SetPage(recLUT, hwLUT, recROM2, 0xa000, i, i - 0x1e40); + } + if( recConstBuf == NULL ) recConstBuf = (u32*) _aligned_malloc( RECCONSTBUF_SIZE * sizeof(*recConstBuf), 16 ); @@ -620,7 +629,7 @@ static void recShutdown() recBlocks.Reset(); - recRAM = recROM = recROM1 = NULL; + recRAM = recROM = recROM1 = recROM2 = NULL; safe_aligned_free( recConstBuf ); safe_free( s_pInstCache );