psxmem: use rounding that's more likely to work
authornotaz <notasas@gmail.com>
Sun, 28 Feb 2016 21:36:59 +0000 (23:36 +0200)
committernotaz <notasas@gmail.com>
Sun, 28 Feb 2016 21:36:59 +0000 (23:36 +0200)
libpcsxcore/psxmem.c

index 6277220..14fd911 100644 (file)
@@ -43,7 +43,7 @@ void *psxMap(unsigned long addr, size_t size, int is_fixed,
                enum psxMapTag tag)
 {
        int flags = MAP_PRIVATE | MAP_ANONYMOUS;
-       int tried_to_align = 0;
+       int try_ = 0;
        unsigned long mask;
        void *req, *ret;
 
@@ -73,15 +73,15 @@ retry:
                        return NULL;
                }
 
-               if (((addr ^ (long)ret) & 0x00ffffff) && !tried_to_align)
+               if (((addr ^ (unsigned long)ret) & ~0xff000000l) && try_ < 2)
                {
                        psxUnmap(ret, size, tag);
 
                        // try to use similarly aligned memory instead
                        // (recompiler needs this)
-                       mask = (addr - 1) & ~addr & 0x07ffffff;
-                       addr = (unsigned long)(ret + mask) & ~mask;
-                       tried_to_align = 1;
+                       mask = try_ ? 0xffff : 0xffffff;
+                       addr = ((unsigned long)ret + mask) & ~mask;
+                       try_++;
                        goto retry;
                }
        }
@@ -137,13 +137,8 @@ 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"));