Fix build error about undefined reference to `deinit_vita_mmap'
[pcsx_rearmed.git] / frontend / libretro.c
index 5bf737f..2efccfa 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
+#ifdef __MACH__
+#include <unistd.h>
+#include <sys/syscall.h>
+#endif
 
 #include "../libpcsxcore/misc.h"
 #include "../libpcsxcore/psxcounters.h"
@@ -256,6 +260,87 @@ void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
 }
 #endif
 
+#ifdef VITA
+typedef struct
+{
+   void* buffer;
+   uint32_t target_map;
+   size_t size;
+   enum psxMapTag tag;
+}psx_map_t;
+
+void* addr = NULL;
+
+psx_map_t custom_psx_maps[] = {
+   {NULL, NULL, 0x210000, MAP_TAG_RAM},   // 0x80000000
+   {NULL, NULL, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
+   {NULL, NULL, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
+   {NULL, NULL, 0x800000, MAP_TAG_LUTS},  // 0x08000000
+   {NULL, NULL, 0x200000, MAP_TAG_VRAM},  // 0x00000000
+};
+
+int init_vita_mmap(){
+  int n;
+  addr = malloc(64*1024*1024);
+  if(addr==NULL)
+    return -1;
+  addr = ((u32)(addr+0xFFFFFF))&~0xFFFFFF;
+  custom_psx_maps[0].buffer=addr+0x2000000;
+  custom_psx_maps[1].buffer=addr+0x1800000;
+  custom_psx_maps[2].buffer=addr+0x1c00000;
+  custom_psx_maps[3].buffer=addr+0x0000000;
+  custom_psx_maps[4].buffer=addr+0x1000000;
+#if 0
+  for(n = 0; n < 5; n++){
+    sceClibPrintf("addr reserved %x\n",custom_psx_maps[n].buffer);
+  }
+#endif
+  return 0;
+}
+
+void deinit_vita_mmap(){
+  free(addr);
+}
+
+void* pl_vita_mmap(unsigned long addr, size_t size, int is_fixed,
+       enum psxMapTag tag)
+{
+   (void)is_fixed;
+   (void)addr;
+
+
+    psx_map_t* custom_map = custom_psx_maps;
+
+    for (; custom_map->size; custom_map++)
+    {
+       if ((custom_map->size == size) && (custom_map->tag == tag))
+       {
+          return custom_map->buffer;
+       }
+    }
+
+
+   return malloc(size);
+}
+
+void pl_vita_munmap(void *ptr, size_t size, enum psxMapTag tag)
+{
+   (void)tag;
+
+   psx_map_t* custom_map = custom_psx_maps;
+
+  for (; custom_map->size; custom_map++)
+  {
+     if ((custom_map->buffer == ptr))
+     {
+        return;
+     }
+  }
+
+   free(ptr);
+}
+#endif
+
 static void *pl_mmap(unsigned int size)
 {
        return psxMap(0, size, 0, MAP_TAG_VRAM);
@@ -1471,16 +1556,29 @@ void retro_init(void)
        int i, ret;
        bool found_bios = false;
 
+#ifdef __MACH__
+       // magic sauce to make the dynarec work on iOS
+       syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0);
+#endif
+
 #ifdef _3DS
    psxMapHook = pl_3ds_mmap;
    psxUnmapHook = pl_3ds_munmap;
+#endif
+#ifdef VITA
+   if(init_vita_mmap()<0)
+      abort();
+   psxMapHook = pl_vita_mmap;
+   psxUnmapHook = pl_vita_munmap;
 #endif
        ret = emu_core_preinit();
-#ifdef _3DS
+#ifdef _3DS 
    /* emu_core_preinit sets the cpu to dynarec */
    if(!__ctr_svchax)
       Config.Cpu = CPU_INTERPRETER;
 #endif
+  Config.Cpu = CPU_INTERPRETER;
+
        ret |= emu_core_init();
        if (ret != 0) {
                SysPrintf("PCSX init failed.\n");
@@ -1560,6 +1658,10 @@ void retro_deinit(void)
        free(vout_buf);
 #endif
        vout_buf = NULL;
+
+#ifdef VITA
+  deinit_vita_mmap();
+#endif
 }
 
 #ifdef VITA