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