From: notaz Date: Thu, 13 Oct 2022 20:55:21 +0000 (+0300) Subject: merge from libretro fork X-Git-Tag: r24~292 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a8d521fba9c86ae7b51369ce061bf63112b745f;p=pcsx_rearmed.git merge from libretro fork + minor modifications Reducing the diff as it's too hard to track down breakage when one works but not the other. --- diff --git a/frontend/blit320.h b/frontend/blit320.h index 434b52a0..ea1d2a54 100644 --- a/frontend/blit320.h +++ b/frontend/blit320.h @@ -1,3 +1,8 @@ +#ifndef __BLIT320_H__ +#define __BLIT320_H__ + void blit320_640(void *dst, const void *src, int unused); void blit320_512(void *dst, const void *src, int unused); void blit320_368(void *dst, const void *src, int unused); + +#endif /* __BLIT320_H__ */ diff --git a/frontend/cspace.h b/frontend/cspace.h index 8c92d2d9..6dbd5e0f 100644 --- a/frontend/cspace.h +++ b/frontend/cspace.h @@ -1,3 +1,6 @@ +#ifndef __CSPACE_H__ +#define __CSPACE_H__ + #ifdef __cplusplus extern "C" { @@ -19,3 +22,5 @@ void bgr888_to_uyvy(void *d, const void *s, int pixels); #ifdef __cplusplus } #endif + +#endif /* __CSPACE_H__ */ diff --git a/frontend/in_tsbutton.h b/frontend/in_tsbutton.h index 82fab29c..65a178fb 100644 --- a/frontend/in_tsbutton.h +++ b/frontend/in_tsbutton.h @@ -1 +1,6 @@ +#ifndef __IN_TSBUTTON_H__ +#define __IN_TSBUTTON_H__ + void in_tsbutton_init(void); + +#endif /* __IN_TSBUTTON_H__ */ diff --git a/frontend/libretro.c b/frontend/libretro.c index 4c285cfb..42f6151f 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -15,6 +15,10 @@ #include #endif +#ifdef SWITCH +#include +#endif + #include "../libpcsxcore/misc.h" #include "../libpcsxcore/psxcounters.h" #include "../libpcsxcore/psxmem_map.h" @@ -22,190 +26,499 @@ #include "../libpcsxcore/cdrom.h" #include "../libpcsxcore/cdriso.h" #include "../libpcsxcore/cheat.h" +#include "../libpcsxcore/r3000a.h" #include "../plugins/dfsound/out.h" #include "../plugins/dfsound/spu_config.h" #include "../plugins/dfinput/externals.h" #include "cspace.h" #include "main.h" +#include "menu.h" #include "plugin.h" #include "plugin_lib.h" #include "arm_features.h" #include "revision.h" -#include "libretro.h" + +#include +#include "libretro_core_options.h" + +#ifdef USE_LIBRETRO_VFS +#include +#endif + +#ifdef _3DS +#include "3ds/3ds_utils.h" +#endif + +#define PORTS_NUMBER 8 + +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + +#ifndef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + +#define ISHEXDEC ((buf[cursor] >= '0') && (buf[cursor] <= '9')) || ((buf[cursor] >= 'a') && (buf[cursor] <= 'f')) || ((buf[cursor] >= 'A') && (buf[cursor] <= 'F')) + +#define INTERNAL_FPS_SAMPLE_PERIOD 64 + +//hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key +static int rebootemu = 0; static retro_video_refresh_t video_cb; static retro_input_poll_t input_poll_cb; static retro_input_state_t input_state_cb; static retro_environment_t environ_cb; static retro_audio_sample_batch_t audio_batch_cb; -static struct retro_rumble_interface rumble; +static retro_set_rumble_state_t rumble_cb; +static struct retro_log_callback logging; +static retro_log_printf_t log_cb; + +static unsigned msg_interface_version = 0; static void *vout_buf; +static void *vout_buf_ptr; static int vout_width, vout_height; static int vout_doffs_old, vout_fb_dirty; static bool vout_can_dupe; static bool duping_enable; +static bool found_bios; +static bool display_internal_fps = false; +static unsigned frame_count = 0; +static bool libretro_supports_bitmasks = false; +static bool libretro_supports_option_categories = false; +static bool show_input_settings = true; +#ifdef GPU_PEOPS +static bool show_advanced_gpu_peops_settings = true; +#endif +#ifdef GPU_UNAI +static bool show_advanced_gpu_unai_settings = true; +#endif +static float mouse_sensitivity = 1.0f; + +typedef enum +{ + FRAMESKIP_NONE = 0, + FRAMESKIP_AUTO, + FRAMESKIP_AUTO_THRESHOLD, + FRAMESKIP_FIXED_INTERVAL +} frameskip_type_t; + +static unsigned frameskip_type = FRAMESKIP_NONE; +static unsigned frameskip_threshold = 0; +static unsigned frameskip_interval = 0; +static unsigned frameskip_counter = 0; + +static int retro_audio_buff_active = false; +static unsigned retro_audio_buff_occupancy = 0; +static int retro_audio_buff_underrun = false; + +static unsigned retro_audio_latency = 0; +static int update_audio_latency = false; + +static unsigned previous_width = 0; +static unsigned previous_height = 0; static int plugins_opened; static int is_pal_mode; /* memory card data */ extern char Mcd1Data[MCD_SIZE]; +extern char Mcd2Data[MCD_SIZE]; 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_keystate; +int in_type[8] = { + PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, + PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, + PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, + PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE +}; +int in_analog_left[8][2] = { { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 } }; +int in_analog_right[8][2] = { { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 } }; +unsigned short in_keystate[PORTS_NUMBER]; +int in_mouse[8][2]; +int multitap1 = 0; +int multitap2 = 0; int in_enable_vibration = 1; +// NegCon adjustment parameters +// > The NegCon 'twist' action is somewhat awkward when mapped +// to a standard analog stick -> user should be able to tweak +// response/deadzone for comfort +// > When response is linear, 'additional' deadzone (set here) +// may be left at zero, since this is normally handled via in-game +// options menus +// > When response is non-linear, deadzone should be set to match the +// controller being used (otherwise precision may be lost) +// > negcon_linearity: +// - 1: Response is linear - recommended when using racing wheel +// peripherals, not recommended for standard gamepads +// - 2: Response is quadratic - optimal setting for gamepads +// - 3: Response is cubic - enables precise fine control, but +// difficult to use... +#define NEGCON_RANGE 0x7FFF +static int negcon_deadzone = 0; +static int negcon_linearity = 1; + +static bool axis_bounds_modifier; + /* PSX max resolution is 640x512, but with enhancement it's 1024x512 */ -#define VOUT_MAX_WIDTH 1024 +#define VOUT_MAX_WIDTH 1024 #define VOUT_MAX_HEIGHT 512 +//Dummy functions +bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) { return false; } +void retro_unload_game(void) {} +static int vout_open(void) { return 0; } +static void vout_close(void) {} +static int snd_init(void) { return 0; } +static void snd_finish(void) {} +static int snd_busy(void) { return 0; } + +#define GPU_PEOPS_ODD_EVEN_BIT (1 << 0) +#define GPU_PEOPS_EXPAND_SCREEN_WIDTH (1 << 1) +#define GPU_PEOPS_IGNORE_BRIGHTNESS (1 << 2) +#define GPU_PEOPS_DISABLE_COORD_CHECK (1 << 3) +#define GPU_PEOPS_LAZY_SCREEN_UPDATE (1 << 6) +#define GPU_PEOPS_OLD_FRAME_SKIP (1 << 7) +#define GPU_PEOPS_REPEATED_TRIANGLES (1 << 8) +#define GPU_PEOPS_QUADS_WITH_TRIANGLES (1 << 9) +#define GPU_PEOPS_FAKE_BUSY_STATE (1 << 10) + static void init_memcard(char *mcd_data) { - unsigned off = 0; - unsigned i; + unsigned off = 0; + unsigned i; - memset(mcd_data, 0, MCD_SIZE); + memset(mcd_data, 0, MCD_SIZE); - mcd_data[off++] = 'M'; - mcd_data[off++] = 'C'; - off += 0x7d; - mcd_data[off++] = 0x0e; + mcd_data[off++] = 'M'; + mcd_data[off++] = 'C'; + off += 0x7d; + mcd_data[off++] = 0x0e; - for (i = 0; i < 15; i++) { - mcd_data[off++] = 0xa0; - off += 0x07; - mcd_data[off++] = 0xff; - mcd_data[off++] = 0xff; - off += 0x75; - mcd_data[off++] = 0xa0; - } + for (i = 0; i < 15; i++) + { + mcd_data[off++] = 0xa0; + off += 0x07; + mcd_data[off++] = 0xff; + mcd_data[off++] = 0xff; + off += 0x75; + mcd_data[off++] = 0xa0; + } - for (i = 0; i < 20; i++) { - mcd_data[off++] = 0xff; - mcd_data[off++] = 0xff; - mcd_data[off++] = 0xff; - mcd_data[off++] = 0xff; - off += 0x04; - mcd_data[off++] = 0xff; - mcd_data[off++] = 0xff; - off += 0x76; - } + for (i = 0; i < 20; i++) + { + mcd_data[off++] = 0xff; + mcd_data[off++] = 0xff; + mcd_data[off++] = 0xff; + mcd_data[off++] = 0xff; + off += 0x04; + mcd_data[off++] = 0xff; + mcd_data[off++] = 0xff; + off += 0x76; + } } -static int vout_open(void) +static void set_vout_fb() { - return 0; + struct retro_framebuffer fb = { 0 }; + + fb.width = vout_width; + fb.height = vout_height; + fb.access_flags = RETRO_MEMORY_ACCESS_WRITE; + + if (environ_cb(RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER, &fb) && fb.format == RETRO_PIXEL_FORMAT_RGB565) + vout_buf_ptr = (uint16_t *)fb.data; + else + vout_buf_ptr = vout_buf; } static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp) { - vout_width = w; - vout_height = h; + vout_width = w; + vout_height = h; + + if (previous_width != vout_width || previous_height != vout_height) + { + previous_width = vout_width; + previous_height = vout_height; + + struct retro_system_av_info info; + retro_get_system_av_info(&info); + environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &info.geometry); + } + + set_vout_fb(); } #ifndef FRONTEND_SUPPORTS_RGB565 static void convert(void *buf, size_t bytes) { - unsigned int i, v, *p = buf; + unsigned int i, v, *p = buf; - for (i = 0; i < bytes / 4; i++) { - v = p[i]; - p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0); - } + for (i = 0; i < bytes / 4; i++) + { + v = p[i]; + p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0); + } } #endif static void vout_flip(const void *vram, int stride, int bgr24, int w, int h) { - unsigned short *dest = vout_buf; - const unsigned short *src = vram; - int dstride = vout_width, h1 = h; - int doffs; - - if (vram == NULL) { - // blanking - memset(vout_buf, 0, dstride * h * 2); - goto out; - } - - doffs = (vout_height - h) * dstride; - doffs += (dstride - w) / 2 & ~1; - if (doffs != vout_doffs_old) { - // clear borders - memset(vout_buf, 0, dstride * h * 2); - vout_doffs_old = doffs; - } - dest += doffs; - - if (bgr24) - { - // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here? - for (; h1-- > 0; dest += dstride, src += stride) - { - bgr888_to_rgb565(dest, src, w * 3); - } - } - else - { - for (; h1-- > 0; dest += dstride, src += stride) - { - bgr555_to_rgb565(dest, src, w * 2); - } - } + unsigned short *dest = vout_buf_ptr; + const unsigned short *src = vram; + int dstride = vout_width, h1 = h; + int doffs; + + if (vram == NULL) + { + // blanking + memset(vout_buf_ptr, 0, dstride * h * 2); + goto out; + } + + doffs = (vout_height - h) * dstride; + doffs += (dstride - w) / 2 & ~1; + if (doffs != vout_doffs_old) + { + // clear borders + memset(vout_buf_ptr, 0, dstride * h * 2); + vout_doffs_old = doffs; + } + dest += doffs; + + if (bgr24) + { + // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here? + for (; h1-- > 0; dest += dstride, src += stride) + { + bgr888_to_rgb565(dest, src, w * 3); + } + } + else + { + for (; h1-- > 0; dest += dstride, src += stride) + { + bgr555_to_rgb565(dest, src, w * 2); + } + } out: #ifndef FRONTEND_SUPPORTS_RGB565 - convert(vout_buf, vout_width * vout_height * 2); + convert(vout_buf_ptr, vout_width * vout_height * 2); +#endif + vout_fb_dirty = 1; + pl_rearmed_cbs.flip_cnt++; +} + +#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_svchax) + { + 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, (void *)custom_map->target_map, (void *)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_svchax) + { + 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, (void *)custom_map->target_map, (void *)ptr_aligned, size, MEMOP_UNMAP, 0x3); + + free(custom_map->buffer); + custom_map->buffer = NULL; + return; + } + } + } + + free(ptr); +} +#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; + void *tmpaddr; + 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; + custom_psx_maps[4].buffer = tmpaddr + 0x1000000; +#if 0 + for(n = 0; n < 5; n++){ + sceClibPrintf("addr reserved %x\n",custom_psx_maps[n].buffer); + } #endif - vout_fb_dirty = 1; - pl_rearmed_cbs.flip_cnt++; + 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); } -static void vout_close(void) +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); + return psxMap(0, size, 0, MAP_TAG_VRAM); } static void pl_munmap(void *ptr, unsigned int size) { - psxUnmap(ptr, size, MAP_TAG_VRAM); + psxUnmap(ptr, size, MAP_TAG_VRAM); } struct rearmed_cbs pl_rearmed_cbs = { - .pl_vout_open = vout_open, - .pl_vout_set_mode = vout_set_mode, - .pl_vout_flip = vout_flip, - .pl_vout_close = vout_close, - .mmap = pl_mmap, - .munmap = pl_munmap, - /* from psxcounters */ - .gpu_hcnt = &hSyncCount, - .gpu_frame_count = &frame_counter, + .pl_vout_open = vout_open, + .pl_vout_set_mode = vout_set_mode, + .pl_vout_flip = vout_flip, + .pl_vout_close = vout_close, + .mmap = pl_mmap, + .munmap = pl_munmap, + /* from psxcounters */ + .gpu_hcnt = &hSyncCount, + .gpu_frame_count = &frame_counter, }; void pl_frame_limit(void) { - /* called once per frame, make psxCpu->Execute() above return */ - stop = 1; + /* called once per frame, make psxCpu->Execute() above return */ + stop = 1; } void pl_timing_prepare(int is_pal) { - is_pal_mode = is_pal; + is_pal_mode = is_pal; } void plat_trigger_vibrate(int pad, int low, int high) { - rumble.set_rumble_state(pad, RETRO_RUMBLE_STRONG, high << 8); - rumble.set_rumble_state(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0); + if (!rumble_cb) + return; + + if (in_enable_vibration) + { + rumble_cb(pad, RETRO_RUMBLE_STRONG, high << 8); + rumble_cb(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0); + } } void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in) @@ -213,60 +526,271 @@ void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in) } /* sound calls */ -static int snd_init(void) +static void snd_feed(void *buf, int bytes) { - return 0; + if (audio_batch_cb != NULL) + audio_batch_cb(buf, bytes / 4); } -static void snd_finish(void) +void out_register_libretro(struct out_driver *drv) { + drv->name = "libretro"; + drv->init = snd_init; + drv->finish = snd_finish; + drv->busy = snd_busy; + drv->feed = snd_feed; } -static int snd_busy(void) +#define RETRO_DEVICE_PSE_STANDARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0) +#define RETRO_DEVICE_PSE_ANALOG RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 0) +#define RETRO_DEVICE_PSE_DUALSHOCK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 1) +#define RETRO_DEVICE_PSE_NEGCON RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 2) +#define RETRO_DEVICE_PSE_GUNCON RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 0) +#define RETRO_DEVICE_PSE_MOUSE RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 0) + +static char *get_pse_pad_label[] = { + "none", "mouse", "negcon", "konami gun", "standard", "analog", "guncon", "dualshock" +}; + +static const struct retro_controller_description pads[7] = { - return 0; -} + { "standard", RETRO_DEVICE_JOYPAD }, + { "analog", RETRO_DEVICE_PSE_ANALOG }, + { "dualshock", RETRO_DEVICE_PSE_DUALSHOCK }, + { "negcon", RETRO_DEVICE_PSE_NEGCON }, + { "guncon", RETRO_DEVICE_PSE_GUNCON }, + { "mouse", RETRO_DEVICE_PSE_MOUSE }, + { NULL, 0 }, +}; -static void snd_feed(void *buf, int bytes) +static const struct retro_controller_info ports[9] = { - if (audio_batch_cb != NULL) - audio_batch_cb(buf, bytes / 4); -} + { pads, 7 }, + { pads, 7 }, + { pads, 7 }, + { pads, 7 }, + { pads, 7 }, + { pads, 7 }, + { pads, 7 }, + { pads, 7 }, + { NULL, 0 }, +}; -void out_register_libretro(struct out_driver *drv) +/* libretro */ + +static bool update_option_visibility(void) { - drv->name = "libretro"; - drv->init = snd_init; - drv->finish = snd_finish; - drv->busy = snd_busy; - drv->feed = snd_feed; + struct retro_variable var = {0}; + struct retro_core_option_display option_display = {0}; + bool updated = false; + unsigned i; + + /* If frontend supports core option categories + * then show/hide core option entries are ignored + * and no options should be hidden */ + if (libretro_supports_option_categories) + return false; + + var.key = "pcsx_rearmed_show_input_settings"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + bool show_input_settings_prev = + show_input_settings; + + show_input_settings = true; + if (strcmp(var.value, "disabled") == 0) + show_input_settings = false; + + if (show_input_settings != + show_input_settings_prev) + { + char input_option[][50] = { + "pcsx_rearmed_analog_axis_modifier", + "pcsx_rearmed_vibration", + "pcsx_rearmed_multitap", + "pcsx_rearmed_negcon_deadzone", + "pcsx_rearmed_negcon_response", + "pcsx_rearmed_input_sensitivity", + "pcsx_rearmed_gunconadjustx", + "pcsx_rearmed_gunconadjusty", + "pcsx_rearmed_gunconadjustratiox", + "pcsx_rearmed_gunconadjustratioy" + }; + + option_display.visible = show_input_settings; + + for (i = 0; + i < (sizeof(input_option) / + sizeof(input_option[0])); + i++) + { + option_display.key = input_option[i]; + environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, + &option_display); + } + + updated = true; + } + } +#ifdef GPU_PEOPS + var.key = "pcsx_rearmed_show_gpu_peops_settings"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + bool show_advanced_gpu_peops_settings_prev = + show_advanced_gpu_peops_settings; + + show_advanced_gpu_peops_settings = true; + if (strcmp(var.value, "disabled") == 0) + show_advanced_gpu_peops_settings = false; + + if (show_advanced_gpu_peops_settings != + show_advanced_gpu_peops_settings_prev) + { + unsigned i; + struct retro_core_option_display option_display; + char gpu_peops_option[][45] = { + "pcsx_rearmed_gpu_peops_odd_even_bit", + "pcsx_rearmed_gpu_peops_expand_screen_width", + "pcsx_rearmed_gpu_peops_ignore_brightness", + "pcsx_rearmed_gpu_peops_disable_coord_check", + "pcsx_rearmed_gpu_peops_lazy_screen_update", + "pcsx_rearmed_gpu_peops_repeated_triangles", + "pcsx_rearmed_gpu_peops_quads_with_triangles", + "pcsx_rearmed_gpu_peops_fake_busy_state" + }; + + option_display.visible = show_advanced_gpu_peops_settings; + + for (i = 0; + i < (sizeof(gpu_peops_option) / + sizeof(gpu_peops_option[0])); + i++) + { + option_display.key = gpu_peops_option[i]; + environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, + &option_display); + } + + updated = true; + } + } +#endif +#ifdef GPU_UNAI + var.key = "pcsx_rearmed_show_gpu_unai_settings"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + bool show_advanced_gpu_unai_settings_prev = + show_advanced_gpu_unai_settings; + + show_advanced_gpu_unai_settings = true; + if (strcmp(var.value, "disabled") == 0) + show_advanced_gpu_unai_settings = false; + + if (show_advanced_gpu_unai_settings != + show_advanced_gpu_unai_settings_prev) + { + unsigned i; + struct retro_core_option_display option_display; + char gpu_unai_option[][40] = { + "pcsx_rearmed_gpu_unai_blending", + "pcsx_rearmed_gpu_unai_lighting", + "pcsx_rearmed_gpu_unai_fast_lighting", + "pcsx_rearmed_gpu_unai_scale_hires", + }; + + option_display.visible = show_advanced_gpu_unai_settings; + + for (i = 0; + i < (sizeof(gpu_unai_option) / + sizeof(gpu_unai_option[0])); + i++) + { + option_display.key = gpu_unai_option[i]; + environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, + &option_display); + } + + updated = true; + } + } +#endif + return updated; } -/* libretro */ void retro_set_environment(retro_environment_t cb) { - static const struct retro_variable vars[] = { - { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" }, - { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" }, - { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog" }, - { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog" }, -#ifndef DRC_DISABLE - { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" }, -#endif -#ifdef __ARM_NEON__ - { "pcsx_rearmed_neon_interlace_enable", "Enable interlacing mode(s); disabled|enabled" }, - { "pcsx_rearmed_neon_enhancement_enable", "Enhanced resolution (slow); disabled|enabled" }, - { "pcsx_rearmed_neon_enhancement_no_main", "Enhanced resolution speed hack; disabled|enabled" }, + bool option_categories = false; +#ifdef USE_LIBRETRO_VFS + struct retro_vfs_interface_info vfs_iface_info; #endif - { "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" }, - { NULL, NULL }, - }; environ_cb = cb; - cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars); + if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging)) + log_cb = logging.log; + + environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); + + /* Set core options + * An annoyance: retro_set_environment() can be called + * multiple times, and depending upon the current frontend + * state various environment callbacks may be disabled. + * This means the reported 'categories_supported' status + * may change on subsequent iterations. We therefore have + * to record whether 'categories_supported' is true on any + * iteration, and latch the result */ + libretro_set_core_options(environ_cb, &option_categories); + libretro_supports_option_categories |= option_categories; + + /* If frontend supports core option categories, + * any show/hide core option entries are unused + * and should be hidden */ + if (libretro_supports_option_categories) + { + struct retro_core_option_display option_display; + option_display.visible = false; + + option_display.key = "pcsx_rearmed_show_input_settings"; + environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, + &option_display); + +#ifdef GPU_PEOPS + option_display.key = "pcsx_rearmed_show_gpu_peops_settings"; + environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, + &option_display); +#endif +#ifdef GPU_UNAI + option_display.key = "pcsx_rearmed_show_gpu_unai_settings"; + environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, + &option_display); +#endif + } + /* If frontend does not support core option + * categories, core options may be shown/hidden + * at runtime. In this case, register 'update + * display' callback, so frontend can update + * core options menu without calling retro_run() */ + else + { + struct retro_core_options_update_display_callback update_display_cb; + update_display_cb.callback = update_option_visibility; + + environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_UPDATE_DISPLAY_CALLBACK, + &update_display_cb); + } + +#ifdef USE_LIBRETRO_VFS + vfs_iface_info.required_interface_version = 1; + vfs_iface_info.iface = NULL; + if (environ_cb(RETRO_ENVIRONMENT_GET_VFS_INTERFACE, &vfs_iface_info)) + filestream_vfs_init(&vfs_iface_info); +#endif } void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; } @@ -277,331 +801,565 @@ void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; } unsigned retro_api_version(void) { - return RETRO_API_VERSION; + return RETRO_API_VERSION; +} + +static void update_multitap(void) +{ + struct retro_variable var = { 0 }; + + multitap1 = 0; + multitap2 = 0; + + var.value = NULL; + var.key = "pcsx_rearmed_multitap"; + if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)) + { + if (strcmp(var.value, "port 1") == 0) + multitap1 = 1; + else if (strcmp(var.value, "port 2") == 0) + multitap2 = 1; + else if (strcmp(var.value, "ports 1 and 2") == 0) + { + multitap1 = 1; + multitap2 = 1; + } + } } void retro_set_controller_port_device(unsigned port, unsigned device) { + if (port >= PORTS_NUMBER) + return; + + switch (device) + { + case RETRO_DEVICE_JOYPAD: + case RETRO_DEVICE_PSE_STANDARD: + in_type[port] = PSE_PAD_TYPE_STANDARD; + break; + case RETRO_DEVICE_PSE_ANALOG: + in_type[port] = PSE_PAD_TYPE_ANALOGJOY; + break; + case RETRO_DEVICE_PSE_DUALSHOCK: + in_type[port] = PSE_PAD_TYPE_ANALOGPAD; + break; + case RETRO_DEVICE_PSE_MOUSE: + in_type[port] = PSE_PAD_TYPE_MOUSE; + break; + case RETRO_DEVICE_PSE_NEGCON: + in_type[port] = PSE_PAD_TYPE_NEGCON; + break; + case RETRO_DEVICE_PSE_GUNCON: + in_type[port] = PSE_PAD_TYPE_GUNCON; + break; + case RETRO_DEVICE_NONE: + default: + in_type[port] = PSE_PAD_TYPE_NONE; + break; + } + + SysPrintf("port: %u device: %s\n", port + 1, get_pse_pad_label[in_type[port]]); } void retro_get_system_info(struct retro_system_info *info) { - memset(info, 0, sizeof(*info)); - info->library_name = "PCSX-ReARMed"; - info->library_version = "r22"; - info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u"; - info->need_fullpath = true; +#ifndef GIT_VERSION +#define GIT_VERSION "" +#endif + memset(info, 0, sizeof(*info)); + info->library_name = "PCSX-ReARMed"; + info->library_version = "r23l" GIT_VERSION; + info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u|chd"; + info->need_fullpath = true; } void retro_get_system_av_info(struct retro_system_av_info *info) { - memset(info, 0, sizeof(*info)); - info->timing.fps = is_pal_mode ? 50 : 60; - info->timing.sample_rate = 44100; - info->geometry.base_width = 320; - info->geometry.base_height = 240; - info->geometry.max_width = VOUT_MAX_WIDTH; - info->geometry.max_height = VOUT_MAX_HEIGHT; - info->geometry.aspect_ratio = 4.0 / 3.0; + unsigned geom_height = vout_height > 0 ? vout_height : 240; + unsigned geom_width = vout_width > 0 ? vout_width : 320; + + memset(info, 0, sizeof(*info)); + info->timing.fps = is_pal_mode ? 50.0 : 60.0; + info->timing.sample_rate = 44100.0; + info->geometry.base_width = geom_width; + info->geometry.base_height = geom_height; + info->geometry.max_width = VOUT_MAX_WIDTH; + info->geometry.max_height = VOUT_MAX_HEIGHT; + info->geometry.aspect_ratio = 4.0 / 3.0; } /* savestates */ -size_t retro_serialize_size(void) -{ - // it's currently 4380651-4397047 bytes, - // but have some reserved for future - return 0x440000; +size_t retro_serialize_size(void) +{ + // it's currently 4380651-4397047 bytes, + // but have some reserved for future + return 0x440000; } -struct save_fp { - char *buf; - size_t pos; - int is_write; +struct save_fp +{ + char *buf; + size_t pos; + int is_write; }; static void *save_open(const char *name, const char *mode) { - struct save_fp *fp; + struct save_fp *fp; - if (name == NULL || mode == NULL) - return NULL; + if (name == NULL || mode == NULL) + return NULL; - fp = malloc(sizeof(*fp)); - if (fp == NULL) - return NULL; + fp = malloc(sizeof(*fp)); + if (fp == NULL) + return NULL; - fp->buf = (char *)name; - fp->pos = 0; - fp->is_write = (mode[0] == 'w' || mode[1] == 'w'); + fp->buf = (char *)name; + fp->pos = 0; + fp->is_write = (mode[0] == 'w' || mode[1] == 'w'); - return fp; + return fp; } static int save_read(void *file, void *buf, u32 len) { - struct save_fp *fp = file; - if (fp == NULL || buf == NULL) - return -1; + struct save_fp *fp = file; + if (fp == NULL || buf == NULL) + return -1; - memcpy(buf, fp->buf + fp->pos, len); - fp->pos += len; - return len; + memcpy(buf, fp->buf + fp->pos, len); + fp->pos += len; + return len; } static int save_write(void *file, const void *buf, u32 len) { - struct save_fp *fp = file; - if (fp == NULL || buf == NULL) - return -1; + struct save_fp *fp = file; + if (fp == NULL || buf == NULL) + return -1; - memcpy(fp->buf + fp->pos, buf, len); - fp->pos += len; - return len; + memcpy(fp->buf + fp->pos, buf, len); + fp->pos += len; + return len; } static long save_seek(void *file, long offs, int whence) { - struct save_fp *fp = file; - if (fp == NULL) - return -1; + struct save_fp *fp = file; + if (fp == NULL) + return -1; - switch (whence) { - case SEEK_CUR: - fp->pos += offs; - return fp->pos; - case SEEK_SET: - fp->pos = offs; - return fp->pos; - default: - return -1; - } + switch (whence) + { + case SEEK_CUR: + fp->pos += offs; + return fp->pos; + case SEEK_SET: + fp->pos = offs; + return fp->pos; + default: + return -1; + } } static void save_close(void *file) { - struct save_fp *fp = file; - size_t r_size = retro_serialize_size(); - if (fp == NULL) - return; - - if (fp->pos > r_size) - SysPrintf("ERROR: save buffer overflow detected\n"); - else if (fp->is_write && fp->pos < r_size) - // make sure we don't save trash in leftover space - memset(fp->buf + fp->pos, 0, r_size - fp->pos); - free(fp); + struct save_fp *fp = file; + size_t r_size = retro_serialize_size(); + if (fp == NULL) + return; + + if (fp->pos > r_size) + SysPrintf("ERROR: save buffer overflow detected\n"); + else if (fp->is_write && fp->pos < r_size) + // make sure we don't save trash in leftover space + memset(fp->buf + fp->pos, 0, r_size - fp->pos); + free(fp); } bool retro_serialize(void *data, size_t size) -{ - int ret = SaveState(data); - return ret == 0 ? true : false; +{ + int ret = SaveState(data); + return ret == 0 ? true : false; } bool retro_unserialize(const void *data, size_t size) { - int ret = LoadState(data); - return ret == 0 ? true : false; + int ret = LoadState(data); + return ret == 0 ? true : false; } /* cheats */ void retro_cheat_reset(void) { - ClearAllCheats(); + ClearAllCheats(); } void retro_cheat_set(unsigned index, bool enabled, const char *code) { - char buf[256]; - int ret; + char buf[256]; + int ret; + + // cheat funcs are destructive, need a copy.. + strncpy(buf, code, sizeof(buf)); + buf[sizeof(buf) - 1] = 0; - // cheat funcs are destructive, need a copy.. - strncpy(buf, code, sizeof(buf)); - buf[sizeof(buf) - 1] = 0; + //Prepare buffered cheat for PCSX's AddCheat fucntion. + int cursor = 0; + int nonhexdec = 0; + while (buf[cursor]) + { + if (!(ISHEXDEC)) + { + if (++nonhexdec % 2) + { + buf[cursor] = ' '; + } + else + { + buf[cursor] = '\n'; + } + } + cursor++; + } - if (index < NumCheats) - ret = EditCheat(index, "", buf); - else - ret = AddCheat("", buf); + if (index < NumCheats) + ret = EditCheat(index, "", buf); + else + ret = AddCheat("", buf); - if (ret != 0) - SysPrintf("Failed to set cheat %#u\n", index); - else if (index < NumCheats) - Cheats[index].Enabled = enabled; + if (ret != 0) + SysPrintf("Failed to set cheat %#u\n", index); + else if (index < NumCheats) + Cheats[index].Enabled = enabled; } +// just in case, maybe a win-rt port in the future? +#ifdef _WIN32 +#define SLASH '\\' +#else +#define SLASH '/' +#endif + +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + /* multidisk support */ +static unsigned int disk_initial_index; +static char disk_initial_path[PATH_MAX]; static bool disk_ejected; static unsigned int disk_current_index; static unsigned int disk_count; -static struct disks_state { - char *fname; - int internal_index; // for multidisk eboots +static struct disks_state +{ + char *fname; + char *flabel; + int internal_index; // for multidisk eboots } disks[8]; +static void get_disk_label(char *disk_label, const char *disk_path, size_t len) +{ + const char *base = NULL; + + if (!disk_path || (*disk_path == '\0')) + return; + + base = strrchr(disk_path, SLASH); + if (!base) + base = disk_path; + + if (*base == SLASH) + base++; + + strncpy(disk_label, base, len - 1); + disk_label[len - 1] = '\0'; + + char *ext = strrchr(disk_label, '.'); + if (ext) + *ext = '\0'; +} + +static void disk_init(void) +{ + size_t i; + + disk_ejected = false; + disk_current_index = 0; + disk_count = 0; + + for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) + { + if (disks[i].fname != NULL) + { + free(disks[i].fname); + disks[i].fname = NULL; + } + if (disks[i].flabel != NULL) + { + free(disks[i].flabel); + disks[i].flabel = NULL; + } + disks[i].internal_index = 0; + } +} + static bool disk_set_eject_state(bool ejected) { - // weird PCSX API.. - SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2)); - LidInterrupt(); + // weird PCSX API.. + SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2)); + LidInterrupt(); - disk_ejected = ejected; - return true; + disk_ejected = ejected; + return true; } static bool disk_get_eject_state(void) { - /* can't be controlled by emulated software */ - return disk_ejected; + /* can't be controlled by emulated software */ + return disk_ejected; } static unsigned int disk_get_image_index(void) { - return disk_current_index; + return disk_current_index; } static bool disk_set_image_index(unsigned int index) { - if (index >= sizeof(disks) / sizeof(disks[0])) - return false; + if (index >= sizeof(disks) / sizeof(disks[0])) + return false; - CdromId[0] = '\0'; - CdromLabel[0] = '\0'; + CdromId[0] = '\0'; + CdromLabel[0] = '\0'; - if (disks[index].fname == NULL) { - SysPrintf("missing disk #%u\n", index); - CDR_shutdown(); + if (disks[index].fname == NULL) + { + SysPrintf("missing disk #%u\n", index); + CDR_shutdown(); - // RetroArch specifies "no disk" with index == count, - // so don't fail here.. - disk_current_index = index; - return true; - } + // RetroArch specifies "no disk" with index == count, + // so don't fail here.. + disk_current_index = index; + return true; + } - SysPrintf("switching to disk %u: \"%s\" #%d\n", index, - disks[index].fname, disks[index].internal_index); + SysPrintf("switching to disk %u: \"%s\" #%d\n", index, + disks[index].fname, disks[index].internal_index); - cdrIsoMultidiskSelect = disks[index].internal_index; - set_cd_image(disks[index].fname); - if (ReloadCdromPlugin() < 0) { - SysPrintf("failed to load cdr plugin\n"); - return false; - } - if (CDR_open() < 0) { - SysPrintf("failed to open cdr plugin\n"); - return false; - } + cdrIsoMultidiskSelect = disks[index].internal_index; + set_cd_image(disks[index].fname); + if (ReloadCdromPlugin() < 0) + { + SysPrintf("failed to load cdr plugin\n"); + return false; + } + if (CDR_open() < 0) + { + SysPrintf("failed to open cdr plugin\n"); + return false; + } - if (!disk_ejected) { - SetCdOpenCaseTime(time(NULL) + 2); - LidInterrupt(); - } + if (!disk_ejected) + { + SetCdOpenCaseTime(time(NULL) + 2); + LidInterrupt(); + } - disk_current_index = index; - return true; + disk_current_index = index; + return true; } static unsigned int disk_get_num_images(void) { - return disk_count; + return disk_count; } static bool disk_replace_image_index(unsigned index, - const struct retro_game_info *info) + const struct retro_game_info *info) { - char *old_fname; - bool ret = true; + char *old_fname = NULL; + char *old_flabel = NULL; + bool ret = true; + + if (index >= sizeof(disks) / sizeof(disks[0])) + return false; + + old_fname = disks[index].fname; + old_flabel = disks[index].flabel; + + disks[index].fname = NULL; + disks[index].flabel = NULL; + disks[index].internal_index = 0; + + if (info != NULL) + { + char disk_label[PATH_MAX]; + disk_label[0] = '\0'; + + disks[index].fname = strdup(info->path); - if (index >= sizeof(disks) / sizeof(disks[0])) - return false; + get_disk_label(disk_label, info->path, PATH_MAX); + disks[index].flabel = strdup(disk_label); - old_fname = disks[index].fname; - disks[index].fname = NULL; - disks[index].internal_index = 0; + if (index == disk_current_index) + ret = disk_set_image_index(index); + } - if (info != NULL) { - disks[index].fname = strdup(info->path); - if (index == disk_current_index) - ret = disk_set_image_index(index); - } + if (old_fname != NULL) + free(old_fname); - if (old_fname != NULL) - free(old_fname); + if (old_flabel != NULL) + free(old_flabel); - return ret; + return ret; } static bool disk_add_image_index(void) { - if (disk_count >= 8) - return false; + if (disk_count >= 8) + return false; - disk_count++; - return true; + disk_count++; + return true; } -static struct retro_disk_control_callback disk_control = { - .set_eject_state = disk_set_eject_state, - .get_eject_state = disk_get_eject_state, - .get_image_index = disk_get_image_index, - .set_image_index = disk_set_image_index, - .get_num_images = disk_get_num_images, - .replace_image_index = disk_replace_image_index, - .add_image_index = disk_add_image_index, -}; +static bool disk_set_initial_image(unsigned index, const char *path) +{ + if (index >= sizeof(disks) / sizeof(disks[0])) + return false; -// just in case, maybe a win-rt port in the future? -#ifdef _WIN32 -#define SLASH '\\' -#else -#define SLASH '/' -#endif + if (!path || (*path == '\0')) + return false; -static char base_dir[PATH_MAX]; + disk_initial_index = index; -static bool read_m3u(const char *file) -{ - char line[PATH_MAX]; - char name[PATH_MAX]; - FILE *f = fopen(file, "r"); - if (!f) - return false; - - while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) { - if (line[0] == '#') - continue; - char *carrige_return = strchr(line, '\r'); - if (carrige_return) - *carrige_return = '\0'; - char *newline = strchr(line, '\n'); - if (newline) - *newline = '\0'; - - if (line[0] != '\0') - { - snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line); - disks[disk_count++].fname = strdup(name); - } - } - - fclose(f); - return (disk_count != 0); + strncpy(disk_initial_path, path, sizeof(disk_initial_path) - 1); + disk_initial_path[sizeof(disk_initial_path) - 1] = '\0'; + + return true; } -static void extract_directory(char *buf, const char *path, size_t size) +static bool disk_get_image_path(unsigned index, char *path, size_t len) { - char *base; - strncpy(buf, path, size - 1); - buf[size - 1] = '\0'; + const char *fname = NULL; - base = strrchr(buf, '/'); - if (!base) - base = strrchr(buf, '\\'); + if (len < 1) + return false; - if (base) - *base = '\0'; - else - { + if (index >= sizeof(disks) / sizeof(disks[0])) + return false; + + fname = disks[index].fname; + + if (!fname || (*fname == '\0')) + return false; + + strncpy(path, fname, len - 1); + path[len - 1] = '\0'; + + return true; +} + +static bool disk_get_image_label(unsigned index, char *label, size_t len) +{ + const char *flabel = NULL; + + if (len < 1) + return false; + + if (index >= sizeof(disks) / sizeof(disks[0])) + return false; + + flabel = disks[index].flabel; + + if (!flabel || (*flabel == '\0')) + return false; + + strncpy(label, flabel, len - 1); + label[len - 1] = '\0'; + + return true; +} + +static struct retro_disk_control_callback disk_control = { + .set_eject_state = disk_set_eject_state, + .get_eject_state = disk_get_eject_state, + .get_image_index = disk_get_image_index, + .set_image_index = disk_set_image_index, + .get_num_images = disk_get_num_images, + .replace_image_index = disk_replace_image_index, + .add_image_index = disk_add_image_index, +}; + +static struct retro_disk_control_ext_callback disk_control_ext = { + .set_eject_state = disk_set_eject_state, + .get_eject_state = disk_get_eject_state, + .get_image_index = disk_get_image_index, + .set_image_index = disk_set_image_index, + .get_num_images = disk_get_num_images, + .replace_image_index = disk_replace_image_index, + .add_image_index = disk_add_image_index, + .set_initial_image = disk_set_initial_image, + .get_image_path = disk_get_image_path, + .get_image_label = disk_get_image_label, +}; + +static char base_dir[1024]; + +static bool read_m3u(const char *file) +{ + char line[1024]; + char name[PATH_MAX]; + FILE *fp = fopen(file, "r"); + if (!fp) + return false; + + while (fgets(line, sizeof(line), fp) && disk_count < sizeof(disks) / sizeof(disks[0])) + { + if (line[0] == '#') + continue; + char *carrige_return = strchr(line, '\r'); + if (carrige_return) + *carrige_return = '\0'; + char *newline = strchr(line, '\n'); + if (newline) + *newline = '\0'; + + if (line[0] != '\0') + { + char disk_label[PATH_MAX]; + disk_label[0] = '\0'; + + snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line); + disks[disk_count].fname = strdup(name); + + get_disk_label(disk_label, name, PATH_MAX); + disks[disk_count].flabel = strdup(disk_label); + + disk_count++; + } + } + + fclose(fp); + return (disk_count != 0); +} + +static void extract_directory(char *buf, const char *path, size_t size) +{ + char *base; + strncpy(buf, path, size - 1); + buf[size - 1] = '\0'; + + base = strrchr(buf, '/'); + if (!base) + base = strrchr(buf, '\\'); + + if (base) + *base = '\0'; + else + { buf[0] = '.'; buf[1] = '\0'; } @@ -614,361 +1372,430 @@ static void extract_directory(char *buf, const char *path, size_t size) * Find the first occurrence of find in s, ignore case. */ char * -strcasestr(const char *s, const char*find) -{ - char c, sc; - size_t len; - - if ((c = *find++) != 0) { - c = tolower((unsigned char)c); - len = strlen(find); - do { - do { - if ((sc = *s++) == 0) - return (NULL); - } while ((char)tolower((unsigned char)sc) != c); - } while (strncasecmp(s, find, len) != 0); - s--; - } - return ((char *)s); +strcasestr(const char *s, const char *find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) + { + c = tolower((unsigned char)c); + len = strlen(find); + do + { + do + { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); } #endif +static void set_retro_memmap(void) +{ +#ifndef NDEBUG + struct retro_memory_map retromap = { 0 }; + struct retro_memory_descriptor mmap = { + 0, psxM, 0, 0, 0, 0, 0x200000 + }; + + retromap.descriptors = &mmap; + retromap.num_descriptors = 1; + + environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &retromap); +#endif +} + +static void retro_audio_buff_status_cb( + bool active, unsigned occupancy, bool underrun_likely) +{ + retro_audio_buff_active = active; + retro_audio_buff_occupancy = occupancy; + retro_audio_buff_underrun = underrun_likely; +} + +static void retro_set_audio_buff_status_cb(void) +{ + if (frameskip_type == FRAMESKIP_NONE) + { + environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL); + retro_audio_latency = 0; + } + else + { + bool calculate_audio_latency = true; + + if (frameskip_type == FRAMESKIP_FIXED_INTERVAL) + environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL); + else + { + struct retro_audio_buffer_status_callback buf_status_cb; + buf_status_cb.callback = retro_audio_buff_status_cb; + if (!environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, + &buf_status_cb)) + { + retro_audio_buff_active = false; + retro_audio_buff_occupancy = 0; + retro_audio_buff_underrun = false; + retro_audio_latency = 0; + calculate_audio_latency = false; + } + } + + if (calculate_audio_latency) + { + /* Frameskip is enabled - increase frontend + * audio latency to minimise potential + * buffer underruns */ + uint32_t frame_time_usec = 1000000.0 / (is_pal_mode ? 50.0 : 60.0); + + /* Set latency to 6x current frame time... */ + retro_audio_latency = (unsigned)(6 * frame_time_usec / 1000); + + /* ...then round up to nearest multiple of 32 */ + retro_audio_latency = (retro_audio_latency + 0x1F) & ~0x1F; + } + } + + update_audio_latency = true; + frameskip_counter = 0; +} + +static void update_variables(bool in_flight); bool retro_load_game(const struct retro_game_info *info) { - size_t i; - bool is_m3u = (strcasestr(info->path, ".m3u") != NULL); + size_t i; + unsigned int cd_index = 0; + bool is_m3u = (strcasestr(info->path, ".m3u") != NULL); struct retro_input_descriptor desc[] = { - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, - { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, - { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, - { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, - - - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, - { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, - { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, - { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, - - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, - { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, - { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, - { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, - - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, - { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, - { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, - { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, - - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, - { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, - { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, - { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, - - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, - { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, - { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, - { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, - - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, - { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, - { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, - { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, - - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, - { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, - { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, - { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, - { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, - { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, +#define JOYP(port) \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, \ + { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, \ + { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, \ + { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, \ + { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, \ + { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, \ + { port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER, "Gun Trigger" }, \ + { port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD, "Gun Reload" }, \ + { port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_A, "Gun Aux A" }, \ + { port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_B, "Gun Aux B" }, + + JOYP(0) + JOYP(1) + JOYP(2) + JOYP(3) + JOYP(4) + JOYP(5) + JOYP(6) + JOYP(7) { 0 }, }; + frame_count = 0; + environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); #ifdef FRONTEND_SUPPORTS_RGB565 - enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; - if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { - SysPrintf("RGB565 supported, using it\n"); - } + enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; + if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) + { + SysPrintf("RGB565 supported, using it\n"); + } #endif - if (info == NULL || info->path == NULL) { - SysPrintf("info->path required\n"); - return false; - } + if (info == NULL || info->path == NULL) + { + SysPrintf("info->path required\n"); + return false; + } - if (plugins_opened) { - ClosePlugins(); - plugins_opened = 0; - } + update_variables(false); - for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) { - if (disks[i].fname != NULL) { - free(disks[i].fname); - disks[i].fname = NULL; - } - disks[i].internal_index = 0; - } + if (plugins_opened) + { + ClosePlugins(); + plugins_opened = 0; + } - disk_current_index = 0; - extract_directory(base_dir, info->path, sizeof(base_dir)); + disk_init(); - if (is_m3u) { - if (!read_m3u(info->path)) { - SysPrintf("failed to read m3u file\n"); - return false; - } - } else { - disk_count = 1; - disks[0].fname = strdup(info->path); - } + extract_directory(base_dir, info->path, sizeof(base_dir)); - set_cd_image(disks[0].fname); + if (is_m3u) + { + if (!read_m3u(info->path)) + { + log_cb(RETRO_LOG_INFO, "failed to read m3u file\n"); + return false; + } + } + else + { + char disk_label[PATH_MAX]; + disk_label[0] = '\0'; - /* have to reload after set_cd_image for correct cdr plugin */ - if (LoadPlugins() == -1) { - SysPrintf("failed to load plugins\n"); - return false; - } + disk_count = 1; + disks[0].fname = strdup(info->path); - plugins_opened = 1; - NetOpened = 0; + get_disk_label(disk_label, info->path, PATH_MAX); + disks[0].flabel = strdup(disk_label); + } - if (OpenPlugins() == -1) { - SysPrintf("failed to open plugins\n"); - return false; - } + /* If this is an M3U file, attempt to set the + * initial disk image */ + if (is_m3u && (disk_initial_index > 0) && (disk_initial_index < disk_count)) + { + const char *fname = disks[disk_initial_index].fname; - plugin_call_rearmed_cbs(); - dfinput_activate(); + if (fname && (*fname != '\0')) + if (strcmp(disk_initial_path, fname) == 0) + cd_index = disk_initial_index; + } - Config.PsxAuto = 1; - if (CheckCdrom() == -1) { - SysPrintf("unsupported/invalid CD image: %s\n", info->path); - return false; - } + set_cd_image(disks[cd_index].fname); + disk_current_index = cd_index; - SysReset(); + /* have to reload after set_cd_image for correct cdr plugin */ + if (LoadPlugins() == -1) + { + log_cb(RETRO_LOG_INFO, "failed to load plugins\n"); + return false; + } - if (LoadCdrom() == -1) { - SysPrintf("could not load CD-ROM!\n"); - return false; - } - emu_on_new_cd(0); + plugins_opened = 1; + NetOpened = 0; - // multidisk images - if (!is_m3u) { - disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8; - for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) { - disks[i].fname = strdup(info->path); - disks[i].internal_index = i; - } - } + if (OpenPlugins() == -1) + { + log_cb(RETRO_LOG_INFO, "failed to open plugins\n"); + return false; + } - return true; -} + /* Handle multi-disk images (i.e. PBP) + * > Cannot do this until after OpenPlugins() is + * called (since this sets the value of + * cdrIsoMultidiskCount) */ + if (!is_m3u && (cdrIsoMultidiskCount > 1)) + { + disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8; -bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) -{ - return false; -} + /* Small annoyance: We need to change the label + * of disk 0, so have to clear existing entries */ + if (disks[0].fname != NULL) + free(disks[0].fname); + disks[0].fname = NULL; -void retro_unload_game(void) -{ + if (disks[0].flabel != NULL) + free(disks[0].flabel); + disks[0].flabel = NULL; + + for (i = 0; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) + { + char disk_name[PATH_MAX - 16] = { 0 }; + char disk_label[PATH_MAX] = { 0 }; + + disks[i].fname = strdup(info->path); + + get_disk_label(disk_name, info->path, sizeof(disk_name)); + snprintf(disk_label, sizeof(disk_label), "%s #%u", disk_name, (unsigned)i + 1); + disks[i].flabel = strdup(disk_label); + + disks[i].internal_index = i; + } + + /* This is not an M3U file, so initial disk + * image has not yet been set - attempt to + * do so now */ + if ((disk_initial_index > 0) && (disk_initial_index < disk_count)) + { + const char *fname = disks[disk_initial_index].fname; + + if (fname && (*fname != '\0')) + if (strcmp(disk_initial_path, fname) == 0) + cd_index = disk_initial_index; + } + + if (cd_index > 0) + { + CdromId[0] = '\0'; + CdromLabel[0] = '\0'; + + cdrIsoMultidiskSelect = disks[cd_index].internal_index; + disk_current_index = cd_index; + set_cd_image(disks[cd_index].fname); + + if (ReloadCdromPlugin() < 0) + { + log_cb(RETRO_LOG_INFO, "failed to reload cdr plugins\n"); + return false; + } + if (CDR_open() < 0) + { + log_cb(RETRO_LOG_INFO, "failed to open cdr plugin\n"); + return false; + } + } + } + + /* set ports to use "standard controller" initially */ + for (i = 0; i < 8; ++i) + in_type[i] = PSE_PAD_TYPE_STANDARD; + + plugin_call_rearmed_cbs(); + /* dfinput_activate(); */ + + if (CheckCdrom() == -1) + { + log_cb(RETRO_LOG_INFO, "unsupported/invalid CD image: %s\n", info->path); + return false; + } + + SysReset(); + + if (LoadCdrom() == -1) + { + log_cb(RETRO_LOG_INFO, "could not load CD\n"); + return false; + } + emu_on_new_cd(0); + + set_retro_memmap(); + retro_set_audio_buff_status_cb(); + + return true; } unsigned retro_get_region(void) { - return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC; + return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC; } void *retro_get_memory_data(unsigned id) { - if (id == RETRO_MEMORY_SAVE_RAM) - return Mcd1Data; - else - return NULL; + if (id == RETRO_MEMORY_SAVE_RAM) + return Mcd1Data; + else if (id == RETRO_MEMORY_SYSTEM_RAM) + return psxM; + else + return NULL; } size_t retro_get_memory_size(unsigned id) { - if (id == RETRO_MEMORY_SAVE_RAM) - return MCD_SIZE; - else - return 0; + if (id == RETRO_MEMORY_SAVE_RAM) + return MCD_SIZE; + else if (id == RETRO_MEMORY_SYSTEM_RAM) + return 0x200000; + else + return 0; } void retro_reset(void) { - SysReset(); + //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key + rebootemu = 1; + //SysReset(); } static const unsigned short retro_psx_map[] = { - [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS, - [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE, - [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT, - [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START, - [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP, - [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN, - [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT, - [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT, - [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE, - [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE, - [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1, - [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1, - [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2, - [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2, - [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3, - [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3, + [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS, + [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE, + [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT, + [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START, + [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP, + [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN, + [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT, + [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT, + [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE, + [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE, + [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1, + [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1, + [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2, + [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2, + [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3, + [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3, }; #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0])) +//Percentage distance of screen to adjust +static int GunconAdjustX = 0; +static int GunconAdjustY = 0; + +//Used when out by a percentage +static float GunconAdjustRatioX = 1; +static float GunconAdjustRatioY = 1; + static void update_variables(bool in_flight) { struct retro_variable var; +#ifdef GPU_PEOPS + // Always enable GPU_PEOPS_OLD_FRAME_SKIP flag + // (this is set in standalone, with no option + // to change it) + int gpu_peops_fix = GPU_PEOPS_OLD_FRAME_SKIP; +#endif + frameskip_type_t prev_frameskip_type; + + var.value = NULL; + var.key = "pcsx_rearmed_frameskip_type"; + + prev_frameskip_type = frameskip_type; + frameskip_type = FRAMESKIP_NONE; + pl_rearmed_cbs.frameskip = 0; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "auto") == 0) + frameskip_type = FRAMESKIP_AUTO; + if (strcmp(var.value, "auto_threshold") == 0) + frameskip_type = FRAMESKIP_AUTO_THRESHOLD; + if (strcmp(var.value, "fixed_interval") == 0) + frameskip_type = FRAMESKIP_FIXED_INTERVAL; + } + + if (frameskip_type != 0) + pl_rearmed_cbs.frameskip = -1; var.value = NULL; - var.key = "pcsx_rearmed_frameskip"; + var.key = "pcsx_rearmed_frameskip_threshold"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + frameskip_threshold = strtol(var.value, NULL, 10); + } - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - pl_rearmed_cbs.frameskip = atoi(var.value); + var.value = NULL; + var.key = "pcsx_rearmed_frameskip_interval"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + frameskip_interval = strtol(var.value, NULL, 10); + } var.value = NULL; var.key = "pcsx_rearmed_region"; - - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { Config.PsxAuto = 0; - if (strcmp(var.value, "Automatic") == 0) + if (strcmp(var.value, "auto") == 0) Config.PsxAuto = 1; else if (strcmp(var.value, "NTSC") == 0) Config.PsxType = 0; @@ -976,31 +1803,87 @@ static void update_variables(bool in_flight) Config.PsxType = 1; } + update_multitap(); + var.value = NULL; - var.key = "pcsx_rearmed_pad1type"; + var.key = "pcsx_rearmed_negcon_deadzone"; + negcon_deadzone = 0; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + negcon_deadzone = (int)(atoi(var.value) * 0.01f * NEGCON_RANGE); + } - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + var.value = NULL; + var.key = "pcsx_rearmed_negcon_response"; + negcon_linearity = 1; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - in_type1 = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type1 = PSE_PAD_TYPE_ANALOGPAD; + if (strcmp(var.value, "quadratic") == 0) + { + negcon_linearity = 2; + } + else if (strcmp(var.value, "cubic") == 0) + { + negcon_linearity = 3; + } + } + + var.value = NULL; + var.key = "pcsx_rearmed_analog_axis_modifier"; + axis_bounds_modifier = true; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "square") == 0) + { + axis_bounds_modifier = true; + } + else if (strcmp(var.value, "circle") == 0) + { + axis_bounds_modifier = false; + } + } + + var.value = NULL; + var.key = "pcsx_rearmed_vibration"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + in_enable_vibration = 0; + else if (strcmp(var.value, "enabled") == 0) + in_enable_vibration = 1; } var.value = NULL; - var.key = "pcsx_rearmed_pad2type"; + var.key = "pcsx_rearmed_dithering"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - in_type2 = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type2 = PSE_PAD_TYPE_ANALOGPAD; + if (strcmp(var.value, "disabled") == 0) + { + pl_rearmed_cbs.gpu_peops.iUseDither = 0; + pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 0; + pl_rearmed_cbs.gpu_unai.dithering = 0; +#ifdef GPU_NEON + pl_rearmed_cbs.gpu_neon.allow_dithering = 0; +#endif + } + else if (strcmp(var.value, "enabled") == 0) + { + pl_rearmed_cbs.gpu_peops.iUseDither = 1; + pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 1; + pl_rearmed_cbs.gpu_unai.dithering = 1; +#ifdef GPU_NEON + pl_rearmed_cbs.gpu_neon.allow_dithering = 1; +#endif + } } -#ifdef __ARM_NEON__ - var.value = "NULL"; +#ifdef GPU_NEON + var.value = NULL; var.key = "pcsx_rearmed_neon_interlace_enable"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "disabled") == 0) pl_rearmed_cbs.gpu_neon.allow_interlace = 0; @@ -1011,7 +1894,7 @@ static void update_variables(bool in_flight) var.value = NULL; var.key = "pcsx_rearmed_neon_enhancement_enable"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "disabled") == 0) pl_rearmed_cbs.gpu_neon.enhancement_enable = 0; @@ -1022,7 +1905,7 @@ static void update_variables(bool in_flight) var.value = NULL; var.key = "pcsx_rearmed_neon_enhancement_no_main"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "disabled") == 0) pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0; @@ -1031,55 +1914,155 @@ static void update_variables(bool in_flight) } #endif - var.value = "NULL"; + var.value = NULL; var.key = "pcsx_rearmed_duping_enable"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (strcmp(var.value, "off") == 0) + if (strcmp(var.value, "disabled") == 0) duping_enable = false; - else if (strcmp(var.value, "on") == 0) + else if (strcmp(var.value, "enabled") == 0) duping_enable = true; } + var.value = NULL; + var.key = "pcsx_rearmed_display_internal_fps"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + display_internal_fps = false; + else if (strcmp(var.value, "enabled") == 0) + display_internal_fps = true; + } + + // + // CPU emulation related config #ifndef DRC_DISABLE var.value = NULL; var.key = "pcsx_rearmed_drc"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (!environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) + var.value = "enabled"; + { R3000Acpu *prev_cpu = psxCpu; +#if defined(LIGHTREC) + bool can_use_dynarec = found_bios; +#else + bool can_use_dynarec = 1; +#endif - if (strcmp(var.value, "disabled") == 0) +#ifdef _3DS + if (!__ctr_svchax) + Config.Cpu = CPU_INTERPRETER; + else +#endif + if (strcmp(var.value, "disabled") == 0 || !can_use_dynarec) Config.Cpu = CPU_INTERPRETER; else if (strcmp(var.value, "enabled") == 0) Config.Cpu = CPU_DYNAREC; psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec; - if (psxCpu != prev_cpu) { + if (psxCpu != prev_cpu) + { prev_cpu->Shutdown(); psxCpu->Init(); psxCpu->Reset(); // not really a reset.. } } -#endif +#endif /* !DRC_DISABLE */ + + var.value = NULL; + var.key = "pcsx_rearmed_psxclock"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + int psxclock = atoi(var.value); + Config.cycle_multiplier = 10000 / psxclock; + } + +#if !defined(DRC_DISABLE) && !defined(LIGHTREC) + var.value = NULL; + var.key = "pcsx_rearmed_nosmccheck"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + new_dynarec_hacks |= NDHACK_NO_SMC_CHECK; + else + new_dynarec_hacks &= ~NDHACK_NO_SMC_CHECK; + } + + var.value = NULL; + var.key = "pcsx_rearmed_gteregsunneeded"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + new_dynarec_hacks |= NDHACK_GTE_UNNEEDED; + else + new_dynarec_hacks &= ~NDHACK_GTE_UNNEEDED; + } + + var.value = NULL; + var.key = "pcsx_rearmed_nogteflags"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + new_dynarec_hacks |= NDHACK_GTE_NO_FLAGS; + else + new_dynarec_hacks &= ~NDHACK_GTE_NO_FLAGS; + } + + var.value = NULL; + var.key = "pcsx_rearmed_nocompathacks"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + new_dynarec_hacks |= NDHACK_NO_COMPAT_HACKS; + else + new_dynarec_hacks &= ~NDHACK_NO_COMPAT_HACKS; + } +#endif /* !DRC_DISABLE && !LIGHTREC */ + + var.value = NULL; + var.key = "pcsx_rearmed_nostalls"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + Config.DisableStalls = 1; + else + Config.DisableStalls = 0; + } + + var.value = NULL; + var.key = "pcsx_rearmed_icache_emulation"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + Config.icache_emulation = 0; + else if (strcmp(var.value, "enabled") == 0) + Config.icache_emulation = 1; + } + psxCpu->ApplyConfig(); - var.value = "NULL"; + // end of CPU emu config + // + + var.value = NULL; var.key = "pcsx_rearmed_spu_reverb"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (strcmp(var.value, "off") == 0) + if (strcmp(var.value, "disabled") == 0) spu_config.iUseReverb = false; - else if (strcmp(var.value, "on") == 0) + else if (strcmp(var.value, "enabled") == 0) spu_config.iUseReverb = true; } - var.value = "NULL"; + var.value = NULL; var.key = "pcsx_rearmed_spu_interpolation"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "simple") == 0) spu_config.iUseInterpolation = 1; @@ -1091,103 +2074,739 @@ static void update_variables(bool in_flight) spu_config.iUseInterpolation = 0; } - if (in_flight) { +#ifndef _WIN32 + var.value = NULL; + var.key = "pcsx_rearmed_async_cd"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "async") == 0) + { + Config.AsyncCD = 1; + Config.CHD_Precache = 0; + } + else if (strcmp(var.value, "sync") == 0) + { + Config.AsyncCD = 0; + Config.CHD_Precache = 0; + } + else if (strcmp(var.value, "precache") == 0) + { + Config.AsyncCD = 0; + Config.CHD_Precache = 1; + } + } +#endif + + var.value = NULL; + var.key = "pcsx_rearmed_noxadecoding"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + Config.Xa = 1; + else + Config.Xa = 0; + } + + var.value = NULL; + var.key = "pcsx_rearmed_nocdaudio"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + Config.Cdda = 1; + else + Config.Cdda = 0; + } + +#ifdef THREAD_RENDERING + var.key = "pcsx_rearmed_gpu_thread_rendering"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + pl_rearmed_cbs.thread_rendering = THREAD_RENDERING_OFF; + else if (strcmp(var.value, "sync") == 0) + pl_rearmed_cbs.thread_rendering = THREAD_RENDERING_SYNC; + else if (strcmp(var.value, "async") == 0) + pl_rearmed_cbs.thread_rendering = THREAD_RENDERING_ASYNC; + } +#endif + +#ifdef GPU_PEOPS + var.value = NULL; + var.key = "pcsx_rearmed_gpu_peops_odd_even_bit"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + gpu_peops_fix |= GPU_PEOPS_ODD_EVEN_BIT; + } + + var.value = NULL; + var.key = "pcsx_rearmed_gpu_peops_expand_screen_width"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + gpu_peops_fix |= GPU_PEOPS_EXPAND_SCREEN_WIDTH; + } + + var.value = NULL; + var.key = "pcsx_rearmed_gpu_peops_ignore_brightness"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + gpu_peops_fix |= GPU_PEOPS_IGNORE_BRIGHTNESS; + } + + var.value = NULL; + var.key = "pcsx_rearmed_gpu_peops_disable_coord_check"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + gpu_peops_fix |= GPU_PEOPS_DISABLE_COORD_CHECK; + } + + var.value = NULL; + var.key = "pcsx_rearmed_gpu_peops_lazy_screen_update"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + gpu_peops_fix |= GPU_PEOPS_LAZY_SCREEN_UPDATE; + } + + var.value = NULL; + var.key = "pcsx_rearmed_gpu_peops_repeated_triangles"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + gpu_peops_fix |= GPU_PEOPS_REPEATED_TRIANGLES; + } + + var.value = NULL; + var.key = "pcsx_rearmed_gpu_peops_quads_with_triangles"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + gpu_peops_fix |= GPU_PEOPS_QUADS_WITH_TRIANGLES; + } + + var.value = NULL; + var.key = "pcsx_rearmed_gpu_peops_fake_busy_state"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "enabled") == 0) + gpu_peops_fix |= GPU_PEOPS_FAKE_BUSY_STATE; + } + + if (pl_rearmed_cbs.gpu_peops.dwActFixes != gpu_peops_fix) + pl_rearmed_cbs.gpu_peops.dwActFixes = gpu_peops_fix; +#endif + +#ifdef GPU_UNAI + /* Note: This used to be an option, but it only works + * (correctly) when running high resolution games + * (480i, 512i) and has been obsoleted by + * pcsx_rearmed_gpu_unai_scale_hires */ + pl_rearmed_cbs.gpu_unai.ilace_force = 0; + /* Note: This used to be an option, but it has no + * discernable effect and has been obsoleted by + * pcsx_rearmed_gpu_unai_scale_hires */ + pl_rearmed_cbs.gpu_unai.pixel_skip = 0; + + var.key = "pcsx_rearmed_gpu_unai_lighting"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + pl_rearmed_cbs.gpu_unai.lighting = 0; + else if (strcmp(var.value, "enabled") == 0) + pl_rearmed_cbs.gpu_unai.lighting = 1; + } + + var.key = "pcsx_rearmed_gpu_unai_fast_lighting"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + pl_rearmed_cbs.gpu_unai.fast_lighting = 0; + else if (strcmp(var.value, "enabled") == 0) + pl_rearmed_cbs.gpu_unai.fast_lighting = 1; + } + + var.key = "pcsx_rearmed_gpu_unai_blending"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + pl_rearmed_cbs.gpu_unai.blending = 0; + else if (strcmp(var.value, "enabled") == 0) + pl_rearmed_cbs.gpu_unai.blending = 1; + } + + var.key = "pcsx_rearmed_gpu_unai_scale_hires"; + var.value = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (strcmp(var.value, "disabled") == 0) + pl_rearmed_cbs.gpu_unai.scale_hires = 0; + else if (strcmp(var.value, "enabled") == 0) + pl_rearmed_cbs.gpu_unai.scale_hires = 1; + } +#endif // GPU_UNAI + + //This adjustment process gives the user the ability to manually align the mouse up better + //with where the shots are in the emulator. + + var.value = NULL; + var.key = "pcsx_rearmed_gunconadjustx"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + GunconAdjustX = atoi(var.value); + } + + var.value = NULL; + var.key = "pcsx_rearmed_gunconadjusty"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + GunconAdjustY = atoi(var.value); + } + + var.value = NULL; + var.key = "pcsx_rearmed_gunconadjustratiox"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + GunconAdjustRatioX = atof(var.value); + } + + var.value = NULL; + var.key = "pcsx_rearmed_gunconadjustratioy"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + GunconAdjustRatioY = atof(var.value); + } + + var.value = NULL; + var.key = "pcsx_rearmed_input_sensitivity"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + mouse_sensitivity = atof(var.value); + } + + if (in_flight) + { // inform core things about possible config changes plugin_call_rearmed_cbs(); - if (GPU_open != NULL && GPU_close != NULL) { + if (GPU_open != NULL && GPU_close != NULL) + { GPU_close(); GPU_open(&gpuDisp, "PCSX", NULL); } - dfinput_activate(); + /* Reinitialise frameskipping, if required */ + if (((frameskip_type != prev_frameskip_type))) + retro_set_audio_buff_status_cb(); + + /* dfinput_activate(); */ } + else + { + //not yet running + + //bootlogo display hack + if (found_bios) + { + var.value = NULL; + var.key = "pcsx_rearmed_show_bios_bootlogo"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + Config.SlowBoot = 0; + rebootemu = 0; + if (strcmp(var.value, "enabled") == 0) + { + Config.SlowBoot = 1; + rebootemu = 1; + } + } + } + } + + update_option_visibility(); } -void retro_run(void) +// Taken from beetle-psx-libretro +static uint16_t get_analog_button(int16_t ret, retro_input_state_t input_state_cb, int player_index, int id) { - int i; + // NOTE: Analog buttons were added Nov 2017. Not all front-ends support this + // feature (or pre-date it) so we need to handle this in a graceful way. + + // First, try and get an analog value using the new libretro API constant + uint16_t button = input_state_cb(player_index, + RETRO_DEVICE_ANALOG, + RETRO_DEVICE_INDEX_ANALOG_BUTTON, + id); + button = MIN(button / 128, 255); - input_poll_cb(); + if (button == 0) + { + // If we got exactly zero, we're either not pressing the button, or the front-end + // is not reporting analog values. We need to do a second check using the classic + // digital API method, to at least get some response - better than nothing. - bool updated = false; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) - update_variables(true); + // NOTE: If we're really just not holding the button, we're still going to get zero. - in_keystate = 0; - for (i = 0; i < RETRO_PSX_MAP_LEN; i++) - if (input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, i)) - in_keystate |= retro_psx_map[i]; - in_keystate <<= 16; - for (i = 0; i < RETRO_PSX_MAP_LEN; i++) - if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i)) - in_keystate |= retro_psx_map[i]; + button = (ret & (1 << id)) ? 255 : 0; + } - if (in_type1 == PSE_PAD_TYPE_ANALOGPAD) - { - in_a1[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128; - in_a1[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128; - in_a2[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128; - in_a2[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128; - } + return button; +} - stop = 0; - psxCpu->Execute(); +unsigned char axis_range_modifier(int16_t axis_value, bool is_square) +{ + float modifier_axis_range = 0; + + if (is_square) + { + modifier_axis_range = round((axis_value >> 8) / 0.785) + 128; + if (modifier_axis_range < 0) + { + modifier_axis_range = 0; + } + else if (modifier_axis_range > 255) + { + modifier_axis_range = 255; + } + } + else + { + modifier_axis_range = MIN(((axis_value >> 8) + 128), 255); + } - video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf : NULL, - vout_width, vout_height, vout_width * 2); - vout_fb_dirty = 0; + return modifier_axis_range; } -static bool try_use_bios(const char *path) +static void update_input_guncon(int port, int ret) { - FILE *f; - long size; - const char *name; + //ToDo: + //Core option for cursors for both players + //Separate pointer and lightgun control types + + //Mouse range is -32767 -> 32767 + //1% is about 655 + //Use the left analog stick field to store the absolute coordinates + //Fix cursor to top-left when gun is detected as "offscreen" + if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN) || input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD)) + { + in_analog_left[port][0] = -32767; + in_analog_left[port][1] = -32767; + } + else + { + int gunx = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X); + int guny = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y); + + in_analog_left[port][0] = (gunx * GunconAdjustRatioX) + (GunconAdjustX * 655); + in_analog_left[port][1] = (guny * GunconAdjustRatioY) + (GunconAdjustY * 655); + } + + //GUNCON has 3 controls, Trigger,A,B which equal Circle,Start,Cross - f = fopen(path, "rb"); - if (f == NULL) - return false; + // Trigger + if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER) || input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD)) + in_keystate[port] |= (1 << DKEY_CIRCLE); - fseek(f, 0, SEEK_END); - size = ftell(f); - fclose(f); + // A + if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_A)) + in_keystate[port] |= (1 << DKEY_START); - if (size != 512 * 1024) - return false; + // B + if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_B)) + in_keystate[port] |= (1 << DKEY_CROSS); + +} - name = strrchr(path, SLASH); - if (name++ == NULL) - name = path; - snprintf(Config.Bios, sizeof(Config.Bios), "%s", name); - return true; +static void update_input_negcon(int port, int ret) +{ + int lsx; + int rsy; + int negcon_i_rs; + int negcon_ii_rs; + float negcon_twist_amplitude; + + // Query digital inputs + // + // > Pad-Up + if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_UP)) + in_keystate[port] |= (1 << DKEY_UP); + // > Pad-Right + if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT)) + in_keystate[port] |= (1 << DKEY_RIGHT); + // > Pad-Down + if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN)) + in_keystate[port] |= (1 << DKEY_DOWN); + // > Pad-Left + if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) + in_keystate[port] |= (1 << DKEY_LEFT); + // > Start + if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_START)) + in_keystate[port] |= (1 << DKEY_START); + // > neGcon A + if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_A)) + in_keystate[port] |= (1 << DKEY_CIRCLE); + // > neGcon B + if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_X)) + in_keystate[port] |= (1 << DKEY_TRIANGLE); + // > neGcon R shoulder (digital) + if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_R)) + in_keystate[port] |= (1 << DKEY_R1); + // Query analog inputs + // + // From studying 'libpcsxcore/plugins.c' and 'frontend/plugin.c': + // >> pad->leftJoyX == in_analog_left[port][0] == NeGcon II + // >> pad->leftJoyY == in_analog_left[port][1] == NeGcon L + // >> pad->rightJoyX == in_analog_right[port][0] == NeGcon twist + // >> pad->rightJoyY == in_analog_right[port][1] == NeGcon I + // So we just have to map in_analog_left/right to more + // appropriate inputs... + // + // > NeGcon twist + // >> Get raw analog stick value and account for deadzone + lsx = input_state_cb(port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X); + if (lsx > negcon_deadzone) + lsx = lsx - negcon_deadzone; + else if (lsx < -negcon_deadzone) + lsx = lsx + negcon_deadzone; + else + lsx = 0; + // >> Convert to an 'amplitude' [-1.0,1.0] and adjust response + negcon_twist_amplitude = (float)lsx / (float)(NEGCON_RANGE - negcon_deadzone); + if (negcon_linearity == 2) + { + if (negcon_twist_amplitude < 0.0) + negcon_twist_amplitude = -(negcon_twist_amplitude * negcon_twist_amplitude); + else + negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude; + } + else if (negcon_linearity == 3) + negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude * negcon_twist_amplitude; + // >> Convert to final 'in_analog' integer value [0,255] + in_analog_right[port][0] = MAX(MIN((int)(negcon_twist_amplitude * 128.0f) + 128, 255), 0); + // > NeGcon I + II + // >> Handle right analog stick vertical axis mapping... + // - Up (-Y) == accelerate == neGcon I + // - Down (+Y) == brake == neGcon II + negcon_i_rs = 0; + negcon_ii_rs = 0; + rsy = input_state_cb(port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y); + if (rsy >= 0) + { + // Account for deadzone + // (Note: have never encountered a gamepad with significant differences + // in deadzone between left/right analog sticks, so use the regular 'twist' + // deadzone here) + if (rsy > negcon_deadzone) + rsy = rsy - negcon_deadzone; + else + rsy = 0; + // Convert to 'in_analog' integer value [0,255] + negcon_ii_rs = MIN((int)(((float)rsy / (float)(NEGCON_RANGE - negcon_deadzone)) * 255.0f), 255); + } + else + { + if (rsy < -negcon_deadzone) + rsy = -1 * (rsy + negcon_deadzone); + else + rsy = 0; + negcon_i_rs = MIN((int)(((float)rsy / (float)(NEGCON_RANGE - negcon_deadzone)) * 255.0f), 255); + } + // >> NeGcon I + in_analog_right[port][1] = MAX( + MAX( + get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_R2), + get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_B)), + negcon_i_rs); + // >> NeGcon II + in_analog_left[port][0] = MAX( + MAX( + get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_L2), + get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_Y)), + negcon_ii_rs); + // > NeGcon L + in_analog_left[port][1] = get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_L); +} + +static void update_input_mouse(int port, int ret) +{ + float raw_x = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); + float raw_y = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); + + int x = (int)roundf(raw_x * mouse_sensitivity); + int y = (int)roundf(raw_y * mouse_sensitivity); + + if (x > 127) x = 127; + else if (x < -128) x = -128; + + if (y > 127) y = 127; + else if (y < -128) y = -128; + + in_mouse[port][0] = x; /* -128..+128 left/right movement, 0 = no movement */ + in_mouse[port][1] = y; /* -128..+128 down/up movement, 0 = no movement */ + + /* left mouse button state */ + if (input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) + in_keystate[port] |= 1 << 11; + + /* right mouse button state */ + if (input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)) + in_keystate[port] |= 1 << 10; } -#if 1 +static void update_input(void) +{ + // reset all keystate, query libretro for keystate + int i; + int j; + + for (i = 0; i < PORTS_NUMBER; i++) + { + int16_t ret = 0; + int type = in_type[i]; + + in_keystate[i] = 0; + + if (type == PSE_PAD_TYPE_NONE) + continue; + + if (libretro_supports_bitmasks) + ret = input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK); + else + { + for (j = 0; j < (RETRO_DEVICE_ID_JOYPAD_R3 + 1); j++) + { + if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j)) + ret |= (1 << j); + } + } + + switch (type) + { + case PSE_PAD_TYPE_GUNCON: + update_input_guncon(i, ret); + break; + case PSE_PAD_TYPE_NEGCON: + update_input_negcon(i, ret); + break; + case PSE_PAD_TYPE_MOUSE: + update_input_mouse(i, ret); + break; + default: + // Query digital inputs + for (j = 0; j < RETRO_PSX_MAP_LEN; j++) + if (ret & (1 << j)) + in_keystate[i] |= retro_psx_map[j]; + + // Query analog inputs + if (type == PSE_PAD_TYPE_ANALOGJOY || type == PSE_PAD_TYPE_ANALOGPAD) + { + in_analog_left[i][0] = axis_range_modifier(input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X), axis_bounds_modifier); + in_analog_left[i][1] = axis_range_modifier(input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y), axis_bounds_modifier); + in_analog_right[i][0] = axis_range_modifier(input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X), axis_bounds_modifier); + in_analog_right[i][1] = axis_range_modifier(input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y), axis_bounds_modifier); + } + } + } +} + +static void print_internal_fps(void) +{ + if (display_internal_fps) + { + frame_count++; + + if (frame_count % INTERNAL_FPS_SAMPLE_PERIOD == 0) + { + unsigned internal_fps = pl_rearmed_cbs.flip_cnt * (is_pal_mode ? 50 : 60) / INTERNAL_FPS_SAMPLE_PERIOD; + char str[64]; + const char *strc = (const char *)str; + + str[0] = '\0'; + + snprintf(str, sizeof(str), "Internal FPS: %2d", internal_fps); + + pl_rearmed_cbs.flip_cnt = 0; + + if (msg_interface_version >= 1) + { + struct retro_message_ext msg = { + strc, + 3000, + 1, + RETRO_LOG_INFO, + RETRO_MESSAGE_TARGET_OSD, + RETRO_MESSAGE_TYPE_STATUS, + -1 + }; + environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg); + } + else + { + struct retro_message msg = { + strc, + 180 + }; + environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); + } + } + } + else + frame_count = 0; +} + +void retro_run(void) +{ + //SysReset must be run while core is running,Not in menu (Locks up Retroarch) + if (rebootemu != 0) + { + rebootemu = 0; + SysReset(); + if (!Config.HLE && !Config.SlowBoot) + { + // skip BIOS logos + psxRegs.pc = psxRegs.GPR.n.ra; + } + return; + } + + print_internal_fps(); + + /* Check whether current frame should + * be skipped */ + pl_rearmed_cbs.fskip_force = 0; + pl_rearmed_cbs.fskip_dirty = 0; + + if (frameskip_type != FRAMESKIP_NONE) + { + bool skip_frame = false; + + switch (frameskip_type) + { + case FRAMESKIP_AUTO: + skip_frame = retro_audio_buff_active && retro_audio_buff_underrun; + break; + case FRAMESKIP_AUTO_THRESHOLD: + skip_frame = retro_audio_buff_active && (retro_audio_buff_occupancy < frameskip_threshold); + break; + case FRAMESKIP_FIXED_INTERVAL: + skip_frame = true; + break; + default: + break; + } + + if (skip_frame && frameskip_counter < frameskip_interval) + pl_rearmed_cbs.fskip_force = 1; + } + + /* If frameskip/timing settings have changed, + * update frontend audio latency + * > Can do this before or after the frameskip + * check, but doing it after means we at least + * retain the current frame's audio output */ + if (update_audio_latency) + { + environ_cb(RETRO_ENVIRONMENT_SET_MINIMUM_AUDIO_LATENCY, + &retro_audio_latency); + update_audio_latency = false; + } + + input_poll_cb(); + + update_input(); + + bool updated = false; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) + update_variables(true); + + stop = 0; + psxCpu->Execute(); + + if (pl_rearmed_cbs.fskip_dirty == 1) { + if (frameskip_counter < frameskip_interval) + frameskip_counter++; + else if (frameskip_counter >= frameskip_interval || !pl_rearmed_cbs.fskip_force) + frameskip_counter = 0; + } + + video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf_ptr : NULL, + vout_width, vout_height, vout_width * 2); + vout_fb_dirty = 0; + + set_vout_fb(); +} + +static bool try_use_bios(const char *path) +{ + long size; + const char *name; + FILE *fp = fopen(path, "rb"); + if (fp == NULL) + return false; + + fseek(fp, 0, SEEK_END); + size = ftell(fp); + fclose(fp); + + if (size != 512 * 1024) + return false; + + name = strrchr(path, SLASH); + if (name++ == NULL) + name = path; + snprintf(Config.Bios, sizeof(Config.Bios), "%s", name); + return true; +} + +#ifndef VITA #include #include static bool find_any_bios(const char *dirpath, char *path, size_t path_size) { - DIR *dir; - struct dirent *ent; - bool ret = false; + DIR *dir; + struct dirent *ent; + bool ret = false; - dir = opendir(dirpath); - if (dir == NULL) - return false; + dir = opendir(dirpath); + if (dir == NULL) + return false; - while ((ent = readdir(dir))) { - if (strncasecmp(ent->d_name, "scph", 4) != 0) - continue; + while ((ent = readdir(dir))) + { + if ((strncasecmp(ent->d_name, "scph", 4) != 0) && (strncasecmp(ent->d_name, "psx", 3) != 0)) + continue; - snprintf(path, path_size, "%s/%s", dirpath, ent->d_name); - ret = try_use_bios(path); - if (ret) - break; - } - closedir(dir); - return ret; + snprintf(path, path_size, "%s%c%s", dirpath, SLASH, ent->d_name); + ret = try_use_bios(path); + if (ret) + break; + } + closedir(dir); + return ret; } #else #define find_any_bios(...) false @@ -1199,91 +2818,303 @@ static void check_system_specs(void) environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level); } +static int init_memcards(void) +{ + int ret = 0; + const char *dir; + struct retro_variable var = { .key = "pcsx_rearmed_memcard2", .value = NULL }; + static const char CARD2_FILE[] = "pcsx-card2.mcd"; + + // Memcard2 will be handled and is re-enabled if needed using core + // operations. + // Memcard1 is handled by libretro, doing this will set core to + // skip file io operations for memcard1 like SaveMcd + snprintf(Config.Mcd1, sizeof(Config.Mcd1), "none"); + snprintf(Config.Mcd2, sizeof(Config.Mcd2), "none"); + init_memcard(Mcd1Data); + // Memcard 2 is managed by the emulator on the filesystem, + // There is no need to initialize Mcd2Data like Mcd1Data. + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + SysPrintf("Memcard 2: %s\n", var.value); + if (memcmp(var.value, "enabled", 7) == 0) + { + if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) + { + if (strlen(dir) + strlen(CARD2_FILE) + 2 > sizeof(Config.Mcd2)) + { + SysPrintf("Path '%s' is too long. Cannot use memcard 2. Use a shorter path.\n", dir); + ret = -1; + } + else + { + McdDisable[1] = 0; + snprintf(Config.Mcd2, sizeof(Config.Mcd2), "%s/%s", dir, CARD2_FILE); + SysPrintf("Use memcard 2: %s\n", Config.Mcd2); + } + } + else + { + SysPrintf("Could not get save directory! Could not create memcard 2."); + ret = -1; + } + } + } + return ret; +} + +static void loadPSXBios(void) +{ + const char *dir; + char path[PATH_MAX]; + unsigned useHLE = 0; + + const char *bios[] = { + "PSXONPSP660", "psxonpsp660", + "SCPH101", "scph101", + "SCPH5501", "scph5501", + "SCPH7001", "scph7001", + "SCPH1001", "scph1001" + }; + + struct retro_variable var = { + .key = "pcsx_rearmed_bios", + .value = NULL + }; + + found_bios = 0; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + { + if (!strcmp(var.value, "HLE")) + useHLE = 1; + } + + if (!useHLE) + { + if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) + { + unsigned i; + snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir); + + for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) + { + snprintf(path, sizeof(path), "%s%c%s.bin", dir, SLASH, bios[i]); + found_bios = try_use_bios(path); + if (found_bios) + break; + } + + if (!found_bios) + found_bios = find_any_bios(dir, path, sizeof(path)); + } + if (found_bios) + { + SysPrintf("found BIOS file: %s\n", Config.Bios); + } + } + + if (!found_bios) + { + const char *msg_str; + if (useHLE) + { + msg_str = "BIOS set to \'hle\' in core options - real BIOS will be ignored"; + SysPrintf("Using HLE BIOS.\n"); + } + else + { + msg_str = "No PlayStation BIOS file found - add for better compatibility"; + SysPrintf("No BIOS files found.\n"); + } + + if (msg_interface_version >= 1) + { + struct retro_message_ext msg = { + msg_str, + 3000, + 3, + RETRO_LOG_WARN, + RETRO_MESSAGE_TARGET_ALL, + RETRO_MESSAGE_TYPE_NOTIFICATION, + -1 + }; + environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg); + } + else + { + struct retro_message msg = { + msg_str, + 180 + }; + environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); + } + } +} + void retro_init(void) { - const char *bios[] = { "scph1001", "scph5501", "scph7001" }; - const char *dir; - char path[256]; - int i, ret; - bool found_bios = false; + unsigned dci_version = 0; + struct retro_rumble_interface rumble; + int ret; -#ifdef __MACH__ - // magic sauce to make the dynarec work on iOS - syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0); + msg_interface_version = 0; + environ_cb(RETRO_ENVIRONMENT_GET_MESSAGE_INTERFACE_VERSION, &msg_interface_version); + +#if defined(__MACH__) && !defined(TVOS) + // magic sauce to make the dynarec work on iOS + syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0); #endif - ret = emu_core_preinit(); - ret |= emu_core_init(); - if (ret != 0) { - SysPrintf("PCSX init failed.\n"); - exit(1); - } +#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 + /* emu_core_preinit sets the cpu to dynarec */ + if (!__ctr_svchax) + Config.Cpu = CPU_INTERPRETER; +#endif + ret |= init_memcards(); -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) - posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); + ret |= emu_core_init(); + if (ret != 0) + { + SysPrintf("PCSX init failed.\n"); + exit(1); + } + +#ifdef _3DS + vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80); +#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA) && !defined(__SWITCH__) + if (posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2) != 0) + vout_buf = (void *) 0; #else - vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); + vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); #endif - if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && 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]); - found_bios = try_use_bios(path); - if (found_bios) - break; - } - - if (!found_bios) - found_bios = find_any_bios(dir, path, sizeof(path)); - } - if (found_bios) { - SysPrintf("found BIOS file: %s\n", Config.Bios); - } - else - { - SysPrintf("no BIOS files found.\n"); - struct retro_message msg = - { - "no BIOS found, expect bugs!", - 180 - }; - environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg); - } - - environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe); - environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control); - environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble); - - /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times) - * we have to do this because cache misses and some IO penalties - * are not emulated. Warning: changing this may break compatibility. */ - cycle_multiplier = 175; -#ifdef HAVE_PRE_ARMV7 - cycle_multiplier = 200; + vout_buf_ptr = vout_buf; + + loadPSXBios(); + + environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe); + + disk_initial_index = 0; + disk_initial_path[0] = '\0'; + if (environ_cb(RETRO_ENVIRONMENT_GET_DISK_CONTROL_INTERFACE_VERSION, &dci_version) && (dci_version >= 1)) + environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE, &disk_control_ext); + else + environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control); + + rumble_cb = NULL; + if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble)) + rumble_cb = rumble.set_rumble_state; + + /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times) + * we have to do this because cache misses and some IO penalties + * are not emulated. Warning: changing this may break compatibility. */ + Config.cycle_multiplier = CYCLE_MULT_DEFAULT; +#if defined(HAVE_PRE_ARMV7) && !defined(_3DS) + Config.cycle_multiplier = 200; #endif - pl_rearmed_cbs.gpu_peops.iUseDither = 1; - spu_config.iUseFixedUpdates = 1; + pl_rearmed_cbs.gpu_peops.iUseDither = 1; + pl_rearmed_cbs.gpu_peops.dwActFixes = GPU_PEOPS_OLD_FRAME_SKIP; + spu_config.iUseFixedUpdates = 1; - McdDisable[0] = 0; - McdDisable[1] = 1; - init_memcard(Mcd1Data); + SaveFuncs.open = save_open; + SaveFuncs.read = save_read; + SaveFuncs.write = save_write; + SaveFuncs.seek = save_seek; + SaveFuncs.close = save_close; - SaveFuncs.open = save_open; - SaveFuncs.read = save_read; - SaveFuncs.write = save_write; - SaveFuncs.seek = save_seek; - SaveFuncs.close = save_close; + if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL)) + libretro_supports_bitmasks = true; - update_variables(false); - check_system_specs(); + check_system_specs(); } void retro_deinit(void) { - SysClose(); - free(vout_buf); - vout_buf = NULL; + if (plugins_opened) + { + ClosePlugins(); + plugins_opened = 0; + } + SysClose(); +#ifdef _3DS + linearFree(vout_buf); +#else + free(vout_buf); +#endif + vout_buf = NULL; + +#ifdef VITA + deinit_vita_mmap(); +#endif + libretro_supports_bitmasks = false; + libretro_supports_option_categories = false; + + show_input_settings = true; +#ifdef GPU_PEOPS + show_advanced_gpu_peops_settings = true; +#endif +#ifdef GPU_UNAI + show_advanced_gpu_unai_settings = true; +#endif + + /* Have to reset disks struct, otherwise + * fnames/flabels will leak memory */ + disk_init(); + frameskip_type = FRAMESKIP_NONE; + frameskip_threshold = 0; + frameskip_interval = 0; + frameskip_counter = 0; + retro_audio_buff_active = false; + retro_audio_buff_occupancy = 0; + retro_audio_buff_underrun = false; + retro_audio_latency = 0; + update_audio_latency = false; +} + +#ifdef VITA +#include +int usleep(unsigned long us) +{ + sceKernelDelayThread(us); +} +#endif + +void SysPrintf(const char *fmt, ...) +{ + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + if (log_cb) + log_cb(RETRO_LOG_INFO, "%s", msg); +} + +/* Prints debug-level logs */ +void SysDLog(const char *fmt, ...) +{ + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + if (log_cb) + log_cb(RETRO_LOG_DEBUG, "%s", msg); } diff --git a/frontend/libretro.h b/frontend/libretro.h deleted file mode 100755 index 16c274a1..00000000 --- a/frontend/libretro.h +++ /dev/null @@ -1,1926 +0,0 @@ -/* Copyright (C) 2010-2014 The RetroArch team - * - * --------------------------------------------------------------------------------------- - * The following license statement only applies to this libretro API header (libretro.h). - * --------------------------------------------------------------------------------------- - * - * Permission is hereby granted, free of charge, - * to any person obtaining a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef LIBRETRO_H__ -#define LIBRETRO_H__ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef __cplusplus -#if defined(_MSC_VER) && !defined(SN_TARGET_PS3) -/* Hack applied for MSVC when compiling in C89 mode - * as it isn't C99-compliant. */ -#define bool unsigned char -#define true 1 -#define false 0 -#else -#include -#endif -#endif - -/* Used for checking API/ABI mismatches that can break libretro - * implementations. - * It is not incremented for compatible changes to the API. - */ -#define RETRO_API_VERSION 1 - -/* - * Libretro's fundamental device abstractions. - * - * Libretro's input system consists of some standardized device types, - * such as a joypad (with/without analog), mouse, keyboard, lightgun - * and a pointer. - * - * The functionality of these devices are fixed, and individual cores - * map their own concept of a controller to libretro's abstractions. - * This makes it possible for frontends to map the abstract types to a - * real input device, and not having to worry about binding input - * correctly to arbitrary controller layouts. - */ - -#define RETRO_DEVICE_TYPE_SHIFT 8 -#define RETRO_DEVICE_MASK ((1 << RETRO_DEVICE_TYPE_SHIFT) - 1) -#define RETRO_DEVICE_SUBCLASS(base, id) (((id + 1) << RETRO_DEVICE_TYPE_SHIFT) | base) - -/* Input disabled. */ -#define RETRO_DEVICE_NONE 0 - -/* The JOYPAD is called RetroPad. It is essentially a Super Nintendo - * controller, but with additional L2/R2/L3/R3 buttons, similar to a - * PS1 DualShock. */ -#define RETRO_DEVICE_JOYPAD 1 - -/* The mouse is a simple mouse, similar to Super Nintendo's mouse. - * X and Y coordinates are reported relatively to last poll (poll callback). - * It is up to the libretro implementation to keep track of where the mouse - * pointer is supposed to be on the screen. - * The frontend must make sure not to interfere with its own hardware - * mouse pointer. - */ -#define RETRO_DEVICE_MOUSE 2 - -/* KEYBOARD device lets one poll for raw key pressed. - * It is poll based, so input callback will return with the current - * pressed state. - * For event/text based keyboard input, see - * RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. - */ -#define RETRO_DEVICE_KEYBOARD 3 - -/* Lightgun X/Y coordinates are reported relatively to last poll, - * similar to mouse. */ -#define RETRO_DEVICE_LIGHTGUN 4 - -/* The ANALOG device is an extension to JOYPAD (RetroPad). - * Similar to DualShock it adds two analog sticks. - * This is treated as a separate device type as it returns values in the - * full analog range of [-0x8000, 0x7fff]. Positive X axis is right. - * Positive Y axis is down. - * Only use ANALOG type when polling for analog values of the axes. - */ -#define RETRO_DEVICE_ANALOG 5 - -/* Abstracts the concept of a pointing mechanism, e.g. touch. - * This allows libretro to query in absolute coordinates where on the - * screen a mouse (or something similar) is being placed. - * For a touch centric device, coordinates reported are the coordinates - * of the press. - * - * Coordinates in X and Y are reported as: - * [-0x7fff, 0x7fff]: -0x7fff corresponds to the far left/top of the screen, - * and 0x7fff corresponds to the far right/bottom of the screen. - * The "screen" is here defined as area that is passed to the frontend and - * later displayed on the monitor. - * - * The frontend is free to scale/resize this screen as it sees fit, however, - * (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the - * game image, etc. - * - * To check if the pointer coordinates are valid (e.g. a touch display - * actually being touched), PRESSED returns 1 or 0. - * - * If using a mouse on a desktop, PRESSED will usually correspond to the - * left mouse button, but this is a frontend decision. - * PRESSED will only return 1 if the pointer is inside the game screen. - * - * For multi-touch, the index variable can be used to successively query - * more presses. - * If index = 0 returns true for _PRESSED, coordinates can be extracted - * with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with - * index = 1, and so on. - * Eventually _PRESSED will return false for an index. No further presses - * are registered at this point. */ -#define RETRO_DEVICE_POINTER 6 - -/* Buttons for the RetroPad (JOYPAD). - * The placement of these is equivalent to placements on the - * Super Nintendo controller. - * L2/R2/L3/R3 buttons correspond to the PS1 DualShock. */ -#define RETRO_DEVICE_ID_JOYPAD_B 0 -#define RETRO_DEVICE_ID_JOYPAD_Y 1 -#define RETRO_DEVICE_ID_JOYPAD_SELECT 2 -#define RETRO_DEVICE_ID_JOYPAD_START 3 -#define RETRO_DEVICE_ID_JOYPAD_UP 4 -#define RETRO_DEVICE_ID_JOYPAD_DOWN 5 -#define RETRO_DEVICE_ID_JOYPAD_LEFT 6 -#define RETRO_DEVICE_ID_JOYPAD_RIGHT 7 -#define RETRO_DEVICE_ID_JOYPAD_A 8 -#define RETRO_DEVICE_ID_JOYPAD_X 9 -#define RETRO_DEVICE_ID_JOYPAD_L 10 -#define RETRO_DEVICE_ID_JOYPAD_R 11 -#define RETRO_DEVICE_ID_JOYPAD_L2 12 -#define RETRO_DEVICE_ID_JOYPAD_R2 13 -#define RETRO_DEVICE_ID_JOYPAD_L3 14 -#define RETRO_DEVICE_ID_JOYPAD_R3 15 - -/* Index / Id values for ANALOG device. */ -#define RETRO_DEVICE_INDEX_ANALOG_LEFT 0 -#define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1 -#define RETRO_DEVICE_ID_ANALOG_X 0 -#define RETRO_DEVICE_ID_ANALOG_Y 1 - -/* Id values for MOUSE. */ -#define RETRO_DEVICE_ID_MOUSE_X 0 -#define RETRO_DEVICE_ID_MOUSE_Y 1 -#define RETRO_DEVICE_ID_MOUSE_LEFT 2 -#define RETRO_DEVICE_ID_MOUSE_RIGHT 3 -#define RETRO_DEVICE_ID_MOUSE_WHEELUP 4 -#define RETRO_DEVICE_ID_MOUSE_WHEELDOWN 5 -#define RETRO_DEVICE_ID_MOUSE_MIDDLE 6 - -/* Id values for LIGHTGUN types. */ -#define RETRO_DEVICE_ID_LIGHTGUN_X 0 -#define RETRO_DEVICE_ID_LIGHTGUN_Y 1 -#define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER 2 -#define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3 -#define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4 -#define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5 -#define RETRO_DEVICE_ID_LIGHTGUN_START 6 - -/* Id values for POINTER. */ -#define RETRO_DEVICE_ID_POINTER_X 0 -#define RETRO_DEVICE_ID_POINTER_Y 1 -#define RETRO_DEVICE_ID_POINTER_PRESSED 2 - -/* Returned from retro_get_region(). */ -#define RETRO_REGION_NTSC 0 -#define RETRO_REGION_PAL 1 - -/* Id values for LANGUAGE */ -enum retro_language -{ - RETRO_LANGUAGE_ENGLISH = 0, - RETRO_LANGUAGE_JAPANESE = 1, - RETRO_LANGUAGE_FRENCH = 2, - RETRO_LANGUAGE_SPANISH = 3, - RETRO_LANGUAGE_GERMAN = 4, - RETRO_LANGUAGE_ITALIAN = 5, - RETRO_LANGUAGE_DUTCH = 6, - RETRO_LANGUAGE_PORTUGUESE = 7, - RETRO_LANGUAGE_RUSSIAN = 8, - RETRO_LANGUAGE_KOREAN = 9, - RETRO_LANGUAGE_CHINESE_TRADITIONAL = 10, - RETRO_LANGUAGE_CHINESE_SIMPLIFIED = 11, - RETRO_LANGUAGE_LAST, - - /* Ensure sizeof(enum) == sizeof(int) */ - RETRO_LANGUAGE_DUMMY = INT_MAX -}; - -/* Passed to retro_get_memory_data/size(). - * If the memory type doesn't apply to the - * implementation NULL/0 can be returned. - */ -#define RETRO_MEMORY_MASK 0xff - -/* Regular save RAM. This RAM is usually found on a game cartridge, - * backed up by a battery. - * If save game data is too complex for a single memory buffer, - * the SAVE_DIRECTORY (preferably) or SYSTEM_DIRECTORY environment - * callback can be used. */ -#define RETRO_MEMORY_SAVE_RAM 0 - -/* Some games have a built-in clock to keep track of time. - * This memory is usually just a couple of bytes to keep track of time. - */ -#define RETRO_MEMORY_RTC 1 - -/* System ram lets a frontend peek into a game systems main RAM. */ -#define RETRO_MEMORY_SYSTEM_RAM 2 - -/* Video ram lets a frontend peek into a game systems video RAM (VRAM). */ -#define RETRO_MEMORY_VIDEO_RAM 3 - -/* Keysyms used for ID in input state callback when polling RETRO_KEYBOARD. */ -enum retro_key -{ - RETROK_UNKNOWN = 0, - RETROK_FIRST = 0, - RETROK_BACKSPACE = 8, - RETROK_TAB = 9, - RETROK_CLEAR = 12, - RETROK_RETURN = 13, - RETROK_PAUSE = 19, - RETROK_ESCAPE = 27, - RETROK_SPACE = 32, - RETROK_EXCLAIM = 33, - RETROK_QUOTEDBL = 34, - RETROK_HASH = 35, - RETROK_DOLLAR = 36, - RETROK_AMPERSAND = 38, - RETROK_QUOTE = 39, - RETROK_LEFTPAREN = 40, - RETROK_RIGHTPAREN = 41, - RETROK_ASTERISK = 42, - RETROK_PLUS = 43, - RETROK_COMMA = 44, - RETROK_MINUS = 45, - RETROK_PERIOD = 46, - RETROK_SLASH = 47, - RETROK_0 = 48, - RETROK_1 = 49, - RETROK_2 = 50, - RETROK_3 = 51, - RETROK_4 = 52, - RETROK_5 = 53, - RETROK_6 = 54, - RETROK_7 = 55, - RETROK_8 = 56, - RETROK_9 = 57, - RETROK_COLON = 58, - RETROK_SEMICOLON = 59, - RETROK_LESS = 60, - RETROK_EQUALS = 61, - RETROK_GREATER = 62, - RETROK_QUESTION = 63, - RETROK_AT = 64, - RETROK_LEFTBRACKET = 91, - RETROK_BACKSLASH = 92, - RETROK_RIGHTBRACKET = 93, - RETROK_CARET = 94, - RETROK_UNDERSCORE = 95, - RETROK_BACKQUOTE = 96, - RETROK_a = 97, - RETROK_b = 98, - RETROK_c = 99, - RETROK_d = 100, - RETROK_e = 101, - RETROK_f = 102, - RETROK_g = 103, - RETROK_h = 104, - RETROK_i = 105, - RETROK_j = 106, - RETROK_k = 107, - RETROK_l = 108, - RETROK_m = 109, - RETROK_n = 110, - RETROK_o = 111, - RETROK_p = 112, - RETROK_q = 113, - RETROK_r = 114, - RETROK_s = 115, - RETROK_t = 116, - RETROK_u = 117, - RETROK_v = 118, - RETROK_w = 119, - RETROK_x = 120, - RETROK_y = 121, - RETROK_z = 122, - RETROK_DELETE = 127, - - RETROK_KP0 = 256, - RETROK_KP1 = 257, - RETROK_KP2 = 258, - RETROK_KP3 = 259, - RETROK_KP4 = 260, - RETROK_KP5 = 261, - RETROK_KP6 = 262, - RETROK_KP7 = 263, - RETROK_KP8 = 264, - RETROK_KP9 = 265, - RETROK_KP_PERIOD = 266, - RETROK_KP_DIVIDE = 267, - RETROK_KP_MULTIPLY = 268, - RETROK_KP_MINUS = 269, - RETROK_KP_PLUS = 270, - RETROK_KP_ENTER = 271, - RETROK_KP_EQUALS = 272, - - RETROK_UP = 273, - RETROK_DOWN = 274, - RETROK_RIGHT = 275, - RETROK_LEFT = 276, - RETROK_INSERT = 277, - RETROK_HOME = 278, - RETROK_END = 279, - RETROK_PAGEUP = 280, - RETROK_PAGEDOWN = 281, - - RETROK_F1 = 282, - RETROK_F2 = 283, - RETROK_F3 = 284, - RETROK_F4 = 285, - RETROK_F5 = 286, - RETROK_F6 = 287, - RETROK_F7 = 288, - RETROK_F8 = 289, - RETROK_F9 = 290, - RETROK_F10 = 291, - RETROK_F11 = 292, - RETROK_F12 = 293, - RETROK_F13 = 294, - RETROK_F14 = 295, - RETROK_F15 = 296, - - RETROK_NUMLOCK = 300, - RETROK_CAPSLOCK = 301, - RETROK_SCROLLOCK = 302, - RETROK_RSHIFT = 303, - RETROK_LSHIFT = 304, - RETROK_RCTRL = 305, - RETROK_LCTRL = 306, - RETROK_RALT = 307, - RETROK_LALT = 308, - RETROK_RMETA = 309, - RETROK_LMETA = 310, - RETROK_LSUPER = 311, - RETROK_RSUPER = 312, - RETROK_MODE = 313, - RETROK_COMPOSE = 314, - - RETROK_HELP = 315, - RETROK_PRINT = 316, - RETROK_SYSREQ = 317, - RETROK_BREAK = 318, - RETROK_MENU = 319, - RETROK_POWER = 320, - RETROK_EURO = 321, - RETROK_UNDO = 322, - - RETROK_LAST, - - RETROK_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */ -}; - -enum retro_mod -{ - RETROKMOD_NONE = 0x0000, - - RETROKMOD_SHIFT = 0x01, - RETROKMOD_CTRL = 0x02, - RETROKMOD_ALT = 0x04, - RETROKMOD_META = 0x08, - - RETROKMOD_NUMLOCK = 0x10, - RETROKMOD_CAPSLOCK = 0x20, - RETROKMOD_SCROLLOCK = 0x40, - - RETROKMOD_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */ -}; - -/* If set, this call is not part of the public libretro API yet. It can - * change or be removed at any time. */ -#define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000 -/* Environment callback to be used internally in frontend. */ -#define RETRO_ENVIRONMENT_PRIVATE 0x20000 - -/* Environment commands. */ -#define RETRO_ENVIRONMENT_SET_ROTATION 1 /* const unsigned * -- - * Sets screen rotation of graphics. - * Is only implemented if rotation can be accelerated by hardware. - * Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180, - * 270 degrees counter-clockwise respectively. - */ -#define RETRO_ENVIRONMENT_GET_OVERSCAN 2 /* bool * -- - * Boolean value whether or not the implementation should use overscan, - * or crop away overscan. - */ -#define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 /* bool * -- - * Boolean value whether or not frontend supports frame duping, - * passing NULL to video frame callback. - */ - - /* Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES), - * and reserved to avoid possible ABI clash. - */ - -#define RETRO_ENVIRONMENT_SET_MESSAGE 6 /* const struct retro_message * -- - * Sets a message to be displayed in implementation-specific manner - * for a certain amount of 'frames'. - * Should not be used for trivial messages, which should simply be - * logged via RETRO_ENVIRONMENT_GET_LOG_INTERFACE (or as a - * fallback, stderr). - */ -#define RETRO_ENVIRONMENT_SHUTDOWN 7 /* N/A (NULL) -- - * Requests the frontend to shutdown. - * Should only be used if game has a specific - * way to shutdown the game from a menu item or similar. - */ -#define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8 - /* const unsigned * -- - * Gives a hint to the frontend how demanding this implementation - * is on a system. E.g. reporting a level of 2 means - * this implementation should run decently on all frontends - * of level 2 and up. - * - * It can be used by the frontend to potentially warn - * about too demanding implementations. - * - * The levels are "floating". - * - * This function can be called on a per-game basis, - * as certain games an implementation can play might be - * particularly demanding. - * If called, it should be called in retro_load_game(). - */ -#define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9 - /* const char ** -- - * Returns the "system" directory of the frontend. - * This directory can be used to store system specific - * content such as BIOSes, configuration data, etc. - * The returned value can be NULL. - * If so, no such directory is defined, - * and it's up to the implementation to find a suitable directory. - * - * NOTE: Some cores used this folder also for "save" data such as - * memory cards, etc, for lack of a better place to put it. - * This is now discouraged, and if possible, cores should try to - * use the new GET_SAVE_DIRECTORY. - */ -#define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10 - /* const enum retro_pixel_format * -- - * Sets the internal pixel format used by the implementation. - * The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555. - * This pixel format however, is deprecated (see enum retro_pixel_format). - * If the call returns false, the frontend does not support this pixel - * format. - * - * This function should be called inside retro_load_game() or - * retro_get_system_av_info(). - */ -#define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11 - /* const struct retro_input_descriptor * -- - * Sets an array of retro_input_descriptors. - * It is up to the frontend to present this in a usable way. - * The array is terminated by retro_input_descriptor::description - * being set to NULL. - * This function can be called at any time, but it is recommended - * to call it as early as possible. - */ -#define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12 - /* const struct retro_keyboard_callback * -- - * Sets a callback function used to notify core about keyboard events. - */ -#define RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE 13 - /* const struct retro_disk_control_callback * -- - * Sets an interface which frontend can use to eject and insert - * disk images. - * This is used for games which consist of multiple images and - * must be manually swapped out by the user (e.g. PSX). - */ -#define RETRO_ENVIRONMENT_SET_HW_RENDER 14 - /* struct retro_hw_render_callback * -- - * Sets an interface to let a libretro core render with - * hardware acceleration. - * Should be called in retro_load_game(). - * If successful, libretro cores will be able to render to a - * frontend-provided framebuffer. - * The size of this framebuffer will be at least as large as - * max_width/max_height provided in get_av_info(). - * If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or - * NULL to retro_video_refresh_t. - */ -#define RETRO_ENVIRONMENT_GET_VARIABLE 15 - /* struct retro_variable * -- - * Interface to acquire user-defined information from environment - * that cannot feasibly be supported in a multi-system way. - * 'key' should be set to a key which has already been set by - * SET_VARIABLES. - * 'data' will be set to a value or NULL. - */ -#define RETRO_ENVIRONMENT_SET_VARIABLES 16 - /* const struct retro_variable * -- - * Allows an implementation to signal the environment - * which variables it might want to check for later using - * GET_VARIABLE. - * This allows the frontend to present these variables to - * a user dynamically. - * This should be called as early as possible (ideally in - * retro_set_environment). - * - * 'data' points to an array of retro_variable structs - * terminated by a { NULL, NULL } element. - * retro_variable::key should be namespaced to not collide - * with other implementations' keys. E.g. A core called - * 'foo' should use keys named as 'foo_option'. - * retro_variable::value should contain a human readable - * description of the key as well as a '|' delimited list - * of expected values. - * - * The number of possible options should be very limited, - * i.e. it should be feasible to cycle through options - * without a keyboard. - * - * First entry should be treated as a default. - * - * Example entry: - * { "foo_option", "Speed hack coprocessor X; false|true" } - * - * Text before first ';' is description. This ';' must be - * followed by a space, and followed by a list of possible - * values split up with '|'. - * - * Only strings are operated on. The possible values will - * generally be displayed and stored as-is by the frontend. - */ -#define RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE 17 - /* bool * -- - * Result is set to true if some variables are updated by - * frontend since last call to RETRO_ENVIRONMENT_GET_VARIABLE. - * Variables should be queried with GET_VARIABLE. - */ -#define RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME 18 - /* const bool * -- - * If true, the libretro implementation supports calls to - * retro_load_game() with NULL as argument. - * Used by cores which can run without particular game data. - * This should be called within retro_set_environment() only. - */ -#define RETRO_ENVIRONMENT_GET_LIBRETRO_PATH 19 - /* const char ** -- - * Retrieves the absolute path from where this libretro - * implementation was loaded. - * NULL is returned if the libretro was loaded statically - * (i.e. linked statically to frontend), or if the path cannot be - * determined. - * Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can - * be loaded without ugly hacks. - */ - - /* Environment 20 was an obsolete version of SET_AUDIO_CALLBACK. - * It was not used by any known core at the time, - * and was removed from the API. */ -#define RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK 22 - /* const struct retro_audio_callback * -- - * Sets an interface which is used to notify a libretro core about audio - * being available for writing. - * The callback can be called from any thread, so a core using this must - * have a thread safe audio implementation. - * It is intended for games where audio and video are completely - * asynchronous and audio can be generated on the fly. - * This interface is not recommended for use with emulators which have - * highly synchronous audio. - * - * The callback only notifies about writability; the libretro core still - * has to call the normal audio callbacks - * to write audio. The audio callbacks must be called from within the - * notification callback. - * The amount of audio data to write is up to the implementation. - * Generally, the audio callback will be called continously in a loop. - * - * Due to thread safety guarantees and lack of sync between audio and - * video, a frontend can selectively disallow this interface based on - * internal configuration. A core using this interface must also - * implement the "normal" audio interface. - * - * A libretro core using SET_AUDIO_CALLBACK should also make use of - * SET_FRAME_TIME_CALLBACK. - */ -#define RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK 21 - /* const struct retro_frame_time_callback * -- - * Lets the core know how much time has passed since last - * invocation of retro_run(). - * The frontend can tamper with the timing to fake fast-forward, - * slow-motion, frame stepping, etc. - * In this case the delta time will use the reference value - * in frame_time_callback.. - */ -#define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE 23 - /* struct retro_rumble_interface * -- - * Gets an interface which is used by a libretro core to set - * state of rumble motors in controllers. - * A strong and weak motor is supported, and they can be - * controlled indepedently. - */ -#define RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES 24 - /* uint64_t * -- - * Gets a bitmask telling which device type are expected to be - * handled properly in a call to retro_input_state_t. - * Devices which are not handled or recognized always return - * 0 in retro_input_state_t. - * Example bitmask: caps = (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG). - * Should only be called in retro_run(). - */ -#define RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE (25 | RETRO_ENVIRONMENT_EXPERIMENTAL) - /* struct retro_sensor_interface * -- - * Gets access to the sensor interface. - * The purpose of this interface is to allow - * setting state related to sensors such as polling rate, - * enabling/disable it entirely, etc. - * Reading sensor state is done via the normal - * input_state_callback API. - */ -#define RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE (26 | RETRO_ENVIRONMENT_EXPERIMENTAL) - /* struct retro_camera_callback * -- - * Gets an interface to a video camera driver. - * A libretro core can use this interface to get access to a - * video camera. - * New video frames are delivered in a callback in same - * thread as retro_run(). - * - * GET_CAMERA_INTERFACE should be called in retro_load_game(). - * - * Depending on the camera implementation used, camera frames - * will be delivered as a raw framebuffer, - * or as an OpenGL texture directly. - * - * The core has to tell the frontend here which types of - * buffers can be handled properly. - * An OpenGL texture can only be handled when using a - * libretro GL core (SET_HW_RENDER). - * It is recommended to use a libretro GL core when - * using camera interface. - * - * The camera is not started automatically. The retrieved start/stop - * functions must be used to explicitly - * start and stop the camera driver. - */ -#define RETRO_ENVIRONMENT_GET_LOG_INTERFACE 27 - /* struct retro_log_callback * -- - * Gets an interface for logging. This is useful for - * logging in a cross-platform way - * as certain platforms cannot use use stderr for logging. - * It also allows the frontend to - * show logging information in a more suitable way. - * If this interface is not used, libretro cores should - * log to stderr as desired. - */ -#define RETRO_ENVIRONMENT_GET_PERF_INTERFACE 28 - /* struct retro_perf_callback * -- - * Gets an interface for performance counters. This is useful - * for performance logging in a cross-platform way and for detecting - * architecture-specific features, such as SIMD support. - */ -#define RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE 29 - /* struct retro_location_callback * -- - * Gets access to the location interface. - * The purpose of this interface is to be able to retrieve - * location-based information from the host device, - * such as current latitude / longitude. - */ -#define RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY 30 - /* const char ** -- - * Returns the "content" directory of the frontend. - * This directory can be used to store specific assets that the - * core relies upon, such as art assets, - * input data, etc etc. - * The returned value can be NULL. - * If so, no such directory is defined, - * and it's up to the implementation to find a suitable directory. - */ -#define RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY 31 - /* const char ** -- - * Returns the "save" directory of the frontend. - * This directory can be used to store SRAM, memory cards, - * high scores, etc, if the libretro core - * cannot use the regular memory interface (retro_get_memory_data()). - * - * NOTE: libretro cores used to check GET_SYSTEM_DIRECTORY for - * similar things before. - * They should still check GET_SYSTEM_DIRECTORY if they want to - * be backwards compatible. - * The path here can be NULL. It should only be non-NULL if the - * frontend user has set a specific save path. - */ -#define RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO 32 - /* const struct retro_system_av_info * -- - * Sets a new av_info structure. This can only be called from - * within retro_run(). - * This should *only* be used if the core is completely altering the - * internal resolutions, aspect ratios, timings, sampling rate, etc. - * Calling this can require a full reinitialization of video/audio - * drivers in the frontend, - * - * so it is important to call it very sparingly, and usually only with - * the users explicit consent. - * An eventual driver reinitialize will happen so that video and - * audio callbacks - * happening after this call within the same retro_run() call will - * target the newly initialized driver. - * - * This callback makes it possible to support configurable resolutions - * in games, which can be useful to - * avoid setting the "worst case" in max_width/max_height. - * - * ***HIGHLY RECOMMENDED*** Do not call this callback every time - * resolution changes in an emulator core if it's - * expected to be a temporary change, for the reasons of possible - * driver reinitialization. - * This call is not a free pass for not trying to provide - * correct values in retro_get_system_av_info(). If you need to change - * things like aspect ratio or nominal width/height, - * use RETRO_ENVIRONMENT_SET_GEOMETRY, which is a softer variant - * of SET_SYSTEM_AV_INFO. - * - * If this returns false, the frontend does not acknowledge a - * changed av_info struct. - */ -#define RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK 33 - /* const struct retro_get_proc_address_interface * -- - * Allows a libretro core to announce support for the - * get_proc_address() interface. - * This interface allows for a standard way to extend libretro where - * use of environment calls are too indirect, - * e.g. for cases where the frontend wants to call directly into the core. - * - * If a core wants to expose this interface, SET_PROC_ADDRESS_CALLBACK - * **MUST** be called from within retro_set_environment(). - */ -#define RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO 34 - /* const struct retro_subsystem_info * -- - * This environment call introduces the concept of libretro "subsystems". - * A subsystem is a variant of a libretro core which supports - * different kinds of games. - * The purpose of this is to support e.g. emulators which might - * have special needs, e.g. Super Nintendo's Super GameBoy, Sufami Turbo. - * It can also be used to pick among subsystems in an explicit way - * if the libretro implementation is a multi-system emulator itself. - * - * Loading a game via a subsystem is done with retro_load_game_special(), - * and this environment call allows a libretro core to expose which - * subsystems are supported for use with retro_load_game_special(). - * A core passes an array of retro_game_special_info which is terminated - * with a zeroed out retro_game_special_info struct. - * - * If a core wants to use this functionality, SET_SUBSYSTEM_INFO - * **MUST** be called from within retro_set_environment(). - */ -#define RETRO_ENVIRONMENT_SET_CONTROLLER_INFO 35 - /* const struct retro_controller_info * -- - * This environment call lets a libretro core tell the frontend - * which controller types are recognized in calls to - * retro_set_controller_port_device(). - * - * Some emulators such as Super Nintendo - * support multiple lightgun types which must be specifically - * selected from. - * It is therefore sometimes necessary for a frontend to be able - * to tell the core about a special kind of input device which is - * not covered by the libretro input API. - * - * In order for a frontend to understand the workings of an input device, - * it must be a specialized type - * of the generic device types already defined in the libretro API. - * - * Which devices are supported can vary per input port. - * The core must pass an array of const struct retro_controller_info which - * is terminated with a blanked out struct. Each element of the struct - * corresponds to an ascending port index to - * retro_set_controller_port_device(). - * Even if special device types are set in the libretro core, - * libretro should only poll input based on the base input device types. - */ -#define RETRO_ENVIRONMENT_SET_MEMORY_MAPS (36 | RETRO_ENVIRONMENT_EXPERIMENTAL) - /* const struct retro_memory_map * -- - * This environment call lets a libretro core tell the frontend - * about the memory maps this core emulates. - * This can be used to implement, for example, cheats in a core-agnostic way. - * - * Should only be used by emulators; it doesn't make much sense for - * anything else. - * It is recommended to expose all relevant pointers through - * retro_get_memory_* as well. - * - * Can be called from retro_init and retro_load_game. - */ -#define RETRO_ENVIRONMENT_SET_GEOMETRY 37 - /* const struct retro_game_geometry * -- - * This environment call is similar to SET_SYSTEM_AV_INFO for changing - * video parameters, but provides a guarantee that drivers will not be - * reinitialized. - * This can only be called from within retro_run(). - * - * The purpose of this call is to allow a core to alter nominal - * width/heights as well as aspect ratios on-the-fly, which can be - * useful for some emulators to change in run-time. - * - * max_width/max_height arguments are ignored and cannot be changed - * with this call as this could potentially require a reinitialization or a - * non-constant time operation. - * If max_width/max_height are to be changed, SET_SYSTEM_AV_INFO is required. - * - * A frontend must guarantee that this environment call completes in - * constant time. - */ -#define RETRO_ENVIRONMENT_GET_USERNAME 38 - /* const char ** - * Returns the specified username of the frontend, if specified by the user. - * This username can be used as a nickname for a core that has online facilities - * or any other mode where personalization of the user is desirable. - * The returned value can be NULL. - * If this environ callback is used by a core that requires a valid username, - * a default username should be specified by the core. - */ -#define RETRO_ENVIRONMENT_GET_LANGUAGE 39 - /* unsigned * -- - * Returns the specified language of the frontend, if specified by the user. - * It can be used by the core for localization purposes. - */ - -#define RETRO_MEMDESC_CONST (1 << 0) /* The frontend will never change this memory area once retro_load_game has returned. */ -#define RETRO_MEMDESC_BIGENDIAN (1 << 1) /* The memory area contains big endian data. Default is little endian. */ -#define RETRO_MEMDESC_ALIGN_2 (1 << 16) /* All memory access in this area is aligned to their own size, or 2, whichever is smaller. */ -#define RETRO_MEMDESC_ALIGN_4 (2 << 16) -#define RETRO_MEMDESC_ALIGN_8 (3 << 16) -#define RETRO_MEMDESC_MINSIZE_2 (1 << 24) /* All memory in this region is accessed at least 2 bytes at the time. */ -#define RETRO_MEMDESC_MINSIZE_4 (2 << 24) -#define RETRO_MEMDESC_MINSIZE_8 (3 << 24) -struct retro_memory_descriptor -{ - uint64_t flags; - - /* Pointer to the start of the relevant ROM or RAM chip. - * It's strongly recommended to use 'offset' if possible, rather than - * doing math on the pointer. - * - * If the same byte is mapped my multiple descriptors, their descriptors - * must have the same pointer. - * If 'start' does not point to the first byte in the pointer, put the - * difference in 'offset' instead. - * - * May be NULL if there's nothing usable here (e.g. hardware registers and - * open bus). No flags should be set if the pointer is NULL. - * It's recommended to minimize the number of descriptors if possible, - * but not mandatory. */ - void *ptr; - size_t offset; - - /* This is the location in the emulated address space - * where the mapping starts. */ - size_t start; - - /* Which bits must be same as in 'start' for this mapping to apply. - * The first memory descriptor to claim a certain byte is the one - * that applies. - * A bit which is set in 'start' must also be set in this. - * Can be zero, in which case each byte is assumed mapped exactly once. - * In this case, 'len' must be a power of two. */ - size_t select; - - /* If this is nonzero, the set bits are assumed not connected to the - * memory chip's address pins. */ - size_t disconnect; - - /* This one tells the size of the current memory area. - * If, after start+disconnect are applied, the address is higher than - * this, the highest bit of the address is cleared. - * - * If the address is still too high, the next highest bit is cleared. - * Can be zero, in which case it's assumed to be infinite (as limited - * by 'select' and 'disconnect'). */ - size_t len; - - /* To go from emulated address to physical address, the following - * order applies: - * Subtract 'start', pick off 'disconnect', apply 'len', add 'offset'. - * - * The address space name must consist of only a-zA-Z0-9_-, - * should be as short as feasible (maximum length is 8 plus the NUL), - * and may not be any other address space plus one or more 0-9A-F - * at the end. - * However, multiple memory descriptors for the same address space is - * allowed, and the address space name can be empty. NULL is treated - * as empty. - * - * Address space names are case sensitive, but avoid lowercase if possible. - * The same pointer may exist in multiple address spaces. - * - * Examples: - * blank+blank - valid (multiple things may be mapped in the same namespace) - * 'Sp'+'Sp' - valid (multiple things may be mapped in the same namespace) - * 'A'+'B' - valid (neither is a prefix of each other) - * 'S'+blank - valid ('S' is not in 0-9A-F) - * 'a'+blank - valid ('a' is not in 0-9A-F) - * 'a'+'A' - valid (neither is a prefix of each other) - * 'AR'+blank - valid ('R' is not in 0-9A-F) - * 'ARB'+blank - valid (the B can't be part of the address either, because - * there is no namespace 'AR') - * blank+'B' - not valid, because it's ambigous which address space B1234 - * would refer to. - * The length can't be used for that purpose; the frontend may want - * to append arbitrary data to an address, without a separator. */ - const char *addrspace; -}; - -/* The frontend may use the largest value of 'start'+'select' in a - * certain namespace to infer the size of the address space. - * - * If the address space is larger than that, a mapping with .ptr=NULL - * should be at the end of the array, with .select set to all ones for - * as long as the address space is big. - * - * Sample descriptors (minus .ptr, and RETRO_MEMFLAG_ on the flags): - * SNES WRAM: - * .start=0x7E0000, .len=0x20000 - * (Note that this must be mapped before the ROM in most cases; some of the - * ROM mappers - * try to claim $7E0000, or at least $7E8000.) - * SNES SPC700 RAM: - * .addrspace="S", .len=0x10000 - * SNES WRAM mirrors: - * .flags=MIRROR, .start=0x000000, .select=0xC0E000, .len=0x2000 - * .flags=MIRROR, .start=0x800000, .select=0xC0E000, .len=0x2000 - * SNES WRAM mirrors, alternate equivalent descriptor: - * .flags=MIRROR, .select=0x40E000, .disconnect=~0x1FFF - * (Various similar constructions can be created by combining parts of - * the above two.) - * SNES LoROM (512KB, mirrored a couple of times): - * .flags=CONST, .start=0x008000, .select=0x408000, .disconnect=0x8000, .len=512*1024 - * .flags=CONST, .start=0x400000, .select=0x400000, .disconnect=0x8000, .len=512*1024 - * SNES HiROM (4MB): - * .flags=CONST, .start=0x400000, .select=0x400000, .len=4*1024*1024 - * .flags=CONST, .offset=0x8000, .start=0x008000, .select=0x408000, .len=4*1024*1024 - * SNES ExHiROM (8MB): - * .flags=CONST, .offset=0, .start=0xC00000, .select=0xC00000, .len=4*1024*1024 - * .flags=CONST, .offset=4*1024*1024, .start=0x400000, .select=0xC00000, .len=4*1024*1024 - * .flags=CONST, .offset=0x8000, .start=0x808000, .select=0xC08000, .len=4*1024*1024 - * .flags=CONST, .offset=4*1024*1024+0x8000, .start=0x008000, .select=0xC08000, .len=4*1024*1024 - * Clarify the size of the address space: - * .ptr=NULL, .select=0xFFFFFF - * .len can be implied by .select in many of them, but was included for clarity. - */ - -struct retro_memory_map -{ - const struct retro_memory_descriptor *descriptors; - unsigned num_descriptors; -}; - -struct retro_controller_description -{ - /* Human-readable description of the controller. Even if using a generic - * input device type, this can be set to the particular device type the - * core uses. */ - const char *desc; - - /* Device type passed to retro_set_controller_port_device(). If the device - * type is a sub-class of a generic input device type, use the - * RETRO_DEVICE_SUBCLASS macro to create an ID. - * - * E.g. RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1). */ - unsigned id; -}; - -struct retro_controller_info -{ - const struct retro_controller_description *types; - unsigned num_types; -}; - -struct retro_subsystem_memory_info -{ - /* The extension associated with a memory type, e.g. "psram". */ - const char *extension; - - /* The memory type for retro_get_memory(). This should be at - * least 0x100 to avoid conflict with standardized - * libretro memory types. */ - unsigned type; -}; - -struct retro_subsystem_rom_info -{ - /* Describes what the content is (SGB BIOS, GB ROM, etc). */ - const char *desc; - - /* Same definition as retro_get_system_info(). */ - const char *valid_extensions; - - /* Same definition as retro_get_system_info(). */ - bool need_fullpath; - - /* Same definition as retro_get_system_info(). */ - bool block_extract; - - /* This is set if the content is required to load a game. - * If this is set to false, a zeroed-out retro_game_info can be passed. */ - bool required; - - /* Content can have multiple associated persistent - * memory types (retro_get_memory()). */ - const struct retro_subsystem_memory_info *memory; - unsigned num_memory; -}; - -struct retro_subsystem_info -{ - /* Human-readable string of the subsystem type, e.g. "Super GameBoy" */ - const char *desc; - - /* A computer friendly short string identifier for the subsystem type. - * This name must be [a-z]. - * E.g. if desc is "Super GameBoy", this can be "sgb". - * This identifier can be used for command-line interfaces, etc. - */ - const char *ident; - - /* Infos for each content file. The first entry is assumed to be the - * "most significant" content for frontend purposes. - * E.g. with Super GameBoy, the first content should be the GameBoy ROM, - * as it is the most "significant" content to a user. - * If a frontend creates new file paths based on the content used - * (e.g. savestates), it should use the path for the first ROM to do so. */ - const struct retro_subsystem_rom_info *roms; - - /* Number of content files associated with a subsystem. */ - unsigned num_roms; - - /* The type passed to retro_load_game_special(). */ - unsigned id; -}; - -typedef void (*retro_proc_address_t)(void); - -/* libretro API extension functions: - * (None here so far). - * - * Get a symbol from a libretro core. - * Cores should only return symbols which are actual - * extensions to the libretro API. - * - * Frontends should not use this to obtain symbols to standard - * libretro entry points (static linking or dlsym). - * - * The symbol name must be equal to the function name, - * e.g. if void retro_foo(void); exists, the symbol must be called "retro_foo". - * The returned function pointer must be cast to the corresponding type. - */ -typedef retro_proc_address_t (*retro_get_proc_address_t)(const char *sym); - -struct retro_get_proc_address_interface -{ - retro_get_proc_address_t get_proc_address; -}; - -enum retro_log_level -{ - RETRO_LOG_DEBUG = 0, - RETRO_LOG_INFO, - RETRO_LOG_WARN, - RETRO_LOG_ERROR, - - RETRO_LOG_DUMMY = INT_MAX -}; - -/* Logging function. Takes log level argument as well. */ -typedef void (*retro_log_printf_t)(enum retro_log_level level, - const char *fmt, ...); - -struct retro_log_callback -{ - retro_log_printf_t log; -}; - -/* Performance related functions */ - -/* ID values for SIMD CPU features */ -#define RETRO_SIMD_SSE (1 << 0) -#define RETRO_SIMD_SSE2 (1 << 1) -#define RETRO_SIMD_VMX (1 << 2) -#define RETRO_SIMD_VMX128 (1 << 3) -#define RETRO_SIMD_AVX (1 << 4) -#define RETRO_SIMD_NEON (1 << 5) -#define RETRO_SIMD_SSE3 (1 << 6) -#define RETRO_SIMD_SSSE3 (1 << 7) -#define RETRO_SIMD_MMX (1 << 8) -#define RETRO_SIMD_MMXEXT (1 << 9) -#define RETRO_SIMD_SSE4 (1 << 10) -#define RETRO_SIMD_SSE42 (1 << 11) -#define RETRO_SIMD_AVX2 (1 << 12) -#define RETRO_SIMD_VFPU (1 << 13) -#define RETRO_SIMD_PS (1 << 14) -#define RETRO_SIMD_AES (1 << 15) - -typedef uint64_t retro_perf_tick_t; -typedef int64_t retro_time_t; - -struct retro_perf_counter -{ - const char *ident; - retro_perf_tick_t start; - retro_perf_tick_t total; - retro_perf_tick_t call_cnt; - - bool registered; -}; - -/* Returns current time in microseconds. - * Tries to use the most accurate timer available. - */ -typedef retro_time_t (*retro_perf_get_time_usec_t)(void); - -/* A simple counter. Usually nanoseconds, but can also be CPU cycles. - * Can be used directly if desired (when creating a more sophisticated - * performance counter system). - * */ -typedef retro_perf_tick_t (*retro_perf_get_counter_t)(void); - -/* Returns a bit-mask of detected CPU features (RETRO_SIMD_*). */ -typedef uint64_t (*retro_get_cpu_features_t)(void); - -/* Asks frontend to log and/or display the state of performance counters. - * Performance counters can always be poked into manually as well. - */ -typedef void (*retro_perf_log_t)(void); - -/* Register a performance counter. - * ident field must be set with a discrete value and other values in - * retro_perf_counter must be 0. - * Registering can be called multiple times. To avoid calling to - * frontend redundantly, you can check registered field first. */ -typedef void (*retro_perf_register_t)(struct retro_perf_counter *counter); - -/* Starts a registered counter. */ -typedef void (*retro_perf_start_t)(struct retro_perf_counter *counter); - -/* Stops a registered counter. */ -typedef void (*retro_perf_stop_t)(struct retro_perf_counter *counter); - -/* For convenience it can be useful to wrap register, start and stop in macros. - * E.g.: - * #ifdef LOG_PERFORMANCE - * #define RETRO_PERFORMANCE_INIT(perf_cb, name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name)) - * #define RETRO_PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name)) - * #define RETRO_PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name)) - * #else - * ... Blank macros ... - * #endif - * - * These can then be used mid-functions around code snippets. - * - * extern struct retro_perf_callback perf_cb; * Somewhere in the core. - * - * void do_some_heavy_work(void) - * { - * RETRO_PERFORMANCE_INIT(cb, work_1; - * RETRO_PERFORMANCE_START(cb, work_1); - * heavy_work_1(); - * RETRO_PERFORMANCE_STOP(cb, work_1); - * - * RETRO_PERFORMANCE_INIT(cb, work_2); - * RETRO_PERFORMANCE_START(cb, work_2); - * heavy_work_2(); - * RETRO_PERFORMANCE_STOP(cb, work_2); - * } - * - * void retro_deinit(void) - * { - * perf_cb.perf_log(); * Log all perf counters here for example. - * } - */ - -struct retro_perf_callback -{ - retro_perf_get_time_usec_t get_time_usec; - retro_get_cpu_features_t get_cpu_features; - - retro_perf_get_counter_t get_perf_counter; - retro_perf_register_t perf_register; - retro_perf_start_t perf_start; - retro_perf_stop_t perf_stop; - retro_perf_log_t perf_log; -}; - -/* FIXME: Document the sensor API and work out behavior. - * It will be marked as experimental until then. - */ -enum retro_sensor_action -{ - RETRO_SENSOR_ACCELEROMETER_ENABLE = 0, - RETRO_SENSOR_ACCELEROMETER_DISABLE, - - RETRO_SENSOR_DUMMY = INT_MAX -}; - -/* Id values for SENSOR types. */ -#define RETRO_SENSOR_ACCELEROMETER_X 0 -#define RETRO_SENSOR_ACCELEROMETER_Y 1 -#define RETRO_SENSOR_ACCELEROMETER_Z 2 - -typedef bool (*retro_set_sensor_state_t)(unsigned port, - enum retro_sensor_action action, unsigned rate); - -typedef float (*retro_sensor_get_input_t)(unsigned port, unsigned id); - -struct retro_sensor_interface -{ - retro_set_sensor_state_t set_sensor_state; - retro_sensor_get_input_t get_sensor_input; -}; - -enum retro_camera_buffer -{ - RETRO_CAMERA_BUFFER_OPENGL_TEXTURE = 0, - RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER, - - RETRO_CAMERA_BUFFER_DUMMY = INT_MAX -}; - -/* Starts the camera driver. Can only be called in retro_run(). */ -typedef bool (*retro_camera_start_t)(void); - -/* Stops the camera driver. Can only be called in retro_run(). */ -typedef void (*retro_camera_stop_t)(void); - -/* Callback which signals when the camera driver is initialized - * and/or deinitialized. - * retro_camera_start_t can be called in initialized callback. - */ -typedef void (*retro_camera_lifetime_status_t)(void); - -/* A callback for raw framebuffer data. buffer points to an XRGB8888 buffer. - * Width, height and pitch are similar to retro_video_refresh_t. - * First pixel is top-left origin. - */ -typedef void (*retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer, - unsigned width, unsigned height, size_t pitch); - -/* A callback for when OpenGL textures are used. - * - * texture_id is a texture owned by camera driver. - * Its state or content should be considered immutable, except for things like - * texture filtering and clamping. - * - * texture_target is the texture target for the GL texture. - * These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly - * more depending on extensions. - * - * affine points to a packed 3x3 column-major matrix used to apply an affine - * transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0)) - * After transform, normalized texture coord (0, 0) should be bottom-left - * and (1, 1) should be top-right (or (width, height) for RECTANGLE). - * - * GL-specific typedefs are avoided here to avoid relying on gl.h in - * the API definition. - */ -typedef void (*retro_camera_frame_opengl_texture_t)(unsigned texture_id, - unsigned texture_target, const float *affine); - -struct retro_camera_callback -{ - /* Set by libretro core. - * Example bitmask: caps = (1 << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER). - */ - uint64_t caps; - - unsigned width; /* Desired resolution for camera. Is only used as a hint. */ - unsigned height; - retro_camera_start_t start; /* Set by frontend. */ - retro_camera_stop_t stop; /* Set by frontend. */ - - /* Set by libretro core if raw framebuffer callbacks will be used. */ - retro_camera_frame_raw_framebuffer_t frame_raw_framebuffer; - /* Set by libretro core if OpenGL texture callbacks will be used. */ - retro_camera_frame_opengl_texture_t frame_opengl_texture; - - /* Set by libretro core. Called after camera driver is initialized and - * ready to be started. - * Can be NULL, in which this callback is not called. - */ - retro_camera_lifetime_status_t initialized; - - /* Set by libretro core. Called right before camera driver is - * deinitialized. - * Can be NULL, in which this callback is not called. - */ - retro_camera_lifetime_status_t deinitialized; -}; - -/* Sets the interval of time and/or distance at which to update/poll - * location-based data. - * - * To ensure compatibility with all location-based implementations, - * values for both interval_ms and interval_distance should be provided. - * - * interval_ms is the interval expressed in milliseconds. - * interval_distance is the distance interval expressed in meters. - */ -typedef void (*retro_location_set_interval_t)(unsigned interval_ms, - unsigned interval_distance); - -/* Start location services. The device will start listening for changes to the - * current location at regular intervals (which are defined with - * retro_location_set_interval_t). */ -typedef bool (*retro_location_start_t)(void); - -/* Stop location services. The device will stop listening for changes - * to the current location. */ -typedef void (*retro_location_stop_t)(void); - -/* Get the position of the current location. Will set parameters to - * 0 if no new location update has happened since the last time. */ -typedef bool (*retro_location_get_position_t)(double *lat, double *lon, - double *horiz_accuracy, double *vert_accuracy); - -/* Callback which signals when the location driver is initialized - * and/or deinitialized. - * retro_location_start_t can be called in initialized callback. - */ -typedef void (*retro_location_lifetime_status_t)(void); - -struct retro_location_callback -{ - retro_location_start_t start; - retro_location_stop_t stop; - retro_location_get_position_t get_position; - retro_location_set_interval_t set_interval; - - retro_location_lifetime_status_t initialized; - retro_location_lifetime_status_t deinitialized; -}; - -enum retro_rumble_effect -{ - RETRO_RUMBLE_STRONG = 0, - RETRO_RUMBLE_WEAK = 1, - - RETRO_RUMBLE_DUMMY = INT_MAX -}; - -/* Sets rumble state for joypad plugged in port 'port'. - * Rumble effects are controlled independently, - * and setting e.g. strong rumble does not override weak rumble. - * Strength has a range of [0, 0xffff]. - * - * Returns true if rumble state request was honored. - * Calling this before first retro_run() is likely to return false. */ -typedef bool (*retro_set_rumble_state_t)(unsigned port, - enum retro_rumble_effect effect, uint16_t strength); - -struct retro_rumble_interface -{ - retro_set_rumble_state_t set_rumble_state; -}; - -/* Notifies libretro that audio data should be written. */ -typedef void (*retro_audio_callback_t)(void); - -/* True: Audio driver in frontend is active, and callback is - * expected to be called regularily. - * False: Audio driver in frontend is paused or inactive. - * Audio callback will not be called until set_state has been - * called with true. - * Initial state is false (inactive). - */ -typedef void (*retro_audio_set_state_callback_t)(bool enabled); - -struct retro_audio_callback -{ - retro_audio_callback_t callback; - retro_audio_set_state_callback_t set_state; -}; - -/* Notifies a libretro core of time spent since last invocation - * of retro_run() in microseconds. - * - * It will be called right before retro_run() every frame. - * The frontend can tamper with timing to support cases like - * fast-forward, slow-motion and framestepping. - * - * In those scenarios the reference frame time value will be used. */ -typedef int64_t retro_usec_t; -typedef void (*retro_frame_time_callback_t)(retro_usec_t usec); -struct retro_frame_time_callback -{ - retro_frame_time_callback_t callback; - /* Represents the time of one frame. It is computed as - * 1000000 / fps, but the implementation will resolve the - * rounding to ensure that framestepping, etc is exact. */ - retro_usec_t reference; -}; - -/* Pass this to retro_video_refresh_t if rendering to hardware. - * Passing NULL to retro_video_refresh_t is still a frame dupe as normal. - * */ -#define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1) - -/* Invalidates the current HW context. - * Any GL state is lost, and must not be deinitialized explicitly. - * If explicit deinitialization is desired by the libretro core, - * it should implement context_destroy callback. - * If called, all GPU resources must be reinitialized. - * Usually called when frontend reinits video driver. - * Also called first time video driver is initialized, - * allowing libretro core to initialize resources. - */ -typedef void (*retro_hw_context_reset_t)(void); - -/* Gets current framebuffer which is to be rendered to. - * Could change every frame potentially. - */ -typedef uintptr_t (*retro_hw_get_current_framebuffer_t)(void); - -/* Get a symbol from HW context. */ -typedef retro_proc_address_t (*retro_hw_get_proc_address_t)(const char *sym); - -enum retro_hw_context_type -{ - RETRO_HW_CONTEXT_NONE = 0, - /* OpenGL 2.x. Driver can choose to use latest compatibility context. */ - RETRO_HW_CONTEXT_OPENGL = 1, - /* OpenGL ES 2.0. */ - RETRO_HW_CONTEXT_OPENGLES2 = 2, - /* Modern desktop core GL context. Use version_major/ - * version_minor fields to set GL version. */ - RETRO_HW_CONTEXT_OPENGL_CORE = 3, - /* OpenGL ES 3.0 */ - RETRO_HW_CONTEXT_OPENGLES3 = 4, - /* OpenGL ES 3.1+. Set version_major/version_minor. For GLES2 and GLES3, - * use the corresponding enums directly. */ - RETRO_HW_CONTEXT_OPENGLES_VERSION = 5, - - RETRO_HW_CONTEXT_DUMMY = INT_MAX -}; - -struct retro_hw_render_callback -{ - /* Which API to use. Set by libretro core. */ - enum retro_hw_context_type context_type; - - /* Called when a context has been created or when it has been reset. - * An OpenGL context is only valid after context_reset() has been called. - * - * When context_reset is called, OpenGL resources in the libretro - * implementation are guaranteed to be invalid. - * - * It is possible that context_reset is called multiple times during an - * application lifecycle. - * If context_reset is called without any notification (context_destroy), - * the OpenGL context was lost and resources should just be recreated - * without any attempt to "free" old resources. - */ - retro_hw_context_reset_t context_reset; - - /* Set by frontend. */ - retro_hw_get_current_framebuffer_t get_current_framebuffer; - - /* Set by frontend. */ - retro_hw_get_proc_address_t get_proc_address; - - /* Set if render buffers should have depth component attached. */ - bool depth; - - /* Set if stencil buffers should be attached. */ - bool stencil; - - /* If depth and stencil are true, a packed 24/8 buffer will be added. - * Only attaching stencil is invalid and will be ignored. */ - - /* Use conventional bottom-left origin convention. If false, - * standard libretro top-left origin semantics are used. */ - bool bottom_left_origin; - - /* Major version number for core GL context or GLES 3.1+. */ - unsigned version_major; - - /* Minor version number for core GL context or GLES 3.1+. */ - unsigned version_minor; - - /* If this is true, the frontend will go very far to avoid - * resetting context in scenarios like toggling fullscreen, etc. - */ - bool cache_context; - - /* The reset callback might still be called in extreme situations - * such as if the context is lost beyond recovery. - * - * For optimal stability, set this to false, and allow context to be - * reset at any time. - */ - - /* A callback to be called before the context is destroyed in a - * controlled way by the frontend. */ - retro_hw_context_reset_t context_destroy; - - /* OpenGL resources can be deinitialized cleanly at this step. - * context_destroy can be set to NULL, in which resources will - * just be destroyed without any notification. - * - * Even when context_destroy is non-NULL, it is possible that - * context_reset is called without any destroy notification. - * This happens if context is lost by external factors (such as - * notified by GL_ARB_robustness). - * - * In this case, the context is assumed to be already dead, - * and the libretro implementation must not try to free any OpenGL - * resources in the subsequent context_reset. - */ - - /* Creates a debug context. */ - bool debug_context; -}; - -/* Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. - * Called by the frontend in response to keyboard events. - * down is set if the key is being pressed, or false if it is being released. - * keycode is the RETROK value of the char. - * character is the text character of the pressed key. (UTF-32). - * key_modifiers is a set of RETROKMOD values or'ed together. - * - * The pressed/keycode state can be indepedent of the character. - * It is also possible that multiple characters are generated from a - * single keypress. - * Keycode events should be treated separately from character events. - * However, when possible, the frontend should try to synchronize these. - * If only a character is posted, keycode should be RETROK_UNKNOWN. - * - * Similarily if only a keycode event is generated with no corresponding - * character, character should be 0. - */ -typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, - uint32_t character, uint16_t key_modifiers); - -struct retro_keyboard_callback -{ - retro_keyboard_event_t callback; -}; - -/* Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE. - * Should be set for implementations which can swap out multiple disk - * images in runtime. - * - * If the implementation can do this automatically, it should strive to do so. - * However, there are cases where the user must manually do so. - * - * Overview: To swap a disk image, eject the disk image with - * set_eject_state(true). - * Set the disk index with set_image_index(index). Insert the disk again - * with set_eject_state(false). - */ - -/* If ejected is true, "ejects" the virtual disk tray. - * When ejected, the disk image index can be set. - */ -typedef bool (*retro_set_eject_state_t)(bool ejected); - -/* Gets current eject state. The initial state is 'not ejected'. */ -typedef bool (*retro_get_eject_state_t)(void); - -/* Gets current disk index. First disk is index 0. - * If return value is >= get_num_images(), no disk is currently inserted. - */ -typedef unsigned (*retro_get_image_index_t)(void); - -/* Sets image index. Can only be called when disk is ejected. - * The implementation supports setting "no disk" by using an - * index >= get_num_images(). - */ -typedef bool (*retro_set_image_index_t)(unsigned index); - -/* Gets total number of images which are available to use. */ -typedef unsigned (*retro_get_num_images_t)(void); - -struct retro_game_info; - -/* Replaces the disk image associated with index. - * Arguments to pass in info have same requirements as retro_load_game(). - * Virtual disk tray must be ejected when calling this. - * - * Replacing a disk image with info = NULL will remove the disk image - * from the internal list. - * As a result, calls to get_image_index() can change. - * - * E.g. replace_image_index(1, NULL), and previous get_image_index() - * returned 4 before. - * Index 1 will be removed, and the new index is 3. - */ -typedef bool (*retro_replace_image_index_t)(unsigned index, - const struct retro_game_info *info); - -/* Adds a new valid index (get_num_images()) to the internal disk list. - * This will increment subsequent return values from get_num_images() by 1. - * This image index cannot be used until a disk image has been set - * with replace_image_index. */ -typedef bool (*retro_add_image_index_t)(void); - -struct retro_disk_control_callback -{ - retro_set_eject_state_t set_eject_state; - retro_get_eject_state_t get_eject_state; - - retro_get_image_index_t get_image_index; - retro_set_image_index_t set_image_index; - retro_get_num_images_t get_num_images; - - retro_replace_image_index_t replace_image_index; - retro_add_image_index_t add_image_index; -}; - -enum retro_pixel_format -{ - /* 0RGB1555, native endian. - * 0 bit must be set to 0. - * This pixel format is default for compatibility concerns only. - * If a 15/16-bit pixel format is desired, consider using RGB565. */ - RETRO_PIXEL_FORMAT_0RGB1555 = 0, - - /* XRGB8888, native endian. - * X bits are ignored. */ - RETRO_PIXEL_FORMAT_XRGB8888 = 1, - - /* RGB565, native endian. - * This pixel format is the recommended format to use if a 15/16-bit - * format is desired as it is the pixel format that is typically - * available on a wide range of low-power devices. - * - * It is also natively supported in APIs like OpenGL ES. */ - RETRO_PIXEL_FORMAT_RGB565 = 2, - - /* Ensure sizeof() == sizeof(int). */ - RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX -}; - -struct retro_message -{ - const char *msg; /* Message to be displayed. */ - unsigned frames; /* Duration in frames of message. */ -}; - -/* Describes how the libretro implementation maps a libretro input bind - * to its internal input system through a human readable string. - * This string can be used to better let a user configure input. */ -struct retro_input_descriptor -{ - /* Associates given parameters with a description. */ - unsigned port; - unsigned device; - unsigned index; - unsigned id; - - /* Human readable description for parameters. - * The pointer must remain valid until - * retro_unload_game() is called. */ - const char *description; -}; - -struct retro_system_info -{ - /* All pointers are owned by libretro implementation, and pointers must - * remain valid until retro_deinit() is called. */ - - const char *library_name; /* Descriptive name of library. Should not - * contain any version numbers, etc. */ - const char *library_version; /* Descriptive version of core. */ - - const char *valid_extensions; /* A string listing probably content - * extensions the core will be able to - * load, separated with pipe. - * I.e. "bin|rom|iso". - * Typically used for a GUI to filter - * out extensions. */ - - /* If true, retro_load_game() is guaranteed to provide a valid pathname - * in retro_game_info::path. - * ::data and ::size are both invalid. - * - * If false, ::data and ::size are guaranteed to be valid, but ::path - * might not be valid. - * - * This is typically set to true for libretro implementations that must - * load from file. - * Implementations should strive for setting this to false, as it allows - * the frontend to perform patching, etc. */ - bool need_fullpath; - - /* If true, the frontend is not allowed to extract any archives before - * loading the real content. - * Necessary for certain libretro implementations that load games - * from zipped archives. */ - bool block_extract; -}; - -struct retro_game_geometry -{ - unsigned base_width; /* Nominal video width of game. */ - unsigned base_height; /* Nominal video height of game. */ - unsigned max_width; /* Maximum possible width of game. */ - unsigned max_height; /* Maximum possible height of game. */ - - float aspect_ratio; /* Nominal aspect ratio of game. If - * aspect_ratio is <= 0.0, an aspect ratio - * of base_width / base_height is assumed. - * A frontend could override this setting, - * if desired. */ -}; - -struct retro_system_timing -{ - double fps; /* FPS of video content. */ - double sample_rate; /* Sampling rate of audio. */ -}; - -struct retro_system_av_info -{ - struct retro_game_geometry geometry; - struct retro_system_timing timing; -}; - -struct retro_variable -{ - /* Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE. - * If NULL, obtains the complete environment string if more - * complex parsing is necessary. - * The environment string is formatted as key-value pairs - * delimited by semicolons as so: - * "key1=value1;key2=value2;..." - */ - const char *key; - - /* Value to be obtained. If key does not exist, it is set to NULL. */ - const char *value; -}; - -struct retro_game_info -{ - const char *path; /* Path to game, UTF-8 encoded. - * Usually used as a reference. - * May be NULL if rom was loaded from stdin - * or similar. - * retro_system_info::need_fullpath guaranteed - * that this path is valid. */ - const void *data; /* Memory buffer of loaded game. Will be NULL - * if need_fullpath was set. */ - size_t size; /* Size of memory buffer. */ - const char *meta; /* String of implementation specific meta-data. */ -}; - -/* Callbacks */ - -/* Environment callback. Gives implementations a way of performing - * uncommon tasks. Extensible. */ -typedef bool (*retro_environment_t)(unsigned cmd, void *data); - -/* Render a frame. Pixel format is 15-bit 0RGB1555 native endian - * unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT). - * - * Width and height specify dimensions of buffer. - * Pitch specifices length in bytes between two lines in buffer. - * - * For performance reasons, it is highly recommended to have a frame - * that is packed in memory, i.e. pitch == width * byte_per_pixel. - * Certain graphic APIs, such as OpenGL ES, do not like textures - * that are not packed in memory. - */ -typedef void (*retro_video_refresh_t)(const void *data, unsigned width, - unsigned height, size_t pitch); - -/* Renders a single audio frame. Should only be used if implementation - * generates a single sample at a time. - * Format is signed 16-bit native endian. - */ -typedef void (*retro_audio_sample_t)(int16_t left, int16_t right); - -/* Renders multiple audio frames in one go. - * - * One frame is defined as a sample of left and right channels, interleaved. - * I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames. - * Only one of the audio callbacks must ever be used. - */ -typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data, - size_t frames); - -/* Polls input. */ -typedef void (*retro_input_poll_t)(void); - -/* Queries for input for player 'port'. device will be masked with - * RETRO_DEVICE_MASK. - * - * Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that - * have been set with retro_set_controller_port_device() - * will still use the higher level RETRO_DEVICE_JOYPAD to request input. - */ -typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device, - unsigned index, unsigned id); - -/* Sets callbacks. retro_set_environment() is guaranteed to be called - * before retro_init(). - * - * The rest of the set_* functions are guaranteed to have been called - * before the first call to retro_run() is made. */ -void retro_set_environment(retro_environment_t); -void retro_set_video_refresh(retro_video_refresh_t); -void retro_set_audio_sample(retro_audio_sample_t); -void retro_set_audio_sample_batch(retro_audio_sample_batch_t); -void retro_set_input_poll(retro_input_poll_t); -void retro_set_input_state(retro_input_state_t); - -/* Library global initialization/deinitialization. */ -void retro_init(void); -void retro_deinit(void); - -/* Must return RETRO_API_VERSION. Used to validate ABI compatibility - * when the API is revised. */ -unsigned retro_api_version(void); - -/* Gets statically known system info. Pointers provided in *info - * must be statically allocated. - * Can be called at any time, even before retro_init(). */ -void retro_get_system_info(struct retro_system_info *info); - -/* Gets information about system audio/video timings and geometry. - * Can be called only after retro_load_game() has successfully completed. - * NOTE: The implementation of this function might not initialize every - * variable if needed. - * E.g. geom.aspect_ratio might not be initialized if core doesn't - * desire a particular aspect ratio. */ -void retro_get_system_av_info(struct retro_system_av_info *info); - -/* Sets device to be used for player 'port'. - * By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all - * available ports. - * Setting a particular device type is not a guarantee that libretro cores - * will only poll input based on that particular device type. It is only a - * hint to the libretro core when a core cannot automatically detect the - * appropriate input device type on its own. It is also relevant when a - * core can change its behavior depending on device type. */ -void retro_set_controller_port_device(unsigned port, unsigned device); - -/* Resets the current game. */ -void retro_reset(void); - -/* Runs the game for one video frame. - * During retro_run(), input_poll callback must be called at least once. - * - * If a frame is not rendered for reasons where a game "dropped" a frame, - * this still counts as a frame, and retro_run() should explicitly dupe - * a frame if GET_CAN_DUPE returns true. - * In this case, the video callback can take a NULL argument for data. - */ -void retro_run(void); - -/* Returns the amount of data the implementation requires to serialize - * internal state (save states). - * Between calls to retro_load_game() and retro_unload_game(), the - * returned size is never allowed to be larger than a previous returned - * value, to ensure that the frontend can allocate a save state buffer once. - */ -size_t retro_serialize_size(void); - -/* Serializes internal state. If failed, or size is lower than - * retro_serialize_size(), it should return false, true otherwise. */ -bool retro_serialize(void *data, size_t size); -bool retro_unserialize(const void *data, size_t size); - -void retro_cheat_reset(void); -void retro_cheat_set(unsigned index, bool enabled, const char *code); - -/* Loads a game. */ -bool retro_load_game(const struct retro_game_info *game); - -/* Loads a "special" kind of game. Should not be used, - * except in extreme cases. */ -bool retro_load_game_special( - unsigned game_type, - const struct retro_game_info *info, size_t num_info -); - -/* Unloads a currently loaded game. */ -void retro_unload_game(void); - -/* Gets region of game. */ -unsigned retro_get_region(void); - -/* Gets region of memory. */ -void *retro_get_memory_data(unsigned id); -size_t retro_get_memory_size(unsigned id); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h new file mode 100644 index 00000000..39bc32b6 --- /dev/null +++ b/frontend/libretro_core_options.h @@ -0,0 +1,1557 @@ +#ifndef LIBRETRO_CORE_OPTIONS_H__ +#define LIBRETRO_CORE_OPTIONS_H__ + +#include +#include + +#include +#include + +#ifndef HAVE_NO_LANGEXTRA +#include "libretro_core_options_intl.h" +#endif + +/* + ******************************** + * VERSION: 2.0 + ******************************** + * + * - 2.0: Add support for core options v2 interface + * - 1.3: Move translations to libretro_core_options_intl.h + * - libretro_core_options_intl.h includes BOM and utf-8 + * fix for MSVC 2010-2013 + * - Added HAVE_NO_LANGEXTRA flag to disable translations + * on platforms/compilers without BOM support + * - 1.2: Use core options v1 interface when + * RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION is >= 1 + * (previously required RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION == 1) + * - 1.1: Support generation of core options v0 retro_core_option_value + * arrays containing options with a single value + * - 1.0: First commit +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + ******************************** + * Core Option Definitions + ******************************** +*/ + +/* RETRO_LANGUAGE_ENGLISH */ + +/* Default language: + * - All other languages must include the same keys and values + * - Will be used as a fallback in the event that frontend language + * is not available + * - Will be used as a fallback for any missing entries in + * frontend language definition + */ + +struct retro_core_option_v2_category option_cats_us[] = { + { + "system", + "System", + "Configure base hardware parameters: region, BIOS selection, memory cards, etc." + }, + { + "video", + "Video", + "Configure base display parameters." + }, +#ifdef GPU_NEON + { + "gpu_neon", + "GPU Plugin", + "Configure low-level settings of the NEON GPU plugin." + }, +#endif +#ifdef GPU_PEOPS + { + "gpu_peops", + "GPU Plugin (Advanced)", + "Configure low-level settings of the P.E.Op.S. GPU plugin." + }, +#endif +#ifdef GPU_UNAI + { + "gpu_unai", + "GPU Plugin (Advanced)", + "Configure low-level settings of the UNAI GPU plugin." + }, +#endif + { + "audio", + "Audio", + "Configure sound emulation: reverb, interpolation, CD audio decoding." + }, + { + "input", + "Input", + "Configure input devices: analog response, haptic feedback, Multitaps, light guns, etc." + }, + { + "compat_hack", + "Compatibility Fixes", + "Configure settings/workarounds required for correct operation of specific games." + }, +#if !defined(DRC_DISABLE) && !defined(LIGHTREC) + { + "speed_hack", + "Speed Hacks (Advanced)", + "Configure hacks that may improve performance at the expense of decreased accuracy/stability." + }, +#endif + { NULL, NULL, NULL }, +}; + +struct retro_core_option_v2_definition option_defs_us[] = { + { + "pcsx_rearmed_region", + "Region", + NULL, + "Specify which region the system is from. 'NTSC' is 60 Hz while 'PAL' is 50 Hz. 'Auto' will detect the region of the currently loaded content. Games may run faster or slower than normal if the incorrect region is selected.", + NULL, + "system", + { + { "auto", "Auto" }, + { "NTSC", NULL }, + { "PAL", NULL }, + { NULL, NULL }, + }, + "auto", + }, + { + "pcsx_rearmed_bios", + "BIOS Selection", + NULL, + "Specify which BIOS to use. 'Auto' will attempt to load a real bios file from the frontend 'system' directory, falling back to high level emulation if unavailable. 'HLE' forces high level BIOS emulation. It is recommended to use an official bios file for better compatibility.", + NULL, + "system", + { + { "auto", "Auto" }, + { "HLE", NULL }, + { NULL, NULL }, + }, + "auto", + }, + { + "pcsx_rearmed_show_bios_bootlogo", + "Show BIOS Boot Logo", + NULL, + "When using an official BIOS file, specify whether to show the PlayStation logo upon starting or resetting content. Warning: Enabling the boot logo may reduce game compatibility.", + NULL, + "system", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_memcard2", + "Enable Second Memory Card (Shared)", + NULL, + "Emulate a second memory card in slot 2. This will be shared by all games.", + NULL, + "system", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, +#ifndef _WIN32 + { + "pcsx_rearmed_async_cd", + "CD Access Method (Restart)", + NULL, + "Select method used to read data from content disk images. 'Synchronous' mimics original hardware. 'Asynchronous' can reduce stuttering on devices with slow storage. 'Pre-Cache (CHD)' loads disk image into memory for faster access (CHD files only).", + NULL, + "system", + { + { "sync", "Synchronous" }, + { "async", "Asynchronous" }, + { "precache", "Pre-Cache (CHD)" }, + { NULL, NULL}, + }, + "sync", + }, +#endif +#ifndef DRC_DISABLE + { + "pcsx_rearmed_drc", + "Dynamic Recompiler", + NULL, + "Dynamically recompile PSX CPU instructions to native instructions. Much faster than using an interpreter, but may be less accurate on some platforms.", + NULL, + "system", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "enabled", + }, +#endif + { + "pcsx_rearmed_psxclock", + "PSX CPU Clock Speed", + NULL, + "Overclock or under-clock the PSX CPU. Try adjusting this if the game is too slow, too fast or hangs." +#if defined(LIGHTREC) + " Currently doesn't work with Lightrec dynarec." +#endif +#if defined(HAVE_PRE_ARMV7) && !defined(_3DS) + " Default is 50." +#else + " Default is 57." +#endif + , + NULL, + "system", + { + { "30", NULL }, + { "31", NULL }, + { "32", NULL }, + { "33", NULL }, + { "34", NULL }, + { "35", NULL }, + { "36", NULL }, + { "37", NULL }, + { "38", NULL }, + { "39", NULL }, + { "40", NULL }, + { "41", NULL }, + { "42", NULL }, + { "43", NULL }, + { "44", NULL }, + { "45", NULL }, + { "46", NULL }, + { "47", NULL }, + { "48", NULL }, + { "49", NULL }, + { "50", NULL }, + { "51", NULL }, + { "52", NULL }, + { "53", NULL }, + { "54", NULL }, + { "55", NULL }, + { "56", NULL }, + { "57", NULL }, + { "58", NULL }, + { "59", NULL }, + { "60", NULL }, + { "61", NULL }, + { "62", NULL }, + { "63", NULL }, + { "64", NULL }, + { "65", NULL }, + { "66", NULL }, + { "67", NULL }, + { "68", NULL }, + { "69", NULL }, + { "70", NULL }, + { "71", NULL }, + { "72", NULL }, + { "73", NULL }, + { "74", NULL }, + { "75", NULL }, + { "76", NULL }, + { "77", NULL }, + { "78", NULL }, + { "79", NULL }, + { "80", NULL }, + { "81", NULL }, + { "82", NULL }, + { "83", NULL }, + { "84", NULL }, + { "85", NULL }, + { "86", NULL }, + { "87", NULL }, + { "88", NULL }, + { "89", NULL }, + { "90", NULL }, + { "91", NULL }, + { "92", NULL }, + { "93", NULL }, + { "94", NULL }, + { "95", NULL }, + { "96", NULL }, + { "97", NULL }, + { "98", NULL }, + { "99", NULL }, + { "100", NULL }, + { NULL, NULL }, + }, +#if defined(HAVE_PRE_ARMV7) && !defined(_3DS) + "50", +#else + "57", +#endif + }, + { + "pcsx_rearmed_dithering", + "Dithering Pattern", + NULL, + "Enable emulation of the dithering technique used by the PSX to smooth out color banding artifacts. Increases performance requirements.", + NULL, + "video", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, +#if defined HAVE_LIBNX || defined _3DS + "disabled", +#else + "enabled", +#endif + }, + { + "pcsx_rearmed_duping_enable", + "Frame Duping (Speedup)", + NULL, + "When enabled and supported by the libretro frontend, provides a small performance increase by directing the frontend to repeat the previous frame if the core has nothing new to display.", + NULL, + "video", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "enabled", + }, +#ifdef THREAD_RENDERING + { + "pcsx_rearmed_gpu_thread_rendering", + "Threaded Rendering", + NULL, + "When enabled, runs GPU commands in a secondary thread. 'Synchronous' improves performance while maintaining proper frame pacing. 'Asynchronous' improves performance even further, but may cause dropped frames and increased latency. Produces best results with games that run natively at less than 60 frames per second.", + NULL, + "video", + { + { "disabled", NULL }, + { "sync", "Synchronous" }, + { "async", "Asynchronous" }, + { NULL, NULL}, + }, + "disabled", + }, +#endif + { + "pcsx_rearmed_frameskip_type", + "Frameskip", + NULL, + "Skip frames to avoid audio buffer under-run (crackling). Improves performance at the expense of visual smoothness. 'Auto' skips frames when advised by the frontend. 'Auto (Threshold)' utilises the 'Frameskip Threshold (%)' setting. 'Fixed Interval' utilises the 'Frameskip Interval' setting.", + NULL, + "video", + { + { "disabled", NULL }, + { "auto", "Auto" }, + { "auto_threshold", "Auto (Threshold)" }, + { "fixed_interval", "Fixed Interval" }, + { NULL, NULL }, + }, + "disabled" + }, + { + "pcsx_rearmed_frameskip_threshold", + "Frameskip Threshold (%)", + NULL, + "When 'Frameskip' is set to 'Auto (Threshold)', specifies the audio buffer occupancy threshold (percentage) below which frames will be skipped. Higher values reduce the risk of crackling by causing frames to be dropped more frequently.", + NULL, + "video", + { + { "15", NULL }, + { "18", NULL }, + { "21", NULL }, + { "24", NULL }, + { "27", NULL }, + { "30", NULL }, + { "33", NULL }, + { "36", NULL }, + { "39", NULL }, + { "42", NULL }, + { "45", NULL }, + { "48", NULL }, + { "51", NULL }, + { "54", NULL }, + { "57", NULL }, + { "60", NULL }, + { NULL, NULL }, + }, + "33" + }, + { + "pcsx_rearmed_frameskip_interval", + "Frameskip Interval", + NULL, + "Specify the maximum number of frames that can be skipped before a new frame is rendered.", + NULL, + "video", + { + { "1", NULL }, + { "2", NULL }, + { "3", NULL }, + { "4", NULL }, + { "5", NULL }, + { "6", NULL }, + { "7", NULL }, + { "8", NULL }, + { "9", NULL }, + { "10", NULL }, + { NULL, NULL }, + }, + "3" + }, + { + "pcsx_rearmed_display_internal_fps", + "Display Internal FPS", + NULL, + "Show the internal frame rate at which the emulated PlayStation system is rendering content. Note: Requires on-screen notifications to be enabled in the libretro frontend.", + NULL, + "video", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, +#ifdef GPU_NEON + { + "pcsx_rearmed_neon_interlace_enable", + "(GPU) Show Interlaced Video", + "Show Interlaced Video", + "When enabled, games that run in high resolution video modes (480i, 512i) will produced interlaced video output. While this displays correctly on CRT televisions, it will produce artifacts on modern displays. When disabled, all video is output in progressive format.", + NULL, + "gpu_neon", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_neon_enhancement_enable", + "(GPU) Enhanced Resolution (Slow)", + "Enhanced Resolution (Slow)", + "Render games that do not already run in high resolution video modes (480i, 512i) at twice the native internal resolution. Improves the fidelity of 3D models at the expense of increased performance requirements. 2D elements are generally unaffected by this setting.", + NULL, + "gpu_neon", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_neon_enhancement_no_main", + "(GPU) Enhanced Resolution Speed Hack", + "Enhanced Resolution Speed Hack", + "Improves performance when 'Enhanced Resolution (Slow)' is enabled, but reduces compatibility and may cause rendering errors.", + NULL, + "gpu_neon", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, +#endif /* GPU_NEON */ +#ifdef GPU_PEOPS + { + "pcsx_rearmed_show_gpu_peops_settings", + "Show Advanced P.E.Op.S. GPU Settings", + NULL, + "Show low-level configuration options for the P.E.Op.S. GPU plugin. Quick Menu may need to be toggled for this setting to take effect.", + NULL, + NULL, + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_peops_odd_even_bit", + "(GPU) Odd/Even Bit Hack", + "Odd/Even Bit Hack", + "A hack fix used to correct lock-ups that may occur in games such as Chrono Cross. Disable unless required.", + NULL, + "gpu_peops", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_peops_expand_screen_width", + "(GPU) Expand Screen Width", + "Expand Screen Width", + "Intended for use only with Capcom 2D fighting games. Enlarges the display area at the right side of the screen to show all background elements without cut-off. May cause rendering errors.", + NULL, + "gpu_peops", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_peops_ignore_brightness", + "(GPU) Ignore Brightness Color", + "Ignore Brightness Color", + "A hack fix used to repair black screens in Lunar Silver Star Story Complete when entering a house or a menu. Disable unless required.", + NULL, + "gpu_peops", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_peops_disable_coord_check", + "(GPU) Disable Coordinate Check", + "Disable Coordinate Check", + "Legacy compatibility mode. May improve games that fail to run correctly on newer GPU hardware. Disable unless required.", + NULL, + "gpu_peops", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_peops_lazy_screen_update", + "(GPU) Lazy Screen Update", + "Lazy Screen Update", + "A partial fix to prevent text box flickering in Dragon Warrior VII. May also improve Pandemonium 2. Disable unless required.", + NULL, + "gpu_peops", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_peops_repeated_triangles", + "(GPU) Repeat Flat Tex Triangles", + "Repeat Flat Tex Triangles", + "A hack fix used to correct rendering errors in Star Wars: Dark Forces. Disable unless required.", + NULL, + "gpu_peops", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_peops_quads_with_triangles", + "(GPU) Draw Tex-Quads as Triangles", + "Draw Tex-Quads as Triangles", + "Corrects graphical distortions that may occur when games utilize Gouraud Shading, at the expense of reduced texture quality. Disable unless required.", + NULL, + "gpu_peops", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_peops_fake_busy_state", + "(GPU) Fake 'GPU Busy' States", + "Fake 'GPU Busy' States", + "Emulate the 'GPU is busy' (drawing primitives) status flag of the original hardware instead of assuming the GPU is always ready for commands. May improve compatibility at the expense of reduced performance. Disable unless required.", + NULL, + "gpu_peops", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, +#endif /* GPU_PEOPS */ +#ifdef GPU_UNAI + { + "pcsx_rearmed_show_gpu_unai_settings", + "Show Advanced UNAI GPU Settings", + NULL, + "Show low-level configuration options for the UNAI GPU plugin. Quick Menu may need to be toggled for this setting to take effect.", + NULL, + NULL, + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL}, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_unai_blending", + "(GPU) Texture Blending", + "Texture Blending", + "Enable alpha-based (and additive) texture blending. Required for various rendering effects, including transparency (e.g. water, shadows). Can be disabled to improve performance at the expense of severe display errors/inaccuracies.", + NULL, + "gpu_unai", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL}, + }, + "enabled", + }, + { + "pcsx_rearmed_gpu_unai_lighting", + "(GPU) Lighting Effects", + "Lighting Effects", + "Enable simulated lighting effects (via vertex coloring combined with texture mapping). Required by almost all 3D games. Can be disabled to improve performance at the expense of severe display errors/inaccuracies (missing shadows, flat textures, etc.).", + NULL, + "gpu_unai", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL}, + }, + "enabled", + }, + { + "pcsx_rearmed_gpu_unai_fast_lighting", + "(GPU) Fast Lighting", + "Fast Lighting", + "Improves performance when 'Lighting Effects' are enabled, but may cause moderate/severe rendering errors.", + NULL, + "gpu_unai", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL}, + }, + "disabled", + }, + { + "pcsx_rearmed_gpu_unai_scale_hires", + "(GPU) Hi-Res Downscaling", + "Hi-Res Downscaling", + "When enabled, games that run in high resolution video modes (480i, 512i) will be downscaled to 320x240. Can improve performance, and is recommended on devices with native 240p display resolutions.", + NULL, + "gpu_unai", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL}, + }, +#ifdef _MIYOO + "enabled", +#else + "disabled", +#endif + }, +#endif /* GPU_UNAI */ + { + "pcsx_rearmed_spu_reverb", + "Audio Reverb Effects", + "Reverb Effects", + "Enable emulation of the reverb feature provided by the PSX SPU. Can be disabled to improve performance at the expense of reduced audio quality/authenticity.", + NULL, + "audio", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, +#ifdef HAVE_PRE_ARMV7 + "disabled", +#else + "enabled", +#endif + }, + { + "pcsx_rearmed_spu_interpolation", + "Sound Interpolation", + NULL, + "Enable emulation of the in-built audio interpolation provided by the PSX SPU. 'Gaussian' sounds closest to original hardware. 'Simple' improves performance but reduces quality. 'Cubic' has the highest performance requirements but produces increased clarity. Can be disabled entirely for maximum performance, at the expense of greatly reduced audio quality.", + NULL, + "audio", + { + { "simple", "Simple" }, + { "gaussian", "Gaussian" }, + { "cubic", "Cubic" }, + { "off", "disabled" }, + { NULL, NULL }, + }, +#ifdef HAVE_PRE_ARMV7 + "off", +#else + "simple", +#endif + }, + { + "pcsx_rearmed_nocdaudio", + "CD Audio", + NULL, + "Enable playback of CD (CD-DA) audio tracks. Can be disabled to improve performance in games that include CD audio, at the expense of missing music.", + NULL, + "audio", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "enabled", + }, + { + "pcsx_rearmed_noxadecoding", + "XA Decoding", + NULL, + "Enable playback of XA (eXtended Architecture ADPCM) audio tracks. Can be disabled to improve performance in games that include XA audio, at the expense of missing music.", + NULL, + "audio", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "enabled", + }, + { + "pcsx_rearmed_show_input_settings", + "Show Input Settings", + NULL, + "Show configuration options for all input devices: analog response, Multitaps, light guns, etc. Quick Menu may need to be toggled for this setting to take effect.", + NULL, + NULL, + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_analog_axis_modifier", + "Analog Axis Bounds", + NULL, + "Specify range limits for the left and right analog sticks when input device is set to 'analog' or 'dualshock'. 'Square' bounds improve input response when using controllers with highly circular ranges that are unable to fully saturate the X and Y axes at 45 degree deflections.", + NULL, + "input", + { + { "circle", "Circle" }, + { "square", "Square" }, + { NULL, NULL }, + }, + "circle", + }, + { + "pcsx_rearmed_vibration", + "Rumble Effects", + NULL, + "Enable haptic feedback when using a rumble-equipped gamepad with input device set to 'dualshock'.", + NULL, + "input", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "enabled", + }, + { + "pcsx_rearmed_multitap", + "Multitap Mode (Restart)", + NULL, + "Connect a virtual PSX Multitap peripheral to either controller 'Port 1' or controller 'Port 2' for 5 player simultaneous input, or to both 'Ports 1 and 2' for 8 player input. Mutlitap usage requires compatible games. To avoid input defects, option should be disabled when running games that have no support for Multitap features.", + NULL, + "input", + { + { "disabled", NULL }, + { "port 1", "Port 1" }, + { "port 2", "Port 2" }, + { "ports 1 and 2", "Ports 1 and 2" }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_negcon_deadzone", + "NegCon Twist Deadzone", + NULL, + "Set the deadzone of the RetroPad left analog stick when simulating the 'twist' action of emulated neGcon Controllers. Used to eliminate drift/unwanted input.", + NULL, + "input", + { + { "0", "0%" }, + { "3", "3%" }, + { "5", "5%" }, + { "7", "7%" }, + { "10", "10%" }, + { "13", "13%" }, + { "15", "15%" }, + { "17", "17%" }, + { "20", "20%" }, + { "23", "23%" }, + { "25", "25%" }, + { "27", "27%" }, + { "30", "30%" }, + { NULL, NULL }, + }, + "0", + }, + { + "pcsx_rearmed_negcon_response", + "NegCon Twist Response", + NULL, + "Specify the analog response when using a RetroPad left analog stick to simulate the 'twist' action of emulated neGcon Controllers.", + NULL, + "input", + { + { "linear", "Linear" }, + { "quadratic", "Quadratic" }, + { "cubic", "Cubic" }, + { NULL, NULL }, + }, + "linear", + }, + { + "pcsx_rearmed_input_sensitivity", + "Mouse Sensitivity", + NULL, + "Adjust responsiveness of emulated 'mouse' input devices.", + NULL, + "input", + { + { "0.05", NULL }, + { "0.10", NULL }, + { "0.15", NULL }, + { "0.20", NULL }, + { "0.25", NULL }, + { "0.30", NULL }, + { "0.35", NULL }, + { "0.40", NULL }, + { "0.45", NULL }, + { "0.50", NULL }, + { "0.55", NULL }, + { "0.60", NULL }, + { "0.65", NULL }, + { "0.70", NULL }, + { "0.75", NULL }, + { "0.80", NULL }, + { "0.85", NULL }, + { "0.90", NULL }, + { "0.95", NULL }, + { "1.00", NULL }, + { "1.05", NULL }, + { "1.10", NULL }, + { "1.15", NULL }, + { "1.20", NULL }, + { "1.25", NULL }, + { "1.30", NULL }, + { "1.35", NULL }, + { "1.40", NULL }, + { "1.45", NULL }, + { "1.50", NULL }, + { "1.55", NULL }, + { "1.60", NULL }, + { "1.65", NULL }, + { "1.70", NULL }, + { "1.75", NULL }, + { "1.80", NULL }, + { "1.85", NULL }, + { "1.90", NULL }, + { "1.95", NULL }, + { "2.00", NULL }, + }, + "1.00", + }, + { + "pcsx_rearmed_gunconadjustx", + "Guncon X Axis Offset", + NULL, + "Apply an X axis offset to light gun input when emulating a Guncon device. Can be used to correct aiming misalignments.", + NULL, + "input", + { + { "-25", NULL }, + { "-24", NULL }, + { "-23", NULL }, + { "-22", NULL }, + { "-21", NULL }, + { "-20", NULL }, + { "-19", NULL }, + { "-18", NULL }, + { "-17", NULL }, + { "-16", NULL }, + { "-15", NULL }, + { "-14", NULL }, + { "-13", NULL }, + { "-12", NULL }, + { "-11", NULL }, + { "-10", NULL }, + { "-9", NULL }, + { "-8", NULL }, + { "-7", NULL }, + { "-6", NULL }, + { "-5", NULL }, + { "-4", NULL }, + { "-3", NULL }, + { "-2", NULL }, + { "-1", NULL }, + { "0", NULL }, + { "1", NULL }, + { "2", NULL }, + { "3", NULL }, + { "4", NULL }, + { "5", NULL }, + { "6", NULL }, + { "7", NULL }, + { "8", NULL }, + { "9", NULL }, + { "10", NULL }, + { "11", NULL }, + { "12", NULL }, + { "13", NULL }, + { "14", NULL }, + { "15", NULL }, + { "16", NULL }, + { "17", NULL }, + { "18", NULL }, + { "19", NULL }, + { "20", NULL }, + { "21", NULL }, + { "22", NULL }, + { "23", NULL }, + { "24", NULL }, + { "25", NULL }, + { NULL, NULL }, + }, + "0", + }, + { + "pcsx_rearmed_gunconadjusty", + "Guncon Y Axis Offset", + NULL, + "Apply a Y axis offset to light gun input when emulating a Guncon device. Can be used to correct aiming misalignments.", + NULL, + "input", + { + { "-25", NULL }, + { "-24", NULL }, + { "-23", NULL }, + { "-22", NULL }, + { "-21", NULL }, + { "-20", NULL }, + { "-19", NULL }, + { "-18", NULL }, + { "-17", NULL }, + { "-16", NULL }, + { "-15", NULL }, + { "-14", NULL }, + { "-13", NULL }, + { "-12", NULL }, + { "-11", NULL }, + { "-10", NULL }, + { "-9", NULL }, + { "-8", NULL }, + { "-7", NULL }, + { "-6", NULL }, + { "-5", NULL }, + { "-4", NULL }, + { "-3", NULL }, + { "-2", NULL }, + { "-1", NULL }, + { "0", NULL }, + { "1", NULL }, + { "2", NULL }, + { "3", NULL }, + { "4", NULL }, + { "5", NULL }, + { "6", NULL }, + { "7", NULL }, + { "8", NULL }, + { "9", NULL }, + { "10", NULL }, + { "11", NULL }, + { "12", NULL }, + { "13", NULL }, + { "14", NULL }, + { "15", NULL }, + { "16", NULL }, + { "17", NULL }, + { "18", NULL }, + { "19", NULL }, + { "20", NULL }, + { "21", NULL }, + { "22", NULL }, + { "23", NULL }, + { "24", NULL }, + { "25", NULL }, + { NULL, NULL }, + }, + "0", + }, + { + "pcsx_rearmed_gunconadjustratiox", + "Guncon X Axis Response", + NULL, + "Adjust relative magnitude of horizontal light gun motion when emulating a Guncon device. Can be used to correct aiming misalignments.", + NULL, + "input", + { + { "0.75", NULL }, + { "0.76", NULL }, + { "0.77", NULL }, + { "0.78", NULL }, + { "0.79", NULL }, + { "0.80", NULL }, + { "0.81", NULL }, + { "0.82", NULL }, + { "0.83", NULL }, + { "0.84", NULL }, + { "0.85", NULL }, + { "0.86", NULL }, + { "0.87", NULL }, + { "0.88", NULL }, + { "0.89", NULL }, + { "0.90", NULL }, + { "0.91", NULL }, + { "0.92", NULL }, + { "0.93", NULL }, + { "0.94", NULL }, + { "0.95", NULL }, + { "0.96", NULL }, + { "0.97", NULL }, + { "0.98", NULL }, + { "0.99", NULL }, + { "1.00", NULL }, + { "1.01", NULL }, + { "1.02", NULL }, + { "1.03", NULL }, + { "1.04", NULL }, + { "1.05", NULL }, + { "1.06", NULL }, + { "1.07", NULL }, + { "1.08", NULL }, + { "1.09", NULL }, + { "1.10", NULL }, + { "1.11", NULL }, + { "1.12", NULL }, + { "1.13", NULL }, + { "1.14", NULL }, + { "1.15", NULL }, + { "1.16", NULL }, + { "1.17", NULL }, + { "1.18", NULL }, + { "1.19", NULL }, + { "1.20", NULL }, + { "1.21", NULL }, + { "1.22", NULL }, + { "1.23", NULL }, + { "1.24", NULL }, + { "1.25", NULL }, + { NULL, NULL }, + }, + "1.00", + }, + { + "pcsx_rearmed_gunconadjustratioy", + "Guncon Y Axis Response", + NULL, + "Adjust relative magnitude of vertical light gun motion when emulating a Guncon device. Can be used to correct aiming misalignments.", + NULL, + "input", + { + { "0.75", NULL }, + { "0.76", NULL }, + { "0.77", NULL }, + { "0.78", NULL }, + { "0.79", NULL }, + { "0.80", NULL }, + { "0.81", NULL }, + { "0.82", NULL }, + { "0.83", NULL }, + { "0.84", NULL }, + { "0.85", NULL }, + { "0.86", NULL }, + { "0.87", NULL }, + { "0.88", NULL }, + { "0.89", NULL }, + { "0.90", NULL }, + { "0.91", NULL }, + { "0.92", NULL }, + { "0.93", NULL }, + { "0.94", NULL }, + { "0.95", NULL }, + { "0.96", NULL }, + { "0.97", NULL }, + { "0.98", NULL }, + { "0.99", NULL }, + { "1.00", NULL }, + { "1.01", NULL }, + { "1.02", NULL }, + { "1.03", NULL }, + { "1.04", NULL }, + { "1.05", NULL }, + { "1.06", NULL }, + { "1.07", NULL }, + { "1.08", NULL }, + { "1.09", NULL }, + { "1.10", NULL }, + { "1.11", NULL }, + { "1.12", NULL }, + { "1.13", NULL }, + { "1.14", NULL }, + { "1.15", NULL }, + { "1.16", NULL }, + { "1.17", NULL }, + { "1.18", NULL }, + { "1.19", NULL }, + { "1.20", NULL }, + { "1.21", NULL }, + { "1.22", NULL }, + { "1.23", NULL }, + { "1.24", NULL }, + { "1.25", NULL }, + { NULL, NULL }, + }, + "1.00", + }, + { + "pcsx_rearmed_icache_emulation", + "Instruction Cache Emulation", + NULL, + "Enable emulation of the PSX CPU instruction cache. Improves accuracy at the expense of increased performance overheads. Required for Formula One 2001, Formula One Arcade and Formula One 99. [Interpreter only and partial on lightrec, unsupported when using ARMv7 backend]", + NULL, + "compat_hack", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, +#if !defined(DRC_DISABLE) && !defined(LIGHTREC) + { + "pcsx_rearmed_nocompathacks", + "Disable Automatic Compatibility Hacks", + NULL, + "By default, PCSX-ReARMed will apply auxiliary compatibility hacks automatically, based on the currently loaded content. This behaviour is required for correct operation, but may be disabled if desired.", + NULL, + "compat_hack", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_nosmccheck", + "(Speed Hack) Disable SMC Checks", + "Disable SMC Checks", + "Will cause crashes when loading, and lead to memory card failure.", + NULL, + "speed_hack", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_gteregsunneeded", + "(Speed Hack) Assume GTE Registers Unneeded", + "Assume GTE Registers Unneeded", + "May cause rendering errors.", + NULL, + "speed_hack", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_nogteflags", + "(Speed Hack) Disable GTE Flags", + "Disable GTE Flags", + "Will cause rendering errors.", + NULL, + "speed_hack", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, + { + "pcsx_rearmed_nostalls", + "(Speed Hack) Disable CPU/GTE Stalls", + "Disable CPU/GTE Stalls", + "Will cause some games to run too quickly.", + NULL, + "speed_hack", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, +#endif /* !DRC_DISABLE && !LIGHTREC */ + { NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL }, +}; + +struct retro_core_options_v2 options_us = { + option_cats_us, + option_defs_us +}; + +/* + ******************************** + * Language Mapping + ******************************** +*/ + +#ifndef HAVE_NO_LANGEXTRA +struct retro_core_options_v2 *options_intl[RETRO_LANGUAGE_LAST] = { + &options_us, /* RETRO_LANGUAGE_ENGLISH */ + NULL, /* RETRO_LANGUAGE_JAPANESE */ + NULL, /* RETRO_LANGUAGE_FRENCH */ + NULL, /* RETRO_LANGUAGE_SPANISH */ + NULL, /* RETRO_LANGUAGE_GERMAN */ + NULL, /* RETRO_LANGUAGE_ITALIAN */ + NULL, /* RETRO_LANGUAGE_DUTCH */ + NULL, /* RETRO_LANGUAGE_PORTUGUESE_BRAZIL */ + NULL, /* RETRO_LANGUAGE_PORTUGUESE_PORTUGAL */ + NULL, /* RETRO_LANGUAGE_RUSSIAN */ + NULL, /* RETRO_LANGUAGE_KOREAN */ + NULL, /* RETRO_LANGUAGE_CHINESE_TRADITIONAL */ + NULL, /* RETRO_LANGUAGE_CHINESE_SIMPLIFIED */ + NULL, /* RETRO_LANGUAGE_ESPERANTO */ + NULL, /* RETRO_LANGUAGE_POLISH */ + NULL, /* RETRO_LANGUAGE_VIETNAMESE */ + NULL, /* RETRO_LANGUAGE_ARABIC */ + NULL, /* RETRO_LANGUAGE_GREEK */ + &options_tr, /* RETRO_LANGUAGE_TURKISH */ +}; +#endif + +/* + ******************************** + * Functions + ******************************** +*/ + +/* Handles configuration/setting of core options. + * Should be called as early as possible - ideally inside + * retro_set_environment(), and no later than retro_load_game() + * > We place the function body in the header to avoid the + * necessity of adding more .c files (i.e. want this to + * be as painless as possible for core devs) + */ + +static INLINE void libretro_set_core_options(retro_environment_t environ_cb, + bool *categories_supported) +{ + unsigned version = 0; +#ifndef HAVE_NO_LANGEXTRA + unsigned language = 0; +#endif + + if (!environ_cb || !categories_supported) + return; + + *categories_supported = false; + + if (!environ_cb(RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION, &version)) + version = 0; + + if (version >= 2) + { +#ifndef HAVE_NO_LANGEXTRA + struct retro_core_options_v2_intl core_options_intl; + + core_options_intl.us = &options_us; + core_options_intl.local = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_LANGUAGE, &language) && + (language < RETRO_LANGUAGE_LAST) && (language != RETRO_LANGUAGE_ENGLISH)) + core_options_intl.local = options_intl[language]; + + *categories_supported = environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2_INTL, + &core_options_intl); +#else + *categories_supported = environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2, + &options_us); +#endif + } + else + { + size_t i, j; + size_t option_index = 0; + size_t num_options = 0; + struct retro_core_option_definition + *option_v1_defs_us = NULL; +#ifndef HAVE_NO_LANGEXTRA + size_t num_options_intl = 0; + struct retro_core_option_v2_definition + *option_defs_intl = NULL; + struct retro_core_option_definition + *option_v1_defs_intl = NULL; + struct retro_core_options_intl + core_options_v1_intl; +#endif + struct retro_variable *variables = NULL; + char **values_buf = NULL; + + /* Determine total number of options */ + while (true) + { + if (option_defs_us[num_options].key) + num_options++; + else + break; + } + + if (version >= 1) + { + /* Allocate US array */ + option_v1_defs_us = (struct retro_core_option_definition *) + calloc(num_options + 1, sizeof(struct retro_core_option_definition)); + + /* Copy parameters from option_defs_us array */ + for (i = 0; i < num_options; i++) + { + struct retro_core_option_v2_definition *option_def_us = &option_defs_us[i]; + struct retro_core_option_value *option_values = option_def_us->values; + struct retro_core_option_definition *option_v1_def_us = &option_v1_defs_us[i]; + struct retro_core_option_value *option_v1_values = option_v1_def_us->values; + + option_v1_def_us->key = option_def_us->key; + option_v1_def_us->desc = option_def_us->desc; + option_v1_def_us->info = option_def_us->info; + option_v1_def_us->default_value = option_def_us->default_value; + + /* Values must be copied individually... */ + while (option_values->value) + { + option_v1_values->value = option_values->value; + option_v1_values->label = option_values->label; + + option_values++; + option_v1_values++; + } + } + +#ifndef HAVE_NO_LANGEXTRA + if (environ_cb(RETRO_ENVIRONMENT_GET_LANGUAGE, &language) && + (language < RETRO_LANGUAGE_LAST) && (language != RETRO_LANGUAGE_ENGLISH) && + options_intl[language]) + option_defs_intl = options_intl[language]->definitions; + + if (option_defs_intl) + { + /* Determine number of intl options */ + while (true) + { + if (option_defs_intl[num_options_intl].key) + num_options_intl++; + else + break; + } + + /* Allocate intl array */ + option_v1_defs_intl = (struct retro_core_option_definition *) + calloc(num_options_intl + 1, sizeof(struct retro_core_option_definition)); + + /* Copy parameters from option_defs_intl array */ + for (i = 0; i < num_options_intl; i++) + { + struct retro_core_option_v2_definition *option_def_intl = &option_defs_intl[i]; + struct retro_core_option_value *option_values = option_def_intl->values; + struct retro_core_option_definition *option_v1_def_intl = &option_v1_defs_intl[i]; + struct retro_core_option_value *option_v1_values = option_v1_def_intl->values; + + option_v1_def_intl->key = option_def_intl->key; + option_v1_def_intl->desc = option_def_intl->desc; + option_v1_def_intl->info = option_def_intl->info; + option_v1_def_intl->default_value = option_def_intl->default_value; + + /* Values must be copied individually... */ + while (option_values->value) + { + option_v1_values->value = option_values->value; + option_v1_values->label = option_values->label; + + option_values++; + option_v1_values++; + } + } + } + + core_options_v1_intl.us = option_v1_defs_us; + core_options_v1_intl.local = option_v1_defs_intl; + + environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL, &core_options_v1_intl); +#else + environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS, option_v1_defs_us); +#endif + } + else + { + /* Allocate arrays */ + variables = (struct retro_variable *)calloc(num_options + 1, + sizeof(struct retro_variable)); + values_buf = (char **)calloc(num_options, sizeof(char *)); + + if (!variables || !values_buf) + goto error; + + /* Copy parameters from option_defs_us array */ + for (i = 0; i < num_options; i++) + { + const char *key = option_defs_us[i].key; + const char *desc = option_defs_us[i].desc; + const char *default_value = option_defs_us[i].default_value; + struct retro_core_option_value *values = option_defs_us[i].values; + size_t buf_len = 3; + size_t default_index = 0; + + values_buf[i] = NULL; + + /* Skip options that are irrelevant when using the + * old style core options interface */ + if ((strcmp(key, "pcsx_rearmed_show_input_settings") == 0) || + (strcmp(key, "pcsx_rearmed_show_gpu_peops_settings") == 0) || + (strcmp(key, "pcsx_rearmed_show_gpu_unai_settings") == 0)) + continue; + + if (desc) + { + size_t num_values = 0; + + /* Determine number of values */ + while (true) + { + if (values[num_values].value) + { + /* Check if this is the default value */ + if (default_value) + if (strcmp(values[num_values].value, default_value) == 0) + default_index = num_values; + + buf_len += strlen(values[num_values].value); + num_values++; + } + else + break; + } + + /* Build values string */ + if (num_values > 0) + { + buf_len += num_values - 1; + buf_len += strlen(desc); + + values_buf[i] = (char *)calloc(buf_len, sizeof(char)); + if (!values_buf[i]) + goto error; + + strcpy(values_buf[i], desc); + strcat(values_buf[i], "; "); + + /* Default value goes first */ + strcat(values_buf[i], values[default_index].value); + + /* Add remaining values */ + for (j = 0; j < num_values; j++) + { + if (j != default_index) + { + strcat(values_buf[i], "|"); + strcat(values_buf[i], values[j].value); + } + } + } + } + + variables[option_index].key = key; + variables[option_index].value = values_buf[i]; + option_index++; + } + + /* Set variables */ + environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables); + } + +error: + /* Clean up */ + + if (option_v1_defs_us) + { + free(option_v1_defs_us); + option_v1_defs_us = NULL; + } + +#ifndef HAVE_NO_LANGEXTRA + if (option_v1_defs_intl) + { + free(option_v1_defs_intl); + option_v1_defs_intl = NULL; + } +#endif + + if (values_buf) + { + for (i = 0; i < num_options; i++) + { + if (values_buf[i]) + { + free(values_buf[i]); + values_buf[i] = NULL; + } + } + + free(values_buf); + values_buf = NULL; + } + + if (variables) + { + free(variables); + variables = NULL; + } + } +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontend/libretro_core_options_intl.h b/frontend/libretro_core_options_intl.h new file mode 100644 index 00000000..5b04d601 --- /dev/null +++ b/frontend/libretro_core_options_intl.h @@ -0,0 +1,552 @@ +#ifndef LIBRETRO_CORE_OPTIONS_INTL_H__ +#define LIBRETRO_CORE_OPTIONS_INTL_H__ + +#if defined(_MSC_VER) && (_MSC_VER >= 1500 && _MSC_VER < 1900) +/* https://support.microsoft.com/en-us/kb/980263 */ +#pragma execution_character_set("utf-8") +#pragma warning(disable:4566) +#endif + +#include + +/* + ******************************** + * VERSION: 2.0 + ******************************** + * + * - 2.0: Add support for core options v2 interface + * - 1.3: Move translations to libretro_core_options_intl.h + * - libretro_core_options_intl.h includes BOM and utf-8 + * fix for MSVC 2010-2013 + * - Added HAVE_NO_LANGEXTRA flag to disable translations + * on platforms/compilers without BOM support + * - 1.2: Use core options v1 interface when + * RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION is >= 1 + * (previously required RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION == 1) + * - 1.1: Support generation of core options v0 retro_core_option_value + * arrays containing options with a single value + * - 1.0: First commit +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + ******************************** + * Core Option Definitions + ******************************** +*/ + +/* RETRO_LANGUAGE_JAPANESE */ + +/* RETRO_LANGUAGE_FRENCH */ + +/* RETRO_LANGUAGE_SPANISH */ + +/* RETRO_LANGUAGE_GERMAN */ + +/* RETRO_LANGUAGE_ITALIAN */ + +/* RETRO_LANGUAGE_DUTCH */ + +/* RETRO_LANGUAGE_PORTUGUESE_BRAZIL */ + +/* RETRO_LANGUAGE_PORTUGUESE_PORTUGAL */ + +/* RETRO_LANGUAGE_RUSSIAN */ + +/* RETRO_LANGUAGE_KOREAN */ + +/* RETRO_LANGUAGE_CHINESE_TRADITIONAL */ + +/* RETRO_LANGUAGE_CHINESE_SIMPLIFIED */ + +/* RETRO_LANGUAGE_ESPERANTO */ + +/* RETRO_LANGUAGE_POLISH */ + +/* RETRO_LANGUAGE_VIETNAMESE */ + +/* RETRO_LANGUAGE_ARABIC */ + +/* RETRO_LANGUAGE_GREEK */ + +/* RETRO_LANGUAGE_TURKISH */ + +struct retro_core_option_v2_category option_cats_tr[] = { + { NULL, NULL, NULL }, +}; + +struct retro_core_option_v2_definition option_defs_tr[] = { + { + "pcsx_rearmed_frameskip", + "Kare Atlama", + NULL, + "Görsel pürüzsüzlük pahasına performansı artırmak için ne kadar karenin atlanması gerektiğini seçin.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_bios", + "BIOS Kullan", + NULL, + "Gerçek bios dosyasını (varsa) veya öykünmüş bios'u (HLE) kullanmanızı sağlar. Daha iyi uyumluluk için resmi bios dosyasını kullanmanız önerilir.", + NULL, + NULL, + { + { "auto", "otomatik" }, + { NULL, NULL }, + }, + "auto", + }, + { + "pcsx_rearmed_region", + "Bölge", + NULL, + "Sistemin hangi bölgeden olduğunu seçin. NTSC için 60 Hz, PAL için 50 Hz.", + NULL, + NULL, + { + { "auto", "otomatik" }, + { NULL, NULL }, + }, + "auto", + }, + { + "pcsx_rearmed_memcard2", + "Ä°kinci Bellek Kartını Etkinleştir (Paylaşılan)", + NULL, + "2. Hafıza kartı yuvasını etkinleştirin. Bu hafıza kartı tüm oyunlar arasında paylaşılır.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_multitap1", + "Multitap 1", + NULL, + "Bağlantı noktası 1'deki multitap'ı etkinleştirir / devre dışı bırakır ve izin veren oyunlarda 5 oyuncuya kadar izin verir.", + NULL, + NULL, + { + { "auto", "otomatik" }, + { NULL, NULL }, + }, + "auto", + }, + { + "pcsx_rearmed_multitap2", + "Multitap 2", + NULL, + "Bağlantı noktası 2'deki multitap'ı etkinleştirir/devre dışı bırakır ve izin veren oyunlarda 8 oyuncuya kadar izin verir. Bunun çalışması için Multitap 1'in etkinleştirilmesi gerekir.", + NULL, + NULL, + { + { "auto", "otomatik" }, + { NULL, NULL }, + }, + "auto", + }, + { + "pcsx_rearmed_negcon_deadzone", + "NegCon Twist Deadzone (Yüzdelik)", + NULL, + "Öykünülmüş neGcon kontrolörünün 'büküm' eylemini simüle ederken RetroPad sol analog çubuğunun ölü bölgesini ayarlar. Sürüklenme/istenmeyen girişi ortadan kaldırmak için kullanılır.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_negcon_response", + "NegCon Twist Response", + NULL, + "Öykünülmüş neGcon kontrolörünün 'bükümünü' simule etmek için bir RetroPad sol analog çubuğu kullanırken analog cevabını belirtir.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_vibration", + "Titreşimi Etkinleştir", + NULL, + "Titreşim özelliklerini destekleyen kontrolörler için titreşim geri bildirimini etkinleştirir.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_dithering", + "Dithering Etkinleştir", + NULL, + "Kapalı ise, PSX'in renk bantlarıyla mücadele etmek için uyguladığı renk taklidi düzenini devre dışı bırakır.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + +#ifdef NEW_DYNAREC + { + "pcsx_rearmed_drc", + "Dinamik Yeniden Derleyici", + NULL, + "Çekirdeğin dinamik yeniden derleyici veya tercüman(daha yavaş) CPU talimatlarını kullanmasını sağlar.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_psxclock", + "PSX CPU Saat Hızı", + NULL, +#if defined(HAVE_PRE_ARMV7) && !defined(_3DS) + "Overclock or underclock the PSX clock. Default is 50", +#else + "Overclock or underclock the PSX clock. Default is 57", +#endif + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, +#endif /* NEW_DYNAREC */ + +#ifdef GPU_NEON + { + "pcsx_rearmed_neon_interlace_enable", + "Interlacing Mode'u etkinleştir", + NULL, + "Sahte tarama çizgileri efektini etkinleştirir.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_neon_enhancement_enable", + "Geliştirilmiş Çözünürlük (Yavaş)", + NULL, + "Düşük performans pahasına çift çözünürlükte işler.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_neon_enhancement_no_main", + "Geliştirilmiş Çözünürlük (Speed Hack)", + NULL, + "Geliştirilmiş çözünürlük seçeneği için hız aşırtma(bazı oyunlarda sorun çıkartabilir).", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, +#endif /* GPU_NEON */ + + { + "pcsx_rearmed_duping_enable", + "Frame Duping", + NULL, + "Yeni bir veri yoksa, bir hızlandırma, son kareyi yeniden çizer/yeniden kullanır.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_display_internal_fps", + "Dahili FPS'yi görüntüle", + NULL, + "Etkinleştirildiğinde ekranda saniye başına kareyi gösterir.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + + /* GPU PEOPS OPTIONS */ +#ifdef GPU_PEOPS + { + "pcsx_rearmed_show_gpu_peops_settings", + "Gelişmiş GPU Ayarlarını Göster", + NULL, + "Çeşitli GPU düzeltmelerini etkinleştirin veya devre dışı bırakın. Ayarların etkili olması için core'un yeniden başlatılması gerekebilir. NOT: Bu ayarın etkili olabilmesi için Hızlı Menü’nün değiştirilmesi gerekir.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gpu_peops_odd_even_bit", + "(GPU) Odd/Even Bit Hack", + NULL, + "Chrono Cross için gerekli.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gpu_peops_expand_screen_width", + "(GPU) Ekran Genişliğini Genişlet", + NULL, + "Capcom dövüş oyunları", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gpu_peops_ignore_brightness", + "(GPU) Parlaklık Rengini Yoksay", + NULL, + "Lunar Silver Star Story oyunlarında siyah ekran", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gpu_peops_disable_coord_check", + "(GPU) Koordinat Kontrolünü Devre Dışı Bırak", + NULL, + "Uyumluluk modu", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gpu_peops_lazy_screen_update", + "(GPU) Tembel Ekran Güncellemesi", + NULL, + "Pandemonium 2", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gpu_peops_old_frame_skip", + "(GPU) Eski Çerçeve Atlama", + NULL, + "Her ikinci kareyi atla", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gpu_peops_repeated_triangles", + "(GPU) Tekrarlanan Düz Doku Üçgenleri", + NULL, + "Star Wars: Dark Forces için gerekli", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gpu_peops_quads_with_triangles", + "(GPU) Üçgenler ile Dörtlü Çiz", + NULL, + "Daha iyi g renkler, daha kötü dokular", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gpu_peops_fake_busy_state", + "(GPU) Sahte 'Gpu Meşgul' Konumları", + NULL, + "Çizimden sonra meşgul bayraklarını değiştir", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, +#endif /* GPU_PEOPS */ + + { + "pcsx_rearmed_show_bios_bootlogo", + "Bios Bootlogo'yu Göster", + NULL, + "Etkinleştirildiğinde, başlatırken veya sıfırlarken PlayStation logosunu gösterir. (Bazı oyunları bozabilir).", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_spu_reverb", + "Ses Yankısı", + NULL, + "Ses yankı efektini etkinleştirir veya devre dışı bırakır.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_spu_interpolation", + "Ses Enterpolasyonu", + NULL, + NULL, + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_icache_emulation", + "ICache Düzeltmleri", + NULL, + NULL, + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + + /* ADVANCED OPTIONS */ + { + "pcsx_rearmed_noxadecoding", + "XA Kod Çözme", + NULL, + NULL, + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_nocdaudio", + "CD Ses", + NULL, + NULL, + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + +#ifdef NEW_DYNAREC + { + "pcsx_rearmed_nosmccheck", + "(Speed Hack) SMC Kontrollerini Devre Dışı Bırak", + NULL, + "Yükleme sırasında çökmelere neden olabilir, hafıza kartını bozabilir.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_gteregsunneeded", + "(Speed Hack) GTE'nin Gereksiz Olduğunu Varsayın", + NULL, + "Grafiksel bozukluklara neden olabilir.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, + { + "pcsx_rearmed_nogteflags", + "(Speed Hack) GTE Bayraklarını Devredışı Bırakın", + NULL, + "Grafiksel bozukluklara neden olur.", + NULL, + NULL, + { + { NULL, NULL }, + }, + NULL + }, +#endif /* NEW_DYNAREC */ + + { NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL }, +}; + +struct retro_core_options_v2 options_tr = { + option_cats_tr, + option_defs_tr +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontend/link.T b/frontend/link.T new file mode 100644 index 00000000..b0c262db --- /dev/null +++ b/frontend/link.T @@ -0,0 +1,5 @@ +{ + global: retro_*; + local: *; +}; + diff --git a/frontend/main.c b/frontend/main.c index 3440e388..dcac1d98 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -11,7 +11,7 @@ #include #include #include -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(NO_DYLIB) #include #endif @@ -158,15 +158,17 @@ void emu_set_default_config(void) spu_config.iVolume = 768; spu_config.iTempo = 0; spu_config.iUseThread = 1; // no effect if only 1 core is detected -#ifdef HAVE_PRE_ARMV7 /* XXX GPH hack */ +#if defined(HAVE_PRE_ARMV7) && !defined(_3DS) /* XXX GPH hack */ spu_config.iUseReverb = 0; spu_config.iUseInterpolation = 0; +#ifndef HAVE_LIBRETRO spu_config.iTempo = 1; +#endif #endif new_dynarec_hacks = 0; - in_type1 = PSE_PAD_TYPE_STANDARD; - in_type2 = PSE_PAD_TYPE_STANDARD; + in_type[0] = PSE_PAD_TYPE_STANDARD; + in_type[1] = PSE_PAD_TYPE_STANDARD; } void do_emu_action(void) @@ -313,7 +315,7 @@ static int cdidcmp(const char *id1, const char *id2) static void parse_cwcheat(void) { - char line[256], buf[64], name[64], *p; + char line[256], buf[256], name[256], *p; int newcheat = 1; u32 a, v; FILE *f; @@ -755,10 +757,10 @@ void SysReset() { // reset can run code, timing must be set pl_timing_prepare(Config.PsxType); - EmuReset(); - // hmh core forgets this CDR_stop(); + + EmuReset(); GPU_updateLace = real_lace; g_emu_resetting = 0; @@ -806,7 +808,7 @@ int emu_save_state(int slot) return ret; ret = SaveState(fname); -#ifdef HAVE_PRE_ARMV7 /* XXX GPH hack */ +#if defined(HAVE_PRE_ARMV7) && !defined(_3DS) && !defined(__SWITCH__) /* XXX GPH hack */ sync(); #endif SysPrintf("* %s \"%s\" [%d]\n", @@ -828,6 +830,7 @@ int emu_load_state(int slot) return LoadState(fname); } +#ifndef HAVE_LIBRETRO #ifndef ANDROID void SysPrintf(const char *fmt, ...) { @@ -852,6 +855,7 @@ void SysPrintf(const char *fmt, ...) { } #endif +#endif /* HAVE_LIBRETRO */ void SysMessage(const char *fmt, ...) { va_list list; @@ -901,14 +905,15 @@ static int _OpenPlugins(void) { if (Config.UseNet && !NetOpened) { netInfo info; - char path[MAXPATHLEN]; + char path[MAXPATHLEN * 2]; char dotdir[MAXPATHLEN]; MAKE_PATH(dotdir, "/.pcsx/plugins/", NULL); strcpy(info.EmuName, "PCSX"); - strncpy(info.CdromID, CdromId, 9); - strncpy(info.CdromLabel, CdromLabel, 9); + memcpy(info.CdromID, CdromId, 9); /* no \0 trailing character? */ + memcpy(info.CdromLabel, CdromLabel, 9); + info.CdromLabel[9] = '\0'; info.psxMem = psxM; info.GPU_showScreenPic = GPU_showScreenPic; info.GPU_displayText = GPU_displayText; @@ -1020,7 +1025,7 @@ void *SysLoadLibrary(const char *lib) { return (void *)(uintptr_t)(PLUGIN_DL_BASE + builtin_plugin_ids[i]); } -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(NO_DYLIB) ret = dlopen(lib, RTLD_NOW); if (ret == NULL) SysMessage("dlopen: %s", dlerror()); @@ -1037,7 +1042,7 @@ void *SysLoadSym(void *lib, const char *sym) { if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins)) return plugin_link(plugid - PLUGIN_DL_BASE, sym); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(NO_DYLIB) return dlsym(lib, sym); #else return NULL; @@ -1045,7 +1050,9 @@ void *SysLoadSym(void *lib, const char *sym) { } const char *SysLibError() { -#ifndef _WIN32 +#if defined(NO_DYLIB) + return NULL; +#elif !defined(_WIN32) return dlerror(); #else return "not supported"; @@ -1058,8 +1065,7 @@ void SysCloseLibrary(void *lib) { if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins)) return; -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(NO_DYLIB) dlclose(lib); #endif } - diff --git a/frontend/menu.c b/frontend/menu.c index 2e4091c3..d1e0413a 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -309,14 +309,14 @@ static void menu_sync_config(void) Config.cycle_multiplier = 10000 / psx_clock; switch (in_type_sel1) { - case 1: in_type1 = PSE_PAD_TYPE_ANALOGPAD; break; - case 2: in_type1 = PSE_PAD_TYPE_GUNCON; break; - default: in_type1 = PSE_PAD_TYPE_STANDARD; + case 1: in_type[0] = PSE_PAD_TYPE_ANALOGPAD; break; + case 2: in_type[0] = PSE_PAD_TYPE_NEGCON; break; + default: in_type[0] = PSE_PAD_TYPE_STANDARD; } switch (in_type_sel2) { - case 1: in_type2 = PSE_PAD_TYPE_ANALOGPAD; break; - case 2: in_type2 = PSE_PAD_TYPE_GUNCON; break; - default: in_type2 = PSE_PAD_TYPE_STANDARD; + case 1: in_type[1] = PSE_PAD_TYPE_ANALOGPAD; break; + case 2: in_type[1] = PSE_PAD_TYPE_NEGCON; break; + default: in_type[1] = PSE_PAD_TYPE_STANDARD; } if (in_evdev_allow_abs_only != allow_abs_only_old) { in_probe(); diff --git a/frontend/menu.h b/frontend/menu.h index 81cd1baf..8f5acda7 100644 --- a/frontend/menu.h +++ b/frontend/menu.h @@ -1,3 +1,6 @@ +#ifndef __MENU_H__ +#define __MENU_H__ + void menu_init(void); void menu_prepare_emu(void); void menu_loop(void); @@ -35,3 +38,5 @@ extern int soft_filter; extern int g_menuscreen_w; extern int g_menuscreen_h; + +#endif /* __MENU_H__ */ diff --git a/frontend/nopic.h b/frontend/nopic.h index d664f805..1815983f 100644 --- a/frontend/nopic.h +++ b/frontend/nopic.h @@ -1,3 +1,6 @@ +#ifndef __NOPIC_H__ +#define __NOPIC_H__ + /* these are just deps, to be removed */ static const struct { @@ -54,4 +57,4 @@ void DrawNumBorPic(unsigned char *pMem, int lSelectedSlot) } } - +#endif /* __NOPIC_H__ */ diff --git a/frontend/pl_gun_ts.h b/frontend/pl_gun_ts.h index 4e3d195f..8a336271 100644 --- a/frontend/pl_gun_ts.h +++ b/frontend/pl_gun_ts.h @@ -1,3 +1,6 @@ +#ifndef __PL_GUN_TS_H__ +#define __PL_GUN_TS_H__ + #ifdef HAVE_TSLIB struct tsdev; @@ -16,3 +19,5 @@ int pl_gun_ts_get_fd(struct tsdev *ts); #define pl_set_gun_rect(...) do {} while (0) #endif + +#endif /* __PL_GUN_TS_H__ */ diff --git a/frontend/plat.h b/frontend/plat.h index 6b0cd65b..8a296ea4 100644 --- a/frontend/plat.h +++ b/frontend/plat.h @@ -1,3 +1,6 @@ +#ifndef __PLAT_H__ +#define __PLAT_H__ + void plat_init(void); void plat_finish(void); void plat_minimize(void); @@ -8,3 +11,5 @@ void plat_gvideo_open(int is_pal); void *plat_gvideo_set_mode(int *w, int *h, int *bpp); void *plat_gvideo_flip(void); void plat_gvideo_close(void); + +#endif /* __PLAT_H__ */ diff --git a/frontend/plat_omap.h b/frontend/plat_omap.h index e47410a3..151f09cd 100644 --- a/frontend/plat_omap.h +++ b/frontend/plat_omap.h @@ -1,5 +1,8 @@ +#ifndef __PLAT_OMAP_H__ +#define __PLAT_OMAP_H__ void plat_omap_init(void); void plat_omap_finish(void); void plat_omap_gvideo_open(void); +#endif /* __PLAT_OMAP_H__ */ diff --git a/frontend/plugin.c b/frontend/plugin.c index 5f9c5ffb..7f3b8a46 100644 --- a/frontend/plugin.c +++ b/frontend/plugin.c @@ -48,21 +48,21 @@ extern int CALLBACK SPUplayCDDAchannel(short *, int, unsigned int, int); /* PAD */ static long CALLBACK PADreadPort1(PadDataS *pad) { - pad->controllerType = in_type1; - pad->buttonStatus = ~in_keystate; - if (in_type1 == PSE_PAD_TYPE_ANALOGPAD) { - pad->leftJoyX = in_a1[0]; - pad->leftJoyY = in_a1[1]; - pad->rightJoyX = in_a2[0]; - pad->rightJoyY = in_a2[1]; + pad->controllerType = in_type[0]; + pad->buttonStatus = ~in_keystate[0]; + if (in_type[0] == PSE_PAD_TYPE_ANALOGPAD) { + pad->leftJoyX = in_analog_left[0][0]; + pad->leftJoyY = in_analog_left[0][1]; + pad->rightJoyX = in_analog_right[0][0]; + pad->rightJoyY = in_analog_right[0][1]; } return 0; } static long CALLBACK PADreadPort2(PadDataS *pad) { - pad->controllerType = in_type2; - pad->buttonStatus = ~in_keystate >> 16; + pad->controllerType = in_type[1]; + pad->buttonStatus = ~in_keystate[0] >> 16; return 0; } diff --git a/frontend/plugin.h b/frontend/plugin.h index e7a56453..5e12f902 100644 --- a/frontend/plugin.h +++ b/frontend/plugin.h @@ -1,3 +1,6 @@ +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ + #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #define PLUGIN_DL_BASE 0xfbad0000 @@ -12,3 +15,5 @@ enum builtint_plugins_e { void *plugin_link(enum builtint_plugins_e id, const char *sym); void plugin_call_rearmed_cbs(void); + +#endif /* __PLUGIN_H__ */ diff --git a/frontend/plugin_lib.c b/frontend/plugin_lib.c index 588f1337..171296d2 100644 --- a/frontend/plugin_lib.c +++ b/frontend/plugin_lib.c @@ -36,11 +36,16 @@ #define HUD_HEIGHT 10 -int in_type1, in_type2; -int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 }; +int in_type[8]; +int multitap1; +int multitap2; +int in_analog_left[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }}; +int in_analog_right[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }}; int in_adev[2] = { -1, -1 }, in_adev_axis[2][2] = {{ 0, 1 }, { 0, 1 }}; int in_adev_is_nublike[2]; -int in_keystate, in_state_gun; +unsigned short in_keystate[8]; +int in_mouse[8][2]; +int in_state_gun; int in_enable_vibration; void *tsdev; void *pl_vout_buf; @@ -567,7 +572,7 @@ static void update_analog_nub_adjust(int *x_, int *y_) static void update_analogs(void) { - int *nubp[2] = { in_a1, in_a2 }; + int *nubp[2] = { in_analog_left[0], in_analog_right[0] }; int vals[2]; int i, a, v, ret; @@ -595,7 +600,6 @@ static void update_analogs(void) } } - //printf("%4d %4d %4d %4d\n", in_a1[0], in_a1[1], in_a2[0], in_a2[1]); } static void update_input(void) @@ -604,7 +608,7 @@ static void update_input(void) unsigned int emu_act; in_update(actions); - if (in_type1 == PSE_PAD_TYPE_ANALOGPAD) + if (in_type[0] == PSE_PAD_TYPE_ANALOGJOY || in_type[0] == PSE_PAD_TYPE_ANALOGPAD) update_analogs(); emu_act = actions[IN_BINDTYPE_EMU]; in_state_gun = (emu_act & SACTION_GUN_MASK) >> SACTION_GUN_TRIGGER; @@ -618,7 +622,7 @@ static void update_input(void) } emu_set_action(emu_act); - in_keystate = actions[IN_BINDTYPE_PLAYER12]; + in_keystate[0] = actions[IN_BINDTYPE_PLAYER12]; } #else /* MAEMO */ extern void update_input(void); diff --git a/frontend/plugin_lib.h b/frontend/plugin_lib.h index f55eb449..3f8b5c41 100644 --- a/frontend/plugin_lib.h +++ b/frontend/plugin_lib.h @@ -1,3 +1,9 @@ +#ifndef __PLUGIN_LIB_H__ +#define __PLUGIN_LIB_H__ + +#define THREAD_RENDERING_OFF 0 +#define THREAD_RENDERING_SYNC 1 +#define THREAD_RENDERING_ASYNC 2 enum { DKEY_SELECT = 0, @@ -17,8 +23,15 @@ enum { DKEY_CROSS, DKEY_SQUARE, }; -extern int in_type1, in_type2; -extern int in_keystate, in_state_gun, in_a1[2], in_a2[2]; +extern int in_state_gun; +extern int in_type[8]; +extern int multitap1; +extern int multitap2; +extern int in_analog_left[8][2]; +extern int in_analog_right[8][2]; +extern unsigned short in_keystate[8]; +extern int in_mouse[8][2]; + extern int in_adev[2], in_adev_axis[2][2]; extern int in_adev_is_nublike[2]; extern int in_enable_vibration; @@ -112,3 +125,5 @@ extern void (*pl_plat_hud_print)(int x, int y, const char *str, int bpp); #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #endif + +#endif /* __PLUGIN_LIB_H__ */ diff --git a/include/config.h b/include/config.h index ce2f3ea1..340cc2f9 100644 --- a/include/config.h +++ b/include/config.h @@ -1,2 +1,7 @@ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + #define MAXPATHLEN 256 -#define PACKAGE_VERSION "1.9" +#define PCSX_VERSION "1.9" + +#endif /* __CONFIG_H__ */ diff --git a/include/pcnt.h b/include/pcnt.h index 9ddd5003..c956b411 100644 --- a/include/pcnt.h +++ b/include/pcnt.h @@ -1,3 +1,5 @@ +#ifndef __PCNT_H__ +#define __PCNT_H__ enum pcounters { PCNT_ALL, @@ -130,3 +132,5 @@ void pcnt_gte_end(int op); #define pcnt_print(fps) #endif + +#endif /* __PCNT_H__ */ diff --git a/include/psemu_plugin_defs.h b/include/psemu_plugin_defs.h index fa626272..b855eacc 100644 --- a/include/psemu_plugin_defs.h +++ b/include/psemu_plugin_defs.h @@ -157,6 +157,8 @@ typedef struct +// No controller +#define PSE_PAD_TYPE_NONE 0 // MOUSE SCPH-1030 #define PSE_PAD_TYPE_MOUSE 1 // NEGCON - 16 button analog controller SLPH-00001 @@ -195,9 +197,15 @@ typedef struct typedef struct { - // controler type - fill it withe predefined values above + // controller type - fill it withe predefined values above unsigned char controllerType; + //0 : no multitap between psx and pad + //1 : multitap between psx and pad on port 1 + //2 : multitap between psx and pad on port 2 + int portMultitap; + int requestPadIndex; + // status of buttons - every controller fills this field unsigned short buttonStatus; @@ -211,8 +219,13 @@ typedef struct unsigned char Vib[2]; unsigned char VibF[2]; - + + //configuration mode Request 0x43 + int configMode; unsigned char reserved[87]; + + //Lightgun values + int absoluteX,absoluteY; } PadDataS; diff --git a/jni/Android.mk b/jni/Android.mk index da000f3e..501b0671 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -4,96 +4,221 @@ $(shell cd "$(LOCAL_PATH)" && ((git describe --always || echo) | sed -e 's/.*/#d $(shell cd "$(LOCAL_PATH)" && (diff -q ../frontend/revision.h_ ../frontend/revision.h > /dev/null 2>&1 || cp ../frontend/revision.h_ ../frontend/revision.h)) $(shell cd "$(LOCAL_PATH)" && (rm ../frontend/revision.h_)) -include $(CLEAR_VARS) - -APP_DIR := ../../src - -ifneq ($(TARGET_ARCH_ABI),armeabi-v7a) - NO_NEON_BUILD := 1 -else - NO_NEON_BUILD := $(NO_NEON) -endif - -ifeq ($(NO_NEON_BUILD)$(TARGET_ARCH_ABI),1armeabi-v7a) - LOCAL_MODULE := retro-noneon -else - LOCAL_MODULE := retro -endif +HAVE_CHD ?= 1 +USE_LIBRETRO_VFS ?= 0 + +ROOT_DIR := $(LOCAL_PATH)/.. +CORE_DIR := $(ROOT_DIR)/libpcsxcore +SPU_DIR := $(ROOT_DIR)/plugins/dfsound +GPU_DIR := $(ROOT_DIR)/plugins/gpulib +CDR_DIR := $(ROOT_DIR)/plugins/cdrcimg +INPUT_DIR := $(ROOT_DIR)/plugins/dfinput +FRONTEND_DIR := $(ROOT_DIR)/frontend +NEON_DIR := $(ROOT_DIR)/plugins/gpu_neon +UNAI_DIR := $(ROOT_DIR)/plugins/gpu_unai +PEOPS_DIR := $(ROOT_DIR)/plugins/dfxvideo +DYNAREC_DIR := $(ROOT_DIR)/libpcsxcore/new_dynarec +DEPS_DIR := $(ROOT_DIR)/deps +LIBRETRO_COMMON := $(ROOT_DIR)/libretro-common +EXTRA_INCLUDES := + +# core +SOURCES_C := $(CORE_DIR)/cdriso.c \ + $(CORE_DIR)/cdrom.c \ + $(CORE_DIR)/cheat.c \ + $(CORE_DIR)/database.c \ + $(CORE_DIR)/decode_xa.c \ + $(CORE_DIR)/mdec.c \ + $(CORE_DIR)/misc.c \ + $(CORE_DIR)/plugins.c \ + $(CORE_DIR)/ppf.c \ + $(CORE_DIR)/psxbios.c \ + $(CORE_DIR)/psxcommon.c \ + $(CORE_DIR)/psxcounters.c \ + $(CORE_DIR)/psxdma.c \ + $(CORE_DIR)/psxhle.c \ + $(CORE_DIR)/psxhw.c \ + $(CORE_DIR)/psxinterpreter.c \ + $(CORE_DIR)/psxmem.c \ + $(CORE_DIR)/r3000a.c \ + $(CORE_DIR)/sio.c \ + $(CORE_DIR)/spu.c \ + $(CORE_DIR)/gte.c \ + $(CORE_DIR)/gte_nf.c \ + $(CORE_DIR)/gte_divider.c -ifeq ($(TARGET_ARCH),arm) - LOCAL_ARM_MODE := arm - - LOCAL_CFLAGS += -DANDROID_ARM - - LOCAL_SRC_FILES += ../libpcsxcore/gte_arm.S - - # dynarec - LOCAL_SRC_FILES += ../libpcsxcore/new_dynarec/new_dynarec.c ../libpcsxcore/new_dynarec/linkage_arm.S ../libpcsxcore/new_dynarec/emu_if.c ../libpcsxcore/new_dynarec/pcsxmem.c - - # spu - LOCAL_SRC_FILES += ../plugins/dfsound/arm_utils.S +# spu +SOURCES_C += $(SPU_DIR)/dma.c \ + $(SPU_DIR)/freeze.c \ + $(SPU_DIR)/registers.c \ + $(SPU_DIR)/spu.c \ + $(SPU_DIR)/out.c \ + $(SPU_DIR)/nullsnd.c - # misc +# gpu +SOURCES_C += $(GPU_DIR)/gpu.c \ + $(GPU_DIR)/vout_pl.c - ifeq ($(NO_NEON_BUILD),1) - # gpu - LOCAL_CFLAGS += -DREARMED - LOCAL_SRC_FILES += ../plugins/gpu_unai/gpulib_if.cpp ../plugins/gpu_unai/gpu_arm.s - LOCAL_SRC_FILES += ../frontend/cspace_arm.S - else - LOCAL_ARM_NEON := true - LOCAL_CFLAGS += -DNEON_BUILD -DTEXTURE_CACHE_4BPP -DTEXTURE_CACHE_8BPP - LOCAL_SRC_FILES += ../libpcsxcore/gte_neon.S ../frontend/cspace_neon.S +# cdrcimg +SOURCES_C += $(CDR_DIR)/cdrcimg.c - # gpu - LOCAL_SRC_FILES += ../plugins/gpu_neon/psx_gpu_if.c ../plugins/gpu_neon/psx_gpu/psx_gpu_arm_neon.S - endif +# dfinput +SOURCES_C += $(INPUT_DIR)/main.c \ + $(INPUT_DIR)/pad.c \ + $(INPUT_DIR)/guncon.c + +# frontend +SOURCES_C += $(FRONTEND_DIR)/main.c \ + $(FRONTEND_DIR)/plugin.c \ + $(FRONTEND_DIR)/cspace.c \ + $(FRONTEND_DIR)/libretro.c + +# libchdr +SOURCES_C += \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Alloc.c \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Bra86.c \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/BraIA64.c \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/CpuArch.c \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Delta.c \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/LzFind.c \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Lzma86Dec.c \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/LzmaDec.c \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/LzmaEnc.c \ + $(DEPS_DIR)/libchdr/deps/lzma-19.00/src/Sort.c \ + $(DEPS_DIR)/libchdr/src/libchdr_bitstream.c \ + $(DEPS_DIR)/libchdr/src/libchdr_cdrom.c \ + $(DEPS_DIR)/libchdr/src/libchdr_chd.c \ + $(DEPS_DIR)/libchdr/src/libchdr_flac.c \ + $(DEPS_DIR)/libchdr/src/libchdr_huffman.c +SOURCES_ASM := + +COREFLAGS := -ffast-math -funroll-loops -DHAVE_LIBRETRO -DNO_FRONTEND -DFRONTEND_SUPPORTS_RGB565 -DANDROID -DREARMED +COREFLAGS += -DHAVE_CHD -D_7ZIP_ST + +ifeq ($(USE_LIBRETRO_VFS),1) +SOURCES_C += \ + $(LIBRETRO_COMMON)/compat/compat_posix_string.c \ + $(LIBRETRO_COMMON)/compat/fopen_utf8.c \ + $(LIBRETRO_COMMON)/encodings/compat_strl.c \ + $(LIBRETRO_COMMON)/encodings/encoding_utf.c \ + $(LIBRETRO_COMMON)/file/file_path.c \ + $(LIBRETRO_COMMON)/streams/file_stream.c \ + $(LIBRETRO_COMMON)/streams/file_stream_transforms.c \ + $(LIBRETRO_COMMON)/string/stdstring.c \ + $(LIBRETRO_COMMON)/time/rtime.c \ + $(LIBRETRO_COMMON)/vfs/vfs_implementation.c +COREFLAGS += -DUSE_LIBRETRO_VFS endif -ifeq ($(TARGET_ARCH),x86) - LOCAL_CFLAGS += -DANDROID_X86 +HAVE_ARI64=0 +HAVE_LIGHTREC=0 +LIGHTREC_CUSTOM_MAP=0 +HAVE_GPU_NEON=0 +ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) + HAVE_ARI64=1 + HAVE_GPU_NEON=1 +else ifeq ($(TARGET_ARCH_ABI),armeabi) + HAVE_ARI64=1 +else ifeq ($(TARGET_ARCH_ABI),arm64-v8a) + HAVE_ARI64=1 + HAVE_GPU_NEON=1 +else ifeq ($(TARGET_ARCH_ABI),x86_64) + HAVE_LIGHTREC=1 + HAVE_GPU_NEON=1 +else ifeq ($(TARGET_ARCH_ABI),x86) + HAVE_LIGHTREC=1 + HAVE_GPU_NEON=1 +else + COREFLAGS += -DDRC_DISABLE endif - -ifeq ($(TARGET_ARCH),mips) - LOCAL_CFLAGS += -DANDROID_MIPS -D__mips__ -D__MIPSEL__ + COREFLAGS += -DLIGHTREC_CUSTOM_MAP=$(LIGHTREC_CUSTOM_MAP) + +ifeq ($(HAVE_ARI64),1) + SOURCES_C += $(DYNAREC_DIR)/new_dynarec.c \ + $(DYNAREC_DIR)/pcsxmem.c + ifeq ($(TARGET_ARCH_ABI),arm64-v8a) + SOURCES_ASM += $(DYNAREC_DIR)/linkage_arm64.S + else + SOURCES_ASM += $(CORE_DIR)/gte_arm.S \ + $(SPU_DIR)/arm_utils.S \ + $(DYNAREC_DIR)/linkage_arm.S + endif +endif + SOURCES_C += $(DYNAREC_DIR)/emu_if.c + +ifeq ($(HAVE_LIGHTREC),1) + COREFLAGS += -DLIGHTREC -DLIGHTREC_STATIC + EXTRA_INCLUDES += $(DEPS_DIR)/lightning/include \ + $(DEPS_DIR)/lightrec \ + $(DEPS_DIR)/lightrec/tlsf \ + $(ROOT_DIR)/include/lightning \ + $(ROOT_DIR)/include/lightrec + SOURCES_C += $(DEPS_DIR)/lightrec/blockcache.c \ + $(DEPS_DIR)/lightrec/disassembler.c \ + $(DEPS_DIR)/lightrec/emitter.c \ + $(DEPS_DIR)/lightrec/interpreter.c \ + $(DEPS_DIR)/lightrec/lightrec.c \ + $(DEPS_DIR)/lightrec/memmanager.c \ + $(DEPS_DIR)/lightrec/optimizer.c \ + $(DEPS_DIR)/lightrec/regcache.c \ + $(DEPS_DIR)/lightrec/recompiler.c \ + $(DEPS_DIR)/lightrec/reaper.c + SOURCES_C += $(DEPS_DIR)/lightning/lib/jit_disasm.c \ + $(DEPS_DIR)/lightning/lib/jit_memory.c \ + $(DEPS_DIR)/lightning/lib/jit_names.c \ + $(DEPS_DIR)/lightning/lib/jit_note.c \ + $(DEPS_DIR)/lightning/lib/jit_print.c \ + $(DEPS_DIR)/lightning/lib/jit_size.c \ + $(DEPS_DIR)/lightning/lib/lightning.c + SOURCES_C += $(CORE_DIR)/lightrec/plugin.c $(DEPS_DIR)/lightrec/tlsf/tlsf.c +ifeq ($(LIGHTREC_CUSTOM_MAP),1) + SOURCES_C += $(CORE_DIR)/lightrec/mem.c endif - -ifneq ($(TARGET_ARCH),arm) - # gpu - LOCAL_CFLAGS += -DREARMED - LOCAL_SRC_FILES += ../plugins/gpu_unai/gpulib_if.cpp endif -LOCAL_SRC_FILES += ../libpcsxcore/cdriso.c ../libpcsxcore/cdrom.c ../libpcsxcore/cheat.c ../libpcsxcore/debug.c \ - ../libpcsxcore/decode_xa.c ../libpcsxcore/disr3000a.c ../libpcsxcore/mdec.c \ - ../libpcsxcore/misc.c ../libpcsxcore/plugins.c ../libpcsxcore/ppf.c ../libpcsxcore/psxbios.c \ - ../libpcsxcore/psxcommon.c ../libpcsxcore/psxcounters.c ../libpcsxcore/psxdma.c ../libpcsxcore/psxhle.c \ - ../libpcsxcore/psxhw.c ../libpcsxcore/psxinterpreter.c ../libpcsxcore/psxmem.c ../libpcsxcore/r3000a.c \ - ../libpcsxcore/sio.c ../libpcsxcore/socket.c ../libpcsxcore/spu.c -LOCAL_SRC_FILES += ../libpcsxcore/gte.c ../libpcsxcore/gte_nf.c ../libpcsxcore/gte_divider.c - -# spu -LOCAL_SRC_FILES += ../plugins/dfsound/dma.c ../plugins/dfsound/freeze.c \ - ../plugins/dfsound/registers.c ../plugins/dfsound/spu.c \ - ../plugins/dfsound/out.c ../plugins/dfsound/nullsnd.c - -# builtin gpu -LOCAL_SRC_FILES += ../plugins/gpulib/gpu.c ../plugins/gpulib/vout_pl.c - -# cdrcimg -LOCAL_SRC_FILES += ../plugins/cdrcimg/cdrcimg.c - -# dfinput -LOCAL_SRC_FILES += ../plugins/dfinput/main.c ../plugins/dfinput/pad.c ../plugins/dfinput/guncon.c -# misc -LOCAL_SRC_FILES += ../frontend/main.c ../frontend/plugin.c ../frontend/cspace.c +ifeq ($(HAVE_GPU_NEON),1) + COREFLAGS += -DNEON_BUILD -DTEXTURE_CACHE_4BPP -DTEXTURE_CACHE_8BPP -DGPU_NEON + ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) + COREFLAGS += -DHAVE_bgr555_to_rgb565 -DHAVE_bgr888_to_x + SOURCES_ASM += $(CORE_DIR)/gte_neon.S \ + $(NEON_DIR)/psx_gpu/psx_gpu_arm_neon.S \ + $(FRONTEND_DIR)/cspace_neon.S + else + COREFLAGS += -DSIMD_BUILD + SOURCES_C += $(NEON_DIR)/psx_gpu/psx_gpu_simd.c + endif + SOURCES_C += $(NEON_DIR)/psx_gpu_if.c +else ifeq ($(TARGET_ARCH_ABI),armeabi) + COREFLAGS += -DUSE_GPULIB=1 -DGPU_UNAI + COREFLAGS += -DHAVE_bgr555_to_rgb565 + SOURCES_ASM += $(UNAI_DIR)/gpu_arm.S \ + $(FRONTEND_DIR)/cspace_arm.S + SOURCES_C += $(UNAI_DIR)/gpulib_if.cpp +else + COREFLAGS += -fno-strict-aliasing -DGPU_PEOPS + SOURCES_C += $(PEOPS_DIR)/gpulib_if.c +endif -# libretro -LOCAL_SRC_FILES += ../frontend/libretro.c +GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)" +ifneq ($(GIT_VERSION)," unknown") + COREFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" +endif -LOCAL_CFLAGS += -O3 -ffast-math -funroll-loops -DNDEBUG -D_FILE_OFFSET_BITS=64 -DHAVE_LIBRETRO -DNO_FRONTEND -DFRONTEND_SUPPORTS_RGB565 -LOCAL_C_INCLUDES += $(LOCAL_PATH)/../include -LOCAL_LDLIBS := -lz -llog +include $(CLEAR_VARS) +LOCAL_MODULE := retro +LOCAL_SRC_FILES := $(SOURCES_C) $(SOURCES_ASM) +LOCAL_CFLAGS := $(COREFLAGS) +LOCAL_C_INCLUDES := $(ROOT_DIR)/include +LOCAL_C_INCLUDES += $(DEPS_DIR)/crypto $(DEPS_DIR)/libchdr/deps/lzma-19.00/include $(DEPS_DIR)/libchdr/include $(DEPS_DIR)/libchdr/include/libchdr +LOCAL_C_INCLUDES += $(LIBRETRO_COMMON)/include +LOCAL_C_INCLUDES += $(EXTRA_INCLUDES) +LOCAL_LDFLAGS := -Wl,-version-script=$(FRONTEND_DIR)/link.T +LOCAL_LDLIBS := -lz -llog +LOCAL_ARM_MODE := arm + +ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) + LOCAL_ARM_NEON := true +endif include $(BUILD_SHARED_LIBRARY) diff --git a/jni/Application.mk b/jni/Application.mk index f05229c8..a252a72d 100644 --- a/jni/Application.mk +++ b/jni/Application.mk @@ -1 +1 @@ -APP_ABI := armeabi armeabi-v7a +APP_ABI := all diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index 7715a2b7..b3e238b6 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -1518,7 +1518,7 @@ void psxDma3(u32 madr, u32 bcr, u32 chcr) { switch (chcr & 0x71000000) { case 0x11000000: ptr = (u8 *)PSXM(madr); - if (ptr == NULL) { + if (ptr == INVALID_PTR) { CDR_LOG_I("psxDma3() Log: *** DMA 3 *** NULL Pointer!\n"); break; } diff --git a/libpcsxcore/database.c b/libpcsxcore/database.c index 561aedee..1ea8d43b 100644 --- a/libpcsxcore/database.c +++ b/libpcsxcore/database.c @@ -30,7 +30,7 @@ cycle_multiplier_overrides[] = * changing memcard settings is enough to break/unbreak it */ { "SLPS02528", 190 }, { "SLPS02636", 190 }, -#ifdef DRC_DISABLE /* new_dynarec has a hack for this game */ +#if defined(DRC_DISABLE) || defined(LIGHTREC) /* new_dynarec has a hack for this game */ /* Parasite Eve II - internal timer checks */ { "SLUS01042", 125 }, { "SLUS01055", 125 }, diff --git a/libpcsxcore/debug.c b/libpcsxcore/debug.c index d7b2d21e..7fac2e42 100644 --- a/libpcsxcore/debug.c +++ b/libpcsxcore/debug.c @@ -450,7 +450,7 @@ static void ProcessCommands() { sprintf(reply, "200 %s\r\n", arguments == NULL ? "OK" : arguments); break; case 0x101: - sprintf(reply, "201 %s\r\n", PACKAGE_VERSION); + sprintf(reply, "201 %s\r\n", PCSX_VERSION); break; case 0x102: sprintf(reply, "202 1.0\r\n"); diff --git a/libpcsxcore/disr3000a.c b/libpcsxcore/disr3000a.c index a350da1a..5a79442d 100644 --- a/libpcsxcore/disr3000a.c +++ b/libpcsxcore/disr3000a.c @@ -78,17 +78,17 @@ typedef char* (*TdisR3000AF)(u32 code, u32 pc); #define _Branch_ (pc + 4 + ((short)_Im_ * 4)) #define _OfB_ _Im_, _nRs_ -#define dName(i) sprintf(ostr, "%s %-7s,", ostr, i) -#define dGPR(i) sprintf(ostr, "%s %8.8x (%s),", ostr, psxRegs.GPR.r[i], disRNameGPR[i]) -#define dCP0(i) sprintf(ostr, "%s %8.8x (%s),", ostr, psxRegs.CP0.r[i], disRNameCP0[i]) -#define dHI() sprintf(ostr, "%s %8.8x (%s),", ostr, psxRegs.GPR.n.hi, "hi") -#define dLO() sprintf(ostr, "%s %8.8x (%s),", ostr, psxRegs.GPR.n.lo, "lo") -#define dImm() sprintf(ostr, "%s %4.4x (%d),", ostr, _Im_, _Im_) -#define dTarget() sprintf(ostr, "%s %8.8x,", ostr, _Target_) -#define dSa() sprintf(ostr, "%s %2.2x (%d),", ostr, _Sa_, _Sa_) -#define dOfB() sprintf(ostr, "%s %4.4x (%8.8x (%s)),", ostr, _Im_, psxRegs.GPR.r[_Rs_], disRNameGPR[_Rs_]) -#define dOffset() sprintf(ostr, "%s %8.8x,", ostr, _Branch_) -#define dCode() sprintf(ostr, "%s %8.8x,", ostr, (code >> 6) & 0xffffff) +#define dName(i) snprintf(ostr, sizeof(ostr), "%s %-7s,", ostr, i) +#define dGPR(i) snprintf(ostr, sizeof(ostr), "%s %8.8x (%s),", ostr, psxRegs.GPR.r[i], disRNameGPR[i]) +#define dCP0(i) snprintf(ostr, sizeof(ostr), "%s %8.8x (%s),", ostr, psxRegs.CP0.r[i], disRNameCP0[i]) +#define dHI() snprintf(ostr, sizeof(ostr), "%s %8.8x (%s),", ostr, psxRegs.GPR.n.hi, "hi") +#define dLO() snprintf(ostr, sizeof(ostr), "%s %8.8x (%s),", ostr, psxRegs.GPR.n.lo, "lo") +#define dImm() snprintf(ostr, sizeof(ostr), "%s %4.4x (%d),", ostr, _Im_, _Im_) +#define dTarget() snprintf(ostr, sizeof(ostr), "%s %8.8x,", ostr, _Target_) +#define dSa() snprintf(ostr, sizeof(ostr), "%s %2.2x (%d),", ostr, _Sa_, _Sa_) +#define dOfB() snprintf(ostr, sizeof(ostr), "%s %4.4x (%8.8x (%s)),", ostr, _Im_, psxRegs.GPR.r[_Rs_], disRNameGPR[_Rs_]) +#define dOffset() snprintf(ostr, sizeof(ostr), "%s %8.8x,", ostr, _Branch_) +#define dCode() snprintf(ostr, sizeof(ostr), "%s %8.8x,", ostr, (code >> 6) & 0xffffff) /********************************************************* * Arithmetic with immediate operand * diff --git a/libpcsxcore/gpu.h b/libpcsxcore/gpu.h index 9dfe6347..c924b67b 100644 --- a/libpcsxcore/gpu.h +++ b/libpcsxcore/gpu.h @@ -21,6 +21,9 @@ * that GPU plugin doesn't. */ +#ifndef __GPU_H__ +#define __GPU_H__ + #define PSXGPU_LCF (1<<31) #define PSXGPU_nBUSY (1<<26) #define PSXGPU_ILACE (1<<22) @@ -38,3 +41,5 @@ HW_GPU_STATUS &= SWAP32(PSXGPU_TIMING_BITS); \ HW_GPU_STATUS |= SWAP32(GPU_readStatus() & ~PSXGPU_TIMING_BITS); \ } + +#endif /* __GPU_H__ */ diff --git a/libpcsxcore/gte_arm.h b/libpcsxcore/gte_arm.h index 6b240db7..0288944a 100644 --- a/libpcsxcore/gte_arm.h +++ b/libpcsxcore/gte_arm.h @@ -15,6 +15,9 @@ * along with this program; if not, see . */ +#ifndef __GTE_ARM_H__ +#define __GTE_ARM_H__ + void gteRTPS_nf_arm(void *cp2_regs, int opcode); void gteRTPT_nf_arm(void *cp2_regs, int opcode); void gteNCLIP_arm(void *cp2_regs, int opcode); @@ -28,3 +31,5 @@ void gteMACtoIR_lm0(void *cp2_regs); void gteMACtoIR_lm1(void *cp2_regs); void gteMACtoIR_lm0_nf(void *cp2_regs); void gteMACtoIR_lm1_nf(void *cp2_regs); + +#endif /* __GTE_ARM_H__ */ diff --git a/libpcsxcore/gte_divider.h b/libpcsxcore/gte_divider.h index 99b01eb3..765b971d 100644 --- a/libpcsxcore/gte_divider.h +++ b/libpcsxcore/gte_divider.h @@ -15,4 +15,9 @@ * along with this program; if not, see . */ +#ifndef __GTE_DIVIDER_H__ +#define __GTE_DIVIDER_H__ + u32 DIVIDE(u16 n, u16 d); + +#endif /* __GTE_DIVIDER_H__ */ diff --git a/libpcsxcore/gte_neon.h b/libpcsxcore/gte_neon.h index 2fd9e4d7..f371640f 100644 --- a/libpcsxcore/gte_neon.h +++ b/libpcsxcore/gte_neon.h @@ -15,6 +15,9 @@ * along with this program; if not, see . */ +#ifndef __GTE_NEON_H__ +#define __GTE_NEON_H__ + void gteRTPS_neon(void *cp2_regs, int opcode); void gteRTPT_neon(void *cp2_regs, int opcode); @@ -23,3 +26,5 @@ void gteMVMVA_part_neon(void *cp2_regs, int opcode); // after NEON call only, does not do gteIR void gteMACtoIR_flags_neon(void *cp2_regs, int lm); + +#endif /* __GTE_NEON_H__ */ diff --git a/libpcsxcore/lightrec/mem.h b/libpcsxcore/lightrec/mem.h new file mode 100644 index 00000000..98dbbdeb --- /dev/null +++ b/libpcsxcore/lightrec/mem.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022 Paul Cercueil + */ + +#ifndef __LIGHTREC_MEM_H__ +#define __LIGHTREC_MEM_H__ + +#ifdef LIGHTREC + +#define CODE_BUFFER_SIZE (8 * 1024 * 1024) + +extern void *code_buffer; + +int lightrec_init_mmap(void); +void lightrec_free_mmap(void); + +#else /* if !LIGHTREC */ + +#define lightrec_init_mmap() -1 /* should not be called */ +#define lightrec_free_mmap() + +#undef LIGHTREC_CUSTOM_MAP +#define LIGHTREC_CUSTOM_MAP 0 + +#endif + +#endif /* __LIGHTREC_MEM_H__ */ diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index d83ee194..8010d7a5 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -69,7 +69,7 @@ static void mmssdd( char *b, char *p ) m = ((m / 10) << 4) | m % 10; s = ((s / 10) << 4) | s % 10; - d = ((d / 10) << 4) | d % 10; + d = ((d / 10) << 4) | d % 10; p[0] = m; p[1] = s; @@ -176,7 +176,7 @@ int LoadCdrom() { // is just below, do it here fake_bios_gpu_setup(); - if (!Config.HLE) { + if (!Config.HLE && !Config.SlowBoot) { // skip BIOS logos psxRegs.pc = psxRegs.GPR.n.ra; return 0; @@ -187,7 +187,7 @@ int LoadCdrom() { READTRACK(); // skip head and sub, and go to the root directory record - dir = (struct iso_directory_record*) &buf[12+156]; + dir = (struct iso_directory_record*) &buf[12+156]; mmssdd(dir->extent, (char*)time); @@ -232,7 +232,7 @@ int LoadCdrom() { psxRegs.pc = SWAP32(tmpHead.pc0); psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0); - psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr); + psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr); if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00; tmpHead.t_size = SWAP32(tmpHead.t_size); @@ -248,7 +248,7 @@ int LoadCdrom() { incTime(); READTRACK(); - if (ptr != NULL) memcpy(ptr, buf+12, 2048); + if (ptr != INVALID_PTR) memcpy(ptr, buf+12, 2048); tmpHead.t_size -= 2048; tmpHead.t_addr += 2048; @@ -272,7 +272,7 @@ int LoadCdromFile(const char *filename, EXE_HEADER *head) { READTRACK(); // skip head and sub, and go to the root directory record - dir = (struct iso_directory_record *)&buf[12 + 156]; + dir = (struct iso_directory_record *)&buf[12 + 156]; mmssdd(dir->extent, (char*)time); @@ -294,7 +294,7 @@ int LoadCdromFile(const char *filename, EXE_HEADER *head) { READTRACK(); mem = PSXM(addr); - if (mem) + if (mem != INVALID_PTR) memcpy(mem, buf + 12, 2048); size -= 2048; @@ -327,7 +327,7 @@ int CheckCdrom() { strncpy(CdromLabel, buf + 52, 32); // skip head and sub, and go to the root directory record - dir = (struct iso_directory_record *)&buf[12 + 156]; + dir = (struct iso_directory_record *)&buf[12 + 156]; mmssdd(dir->extent, (char *)time); @@ -355,6 +355,14 @@ int CheckCdrom() { return -1; } } + /* Workaround for Wild Arms EU/US which has non-standard string causing incorrect region detection */ + if (exename[0] == 'E' && exename[1] == 'X' && exename[2] == 'E' && exename[3] == '\\') { + size_t offset = 4; + size_t i, len = strlen(exename) - offset; + for (i = 0; i < len; i++) + exename[i] = exename[i + offset]; + exename[i] = '\0'; + } } else if (GetCdromFile(mdir, time, "PSX.EXE;1") != -1) { strcpy(exename, "PSX.EXE;1"); strcpy(CdromId, "SLUS99999"); @@ -409,7 +417,9 @@ static int PSXGetFileType(FILE *f) { current = ftell(f); fseek(f, 0L, SEEK_SET); - fread(mybuf, 2048, 1, f); + if (fread(&mybuf, 1, sizeof(mybuf), f) != sizeof(mybuf)) + goto io_fail; + fseek(f, current, SEEK_SET); exe_hdr = (EXE_HEADER *)mybuf; @@ -424,6 +434,12 @@ static int PSXGetFileType(FILE *f) { return COFF_EXE; return INVALID_EXE; + +io_fail: +#ifndef NDEBUG + SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__); +#endif + return INVALID_EXE; } // temporary pandora workaround.. @@ -432,7 +448,7 @@ size_t fread_to_ram(void *ptr, size_t size, size_t nmemb, FILE *stream) { void *tmp; size_t ret = 0; - + tmp = malloc(size * nmemb); if (tmp) { ret = fread(tmp, size, nmemb, stream); @@ -451,8 +467,8 @@ int Load(const char *ExePath) { u32 section_address, section_size; void *mem; - strncpy(CdromId, "SLUS99999", 9); - strncpy(CdromLabel, "SLUS_999.99", 11); + strcpy(CdromId, "SLUS99999"); + strcpy(CdromLabel, "SLUS_999.99"); tmpFile = fopen(ExePath, "rb"); if (tmpFile == NULL) { @@ -462,19 +478,19 @@ int Load(const char *ExePath) { type = PSXGetFileType(tmpFile); switch (type) { case PSX_EXE: - fread(&tmpHead,sizeof(EXE_HEADER),1,tmpFile); + if (fread(&tmpHead, 1, sizeof(EXE_HEADER), tmpFile) != sizeof(EXE_HEADER)) + goto fail_io; section_address = SWAP32(tmpHead.t_addr); section_size = SWAP32(tmpHead.t_size); mem = PSXM(section_address); - if (mem != NULL) { - fseek(tmpFile, 0x800, SEEK_SET); + if (mem != INVALID_PTR) { + fseek(tmpFile, 0x800, SEEK_SET); fread_to_ram(mem, section_size, 1, tmpFile); psxCpu->Clear(section_address, section_size / 4); } - fclose(tmpFile); psxRegs.pc = SWAP32(tmpHead.pc0); psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0); - psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr); + psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr); if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00; retval = 0; @@ -482,25 +498,29 @@ int Load(const char *ExePath) { case CPE_EXE: fseek(tmpFile, 6, SEEK_SET); /* Something tells me we should go to 4 and read the "08 00" here... */ do { - fread(&opcode, 1, 1, tmpFile); + if (fread(&opcode, 1, sizeof(opcode), tmpFile) != sizeof(opcode)) + goto fail_io; switch (opcode) { case 1: /* Section loading */ - fread(§ion_address, 4, 1, tmpFile); - fread(§ion_size, 4, 1, tmpFile); + if (fread(§ion_address, 1, sizeof(section_address), tmpFile) != sizeof(section_address)) + goto fail_io; + if (fread(§ion_size, 1, sizeof(section_size), tmpFile) != sizeof(section_size)) + goto fail_io; section_address = SWAPu32(section_address); section_size = SWAPu32(section_size); #ifdef EMU_LOG EMU_LOG("Loading %08X bytes from %08X to %08X\n", section_size, ftell(tmpFile), section_address); #endif mem = PSXM(section_address); - if (mem != NULL) { + if (mem != INVALID_PTR) { fread_to_ram(mem, section_size, 1, tmpFile); psxCpu->Clear(section_address, section_size / 4); } break; case 3: /* register loading (PC only?) */ fseek(tmpFile, 2, SEEK_CUR); /* unknown field */ - fread(&psxRegs.pc, 4, 1, tmpFile); + if (fread(&psxRegs.pc, 1, sizeof(psxRegs.pc), tmpFile) != sizeof(psxRegs.pc)) + goto fail_io; psxRegs.pc = SWAPu32(psxRegs.pc); break; case 0: /* End of file */ @@ -529,7 +549,16 @@ int Load(const char *ExePath) { CdromLabel[0] = '\0'; } + if (tmpFile) + fclose(tmpFile); return retval; + +fail_io: +#ifndef NDEBUG + SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__); +#endif + fclose(tmpFile); + return -1; } // STATES @@ -563,7 +592,7 @@ struct PcsxSaveFuncs SaveFuncs = { zlib_open, zlib_read, zlib_write, zlib_seek, zlib_close }; -static const char PcsxHeader[32] = "STv4 PCSX v" PACKAGE_VERSION; +static const char PcsxHeader[32] = "STv4 PCSX v" PCSX_VERSION; // Savestate Versioning! // If you make changes to the savestate version, please increment the value below. diff --git a/libpcsxcore/new_dynarec/emu_if.c b/libpcsxcore/new_dynarec/emu_if.c index c09e9eca..dc17f2d4 100644 --- a/libpcsxcore/new_dynarec/emu_if.c +++ b/libpcsxcore/new_dynarec/emu_if.c @@ -190,7 +190,7 @@ void new_dyna_freeze(void *f, int mode) //printf("drc: %d block info entries %s\n", size/8, mode ? "saved" : "loaded"); } -#ifndef DRC_DISABLE +#if !defined(DRC_DISABLE) && !defined(LIGHTREC) /* GTE stuff */ void *gte_handlers[64]; diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index 0423310b..c70ed67f 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -702,7 +702,7 @@ void CALLBACK clearDynarec(void) { int LoadPlugins() { int ret; - char Plugin[MAXPATHLEN]; + char Plugin[MAXPATHLEN * 2]; ReleasePlugins(); SysLibError(); @@ -807,7 +807,7 @@ int ReloadCdromPlugin() if (UsingIso()) { LoadCDRplugin(NULL); } else { - char Plugin[MAXPATHLEN]; + char Plugin[MAXPATHLEN * 2]; sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Cdr); if (LoadCDRplugin(Plugin) == -1) return -1; } @@ -820,7 +820,7 @@ void SetIsoFile(const char *filename) { IsoFile[0] = '\0'; return; } - strncpy(IsoFile, filename, MAXPATHLEN); + strncpy(IsoFile, filename, MAXPATHLEN - 1); } const char *GetIsoFile(void) { diff --git a/libpcsxcore/ppf.c b/libpcsxcore/ppf.c index edebdd03..18c5413e 100644 --- a/libpcsxcore/ppf.c +++ b/libpcsxcore/ppf.c @@ -183,7 +183,7 @@ void BuildPPFCache() { char method, undo = 0, blockcheck = 0; int dizlen, dizyn; unsigned char ppfmem[512]; - char szPPF[MAXPATHLEN]; + char szPPF[MAXPATHLEN * 2]; int count, seekpos, pos; u32 anz; // use 32-bit to avoid stupid overflows s32 ladr, off, anx; @@ -212,7 +212,8 @@ void BuildPPFCache() { if (ppffile == NULL) return; memset(buffer, 0, 5); - fread(buffer, 3, 1, ppffile); + if (fread(buffer, 1, 3, ppffile) != 3) + goto fail_io; if (strcmp(buffer, "PPF") != 0) { SysPrintf(_("Invalid PPF patch: %s.\n"), szPPF); @@ -235,12 +236,14 @@ void BuildPPFCache() { fseek(ppffile, -8, SEEK_END); memset(buffer, 0, 5); - fread(buffer, 4, 1, ppffile); + if (fread(buffer, 1, 4, ppffile) != 4) + goto fail_io; if (strcmp(".DIZ", buffer) != 0) { dizyn = 0; } else { - fread(&dizlen, 4, 1, ppffile); + if (fread(&dizlen, 1, 4, ppffile) != 4) + goto fail_io; dizlen = SWAP32(dizlen); dizyn = 1; } @@ -266,12 +269,15 @@ void BuildPPFCache() { fseek(ppffile, -6, SEEK_END); memset(buffer, 0, 5); - fread(buffer, 4, 1, ppffile); + if (fread(buffer, 1, 4, ppffile) != 4) + goto fail_io; dizlen = 0; if (strcmp(".DIZ", buffer) == 0) { fseek(ppffile, -2, SEEK_END); - fread(&dizlen, 2, 1, ppffile); + // TODO: Endian/size unsafe? + if (fread(&dizlen, 1, 2, ppffile) != 2) + goto fail_io; dizlen = SWAP32(dizlen); dizlen += 36; } @@ -298,13 +304,19 @@ void BuildPPFCache() { // now do the data reading do { fseek(ppffile, seekpos, SEEK_SET); - fread(&pos, 4, 1, ppffile); + if (fread(&pos, 1, sizeof(pos), ppffile) != sizeof(pos)) + goto fail_io; pos = SWAP32(pos); - if (method == 2) fread(buffer, 4, 1, ppffile); // skip 4 bytes on ppf3 (no int64 support here) + if (method == 2) { + // skip 4 bytes on ppf3 (no int64 support here) + if (fread(buffer, 1, 4, ppffile) != 4) + goto fail_io; + } anz = fgetc(ppffile); - fread(ppfmem, anz, 1, ppffile); + if (fread(ppfmem, 1, anz, ppffile) != anz) + goto fail_io; ladr = pos / CD_FRAMESIZE_RAW; off = pos % CD_FRAMESIZE_RAW; @@ -331,6 +343,12 @@ void BuildPPFCache() { FillPPFCache(); // build address array SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, szPPF); + +fail_io: +#ifndef NDEBUG + SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__); +#endif + fclose(ppffile); } // redump.org SBI files, slightly different handling from PCSX-Reloaded @@ -353,12 +371,15 @@ int LoadSBI(const char *fname, int sector_count) { } // 4-byte SBI header - fread(buffer, 1, 4, sbihandle); + if (fread(buffer, 1, 4, sbihandle) != 4) + goto fail_io; + while (1) { s = fread(sbitime, 1, 3, sbihandle); if (s != 3) - break; - fread(&t, 1, 1, sbihandle); + goto fail_io; + if (fread(&t, 1, sizeof(t), sbihandle) != sizeof(t)) + goto fail_io; switch (t) { default: case 1: @@ -379,8 +400,14 @@ int LoadSBI(const char *fname, int sector_count) { } fclose(sbihandle); - return 0; + +fail_io: +#ifndef NDEBUG + SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__); +#endif + fclose(sbihandle); + return -1; } void UnloadSBI(void) { diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 8e993c3f..203f85d1 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -18,7 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. * ***************************************************************************/ -/* Gameblabla 2018-2019 : +/* Gameblabla 2018-2019 : * Numerous changes to bios calls as well as improvements in order to conform to nocash's findings * for the PSX bios calls. Thanks senquack for helping out with some of the changes * and helping to spot issues and refine my patches. @@ -33,6 +33,7 @@ #include "psxbios.h" #include "psxhw.h" #include "gpu.h" +#include "sio.h" #include #if (defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__) @@ -221,7 +222,7 @@ typedef struct { u32 func; } TCB; -typedef struct { +typedef struct { u32 _pc0; u32 gp0; u32 t_addr; @@ -259,7 +260,7 @@ static int pad_buf1len, pad_buf2len; static int pad_stopped = 0; static u32 regs[35]; -static EvCB *Event; +static EvCB *EventCB; static EvCB *HwEV; // 0xf0 static EvCB *EvEV; // 0xf1 static EvCB *RcEV; // 0xf2 @@ -271,10 +272,10 @@ static u32 *heap_addr = NULL; static u32 *heap_end = NULL; static u32 SysIntRP[8]; static int CardState = -1; -static TCB Thread[8]; +static TCB ThreadCB[8]; static int CurThread = 0; static FileDesc FDesc[32]; -static u32 card_active_chan; +static u32 card_active_chan = 0; boolean hleSoftCall = FALSE; @@ -303,12 +304,12 @@ static inline void softCall2(u32 pc) { } static inline void DeliverEvent(u32 ev, u32 spec) { - if (Event[ev][spec].status != EvStACTIVE) return; + if (EventCB[ev][spec].status != EvStACTIVE) return; -// Event[ev][spec].status = EvStALREADY; - if (Event[ev][spec].mode == EvMdINTR) { - softCall2(Event[ev][spec].fhandler); - } else Event[ev][spec].status = EvStALREADY; +// EventCB[ev][spec].status = EvStALREADY; + if (EventCB[ev][spec].mode == EvMdINTR) { + softCall2(EventCB[ev][spec].fhandler); + } else EventCB[ev][spec].status = EvStALREADY; } static unsigned interrupt_r26=0x8004E8B0; @@ -372,7 +373,7 @@ void psxBios_getc(void) // 0x03, 0x35 #endif v0 = -1; - if (pa1) { + if (pa1 != INVALID_PTR) { switch (a0) { case 2: buread(pa1, 1, 1); break; case 3: buread(pa1, 2, 1); break; @@ -391,7 +392,7 @@ void psxBios_putc(void) // 0x09, 0x3B PSXBIOS_LOG("psxBios_%s\n", biosA0n[0x09]); #endif v0 = -1; - if (!pa1) { + if (pa1 == INVALID_PTR) { pc0 = ra; return; } @@ -700,7 +701,7 @@ void psxBios_index() { // 0x1c pc0 = ra; return; } - + do { if (*p == a1) { v0 = a0 + (p - (char *)Ra0); @@ -929,7 +930,7 @@ void psxBios_memcmp() { // 0x2d void psxBios_memchr() { // 0x2e char *p = (char *)Ra0; - + if (a0 == 0 || a2 > 0x7FFFFFFF) { pc0 = ra; @@ -1260,7 +1261,7 @@ void psxBios_printf() { // 0x3f void *psp; psp = PSXM(sp); - if (psp) { + if (psp != INVALID_PTR) { memcpy(save, psp, 4 * 4); psxMu32ref(sp) = SWAP32((u32)a0); psxMu32ref(sp + 4) = SWAP32((u32)a1); @@ -1429,7 +1430,7 @@ void psxBios_GPU_dw() { // 0x46 } pc0 = ra; -} +} void psxBios_mem2vram() { // 0x47 int size; @@ -1457,8 +1458,8 @@ void psxBios_SendGPU() { // 0x48 void psxBios_GPU_cw() { // 0x49 gpuSyncPluginSR(); GPU_writeData(a0); - pc0 = ra; v0 = HW_GPU_STATUS; + pc0 = ra; } void psxBios_GPU_cwb() { // 0x4a @@ -1509,7 +1510,7 @@ void psxBios_LoadExec() { // 51 #endif s_addr = a1; s_size = a2; - a1 = 0xf000; + a1 = 0xf000; psxBios_Load(); header->S_addr = s_addr; @@ -1564,7 +1565,7 @@ void psxBios_SetMem() { // 9f psxHu32ref(0x1060) = SWAP32(new | 0x300); psxMu32ref(0x060) = a0; SysPrintf("Change effective memory : %d MBytes\n",a0); - + default: SysPrintf("Effective memory must be 2/8 MBytes\n"); break; @@ -1584,16 +1585,16 @@ void psxBios__card_info() { // ab #ifdef PSXBIOS_LOG PSXBIOS_LOG("psxBios_%s: %x\n", biosA0n[0xab], a0); #endif - u32 ret; + u32 ret, port; card_active_chan = a0; - - switch (card_active_chan) - { - case 0x00: case 0x01: case 0x02: case 0x03: - ret = Config.Mcd1[0] ? 0x2 : 0x8; - break; - case 0x10: case 0x11: case 0x12: case 0x13: - ret = Config.Mcd2[0] ? 0x2 : 0x8; + port = card_active_chan >> 4; + + switch (port) { + case 0x0: + case 0x1: + ret = 0x2; + if (McdDisable[port & 1]) + ret = 0x8; break; default: #ifdef PSXBIOS_LOG @@ -1602,8 +1603,12 @@ void psxBios__card_info() { // ab ret = 0x11; break; } - - DeliverEvent(0x11, 0x2); // 0xf4000001, 0x0004 + + if (McdDisable[0] && McdDisable[1]) + ret = 0x8; + + DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 +// DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 DeliverEvent(0x81, ret); // 0xf4000001, 0x0004 v0 = 1; pc0 = ra; } @@ -1692,14 +1697,14 @@ void psxBios_ResetRCnt() { // 06 } -/* gets ev for use with Event */ +/* gets ev for use with EventCB */ #define GetEv() \ ev = (a0 >> 24) & 0xf; \ if (ev == 0xf) ev = 0x5; \ ev*= 32; \ ev+= a0&0x1f; -/* gets spec for use with Event */ +/* gets spec for use with EventCB */ #define GetSpec() \ spec = 0; \ switch (a1) { \ @@ -1737,9 +1742,9 @@ void psxBios_OpenEvent() { // 08 PSXBIOS_LOG("psxBios_%s %x,%x (class:%x, spec:%x, mode:%x, func:%x)\n", biosB0n[0x08], ev, spec, a0, a1, a2, a3); #endif - Event[ev][spec].status = EvStWAIT; - Event[ev][spec].mode = a2; - Event[ev][spec].fhandler = a3; + EventCB[ev][spec].status = EvStWAIT; + EventCB[ev][spec].mode = a2; + EventCB[ev][spec].fhandler = a3; v0 = ev | (spec << 8); pc0 = ra; @@ -1755,7 +1760,7 @@ void psxBios_CloseEvent() { // 09 PSXBIOS_LOG("psxBios_%s %x,%x\n", biosB0n[0x09], ev, spec); #endif - Event[ev][spec].status = EvStUNUSED; + EventCB[ev][spec].status = EvStUNUSED; v0 = 1; pc0 = ra; } @@ -1768,17 +1773,17 @@ void psxBios_WaitEvent() { // 0a #ifdef PSXBIOS_LOG PSXBIOS_LOG("psxBios_%s %x,%x\n", biosB0n[0x0a], ev, spec); #endif - if (Event[ev][spec].status == EvStUNUSED) + if (EventCB[ev][spec].status == EvStUNUSED) { v0 = 0; - pc0 = ra; + pc0 = ra; return; } - if (Event[ev][spec].status == EvStALREADY) + if (EventCB[ev][spec].status == EvStALREADY) { /* Callback events (mode=EvMdINTR) do never set the ready flag (and thus WaitEvent would hang forever). */ - if (!(Event[ev][spec].mode == EvMdINTR)) Event[ev][spec].status = EvStACTIVE; + if (!(EventCB[ev][spec].mode == EvMdINTR)) EventCB[ev][spec].status = EvStACTIVE; v0 = 1; pc0 = ra; return; @@ -1794,12 +1799,12 @@ void psxBios_TestEvent() { // 0b ev = a0 & 0xff; spec = (a0 >> 8) & 0xff; - if (Event[ev][spec].status == EvStALREADY) + if (EventCB[ev][spec].status == EvStALREADY) { - if (!(Event[ev][spec].mode == EvMdINTR)) Event[ev][spec].status = EvStACTIVE; + if (!(EventCB[ev][spec].mode == EvMdINTR)) EventCB[ev][spec].status = EvStACTIVE; v0 = 1; - } - else + } + else { v0 = 0; } @@ -1821,7 +1826,7 @@ void psxBios_EnableEvent() { // 0c PSXBIOS_LOG("psxBios_%s %x,%x\n", biosB0n[0x0c], ev, spec); #endif - Event[ev][spec].status = EvStACTIVE; + EventCB[ev][spec].status = EvStACTIVE; v0 = 1; pc0 = ra; } @@ -1836,7 +1841,7 @@ void psxBios_DisableEvent() { // 0d PSXBIOS_LOG("psxBios_%s %x,%x\n", biosB0n[0x0d], ev, spec); #endif - Event[ev][spec].status = EvStWAIT; + EventCB[ev][spec].status = EvStWAIT; v0 = 1; pc0 = ra; } @@ -1850,7 +1855,7 @@ void psxBios_OpenTh() { // 0e for (th=1; th<8; th++) { - if (Thread[th].status == 0) break; + if (ThreadCB[th].status == 0) break; } if (th == 8) { @@ -1867,10 +1872,10 @@ void psxBios_OpenTh() { // 0e PSXBIOS_LOG("psxBios_%s: %x\n", biosB0n[0x0e], th); #endif - Thread[th].status = 1; - Thread[th].func = a0; - Thread[th].reg[29] = a1; - Thread[th].reg[28] = a2; + ThreadCB[th].status = 1; + ThreadCB[th].func = a0; + ThreadCB[th].reg[29] = a1; + ThreadCB[th].reg[28] = a2; v0 = th; pc0 = ra; } @@ -1887,8 +1892,8 @@ void psxBios_CloseTh() { // 0f #endif /* The return value is always 1 (even if the handle was already closed). */ v0 = 1; - if (Thread[th].status != 0) { - Thread[th].status = 0; + if (ThreadCB[th].status != 0) { + ThreadCB[th].status = 0; } pc0 = ra; @@ -1906,18 +1911,18 @@ void psxBios_ChangeTh() { // 10 #endif /* The return value is always 1. */ v0 = 1; - if (Thread[th].status == 0 || CurThread == th) { + if (ThreadCB[th].status == 0 || CurThread == th) { pc0 = ra; } else { - if (Thread[CurThread].status == 2) { - Thread[CurThread].status = 1; - Thread[CurThread].func = ra; - memcpy(Thread[CurThread].reg, psxRegs.GPR.r, 32*4); + if (ThreadCB[CurThread].status == 2) { + ThreadCB[CurThread].status = 1; + ThreadCB[CurThread].func = ra; + memcpy(ThreadCB[CurThread].reg, psxRegs.GPR.r, 32*4); } - memcpy(psxRegs.GPR.r, Thread[th].reg, 32*4); - pc0 = Thread[th].func; - Thread[th].status = 2; + memcpy(psxRegs.GPR.r, ThreadCB[th].reg, 32*4); + pc0 = ThreadCB[th].func; + ThreadCB[th].status = 2; CurThread = th; } } @@ -2021,26 +2026,27 @@ void psxBios_UnDeliverEvent() { // 0x20 PSXBIOS_LOG("psxBios_%s %x,%x\n", biosB0n[0x20], ev, spec); #endif - if (Event[ev][spec].status == EvStALREADY && - Event[ev][spec].mode == EvMdNOINTR) - Event[ev][spec].status = EvStACTIVE; + if (EventCB[ev][spec].status == EvStALREADY && + EventCB[ev][spec].mode == EvMdNOINTR) + EventCB[ev][spec].status = EvStACTIVE; pc0 = ra; } char ffile[64], *pfile; int nfile; + static void buopen(int mcd, char *ptr, char *cfg) { int i; - char *fptr = ptr; + char *mcd_data = ptr; strcpy(FDesc[1 + mcd].name, Ra0+5); FDesc[1 + mcd].offset = 0; FDesc[1 + mcd].mode = a1; for (i=1; i<16; i++) { - fptr += 128; + const char *fptr = mcd_data + 128 * i; if ((*fptr & 0xF0) != 0x50) continue; if (strcmp(FDesc[1 + mcd].name, fptr+0xa)) continue; FDesc[1 + mcd].mcfile = i; @@ -2049,12 +2055,11 @@ static void buopen(int mcd, char *ptr, char *cfg) break; } if (a1 & 0x200 && v0 == -1) { /* FCREAT */ - fptr = ptr; for (i=1; i<16; i++) { int j, xor, nblk = a1 >> 16; - u8 *pptr, *fptr2; + char *pptr, *fptr2; + char *fptr = mcd_data + 128 * i; - fptr += 128; if ((*fptr & 0xF0) != 0xa0) continue; FDesc[1 + mcd].mcfile = i; @@ -2064,12 +2069,12 @@ static void buopen(int mcd, char *ptr, char *cfg) fptr[6] = 0x00; fptr[7] = 0x00; strcpy(fptr+0xa, FDesc[1 + mcd].name); - pptr = fptr2 = (u8 *)fptr; + pptr = fptr2 = fptr; for(j=2; j<=nblk; j++) { int k; for(i++; i<16; i++) { fptr2 += 128; - + memset(fptr2, 0, 128); fptr2[0] = j < nblk ? 0x52 : 0x53; pptr[8] = i - 1; @@ -2107,7 +2112,7 @@ void psxBios_open() { // 0x32 v0 = -1; - if (pa0) { + if (pa0 != INVALID_PTR) { if (!strncmp(pa0, "bu00", 4)) { buopen(1, Mcd1Data, Config.Mcd1); } @@ -2161,13 +2166,13 @@ void psxBios_read() { // 0x34 v0 = -1; - if (pa1) { + if (pa1 != INVALID_PTR) { switch (a0) { case 2: buread(pa1, 1, a2); break; case 3: buread(pa1, 2, a2); break; } } - + pc0 = ra; } @@ -2184,7 +2189,7 @@ void psxBios_write() { // 0x35/0x03 #endif v0 = -1; - if (!pa1) { + if (pa1 == INVALID_PTR) { pc0 = ra; return; } @@ -2233,7 +2238,7 @@ void psxBios_puts() { // 3e/3f /* To avoid any issues with different behaviour when using the libc's own strlen instead. * We want to mimic the PSX's behaviour in this case for bufile. */ -static size_t strlen_internal(char* p) +static size_t strlen_internal(char* p) { size_t size_of_array = 0; while (*p++) size_of_array++; @@ -2274,7 +2279,7 @@ static size_t strlen_internal(char* p) /* * struct DIRENTRY* firstfile(char *name,struct DIRENTRY *dir); */ - + void psxBios_firstfile() { // 42 struct DIRENTRY *dir = (struct DIRENTRY *)Ra1; void *pa0 = Ra0; @@ -2288,7 +2293,7 @@ void psxBios_firstfile() { // 42 v0 = 0; - if (pa0) { + if (pa0 != INVALID_PTR) { strcpy(ffile, pa0); pfile = ffile+5; nfile = 0; @@ -2366,7 +2371,7 @@ void psxBios_rename() { // 44 v0 = 0; - if (pa0 && pa1) { + if (pa0 != INVALID_PTR && pa1 != INVALID_PTR) { if (!strncmp(pa0, "bu00", 4) && !strncmp(pa1, "bu00", 4)) { burename(1); } @@ -2408,7 +2413,7 @@ void psxBios_delete() { // 45 v0 = 0; - if (pa0) { + if (pa0 != INVALID_PTR) { if (!strncmp(pa0, "bu00", 4)) { budelete(1); } @@ -2471,7 +2476,7 @@ void psxBios__card_write() { // 0x4e card_active_chan = a0; port = a0 >> 4; - if (pa2) { + if (pa2 != INVALID_PTR) { if (port == 0) { memcpy(Mcd1Data + a1 * 128, pa2, 128); SaveMcd(Config.Mcd1, Mcd1Data, a1 * 128, 128); @@ -2507,7 +2512,7 @@ void psxBios__card_read() { // 0x4f card_active_chan = a0; port = a0 >> 4; - if (pa2) { + if (pa2 != INVALID_PTR) { if (port == 0) { memcpy(pa2, Mcd1Data + a1 * 128, 128); } else { @@ -2531,7 +2536,7 @@ void psxBios__new_card() { // 0x50 /* According to a user, this allows Final Fantasy Tactics to save/load properly */ void psxBios__get_error(void) // 55 -{ +{ v0 = 0; pc0 = ra; } @@ -2607,7 +2612,7 @@ void psxBios__card_chan() { // 0x58 void psxBios_ChangeClearPad() { // 5b #ifdef PSXBIOS_LOG PSXBIOS_LOG("psxBios_%s: %x\n", biosB0n[0x5b], a0); -#endif +#endif pc0 = ra; } @@ -2675,11 +2680,11 @@ void psxBios_ChangeClearRCnt() { // 0a pc0 = ra; } -void psxBios_dummy() { +void psxBios_dummy() { #ifdef PSXBIOS_LOG PSXBIOS_LOG("unk %x call: %x\n", pc0 & 0x1fffff, t1); #endif - pc0 = ra; + pc0 = ra; } void (*biosA0[256])(); @@ -2690,7 +2695,7 @@ void (*biosC0[256])(); void psxBiosInit() { u32 base, size; - u32 *ptr; + u32 *ptr; int i; uLongf len; @@ -2773,7 +2778,7 @@ void psxBiosInit() { biosA0[0x39] = psxBios_InitHeap; //biosA0[0x3a] = psxBios__exit; biosA0[0x3b] = psxBios_getchar; - biosA0[0x3c] = psxBios_putchar; + biosA0[0x3c] = psxBios_putchar; //biosA0[0x3d] = psxBios_gets; //biosA0[0x40] = psxBios_sys_a0_40; //biosA0[0x41] = psxBios_LoadTest; @@ -2789,7 +2794,7 @@ void psxBiosInit() { biosA0[0x4b] = psxBios_GPU_SendPackets; biosA0[0x4c] = psxBios_sys_a0_4c; biosA0[0x4d] = psxBios_GPU_GetGPUStatus; - //biosA0[0x4e] = psxBios_GPU_sync; + //biosA0[0x4e] = psxBios_GPU_sync; //biosA0[0x4f] = psxBios_sys_a0_4f; //biosA0[0x50] = psxBios_sys_a0_50; biosA0[0x51] = psxBios_LoadExec; @@ -2841,10 +2846,10 @@ void psxBiosInit() { //biosA0[0x7f] = psxBios_sys_a0_7f; //biosA0[0x80] = psxBios_sys_a0_80; //biosA0[0x81] = psxBios_sys_a0_81; - //biosA0[0x82] = psxBios_sys_a0_82; + //biosA0[0x82] = psxBios_sys_a0_82; //biosA0[0x83] = psxBios_sys_a0_83; //biosA0[0x84] = psxBios_sys_a0_84; - //biosA0[0x85] = psxBios__96_CdStop; + //biosA0[0x85] = psxBios__96_CdStop; //biosA0[0x86] = psxBios_sys_a0_86; //biosA0[0x87] = psxBios_sys_a0_87; //biosA0[0x88] = psxBios_sys_a0_88; @@ -2996,7 +3001,7 @@ void psxBiosInit() { //biosC0[0x07] = psxBios_InstallExeptionHandler; //biosC0[0x08] = psxBios_SysInitMemory; //biosC0[0x09] = psxBios_SysInitKMem; - biosC0[0x0a] = psxBios_ChangeClearRCnt; + biosC0[0x0a] = psxBios_ChangeClearRCnt; //biosC0[0x0b] = psxBios_SystemError; //biosC0[0x0c] = psxBios_InitDefInt; //biosC0[0x0d] = psxBios_sys_c0_0d; @@ -3019,14 +3024,14 @@ void psxBiosInit() { /**/ base = 0x1000; size = sizeof(EvCB) * 32; - Event = (void *)&psxR[base]; base += size * 6; - memset(Event, 0, size * 6); - HwEV = Event; - EvEV = Event + 32; - RcEV = Event + 32 * 2; - UeEV = Event + 32 * 3; - SwEV = Event + 32 * 4; - ThEV = Event + 32 * 5; + EventCB = (void *)&psxR[base]; base += size * 6; + memset(EventCB, 0, size * 6); + HwEV = EventCB; + EvEV = EventCB + 32; + RcEV = EventCB + 32 * 2; + UeEV = EventCB + 32 * 3; + SwEV = EventCB + 32 * 4; + ThEV = EventCB + 32 * 5; ptr = (u32 *)&psxM[0x0874]; // b0 table ptr[0] = SWAPu32(0x4c54 - 0x884); @@ -3035,8 +3040,8 @@ void psxBiosInit() { ptr[6] = SWAPu32(0xc80); memset(SysIntRP, 0, sizeof(SysIntRP)); - memset(Thread, 0, sizeof(Thread)); - Thread[0].status = 2; // main thread + memset(ThreadCB, 0, sizeof(ThreadCB)); + ThreadCB[0].status = 2; // main thread pad_stopped = 1; jmp_int = NULL; @@ -3064,7 +3069,7 @@ void psxBiosInit() { */ // opcode HLE psxRu32ref(0x0000) = SWAPu32((0x3b << 26) | 4); - /* Whatever this does, it actually breaks CTR, even without the uninitiliazed memory patch. + /* Whatever this does, it actually breaks CTR, even without the uninitiliazed memory patch. Normally games shouldn't read from address 0 yet they do. See explanation below in details. */ //psxMu32ref(0x0000) = SWAPu32((0x3b << 26) | 0); psxMu32ref(0x00a0) = SWAPu32((0x3b << 26) | 1); @@ -3092,14 +3097,14 @@ void psxBiosInit() { psxHu32ref(0x1060) = SWAPu32(0x00000b88); hleSoftCall = FALSE; - + /* Some games like R-Types, CTR, Fade to Black read from adress 0x00000000 due to uninitialized pointers. See Garbage Area at Address 00000000h in Nocash PSX Specfications for more information. Here are some examples of games not working with this fix in place : R-type won't get past the Irem logo if not implemented. Crash Team Racing will softlock after the Sony logo. */ - + psxMu32ref(0x0000) = SWAPu32(0x00000003); /* But overwritten by 00000003h after soon. @@ -3280,7 +3285,7 @@ void psxBiosException() { break; case 2: // ExitCritical - enable irq's - psxRegs.CP0.n.Status |= 0x404; + psxRegs.CP0.n.Status |= 0x404; break; /* Normally this should cover SYS(00h, SYS(04h but they don't do anything relevant so... */ default: @@ -3339,7 +3344,7 @@ void psxBiosFreeze(int Mode) { bfreezes(regs); bfreezes(SysIntRP); bfreezel(&CardState); - bfreezes(Thread); + bfreezes(ThreadCB); bfreezel(&CurThread); bfreezes(FDesc); bfreezel(&card_active_chan); diff --git a/libpcsxcore/psxcommon.h b/libpcsxcore/psxcommon.h index 382d9194..522abbc8 100644 --- a/libpcsxcore/psxcommon.h +++ b/libpcsxcore/psxcommon.h @@ -51,7 +51,9 @@ extern "C" { #include #include #include +#ifndef __SWITCH__ #include +#endif #include // Define types @@ -130,8 +132,10 @@ typedef struct { boolean Mdec; boolean PsxAuto; boolean Cdda; + boolean AsyncCD; boolean CHD_Precache; /* loads disk image into memory, works with CHD only. */ boolean HLE; + boolean SlowBoot; boolean Debug; boolean PsxOut; boolean UseNet; diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c index 32a18475..e19b7819 100644 --- a/libpcsxcore/psxcounters.c +++ b/libpcsxcore/psxcounters.c @@ -376,7 +376,7 @@ void psxRcntUpdate() psxRcntSet(); -#ifndef NDEBUG +#if 0 //ndef NDEBUG DebugVSync(); #endif } diff --git a/libpcsxcore/psxdma.c b/libpcsxcore/psxdma.c index 70e12f6e..d7c4caec 100644 --- a/libpcsxcore/psxdma.c +++ b/libpcsxcore/psxdma.c @@ -45,7 +45,7 @@ void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU PSXDMA_LOG("*** DMA4 SPU - mem2spu *** %x addr = %x size = %x\n", chcr, madr, bcr); #endif ptr = (u16 *)PSXM(madr); - if (ptr == NULL) { + if (ptr == INVALID_PTR) { #ifdef CPU_LOG CPU_LOG("*** DMA4 SPU - mem2spu *** NULL Pointer!!!\n"); #endif @@ -62,7 +62,7 @@ void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU PSXDMA_LOG("*** DMA4 SPU - spu2mem *** %x addr = %x size = %x\n", chcr, madr, bcr); #endif ptr = (u16 *)PSXM(madr); - if (ptr == NULL) { + if (ptr == INVALID_PTR) { #ifdef CPU_LOG CPU_LOG("*** DMA4 SPU - spu2mem *** NULL Pointer!!!\n"); #endif @@ -137,7 +137,7 @@ void psxDma2(u32 madr, u32 bcr, u32 chcr) { // GPU PSXDMA_LOG("*** DMA2 GPU - vram2mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); #endif ptr = (u32 *)PSXM(madr); - if (ptr == NULL) { + if (ptr == INVALID_PTR) { #ifdef CPU_LOG CPU_LOG("*** DMA2 GPU - vram2mem *** NULL Pointer!!!\n"); #endif @@ -159,7 +159,7 @@ void psxDma2(u32 madr, u32 bcr, u32 chcr) { // GPU PSXDMA_LOG("*** DMA 2 - GPU mem2vram *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); #endif ptr = (u32 *)PSXM(madr); - if (ptr == NULL) { + if (ptr == INVALID_PTR) { #ifdef CPU_LOG CPU_LOG("*** DMA2 GPU - mem2vram *** NULL Pointer!!!\n"); #endif @@ -225,7 +225,7 @@ void psxDma6(u32 madr, u32 bcr, u32 chcr) { #endif if (chcr == 0x11000002) { - if (mem == NULL) { + if (mem == INVALID_PTR) { #ifdef CPU_LOG CPU_LOG("*** DMA6 OT *** NULL Pointer!!!\n"); #endif diff --git a/libpcsxcore/psxhle.c b/libpcsxcore/psxhle.c index 064d4011..7ca81b47 100644 --- a/libpcsxcore/psxhle.c +++ b/libpcsxcore/psxhle.c @@ -23,6 +23,12 @@ #include "psxhle.h" +#if 0 +#define PSXHLE_LOG SysPrintf +#else +#define PSXHLE_LOG(...) +#endif + static void hleDummy() { psxRegs.pc = psxRegs.GPR.n.ra; @@ -54,10 +60,10 @@ static void hleC0() { } static void hleBootstrap() { // 0xbfc00000 - SysPrintf("hleBootstrap\n"); + PSXHLE_LOG("hleBootstrap\n"); CheckCdrom(); LoadCdrom(); - SysPrintf("CdromLabel: \"%s\": PC = %8.8lx (SP = %8.8lx)\n", CdromLabel, psxRegs.pc, psxRegs.GPR.n.sp); + PSXHLE_LOG("CdromLabel: \"%s\": PC = %8.8lx (SP = %8.8lx)\n", CdromLabel, psxRegs.pc, psxRegs.GPR.n.sp); } typedef struct { @@ -77,7 +83,7 @@ typedef struct { static void hleExecRet() { EXEC *header = (EXEC*)PSXM(psxRegs.GPR.n.s0); - SysPrintf("ExecRet %x: %x\n", psxRegs.GPR.n.s0, header->ret); + PSXHLE_LOG("ExecRet %x: %x\n", psxRegs.GPR.n.s0, header->ret); psxRegs.GPR.n.ra = header->ret; psxRegs.GPR.n.sp = header->_sp; @@ -89,7 +95,7 @@ static void hleExecRet() { psxRegs.pc = psxRegs.GPR.n.ra; } -void (* const psxHLEt[])() = { +void (* const psxHLEt[8])() = { hleDummy, hleA0, hleB0, hleC0, hleBootstrap, hleExecRet, hleDummy, hleDummy diff --git a/libpcsxcore/psxinterpreter.c b/libpcsxcore/psxinterpreter.c index 4ae9417a..3d083645 100644 --- a/libpcsxcore/psxinterpreter.c +++ b/libpcsxcore/psxinterpreter.c @@ -1101,7 +1101,7 @@ static void intExecute() { execI_(memRLUT, regs_); } -static void intExecuteBlock() { +void intExecuteBlock() { psxRegisters *regs_ = &psxRegs; u8 **memRLUT = psxMemRLUT; diff --git a/libpcsxcore/psxinterpreter.h b/libpcsxcore/psxinterpreter.h index f8581b82..b3652c0e 100644 --- a/libpcsxcore/psxinterpreter.h +++ b/libpcsxcore/psxinterpreter.h @@ -8,4 +8,7 @@ void MTC0(psxRegisters *regs_, int reg, u32 val); void gteNULL(struct psxCP2Regs *regs); extern void (*psxCP2[64])(struct psxCP2Regs *regs); +// called by lightrec +void intExecuteBlock(); + #endif // __PSXINTERPRETER_H__ diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c index 2a963334..37a0efd0 100644 --- a/libpcsxcore/psxmem.c +++ b/libpcsxcore/psxmem.c @@ -30,8 +30,13 @@ //#include "debug.h" #define DebugCheckBP(...) +#include "lightrec/mem.h" #include "memmap.h" +#ifdef USE_LIBRETRO_VFS +#include +#endif + #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON #endif @@ -52,7 +57,7 @@ retry: if (psxMapHook != NULL) { ret = psxMapHook(addr, size, 0, tag); if (ret == NULL) - return NULL; + return MAP_FAILED; } else { /* avoid MAP_FIXED, it overrides existing mappings.. */ @@ -62,7 +67,7 @@ retry: req = (void *)(uintptr_t)addr; ret = mmap(req, size, PROT_READ | PROT_WRITE, flags, -1, 0); if (ret == MAP_FAILED) - return NULL; + return ret; } if (addr != 0 && ret != (void *)(uintptr_t)addr) { @@ -71,7 +76,7 @@ retry: if (is_fixed) { psxUnmap(ret, size, tag); - return NULL; + return MAP_FAILED; } if (((addr ^ (unsigned long)(uintptr_t)ret) & ~0xff000000l) && try_ < 2) @@ -128,33 +133,71 @@ u8 **psxMemRLUT = NULL; 0xbfc0_0000-0xbfc7_ffff BIOS Mirror (512K) Uncached */ -int psxMemInit() { - int i; - - psxMemRLUT = (u8 **)malloc(0x10000 * sizeof(void *)); - psxMemWLUT = (u8 **)malloc(0x10000 * sizeof(void *)); - memset(psxMemRLUT, 0, 0x10000 * sizeof(void *)); - memset(psxMemWLUT, 0, 0x10000 * sizeof(void *)); - +static int psxMemInitMap(void) +{ psxM = psxMap(0x80000000, 0x00210000, 1, MAP_TAG_RAM); - if (psxM == NULL) + if (psxM == MAP_FAILED) psxM = psxMap(0x77000000, 0x00210000, 0, MAP_TAG_RAM); - if (psxM == NULL) { + if (psxM == MAP_FAILED) { SysMessage(_("mapping main RAM failed")); + psxM = NULL; return -1; } - psxP = &psxM[0x200000]; + psxH = psxMap(0x1f800000, 0x10000, 0, MAP_TAG_OTHER); + if (psxH == MAP_FAILED) { + SysMessage(_("Error allocating memory!")); + psxMemShutdown(); + return -1; + } + psxR = psxMap(0x1fc00000, 0x80000, 0, MAP_TAG_OTHER); + if (psxR == MAP_FAILED) { + SysMessage(_("Error allocating memory!")); + psxMemShutdown(); + return -1; + } - if (psxMemRLUT == NULL || psxMemWLUT == NULL || - psxR == NULL || psxP == NULL || psxH == NULL) { + return 0; +} + +static void psxMemFreeMap(void) +{ + if (psxM) psxUnmap(psxM, 0x00210000, MAP_TAG_RAM); + if (psxH) psxUnmap(psxH, 0x10000, MAP_TAG_OTHER); + if (psxR) psxUnmap(psxR, 0x80000, MAP_TAG_OTHER); + psxM = psxH = psxR = NULL; + psxP = NULL; +} + +int psxMemInit(void) +{ + unsigned int i; + int ret; + + if (LIGHTREC_CUSTOM_MAP) + ret = lightrec_init_mmap(); + else + ret = psxMemInitMap(); + if (ret) { + SysMessage(_("Error allocating memory!")); + psxMemShutdown(); + return -1; + } + + psxMemRLUT = (u8 **)malloc(0x10000 * sizeof(void *)); + psxMemWLUT = (u8 **)malloc(0x10000 * sizeof(void *)); + + if (psxMemRLUT == NULL || psxMemWLUT == NULL) { SysMessage(_("Error allocating memory!")); psxMemShutdown(); return -1; } + memset(psxMemRLUT, (uintptr_t)INVALID_PTR, 0x10000 * sizeof(void *)); + memset(psxMemWLUT, (uintptr_t)INVALID_PTR, 0x10000 * sizeof(void *)); + // MemR for (i = 0; i < 0x80; i++) psxMemRLUT[i + 0x0000] = (u8 *)&psxM[(i & 0x1f) << 16]; @@ -179,7 +222,7 @@ int psxMemInit() { // NOTE: Not sure if this is needed to fix any games but seems wise, // seeing as some games do read from PIO as part of copy-protection // check. (See fix in psxMemReset() regarding psxP region reads). - psxMemWLUT[0x1f00] = NULL; + psxMemWLUT[0x1f00] = INVALID_PTR; psxMemWLUT[0x1f80] = (u8 *)psxH; return 0; @@ -192,6 +235,8 @@ void psxMemReset() { memset(psxM, 0, 0x00200000); memset(psxP, 0xff, 0x00010000); + Config.HLE = TRUE; + if (strcmp(Config.Bios, "HLE") != 0) { sprintf(bios, "%s/%s", Config.BiosDir, Config.Bios); f = fopen(bios, "rb"); @@ -199,19 +244,22 @@ void psxMemReset() { if (f == NULL) { SysMessage(_("Could not open BIOS:\"%s\". Enabling HLE Bios!\n"), bios); memset(psxR, 0, 0x80000); - Config.HLE = TRUE; } else { - fread(psxR, 1, 0x80000, f); + if (fread(psxR, 1, 0x80000, f) == 0x80000) { + Config.HLE = FALSE; + } else { + SysMessage(_("The selected BIOS:\"%s\" is of wrong size. Enabling HLE Bios!\n"), bios); + } fclose(f); - Config.HLE = FALSE; } - } else Config.HLE = TRUE; + } } void psxMemShutdown() { - psxUnmap(psxM, 0x00210000, MAP_TAG_RAM); psxM = NULL; - psxUnmap(psxH, 0x10000, MAP_TAG_OTHER); psxH = NULL; - psxUnmap(psxR, 0x80000, MAP_TAG_OTHER); psxR = NULL; + if (LIGHTREC_CUSTOM_MAP) + lightrec_free_mmap(); + else + psxMemFreeMap(); free(psxMemRLUT); psxMemRLUT = NULL; free(psxMemWLUT); psxMemWLUT = NULL; @@ -231,7 +279,7 @@ u8 psxMemRead8(u32 mem) { return psxHwRead8(mem); } else { p = (char *)(psxMemRLUT[t]); - if (p != NULL) { + if (p != INVALID_PTR) { if (Config.Debug) DebugCheckBP((mem & 0xffffff) | 0x80000000, R1); return *(u8 *)(p + (mem & 0xffff)); @@ -256,7 +304,7 @@ u16 psxMemRead16(u32 mem) { return psxHwRead16(mem); } else { p = (char *)(psxMemRLUT[t]); - if (p != NULL) { + if (p != INVALID_PTR) { if (Config.Debug) DebugCheckBP((mem & 0xffffff) | 0x80000000, R2); return SWAPu16(*(u16 *)(p + (mem & 0xffff))); @@ -281,7 +329,7 @@ u32 psxMemRead32(u32 mem) { return psxHwRead32(mem); } else { p = (char *)(psxMemRLUT[t]); - if (p != NULL) { + if (p != INVALID_PTR) { if (Config.Debug) DebugCheckBP((mem & 0xffffff) | 0x80000000, R4); return SWAPu32(*(u32 *)(p + (mem & 0xffff))); @@ -306,7 +354,7 @@ void psxMemWrite8(u32 mem, u8 value) { psxHwWrite8(mem, value); } else { p = (char *)(psxMemWLUT[t]); - if (p != NULL) { + if (p != INVALID_PTR) { if (Config.Debug) DebugCheckBP((mem & 0xffffff) | 0x80000000, W1); *(u8 *)(p + (mem & 0xffff)) = value; @@ -333,7 +381,7 @@ void psxMemWrite16(u32 mem, u16 value) { psxHwWrite16(mem, value); } else { p = (char *)(psxMemWLUT[t]); - if (p != NULL) { + if (p != INVALID_PTR) { if (Config.Debug) DebugCheckBP((mem & 0xffffff) | 0x80000000, W2); *(u16 *)(p + (mem & 0xffff)) = SWAPu16(value); @@ -361,7 +409,7 @@ void psxMemWrite32(u32 mem, u32 value) { psxHwWrite32(mem, value); } else { p = (char *)(psxMemWLUT[t]); - if (p != NULL) { + if (p != INVALID_PTR) { if (Config.Debug) DebugCheckBP((mem & 0xffffff) | 0x80000000, W4); *(u32 *)(p + (mem & 0xffff)) = SWAPu32(value); @@ -385,9 +433,9 @@ void psxMemWrite32(u32 mem, u32 value) { case 0x800: case 0x804: if (writeok == 0) break; writeok = 0; - memset(psxMemWLUT + 0x0000, 0, 0x80 * sizeof(void *)); - memset(psxMemWLUT + 0x8000, 0, 0x80 * sizeof(void *)); - memset(psxMemWLUT + 0xa000, 0, 0x80 * sizeof(void *)); + memset(psxMemWLUT + 0x0000, (uintptr_t)INVALID_PTR, 0x80 * sizeof(void *)); + memset(psxMemWLUT + 0x8000, (uintptr_t)INVALID_PTR, 0x80 * sizeof(void *)); + memset(psxMemWLUT + 0xa000, (uintptr_t)INVALID_PTR, 0x80 * sizeof(void *)); /* Required for icache interpreter otherwise Armored Core won't boot on icache interpreter */ psxCpu->Notify(R3000ACPU_NOTIFY_CACHE_ISOLATED, NULL); break; @@ -423,7 +471,7 @@ void *psxMemPointer(u32 mem) { return NULL; } else { p = (char *)(psxMemWLUT[t]); - if (p != NULL) { + if (p != INVALID_PTR) { return (void *)(p + (mem & 0xffff)); } return NULL; diff --git a/libpcsxcore/psxmem.h b/libpcsxcore/psxmem.h index ec4b970a..14ff0033 100644 --- a/libpcsxcore/psxmem.h +++ b/libpcsxcore/psxmem.h @@ -46,6 +46,12 @@ extern "C" { #endif +#ifdef LIGHTREC +#define INVALID_PTR ((void *)-1) +#else +#define INVALID_PTR NULL +#endif + extern s8 *psxM; #define psxMs8(mem) psxM[(mem) & 0x1fffff] #define psxMs16(mem) (SWAP16(*(s16 *)&psxM[(mem) & 0x1fffff])) @@ -109,7 +115,7 @@ extern s8 *psxH; extern u8 **psxMemWLUT; extern u8 **psxMemRLUT; -#define PSXM(mem) (psxMemRLUT[(mem) >> 16] == 0 ? NULL : (u8*)(psxMemRLUT[(mem) >> 16] + ((mem) & 0xffff))) +#define PSXM(mem) (psxMemRLUT[(mem) >> 16] == INVALID_PTR ? INVALID_PTR : (u8*)(psxMemRLUT[(mem) >> 16] + ((mem) & 0xffff))) #define PSXMs8(mem) (*(s8 *)PSXM(mem)) #define PSXMs16(mem) (SWAP16(*(s16 *)PSXM(mem))) #define PSXMs32(mem) (SWAP32(*(s32 *)PSXM(mem))) diff --git a/libpcsxcore/r3000a.c b/libpcsxcore/r3000a.c index d8268e2a..ddf83886 100644 --- a/libpcsxcore/r3000a.c +++ b/libpcsxcore/r3000a.c @@ -33,7 +33,7 @@ psxRegisters psxRegs; #endif int psxInit() { - SysPrintf(_("Running PCSX Version %s (%s).\n"), PACKAGE_VERSION, __DATE__); + SysPrintf(_("Running PCSX Version %s (%s).\n"), PCSX_VERSION, __DATE__); #ifndef DRC_DISABLE if (Config.Cpu == CPU_INTERPRETER) { @@ -77,10 +77,11 @@ void psxReset() { } void psxShutdown() { - psxMemShutdown(); psxBiosShutdown(); psxCpu->Shutdown(); + + psxMemShutdown(); } void psxException(u32 code, u32 bd) { diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c index 329bc36b..6478338d 100644 --- a/libpcsxcore/sio.c +++ b/libpcsxcore/sio.c @@ -24,6 +24,10 @@ #include "sio.h" #include +#ifdef USE_LIBRETRO_VFS +#include +#endif + // Status Flags #define TX_RDY 0x0001 #define RX_RDY 0x0002 @@ -407,6 +411,12 @@ void LoadMcd(int mcd, char *str) { } McdDisable[mcd - 1] = 0; +#ifdef HAVE_LIBRETRO + // memcard1 is handled by libretro + if (mcd == 1) + return; +#endif + if (str == NULL || strcmp(str, "none") == 0) { McdDisable[mcd - 1] = 1; return; @@ -428,7 +438,12 @@ void LoadMcd(int mcd, char *str) { else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } - fread(data, 1, MCD_SIZE, f); + if (fread(data, 1, MCD_SIZE, f) != MCD_SIZE) { +#ifndef NDEBUG + SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__); +#endif + memset(data, 0x00, MCD_SIZE); + } fclose(f); } else @@ -443,7 +458,12 @@ void LoadMcd(int mcd, char *str) { else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } - fread(data, 1, MCD_SIZE, f); + if (fread(data, 1, MCD_SIZE, f) != MCD_SIZE) { +#ifndef NDEBUG + SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__); +#endif + memset(data, 0x00, MCD_SIZE); + } fclose(f); } } diff --git a/libpcsxcore/sjisfont.h b/libpcsxcore/sjisfont.h index 105d6243..0692648b 100644 --- a/libpcsxcore/sjisfont.h +++ b/libpcsxcore/sjisfont.h @@ -21,6 +21,9 @@ // Converted to binary format by Wei Mingzhi . // +#ifndef __SJISFONT_H__ +#define __SJISFONT_H__ + const unsigned char font_8140[] = { 0x78, 0xda, 0xad, 0x3b, 0x3b, 0x90, 0x1b, 0xc9, 0x75, 0x3d, 0x9f, 0x05, 0x1a, 0xcb, 0xe1, 0x4e, @@ -6954,3 +6957,5 @@ const unsigned char font_889f[] = { 0xeb, 0xe7, 0xa8, 0x89, 0x0a, 0x11, 0xbc, 0xbc, 0x33, 0xf9, 0xff, 0xe8, 0xc4, 0x21, 0xbf }; + +#endif /* __SJISFONT_H__ */ diff --git a/libpcsxcore/socket.c b/libpcsxcore/socket.c index 31f82e25..df768e68 100644 --- a/libpcsxcore/socket.c +++ b/libpcsxcore/socket.c @@ -15,6 +15,22 @@ * along with this program; if not, see . */ +#ifdef NO_SOCKET + +int StartServer() { return 0;} +void StopServer() {} +void GetClient() {} +void CloseClient() {} +int HasClient() { return 0;} +int ReadSocket(char * buffer, int len) { return 0;} +int RawReadSocket(char * buffer, int len) { return 0;} +void WriteSocket(char * buffer, int len) {} + +void SetsBlock() {} +void SetsNonblock() {} + +#else // NO_SOCKET + #ifdef _WIN32 #include #endif @@ -119,7 +135,7 @@ void GetClient() { } #endif - sprintf(hello, "000 PCSX Version %s - Debug console\r\n", PACKAGE_VERSION); + sprintf(hello, "000 PCSX Version %s - Debug console\r\n", PCSX_VERSION); WriteSocket(hello, strlen(hello)); ptr = 0; } @@ -252,3 +268,4 @@ void SetsNonblock() { fcntl(server_socket, F_SETFL, flags | O_NONBLOCK); #endif } +#endif // NO_SOCKET diff --git a/plugins/cdrcimg/cdrcimg.c b/plugins/cdrcimg/cdrcimg.c index 22545162..b3bee271 100644 --- a/plugins/cdrcimg/cdrcimg.c +++ b/plugins/cdrcimg/cdrcimg.c @@ -284,7 +284,7 @@ static long CDRinit(void) return -1; } } -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(NO_DYLIB) if (pBZ2_bzBuffToBuffDecompress == NULL) { void *h = dlopen("/usr/lib/libbz2.so.1", RTLD_LAZY); if (h == NULL) diff --git a/plugins/cdrcimg/cdrcimg.h b/plugins/cdrcimg/cdrcimg.h index efeaaf9d..0c6d001c 100644 --- a/plugins/cdrcimg/cdrcimg.h +++ b/plugins/cdrcimg/cdrcimg.h @@ -1,3 +1,7 @@ +#ifndef __P_CDRCIMG_H__ +#define __P_CDRCIMG_H__ void cdrcimg_set_fname(const char *fname); void *cdrcimg_get_sym(const char *sym); + +#endif /* __P_CDRCIMG_H__ */ diff --git a/plugins/dfinput/externals.h b/plugins/dfinput/externals.h index a446956e..2e216fdc 100644 --- a/plugins/dfinput/externals.h +++ b/plugins/dfinput/externals.h @@ -1,3 +1,5 @@ +#ifndef __P_EXTERNALS_H__ +#define __P_EXTERNALS_H__ void dfinput_activate(void); @@ -12,3 +14,5 @@ extern void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in); /* vibration trigger to frontend */ extern int in_enable_vibration; extern void plat_trigger_vibrate(int pad, int low, int high); + +#endif /* __P_EXTERNALS_H__ */ diff --git a/plugins/dfinput/main.c b/plugins/dfinput/main.c index 937f7882..4f1d03f6 100644 --- a/plugins/dfinput/main.c +++ b/plugins/dfinput/main.c @@ -20,6 +20,8 @@ extern unsigned char CALLBACK PAD2__startPoll(int pad); extern unsigned char CALLBACK PAD1__poll(unsigned char value); extern unsigned char CALLBACK PAD2__poll(unsigned char value); +#ifndef HAVE_LIBRETRO + static int old_controller_type1 = -1, old_controller_type2 = -1; #define select_pad(n) \ @@ -37,6 +39,7 @@ static int old_controller_type1 = -1, old_controller_type2 = -1; PAD##n##_poll = PADpoll_guncon; \ guncon_init(); \ break; \ + case PSE_PAD_TYPE_NEGCON: \ case PSE_PAD_TYPE_GUN: \ default: \ PAD##n##_startPoll = PAD##n##__startPoll; \ @@ -49,9 +52,20 @@ void dfinput_activate(void) { PadDataS pad; + pad.portMultitap = -1; + pad.requestPadIndex = 0; PAD1_readPort1(&pad); select_pad(1); + pad.requestPadIndex = 1; PAD2_readPort2(&pad); select_pad(2); } + +#else // use libretro's libpcsxcore/plugins.c code + +void dfinput_activate(void) +{ +} + +#endif diff --git a/plugins/dfinput/main.h b/plugins/dfinput/main.h index e83306a6..96cebfac 100644 --- a/plugins/dfinput/main.h +++ b/plugins/dfinput/main.h @@ -1,3 +1,6 @@ +#ifndef __P_MAIN_H__ +#define __P_MAIN_H__ + #include "psemu_plugin_defs.h" #include "externals.h" @@ -16,3 +19,5 @@ void guncon_init(void); /* get button state and pad type from main emu */ extern long (*PAD1_readPort1)(PadDataS *pad); extern long (*PAD2_readPort2)(PadDataS *pad); + +#endif /* __P_MAIN_H__ */ diff --git a/plugins/dfinput/pad.c b/plugins/dfinput/pad.c index 7e00a113..3e333660 100644 --- a/plugins/dfinput/pad.c +++ b/plugins/dfinput/pad.c @@ -42,6 +42,7 @@ enum { CMD_VIBRATION_TOGGLE = 0x4D, }; +#ifndef HAVE_LIBRETRO static struct { uint8_t PadMode; uint8_t PadID; @@ -242,6 +243,7 @@ static void do_vibration(unsigned char value) break; } } +#endif #if 0 #include @@ -254,6 +256,7 @@ unsigned char PADpoll(unsigned char value) { #define PADpoll PADpoll_ #endif +#ifndef HAVE_LIBRETRO unsigned char PADpoll_pad(unsigned char value) { if (CurByte == 0) { CurCmd = value; @@ -302,3 +305,4 @@ void pad_init(void) padstate[i].PadMode = padstate[i].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD; } } +#endif diff --git a/plugins/dfsound/dma.h b/plugins/dfsound/dma.h index 440536fe..4982432b 100644 --- a/plugins/dfsound/dma.h +++ b/plugins/dfsound/dma.h @@ -24,8 +24,12 @@ // //*************************************************************************// +#ifndef __P_DMA_H__ +#define __P_DMA_H__ unsigned short CALLBACK SPUreadDMA(void); void CALLBACK SPUreadDMAMem(unsigned short * pusPSXMem,int iSize); void CALLBACK SPUwriteDMA(unsigned short val); void CALLBACK SPUwriteDMAMem(unsigned short * pusPSXMem,int iSize); + +#endif /* __P_DMA_H__ */ diff --git a/plugins/dfsound/externals.h b/plugins/dfsound/externals.h index 1cfef661..51574121 100644 --- a/plugins/dfsound/externals.h +++ b/plugins/dfsound/externals.h @@ -15,6 +15,9 @@ * * ***************************************************************************/ +#ifndef __P_SOUND_EXTERNALS_H__ +#define __P_SOUND_EXTERNALS_H__ + #include ///////////////////////////////////////////////////////// @@ -259,3 +262,4 @@ void schedule_next_irq(void); #endif +#endif /* __P_SOUND_EXTERNALS_H__ */ diff --git a/plugins/dfsound/out.h b/plugins/dfsound/out.h index 46070997..e4878a83 100644 --- a/plugins/dfsound/out.h +++ b/plugins/dfsound/out.h @@ -1,3 +1,5 @@ +#ifndef __P_OUT_H__ +#define __P_OUT_H__ struct out_driver { const char *name; @@ -10,3 +12,5 @@ struct out_driver { extern struct out_driver *out_current; void SetupSound(void); + +#endif /* __P_OUT_H__ */ diff --git a/plugins/dfsound/registers.h b/plugins/dfsound/registers.h index 3bca5180..28641b81 100644 --- a/plugins/dfsound/registers.h +++ b/plugins/dfsound/registers.h @@ -15,6 +15,9 @@ * * ***************************************************************************/ +#ifndef __P_REGISTERS_H__ +#define __P_REGISTERS_H__ + #define H_SPUReverbAddr 0x0da2 #define H_SPUirqAddr 0x0da4 #define H_SPUaddr 0x0da6 @@ -154,3 +157,4 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, unsigned int cycles); +#endif /* __P_REGISTERS_H__ */ diff --git a/plugins/dfsound/spu.h b/plugins/dfsound/spu.h index 8a0f2d2e..0cef6520 100644 --- a/plugins/dfsound/spu.h +++ b/plugins/dfsound/spu.h @@ -15,6 +15,11 @@ * * ***************************************************************************/ +#ifndef __P_SPU_H__ +#define __P_SPU_H__ + void ClearWorkingState(void); void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap, unsigned int cycle, int is_start); int CALLBACK SPUplayCDDAchannel(short *pcm, int bytes, unsigned int cycle, int is_start); + +#endif /* __P_SPU_H__ */ diff --git a/plugins/dfsound/spu_c64x.h b/plugins/dfsound/spu_c64x.h index 7c4d5659..56ede38d 100644 --- a/plugins/dfsound/spu_c64x.h +++ b/plugins/dfsound/spu_c64x.h @@ -1,3 +1,6 @@ +#ifndef __P_SPU_C64X_H__ +#define __P_SPU_C64X_H__ + #define COMPONENT_NAME "pcsxr_spu" enum { @@ -26,3 +29,5 @@ struct region_mem { }; #define ACTIVE_CNT 3 + +#endif /* __P_SPU_C64X_H__ */ diff --git a/plugins/dfsound/spu_config.h b/plugins/dfsound/spu_config.h index 3e88a2c2..95c89486 100644 --- a/plugins/dfsound/spu_config.h +++ b/plugins/dfsound/spu_config.h @@ -1,3 +1,6 @@ +#ifndef __P_SPU_CONFIG_H__ +#define __P_SPU_CONFIG_H__ + // user settings typedef struct @@ -15,3 +18,5 @@ typedef struct } SPUConfig; extern SPUConfig spu_config; + +#endif /* __P_SPU_CONFIG_H__ */ diff --git a/plugins/dfsound/stdafx.h b/plugins/dfsound/stdafx.h index 82b0d7e5..96335e38 100644 --- a/plugins/dfsound/stdafx.h +++ b/plugins/dfsound/stdafx.h @@ -15,6 +15,9 @@ * * ***************************************************************************/ +#ifndef __P_STDAFX_H__ +#define __P_STDAFX_H__ + #include #include #include @@ -30,3 +33,5 @@ #endif #include "psemuxa.h" + +#endif /* __P_STDAFX_H__ */ diff --git a/plugins/dfsound/xa.h b/plugins/dfsound/xa.h index cbf2843f..137fe436 100644 --- a/plugins/dfsound/xa.h +++ b/plugins/dfsound/xa.h @@ -15,6 +15,11 @@ * * ***************************************************************************/ +#ifndef __P_XA_H__ +#define __P_XA_H__ + INLINE void MixXA(void); INLINE void FeedXA(xa_decode_t *xap); -INLINE int FeedCDDA(unsigned char *pcm, int nBytes); +INLINE int FeedCDDA(unsigned char *pcm, int nBytes); + +#endif /* __P_XA_H__ */ diff --git a/plugins/dfxvideo/gpulib_if.c b/plugins/dfxvideo/gpulib_if.c index 245d2274..3a41cd7c 100644 --- a/plugins/dfxvideo/gpulib_if.c +++ b/plugins/dfxvideo/gpulib_if.c @@ -301,11 +301,11 @@ void renderer_notify_res_change(void) extern const unsigned char cmd_lengths[256]; -int do_cmd_list(unsigned int *list, int list_len, int *last_cmd) +int do_cmd_list(uint32_t *list, int list_len, int *last_cmd) { unsigned int cmd = 0, len; - unsigned int *list_start = list; - unsigned int *list_end = list + list_len; + uint32_t *list_start = list; + uint32_t *list_end = list + list_len; for (; list < list_end; list += 1 + len) { diff --git a/plugins/dfxvideo/soft.c b/plugins/dfxvideo/soft.c index a9d9e042..5c71fd33 100644 --- a/plugins/dfxvideo/soft.c +++ b/plugins/dfxvideo/soft.c @@ -6317,6 +6317,7 @@ static void DrawSoftwareSpriteMirror(unsigned char * baseAddr,int32_t w,int32_t sprtYa=(sprtY<<10); clutP=(clutY0<<10)+clutX0; for (sprCY=0;sprCY>4)&0xf)])); GetTextureTransColG_SPR(&psxVuw[sprA+1],GETLE16(&psxVuw[clutP+(tC&0xf)])); } + } return; case 1: clutP>>=1; for(sprCY=0;sprCY #ifdef __cplusplus @@ -135,3 +138,5 @@ void GPUrearmedCallbacks(const struct rearmed_cbs *cbs_); #ifdef __cplusplus } #endif + +#endif /* __GPULIB_GPU_H__ */ diff --git a/plugins/gpulib/vout_sdl.c b/plugins/gpulib/vout_sdl.c index b8c4eae2..56ab811c 100644 --- a/plugins/gpulib/vout_sdl.c +++ b/plugins/gpulib/vout_sdl.c @@ -54,7 +54,7 @@ void vout_update(void) int i; SDL_LockSurface(screen); - if (gpu.status.rgb24) + if (gpu.status & PSX_GPU_STATUS_RGB24) { uint8_t *s; int y; diff --git a/plugins/spunull/register.h b/plugins/spunull/register.h index 52128b76..2e0b8923 100644 --- a/plugins/spunull/register.h +++ b/plugins/spunull/register.h @@ -1,3 +1,6 @@ +#ifndef __SPUNULL_REGISTER_H__ +#define __SPUNULL_REGISTER_H__ + #define H_SPUirqAddr 0x0da4 #define H_SPUaddr 0x0da6 #define H_SPUdata 0x0da8 @@ -119,3 +122,4 @@ #define H_SPU_ADSRLevel22 0x0d68 #define H_SPU_ADSRLevel23 0x0d78 +#endif /* __SPUNULL_REGISTER_H__ */