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 | |
18 | #include "../libpcsxcore/misc.h" | |
19 | #include "../libpcsxcore/psxcounters.h" | |
87e5b45f | 20 | #include "../libpcsxcore/psxmem_map.h" |
38c2028e | 21 | #include "../libpcsxcore/new_dynarec/new_dynarec.h" |
23ea11bd | 22 | #include "../libpcsxcore/cdrom.h" |
23 | #include "../libpcsxcore/cdriso.h" | |
6e921e1d | 24 | #include "../libpcsxcore/cheat.h" |
f422f444 | 25 | #include "../libpcsxcore/r3000a.h" |
07c13dfd | 26 | #include "../plugins/dfsound/out.h" |
01394a7f | 27 | #include "../plugins/dfsound/spu_config.h" |
805fe9bc | 28 | #include "../plugins/dfinput/externals.h" |
c82f907a | 29 | #include "cspace.h" |
38c2028e | 30 | #include "main.h" |
b12cce74 | 31 | #include "menu.h" |
38c2028e | 32 | #include "plugin.h" |
33 | #include "plugin_lib.h" | |
ace14ab3 | 34 | #include "arm_features.h" |
38c2028e | 35 | #include "revision.h" |
919cac88 | 36 | |
37 | #include <libretro.h> | |
38 | #include "libretro_core_options.h" | |
38c2028e | 39 | |
fc99395c | 40 | #ifdef _3DS |
fc99395c | 41 | #include "3ds/3ds_utils.h" |
fc99395c | 42 | #endif |
43 | ||
8136cafb AP |
44 | #define PORTS_NUMBER 8 |
45 | ||
a9bb0712 | 46 | #ifndef MIN |
47 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
48 | #endif | |
49 | ||
8741f7a2 | 50 | #ifndef MAX |
51 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
52 | #endif | |
53 | ||
47624ecf | 54 | #define ISHEXDEC ((buf[cursor]>='0') && (buf[cursor]<='9')) || ((buf[cursor]>='a') && (buf[cursor]<='f')) || ((buf[cursor]>='A') && (buf[cursor]<='F')) |
55 | ||
2df7fcac BP |
56 | #define INTERNAL_FPS_SAMPLE_PERIOD 64 |
57 | ||
726da67c | 58 | //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key |
76996fc3 | 59 | static int rebootemu = 0; |
726da67c | 60 | |
38c2028e | 61 | static retro_video_refresh_t video_cb; |
62 | static retro_input_poll_t input_poll_cb; | |
63 | static retro_input_state_t input_state_cb; | |
64 | static retro_environment_t environ_cb; | |
65 | static retro_audio_sample_batch_t audio_batch_cb; | |
79f29e0a | 66 | static retro_set_rumble_state_t rumble_cb; |
b2aef321 | 67 | static struct retro_log_callback logging; |
68 | static retro_log_printf_t log_cb; | |
38c2028e | 69 | |
70 | static void *vout_buf; | |
65a0505f | 71 | static void * vout_buf_ptr; |
70d56ca3 | 72 | static int vout_width, vout_height; |
73 | static int vout_doffs_old, vout_fb_dirty; | |
1a6164a1 | 74 | static bool vout_can_dupe; |
0e5a7b7d | 75 | static bool duping_enable; |
b580cc4f | 76 | static bool found_bios; |
2df7fcac BP |
77 | static bool display_internal_fps = false; |
78 | static unsigned frame_count = 0; | |
6fbd15c8 | 79 | static bool libretro_supports_bitmasks = false; |
c8108d88 | 80 | static int show_advanced_gpu_peops_settings = -1; |
030d1121 | 81 | static int show_advanced_gpu_unai_settings = -1; |
70d56ca3 | 82 | |
4ce3bd43 VP |
83 | static unsigned previous_width = 0; |
84 | static unsigned previous_height = 0; | |
85 | ||
38c2028e | 86 | static int plugins_opened; |
17f84149 | 87 | static int is_pal_mode; |
38c2028e | 88 | |
f9f60dae TK |
89 | /* memory card data */ |
90 | extern char Mcd1Data[MCD_SIZE]; | |
76e889bc | 91 | extern char Mcd2Data[MCD_SIZE]; |
f9f60dae | 92 | extern char McdDisable[2]; |
38c2028e | 93 | |
94 | /* PCSX ReARMed core calls and stuff */ | |
15504ca8 AP |
95 | int in_type[8] = { PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, |
96 | PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, | |
97 | PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, | |
98 | PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE }; | |
61c4962a | 99 | int in_analog_left[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }}; |
100 | int in_analog_right[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }}; | |
3c0fb554 | 101 | unsigned short in_keystate[PORTS_NUMBER]; |
29f3675b | 102 | int multitap1 = 0; |
103 | int multitap2 = 0; | |
4e477065 | 104 | int in_enable_vibration = 1; |
38c2028e | 105 | |
e1442c48 | 106 | // NegCon adjustment parameters |
107 | // > The NegCon 'twist' action is somewhat awkward when mapped | |
108 | // to a standard analog stick -> user should be able to tweak | |
109 | // response/deadzone for comfort | |
110 | // > When response is linear, 'additional' deadzone (set here) | |
111 | // may be left at zero, since this is normally handled via in-game | |
112 | // options menus | |
113 | // > When response is non-linear, deadzone should be set to match the | |
114 | // controller being used (otherwise precision may be lost) | |
115 | // > negcon_linearity: | |
116 | // - 1: Response is linear - recommended when using racing wheel | |
117 | // peripherals, not recommended for standard gamepads | |
118 | // - 2: Response is quadratic - optimal setting for gamepads | |
119 | // - 3: Response is cubic - enables precise fine control, but | |
120 | // difficult to use... | |
121 | #define NEGCON_RANGE 0x7FFF | |
122 | static int negcon_deadzone = 0; | |
123 | static int negcon_linearity = 1; | |
124 | ||
805fe9bc | 125 | /* PSX max resolution is 640x512, but with enhancement it's 1024x512 */ |
126 | #define VOUT_MAX_WIDTH 1024 | |
127 | #define VOUT_MAX_HEIGHT 512 | |
128 | ||
646a63e4 | 129 | //Dummy functions |
130 | bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info){return false;} | |
131 | void retro_unload_game(void){} | |
132 | static int vout_open(void){return 0;} | |
133 | static void vout_close(void){} | |
134 | static int snd_init(void){return 0;} | |
135 | static void snd_finish(void){} | |
136 | static int snd_busy(void){return 0;} | |
137 | ||
6713b629 | 138 | #define GPU_PEOPS_ODD_EVEN_BIT (1 << 0) |
139 | #define GPU_PEOPS_EXPAND_SCREEN_WIDTH (1 << 1) | |
140 | #define GPU_PEOPS_IGNORE_BRIGHTNESS (1 << 2) | |
141 | #define GPU_PEOPS_DISABLE_COORD_CHECK (1 << 3) | |
142 | #define GPU_PEOPS_LAZY_SCREEN_UPDATE (1 << 6) | |
143 | #define GPU_PEOPS_OLD_FRAME_SKIP (1 << 7) | |
144 | #define GPU_PEOPS_REPEATED_TRIANGLES (1 << 8) | |
145 | #define GPU_PEOPS_QUADS_WITH_TRIANGLES (1 << 9) | |
146 | #define GPU_PEOPS_FAKE_BUSY_STATE (1 << 10) | |
147 | ||
7df396ea TK |
148 | static void init_memcard(char *mcd_data) |
149 | { | |
150 | unsigned off = 0; | |
151 | unsigned i; | |
152 | ||
153 | memset(mcd_data, 0, MCD_SIZE); | |
154 | ||
155 | mcd_data[off++] = 'M'; | |
156 | mcd_data[off++] = 'C'; | |
157 | off += 0x7d; | |
158 | mcd_data[off++] = 0x0e; | |
159 | ||
160 | for (i = 0; i < 15; i++) { | |
161 | mcd_data[off++] = 0xa0; | |
162 | off += 0x07; | |
163 | mcd_data[off++] = 0xff; | |
164 | mcd_data[off++] = 0xff; | |
165 | off += 0x75; | |
166 | mcd_data[off++] = 0xa0; | |
167 | } | |
168 | ||
169 | for (i = 0; i < 20; i++) { | |
170 | mcd_data[off++] = 0xff; | |
171 | mcd_data[off++] = 0xff; | |
172 | mcd_data[off++] = 0xff; | |
173 | mcd_data[off++] = 0xff; | |
174 | off += 0x04; | |
175 | mcd_data[off++] = 0xff; | |
176 | mcd_data[off++] = 0xff; | |
177 | off += 0x76; | |
178 | } | |
179 | } | |
180 | ||
49c61096 | 181 | static void set_vout_fb() |
38c2028e | 182 | { |
6558949c FJGG |
183 | struct retro_framebuffer fb = {0}; |
184 | ||
185 | fb.width = vout_width; | |
186 | fb.height = vout_height; | |
187 | fb.access_flags = RETRO_MEMORY_ACCESS_WRITE; | |
188 | ||
6558949c | 189 | if (environ_cb(RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER, &fb) && fb.format == RETRO_PIXEL_FORMAT_RGB565) |
49c61096 G |
190 | vout_buf_ptr = (uint16_t*)fb.data; |
191 | else | |
192 | vout_buf_ptr = vout_buf; | |
193 | } | |
6558949c | 194 | |
49c61096 G |
195 | static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp) |
196 | { | |
197 | vout_width = w; | |
198 | vout_height = h; | |
199 | ||
4ce3bd43 VP |
200 | if (previous_width != vout_width || previous_height != vout_height) |
201 | { | |
202 | previous_width = vout_width; | |
203 | previous_height = vout_height; | |
204 | ||
d3c41e5e VP |
205 | struct retro_system_av_info info; |
206 | retro_get_system_av_info(&info); | |
207 | environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &info.geometry); | |
4ce3bd43 | 208 | } |
d3c41e5e | 209 | |
49c61096 | 210 | set_vout_fb(); |
38c2028e | 211 | } |
212 | ||
cc4f9b70 | 213 | #ifndef FRONTEND_SUPPORTS_RGB565 |
9c59f120 | 214 | static void convert(void *buf, size_t bytes) |
38c2028e | 215 | { |
216 | unsigned int i, v, *p = buf; | |
217 | ||
9c59f120 | 218 | for (i = 0; i < bytes / 4; i++) { |
38c2028e | 219 | v = p[i]; |
220 | p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0); | |
221 | } | |
222 | } | |
46aa5b98 | 223 | #endif |
38c2028e | 224 | |
fa56d360 | 225 | static void vout_flip(const void *vram, int stride, int bgr24, int w, int h) |
38c2028e | 226 | { |
65a0505f | 227 | unsigned short *dest = vout_buf_ptr; |
fa56d360 | 228 | const unsigned short *src = vram; |
70d56ca3 | 229 | int dstride = vout_width, h1 = h; |
230 | int doffs; | |
38c2028e | 231 | |
fa56d360 | 232 | if (vram == NULL) { |
233 | // blanking | |
65a0505f | 234 | memset(vout_buf_ptr, 0, dstride * h * 2); |
fa56d360 | 235 | goto out; |
236 | } | |
237 | ||
70d56ca3 | 238 | doffs = (vout_height - h) * dstride; |
239 | doffs += (dstride - w) / 2 & ~1; | |
240 | if (doffs != vout_doffs_old) { | |
241 | // clear borders | |
65a0505f | 242 | memset(vout_buf_ptr, 0, dstride * h * 2); |
70d56ca3 | 243 | vout_doffs_old = doffs; |
244 | } | |
245 | dest += doffs; | |
246 | ||
fa56d360 | 247 | if (bgr24) |
248 | { | |
249 | // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here? | |
250 | for (; h1-- > 0; dest += dstride, src += stride) | |
251 | { | |
252 | bgr888_to_rgb565(dest, src, w * 3); | |
253 | } | |
254 | } | |
255 | else | |
256 | { | |
257 | for (; h1-- > 0; dest += dstride, src += stride) | |
258 | { | |
259 | bgr555_to_rgb565(dest, src, w * 2); | |
260 | } | |
261 | } | |
38c2028e | 262 | |
fa56d360 | 263 | out: |
46aa5b98 | 264 | #ifndef FRONTEND_SUPPORTS_RGB565 |
65a0505f | 265 | convert(vout_buf_ptr, vout_width * vout_height * 2); |
46aa5b98 | 266 | #endif |
70d56ca3 | 267 | vout_fb_dirty = 1; |
fa56d360 | 268 | pl_rearmed_cbs.flip_cnt++; |
38c2028e | 269 | } |
270 | ||
fc99395c | 271 | #ifdef _3DS |
272 | typedef struct | |
273 | { | |
274 | void* buffer; | |
275 | uint32_t target_map; | |
276 | size_t size; | |
277 | enum psxMapTag tag; | |
278 | }psx_map_t; | |
279 | ||
280 | psx_map_t custom_psx_maps[] = { | |
281 | {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000 | |
282 | {NULL, 0x12800000, 0x010000, MAP_TAG_OTHER}, // 0x1f800000 | |
283 | {NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000 | |
284 | {NULL, 0x11000000, 0x800000, MAP_TAG_LUTS}, // 0x08000000 | |
285 | {NULL, 0x12000000, 0x200000, MAP_TAG_VRAM}, // 0x00000000 | |
286 | }; | |
287 | ||
288 | void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed, | |
289 | enum psxMapTag tag) | |
290 | { | |
291 | (void)is_fixed; | |
292 | (void)addr; | |
293 | ||
f72db18e | 294 | if (__ctr_svchax) |
fc99395c | 295 | { |
296 | psx_map_t* custom_map = custom_psx_maps; | |
297 | ||
298 | for (; custom_map->size; custom_map++) | |
299 | { | |
300 | if ((custom_map->size == size) && (custom_map->tag == tag)) | |
301 | { | |
302 | uint32_t ptr_aligned, tmp; | |
303 | ||
304 | custom_map->buffer = malloc(size + 0x1000); | |
305 | ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF; | |
306 | ||
f72db18e | 307 | if(svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_MAP, 0x3) < 0) |
fc99395c | 308 | { |
309 | SysPrintf("could not map memory @0x%08X\n", custom_map->target_map); | |
310 | exit(1); | |
311 | } | |
312 | ||
313 | return (void*)custom_map->target_map; | |
314 | } | |
315 | } | |
316 | } | |
317 | ||
318 | return malloc(size); | |
319 | } | |
320 | ||
321 | void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag) | |
cc56203b | 322 | { |
fc99395c | 323 | (void)tag; |
324 | ||
f72db18e | 325 | if (__ctr_svchax) |
fc99395c | 326 | { |
327 | psx_map_t* custom_map = custom_psx_maps; | |
328 | ||
329 | for (; custom_map->size; custom_map++) | |
330 | { | |
331 | if ((custom_map->target_map == (uint32_t)ptr)) | |
332 | { | |
333 | uint32_t ptr_aligned, tmp; | |
334 | ||
335 | ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF; | |
336 | ||
f72db18e | 337 | svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_UNMAP, 0x3); |
fc99395c | 338 | |
339 | free(custom_map->buffer); | |
340 | custom_map->buffer = NULL; | |
341 | return; | |
342 | } | |
343 | } | |
344 | } | |
345 | ||
346 | free(ptr); | |
347 | } | |
348 | #endif | |
349 | ||
1a5fd794 | 350 | #ifdef VITA |
351 | typedef struct | |
352 | { | |
353 | void* buffer; | |
354 | uint32_t target_map; | |
355 | size_t size; | |
356 | enum psxMapTag tag; | |
357 | }psx_map_t; | |
358 | ||
73081f23 FJGG |
359 | void* addr = NULL; |
360 | ||
1a5fd794 | 361 | psx_map_t custom_psx_maps[] = { |
362 | {NULL, NULL, 0x210000, MAP_TAG_RAM}, // 0x80000000 | |
363 | {NULL, NULL, 0x010000, MAP_TAG_OTHER}, // 0x1f800000 | |
364 | {NULL, NULL, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000 | |
365 | {NULL, NULL, 0x800000, MAP_TAG_LUTS}, // 0x08000000 | |
366 | {NULL, NULL, 0x200000, MAP_TAG_VRAM}, // 0x00000000 | |
367 | }; | |
368 | ||
73081f23 FJGG |
369 | int init_vita_mmap(){ |
370 | int n; | |
848b806c | 371 | void * tmpaddr; |
73081f23 FJGG |
372 | addr = malloc(64*1024*1024); |
373 | if(addr==NULL) | |
374 | return -1; | |
848b806c FJGG |
375 | tmpaddr = ((u32)(addr+0xFFFFFF))&~0xFFFFFF; |
376 | custom_psx_maps[0].buffer=tmpaddr+0x2000000; | |
377 | custom_psx_maps[1].buffer=tmpaddr+0x1800000; | |
378 | custom_psx_maps[2].buffer=tmpaddr+0x1c00000; | |
379 | custom_psx_maps[3].buffer=tmpaddr+0x0000000; | |
380 | custom_psx_maps[4].buffer=tmpaddr+0x1000000; | |
73081f23 FJGG |
381 | #if 0 |
382 | for(n = 0; n < 5; n++){ | |
383 | sceClibPrintf("addr reserved %x\n",custom_psx_maps[n].buffer); | |
384 | } | |
385 | #endif | |
386 | return 0; | |
387 | } | |
388 | ||
389 | void deinit_vita_mmap(){ | |
390 | free(addr); | |
391 | } | |
392 | ||
1a5fd794 | 393 | void* pl_vita_mmap(unsigned long addr, size_t size, int is_fixed, |
394 | enum psxMapTag tag) | |
395 | { | |
396 | (void)is_fixed; | |
397 | (void)addr; | |
398 | ||
399 | ||
400 | psx_map_t* custom_map = custom_psx_maps; | |
401 | ||
402 | for (; custom_map->size; custom_map++) | |
403 | { | |
404 | if ((custom_map->size == size) && (custom_map->tag == tag)) | |
405 | { | |
1a5fd794 | 406 | return custom_map->buffer; |
407 | } | |
408 | } | |
409 | ||
410 | ||
411 | return malloc(size); | |
412 | } | |
413 | ||
414 | void pl_vita_munmap(void *ptr, size_t size, enum psxMapTag tag) | |
415 | { | |
416 | (void)tag; | |
417 | ||
418 | psx_map_t* custom_map = custom_psx_maps; | |
419 | ||
420 | for (; custom_map->size; custom_map++) | |
421 | { | |
422 | if ((custom_map->buffer == ptr)) | |
423 | { | |
1a5fd794 | 424 | return; |
425 | } | |
426 | } | |
427 | ||
428 | free(ptr); | |
429 | } | |
430 | #endif | |
431 | ||
fc99395c | 432 | static void *pl_mmap(unsigned int size) |
ace14ab3 | 433 | { |
87e5b45f | 434 | return psxMap(0, size, 0, MAP_TAG_VRAM); |
cc56203b | 435 | } |
436 | ||
437 | static void pl_munmap(void *ptr, unsigned int size) | |
438 | { | |
87e5b45f | 439 | psxUnmap(ptr, size, MAP_TAG_VRAM); |
cc56203b | 440 | } |
441 | ||
38c2028e | 442 | struct rearmed_cbs pl_rearmed_cbs = { |
443 | .pl_vout_open = vout_open, | |
444 | .pl_vout_set_mode = vout_set_mode, | |
445 | .pl_vout_flip = vout_flip, | |
446 | .pl_vout_close = vout_close, | |
cc56203b | 447 | .mmap = pl_mmap, |
448 | .munmap = pl_munmap, | |
38c2028e | 449 | /* from psxcounters */ |
450 | .gpu_hcnt = &hSyncCount, | |
451 | .gpu_frame_count = &frame_counter, | |
452 | }; | |
453 | ||
454 | void pl_frame_limit(void) | |
455 | { | |
456 | /* called once per frame, make psxCpu->Execute() above return */ | |
457 | stop = 1; | |
458 | } | |
459 | ||
460 | void pl_timing_prepare(int is_pal) | |
461 | { | |
17f84149 | 462 | is_pal_mode = is_pal; |
38c2028e | 463 | } |
464 | ||
d71c7095 | 465 | void plat_trigger_vibrate(int pad, int low, int high) |
38c2028e | 466 | { |
79f29e0a | 467 | if (!rumble_cb) |
468 | return; | |
469 | ||
470 | if (in_enable_vibration) | |
70fb8fe7 | 471 | { |
79f29e0a | 472 | rumble_cb(pad, RETRO_RUMBLE_STRONG, high << 8); |
473 | rumble_cb(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0); | |
70fb8fe7 | 474 | } |
38c2028e | 475 | } |
476 | ||
e4c83ca6 | 477 | void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in) |
38c2028e | 478 | { |
479 | } | |
480 | ||
481 | /* sound calls */ | |
07c13dfd | 482 | static void snd_feed(void *buf, int bytes) |
38c2028e | 483 | { |
db126209 | 484 | if (audio_batch_cb != NULL) |
485 | audio_batch_cb(buf, bytes / 4); | |
38c2028e | 486 | } |
487 | ||
07c13dfd | 488 | void out_register_libretro(struct out_driver *drv) |
489 | { | |
490 | drv->name = "libretro"; | |
491 | drv->init = snd_init; | |
492 | drv->finish = snd_finish; | |
493 | drv->busy = snd_busy; | |
494 | drv->feed = snd_feed; | |
495 | } | |
496 | ||
38c2028e | 497 | /* libretro */ |
e268a47e | 498 | void retro_set_environment(retro_environment_t cb) |
499 | { | |
e268a47e | 500 | environ_cb = cb; |
501 | ||
919cac88 | 502 | if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging)) |
503 | log_cb = logging.log; | |
504 | ||
505 | libretro_set_core_options(environ_cb); | |
e268a47e | 506 | } |
507 | ||
38c2028e | 508 | void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; } |
509 | void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; } | |
510 | void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; } | |
511 | void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; } | |
512 | void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; } | |
513 | ||
514 | unsigned retro_api_version(void) | |
515 | { | |
516 | return RETRO_API_VERSION; | |
517 | } | |
518 | ||
15504ca8 | 519 | static int controller_port_variable(unsigned port, struct retro_variable *var) |
8136cafb AP |
520 | { |
521 | if (port >= PORTS_NUMBER) | |
15504ca8 | 522 | return 0; |
8136cafb | 523 | |
15504ca8 AP |
524 | if (!environ_cb) |
525 | return 0; | |
8136cafb | 526 | |
15504ca8 | 527 | var->value = NULL; |
a06f5a70 AP |
528 | switch (port) { |
529 | case 0: | |
15504ca8 | 530 | var->key = "pcsx_rearmed_pad1type"; |
a06f5a70 AP |
531 | break; |
532 | case 1: | |
15504ca8 | 533 | var->key = "pcsx_rearmed_pad2type"; |
a06f5a70 AP |
534 | break; |
535 | case 2: | |
15504ca8 | 536 | var->key = "pcsx_rearmed_pad3type"; |
a06f5a70 AP |
537 | break; |
538 | case 3: | |
15504ca8 | 539 | var->key = "pcsx_rearmed_pad4type"; |
a06f5a70 AP |
540 | break; |
541 | case 4: | |
15504ca8 | 542 | var->key = "pcsx_rearmed_pad5type"; |
a06f5a70 AP |
543 | break; |
544 | case 5: | |
15504ca8 | 545 | var->key = "pcsx_rearmed_pad6type"; |
a06f5a70 AP |
546 | break; |
547 | case 6: | |
15504ca8 | 548 | var->key = "pcsx_rearmed_pad7type"; |
a06f5a70 AP |
549 | break; |
550 | case 7: | |
15504ca8 | 551 | var->key = "pcsx_rearmed_pad8type"; |
a06f5a70 AP |
552 | break; |
553 | } | |
554 | ||
15504ca8 AP |
555 | return environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, var) || var->value; |
556 | } | |
557 | ||
558 | static void update_controller_port_variable(unsigned port) | |
559 | { | |
560 | if (port >= PORTS_NUMBER) | |
561 | return; | |
562 | ||
563 | struct retro_variable var; | |
564 | ||
565 | if (controller_port_variable(port, &var)) | |
8136cafb | 566 | { |
3c0fb554 | 567 | if (strcmp(var.value, "standard") == 0) |
8342a300 | 568 | in_type[port] = PSE_PAD_TYPE_STANDARD; |
3c0fb554 | 569 | else if (strcmp(var.value, "analog") == 0) |
de95fedd S |
570 | in_type[port] = PSE_PAD_TYPE_ANALOGJOY; |
571 | else if (strcmp(var.value, "dualshock") == 0) | |
8342a300 | 572 | in_type[port] = PSE_PAD_TYPE_ANALOGPAD; |
8136cafb | 573 | else if (strcmp(var.value, "negcon") == 0) |
8342a300 | 574 | in_type[port] = PSE_PAD_TYPE_NEGCON; |
e8e20a7d S |
575 | else if (strcmp(var.value, "guncon") == 0) |
576 | in_type[port] = PSE_PAD_TYPE_GUNCON; | |
8c047f6f | 577 | else if (strcmp(var.value, "none") == 0) |
8342a300 | 578 | in_type[port] = PSE_PAD_TYPE_NONE; |
15504ca8 | 579 | // else 'default' case, do nothing |
3dc2e39e | 580 | } |
15504ca8 | 581 | } |
3dc2e39e | 582 | |
15504ca8 AP |
583 | static void update_controller_port_device(unsigned port, unsigned device) |
584 | { | |
585 | if (port >= PORTS_NUMBER) | |
586 | return; | |
587 | ||
588 | struct retro_variable var; | |
589 | ||
590 | if (!controller_port_variable(port, &var)) | |
591 | return; | |
592 | ||
593 | if (strcmp(var.value, "default") != 0) | |
594 | return; | |
595 | ||
596 | switch (device) | |
597 | { | |
598 | case RETRO_DEVICE_JOYPAD: | |
599 | in_type[port] = PSE_PAD_TYPE_STANDARD; | |
600 | break; | |
601 | case RETRO_DEVICE_ANALOG: | |
602 | in_type[port] = PSE_PAD_TYPE_ANALOGPAD; | |
603 | break; | |
604 | case RETRO_DEVICE_MOUSE: | |
605 | in_type[port] = PSE_PAD_TYPE_MOUSE; | |
606 | break; | |
607 | case RETRO_DEVICE_LIGHTGUN: | |
608 | in_type[port] = PSE_PAD_TYPE_GUN; | |
609 | break; | |
610 | case RETRO_DEVICE_NONE: | |
611 | default: | |
612 | in_type[port] = PSE_PAD_TYPE_NONE; | |
613 | } | |
8136cafb AP |
614 | } |
615 | ||
30d43b8a AP |
616 | static void update_multitap() |
617 | { | |
618 | struct retro_variable var; | |
6cdf212f | 619 | int auto_case, port; |
30d43b8a AP |
620 | |
621 | var.value = NULL; | |
622 | var.key = "pcsx_rearmed_multitap1"; | |
3dc2e39e AP |
623 | auto_case = 0; |
624 | if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)) | |
30d43b8a AP |
625 | { |
626 | if (strcmp(var.value, "enabled") == 0) | |
627 | multitap1 = 1; | |
628 | else if (strcmp(var.value, "disabled") == 0) | |
629 | multitap1 = 0; | |
630 | else // 'auto' case | |
3dc2e39e AP |
631 | auto_case = 1; |
632 | } | |
633 | else | |
15504ca8 | 634 | auto_case = 1; |
3dc2e39e AP |
635 | |
636 | if (auto_case) | |
637 | { | |
638 | // If a gamepad is plugged after port 2, we need a first multitap. | |
639 | multitap1 = 0; | |
6cdf212f | 640 | for (port = 2; port < PORTS_NUMBER; port++) |
3dc2e39e | 641 | multitap1 |= in_type[port] != PSE_PAD_TYPE_NONE; |
30d43b8a AP |
642 | } |
643 | ||
644 | var.value = NULL; | |
645 | var.key = "pcsx_rearmed_multitap2"; | |
3dc2e39e AP |
646 | auto_case = 0; |
647 | if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)) | |
30d43b8a AP |
648 | { |
649 | if (strcmp(var.value, "enabled") == 0) | |
650 | multitap2 = 1; | |
651 | else if (strcmp(var.value, "disabled") == 0) | |
652 | multitap2 = 0; | |
653 | else // 'auto' case | |
3dc2e39e AP |
654 | auto_case = 1; |
655 | } | |
656 | else | |
15504ca8 | 657 | auto_case = 1; |
3dc2e39e AP |
658 | |
659 | if (auto_case) | |
660 | { | |
661 | // If a gamepad is plugged after port 4, we need a second multitap. | |
662 | multitap2 = 0; | |
6cdf212f | 663 | for (port = 4; port < PORTS_NUMBER; port++) |
3dc2e39e | 664 | multitap2 |= in_type[port] != PSE_PAD_TYPE_NONE; |
30d43b8a AP |
665 | } |
666 | } | |
667 | ||
38c2028e | 668 | void retro_set_controller_port_device(unsigned port, unsigned device) |
669 | { | |
ace14ab3 | 670 | SysPrintf("port %u device %u",port,device); |
8c047f6f AP |
671 | |
672 | if (port >= PORTS_NUMBER) | |
673 | return; | |
674 | ||
675 | update_controller_port_device(port, device); | |
676 | update_multitap(); | |
38c2028e | 677 | } |
678 | ||
679 | void retro_get_system_info(struct retro_system_info *info) | |
680 | { | |
681 | memset(info, 0, sizeof(*info)); | |
682 | info->library_name = "PCSX-ReARMed"; | |
8fc5171a GR |
683 | #ifndef GIT_VERSION |
684 | #define GIT_VERSION "" | |
685 | #endif | |
686 | info->library_version = "r22" GIT_VERSION; | |
ce188d4d | 687 | info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u|chd"; |
38c2028e | 688 | info->need_fullpath = true; |
689 | } | |
690 | ||
691 | void retro_get_system_av_info(struct retro_system_av_info *info) | |
692 | { | |
d3c41e5e VP |
693 | |
694 | unsigned geom_height = vout_height > 0 ? vout_height : 240; | |
695 | unsigned geom_width = vout_width > 0 ? vout_width : 320; | |
696 | ||
38c2028e | 697 | memset(info, 0, sizeof(*info)); |
17f84149 | 698 | info->timing.fps = is_pal_mode ? 50 : 60; |
38c2028e | 699 | info->timing.sample_rate = 44100; |
d3c41e5e VP |
700 | info->geometry.base_width = geom_width; |
701 | info->geometry.base_height = geom_height; | |
805fe9bc | 702 | info->geometry.max_width = VOUT_MAX_WIDTH; |
703 | info->geometry.max_height = VOUT_MAX_HEIGHT; | |
38c2028e | 704 | info->geometry.aspect_ratio = 4.0 / 3.0; |
705 | } | |
706 | ||
6e921e1d | 707 | /* savestates */ |
ace14ab3 | 708 | size_t retro_serialize_size(void) |
709 | { | |
03f55e6b | 710 | // it's currently 4380651-4397047 bytes, |
711 | // but have some reserved for future | |
712 | return 0x440000; | |
6e921e1d | 713 | } |
714 | ||
715 | struct save_fp { | |
716 | char *buf; | |
717 | size_t pos; | |
718 | int is_write; | |
719 | }; | |
720 | ||
721 | static void *save_open(const char *name, const char *mode) | |
722 | { | |
723 | struct save_fp *fp; | |
724 | ||
725 | if (name == NULL || mode == NULL) | |
726 | return NULL; | |
727 | ||
728 | fp = malloc(sizeof(*fp)); | |
729 | if (fp == NULL) | |
730 | return NULL; | |
731 | ||
732 | fp->buf = (char *)name; | |
733 | fp->pos = 0; | |
734 | fp->is_write = (mode[0] == 'w' || mode[1] == 'w'); | |
735 | ||
736 | return fp; | |
737 | } | |
738 | ||
739 | static int save_read(void *file, void *buf, u32 len) | |
740 | { | |
741 | struct save_fp *fp = file; | |
742 | if (fp == NULL || buf == NULL) | |
743 | return -1; | |
744 | ||
745 | memcpy(buf, fp->buf + fp->pos, len); | |
746 | fp->pos += len; | |
747 | return len; | |
748 | } | |
749 | ||
750 | static int save_write(void *file, const void *buf, u32 len) | |
751 | { | |
752 | struct save_fp *fp = file; | |
753 | if (fp == NULL || buf == NULL) | |
754 | return -1; | |
755 | ||
756 | memcpy(fp->buf + fp->pos, buf, len); | |
757 | fp->pos += len; | |
758 | return len; | |
759 | } | |
760 | ||
761 | static long save_seek(void *file, long offs, int whence) | |
762 | { | |
763 | struct save_fp *fp = file; | |
764 | if (fp == NULL) | |
765 | return -1; | |
766 | ||
767 | switch (whence) { | |
768 | case SEEK_CUR: | |
769 | fp->pos += offs; | |
770 | return fp->pos; | |
771 | case SEEK_SET: | |
772 | fp->pos = offs; | |
773 | return fp->pos; | |
774 | default: | |
775 | return -1; | |
776 | } | |
777 | } | |
778 | ||
779 | static void save_close(void *file) | |
780 | { | |
781 | struct save_fp *fp = file; | |
782 | size_t r_size = retro_serialize_size(); | |
783 | if (fp == NULL) | |
784 | return; | |
785 | ||
786 | if (fp->pos > r_size) | |
787 | SysPrintf("ERROR: save buffer overflow detected\n"); | |
788 | else if (fp->is_write && fp->pos < r_size) | |
789 | // make sure we don't save trash in leftover space | |
790 | memset(fp->buf + fp->pos, 0, r_size - fp->pos); | |
791 | free(fp); | |
38c2028e | 792 | } |
793 | ||
794 | bool retro_serialize(void *data, size_t size) | |
ace14ab3 | 795 | { |
6e921e1d | 796 | int ret = SaveState(data); |
797 | return ret == 0 ? true : false; | |
38c2028e | 798 | } |
799 | ||
800 | bool retro_unserialize(const void *data, size_t size) | |
801 | { | |
6e921e1d | 802 | int ret = LoadState(data); |
803 | return ret == 0 ? true : false; | |
38c2028e | 804 | } |
805 | ||
23ea11bd | 806 | /* cheats */ |
38c2028e | 807 | void retro_cheat_reset(void) |
808 | { | |
6e921e1d | 809 | ClearAllCheats(); |
38c2028e | 810 | } |
811 | ||
812 | void retro_cheat_set(unsigned index, bool enabled, const char *code) | |
813 | { | |
6e921e1d | 814 | char buf[256]; |
815 | int ret; | |
816 | ||
817 | // cheat funcs are destructive, need a copy.. | |
818 | strncpy(buf, code, sizeof(buf)); | |
819 | buf[sizeof(buf) - 1] = 0; | |
5bf56268 | 820 | |
47624ecf | 821 | //Prepare buffered cheat for PCSX's AddCheat fucntion. |
822 | int cursor=0; | |
823 | int nonhexdec=0; | |
824 | while (buf[cursor]){ | |
825 | if (!(ISHEXDEC)){ | |
826 | if (++nonhexdec%2){ | |
827 | buf[cursor]=' '; | |
828 | } else { | |
829 | buf[cursor]='\n'; | |
830 | } | |
831 | } | |
832 | cursor++; | |
833 | } | |
5bf56268 | 834 | |
6e921e1d | 835 | |
836 | if (index < NumCheats) | |
837 | ret = EditCheat(index, "", buf); | |
838 | else | |
839 | ret = AddCheat("", buf); | |
840 | ||
841 | if (ret != 0) | |
842 | SysPrintf("Failed to set cheat %#u\n", index); | |
843 | else if (index < NumCheats) | |
844 | Cheats[index].Enabled = enabled; | |
38c2028e | 845 | } |
846 | ||
23ea11bd | 847 | /* multidisk support */ |
848 | static bool disk_ejected; | |
849 | static unsigned int disk_current_index; | |
51ba7408 | 850 | static unsigned int disk_count; |
23ea11bd | 851 | static struct disks_state { |
852 | char *fname; | |
853 | int internal_index; // for multidisk eboots | |
854 | } disks[8]; | |
855 | ||
856 | static bool disk_set_eject_state(bool ejected) | |
857 | { | |
858 | // weird PCSX API.. | |
859 | SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2)); | |
860 | LidInterrupt(); | |
861 | ||
862 | disk_ejected = ejected; | |
863 | return true; | |
864 | } | |
865 | ||
866 | static bool disk_get_eject_state(void) | |
867 | { | |
868 | /* can't be controlled by emulated software */ | |
869 | return disk_ejected; | |
870 | } | |
871 | ||
872 | static unsigned int disk_get_image_index(void) | |
873 | { | |
874 | return disk_current_index; | |
875 | } | |
876 | ||
877 | static bool disk_set_image_index(unsigned int index) | |
878 | { | |
879 | if (index >= sizeof(disks) / sizeof(disks[0])) | |
880 | return false; | |
881 | ||
882 | CdromId[0] = '\0'; | |
883 | CdromLabel[0] = '\0'; | |
884 | ||
885 | if (disks[index].fname == NULL) { | |
886 | SysPrintf("missing disk #%u\n", index); | |
887 | CDR_shutdown(); | |
888 | ||
889 | // RetroArch specifies "no disk" with index == count, | |
890 | // so don't fail here.. | |
891 | disk_current_index = index; | |
892 | return true; | |
893 | } | |
894 | ||
895 | SysPrintf("switching to disk %u: \"%s\" #%d\n", index, | |
896 | disks[index].fname, disks[index].internal_index); | |
897 | ||
898 | cdrIsoMultidiskSelect = disks[index].internal_index; | |
899 | set_cd_image(disks[index].fname); | |
900 | if (ReloadCdromPlugin() < 0) { | |
901 | SysPrintf("failed to load cdr plugin\n"); | |
902 | return false; | |
903 | } | |
904 | if (CDR_open() < 0) { | |
905 | SysPrintf("failed to open cdr plugin\n"); | |
906 | return false; | |
907 | } | |
908 | ||
909 | if (!disk_ejected) { | |
910 | SetCdOpenCaseTime(time(NULL) + 2); | |
911 | LidInterrupt(); | |
912 | } | |
913 | ||
914 | disk_current_index = index; | |
915 | return true; | |
916 | } | |
917 | ||
918 | static unsigned int disk_get_num_images(void) | |
919 | { | |
51ba7408 | 920 | return disk_count; |
23ea11bd | 921 | } |
922 | ||
923 | static bool disk_replace_image_index(unsigned index, | |
924 | const struct retro_game_info *info) | |
925 | { | |
926 | char *old_fname; | |
927 | bool ret = true; | |
928 | ||
929 | if (index >= sizeof(disks) / sizeof(disks[0])) | |
930 | return false; | |
931 | ||
932 | old_fname = disks[index].fname; | |
933 | disks[index].fname = NULL; | |
934 | disks[index].internal_index = 0; | |
935 | ||
936 | if (info != NULL) { | |
937 | disks[index].fname = strdup(info->path); | |
938 | if (index == disk_current_index) | |
939 | ret = disk_set_image_index(index); | |
940 | } | |
941 | ||
942 | if (old_fname != NULL) | |
943 | free(old_fname); | |
944 | ||
945 | return ret; | |
946 | } | |
947 | ||
948 | static bool disk_add_image_index(void) | |
949 | { | |
51ba7408 T |
950 | if (disk_count >= 8) |
951 | return false; | |
952 | ||
953 | disk_count++; | |
23ea11bd | 954 | return true; |
955 | } | |
956 | ||
957 | static struct retro_disk_control_callback disk_control = { | |
958 | .set_eject_state = disk_set_eject_state, | |
959 | .get_eject_state = disk_get_eject_state, | |
960 | .get_image_index = disk_get_image_index, | |
961 | .set_image_index = disk_set_image_index, | |
962 | .get_num_images = disk_get_num_images, | |
963 | .replace_image_index = disk_replace_image_index, | |
964 | .add_image_index = disk_add_image_index, | |
965 | }; | |
966 | ||
9fba39a9 T |
967 | // just in case, maybe a win-rt port in the future? |
968 | #ifdef _WIN32 | |
969 | #define SLASH '\\' | |
970 | #else | |
971 | #define SLASH '/' | |
972 | #endif | |
973 | ||
9096ba88 | 974 | #ifndef PATH_MAX |
975 | #define PATH_MAX 4096 | |
976 | #endif | |
977 | ||
e6f1e7f7 | 978 | static char base_dir[1024]; |
9fba39a9 T |
979 | |
980 | static bool read_m3u(const char *file) | |
981 | { | |
e6f1e7f7 | 982 | char line[1024]; |
9fba39a9 | 983 | char name[PATH_MAX]; |
9fba39a9 T |
984 | FILE *f = fopen(file, "r"); |
985 | if (!f) | |
986 | return false; | |
987 | ||
51ba7408 | 988 | while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) { |
9fba39a9 T |
989 | if (line[0] == '#') |
990 | continue; | |
991 | char *carrige_return = strchr(line, '\r'); | |
992 | if (carrige_return) | |
993 | *carrige_return = '\0'; | |
994 | char *newline = strchr(line, '\n'); | |
995 | if (newline) | |
996 | *newline = '\0'; | |
997 | ||
998 | if (line[0] != '\0') | |
999 | { | |
1000 | snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line); | |
51ba7408 | 1001 | disks[disk_count++].fname = strdup(name); |
9fba39a9 T |
1002 | } |
1003 | } | |
1004 | ||
1005 | fclose(f); | |
51ba7408 | 1006 | return (disk_count != 0); |
9fba39a9 T |
1007 | } |
1008 | ||
1009 | static void extract_directory(char *buf, const char *path, size_t size) | |
1010 | { | |
1011 | char *base; | |
1012 | strncpy(buf, path, size - 1); | |
1013 | buf[size - 1] = '\0'; | |
1014 | ||
1015 | base = strrchr(buf, '/'); | |
1016 | if (!base) | |
1017 | base = strrchr(buf, '\\'); | |
1018 | ||
1019 | if (base) | |
1020 | *base = '\0'; | |
1021 | else | |
1022 | { | |
1023 | buf[0] = '.'; | |
1024 | buf[1] = '\0'; | |
1025 | } | |
1026 | } | |
1027 | ||
003cfc63 | 1028 | #if defined(__QNX__) || defined(_WIN32) |
41294f4d | 1029 | /* Blackberry QNX doesn't have strcasestr */ |
1030 | ||
1031 | /* | |
1032 | * Find the first occurrence of find in s, ignore case. | |
1033 | */ | |
1034 | char * | |
1035 | strcasestr(const char *s, const char*find) | |
1036 | { | |
1037 | char c, sc; | |
1038 | size_t len; | |
1039 | ||
1040 | if ((c = *find++) != 0) { | |
1041 | c = tolower((unsigned char)c); | |
1042 | len = strlen(find); | |
1043 | do { | |
1044 | do { | |
1045 | if ((sc = *s++) == 0) | |
1046 | return (NULL); | |
1047 | } while ((char)tolower((unsigned char)sc) != c); | |
1048 | } while (strncasecmp(s, find, len) != 0); | |
1049 | s--; | |
1050 | } | |
1051 | return ((char *)s); | |
1052 | } | |
1053 | #endif | |
1054 | ||
b5926d18 | 1055 | static void set_retro_memmap(void) |
1056 | { | |
1057 | struct retro_memory_map retromap = { 0 }; | |
1058 | struct retro_memory_descriptor mmap = | |
1059 | { | |
1060 | 0, psxM, 0, 0, 0, 0, 0x200000 | |
1061 | }; | |
1062 | ||
1063 | retromap.descriptors = &mmap; | |
1064 | retromap.num_descriptors = 1; | |
1065 | ||
1066 | environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &retromap); | |
1067 | } | |
1068 | ||
38c2028e | 1069 | bool retro_load_game(const struct retro_game_info *info) |
1070 | { | |
23ea11bd | 1071 | size_t i; |
9fba39a9 T |
1072 | bool is_m3u = (strcasestr(info->path, ".m3u") != NULL); |
1073 | ||
e3f8313f | 1074 | struct retro_input_descriptor desc[] = { |
1075 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, | |
1076 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, | |
1077 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, | |
1078 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, | |
1079 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, | |
1080 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, | |
1081 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, | |
1082 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, | |
1083 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, | |
1084 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, | |
1085 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, | |
1086 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, | |
1087 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, | |
1088 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, | |
1089 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, | |
1090 | { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, | |
3e24db84 | 1091 | { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, |
1092 | { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, | |
1093 | { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, | |
1094 | { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, | |
1095 | ||
e3f8313f | 1096 | |
1097 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, | |
1098 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, | |
1099 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, | |
1100 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, | |
1101 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, | |
1102 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, | |
1103 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, | |
1104 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, | |
1105 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, | |
1106 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, | |
1107 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, | |
1108 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, | |
1109 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, | |
1110 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, | |
1111 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, | |
1112 | { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, | |
3e24db84 | 1113 | { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, |
1114 | { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, | |
1115 | { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, | |
1116 | { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, | |
e3f8313f | 1117 | |
1118 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, | |
1119 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, | |
1120 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, | |
1121 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, | |
1122 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, | |
1123 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, | |
1124 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, | |
1125 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, | |
1126 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, | |
1127 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, | |
1128 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, | |
1129 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, | |
1130 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, | |
1131 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, | |
1132 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, | |
1133 | { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, | |
3e24db84 | 1134 | { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, |
1135 | { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, | |
1136 | { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, | |
1137 | { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, | |
e3f8313f | 1138 | |
1139 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, | |
1140 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, | |
1141 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, | |
1142 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, | |
1143 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, | |
1144 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, | |
1145 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, | |
1146 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, | |
1147 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, | |
1148 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, | |
1149 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, | |
1150 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, | |
1151 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, | |
1152 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, | |
1153 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, | |
1154 | { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, | |
3e24db84 | 1155 | { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, |
1156 | { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, | |
1157 | { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, | |
1158 | { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, | |
e3f8313f | 1159 | |
1160 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, | |
1161 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, | |
1162 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, | |
1163 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, | |
1164 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, | |
1165 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, | |
1166 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, | |
1167 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, | |
1168 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, | |
1169 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, | |
1170 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, | |
1171 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, | |
1172 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, | |
1173 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, | |
1174 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, | |
1175 | { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, | |
3e24db84 | 1176 | { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, |
1177 | { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, | |
1178 | { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, | |
1179 | { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, | |
e3f8313f | 1180 | |
1181 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, | |
1182 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, | |
1183 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, | |
1184 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, | |
1185 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, | |
1186 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, | |
1187 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, | |
1188 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, | |
1189 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, | |
1190 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, | |
1191 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, | |
1192 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, | |
1193 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, | |
1194 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, | |
1195 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, | |
ace14ab3 | 1196 | { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, |
3e24db84 | 1197 | { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, |
1198 | { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, | |
1199 | { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, | |
1200 | { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, | |
e3f8313f | 1201 | |
1202 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, | |
1203 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, | |
1204 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, | |
1205 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, | |
1206 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, | |
1207 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, | |
1208 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, | |
1209 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, | |
1210 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, | |
1211 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, | |
1212 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, | |
1213 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, | |
1214 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, | |
1215 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, | |
1216 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, | |
ace14ab3 | 1217 | { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, |
3e24db84 | 1218 | { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, |
1219 | { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, | |
1220 | { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, | |
1221 | { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, | |
e3f8313f | 1222 | |
1223 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, | |
1224 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, | |
1225 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, | |
1226 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, | |
1227 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, | |
1228 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, | |
1229 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, | |
1230 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, | |
1231 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, | |
1232 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, | |
1233 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, | |
1234 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, | |
1235 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, | |
1236 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, | |
1237 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, | |
ace14ab3 | 1238 | { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, |
3e24db84 | 1239 | { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, |
1240 | { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, | |
1241 | { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, | |
1242 | { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, | |
e3f8313f | 1243 | |
1244 | { 0 }, | |
1245 | }; | |
1246 | ||
2df7fcac BP |
1247 | frame_count = 0; |
1248 | ||
e3f8313f | 1249 | environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); |
1250 | ||
46aa5b98 | 1251 | #ifdef FRONTEND_SUPPORTS_RGB565 |
c19aba43 | 1252 | enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; |
9f766dbe | 1253 | if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { |
f29fbd53 | 1254 | SysPrintf("RGB565 supported, using it\n"); |
c19aba43 | 1255 | } |
46aa5b98 | 1256 | #endif |
c19aba43 | 1257 | |
23ea11bd | 1258 | if (info == NULL || info->path == NULL) { |
1259 | SysPrintf("info->path required\n"); | |
1260 | return false; | |
1261 | } | |
1262 | ||
38c2028e | 1263 | if (plugins_opened) { |
1264 | ClosePlugins(); | |
1265 | plugins_opened = 0; | |
1266 | } | |
1267 | ||
23ea11bd | 1268 | for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) { |
1269 | if (disks[i].fname != NULL) { | |
1270 | free(disks[i].fname); | |
1271 | disks[i].fname = NULL; | |
1272 | } | |
1273 | disks[i].internal_index = 0; | |
1274 | } | |
1275 | ||
1276 | disk_current_index = 0; | |
9fba39a9 T |
1277 | extract_directory(base_dir, info->path, sizeof(base_dir)); |
1278 | ||
1279 | if (is_m3u) { | |
1280 | if (!read_m3u(info->path)) { | |
b2aef321 | 1281 | log_cb(RETRO_LOG_INFO, "failed to read m3u file\n"); |
9fba39a9 T |
1282 | return false; |
1283 | } | |
51ba7408 T |
1284 | } else { |
1285 | disk_count = 1; | |
9fba39a9 | 1286 | disks[0].fname = strdup(info->path); |
51ba7408 | 1287 | } |
23ea11bd | 1288 | |
1289 | set_cd_image(disks[0].fname); | |
38c2028e | 1290 | |
1291 | /* have to reload after set_cd_image for correct cdr plugin */ | |
1292 | if (LoadPlugins() == -1) { | |
b2aef321 | 1293 | log_cb(RETRO_LOG_INFO, "failed to load plugins\n"); |
38c2028e | 1294 | return false; |
1295 | } | |
1296 | ||
1297 | plugins_opened = 1; | |
1298 | NetOpened = 0; | |
1299 | ||
1300 | if (OpenPlugins() == -1) { | |
b2aef321 | 1301 | log_cb(RETRO_LOG_INFO, "failed to open plugins\n"); |
38c2028e | 1302 | return false; |
1303 | } | |
1304 | ||
1305 | plugin_call_rearmed_cbs(); | |
19a784e6 | 1306 | dfinput_activate(); |
38c2028e | 1307 | |
38c2028e | 1308 | if (CheckCdrom() == -1) { |
b2aef321 | 1309 | log_cb(RETRO_LOG_INFO, "unsupported/invalid CD image: %s\n", info->path); |
38c2028e | 1310 | return false; |
1311 | } | |
1312 | ||
6492c6e8 | 1313 | SysReset(); |
38c2028e | 1314 | |
1315 | if (LoadCdrom() == -1) { | |
b2aef321 | 1316 | log_cb(RETRO_LOG_INFO, "could not load CD\n"); |
38c2028e | 1317 | return false; |
1318 | } | |
79f216e3 | 1319 | emu_on_new_cd(0); |
38c2028e | 1320 | |
23ea11bd | 1321 | // multidisk images |
9fba39a9 | 1322 | if (!is_m3u) { |
51ba7408 | 1323 | disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8; |
9fba39a9 T |
1324 | for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) { |
1325 | disks[i].fname = strdup(info->path); | |
1326 | disks[i].internal_index = i; | |
1327 | } | |
23ea11bd | 1328 | } |
1329 | ||
b5926d18 | 1330 | set_retro_memmap(); |
1331 | ||
38c2028e | 1332 | return true; |
1333 | } | |
1334 | ||
38c2028e | 1335 | unsigned retro_get_region(void) |
1336 | { | |
17f84149 | 1337 | return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC; |
38c2028e | 1338 | } |
1339 | ||
1340 | void *retro_get_memory_data(unsigned id) | |
1341 | { | |
b40a83db T |
1342 | if (id == RETRO_MEMORY_SAVE_RAM) |
1343 | return Mcd1Data; | |
2683f84f | 1344 | else if (id == RETRO_MEMORY_SYSTEM_RAM) |
1345 | return psxM; | |
b40a83db T |
1346 | else |
1347 | return NULL; | |
38c2028e | 1348 | } |
1349 | ||
1350 | size_t retro_get_memory_size(unsigned id) | |
1351 | { | |
b40a83db T |
1352 | if (id == RETRO_MEMORY_SAVE_RAM) |
1353 | return MCD_SIZE; | |
2683f84f | 1354 | else if (id == RETRO_MEMORY_SYSTEM_RAM) |
6af013d2 | 1355 | return 0x200000; |
b40a83db T |
1356 | else |
1357 | return 0; | |
38c2028e | 1358 | } |
1359 | ||
1360 | void retro_reset(void) | |
1361 | { | |
d9e77039 | 1362 | //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key |
1363 | rebootemu = 1; | |
1364 | //SysReset(); | |
38c2028e | 1365 | } |
1366 | ||
1367 | static const unsigned short retro_psx_map[] = { | |
1368 | [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS, | |
1369 | [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE, | |
1370 | [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT, | |
1371 | [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START, | |
1372 | [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP, | |
1373 | [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN, | |
1374 | [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT, | |
1375 | [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT, | |
1376 | [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE, | |
1377 | [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE, | |
1378 | [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1, | |
1379 | [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1, | |
1380 | [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2, | |
1381 | [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2, | |
1382 | [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3, | |
1383 | [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3, | |
1384 | }; | |
1385 | #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0])) | |
1386 | ||
805fe9bc | 1387 | static void update_variables(bool in_flight) |
e268a47e | 1388 | { |
e268a47e | 1389 | struct retro_variable var; |
6cdf212f | 1390 | int i; |
c8108d88 | 1391 | int gpu_peops_fix = 0; |
ace14ab3 | 1392 | |
e268a47e | 1393 | var.value = NULL; |
4e477065 | 1394 | var.key = "pcsx_rearmed_frameskip"; |
7d68d030 | 1395 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) |
1396 | pl_rearmed_cbs.frameskip = atoi(var.value); | |
9f5a28d9 | 1397 | |
1398 | var.value = NULL; | |
4e477065 | 1399 | var.key = "pcsx_rearmed_region"; |
9f5a28d9 | 1400 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) |
1401 | { | |
1402 | Config.PsxAuto = 0; | |
f4cceff6 | 1403 | if (strcmp(var.value, "auto") == 0) |
9f5a28d9 | 1404 | Config.PsxAuto = 1; |
1405 | else if (strcmp(var.value, "NTSC") == 0) | |
1406 | Config.PsxType = 0; | |
1407 | else if (strcmp(var.value, "PAL") == 0) | |
1408 | Config.PsxType = 1; | |
1409 | } | |
4615b075 | 1410 | |
6cdf212f | 1411 | for (i = 0; i < PORTS_NUMBER; i++) |
15504ca8 | 1412 | update_controller_port_variable(i); |
61c4962a | 1413 | |
30d43b8a | 1414 | update_multitap(); |
61c4962a | 1415 | |
e1442c48 | 1416 | var.value = NULL; |
1417 | var.key = "pcsx_rearmed_negcon_deadzone"; | |
1418 | negcon_deadzone = 0; | |
1419 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1420 | { | |
1421 | negcon_deadzone = (int)(atoi(var.value) * 0.01f * NEGCON_RANGE); | |
1422 | } | |
1423 | ||
1424 | var.value = NULL; | |
1425 | var.key = "pcsx_rearmed_negcon_response"; | |
1426 | negcon_linearity = 1; | |
1427 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1428 | { | |
1429 | if (strcmp(var.value, "quadratic") == 0){ | |
1430 | negcon_linearity = 2; | |
1431 | } else if (strcmp(var.value, "cubic") == 0){ | |
1432 | negcon_linearity = 3; | |
1433 | } | |
1434 | } | |
1435 | ||
70fb8fe7 | 1436 | var.value = NULL; |
1437 | var.key = "pcsx_rearmed_vibration"; | |
1438 | ||
1439 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1440 | { | |
1441 | if (strcmp(var.value, "disabled") == 0) | |
1442 | in_enable_vibration = 0; | |
1443 | else if (strcmp(var.value, "enabled") == 0) | |
1444 | in_enable_vibration = 1; | |
1445 | } | |
1446 | ||
5c1cbedc | 1447 | var.value = NULL; |
1448 | var.key = "pcsx_rearmed_dithering"; | |
1449 | ||
1450 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1451 | { | |
1452 | if (strcmp(var.value, "disabled") == 0) { | |
1453 | pl_rearmed_cbs.gpu_peops.iUseDither = 0; | |
1454 | pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 0; | |
030d1121 | 1455 | pl_rearmed_cbs.gpu_unai.dithering = 0; |
5c1cbedc | 1456 | #ifdef __ARM_NEON__ |
1457 | pl_rearmed_cbs.gpu_neon.allow_dithering = 0; | |
1458 | #endif | |
1459 | } | |
1460 | else if (strcmp(var.value, "enabled") == 0) { | |
1461 | pl_rearmed_cbs.gpu_peops.iUseDither = 1; | |
1462 | pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 1; | |
030d1121 | 1463 | pl_rearmed_cbs.gpu_unai.dithering = 1; |
5c1cbedc | 1464 | #ifdef __ARM_NEON__ |
1465 | pl_rearmed_cbs.gpu_neon.allow_dithering = 1; | |
1466 | #endif | |
1467 | } | |
1468 | } | |
1469 | ||
7d68d030 | 1470 | #ifdef __ARM_NEON__ |
9f5a28d9 | 1471 | var.value = "NULL"; |
55e5626b | 1472 | var.key = "pcsx_rearmed_neon_interlace_enable"; |
9f5a28d9 | 1473 | |
1474 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1475 | { | |
1476 | if (strcmp(var.value, "disabled") == 0) | |
1477 | pl_rearmed_cbs.gpu_neon.allow_interlace = 0; | |
1478 | else if (strcmp(var.value, "enabled") == 0) | |
1479 | pl_rearmed_cbs.gpu_neon.allow_interlace = 1; | |
1480 | } | |
1481 | ||
7d68d030 | 1482 | var.value = NULL; |
55e5626b | 1483 | var.key = "pcsx_rearmed_neon_enhancement_enable"; |
7d68d030 | 1484 | |
1485 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1486 | { | |
1487 | if (strcmp(var.value, "disabled") == 0) | |
1488 | pl_rearmed_cbs.gpu_neon.enhancement_enable = 0; | |
1489 | else if (strcmp(var.value, "enabled") == 0) | |
1490 | pl_rearmed_cbs.gpu_neon.enhancement_enable = 1; | |
1491 | } | |
354329fa | 1492 | |
1493 | var.value = NULL; | |
55e5626b | 1494 | var.key = "pcsx_rearmed_neon_enhancement_no_main"; |
354329fa | 1495 | |
1496 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1497 | { | |
1498 | if (strcmp(var.value, "disabled") == 0) | |
1499 | pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0; | |
1500 | else if (strcmp(var.value, "enabled") == 0) | |
1501 | pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1; | |
1502 | } | |
094ec204 | 1503 | #endif |
0e5a7b7d | 1504 | |
1505 | var.value = "NULL"; | |
1506 | var.key = "pcsx_rearmed_duping_enable"; | |
1507 | ||
1508 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1509 | { | |
0a6520c3 | 1510 | if (strcmp(var.value, "disabled") == 0) |
0e5a7b7d | 1511 | duping_enable = false; |
0a6520c3 | 1512 | else if (strcmp(var.value, "enabled") == 0) |
0e5a7b7d | 1513 | duping_enable = true; |
1514 | } | |
1515 | ||
2df7fcac BP |
1516 | var.value = "NULL"; |
1517 | var.key = "pcsx_rearmed_display_internal_fps"; | |
1518 | ||
1519 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1520 | { | |
1521 | if (strcmp(var.value, "disabled") == 0) | |
1522 | display_internal_fps = false; | |
1523 | else if (strcmp(var.value, "enabled") == 0) | |
1524 | display_internal_fps = true; | |
1525 | } | |
1526 | ||
48f615ba | 1527 | #ifndef DRC_DISABLE |
1528 | var.value = NULL; | |
4e477065 | 1529 | var.key = "pcsx_rearmed_drc"; |
48f615ba | 1530 | |
1531 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1532 | { | |
1533 | R3000Acpu *prev_cpu = psxCpu; | |
1534 | ||
fc99395c | 1535 | #ifdef _3DS |
f72db18e | 1536 | if(!__ctr_svchax) |
fc99395c | 1537 | Config.Cpu = CPU_INTERPRETER; |
1538 | else | |
1539 | #endif | |
48f615ba | 1540 | if (strcmp(var.value, "disabled") == 0) |
1541 | Config.Cpu = CPU_INTERPRETER; | |
1542 | else if (strcmp(var.value, "enabled") == 0) | |
1543 | Config.Cpu = CPU_DYNAREC; | |
1544 | ||
1545 | psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec; | |
1546 | if (psxCpu != prev_cpu) { | |
1547 | prev_cpu->Shutdown(); | |
1548 | psxCpu->Init(); | |
1549 | psxCpu->Reset(); // not really a reset.. | |
1550 | } | |
1551 | } | |
1552 | #endif | |
805fe9bc | 1553 | |
01394a7f | 1554 | var.value = "NULL"; |
1555 | var.key = "pcsx_rearmed_spu_reverb"; | |
1556 | ||
1557 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1558 | { | |
0a6520c3 | 1559 | if (strcmp(var.value, "disabled") == 0) |
01394a7f | 1560 | spu_config.iUseReverb = false; |
0a6520c3 | 1561 | else if (strcmp(var.value, "enabled") == 0) |
01394a7f | 1562 | spu_config.iUseReverb = true; |
1563 | } | |
1564 | ||
1565 | var.value = "NULL"; | |
1566 | var.key = "pcsx_rearmed_spu_interpolation"; | |
1567 | ||
1568 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1569 | { | |
1570 | if (strcmp(var.value, "simple") == 0) | |
1571 | spu_config.iUseInterpolation = 1; | |
1572 | else if (strcmp(var.value, "gaussian") == 0) | |
1573 | spu_config.iUseInterpolation = 2; | |
1574 | else if (strcmp(var.value, "cubic") == 0) | |
1575 | spu_config.iUseInterpolation = 3; | |
1576 | else if (strcmp(var.value, "off") == 0) | |
1577 | spu_config.iUseInterpolation = 0; | |
1578 | } | |
1579 | ||
b3480be8 | 1580 | var.value = "NULL"; |
1581 | var.key = "pcsx_rearmed_pe2_fix"; | |
1582 | ||
1583 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1584 | { | |
1585 | if (strcmp(var.value, "disabled") == 0) | |
1586 | Config.RCntFix = 0; | |
1587 | else if (strcmp(var.value, "enabled") == 0) | |
1588 | Config.RCntFix = 1; | |
1589 | } | |
ace14ab3 | 1590 | |
1d6abe26 | 1591 | var.value = "NULL"; |
1592 | var.key = "pcsx_rearmed_idiablofix"; | |
1593 | ||
1594 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1595 | { | |
1596 | if (strcmp(var.value, "disabled") == 0) | |
1597 | spu_config.idiablofix = 0; | |
1598 | else if (strcmp(var.value, "enabled") == 0) | |
1599 | spu_config.idiablofix = 1; | |
1600 | } | |
1601 | ||
b3480be8 | 1602 | var.value = "NULL"; |
1603 | var.key = "pcsx_rearmed_inuyasha_fix"; | |
1604 | ||
1605 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1606 | { | |
1607 | if (strcmp(var.value, "disabled") == 0) | |
1608 | Config.VSyncWA = 0; | |
1609 | else if (strcmp(var.value, "enabled") == 0) | |
1610 | Config.VSyncWA = 1; | |
1611 | } | |
1612 | ||
b12cce74 | 1613 | var.value = NULL; |
1614 | var.key = "pcsx_rearmed_noxadecoding"; | |
1615 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1616 | { | |
1617 | if (strcmp(var.value, "disabled") == 0) | |
1618 | Config.Xa = 1; | |
1619 | else | |
1620 | Config.Xa = 0; | |
1621 | } | |
1622 | ||
1623 | var.value = NULL; | |
1624 | var.key = "pcsx_rearmed_nocdaudio"; | |
1625 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1626 | { | |
1627 | if (strcmp(var.value, "disabled") == 0) | |
1628 | Config.Cdda = 1; | |
1629 | else | |
1630 | Config.Cdda = 0; | |
1631 | } | |
1632 | ||
34af0fff | 1633 | var.value = NULL; |
1634 | var.key = "pcsx_rearmed_spuirq"; | |
1635 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1636 | { | |
1637 | if (strcmp(var.value, "disabled") == 0) | |
1638 | Config.SpuIrq = 0; | |
1639 | else | |
1640 | Config.SpuIrq = 1; | |
1641 | } | |
1642 | ||
decba348 | 1643 | #ifndef DRC_DISABLE |
1644 | var.value = NULL; | |
1645 | var.key = "pcsx_rearmed_nosmccheck"; | |
1646 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1647 | { | |
1648 | if (strcmp(var.value, "enabled") == 0) | |
1649 | new_dynarec_hacks |= NDHACK_NO_SMC_CHECK; | |
1650 | else | |
1651 | new_dynarec_hacks &= ~NDHACK_NO_SMC_CHECK; | |
1652 | } | |
1653 | ||
1654 | var.value = NULL; | |
1655 | var.key = "pcsx_rearmed_gteregsunneeded"; | |
1656 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1657 | { | |
1658 | if (strcmp(var.value, "enabled") == 0) | |
1659 | new_dynarec_hacks |= NDHACK_GTE_UNNEEDED; | |
1660 | else | |
1661 | new_dynarec_hacks &= ~NDHACK_GTE_UNNEEDED; | |
1662 | } | |
1663 | ||
1664 | var.value = NULL; | |
1665 | var.key = "pcsx_rearmed_nogteflags"; | |
1666 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1667 | { | |
1668 | if (strcmp(var.value, "enabled") == 0) | |
1669 | new_dynarec_hacks |= NDHACK_GTE_NO_FLAGS; | |
1670 | else | |
1671 | new_dynarec_hacks &= ~NDHACK_GTE_NO_FLAGS; | |
1672 | } | |
1673 | #endif | |
1674 | ||
2d17de26 | 1675 | #ifdef GPU_PEOPS |
c8108d88 | 1676 | var.value = "NULL"; |
6713b629 | 1677 | var.key = "pcsx_rearmed_gpu_peops_odd_even_bit"; |
c8108d88 | 1678 | |
1679 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1680 | { | |
1681 | if (strcmp(var.value, "enabled") == 0) | |
6713b629 | 1682 | gpu_peops_fix |= GPU_PEOPS_ODD_EVEN_BIT; |
c8108d88 | 1683 | } |
1684 | ||
1685 | var.value = "NULL"; | |
6713b629 | 1686 | var.key = "pcsx_rearmed_gpu_peops_expand_screen_width"; |
c8108d88 | 1687 | |
1688 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1689 | { | |
1690 | if (strcmp(var.value, "enabled") == 0) | |
6713b629 | 1691 | gpu_peops_fix |= GPU_PEOPS_EXPAND_SCREEN_WIDTH; |
c8108d88 | 1692 | } |
1693 | ||
1694 | var.value = "NULL"; | |
6713b629 | 1695 | var.key = "pcsx_rearmed_gpu_peops_ignore_brightness"; |
c8108d88 | 1696 | |
1697 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1698 | { | |
1699 | if (strcmp(var.value, "enabled") == 0) | |
6713b629 | 1700 | gpu_peops_fix |= GPU_PEOPS_IGNORE_BRIGHTNESS; |
c8108d88 | 1701 | } |
1702 | ||
1703 | var.value = "NULL"; | |
6713b629 | 1704 | var.key = "pcsx_rearmed_gpu_peops_disable_coord_check"; |
c8108d88 | 1705 | |
1706 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1707 | { | |
1708 | if (strcmp(var.value, "enabled") == 0) | |
6713b629 | 1709 | gpu_peops_fix |= GPU_PEOPS_DISABLE_COORD_CHECK; |
c8108d88 | 1710 | } |
1711 | ||
1712 | var.value = "NULL"; | |
6713b629 | 1713 | var.key = "pcsx_rearmed_gpu_peops_lazy_screen_update"; |
c8108d88 | 1714 | |
1715 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1716 | { | |
1717 | if (strcmp(var.value, "enabled") == 0) | |
6713b629 | 1718 | gpu_peops_fix |= GPU_PEOPS_LAZY_SCREEN_UPDATE; |
c8108d88 | 1719 | } |
1720 | ||
1721 | var.value = "NULL"; | |
6713b629 | 1722 | var.key = "pcsx_rearmed_gpu_peops_old_frame_skip"; |
c8108d88 | 1723 | |
1724 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1725 | { | |
1726 | if (strcmp(var.value, "enabled") == 0) | |
6713b629 | 1727 | gpu_peops_fix |= GPU_PEOPS_OLD_FRAME_SKIP; |
c8108d88 | 1728 | } |
1729 | ||
1730 | var.value = "NULL"; | |
6713b629 | 1731 | var.key = "pcsx_rearmed_gpu_peops_repeated_triangles"; |
c8108d88 | 1732 | |
1733 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1734 | { | |
1735 | if (strcmp(var.value, "enabled") == 0) | |
6713b629 | 1736 | gpu_peops_fix |= GPU_PEOPS_REPEATED_TRIANGLES; |
c8108d88 | 1737 | } |
1738 | ||
1739 | var.value = "NULL"; | |
6713b629 | 1740 | var.key = "pcsx_rearmed_gpu_peops_quads_with_triangles"; |
c8108d88 | 1741 | |
1742 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1743 | { | |
1744 | if (strcmp(var.value, "enabled") == 0) | |
6713b629 | 1745 | gpu_peops_fix |= GPU_PEOPS_QUADS_WITH_TRIANGLES; |
c8108d88 | 1746 | } |
1747 | ||
1748 | var.value = "NULL"; | |
6713b629 | 1749 | var.key = "pcsx_rearmed_gpu_peops_fake_busy_state"; |
c8108d88 | 1750 | |
1751 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1752 | { | |
1753 | if (strcmp(var.value, "enabled") == 0) | |
6713b629 | 1754 | gpu_peops_fix |= GPU_PEOPS_FAKE_BUSY_STATE; |
c8108d88 | 1755 | } |
1756 | ||
1757 | if (pl_rearmed_cbs.gpu_peops.dwActFixes != gpu_peops_fix) | |
1758 | pl_rearmed_cbs.gpu_peops.dwActFixes = gpu_peops_fix; | |
1759 | ||
1760 | ||
6713b629 | 1761 | /* Show/hide core options */ |
c8108d88 | 1762 | |
1763 | var.key = "pcsx_rearmed_show_gpu_peops_settings"; | |
1764 | var.value = NULL; | |
1765 | ||
1766 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1767 | { | |
1768 | int show_advanced_gpu_peops_settings_prev = show_advanced_gpu_peops_settings; | |
1769 | ||
1770 | show_advanced_gpu_peops_settings = 1; | |
1771 | if (strcmp(var.value, "disabled") == 0) | |
1772 | show_advanced_gpu_peops_settings = 0; | |
1773 | ||
1774 | if (show_advanced_gpu_peops_settings != show_advanced_gpu_peops_settings_prev) | |
1775 | { | |
1776 | unsigned i; | |
1777 | struct retro_core_option_display option_display; | |
6713b629 | 1778 | char gpu_peops_option[9][45] = { |
1779 | "pcsx_rearmed_gpu_peops_odd_even_bit", | |
1780 | "pcsx_rearmed_gpu_peops_expand_screen_width", | |
1781 | "pcsx_rearmed_gpu_peops_ignore_brightness", | |
1782 | "pcsx_rearmed_gpu_peops_disable_coord_check", | |
1783 | "pcsx_rearmed_gpu_peops_lazy_screen_update", | |
1784 | "pcsx_rearmed_gpu_peops_old_frame_skip", | |
1785 | "pcsx_rearmed_gpu_peops_repeated_triangles", | |
1786 | "pcsx_rearmed_gpu_peops_quads_with_triangles", | |
1787 | "pcsx_rearmed_gpu_peops_fake_busy_state", | |
c8108d88 | 1788 | }; |
1789 | ||
1790 | option_display.visible = show_advanced_gpu_peops_settings; | |
1791 | ||
1792 | for (i = 0; i < 9; i++) | |
1793 | { | |
1794 | option_display.key = gpu_peops_option[i]; | |
1795 | environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display); | |
1796 | } | |
1797 | } | |
1798 | } | |
1799 | #endif | |
1800 | ||
030d1121 | 1801 | #ifdef GPU_UNAI |
1802 | var.key = "pcsx_rearmed_gpu_unai_ilace_force"; | |
1803 | var.value = NULL; | |
1804 | ||
1805 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1806 | { | |
1807 | if (strcmp(var.value, "disabled") == 0) | |
1808 | pl_rearmed_cbs.gpu_unai.ilace_force = 0; | |
1809 | else if (strcmp(var.value, "enabled") == 0) | |
1810 | pl_rearmed_cbs.gpu_unai.ilace_force = 1; | |
1811 | } | |
1812 | ||
1813 | var.key = "pcsx_rearmed_gpu_unai_pixel_skip"; | |
1814 | var.value = NULL; | |
1815 | ||
1816 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1817 | { | |
1818 | if (strcmp(var.value, "disabled") == 0) | |
1819 | pl_rearmed_cbs.gpu_unai.pixel_skip = 0; | |
1820 | else if (strcmp(var.value, "enabled") == 0) | |
1821 | pl_rearmed_cbs.gpu_unai.pixel_skip = 1; | |
1822 | } | |
1823 | ||
1824 | var.key = "pcsx_rearmed_gpu_unai_lighting"; | |
1825 | var.value = NULL; | |
1826 | ||
1827 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1828 | { | |
1829 | if (strcmp(var.value, "disabled") == 0) | |
1830 | pl_rearmed_cbs.gpu_unai.lighting = 0; | |
1831 | else if (strcmp(var.value, "enabled") == 0) | |
1832 | pl_rearmed_cbs.gpu_unai.lighting = 1; | |
1833 | } | |
1834 | ||
1835 | var.key = "pcsx_rearmed_gpu_unai_fast_lighting"; | |
1836 | var.value = NULL; | |
1837 | ||
1838 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1839 | { | |
1840 | if (strcmp(var.value, "disabled") == 0) | |
1841 | pl_rearmed_cbs.gpu_unai.fast_lighting = 0; | |
1842 | else if (strcmp(var.value, "enabled") == 0) | |
1843 | pl_rearmed_cbs.gpu_unai.fast_lighting = 1; | |
1844 | } | |
1845 | ||
1846 | var.key = "pcsx_rearmed_gpu_unai_blending"; | |
1847 | var.value = NULL; | |
1848 | ||
1849 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1850 | { | |
1851 | if (strcmp(var.value, "disabled") == 0) | |
1852 | pl_rearmed_cbs.gpu_unai.blending = 0; | |
1853 | else if (strcmp(var.value, "enabled") == 0) | |
1854 | pl_rearmed_cbs.gpu_unai.blending = 1; | |
1855 | } | |
1856 | ||
1857 | var.key = "pcsx_rearmed_show_gpu_unai_settings"; | |
1858 | var.value = NULL; | |
1859 | ||
1860 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) | |
1861 | { | |
1862 | int show_advanced_gpu_unai_settings_prev = show_advanced_gpu_unai_settings; | |
1863 | ||
1864 | show_advanced_gpu_unai_settings = 1; | |
1865 | if (strcmp(var.value, "disabled") == 0) | |
1866 | show_advanced_gpu_unai_settings = 0; | |
1867 | ||
1868 | if (show_advanced_gpu_unai_settings != show_advanced_gpu_unai_settings_prev) | |
1869 | { | |
1870 | unsigned i; | |
1871 | struct retro_core_option_display option_display; | |
1872 | char gpu_unai_option[5][40] = { | |
1873 | "pcsx_rearmed_gpu_unai_blending", | |
1874 | "pcsx_rearmed_gpu_unai_lighting", | |
1875 | "pcsx_rearmed_gpu_unai_fast_lighting", | |
1876 | "pcsx_rearmed_gpu_unai_ilace_force", | |
1877 | "pcsx_rearmed_gpu_unai_pixel_skip", | |
1878 | }; | |
1879 | ||
1880 | option_display.visible = show_advanced_gpu_unai_settings; | |
1881 | ||
1882 | for (i = 0; i < 5; i++) | |
1883 | { | |
1884 | option_display.key = gpu_unai_option[i]; | |
1885 | environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display); | |
1886 | } | |
1887 | } | |
1888 | } | |
1889 | #endif // GPU_UNAI | |
1890 | ||
32ab9e53 TJ |
1891 | if (in_flight) { |
1892 | // inform core things about possible config changes | |
1893 | plugin_call_rearmed_cbs(); | |
805fe9bc | 1894 | |
32ab9e53 TJ |
1895 | if (GPU_open != NULL && GPU_close != NULL) { |
1896 | GPU_close(); | |
1897 | GPU_open(&gpuDisp, "PCSX", NULL); | |
1898 | } | |
805fe9bc | 1899 | |
32ab9e53 TJ |
1900 | dfinput_activate(); |
1901 | } | |
27cf7d31 | 1902 | else |
1903 | { | |
b580cc4f | 1904 | //not yet running |
5bf56268 | 1905 | |
b580cc4f | 1906 | //bootlogo display hack |
1907 | if (found_bios) { | |
1908 | var.value = "NULL"; | |
1909 | var.key = "pcsx_rearmed_show_bios_bootlogo"; | |
1910 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1911 | { | |
27cf7d31 | 1912 | Config.SlowBoot = 0; |
1913 | rebootemu = 0; | |
0a6520c3 | 1914 | if (strcmp(var.value, "enabled") == 0) |
27cf7d31 | 1915 | { |
f422f444 | 1916 | Config.SlowBoot = 1; |
27cf7d31 | 1917 | rebootemu = 1; |
1918 | } | |
b580cc4f | 1919 | } |
1920 | } | |
f8983cce | 1921 | #ifndef DRC_DISABLE |
1922 | var.value = "NULL"; | |
1923 | var.key = "pcsx_rearmed_psxclock"; | |
1924 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
1925 | { | |
1926 | int psxclock = atoi(var.value); | |
1927 | cycle_multiplier = 10000 / psxclock; | |
1928 | } | |
1929 | #endif | |
b580cc4f | 1930 | } |
e268a47e | 1931 | } |
1932 | ||
8741f7a2 | 1933 | // Taken from beetle-psx-libretro |
6fbd15c8 | 1934 | static uint16_t get_analog_button(int16_t ret, retro_input_state_t input_state_cb, int player_index, int id) |
8741f7a2 | 1935 | { |
8741f7a2 | 1936 | // NOTE: Analog buttons were added Nov 2017. Not all front-ends support this |
1937 | // feature (or pre-date it) so we need to handle this in a graceful way. | |
1938 | ||
1939 | // First, try and get an analog value using the new libretro API constant | |
6fbd15c8 | 1940 | uint16_t button = input_state_cb(player_index, |
8741f7a2 | 1941 | RETRO_DEVICE_ANALOG, |
1942 | RETRO_DEVICE_INDEX_ANALOG_BUTTON, | |
1943 | id); | |
1944 | button = MIN(button / 128, 255); | |
1945 | ||
1946 | if (button == 0) | |
1947 | { | |
1948 | // If we got exactly zero, we're either not pressing the button, or the front-end | |
1949 | // is not reporting analog values. We need to do a second check using the classic | |
1950 | // digital API method, to at least get some response - better than nothing. | |
1951 | ||
1952 | // NOTE: If we're really just not holding the button, we're still going to get zero. | |
1953 | ||
6fbd15c8 | 1954 | button = (ret & (1 << id)) ? 255 : 0; |
8741f7a2 | 1955 | } |
1956 | ||
1957 | return button; | |
1958 | } | |
1959 | ||
ace14ab3 | 1960 | void retro_run(void) |
38c2028e | 1961 | { |
f422f444 | 1962 | int i; |
1963 | //SysReset must be run while core is running,Not in menu (Locks up Retroarch) | |
1964 | if (rebootemu != 0) { | |
1965 | rebootemu = 0; | |
1966 | SysReset(); | |
1967 | if (!Config.HLE && !Config.SlowBoot) { | |
1968 | // skip BIOS logos | |
1969 | psxRegs.pc = psxRegs.GPR.n.ra; | |
f422f444 | 1970 | } |
f8983cce | 1971 | } |
38c2028e | 1972 | |
2df7fcac BP |
1973 | if (display_internal_fps) { |
1974 | frame_count++; | |
1975 | ||
1976 | if (frame_count % INTERNAL_FPS_SAMPLE_PERIOD == 0) { | |
1977 | unsigned internal_fps = pl_rearmed_cbs.flip_cnt * (is_pal_mode ? 50 : 60) / INTERNAL_FPS_SAMPLE_PERIOD; | |
1978 | char str[64]; | |
1979 | const char *strc = (const char*)str; | |
1980 | struct retro_message msg = | |
1981 | { | |
1982 | strc, | |
1983 | 180 | |
1984 | }; | |
1985 | ||
1986 | str[0] = '\0'; | |
1987 | ||
1988 | snprintf(str, sizeof(str), "Internal FPS: %2d", internal_fps); | |
1989 | ||
1990 | pl_rearmed_cbs.flip_cnt = 0; | |
1991 | ||
1992 | environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); | |
1993 | } | |
2df7fcac | 1994 | } |
6fbd15c8 | 1995 | else |
1996 | frame_count = 0; | |
2df7fcac | 1997 | |
38c2028e | 1998 | input_poll_cb(); |
e268a47e | 1999 | |
805fe9bc | 2000 | bool updated = false; |
2001 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) | |
2002 | update_variables(true); | |
e268a47e | 2003 | |
3b1a5e21 | 2004 | // reset all keystate, query libretro for keystate |
61c4962a | 2005 | int j; |
e1442c48 | 2006 | int lsx; |
064f8235 | 2007 | int rsy; |
e1442c48 | 2008 | float negcon_twist_amplitude; |
064f8235 | 2009 | int negcon_i_rs; |
2010 | int negcon_ii_rs; | |
6fbd15c8 | 2011 | for(i = 0; i < PORTS_NUMBER; i++) |
2012 | { | |
2013 | int16_t ret = 0; | |
61c4962a | 2014 | in_keystate[i] = 0; |
3c0fb554 AP |
2015 | |
2016 | if (in_type[i] == PSE_PAD_TYPE_NONE) | |
2017 | continue; | |
c8108d88 | 2018 | |
6fbd15c8 | 2019 | if (libretro_supports_bitmasks) |
2020 | ret = input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK); | |
2021 | else | |
2022 | { | |
a3c2efcd T |
2023 | unsigned j; |
2024 | for (j = 0; j < (RETRO_DEVICE_ID_JOYPAD_R3+1); j++) | |
6fbd15c8 | 2025 | { |
a3c2efcd T |
2026 | if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j)) |
2027 | ret |= (1 << j); | |
6fbd15c8 | 2028 | } |
2029 | } | |
3c0fb554 | 2030 | |
e8e20a7d S |
2031 | if (in_type[i] == PSE_PAD_TYPE_GUNCON) |
2032 | { | |
2033 | //ToDo move across to: | |
2034 | //RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X | |
2035 | //RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y | |
2036 | //RETRO_DEVICE_ID_LIGHTGUN_TRIGGER | |
2037 | //RETRO_DEVICE_ID_LIGHTGUN_RELOAD | |
2038 | //RETRO_DEVICE_ID_LIGHTGUN_AUX_A | |
2039 | //RETRO_DEVICE_ID_LIGHTGUN_AUX_B | |
2040 | //Though not sure these are hooked up properly on the Pi | |
2041 | ||
2042 | //ToDo | |
2043 | //Put the controller index back to i instead of hardcoding to 1 when the libretro overlay crash bug is fixed | |
2044 | //This is required for 2 player | |
2045 | ||
2046 | //GUNCON has 3 controls, Trigger,A,B which equal Circle,Start,Cross | |
2047 | ||
2048 | // Trigger | |
e8e20a7d S |
2049 | //The 1 is hardcoded instead of i to prevent the overlay mouse button libretro crash bug |
2050 | if (input_state_cb(1, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)){ | |
2051 | in_keystate[i] |= (1 << DKEY_CIRCLE); | |
2052 | } | |
2053 | ||
2054 | // A | |
2055 | if (input_state_cb(1, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT)){ | |
2056 | in_keystate[i] |= (1 << DKEY_START); | |
2057 | } | |
2058 | ||
2059 | // B | |
2060 | if (input_state_cb(1, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE)){ | |
2061 | in_keystate[i] |= (1 << DKEY_CROSS); | |
2062 | } | |
2063 | ||
2064 | //The 1 is hardcoded instead of i to prevent the overlay mouse button libretro crash bug | |
2065 | int gunx = input_state_cb(1, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X); | |
2066 | int guny = input_state_cb(1, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y); | |
2067 | ||
2068 | //This adjustment process gives the user the ability to manually align the mouse up better | |
2069 | //with where the shots are in the emulator. | |
2070 | ||
2071 | //Percentage distance of screen to adjust | |
2072 | int GunconAdjustX = 0; | |
2073 | int GunconAdjustY = 0; | |
2074 | ||
2075 | //Used when out by a percentage | |
2076 | float GunconAdjustRatioX = 1; | |
2077 | float GunconAdjustRatioY = 1; | |
2078 | ||
2079 | struct retro_variable var; | |
2080 | var.value = NULL; | |
2081 | var.key = "pcsx_rearmed_gunconadjustx"; | |
2082 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
2083 | { | |
2084 | GunconAdjustX = atoi(var.value); | |
2085 | } | |
2086 | ||
2087 | var.value = NULL; | |
2088 | var.key = "pcsx_rearmed_gunconadjusty"; | |
2089 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
2090 | { | |
2091 | GunconAdjustY = atoi(var.value); | |
2092 | } | |
2093 | ||
2094 | ||
2095 | var.value = NULL; | |
2096 | var.key = "pcsx_rearmed_gunconadjustratiox"; | |
2097 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
2098 | { | |
2099 | GunconAdjustRatioX = atof(var.value); | |
2100 | } | |
2101 | ||
2102 | ||
2103 | var.value = NULL; | |
2104 | var.key = "pcsx_rearmed_gunconadjustratioy"; | |
2105 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) | |
2106 | { | |
2107 | GunconAdjustRatioY = atof(var.value); | |
2108 | } | |
2109 | ||
2110 | //Mouse range is -32767 -> 32767 | |
2111 | //1% is about 655 | |
2112 | //Use the left analog stick field to store the absolute coordinates | |
2113 | in_analog_left[0][0] = (gunx*GunconAdjustRatioX) + (GunconAdjustX * 655); | |
2114 | in_analog_left[0][1] = (guny*GunconAdjustRatioY) + (GunconAdjustY * 655); | |
2115 | ||
2116 | ||
2117 | } | |
8741f7a2 | 2118 | if (in_type[i] == PSE_PAD_TYPE_NEGCON) |
56abf614 | 2119 | { |
8741f7a2 | 2120 | // Query digital inputs |
2121 | // | |
2122 | // > Pad-Up | |
9b6b4a24 | 2123 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_UP)) |
8741f7a2 | 2124 | in_keystate[i] |= (1 << DKEY_UP); |
8741f7a2 | 2125 | // > Pad-Right |
6fbd15c8 | 2126 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT)) |
8741f7a2 | 2127 | in_keystate[i] |= (1 << DKEY_RIGHT); |
8741f7a2 | 2128 | // > Pad-Down |
6fbd15c8 | 2129 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN)) |
8741f7a2 | 2130 | in_keystate[i] |= (1 << DKEY_DOWN); |
8741f7a2 | 2131 | // > Pad-Left |
6fbd15c8 | 2132 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) |
8741f7a2 | 2133 | in_keystate[i] |= (1 << DKEY_LEFT); |
8741f7a2 | 2134 | // > Start |
6fbd15c8 | 2135 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_START)) |
8741f7a2 | 2136 | in_keystate[i] |= (1 << DKEY_START); |
8741f7a2 | 2137 | // > neGcon A |
6fbd15c8 | 2138 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_A)) |
8741f7a2 | 2139 | in_keystate[i] |= (1 << DKEY_CIRCLE); |
8741f7a2 | 2140 | // > neGcon B |
6fbd15c8 | 2141 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_X)) |
8741f7a2 | 2142 | in_keystate[i] |= (1 << DKEY_TRIANGLE); |
8741f7a2 | 2143 | // > neGcon R shoulder (digital) |
6fbd15c8 | 2144 | if (ret & (1 << RETRO_DEVICE_ID_JOYPAD_R)) |
8741f7a2 | 2145 | in_keystate[i] |= (1 << DKEY_R1); |
8741f7a2 | 2146 | // Query analog inputs |
2147 | // | |
2148 | // From studying 'libpcsxcore/plugins.c' and 'frontend/plugin.c': | |
2149 | // >> pad->leftJoyX == in_analog_left[i][0] == NeGcon II | |
2150 | // >> pad->leftJoyY == in_analog_left[i][1] == NeGcon L | |
2151 | // >> pad->rightJoyX == in_analog_right[i][0] == NeGcon twist | |
2152 | // >> pad->rightJoyY == in_analog_right[i][1] == NeGcon I | |
2153 | // So we just have to map in_analog_left/right to more | |
2154 | // appropriate inputs... | |
2155 | // | |
2156 | // > NeGcon twist | |
e1442c48 | 2157 | // >> Get raw analog stick value and account for deadzone |
2158 | lsx = input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X); | |
6fbd15c8 | 2159 | if (lsx > negcon_deadzone) |
e1442c48 | 2160 | lsx = lsx - negcon_deadzone; |
6fbd15c8 | 2161 | else if (lsx < -negcon_deadzone) |
e1442c48 | 2162 | lsx = lsx + negcon_deadzone; |
6fbd15c8 | 2163 | else |
e1442c48 | 2164 | lsx = 0; |
e1442c48 | 2165 | // >> Convert to an 'amplitude' [-1.0,1.0] and adjust response |
2166 | negcon_twist_amplitude = (float)lsx / (float)(NEGCON_RANGE - negcon_deadzone); | |
6fbd15c8 | 2167 | if (negcon_linearity == 2) |
2168 | { | |
2169 | if (negcon_twist_amplitude < 0.0) | |
e1442c48 | 2170 | negcon_twist_amplitude = -(negcon_twist_amplitude * negcon_twist_amplitude); |
6fbd15c8 | 2171 | else |
e1442c48 | 2172 | negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude; |
e1442c48 | 2173 | } |
6fbd15c8 | 2174 | else if (negcon_linearity == 3) |
2175 | negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude * negcon_twist_amplitude; | |
e1442c48 | 2176 | // >> Convert to final 'in_analog' integer value [0,255] |
2177 | in_analog_right[i][0] = MAX(MIN((int)(negcon_twist_amplitude * 128.0f) + 128, 255), 0); | |
064f8235 | 2178 | // > NeGcon I + II |
2179 | // >> Handle right analog stick vertical axis mapping... | |
2180 | // - Up (-Y) == accelerate == neGcon I | |
2181 | // - Down (+Y) == brake == neGcon II | |
2182 | negcon_i_rs = 0; | |
2183 | negcon_ii_rs = 0; | |
2184 | rsy = input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y); | |
2185 | if (rsy >= 0){ | |
2186 | // Account for deadzone | |
2187 | // (Note: have never encountered a gamepad with significant differences | |
2188 | // in deadzone between left/right analog sticks, so use the regular 'twist' | |
2189 | // deadzone here) | |
6fbd15c8 | 2190 | if (rsy > negcon_deadzone) |
064f8235 | 2191 | rsy = rsy - negcon_deadzone; |
6fbd15c8 | 2192 | else |
064f8235 | 2193 | rsy = 0; |
064f8235 | 2194 | // Convert to 'in_analog' integer value [0,255] |
2195 | negcon_ii_rs = MIN((int)(((float)rsy / (float)(NEGCON_RANGE - negcon_deadzone)) * 255.0f), 255); | |
2196 | } else { | |
6fbd15c8 | 2197 | if (rsy < -negcon_deadzone) |
064f8235 | 2198 | rsy = -1 * (rsy + negcon_deadzone); |
6fbd15c8 | 2199 | else |
064f8235 | 2200 | rsy = 0; |
064f8235 | 2201 | negcon_i_rs = MIN((int)(((float)rsy / (float)(NEGCON_RANGE - negcon_deadzone)) * 255.0f), 255); |
2202 | } | |
2203 | // >> NeGcon I | |
8741f7a2 | 2204 | in_analog_right[i][1] = MAX( |
064f8235 | 2205 | MAX( |
6fbd15c8 | 2206 | get_analog_button(ret, input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_R2), |
2207 | get_analog_button(ret, input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_B) | |
064f8235 | 2208 | ), |
2209 | negcon_i_rs | |
8741f7a2 | 2210 | ); |
064f8235 | 2211 | // >> NeGcon II |
8741f7a2 | 2212 | in_analog_left[i][0] = MAX( |
064f8235 | 2213 | MAX( |
6fbd15c8 | 2214 | get_analog_button(ret, input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_L2), |
2215 | get_analog_button(ret, input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_Y) | |
064f8235 | 2216 | ), |
2217 | negcon_ii_rs | |
8741f7a2 | 2218 | ); |
2219 | // > NeGcon L | |
6fbd15c8 | 2220 | in_analog_left[i][1] = get_analog_button(ret, input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_L); |
8741f7a2 | 2221 | } |
e8e20a7d | 2222 | if (in_type[i] != PSE_PAD_TYPE_NEGCON && in_type[i] != PSE_PAD_TYPE_GUNCON) |
8741f7a2 | 2223 | { |
2224 | // Query digital inputs | |
6fbd15c8 | 2225 | for (j = 0; j < RETRO_PSX_MAP_LEN; j++) |
2226 | if (ret & (1 << j)) | |
8741f7a2 | 2227 | in_keystate[i] |= retro_psx_map[j]; |
6fbd15c8 | 2228 | |
8741f7a2 | 2229 | // Query analog inputs |
de95fedd | 2230 | if (in_type[i] == PSE_PAD_TYPE_ANALOGJOY || in_type[i] == PSE_PAD_TYPE_ANALOGPAD) |
8741f7a2 | 2231 | { |
2232 | in_analog_left[i][0] = MIN((input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 255) + 128, 255); | |
2233 | in_analog_left[i][1] = MIN((input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 255) + 128, 255); | |
2234 | in_analog_right[i][0] = MIN((input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 255) + 128, 255); | |
2235 | in_analog_right[i][1] = MIN((input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 255) + 128, 255); | |
2236 | } | |
56abf614 | 2237 | } |
61c4962a | 2238 | } |
e8d96071 | 2239 | |
38c2028e | 2240 | stop = 0; |
2241 | psxCpu->Execute(); | |
2242 | ||
65a0505f | 2243 | video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf_ptr : NULL, |
1a6164a1 | 2244 | vout_width, vout_height, vout_width * 2); |
70d56ca3 | 2245 | vout_fb_dirty = 0; |
49c61096 G |
2246 | |
2247 | set_vout_fb(); | |
38c2028e | 2248 | } |
2249 | ||
74ebc05b | 2250 | static bool try_use_bios(const char *path) |
2251 | { | |
2252 | FILE *f; | |
2253 | long size; | |
2254 | const char *name; | |
2255 | ||
2256 | f = fopen(path, "rb"); | |
2257 | if (f == NULL) | |
2258 | return false; | |
2259 | ||
2260 | fseek(f, 0, SEEK_END); | |
2261 | size = ftell(f); | |
2262 | fclose(f); | |
2263 | ||
2264 | if (size != 512 * 1024) | |
2265 | return false; | |
2266 | ||
2267 | name = strrchr(path, SLASH); | |
2268 | if (name++ == NULL) | |
2269 | name = path; | |
2270 | snprintf(Config.Bios, sizeof(Config.Bios), "%s", name); | |
2271 | return true; | |
2272 | } | |
2273 | ||
c4052f4d | 2274 | #ifndef VITA |
74ebc05b | 2275 | #include <sys/types.h> |
2276 | #include <dirent.h> | |
2277 | ||
2278 | static bool find_any_bios(const char *dirpath, char *path, size_t path_size) | |
2279 | { | |
2280 | DIR *dir; | |
2281 | struct dirent *ent; | |
2282 | bool ret = false; | |
2283 | ||
2284 | dir = opendir(dirpath); | |
2285 | if (dir == NULL) | |
2286 | return false; | |
2287 | ||
2288 | while ((ent = readdir(dir))) { | |
106c2c03 | 2289 | if ((strncasecmp(ent->d_name, "scph", 4) != 0) && (strncasecmp(ent->d_name, "psx", 3) != 0)) |
74ebc05b | 2290 | continue; |
2291 | ||
1477f557 | 2292 | snprintf(path, path_size, "%s%c%s", dirpath, SLASH, ent->d_name); |
74ebc05b | 2293 | ret = try_use_bios(path); |
2294 | if (ret) | |
2295 | break; | |
2296 | } | |
2297 | closedir(dir); | |
2298 | return ret; | |
2299 | } | |
2300 | #else | |
2301 | #define find_any_bios(...) false | |
2302 | #endif | |
2303 | ||
11813b9d | 2304 | static void check_system_specs(void) |
2305 | { | |
2306 | unsigned level = 6; | |
2307 | environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level); | |
2308 | } | |
2309 | ||
d382721e MOB |
2310 | static int init_memcards(void) |
2311 | { | |
2312 | int ret = 0; | |
2313 | const char *dir; | |
2314 | struct retro_variable var = { .key="pcsx_rearmed_memcard2", .value=NULL }; | |
2315 | static const char CARD2_FILE[] = "pcsx-card2.mcd"; | |
2316 | ||
5bf56268 | 2317 | // Memcard2 will be handled and is re-enabled if needed using core |
2318 | // operations. | |
2319 | // Memcard1 is handled by libretro, doing this will set core to | |
2320 | // skip file io operations for memcard1 like SaveMcd | |
2321 | snprintf(Config.Mcd1, sizeof(Config.Mcd1), "none"); | |
2322 | snprintf(Config.Mcd2, sizeof(Config.Mcd2), "none"); | |
d382721e MOB |
2323 | init_memcard(Mcd1Data); |
2324 | // Memcard 2 is managed by the emulator on the filesystem, | |
2325 | // There is no need to initialize Mcd2Data like Mcd1Data. | |
2326 | ||
2327 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { | |
2328 | SysPrintf("Memcard 2: %s\n", var.value); | |
2329 | if (memcmp(var.value, "enabled", 7) == 0) { | |
2330 | if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) { | |
2331 | if (strlen(dir) + strlen(CARD2_FILE) + 2 > sizeof(Config.Mcd2)) { | |
2332 | SysPrintf("Path '%s' is too long. Cannot use memcard 2. Use a shorter path.\n", dir); | |
2333 | ret = -1; | |
2334 | } else { | |
2335 | McdDisable[1] = 0; | |
2336 | snprintf(Config.Mcd2, sizeof(Config.Mcd2), "%s/%s", dir, CARD2_FILE); | |
2337 | SysPrintf("Use memcard 2: %s\n", Config.Mcd2); | |
2338 | } | |
2339 | } else { | |
2340 | SysPrintf("Could not get save directory! Could not create memcard 2."); | |
2341 | ret = -1; | |
2342 | } | |
2343 | } | |
2344 | } | |
2345 | return ret; | |
2346 | } | |
2347 | ||
9e7bdf29 | 2348 | static void loadPSXBios(void) |
38c2028e | 2349 | { |
9e7bdf29 | 2350 | const char *dir; |
e6f1e7f7 | 2351 | char path[PATH_MAX]; |
9e7bdf29 | 2352 | unsigned useHLE = 0; |
2353 | ||
1477f557 | 2354 | const char *bios[] = { |
106c2c03 | 2355 | "PSXONPSP660", "psxonpsp660", |
43702642 | 2356 | "SCPH101", "scph101", |
2357 | "SCPH5501", "scph5501", | |
2358 | "SCPH7001", "scph7001", | |
2359 | "SCPH1001", "scph1001" | |
1477f557 | 2360 | }; |
9e7bdf29 | 2361 | |
2362 | struct retro_variable var = { | |
2363 | .key = "pcsx_rearmed_bios", | |
2364 | .value = NULL | |
2365 | }; | |
2366 | ||
2367 | found_bios = 0; | |
2368 | ||
2369 | if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { | |
2370 | if (!strcmp(var.value, "HLE")) | |
2371 | useHLE = 1; | |
2372 | } | |
2373 | ||
2374 | if (!useHLE) | |
2375 | { | |
2376 | if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) | |
2377 | { | |
2378 | unsigned i; | |
2379 | snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir); | |
2380 | ||
2381 | for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) { | |
2382 | snprintf(path, sizeof(path), "%s%c%s.bin", dir, SLASH, bios[i]); | |
2383 | found_bios = try_use_bios(path); | |
2384 | if (found_bios) | |
2385 | break; | |
2386 | } | |
2387 | ||
2388 | if (!found_bios) | |
2389 | found_bios = find_any_bios(dir, path, sizeof(path)); | |
2390 | } | |
2391 | if (found_bios) { | |
2392 | SysPrintf("found BIOS file: %s\n", Config.Bios); | |
2393 | } | |
2394 | } | |
2395 | ||
2396 | if (useHLE || !found_bios) | |
2397 | { | |
2398 | SysPrintf("no BIOS files found.\n"); | |
2399 | struct retro_message msg = | |
2400 | { | |
2401 | "No PlayStation BIOS file found - add for better compatibility", | |
2402 | 180 | |
2403 | }; | |
2404 | environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg); | |
2405 | } | |
2406 | } | |
2407 | ||
2408 | void retro_init(void) | |
2409 | { | |
2410 | struct retro_rumble_interface rumble; | |
2411 | int ret; | |
38c2028e | 2412 | |
d148d265 | 2413 | #ifdef __MACH__ |
2414 | // magic sauce to make the dynarec work on iOS | |
2415 | syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0); | |
2416 | #endif | |
2417 | ||
fc99395c | 2418 | #ifdef _3DS |
fc99395c | 2419 | psxMapHook = pl_3ds_mmap; |
2420 | psxUnmapHook = pl_3ds_munmap; | |
1a5fd794 | 2421 | #endif |
2422 | #ifdef VITA | |
73081f23 FJGG |
2423 | if(init_vita_mmap()<0) |
2424 | abort(); | |
1a5fd794 | 2425 | psxMapHook = pl_vita_mmap; |
2426 | psxUnmapHook = pl_vita_munmap; | |
fc99395c | 2427 | #endif |
38c2028e | 2428 | ret = emu_core_preinit(); |
5bf56268 | 2429 | #ifdef _3DS |
e4d84733 | 2430 | /* emu_core_preinit sets the cpu to dynarec */ |
f72db18e | 2431 | if(!__ctr_svchax) |
e4d84733 | 2432 | Config.Cpu = CPU_INTERPRETER; |
2433 | #endif | |
d382721e | 2434 | ret |= init_memcards(); |
73081f23 | 2435 | |
38c2028e | 2436 | ret |= emu_core_init(); |
2437 | if (ret != 0) { | |
f29fbd53 | 2438 | SysPrintf("PCSX init failed.\n"); |
38c2028e | 2439 | exit(1); |
2440 | } | |
2441 | ||
0b7f536b | 2442 | #ifdef _3DS |
2443 | vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80); | |
2444 | #elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA) | |
a9579f3b | 2445 | posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); |
29122437 TJ |
2446 | #else |
2447 | vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); | |
2448 | #endif | |
5bf56268 | 2449 | |
9e7bdf29 | 2450 | vout_buf_ptr = vout_buf; |
74ebc05b | 2451 | |
9e7bdf29 | 2452 | loadPSXBios(); |
38c2028e | 2453 | |
1a6164a1 | 2454 | environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe); |
23ea11bd | 2455 | environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control); |
79f29e0a | 2456 | |
2457 | rumble_cb = NULL; | |
2458 | if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble)) | |
2459 | rumble_cb = rumble.set_rumble_state; | |
1a6164a1 | 2460 | |
5ca2ec64 | 2461 | /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times) |
2462 | * we have to do this because cache misses and some IO penalties | |
2463 | * are not emulated. Warning: changing this may break compatibility. */ | |
5ca2ec64 | 2464 | cycle_multiplier = 175; |
ace14ab3 | 2465 | #ifdef HAVE_PRE_ARMV7 |
5ca2ec64 | 2466 | cycle_multiplier = 200; |
2467 | #endif | |
46b3a2fc | 2468 | pl_rearmed_cbs.gpu_peops.iUseDither = 1; |
6713b629 | 2469 | pl_rearmed_cbs.gpu_peops.dwActFixes = GPU_PEOPS_OLD_FRAME_SKIP; |
1e0eac23 | 2470 | spu_config.iUseFixedUpdates = 1; |
5ca2ec64 | 2471 | |
6e921e1d | 2472 | SaveFuncs.open = save_open; |
2473 | SaveFuncs.read = save_read; | |
2474 | SaveFuncs.write = save_write; | |
2475 | SaveFuncs.seek = save_seek; | |
2476 | SaveFuncs.close = save_close; | |
e268a47e | 2477 | |
6fbd15c8 | 2478 | if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL)) |
2479 | libretro_supports_bitmasks = true; | |
2480 | ||
805fe9bc | 2481 | update_variables(false); |
32ab9e53 | 2482 | check_system_specs(); |
38c2028e | 2483 | } |
2484 | ||
2485 | void retro_deinit(void) | |
2486 | { | |
3d3bda68 | 2487 | ClosePlugins(); |
38c2028e | 2488 | SysClose(); |
0b7f536b | 2489 | #ifdef _3DS |
2490 | linearFree(vout_buf); | |
2491 | #else | |
38c2028e | 2492 | free(vout_buf); |
0b7f536b | 2493 | #endif |
38c2028e | 2494 | vout_buf = NULL; |
d8f2e2d8 SL |
2495 | |
2496 | #ifdef VITA | |
73081f23 | 2497 | deinit_vita_mmap(); |
d8f2e2d8 | 2498 | #endif |
6fbd15c8 | 2499 | libretro_supports_bitmasks = false; |
38c2028e | 2500 | } |
c4052f4d | 2501 | |
2502 | #ifdef VITA | |
2503 | #include <psp2/kernel/threadmgr.h> | |
2504 | int usleep (unsigned long us) | |
2505 | { | |
2506 | sceKernelDelayThread(us); | |
2507 | } | |
2508 | #endif | |
130984f5 | 2509 | |
2510 | void SysPrintf(const char *fmt, ...) { | |
2511 | va_list list; | |
2512 | char msg[512]; | |
2513 | ||
2514 | va_start(list, fmt); | |
2515 | vsprintf(msg, fmt, list); | |
2516 | va_end(list); | |
2517 | ||
2518 | if (log_cb) | |
2519 | log_cb(RETRO_LOG_INFO, "%s", msg); | |
2520 | } |