There's no day like today. This just follows up on the last commit: game drivers are less special special - they have configuration instantiated in the usual way.

This commit is contained in:
Vas Crabb 2017-05-22 18:17:29 +10:00
parent a6ee791664
commit 89524dd10e
5 changed files with 50 additions and 54 deletions

View File

@ -645,6 +645,20 @@ machine_config_constructor device_t::device_mconfig_additions() const
}
//-------------------------------------------------
// device_add_mconfig - add device-specific
// machine configuration
//-------------------------------------------------
void device_t::device_add_mconfig(machine_config &config)
{
// backwards-compatibility for devices using free functions
machine_config_constructor const additions(device_mconfig_additions());
if (additions)
additions(config, this, nullptr);
}
//-------------------------------------------------
// input_ports - return a pointer to the implicit
// input ports description for this device

View File

@ -413,7 +413,6 @@ public:
const input_device_default *input_ports_defaults() const { return m_input_defaults; }
const std::vector<rom_entry> &rom_region_vector() const;
const rom_entry *rom_region() const { return rom_region_vector().data(); }
machine_config_constructor machine_config_additions() const { return device_mconfig_additions(); }
ioport_constructor input_ports() const { return device_input_ports(); }
u8 default_bios() const { return m_default_bios; }
u8 system_bios() const { return m_system_bios; }
@ -454,6 +453,7 @@ public:
std::string parameter(const char *tag) const;
// configuration helpers
void add_machine_configuration(machine_config &config) { device_add_mconfig(config); }
static void static_set_clock(device_t &device, u32 clock);
static void static_set_input_default(device_t &device, const input_device_default *config) { device.m_input_defaults = config; }
static void static_set_default_bios_tag(device_t &device, const char *tag) { std::string default_bios_tag(tag); device.m_default_bios_tag = default_bios_tag; }
@ -515,6 +515,7 @@ protected:
// device-level overrides
virtual const tiny_rom_entry *device_rom_region() const;
virtual machine_config_constructor device_mconfig_additions() const;
virtual void device_add_mconfig(machine_config &config);
virtual ioport_constructor device_input_ports() const;
virtual void device_config_complete();
virtual void device_validity_check(validity_checker &valid) const ATTR_COLD;

View File

@ -95,7 +95,6 @@ public:
const char * parent; // if this is a clone, the name of the parent
const char * year; // year the game was released
const char * manufacturer; // manufacturer of the game
machine_config_constructor machine_config; // machine driver tokens
ioport_constructor ipt; // pointer to constructor for input ports
driver_init_helper const & driver_init; // DRIVER_INIT callback
const tiny_rom_entry * rom; // pointer to list of ROMs for the game
@ -118,27 +117,33 @@ public:
// wrappers for declaring and defining game drivers
#define GAME_NAME(name) driver_##name
#define GAME_TRAITS_NAME(name) driver_##name##traits
#define GAME_TRAITS_NAME(name) driver_##name##_device
#define GAME_EXTERN(name) extern game_driver const GAME_NAME(name)
// static game traits
#define GAME_DRIVER_TRAITS(NAME, FULLNAME) \
#define GAME_DRIVER_TRAITS(NAME, FULLNAME, MACHINE, CLASS) \
namespace { \
struct GAME_TRAITS_NAME(NAME) { static constexpr char const shortname[] = #NAME, fullname[] = FULLNAME, source[] = __FILE__; }; \
class GAME_TRAITS_NAME(NAME) : public CLASS \
{ \
public: \
static constexpr char const shortname[] = #NAME, fullname[] = FULLNAME, source[] = __FILE__; \
GAME_TRAITS_NAME(NAME)(const machine_config &mconfig, device_type type, const char *tag) : CLASS(mconfig, type, tag) { } \
protected: \
virtual void device_add_mconfig(machine_config &config) override { MACHINE_CONFIG_NAME(MACHINE)(config, this, nullptr); } \
}; \
constexpr char const GAME_TRAITS_NAME(NAME)::shortname[], GAME_TRAITS_NAME(NAME)::fullname[], GAME_TRAITS_NAME(NAME)::source[]; \
}
#define GAME_DRIVER_TYPE(NAME, CLASS) driver_device_creator<CLASS, (GAME_TRAITS_NAME(NAME)::shortname), (GAME_TRAITS_NAME(NAME)::fullname), (GAME_TRAITS_NAME(NAME)::source)>
#define GAME_DRIVER_TYPE(NAME) driver_device_creator<GAME_TRAITS_NAME(NAME), (GAME_TRAITS_NAME(NAME)::shortname), (GAME_TRAITS_NAME(NAME)::fullname), (GAME_TRAITS_NAME(NAME)::source)>
// standard GAME() macro
#define GAME(YEAR,NAME,PARENT,MACHINE,INPUT,CLASS,INIT,MONITOR,COMPANY,FULLNAME,FLAGS) \
GAME_DRIVER_TRAITS(NAME,FULLNAME) \
GAME_DRIVER_TRAITS(NAME, FULLNAME, MACHINE, CLASS) \
extern game_driver const GAME_NAME(NAME) \
{ \
GAME_DRIVER_TYPE(NAME, CLASS), \
GAME_DRIVER_TYPE(NAME), \
#PARENT, \
#YEAR, \
COMPANY, \
MACHINE_CONFIG_NAME(MACHINE), \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
ROM_NAME(NAME), \
@ -150,14 +155,13 @@ extern game_driver const GAME_NAME(NAME) \
// standard macro with additional layout
#define GAMEL(YEAR,NAME,PARENT,MACHINE,INPUT,CLASS,INIT,MONITOR,COMPANY,FULLNAME,FLAGS,LAYOUT) \
GAME_DRIVER_TRAITS(NAME,FULLNAME) \
GAME_DRIVER_TRAITS(NAME, FULLNAME, MACHINE, CLASS) \
extern game_driver const GAME_NAME(NAME) \
{ \
GAME_DRIVER_TYPE(NAME, CLASS), \
GAME_DRIVER_TYPE(NAME), \
#PARENT, \
#YEAR, \
COMPANY, \
MACHINE_CONFIG_NAME(MACHINE), \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
ROM_NAME(NAME), \
@ -170,14 +174,13 @@ extern game_driver const GAME_NAME(NAME) \
// standard console definition macro
#define CONS(YEAR,NAME,PARENT,COMPAT,MACHINE,INPUT,CLASS,INIT,COMPANY,FULLNAME,FLAGS) \
GAME_DRIVER_TRAITS(NAME,FULLNAME) \
GAME_DRIVER_TRAITS(NAME, FULLNAME, MACHINE, CLASS) \
extern game_driver const GAME_NAME(NAME) \
{ \
GAME_DRIVER_TYPE(NAME, CLASS), \
GAME_DRIVER_TYPE(NAME), \
#PARENT, \
#YEAR, \
COMPANY, \
MACHINE_CONFIG_NAME(MACHINE), \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
ROM_NAME(NAME), \
@ -189,14 +192,13 @@ extern game_driver const GAME_NAME(NAME) \
// standard computer definition macro
#define COMP(YEAR,NAME,PARENT,COMPAT,MACHINE,INPUT,CLASS,INIT,COMPANY,FULLNAME,FLAGS) \
GAME_DRIVER_TRAITS(NAME,FULLNAME) \
GAME_DRIVER_TRAITS(NAME, FULLNAME, MACHINE, CLASS) \
extern game_driver const GAME_NAME(NAME) \
{ \
GAME_DRIVER_TYPE(NAME, CLASS), \
GAME_DRIVER_TYPE(NAME), \
#PARENT, \
#YEAR, \
COMPANY, \
MACHINE_CONFIG_NAME(MACHINE), \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
ROM_NAME(NAME), \
@ -208,14 +210,13 @@ extern game_driver const GAME_NAME(NAME) \
// standard system definition macro
#define SYST(YEAR,NAME,PARENT,COMPAT,MACHINE,INPUT,CLASS,INIT,COMPANY,FULLNAME,FLAGS) \
GAME_DRIVER_TRAITS(NAME,FULLNAME) \
GAME_DRIVER_TRAITS(NAME, FULLNAME, MACHINE, CLASS) \
extern game_driver const GAME_NAME(NAME) \
{ \
GAME_DRIVER_TYPE(NAME, CLASS), \
GAME_DRIVER_TYPE(NAME), \
#PARENT, \
#YEAR, \
COMPANY, \
MACHINE_CONFIG_NAME(MACHINE), \
INPUT_PORTS_NAME(INPUT), \
game_driver::make_driver_init(&CLASS::init_##INIT), \
ROM_NAME(NAME), \

View File

@ -29,8 +29,8 @@ machine_config::machine_config(const game_driver &gamedrv, emu_options &options)
m_gamedrv(gamedrv),
m_options(options)
{
// add the root device and construct the config
(*gamedrv.machine_config)(*this, device_add(nullptr, "root", gamedrv.type, 0), nullptr);
// add the root device
device_add(nullptr, "root", gamedrv.type, 0);
// intialize slot devices - make sure that any required devices have been allocated
for (device_slot_interface &slot : slot_interface_iterator(root_device()))
@ -139,26 +139,25 @@ device_t *machine_config::device_add(device_t *owner, const char *tag, device_ty
std::string part(tag, next-tag);
owner = owner->subdevices().find(part);
if (owner == nullptr)
throw emu_fatalerror("Could not find %s when looking up path for device %s\n",
part.c_str(), orig_tag);
throw emu_fatalerror("Could not find %s when looking up path for device %s\n", part.c_str(), orig_tag);
tag = next+1;
}
assert(tag[0] != '\0');
if (owner != nullptr)
{
// allocate the new device
std::unique_ptr<device_t> device = type(*this, tag, owner, clock);
// append it to the owner's list
return &config_new_device(owner->subdevices().m_list.append(*device.release()));
// allocate the new device and append it to the owner's list
device_t *const device = &owner->subdevices().m_list.append(*type(*this, tag, owner, clock).release());
device->add_machine_configuration(*this);
return device;
}
else
{
// allocate the root device directly
assert(!m_root_device);
m_root_device = type(*this, tag, nullptr, clock);
return &config_new_device(*m_root_device);
m_root_device->add_machine_configuration(*this);
return m_root_device.get();
}
}
@ -187,11 +186,10 @@ device_t *machine_config::device_replace(device_t *owner, const char *tag, devic
// remove references to the old device
remove_references(*old_device);
// allocate the new device
std::unique_ptr<device_t> new_device = type(*this, tag, owner, clock);
// substitute it for the old one in the owner's list
return &config_new_device(owner->subdevices().m_list.replace_and_remove(*new_device.release(), *old_device));
// allocate the new device and substitute it for the old one in the owner's list
device_t *const new_device = &owner->subdevices().m_list.replace_and_remove(*type(*this, tag, owner, clock).release(), *old_device);
new_device->add_machine_configuration(*this);
return new_device;
}
}
@ -254,20 +252,3 @@ void machine_config::remove_references(ATTR_UNUSED device_t &device)
for (device_t &scan : device_iterator(root_device()))
scan.subdevices().m_tagmap.clear(); //remove(&device);
}
//-------------------------------------------------
// config_new_device - helper for recursive
// configuration of newly added devices
//-------------------------------------------------
device_t &machine_config::config_new_device(device_t &device)
{
// apply any machine configuration owned by the device now
machine_config_constructor additions = device.machine_config_additions();
if (additions != nullptr)
(*additions)(*this, &device, nullptr);
// return the new device
return device;
}

View File

@ -81,7 +81,6 @@ public:
private:
// internal helpers
void remove_references(ATTR_UNUSED device_t &device);
device_t &config_new_device(device_t &device);
// internal state
const game_driver & m_gamedrv;