libretro.cpp 110 KB
Newer Older
1
2
#include <cstdio>
#include <cstdarg>
3
#include <math.h>
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
4
#include "types.h"
5
6
7
#ifndef _WIN32
#include <sys/time.h>
#endif
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
8

m4xw's avatar
m4xw committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifdef HAVE_LIBNX
#include <stdlib.h>
#include <string.h>
#include <switch.h>

// strdup seems to be missing on the dkp toolchain
// TODO: Investigate more
char* strdup(const char *str)
{
	size_t size = strlen(str) + 1;
	char *copy;

	if ((copy = malloc(size)) == NULL)
		return(NULL);
	(void)memcpy(copy, str, size);
	return(copy);
}

#endif

29
#include <sys/stat.h>
30
#include <file/file_path.h>
31

Libretro-Admin's avatar
Libretro-Admin committed
32
33
#include <libretro.h>

Libretro-Admin's avatar
Update    
Libretro-Admin committed
34
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
Libretro-Admin's avatar
Libretro-Admin committed
35
#include <glsm/glsm.h>
36
#endif
Flyinghead's avatar
Flyinghead committed
37
38
39
#ifdef HAVE_VULKAN
#include "rend/vulkan/vulkan_context.h"
#endif
40
#include "emulator.h"
Libretro-Admin's avatar
Update    
Libretro-Admin committed
41
#include "../rend/rend.h"
Sven's avatar
Sven committed
42
#include "../hw/sh4/sh4_mem.h"
Flyinghead's avatar
Flyinghead committed
43
#include "../hw/sh4/sh4_sched.h"
44
#include "../hw/sh4/dyna/blockmanager.h"
45
#include "keyboard_map.h"
46
#include "hw/maple/maple_cfg.h"
47
#include "hw/maple/maple_if.h"
Flyinghead's avatar
Flyinghead committed
48
#include "hw/maple/maple_cfg.h"
Flyinghead's avatar
Flyinghead committed
49
#include "../hw/pvr/spg.h"
Flyinghead's avatar
Flyinghead committed
50
#include "../hw/naomi/naomi_cart.h"
51
#include "../imgread/common.h"
Flyinghead's avatar
Flyinghead committed
52
#include "../hw/aica/dsp.h"
53
#include "log/LogManager.h"
Flyinghead's avatar
Flyinghead committed
54
#include "cheats.h"
55
#include "rend/CustomTexture.h"
56

57
58
59
60
61
62
#if defined(_XBOX) || defined(_WIN32)
char slash = '\\';
#else
char slash = '/';
#endif

63
64
#define RETRO_DEVICE_TWINSTICK				RETRO_DEVICE_SUBCLASS( RETRO_DEVICE_JOYPAD, 1 )
#define RETRO_DEVICE_TWINSTICK_SATURN		RETRO_DEVICE_SUBCLASS( RETRO_DEVICE_JOYPAD, 2 )
65
#define RETRO_DEVICE_ASCIISTICK				RETRO_DEVICE_SUBCLASS( RETRO_DEVICE_JOYPAD, 3 )
66

Sven's avatar
Sven committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#define RETRO_ENVIRONMENT_RETROARCH_START_BLOCK 0x800000

#define RETRO_ENVIRONMENT_SET_SAVE_STATE_IN_BACKGROUND (2 | RETRO_ENVIRONMENT_RETROARCH_START_BLOCK)
                                            /* bool * --
                                            * Boolean value that tells the front end to save states in the
                                            * background or not.
                                            */

#define RETRO_ENVIRONMENT_GET_CLEAR_ALL_THREAD_WAITS_CB (3 | RETRO_ENVIRONMENT_RETROARCH_START_BLOCK)
                                            /* retro_environment_t * --
                                            * Provides the callback to the frontend method which will cancel
                                            * all currently waiting threads.  Used when coordination is needed
                                            * between the core and the frontend to gracefully stop all threads.
                                            */

82
83
84
85
86
87
88
89
90
91
92
93
94
95
#define RETRO_ENVIRONMENT_POLL_TYPE_OVERRIDE (4 | RETRO_ENVIRONMENT_RETROARCH_START_BLOCK)
                                            /* unsigned * --
                                            * Tells the frontend to override the poll type behavior. 
                                            * Allows the frontend to influence the polling behavior of the
                                            * frontend.
                                            *
                                            * Will be unset when retro_unload_game is called.
                                            *
                                            * 0 - Don't Care, no changes, frontend still determines polling type behavior.
                                            * 1 - Early
                                            * 2 - Normal
                                            * 3 - Late
                                            */

jdgleaver's avatar
jdgleaver committed
96
#include "libretro_core_option_defines.h"
Libretro-Admin's avatar
Libretro-Admin committed
97
98
#include "libretro_core_options.h"

Libretro-Admin's avatar
Libretro-Admin committed
99
u32 fskip;
Libretro-Admin's avatar
Libretro-Admin committed
100
101
extern int screen_width;
extern int screen_height;
102
103
char save_dir[PATH_MAX];
char eeprom_file[PATH_MAX];
104
char nvmem_file[PATH_MAX];
Flyinghead's avatar
Flyinghead committed
105
char nvmem_file2[PATH_MAX];		// AtomisWave
Libretro-Admin's avatar
Libretro-Admin committed
106
bool boot_to_bios;
107

barbudreadmon's avatar
barbudreadmon committed
108
109
static bool devices_need_refresh = false;
static int device_type[4] = {-1,-1,-1,-1};
110
111
static int astick_deadzone = 0;
static int trigger_deadzone = 0;
David Walters's avatar
David Walters committed
112
static bool digital_triggers = false;
113
static bool allow_service_buttons = false;
114

Libretro-Admin's avatar
Libretro-Admin committed
115
116
static bool libretro_supports_bitmasks = false;

117
u32 kcode[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
118
119
120
121
u8 rt[4] = {0, 0, 0, 0};
u8 lt[4] = {0, 0, 0, 0};
u32 vks[4];
s8 joyx[4], joyy[4];
Flyinghead's avatar
Flyinghead committed
122
s8 joyrx[4], joyry[4];
123
124
extern f32 mo_x_abs[4];
extern f32 mo_y_abs[4];
125
126
127
128
extern u32 mo_buttons[4];
extern f32 mo_x_delta[4];
extern f32 mo_y_delta[4];
extern f32 mo_wheel_delta[4];
129

Higor Eurípedes's avatar
Higor Eurípedes committed
130
bool enable_purupuru = true;
131
132
133
static u32 vib_stop_time[4];
static double vib_strength[4];
static double vib_delta[4];
Libretro-Admin's avatar
Libretro-Admin committed
134

135
136
unsigned per_content_vmus = 0;

137
static bool first_run = true;
Libretro-Admin's avatar
Libretro-Admin committed
138

139
140
enum DreamcastController
{
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
   DC_BTN_C       = 1,
   DC_BTN_B       = 1<<1,
   DC_BTN_A       = 1<<2,
   DC_BTN_START   = 1<<3,
   DC_DPAD_UP     = 1<<4,
   DC_DPAD_DOWN   = 1<<5,
   DC_DPAD_LEFT   = 1<<6,
   DC_DPAD_RIGHT  = 1<<7,
   DC_BTN_Z       = 1<<8,
   DC_BTN_Y       = 1<<9,
   DC_BTN_X       = 1<<10,
   DC_BTN_D       = 1<<11,
   DC_DPAD2_UP    = 1<<12,
   DC_DPAD2_DOWN  = 1<<13,
   DC_DPAD2_LEFT  = 1<<14,
   DC_DPAD2_RIGHT = 1<<15,

   DC_AXIS_LT = 0X10000,
   DC_AXIS_RT = 0X10001,
   DC_AXIS_X  = 0X20000,
   DC_AXIS_Y  = 0X20001,
162
};
163

164
165
166
struct retro_perf_callback perf_cb;
retro_get_cpu_features_t perf_get_cpu_features_cb = NULL;

167
168
169
170
171
172
173
// Callbacks
retro_log_printf_t         log_cb = NULL;
retro_video_refresh_t      video_cb = NULL;
retro_input_poll_t         poll_cb = NULL;
retro_input_state_t        input_cb = NULL;
retro_audio_sample_batch_t audio_batch_cb = NULL;
retro_environment_t        environ_cb = NULL;
174
retro_environment_t        frontend_clear_thread_waits_cb = NULL;
Higor Eurípedes's avatar
Higor Eurípedes committed
175
static retro_rumble_interface rumble;
176

177
void FlushCache();	// Arm dynarec (arm and x86 only)
178
bool rend_single_frame();
179
void rend_cancel_emu_wait();
Flyinghead's avatar
Flyinghead committed
180
bool acquire_mainloop_lock();
Libretro-Admin's avatar
Updates    
Libretro-Admin committed
181

182
static void refresh_devices(bool first_startup);
183
static void init_disk_control_interface(void);
Mike Sheehan's avatar
Mike Sheehan committed
184
185
static bool read_m3u(const char *file);

Libretro-Admin's avatar
Libretro-Admin committed
186
char *game_data;
187
char g_base_name[128];
Libretro-Admin's avatar
Libretro-Admin committed
188
char game_dir[1024];
189
char game_dir_no_slash[1024];
190
191
char vmu_dir_no_slash[PATH_MAX];
char content_name[PATH_MAX];
Flyinghead's avatar
Flyinghead committed
192
char g_roms_dir[PATH_MAX];
193
static bool emu_in_thread = false;
194
static bool performed_serialization = false;
195
#if !defined(TARGET_NO_THREADS)
196
static void *emu_thread_func(void *);
197
static cThread emu_thread(&emu_thread_func, 0);
198
199
static cMutex mtx_serialization ;
static cMutex mtx_mainloop ;
200
static bool gl_ctx_resetting = false;
201
bool reset_requested;
202

Mike Sheehan's avatar
Mike Sheehan committed
203
204
// Disk swapping
static struct retro_disk_control_callback retro_disk_control_cb;
205
206
207
static struct retro_disk_control_ext_callback retro_disk_control_ext_cb;
static unsigned disk_initial_index = 0;
static std::string disk_initial_path;
Mike Sheehan's avatar
Mike Sheehan committed
208
209
static unsigned disk_index = 0;
static std::vector<std::string> disk_paths;
210
static std::vector<std::string> disk_labels;
Mike Sheehan's avatar
Mike Sheehan committed
211
212
static bool disc_tray_open = false;

213
u64 pixel_buffer_size = 512 * 1024 * 1024;	// Initial size 512 MB
214

215
216
static void *emu_thread_func(void *)
{
217
    emu_in_thread = true ;
218
219
220
    while ( true )
    {
    	performed_serialization = false ;
Libretro-Admin's avatar
Libretro-Admin committed
221
222
    	mtx_mainloop.lock();
    	rend_cancel_emu_wait();
223
        dc_run();
Libretro-Admin's avatar
Libretro-Admin committed
224
        mtx_mainloop.unlock();
225

Libretro-Admin's avatar
Libretro-Admin committed
226
227
    	mtx_serialization.lock();
    	mtx_serialization.unlock();
228

229
    	if (!performed_serialization && !reset_requested)
230
    		break ;
231
232
    	if (reset_requested)
    	{
barbudreadmon's avatar
barbudreadmon committed
233
    		dc_reset(false);
234
235
    		reset_requested = false;
    	}
236
    }
237

Libretro-Admin's avatar
Libretro-Admin committed
238
	rend_cancel_emu_wait();
239
240
    dc_term();

241
242
    emu_in_thread = false ;

243
244
    return NULL;
}
245
246
#endif

247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
void retro_set_video_refresh(retro_video_refresh_t cb)
{
   video_cb = cb;
}

void retro_set_audio_sample(retro_audio_sample_t cb)
{
   // Nothing to do here
}

void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb)
{
   audio_batch_cb = cb;
}

void retro_set_input_poll(retro_input_poll_t cb)
{
   poll_cb = cb;
}

void retro_set_input_state(retro_input_state_t cb)
{
   input_cb = cb;
}

272
273
274
275
276
277
278
279
280
281
282
283
static void input_set_deadzone_stick( int percent )
{
   if ( percent >= 0 && percent <= 100 )
      astick_deadzone = (int)( percent * 0.01f * 0x8000);
}

static void input_set_deadzone_trigger( int percent )
{
   if ( percent >= 0 && percent <= 100 )
      trigger_deadzone = (int)( percent * 0.01f * 0x8000);
}

284
285
286
void retro_set_environment(retro_environment_t cb)
{
   environ_cb = cb;
287

Libretro-Admin's avatar
Libretro-Admin committed
288
   libretro_set_core_options(environ_cb);
289
290
291

   static const struct retro_controller_description ports_default[] =
   {
292
293
		 { "Controller",	RETRO_DEVICE_JOYPAD },
		 { "Arcade Stick",	RETRO_DEVICE_ASCIISTICK },
294
295
		 { "Keyboard",		RETRO_DEVICE_KEYBOARD },
		 { "Mouse",			RETRO_DEVICE_MOUSE },
Flyinghead's avatar
Flyinghead committed
296
		 { "Light Gun",		RETRO_DEVICE_LIGHTGUN },
297
298
		 { "Twin Stick",	RETRO_DEVICE_TWINSTICK },
		 { "Saturn Twin-Stick",	RETRO_DEVICE_TWINSTICK_SATURN },
299
300
301
		 { 0 },
   };
   static const struct retro_controller_info ports[] = {
302
303
304
305
           { ports_default,  7 },
           { ports_default,  7 },
           { ports_default,  7 },
           { ports_default,  7 },
306
307
308
           { 0 },
   };
   environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
309
310
}

311
void retro_keyboard_event(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
312
313
314
315

// Now comes the interesting stuff
void retro_init(void)
{
Libretro-Admin's avatar
Libretro-Admin committed
316
317
   screen_width  = 640;
   screen_height = 480;
318
319
320
321
322
323
   // Logging
   struct retro_log_callback log;
   if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
      log_cb = log.log;
   else
      log_cb = NULL;
324
   LogManager::Init((void *)log_cb);
325

326
327
328
329
330
   if (environ_cb(RETRO_ENVIRONMENT_GET_PERF_INTERFACE, &perf_cb))
      perf_get_cpu_features_cb = perf_cb.get_cpu_features;
   else
      perf_get_cpu_features_cb = NULL;

331
332
333
   // Set color mode
   unsigned color_mode = RETRO_PIXEL_FORMAT_XRGB8888;
   environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &color_mode);
334
335
336

   environ_cb(RETRO_ENVIRONMENT_GET_CLEAR_ALL_THREAD_WAITS_CB, &frontend_clear_thread_waits_cb);

337
338
339
   init_kb_map();
   struct retro_keyboard_callback kb_callback = { &retro_keyboard_event };
   environ_cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &kb_callback);
Libretro-Admin's avatar
Libretro-Admin committed
340
341
342

   if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL))
      libretro_supports_bitmasks = true;
343
344

   init_disk_control_interface();
345
346
347
348
}

void retro_deinit(void)
{
349
   first_run = true;
350
351
352

   //When auto-save states are enabled this is needed to prevent the core from shutting down before
   //any save state actions are still running - which results in partial saves
Libretro-Admin's avatar
Libretro-Admin committed
353
354
   mtx_serialization.lock();
   mtx_serialization.unlock();
355

Libretro-Admin's avatar
Libretro-Admin committed
356
   libretro_supports_bitmasks = false;
357
   LogManager::Shutdown();
358
359
}

360
static bool is_dupe = false;
361
extern int GDROM_TICK;
362
static bool rotate_screen = false;
363

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
static void set_variable_visibility(void)
{
   struct retro_core_option_display option_display;
   struct retro_variable var;
   char key[256];
   unsigned i;

   /* Show/hide NAOMI/Atomiswave options */
   option_display.visible = ((settings.System == DC_PLATFORM_NAOMI) ||
                             (settings.System == DC_PLATFORM_ATOMISWAVE));

   option_display.key = CORE_OPTION_NAME "_allow_service_buttons";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_enable_naomi_15khz_dipswitch";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);

   /* Show/hide Dreamcast options */
   option_display.visible = (settings.System == DC_PLATFORM_DREAMCAST);

   option_display.key = CORE_OPTION_NAME "_boot_to_bios";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_hle_bios";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_gdrom_fast_loading";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_cable_type";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_broadcast";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_language";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_force_wince";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_enable_purupuru";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_per_content_vmus";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   option_display.key = CORE_OPTION_NAME "_show_vmu_screen_settings";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);

   /* Show/hide settings-dependent options */
   option_display.visible = !settings.rend.ThreadedRendering;

   option_display.key = CORE_OPTION_NAME "_framerate";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);

   option_display.visible = settings.rend.ThreadedRendering;

   option_display.key = CORE_OPTION_NAME "_synchronous_rendering";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);

   option_display.key = CORE_OPTION_NAME "_delay_frame_swapping";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
   // Only for per-pixel renderers
   option_display.visible = settings.pvr.rend == 3 || settings.pvr.rend == 5;
   option_display.key = CORE_OPTION_NAME "_oit_abuffer_size";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);

   // Only if texture upscaling is enabled
   option_display.visible = settings.rend.TextureUpscale > 1;
   option_display.key = CORE_OPTION_NAME "_texupscale_max_filtered_texture_size";
   environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);

   // Only for Vulkan. TODO Unfortunately, at startup the graphic context hasn't been determined yet.
   //option_display.visible = settings.pvr.rend == 4 || settings.pvr.rend == 5;
   //option_display.key = CORE_OPTION_NAME "_anisotropic_filtering";
   //environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);

433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
   /* Show/hide VMU screen options */
   if (settings.System == DC_PLATFORM_DREAMCAST)
   {
      option_display.visible = true;
      var.key = CORE_OPTION_NAME "_show_vmu_screen_settings";

      if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
         if (!strcmp(var.value, "disabled"))
            option_display.visible = false;
   }
   else
      option_display.visible = false;

   for (i = 0; i < 4; i++)
   {
      option_display.key = key;

      key[0] = '\0';
      snprintf(key, sizeof(key), "%s%u%s", CORE_OPTION_NAME "_vmu", i + 1, "_screen_display");
      environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
      key[0] = '\0';
      snprintf(key, sizeof(key), "%s%u%s", CORE_OPTION_NAME "_vmu", i + 1, "_screen_position");
      environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
      key[0] = '\0';
      snprintf(key, sizeof(key), "%s%u%s", CORE_OPTION_NAME "_vmu", i + 1, "_screen_size_mult");
      environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
      key[0] = '\0';
      snprintf(key, sizeof(key), "%s%u%s", CORE_OPTION_NAME "_vmu", i + 1, "_pixel_on_color");
      environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
      key[0] = '\0';
      snprintf(key, sizeof(key), "%s%u%s", CORE_OPTION_NAME "_vmu", i + 1, "_pixel_off_color");
      environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
      key[0] = '\0';
      snprintf(key, sizeof(key), "%s%u%s", CORE_OPTION_NAME "_vmu", i + 1, "_screen_opacity");
      environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   }

   /* Show/hide light gun options */
   option_display.visible = true;
   var.key = CORE_OPTION_NAME "_show_lightgun_settings";

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
      if (!strcmp(var.value, "disabled"))
         option_display.visible = false;

   for (i = 0; i < 4; i++)
   {
      option_display.key = key;

      key[0] = '\0';
      snprintf(key, sizeof(key), "%s%u%s", CORE_OPTION_NAME "_lightgun", i + 1, "_crosshair");
      environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
   }
}

Libretro-Admin's avatar
Libretro-Admin committed
488
static void update_variables(bool first_startup)
489
{
490
   struct retro_variable var;
Sven's avatar
Sven committed
491
492
   int i ;
   char key[256] ;
493

494
   var.key = CORE_OPTION_NAME "_per_content_vmus";
495
496
497
498
499
500
501
502
503
504
505
   unsigned previous_per_content_vmus = per_content_vmus;
   per_content_vmus = 0;

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("VMU A1", var.value))
         per_content_vmus = 1;
      else if (!strcmp("All VMUs", var.value))
         per_content_vmus = 2;
   }

506
507
   if (!first_startup && per_content_vmus != previous_per_content_vmus
   		&& settings.System == DC_PLATFORM_DREAMCAST)
508
   {
509
510
511
512
   	// Recreate the VMUs so that the save location is taken into account.
   	// Don't do this at startup because we don't know the system type yet
   	// and the VMUs haven't been created anyway
   	maple_ReconnectDevices();
513
514
   }

515
   var.key = CORE_OPTION_NAME "_widescreen_hack";
516
517
518
519
520
521
522
523
524
525
526

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp(var.value, "enabled"))
         settings.rend.WideScreen = 1;
      else
         settings.rend.WideScreen = 0;
   }
   else
      settings.rend.WideScreen = 0;

Flyinghead's avatar
Flyinghead committed
527
528
529
530
531
532
533
534
535
536
537
538
   var.key = CORE_OPTION_NAME "_widescreen_cheats";

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp(var.value, "enabled"))
         settings.rend.WidescreenGameHacks = true;
      else
         settings.rend.WidescreenGameHacks = false;
   }
   else
      settings.rend.WidescreenGameHacks = false;

539
   var.key = CORE_OPTION_NAME "_screen_rotation";
540
541
542
543
544
545
   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && !strcmp("vertical", var.value))
   {
	  rotate_screen = true;
	  settings.rend.WideScreen = 0;
   }

546
   var.key = CORE_OPTION_NAME "_internal_resolution";
547
548
549
550
551
552

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      char *pch;
      char str[100];
      snprintf(str, sizeof(str), "%s", var.value);
553

554
555
556
557
558
559
560
      pch = strtok(str, "x");
      if (pch)
         screen_width = strtoul(pch, NULL, 0);
      pch = strtok(NULL, "x");
      if (pch)
         screen_height = strtoul(pch, NULL, 0);

561
      DEBUG_LOG(COMMON, "Got size: %u x %u.\n", screen_width, screen_height);
562
   }
563

564

565
   var.key = CORE_OPTION_NAME "_cpu_mode";
566
567
568
569
570
571
572
573
574

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp(var.value, "dynamic_recompiler"))
         settings.dynarec.Type = 0;
      else if (!strcmp(var.value, "generic_recompiler"))
         settings.dynarec.Type = 1;
   }

575
   var.key = CORE_OPTION_NAME "_boot_to_bios";
Libretro-Admin's avatar
Libretro-Admin committed
576
577
578
579
580
581
582
583
584
585
586

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp(var.value, "enabled"))
         boot_to_bios = true;
      else if (!strcmp(var.value, "disabled"))
         boot_to_bios = false;
   }
   else
      boot_to_bios = false;

587
   var.key = CORE_OPTION_NAME "_gdrom_fast_loading";
588
589
590
591

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp(var.value, "enabled"))
592
         GDROM_TICK      = 512;
593
594
595
596
597
598
      else if (!strcmp(var.value, "disabled"))
         GDROM_TICK      = 1500000;
   }
   else
      GDROM_TICK      = 1500000;

599
   var.key = CORE_OPTION_NAME "_alpha_sorting";
Flyinghead's avatar
Flyinghead committed
600
   int previous_renderer = settings.pvr.rend;
601
602
603
604

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp(var.value, "per-strip (fast, least accurate)"))
Flyinghead's avatar
Flyinghead committed
605
      {
Flyinghead's avatar
Flyinghead committed
606
607
608
609
      	if (settings.pvr.rend == 5)
      		settings.pvr.rend = 4;
      	else if (settings.pvr.rend == 3)
      		settings.pvr.rend = 0;
610
         settings.pvr.Emulation.AlphaSortMode = 1;
Flyinghead's avatar
Flyinghead committed
611
      }
612
      else if (!strcmp(var.value, "per-triangle (normal)"))
Flyinghead's avatar
Flyinghead committed
613
      {
Flyinghead's avatar
Flyinghead committed
614
615
616
617
      	if (settings.pvr.rend == 5)
      		settings.pvr.rend = 4;
      	else if (settings.pvr.rend == 3)
      		settings.pvr.rend = 0;
618
         settings.pvr.Emulation.AlphaSortMode = 0;
Flyinghead's avatar
Flyinghead committed
619
      }
620
      else if (!strcmp(var.value, "per-pixel (accurate)"))
Flyinghead's avatar
Flyinghead committed
621
      {
Flyinghead's avatar
Flyinghead committed
622
623
624
625
      	if (settings.pvr.rend == 4)
      		settings.pvr.rend = 5;
      	else if (settings.pvr.rend == 0)
      		settings.pvr.rend = 3;
Flyinghead's avatar
Flyinghead committed
626
627
         settings.pvr.Emulation.AlphaSortMode = 0;	// Not used
      }
628
629
   }
   else
Flyinghead's avatar
Flyinghead committed
630
   {
Flyinghead's avatar
Flyinghead committed
631
632
633
634
   	if (settings.pvr.rend == 5)
   		settings.pvr.rend = 4;
   	else if (settings.pvr.rend == 3)
   		settings.pvr.rend = 0;
635
      settings.pvr.Emulation.AlphaSortMode = 0;
Flyinghead's avatar
Flyinghead committed
636
637
638
   }
   if (!first_startup && previous_renderer != settings.pvr.rend)
	  renderer_changed = true;
639

640
   var.key = CORE_OPTION_NAME "_mipmapping";
641
642
643
644

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp(var.value, "enabled"))
645
         settings.rend.UseMipmaps      = 1;
646
      else if (!strcmp(var.value, "disabled"))
647
         settings.rend.UseMipmaps      = 0;
648
649
   }
   else
650
      settings.rend.UseMipmaps      = 1;
651

barbudreadmon's avatar
barbudreadmon committed
652
653
654
655
656
657
658
659
660
661
662
663
   var.key = CORE_OPTION_NAME "_fog";

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp(var.value, "enabled"))
         settings.rend.Fog      = true;
      else if (!strcmp(var.value, "disabled"))
         settings.rend.Fog      = false;
   }
   else
      settings.rend.Fog      = true;

Libretro-Admin's avatar
Libretro-Admin committed
664
665
   if (first_startup)
   {
666
      var.key = CORE_OPTION_NAME "_system";
667
668
669
670
671
672
673
674
675

      if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
      {
         if (!strcmp(var.value, "auto"))
            settings.System = DC_PLATFORM_DREAMCAST;
         else if (!strcmp(var.value, "dreamcast"))
            settings.System = DC_PLATFORM_DREAMCAST;
         else if (!strcmp(var.value, "naomi"))
            settings.System = DC_PLATFORM_NAOMI;
Flyinghead's avatar
Flyinghead committed
676
677
         else if (!strcmp(var.value, "atomiswave"))
            settings.System = DC_PLATFORM_ATOMISWAVE;
678
679
680
      }
      else
         settings.System = DC_PLATFORM_DREAMCAST;
681

Flyinghead's avatar
Flyinghead committed
682
683
684
      var.key = CORE_OPTION_NAME "_hle_bios";

      if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
685
      	settings.bios.UseReios = !strcmp(var.value, "enabled") && !boot_to_bios;
Flyinghead's avatar
Flyinghead committed
686
687
688
      else
      	settings.bios.UseReios = false;

689
#if defined(HAVE_OIT) || defined(HAVE_VULKAN)
690
      var.key = CORE_OPTION_NAME "_oit_abuffer_size";
691
692
693
694

      if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
      {
         if (!strcmp(var.value, "512MB"))
Flyinghead's avatar
Flyinghead committed
695
            pixel_buffer_size = 0x20000000u;
696
         else if (!strcmp(var.value, "1GB"))
Flyinghead's avatar
Flyinghead committed
697
            pixel_buffer_size = 0x40000000u;
698
         else if (!strcmp(var.value, "2GB"))
699
            pixel_buffer_size = 0x7ff00000u;
700
701
         else if (!strcmp(var.value, "4GB"))
            pixel_buffer_size = 0xFFFFFFFFu;
702
         else
Flyinghead's avatar
Flyinghead committed
703
            pixel_buffer_size = 0x20000000u;
704
705
      }
      else
Flyinghead's avatar
Flyinghead committed
706
         pixel_buffer_size = 0x20000000u;
707
#endif
Libretro-Admin's avatar
Libretro-Admin committed
708
   }
Libretro-Admin's avatar
Libretro-Admin committed
709

710
   var.key = CORE_OPTION_NAME "_volume_modifier_enable";
711
712
713
714

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp(var.value, "disabled"))
Flyinghead's avatar
Flyinghead committed
715
      	settings.rend.ModifierVolumes      = false;
716
      else if (!strcmp(var.value, "enabled"))
Flyinghead's avatar
Flyinghead committed
717
      	settings.rend.ModifierVolumes      = true;
718
719
   }
   else
Flyinghead's avatar
Flyinghead committed
720
   	settings.rend.ModifierVolumes      = true;
721

722
   var.key = CORE_OPTION_NAME "_cable_type";
Libretro-Admin's avatar
Libretro-Admin committed
723
724
725

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
Libretro-Admin's avatar
Libretro-Admin committed
726
      if (!strcmp("VGA (RGB)", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
727
728
729
         settings.dreamcast.cable = 0;
      else if (!strcmp("TV (RGB)", var.value))
         settings.dreamcast.cable = 2;
730
      else if (!strcmp("TV (Composite)", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
731
732
         settings.dreamcast.cable = 3;
   }
733

734
   var.key = CORE_OPTION_NAME "_broadcast";
Libretro-Admin's avatar
Libretro-Admin committed
735
736
737

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
738
      if (!strcmp("NTSC", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
739
         settings.dreamcast.broadcast = 0;
740
      else if (!strcmp("PAL", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
741
         settings.dreamcast.broadcast = 1;
742
      else if (!strcmp("PAL_M", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
743
         settings.dreamcast.broadcast = 2;
744
      else if (!strcmp("PAL_N", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
745
         settings.dreamcast.broadcast = 3;
746
      else if (!strcmp("Default", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
747
748
749
750
751
         settings.dreamcast.broadcast = 4;
   }
   else
         settings.dreamcast.broadcast = 4;

752
   var.key = CORE_OPTION_NAME "_framerate";
753
754
755
756
757
758
759
760
761
762
763

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("normal", var.value))
         settings.UpdateMode = 0;
      else if (!strcmp("fullspeed", var.value))
         settings.UpdateMode = 1;
   }
   else
      settings.UpdateMode = 0;

764
   var.key = CORE_OPTION_NAME "_region";
Libretro-Admin's avatar
Libretro-Admin committed
765
766
767

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
768
      if (!strcmp("Japan", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
769
         settings.dreamcast.region = 0;
770
      else if (!strcmp("USA", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
771
         settings.dreamcast.region = 1;
772
      else if (!strcmp("Europe", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
773
         settings.dreamcast.region = 2;
774
      else if (!strcmp("Default", var.value))
Libretro-Admin's avatar
Libretro-Admin committed
775
776
777
778
779
         settings.dreamcast.region = 3;
   }
   else
         settings.dreamcast.region = 3;

780
   var.key = CORE_OPTION_NAME "_language";
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("Japanese", var.value))
         settings.dreamcast.language = 0;
      else if (!strcmp("English", var.value))
         settings.dreamcast.language = 1;
      else if (!strcmp("German", var.value))
         settings.dreamcast.language = 2;
      else if (!strcmp("French", var.value))
         settings.dreamcast.language = 3;
      else if (!strcmp("Spanish", var.value))
         settings.dreamcast.language = 4;
      else if (!strcmp("Italian", var.value))
         settings.dreamcast.language = 5;
      else if (!strcmp("Default", var.value))
         settings.dreamcast.language = 6;
   }
   else
         settings.dreamcast.language = 6;

802
   var.key = CORE_OPTION_NAME "_div_matching";
803
804
805

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
806
      if (!strcmp("auto", var.value) && !settings.dynarec.ForceDisableDivMatching)
807
         settings.dynarec.DisableDivMatching = 0;
808
      else
809
810
811
         settings.dynarec.DisableDivMatching = 1;
   }

812
813
814
815
816
817
818
819
   var.key = CORE_OPTION_NAME "_force_wince";

   settings.dreamcast.ForceWinCE = false;
   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
   	settings.dreamcast.ForceWinCE = !strcmp("enabled", var.value);
   }

820
821
822
823
824
825
826
827
828
829
830
   var.key = CORE_OPTION_NAME "_anisotropic_filtering";

   settings.rend.AnisotropicFiltering = 4;
   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("off", var.value))
      	settings.rend.AnisotropicFiltering = 1;
      else
      	settings.rend.AnisotropicFiltering = std::max(1, std::min(16, atoi(var.value)));
   }

831
832
833
834
835
836
   var.key = CORE_OPTION_NAME "_pvr2_filtering";

   settings.rend.PowerVR2Filter = false;
   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
     	settings.rend.PowerVR2Filter = !strcmp("enabled", var.value);

837
#ifdef HAVE_TEXUPSCALE
838
   var.key = CORE_OPTION_NAME "_texupscale";
839
840
841
842

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("off", var.value))
843
         settings.rend.TextureUpscale = 1;
844
      else if (!strcmp("2x", var.value))
845
         settings.rend.TextureUpscale = 2;
846
      else if (!strcmp("4x", var.value))
847
848
849
         settings.rend.TextureUpscale = 4;
      else if (!strcmp("6x", var.value))
         settings.rend.TextureUpscale = 6;
850
   }
851
852
   else if (first_startup)
      settings.rend.TextureUpscale = 1;
853

854
   var.key = CORE_OPTION_NAME "_texupscale_max_filtered_texture_size";
855
856
857
858
859
860
861
862
863
864
865
866
867
868

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("256", var.value))
         settings.rend.MaxFilteredTextureSize = 256;
      else if (!strcmp("512", var.value))
         settings.rend.MaxFilteredTextureSize = 512;
      else if (!strcmp("1024", var.value))
         settings.rend.MaxFilteredTextureSize = 1024;
   }
   else
      settings.rend.MaxFilteredTextureSize = 256;
#endif

869
   var.key = CORE_OPTION_NAME "_enable_rttb";
870
871
872
873
874

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("enabled", var.value))
         settings.rend.RenderToTextureBuffer = true;
875
      else
876
         settings.rend.RenderToTextureBuffer = false;
877
   }
878
879
   else
      settings.rend.RenderToTextureBuffer = false;
Higor Eurípedes's avatar
Higor Eurípedes committed
880

881
   var.key = CORE_OPTION_NAME "_render_to_texture_upscaling";
882
883
884
885
886
887
888
889
890
891
892
893
894
895

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      char *pch;
      char str[100];
      sprintf(str, "%s", var.value);

      pch = strtok(str, "x");
      if (pch)
         settings.rend.RenderToTextureUpscale = strtoul(pch, NULL, 0);
   }
   else if (first_startup)
      settings.rend.RenderToTextureUpscale = 1;

896
897
898
#if !defined(TARGET_NO_THREADS)
   if (first_startup)
   {
899
	   var.key = CORE_OPTION_NAME "_threaded_rendering";
900
901
902
903
904
905
906
907
908
909

	   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
	   {
		   if (!strcmp("enabled", var.value))
			   settings.rend.ThreadedRendering = true;
		   else
			   settings.rend.ThreadedRendering = false;
	   }
	   else
		   settings.rend.ThreadedRendering = false;
910
911

	   if ( settings.rend.ThreadedRendering  )
912
913
914
      {
         bool save_state_in_background = true ;
         unsigned poll_type_early      = 1; /* POLL_TYPE_EARLY */
915
		   environ_cb(RETRO_ENVIRONMENT_SET_SAVE_STATE_IN_BACKGROUND, &save_state_in_background);
916
917
         environ_cb(RETRO_ENVIRONMENT_POLL_TYPE_OVERRIDE, &poll_type_early);
      }
918
919
920
   }
#endif

921
   var.key = CORE_OPTION_NAME "_synchronous_rendering";
922
923
924
925
926
927
928
929
930
931
   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
	   if (!strcmp("enabled", var.value))
		   settings.pvr.SynchronousRendering = 1;
	   else
		   settings.pvr.SynchronousRendering = 0;
   }
   else
	   settings.pvr.SynchronousRendering = 0;

932
933
934
935
936
937
938
939
940
941
942
   var.key = CORE_OPTION_NAME "_delay_frame_swapping";
   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
	   if (!strcmp("enabled", var.value))
		   settings.rend.DelayFrameSwapping = true;
	   else
		   settings.rend.DelayFrameSwapping = false;
   }
   else
   	settings.rend.DelayFrameSwapping = false;

943
   var.key = CORE_OPTION_NAME "_frame_skipping";
Flyinghead's avatar
Flyinghead committed
944
945
946
947
948
   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
	   if (!strcmp("disabled", var.value))
		   settings.pvr.ta_skip = 0;
	   else {
Libretro-Admin's avatar
Libretro-Admin committed
949
		   settings.pvr.ta_skip = std::max(0, std::min(6, var.value[0] - '0'));
Flyinghead's avatar
Flyinghead committed
950
951
952
953
954
	   }
   }
   else
	   settings.pvr.ta_skip = 0;

955
   var.key = CORE_OPTION_NAME "_enable_purupuru";
Higor Eurípedes's avatar
Higor Eurípedes committed
956
   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
957
958
959
960
   {
      if (enable_purupuru != (strcmp("enabled", var.value) == 0) && settings.System == DC_PLATFORM_DREAMCAST)
      {
      	enable_purupuru = (strcmp("enabled", var.value) == 0);
Flyinghead's avatar
Flyinghead committed
961
962
      	if (!first_startup)
      		maple_ReconnectDevices();
963
964
      }
   }
965

966
   var.key = CORE_OPTION_NAME "_analog_stick_deadzone";
967
968
969
970
971
   var.value = NULL;

   if ( environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value )
      input_set_deadzone_stick( atoi( var.value ) );

972
   var.key = CORE_OPTION_NAME "_trigger_deadzone";
973
974
975
976
   var.value = NULL;

   if ( environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value )
      input_set_deadzone_trigger( atoi( var.value ) );
David Walters's avatar
David Walters committed
977

978
   var.key = CORE_OPTION_NAME "_enable_dsp";
Libretro-Admin's avatar
Libretro-Admin committed
979
980
981
982
983
984
985
986
987
988
989
990
991

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("enabled", var.value))
      {
         settings.aica.DSPEnabled = true;
         settings.aica.NoBatch    = 1;
      }
      else
      {
         settings.aica.DSPEnabled = false;
      }
   }
Libretro-Admin's avatar
Libretro-Admin committed
992
   else if (first_run)
Libretro-Admin's avatar
Libretro-Admin committed
993
994
995
996
997
   {
      settings.aica.DSPEnabled = true;
      settings.aica.NoBatch    = 1;
   }

998
   var.key = CORE_OPTION_NAME "_digital_triggers";
David Walters's avatar
David Walters committed
999
1000
1001
1002
1003
1004
1005
1006
1007
1008

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("enabled", var.value))
         digital_triggers = true;
      else
         digital_triggers = false;
   }
   else
      digital_triggers = false;
1009

1010
   var.key = CORE_OPTION_NAME "_allow_service_buttons";
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("enabled", var.value))
         allow_service_buttons = true;
      else
         allow_service_buttons = false;
   }
   else
      allow_service_buttons = false;
Sven's avatar
Sven committed
1021

1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
   var.key = CORE_OPTION_NAME "_enable_naomi_15khz_dipswitch";

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("enabled", var.value))
         enable_naomi_15khz_dipswitch = true;
      else
         enable_naomi_15khz_dipswitch = false;
   }
   else
      enable_naomi_15khz_dipswitch = false;

   var.key = CORE_OPTION_NAME "_custom_textures";
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("enabled", var.value))
         settings.rend.CustomTextures = true;
      else
    	 settings.rend.CustomTextures = false;
   }
   else
	  settings.rend.CustomTextures = false;

1046
   var.key = CORE_OPTION_NAME "_dump_textures";
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057

   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
   {
      if (!strcmp("enabled", var.value))
         settings.rend.DumpTextures = true;
      else
    	 settings.rend.DumpTextures = false;
   }
   else
	  settings.rend.DumpTextures = false;

Sven's avatar
Sven committed
1058
1059
1060
1061
1062
   key[0] = '\0' ;

   var.key = key ;
   for ( i = 0 ; i < 4 ; i++)
   {
1063
1064
1065
1066
      lightgun_params[i].offscreen = true;	   
      lightgun_params[i].x = 0;	   
      lightgun_params[i].y = 0;	   
      lightgun_params[i].dirty = true;	   
1067
      lightgun_params[i].colour = LIGHTGUN_COLOR_OFF;
1068

1069
      snprintf(key, sizeof(key), CORE_OPTION_NAME "_lightgun%d_crosshair", i+1) ;
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084

      if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value  )
      {
         if (!strcmp("disabled", var.value))
        	 lightgun_params[i].colour = LIGHTGUN_COLOR_OFF;
         else if (!strcmp("White", var.value))
        	 lightgun_params[i].colour = LIGHTGUN_COLOR_WHITE;
         else if (!strcmp("Red", var.value))
        	 lightgun_params[i].colour = LIGHTGUN_COLOR_RED;
         else if (!strcmp("Green", var.value))
        	 lightgun_params[i].colour = LIGHTGUN_COLOR_GREEN;
         else if (!strcmp("Blue", var.value))
        	 lightgun_params[i].colour = LIGHTGUN_COLOR_BLUE;
      }
	   
Sven's avatar
Sven committed
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
      vmu_screen_params[i].vmu_screen_display = false ;
      vmu_screen_params[i].vmu_screen_position = UPPER_LEFT ;
      vmu_screen_params[i].vmu_screen_size_mult = 1 ;
      vmu_screen_params[i].vmu_pixel_on_R = VMU_SCREEN_COLOR_MAP[VMU_DEFAULT_ON].r ;
      vmu_screen_params[i].vmu_pixel_on_G = VMU_SCREEN_COLOR_MAP[VMU_DEFAULT_ON].g ;
      vmu_screen_params[i].vmu_pixel_on_B = VMU_SCREEN_COLOR_MAP[VMU_DEFAULT_ON].b ;
      vmu_screen_params[i].vmu_pixel_off_R = VMU_SCREEN_COLOR_MAP[VMU_DEFAULT_OFF].r ;
      vmu_screen_params[i].vmu_pixel_off_G = VMU_SCREEN_COLOR_MAP[VMU_DEFAULT_OFF].g ;
      vmu_screen_params[i].vmu_pixel_off_B = VMU_SCREEN_COLOR_MAP[VMU_DEFAULT_OFF].b ;
      vmu_screen_params[i].vmu_screen_opacity = 0xFF ;
      vmu_screen_params[i].vmu_screen_needs_update = true ;

1097
      snprintf(key, sizeof(key), CORE_OPTION_NAME "_vmu%d_screen_display", i+1) ;
Sven's avatar
Sven committed
1098
1099
1100
1101
1102

      if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && !strcmp("enabled", var.value) )
       	 vmu_screen_params[i].vmu_screen_display = true ;


1103
      snprintf(key, sizeof(key), CORE_OPTION_NAME "_vmu%d_screen_position", i+1) ;
Sven's avatar
Sven committed
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116

      if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value  )
      {
         if (!strcmp("Upper Left", var.value))
        	 vmu_screen_params[i].vmu_screen_position = UPPER_LEFT;
         else if (!strcmp("Upper Right", var.value))
        	 vmu_screen_params[i].vmu_screen_position = UPPER_RIGHT;
         else if (!strcmp("Lower Left", var.value))
        	 vmu_screen_params[i].vmu_screen_position = LOWER_LEFT;
         else if (!strcmp("Lower Right", var.value))
        	 vmu_screen_params[i].vmu_screen_position = LOWER_RIGHT;
      }

1117
      snprintf(key, sizeof(key), CORE_OPTION_NAME "_vmu%d_screen_size_mult", i+1) ;
Sven's avatar
Sven committed
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132

      if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value  )
      {
         if (!strcmp("1x", var.value))
        	 vmu_screen_params[i].vmu_screen_size_mult = 1;
         else if (!strcmp("2x", var.value))
        	 vmu_screen_params[i].vmu_screen_size_mult = 2;
         else if (!strcmp("3x", var.value))
        	 vmu_screen_params[i].vmu_screen_size_mult = 3;
         else if (!strcmp("4x", var.value))
        	 vmu_screen_params[i].vmu_screen_size_mult = 4;
         else if (!strcmp("5x", var.value))
        	 vmu_screen_params[i].vmu_screen_size_mult = 5;
      }

1133
      snprintf(key, sizeof(key), CORE_OPTION_NAME "_vmu%d_screen_opacity", i+1) ;
Sven's avatar
Sven committed
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158

      if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value  )
      {
         if (!strcmp("100%", var.value))
        	 vmu_screen_params[i].vmu_screen_opacity = 255;
         else if