-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathretromain.c
More file actions
executable file
·2383 lines (2023 loc) · 75.6 KB
/
retromain.c
File metadata and controls
executable file
·2383 lines (2023 loc) · 75.6 KB
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
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include "osdepend.h"
#include "emu.h"
#include "render.h"
#include "ui/ui.h"
#include "uiinput.h"
#include "drivenum.h"
#include "libretro.h"
#include "retroosd.h"
#include "clifront.h"
#include "osdobj_common.h"
#include "modules/lib/osdlib.h"
#include "modules/osdmodule.h"
#include "modules/font/font_module.h"
#include "libretro_shared.h"
#ifdef _WIN32
char slash = '\\';
#else
char slash = '/';
#endif
/* Args for experimental_commandline */
static char ARGUV[32][1024];
static unsigned char ARGUC=0;
extern retro_audio_sample_batch_t audio_batch_cb;
extern bool g_print_verbose;
typedef struct joystate_t
{
int button[MAX_BUTTONS];
int a1[2];
int a2[2];
}Joystate;
/* rendering target */
render_target *our_target = NULL;
/* input device */
static input_device *retrokbd_device; // KEYBD
static input_device *mouse_device; // MOUSE
static input_device *joy_device[4];// JOY0/JOY1/JOY2/JOY3
static input_device *Pad_device[4];// PAD0/PAD1/PAD2/PAD3
/* state */
UINT16 retrokbd_state[RETROK_LAST];
int mouseLX;
int mouseLY;
int mouseBUT[4];
static Joystate joystate[4];
int ui_ipt_pushchar=-1;
int mame_reset = -1;
/* core options */
bool hide_nagscreen = false;
bool hide_warnings = false;
bool nobuffer_enable = false;
bool hide_gameinfo = false;
bool mouse_enable = false;
bool cheats_enable = false;
bool alternate_renderer = false;
bool boot_to_osd_enable = false;
bool boot_to_bios_enable = false;
bool experimental_cmdline = false;
bool softlist_enable = false;
bool softlist_auto = false;
bool write_config_enable = false;
bool read_config_enable = false;
bool auto_save_enable = false;
bool throttle_enable = false;
bool game_specific_saves_enable = false;
// emu flags
static int tate = 0;
static int screenRot = 0;
int vertical,orient;
static bool arcade=FALSE;
static int FirstTimeUpdate = 1;
// rom file name and path
char g_rom_dir[1024];
char mediaType[10];
static char MgamePath[1024];
static char MparentPath[1024];
static char MgameName[512];
static char MsystemName[512];
static char gameName[1024];
// args for cores
static char XARGV[64][1024];
static const char* xargv_cmd[64];
int PARAMCOUNT=0;
// path configuration
#define NB_OPTPATH 12
static const char *dir_name[NB_OPTPATH]= {
"cfg","nvram","hi"/*,"memcard"*/,"input",
"states" ,"snaps","diff","samples",
"artwork","cheat","ini","hash"
};
static const char *opt_name[NB_OPTPATH]= {
"-cfg_directory","-nvram_directory","-hiscore_directory",/*"-memcard_directory",*/"-input_directory",
"-state_directory" ,"-snapshot_directory","-diff_directory","-samplepath",
"-artpath","-cheatpath","-inipath","-hashpath"
};
int opt_type[NB_OPTPATH]={ // 0 for save_dir | 1 for system_dir
0,0,0,0,
0,0,0,1,
1,1,1,1
};
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
static int init3d=1;
#else
#include "rendersw.inc"
#endif
//============================================================
// OSD
//============================================================
const options_entry osd_options::s_option_entries[] =
{
{ NULL, NULL, OPTION_HEADER, "OSD FONT OPTIONS" },
{ OSD_FONT_PROVIDER, "auto", OPTION_STRING, "provider for ui font: " },
{ NULL, NULL, OPTION_HEADER, "OSD CLI OPTIONS" },
{ OSDCOMMAND_LIST_MIDI_DEVICES ";mlist", "0", OPTION_COMMAND, "list available MIDI I/O devices" },
{ OSDCOMMAND_LIST_NETWORK_ADAPTERS ";nlist", "0", OPTION_COMMAND, "list available network adapters" },
// debugging options
{ NULL, NULL, OPTION_HEADER, "OSD DEBUGGING OPTIONS" },
{ OSDOPTION_DEBUGGER, OSDOPTVAL_AUTO, OPTION_STRING, "debugger used : " },
{ OSDOPTION_WATCHDOG ";wdog", "0", OPTION_INTEGER, "force the program to terminate if no updates within specified number of seconds" },
// performance options
{ NULL, NULL, OPTION_HEADER, "OSD PERFORMANCE OPTIONS" },
{ OSDOPTION_MULTITHREADING ";mt", "0", OPTION_BOOLEAN, "enable multithreading; this enables rendering and blitting on a separate thread" },
{ OSDOPTION_NUMPROCESSORS ";np", OSDOPTVAL_AUTO, OPTION_STRING, "number of processors; this overrides the number the system reports" },
{ OSDOPTION_BENCH, "0", OPTION_INTEGER, "benchmark for the given number of emulated seconds; implies -video none -sound none -nothrottle" },
// video options
{ NULL, NULL, OPTION_HEADER, "OSD VIDEO OPTIONS" },
// OS X can be trusted to have working hardware OpenGL, so default to it on for the best user experience
{ OSDOPTION_VIDEO, OSDOPTVAL_AUTO, OPTION_STRING, "video output method: " },
{ OSDOPTION_NUMSCREENS "(1-4)", "1", OPTION_INTEGER, "number of screens to create; usually, you want just one" },
{ OSDOPTION_WINDOW ";w", "0", OPTION_BOOLEAN, "enable window mode; otherwise, full screen mode is assumed" },
{ OSDOPTION_MAXIMIZE ";max", "1", OPTION_BOOLEAN, "default to maximized windows; otherwise, windows will be minimized" },
{ OSDOPTION_KEEPASPECT ";ka", "1", OPTION_BOOLEAN, "constrain to the proper aspect ratio" },
{ OSDOPTION_UNEVENSTRETCH ";ues", "1", OPTION_BOOLEAN, "allow non-integer stretch factors" },
{ OSDOPTION_WAITVSYNC ";vs", "0", OPTION_BOOLEAN, "enable waiting for the start of VBLANK before flipping screens; reduces tearing effects" },
{ OSDOPTION_SYNCREFRESH ";srf", "0", OPTION_BOOLEAN, "enable using the start of VBLANK for throttling instead of the game time" },
// per-window options
{ NULL, NULL, OPTION_HEADER, "OSD PER-WINDOW VIDEO OPTIONS" },
{ OSDOPTION_SCREEN, OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the first screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_ASPECT ";screen_aspect", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio for all screens; 'auto' here will try to make a best guess" },
{ OSDOPTION_RESOLUTION ";r", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution for all screens; format is <width>x<height>[@<refreshrate>] or 'auto'" },
{ OSDOPTION_VIEW, OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for all screens" },
{ OSDOPTION_SCREEN "0", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the first screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_ASPECT "0", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the first screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_RESOLUTION "0;r0", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the first screen; format is <width>x<height>[@<refreshrate>] or 'auto'" },
{ OSDOPTION_VIEW "0", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the first screen" },
{ OSDOPTION_SCREEN "1", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the second screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_ASPECT "1", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the second screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_RESOLUTION "1;r1", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the second screen; format is <width>x<height>[@<refreshrate>] or 'auto'" },
{ OSDOPTION_VIEW "1", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the second screen" },
{ OSDOPTION_SCREEN "2", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the third screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_ASPECT "2", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the third screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_RESOLUTION "2;r2", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the third screen; format is <width>x<height>[@<refreshrate>] or 'auto'" },
{ OSDOPTION_VIEW "2", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the third screen" },
{ OSDOPTION_SCREEN "3", OSDOPTVAL_AUTO, OPTION_STRING, "explicit name of the fourth screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_ASPECT "3", OSDOPTVAL_AUTO, OPTION_STRING, "aspect ratio of the fourth screen; 'auto' here will try to make a best guess" },
{ OSDOPTION_RESOLUTION "3;r3", OSDOPTVAL_AUTO, OPTION_STRING, "preferred resolution of the fourth screen; format is <width>x<height>[@<refreshrate>] or 'auto'" },
{ OSDOPTION_VIEW "3", OSDOPTVAL_AUTO, OPTION_STRING, "preferred view for the fourth screen" },
// full screen options
{ NULL, NULL, OPTION_HEADER, "OSD FULL SCREEN OPTIONS" },
{ OSDOPTION_SWITCHRES, "0", OPTION_BOOLEAN, "enable resolution switching" },
// sound options
{ NULL, NULL, OPTION_HEADER, "OSD SOUND OPTIONS" },
{ OSDOPTION_SOUND, OSDOPTVAL_AUTO, OPTION_STRING, "sound output method: " },
{ OSDOPTION_AUDIO_LATENCY "(1-5)", "2", OPTION_INTEGER, "set audio latency (increase to reduce glitches, decrease for responsiveness)" },
{ NULL, NULL, OPTION_HEADER, "OSD VIDEO OPTIONS" },
{ OSDOPTION_FILTER ";glfilter;flt", "1", OPTION_BOOLEAN, "enable bilinear filtering on screen output" },
{ OSDOPTION_PRESCALE, "1", OPTION_INTEGER, "scale screen rendering by this amount in software" },
#ifdef USE_OPENGL
// OpenGL specific options
{ NULL, NULL, OPTION_HEADER, "OpenGL-SPECIFIC OPTIONS" },
{ OSDOPTION_GL_FORCEPOW2TEXTURE, "0", OPTION_BOOLEAN, "force power of two textures (default no)" },
{ OSDOPTION_GL_NOTEXTURERECT, "0", OPTION_BOOLEAN, "don't use OpenGL GL_ARB_texture_rectangle (default on)" },
{ OSDOPTION_GL_VBO, "1", OPTION_BOOLEAN, "enable OpenGL VBO, if available (default on)" },
{ OSDOPTION_GL_PBO, "1", OPTION_BOOLEAN, "enable OpenGL PBO, if available (default on)" },
{ OSDOPTION_GL_GLSL, "0", OPTION_BOOLEAN, "enable OpenGL GLSL, if available (default off)" },
{ OSDOPTION_GLSL_FILTER, "1", OPTION_STRING, "enable OpenGL GLSL filtering instead of FF filtering 0-plain, 1-bilinear (default)" },
{ OSDOPTION_SHADER_MAME "0", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 0" },
{ OSDOPTION_SHADER_MAME "1", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 1" },
{ OSDOPTION_SHADER_MAME "2", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 2" },
{ OSDOPTION_SHADER_MAME "3", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 3" },
{ OSDOPTION_SHADER_MAME "4", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 4" },
{ OSDOPTION_SHADER_MAME "5", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 5" },
{ OSDOPTION_SHADER_MAME "6", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 6" },
{ OSDOPTION_SHADER_MAME "7", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 7" },
{ OSDOPTION_SHADER_MAME "8", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 8" },
{ OSDOPTION_SHADER_MAME "9", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader set mame bitmap 9" },
{ OSDOPTION_SHADER_SCREEN "0", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 0" },
{ OSDOPTION_SHADER_SCREEN "1", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 1" },
{ OSDOPTION_SHADER_SCREEN "2", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 2" },
{ OSDOPTION_SHADER_SCREEN "3", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 3" },
{ OSDOPTION_SHADER_SCREEN "4", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 4" },
{ OSDOPTION_SHADER_SCREEN "5", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 5" },
{ OSDOPTION_SHADER_SCREEN "6", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 6" },
{ OSDOPTION_SHADER_SCREEN "7", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 7" },
{ OSDOPTION_SHADER_SCREEN "8", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 8" },
{ OSDOPTION_SHADER_SCREEN "9", OSDOPTVAL_NONE, OPTION_STRING, "custom OpenGL GLSL shader screen bitmap 9" },
#endif
// End of list
{ NULL }
};
osd_options::osd_options()
: cli_options()
{
add_entries(osd_options::s_option_entries);
};
//-------------------------------------------------
// osd_interface - constructor
//-------------------------------------------------
osd_common_t::osd_common_t(osd_options &options)
: osd_output(), m_machine(NULL),
m_options(options)
{
osd_output::push(this);
}
//-------------------------------------------------
// osd_interface - destructor
//-------------------------------------------------
osd_common_t::~osd_common_t()
{
for(int i= 0; i < m_video_names.count(); ++i)
osd_free(const_cast<char*>(m_video_names[i]));
//m_video_options,reset();
osd_output::pop(this);
}
#define REGISTER_MODULE(_O, _X ) { extern const module_type _X; _O . register_module( _X ); }
void osd_common_t::register_options()
{
REGISTER_MODULE(m_mod_man, FONT_NONE);
#ifndef NO_USE_MIDI
REGISTER_MODULE(m_mod_man, MIDI_PM);
#endif
REGISTER_MODULE(m_mod_man, MIDI_NONE);
// after initialization we know which modules are supported
const char *names[20];
int num;
m_mod_man.get_module_names(OSD_FONT_PROVIDER, 20, &num, names);
dynamic_array<const char *> dnames;
for (int i = 0; i < num; i++)
dnames.append(names[i]);
update_option(OSD_FONT_PROVIDER, dnames);
// Register video options and update options
video_options_add("none", NULL);
video_register();
update_option(OSDOPTION_VIDEO, m_video_names);
}
void osd_common_t::update_option(const char * key, dynamic_array<const char *> &values)
{
astring current_value(m_options.description(key));
astring new_option_value("");
for (int index = 0; index < values.count(); index++)
{
astring t(values[index]);
if (new_option_value.len() > 0)
{
if( index != (values.count()-1))
new_option_value.cat(", ");
else
new_option_value.cat(" or ");
}
new_option_value.cat(t);
}
// TODO: core_strdup() is leaked
m_options.set_description(key, core_strdup(current_value.cat(new_option_value).cstr()));
}
//-------------------------------------------------
// output_callback - callback for osd_printf_...
//-------------------------------------------------
void osd_common_t::output_callback(osd_output_channel channel, const char *msg, va_list args)
{
switch (channel)
{
case OSD_OUTPUT_CHANNEL_ERROR:
case OSD_OUTPUT_CHANNEL_WARNING:
vfprintf(stderr, msg, args);
break;
case OSD_OUTPUT_CHANNEL_INFO:
case OSD_OUTPUT_CHANNEL_VERBOSE:
case OSD_OUTPUT_CHANNEL_LOG:
vfprintf(stdout, msg, args);
break;
case OSD_OUTPUT_CHANNEL_DEBUG:
#ifdef MAME_DEBUG
vfprintf(stdout, msg, args);
#endif
break;
default:
break;
}
}
//-------------------------------------------------
// init - initialize the OSD system.
//-------------------------------------------------
void osd_common_t::init(running_machine &machine)
{
//
// This function is responsible for initializing the OSD-specific
// video and input functionality, and registering that functionality
// with the MAME core.
//
// In terms of video, this function is expected to create one or more
// render_targets that will be used by the MAME core to provide graphics
// data to the system. Although it is possible to do this later, the
// assumption in the MAME core is that the user interface will be
// visible starting at init() time, so you will have some work to
// do to avoid these assumptions.
//
// In terms of input, this function is expected to enumerate all input
// devices available and describe them to the MAME core by adding
// input devices and their attached items (buttons/axes) via the input
// system.
//
// Beyond these core responsibilities, init() should also initialize
// any other OSD systems that require information about the current
// running_machine.
//
// This callback is also the last opportunity to adjust the options
// before they are consumed by the rest of the core.
//
// Future work/changes:
//
// Audio initialization may eventually move into here as well,
// instead of relying on independent callbacks from each system.
//
m_machine = &machine;
osd_options &options = downcast<osd_options &>(machine.options());
// extract the verbose printing option
if (options.verbose())
g_print_verbose = true;
// ensure we get called on the way out
machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(osd_common_t::osd_exit), this));
}
//-------------------------------------------------
// update - periodic system update
//-------------------------------------------------
void osd_common_t::update(bool skip_redraw, UINT32 flags)
{
//
// This method is called periodically to flush video updates to the
// screen, and also to allow the OSD a chance to update other systems
// on a regular basis. In general this will be called at the frame
// rate of the system being run; however, it may be called at more
// irregular intervals in some circumstances (e.g., multi-screen games
// or games with asynchronous updates).
//
}
//-------------------------------------------------
// update_audio_stream - update the stereo audio
// stream
//-------------------------------------------------
void osd_common_t::update_audio_stream(const INT16 *buffer, int samples_this_frame)
{
//
// This method is called whenever the system has new audio data to stream.
// It provides an array of stereo samples in L-R order which should be
// output at the configured sample_rate.
//
if (retro_pause != -1)
audio_batch_cb(buffer, samples_this_frame);
}
//-------------------------------------------------
// set_mastervolume - set the system volume
//-------------------------------------------------
void osd_common_t::set_mastervolume(int attenuation)
{
//
// Attenuation is the attenuation in dB (a negative number).
// To convert from dB to a linear volume scale do the following:
// volume = MAX_VOLUME;
// while (attenuation++ < 0)
// volume /= 1.122018454; // = (10 ^ (1/20)) = 1dB
//
}
//-------------------------------------------------
// customize_input_type_list - provide OSD
// additions/modifications to the input list
//-------------------------------------------------
void osd_common_t::customize_input_type_list(simple_list<input_type_entry> &typelist)
{
//
// inptport.c defines some general purpose defaults for key and joystick bindings.
// They may be further adjusted by the OS dependent code to better match the
// available keyboard, e.g. one could map pause to the Pause key instead of P, or
// snapshot to PrtScr instead of F12. Of course the user can further change the
// settings to anything he/she likes.
//
// This function is called on startup, before reading the configuration from disk.
// Scan the list, and change the keys/joysticks you want.
//
}
//-------------------------------------------------
// font_open - attempt to "open" a handle to the
// font with the given name
//-------------------------------------------------
osd_font *osd_common_t::font_open(const char *name, int &height)
{
return NULL;
}
//-------------------------------------------------
// font_close - release resources associated with
// a given OSD font
//-------------------------------------------------
void osd_common_t::font_close(osd_font *font)
{
}
//-------------------------------------------------
// font_get_bitmap - allocate and populate a
// BITMAP_FORMAT_ARGB32 bitmap containing the
// pixel values rgb_t(0xff,0xff,0xff,0xff)
// or rgb_t(0x00,0xff,0xff,0xff) for each
// pixel of a black & white font
//-------------------------------------------------
bool osd_common_t::font_get_bitmap(osd_font *font, unicode_char chnum, bitmap_argb32 &bitmap, INT32 &width, INT32 &xoffs, INT32 &yoffs)
{
return false;
}
//-------------------------------------------------
// get_slider_list - allocate and populate a
// list of OS-dependent slider values.
//-------------------------------------------------
void *osd_common_t::get_slider_list()
{
return NULL;
}
//-------------------------------------------------
// execute_command - execute a command not yet
// handled by the core
//-------------------------------------------------
bool osd_common_t::execute_command(const char *command)
{
if (strcmp(command, OSDCOMMAND_LIST_NETWORK_ADAPTERS) == 0)
{
osd_module *om = select_module_options(options(), OSD_NETDEV_PROVIDER);
if (om->probe())
{
om->init();
osd_list_network_adapters();
om->exit();
}
return true;
}
else if (strcmp(command, OSDCOMMAND_LIST_MIDI_DEVICES) == 0)
{
osd_module *om = select_module_options(options(), OSD_MIDI_PROVIDER);
midi_module *pm = select_module_options<midi_module *>(options(), OSD_MIDI_PROVIDER);
if (om->probe())
{
om->init();
pm->list_midi_devices();
om->exit();
}
return true;
}
return false;
}
void osd_common_t::init_subsystems()
{
if (!video_init())
{
video_exit();
osd_printf_error("video_init: Initialization failed!\n\n\n");
fflush(stderr);
fflush(stdout);
exit(-1);
}
input_init();
output_init();
m_font_module = select_module_options<font_module *>(options(), OSD_FONT_PROVIDER);
select_module_options<netdev_module *>(options(), OSD_NETDEV_PROVIDER);
m_midi = select_module_options<midi_module *>(options(), OSD_MIDI_PROVIDER);
m_mod_man.init();
}
bool osd_common_t::video_init()
{
return true;
}
bool osd_common_t::window_init()
{
return true;
}
bool osd_common_t::no_sound()
{
return (strcmp(options().sound(),"none")==0) ? true : false;
}
void osd_common_t::video_register()
{
}
bool osd_common_t::input_init()
{
return true;
}
bool osd_common_t::output_init()
{
return true;
}
void osd_common_t::exit_subsystems()
{
video_exit();
input_exit();
output_exit();
}
void osd_common_t::video_exit()
{
}
void osd_common_t::window_exit()
{
}
void osd_common_t::input_exit()
{
}
void osd_common_t::output_exit()
{
}
void osd_common_t::osd_exit()
{
m_mod_man.exit();
exit_subsystems();
}
void osd_common_t::video_options_add(const char *name, void *type)
{
//m_video_options.add(name, type, false);
m_video_names.append(core_strdup(name));
}
//============================================================
// INPUT
//============================================================
#ifndef RETROK_TILDE
#define RETROK_TILDE 178
#endif
static UINT16 retrokbd_state2[RETROK_LAST];
struct kt_table
{
const char * mame_key_name;
int retro_key_name;
input_item_id mame_key;
};
kt_table ktable[]={
{"A",RETROK_a,ITEM_ID_A},
{"B",RETROK_b,ITEM_ID_B},
{"C",RETROK_c,ITEM_ID_C},
{"D",RETROK_d,ITEM_ID_D},
{"E",RETROK_e,ITEM_ID_E},
{"F",RETROK_f,ITEM_ID_F},
{"G",RETROK_g,ITEM_ID_G},
{"H",RETROK_h,ITEM_ID_H},
{"I",RETROK_i,ITEM_ID_I},
{"J",RETROK_j,ITEM_ID_J},
{"K",RETROK_k,ITEM_ID_K},
{"L",RETROK_l,ITEM_ID_L},
{"M",RETROK_m,ITEM_ID_M},
{"N",RETROK_n,ITEM_ID_N},
{"O",RETROK_o,ITEM_ID_O},
{"P",RETROK_p,ITEM_ID_P},
{"Q",RETROK_q,ITEM_ID_Q},
{"R",RETROK_r,ITEM_ID_R},
{"S",RETROK_s,ITEM_ID_S},
{"T",RETROK_t,ITEM_ID_T},
{"U",RETROK_u,ITEM_ID_U},
{"V",RETROK_v,ITEM_ID_V},
{"W",RETROK_w,ITEM_ID_W},
{"X",RETROK_x,ITEM_ID_X},
{"Y",RETROK_y,ITEM_ID_Y},
{"Z",RETROK_z,ITEM_ID_Z},
{"0",RETROK_0,ITEM_ID_0},
{"1",RETROK_1,ITEM_ID_1},
{"2",RETROK_2,ITEM_ID_2},
{"3",RETROK_3,ITEM_ID_3},
{"4",RETROK_4,ITEM_ID_4},
{"5",RETROK_5,ITEM_ID_5},
{"6",RETROK_6,ITEM_ID_6},
{"7",RETROK_7,ITEM_ID_7},
{"8",RETROK_8,ITEM_ID_8},
{"9",RETROK_9,ITEM_ID_9},
{"F1",RETROK_F1,ITEM_ID_F1},
{"F2",RETROK_F2,ITEM_ID_F2},
{"F3",RETROK_F3,ITEM_ID_F3},
{"F4",RETROK_F4,ITEM_ID_F4},
{"F5",RETROK_F5,ITEM_ID_F5},
{"F6",RETROK_F6,ITEM_ID_F6},
{"F7",RETROK_F7,ITEM_ID_F7},
{"F8",RETROK_F8,ITEM_ID_F8},
{"F9",RETROK_F9,ITEM_ID_F9},
{"F10",RETROK_F10,ITEM_ID_F10},
{"F11",RETROK_F11,ITEM_ID_F11},
{"F12",RETROK_F12,ITEM_ID_F12},
{"F13",RETROK_F13,ITEM_ID_F13},
{"F14",RETROK_F14,ITEM_ID_F14},
{"F15",RETROK_F15,ITEM_ID_F15},
{"Esc",RETROK_ESCAPE,ITEM_ID_ESC},
{"TILDE",RETROK_TILDE,ITEM_ID_TILDE},
{"MINUS",RETROK_MINUS,ITEM_ID_MINUS},
{"EQUALS",RETROK_EQUALS,ITEM_ID_EQUALS},
{"BKCSPACE",RETROK_BACKSPACE,ITEM_ID_BACKSPACE},
{"TAB",RETROK_TAB,ITEM_ID_TAB},
{"(",RETROK_LEFTPAREN,ITEM_ID_OPENBRACE},
{")",RETROK_RIGHTPAREN,ITEM_ID_CLOSEBRACE},
{"ENTER",RETROK_RETURN,ITEM_ID_ENTER},
{"·",RETROK_COLON,ITEM_ID_COLON},
{"\'",RETROK_QUOTE,ITEM_ID_QUOTE},
{"BCKSLASH",RETROK_BACKSLASH,ITEM_ID_BACKSLASH},
///**/BCKSLASH2*/RETROK_,ITEM_ID_BACKSLASH2},
{",",RETROK_COMMA,ITEM_ID_COMMA},
///**/STOP*/RETROK_,ITEM_ID_STOP},
{"/",RETROK_SLASH,ITEM_ID_SLASH},
{"SPACE",RETROK_SPACE,ITEM_ID_SPACE},
{"INS",RETROK_INSERT,ITEM_ID_INSERT},
{"DEL",RETROK_DELETE,ITEM_ID_DEL},
{"HOME",RETROK_HOME,ITEM_ID_HOME},
{"END",RETROK_END,ITEM_ID_END},
{"PGUP",RETROK_PAGEUP,ITEM_ID_PGUP},
{"PGDW",RETROK_PAGEDOWN,ITEM_ID_PGDN},
{"LEFT",RETROK_LEFT,ITEM_ID_LEFT},
{"RIGHT",RETROK_RIGHT,ITEM_ID_RIGHT},
{"UP",RETROK_UP,ITEM_ID_UP},
{"DOWN",RETROK_DOWN,ITEM_ID_DOWN},
{"KO",RETROK_KP0,ITEM_ID_0_PAD},
{"K1",RETROK_KP1,ITEM_ID_1_PAD},
{"K2",RETROK_KP2,ITEM_ID_2_PAD},
{"K3",RETROK_KP3,ITEM_ID_3_PAD},
{"K4",RETROK_KP4,ITEM_ID_4_PAD},
{"K5",RETROK_KP5,ITEM_ID_5_PAD},
{"K6",RETROK_KP6,ITEM_ID_6_PAD},
{"K7",RETROK_KP7,ITEM_ID_7_PAD},
{"K8",RETROK_KP8,ITEM_ID_8_PAD},
{"K9",RETROK_KP9,ITEM_ID_9_PAD},
{"K/",RETROK_KP_DIVIDE,ITEM_ID_SLASH_PAD},
{"K*",RETROK_KP_MULTIPLY,ITEM_ID_ASTERISK},
{"K-",RETROK_KP_MINUS,ITEM_ID_MINUS_PAD},
{"K+",RETROK_KP_PLUS,ITEM_ID_PLUS_PAD},
{"KDEL",RETROK_KP_PERIOD,ITEM_ID_DEL_PAD},
{"KRTRN",RETROK_KP_ENTER,ITEM_ID_ENTER_PAD},
{"PRINT",RETROK_PRINT,ITEM_ID_PRTSCR},
{"PAUSE",RETROK_PAUSE,ITEM_ID_PAUSE},
{"LSHFT",RETROK_LSHIFT,ITEM_ID_LSHIFT},
{"RSHFT",RETROK_RSHIFT,ITEM_ID_RSHIFT},
{"LCTRL",RETROK_LCTRL,ITEM_ID_LCONTROL},
{"RCTRL",RETROK_RCTRL,ITEM_ID_RCONTROL},
{"LALT",RETROK_LALT,ITEM_ID_LALT},
{"RALT",RETROK_RALT,ITEM_ID_RALT},
{"SCRLOCK",RETROK_SCROLLOCK,ITEM_ID_SCRLOCK},
{"NUMLOCK",RETROK_NUMLOCK,ITEM_ID_NUMLOCK},
{"CPSLOCK",RETROK_CAPSLOCK,ITEM_ID_CAPSLOCK},
{"LMETA",RETROK_LMETA,ITEM_ID_LWIN},
{"RMETA",RETROK_RMETA,ITEM_ID_RWIN},
{"MENU",RETROK_MENU,ITEM_ID_MENU},
{"BREAK",RETROK_BREAK,ITEM_ID_CANCEL},
{"-1",-1,ITEM_ID_INVALID},
};
enum
{
RETROPAD_B,
RETROPAD_Y,
RETROPAD_SELECT,
RETROPAD_START,
RETROPAD_PAD_UP,
RETROPAD_PAD_DOWN,
RETROPAD_PAD_LEFT,
RETROPAD_PAD_RIGHT,
RETROPAD_A,
RETROPAD_X,
RETROPAD_L,
RETROPAD_R,
RETROPAD_L2,
RETROPAD_R2,
RETROPAD_L3,
RETROPAD_R3,
RETROPAD_TOTAL
};
static const char *Buttons_Name[MAX_BUTTONS]=
{
"B", //0
"Y", //1
"SELECT", //2
"START", //3
"Pad UP", //4
"Pad DOWN", //5
"Pad LEFT", //6
"Pad RIGHT", //7
"A", //8
"X", //9
"L", //10
"R", //11
"L2", //12
"R2", //13
"L3", //14
"R3", //15
};
input_item_id PAD_DIR[4][4]=
{
{ITEM_ID_UP,ITEM_ID_DOWN,ITEM_ID_LEFT,ITEM_ID_RIGHT },
{ITEM_ID_R ,ITEM_ID_F ,ITEM_ID_D ,ITEM_ID_G },
{ITEM_ID_I,ITEM_ID_K,ITEM_ID_J,ITEM_ID_L },
{ITEM_ID_8_PAD ,ITEM_ID_2_PAD ,ITEM_ID_4_PAD ,ITEM_ID_6_PAD }
};
// Default : A ->B1 | B ->B2 | X ->B3 | Y ->B4 | L ->B5 | R ->B6 | keyboard c ->B7 | keyboard v -> B8
int Buttons_mapping[8]={RETROPAD_A,RETROPAD_B,RETROPAD_X,RETROPAD_Y,RETROPAD_L,RETROPAD_R,RETROK_c,RETROK_v};
static void Input_Binding(running_machine &machine);
static INT32 retrokbd_get_state(void *device_internal, void *item_internal)
{
UINT8 *itemdata = (UINT8 *)item_internal;
return *itemdata ;
}
static INT32 generic_axis_get_state(void *device_internal, void *item_internal)
{
INT32 *axisdata = (INT32 *) item_internal;
return *axisdata;
}
static INT32 generic_button_get_state(void *device_internal, void *item_internal)
{
INT32 *itemdata = (INT32 *) item_internal;
return *itemdata >> 7;
}
#define input_device_item_add_joy(a,b,c,d,e) joy_device[a]->add_item(b,d,e,c)
#define input_device_item_add_mouse(a,b,c,d,e) mouse_device->add_item(b,d,e,c)
#define input_device_item_add_kbd(a,b,c,d,e) retrokbd_device->add_item(b,d,e,c)
#define input_device_item_add_pad(a,b,c,d,e) Pad_device[a]->add_item(b,d,e,c)
void process_keyboard_state(void)
{
/* TODO: handle mods:SHIFT/CTRL/ALT/META/NUMLOCK/CAPSLOCK/SCROLLOCK */
unsigned i = 0;
do
{
retrokbd_state[ktable[i].retro_key_name] = input_state_cb(0, RETRO_DEVICE_KEYBOARD, 0,ktable[i].retro_key_name) ? 0x80 : 0;
if(retrokbd_state[ktable[i].retro_key_name] && retrokbd_state2[ktable[i].retro_key_name] == 0)
{
ui_ipt_pushchar=ktable[i].retro_key_name;
retrokbd_state2[ktable[i].retro_key_name]=1;
}
else if(!retrokbd_state[ktable[i].retro_key_name] && retrokbd_state2[ktable[i].retro_key_name] == 1)
retrokbd_state2[ktable[i].retro_key_name]=0;
i++;
}while(ktable[i].retro_key_name!=-1);
}
void process_joypad_state(void)
{
unsigned i, j;
for(j = 0;j < 4; j++)
{
for(i = 0;i < MAX_BUTTONS; i++)
joystate[j].button[i] = input_state_cb(j, RETRO_DEVICE_JOYPAD, 0,i)?0x80:0;
joystate[j].a1[0] = 2 * (input_state_cb(j, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X));
joystate[j].a1[1] = 2 * (input_state_cb(j, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y));
joystate[j].a2[0] = 2 * (input_state_cb(j, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X));
joystate[j].a2[1] = 2 * (input_state_cb(j, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y));
}
}
void process_mouse_state(void)
{
static int mbL = 0, mbR = 0;
int mouse_l;
int mouse_r;
int16_t mouse_x;
int16_t mouse_y;
if (!mouse_enable)
return;
mouse_x = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
mouse_y = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
mouse_l = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT);
mouse_r = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT);
mouseLX = mouse_x*INPUT_RELATIVE_PER_PIXEL;
mouseLY = mouse_y*INPUT_RELATIVE_PER_PIXEL;
if(mbL==0 && mouse_l)
{
mbL=1;
mouseBUT[0]=0x80;
}
else if(mbL==1 && !mouse_l)
{
mouseBUT[0]=0;
mbL=0;
}
if(mbR==0 && mouse_r)
{
mbR=1;
mouseBUT[1]=1;
}
else if(mbR==1 && !mouse_r)
{
mouseBUT[1]=0;
mbR=0;
}
}
static void initInput(running_machine &machine)
{
int i,j,button;
char defname[20];
if (mouse_enable)
{
//MOUSE
mouse_device = machine.input().device_class(DEVICE_CLASS_MOUSE).add_device("Mice1");
// add the axes
input_device_item_add_mouse(mouse_device , "X", &mouseLX, ITEM_ID_XAXIS, generic_axis_get_state);
input_device_item_add_mouse(mouse_device , "Y", &mouseLY, ITEM_ID_YAXIS, generic_axis_get_state);
// add the buttons
for (button = 0; button < 4; button++)
{
input_item_id itemid = (input_item_id) (ITEM_ID_BUTTON1+button);
sprintf(defname, "B%d", button + 1);
input_device_item_add_mouse(mouse_device, defname, &mouseBUT[button], itemid, generic_button_get_state);
}
}
//KEYBOARD
retrokbd_device = machine.input().device_class(DEVICE_CLASS_KEYBOARD).add_device("Retrokdb");
if (retrokbd_device == NULL)
fatalerror("KBD Error creating keyboard device\n");
for(i = 0; i < RETROK_LAST; i++){
retrokbd_state[i]=0;
retrokbd_state2[i]=0;
}
i=0;
do{
input_device_item_add_kbd(retrokbd_device,\
ktable[i].mame_key_name, &retrokbd_state[ktable[i].retro_key_name],ktable[i].mame_key,retrokbd_get_state);
i++;
}while(ktable[i].retro_key_name!=-1);
//JOY/PAD
Input_Binding(machine);
for(i=0;i<4;i++)
{
sprintf(defname, "Joy%d", i);
joy_device[i]=machine.input().device_class(DEVICE_CLASS_JOYSTICK).add_device(defname);
// add the axes
input_device_item_add_joy (i, "LX", &joystate[i].a1[0], ITEM_ID_XAXIS, generic_axis_get_state);
input_device_item_add_joy (i, "LY", &joystate[i].a1[1], ITEM_ID_YAXIS, generic_axis_get_state);
input_device_item_add_joy (i, "RX", &joystate[i].a2[0], ITEM_ID_RXAXIS, generic_axis_get_state);
input_device_item_add_joy (i, "RY", &joystate[i].a2[1], ITEM_ID_RYAXIS, generic_axis_get_state);
//add the buttons
for(j=0;j<MAX_BUTTONS;j++)joystate[i].button[j] = 0;
input_device_item_add_joy (i,Buttons_Name[RETROPAD_START],&joystate[i].button[RETROPAD_START],ITEM_ID_START,generic_button_get_state );
input_device_item_add_joy (i,Buttons_Name[RETROPAD_SELECT],&joystate[i].button[RETROPAD_SELECT],ITEM_ID_SELECT,generic_button_get_state );
input_device_item_add_joy (i,Buttons_Name[Buttons_mapping[0]],\
&joystate[i].button[Buttons_mapping[0]],(input_item_id)(ITEM_ID_BUTTON1+0),generic_button_get_state );
input_device_item_add_joy (i,Buttons_Name[Buttons_mapping[1]],\
&joystate[i].button[Buttons_mapping[1]],(input_item_id)(ITEM_ID_BUTTON1+1),generic_button_get_state );
input_device_item_add_joy (i,Buttons_Name[Buttons_mapping[2]],\
&joystate[i].button[Buttons_mapping[2]],(input_item_id)(ITEM_ID_BUTTON1+2),generic_button_get_state );
input_device_item_add_joy (i,Buttons_Name[Buttons_mapping[3]],\
&joystate[i].button[Buttons_mapping[3]],(input_item_id)(ITEM_ID_BUTTON1+3),generic_button_get_state );
input_device_item_add_joy (i,Buttons_Name[Buttons_mapping[4]],\
&joystate[i].button[Buttons_mapping[4]],(input_item_id)(ITEM_ID_BUTTON1+4),generic_button_get_state );
input_device_item_add_joy (i,Buttons_Name[Buttons_mapping[5]],\
&joystate[i].button[Buttons_mapping[5]],(input_item_id)(ITEM_ID_BUTTON1+5),generic_button_get_state );
if (Buttons_mapping[6]!=RETROK_c)
{
input_device_item_add_joy (i,Buttons_Name[Buttons_mapping[6]],\
&joystate[i].button[Buttons_mapping[6]],(input_item_id)(ITEM_ID_BUTTON1+6),generic_button_get_state );
}
if (Buttons_mapping[7]!=RETROK_v)
{
input_device_item_add_joy (i,Buttons_Name[Buttons_mapping[7]],\
&joystate[i].button[Buttons_mapping[7]],(input_item_id)(ITEM_ID_BUTTON1+7),generic_button_get_state );