/
mame2003.c
1624 lines (1368 loc) · 64 KB
/
mame2003.c
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
/*********************************************************************
mame2003.c
a port of mame 0.78 to the libretro API
*********************************************************************/
#include <stdint.h>
#include <string/stdstring.h>
#include <libretro.h>
#include <file/file_path.h>
#include "mame.h"
#include "driver.h"
#include "state.h"
#include "log.h"
#include "input.h"
#include "inptport.h"
#include "fileio.h"
#include "controls.h"
static const struct GameDriver *game_driver;
static float delta_samples;
int samples_per_frame = 0;
short* samples_buffer;
short* conversion_buffer;
int usestereo = 1;
int16_t prev_pointer_x;
int16_t prev_pointer_y;
unsigned retroColorMode;
unsigned long lastled = 0;
int16_t XsoundBuffer[2048];
bool is_neogeo = false;
bool is_stv = false;
extern const struct KeyboardInfo retroKeys[];
extern int retroKeyState[512];
extern int retroJsState[72];
extern int16_t mouse_x[4];
extern int16_t mouse_y[4];
extern struct osd_create_params videoConfig;
extern int16_t analogjoy[4][4];
struct ipd *default_inputs; /* pointer the array of structs with default MAME input mappings and labels */
retro_log_printf_t log_cb;
struct retro_perf_callback perf_cb;
retro_environment_t environ_cb = NULL;
retro_video_refresh_t video_cb = NULL;
static retro_input_poll_t poll_cb = NULL;
static retro_input_state_t input_cb = NULL;
static retro_audio_sample_batch_t audio_batch_cb = NULL;
retro_set_led_state_t led_state_cb = NULL;
bool old_dual_joystick_state = false; /* used to track when this core option changes */
/******************************************************************************
private function prototypes
******************************************************************************/
static void init_core_options(void);
void init_option(struct retro_variable *option, const char *key, const char *value);
static void update_variables(bool first_time);
static void check_system_specs(void);
void retro_describe_buttons(void);
/******************************************************************************
implementation of key libretro functions
******************************************************************************/
void retro_init (void)
{
struct retro_log_callback log;
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
log_cb = log.log;
else
log_cb = NULL;
#ifdef LOG_PERFORMANCE
environ_cb(RETRO_ENVIRONMENT_GET_PERF_INTERFACE, &perf_cb);
#endif
options.use_samples = 1;
check_system_specs();
}
static void check_system_specs(void)
{
/* TODO - set variably */
/* Midway DCS - Mortal Kombat/NBA Jam etc. require level 9 */
unsigned level = 10;
environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
}
void retro_set_environment(retro_environment_t cb)
{
environ_cb = cb;
}
static void init_core_options(void)
{
int default_index = 0;
int effective_index = 0;
static struct retro_variable default_options[OPT_end + 1]; /* need the plus one for the NULL entries at the end */
static struct retro_variable effective_options[OPT_end + 1];
init_option(&default_options[OPT_FRAMESKIP], APPNAME"_frameskip", "Frameskip; 0|1|2|3|4|5");
init_option(&default_options[OPT_INPUT_INTERFACE], APPNAME"_input_interface", "Input interface; retropad|mame_keyboard|simultaneous");
init_option(&default_options[OPT_RETROPAD_LAYOUT], APPNAME"_retropad_layout", "RetroPad Layout; 10-Button Arcade|modern|SNES|MAME classic");
#if defined(__IOS__)
init_option(&default_options[OPT_MOUSE_DEVICE], APPNAME"_mouse_device", "Mouse Device; pointer|mouse|disabled");
#else
init_option(&default_options[OPT_MOUSE_DEVICE], APPNAME"_mouse_device", "Mouse Device; mouse|pointer|disabled");
#endif
init_option(&default_options[OPT_CROSSHAIR_ENABLED], APPNAME"_crosshair_enabled", "Show Lightgun crosshair; enabled|disabled");
init_option(&default_options[OPT_SKIP_DISCLAIMER], APPNAME"_skip_disclaimer", "Skip Disclaimer; disabled|enabled");
init_option(&default_options[OPT_SKIP_WARNINGS], APPNAME"_skip_warnings", "Skip Warnings; disabled|enabled");
init_option(&default_options[OPT_DISPLAY_SETUP], APPNAME"_display_setup", "Display MAME menu; disabled|enabled");
init_option(&default_options[OPT_BRIGHTNESS], APPNAME"_brightness",
"Brightness; 1.0|0.2|0.3|0.4|0.5|0.6|0.7|0.8|0.9|1.1|1.2|1.3|1.4|1.5|1.6|1.7|1.8|1.9|2.0");
init_option(&default_options[OPT_GAMMA], APPNAME"_gamma",
"Gamma correction; 1.2|0.5|0.6|0.7|0.8|0.9|1.1|1.2|1.3|1.4|1.5|1.6|1.7|1.8|1.9|2.0");
init_option(&default_options[OPT_BACKDROP], APPNAME"_enable_backdrop", "EXPERIMENTAL: Use Backdrop artwork (Restart); disabled|enabled");
init_option(&default_options[OPT_NEOGEO_BIOS], APPNAME"_neogeo_bios",
"Specify Neo Geo BIOS (Restart); default|euro|euro-s1|us|us-e|asia|japan|japan-s2|unibios33|unibios20|unibios13|unibios11|unibios10|debug|asia-aes");
init_option(&default_options[OPT_STV_BIOS], APPNAME"_stv_bios", "Specify Sega ST-V BIOS (Restart); default|japan|japana|us|japan_b|taiwan|europe");
init_option(&default_options[OPT_SHARE_DIAL], APPNAME"_dialsharexy", "Share 2 player dial controls across one X/Y device; disabled|enabled");
init_option(&default_options[OPT_DUAL_JOY], APPNAME"_dual_joysticks", "Dual Joystick Mode (Players 1 & 2); disabled|enabled");
init_option(&default_options[OPT_RSTICK_BTNS], APPNAME"_rstick_to_btns", "Right Stick to Buttons; enabled|disabled");
init_option(&default_options[OPT_TATE_MODE], APPNAME"_tate_mode", "TATE Mode; disabled|enabled");
init_option(&default_options[OPT_VECTOR_RESOLUTION], APPNAME"_vector_resolution_multiplier",
"EXPERIMENTAL: Vector resolution multiplier (Restart); 1|2|3|4|5|6");
init_option(&default_options[OPT_VECTOR_ANTIALIAS], APPNAME"_vector_antialias", "EXPERIMENTAL: Vector antialias; disabled|enabled");
init_option(&default_options[OPT_VECTOR_TRANSLUCENCY], APPNAME"_vector_translucency", "Vector translucency; enabled|disabled");
init_option(&default_options[OPT_VECTOR_BEAM], APPNAME"_vector_beam_width", "EXPERIMENTAL: Vector beam width; 1|2|3|4|5");
init_option(&default_options[OPT_VECTOR_FLICKER], APPNAME"_vector_flicker", "Vector flicker; 20|0|10|20|30|40|50|60|70|80|90|100");
init_option(&default_options[OPT_VECTOR_INTENSITY], APPNAME"_vector_intensity", "Vector intensity; 1.5|0.5|1|2|2.5|3");
init_option(&default_options[OPT_SKIP_CRC], APPNAME"_skip_rom_verify", "EXPERIMENTAL: Skip ROM verification (Restart); disabled|enabled");
init_option(&default_options[OPT_SAMPLE_RATE], APPNAME"_sample_rate", "Sample Rate (KHz); 48000|8000|11025|22050|44100");
init_option(&default_options[OPT_DCS_SPEEDHACK], APPNAME"_dcs_speedhack", "DCS Speedhack; enabled|disabled");
init_option(&default_options[OPT_end], NULL, NULL);
for(default_index = 0; default_index < (OPT_end + 1); default_index++)
{
if((default_index == OPT_STV_BIOS && !is_stv) || (default_index == OPT_NEOGEO_BIOS && !is_neogeo))
continue; /* only offer BIOS selection when it is relevant */
effective_options[effective_index] = default_options[default_index];
effective_index++;
}
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)effective_options);
}
void init_option(struct retro_variable *option, const char *key, const char *value)
{
option->key = key;
option->value = value;
}
static void update_variables(bool first_time)
{
struct retro_led_interface ledintf;
struct retro_variable var;
var.value = NULL;
var.key = APPNAME"_frameskip";
options.frameskip = 0; /* default if none set by frontend */
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
options.frameskip = atoi(var.value);
}
var.value = NULL;
var.key = APPNAME"_input_interface";
options.input_interface = RETRO_DEVICE_JOYPAD;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "retropad") == 0)
options.input_interface = RETRO_DEVICE_JOYPAD;
else if(strcmp(var.value, "mame_keyboard") == 0)
options.input_interface = RETRO_DEVICE_KEYBOARD;
else
options.input_interface = 0; /* retropad and keyboard simultaneously. "classic mame2003 input mode" */
}
var.value = NULL;
var.key = APPNAME"_retropad_layout";
options.retropad_layout = RETROPAD_MAME;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "modern") == 0)
options.retropad_layout = RETROPAD_MODERN;
else if(strcmp(var.value, "SNES") == 0)
options.retropad_layout = RETROPAD_SNES;
else if(strcmp(var.value, "10-Button Arcade") == 0)
options.retropad_layout = RETROPAD_10BUTTON;
else
options.retropad_layout = RETROPAD_MAME;
if(!first_time)
retro_describe_buttons(); /* the first time, MAME's init_game() needs to be called before this so there is also */
/* retro_describe_buttons() in retro_load_game() to take care of the initial description */
}
var.value = NULL;
var.key = APPNAME"_mouse_device";
options.mouse_device = 0;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "pointer") == 0)
options.mouse_device = RETRO_DEVICE_POINTER;
else if(strcmp(var.value, "mouse") == 0)
options.mouse_device = RETRO_DEVICE_MOUSE;
else
options.mouse_device = 0;
}
var.value = NULL;
var.key = APPNAME"_crosshair_enabled";
options.crosshair_enable = 0;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.crosshair_enable = 1;
else
options.crosshair_enable = 0;
}
var.value = NULL;
var.key = APPNAME"_skip_disclaimer";
options.skip_disclaimer = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.skip_disclaimer = true;
else
options.skip_disclaimer = false;
}
var.value = NULL;
var.key = APPNAME"_skip_warnings";
options.skip_warnings = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.skip_warnings = true;
else
options.skip_warnings = false;
}
var.value = NULL;
var.key = APPNAME"_display_setup";
options.display_setup = 0;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.display_setup = 1;
else
options.display_setup = 0;
}
var.value = NULL;
var.key = APPNAME"_brightness";
options.brightness = 1.0f; /* default if none set by frontend */
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
options.brightness = atof(var.value);
if(!first_time)
palette_set_global_brightness(options.brightness);
}
var.value = NULL;
var.key = APPNAME"_gamma";
options.gamma = 1.2f; /* default if none set by frontend */
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
options.gamma = atof(var.value);
if(!first_time)
palette_set_global_gamma(options.gamma);
}
/* TODO: Add overclock option. Below is the code from the old MAME osd to help process the core option.*/
/*
double overclock;
int cpu, doallcpus = 0, oc;
if (code_pressed(KEYCODE_LSHIFT) || code_pressed(KEYCODE_RSHIFT))
doallcpus = 1;
if (!code_pressed(KEYCODE_LCONTROL) && !code_pressed(KEYCODE_RCONTROL))
increment *= 5;
if( increment )
{
overclock = timer_get_overclock(arg);
overclock += 0.01 * increment;
if (overclock < 0.01) overclock = 0.01;
if (overclock > 2.0) overclock = 2.0;
if( doallcpus )
for( cpu = 0; cpu < cpu_gettotalcpu(); cpu++ )
timer_set_overclock(cpu, overclock);
else
timer_set_overclock(arg, overclock);
}
oc = 100 * timer_get_overclock(arg) + 0.5;
if( doallcpus )
sprintf(buf,"%s %s %3d%%", ui_getstring (UI_allcpus), ui_getstring (UI_overclock), oc);
else
sprintf(buf,"%s %s%d %3d%%", ui_getstring (UI_overclock), ui_getstring (UI_cpu), arg, oc);
displayosd(bitmap,buf,oc/2,100/2);
*/
var.value = NULL;
var.key = APPNAME"_enable_backdrop";
options.use_artwork = ARTWORK_USE_NONE;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.use_artwork = ARTWORK_USE_BACKDROPS;
else
options.use_artwork = ARTWORK_USE_NONE;
}
/** BEGIN BIOS OPTIONS **/
options.bios = NULL;
options.neogeo_bios = NULL;
options.stv_bios = NULL;
var.value = NULL;
var.key = APPNAME"_neogeo_bios";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "default") != 0) /* leave as null if set to default */
options.neogeo_bios = strdup(var.value);
}
var.value = NULL;
var.key = APPNAME"_stv_bios";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "default") != 0) /* do nothing if set to default */
{
options.stv_bios = strdup(var.value);
}
}
/** END BIOS OPTIONS **/
var.value = NULL;
var.key = APPNAME"_dialsharexy";
options.dial_share_xy = 0;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.dial_share_xy = 1;
else
options.dial_share_xy = 0;
}
var.value = NULL;
var.key = APPNAME"_dual_joysticks";
options.dual_joysticks = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.dual_joysticks = true;
else
options.dual_joysticks = false;
}
if(first_time)
{
old_dual_joystick_state = options.dual_joysticks;
}
else if(old_dual_joystick_state != options.dual_joysticks)
{
char cfg_file_path[PATH_MAX_LENGTH];
char buffer[PATH_MAX_LENGTH];
osd_get_path(FILETYPE_CONFIG, buffer);
snprintf(cfg_file_path, PATH_MAX_LENGTH, "%s%s%s.cfg", buffer, path_default_slash(), options.romset_filename_noext);
buffer[0] = '\0';
if(path_is_valid(cfg_file_path))
{
if(!remove(cfg_file_path) == 0)
{
snprintf(buffer, PATH_MAX_LENGTH, "%s.cfg exists but cannot be deleted!\n", options.romset_filename_noext);
}
else
{
snprintf(buffer, PATH_MAX_LENGTH, "%s.cfg exists but cannot be deleted!\n", options.romset_filename_noext);
}
}
log_cb(RETRO_LOG_INFO, LOGPRE "%s Reloading input maps.\n", buffer);
usrintf_showmessage_secs(4, "%s Reloading input maps.", buffer);
load_input_port_settings();
old_dual_joystick_state = options.dual_joysticks;
}
var.value = NULL;
var.key = APPNAME"_rstick_to_btns";
options.rstick_to_btns = 0;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.rstick_to_btns = 1;
else
options.rstick_to_btns = 0;
}
var.value = NULL;
var.key = APPNAME"_tate_mode";
options.tate_mode = 0;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.tate_mode = 1;
else
options.tate_mode = 0;
}
var.value = NULL;
var.key = APPNAME"_vector_resolution_multiplier";
options.vector_resolution_multiplier = 1;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
options.vector_resolution_multiplier = atoi(var.value);
}
var.value = NULL;
var.key = APPNAME"_vector_antialias";
options.antialias = 0;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.antialias = 1; /* integer: 1 to enable antialiasing on vectors _ does not work as of 2018/04/17*/
else
options.antialias = 0;
}
var.value = NULL;
var.key = APPNAME"_vector_translucency";
options.translucency = 1;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.translucency = 1; /* integer: 1 to enable translucency on vectors */
else
options.translucency = 0;
}
var.value = NULL;
var.key = APPNAME"_vector_beam_width";
options.beam = 1;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
options.beam = atoi(var.value); /* integer: vector beam width */
}
var.value = NULL;
var.key = APPNAME"_vector_flicker";
options.vector_flicker = 20;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
options.vector_flicker = (int)(2.55 * atof(var.value)); /* why 2.55? must be an old mame family recipe */
}
var.value = NULL;
var.key = APPNAME"_vector_intensity";
options.vector_intensity_correction = 1.5f;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
options.vector_intensity_correction = atof(var.value); /* float: vector beam intensity */
}
var.value = NULL;
var.key = APPNAME"_skip_rom_verify";
options.skip_rom_verify = 0;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 1)
options.skip_rom_verify = 1;
else
options.skip_rom_verify = 0;
}
var.value = NULL;
var.key = APPNAME"_sample_rate";
options.samplerate = 48000;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
options.samplerate = atoi(var.value);
}
var.value = NULL;
var.key = APPNAME"_dcs_speedhack";
options.activate_dcs_speedhack = 1;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if(strcmp(var.value, "enabled") == 0)
options.activate_dcs_speedhack = 1;
else
options.activate_dcs_speedhack = 0;
}
ledintf.set_led_state = NULL;
environ_cb(RETRO_ENVIRONMENT_GET_LED_INTERFACE, &ledintf);
led_state_cb = ledintf.set_led_state;
}
void retro_get_system_av_info(struct retro_system_av_info *info)
{
const int orientation = game_driver->flags & ORIENTATION_MASK;
const bool rotated = ((orientation == ROT90) || (orientation == ROT270));
const int width = rotated ? videoConfig.height : videoConfig.width;
const int height = rotated ? videoConfig.width : videoConfig.height;
info->geometry.base_width = width;
info->geometry.base_height = height;
info->geometry.max_width = width;
info->geometry.max_height = height;
info->geometry.aspect_ratio = (rotated && !options.tate_mode) ? (float)videoConfig.aspect_y / (float)videoConfig.aspect_x : (float)videoConfig.aspect_x / (float)videoConfig.aspect_y;
if (Machine->drv->frames_per_second < 60.0 )
info->timing.fps = 60.0;
else
info->timing.fps = Machine->drv->frames_per_second; /* qbert is 61 fps */
info->timing.sample_rate = Machine->drv->frames_per_second * 1000;
}
unsigned retro_api_version(void)
{
return RETRO_API_VERSION;
}
void retro_get_system_info(struct retro_system_info *info)
{
info->library_name = "MAME 2003-plus";
#ifndef GIT_VERSION
#define GIT_VERSION ""
#endif
info->library_version = "0.78" GIT_VERSION;
info->valid_extensions = "zip";
info->need_fullpath = true;
info->block_extract = true;
}
bool retro_load_game(const struct retro_game_info *game)
{
int driverIndex = 0;
char *driver_lookup = NULL;
int orientation = 0;
unsigned rotateMode = 0;
static const int uiModes[] = {ROT0, ROT90, ROT180, ROT270};
if(string_is_empty(game->path))
{
log_cb(RETRO_LOG_ERROR, LOGPRE "Content path is not set. Exiting!\n");
return false;
}
log_cb(RETRO_LOG_INFO, LOGPRE "Content path: %s.\n", game->path);
if(!path_is_valid(game->path))
{
log_cb(RETRO_LOG_ERROR, LOGPRE "Content path is not valid. Exiting!");
return false;
}
driver_lookup = strdup(path_basename(game->path));
path_remove_extension(driver_lookup);
log_cb(RETRO_LOG_INFO, LOGPRE "Content lookup name: %s.\n", driver_lookup);
for (driverIndex = 0; driverIndex < total_drivers; driverIndex++)
{
const struct GameDriver *needle = drivers[driverIndex];
if ((strcasecmp(driver_lookup, needle->description) == 0)
|| (strcasecmp(driver_lookup, needle->name) == 0) )
{
log_cb(RETRO_LOG_INFO, LOGPRE "Total MAME drivers: %i. Matched game driver: %s.\n", (int) total_drivers, needle->name);
game_driver = needle;
options.romset_filename_noext = driver_lookup;
if(game_driver->bios != NULL) /* this is a driver that uses a bios, but which bios is it? */
{
const char *ancestor_name = NULL;
if(game_driver->clone_of && !string_is_empty(game_driver->clone_of->name))
{
ancestor_name = game_driver->clone_of->name;
if(game_driver->clone_of->clone_of && !string_is_empty(game_driver->clone_of->clone_of->name)) /* search up to two levels up */
ancestor_name = game_driver->clone_of->clone_of->name; /* that's enough, right? */
else
ancestor_name = game_driver->clone_of->name;
}
if(!string_is_empty(ancestor_name))
{
if(strcmp(ancestor_name, "neogeo") == 0)
{
is_neogeo = true;
log_cb(RETRO_LOG_INFO, LOGPRE "Content identified as a Neo Geo game.\n");
}
else if(strcmp(ancestor_name, "stvbios") == 0)
{
is_stv = true;
log_cb(RETRO_LOG_INFO, LOGPRE "Content identified as a ST-V game.\n");
}
}
}
break;
}
}
if(driverIndex == total_drivers)
{
log_cb(RETRO_LOG_ERROR, LOGPRE "Total MAME drivers: %i. MAME driver not found for selected game!", (int) total_drivers);
return false;
}
options.libretro_content_path = strdup(game->path);
path_basedir(options.libretro_content_path);
/* Get system directory from frontend */
options.libretro_system_path = NULL;
environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY,&options.libretro_system_path);
if (options.libretro_system_path == NULL || options.libretro_system_path[0] == '\0')
{
log_cb(RETRO_LOG_INFO, LOGPRE "libretro system path not set by frontend, using content path\n");
options.libretro_system_path = options.libretro_content_path;
}
/* Get save directory from frontend */
options.libretro_save_path = NULL;
environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY,&options.libretro_save_path);
if (options.libretro_save_path == NULL || options.libretro_save_path[0] == '\0')
{
log_cb(RETRO_LOG_INFO, LOGPRE "libretro save path not set by frontent, using content path\n");
options.libretro_save_path = options.libretro_content_path;
}
log_cb(RETRO_LOG_INFO, LOGPRE "content path: %s\n", options.libretro_content_path);
log_cb(RETRO_LOG_INFO, LOGPRE " system path: %s\n", options.libretro_system_path);
log_cb(RETRO_LOG_INFO, LOGPRE " save path: %s\n", options.libretro_save_path);
/* Setup Rotation */
rotateMode = 0;
orientation = drivers[driverIndex]->flags & ORIENTATION_MASK;
rotateMode = (orientation == ROT270) ? 1 : rotateMode;
rotateMode = (orientation == ROT180) ? 2 : rotateMode;
rotateMode = (orientation == ROT90) ? 3 : rotateMode;
environ_cb(RETRO_ENVIRONMENT_SET_ROTATION, &rotateMode);
options.ui_orientation = uiModes[rotateMode];
init_core_options();
update_variables(true);
if(is_neogeo)
options.bios = options.neogeo_bios;
else if(is_stv)
options.bios = options.stv_bios;
if(!init_game(driverIndex))
return false;
retro_describe_buttons(); /* needs to be called after init_game() in order to use MAME button label strings */
if(!run_game(driverIndex))
return false;
return true;
}
void retro_reset (void)
{
machine_reset(); /* use MAME function */
}
/* get pointer axis vector from coord */
int16_t get_pointer_delta(int16_t coord, int16_t *prev_coord)
{
int16_t delta = 0;
if (*prev_coord == 0 || coord == 0)
{
*prev_coord = coord;
}
else
{
if (coord != *prev_coord)
{
delta = coord - *prev_coord;
*prev_coord = coord;
}
}
return delta;
}
void retro_run (void)
{
int i;
bool pointer_pressed;
const struct KeyboardInfo *thisInput;
bool updated = false;
poll_cb();
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
update_variables(false);
/* Keyboard */
thisInput = retroKeys;
while(thisInput->name)
{
retroKeyState[thisInput->code] = input_cb(0, RETRO_DEVICE_KEYBOARD, 0, thisInput->code);
thisInput ++;
}
for (i = 0; i < 4; i ++)
{
unsigned int offset = (i * 18);
/* Analog joystick */
analogjoy[i][0] = input_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X);
analogjoy[i][1] = input_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y);
analogjoy[i][2] = input_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X);
analogjoy[i][3] = input_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y);
/* Joystick */
if (options.rstick_to_btns)
{
/* if less than 0.5 force, ignore and read buttons as usual */
retroJsState[0 + offset] = analogjoy[i][3] > 0x4000 ? 1 : input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
retroJsState[1 + offset] = analogjoy[i][2] < -0x4000 ? 1 : input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y);
}
else
{
retroJsState[0 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
retroJsState[1 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y);
}
retroJsState[2 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT);
retroJsState[3 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START);
retroJsState[4 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP);
retroJsState[5 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN);
retroJsState[6 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT);
retroJsState[7 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT);
if (options.rstick_to_btns)
{
retroJsState[8 + offset] = analogjoy[i][2] > 0x4000 ? 1 : input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
retroJsState[9 + offset] = analogjoy[i][3] < -0x4000 ? 1 : input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
}
else
{
retroJsState[8 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
retroJsState[9 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
}
retroJsState[10 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L);
retroJsState[11 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R);
retroJsState[12 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2);
retroJsState[13 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2);
retroJsState[14 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3);
retroJsState[15 + offset] = input_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3);
if (options.mouse_device)
{
if (options.mouse_device == RETRO_DEVICE_MOUSE)
{
retroJsState[16 + offset] = input_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT);
retroJsState[17 + offset] = input_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT);
mouse_x[i] = input_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
mouse_y[i] = input_cb(i, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
}
else /* RETRO_DEVICE_POINTER */
{
pointer_pressed = input_cb(i, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);
retroJsState[16 + offset] = pointer_pressed;
retroJsState[17 + offset] = 0; /* padding */
mouse_x[i] = pointer_pressed ? get_pointer_delta(input_cb(i, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X), &prev_pointer_x) : 0;
mouse_y[i] = pointer_pressed ? get_pointer_delta(input_cb(i, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y), &prev_pointer_y) : 0;
}
}
else
{
retroJsState[16 + offset] = 0;
retroJsState[17 + offset] = 0;
}
}
mame_frame();
}
void retro_unload_game(void)
{
mame_done();
/* do we need to be freeing things here? */
free(options.romset_filename_noext);
if(options.bios) free(options.bios);
if(options.neogeo_bios) free(options.neogeo_bios);
if(options.stv_bios) free(options.stv_bios);
}
void retro_deinit(void)
{
#ifdef LOG_PERFORMANCE
perf_cb.perf_log();
#endif
}
size_t retro_serialize_size(void)
{
extern size_t state_get_dump_size(void);
return state_get_dump_size();
}
bool retro_serialize(void *data, size_t size)
{
int cpunum;
if(retro_serialize_size() && data && size)
{
/* write the save state */
state_save_save_begin(data);
/* write tag 0 */
state_save_set_current_tag(0);
if(state_save_save_continue())
{
return false;
}
/* loop over CPUs */
for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++)
{
cpuintrf_push_context(cpunum);
/* make sure banking is set */
activecpu_reset_banking();
/* save the CPU data */
state_save_set_current_tag(cpunum + 1);
if(state_save_save_continue())
return false;
cpuintrf_pop_context();
}
/* finish and close */
state_save_save_finish();
return true;
}
return false;
}
bool retro_unserialize(const void * data, size_t size)
{
int cpunum;
/* if successful, load it */
if (retro_serialize_size() && data && size && !state_save_load_begin((void*)data, size))
{
/* read tag 0 */
state_save_set_current_tag(0);
if(state_save_load_continue())
return false;
/* loop over CPUs */
for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++)
{
cpuintrf_push_context(cpunum);
/* make sure banking is set */
activecpu_reset_banking();
/* load the CPU data */
state_save_set_current_tag(cpunum + 1);
if(state_save_load_continue())
return false;
cpuintrf_pop_context();
}
/* finish and close */
state_save_load_finish();
return true;
}
return false;
}
/******************************************************************************
Sound
osd_start_audio_stream() is called at the start of the emulation to initialize
the output stream, then osd_update_audio_stream() is called every frame to
feed new data. osd_stop_audio_stream() is called when the emulation is stopped.
The sample rate is fixed at Machine->sample_rate. Samples are 16-bit, signed.
When the stream is stereo, left and right samples are alternated in the
stream.
osd_start_audio_stream() and osd_update_audio_stream() must return the number
of samples (or couples of samples, when using stereo) required for next frame.
This will be around Machine->sample_rate / Machine->drv->frames_per_second,
the code may adjust it by SMALL AMOUNTS to keep timing accurate and to
maintain audio and video in sync when using vsync. Note that sound emulation,
especially when DACs are involved, greatly depends on the number of samples
per frame to be roughly constant, so the returned value must always stay close
to the reference value of Machine->sample_rate / Machine->drv->frames_per_second.
Of course that value is not necessarily an integer so at least a +/- 1
adjustment is necessary to avoid drifting over time.
******************************************************************************/
int osd_start_audio_stream(int stereo)
{
Machine->sample_rate = Machine->drv->frames_per_second * 1000;
delta_samples = 0.0f;
usestereo = stereo ? 1 : 0;
/* determine the number of samples per frame */
samples_per_frame = Machine->sample_rate / Machine->drv->frames_per_second;
if (Machine->sample_rate == 0) return 0;
samples_buffer = (short *) calloc(samples_per_frame, 2 + usestereo * 2);
if (!usestereo) conversion_buffer = (short *) calloc(samples_per_frame, 4);
return samples_per_frame;
}
int osd_update_audio_stream(INT16 *buffer)
{
int i,j;
if ( Machine->sample_rate !=0 && buffer )
{
memcpy(samples_buffer, buffer, samples_per_frame * (usestereo ? 4 : 2));
if (usestereo)
audio_batch_cb(samples_buffer, samples_per_frame);
else
{
for (i = 0, j = 0; i < samples_per_frame; i++)
{
conversion_buffer[j++] = samples_buffer[i];
conversion_buffer[j++] = samples_buffer[i];
}
audio_batch_cb(conversion_buffer,samples_per_frame);