X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fpsxmem.c;h=a85fb27d3773d3c6c96b6e08655c8dbdb028c5da;hb=ee8fd5674f74f307878f2dabef7641a837fb2a99;hp=ffa0dd70d29212d0d5eba04bbc6da880c27e91be;hpb=b012a437739802ba3f35827b17469ea7a8b7953c;p=pcsx_rearmed.git diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c index ffa0dd70..a85fb27d 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 @@ -41,7 +42,7 @@ boolean writeok = TRUE; -#ifndef NDEBUG +#if 0 //ndef NDEBUG #include "debug.h" #else void DebugCheckBP(u32 address, enum breakpoint_types type) {} @@ -70,13 +71,13 @@ retry: /* if (is_fixed) flags |= MAP_FIXED; */ - req = (void *)addr; + req = (void *)(uintptr_t)addr; ret = mmap(req, size, PROT_READ | PROT_WRITE, flags, -1, 0); if (ret == MAP_FAILED) return ret; } - if (addr != 0 && ret != (void *)addr) { + if (addr != 0 && ret != (void *)(uintptr_t)addr) { SysMessage("psxMap: warning: wanted to map @%08x, got %p\n", addr, ret); @@ -85,14 +86,14 @@ retry: return MAP_FAILED; } - if (((addr ^ (unsigned long)ret) & ~0xff000000l) && try_ < 2) + if (((addr ^ (unsigned long)(uintptr_t)ret) & ~0xff000000l) && try_ < 2) { psxUnmap(ret, size, tag); // try to use similarly aligned memory instead // (recompiler needs this) mask = try_ ? 0xffff : 0xffffff; - addr = ((unsigned long)ret + mask) & ~mask; + addr = ((uintptr_t)ret + mask) & ~mask; try_++; goto retry; } @@ -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) + 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) + lightrec_free_mmap(); + else + psxMemFreeMap(); free(psxMemRLUT); psxMemRLUT = NULL; free(psxMemWLUT); psxMemWLUT = NULL;