Made core able to use bios selection per slot device [Miodrag Milanovic]

Sample of usage :
  mess kc85_4 -exp d004gide,bios=v31

Will need to cleanup handling of sub options to make it more robust and able to validate
This commit is contained in:
Miodrag Milanovic 2012-09-05 10:30:30 +00:00
parent f6c7aa39ba
commit 913ee29d76
6 changed files with 73 additions and 21 deletions

View File

@ -38,10 +38,11 @@ device_t* device_slot_interface::get_card_device()
{ {
const char *subtag; const char *subtag;
device_t *dev = NULL; device_t *dev = NULL;
astring temp;
if (!device().mconfig().options().exists(device().tag()+1)) { if (!device().mconfig().options().exists(device().tag()+1)) {
subtag = m_default_card; subtag = m_default_card;
} else { } else {
subtag = device().mconfig().options().value(device().tag()+1); subtag = device().mconfig().options().main_value(temp,device().tag()+1);
} }
if (subtag && *subtag != 0) { if (subtag && *subtag != 0) {
device_slot_card_interface *intf = NULL; device_slot_card_interface *intf = NULL;

View File

@ -565,3 +565,31 @@ bool emu_options::parse_one_ini(const char *basename, int priority, astring *err
return result; return result;
} }
const char *emu_options::main_value(astring &buffer, const char *name) const
{
buffer = value(name);
int pos = buffer.chr(0,',');
if (pos!=-1) {
buffer = buffer.substr(0,pos);
}
return buffer.cstr();
}
const char *emu_options::sub_value(astring &buffer, const char *name, const char *subname) const
{
astring tmp = ",";
tmp.cat(subname);
tmp.cat("=");
buffer = value(name);
int pos = buffer.find(0,tmp);
if (pos!=-1) {
int endpos = buffer.chr(pos+1,',');
if(endpos==-1) endpos = buffer.len();
buffer = buffer.substr(pos+tmp.len(),endpos-pos-tmp.len());
} else {
buffer ="";
}
return buffer.cstr();
}

View File

@ -357,6 +357,9 @@ public:
const char *device_option(device_image_interface &image); const char *device_option(device_image_interface &image);
void remove_device_options(); void remove_device_options();
const char *main_value(astring &buffer, const char *option) const;
const char *sub_value(astring &buffer, const char *name, const char *subname) const;
private: private:
// device-specific option handling // device-specific option handling
void add_device_options(bool isfirst); void add_device_options(bool isfirst);

View File

@ -76,7 +76,8 @@ machine_config::machine_config(const game_driver &gamedrv, emu_options &options)
if (intf != NULL) if (intf != NULL)
{ {
device_t &owner = slot->device(); device_t &owner = slot->device();
const char *selval = options.value(owner.tag()+1); astring temp;
const char *selval = options.main_value(temp, owner.tag()+1);
bool isdefault = (options.priority(owner.tag()+1)==OPTION_PRIORITY_DEFAULT); bool isdefault = (options.priority(owner.tag()+1)==OPTION_PRIORITY_DEFAULT);
if (!is_selected_driver || !options.exists(owner.tag()+1)) if (!is_selected_driver || !options.exists(owner.tag()+1))
selval = slot->get_default_card(); selval = slot->get_default_card();

View File

@ -283,24 +283,22 @@ static void CLIB_DECL ATTR_PRINTF(1,2) debugload(const char *string, ...)
from SystemBios structure and OPTION_BIOS from SystemBios structure and OPTION_BIOS
-------------------------------------------------*/ -------------------------------------------------*/
static void determine_bios_rom(rom_load_data *romdata) static void determine_bios_rom(rom_load_data *romdata, device_t *device,const char *specbios)
{ {
const char *specbios = romdata->machine().options().bios();
const char *defaultname = NULL; const char *defaultname = NULL;
const rom_entry *rom; const rom_entry *rom;
int default_no = 1; int default_no = 1;
int bios_count = 0; int bios_count = 0;
device_t &rootdevice = romdata->machine().config().root_device(); device->set_system_bios(0);
rootdevice.set_system_bios(0);
/* first determine the default BIOS name */ /* first determine the default BIOS name */
for (rom = rootdevice.rom_region(); !ROMENTRY_ISEND(rom); rom++) for (rom = device->rom_region(); !ROMENTRY_ISEND(rom); rom++)
if (ROMENTRY_ISDEFAULT_BIOS(rom)) if (ROMENTRY_ISDEFAULT_BIOS(rom))
defaultname = ROM_GETNAME(rom); defaultname = ROM_GETNAME(rom);
/* look for a BIOS with a matching name */ /* look for a BIOS with a matching name */
for (rom = rootdevice.rom_region(); !ROMENTRY_ISEND(rom); rom++) for (rom = device->rom_region(); !ROMENTRY_ISEND(rom); rom++)
if (ROMENTRY_ISSYSTEM_BIOS(rom)) if (ROMENTRY_ISSYSTEM_BIOS(rom))
{ {
const char *biosname = ROM_GETNAME(rom); const char *biosname = ROM_GETNAME(rom);
@ -310,14 +308,14 @@ static void determine_bios_rom(rom_load_data *romdata)
/* Allow '-bios n' to still be used */ /* Allow '-bios n' to still be used */
sprintf(bios_number, "%d", bios_flags - 1); sprintf(bios_number, "%d", bios_flags - 1);
if (mame_stricmp(bios_number, specbios) == 0 || mame_stricmp(biosname, specbios) == 0) if (mame_stricmp(bios_number, specbios) == 0 || mame_stricmp(biosname, specbios) == 0)
rootdevice.set_system_bios(bios_flags); device->set_system_bios(bios_flags);
if (defaultname != NULL && mame_stricmp(biosname, defaultname) == 0) if (defaultname != NULL && mame_stricmp(biosname, defaultname) == 0)
default_no = bios_flags; default_no = bios_flags;
bios_count++; bios_count++;
} }
/* if none found, use the default */ /* if none found, use the default */
if (rootdevice.system_bios() == 0 && bios_count > 0) if (device->system_bios() == 0 && bios_count > 0)
{ {
/* if we got neither an empty string nor 'default' then warn the user */ /* if we got neither an empty string nor 'default' then warn the user */
if (specbios[0] != 0 && strcmp(specbios, "default") != 0 && romdata != NULL) if (specbios[0] != 0 && strcmp(specbios, "default") != 0 && romdata != NULL)
@ -327,10 +325,10 @@ static void determine_bios_rom(rom_load_data *romdata)
} }
/* set to default */ /* set to default */
rootdevice.set_system_bios(default_no); device->set_system_bios(default_no);
} }
rootdevice.set_default_bios(default_no); device->set_default_bios(default_no);
LOG(("Using System BIOS: %d\n", rootdevice.system_bios())); LOG(("For \"%s\" using System BIOS: %d\n", device->tag(), device->system_bios()));
} }
@ -352,7 +350,7 @@ static void count_roms(rom_load_data *romdata)
for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
for (region = rom_first_region(*device); region != NULL; region = rom_next_region(region)) for (region = rom_first_region(*device); region != NULL; region = rom_next_region(region))
for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
if (ROM_GETBIOSFLAGS(rom) == 0 || ROM_GETBIOSFLAGS(rom) == romdata->machine().config().root_device().system_bios()) if (ROM_GETBIOSFLAGS(rom) == 0 || ROM_GETBIOSFLAGS(rom) == device->system_bios())
{ {
romdata->romstotal++; romdata->romstotal++;
romdata->romstotalsize += rom_file_size(rom); romdata->romstotalsize += rom_file_size(rom);
@ -848,7 +846,7 @@ static void copy_rom_data(rom_load_data *romdata, const rom_entry *romp)
for a region for a region
-------------------------------------------------*/ -------------------------------------------------*/
static void process_rom_entries(rom_load_data *romdata, const char *regiontag, const rom_entry *parent_region, const rom_entry *romp) static void process_rom_entries(rom_load_data *romdata, const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, device_t *device)
{ {
UINT32 lastflags = 0; UINT32 lastflags = 0;
@ -878,7 +876,7 @@ static void process_rom_entries(rom_load_data *romdata, const char *regiontag, c
/* handle files */ /* handle files */
else if (ROMENTRY_ISFILE(romp)) else if (ROMENTRY_ISFILE(romp))
{ {
int irrelevantbios = (ROM_GETBIOSFLAGS(romp) != 0 && ROM_GETBIOSFLAGS(romp) != romdata->machine().config().root_device().system_bios()); int irrelevantbios = (ROM_GETBIOSFLAGS(romp) != 0 && ROM_GETBIOSFLAGS(romp) != device->system_bios());
const rom_entry *baserom = romp; const rom_entry *baserom = romp;
int explength = 0; int explength = 0;
@ -1357,7 +1355,7 @@ void load_software_part_region(device_t *device, char *swlist, char *swname, rom
/* now process the entries in the region */ /* now process the entries in the region */
if (ROMREGION_ISROMDATA(region)) if (ROMREGION_ISROMDATA(region))
process_rom_entries(romdata, locationtag, region, region + 1); process_rom_entries(romdata, locationtag, region, region + 1, device);
else if (ROMREGION_ISDISKDATA(region)) else if (ROMREGION_ISDISKDATA(region))
process_disk_entries(romdata, core_strdup(regiontag.cstr()), region, region + 1, locationtag); process_disk_entries(romdata, core_strdup(regiontag.cstr()), region, region + 1, locationtag);
} }
@ -1421,7 +1419,7 @@ static void process_region_list(rom_load_data *romdata)
#endif #endif
/* now process the entries in the region */ /* now process the entries in the region */
process_rom_entries(romdata, device->shortname(), region, region + 1); process_rom_entries(romdata, device->shortname(), region, region + 1, device);
} }
else if (ROMREGION_ISDISKDATA(region)) else if (ROMREGION_ISDISKDATA(region))
process_disk_entries(romdata, regiontag, region, region + 1, NULL); process_disk_entries(romdata, regiontag, region, region + 1, NULL);
@ -1456,7 +1454,19 @@ void rom_init(running_machine &machine)
romdata->m_machine = &machine; romdata->m_machine = &machine;
/* figure out which BIOS we are using */ /* figure out which BIOS we are using */
determine_bios_rom(romdata); device_iterator deviter(romdata->machine().config().root_device());
for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) {
if (device->rom_region()) {
const char *specbios;
astring temp;
if (strcmp(device->tag(),":")==0) {
specbios = romdata->machine().options().bios();
} else {
specbios = romdata->machine().options().sub_value(temp,device->owner()->tag()+1,"bios");
}
determine_bios_rom(romdata, device, specbios);
}
}
/* count the total number of ROMs */ /* count the total number of ROMs */
count_roms(romdata); count_roms(romdata);

View File

@ -367,7 +367,8 @@ void ui_menu_keyboard_mode::handle()
-------------------------------------------------*/ -------------------------------------------------*/
int ui_menu_slot_devices::slot_get_current_index(device_slot_interface *slot) int ui_menu_slot_devices::slot_get_current_index(device_slot_interface *slot)
{ {
const char *current = machine().options().value(slot->device().tag()+1); astring temp;
const char *current = machine().options().main_value(temp,slot->device().tag()+1);
const slot_interface* intf = slot->get_slot_interfaces(); const slot_interface* intf = slot->get_slot_interfaces();
int val = -1; int val = -1;
for (int i = 0; intf[i].name != NULL; i++) { for (int i = 0; intf[i].name != NULL; i++) {
@ -421,7 +422,8 @@ const char *ui_menu_slot_devices::slot_get_prev(device_slot_interface *slot)
-------------------------------------------------*/ -------------------------------------------------*/
const char *ui_menu_slot_devices::get_slot_device(device_slot_interface *slot) const char *ui_menu_slot_devices::get_slot_device(device_slot_interface *slot)
{ {
return machine().options().value(slot->device().tag()+1); astring temp;
return machine().options().main_value(temp,slot->device().tag()+1);
} }
@ -551,6 +553,13 @@ void ui_menu_bios_selection::handle()
astring error; astring error;
machine().options().set_value("bios", val-1, OPTION_PRIORITY_CMDLINE, error); machine().options().set_value("bios", val-1, OPTION_PRIORITY_CMDLINE, error);
assert(!error); assert(!error);
} else {
astring error;
astring value;
astring temp;
value.printf("%s,bios=%d",machine().options().main_value(temp,dev->owner()->tag()+1),val-1);
machine().options().set_value(dev->owner()->tag()+1, value.cstr(), OPTION_PRIORITY_CMDLINE, error);
assert(!error);
} }
reset(UI_MENU_RESET_REMEMBER_REF); reset(UI_MENU_RESET_REMEMBER_REF);
} }