From 1a5fd79401ac52789fad34c6b852b947200a6334 Mon Sep 17 00:00:00 2001 From: frangarcj Date: Tue, 6 Sep 2016 13:49:55 +0200 Subject: (VITA) Some dynarec --- frontend/libretro.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'frontend/libretro.c') diff --git a/frontend/libretro.c b/frontend/libretro.c index 5bf737f..75f9b98 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -256,6 +256,85 @@ 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; + +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 +}; + +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)) + { + int block, ret; + char blockname[32]; + sprintf(blockname, "CODE 0x%08X",tag); + + block = sceKernelAllocMemBlockForVM(blockname, size); + if(block<=0){ + sceClibPrintf("could not alloc mem block @0x%08X 0x%08X \n", block, tag); + exit(1); + } + + // get base address + ret = sceKernelGetMemBlockBase(block, &custom_map->buffer); + if (ret < 0) + { + sceClibPrintf("could get address @0x%08X 0x%08X 0x%08X \n", block, ret, tag); + exit(1); + } + + custom_map->target_map = block; + + 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)) + { + sceKernelFreeMemBlock(custom_map->target_map); + custom_map->buffer = NULL; + custom_map->target_map = NULL; + return; + } + } + + free(ptr); +} +#endif + static void *pl_mmap(unsigned int size) { return psxMap(0, size, 0, MAP_TAG_VRAM); @@ -1474,6 +1553,10 @@ void retro_init(void) #ifdef _3DS psxMapHook = pl_3ds_mmap; psxUnmapHook = pl_3ds_munmap; +#endif +#ifdef VITA + psxMapHook = pl_vita_mmap; + psxUnmapHook = pl_vita_munmap; #endif ret = emu_core_preinit(); #ifdef _3DS -- cgit v1.2.3 From 9facb65b76d846175f3ef9fbeafd1c590a0e0630 Mon Sep 17 00:00:00 2001 From: frangarcj Date: Tue, 6 Sep 2016 17:50:57 +0200 Subject: (VITA) I think that is not VM Memory and do some alignment --- frontend/libretro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'frontend/libretro.c') diff --git a/frontend/libretro.c b/frontend/libretro.c index 75f9b98..444719a 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -290,7 +290,7 @@ void* pl_vita_mmap(unsigned long addr, size_t size, int is_fixed, char blockname[32]; sprintf(blockname, "CODE 0x%08X",tag); - block = sceKernelAllocMemBlockForVM(blockname, size); + block = sceKernelAllocMemBlock(blockname, size + 0x1000); if(block<=0){ sceClibPrintf("could not alloc mem block @0x%08X 0x%08X \n", block, tag); exit(1); @@ -303,7 +303,7 @@ void* pl_vita_mmap(unsigned long addr, size_t size, int is_fixed, sceClibPrintf("could get address @0x%08X 0x%08X 0x%08X \n", block, ret, tag); exit(1); } - + custom_map->buffer = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF; custom_map->target_map = block; return custom_map->buffer; -- cgit v1.2.3