{ NULL, 0x12800000, 0x010000, MAP_TAG_OTHER }, // 0x1f800000
{ NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER }, // 0x1fc00000
{ NULL, 0x11000000, 0x800000, MAP_TAG_LUTS }, // 0x08000000
- { NULL, 0x12000000, 0x200000, MAP_TAG_VRAM }, // 0x00000000
+ { NULL, 0x12000000, 0x201000, MAP_TAG_VRAM }, // 0x00000000
};
void *pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed,
typedef struct
{
void *buffer;
- uint32_t target_map;
size_t size;
enum psxMapTag tag;
+ int used;
} psx_map_t;
-void *addr = NULL;
+static 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
+ { NULL, 0x800000, MAP_TAG_LUTS },
+ { NULL, 0x080000, MAP_TAG_OTHER },
+ { NULL, 0x010000, MAP_TAG_OTHER },
+ { NULL, 0x201000, MAP_TAG_VRAM },
+ { NULL, 0x802000, MAP_TAG_VRAM }, // enhanced renderer
+ { NULL, 0x210000, MAP_TAG_RAM },
};
int init_vita_mmap()
addr = malloc(64 * 1024 * 1024);
if (addr == NULL)
return -1;
- tmpaddr = ((u32)(addr + 0xFFFFFF)) & ~0xFFFFFF;
- custom_psx_maps[0].buffer = tmpaddr + 0x2000000;
- custom_psx_maps[1].buffer = tmpaddr + 0x1800000;
- custom_psx_maps[2].buffer = tmpaddr + 0x1c00000;
- custom_psx_maps[3].buffer = tmpaddr + 0x0000000;
+ tmpaddr = (void *)(((size_t)addr + 0xFFFFFF) & ~0xFFFFFF);
+ custom_psx_maps[0].buffer = tmpaddr + 0x0000000;
+ custom_psx_maps[1].buffer = tmpaddr + 0x0800000;
+ custom_psx_maps[2].buffer = tmpaddr + 0x0880000;
+ custom_psx_maps[3].buffer = tmpaddr + 0x0900000;
custom_psx_maps[4].buffer = tmpaddr + 0x1000000;
+ custom_psx_maps[5].buffer = tmpaddr + 0x2000000;
#if 0
for(n = 0; n < 5; n++){
sceClibPrintf("addr reserved %x\n",custom_psx_maps[n].buffer);
void deinit_vita_mmap()
{
+ size_t i;
+ for (i = 0; i < sizeof(custom_psx_maps) / sizeof(custom_psx_maps[0]); i++) {
+ custom_psx_maps[i].buffer = NULL;
+ custom_psx_maps[i].used = 0;
+ }
free(addr);
}
for (; custom_map->size; custom_map++)
{
- if ((custom_map->size == size) && (custom_map->tag == tag))
+ if (custom_map->size == size && custom_map->tag == tag && !custom_map->used)
{
+ custom_map->used = 1;
return custom_map->buffer;
}
}
{
if ((custom_map->buffer == ptr))
{
+ custom_map->used = 0;
return;
}
}
}
}
-// double, for overdraw guard
-#define VRAM_SIZE ((1024 * 512 * 2 * 2) + 4096)
+#ifndef max
+#define max(a, b) (((a) > (b)) ? (a) : (b))
+#endif
// Minimum 16-byte VRAM alignment needed by gpu_unai's pixel-skipping
// renderer/downscaler it uses in high res modes:
#define VRAM_ALIGN 16
#endif
+// double, for overdraw guard + at least 1 page before
+#define VRAM_SIZE ((1024 * 512 * 2 * 2) + max(VRAM_ALIGN, 4096))
+
// vram ptr received from mmap/malloc/alloc (will deallocate using this)
static uint16_t *vram_ptr_orig = NULL;
static int map_vram(void)
{
#if GPULIB_USE_MMAP
- gpu.vram = vram_ptr_orig = gpu.mmap(VRAM_SIZE + (VRAM_ALIGN-1));
+ gpu.vram = vram_ptr_orig = gpu.mmap(VRAM_SIZE);
#else
- gpu.vram = vram_ptr_orig = calloc(VRAM_SIZE + (VRAM_ALIGN-1), 1);
+ gpu.vram = vram_ptr_orig = calloc(VRAM_SIZE, 1);
#endif
if (gpu.vram != NULL && gpu.vram != (void *)(intptr_t)-1) {
// 4kb guard in front