From 479d58cf907d87d12c2ab6cf9acc17f88ef2eeec Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 11 May 2022 16:31:05 +0100 Subject: [PATCH] psxmem: Add support for Lightrec's custom mem init sequence Adapt the current psxmem.c code to support Lightrec's custom memory init functions. Signed-off-by: Paul Cercueil --- libpcsxcore/lightrec/plugin.c | 6 ++++++ libpcsxcore/psxmem.c | 38 +++++++++++++++++++++++++++++------ libpcsxcore/r3000a.c | 3 ++- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/libpcsxcore/lightrec/plugin.c b/libpcsxcore/lightrec/plugin.c index fe99e73d..4b28c566 100644 --- a/libpcsxcore/lightrec/plugin.c +++ b/libpcsxcore/lightrec/plugin.c @@ -311,6 +311,12 @@ static int lightrec_plugin_init(void) lightrec_map[PSX_MAP_SCRATCH_PAD].address = psxH; lightrec_map[PSX_MAP_PARALLEL_PORT].address = psxP; + if (LIGHTREC_CUSTOM_MAP) { + lightrec_map[PSX_MAP_MIRROR1].address = psxM + 0x200000; + lightrec_map[PSX_MAP_MIRROR2].address = psxM + 0x400000; + lightrec_map[PSX_MAP_MIRROR3].address = psxM + 0x600000; + } + lightrec_debug = !!getenv("LIGHTREC_DEBUG"); lightrec_very_debug = !!getenv("LIGHTREC_VERY_DEBUG"); use_lightrec_interpreter = !!getenv("LIGHTREC_INTERPRETER"); diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c index ffa0dd70..1f7aa8cd 100644 --- a/libpcsxcore/psxmem.c +++ b/libpcsxcore/psxmem.c @@ -29,6 +29,7 @@ #include "psxhw.h" #include "debug.h" +#include "lightrec/mem.h" #include "memmap.h" #ifdef USE_LIBRETRO_VFS @@ -139,9 +140,8 @@ u8 **psxMemRLUT = NULL; 0xbfc0_0000-0xbfc7_ffff BIOS Mirror (512K) Uncached */ -int psxMemInit() { - int i; - +static int psxMemInitMap(void) +{ psxM = psxMap(0x80000000, 0x00210000, 1, MAP_TAG_RAM); if (psxM == MAP_FAILED) psxM = psxMap(0x77000000, 0x00210000, 0, MAP_TAG_RAM); @@ -160,6 +160,31 @@ int psxMemInit() { return -1; } + return 0; +} + +static void psxMemFreeMap(void) +{ + psxUnmap(psxM, 0x00210000, MAP_TAG_RAM); psxM = NULL; + psxUnmap(psxH, 0x10000, MAP_TAG_OTHER); psxH = NULL; + psxUnmap(psxR, 0x80000, MAP_TAG_OTHER); psxR = NULL; +} + +int psxMemInit(void) +{ + unsigned int i; + int ret; + + if (LIGHTREC_CUSTOM_MAP && Config.Cpu == CPU_DYNAREC) + ret = lightrec_init_mmap(); + else + ret = psxMemInitMap(); + if (ret) { + SysMessage(_("Error allocating memory!")); + psxMemShutdown(); + return -1; + } + psxMemRLUT = (u8 **)malloc(0x10000 * sizeof(void *)); psxMemWLUT = (u8 **)malloc(0x10000 * sizeof(void *)); @@ -230,9 +255,10 @@ void psxMemReset() { } void psxMemShutdown() { - psxUnmap(psxM, 0x00210000, MAP_TAG_RAM); psxM = NULL; - psxUnmap(psxH, 0x10000, MAP_TAG_OTHER); psxH = NULL; - psxUnmap(psxR, 0x80000, MAP_TAG_OTHER); psxR = NULL; + if (LIGHTREC_CUSTOM_MAP && Config.Cpu == CPU_DYNAREC) + lightrec_free_mmap(); + else + psxMemFreeMap(); free(psxMemRLUT); psxMemRLUT = NULL; free(psxMemWLUT); psxMemWLUT = NULL; diff --git a/libpcsxcore/r3000a.c b/libpcsxcore/r3000a.c index 3a7c3581..57ae830e 100644 --- a/libpcsxcore/r3000a.c +++ b/libpcsxcore/r3000a.c @@ -76,10 +76,11 @@ void psxReset() { } void psxShutdown() { - psxMemShutdown(); psxBiosShutdown(); psxCpu->Shutdown(); + + psxMemShutdown(); } void psxException(u32 code, u32 bd) { -- 2.39.5