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