1
/***************************************************************************
5
Options file and command line management.
7
****************************************************************************
12
Redistribution and use in source and binary forms, with or without
13
modification, are permitted provided that the following conditions are
16
* Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
18
* Redistributions in binary form must reproduce the above copyright
19
notice, this list of conditions and the following disclaimer in
20
the documentation and/or other materials provided with the
22
* Neither the name 'MAME' nor the names of its contributors may be
23
used to endorse or promote products derived from this software
24
without specific prior written permission.
26
THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
POSSIBILITY OF SUCH DAMAGE.
38
***************************************************************************/
47
//**************************************************************************
48
// CORE EMULATOR OPTIONS
49
//**************************************************************************
51
const options_entry emu_options::s_option_entries[] =
53
// unadorned options - only a single one supported at the moment
54
{ OPTION_SYSTEMNAME, NULL, OPTION_STRING, NULL },
55
{ OPTION_SOFTWARENAME, NULL, OPTION_STRING, NULL },
58
{ NULL, NULL, OPTION_HEADER, "CORE CONFIGURATION OPTIONS" },
59
{ OPTION_READCONFIG ";rc", "1", OPTION_BOOLEAN, "enable loading of configuration files" },
60
{ OPTION_WRITECONFIG ";wc", "0", OPTION_BOOLEAN, "writes configuration to (driver).ini on exit" },
63
{ NULL, NULL, OPTION_HEADER, "CORE SEARCH PATH OPTIONS" },
64
{ OPTION_MEDIAPATH ";rp;biospath;bp", "roms", OPTION_STRING, "path to ROMsets and hard disk images" },
65
{ OPTION_HASHPATH ";hash_directory;hash", "hash", OPTION_STRING, "path to hash files" },
66
{ OPTION_SAMPLEPATH ";sp", "samples", OPTION_STRING, "path to samplesets" },
67
{ OPTION_ARTPATH, "artwork", OPTION_STRING, "path to artwork files" },
68
{ OPTION_CTRLRPATH, "ctrlr", OPTION_STRING, "path to controller definitions" },
69
{ OPTION_INIPATH, ".;ini", OPTION_STRING, "path to ini files" },
70
{ OPTION_FONTPATH, ".", OPTION_STRING, "path to font files" },
71
{ OPTION_CHEATPATH, "cheat", OPTION_STRING, "path to cheat files" },
72
{ OPTION_CROSSHAIRPATH, "crosshair", OPTION_STRING, "path to crosshair files" },
74
// output directory options
75
{ NULL, NULL, OPTION_HEADER, "CORE OUTPUT DIRECTORY OPTIONS" },
76
{ OPTION_CFG_DIRECTORY, "cfg", OPTION_STRING, "directory to save configurations" },
77
{ OPTION_NVRAM_DIRECTORY, "nvram", OPTION_STRING, "directory to save nvram contents" },
78
{ OPTION_MEMCARD_DIRECTORY, "memcard", OPTION_STRING, "directory to save memory card contents" },
79
{ OPTION_INPUT_DIRECTORY, "inp", OPTION_STRING, "directory to save input device logs" },
80
{ OPTION_STATE_DIRECTORY, "sta", OPTION_STRING, "directory to save states" },
81
{ OPTION_SNAPSHOT_DIRECTORY, "snap", OPTION_STRING, "directory to save screenshots" },
82
{ OPTION_DIFF_DIRECTORY, "diff", OPTION_STRING, "directory to save hard drive image difference files" },
83
{ OPTION_COMMENT_DIRECTORY, "comments", OPTION_STRING, "directory to save debugger comments" },
85
// state/playback options
86
{ NULL, NULL, OPTION_HEADER, "CORE STATE/PLAYBACK OPTIONS" },
87
{ OPTION_STATE, NULL, OPTION_STRING, "saved state to load" },
88
{ OPTION_AUTOSAVE, "0", OPTION_BOOLEAN, "enable automatic restore at startup, and automatic save at exit time" },
89
{ OPTION_PLAYBACK ";pb", NULL, OPTION_STRING, "playback an input file" },
90
{ OPTION_RECORD ";rec", NULL, OPTION_STRING, "record an input file" },
91
{ OPTION_MNGWRITE, NULL, OPTION_STRING, "optional filename to write a MNG movie of the current session" },
92
{ OPTION_AVIWRITE, NULL, OPTION_STRING, "optional filename to write an AVI movie of the current session" },
93
{ OPTION_WAVWRITE, NULL, OPTION_STRING, "optional filename to write a WAV file of the current session" },
94
{ OPTION_SNAPNAME, "%g/%i", OPTION_STRING, "override of the default snapshot/movie naming; %g == gamename, %i == index" },
95
{ OPTION_SNAPSIZE, "auto", OPTION_STRING, "specify snapshot/movie resolution (<width>x<height>) or 'auto' to use minimal size " },
96
{ OPTION_SNAPVIEW, "internal", OPTION_STRING, "specify snapshot/movie view or 'internal' to use internal pixel-aspect views" },
97
{ OPTION_BURNIN, "0", OPTION_BOOLEAN, "create burn-in snapshots for each screen" },
99
// performance options
100
{ NULL, NULL, OPTION_HEADER, "CORE PERFORMANCE OPTIONS" },
101
{ OPTION_AUTOFRAMESKIP ";afs", "0", OPTION_BOOLEAN, "enable automatic frameskip selection" },
102
{ OPTION_FRAMESKIP ";fs(0-10)", "0", OPTION_INTEGER, "set frameskip to fixed value, 0-10 (autoframeskip must be disabled)" },
103
{ OPTION_SECONDS_TO_RUN ";str", "0", OPTION_INTEGER, "number of emulated seconds to run before automatically exiting" },
104
{ OPTION_THROTTLE, "1", OPTION_BOOLEAN, "enable throttling to keep game running in sync with real time" },
105
{ OPTION_SLEEP, "1", OPTION_BOOLEAN, "enable sleeping, which gives time back to other applications when idle" },
106
{ OPTION_SPEED "(0.01-100)", "1.0", OPTION_FLOAT, "controls the speed of gameplay, relative to realtime; smaller numbers are slower" },
107
{ OPTION_REFRESHSPEED ";rs", "0", OPTION_BOOLEAN, "automatically adjusts the speed of gameplay to keep the refresh rate lower than the screen" },
110
{ NULL, NULL, OPTION_HEADER, "CORE ROTATION OPTIONS" },
111
{ OPTION_ROTATE, "1", OPTION_BOOLEAN, "rotate the game screen according to the game's orientation needs it" },
112
{ OPTION_ROR, "0", OPTION_BOOLEAN, "rotate screen clockwise 90 degrees" },
113
{ OPTION_ROL, "0", OPTION_BOOLEAN, "rotate screen counterclockwise 90 degrees" },
114
{ OPTION_AUTOROR, "0", OPTION_BOOLEAN, "automatically rotate screen clockwise 90 degrees if vertical" },
115
{ OPTION_AUTOROL, "0", OPTION_BOOLEAN, "automatically rotate screen counterclockwise 90 degrees if vertical" },
116
{ OPTION_FLIPX, "0", OPTION_BOOLEAN, "flip screen left-right" },
117
{ OPTION_FLIPY, "0", OPTION_BOOLEAN, "flip screen upside-down" },
120
{ NULL, NULL, OPTION_HEADER, "CORE ARTWORK OPTIONS" },
121
{ OPTION_ARTWORK_CROP ";artcrop", "0", OPTION_BOOLEAN, "crop artwork to game screen size" },
122
{ OPTION_USE_BACKDROPS ";backdrop", "1", OPTION_BOOLEAN, "enable backdrops if artwork is enabled and available" },
123
{ OPTION_USE_OVERLAYS ";overlay", "1", OPTION_BOOLEAN, "enable overlays if artwork is enabled and available" },
124
{ OPTION_USE_BEZELS ";bezel", "1", OPTION_BOOLEAN, "enable bezels if artwork is enabled and available" },
125
{ OPTION_USE_CPANELS ";cpanel", "1", OPTION_BOOLEAN, "enable cpanels if artwork is enabled and available" },
126
{ OPTION_USE_MARQUEES ";marquee", "1", OPTION_BOOLEAN, "enable marquees if artwork is enabled and available" },
129
{ NULL, NULL, OPTION_HEADER, "CORE SCREEN OPTIONS" },
130
{ OPTION_BRIGHTNESS "(0.1-2.0)", "1.0", OPTION_FLOAT, "default game screen brightness correction" },
131
{ OPTION_CONTRAST "(0.1-2.0)", "1.0", OPTION_FLOAT, "default game screen contrast correction" },
132
{ OPTION_GAMMA "(0.1-3.0)", "1.0", OPTION_FLOAT, "default game screen gamma correction" },
133
{ OPTION_PAUSE_BRIGHTNESS "(0.0-1.0)", "0.65", OPTION_FLOAT, "amount to scale the screen brightness when paused" },
134
{ OPTION_EFFECT, "none", OPTION_STRING, "name of a PNG file to use for visual effects, or 'none'" },
137
{ NULL, NULL, OPTION_HEADER, "CORE VECTOR OPTIONS" },
138
{ OPTION_ANTIALIAS ";aa", "1", OPTION_BOOLEAN, "use antialiasing when drawing vectors" },
139
{ OPTION_BEAM, "1.0", OPTION_FLOAT, "set vector beam width" },
140
{ OPTION_FLICKER, "0", OPTION_FLOAT, "set vector flicker effect" },
143
{ NULL, NULL, OPTION_HEADER, "CORE SOUND OPTIONS" },
144
{ OPTION_SOUND, "1", OPTION_BOOLEAN, "enable sound output" },
145
{ OPTION_SAMPLERATE ";sr(1000-1000000)", "48000", OPTION_INTEGER, "set sound output sample rate" },
146
{ OPTION_SAMPLES, "1", OPTION_BOOLEAN, "enable the use of external samples if available" },
147
{ OPTION_VOLUME ";vol", "0", OPTION_INTEGER, "sound volume in decibels (-32 min, 0 max)" },
150
{ NULL, NULL, OPTION_HEADER, "CORE INPUT OPTIONS" },
151
{ OPTION_COIN_LOCKOUT ";coinlock", "1", OPTION_BOOLEAN, "enable coin lockouts to actually lock out coins" },
152
{ OPTION_CTRLR, NULL, OPTION_STRING, "preconfigure for specified controller" },
153
{ OPTION_MOUSE, "0", OPTION_BOOLEAN, "enable mouse input" },
154
{ OPTION_JOYSTICK ";joy", "1", OPTION_BOOLEAN, "enable joystick input" },
155
{ OPTION_LIGHTGUN ";gun", "0", OPTION_BOOLEAN, "enable lightgun input" },
156
{ OPTION_MULTIKEYBOARD ";multikey", "0", OPTION_BOOLEAN, "enable separate input from each keyboard device (if present)" },
157
{ OPTION_MULTIMOUSE, "0", OPTION_BOOLEAN, "enable separate input from each mouse device (if present)" },
158
{ OPTION_STEADYKEY ";steady", "0", OPTION_BOOLEAN, "enable steadykey support" },
159
{ OPTION_OFFSCREEN_RELOAD ";reload", "0", OPTION_BOOLEAN, "convert lightgun button 2 into offscreen reload" },
160
{ OPTION_JOYSTICK_MAP ";joymap", "auto", OPTION_STRING, "explicit joystick map, or auto to auto-select" },
161
{ OPTION_JOYSTICK_DEADZONE ";joy_deadzone;jdz", "0.3", OPTION_FLOAT, "center deadzone range for joystick where change is ignored (0.0 center, 1.0 end)" },
162
{ OPTION_JOYSTICK_SATURATION ";joy_saturation;jsat", "0.85", OPTION_FLOAT, "end of axis saturation range for joystick where change is ignored (0.0 center, 1.0 end)" },
163
{ OPTION_NATURAL_KEYBOARD ";nat", "0", OPTION_BOOLEAN, "specifies whether to use a natural keyboard or not" },
165
// input autoenable options
166
{ NULL, NULL, OPTION_HEADER, "CORE INPUT AUTOMATIC ENABLE OPTIONS" },
167
{ OPTION_PADDLE_DEVICE ";paddle", "keyboard", OPTION_STRING, "enable (none|keyboard|mouse|lightgun|joystick) if a paddle control is present" },
168
{ OPTION_ADSTICK_DEVICE ";adstick", "keyboard", OPTION_STRING, "enable (none|keyboard|mouse|lightgun|joystick) if an analog joystick control is present" },
169
{ OPTION_PEDAL_DEVICE ";pedal", "keyboard", OPTION_STRING, "enable (none|keyboard|mouse|lightgun|joystick) if a pedal control is present" },
170
{ OPTION_DIAL_DEVICE ";dial", "keyboard", OPTION_STRING, "enable (none|keyboard|mouse|lightgun|joystick) if a dial control is present" },
171
{ OPTION_TRACKBALL_DEVICE ";trackball", "keyboard", OPTION_STRING, "enable (none|keyboard|mouse|lightgun|joystick) if a trackball control is present" },
172
{ OPTION_LIGHTGUN_DEVICE, "keyboard", OPTION_STRING, "enable (none|keyboard|mouse|lightgun|joystick) if a lightgun control is present" },
173
{ OPTION_POSITIONAL_DEVICE, "keyboard", OPTION_STRING, "enable (none|keyboard|mouse|lightgun|joystick) if a positional control is present" },
174
{ OPTION_MOUSE_DEVICE, "mouse", OPTION_STRING, "enable (none|keyboard|mouse|lightgun|joystick) if a mouse control is present" },
177
{ NULL, NULL, OPTION_HEADER, "CORE DEBUGGING OPTIONS" },
178
{ OPTION_LOG, "0", OPTION_BOOLEAN, "generate an error.log file" },
179
{ OPTION_VERBOSE ";v", "0", OPTION_BOOLEAN, "display additional diagnostic information" },
180
{ OPTION_UPDATEINPAUSE, "0", OPTION_BOOLEAN, "keep calling video updates while in pause" },
181
{ OPTION_DEBUG ";d", "0", OPTION_BOOLEAN, "enable/disable debugger" },
182
{ OPTION_DEBUGSCRIPT, NULL, OPTION_STRING, "script for debugger" },
183
{ OPTION_DEBUG_INTERNAL ";di", "0", OPTION_BOOLEAN, "use the internal debugger for debugging" },
186
{ NULL, NULL, OPTION_HEADER, "CORE MISC OPTIONS" },
187
{ OPTION_BIOS, NULL, OPTION_STRING, "select the system BIOS to use" },
188
{ OPTION_CHEAT ";c", "0", OPTION_BOOLEAN, "enable cheat subsystem" },
189
{ OPTION_SKIP_GAMEINFO, "0", OPTION_BOOLEAN, "skip displaying the information screen at startup" },
190
{ OPTION_UI_FONT, "default", OPTION_STRING, "specify a font to use" },
191
{ OPTION_RAMSIZE ";ram", NULL, OPTION_STRING, "size of RAM (if supported by driver)" },
192
{ OPTION_CONFIRM_QUIT, "0", OPTION_BOOLEAN, "display confirm quit screen on exit" },
198
//**************************************************************************
200
//**************************************************************************
202
//-------------------------------------------------
203
// emu_options - constructor
204
//-------------------------------------------------
206
emu_options::emu_options()
208
add_entries(s_option_entries);
212
//-------------------------------------------------
213
// add_slot_options - add all of the slot
214
// options for the configured system
215
//-------------------------------------------------
217
bool emu_options::add_slot_options(bool isfirst)
219
// look up the system configured by name; if no match, do nothing
220
const game_driver *cursystem = system();
221
if (cursystem == NULL)
224
// iterate through all slot devices
225
options_entry entry[2] = { { 0 }, { 0 } };
227
const device_slot_interface *slot = NULL;
228
// create the configuration
229
machine_config config(*cursystem, *this);
231
for (bool gotone = config.devicelist().first(slot); gotone; gotone = slot->next(slot))
233
// first device? add the header as to be pretty
234
if (first && isfirst)
236
entry[0].name = NULL;
237
entry[0].description = "SLOT DEVICES";
238
entry[0].flags = OPTION_HEADER | OPTION_FLAG_DEVICE;
239
entry[0].defvalue = NULL;
244
// retrieve info about the device instance
246
option_name.printf("%s;%s", slot->device().tag(), slot->device().tag());
248
if (!exists(slot->device().tag())) {
251
entry[0].name = slot->device().tag();
252
entry[0].description = NULL;
253
entry[0].flags = OPTION_STRING | OPTION_FLAG_DEVICE;
254
entry[0].defvalue = (slot->get_slot_interfaces() != NULL) ? slot->get_default_card() : NULL;
255
add_entries(entry, true);
263
//-------------------------------------------------
264
// add_device_options - add all of the device
265
// options for the configured system
266
//-------------------------------------------------
268
void emu_options::add_device_options(bool isfirst)
270
// look up the system configured by name; if no match, do nothing
271
const game_driver *cursystem = system();
272
if (cursystem == NULL)
275
// iterate through all slot devices
276
options_entry entry[2] = { { 0 }, { 0 } };
278
// iterate through all image devices
279
const device_image_interface *image = NULL;
280
machine_config config(*cursystem, *this);
281
for (bool gotone = config.devicelist().first(image); gotone; gotone = image->next(image))
283
// first device? add the header as to be pretty
284
if (first && isfirst)
286
entry[0].name = NULL;
287
entry[0].description = "IMAGE DEVICES";
288
entry[0].flags = OPTION_HEADER | OPTION_FLAG_DEVICE;
289
entry[0].defvalue = NULL;
294
// retrieve info about the device instance
296
option_name.printf("%s;%s", image->instance_name(), image->brief_instance_name());
299
entry[0].name = option_name;
300
entry[0].description = NULL;
301
entry[0].flags = OPTION_STRING | OPTION_FLAG_DEVICE;
302
entry[0].defvalue = NULL;
303
add_entries(entry, true);
308
//-------------------------------------------------
309
// remove_device_options - remove device options
310
//-------------------------------------------------
312
void emu_options::remove_device_options()
314
// iterate through options and remove interesting ones
316
for (entry *curentry = first(); curentry != NULL; curentry = nextentry)
318
// pre-fetch the next entry in case we delete this one
319
nextentry = curentry->next();
321
// if this is a device option, nuke it
322
if ((curentry->flags() & OPTION_FLAG_DEVICE) != 0)
323
remove_entry(*curentry);
328
//-------------------------------------------------
329
// parse_command_line - parse the command line
330
// and update the devices
331
//-------------------------------------------------
333
bool emu_options::parse_command_line(int argc, char *argv[], astring &error_string)
335
// remember the original system name
336
astring old_system_name(system_name());
339
bool result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
341
// if the system name changed, fix up the device options
342
if (old_system_name != system_name())
344
// remove any existing device options
345
remove_device_options();
346
add_device_options(true);
348
while (add_slot_options(isfirst)) {
349
result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
350
add_device_options(false);
353
// if we failed the first time, try parsing again with the new options in place
355
result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
361
//-------------------------------------------------
362
// parse_standard_inis - parse the standard set
364
//-------------------------------------------------
366
void emu_options::parse_standard_inis(astring &error_string)
368
// start with an empty string
369
error_string.reset();
371
// parse the INI file defined by the platform (e.g., "mame.ini")
372
// we do this twice so that the first file can change the INI path
373
parse_one_ini(CONFIGNAME, OPTION_PRIORITY_MAME_INI);
374
parse_one_ini(CONFIGNAME, OPTION_PRIORITY_MAME_INI, &error_string);
376
// debug mode: parse "debug.ini" as well
378
parse_one_ini("debug", OPTION_PRIORITY_DEBUG_INI, &error_string);
380
// if we have a valid system driver, parse system-specific INI files
381
const game_driver *cursystem = system();
382
if (cursystem == NULL)
385
// parse "vertical.ini" or "horizont.ini"
386
if (cursystem->flags & ORIENTATION_SWAP_XY)
387
parse_one_ini("vertical", OPTION_PRIORITY_ORIENTATION_INI, &error_string);
389
parse_one_ini("horizont", OPTION_PRIORITY_ORIENTATION_INI, &error_string);
391
// parse "vector.ini" for vector games
393
machine_config config(*cursystem, *this);
394
for (const screen_device *device = config.first_screen(); device != NULL; device = device->next_screen())
395
if (device->screen_type() == SCREEN_TYPE_VECTOR)
397
parse_one_ini("vector", OPTION_PRIORITY_VECTOR_INI, &error_string);
402
// next parse "source/<sourcefile>.ini"; if that doesn't exist, try <sourcefile>.ini
404
core_filename_extract_base(&sourcename, cursystem->source_file, TRUE)->ins(0, "source" PATH_SEPARATOR);
405
if (!parse_one_ini(sourcename, OPTION_PRIORITY_SOURCE_INI, &error_string))
407
core_filename_extract_base(&sourcename, cursystem->source_file, TRUE);
408
parse_one_ini(sourcename, OPTION_PRIORITY_SOURCE_INI, &error_string);
411
// then parse the grandparent, parent, and system-specific INIs
412
int parent = driver_list::clone(*cursystem);
413
int gparent = (parent != -1) ? driver_list::clone(parent) : -1;
415
parse_one_ini(driver_list::driver(gparent).name, OPTION_PRIORITY_GPARENT_INI, &error_string);
417
parse_one_ini(driver_list::driver(parent).name, OPTION_PRIORITY_PARENT_INI, &error_string);
418
parse_one_ini(cursystem->name, OPTION_PRIORITY_DRIVER_INI, &error_string);
422
//-------------------------------------------------
423
// system - return a pointer to the specified
424
// system driver, or NULL if no match
425
//-------------------------------------------------
427
const game_driver *emu_options::system() const
430
int index = driver_list::find(*core_filename_extract_base(&tempstr, system_name(), TRUE));
431
return (index != -1) ? &driver_list::driver(index) : NULL;
435
//-------------------------------------------------
436
// set_system_name - set a new system name
437
//-------------------------------------------------
439
void emu_options::set_system_name(const char *name)
441
// remember the original system name
442
astring old_system_name(system_name());
444
// if the system name changed, fix up the device options
445
if (old_system_name != name)
447
// first set the new name
449
set_value(OPTION_SYSTEMNAME, name, OPTION_PRIORITY_CMDLINE, error);
451
// remove any existing device options
452
remove_device_options();
453
// then add the options
454
add_device_options(true);
459
//-------------------------------------------------
460
// device_option - return the value of the
461
// device-specific option
462
//-------------------------------------------------
464
const char *emu_options::device_option(device_image_interface &image)
466
return value(image.instance_name());
470
//-------------------------------------------------
471
// parse_one_ini - parse a single INI file
472
//-------------------------------------------------
474
bool emu_options::parse_one_ini(const char *basename, int priority, astring *error_string)
476
// don't parse if it has been disabled
480
// open the file; if we fail, that's ok
481
emu_file file(ini_path(), OPEN_FLAG_READ);
482
file_error filerr = file.open(basename, ".ini");
483
if (filerr != FILERR_NONE)
487
mame_printf_verbose("Parsing %s.ini\n", basename);
489
bool result = parse_ini_file(file, priority, OPTION_PRIORITY_DRIVER_INI, error);
491
// append errors if requested
492
if (error && error_string != NULL)
493
error_string->catprintf("While parsing %s:\n%s\n", file.fullpath(), error.cstr());