21
21
- calls mame_validitychecks() [validity.c] to perform validity checks on all compiled drivers
22
22
- calls setjmp to prepare for deep error handling
23
23
- begins resource tracking (level 1)
24
- calls create_machine [mame.c] to initialize the Machine structure
24
- calls create_machine [mame.c] to initialize the running_machine structure
25
25
- calls init_machine() [mame.c]
27
27
init_machine() [mame.c]
98
98
/***************************************************************************
100
***************************************************************************/
102
#define MAX_MEMORY_REGIONS 32
106
/***************************************************************************
108
100
***************************************************************************/
180
172
***************************************************************************/
182
174
/* the active machine */
183
static running_machine *Machine;
175
static running_machine *global_machine;
185
177
/* the current options */
186
178
static core_options *mame_opts;
212
204
extern int mame_validitychecks(const game_driver *driver);
214
static int parse_ini_file(core_options *options, const char *name);
206
static int parse_ini_file(core_options *options, const char *name, int priority);
216
208
static running_machine *create_machine(const game_driver *driver);
217
209
static void destroy_machine(running_machine *machine);
241
233
const device_config *cpu;
243
for (cpu = machine->cpu[0]; cpu != NULL; cpu = cpu->typenext)
235
for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu))
244
236
cpu_eat_cycles(cpu, 1000000000);
335
327
/* load the configuration settings and NVRAM */
336
328
settingsloaded = config_load_settings(machine);
337
329
nvram_load(machine);
330
sound_mute(machine, FALSE);
340
332
/* display the startup screens */
341
333
ui_display_startup_screens(machine, firstrun, !settingsloaded);
353
345
mame->hard_reset_pending = FALSE;
354
346
while ((!mame->hard_reset_pending && !mame->exit_pending) || mame->saveload_pending_file != NULL)
356
profiler_mark(PROFILER_EXTRA);
348
profiler_mark_start(PROFILER_EXTRA);
358
350
/* execute CPUs if not paused */
359
351
if (!mame->paused)
546
/*-------------------------------------------------
547
mame_is_valid_machine - return true if the
548
given machine is valid
549
-------------------------------------------------*/
551
int mame_is_valid_machine(running_machine *machine)
553
return (machine != NULL && machine == global_machine);
555
558
/***************************************************************************
556
559
GLOBAL SYSTEM STATES
1146
1149
void CLIB_DECL fatalerror(const char *text, ...)
1148
extern running_machine *Machine;
1149
running_machine *machine = Machine;
1151
running_machine *machine = global_machine;
1152
1154
/* dump to the buffer; assume no one writes >2k lines this way */
1205
1207
void CLIB_DECL logerror(const char *format, ...)
1207
extern running_machine *Machine;
1208
running_machine *machine = Machine;
1209
running_machine *machine = global_machine;
1210
1211
/* currently, we need a machine to do this */
1211
1212
if (machine != NULL)
1299
1300
/* parse the INI file defined by the platform (e.g., "mame.ini") */
1300
1301
/* we do this twice so that the first file can change the INI path */
1301
parse_ini_file(options, CONFIGNAME);
1302
parse_ini_file(options, CONFIGNAME);
1302
parse_ini_file(options, CONFIGNAME, OPTION_PRIORITY_MAME_INI);
1303
parse_ini_file(options, CONFIGNAME, OPTION_PRIORITY_MAME_INI);
1304
1305
/* debug mode: parse "debug.ini" as well */
1305
1306
if (options_get_bool(options, OPTION_DEBUG))
1306
parse_ini_file(options, "debug");
1307
parse_ini_file(options, "debug", OPTION_PRIORITY_DEBUG_INI);
1308
1309
/* if we have a valid game driver, parse game-specific INI files */
1309
1310
if (driver != NULL)
1311
1313
const game_driver *parent = driver_get_clone(driver);
1312
1314
const game_driver *gparent = (parent != NULL) ? driver_get_clone(parent) : NULL;
1313
1315
const device_config *device;
1317
1319
/* parse "vertical.ini" or "horizont.ini" */
1318
1320
if (driver->flags & ORIENTATION_SWAP_XY)
1319
parse_ini_file(options, "vertical");
1321
parse_ini_file(options, "vertical", OPTION_PRIORITY_ORIENTATION_INI);
1321
parse_ini_file(options, "horizont");
1323
parse_ini_file(options, "horizont", OPTION_PRIORITY_ORIENTATION_INI);
1323
1325
/* parse "vector.ini" for vector games */
1324
1326
config = machine_config_alloc(driver->machine_config);
1327
1329
const screen_config *scrconfig = (const screen_config *)device->inline_config;
1328
1330
if (scrconfig->type == SCREEN_TYPE_VECTOR)
1330
parse_ini_file(options, "vector");
1332
parse_ini_file(options, "vector", OPTION_PRIORITY_VECTOR_INI);
1336
1338
/* next parse "source/<sourcefile>.ini"; if that doesn't exist, try <sourcefile>.ini */
1337
1339
sourcename = core_filename_extract_base(astring_alloc(), driver->source_file, TRUE);
1338
1340
astring_insc(sourcename, 0, "source" PATH_SEPARATOR);
1339
if (!parse_ini_file(options, astring_c(sourcename)))
1341
if (!parse_ini_file(options, astring_c(sourcename), OPTION_PRIORITY_SOURCE_INI))
1341
1343
core_filename_extract_base(sourcename, driver->source_file, TRUE);
1342
parse_ini_file(options, astring_c(sourcename));
1344
parse_ini_file(options, astring_c(sourcename), OPTION_PRIORITY_SOURCE_INI);
1344
1346
astring_free(sourcename);
1346
1348
/* then parent the grandparent, parent, and game-specific INIs */
1347
1349
if (gparent != NULL)
1348
parse_ini_file(options, gparent->name);
1350
parse_ini_file(options, gparent->name, OPTION_PRIORITY_GPARENT_INI);
1349
1351
if (parent != NULL)
1350
parse_ini_file(options, parent->name);
1351
parse_ini_file(options, driver->name);
1352
parse_ini_file(options, parent->name, OPTION_PRIORITY_PARENT_INI);
1354
parse_ini_file(options, driver->name, OPTION_PRIORITY_DRIVER_INI);
1357
1360
parse_ini_file - parse a single INI file
1358
1361
-------------------------------------------------*/
1360
static int parse_ini_file(core_options *options, const char *name)
1363
static int parse_ini_file(core_options *options, const char *name, int priority)
1362
1365
file_error filerr;
1363
1366
mame_file *file;
1377
1380
/* parse the file and close it */
1378
1381
mame_printf_verbose("Parsing %s.ini\n", name);
1379
options_parse_ini_file(options, mame_core_file(file), OPTION_PRIORITY_INI);
1382
options_parse_ini_file(options, mame_core_file(file), priority);
1380
1383
mame_fclose(file);
1421
1423
/* find devices */
1422
machine->cpu[0] = cpu_first(machine->config);
1423
for (cpunum = 1; cpunum < ARRAY_LENGTH(machine->cpu) && machine->cpu[cpunum - 1] != NULL; cpunum++)
1424
machine->cpu[cpunum] = machine->cpu[cpunum - 1]->typenext;
1424
machine->firstcpu = cpu_first(machine->config);
1425
1425
machine->primary_screen = video_screen_first(machine->config);
1427
1427
/* attach this machine to all the devices in the configuration */
1453
1453
static void destroy_machine(running_machine *machine)
1455
assert(machine == Machine);
1455
assert(machine == global_machine);
1457
1457
if (machine->driver_data != NULL)
1458
1458
free(machine->driver_data);
1474
1474
static void init_machine(running_machine *machine)
1476
1476
mame_private *mame = machine->mame_data;
1477
const char *rgntag, *nextrgntag;
1478
1477
time_t newbase;
1480
1479
/* initialize basic can't-fail systems here */
1565
1564
if (machine->config->video_start != NULL)
1566
1565
(*machine->config->video_start)(machine);
1568
/* free memory regions allocated with REGIONFLAG_DISPOSE (typically gfx roms) */
1569
/* but not if the debugger is enabled (so we can look at the data) */
1570
if (PREDECODE_GFX && !options_get_bool(mame_options(), OPTION_DEBUG))
1571
for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = nextrgntag)
1573
nextrgntag = memory_region_next(machine, rgntag);
1574
if (memory_region_flags(machine, rgntag) & ROMREGION_DISPOSE)
1575
memory_region_free(machine, rgntag);
1578
1567
/* initialize miscellaneous systems */
1579
1568
saveload_init(machine);
1580
1569
if (options_get_bool(mame_options(), OPTION_CHEAT))