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