X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=libpcsxcore%2Fpsxmem.c;h=86da68ce693e86654ea425c86f2e5865e4efd703;hp=9e4426755f9cca01dd92e788e70f9c279e9b1c0d;hb=bdd050c3ed792381df2e744fee5b7ee80b93fd68;hpb=b0dd9956467322aca812db75b5e0f11f23c1910b diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c index 9e442675..86da68ce 100644 --- a/libpcsxcore/psxmem.c +++ b/libpcsxcore/psxmem.c @@ -28,7 +28,8 @@ #include "r3000a.h" #include "psxhw.h" #include "debug.h" -#include + +#include "memmap.h" #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON @@ -52,8 +53,9 @@ retry: goto out; } - if (is_fixed) - flags |= MAP_FIXED; + /* avoid MAP_FIXED, it overrides existing mappings.. */ + /* if (is_fixed) + flags |= MAP_FIXED; */ req = (void *)addr; ret = mmap(req, size, PROT_READ | PROT_WRITE, flags, -1, 0); @@ -65,6 +67,11 @@ out: SysMessage("psxMap: warning: wanted to map @%08x, got %p\n", addr, ret); + if (is_fixed) { + psxUnmap(ret, size, tag); + return NULL; + } + if (ret != NULL && ((addr ^ (long)ret) & 0x00ffffff) && !tried_to_align) { @@ -89,7 +96,8 @@ void psxUnmap(void *ptr, size_t size, enum psxMapTag tag) return; } - munmap(ptr, size); + if (ptr) + munmap(ptr, size); } s8 *psxM = NULL; // Kernel & User Memory (2 Meg) @@ -129,8 +137,13 @@ int psxMemInit() { psxM = psxMap(0x80000000, 0x00210000, 1, MAP_TAG_RAM); #ifndef RAM_FIXED +#ifdef __BLACKBERRY_QNX__ + if (psxM == NULL) + psxM = psxMap(0x77000000, 0x00210000, 0, MAP_TAG_RAM); +#else if (psxM == NULL) psxM = psxMap(0x78000000, 0x00210000, 0, MAP_TAG_RAM); +#endif #endif if (psxM == NULL) { SysMessage(_("mapping main RAM failed")); @@ -138,12 +151,13 @@ int psxMemInit() { } psxP = &psxM[0x200000]; - psxH = psxMap(0x1f800000, 0x10000, 1, MAP_TAG_OTHER); + psxH = psxMap(0x1f800000, 0x10000, 0, MAP_TAG_OTHER); psxR = psxMap(0x1fc00000, 0x80000, 0, MAP_TAG_OTHER); if (psxMemRLUT == NULL || psxMemWLUT == NULL || - psxR == NULL || psxP == NULL || psxH != (void *)0x1f800000) { + psxR == NULL || psxP == NULL || psxH == NULL) { SysMessage(_("Error allocating memory!")); + psxMemShutdown(); return -1; } @@ -197,12 +211,12 @@ void psxMemReset() { } void psxMemShutdown() { - psxUnmap(psxM, 0x00210000, MAP_TAG_RAM); - psxUnmap(psxH, 0x1f800000, MAP_TAG_OTHER); - psxUnmap(psxR, 0x80000, MAP_TAG_OTHER); + psxUnmap(psxM, 0x00210000, MAP_TAG_RAM); psxM = NULL; + psxUnmap(psxH, 0x10000, MAP_TAG_OTHER); psxH = NULL; + psxUnmap(psxR, 0x80000, MAP_TAG_OTHER); psxR = NULL; - free(psxMemRLUT); - free(psxMemWLUT); + free(psxMemRLUT); psxMemRLUT = NULL; + free(psxMemWLUT); psxMemWLUT = NULL; } static int writeok = 1; @@ -212,8 +226,8 @@ u8 psxMemRead8(u32 mem) { u32 t; t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) + if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { + if ((mem & 0xffff) < 0x400) return psxHu8(mem); else return psxHwRead8(mem); @@ -237,8 +251,8 @@ u16 psxMemRead16(u32 mem) { u32 t; t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) + if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { + if ((mem & 0xffff) < 0x400) return psxHu16(mem); else return psxHwRead16(mem); @@ -262,8 +276,8 @@ u32 psxMemRead32(u32 mem) { u32 t; t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) + if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { + if ((mem & 0xffff) < 0x400) return psxHu32(mem); else return psxHwRead32(mem); @@ -287,8 +301,8 @@ void psxMemWrite8(u32 mem, u8 value) { u32 t; t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) + if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { + if ((mem & 0xffff) < 0x400) psxHu8(mem) = value; else psxHwWrite8(mem, value); @@ -314,8 +328,8 @@ void psxMemWrite16(u32 mem, u16 value) { u32 t; t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) + if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { + if ((mem & 0xffff) < 0x400) psxHu16ref(mem) = SWAPu16(value); else psxHwWrite16(mem, value); @@ -342,8 +356,8 @@ void psxMemWrite32(u32 mem, u32 value) { // if ((mem&0x1fffff) == 0x71E18 || value == 0x48088800) SysPrintf("t2fix!!\n"); t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) + if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { + if ((mem & 0xffff) < 0x400) psxHu32ref(mem) = SWAPu32(value); else psxHwWrite32(mem, value); @@ -400,8 +414,8 @@ void *psxMemPointer(u32 mem) { u32 t; t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) + if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { + if ((mem & 0xffff) < 0x400) return (void *)&psxH[mem]; else return NULL;