~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/emu/mame.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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]
26
26
 
27
27
            init_machine() [mame.c]
96
96
 
97
97
 
98
98
/***************************************************************************
99
 
    CONSTANTS
100
 
***************************************************************************/
101
 
 
102
 
#define MAX_MEMORY_REGIONS              32
103
 
 
104
 
 
105
 
 
106
 
/***************************************************************************
107
99
    TYPE DEFINITIONS
108
100
***************************************************************************/
109
101
 
180
172
***************************************************************************/
181
173
 
182
174
/* the active machine */
183
 
static running_machine *Machine;
 
175
static running_machine *global_machine;
184
176
 
185
177
/* the current options */
186
178
static core_options *mame_opts;
211
203
 
212
204
extern int mame_validitychecks(const game_driver *driver);
213
205
 
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);
215
207
 
216
208
static running_machine *create_machine(const game_driver *driver);
217
209
static void destroy_machine(running_machine *machine);
240
232
{
241
233
        const device_config *cpu;
242
234
 
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);
245
237
}
246
238
 
281
273
                /* if no driver, use the internal empty driver */
282
274
                if (driver == NULL)
283
275
                {
284
 
                        driver = &driver_empty;
 
276
                        driver = &GAME_NAME(empty);
285
277
                        if (firstgame)
286
278
                                started_empty = TRUE;
287
279
                }
303
295
                mame->current_phase = MAME_PHASE_PREINIT;
304
296
 
305
297
                /* looooong term: remove this */
306
 
                Machine = machine;
 
298
                global_machine = machine;
307
299
 
308
300
                init_resource_tracking();
309
301
 
335
327
                        /* load the configuration settings and NVRAM */
336
328
                        settingsloaded = config_load_settings(machine);
337
329
                        nvram_load(machine);
338
 
                        sound_mute(FALSE);
 
330
                        sound_mute(machine, FALSE);
339
331
 
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)
355
347
                        {
356
 
                                profiler_mark(PROFILER_EXTRA);
 
348
                                profiler_mark_start(PROFILER_EXTRA);
357
349
 
358
350
                                /* execute CPUs if not paused */
359
351
                                if (!mame->paused)
367
359
                                if (mame->saveload_schedule_callback != NULL)
368
360
                                        (*mame->saveload_schedule_callback)(machine);
369
361
 
370
 
                                profiler_mark(PROFILER_END);
 
362
                                profiler_mark_end();
371
363
                        }
372
364
 
373
365
                        /* and out via the exit phase */
377
369
                        end_resource_tracking();
378
370
 
379
371
                        /* save the NVRAM and configuration */
380
 
                        sound_mute(TRUE);
 
372
                        sound_mute(machine, TRUE);
381
373
                        nvram_save(machine);
382
374
                        config_save_settings(machine);
383
375
                }
551
543
}
552
544
 
553
545
 
 
546
/*-------------------------------------------------
 
547
    mame_is_valid_machine - return true if the
 
548
    given machine is valid
 
549
-------------------------------------------------*/
 
550
 
 
551
int mame_is_valid_machine(running_machine *machine)
 
552
{
 
553
        return (machine != NULL && machine == global_machine);
 
554
}
 
555
 
 
556
 
554
557
 
555
558
/***************************************************************************
556
559
    GLOBAL SYSTEM STATES
1145
1148
 
1146
1149
void CLIB_DECL fatalerror(const char *text, ...)
1147
1150
{
1148
 
        extern running_machine *Machine;
1149
 
        running_machine *machine = Machine;
 
1151
        running_machine *machine = global_machine;
1150
1152
        va_list arg;
1151
1153
 
1152
1154
        /* dump to the buffer; assume no one writes >2k lines this way */
1204
1206
 
1205
1207
void CLIB_DECL logerror(const char *format, ...)
1206
1208
{
1207
 
        extern running_machine *Machine;
1208
 
        running_machine *machine = Machine;
 
1209
        running_machine *machine = global_machine;
1209
1210
 
1210
1211
        /* currently, we need a machine to do this */
1211
1212
        if (machine != NULL)
1218
1219
                {
1219
1220
                        va_list arg;
1220
1221
 
1221
 
                        profiler_mark(PROFILER_LOGERROR);
 
1222
                        profiler_mark_start(PROFILER_LOGERROR);
1222
1223
 
1223
1224
                        /* dump to the buffer */
1224
1225
                        va_start(arg, format);
1229
1230
                        for (cb = mame->logerror_callback_list; cb; cb = cb->next)
1230
1231
                                (*cb->func.log)(machine, giant_string_buffer);
1231
1232
 
1232
 
                        profiler_mark(PROFILER_END);
 
1233
                        profiler_mark_end();
1233
1234
                }
1234
1235
        }
1235
1236
}
1298
1299
{
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);
1303
1304
 
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);
1307
1308
 
1308
1309
        /* if we have a valid game driver, parse game-specific INI files */
1309
1310
        if (driver != NULL)
1310
1311
        {
 
1312
#ifndef MESS
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;
1316
1318
 
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);
1320
1322
                else
1321
 
                        parse_ini_file(options, "horizont");
 
1323
                        parse_ini_file(options, "horizont", OPTION_PRIORITY_ORIENTATION_INI);
1322
1324
 
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)
1329
1331
                        {
1330
 
                                parse_ini_file(options, "vector");
 
1332
                                parse_ini_file(options, "vector", OPTION_PRIORITY_VECTOR_INI);
1331
1333
                                break;
1332
1334
                        }
1333
1335
                }
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))
1340
1342
                {
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);
1343
1345
                }
1344
1346
                astring_free(sourcename);
1345
1347
 
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);
 
1353
#endif  /* MESS */
 
1354
                parse_ini_file(options, driver->name, OPTION_PRIORITY_DRIVER_INI);
1352
1355
        }
1353
1356
}
1354
1357
 
1357
1360
    parse_ini_file - parse a single INI file
1358
1361
-------------------------------------------------*/
1359
1362
 
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)
1361
1364
{
1362
1365
        file_error filerr;
1363
1366
        mame_file *file;
1376
1379
 
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);
1381
1384
        return TRUE;
1382
1385
}
1390
1393
static running_machine *create_machine(const game_driver *driver)
1391
1394
{
1392
1395
        running_machine *machine;
1393
 
        int cpunum;
1394
1396
 
1395
1397
        /* allocate memory for the machine */
1396
1398
        machine = (running_machine *)malloc(sizeof(*machine));
1419
1421
        }
1420
1422
 
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);
1426
1426
 
1427
1427
        /* attach this machine to all the devices in the configuration */
1452
1452
 
1453
1453
static void destroy_machine(running_machine *machine)
1454
1454
{
1455
 
        assert(machine == Machine);
 
1455
        assert(machine == global_machine);
1456
1456
 
1457
1457
        if (machine->driver_data != NULL)
1458
1458
                free(machine->driver_data);
1463
1463
        if (machine->basename != NULL)
1464
1464
                free((void *)machine->basename);
1465
1465
        free(machine);
1466
 
        Machine = NULL;
 
1466
        global_machine = NULL;
1467
1467
}
1468
1468
 
1469
1469
 
1474
1474
static void init_machine(running_machine *machine)
1475
1475
{
1476
1476
        mame_private *mame = machine->mame_data;
1477
 
        const char *rgntag, *nextrgntag;
1478
1477
        time_t newbase;
1479
1478
 
1480
1479
        /* initialize basic can't-fail systems here */
1565
1564
        if (machine->config->video_start != NULL)
1566
1565
                (*machine->config->video_start)(machine);
1567
1566
 
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)
1572
 
                {
1573
 
                        nextrgntag = memory_region_next(machine, rgntag);
1574
 
                        if (memory_region_flags(machine, rgntag) & ROMREGION_DISPOSE)
1575
 
                                memory_region_free(machine, rgntag);
1576
 
                }
1577
 
 
1578
1567
        /* initialize miscellaneous systems */
1579
1568
        saveload_init(machine);
1580
1569
        if (options_get_bool(mame_options(), OPTION_CHEAT))