Commit | Line | Data |
---|---|---|
38c2028e | 1 | /* |
003cfc63 | 2 | * (C) notaz, 2012,2014,2015 |
38c2028e | 3 | * |
4 | * This work is licensed under the terms of the GNU GPLv2 or later. | |
5 | * See the COPYING file in the top-level directory. | |
6 | */ | |
7 | ||
805fe9bc | 8 | #define _GNU_SOURCE 1 // strcasestr |
38c2028e | 9 | #include <stdio.h> |
10 | #include <stdlib.h> | |
11 | #include <string.h> | |
74ebc05b | 12 | #include <strings.h> |
d148d265 | 13 | #ifdef __MACH__ |
14 | #include <unistd.h> | |
15 | #include <sys/syscall.h> | |
16 | #endif | |
38c2028e | 17 | |
7a8d521f | 18 | #ifdef SWITCH |
19 | #include <switch.h> | |
20 | #endif | |
21 | ||
38c2028e | 22 | #include "../libpcsxcore/misc.h" |
23 | #include "../libpcsxcore/psxcounters.h" | |
87e5b45f | 24 | #include "../libpcsxcore/psxmem_map.h" |
38c2028e | 25 | #include "../libpcsxcore/new_dynarec/new_dynarec.h" |
23ea11bd | 26 | #include "../libpcsxcore/cdrom.h" |
27 | #include "../libpcsxcore/cdriso.h" | |
6e921e1d | 28 | #include "../libpcsxcore/cheat.h" |
7a8d521f | 29 | #include "../libpcsxcore/r3000a.h" |
abf09485 | 30 | #include "../libpcsxcore/gpu.h" |
f3746eea | 31 | #include "../libpcsxcore/database.h" |
07c13dfd | 32 | #include "../plugins/dfsound/out.h" |
01394a7f | 33 | #include "../plugins/dfsound/spu_config.h" |
c82f907a | 34 | #include "cspace.h" |
38c2028e | 35 | #include "main.h" |
7a8d521f | 36 | #include "menu.h" |
38c2028e | 37 | #include "plugin.h" |
38 | #include "plugin_lib.h" | |
8f2bb0cb | 39 | #include "arm_features.h" |
38c2028e | 40 | #include "revision.h" |
7a8d521f | 41 | |
42 | #include <libretro.h> | |
43 | #include "libretro_core_options.h" | |
44 | ||
45 | #ifdef USE_LIBRETRO_VFS | |
46 | #include <streams/file_stream_transforms.h> | |
47 | #endif | |
48 | ||
49 | #ifdef _3DS | |
50 | #include "3ds/3ds_utils.h" | |
51 | #endif | |
52 | ||
53 | #define PORTS_NUMBER 8 | |
54 | ||
55 | #ifndef MIN | |
56 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
57 | #endif | |
58 | ||
59 | #ifndef MAX | |
60 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
61 | #endif | |
62 | ||
63 | #define ISHEXDEC ((buf[cursor] >= '0') && (buf[cursor] <= '9')) || ((buf[cursor] >= 'a') && (buf[cursor] <= 'f')) || ((buf[cursor] >= 'A') && (buf[cursor] <= 'F')) | |
64 | ||
65 | #define INTERNAL_FPS_SAMPLE_PERIOD 64 | |
66 | ||
67 | //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key | |
68 | static int rebootemu = 0; | |
38c2028e | 69 | |
70 | static retro_video_refresh_t video_cb; | |
71 | static retro_input_poll_t input_poll_cb; | |
72 | static retro_input_state_t input_state_cb; | |
73 | static retro_environment_t environ_cb; | |
74 | static retro_audio_sample_batch_t audio_batch_cb; | |
7a8d521f | 75 | static retro_set_rumble_state_t rumble_cb; |
76 | static struct retro_log_callback logging; | |
77 | static retro_log_printf_t log_cb; | |
78 | ||
79 | static unsigned msg_interface_version = 0; | |
38c2028e | 80 | |
81 | static void *vout_buf; | |
7a8d521f | 82 | static void *vout_buf_ptr; |
5d9e675a | 83 | static int vout_width = 256, vout_height = 240, vout_pitch = 256; |
308c6e67 | 84 | static int vout_fb_dirty; |
f6eb0b1c | 85 | static int psx_w, psx_h; |
1a6164a1 | 86 | static bool vout_can_dupe; |
0e5a7b7d | 87 | static bool duping_enable; |
7a8d521f | 88 | static bool found_bios; |
89 | static bool display_internal_fps = false; | |
90 | static unsigned frame_count = 0; | |
91 | static bool libretro_supports_bitmasks = false; | |
92 | static bool libretro_supports_option_categories = false; | |
93 | static bool show_input_settings = true; | |
94 | #ifdef GPU_PEOPS | |
95 | static bool show_advanced_gpu_peops_settings = true; | |
96 | #endif | |
97 | #ifdef GPU_UNAI | |
98 | static bool show_advanced_gpu_unai_settings = true; | |
99 | #endif | |
100 | static float mouse_sensitivity = 1.0f; | |
6a131b03 | 101 | static unsigned int disk_current_index; |
7a8d521f | 102 | |
103 | typedef enum | |
104 | { | |
105 | FRAMESKIP_NONE = 0, | |
106 | FRAMESKIP_AUTO, | |
107 | FRAMESKIP_AUTO_THRESHOLD, | |
108 | FRAMESKIP_FIXED_INTERVAL | |
109 | } frameskip_type_t; | |
110 | ||
111 | static unsigned frameskip_type = FRAMESKIP_NONE; | |
112 | static unsigned frameskip_threshold = 0; | |
113 | static unsigned frameskip_interval = 0; | |
114 | static unsigned frameskip_counter = 0; | |
115 | ||
116 | static int retro_audio_buff_active = false; | |
117 | static unsigned retro_audio_buff_occupancy = 0; | |
118 | static int retro_audio_buff_underrun = false; | |
119 | ||
120 | static unsigned retro_audio_latency = 0; | |
121 | static int update_audio_latency = false; | |
122 | ||
123 | static unsigned previous_width = 0; | |
124 | static unsigned previous_height = 0; | |
70d56ca3 | 125 | |
38c2028e | 126 | static int plugins_opened; |
17f84149 | 127 | static int is_pal_mode; |
38c2028e | 128 | |
f9f60dae TK |
129 | /* memory card data */ |
130 | extern char Mcd1Data[MCD_SIZE]; | |
7a8d521f | 131 | extern char Mcd2Data[MCD_SIZE]; |
f9f60dae | 132 | extern char McdDisable[2]; |
38c2028e | 133 | |
134 | /* PCSX ReARMed core calls and stuff */ | |
7a8d521f | 135 | int in_type[8] = { |
136 | PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, | |
137 | PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, | |
138 | PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, | |
139 | PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE | |
140 | }; | |
141 | int in_analog_left[8][2] = { { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 } }; | |
142 | int in_analog_right[8][2] = { { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 }, { 127, 127 } }; | |
143 | unsigned short in_keystate[PORTS_NUMBER]; | |
144 | int in_mouse[8][2]; | |
145 | int multitap1 = 0; | |
146 | int multitap2 = 0; | |
4e477065 | 147 | int in_enable_vibration = 1; |
d6a231b7 | 148 | int in_enable_crosshair[2] = { 0, 0 }; |
38c2028e | 149 | |
7a8d521f | 150 | // NegCon adjustment parameters |
151 | // > The NegCon 'twist' action is somewhat awkward when mapped | |
152 | // to a standard analog stick -> user should be able to tweak | |
153 | // response/deadzone for comfort | |
154 | // > When response is linear, 'additional' deadzone (set here) | |
155 | // may be left at zero, since this is normally handled via in-game | |
156 | // options menus | |
157 | // > When response is non-linear, deadzone should be set to match the | |
158 | // controller being used (otherwise precision may be lost) | |
159 | // > negcon_linearity: | |
160 | // - 1: Response is linear - recommended when using racing wheel | |
161 | // peripherals, not recommended for standard gamepads | |
162 | // - 2: Response is quadratic - optimal setting for gamepads | |
163 | // - 3: Response is cubic - enables precise fine control, but | |
164 | // difficult to use... | |
165 | #define NEGCON_RANGE 0x7FFF | |
166 | static int negcon_deadzone = 0; | |
167 | static int negcon_linearity = 1; | |
168 | ||
169 | static bool axis_bounds_modifier; | |
170 | ||
805fe9bc | 171 | /* PSX max resolution is 640x512, but with enhancement it's 1024x512 */ |
7a8d521f | 172 | #define VOUT_MAX_WIDTH 1024 |
805fe9bc | 173 | #define VOUT_MAX_HEIGHT 512 |
174 | ||
7a8d521f | 175 | //Dummy functions |
176 | bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) { return false; } | |
177 | void retro_unload_game(void) {} | |
178 | static int vout_open(void) { return 0; } | |
179 | static void vout_close(void) {} | |
180 | static int snd_init(void) { return 0; } | |
181 | static void snd_finish(void) {} | |
182 | static int snd_busy(void) { return 0; } | |
183 | ||
184 | #define GPU_PEOPS_ODD_EVEN_BIT (1 << 0) | |
185 | #define GPU_PEOPS_EXPAND_SCREEN_WIDTH (1 << 1) | |
186 | #define GPU_PEOPS_IGNORE_BRIGHTNESS (1 << 2) | |
187 | #define GPU_PEOPS_DISABLE_COORD_CHECK (1 << 3) | |
188 | #define GPU_PEOPS_LAZY_SCREEN_UPDATE (1 << 6) | |
189 | #define GPU_PEOPS_OLD_FRAME_SKIP (1 << 7) | |
190 | #define GPU_PEOPS_REPEATED_TRIANGLES (1 << 8) | |
191 | #define GPU_PEOPS_QUADS_WITH_TRIANGLES (1 << 9) | |
192 | #define GPU_PEOPS_FAKE_BUSY_STATE (1 << 10) | |
193 | ||
7df396ea TK |
194 | static void init_memcard(char *mcd_data) |
195 | { | |
7a8d521f | 196 | unsigned off = 0; |
197 | unsigned i; | |
7df396ea | 198 | |
7a8d521f | 199 | memset(mcd_data, 0, MCD_SIZE); |
7df396ea | 200 | |
7a8d521f | 201 | mcd_data[off++] = 'M'; |
202 | mcd_data[off++] = 'C'; | |
203 | off += 0x7d; | |
204 | mcd_data[off++] = 0x0e; | |
7df396ea | 205 | |
7a8d521f | 206 | for (i = 0; i < 15; i++) |
207 | { | |
208 | mcd_data[off++] = 0xa0; | |
209 | off += 0x07; | |
210 | mcd_data[off++] = 0xff; | |
211 | mcd_data[off++] = 0xff; | |
212 | off += 0x75; | |
213 | mcd_data[off++] = 0xa0; | |
214 | } | |
7df396ea | 215 | |
7a8d521f | 216 | for (i = 0; i < 20; i++) |
217 | { | |
218 | mcd_data[off++] = 0xff; | |
219 | mcd_data[off++] = 0xff; | |
220 | mcd_data[off++] = 0xff; | |
221 | mcd_data[off++] = 0xff; | |
222 | off += 0x04; | |
223 | mcd_data[off++] = 0xff; | |
224 | mcd_data[off++] = 0xff; | |
225 | off += 0x76; | |
226 | } | |
7df396ea TK |
227 | } |
228 | ||
7a8d521f | 229 | static void set_vout_fb() |
38c2028e | 230 | { |
7a8d521f | 231 | struct retro_framebuffer fb = { 0 }; |
232 | ||
233 | fb.width = vout_width; | |
234 | fb.height = vout_height; | |
235 | fb.access_flags = RETRO_MEMORY_ACCESS_WRITE; | |
236 | ||
5d9e675a | 237 | vout_pitch = vout_width; |
238 | if (environ_cb(RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER, &fb) && fb.format == RETRO_PIXEL_FORMAT_RGB565) { | |
239 | vout_buf_ptr = fb.data; | |
240 | if (fb.pitch / 2 != vout_pitch && fb.pitch != vout_width * 2) | |
241 | SysPrintf("got unusual pitch %zd for resolution %dx%d\n", fb.pitch, vout_width, vout_height); | |
242 | vout_pitch = fb.pitch / 2; | |
243 | } | |
7a8d521f | 244 | else |
245 | vout_buf_ptr = vout_buf; | |
38c2028e | 246 | } |
247 | ||
e4c83ca6 | 248 | static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp) |
38c2028e | 249 | { |
7a8d521f | 250 | vout_width = w; |
251 | vout_height = h; | |
f6eb0b1c | 252 | psx_w = raw_w; |
253 | psx_h = raw_h; | |
7a8d521f | 254 | |
255 | if (previous_width != vout_width || previous_height != vout_height) | |
256 | { | |
257 | previous_width = vout_width; | |
258 | previous_height = vout_height; | |
259 | ||
260 | struct retro_system_av_info info; | |
261 | retro_get_system_av_info(&info); | |
262 | environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &info.geometry); | |
263 | } | |
264 | ||
265 | set_vout_fb(); | |
38c2028e | 266 | } |
267 | ||
cc4f9b70 | 268 | #ifndef FRONTEND_SUPPORTS_RGB565 |
9c59f120 | 269 | static void convert(void *buf, size_t bytes) |
38c2028e | 270 | { |
7a8d521f | 271 | unsigned int i, v, *p = buf; |
38c2028e | 272 | |
7a8d521f | 273 | for (i = 0; i < bytes / 4; i++) |
274 | { | |
275 | v = p[i]; | |
276 | p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0); | |
277 | } | |
38c2028e | 278 | } |
46aa5b98 | 279 | #endif |
38c2028e | 280 | |
d6a231b7 S |
281 | // Function to add crosshairs |
282 | static void addCrosshair(int port, int crosshair_color, unsigned short *buffer, int bufferStride, int pos_x, int pos_y, int thickness, int size_x, int size_y) { | |
283 | for (port = 0; port < 2; port++) { | |
284 | // Draw the horizontal line of the crosshair | |
285 | for (int i = pos_y - thickness / 2; i <= pos_y + thickness / 2; i++) { | |
286 | for (int j = pos_x - size_x / 2; j <= pos_x + size_x / 2; j++) { | |
287 | if ((i + vout_height) >= 0 && (i + vout_height) < bufferStride && j >= 0 && j < bufferStride && in_enable_crosshair[port] > 0) | |
288 | buffer[i * bufferStride + j] = crosshair_color; | |
289 | } | |
290 | } | |
291 | ||
292 | // Draw the vertical line of the crosshair | |
293 | for (int i = pos_x - thickness / 2; i <= pos_x + thickness / 2; i++) { | |
294 | for (int j = pos_y - size_y / 2; j <= pos_y + size_y / 2; j++) { | |
295 | if (i >= 0 && i < bufferStride && (j + vout_height) >= 0 && (j + vout_height) < bufferStride && in_enable_crosshair[port] > 0) | |
296 | buffer[j * bufferStride + i] = crosshair_color; | |
297 | } | |
298 | } | |
299 | } | |
300 | } | |
301 | ||
302 | struct CrosshairInfo { | |
303 | int pos_x, pos_y, thickness, size_x, size_y; | |
304 | }; | |
305 | ||
306 | // Calculate size and position of crosshairs | |
307 | static void CrosshairDimensions(int port, struct CrosshairInfo *info) { | |
308 | int gunx = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X); | |
309 | int guny = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y); | |
310 | if (gunx == 32767) // Prevent crosshairs from wrapping around right side of screen to left | |
311 | info->pos_x = (gunx + 32767.0f) * vout_width / 65534.0f - 0.5f; | |
312 | else | |
313 | info->pos_x = (gunx + 32767.0f) * vout_width / 65534.0f; | |
314 | info->pos_y = (guny + 32767.0f) * vout_height / 65534.0f - vout_height; | |
315 | info->thickness = pl_rearmed_cbs.gpu_neon.enhancement_enable ? 4 : 2; | |
316 | info->size_x = psx_w * (pl_rearmed_cbs.gpu_neon.enhancement_enable ? 2 : 1) / 40.0f; | |
317 | info->size_y = psx_h * (pl_rearmed_cbs.gpu_neon.enhancement_enable ? 2 : 1) * (4.0f / 3.0f) / 40.0f; | |
318 | } | |
319 | ||
308c6e67 | 320 | static void vout_flip(const void *vram, int stride, int bgr24, |
321 | int x, int y, int w, int h, int dims_changed) | |
38c2028e | 322 | { |
7a8d521f | 323 | unsigned short *dest = vout_buf_ptr; |
324 | const unsigned short *src = vram; | |
5d9e675a | 325 | int dstride = vout_pitch, h1 = h; |
d6a231b7 | 326 | int port = 0; |
7a8d521f | 327 | |
d6a231b7 | 328 | if (vram == NULL || dims_changed || (in_enable_crosshair[0] + in_enable_crosshair[1]) > 0) |
7a8d521f | 329 | { |
308c6e67 | 330 | memset(vout_buf_ptr, 0, dstride * vout_height * 2); |
7a8d521f | 331 | // blanking |
308c6e67 | 332 | if (vram == NULL) |
333 | goto out; | |
7a8d521f | 334 | } |
335 | ||
308c6e67 | 336 | dest += x + y * dstride; |
7a8d521f | 337 | |
338 | if (bgr24) | |
339 | { | |
340 | // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here? | |
341 | for (; h1-- > 0; dest += dstride, src += stride) | |
342 | { | |
343 | bgr888_to_rgb565(dest, src, w * 3); | |
344 | } | |
345 | } | |
346 | else | |
347 | { | |
348 | for (; h1-- > 0; dest += dstride, src += stride) | |
349 | { | |
350 | bgr555_to_rgb565(dest, src, w * 2); | |
351 | } | |
352 | } | |
38c2028e | 353 | |
d6a231b7 S |
354 | for (port = 0; port < 2; port++) { |
355 | if (in_enable_crosshair[port] > 0 && (in_type[port] == PSE_PAD_TYPE_GUNCON || in_type[port] == PSE_PAD_TYPE_GUN)) | |
356 | { | |
357 | struct CrosshairInfo crosshairInfo; | |
358 | CrosshairDimensions(port, &crosshairInfo); | |
359 | addCrosshair(port, in_enable_crosshair[port], dest, dstride, crosshairInfo.pos_x, crosshairInfo.pos_y, crosshairInfo.thickness, crosshairInfo.size_x, crosshairInfo.size_y); | |
360 | } | |
361 | } | |
362 | ||
fa56d360 | 363 | out: |
46aa5b98 | 364 | #ifndef FRONTEND_SUPPORTS_RGB565 |
5d9e675a | 365 | convert(vout_buf_ptr, vout_pitch * vout_height * 2); |
7a8d521f | 366 | #endif |
367 | vout_fb_dirty = 1; | |
368 | pl_rearmed_cbs.flip_cnt++; | |
369 | } | |
370 | ||
371 | #ifdef _3DS | |
372 | typedef struct | |
373 | { | |
374 | void *buffer; | |
375 | uint32_t target_map; | |
376 | size_t size; | |
377 | enum psxMapTag tag; | |
378 | } psx_map_t; | |
379 | ||
380 | psx_map_t custom_psx_maps[] = { | |
381 | { NULL, 0x13000000, 0x210000, MAP_TAG_RAM }, // 0x80000000 | |
382 | { NULL, 0x12800000, 0x010000, MAP_TAG_OTHER }, // 0x1f800000 | |
383 | { NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER }, // 0x1fc00000 | |
384 | { NULL, 0x11000000, 0x800000, MAP_TAG_LUTS }, // 0x08000000 | |
00274bf7 | 385 | { NULL, 0x12000000, 0x201000, MAP_TAG_VRAM }, // 0x00000000 |
7a8d521f | 386 | }; |
387 | ||
388 | void *pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed, | |
389 | enum psxMapTag tag) | |
390 | { | |
391 | (void)is_fixed; | |
392 | (void)addr; | |
393 | ||
394 | if (__ctr_svchax) | |
395 | { | |
396 | psx_map_t *custom_map = custom_psx_maps; | |
397 | ||
398 | for (; custom_map->size; custom_map++) | |
399 | { | |
400 | if ((custom_map->size == size) && (custom_map->tag == tag)) | |
401 | { | |
402 | uint32_t ptr_aligned, tmp; | |
91da8e32 | 403 | void *ret; |
7a8d521f | 404 | |
405 | custom_map->buffer = malloc(size + 0x1000); | |
406 | ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF; | |
407 | ||
408 | if (svcControlMemory(&tmp, (void *)custom_map->target_map, (void *)ptr_aligned, size, MEMOP_MAP, 0x3) < 0) | |
409 | { | |
410 | SysPrintf("could not map memory @0x%08X\n", custom_map->target_map); | |
411 | exit(1); | |
412 | } | |
413 | ||
91da8e32 | 414 | ret = (void *)custom_map->target_map; |
415 | memset(ret, 0, size); | |
416 | return ret; | |
7a8d521f | 417 | } |
418 | } | |
419 | } | |
420 | ||
91da8e32 | 421 | return calloc(size, 1); |
7a8d521f | 422 | } |
423 | ||
424 | void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag) | |
425 | { | |
426 | (void)tag; | |
427 | ||
428 | if (__ctr_svchax) | |
429 | { | |
430 | psx_map_t *custom_map = custom_psx_maps; | |
431 | ||
432 | for (; custom_map->size; custom_map++) | |
433 | { | |
434 | if ((custom_map->target_map == (uint32_t)ptr)) | |
435 | { | |
436 | uint32_t ptr_aligned, tmp; | |
437 | ||
438 | ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF; | |
439 | ||
440 | svcControlMemory(&tmp, (void *)custom_map->target_map, (void *)ptr_aligned, size, MEMOP_UNMAP, 0x3); | |
441 | ||
442 | free(custom_map->buffer); | |
443 | custom_map->buffer = NULL; | |
444 | return; | |
445 | } | |
446 | } | |
447 | } | |
448 | ||
449 | free(ptr); | |
450 | } | |
451 | #endif | |
452 | ||
453 | #ifdef VITA | |
454 | typedef struct | |
455 | { | |
456 | void *buffer; | |
7a8d521f | 457 | size_t size; |
458 | enum psxMapTag tag; | |
00274bf7 | 459 | int used; |
7a8d521f | 460 | } psx_map_t; |
461 | ||
00274bf7 | 462 | static void *addr = NULL; |
7a8d521f | 463 | |
464 | psx_map_t custom_psx_maps[] = { | |
00274bf7 | 465 | { NULL, 0x800000, MAP_TAG_LUTS }, |
466 | { NULL, 0x080000, MAP_TAG_OTHER }, | |
467 | { NULL, 0x010000, MAP_TAG_OTHER }, | |
468 | { NULL, 0x201000, MAP_TAG_VRAM }, | |
469 | { NULL, 0x802000, MAP_TAG_VRAM }, // enhanced renderer | |
470 | { NULL, 0x210000, MAP_TAG_RAM }, | |
7a8d521f | 471 | }; |
472 | ||
473 | int init_vita_mmap() | |
474 | { | |
475 | int n; | |
476 | void *tmpaddr; | |
477 | addr = malloc(64 * 1024 * 1024); | |
478 | if (addr == NULL) | |
479 | return -1; | |
00274bf7 | 480 | tmpaddr = (void *)(((size_t)addr + 0xFFFFFF) & ~0xFFFFFF); |
481 | custom_psx_maps[0].buffer = tmpaddr + 0x0000000; | |
482 | custom_psx_maps[1].buffer = tmpaddr + 0x0800000; | |
483 | custom_psx_maps[2].buffer = tmpaddr + 0x0880000; | |
484 | custom_psx_maps[3].buffer = tmpaddr + 0x0900000; | |
7a8d521f | 485 | custom_psx_maps[4].buffer = tmpaddr + 0x1000000; |
00274bf7 | 486 | custom_psx_maps[5].buffer = tmpaddr + 0x2000000; |
91da8e32 | 487 | memset(tmpaddr, 0, 0x2210000); |
7a8d521f | 488 | #if 0 |
489 | for(n = 0; n < 5; n++){ | |
490 | sceClibPrintf("addr reserved %x\n",custom_psx_maps[n].buffer); | |
491 | } | |
46aa5b98 | 492 | #endif |
7a8d521f | 493 | return 0; |
494 | } | |
495 | ||
496 | void deinit_vita_mmap() | |
497 | { | |
00274bf7 | 498 | size_t i; |
499 | for (i = 0; i < sizeof(custom_psx_maps) / sizeof(custom_psx_maps[0]); i++) { | |
500 | custom_psx_maps[i].buffer = NULL; | |
501 | custom_psx_maps[i].used = 0; | |
502 | } | |
7a8d521f | 503 | free(addr); |
504 | } | |
505 | ||
506 | void *pl_vita_mmap(unsigned long addr, size_t size, int is_fixed, | |
507 | enum psxMapTag tag) | |
508 | { | |
509 | (void)is_fixed; | |
510 | (void)addr; | |
511 | ||
512 | psx_map_t *custom_map = custom_psx_maps; | |
513 | ||
514 | for (; custom_map->size; custom_map++) | |
515 | { | |
00274bf7 | 516 | if (custom_map->size == size && custom_map->tag == tag && !custom_map->used) |
7a8d521f | 517 | { |
00274bf7 | 518 | custom_map->used = 1; |
7a8d521f | 519 | return custom_map->buffer; |
520 | } | |
521 | } | |
522 | ||
91da8e32 | 523 | return calloc(size, 1); |
38c2028e | 524 | } |
525 | ||
7a8d521f | 526 | void pl_vita_munmap(void *ptr, size_t size, enum psxMapTag tag) |
38c2028e | 527 | { |
7a8d521f | 528 | (void)tag; |
529 | ||
530 | psx_map_t *custom_map = custom_psx_maps; | |
531 | ||
532 | for (; custom_map->size; custom_map++) | |
533 | { | |
534 | if ((custom_map->buffer == ptr)) | |
535 | { | |
00274bf7 | 536 | custom_map->used = 0; |
7a8d521f | 537 | return; |
538 | } | |
539 | } | |
540 | ||
541 | free(ptr); | |
38c2028e | 542 | } |
7a8d521f | 543 | #endif |
38c2028e | 544 | |
cc56203b | 545 | static void *pl_mmap(unsigned int size) |
546 | { | |
7a8d521f | 547 | return psxMap(0, size, 0, MAP_TAG_VRAM); |
cc56203b | 548 | } |
549 | ||
550 | static void pl_munmap(void *ptr, unsigned int size) | |
551 | { | |
7a8d521f | 552 | psxUnmap(ptr, size, MAP_TAG_VRAM); |
cc56203b | 553 | } |
554 | ||
38c2028e | 555 | struct rearmed_cbs pl_rearmed_cbs = { |
7a8d521f | 556 | .pl_vout_open = vout_open, |
557 | .pl_vout_set_mode = vout_set_mode, | |
558 | .pl_vout_flip = vout_flip, | |
559 | .pl_vout_close = vout_close, | |
560 | .mmap = pl_mmap, | |
561 | .munmap = pl_munmap, | |
abf09485 | 562 | .gpu_state_change = gpu_state_change, |
7a8d521f | 563 | /* from psxcounters */ |
564 | .gpu_hcnt = &hSyncCount, | |
565 | .gpu_frame_count = &frame_counter, | |
38c2028e | 566 | }; |
567 | ||
568 | void pl_frame_limit(void) | |
569 | { | |
7a8d521f | 570 | /* called once per frame, make psxCpu->Execute() above return */ |
da65071f | 571 | stop++; |
38c2028e | 572 | } |
573 | ||
574 | void pl_timing_prepare(int is_pal) | |
575 | { | |
7a8d521f | 576 | is_pal_mode = is_pal; |
38c2028e | 577 | } |
578 | ||
d71c7095 | 579 | void plat_trigger_vibrate(int pad, int low, int high) |
38c2028e | 580 | { |
7a8d521f | 581 | if (!rumble_cb) |
582 | return; | |
583 | ||
584 | if (in_enable_vibration) | |
585 | { | |
586 | rumble_cb(pad, RETRO_RUMBLE_STRONG, high << 8); | |
587 | rumble_cb(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0); | |
588 | } | |
38c2028e | 589 | } |
590 | ||
d6a231b7 S |
591 | //Percentage distance of screen to adjust for Konami Gun |
592 | static float KonamiGunAdjustX = 0; | |
593 | static float KonamiGunAdjustY = 0; | |
594 | ||
2db412ad | 595 | void pl_gun_byte2(int port, unsigned char byte) |
38c2028e | 596 | { |
d6a231b7 S |
597 | int irq_count = 4; |
598 | float justifier_multiplier = 0; | |
599 | int justifier_width = psx_w; | |
600 | int justifier_height = psx_h; | |
601 | int justifier_offscreen = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN); | |
602 | int justifier_reload = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD); | |
603 | ||
604 | if (justifier_width == 256) | |
605 | justifier_multiplier = is_pal_mode ? .157086f : .158532f; | |
606 | else if (justifier_width == 320) | |
607 | justifier_multiplier = is_pal_mode ? .196358f : .198166f; | |
608 | else if (justifier_width == 384) | |
609 | justifier_multiplier = is_pal_mode ? .224409f : .226475f; | |
610 | else if (justifier_width == 512) | |
611 | justifier_multiplier = is_pal_mode ? .314173f : .317065f; | |
612 | else // (justifier_width == 640) | |
613 | justifier_multiplier = is_pal_mode ? .392717f : .396332f; | |
614 | ||
615 | int gunx = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X); | |
616 | int guny = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y); | |
617 | ||
618 | //Default offset of +105 for X and -12 for Y is chosen to obtain alignment in Die Hard Trilogy, which has no calibration feature | |
619 | int gunx_scaled = ((gunx + 32767.0f) / 65534.0f + KonamiGunAdjustX) * justifier_width / justifier_multiplier + 105.0f; | |
620 | int guny_scaled = ((guny + 32767.0f) / 65534.0f + KonamiGunAdjustY) * justifier_height - 12.0f; | |
621 | ||
622 | if ((byte & 0x10) && !justifier_offscreen && !justifier_reload) | |
623 | { | |
624 | psxScheduleIrq10(irq_count, gunx_scaled, guny_scaled); | |
625 | } | |
38c2028e | 626 | } |
627 | ||
628 | /* sound calls */ | |
7a8d521f | 629 | static void snd_feed(void *buf, int bytes) |
38c2028e | 630 | { |
7a8d521f | 631 | if (audio_batch_cb != NULL) |
632 | audio_batch_cb(buf, bytes / 4); | |
38c2028e | 633 | } |
634 | ||
7a8d521f | 635 | void out_register_libretro(struct out_driver *drv) |
38c2028e | 636 | { |
7a8d521f | 637 | drv->name = "libretro"; |
638 | drv->init = snd_init; | |
639 | drv->finish = snd_finish; | |
640 | drv->busy = snd_busy; | |
641 | drv->feed = snd_feed; | |
38c2028e | 642 | } |
643 | ||
d6a231b7 S |
644 | #define RETRO_DEVICE_PSE_STANDARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0) |
645 | #define RETRO_DEVICE_PSE_ANALOG RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 0) | |
646 | #define RETRO_DEVICE_PSE_DUALSHOCK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 1) | |
647 | #define RETRO_DEVICE_PSE_NEGCON RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 2) | |
648 | #define RETRO_DEVICE_PSE_GUNCON RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 0) | |
649 | #define RETRO_DEVICE_PSE_JUSTIFIER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_LIGHTGUN, 1) | |
650 | #define RETRO_DEVICE_PSE_MOUSE RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 0) | |
7a8d521f | 651 | |
652 | static char *get_pse_pad_label[] = { | |
653 | "none", "mouse", "negcon", "konami gun", "standard", "analog", "guncon", "dualshock" | |
654 | }; | |
655 | ||
d6a231b7 | 656 | static const struct retro_controller_description pads[8] = |
38c2028e | 657 | { |
d6a231b7 S |
658 | { "standard", RETRO_DEVICE_JOYPAD }, |
659 | { "analog", RETRO_DEVICE_PSE_ANALOG }, | |
660 | { "dualshock", RETRO_DEVICE_PSE_DUALSHOCK }, | |
661 | { "negcon", RETRO_DEVICE_PSE_NEGCON }, | |
662 | { "guncon", RETRO_DEVICE_PSE_GUNCON }, | |
663 | { "konami gun", RETRO_DEVICE_PSE_JUSTIFIER }, | |
664 | { "mouse", RETRO_DEVICE_PSE_MOUSE }, | |
7a8d521f | 665 | { NULL, 0 }, |
666 | }; | |
38c2028e | 667 | |
7a8d521f | 668 | static const struct retro_controller_info ports[9] = |
38c2028e | 669 | { |
7a8d521f | 670 | { pads, 7 }, |
671 | { pads, 7 }, | |
672 | { pads, 7 }, | |
673 | { pads, 7 }, | |
674 | { pads, 7 }, | |
675 | { pads, 7 }, | |
676 | { pads, 7 }, | |
677 | { pads, 7 }, | |
678 | { NULL, 0 }, | |
679 | }; | |
38c2028e | 680 | |
7a8d521f | 681 | /* libretro */ |
682 | ||
683 | static bool update_option_visibility(void) | |
07c13dfd | 684 | { |
7a8d521f | 685 | struct retro_variable var = {0}; |
686 | struct retro_core_option_display option_display = {0}; | |
687 | bool updated = false; | |
688 | unsigned i; | |
689 | ||
690 | /* If frontend supports core option categories | |
691 | * then show/hide core option entries are ignored | |
692 | * and no options should be hidden */ | |
693 | if (libretro_supports_option_categories) | |
694 | return false; | |
695 | ||
696 | var.key = "pcsx_rearmed_show_input_settings"; | |
697 | var.value = NULL; | |
698 | ||
699 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
700 | { | |
701 | bool show_input_settings_prev = | |
702 | show_input_settings; | |
703 | ||
704 | show_input_settings = true; | |
705 | if (strcmp(var.value, "disabled") == 0) | |
706 | show_input_settings = false; | |
707 | ||
708 | if (show_input_settings != | |
709 | show_input_settings_prev) | |
710 | { | |
711 | char input_option[][50] = { | |
712 | "pcsx_rearmed_analog_axis_modifier", | |
713 | "pcsx_rearmed_vibration", | |
714 | "pcsx_rearmed_multitap", | |
715 | "pcsx_rearmed_negcon_deadzone", | |
716 | "pcsx_rearmed_negcon_response", | |
717 | "pcsx_rearmed_input_sensitivity", | |
d6a231b7 S |
718 | "pcsx_rearmed_crosshair1", |
719 | "pcsx_rearmed_crosshair2", | |
720 | "pcsx_rearmed_konamigunadjustx", | |
721 | "pcsx_rearmed_konamigunadjusty", | |
7a8d521f | 722 | "pcsx_rearmed_gunconadjustx", |
723 | "pcsx_rearmed_gunconadjusty", | |
724 | "pcsx_rearmed_gunconadjustratiox", | |
725 | "pcsx_rearmed_gunconadjustratioy" | |
726 | }; | |
727 | ||
728 | option_display.visible = show_input_settings; | |
729 | ||
730 | for (i = 0; | |
731 | i < (sizeof(input_option) / | |
732 | sizeof(input_option[0])); | |
733 | i++) | |
734 | { | |
735 | option_display.key = input_option[i]; | |
736 | environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, | |
737 | &option_display); | |
738 | } | |
739 | ||
740 | updated = true; | |
741 | } | |
742 | } | |
743 | #ifdef GPU_PEOPS | |
744 | var.key = "pcsx_rearmed_show_gpu_peops_settings"; | |
745 | var.value = NULL; | |
746 | ||
747 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
748 | { | |
749 | bool show_advanced_gpu_peops_settings_prev = | |
750 | show_advanced_gpu_peops_settings; | |
751 | ||
752 | show_advanced_gpu_peops_settings = true; | |
753 | if (strcmp(var.value, "disabled") == 0) | |
754 | show_advanced_gpu_peops_settings = false; | |
755 | ||
756 | if (show_advanced_gpu_peops_settings != | |
757 | show_advanced_gpu_peops_settings_prev) | |
758 | { | |
759 | unsigned i; | |
760 | struct retro_core_option_display option_display; | |
761 | char gpu_peops_option[][45] = { | |
762 | "pcsx_rearmed_gpu_peops_odd_even_bit", | |
763 | "pcsx_rearmed_gpu_peops_expand_screen_width", | |
764 | "pcsx_rearmed_gpu_peops_ignore_brightness", | |
765 | "pcsx_rearmed_gpu_peops_disable_coord_check", | |
766 | "pcsx_rearmed_gpu_peops_lazy_screen_update", | |
767 | "pcsx_rearmed_gpu_peops_repeated_triangles", | |
768 | "pcsx_rearmed_gpu_peops_quads_with_triangles", | |
769 | "pcsx_rearmed_gpu_peops_fake_busy_state" | |
770 | }; | |
771 | ||
772 | option_display.visible = show_advanced_gpu_peops_settings; | |
773 | ||
774 | for (i = 0; | |
775 | i < (sizeof(gpu_peops_option) / | |
776 | sizeof(gpu_peops_option[0])); | |
777 | i++) | |
778 | { | |
779 | option_display.key = gpu_peops_option[i]; | |
780 | environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, | |
781 | &option_display); | |
782 | } | |
783 | ||
784 | updated = true; | |
785 | } | |
786 | } | |
787 | #endif | |
788 | #ifdef GPU_UNAI | |
789 | var.key = "pcsx_rearmed_show_gpu_unai_settings"; | |
790 | var.value = NULL; | |
791 | ||
792 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
793 | { | |
794 | bool show_advanced_gpu_unai_settings_prev = | |
795 | show_advanced_gpu_unai_settings; | |
796 | ||
797 | show_advanced_gpu_unai_settings = true; | |
798 | if (strcmp(var.value, "disabled") == 0) | |
799 | show_advanced_gpu_unai_settings = false; | |
800 | ||
801 | if (show_advanced_gpu_unai_settings != | |
802 | show_advanced_gpu_unai_settings_prev) | |
803 | { | |
804 | unsigned i; | |
805 | struct retro_core_option_display option_display; | |
806 | char gpu_unai_option[][40] = { | |
807 | "pcsx_rearmed_gpu_unai_blending", | |
808 | "pcsx_rearmed_gpu_unai_lighting", | |
809 | "pcsx_rearmed_gpu_unai_fast_lighting", | |
810 | "pcsx_rearmed_gpu_unai_scale_hires", | |
811 | }; | |
812 | ||
813 | option_display.visible = show_advanced_gpu_unai_settings; | |
814 | ||
815 | for (i = 0; | |
816 | i < (sizeof(gpu_unai_option) / | |
817 | sizeof(gpu_unai_option[0])); | |
818 | i++) | |
819 | { | |
820 | option_display.key = gpu_unai_option[i]; | |
821 | environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, | |
822 | &option_display); | |
823 | } | |
824 | ||
825 | updated = true; | |
826 | } | |
827 | } | |
828 | #endif | |
829 | return updated; | |
07c13dfd | 830 | } |
831 | ||
e268a47e | 832 | void retro_set_environment(retro_environment_t cb) |
833 | { | |
7a8d521f | 834 | bool option_categories = false; |
835 | #ifdef USE_LIBRETRO_VFS | |
836 | struct retro_vfs_interface_info vfs_iface_info; | |
7d68d030 | 837 | #endif |
e268a47e | 838 | |
839 | environ_cb = cb; | |
840 | ||
7a8d521f | 841 | if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging)) |
842 | log_cb = logging.log; | |
843 | ||
844 | environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); | |
845 | ||
846 | /* Set core options | |
847 | * An annoyance: retro_set_environment() can be called | |
848 | * multiple times, and depending upon the current frontend | |
849 | * state various environment callbacks may be disabled. | |
850 | * This means the reported 'categories_supported' status | |
851 | * may change on subsequent iterations. We therefore have | |
852 | * to record whether 'categories_supported' is true on any | |
853 | * iteration, and latch the result */ | |
854 | libretro_set_core_options(environ_cb, &option_categories); | |
855 | libretro_supports_option_categories |= option_categories; | |
856 | ||
857 | /* If frontend supports core option categories, | |
858 | * any show/hide core option entries are unused | |
859 | * and should be hidden */ | |
860 | if (libretro_supports_option_categories) | |
861 | { | |
862 | struct retro_core_option_display option_display; | |
863 | option_display.visible = false; | |
864 | ||
865 | option_display.key = "pcsx_rearmed_show_input_settings"; | |
866 | environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, | |
867 | &option_display); | |
868 | ||
869 | #ifdef GPU_PEOPS | |
870 | option_display.key = "pcsx_rearmed_show_gpu_peops_settings"; | |
871 | environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, | |
872 | &option_display); | |
873 | #endif | |
874 | #ifdef GPU_UNAI | |
875 | option_display.key = "pcsx_rearmed_show_gpu_unai_settings"; | |
876 | environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, | |
877 | &option_display); | |
878 | #endif | |
879 | } | |
880 | /* If frontend does not support core option | |
881 | * categories, core options may be shown/hidden | |
882 | * at runtime. In this case, register 'update | |
883 | * display' callback, so frontend can update | |
884 | * core options menu without calling retro_run() */ | |
885 | else | |
886 | { | |
887 | struct retro_core_options_update_display_callback update_display_cb; | |
888 | update_display_cb.callback = update_option_visibility; | |
889 | ||
890 | environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_UPDATE_DISPLAY_CALLBACK, | |
891 | &update_display_cb); | |
892 | } | |
893 | ||
894 | #ifdef USE_LIBRETRO_VFS | |
895 | vfs_iface_info.required_interface_version = 1; | |
896 | vfs_iface_info.iface = NULL; | |
897 | if (environ_cb(RETRO_ENVIRONMENT_GET_VFS_INTERFACE, &vfs_iface_info)) | |
898 | filestream_vfs_init(&vfs_iface_info); | |
899 | #endif | |
e268a47e | 900 | } |
901 | ||
38c2028e | 902 | void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; } |
903 | void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; } | |
904 | void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; } | |
905 | void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; } | |
906 | void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; } | |
907 | ||
908 | unsigned retro_api_version(void) | |
909 | { | |
7a8d521f | 910 | return RETRO_API_VERSION; |
911 | } | |
912 | ||
913 | static void update_multitap(void) | |
914 | { | |
915 | struct retro_variable var = { 0 }; | |
916 | ||
917 | multitap1 = 0; | |
918 | multitap2 = 0; | |
919 | ||
920 | var.value = NULL; | |
921 | var.key = "pcsx_rearmed_multitap"; | |
922 | if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)) | |
923 | { | |
924 | if (strcmp(var.value, "port 1") == 0) | |
925 | multitap1 = 1; | |
926 | else if (strcmp(var.value, "port 2") == 0) | |
927 | multitap2 = 1; | |
928 | else if (strcmp(var.value, "ports 1 and 2") == 0) | |
929 | { | |
930 | multitap1 = 1; | |
931 | multitap2 = 1; | |
932 | } | |
933 | } | |
38c2028e | 934 | } |
935 | ||
936 | void retro_set_controller_port_device(unsigned port, unsigned device) | |
937 | { | |
7a8d521f | 938 | if (port >= PORTS_NUMBER) |
939 | return; | |
940 | ||
941 | switch (device) | |
942 | { | |
943 | case RETRO_DEVICE_JOYPAD: | |
944 | case RETRO_DEVICE_PSE_STANDARD: | |
945 | in_type[port] = PSE_PAD_TYPE_STANDARD; | |
946 | break; | |
947 | case RETRO_DEVICE_PSE_ANALOG: | |
948 | in_type[port] = PSE_PAD_TYPE_ANALOGJOY; | |
949 | break; | |
950 | case RETRO_DEVICE_PSE_DUALSHOCK: | |
951 | in_type[port] = PSE_PAD_TYPE_ANALOGPAD; | |
952 | break; | |
953 | case RETRO_DEVICE_PSE_MOUSE: | |
954 | in_type[port] = PSE_PAD_TYPE_MOUSE; | |
955 | break; | |
956 | case RETRO_DEVICE_PSE_NEGCON: | |
957 | in_type[port] = PSE_PAD_TYPE_NEGCON; | |
958 | break; | |
959 | case RETRO_DEVICE_PSE_GUNCON: | |
960 | in_type[port] = PSE_PAD_TYPE_GUNCON; | |
961 | break; | |
d6a231b7 S |
962 | case RETRO_DEVICE_PSE_JUSTIFIER: |
963 | in_type[port] = PSE_PAD_TYPE_GUN; | |
964 | break; | |
7a8d521f | 965 | case RETRO_DEVICE_NONE: |
966 | default: | |
967 | in_type[port] = PSE_PAD_TYPE_NONE; | |
968 | break; | |
969 | } | |
970 | ||
971 | SysPrintf("port: %u device: %s\n", port + 1, get_pse_pad_label[in_type[port]]); | |
38c2028e | 972 | } |
973 | ||
974 | void retro_get_system_info(struct retro_system_info *info) | |
975 | { | |
7a8d521f | 976 | #ifndef GIT_VERSION |
977 | #define GIT_VERSION "" | |
978 | #endif | |
979 | memset(info, 0, sizeof(*info)); | |
980 | info->library_name = "PCSX-ReARMed"; | |
981 | info->library_version = "r23l" GIT_VERSION; | |
0cae7d24 | 982 | info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u|chd|iso|exe"; |
7a8d521f | 983 | info->need_fullpath = true; |
38c2028e | 984 | } |
985 | ||
986 | void retro_get_system_av_info(struct retro_system_av_info *info) | |
987 | { | |
5d9e675a | 988 | unsigned geom_height = vout_height; |
989 | unsigned geom_width = vout_width; | |
7a8d521f | 990 | |
991 | memset(info, 0, sizeof(*info)); | |
992 | info->timing.fps = is_pal_mode ? 50.0 : 60.0; | |
993 | info->timing.sample_rate = 44100.0; | |
994 | info->geometry.base_width = geom_width; | |
995 | info->geometry.base_height = geom_height; | |
996 | info->geometry.max_width = VOUT_MAX_WIDTH; | |
997 | info->geometry.max_height = VOUT_MAX_HEIGHT; | |
998 | info->geometry.aspect_ratio = 4.0 / 3.0; | |
38c2028e | 999 | } |
1000 | ||
6e921e1d | 1001 | /* savestates */ |
7a8d521f | 1002 | size_t retro_serialize_size(void) |
1003 | { | |
1004 | // it's currently 4380651-4397047 bytes, | |
1005 | // but have some reserved for future | |
1006 | return 0x440000; | |
6e921e1d | 1007 | } |
1008 | ||
7a8d521f | 1009 | struct save_fp |
1010 | { | |
1011 | char *buf; | |
1012 | size_t pos; | |
1013 | int is_write; | |
6e921e1d | 1014 | }; |
1015 | ||
1016 | static void *save_open(const char *name, const char *mode) | |
1017 | { | |
7a8d521f | 1018 | struct save_fp *fp; |
6e921e1d | 1019 | |
7a8d521f | 1020 | if (name == NULL || mode == NULL) |
1021 | return NULL; | |
6e921e1d | 1022 | |
7a8d521f | 1023 | fp = malloc(sizeof(*fp)); |
1024 | if (fp == NULL) | |
1025 | return NULL; | |
6e921e1d | 1026 | |
7a8d521f | 1027 | fp->buf = (char *)name; |
1028 | fp->pos = 0; | |
1029 | fp->is_write = (mode[0] == 'w' || mode[1] == 'w'); | |
6e921e1d | 1030 | |
7a8d521f | 1031 | return fp; |
6e921e1d | 1032 | } |
1033 | ||
1034 | static int save_read(void *file, void *buf, u32 len) | |
1035 | { | |
7a8d521f | 1036 | struct save_fp *fp = file; |
1037 | if (fp == NULL || buf == NULL) | |
1038 | return -1; | |
6e921e1d | 1039 | |
7a8d521f | 1040 | memcpy(buf, fp->buf + fp->pos, len); |
1041 | fp->pos += len; | |
1042 | return len; | |
6e921e1d | 1043 | } |
1044 | ||
1045 | static int save_write(void *file, const void *buf, u32 len) | |
1046 | { | |
7a8d521f | 1047 | struct save_fp *fp = file; |
1048 | if (fp == NULL || buf == NULL) | |
1049 | return -1; | |
6e921e1d | 1050 | |
7a8d521f | 1051 | memcpy(fp->buf + fp->pos, buf, len); |
1052 | fp->pos += len; | |
1053 | return len; | |
6e921e1d | 1054 | } |
1055 | ||
1056 | static long save_seek(void *file, long offs, int whence) | |
1057 | { | |
7a8d521f | 1058 | struct save_fp *fp = file; |
1059 | if (fp == NULL) | |
1060 | return -1; | |
6e921e1d | 1061 | |
7a8d521f | 1062 | switch (whence) |
1063 | { | |
1064 | case SEEK_CUR: | |
1065 | fp->pos += offs; | |
1066 | return fp->pos; | |
1067 | case SEEK_SET: | |
1068 | fp->pos = offs; | |
1069 | return fp->pos; | |
1070 | default: | |
1071 | return -1; | |
1072 | } | |
6e921e1d | 1073 | } |
1074 | ||
1075 | static void save_close(void *file) | |
1076 | { | |
7a8d521f | 1077 | struct save_fp *fp = file; |
1078 | size_t r_size = retro_serialize_size(); | |
1079 | if (fp == NULL) | |
1080 | return; | |
1081 | ||
1082 | if (fp->pos > r_size) | |
1083 | SysPrintf("ERROR: save buffer overflow detected\n"); | |
1084 | else if (fp->is_write && fp->pos < r_size) | |
1085 | // make sure we don't save trash in leftover space | |
1086 | memset(fp->buf + fp->pos, 0, r_size - fp->pos); | |
1087 | free(fp); | |
38c2028e | 1088 | } |
1089 | ||
1090 | bool retro_serialize(void *data, size_t size) | |
7a8d521f | 1091 | { |
6a131b03 | 1092 | int ret; |
1093 | CdromFrontendId = disk_current_index; | |
1094 | ret = SaveState(data); | |
7a8d521f | 1095 | return ret == 0 ? true : false; |
38c2028e | 1096 | } |
1097 | ||
6a131b03 | 1098 | static bool disk_set_image_index(unsigned int index); |
1099 | ||
38c2028e | 1100 | bool retro_unserialize(const void *data, size_t size) |
1101 | { | |
6a131b03 | 1102 | int ret; |
1103 | CdromFrontendId = -1; | |
1104 | ret = LoadState(data); | |
1105 | if (ret) | |
1106 | return false; | |
1107 | if (CdromFrontendId != -1 && CdromFrontendId != disk_current_index) | |
1108 | disk_set_image_index(CdromFrontendId); | |
1109 | return true; | |
38c2028e | 1110 | } |
1111 | ||
23ea11bd | 1112 | /* cheats */ |
38c2028e | 1113 | void retro_cheat_reset(void) |
1114 | { | |
7a8d521f | 1115 | ClearAllCheats(); |
38c2028e | 1116 | } |
1117 | ||
1118 | void retro_cheat_set(unsigned index, bool enabled, const char *code) | |
1119 | { | |
1e93efc0 | 1120 | int ret = -1; |
1121 | char *buf; | |
7a8d521f | 1122 | |
1e93efc0 | 1123 | // cheat funcs are destructive, need a copy... |
1124 | buf = strdup(code); | |
1125 | if (buf == NULL) | |
1126 | goto finish; | |
6e921e1d | 1127 | |
7a8d521f | 1128 | //Prepare buffered cheat for PCSX's AddCheat fucntion. |
1129 | int cursor = 0; | |
1130 | int nonhexdec = 0; | |
1131 | while (buf[cursor]) | |
1132 | { | |
1133 | if (!(ISHEXDEC)) | |
1134 | { | |
1135 | if (++nonhexdec % 2) | |
1136 | { | |
1137 | buf[cursor] = ' '; | |
1138 | } | |
1139 | else | |
1140 | { | |
1141 | buf[cursor] = '\n'; | |
1142 | } | |
1143 | } | |
1144 | cursor++; | |
1145 | } | |
6e921e1d | 1146 | |
7a8d521f | 1147 | if (index < NumCheats) |
1148 | ret = EditCheat(index, "", buf); | |
1149 | else | |
1150 | ret = AddCheat("", buf); | |
6e921e1d | 1151 | |
1e93efc0 | 1152 | finish: |
7a8d521f | 1153 | if (ret != 0) |
1154 | SysPrintf("Failed to set cheat %#u\n", index); | |
1155 | else if (index < NumCheats) | |
1156 | Cheats[index].Enabled = enabled; | |
1e93efc0 | 1157 | free(buf); |
38c2028e | 1158 | } |
1159 | ||
7a8d521f | 1160 | // just in case, maybe a win-rt port in the future? |
1161 | #ifdef _WIN32 | |
1162 | #define SLASH '\\' | |
1163 | #else | |
1164 | #define SLASH '/' | |
1165 | #endif | |
1166 | ||
1167 | #ifndef PATH_MAX | |
1168 | #define PATH_MAX 4096 | |
1169 | #endif | |
1170 | ||
23ea11bd | 1171 | /* multidisk support */ |
7a8d521f | 1172 | static unsigned int disk_initial_index; |
1173 | static char disk_initial_path[PATH_MAX]; | |
23ea11bd | 1174 | static bool disk_ejected; |
51ba7408 | 1175 | static unsigned int disk_count; |
7a8d521f | 1176 | static struct disks_state |
1177 | { | |
1178 | char *fname; | |
1179 | char *flabel; | |
1180 | int internal_index; // for multidisk eboots | |
23ea11bd | 1181 | } disks[8]; |
1182 | ||
7a8d521f | 1183 | static void get_disk_label(char *disk_label, const char *disk_path, size_t len) |
1184 | { | |
1185 | const char *base = NULL; | |
1186 | ||
1187 | if (!disk_path || (*disk_path == '\0')) | |
1188 | return; | |
1189 | ||
1190 | base = strrchr(disk_path, SLASH); | |
1191 | if (!base) | |
1192 | base = disk_path; | |
1193 | ||
1194 | if (*base == SLASH) | |
1195 | base++; | |
1196 | ||
1197 | strncpy(disk_label, base, len - 1); | |
1198 | disk_label[len - 1] = '\0'; | |
1199 | ||
1200 | char *ext = strrchr(disk_label, '.'); | |
1201 | if (ext) | |
1202 | *ext = '\0'; | |
1203 | } | |
1204 | ||
1205 | static void disk_init(void) | |
1206 | { | |
1207 | size_t i; | |
1208 | ||
1209 | disk_ejected = false; | |
1210 | disk_current_index = 0; | |
1211 | disk_count = 0; | |
1212 | ||
1213 | for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) | |
1214 | { | |
1215 | if (disks[i].fname != NULL) | |
1216 | { | |
1217 | free(disks[i].fname); | |
1218 | disks[i].fname = NULL; | |
1219 | } | |
1220 | if (disks[i].flabel != NULL) | |
1221 | { | |
1222 | free(disks[i].flabel); | |
1223 | disks[i].flabel = NULL; | |
1224 | } | |
1225 | disks[i].internal_index = 0; | |
1226 | } | |
1227 | } | |
1228 | ||
23ea11bd | 1229 | static bool disk_set_eject_state(bool ejected) |
1230 | { | |
7a8d521f | 1231 | // weird PCSX API.. |
1232 | SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2)); | |
1233 | LidInterrupt(); | |
23ea11bd | 1234 | |
7a8d521f | 1235 | disk_ejected = ejected; |
1236 | return true; | |
23ea11bd | 1237 | } |
1238 | ||
1239 | static bool disk_get_eject_state(void) | |
1240 | { | |
7a8d521f | 1241 | /* can't be controlled by emulated software */ |
1242 | return disk_ejected; | |
23ea11bd | 1243 | } |
1244 | ||
1245 | static unsigned int disk_get_image_index(void) | |
1246 | { | |
7a8d521f | 1247 | return disk_current_index; |
23ea11bd | 1248 | } |
1249 | ||
1250 | static bool disk_set_image_index(unsigned int index) | |
1251 | { | |
7a8d521f | 1252 | if (index >= sizeof(disks) / sizeof(disks[0])) |
1253 | return false; | |
23ea11bd | 1254 | |
7a8d521f | 1255 | CdromId[0] = '\0'; |
1256 | CdromLabel[0] = '\0'; | |
23ea11bd | 1257 | |
7a8d521f | 1258 | if (disks[index].fname == NULL) |
1259 | { | |
1260 | SysPrintf("missing disk #%u\n", index); | |
1261 | CDR_shutdown(); | |
23ea11bd | 1262 | |
7a8d521f | 1263 | // RetroArch specifies "no disk" with index == count, |
1264 | // so don't fail here.. | |
1265 | disk_current_index = index; | |
1266 | return true; | |
1267 | } | |
23ea11bd | 1268 | |
7a8d521f | 1269 | SysPrintf("switching to disk %u: \"%s\" #%d\n", index, |
1270 | disks[index].fname, disks[index].internal_index); | |
23ea11bd | 1271 | |
7a8d521f | 1272 | cdrIsoMultidiskSelect = disks[index].internal_index; |
1273 | set_cd_image(disks[index].fname); | |
1274 | if (ReloadCdromPlugin() < 0) | |
1275 | { | |
1276 | SysPrintf("failed to load cdr plugin\n"); | |
1277 | return false; | |
1278 | } | |
1279 | if (CDR_open() < 0) | |
1280 | { | |
1281 | SysPrintf("failed to open cdr plugin\n"); | |
1282 | return false; | |
1283 | } | |
23ea11bd | 1284 | |
7a8d521f | 1285 | if (!disk_ejected) |
1286 | { | |
1287 | SetCdOpenCaseTime(time(NULL) + 2); | |
1288 | LidInterrupt(); | |
1289 | } | |
23ea11bd | 1290 | |
7a8d521f | 1291 | disk_current_index = index; |
1292 | return true; | |
23ea11bd | 1293 | } |
1294 | ||
1295 | static unsigned int disk_get_num_images(void) | |
1296 | { | |
7a8d521f | 1297 | return disk_count; |
23ea11bd | 1298 | } |
1299 | ||
1300 | static bool disk_replace_image_index(unsigned index, | |
7a8d521f | 1301 | const struct retro_game_info *info) |
23ea11bd | 1302 | { |
7a8d521f | 1303 | char *old_fname = NULL; |
1304 | char *old_flabel = NULL; | |
1305 | bool ret = true; | |
1306 | ||
1307 | if (index >= sizeof(disks) / sizeof(disks[0])) | |
1308 | return false; | |
1309 | ||
1310 | old_fname = disks[index].fname; | |
1311 | old_flabel = disks[index].flabel; | |
1312 | ||
1313 | disks[index].fname = NULL; | |
1314 | disks[index].flabel = NULL; | |
1315 | disks[index].internal_index = 0; | |
1316 | ||
1317 | if (info != NULL) | |
1318 | { | |
1319 | char disk_label[PATH_MAX]; | |
1320 | disk_label[0] = '\0'; | |
1321 | ||
1322 | disks[index].fname = strdup(info->path); | |
23ea11bd | 1323 | |
7a8d521f | 1324 | get_disk_label(disk_label, info->path, PATH_MAX); |
1325 | disks[index].flabel = strdup(disk_label); | |
23ea11bd | 1326 | |
7a8d521f | 1327 | if (index == disk_current_index) |
1328 | ret = disk_set_image_index(index); | |
1329 | } | |
23ea11bd | 1330 | |
7a8d521f | 1331 | if (old_fname != NULL) |
1332 | free(old_fname); | |
23ea11bd | 1333 | |
7a8d521f | 1334 | if (old_flabel != NULL) |
1335 | free(old_flabel); | |
23ea11bd | 1336 | |
7a8d521f | 1337 | return ret; |
23ea11bd | 1338 | } |
1339 | ||
1340 | static bool disk_add_image_index(void) | |
1341 | { | |
7a8d521f | 1342 | if (disk_count >= 8) |
1343 | return false; | |
51ba7408 | 1344 | |
7a8d521f | 1345 | disk_count++; |
1346 | return true; | |
23ea11bd | 1347 | } |
1348 | ||
7a8d521f | 1349 | static bool disk_set_initial_image(unsigned index, const char *path) |
1350 | { | |
1351 | if (index >= sizeof(disks) / sizeof(disks[0])) | |
1352 | return false; | |
23ea11bd | 1353 | |
7a8d521f | 1354 | if (!path || (*path == '\0')) |
1355 | return false; | |
9fba39a9 | 1356 | |
7a8d521f | 1357 | disk_initial_index = index; |
9fba39a9 | 1358 | |
7a8d521f | 1359 | strncpy(disk_initial_path, path, sizeof(disk_initial_path) - 1); |
1360 | disk_initial_path[sizeof(disk_initial_path) - 1] = '\0'; | |
1361 | ||
1362 | return true; | |
9fba39a9 T |
1363 | } |
1364 | ||
7a8d521f | 1365 | static bool disk_get_image_path(unsigned index, char *path, size_t len) |
9fba39a9 | 1366 | { |
7a8d521f | 1367 | const char *fname = NULL; |
9fba39a9 | 1368 | |
7a8d521f | 1369 | if (len < 1) |
1370 | return false; | |
9fba39a9 | 1371 | |
7a8d521f | 1372 | if (index >= sizeof(disks) / sizeof(disks[0])) |
1373 | return false; | |
1374 | ||
1375 | fname = disks[index].fname; | |
1376 | ||
1377 | if (!fname || (*fname == '\0')) | |
1378 | return false; | |
1379 | ||
1380 | strncpy(path, fname, len - 1); | |
1381 | path[len - 1] = '\0'; | |
1382 | ||
1383 | return true; | |
1384 | } | |
1385 | ||
1386 | static bool disk_get_image_label(unsigned index, char *label, size_t len) | |
1387 | { | |
1388 | const char *flabel = NULL; | |
1389 | ||
1390 | if (len < 1) | |
1391 | return false; | |
1392 | ||
1393 | if (index >= sizeof(disks) / sizeof(disks[0])) | |
1394 | return false; | |
1395 | ||
1396 | flabel = disks[index].flabel; | |
1397 | ||
1398 | if (!flabel || (*flabel == '\0')) | |
1399 | return false; | |
1400 | ||
1401 | strncpy(label, flabel, len - 1); | |
1402 | label[len - 1] = '\0'; | |
1403 | ||
1404 | return true; | |
1405 | } | |
1406 | ||
1407 | static struct retro_disk_control_callback disk_control = { | |
1408 | .set_eject_state = disk_set_eject_state, | |
1409 | .get_eject_state = disk_get_eject_state, | |
1410 | .get_image_index = disk_get_image_index, | |
1411 | .set_image_index = disk_set_image_index, | |
1412 | .get_num_images = disk_get_num_images, | |
1413 | .replace_image_index = disk_replace_image_index, | |
1414 | .add_image_index = disk_add_image_index, | |
1415 | }; | |
1416 | ||
1417 | static struct retro_disk_control_ext_callback disk_control_ext = { | |
1418 | .set_eject_state = disk_set_eject_state, | |
1419 | .get_eject_state = disk_get_eject_state, | |
1420 | .get_image_index = disk_get_image_index, | |
1421 | .set_image_index = disk_set_image_index, | |
1422 | .get_num_images = disk_get_num_images, | |
1423 | .replace_image_index = disk_replace_image_index, | |
1424 | .add_image_index = disk_add_image_index, | |
1425 | .set_initial_image = disk_set_initial_image, | |
1426 | .get_image_path = disk_get_image_path, | |
1427 | .get_image_label = disk_get_image_label, | |
1428 | }; | |
1429 | ||
1430 | static char base_dir[1024]; | |
1431 | ||
1432 | static bool read_m3u(const char *file) | |
1433 | { | |
1434 | char line[1024]; | |
1435 | char name[PATH_MAX]; | |
1436 | FILE *fp = fopen(file, "r"); | |
1437 | if (!fp) | |
1438 | return false; | |
1439 | ||
1440 | while (fgets(line, sizeof(line), fp) && disk_count < sizeof(disks) / sizeof(disks[0])) | |
1441 | { | |
1442 | if (line[0] == '#') | |
1443 | continue; | |
1444 | char *carrige_return = strchr(line, '\r'); | |
1445 | if (carrige_return) | |
1446 | *carrige_return = '\0'; | |
1447 | char *newline = strchr(line, '\n'); | |
1448 | if (newline) | |
1449 | *newline = '\0'; | |
1450 | ||
1451 | if (line[0] != '\0') | |
1452 | { | |
1453 | char disk_label[PATH_MAX]; | |
1454 | disk_label[0] = '\0'; | |
1455 | ||
1456 | snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line); | |
1457 | disks[disk_count].fname = strdup(name); | |
1458 | ||
1459 | get_disk_label(disk_label, name, PATH_MAX); | |
1460 | disks[disk_count].flabel = strdup(disk_label); | |
1461 | ||
1462 | disk_count++; | |
1463 | } | |
1464 | } | |
1465 | ||
1466 | fclose(fp); | |
1467 | return (disk_count != 0); | |
1468 | } | |
1469 | ||
1470 | static void extract_directory(char *buf, const char *path, size_t size) | |
1471 | { | |
1472 | char *base; | |
1473 | strncpy(buf, path, size - 1); | |
1474 | buf[size - 1] = '\0'; | |
1475 | ||
1476 | base = strrchr(buf, '/'); | |
1477 | if (!base) | |
1478 | base = strrchr(buf, '\\'); | |
1479 | ||
1480 | if (base) | |
1481 | *base = '\0'; | |
1482 | else | |
1483 | { | |
9fba39a9 T |
1484 | buf[0] = '.'; |
1485 | buf[1] = '\0'; | |
1486 | } | |
1487 | } | |
1488 | ||
003cfc63 | 1489 | #if defined(__QNX__) || defined(_WIN32) |
41294f4d | 1490 | /* Blackberry QNX doesn't have strcasestr */ |
1491 | ||
1492 | /* | |
1493 | * Find the first occurrence of find in s, ignore case. | |
1494 | */ | |
1495 | char * | |
7a8d521f | 1496 | strcasestr(const char *s, const char *find) |
1497 | { | |
1498 | char c, sc; | |
1499 | size_t len; | |
1500 | ||
1501 | if ((c = *find++) != 0) | |
1502 | { | |
1503 | c = tolower((unsigned char)c); | |
1504 | len = strlen(find); | |
1505 | do | |
1506 | { | |
1507 | do | |
1508 | { | |
1509 | if ((sc = *s++) == 0) | |
1510 | return (NULL); | |
1511 | } while ((char)tolower((unsigned char)sc) != c); | |
1512 | } while (strncasecmp(s, find, len) != 0); | |
1513 | s--; | |
1514 | } | |
1515 | return ((char *)s); | |
41294f4d | 1516 | } |
1517 | #endif | |
1518 | ||
7a8d521f | 1519 | static void set_retro_memmap(void) |
1520 | { | |
1521 | #ifndef NDEBUG | |
1522 | struct retro_memory_map retromap = { 0 }; | |
1523 | struct retro_memory_descriptor mmap = { | |
1524 | 0, psxM, 0, 0, 0, 0, 0x200000 | |
1525 | }; | |
1526 | ||
1527 | retromap.descriptors = &mmap; | |
1528 | retromap.num_descriptors = 1; | |
1529 | ||
1530 | environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &retromap); | |
1531 | #endif | |
1532 | } | |
1533 | ||
f3746eea | 1534 | static void show_notification(const char *msg_str, |
1535 | unsigned duration_ms, unsigned priority) | |
1536 | { | |
1537 | if (msg_interface_version >= 1) | |
1538 | { | |
1539 | struct retro_message_ext msg = { | |
1540 | msg_str, | |
1541 | duration_ms, | |
1542 | 3, | |
1543 | RETRO_LOG_WARN, | |
1544 | RETRO_MESSAGE_TARGET_ALL, | |
1545 | RETRO_MESSAGE_TYPE_NOTIFICATION, | |
1546 | -1 | |
1547 | }; | |
1548 | environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg); | |
1549 | } | |
1550 | else | |
1551 | { | |
1552 | struct retro_message msg = { | |
1553 | msg_str, | |
1554 | 180 | |
1555 | }; | |
1556 | environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); | |
1557 | } | |
1558 | } | |
1559 | ||
7a8d521f | 1560 | static void retro_audio_buff_status_cb( |
1561 | bool active, unsigned occupancy, bool underrun_likely) | |
1562 | { | |
1563 | retro_audio_buff_active = active; | |
1564 | retro_audio_buff_occupancy = occupancy; | |
1565 | retro_audio_buff_underrun = underrun_likely; | |
1566 | } | |
1567 | ||
1568 | static void retro_set_audio_buff_status_cb(void) | |
1569 | { | |
1570 | if (frameskip_type == FRAMESKIP_NONE) | |
1571 | { | |
1572 | environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL); | |
1573 | retro_audio_latency = 0; | |
1574 | } | |
1575 | else | |
1576 | { | |
1577 | bool calculate_audio_latency = true; | |
1578 | ||
1579 | if (frameskip_type == FRAMESKIP_FIXED_INTERVAL) | |
1580 | environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, NULL); | |
1581 | else | |
1582 | { | |
1583 | struct retro_audio_buffer_status_callback buf_status_cb; | |
1584 | buf_status_cb.callback = retro_audio_buff_status_cb; | |
1585 | if (!environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, | |
1586 | &buf_status_cb)) | |
1587 | { | |
1588 | retro_audio_buff_active = false; | |
1589 | retro_audio_buff_occupancy = 0; | |
1590 | retro_audio_buff_underrun = false; | |
1591 | retro_audio_latency = 0; | |
1592 | calculate_audio_latency = false; | |
1593 | } | |
1594 | } | |
1595 | ||
1596 | if (calculate_audio_latency) | |
1597 | { | |
1598 | /* Frameskip is enabled - increase frontend | |
1599 | * audio latency to minimise potential | |
1600 | * buffer underruns */ | |
1601 | uint32_t frame_time_usec = 1000000.0 / (is_pal_mode ? 50.0 : 60.0); | |
1602 | ||
1603 | /* Set latency to 6x current frame time... */ | |
1604 | retro_audio_latency = (unsigned)(6 * frame_time_usec / 1000); | |
1605 | ||
1606 | /* ...then round up to nearest multiple of 32 */ | |
1607 | retro_audio_latency = (retro_audio_latency + 0x1F) & ~0x1F; | |
1608 | } | |
1609 | } | |
1610 | ||
1611 | update_audio_latency = true; | |
1612 | frameskip_counter = 0; | |
1613 | } | |
1614 | ||
1615 | static void update_variables(bool in_flight); | |
38c2028e | 1616 | bool retro_load_game(const struct retro_game_info *info) |
1617 | { | |
7a8d521f | 1618 | size_t i; |
1619 | unsigned int cd_index = 0; | |
1620 | bool is_m3u = (strcasestr(info->path, ".m3u") != NULL); | |
8cddf575 | 1621 | bool is_exe = (strcasestr(info->path, ".exe") != NULL); |
1622 | int ret; | |
9fba39a9 | 1623 | |
e3f8313f | 1624 | struct retro_input_descriptor desc[] = { |
7a8d521f | 1625 | #define JOYP(port) \ |
1626 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, \ | |
1627 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, \ | |
1628 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, \ | |
1629 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, \ | |
1630 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, \ | |
1631 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, \ | |
1632 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, \ | |
1633 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, \ | |
1634 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, \ | |
1635 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, \ | |
1636 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, \ | |
1637 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, \ | |
1638 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, \ | |
1639 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, \ | |
1640 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, \ | |
1641 | { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, \ | |
1642 | { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, \ | |
1643 | { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, \ | |
1644 | { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, \ | |
1645 | { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, \ | |
1646 | { port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER, "Gun Trigger" }, \ | |
1647 | { port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD, "Gun Reload" }, \ | |
1648 | { port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_A, "Gun Aux A" }, \ | |
d6a231b7 S |
1649 | { port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_B, "Gun Aux B" }, \ |
1650 | { port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_START, "Gun Start" }, | |
7a8d521f | 1651 | |
1652 | JOYP(0) | |
1653 | JOYP(1) | |
1654 | JOYP(2) | |
1655 | JOYP(3) | |
1656 | JOYP(4) | |
1657 | JOYP(5) | |
1658 | JOYP(6) | |
1659 | JOYP(7) | |
e3f8313f | 1660 | |
1661 | { 0 }, | |
1662 | }; | |
1663 | ||
7a8d521f | 1664 | frame_count = 0; |
1665 | ||
e3f8313f | 1666 | environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); |
1667 | ||
46aa5b98 | 1668 | #ifdef FRONTEND_SUPPORTS_RGB565 |
7a8d521f | 1669 | enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; |
1670 | if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) | |
1671 | { | |
1672 | SysPrintf("RGB565 supported, using it\n"); | |
1673 | } | |
46aa5b98 | 1674 | #endif |
c19aba43 | 1675 | |
7a8d521f | 1676 | if (info == NULL || info->path == NULL) |
1677 | { | |
1678 | SysPrintf("info->path required\n"); | |
1679 | return false; | |
1680 | } | |
23ea11bd | 1681 | |
7a8d521f | 1682 | update_variables(false); |
38c2028e | 1683 | |
7a8d521f | 1684 | if (plugins_opened) |
1685 | { | |
1686 | ClosePlugins(); | |
1687 | plugins_opened = 0; | |
1688 | } | |
23ea11bd | 1689 | |
7a8d521f | 1690 | disk_init(); |
9fba39a9 | 1691 | |
7a8d521f | 1692 | extract_directory(base_dir, info->path, sizeof(base_dir)); |
23ea11bd | 1693 | |
7a8d521f | 1694 | if (is_m3u) |
1695 | { | |
1696 | if (!read_m3u(info->path)) | |
1697 | { | |
1698 | log_cb(RETRO_LOG_INFO, "failed to read m3u file\n"); | |
1699 | return false; | |
1700 | } | |
1701 | } | |
1702 | else | |
1703 | { | |
1704 | char disk_label[PATH_MAX]; | |
1705 | disk_label[0] = '\0'; | |
38c2028e | 1706 | |
7a8d521f | 1707 | disk_count = 1; |
1708 | disks[0].fname = strdup(info->path); | |
38c2028e | 1709 | |
7a8d521f | 1710 | get_disk_label(disk_label, info->path, PATH_MAX); |
1711 | disks[0].flabel = strdup(disk_label); | |
1712 | } | |
38c2028e | 1713 | |
7a8d521f | 1714 | /* If this is an M3U file, attempt to set the |
1715 | * initial disk image */ | |
1716 | if (is_m3u && (disk_initial_index > 0) && (disk_initial_index < disk_count)) | |
1717 | { | |
1718 | const char *fname = disks[disk_initial_index].fname; | |
38c2028e | 1719 | |
7a8d521f | 1720 | if (fname && (*fname != '\0')) |
1721 | if (strcmp(disk_initial_path, fname) == 0) | |
1722 | cd_index = disk_initial_index; | |
1723 | } | |
38c2028e | 1724 | |
7a8d521f | 1725 | set_cd_image(disks[cd_index].fname); |
1726 | disk_current_index = cd_index; | |
38c2028e | 1727 | |
7a8d521f | 1728 | /* have to reload after set_cd_image for correct cdr plugin */ |
1729 | if (LoadPlugins() == -1) | |
1730 | { | |
1731 | log_cb(RETRO_LOG_INFO, "failed to load plugins\n"); | |
1732 | return false; | |
1733 | } | |
38c2028e | 1734 | |
7a8d521f | 1735 | plugins_opened = 1; |
1736 | NetOpened = 0; | |
38c2028e | 1737 | |
7a8d521f | 1738 | if (OpenPlugins() == -1) |
1739 | { | |
1740 | log_cb(RETRO_LOG_INFO, "failed to open plugins\n"); | |
1741 | return false; | |
1742 | } | |
23ea11bd | 1743 | |
7a8d521f | 1744 | /* Handle multi-disk images (i.e. PBP) |
1745 | * > Cannot do this until after OpenPlugins() is | |
1746 | * called (since this sets the value of | |
1747 | * cdrIsoMultidiskCount) */ | |
1748 | if (!is_m3u && (cdrIsoMultidiskCount > 1)) | |
1749 | { | |
1750 | disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8; | |
38c2028e | 1751 | |
7a8d521f | 1752 | /* Small annoyance: We need to change the label |
1753 | * of disk 0, so have to clear existing entries */ | |
1754 | if (disks[0].fname != NULL) | |
1755 | free(disks[0].fname); | |
1756 | disks[0].fname = NULL; | |
38c2028e | 1757 | |
7a8d521f | 1758 | if (disks[0].flabel != NULL) |
1759 | free(disks[0].flabel); | |
1760 | disks[0].flabel = NULL; | |
1761 | ||
1762 | for (i = 0; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) | |
1763 | { | |
1764 | char disk_name[PATH_MAX - 16] = { 0 }; | |
1765 | char disk_label[PATH_MAX] = { 0 }; | |
1766 | ||
1767 | disks[i].fname = strdup(info->path); | |
1768 | ||
1769 | get_disk_label(disk_name, info->path, sizeof(disk_name)); | |
1770 | snprintf(disk_label, sizeof(disk_label), "%s #%u", disk_name, (unsigned)i + 1); | |
1771 | disks[i].flabel = strdup(disk_label); | |
1772 | ||
1773 | disks[i].internal_index = i; | |
1774 | } | |
1775 | ||
1776 | /* This is not an M3U file, so initial disk | |
1777 | * image has not yet been set - attempt to | |
1778 | * do so now */ | |
1779 | if ((disk_initial_index > 0) && (disk_initial_index < disk_count)) | |
1780 | { | |
1781 | const char *fname = disks[disk_initial_index].fname; | |
1782 | ||
1783 | if (fname && (*fname != '\0')) | |
1784 | if (strcmp(disk_initial_path, fname) == 0) | |
1785 | cd_index = disk_initial_index; | |
1786 | } | |
1787 | ||
1788 | if (cd_index > 0) | |
1789 | { | |
1790 | CdromId[0] = '\0'; | |
1791 | CdromLabel[0] = '\0'; | |
1792 | ||
1793 | cdrIsoMultidiskSelect = disks[cd_index].internal_index; | |
1794 | disk_current_index = cd_index; | |
1795 | set_cd_image(disks[cd_index].fname); | |
1796 | ||
1797 | if (ReloadCdromPlugin() < 0) | |
1798 | { | |
1799 | log_cb(RETRO_LOG_INFO, "failed to reload cdr plugins\n"); | |
1800 | return false; | |
1801 | } | |
1802 | if (CDR_open() < 0) | |
1803 | { | |
1804 | log_cb(RETRO_LOG_INFO, "failed to open cdr plugin\n"); | |
1805 | return false; | |
1806 | } | |
1807 | } | |
1808 | } | |
1809 | ||
1810 | /* set ports to use "standard controller" initially */ | |
1811 | for (i = 0; i < 8; ++i) | |
1812 | in_type[i] = PSE_PAD_TYPE_STANDARD; | |
1813 | ||
1814 | plugin_call_rearmed_cbs(); | |
1815 | /* dfinput_activate(); */ | |
1816 | ||
8cddf575 | 1817 | if (!is_exe && CheckCdrom() == -1) |
7a8d521f | 1818 | { |
1819 | log_cb(RETRO_LOG_INFO, "unsupported/invalid CD image: %s\n", info->path); | |
1820 | return false; | |
1821 | } | |
1822 | ||
1823 | SysReset(); | |
1824 | ||
8cddf575 | 1825 | if (is_exe) |
1826 | ret = Load(info->path); | |
1827 | else | |
1828 | ret = LoadCdrom(); | |
1829 | if (ret != 0) | |
7a8d521f | 1830 | { |
8cddf575 | 1831 | log_cb(RETRO_LOG_INFO, "could not load %s (%d)\n", is_exe ? "exe" : "CD", ret); |
7a8d521f | 1832 | return false; |
1833 | } | |
1834 | emu_on_new_cd(0); | |
1835 | ||
1836 | set_retro_memmap(); | |
1837 | retro_set_audio_buff_status_cb(); | |
1838 | ||
f3746eea | 1839 | if (check_unsatisfied_libcrypt()) |
1840 | show_notification("LibCrypt protected game with missing SBI detected", 3000, 3); | |
1841 | ||
7a8d521f | 1842 | return true; |
38c2028e | 1843 | } |
1844 | ||
1845 | unsigned retro_get_region(void) | |
1846 | { | |
7a8d521f | 1847 | return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC; |
38c2028e | 1848 | } |
1849 | ||
1850 | void *retro_get_memory_data(unsigned id) | |
1851 | { | |
7a8d521f | 1852 | if (id == RETRO_MEMORY_SAVE_RAM) |
1853 | return Mcd1Data; | |
1854 | else if (id == RETRO_MEMORY_SYSTEM_RAM) | |
1855 | return psxM; | |
1856 | else | |
1857 | return NULL; | |
38c2028e | 1858 | } |
1859 | ||
1860 | size_t retro_get_memory_size(unsigned id) | |
1861 | { | |
7a8d521f | 1862 | if (id == RETRO_MEMORY_SAVE_RAM) |
1863 | return MCD_SIZE; | |
1864 | else if (id == RETRO_MEMORY_SYSTEM_RAM) | |
1865 | return 0x200000; | |
1866 | else | |
1867 | return 0; | |
38c2028e | 1868 | } |
1869 | ||
1870 | void retro_reset(void) | |
1871 | { | |
7a8d521f | 1872 | //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key |
1873 | rebootemu = 1; | |
1874 | //SysReset(); | |
38c2028e | 1875 | } |
1876 | ||
1877 | static const unsigned short retro_psx_map[] = { | |
7a8d521f | 1878 | [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS, |
1879 | [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE, | |
1880 | [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT, | |
1881 | [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START, | |
1882 | [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP, | |
1883 | [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN, | |
1884 | [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT, | |
1885 | [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT, | |
1886 | [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE, | |
1887 | [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE, | |
1888 | [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1, | |
1889 | [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1, | |
1890 | [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2, | |
1891 | [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2, | |
1892 | [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3, | |
1893 | [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3, | |
38c2028e | 1894 | }; |
1895 | #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0])) | |
1896 | ||
d6a231b7 | 1897 | //Percentage distance of screen to adjust for Guncon |
7a8d521f | 1898 | static int GunconAdjustX = 0; |
1899 | static int GunconAdjustY = 0; | |
1900 | ||
d6a231b7 | 1901 | //Used when out by a percentage with Guncon |
7a8d521f | 1902 | static float GunconAdjustRatioX = 1; |
1903 | static float GunconAdjustRatioY = 1; | |
1904 | ||
805fe9bc | 1905 | static void update_variables(bool in_flight) |
e268a47e | 1906 | { |
e268a47e | 1907 | struct retro_variable var; |
7a8d521f | 1908 | #ifdef GPU_PEOPS |
1909 | // Always enable GPU_PEOPS_OLD_FRAME_SKIP flag | |
1910 | // (this is set in standalone, with no option | |
1911 | // to change it) | |
1912 | int gpu_peops_fix = GPU_PEOPS_OLD_FRAME_SKIP; | |
1913 | #endif | |
1914 | frameskip_type_t prev_frameskip_type; | |
1915 | ||
1916 | var.value = NULL; | |
1917 | var.key = "pcsx_rearmed_frameskip_type"; | |
1918 | ||
1919 | prev_frameskip_type = frameskip_type; | |
1920 | frameskip_type = FRAMESKIP_NONE; | |
1921 | pl_rearmed_cbs.frameskip = 0; | |
1922 | ||
1923 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1924 | { | |
1925 | if (strcmp(var.value, "auto") == 0) | |
1926 | frameskip_type = FRAMESKIP_AUTO; | |
1927 | if (strcmp(var.value, "auto_threshold") == 0) | |
1928 | frameskip_type = FRAMESKIP_AUTO_THRESHOLD; | |
1929 | if (strcmp(var.value, "fixed_interval") == 0) | |
1930 | frameskip_type = FRAMESKIP_FIXED_INTERVAL; | |
1931 | } | |
1932 | ||
1933 | if (frameskip_type != 0) | |
1934 | pl_rearmed_cbs.frameskip = -1; | |
7d68d030 | 1935 | |
e268a47e | 1936 | var.value = NULL; |
7a8d521f | 1937 | var.key = "pcsx_rearmed_frameskip_threshold"; |
1938 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1939 | { | |
1940 | frameskip_threshold = strtol(var.value, NULL, 10); | |
1941 | } | |
e268a47e | 1942 | |
7a8d521f | 1943 | var.value = NULL; |
1944 | var.key = "pcsx_rearmed_frameskip_interval"; | |
1945 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1946 | { | |
1947 | frameskip_interval = strtol(var.value, NULL, 10); | |
1948 | } | |
9f5a28d9 | 1949 | |
1950 | var.value = NULL; | |
4e477065 | 1951 | var.key = "pcsx_rearmed_region"; |
7a8d521f | 1952 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
9f5a28d9 | 1953 | { |
1954 | Config.PsxAuto = 0; | |
7a8d521f | 1955 | if (strcmp(var.value, "auto") == 0) |
9f5a28d9 | 1956 | Config.PsxAuto = 1; |
1957 | else if (strcmp(var.value, "NTSC") == 0) | |
1958 | Config.PsxType = 0; | |
1959 | else if (strcmp(var.value, "PAL") == 0) | |
1960 | Config.PsxType = 1; | |
1961 | } | |
4615b075 | 1962 | |
7a8d521f | 1963 | update_multitap(); |
1964 | ||
4615b075 | 1965 | var.value = NULL; |
7a8d521f | 1966 | var.key = "pcsx_rearmed_negcon_deadzone"; |
1967 | negcon_deadzone = 0; | |
1968 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1969 | { | |
1970 | negcon_deadzone = (int)(atoi(var.value) * 0.01f * NEGCON_RANGE); | |
1971 | } | |
4615b075 | 1972 | |
7a8d521f | 1973 | var.value = NULL; |
1974 | var.key = "pcsx_rearmed_negcon_response"; | |
1975 | negcon_linearity = 1; | |
1976 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
4615b075 | 1977 | { |
7a8d521f | 1978 | if (strcmp(var.value, "quadratic") == 0) |
1979 | { | |
1980 | negcon_linearity = 2; | |
1981 | } | |
1982 | else if (strcmp(var.value, "cubic") == 0) | |
1983 | { | |
1984 | negcon_linearity = 3; | |
1985 | } | |
1986 | } | |
1987 | ||
1988 | var.value = NULL; | |
1989 | var.key = "pcsx_rearmed_analog_axis_modifier"; | |
1990 | axis_bounds_modifier = true; | |
1991 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1992 | { | |
1993 | if (strcmp(var.value, "square") == 0) | |
1994 | { | |
1995 | axis_bounds_modifier = true; | |
1996 | } | |
1997 | else if (strcmp(var.value, "circle") == 0) | |
1998 | { | |
1999 | axis_bounds_modifier = false; | |
2000 | } | |
2001 | } | |
2002 | ||
2003 | var.value = NULL; | |
2004 | var.key = "pcsx_rearmed_vibration"; | |
2005 | ||
2006 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2007 | { | |
2008 | if (strcmp(var.value, "disabled") == 0) | |
2009 | in_enable_vibration = 0; | |
2010 | else if (strcmp(var.value, "enabled") == 0) | |
2011 | in_enable_vibration = 1; | |
4615b075 | 2012 | } |
2013 | ||
4e477065 | 2014 | var.value = NULL; |
7a8d521f | 2015 | var.key = "pcsx_rearmed_dithering"; |
4e477065 | 2016 | |
7a8d521f | 2017 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
4e477065 | 2018 | { |
7a8d521f | 2019 | if (strcmp(var.value, "disabled") == 0) |
2020 | { | |
2021 | pl_rearmed_cbs.gpu_peops.iUseDither = 0; | |
2022 | pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 0; | |
2023 | pl_rearmed_cbs.gpu_unai.dithering = 0; | |
2024 | #ifdef GPU_NEON | |
2025 | pl_rearmed_cbs.gpu_neon.allow_dithering = 0; | |
2026 | #endif | |
2027 | } | |
2028 | else if (strcmp(var.value, "enabled") == 0) | |
2029 | { | |
2030 | pl_rearmed_cbs.gpu_peops.iUseDither = 1; | |
2031 | pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 1; | |
2032 | pl_rearmed_cbs.gpu_unai.dithering = 1; | |
2033 | #ifdef GPU_NEON | |
2034 | pl_rearmed_cbs.gpu_neon.allow_dithering = 1; | |
2035 | #endif | |
2036 | } | |
4e477065 | 2037 | } |
2038 | ||
7a8d521f | 2039 | #ifdef GPU_NEON |
2040 | var.value = NULL; | |
fdcde643 | 2041 | var.key = "pcsx_rearmed_neon_interlace_enable_v2"; |
9f5a28d9 | 2042 | |
7a8d521f | 2043 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
9f5a28d9 | 2044 | { |
2045 | if (strcmp(var.value, "disabled") == 0) | |
2046 | pl_rearmed_cbs.gpu_neon.allow_interlace = 0; | |
2047 | else if (strcmp(var.value, "enabled") == 0) | |
2048 | pl_rearmed_cbs.gpu_neon.allow_interlace = 1; | |
fdcde643 | 2049 | else // auto |
2050 | pl_rearmed_cbs.gpu_neon.allow_interlace = 2; | |
9f5a28d9 | 2051 | } |
2052 | ||
7d68d030 | 2053 | var.value = NULL; |
55e5626b | 2054 | var.key = "pcsx_rearmed_neon_enhancement_enable"; |
7d68d030 | 2055 | |
7a8d521f | 2056 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
7d68d030 | 2057 | { |
2058 | if (strcmp(var.value, "disabled") == 0) | |
2059 | pl_rearmed_cbs.gpu_neon.enhancement_enable = 0; | |
2060 | else if (strcmp(var.value, "enabled") == 0) | |
2061 | pl_rearmed_cbs.gpu_neon.enhancement_enable = 1; | |
2062 | } | |
354329fa | 2063 | |
2064 | var.value = NULL; | |
55e5626b | 2065 | var.key = "pcsx_rearmed_neon_enhancement_no_main"; |
354329fa | 2066 | |
7a8d521f | 2067 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
354329fa | 2068 | { |
2069 | if (strcmp(var.value, "disabled") == 0) | |
2070 | pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0; | |
2071 | else if (strcmp(var.value, "enabled") == 0) | |
2072 | pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1; | |
2073 | } | |
094ec204 | 2074 | #endif |
0e5a7b7d | 2075 | |
7a8d521f | 2076 | var.value = NULL; |
0e5a7b7d | 2077 | var.key = "pcsx_rearmed_duping_enable"; |
2078 | ||
7a8d521f | 2079 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
0e5a7b7d | 2080 | { |
7a8d521f | 2081 | if (strcmp(var.value, "disabled") == 0) |
0e5a7b7d | 2082 | duping_enable = false; |
7a8d521f | 2083 | else if (strcmp(var.value, "enabled") == 0) |
0e5a7b7d | 2084 | duping_enable = true; |
2085 | } | |
2086 | ||
7a8d521f | 2087 | var.value = NULL; |
2088 | var.key = "pcsx_rearmed_display_internal_fps"; | |
2089 | ||
2090 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2091 | { | |
2092 | if (strcmp(var.value, "disabled") == 0) | |
2093 | display_internal_fps = false; | |
2094 | else if (strcmp(var.value, "enabled") == 0) | |
2095 | display_internal_fps = true; | |
2096 | } | |
2097 | ||
2098 | // | |
2099 | // CPU emulation related config | |
48f615ba | 2100 | #ifndef DRC_DISABLE |
2101 | var.value = NULL; | |
4e477065 | 2102 | var.key = "pcsx_rearmed_drc"; |
48f615ba | 2103 | |
7a8d521f | 2104 | if (!environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var)) |
2105 | var.value = "enabled"; | |
2106 | ||
48f615ba | 2107 | { |
2108 | R3000Acpu *prev_cpu = psxCpu; | |
2109 | ||
7a8d521f | 2110 | #ifdef _3DS |
2111 | if (!__ctr_svchax) | |
2112 | Config.Cpu = CPU_INTERPRETER; | |
2113 | else | |
2114 | #endif | |
1da9b9ae | 2115 | if (strcmp(var.value, "disabled") == 0) |
48f615ba | 2116 | Config.Cpu = CPU_INTERPRETER; |
2117 | else if (strcmp(var.value, "enabled") == 0) | |
2118 | Config.Cpu = CPU_DYNAREC; | |
2119 | ||
2120 | psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec; | |
7a8d521f | 2121 | if (psxCpu != prev_cpu) |
2122 | { | |
980f7a58 | 2123 | prev_cpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); |
48f615ba | 2124 | prev_cpu->Shutdown(); |
2125 | psxCpu->Init(); | |
980f7a58 | 2126 | psxCpu->Reset(); |
2127 | psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); | |
48f615ba | 2128 | } |
2129 | } | |
7a8d521f | 2130 | #endif /* !DRC_DISABLE */ |
2131 | ||
2132 | var.value = NULL; | |
2133 | var.key = "pcsx_rearmed_psxclock"; | |
2134 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2135 | { | |
2136 | int psxclock = atoi(var.value); | |
2137 | Config.cycle_multiplier = 10000 / psxclock; | |
2138 | } | |
2139 | ||
2140 | #if !defined(DRC_DISABLE) && !defined(LIGHTREC) | |
2141 | var.value = NULL; | |
2142 | var.key = "pcsx_rearmed_nosmccheck"; | |
2143 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2144 | { | |
2145 | if (strcmp(var.value, "enabled") == 0) | |
2146 | new_dynarec_hacks |= NDHACK_NO_SMC_CHECK; | |
2147 | else | |
2148 | new_dynarec_hacks &= ~NDHACK_NO_SMC_CHECK; | |
2149 | } | |
2150 | ||
2151 | var.value = NULL; | |
2152 | var.key = "pcsx_rearmed_gteregsunneeded"; | |
2153 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2154 | { | |
2155 | if (strcmp(var.value, "enabled") == 0) | |
2156 | new_dynarec_hacks |= NDHACK_GTE_UNNEEDED; | |
2157 | else | |
2158 | new_dynarec_hacks &= ~NDHACK_GTE_UNNEEDED; | |
2159 | } | |
2160 | ||
2161 | var.value = NULL; | |
2162 | var.key = "pcsx_rearmed_nogteflags"; | |
2163 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2164 | { | |
2165 | if (strcmp(var.value, "enabled") == 0) | |
2166 | new_dynarec_hacks |= NDHACK_GTE_NO_FLAGS; | |
2167 | else | |
2168 | new_dynarec_hacks &= ~NDHACK_GTE_NO_FLAGS; | |
2169 | } | |
2170 | ||
2171 | var.value = NULL; | |
2172 | var.key = "pcsx_rearmed_nocompathacks"; | |
2173 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2174 | { | |
2175 | if (strcmp(var.value, "enabled") == 0) | |
2176 | new_dynarec_hacks |= NDHACK_NO_COMPAT_HACKS; | |
2177 | else | |
2178 | new_dynarec_hacks &= ~NDHACK_NO_COMPAT_HACKS; | |
2179 | } | |
2180 | #endif /* !DRC_DISABLE && !LIGHTREC */ | |
2181 | ||
2182 | var.value = NULL; | |
2183 | var.key = "pcsx_rearmed_nostalls"; | |
2184 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2185 | { | |
2186 | if (strcmp(var.value, "enabled") == 0) | |
2187 | Config.DisableStalls = 1; | |
2188 | else | |
2189 | Config.DisableStalls = 0; | |
2190 | } | |
2191 | ||
2192 | var.value = NULL; | |
2193 | var.key = "pcsx_rearmed_icache_emulation"; | |
2194 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2195 | { | |
2196 | if (strcmp(var.value, "disabled") == 0) | |
2197 | Config.icache_emulation = 0; | |
2198 | else if (strcmp(var.value, "enabled") == 0) | |
2199 | Config.icache_emulation = 1; | |
2200 | } | |
2201 | ||
bc7c5acb | 2202 | var.value = NULL; |
2203 | var.key = "pcsx_rearmed_exception_emulation"; | |
2204 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2205 | { | |
2206 | if (strcmp(var.value, "enabled") == 0) | |
2207 | Config.PreciseExceptions = 1; | |
2208 | else | |
2209 | Config.PreciseExceptions = 0; | |
2210 | } | |
2211 | ||
32631e6a | 2212 | psxCpu->ApplyConfig(); |
805fe9bc | 2213 | |
7a8d521f | 2214 | // end of CPU emu config |
2215 | // | |
2216 | ||
2217 | var.value = NULL; | |
01394a7f | 2218 | var.key = "pcsx_rearmed_spu_reverb"; |
2219 | ||
7a8d521f | 2220 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
01394a7f | 2221 | { |
7a8d521f | 2222 | if (strcmp(var.value, "disabled") == 0) |
01394a7f | 2223 | spu_config.iUseReverb = false; |
7a8d521f | 2224 | else if (strcmp(var.value, "enabled") == 0) |
01394a7f | 2225 | spu_config.iUseReverb = true; |
2226 | } | |
2227 | ||
7a8d521f | 2228 | var.value = NULL; |
01394a7f | 2229 | var.key = "pcsx_rearmed_spu_interpolation"; |
2230 | ||
7a8d521f | 2231 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) |
01394a7f | 2232 | { |
2233 | if (strcmp(var.value, "simple") == 0) | |
2234 | spu_config.iUseInterpolation = 1; | |
2235 | else if (strcmp(var.value, "gaussian") == 0) | |
2236 | spu_config.iUseInterpolation = 2; | |
2237 | else if (strcmp(var.value, "cubic") == 0) | |
2238 | spu_config.iUseInterpolation = 3; | |
2239 | else if (strcmp(var.value, "off") == 0) | |
2240 | spu_config.iUseInterpolation = 0; | |
2241 | } | |
2242 | ||
16809ab9 | 2243 | var.value = NULL; |
2244 | var.key = "pcsx_rearmed_spu_thread"; | |
2245 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2246 | { | |
2247 | if (strcmp(var.value, "enabled") == 0) | |
2248 | spu_config.iUseThread = 1; | |
2249 | else | |
2250 | spu_config.iUseThread = 0; | |
2251 | } | |
2252 | ||
606bece1 | 2253 | #if 0 // currently disabled, see USE_READ_THREAD in libpcsxcore/cdriso.c |
9165d434 | 2254 | if (P_HAVE_PTHREAD) { |
f28d12a7 PC |
2255 | var.value = NULL; |
2256 | var.key = "pcsx_rearmed_async_cd"; | |
2257 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2258 | { | |
2259 | if (strcmp(var.value, "async") == 0) | |
2260 | { | |
2261 | Config.AsyncCD = 1; | |
2262 | Config.CHD_Precache = 0; | |
2263 | } | |
2264 | else if (strcmp(var.value, "sync") == 0) | |
2265 | { | |
2266 | Config.AsyncCD = 0; | |
2267 | Config.CHD_Precache = 0; | |
2268 | } | |
2269 | else if (strcmp(var.value, "precache") == 0) | |
2270 | { | |
2271 | Config.AsyncCD = 0; | |
2272 | Config.CHD_Precache = 1; | |
2273 | } | |
2274 | } | |
7a8d521f | 2275 | } |
606bece1 | 2276 | #endif |
7a8d521f | 2277 | |
2278 | var.value = NULL; | |
2279 | var.key = "pcsx_rearmed_noxadecoding"; | |
2280 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2281 | { | |
2282 | if (strcmp(var.value, "disabled") == 0) | |
2283 | Config.Xa = 1; | |
2284 | else | |
2285 | Config.Xa = 0; | |
2286 | } | |
2287 | ||
2288 | var.value = NULL; | |
2289 | var.key = "pcsx_rearmed_nocdaudio"; | |
2290 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2291 | { | |
2292 | if (strcmp(var.value, "disabled") == 0) | |
2293 | Config.Cdda = 1; | |
2294 | else | |
2295 | Config.Cdda = 0; | |
2296 | } | |
2297 | ||
8c84ba5f | 2298 | var.value = NULL; |
2299 | var.key = "pcsx_rearmed_gpu_slow_llists"; | |
2300 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2301 | { | |
2302 | if (strcmp(var.value, "disabled") == 0) | |
308c6e67 | 2303 | Config.GpuListWalking = 0; |
8c84ba5f | 2304 | else if (strcmp(var.value, "enabled") == 0) |
308c6e67 | 2305 | Config.GpuListWalking = 1; |
8c84ba5f | 2306 | else // auto |
308c6e67 | 2307 | Config.GpuListWalking = -1; |
2308 | } | |
2309 | ||
2310 | var.value = NULL; | |
2311 | var.key = "pcsx_rearmed_screen_centering"; | |
2312 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2313 | { | |
2314 | if (strcmp(var.value, "game") == 0) | |
2315 | pl_rearmed_cbs.screen_centering_type = 1; | |
44e76f8a | 2316 | else if (strcmp(var.value, "borderless") == 0) |
308c6e67 | 2317 | pl_rearmed_cbs.screen_centering_type = 2; |
44e76f8a | 2318 | else if (strcmp(var.value, "manual") == 0) |
2319 | pl_rearmed_cbs.screen_centering_type = 3; | |
308c6e67 | 2320 | else // auto |
2321 | pl_rearmed_cbs.screen_centering_type = 0; | |
2322 | } | |
2323 | ||
2324 | var.value = NULL; | |
2325 | var.key = "pcsx_rearmed_screen_centering_x"; | |
2326 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2327 | { | |
2328 | pl_rearmed_cbs.screen_centering_x = atoi(var.value); | |
2329 | } | |
2330 | ||
2331 | var.value = NULL; | |
2332 | var.key = "pcsx_rearmed_screen_centering_y"; | |
2333 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2334 | { | |
2335 | pl_rearmed_cbs.screen_centering_y = atoi(var.value); | |
8c84ba5f | 2336 | } |
2337 | ||
7a8d521f | 2338 | #ifdef THREAD_RENDERING |
2339 | var.key = "pcsx_rearmed_gpu_thread_rendering"; | |
2340 | var.value = NULL; | |
2341 | ||
2342 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2343 | { | |
2344 | if (strcmp(var.value, "disabled") == 0) | |
2345 | pl_rearmed_cbs.thread_rendering = THREAD_RENDERING_OFF; | |
2346 | else if (strcmp(var.value, "sync") == 0) | |
2347 | pl_rearmed_cbs.thread_rendering = THREAD_RENDERING_SYNC; | |
2348 | else if (strcmp(var.value, "async") == 0) | |
2349 | pl_rearmed_cbs.thread_rendering = THREAD_RENDERING_ASYNC; | |
2350 | } | |
2351 | #endif | |
2352 | ||
2353 | #ifdef GPU_PEOPS | |
2354 | var.value = NULL; | |
2355 | var.key = "pcsx_rearmed_gpu_peops_odd_even_bit"; | |
2356 | ||
2357 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2358 | { | |
2359 | if (strcmp(var.value, "enabled") == 0) | |
2360 | gpu_peops_fix |= GPU_PEOPS_ODD_EVEN_BIT; | |
2361 | } | |
2362 | ||
2363 | var.value = NULL; | |
2364 | var.key = "pcsx_rearmed_gpu_peops_expand_screen_width"; | |
2365 | ||
2366 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2367 | { | |
2368 | if (strcmp(var.value, "enabled") == 0) | |
2369 | gpu_peops_fix |= GPU_PEOPS_EXPAND_SCREEN_WIDTH; | |
2370 | } | |
2371 | ||
2372 | var.value = NULL; | |
2373 | var.key = "pcsx_rearmed_gpu_peops_ignore_brightness"; | |
2374 | ||
2375 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2376 | { | |
2377 | if (strcmp(var.value, "enabled") == 0) | |
2378 | gpu_peops_fix |= GPU_PEOPS_IGNORE_BRIGHTNESS; | |
2379 | } | |
2380 | ||
2381 | var.value = NULL; | |
2382 | var.key = "pcsx_rearmed_gpu_peops_disable_coord_check"; | |
2383 | ||
2384 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2385 | { | |
2386 | if (strcmp(var.value, "enabled") == 0) | |
2387 | gpu_peops_fix |= GPU_PEOPS_DISABLE_COORD_CHECK; | |
2388 | } | |
2389 | ||
2390 | var.value = NULL; | |
2391 | var.key = "pcsx_rearmed_gpu_peops_lazy_screen_update"; | |
2392 | ||
2393 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2394 | { | |
2395 | if (strcmp(var.value, "enabled") == 0) | |
2396 | gpu_peops_fix |= GPU_PEOPS_LAZY_SCREEN_UPDATE; | |
2397 | } | |
2398 | ||
2399 | var.value = NULL; | |
2400 | var.key = "pcsx_rearmed_gpu_peops_repeated_triangles"; | |
2401 | ||
2402 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2403 | { | |
2404 | if (strcmp(var.value, "enabled") == 0) | |
2405 | gpu_peops_fix |= GPU_PEOPS_REPEATED_TRIANGLES; | |
2406 | } | |
2407 | ||
2408 | var.value = NULL; | |
2409 | var.key = "pcsx_rearmed_gpu_peops_quads_with_triangles"; | |
2410 | ||
2411 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2412 | { | |
2413 | if (strcmp(var.value, "enabled") == 0) | |
2414 | gpu_peops_fix |= GPU_PEOPS_QUADS_WITH_TRIANGLES; | |
2415 | } | |
2416 | ||
2417 | var.value = NULL; | |
2418 | var.key = "pcsx_rearmed_gpu_peops_fake_busy_state"; | |
2419 | ||
2420 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2421 | { | |
2422 | if (strcmp(var.value, "enabled") == 0) | |
2423 | gpu_peops_fix |= GPU_PEOPS_FAKE_BUSY_STATE; | |
2424 | } | |
2425 | ||
2426 | if (pl_rearmed_cbs.gpu_peops.dwActFixes != gpu_peops_fix) | |
2427 | pl_rearmed_cbs.gpu_peops.dwActFixes = gpu_peops_fix; | |
2428 | #endif | |
2429 | ||
2430 | #ifdef GPU_UNAI | |
2431 | /* Note: This used to be an option, but it only works | |
2432 | * (correctly) when running high resolution games | |
2433 | * (480i, 512i) and has been obsoleted by | |
2434 | * pcsx_rearmed_gpu_unai_scale_hires */ | |
2435 | pl_rearmed_cbs.gpu_unai.ilace_force = 0; | |
2436 | /* Note: This used to be an option, but it has no | |
2437 | * discernable effect and has been obsoleted by | |
2438 | * pcsx_rearmed_gpu_unai_scale_hires */ | |
2439 | pl_rearmed_cbs.gpu_unai.pixel_skip = 0; | |
2440 | ||
2441 | var.key = "pcsx_rearmed_gpu_unai_lighting"; | |
2442 | var.value = NULL; | |
2443 | ||
2444 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2445 | { | |
2446 | if (strcmp(var.value, "disabled") == 0) | |
2447 | pl_rearmed_cbs.gpu_unai.lighting = 0; | |
2448 | else if (strcmp(var.value, "enabled") == 0) | |
2449 | pl_rearmed_cbs.gpu_unai.lighting = 1; | |
2450 | } | |
2451 | ||
2452 | var.key = "pcsx_rearmed_gpu_unai_fast_lighting"; | |
2453 | var.value = NULL; | |
2454 | ||
2455 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2456 | { | |
2457 | if (strcmp(var.value, "disabled") == 0) | |
2458 | pl_rearmed_cbs.gpu_unai.fast_lighting = 0; | |
2459 | else if (strcmp(var.value, "enabled") == 0) | |
2460 | pl_rearmed_cbs.gpu_unai.fast_lighting = 1; | |
2461 | } | |
2462 | ||
2463 | var.key = "pcsx_rearmed_gpu_unai_blending"; | |
2464 | var.value = NULL; | |
2465 | ||
2466 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2467 | { | |
2468 | if (strcmp(var.value, "disabled") == 0) | |
2469 | pl_rearmed_cbs.gpu_unai.blending = 0; | |
2470 | else if (strcmp(var.value, "enabled") == 0) | |
2471 | pl_rearmed_cbs.gpu_unai.blending = 1; | |
2472 | } | |
2473 | ||
2474 | var.key = "pcsx_rearmed_gpu_unai_scale_hires"; | |
2475 | var.value = NULL; | |
2476 | ||
2477 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2478 | { | |
2479 | if (strcmp(var.value, "disabled") == 0) | |
2480 | pl_rearmed_cbs.gpu_unai.scale_hires = 0; | |
2481 | else if (strcmp(var.value, "enabled") == 0) | |
2482 | pl_rearmed_cbs.gpu_unai.scale_hires = 1; | |
2483 | } | |
2484 | #endif // GPU_UNAI | |
2485 | ||
d6a231b7 S |
2486 | var.value = NULL; |
2487 | var.key = "pcsx_rearmed_crosshair1"; | |
2488 | ||
2489 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2490 | { | |
2491 | if (strcmp(var.value, "disabled") == 0) | |
2492 | in_enable_crosshair[0] = 0; | |
2493 | else if (strcmp(var.value, "blue") == 0) | |
2494 | in_enable_crosshair[0] = 0x1F; | |
2495 | else if (strcmp(var.value, "green") == 0) | |
2496 | in_enable_crosshair[0] = 0x7E0; | |
2497 | else if (strcmp(var.value, "red") == 0) | |
2498 | in_enable_crosshair[0] = 0xF800; | |
2499 | else if (strcmp(var.value, "white") == 0) | |
2500 | in_enable_crosshair[0] = 0xFFFF; | |
2501 | } | |
2502 | ||
2503 | var.value = NULL; | |
2504 | var.key = "pcsx_rearmed_crosshair2"; | |
2505 | ||
2506 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2507 | { | |
2508 | if (strcmp(var.value, "disabled") == 0) | |
2509 | in_enable_crosshair[1] = 0; | |
2510 | else if (strcmp(var.value, "blue") == 0) | |
2511 | in_enable_crosshair[1] = 0x1F; | |
2512 | else if (strcmp(var.value, "green") == 0) | |
2513 | in_enable_crosshair[1] = 0x7E0; | |
2514 | else if (strcmp(var.value, "red") == 0) | |
2515 | in_enable_crosshair[1] = 0xF800; | |
2516 | else if (strcmp(var.value, "white") == 0) | |
2517 | in_enable_crosshair[1] = 0xFFFF; | |
2518 | } | |
2519 | ||
7a8d521f | 2520 | //This adjustment process gives the user the ability to manually align the mouse up better |
2521 | //with where the shots are in the emulator. | |
2522 | ||
d6a231b7 S |
2523 | var.value = NULL; |
2524 | var.key = "pcsx_rearmed_konamigunadjustx"; | |
2525 | ||
2526 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2527 | { | |
2528 | KonamiGunAdjustX = atof(var.value) / 100.0f; | |
2529 | } | |
2530 | ||
2531 | var.value = NULL; | |
2532 | var.key = "pcsx_rearmed_konamigunadjusty"; | |
2533 | ||
2534 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2535 | { | |
2536 | KonamiGunAdjustY = atof(var.value) / 100.0f; | |
2537 | } | |
2538 | ||
7a8d521f | 2539 | var.value = NULL; |
2540 | var.key = "pcsx_rearmed_gunconadjustx"; | |
2541 | ||
2542 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2543 | { | |
2544 | GunconAdjustX = atoi(var.value); | |
2545 | } | |
2546 | ||
2547 | var.value = NULL; | |
2548 | var.key = "pcsx_rearmed_gunconadjusty"; | |
2549 | ||
2550 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2551 | { | |
2552 | GunconAdjustY = atoi(var.value); | |
2553 | } | |
2554 | ||
2555 | var.value = NULL; | |
2556 | var.key = "pcsx_rearmed_gunconadjustratiox"; | |
2557 | ||
2558 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2559 | { | |
2560 | GunconAdjustRatioX = atof(var.value); | |
2561 | } | |
2562 | ||
2563 | var.value = NULL; | |
2564 | var.key = "pcsx_rearmed_gunconadjustratioy"; | |
2565 | ||
2566 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2567 | { | |
2568 | GunconAdjustRatioY = atof(var.value); | |
2569 | } | |
2570 | ||
2571 | var.value = NULL; | |
2572 | var.key = "pcsx_rearmed_input_sensitivity"; | |
2573 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2574 | { | |
2575 | mouse_sensitivity = atof(var.value); | |
2576 | } | |
2577 | ||
606bece1 | 2578 | if (found_bios) |
2579 | { | |
2580 | var.value = NULL; | |
2581 | var.key = "pcsx_rearmed_show_bios_bootlogo"; | |
2582 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
2583 | { | |
2584 | Config.SlowBoot = 0; | |
2585 | if (strcmp(var.value, "enabled") == 0) | |
2586 | Config.SlowBoot = 1; | |
2587 | } | |
2588 | } | |
2589 | ||
7a8d521f | 2590 | if (in_flight) |
2591 | { | |
32ab9e53 TJ |
2592 | // inform core things about possible config changes |
2593 | plugin_call_rearmed_cbs(); | |
805fe9bc | 2594 | |
7a8d521f | 2595 | if (GPU_open != NULL && GPU_close != NULL) |
2596 | { | |
32ab9e53 TJ |
2597 | GPU_close(); |
2598 | GPU_open(&gpuDisp, "PCSX", NULL); | |
2599 | } | |
805fe9bc | 2600 | |
7a8d521f | 2601 | /* Reinitialise frameskipping, if required */ |
2602 | if (((frameskip_type != prev_frameskip_type))) | |
2603 | retro_set_audio_buff_status_cb(); | |
2604 | ||
2605 | /* dfinput_activate(); */ | |
32ab9e53 | 2606 | } |
7a8d521f | 2607 | |
2608 | update_option_visibility(); | |
e268a47e | 2609 | } |
2610 | ||
7a8d521f | 2611 | // Taken from beetle-psx-libretro |
2612 | static uint16_t get_analog_button(int16_t ret, retro_input_state_t input_state_cb, int player_index, int id) | |
38c2028e | 2613 | { |
7a8d521f | 2614 | // NOTE: Analog buttons were added Nov 2017. Not all front-ends support this |
2615 | // feature (or pre-date it) so we need to handle this in a graceful way. | |
2616 | ||
2617 | // First, try and get an analog value using the new libretro API constant | |
2618 | uint16_t button = input_state_cb(player_index, | |
2619 | RETRO_DEVICE_ANALOG, | |
2620 | RETRO_DEVICE_INDEX_ANALOG_BUTTON, | |
2621 | id); | |
2622 | button = MIN(button / 128, 255); | |
38c2028e | 2623 | |
7a8d521f | 2624 | if (button == 0) |
2625 | { | |
2626 | // If we got exactly zero, we're either not pressing the button, or the front-end | |
2627 | // is not reporting analog values. We need to do a second check using the classic | |
2628 | // digital API method, to at least get some response - better than nothing. | |
e268a47e | 2629 | |
7a8d521f | 2630 | // NOTE: If we're really just not holding the button, we're still going to get zero. |
e268a47e | 2631 | |
7a8d521f | 2632 | button = (ret & (1 << id)) ? 255 : 0; |
2633 | } | |
38c2028e | 2634 | |
7a8d521f | 2635 | return button; |
2636 | } | |
4615b075 | 2637 | |
7a8d521f | 2638 | unsigned char axis_range_modifier(int16_t axis_value, bool is_square) |
2639 | { | |
2640 | float modifier_axis_range = 0; | |
2641 | ||
2642 | if (is_square) | |
2643 | { | |
2644 | modifier_axis_range = round((axis_value >> 8) / 0.785) + 128; | |
2645 | if (modifier_axis_range < 0) | |
2646 | { | |
2647 | modifier_axis_range = 0; | |
2648 | } | |
2649 | else if (modifier_axis_range > 255) | |
2650 | { | |
2651 | modifier_axis_range = 255; | |
2652 | } | |
2653 | } | |
2654 | else | |
2655 | { | |
2656 | modifier_axis_range = MIN(((axis_value >> 8) + 128), 255); | |
2657 | } | |
38c2028e | 2658 | |
7a8d521f | 2659 | return modifier_axis_range; |
38c2028e | 2660 | } |
2661 | ||
7a8d521f | 2662 | static void update_input_guncon(int port, int ret) |
74ebc05b | 2663 | { |
7a8d521f | 2664 | //ToDo: |
7a8d521f | 2665 | //Separate pointer and lightgun control types |
2666 | ||
2667 | //Mouse range is -32767 -> 32767 | |
2668 | //1% is about 655 | |
2669 | //Use the left analog stick field to store the absolute coordinates | |
2db412ad | 2670 | |
2671 | int gunx = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X); | |
2672 | int guny = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y); | |
2673 | ||
2674 | //Have the Libretro API let /libpcsxcore/plugins.c know when the lightgun is pointed offscreen | |
2675 | //Offscreen value is chosen to be well out of range of any possible scaling done via core options | |
7a8d521f | 2676 | 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)) |
2677 | { | |
f6eb0b1c | 2678 | in_analog_left[port][0] = 65536; |
2679 | in_analog_left[port][1] = 65536; | |
7a8d521f | 2680 | } |
2681 | else | |
2682 | { | |
f6eb0b1c | 2683 | in_analog_left[port][0] = ((gunx * GunconAdjustRatioX) + (GunconAdjustX * 655)) / 64 + 512; |
2684 | in_analog_left[port][1] = ((guny * GunconAdjustRatioY) + (GunconAdjustY * 655)) / 64 + 512; | |
7a8d521f | 2685 | } |
2686 | ||
2687 | //GUNCON has 3 controls, Trigger,A,B which equal Circle,Start,Cross | |
74ebc05b | 2688 | |
7a8d521f | 2689 | // Trigger |
2690 | 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)) | |
2691 | in_keystate[port] |= (1 << DKEY_CIRCLE); | |
74ebc05b | 2692 | |
7a8d521f | 2693 | // A |
2694 | if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_A)) | |
2695 | in_keystate[port] |= (1 << DKEY_START); | |
74ebc05b | 2696 | |
7a8d521f | 2697 | // B |
2698 | if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_B)) | |
2699 | in_keystate[port] |= (1 << DKEY_CROSS); | |
2700 | ||
2701 | } | |
74ebc05b | 2702 | |
d6a231b7 S |
2703 | static void update_input_justifier(int port, int ret) |
2704 | { | |
2705 | //ToDo: | |
2706 | //Separate pointer and lightgun control types | |
2707 | ||
2708 | //RetroArch lightgun range is -32767 -> 32767 on both axes (positive Y is down) | |
2709 | ||
2710 | //JUSTIFIER has 3 controls, Trigger,Special,Start which equal Square,Cross,Start | |
2711 | ||
2712 | // Trigger | |
2713 | 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)) | |
2714 | in_keystate[port] |= (1 << DKEY_SQUARE); | |
2715 | ||
2716 | // Special | |
2717 | if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_A)) | |
2718 | in_keystate[port] |= (1 << DKEY_CROSS); | |
2719 | ||
2720 | // Start | |
2721 | if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_START)) | |
2722 | in_keystate[port] |= (1 << DKEY_START); | |
2723 | ||
2724 | } | |
2725 | ||
7a8d521f | 2726 | static void update_input_negcon(int port, int ret) |
2727 | { | |
2728 | int lsx; | |
2729 | int rsy; | |
2730 | int negcon_i_rs; | |
2731 | int negcon_ii_rs; | |
2732 | float negcon_twist_amplitude; | |
2733 | ||
2734 | // Query digital inputs | |
2735 | // | |
2736 | // > Pad-Up | |
2737 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_UP)) | |
2738 | in_keystate[port] |= (1 << DKEY_UP); | |
2739 | // > Pad-Right | |
2740 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT)) | |
2741 | in_keystate[port] |= (1 << DKEY_RIGHT); | |
2742 | // > Pad-Down | |
2743 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN)) | |
2744 | in_keystate[port] |= (1 << DKEY_DOWN); | |
2745 | // > Pad-Left | |
2746 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) | |
2747 | in_keystate[port] |= (1 << DKEY_LEFT); | |
2748 | // > Start | |
2749 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_START)) | |
2750 | in_keystate[port] |= (1 << DKEY_START); | |
2751 | // > neGcon A | |
2752 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_A)) | |
2753 | in_keystate[port] |= (1 << DKEY_CIRCLE); | |
2754 | // > neGcon B | |
2755 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_X)) | |
2756 | in_keystate[port] |= (1 << DKEY_TRIANGLE); | |
2757 | // > neGcon R shoulder (digital) | |
2758 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_R)) | |
2759 | in_keystate[port] |= (1 << DKEY_R1); | |
2760 | // Query analog inputs | |
2761 | // | |
2762 | // From studying 'libpcsxcore/plugins.c' and 'frontend/plugin.c': | |
2763 | // >> pad->leftJoyX == in_analog_left[port][0] == NeGcon II | |
2764 | // >> pad->leftJoyY == in_analog_left[port][1] == NeGcon L | |
2765 | // >> pad->rightJoyX == in_analog_right[port][0] == NeGcon twist | |
2766 | // >> pad->rightJoyY == in_analog_right[port][1] == NeGcon I | |
2767 | // So we just have to map in_analog_left/right to more | |
2768 | // appropriate inputs... | |
2769 | // | |
2770 | // > NeGcon twist | |
2771 | // >> Get raw analog stick value and account for deadzone | |
2772 | lsx = input_state_cb(port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X); | |
2773 | if (lsx > negcon_deadzone) | |
2774 | lsx = lsx - negcon_deadzone; | |
2775 | else if (lsx < -negcon_deadzone) | |
2776 | lsx = lsx + negcon_deadzone; | |
2777 | else | |
2778 | lsx = 0; | |
2779 | // >> Convert to an 'amplitude' [-1.0,1.0] and adjust response | |
2780 | negcon_twist_amplitude = (float)lsx / (float)(NEGCON_RANGE - negcon_deadzone); | |
2781 | if (negcon_linearity == 2) | |
2782 | { | |
2783 | if (negcon_twist_amplitude < 0.0) | |
2784 | negcon_twist_amplitude = -(negcon_twist_amplitude * negcon_twist_amplitude); | |
2785 | else | |
2786 | negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude; | |
2787 | } | |
2788 | else if (negcon_linearity == 3) | |
2789 | negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude * negcon_twist_amplitude; | |
2790 | // >> Convert to final 'in_analog' integer value [0,255] | |
2791 | in_analog_right[port][0] = MAX(MIN((int)(negcon_twist_amplitude * 128.0f) + 128, 255), 0); | |
2792 | // > NeGcon I + II | |
2793 | // >> Handle right analog stick vertical axis mapping... | |
2794 | // - Up (-Y) == accelerate == neGcon I | |
2795 | // - Down (+Y) == brake == neGcon II | |
2796 | negcon_i_rs = 0; | |
2797 | negcon_ii_rs = 0; | |
2798 | rsy = input_state_cb(port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y); | |
2799 | if (rsy >= 0) | |
2800 | { | |
2801 | // Account for deadzone | |
2802 | // (Note: have never encountered a gamepad with significant differences | |
2803 | // in deadzone between left/right analog sticks, so use the regular 'twist' | |
2804 | // deadzone here) | |
2805 | if (rsy > negcon_deadzone) | |
2806 | rsy = rsy - negcon_deadzone; | |
2807 | else | |
2808 | rsy = 0; | |
2809 | // Convert to 'in_analog' integer value [0,255] | |
2810 | negcon_ii_rs = MIN((int)(((float)rsy / (float)(NEGCON_RANGE - negcon_deadzone)) * 255.0f), 255); | |
2811 | } | |
2812 | else | |
2813 | { | |
2814 | if (rsy < -negcon_deadzone) | |
2815 | rsy = -1 * (rsy + negcon_deadzone); | |
2816 | else | |
2817 | rsy = 0; | |
2818 | negcon_i_rs = MIN((int)(((float)rsy / (float)(NEGCON_RANGE - negcon_deadzone)) * 255.0f), 255); | |
2819 | } | |
2820 | // >> NeGcon I | |
2821 | in_analog_right[port][1] = MAX( | |
2822 | MAX( | |
2823 | get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_R2), | |
2824 | get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_B)), | |
2825 | negcon_i_rs); | |
2826 | // >> NeGcon II | |
2827 | in_analog_left[port][0] = MAX( | |
2828 | MAX( | |
2829 | get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_L2), | |
2830 | get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_Y)), | |
2831 | negcon_ii_rs); | |
2832 | // > NeGcon L | |
2833 | in_analog_left[port][1] = get_analog_button(ret, input_state_cb, port, RETRO_DEVICE_ID_JOYPAD_L); | |
2834 | } | |
2835 | ||
2836 | static void update_input_mouse(int port, int ret) | |
2837 | { | |
2838 | float raw_x = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X); | |
2839 | float raw_y = input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y); | |
2840 | ||
2841 | int x = (int)roundf(raw_x * mouse_sensitivity); | |
2842 | int y = (int)roundf(raw_y * mouse_sensitivity); | |
2843 | ||
2844 | if (x > 127) x = 127; | |
2845 | else if (x < -128) x = -128; | |
2846 | ||
2847 | if (y > 127) y = 127; | |
2848 | else if (y < -128) y = -128; | |
2849 | ||
2850 | in_mouse[port][0] = x; /* -128..+128 left/right movement, 0 = no movement */ | |
2851 | in_mouse[port][1] = y; /* -128..+128 down/up movement, 0 = no movement */ | |
2852 | ||
2853 | /* left mouse button state */ | |
2854 | if (input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) | |
2855 | in_keystate[port] |= 1 << 11; | |
2856 | ||
2857 | /* right mouse button state */ | |
2858 | if (input_state_cb(port, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)) | |
2859 | in_keystate[port] |= 1 << 10; | |
74ebc05b | 2860 | } |
2861 | ||
7a8d521f | 2862 | static void update_input(void) |
2863 | { | |
2864 | // reset all keystate, query libretro for keystate | |
2865 | int i; | |
2866 | int j; | |
2867 | ||
2868 | for (i = 0; i < PORTS_NUMBER; i++) | |
2869 | { | |
2870 | int16_t ret = 0; | |
2871 | int type = in_type[i]; | |
2872 | ||
2873 | in_keystate[i] = 0; | |
2874 | ||
2875 | if (type == PSE_PAD_TYPE_NONE) | |
2876 | continue; | |
2877 | ||
2878 | if (libretro_supports_bitmasks) | |
2879 | ret = input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK); | |
2880 | else | |
2881 | { | |
2882 | for (j = 0; j < (RETRO_DEVICE_ID_JOYPAD_R3 + 1); j++) | |
2883 | { | |
2884 | if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j)) | |
2885 | ret |= (1 << j); | |
2886 | } | |
2887 | } | |
2888 | ||
2889 | switch (type) | |
2890 | { | |
2891 | case PSE_PAD_TYPE_GUNCON: | |
2892 | update_input_guncon(i, ret); | |
2893 | break; | |
d6a231b7 S |
2894 | case PSE_PAD_TYPE_GUN: |
2895 | update_input_justifier(i, ret); | |
2896 | break; | |
7a8d521f | 2897 | case PSE_PAD_TYPE_NEGCON: |
2898 | update_input_negcon(i, ret); | |
2899 | break; | |
2900 | case PSE_PAD_TYPE_MOUSE: | |
2901 | update_input_mouse(i, ret); | |
2902 | break; | |
2903 | default: | |
2904 | // Query digital inputs | |
2905 | for (j = 0; j < RETRO_PSX_MAP_LEN; j++) | |
2906 | if (ret & (1 << j)) | |
2907 | in_keystate[i] |= retro_psx_map[j]; | |
2908 | ||
2909 | // Query analog inputs | |
2910 | if (type == PSE_PAD_TYPE_ANALOGJOY || type == PSE_PAD_TYPE_ANALOGPAD) | |
2911 | { | |
2912 | 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); | |
2913 | 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); | |
2914 | 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); | |
2915 | 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); | |
2916 | } | |
2917 | } | |
2918 | } | |
2919 | } | |
2920 | ||
2921 | static void print_internal_fps(void) | |
2922 | { | |
2923 | if (display_internal_fps) | |
2924 | { | |
2925 | frame_count++; | |
2926 | ||
2927 | if (frame_count % INTERNAL_FPS_SAMPLE_PERIOD == 0) | |
2928 | { | |
2929 | unsigned internal_fps = pl_rearmed_cbs.flip_cnt * (is_pal_mode ? 50 : 60) / INTERNAL_FPS_SAMPLE_PERIOD; | |
2930 | char str[64]; | |
2931 | const char *strc = (const char *)str; | |
2932 | ||
2933 | str[0] = '\0'; | |
2934 | ||
2935 | snprintf(str, sizeof(str), "Internal FPS: %2d", internal_fps); | |
2936 | ||
2937 | pl_rearmed_cbs.flip_cnt = 0; | |
2938 | ||
2939 | if (msg_interface_version >= 1) | |
2940 | { | |
2941 | struct retro_message_ext msg = { | |
2942 | strc, | |
2943 | 3000, | |
2944 | 1, | |
2945 | RETRO_LOG_INFO, | |
2946 | RETRO_MESSAGE_TARGET_OSD, | |
2947 | RETRO_MESSAGE_TYPE_STATUS, | |
2948 | -1 | |
2949 | }; | |
2950 | environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg); | |
2951 | } | |
2952 | else | |
2953 | { | |
2954 | struct retro_message msg = { | |
2955 | strc, | |
2956 | 180 | |
2957 | }; | |
2958 | environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); | |
2959 | } | |
2960 | } | |
2961 | } | |
2962 | else | |
2963 | frame_count = 0; | |
2964 | } | |
2965 | ||
2966 | void retro_run(void) | |
2967 | { | |
2968 | //SysReset must be run while core is running,Not in menu (Locks up Retroarch) | |
2969 | if (rebootemu != 0) | |
2970 | { | |
2971 | rebootemu = 0; | |
2972 | SysReset(); | |
d512faf7 | 2973 | if (Config.HLE) |
2974 | LoadCdrom(); | |
7a8d521f | 2975 | } |
2976 | ||
5d9e675a | 2977 | set_vout_fb(); |
7a8d521f | 2978 | print_internal_fps(); |
2979 | ||
2980 | /* Check whether current frame should | |
2981 | * be skipped */ | |
2982 | pl_rearmed_cbs.fskip_force = 0; | |
2983 | pl_rearmed_cbs.fskip_dirty = 0; | |
2984 | ||
2985 | if (frameskip_type != FRAMESKIP_NONE) | |
2986 | { | |
2987 | bool skip_frame = false; | |
2988 | ||
2989 | switch (frameskip_type) | |
2990 | { | |
2991 | case FRAMESKIP_AUTO: | |
2992 | skip_frame = retro_audio_buff_active && retro_audio_buff_underrun; | |
2993 | break; | |
2994 | case FRAMESKIP_AUTO_THRESHOLD: | |
2995 | skip_frame = retro_audio_buff_active && (retro_audio_buff_occupancy < frameskip_threshold); | |
2996 | break; | |
2997 | case FRAMESKIP_FIXED_INTERVAL: | |
2998 | skip_frame = true; | |
2999 | break; | |
3000 | default: | |
3001 | break; | |
3002 | } | |
3003 | ||
3004 | if (skip_frame && frameskip_counter < frameskip_interval) | |
3005 | pl_rearmed_cbs.fskip_force = 1; | |
3006 | } | |
3007 | ||
3008 | /* If frameskip/timing settings have changed, | |
3009 | * update frontend audio latency | |
3010 | * > Can do this before or after the frameskip | |
3011 | * check, but doing it after means we at least | |
3012 | * retain the current frame's audio output */ | |
3013 | if (update_audio_latency) | |
3014 | { | |
3015 | environ_cb(RETRO_ENVIRONMENT_SET_MINIMUM_AUDIO_LATENCY, | |
3016 | &retro_audio_latency); | |
3017 | update_audio_latency = false; | |
3018 | } | |
3019 | ||
3020 | input_poll_cb(); | |
3021 | ||
3022 | update_input(); | |
3023 | ||
3024 | bool updated = false; | |
3025 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) | |
3026 | update_variables(true); | |
3027 | ||
3028 | stop = 0; | |
3029 | psxCpu->Execute(); | |
3030 | ||
3031 | if (pl_rearmed_cbs.fskip_dirty == 1) { | |
3032 | if (frameskip_counter < frameskip_interval) | |
3033 | frameskip_counter++; | |
3034 | else if (frameskip_counter >= frameskip_interval || !pl_rearmed_cbs.fskip_force) | |
3035 | frameskip_counter = 0; | |
3036 | } | |
3037 | ||
3038 | video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf_ptr : NULL, | |
5d9e675a | 3039 | vout_width, vout_height, vout_pitch * 2); |
7a8d521f | 3040 | vout_fb_dirty = 0; |
7a8d521f | 3041 | } |
3042 | ||
4a1d78d4 | 3043 | static bool try_use_bios(const char *path, bool preferred_only) |
7a8d521f | 3044 | { |
3045 | long size; | |
3046 | const char *name; | |
3047 | FILE *fp = fopen(path, "rb"); | |
3048 | if (fp == NULL) | |
3049 | return false; | |
3050 | ||
3051 | fseek(fp, 0, SEEK_END); | |
3052 | size = ftell(fp); | |
3053 | fclose(fp); | |
3054 | ||
7a8d521f | 3055 | name = strrchr(path, SLASH); |
3056 | if (name++ == NULL) | |
3057 | name = path; | |
4a1d78d4 | 3058 | |
3059 | if (preferred_only && size != 512 * 1024) | |
3060 | return false; | |
3061 | if (size != 512 * 1024 && size != 4 * 1024 * 1024) | |
3062 | return false; | |
3063 | if (strstr(name, "unirom")) | |
3064 | return false; | |
3065 | // jp bios have an addidional region check | |
3066 | if (preferred_only && (strcasestr(name, "00.") || strcasestr(name, "j.bin"))) | |
3067 | return false; | |
3068 | ||
7a8d521f | 3069 | snprintf(Config.Bios, sizeof(Config.Bios), "%s", name); |
3070 | return true; | |
3071 | } | |
3072 | ||
3073 | #ifndef VITA | |
74ebc05b | 3074 | #include <sys/types.h> |
3075 | #include <dirent.h> | |
3076 | ||
3077 | static bool find_any_bios(const char *dirpath, char *path, size_t path_size) | |
3078 | { | |
4a1d78d4 | 3079 | static const char *substr_pref[] = { "scph", "ps" }; |
3080 | static const char *substr_alt[] = { "scph", "ps", "openbios" }; | |
7a8d521f | 3081 | DIR *dir; |
3082 | struct dirent *ent; | |
3083 | bool ret = false; | |
378428ac | 3084 | size_t i; |
74ebc05b | 3085 | |
7a8d521f | 3086 | dir = opendir(dirpath); |
3087 | if (dir == NULL) | |
3088 | return false; | |
74ebc05b | 3089 | |
4a1d78d4 | 3090 | // try to find a "better" bios |
3091 | while ((ent = readdir(dir))) | |
7a8d521f | 3092 | { |
4a1d78d4 | 3093 | for (i = 0; i < sizeof(substr_pref) / sizeof(substr_pref[0]); i++) |
378428ac | 3094 | { |
4a1d78d4 | 3095 | const char *substr = substr_pref[i]; |
3096 | if ((strncasecmp(ent->d_name, substr, strlen(substr)) != 0)) | |
378428ac | 3097 | continue; |
4a1d78d4 | 3098 | snprintf(path, path_size, "%s%c%s", dirpath, SLASH, ent->d_name); |
3099 | ret = try_use_bios(path, true); | |
3100 | if (ret) | |
3101 | goto finish; | |
3102 | } | |
3103 | } | |
378428ac | 3104 | |
4a1d78d4 | 3105 | // another pass to look for anything fitting, even ps2 bios |
3106 | rewinddir(dir); | |
3107 | while ((ent = readdir(dir))) | |
3108 | { | |
3109 | for (i = 0; i < sizeof(substr_alt) / sizeof(substr_alt[0]); i++) | |
3110 | { | |
3111 | const char *substr = substr_alt[i]; | |
3112 | if ((strncasecmp(ent->d_name, substr, strlen(substr)) != 0)) | |
3113 | continue; | |
378428ac | 3114 | snprintf(path, path_size, "%s%c%s", dirpath, SLASH, ent->d_name); |
4a1d78d4 | 3115 | ret = try_use_bios(path, false); |
378428ac | 3116 | if (ret) |
4a1d78d4 | 3117 | goto finish; |
378428ac | 3118 | } |
7a8d521f | 3119 | } |
4a1d78d4 | 3120 | |
3121 | ||
3122 | finish: | |
7a8d521f | 3123 | closedir(dir); |
3124 | return ret; | |
74ebc05b | 3125 | } |
3126 | #else | |
3127 | #define find_any_bios(...) false | |
3128 | #endif | |
3129 | ||
11813b9d | 3130 | static void check_system_specs(void) |
3131 | { | |
3132 | unsigned level = 6; | |
3133 | environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level); | |
3134 | } | |
3135 | ||
7a8d521f | 3136 | static int init_memcards(void) |
3137 | { | |
3138 | int ret = 0; | |
3139 | const char *dir; | |
3140 | struct retro_variable var = { .key = "pcsx_rearmed_memcard2", .value = NULL }; | |
3141 | static const char CARD2_FILE[] = "pcsx-card2.mcd"; | |
3142 | ||
3143 | // Memcard2 will be handled and is re-enabled if needed using core | |
3144 | // operations. | |
3145 | // Memcard1 is handled by libretro, doing this will set core to | |
3146 | // skip file io operations for memcard1 like SaveMcd | |
3147 | snprintf(Config.Mcd1, sizeof(Config.Mcd1), "none"); | |
3148 | snprintf(Config.Mcd2, sizeof(Config.Mcd2), "none"); | |
3149 | init_memcard(Mcd1Data); | |
3150 | // Memcard 2 is managed by the emulator on the filesystem, | |
3151 | // There is no need to initialize Mcd2Data like Mcd1Data. | |
3152 | ||
3153 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
3154 | { | |
3155 | SysPrintf("Memcard 2: %s\n", var.value); | |
3156 | if (memcmp(var.value, "enabled", 7) == 0) | |
3157 | { | |
3158 | if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) | |
3159 | { | |
3160 | if (strlen(dir) + strlen(CARD2_FILE) + 2 > sizeof(Config.Mcd2)) | |
3161 | { | |
3162 | SysPrintf("Path '%s' is too long. Cannot use memcard 2. Use a shorter path.\n", dir); | |
3163 | ret = -1; | |
3164 | } | |
3165 | else | |
3166 | { | |
3167 | McdDisable[1] = 0; | |
3168 | snprintf(Config.Mcd2, sizeof(Config.Mcd2), "%s/%s", dir, CARD2_FILE); | |
3169 | SysPrintf("Use memcard 2: %s\n", Config.Mcd2); | |
3170 | } | |
3171 | } | |
3172 | else | |
3173 | { | |
3174 | SysPrintf("Could not get save directory! Could not create memcard 2."); | |
3175 | ret = -1; | |
3176 | } | |
3177 | } | |
3178 | } | |
3179 | return ret; | |
3180 | } | |
3181 | ||
3182 | static void loadPSXBios(void) | |
3183 | { | |
3184 | const char *dir; | |
3185 | char path[PATH_MAX]; | |
3186 | unsigned useHLE = 0; | |
3187 | ||
3188 | const char *bios[] = { | |
3189 | "PSXONPSP660", "psxonpsp660", | |
3190 | "SCPH101", "scph101", | |
3191 | "SCPH5501", "scph5501", | |
3192 | "SCPH7001", "scph7001", | |
3193 | "SCPH1001", "scph1001" | |
3194 | }; | |
3195 | ||
3196 | struct retro_variable var = { | |
3197 | .key = "pcsx_rearmed_bios", | |
3198 | .value = NULL | |
3199 | }; | |
3200 | ||
3201 | found_bios = 0; | |
3202 | ||
3203 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
3204 | { | |
3205 | if (!strcmp(var.value, "HLE")) | |
3206 | useHLE = 1; | |
3207 | } | |
3208 | ||
3209 | if (!useHLE) | |
3210 | { | |
3211 | if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) | |
3212 | { | |
3213 | unsigned i; | |
3214 | snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir); | |
3215 | ||
3216 | for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) | |
3217 | { | |
3218 | snprintf(path, sizeof(path), "%s%c%s.bin", dir, SLASH, bios[i]); | |
4a1d78d4 | 3219 | found_bios = try_use_bios(path, true); |
7a8d521f | 3220 | if (found_bios) |
3221 | break; | |
3222 | } | |
3223 | ||
3224 | if (!found_bios) | |
3225 | found_bios = find_any_bios(dir, path, sizeof(path)); | |
3226 | } | |
3227 | if (found_bios) | |
3228 | { | |
3229 | SysPrintf("found BIOS file: %s\n", Config.Bios); | |
3230 | } | |
3231 | } | |
3232 | ||
3233 | if (!found_bios) | |
3234 | { | |
3235 | const char *msg_str; | |
f3746eea | 3236 | unsigned duration; |
7a8d521f | 3237 | if (useHLE) |
3238 | { | |
f3746eea | 3239 | msg_str = "BIOS set to \'hle\'"; |
7a8d521f | 3240 | SysPrintf("Using HLE BIOS.\n"); |
f3746eea | 3241 | // shorter as the user probably intentionally wants to use HLE |
3242 | duration = 700; | |
7a8d521f | 3243 | } |
3244 | else | |
3245 | { | |
3246 | msg_str = "No PlayStation BIOS file found - add for better compatibility"; | |
3247 | SysPrintf("No BIOS files found.\n"); | |
f3746eea | 3248 | duration = 3000; |
7a8d521f | 3249 | } |
f3746eea | 3250 | show_notification(msg_str, duration, 2); |
7a8d521f | 3251 | } |
3252 | } | |
3253 | ||
38c2028e | 3254 | void retro_init(void) |
3255 | { | |
7a8d521f | 3256 | unsigned dci_version = 0; |
3257 | struct retro_rumble_interface rumble; | |
3258 | int ret; | |
38c2028e | 3259 | |
7a8d521f | 3260 | msg_interface_version = 0; |
3261 | environ_cb(RETRO_ENVIRONMENT_GET_MESSAGE_INTERFACE_VERSION, &msg_interface_version); | |
3262 | ||
3263 | #if defined(__MACH__) && !defined(TVOS) | |
3264 | // magic sauce to make the dynarec work on iOS | |
3265 | syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0); | |
d148d265 | 3266 | #endif |
3267 | ||
7a8d521f | 3268 | #ifdef _3DS |
3269 | psxMapHook = pl_3ds_mmap; | |
3270 | psxUnmapHook = pl_3ds_munmap; | |
3271 | #endif | |
3272 | #ifdef VITA | |
3273 | if (init_vita_mmap() < 0) | |
3274 | abort(); | |
3275 | psxMapHook = pl_vita_mmap; | |
3276 | psxUnmapHook = pl_vita_munmap; | |
3277 | #endif | |
3278 | ret = emu_core_preinit(); | |
3279 | #ifdef _3DS | |
3280 | /* emu_core_preinit sets the cpu to dynarec */ | |
3281 | if (!__ctr_svchax) | |
3282 | Config.Cpu = CPU_INTERPRETER; | |
3283 | #endif | |
3284 | ret |= init_memcards(); | |
38c2028e | 3285 | |
7a8d521f | 3286 | ret |= emu_core_init(); |
3287 | if (ret != 0) | |
3288 | { | |
3289 | SysPrintf("PCSX init failed.\n"); | |
3290 | exit(1); | |
3291 | } | |
3292 | ||
3293 | #ifdef _3DS | |
3294 | vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80); | |
9165d434 | 3295 | #elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && P_HAVE_POSIX_MEMALIGN |
7a8d521f | 3296 | if (posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2) != 0) |
3297 | vout_buf = (void *) 0; | |
91da8e32 | 3298 | else |
3299 | memset(vout_buf, 0, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); | |
29122437 | 3300 | #else |
91da8e32 | 3301 | vout_buf = calloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT, 2); |
29122437 | 3302 | #endif |
38c2028e | 3303 | |
7a8d521f | 3304 | vout_buf_ptr = vout_buf; |
3305 | ||
3306 | loadPSXBios(); | |
3307 | ||
3308 | environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe); | |
3309 | ||
3310 | disk_initial_index = 0; | |
3311 | disk_initial_path[0] = '\0'; | |
3312 | if (environ_cb(RETRO_ENVIRONMENT_GET_DISK_CONTROL_INTERFACE_VERSION, &dci_version) && (dci_version >= 1)) | |
3313 | environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE, &disk_control_ext); | |
3314 | else | |
3315 | environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control); | |
3316 | ||
3317 | rumble_cb = NULL; | |
3318 | if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble)) | |
3319 | rumble_cb = rumble.set_rumble_state; | |
3320 | ||
3321 | /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times) | |
3322 | * we have to do this because cache misses and some IO penalties | |
3323 | * are not emulated. Warning: changing this may break compatibility. */ | |
3324 | Config.cycle_multiplier = CYCLE_MULT_DEFAULT; | |
3325 | #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) | |
3326 | Config.cycle_multiplier = 200; | |
5ca2ec64 | 3327 | #endif |
7a8d521f | 3328 | pl_rearmed_cbs.gpu_peops.iUseDither = 1; |
3329 | pl_rearmed_cbs.gpu_peops.dwActFixes = GPU_PEOPS_OLD_FRAME_SKIP; | |
5ca2ec64 | 3330 | |
7a8d521f | 3331 | SaveFuncs.open = save_open; |
3332 | SaveFuncs.read = save_read; | |
3333 | SaveFuncs.write = save_write; | |
3334 | SaveFuncs.seek = save_seek; | |
3335 | SaveFuncs.close = save_close; | |
6e921e1d | 3336 | |
7a8d521f | 3337 | if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL)) |
3338 | libretro_supports_bitmasks = true; | |
e268a47e | 3339 | |
7a8d521f | 3340 | check_system_specs(); |
38c2028e | 3341 | } |
3342 | ||
3343 | void retro_deinit(void) | |
3344 | { | |
7a8d521f | 3345 | if (plugins_opened) |
3346 | { | |
3347 | ClosePlugins(); | |
3348 | plugins_opened = 0; | |
3349 | } | |
3350 | SysClose(); | |
3351 | #ifdef _3DS | |
3352 | linearFree(vout_buf); | |
3353 | #else | |
3354 | free(vout_buf); | |
3355 | #endif | |
3356 | vout_buf = NULL; | |
3357 | ||
3358 | #ifdef VITA | |
3359 | deinit_vita_mmap(); | |
3360 | #endif | |
3361 | libretro_supports_bitmasks = false; | |
3362 | libretro_supports_option_categories = false; | |
3363 | ||
3364 | show_input_settings = true; | |
3365 | #ifdef GPU_PEOPS | |
3366 | show_advanced_gpu_peops_settings = true; | |
3367 | #endif | |
3368 | #ifdef GPU_UNAI | |
3369 | show_advanced_gpu_unai_settings = true; | |
3370 | #endif | |
3371 | ||
3372 | /* Have to reset disks struct, otherwise | |
3373 | * fnames/flabels will leak memory */ | |
3374 | disk_init(); | |
3375 | frameskip_type = FRAMESKIP_NONE; | |
3376 | frameskip_threshold = 0; | |
3377 | frameskip_interval = 0; | |
3378 | frameskip_counter = 0; | |
3379 | retro_audio_buff_active = false; | |
3380 | retro_audio_buff_occupancy = 0; | |
3381 | retro_audio_buff_underrun = false; | |
3382 | retro_audio_latency = 0; | |
3383 | update_audio_latency = false; | |
3384 | } | |
3385 | ||
3386 | #ifdef VITA | |
3387 | #include <psp2/kernel/threadmgr.h> | |
3388 | int usleep(unsigned long us) | |
3389 | { | |
3390 | sceKernelDelayThread(us); | |
3391 | } | |
3392 | #endif | |
3393 | ||
3394 | void SysPrintf(const char *fmt, ...) | |
3395 | { | |
3396 | va_list list; | |
3397 | char msg[512]; | |
3398 | ||
3399 | va_start(list, fmt); | |
3400 | vsprintf(msg, fmt, list); | |
3401 | va_end(list); | |
3402 | ||
3403 | if (log_cb) | |
3404 | log_cb(RETRO_LOG_INFO, "%s", msg); | |
3405 | } | |
3406 | ||
3407 | /* Prints debug-level logs */ | |
3408 | void SysDLog(const char *fmt, ...) | |
3409 | { | |
3410 | va_list list; | |
3411 | char msg[512]; | |
3412 | ||
3413 | va_start(list, fmt); | |
3414 | vsprintf(msg, fmt, list); | |
3415 | va_end(list); | |
3416 | ||
3417 | if (log_cb) | |
3418 | log_cb(RETRO_LOG_DEBUG, "%s", msg); | |
38c2028e | 3419 | } |
378428ac | 3420 | |
3421 | // vim:sw=3:ts=3:expandtab |