X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=frontend%2Flibretro.c;h=29645875e8e31a066735194fb7cd46637d72e1c5;hb=0b7f536b486f3f411651573009c3da6063b560ea;hp=74b5dbff24d2cf120f0dcd877aaab8da8c1a43fb;hpb=d71c709541218f67ab32229b03307b045a8ed6cb;p=pcsx_rearmed.git diff --git a/frontend/libretro.c b/frontend/libretro.c index 74b5dbff..29645875 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -1,5 +1,5 @@ /* - * (C) notaz, 2012 + * (C) notaz, 2012,2014,2015 * * This work is licensed under the terms of the GNU GPLv2 or later. * See the COPYING file in the top-level directory. @@ -28,6 +28,12 @@ #include "revision.h" #include "libretro.h" +#ifdef _3DS +#include "3ds.h" +#include "3ds/3ds_utils.h" +int ctr_svchack_init_success = 0; +#endif + static retro_video_refresh_t video_cb; static retro_input_poll_t input_poll_cb; static retro_input_state_t input_state_cb; @@ -51,6 +57,7 @@ extern char McdDisable[2]; /* PCSX ReARMed core calls and stuff */ int in_type1, in_type2; int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 }; +int in_a3[2] = { 127, 127 }, in_a4[2] = { 127, 127 }; int in_keystate; int in_enable_vibration = 1; @@ -164,8 +171,87 @@ static void vout_close(void) { } -static void *pl_mmap(unsigned int size) +#ifdef _3DS +typedef struct +{ + void* buffer; + uint32_t target_map; + size_t size; + enum psxMapTag tag; +}psx_map_t; + +psx_map_t custom_psx_maps[] = { + {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000 + {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 +}; + +void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed, + enum psxMapTag tag) +{ + (void)is_fixed; + (void)addr; + + if (ctr_svchack_init_success) + { + psx_map_t* custom_map = custom_psx_maps; + + for (; custom_map->size; custom_map++) + { + if ((custom_map->size == size) && (custom_map->tag == tag)) + { + uint32_t ptr_aligned, tmp; + + custom_map->buffer = malloc(size + 0x1000); + ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF; + + if(svcControlMemory(&tmp, custom_map->target_map, ptr_aligned, size, MEMOP_MAP, 0x3) < 0) + { + SysPrintf("could not map memory @0x%08X\n", custom_map->target_map); + exit(1); + } + + return (void*)custom_map->target_map; + } + } + } + + return malloc(size); +} + +void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag) { + (void)tag; + + if (ctr_svchack_init_success) + { + psx_map_t* custom_map = custom_psx_maps; + + for (; custom_map->size; custom_map++) + { + if ((custom_map->target_map == (uint32_t)ptr)) + { + uint32_t ptr_aligned, tmp; + + ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF; + + svcControlMemory(&tmp, custom_map->target_map, ptr_aligned, size, MEMOP_UNMAP, 0x3); + + free(custom_map->buffer); + custom_map->buffer = NULL; + return; + } + } + } + + free(ptr); +} +#endif + +static void *pl_mmap(unsigned int size) +{ return psxMap(0, size, 0, MAP_TAG_VRAM); } @@ -256,6 +342,8 @@ void retro_set_environment(retro_environment_t cb) { "pcsx_rearmed_duping_enable", "Frame duping; on|off" }, { "pcsx_rearmed_spu_reverb", "Sound: Reverb; on|off" }, { "pcsx_rearmed_spu_interpolation", "Sound: Interpolation; simple|gaussian|cubic|off" }, + { "pcsx_rearmed_pe2_fix", "Parasite Eve 2/Vandal Hearts 1/2 Fix; disabled|enabled" }, + { "pcsx_rearmed_inuyasha_fix", "InuYasha Sengoku Battle Fix; disabled|enabled" }, { NULL, NULL }, }; @@ -283,7 +371,7 @@ void retro_get_system_info(struct retro_system_info *info) { memset(info, 0, sizeof(*info)); info->library_name = "PCSX-ReARMed"; - info->library_version = "r19"; + info->library_version = "r22"; info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u"; info->need_fullpath = true; } @@ -303,8 +391,9 @@ void retro_get_system_av_info(struct retro_system_av_info *info) /* savestates */ size_t retro_serialize_size(void) { - // it's currently 4380651 bytes, but have some reserved for future - return 0x430000; + // it's currently 4380651-4397047 bytes, + // but have some reserved for future + return 0x440000; } struct save_fp { @@ -601,7 +690,7 @@ static void extract_directory(char *buf, const char *path, size_t size) } } -#ifdef __QNX__ +#if defined(__QNX__) || defined(_WIN32) /* Blackberry QNX doesn't have strcasestr */ /* @@ -1044,6 +1133,11 @@ static void update_variables(bool in_flight) { R3000Acpu *prev_cpu = psxCpu; +#ifdef _3DS + if(!ctr_svchack_init_success) + Config.Cpu = CPU_INTERPRETER; + else +#endif if (strcmp(var.value, "disabled") == 0) Config.Cpu = CPU_INTERPRETER; else if (strcmp(var.value, "enabled") == 0) @@ -1084,6 +1178,28 @@ static void update_variables(bool in_flight) spu_config.iUseInterpolation = 0; } + var.value = "NULL"; + var.key = "pcsx_rearmed_pe2_fix"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + if (strcmp(var.value, "disabled") == 0) + Config.RCntFix = 0; + else if (strcmp(var.value, "enabled") == 0) + Config.RCntFix = 1; + } + + var.value = "NULL"; + var.key = "pcsx_rearmed_inuyasha_fix"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + if (strcmp(var.value, "disabled") == 0) + Config.VSyncWA = 0; + else if (strcmp(var.value, "enabled") == 0) + Config.VSyncWA = 1; + } + if (in_flight) { // inform core things about possible config changes plugin_call_rearmed_cbs(); @@ -1124,6 +1240,14 @@ void retro_run(void) in_a2[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128; } + if (in_type2 == PSE_PAD_TYPE_ANALOGPAD) + { + in_a3[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128; + in_a3[1] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128; + in_a4[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128; + in_a4[1] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128; + } + stop = 0; psxCpu->Execute(); @@ -1156,7 +1280,7 @@ static bool try_use_bios(const char *path) return true; } -#if 1 +#ifndef VITA #include #include @@ -1200,14 +1324,26 @@ void retro_init(void) int i, ret; bool found_bios = false; +#ifdef _3DS + ctr_svchack_init_success = ctr_svchack_init(); + psxMapHook = pl_3ds_mmap; + psxUnmapHook = pl_3ds_munmap; +#endif ret = emu_core_preinit(); +#ifdef _3DS + /* emu_core_preinit sets the cpu to dynarec */ + if(!ctr_svchack_init_success) + Config.Cpu = CPU_INTERPRETER; +#endif ret |= emu_core_init(); if (ret != 0) { SysPrintf("PCSX init failed.\n"); exit(1); } -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) +#ifdef _3DS + vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80); +#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA) posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); #else vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); @@ -1215,7 +1351,7 @@ void retro_init(void) if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) { - snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s/", dir); + snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir); for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) { snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]); @@ -1253,6 +1389,8 @@ void retro_init(void) #else cycle_multiplier = 200; #endif + pl_rearmed_cbs.gpu_peops.iUseDither = 1; + spu_config.iUseFixedUpdates = 1; McdDisable[0] = 0; McdDisable[1] = 1; @@ -1271,6 +1409,18 @@ void retro_init(void) void retro_deinit(void) { SysClose(); +#ifdef _3DS + linearFree(vout_buf); +#else free(vout_buf); +#endif vout_buf = NULL; } + +#ifdef VITA +#include +int usleep (unsigned long us) +{ + sceKernelDelayThread(us); +} +#endif