psxmem: Add support for Lightrec's custom mem init sequence
authorPaul Cercueil <paul@crapouillou.net>
Wed, 11 May 2022 15:31:05 +0000 (16:31 +0100)
committerPaul Cercueil <paul@crapouillou.net>
Mon, 30 May 2022 05:34:36 +0000 (06:34 +0100)
Adapt the current psxmem.c code to support Lightrec's custom memory
init functions.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
libpcsxcore/lightrec/plugin.c
libpcsxcore/psxmem.c
libpcsxcore/r3000a.c

index fe99e73..4b28c56 100644 (file)
@@ -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");
index ffa0dd7..1f7aa8c 100644 (file)
@@ -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;
index 3a7c358..57ae830 100644 (file)
@@ -76,10 +76,11 @@ void psxReset() {
 }
 
 void psxShutdown() {
-       psxMemShutdown();
        psxBiosShutdown();
 
        psxCpu->Shutdown();
+
+       psxMemShutdown();
 }
 
 void psxException(u32 code, u32 bd) {