forked from m4xw/dosbox-svn
/
libretro.cpp
1630 lines (1393 loc) · 50.4 KB
/
libretro.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2002-2018 - The DOSBox Team
* Copyright (C) 2015-2018 - Andrés Suárez
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <algorithm>
#include <string>
#include <libgen.h>
#include <stdlib.h>
#include <stdarg.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
#include <cerrno>
#include <cmath>
#include <libco.h>
#include "libretro.h"
#include "libretro_dosbox.h"
#include "file/file_path.h"
#include "libretro_core_options.h"
#include "setup.h"
#include "dosbox.h"
#include "mapper.h"
#include "render.h"
#include "mixer.h"
#include "control.h"
#include "pic.h"
#include "joystick.h"
#include "ints/int10.h"
#include "dos/drives.h"
#include "programs.h"
#if defined(VITA)
# include <psp2/io/fcntl.h>
# include <psp2/io/dirent.h>
# include <psp2/io/stat.h>
#elif defined(PSP)
# include <pspiofilemgr.h>
#endif
#ifdef __QNX__
#include <math.h>
#endif
#ifdef ANDROID
#include "nonlibc.h"
#endif
#define RETRO_DEVICE_JOYSTICK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 1)
#ifndef PATH_MAX_LENGTH
#define PATH_MAX_LENGTH 4096
#endif
#define CORE_VERSION "0.74-SVN"
#ifndef PATH_SEPARATOR
#if defined(WINDOWS_PATH_STYLE) || defined(_WIN32)
#define PATH_SEPARATOR '\\'
#else
#define PATH_SEPARATOR '/'
#endif
#endif
#ifdef WITH_FAKE_SDL
bool startup_state_capslock;
bool startup_state_numlock;
#endif
#ifdef HAVE_LIBNX
#include <switch.h>
extern "C" Jit dynarec_jit;
#endif
#ifdef _WIN32
char slash = '\\';
#else
char slash = '/';
#endif
cothread_t mainThread;
cothread_t emuThread;
bool autofire;
bool dosbox_initialiazed = false;
bool midi_enable = false;
unsigned deadzone;
float mouse_speed_factor_x = 1.0;
float mouse_speed_factor_y = 1.0;
Bit32u MIXER_RETRO_GetFrequency();
void MIXER_CallBack(void * userdata, uint8_t *stream, int len);
extern Config* control;
extern Bit8u herc_pal;
MachineType machine = MCH_VGA;
SVGACards svgaCard = SVGA_None;
enum { CDROM_USE_SDL, CDROM_USE_ASPI, CDROM_USE_IOCTL_DIO, CDROM_USE_IOCTL_DX, CDROM_USE_IOCTL_MCI };
/* input variables */
bool gamepad[16]; /* true means gamepad, false means joystick */
bool connected[16];
bool emulated_mouse;
/* core option variables */
static bool use_core_options;
static bool adv_core_options;
core_timing_mode core_timing = CORE_TIMING_UNSYNCED;
/* directories */
std::string retro_save_directory;
std::string retro_system_directory;
std::string retro_content_directory;
std::string retro_library_name = "DOSBox-SVN";
/* libretro variables */
retro_video_refresh_t video_cb;
retro_audio_sample_batch_t audio_batch_cb;
retro_input_poll_t poll_cb;
retro_input_state_t input_cb;
retro_environment_t environ_cb;
static void RETRO_CALLCONV fallback_log(enum retro_log_level level, const char *fmt, ...);
retro_log_printf_t log_cb = fallback_log;
extern struct retro_midi_interface *retro_midi_interface;
/* DOSBox state */
static std::string loadPath;
static std::string gamePath;
static std::string configPath;
bool dosbox_exit;
static bool frontend_exit;
static bool is_restarting = false;
/* video variables */
extern Bitu RDOSGFXwidth, RDOSGFXheight, RDOSGFXpitch;
extern unsigned RDOSGFXcolorMode;
unsigned currentWidth, currentHeight;
#define DEFAULT_FPS 60.0f
float currentFPS = DEFAULT_FPS;
static float current_aspect_ratio = 0;
/* audio variables */
static uint8_t audioData[829 * 4]; // 49716hz max
static uint32_t samplesPerFrame = 735;
static struct retro_midi_interface midi_interface;
bool disney_init;
/* callbacks */
void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
void retro_set_audio_sample(retro_audio_sample_t cb) { }
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; }
/* disk-control variables */
char disk_array[16][PATH_MAX_LENGTH];
unsigned disk_index = 0;
unsigned disk_count = 0;
bool disk_tray_ejected;
char disk_load_image[PATH_MAX_LENGTH];
bool mount_overlay = true;
/* helper functions */
static char last_written_character = 0;
static void RETRO_CALLCONV fallback_log(enum retro_log_level level, const char *fmt, ...)
{
va_list va;
(void)level;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
}
void write_out_buffer(const char * format,...) {
char buf[2048];
va_list msg;
va_start(msg,format);
#ifdef ANDROID
portable_vsnprintf(buf,2047,format,msg);
#else
vsnprintf(buf,2047,format,msg);
#endif
va_end(msg);
Bit16u size = (Bit16u)strlen(buf);
dos.internal_output=true;
for(Bit16u i = 0; i < size;i++) {
Bit8u out;Bit16u s=1;
if (buf[i] == 0xA && last_written_character != 0xD) {
out = 0xD;DOS_WriteFile(STDOUT,&out,&s);
}
last_written_character = out = buf[i];
DOS_WriteFile(STDOUT,&out,&s);
}
dos.internal_output=false;
}
void write_out (const char * format,...)
{
write_out_buffer("\n");
write_out_buffer(format);
}
bool mount_overlay_filesystem(char drive, const char* path)
{
Bit16u sizes[4];
Bit8u mediaid;
Bit8u o_error = 0;
std::string str_size;
str_size="512,32,32765,16000";
mediaid=0xF8;
Bit8u bit8size=(Bit8u) sizes[1];
DOS_Drive * overlay;
localDrive* ldp = dynamic_cast<localDrive*>(Drives[drive-'A']);
cdromDrive* cdp = dynamic_cast<cdromDrive*>(Drives[drive-'A']);
log_cb(RETRO_LOG_INFO, "[dosbox] mounting %s in %c as overlay\n", path, drive);
struct stat path_stat;
if (stat(path, &path_stat) == 0 && S_ISDIR(path_stat.st_mode))
{
log_cb(RETRO_LOG_INFO, "[dosbox] save directory already exists %s\n", path);
}
else
{
log_cb(RETRO_LOG_INFO, "[dosbox] creating save directory %s\n", path);
#if (WIN32)
if (mkdir(path) == -1)
#else
if (mkdir(path, 0700) == -1)
#endif
{
log_cb(RETRO_LOG_INFO, "[dosbox] error creating save directory %s\n", path);
return false;
}
}
if (!Drives[drive-'A'])
{
log_cb(RETRO_LOG_INFO, "[dosbox] base drive %c is not mounted\n", drive);
write_out("No basedrive mounted yet!");
return false;
}
if (!ldp || cdp)
{
log_cb(RETRO_LOG_INFO, "[dosbox] base drive %c is not compatible\n", drive);
return false;
}
std::string base = ldp->getBasedir();
overlay = new Overlay_Drive(base.c_str(), path, sizes[0], bit8size, sizes[2], sizes[3], mediaid, o_error);
if (overlay)
{
if (o_error)
{
if (o_error == 1)
{
log_cb(RETRO_LOG_INFO, "[dosbox] can't mix absolute and relative paths");
}
else if (o_error == 2)
{
log_cb(RETRO_LOG_INFO, "[dosbox] overlay can't be in the same underlying file system");
}
else
{
log_cb(RETRO_LOG_INFO, "[dosbox] something went wrong");
}
delete overlay;
return false;
}
delete Drives[drive-'A'];
Drives[drive-'A'] = 0;
}
else
{
log_cb(RETRO_LOG_INFO, "[dosbox] overlay construction failed");
return false;
}
Drives[drive - 'A'] = overlay;
mem_writeb(Real2Phys(dos.tables.mediaid) + (drive-'A') * 9, overlay->GetMediaByte());
std::string label;
label = drive; label += "_OVERLAY";
overlay->dirCache.SetLabel(label.c_str(), false, false);
return true;
}
bool mount_disk_image(const char *path, bool silent)
{
char msg[256];
if(control->SecureMode())
{
log_cb(RETRO_LOG_INFO, "[dosbox] this operation is not permitted in secure mode\n");
return false;
}
std::string extension = strrchr(path, '.');
if (extension == ".img")
log_cb(RETRO_LOG_INFO, "[dosbox] mounting disk as floppy %s\n", path);
else if (extension == ".iso" || extension == ".cue")
log_cb(RETRO_LOG_INFO, "[dosbox] mounting disk as cdrom %s\n", path);
else
{
log_cb(RETRO_LOG_INFO, "[dosbox] unsupported disk image\n %s", extension.c_str());
return false;
}
if (disk_count == 0)
{
log_cb(RETRO_LOG_INFO, "[dosbox] no disks added to index\n");
return false;
}
if (extension == ".img")
{
int error = -1;
char drive = 'A';
Bit8u mediaid=0xF0;
Bit16u sizes[4];
std::string fstype="floppy";
std::string str_size;
std::string label;
DOS_Drive* floppy = new fatDrive(path, sizes[0],sizes[1],sizes[2],sizes[3],0);
if(!(dynamic_cast<fatDrive*>(floppy))->created_successfully)
return false;
DriveManager::AppendDisk(drive - 'A', floppy);
DriveManager::InitializeDrive(drive - 'A');
/* set the correct media byte in the table */
mem_writeb(Real2Phys(dos.tables.mediaid) + (drive - 'A') * 9, mediaid);
/* command uses dta so set it to our internal dta */
RealPt save_dta = dos.dta();
dos.dta(dos.tables.tempdta);
for(Bitu i = 0; i < DOS_DRIVES; i++)
if (Drives[i]) Drives[i]->EmptyCache();
DriveManager::CycleDisks(drive - 'A', true);
snprintf(msg, sizeof(msg), "Drive %c is mounted as %s.\n", drive, path);
if (!silent) write_out(msg);
return true;
}
else if (extension == ".iso" || extension == ".cue")
{
int error = -1;
char drive = 'D';
Bit8u mediaid = 0xF8;
std::string fstype="iso";
MSCDEX_SetCDInterface(CDROM_USE_SDL, -1);
DOS_Drive* iso = new isoDrive(drive, path, mediaid, error);
switch (error) {
case 0: break;
case 1:
snprintf(msg, sizeof(msg), "MSCDEX: Failure: Drive-letters of multiple CD-ROM drives have to be continuous.\n");
log_cb(RETRO_LOG_INFO, "[dosbox] %s", msg);
if (!silent) write_out(msg);
return false;
case 2:
snprintf(msg, sizeof(msg), "MSCDEX: Failure: Not yet supported.");
log_cb(RETRO_LOG_INFO, "[dosbox] %s", msg);
if (!silent) write_out(msg);
return false;
case 3:
snprintf(msg, sizeof(msg), "MSCDEX: Specified location is not a CD-ROM drive.\n");
log_cb(RETRO_LOG_INFO, "[dosbox] %s", msg);
if (!silent) write_out(msg);
return false;
case 4:
snprintf(msg, sizeof(msg), "MSCDEX: Failure: Invalid file or unable to open.\n");
log_cb(RETRO_LOG_INFO, "[dosbox] %s", msg);
if (!silent) write_out(msg);
return false;
case 5:
snprintf(msg, sizeof(msg), "MSCDEX: Failure: Too many CD-ROM drives (max: 5). MSCDEX Installation failed.\n");
log_cb(RETRO_LOG_INFO, "[dosbox] %s", msg);
if (!silent) write_out(msg);
return false;
case 6:
snprintf(msg, sizeof(msg), "MSCDEX: Mounted subdirectory: limited support.\n");
log_cb(RETRO_LOG_INFO, "[dosbox] %s", msg);
if (!silent) write_out(msg);
return false;
default:
snprintf(msg, sizeof(msg), "MSCDEX: Failure: Unknown error.\n");
log_cb(RETRO_LOG_INFO, "[dosbox] %s", msg);
if (!silent) write_out(msg);
return false;
}
DriveManager::AppendDisk(drive - 'A', iso);
DriveManager::InitializeDrive(drive - 'A');
/* set the correct media byte in the table */
mem_writeb(Real2Phys(dos.tables.mediaid) + (drive - 'A') * 9, mediaid);
for(Bitu i = 0; i < DOS_DRIVES; i++)
if (Drives[i]) Drives[i]->EmptyCache();
DriveManager::CycleDisks(drive - 'A', true);
snprintf(msg, sizeof(msg), "Drive %c is mounted as %s.\n", drive, path);
log_cb(RETRO_LOG_INFO, "[dosbox] %s", msg);
if (!silent) write_out(msg);
return true;
}
else
return false;
return false;
}
bool unmount_disk_image(char *path)
{
char drive;
std::string extension = strrchr(path, '.');
if (disk_count == 0)
{
log_cb(RETRO_LOG_INFO, "[dosbox] no disks added to index\n");
return false;
}
if (extension == ".img")
{
log_cb(RETRO_LOG_INFO, "[dosbox] unmounting floppy %s\n", path);
drive = 'A';
}
else if (extension == ".iso" || extension == ".cue")
{
log_cb(RETRO_LOG_INFO, "[dosbox] umounting cdrom %s\n", path);
drive = 'D';
}
else
{
log_cb(RETRO_LOG_INFO, "[dosbox] unsupported disk image\n %s", extension.c_str());
return false;
}
if (Drives[drive - 'A'])
DriveManager::UnmountDrive(drive - 'A');
Drives[drive - 'A'] = 0;
DriveManager::CycleDisks(drive - 'A', true);
return true;
}
bool compare_dosbox_variable(std::string section_string, std::string var_string, std::string val_string)
{
bool ret = false;
Section* section = control->GetSection(section_string);
Section_prop *secprop = static_cast <Section_prop*>(section);
if (secprop)
ret =section->GetPropValue(var_string) == val_string;
return ret;
}
bool update_dosbox_variable(bool autoexec, std::string section_string, std::string var_string, std::string val_string)
{
bool ret = false;
if (dosbox_initialiazed)
{
if (compare_dosbox_variable(section_string, var_string, val_string))
return false;
}
Section* section = control->GetSection(section_string);
Section_prop *secprop = static_cast <Section_prop*>(section);
if (secprop)
{
if (!autoexec)
section->ExecuteDestroy(false);
std::string inputline = var_string + "=" + val_string;
ret = section->HandleInputline(inputline.c_str());
if (!autoexec)
section->ExecuteInit(false);
}
log_cb(RETRO_LOG_INFO, "[dosbox] variable %s::%s updated\n", section_string.c_str(), var_string.c_str(), val_string.c_str());
return ret;
}
/* libretro core implementation */
static RETRO_CALLCONV unsigned disk_get_num_images()
{
return disk_count;
}
static RETRO_CALLCONV bool disk_get_eject_state()
{
return disk_tray_ejected;
}
static RETRO_CALLCONV unsigned disk_get_image_index()
{
return disk_index;
}
static RETRO_CALLCONV bool disk_set_eject_state(bool ejected)
{
if (ejected)
log_cb(RETRO_LOG_INFO, "[dosbox] tray open\n");
else
log_cb(RETRO_LOG_INFO, "[dosbox] tray closed\n");
disk_tray_ejected = ejected;
if (disk_count == 0)
return true;
if (ejected)
{
if(unmount_disk_image(disk_array[disk_get_image_index()]))
return true;
else
return false;
}
else
{
if(mount_disk_image(disk_array[disk_get_image_index()], true))
return true;
else
return false;
}
return false;
}
static RETRO_CALLCONV bool disk_set_image_index(unsigned index)
{
if (index < disk_get_num_images())
{
disk_index = index;
log_cb(RETRO_LOG_INFO, "[dosbox] disk index %u\n", index);
return true;
}
return false;
}
static RETRO_CALLCONV bool disk_add_image_index()
{
disk_count++;
log_cb(RETRO_LOG_INFO, "[dosbox] disk count %u\n", disk_count);
return true;
}
static RETRO_CALLCONV bool disk_replace_image_index(unsigned index, const struct retro_game_info *info)
{
if (index < disk_get_num_images())
snprintf(disk_array[index], sizeof(char) * PATH_MAX_LENGTH, "%s", info->path);
else
disk_count--;
return true;
}
static struct retro_disk_control_callback disk_interface = {
disk_set_eject_state,
disk_get_eject_state,
disk_get_image_index,
disk_set_image_index,
disk_get_num_images,
disk_replace_image_index,
disk_add_image_index,
};
static void leave_thread(Bitu)
{
MIXER_CallBack(0, audioData, samplesPerFrame * 4);
co_switch(mainThread);
if (core_timing != CORE_TIMING_SYNCED)
/* Schedule the next frontend interrupt */
PIC_AddEvent(leave_thread, 1000.0f / currentFPS);
}
static void update_gfx_mode(bool change_fps)
{
const float old_fps = currentFPS;
struct retro_system_av_info new_av_info;
bool cb_error = false;
retro_get_system_av_info(&new_av_info);
new_av_info.geometry.base_width = RDOSGFXwidth;
new_av_info.geometry.base_height = RDOSGFXheight;
new_av_info.geometry.aspect_ratio = dosbox_aspect_ratio;
if (change_fps)
{
const float new_fps = (core_timing == CORE_TIMING_SYNCED || core_timing == CORE_TIMING_MATCH_FPS)
? render.src.fps
: DEFAULT_FPS;
new_av_info.timing.fps = new_fps;
new_av_info.timing.sample_rate = (double)MIXER_RETRO_GetFrequency();
cb_error = !environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &new_av_info);
if (cb_error)
log_cb(RETRO_LOG_WARN, "[dosbox] SET_SYSTEM_AV_INFO failed\n");
currentFPS = new_fps;
}
else
{
cb_error = !environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &new_av_info);
if (cb_error)
log_cb(RETRO_LOG_WARN, "[dosbox] SET_GEOMETRY failed\n");
}
if (!cb_error)
log_cb (RETRO_LOG_INFO,
"[dosbox] resolution changed %dx%d @ %.3fHz AR: %.5f => %dx%d @ %.3fHz AR: %.5f\n",
currentWidth, currentHeight, old_fps, current_aspect_ratio,
RDOSGFXwidth, RDOSGFXheight, currentFPS, dosbox_aspect_ratio);
currentWidth = RDOSGFXwidth;
currentHeight = RDOSGFXheight;
current_aspect_ratio = dosbox_aspect_ratio;
}
bool check_blaster_variables(bool autoexec)
{
struct retro_variable var = {0};
bool ret = false;
var.key = "dosbox_svn_sblaster_type";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
update_dosbox_variable(autoexec, "sblaster", "sbtype", var.value);
ret = strcmp(var.value, "none") != 0 ? true : false;
}
var.key = "dosbox_svn_sblaster_base";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "sblaster", "sbbase", var.value);
var.key = "dosbox_svn_sblaster_irq";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "sblaster", "irq", var.value);
var.key = "dosbox_svn_sblaster_dma";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "sblaster", "dma", var.value);
var.key = "dosbox_svn_sblaster_hdma";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "sblaster", "hdma", var.value);
var.key = "dosbox_svn_sblaster_opl_mode";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "sblaster", "oplmode", var.value);
var.key = "dosbox_svn_sblaster_opl_emu";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "sblaster", "oplemu", var.value);
return ret;
}
bool check_gus_variables(bool autoexec)
{
struct retro_variable var = {0};
bool ret = false;
var.key = "dosbox_svn_gus";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
update_dosbox_variable(autoexec, "gus", "gus", var.value);
ret = strcmp(var.value, "true") == 0;
}
var.key = "dosbox_svn_gusrate";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "gus", "gusrate", var.value);
var.key = "dosbox_svn_gusbase";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "gus", "gusbase", var.value);
var.key = "dosbox_svn_gusirq";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "gus", "gusirq", var.value);
var.key = "dosbox_svn_gusdma";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(autoexec, "gus", "gusdma", var.value);
return ret;
}
void core_autoexec()
{
check_blaster_variables(true);
check_gus_variables(true);
}
void check_variables()
{
struct retro_variable var = {0};
static unsigned cycles, cycles_fine, cycles_limit;
static unsigned cycles_multiplier, cycles_multiplier_fine;
static bool update_cycles = false;
char cycles_mode[20];
char machine_type[20];
struct retro_core_option_display option_display;
bool blaster = false;
bool gus = false;
var.key = "dosbox_svn_use_options";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "true") == 0)
use_core_options = true;
else
use_core_options = false;
}
var.key = "dosbox_svn_core_timing";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
core_timing_mode old_timing = core_timing;
if (strcmp(var.value, "external") == 0)
core_timing = CORE_TIMING_SYNCED;
else if (strcmp(var.value, "internal_variable") == 0)
core_timing = CORE_TIMING_MATCH_FPS;
else
core_timing = CORE_TIMING_UNSYNCED;
if (dosbox_initialiazed)
{
if (old_timing == CORE_TIMING_SYNCED && core_timing != CORE_TIMING_SYNCED)
{
DOSBOX_UnlockSpeed(false);
PIC_AddEvent(leave_thread, 1000.0f / currentFPS);
}
if (old_timing != CORE_TIMING_SYNCED && core_timing == CORE_TIMING_SYNCED)
DOSBOX_UnlockSpeed(true);
if (old_timing != CORE_TIMING_UNSYNCED && core_timing == CORE_TIMING_UNSYNCED)
update_gfx_mode(true);
}
snprintf(cycles_mode, sizeof(cycles_mode), "%s", "fixed");
update_cycles = true;
}
if (!use_core_options)
return;
var.key = "dosbox_svn_adv_options";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
adv_core_options = strcmp(var.value, "true") == 0 ? true : false;
}
/* save machine type for option hiding purpose */
var.key = "dosbox_svn_machine_type";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
snprintf(machine_type, sizeof(machine_type), "%s", var.value);
if (!dosbox_initialiazed)
{
var.key = "dosbox_svn_memory_size";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
update_dosbox_variable(false, "dosbox", "memsize", var.value);
var.key = "dosbox_svn_machine_type";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
svgaCard = SVGA_None;
machine = MCH_VGA;
int10.vesa_nolfb = false;
int10.vesa_oldvbe = false;
if (strcmp(var.value, "hercules") == 0)
machine = MCH_HERC;
else if (strcmp(var.value, "cga") == 0)
machine = MCH_CGA;
else if (strcmp(var.value, "pcjr") == 0)
machine = MCH_PCJR;
else if (strcmp(var.value, "tandy") == 0)
machine = MCH_TANDY;
else if (strcmp(var.value, "ega") == 0)
machine = MCH_EGA;
else if (strcmp(var.value, "svga_s3") == 0)
{
machine = MCH_VGA;
svgaCard = SVGA_S3Trio;
}
else if (strcmp(var.value, "svga_et4000") == 0)
{
machine = MCH_VGA;
svgaCard = SVGA_TsengET4K;
}
else if (strcmp(var.value, "svga_et3000") == 0)
{
machine = MCH_VGA;
svgaCard = SVGA_TsengET3K;
}
else if (strcmp(var.value, "svga_paradise") == 0)
{
machine = MCH_VGA;
svgaCard = SVGA_ParadisePVGA1A;
}
else if (strcmp(var.value, "vesa_nolfb") == 0)
{
machine = MCH_VGA;
svgaCard = SVGA_S3Trio;
int10.vesa_nolfb = true;
}
else if (strcmp(var.value, "vesa_nolfb") == 0)
{
machine = MCH_VGA;
svgaCard = SVGA_S3Trio;
int10.vesa_oldvbe = true;
}
else
{
machine = MCH_VGA;
svgaCard = SVGA_None;
}
update_dosbox_variable(false, "dosbox", "machine", var.value);
}
var.key = "dosbox_svn_save_overlay";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && !dosbox_initialiazed)
{
if (strcmp(var.value, "true") == 0)
mount_overlay = true;
else
mount_overlay = false;
}
}
else
{
/* hercules core options */
var.key = "dosbox_svn_machine_hercules_palette";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && machine == MCH_HERC)
{
herc_pal = atoi(var.value);
Herc_Palette();
VGA_DAC_CombineColor(1,7);
}
/* cga core options */
var.key = "dosbox_svn_machine_cga_composite_mode";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && machine == MCH_CGA)
CGA_Composite_Mode(atoi(var.value));
var.key = "dosbox_svn_machine_cga_model";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && machine == MCH_CGA)
CGA_Model(var.value == 0 ? true : false);
blaster = check_blaster_variables(false);
gus = check_gus_variables(false);
var.key = "dosbox_svn_emulated_mouse";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
bool prev = emulated_mouse;
if (strcmp(var.value, "true") == 0)
emulated_mouse = true;
else
emulated_mouse = false;
if (prev != emulated_mouse)
MAPPER_Init();
}
var.key = "dosbox_svn_emulated_mouse_deadzone";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
unsigned prev = deadzone;
deadzone = atoi(var.value);
if (prev != deadzone)
MAPPER_Init();
}
var.key = "dosbox_svn_mouse_speed_factor_x";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
mouse_speed_factor_x = atof(var.value);
var.key = "dosbox_svn_mouse_speed_factor_y";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
mouse_speed_factor_y = atof(var.value);
var.key = "dosbox_svn_cpu_cycles_mode";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (core_timing != CORE_TIMING_SYNCED)
snprintf(cycles_mode, sizeof(cycles_mode), "%s", var.value);
else
snprintf(cycles_mode, sizeof(cycles_mode), "%s", "fixed");
update_cycles = true;
}
var.key = "dosbox_svn_cpu_cycles_limit";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
cycles_limit = atoi(var.value);
update_cycles = true;
}
var.key = "dosbox_svn_cpu_cycles";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
cycles = atoi(var.value);
update_cycles = true;
}
var.key = "dosbox_svn_cpu_cycles_multiplier";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
cycles_multiplier = atoi(var.value);
update_cycles = true;
}
var.key = "dosbox_svn_cpu_cycles_fine";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
cycles_fine = atoi(var.value);
update_cycles = true;
}
var.key = "dosbox_svn_cpu_cycles_multiplier_fine";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
cycles_multiplier_fine = atoi(var.value);