From 503be5cbdb4e06f03f052342f4f40d4898e5938e Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 26 Mar 2018 19:53:18 +1100 Subject: [PATCH] Allow machine configuration to specify BIOS easily, move default BIOS selection into device configuration complete --- src/emu/device.cpp | 51 +++++++++++++++++++++++++- src/emu/device.h | 9 +++-- src/emu/romload.cpp | 73 ++++++++++++++----------------------- src/emu/validity.cpp | 2 + src/mame/drivers/model1.cpp | 6 +-- src/mame/machine/m1comm.cpp | 6 +-- 6 files changed, 90 insertions(+), 57 deletions(-) diff --git a/src/emu/device.cpp b/src/emu/device.cpp index 56369026e76..a039ec1dc0c 100644 --- a/src/emu/device.cpp +++ b/src/emu/device.cpp @@ -231,7 +231,56 @@ void device_t::set_clock(u32 clock) void device_t::config_complete() { - // first notify the interfaces + // resolve default BIOS + tiny_rom_entry const *const roms(rom_region()); + if (roms) + { + // first pass: try to find default BIOS from ROM region or machine configuration + char const *defbios(m_default_bios_tag.empty() ? nullptr : m_default_bios_tag.c_str()); + bool twopass(false), havebios(false); + u8 firstbios(0); + for (const tiny_rom_entry *rom = roms; !m_default_bios && !ROMENTRY_ISEND(rom); ++rom) + { + if (ROMENTRY_ISSYSTEM_BIOS(rom)) + { + if (!havebios) + { + havebios = true; + firstbios = ROM_GETBIOSFLAGS(rom); + } + if (!defbios) + twopass = true; + else if (!std::strcmp(rom->name, defbios)) + m_default_bios = ROM_GETBIOSFLAGS(rom); + } + else if (!defbios && ROMENTRY_ISDEFAULT_BIOS(rom)) + { + defbios = rom->name; + } + } + + // second pass is needed if default BIOS came after one or more system BIOSes + if (havebios && !m_default_bios) + { + if (defbios && twopass) + { + for (const tiny_rom_entry *rom = roms; !m_default_bios && !ROMENTRY_ISEND(rom); ++rom) + { + if (ROMENTRY_ISSYSTEM_BIOS(rom) && !std::strcmp(rom->name, defbios)) + m_default_bios = ROM_GETBIOSFLAGS(rom); + } + } + + // no default BIOS declared but at least one system BIOS declared + if (!m_default_bios) + m_default_bios = firstbios; + } + + // set system BIOS to the default unless something overrides it + set_system_bios(m_default_bios); + } + + // notify the interfaces for (device_interface &intf : interfaces()) intf.interface_config_complete(); diff --git a/src/emu/device.h b/src/emu/device.h index 376d94b9e98..af3cf537646 100644 --- a/src/emu/device.h +++ b/src/emu/device.h @@ -45,6 +45,8 @@ device->set_clock(_clock); #define MCFG_DEVICE_INPUT_DEFAULTS(_config) \ device->set_input_default(DEVICE_INPUT_DEFAULTS_NAME(_config)); +#define MCFG_DEVICE_BIOS(...) \ + device->set_default_bios_tag(__VA_ARGS__); #define DECLARE_READ_LINE_MEMBER(name) int name() #define READ_LINE_MEMBER(name) int name() @@ -455,9 +457,9 @@ public: const std::vector &rom_region_vector() const; const tiny_rom_entry *rom_region() const { return device_rom_region(); } ioport_constructor input_ports() const { return device_input_ports(); } - u8 default_bios() const { return m_default_bios; } + std::string const &get_default_bios_tag() const { return m_default_bios_tag; } + u8 default_bios() const { assert(configured()); return m_default_bios; } u8 system_bios() const { return m_system_bios; } - const std::string &default_bios_tag() const { return m_default_bios_tag; } // interface helpers interface_list &interfaces() { return m_interfaces; } @@ -500,7 +502,7 @@ public: void set_clock(u32 clock); void set_clock(const XTAL &xtal) { set_clock(xtal.value()); } void set_input_default(const input_device_default *config) { m_input_defaults = config; } - void set_default_bios_tag(const char *tag) { m_default_bios_tag = tag; } + template void set_default_bios_tag(Params &&... args) { assert(!configured()); m_default_bios_tag.assign(std::forward(args)...); } // state helpers void config_complete(); @@ -536,7 +538,6 @@ public: offs_t safe_pc() const; offs_t safe_pcbase() const; - void set_default_bios(u8 bios) { m_default_bios = bios; } void set_system_bios(u8 bios) { m_system_bios = bios; } bool findit(bool pre_map, bool isvalidation) const; diff --git a/src/emu/romload.cpp b/src/emu/romload.cpp index 6d2dcfec2e9..31069c68423 100644 --- a/src/emu/romload.cpp +++ b/src/emu/romload.cpp @@ -265,53 +265,34 @@ int rom_load_manager::set_disk_handle(const char *region, const char *fullpath) void rom_load_manager::determine_bios_rom(device_t &device, const char *specbios) { - device.set_system_bios(0); - - /* first determine the default BIOS name */ - char const *defaultname(nullptr); - for (const rom_entry &rom : device.rom_region_vector()) + // default is applied by the device at config complete time + if (specbios && *specbios && core_stricmp(specbios, "default")) { - if (ROMENTRY_ISDEFAULT_BIOS(&rom)) + bool found(false); + for (const rom_entry &rom : device.rom_region_vector()) { - defaultname = ROM_GETNAME(&rom); - break; - } - } + if (ROMENTRY_ISSYSTEM_BIOS(&rom)) + { + char const *const biosname = ROM_GETNAME(&rom); + int const bios_flags = ROM_GETBIOSFLAGS(&rom); + char bios_number[20]; - /* look for a BIOS with a matching name */ - int bios_count = 0, default_no = 1; - for (const rom_entry &rom : device.rom_region_vector()) - { - if (ROMENTRY_ISSYSTEM_BIOS(&rom)) - { - char const *const biosname = ROM_GETNAME(&rom); - int const bios_flags = ROM_GETBIOSFLAGS(&rom); - char bios_number[20]; - - /* Allow '-bios n' to still be used */ - sprintf(bios_number, "%d", bios_flags - 1); - if (!core_stricmp(bios_number, specbios) || !core_stricmp(biosname, specbios)) - device.set_system_bios(bios_flags); - if (defaultname && !core_stricmp(biosname, defaultname)) - default_no = bios_flags; - bios_count++; - } - } - - /* if none found, use the default */ - if (device.system_bios() == 0 && bios_count > 0) - { - /* if we got neither an empty string nor 'default' then warn the user */ - if (specbios[0] && !core_stricmp(specbios, "default")) - { - m_errorstring.append(string_format("%s: invalid bios, reverting to default\n", specbios)); - m_warnings++; + // Allow '-bios n' to still be used + sprintf(bios_number, "%d", bios_flags - 1); + if (!core_stricmp(bios_number, specbios) || !core_stricmp(biosname, specbios)) + { + found = true; + device.set_system_bios(bios_flags); + break; + } + } } - /* set to default */ - device.set_system_bios(default_no); + // if we got neither an empty string nor 'default' then warn the user + m_errorstring.append(util::string_format("%s: invalid BIOS \"%s\", reverting to default\n", device.tag(), specbios)); } - device.set_default_bios(default_no); + + // log final result LOG("For \"%s\" using System BIOS: %d\n", device.tag(), device.system_bios()); } @@ -1490,7 +1471,7 @@ void rom_load_manager::process_region_list() rom_load_manager::rom_load_manager(running_machine &machine) : m_machine(machine) { - /* figure out which BIOS we are using */ + // figure out which BIOS we are using std::map card_bios; for (device_t &device : device_iterator(machine.config().root_device())) { @@ -1523,16 +1504,16 @@ rom_load_manager::rom_load_manager(running_machine &machine) } } - /* count the total number of ROMs */ + // count the total number of ROMs count_roms(); - /* reset the disk list */ + // reset the disk list m_chd_list.clear(); - /* process the ROM entries we were passed */ + // process the ROM entries we were passed process_region_list(); - /* display the results and exit */ + // display the results and exit display_rom_load_results(false); } diff --git a/src/emu/validity.cpp b/src/emu/validity.cpp index 5a74a100147..c47604448bf 100644 --- a/src/emu/validity.cpp +++ b/src/emu/validity.cpp @@ -1620,6 +1620,8 @@ void validity_checker::validate_roms(device_t &root) // check that default BIOS exists if (defbios && (bios_names.find(defbios) == bios_names.end())) osd_printf_error("Default BIOS '%s' not found\n", defbios); + if (!device.get_default_bios_tag().empty() && (bios_names.find(device.get_default_bios_tag()) == bios_names.end())) + osd_printf_error("Configured BIOS '%s' not found\n", device.get_default_bios_tag().c_str()); // final check for empty regions if (items_since_region == 0) diff --git a/src/mame/drivers/model1.cpp b/src/mame/drivers/model1.cpp index 9d095739047..e2a101227bf 100644 --- a/src/mame/drivers/model1.cpp +++ b/src/mame/drivers/model1.cpp @@ -1660,7 +1660,7 @@ MACHINE_CONFIG_START(model1_state::wingwar) MCFG_CPU_PROGRAM_MAP(model1_comm_mem) MCFG_M1COMM_ADD(M1COMM_TAG) - // use EPR-15112 + MCFG_DEVICE_BIOS("epr15112"); MACHINE_CONFIG_END MACHINE_CONFIG_START(model1_state::swa) @@ -1738,14 +1738,14 @@ MACHINE_CONFIG_START(model1_state::vr) model1_vr(config); MCFG_M1COMM_ADD(M1COMM_TAG) - // use EPR-15112 + MCFG_DEVICE_BIOS("epr15112"); MACHINE_CONFIG_END MACHINE_CONFIG_START(model1_state::vformula) model1_vr(config); MCFG_M1COMM_ADD(M1COMM_TAG) - // use EPR-15624 + MCFG_DEVICE_BIOS("epr15624"); MACHINE_CONFIG_END DRIVER_INIT_MEMBER(model1_state,wingwar360) diff --git a/src/mame/machine/m1comm.cpp b/src/mame/machine/m1comm.cpp index 943669406fa..57f6bb14a01 100644 --- a/src/mame/machine/m1comm.cpp +++ b/src/mame/machine/m1comm.cpp @@ -83,14 +83,14 @@ void m1comm_device::m1comm_io(address_map &map) ROM_START( m1comm ) ROM_REGION( 0x20000, Z80_TAG, ROMREGION_ERASEFF ) - ROM_DEFAULT_BIOS("epr-15112") + ROM_DEFAULT_BIOS("epr15112") // found on Virtua Racing and WingWar - ROM_SYSTEM_BIOS( 0, "epr-15112", "EPR-15112" ) + ROM_SYSTEM_BIOS( 0, "epr15112", "EPR-15112" ) ROMX_LOAD( "epr-15112.17", 0x0000, 0x20000, CRC(4950e771) SHA1(99014124e0324dd114cb22f55159d18b597a155a), ROM_BIOS(1) ) // found on Virtua Formula - ROM_SYSTEM_BIOS( 1, "epr-15624", "EPR-15624" ) + ROM_SYSTEM_BIOS( 1, "epr15624", "EPR-15624" ) ROMX_LOAD( "epr-15624.17", 0x0000, 0x20000, CRC(9b3ba315) SHA1(0cd0983cc8b2f2d6b41617d0d0a24cc6c188e62a), ROM_BIOS(2) ) ROM_END