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

« back to all changes in this revision

Viewing changes to src/emu/romload.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:
34
34
    TYPE DEFINITIONS
35
35
***************************************************************************/
36
36
 
37
 
typedef struct _rom_load_data rom_load_data;
38
 
struct _rom_load_data
 
37
typedef struct _open_chd open_chd;
 
38
struct _open_chd
 
39
{
 
40
        open_chd *                      next;                                   /* pointer to next in the list */
 
41
        const char *            region;                                 /* disk region we came from */
 
42
        chd_file *                      origchd;                                /* handle to the original CHD */
 
43
        mame_file *                     origfile;                               /* file handle to the original CHD file */
 
44
        chd_file *                      diffchd;                                /* handle to the diff CHD */
 
45
        mame_file *                     difffile;                               /* file handle to the diff CHD file */
 
46
};
 
47
 
 
48
 
 
49
typedef struct _romload_private rom_load_data;
 
50
struct _romload_private
39
51
{
40
52
        running_machine *machine;                       /* machine object where needed */
41
53
        int                             system_bios;            /* the system BIOS we wish to load */
49
61
        UINT32                  romstotalsize;          /* total size of ROMs to read */
50
62
 
51
63
        mame_file *             file;                           /* current file */
 
64
        open_chd *              chd_list;                       /* disks */
 
65
        open_chd **             chd_list_tailptr;
52
66
 
53
67
        UINT8 *                 regionbase;                     /* base of current region */
54
68
        UINT32                  regionlength;           /* length of current region */
57
71
};
58
72
 
59
73
 
60
 
typedef struct _open_chd open_chd;
61
 
struct _open_chd
62
 
{
63
 
        open_chd *                      next;                                   /* pointer to next in the list */
64
 
        const char *            region;                                 /* disk region we came from */
65
 
        chd_file *                      origchd;                                /* handle to the original CHD */
66
 
        mame_file *                     origfile;                               /* file handle to the original CHD file */
67
 
        chd_file *                      diffchd;                                /* handle to the diff CHD */
68
 
        mame_file *                     difffile;                               /* file handle to the diff CHD file */
69
 
};
70
 
 
71
 
 
72
 
 
73
 
/***************************************************************************
74
 
    GLOBAL VARIABLES
75
 
***************************************************************************/
76
 
 
77
 
/* disks */
78
 
static open_chd *chd_list;
79
 
static open_chd **chd_list_tailptr;
80
 
 
81
 
static int total_rom_load_warnings;
82
 
 
83
 
 
84
 
 
85
74
/***************************************************************************
86
75
    FUNCTION PROTOTYPES
87
76
***************************************************************************/
99
88
    CHD file associated with the given region
100
89
-------------------------------------------------*/
101
90
 
102
 
chd_file *get_disk_handle(const char *region)
 
91
chd_file *get_disk_handle(running_machine *machine, const char *region)
103
92
{
104
93
        open_chd *curdisk;
105
94
 
106
 
        for (curdisk = chd_list; curdisk != NULL; curdisk = curdisk->next)
 
95
        for (curdisk = machine->romload_data->chd_list; curdisk != NULL; curdisk = curdisk->next)
107
96
                if (strcmp(curdisk->region, region) == 0)
108
97
                        return (curdisk->diffchd != NULL) ? curdisk->diffchd : curdisk->origchd;
109
98
        return NULL;
111
100
 
112
101
 
113
102
/*-------------------------------------------------
 
103
    add_disk_handle - add a disk to the to the
 
104
    list of CHD files
 
105
-------------------------------------------------*/
 
106
 
 
107
static void add_disk_handle(running_machine *machine, open_chd *chd)
 
108
{
 
109
        romload_private *romload_data = machine->romload_data;
 
110
 
 
111
        *romload_data->chd_list_tailptr = auto_alloc(machine, open_chd);
 
112
        **romload_data->chd_list_tailptr = *chd;
 
113
        romload_data->chd_list_tailptr = &(*romload_data->chd_list_tailptr)->next;
 
114
}
 
115
 
 
116
 
 
117
/*-------------------------------------------------
114
118
    set_disk_handle - set a pointer to the CHD
115
119
    file associated with the given region
116
120
-------------------------------------------------*/
125
129
        chd.origfile = file;
126
130
 
127
131
        /* we're okay, add to the list of disks */
128
 
        *chd_list_tailptr = auto_alloc(machine, open_chd);
129
 
        **chd_list_tailptr = chd;
130
 
        chd_list_tailptr = &(*chd_list_tailptr)->next;
 
132
        add_disk_handle(machine, &chd);
131
133
}
132
134
 
133
135
 
1225
1227
 
1226
1228
                        /* we're okay, add to the list of disks */
1227
1229
                        LOG(("Assigning to handle %d\n", DISK_GETINDEX(romp)));
1228
 
                        *chd_list_tailptr = auto_alloc(romdata->machine, open_chd);
1229
 
                        **chd_list_tailptr = chd;
1230
 
                        chd_list_tailptr = &(*chd_list_tailptr)->next;
 
1230
                        add_disk_handle(romdata->machine, &chd);
1231
1231
                }
1232
1232
        }
1233
1233
        astring_free(filename);
1338
1338
 
1339
1339
void rom_init(running_machine *machine)
1340
1340
{
1341
 
        rom_load_data romdata;
 
1341
        rom_load_data *romdata;
 
1342
 
 
1343
        /* allocate private data */
 
1344
        machine->romload_data = romdata = auto_alloc_clear(machine, romload_private);
1342
1345
 
1343
1346
        /* make sure we get called back on the way out */
1344
1347
        add_exit_callback(machine, rom_exit);
1345
1348
 
1346
1349
        /* reset the romdata struct */
1347
 
        memset(&romdata, 0, sizeof(romdata));
1348
 
        romdata.machine = machine;
1349
 
        romdata.errorstring = astring_alloc();
 
1350
        romdata->machine = machine;
 
1351
        romdata->errorstring = astring_alloc();
1350
1352
 
1351
1353
        /* figure out which BIOS we are using */
1352
 
        determine_bios_rom(&romdata);
 
1354
        determine_bios_rom(romdata);
1353
1355
 
1354
1356
        /* count the total number of ROMs */
1355
 
        count_roms(&romdata);
 
1357
        count_roms(romdata);
1356
1358
 
1357
1359
        /* reset the disk list */
1358
 
        chd_list = NULL;
1359
 
        chd_list_tailptr = &chd_list;
 
1360
        romdata->chd_list = NULL;
 
1361
        romdata->chd_list_tailptr = &machine->romload_data->chd_list;
1360
1362
 
1361
1363
        /* process the ROM entries we were passed */
1362
 
        process_region_list(&romdata);
 
1364
        process_region_list(romdata);
1363
1365
 
1364
1366
        /* display the results and exit */
1365
 
        total_rom_load_warnings = romdata.warnings;
1366
 
        display_rom_load_results(&romdata);
1367
 
        astring_free(romdata.errorstring);
 
1367
        display_rom_load_results(romdata);
 
1368
        astring_free(romdata->errorstring);
1368
1369
}
1369
1370
 
1370
1371
 
1385
1386
        }
1386
1387
 
1387
1388
        /* close all hard drives */
1388
 
        for (curchd = chd_list; curchd != NULL; curchd = curchd->next)
 
1389
        for (curchd = machine->romload_data->chd_list; curchd != NULL; curchd = curchd->next)
1389
1390
        {
1390
1391
                if (curchd->diffchd != NULL)
1391
1392
                        chd_close(curchd->diffchd);
1404
1405
    warnings we generated
1405
1406
-------------------------------------------------*/
1406
1407
 
1407
 
int rom_load_warnings(void)
 
1408
int rom_load_warnings(running_machine *machine)
1408
1409
{
1409
 
        return total_rom_load_warnings;
 
1410
        return machine->romload_data->warnings;
1410
1411
}