From 68df03a7d236bc63deb648cc019b3e2fc22d222c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miodrag=20Milanovi=C4=87?= Date: Mon, 5 Jul 2021 09:56:08 +0200 Subject: Remove some tag lookups by name (#8252) --- src/devices/bus/macpds/macpds.cpp | 15 ++++----------- src/devices/bus/macpds/macpds.h | 20 +++++++++++--------- src/devices/machine/cs4031.cpp | 11 ++++------- src/devices/machine/cs4031.h | 8 ++++++-- src/devices/machine/lpci.cpp | 9 +++------ src/devices/machine/lpci.h | 5 +++-- src/devices/machine/mcf5206e.cpp | 6 ++---- src/devices/machine/mcf5206e.h | 9 ++++++++- src/emu/machine.h | 3 +-- src/mame/drivers/bfm_ad5.cpp | 2 +- src/mame/drivers/bfm_sc5.cpp | 2 +- src/mame/drivers/ct486.cpp | 2 +- src/mame/drivers/gamtor.cpp | 2 +- src/mame/drivers/jpmsys7.cpp | 2 +- src/mame/drivers/seta2.cpp | 2 +- 15 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/devices/bus/macpds/macpds.cpp b/src/devices/bus/macpds/macpds.cpp index 9f17df8cb6d..036cb51bf1f 100644 --- a/src/devices/bus/macpds/macpds.cpp +++ b/src/devices/bus/macpds/macpds.cpp @@ -33,8 +33,7 @@ macpds_slot_device::macpds_slot_device(const machine_config &mconfig, const char macpds_slot_device::macpds_slot_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, type, tag, owner, clock), device_slot_interface(mconfig, *this), - m_macpds_tag(nullptr), - m_macpds_slottag(nullptr) + m_macpds(*this, finder_base::DUMMY_TAG) { } @@ -46,7 +45,7 @@ void macpds_slot_device::device_start() { device_macpds_card_interface *dev = dynamic_cast(get_card_device()); - if (dev) dev->set_macpds_tag(m_macpds_tag, m_macpds_slottag); + if (dev) dev->set_macpds_and_slot(m_macpds, this); } //************************************************************************** @@ -70,8 +69,7 @@ macpds_device::macpds_device(const machine_config &mconfig, const char *tag, dev macpds_device::macpds_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, type, tag, owner, clock), - m_maincpu(nullptr), - m_cputag(nullptr) + m_maincpu(*this, finder_base::DUMMY_TAG) { } //------------------------------------------------- @@ -80,7 +78,6 @@ macpds_device::macpds_device(const machine_config &mconfig, device_type type, co void macpds_device::device_start() { - m_maincpu = machine().device(m_cputag); } //------------------------------------------------- @@ -98,7 +95,6 @@ void macpds_device::add_macpds_card(device_macpds_card_interface *card) template void macpds_device::install_device(offs_t start, offs_t end, R rhandler, W whandler, uint32_t mask) { - m_maincpu = machine().device(m_cputag); m_maincpu->space(AS_PROGRAM).install_readwrite_handler(start, end, rhandler, whandler, mask); } @@ -114,7 +110,6 @@ template void macpds_device::install_device%x\n", tag, start, end); - m_maincpu = machine().device(m_cputag); address_space &space = m_maincpu->space(AS_PROGRAM); space.install_ram(start, end, data); } @@ -139,8 +134,7 @@ void macpds_device::set_irq_line(int line, int state) device_macpds_card_interface::device_macpds_card_interface(const machine_config &mconfig, device_t &device) : device_interface(device, "macpds"), - m_macpds(nullptr), - m_macpds_tag(nullptr), m_macpds_slottag(nullptr), m_next(nullptr) + m_macpds(nullptr), m_macpds_slot(nullptr), m_next(nullptr) { } @@ -155,7 +149,6 @@ device_macpds_card_interface::~device_macpds_card_interface() void device_macpds_card_interface::set_macpds_device() { - m_macpds = dynamic_cast(device().machine().device(m_macpds_tag)); m_macpds->add_macpds_card(this); } diff --git a/src/devices/bus/macpds/macpds.h b/src/devices/bus/macpds/macpds.h index cd3f84659d0..ad0ce6a2416 100644 --- a/src/devices/bus/macpds/macpds.h +++ b/src/devices/bus/macpds/macpds.h @@ -31,13 +31,14 @@ public: option_reset(); opts(*this); set_default_option(dflt); - set_macpds_slot(nbtag, tag); + set_macpds_slot(nbtag); } macpds_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); // inline configuration - void set_macpds_slot(const char *tag, const char *slottag) { m_macpds_tag = tag; m_macpds_slottag = slottag; } + template + void set_macpds_slot(T &&tag) { m_macpds.set_tag(std::forward(tag));} protected: macpds_slot_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); @@ -46,7 +47,7 @@ protected: virtual void device_start() override; // configuration - const char *m_macpds_tag, *m_macpds_slottag; + required_device m_macpds; }; // device type definition @@ -70,7 +71,9 @@ public: ~macpds_device() { m_device_list.detach_all(); } // inline configuration - void set_cputag(const char *tag) { m_cputag = tag; } + template + void set_cputag(T &&tag) { m_maincpu.set_tag(std::forward(tag)); } + void add_macpds_card(device_macpds_card_interface *card); template void install_device(offs_t start, offs_t end, R rhandler, W whandler, uint32_t mask=0xffffffff); @@ -85,10 +88,9 @@ protected: virtual void device_reset() override; // internal state - cpu_device *m_maincpu; + required_device m_maincpu; simple_list m_device_list; - const char *m_cputag; }; @@ -115,13 +117,13 @@ public: void install_rom(device_t *dev, const char *romregion, uint32_t addr); // inline configuration - void set_macpds_tag(const char *tag, const char *slottag) { m_macpds_tag = tag; m_macpds_slottag = slottag; } + void set_macpds_and_slot(macpds_device *macpds, macpds_slot_device *macpds_slot) { m_macpds = macpds; m_macpds_slot = macpds_slot; } protected: device_macpds_card_interface(const machine_config &mconfig, device_t &device); - macpds_device *m_macpds; - const char *m_macpds_tag, *m_macpds_slottag; + macpds_device *m_macpds; + macpds_slot_device *m_macpds_slot; private: device_macpds_card_interface *m_next; diff --git a/src/devices/machine/cs4031.cpp b/src/devices/machine/cs4031.cpp index b8919cca609..55cb0377cad 100644 --- a/src/devices/machine/cs4031.cpp +++ b/src/devices/machine/cs4031.cpp @@ -28,8 +28,6 @@ #include "emu.h" #include "machine/cs4031.h" -#include "machine/ram.h" - #define LOG_GENERAL (1U << 0) #define LOG_REGISTER (1U << 1) #define LOG_MEMORY (1U << 2) @@ -186,6 +184,7 @@ cs4031_device::cs4031_device(const machine_config &mconfig, const char *tag, dev m_intc2(*this, "intc2"), m_ctc(*this, "ctc"), m_rtc(*this, "rtc"), + m_ram_dev(*this, finder_base::DUMMY_TAG), m_dma_eop(0), m_dma_high_byte(0xff), m_dma_channel(-1), @@ -211,10 +210,8 @@ cs4031_device::cs4031_device(const machine_config &mconfig, const char *tag, dev void cs4031_device::device_start() { - ram_device *ram_dev = machine().device(RAM_TAG); - // make sure the ram device is already running - if (!ram_dev->started()) + if (!m_ram_dev->started()) throw device_missing_dependencies(); // resolve callbacks @@ -249,8 +246,8 @@ void cs4031_device::device_start() m_space = &m_cpu->memory().space(AS_PROGRAM); m_space_io = &m_cpu->memory().space(AS_IO); - m_ram = ram_dev->pointer(); - uint32_t ram_size = ram_dev->size(); + m_ram = m_ram_dev->pointer(); + uint32_t ram_size = m_ram_dev->size(); // install base memory m_space->install_ram(0x000000, 0x09ffff, m_ram); diff --git a/src/devices/machine/cs4031.h b/src/devices/machine/cs4031.h index b8540380679..5e7ea81b4e0 100644 --- a/src/devices/machine/cs4031.h +++ b/src/devices/machine/cs4031.h @@ -30,19 +30,21 @@ #include "machine/pit8253.h" #include "machine/ds128x.h" #include "machine/at_keybc.h" +#include "machine/ram.h" class cs4031_device : public device_t { public: // construction/destruction - template - cs4031_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&cputag, U &&isatag, V &&biostag, W &&keybctag) + template + cs4031_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&cputag, U &&isatag, V &&biostag, W &&keybctag, X &&ramtag) : cs4031_device(mconfig, tag, owner, clock) { set_cputag(std::forward(cputag)); set_isatag(std::forward(isatag)); set_biostag(std::forward(biostag)); set_keybctag(std::forward(keybctag)); + set_ramtag(std::forward(ramtag)); } cs4031_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); @@ -110,6 +112,7 @@ public: template void set_isatag(T &&tag) { m_isa.set_tag(std::forward(tag)); } template void set_biostag(T &&tag) { m_bios.set_tag(std::forward(tag)); } template void set_keybctag(T &&tag) { m_keybc.set_tag(std::forward(tag)); } + template void set_ramtag(T &&tag) { m_ram_dev.set_tag(std::forward(tag)); } protected: // device-level overrides @@ -164,6 +167,7 @@ private: required_device m_intc2; required_device m_ctc; required_device m_rtc; + required_device m_ram_dev; int m_dma_eop; uint8_t m_dma_page[0x10]; diff --git a/src/devices/machine/lpci.cpp b/src/devices/machine/lpci.cpp index 8c2fd6393e0..44b8b84bf3d 100644 --- a/src/devices/machine/lpci.cpp +++ b/src/devices/machine/lpci.cpp @@ -95,7 +95,7 @@ pci_bus_legacy_device::pci_bus_legacy_device(const machine_config &mconfig, cons device_t(mconfig, PCI_BUS_LEGACY, tag, owner, clock), m_read_callback(*this), m_write_callback(*this), - m_father(nullptr), + m_father(*this, finder_base::DUMMY_TAG), m_siblings_count(0) { std::fill(std::begin(m_siblings), std::end(m_siblings), nullptr); @@ -262,11 +262,8 @@ void pci_bus_legacy_device::device_start() m_read_callback.resolve_all(); m_write_callback.resolve_all(); - if (m_father) { - pci_bus_legacy_device *father = machine().device(m_father); - if (father) - father->add_sibling(this, m_busnum); - } + if (m_father.found()) + m_father->add_sibling(this, m_busnum); /* register pci states */ save_item(NAME(m_address)); diff --git a/src/devices/machine/lpci.h b/src/devices/machine/lpci.h index 4b98054bb8d..fb289d5538f 100644 --- a/src/devices/machine/lpci.h +++ b/src/devices/machine/lpci.h @@ -40,7 +40,8 @@ public: void write_64be(offs_t offset, uint64_t data, uint64_t mem_mask = ~0); void set_busnum(int busnum) { m_busnum = busnum; } - void set_father(const char *father) { m_father = father; } + template + void set_father(T &&tag) { m_father.set_tag(std::forward(tag)); } template void set_device(int num, F &&read, const char *rname, G &&write, const char *wname) @@ -69,7 +70,7 @@ private: uint8_t m_busnum; pci_bus_legacy_read_delegate::array<32> m_read_callback; pci_bus_legacy_write_delegate::array<32> m_write_callback; - const char * m_father; + optional_device m_father; pci_bus_legacy_device * m_siblings[8]; uint8_t m_siblings_busnum[8]; int m_siblings_count; diff --git a/src/devices/machine/mcf5206e.cpp b/src/devices/machine/mcf5206e.cpp index 776223dc530..640550fcdec 100644 --- a/src/devices/machine/mcf5206e.cpp +++ b/src/devices/machine/mcf5206e.cpp @@ -661,7 +661,7 @@ TIMER_CALLBACK_MEMBER(mcf5206e_peripheral_device::timer1_callback) // technically we should do the vector check in the IRQ callback as well as various checks based on the IRQ masks before asserting the interrupt if (ICR & 0x80) // AVEC { - if (!(m_IMR & 0x0200)) m_cpu->set_input_line((ICR&0x1c)>>2, HOLD_LINE); + if (!(m_IMR & 0x0200)) m_maincpu->set_input_line((ICR&0x1c)>>2, HOLD_LINE); } LOGMASKED(LOG_TIMER, "timer1_callback\n"); @@ -826,8 +826,8 @@ DEFINE_DEVICE_TYPE(MCF5206E_PERIPHERAL, mcf5206e_peripheral_device, "mcf5206e_pe mcf5206e_peripheral_device::mcf5206e_peripheral_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, MCF5206E_PERIPHERAL, tag, owner, clock), device_memory_interface(mconfig, *this), + m_maincpu(*this, finder_base::DUMMY_TAG), m_space_config("coldfire_regs", ENDIANNESS_BIG, 32,10, 0, address_map_constructor(FUNC(mcf5206e_peripheral_device::coldfire_regs_map), this)) - { } @@ -870,8 +870,6 @@ void mcf5206e_peripheral_device::device_start() void mcf5206e_peripheral_device::device_reset() { - m_cpu = (cpu_device*)machine().device(":maincpu"); // hack. this device should really be attached to a modern CPU core - init_regs(false); m_timer1->adjust(attotime::never); } diff --git a/src/devices/machine/mcf5206e.h b/src/devices/machine/mcf5206e.h index 171620d5f0b..d4ec0dd7980 100644 --- a/src/devices/machine/mcf5206e.h +++ b/src/devices/machine/mcf5206e.h @@ -23,6 +23,13 @@ class mcf5206e_peripheral_device : public device_t, { public: // construction/destruction + template + mcf5206e_peripheral_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&cpu_tag) + : mcf5206e_peripheral_device(mconfig, tag, owner, clock) + { + m_maincpu.set_tag(std::forward(cpu_tag)); + } + mcf5206e_peripheral_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); uint32_t dev_r(offs_t offset, uint32_t mem_mask = ~0); @@ -160,7 +167,7 @@ private: MAX_ICR }; - cpu_device* m_cpu; + required_device m_maincpu; address_space_config m_space_config; diff --git a/src/emu/machine.h b/src/emu/machine.h index 39e09d9fb89..83e1c512268 100644 --- a/src/emu/machine.h +++ b/src/emu/machine.h @@ -168,8 +168,7 @@ public: bool allow_logging() const { return !m_logerror_list.empty(); } // fetch items by name - [[deprecated("absolute tag lookup; use subdevice or finder instead")]] inline device_t *device(const char *tag) const { return root_device().subdevice(tag); } - template [[deprecated("absolute tag lookup; use subdevice or finder instead")]] inline DeviceClass *device(const char *tag) { return downcast(device(tag)); } + template [[deprecated("absolute tag lookup; use subdevice or finder instead")]] inline DeviceClass *device(const char *tag) { return downcast(root_device().subdevice(tag)); } // immediate operations int run(bool quiet); diff --git a/src/mame/drivers/bfm_ad5.cpp b/src/mame/drivers/bfm_ad5.cpp index 22f2e998b4e..4dab82980d5 100644 --- a/src/mame/drivers/bfm_ad5.cpp +++ b/src/mame/drivers/bfm_ad5.cpp @@ -185,7 +185,7 @@ void adder5_state::bfm_ad5(machine_config &config) MCF5206E(config, m_maincpu, 40000000); /* MCF5206eFT */ m_maincpu->set_addrmap(AS_PROGRAM, &adder5_state::ad5_map); m_maincpu->set_periodic_int(FUNC(adder5_state::ad5_fake_timer_int), attotime::from_hz(1000)); - MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0); + MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0, m_maincpu); SPEAKER(config, "lspeaker").front_left(); SPEAKER(config, "rspeaker").front_right(); diff --git a/src/mame/drivers/bfm_sc5.cpp b/src/mame/drivers/bfm_sc5.cpp index 31d0aa07932..43a509329d3 100644 --- a/src/mame/drivers/bfm_sc5.cpp +++ b/src/mame/drivers/bfm_sc5.cpp @@ -338,7 +338,7 @@ void bfm_sc5_state::bfm_sc5(machine_config &config) { MCF5206E(config, m_maincpu, 40000000); /* MCF5206eFT */ m_maincpu->set_addrmap(AS_PROGRAM, &bfm_sc5_state::sc5_map); - MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0); + MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0, m_maincpu); /* sound hardware */ SPEAKER(config, "mono").front_center(); diff --git a/src/mame/drivers/ct486.cpp b/src/mame/drivers/ct486.cpp index cf963431b63..23a4b1dc811 100644 --- a/src/mame/drivers/ct486.cpp +++ b/src/mame/drivers/ct486.cpp @@ -117,7 +117,7 @@ void ct486_state::ct486(machine_config &config) m_maincpu->set_addrmap(AS_IO, &ct486_state::ct486_io); m_maincpu->set_irq_acknowledge_callback("cs4031", FUNC(cs4031_device::int_ack_r)); - CS4031(config, m_cs4031, XTAL(25'000'000), "maincpu", "isa", "bios", "keybc"); + CS4031(config, m_cs4031, XTAL(25'000'000), "maincpu", "isa", "bios", "keybc", RAM_TAG); // cpu connections m_cs4031->hold().set(FUNC(ct486_state::cs4031_hold)); m_cs4031->nmi().set_inputline("maincpu", INPUT_LINE_NMI); diff --git a/src/mame/drivers/gamtor.cpp b/src/mame/drivers/gamtor.cpp index ab2cbac6707..8f3373301e4 100644 --- a/src/mame/drivers/gamtor.cpp +++ b/src/mame/drivers/gamtor.cpp @@ -90,7 +90,7 @@ void gaminator_state::gaminator(machine_config &config) MCF5206E(config, m_maincpu, 40000000); /* definitely Coldfire, model / clock uncertain */ m_maincpu->set_addrmap(AS_PROGRAM, &gaminator_state::gaminator_map); m_maincpu->set_vblank_int("screen", FUNC(gaminator_state::irq6_line_hold)); // irq6 seems to be needed to get past the ROM checking - MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0); + MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0, m_maincpu); screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER)); screen.set_raw(XTAL(25'174'800),900,0,640,526,0,480); diff --git a/src/mame/drivers/jpmsys7.cpp b/src/mame/drivers/jpmsys7.cpp index 2702f1fc070..af16e5bb5f0 100644 --- a/src/mame/drivers/jpmsys7.cpp +++ b/src/mame/drivers/jpmsys7.cpp @@ -60,7 +60,7 @@ void jpmsys7_state::jpmsys7(machine_config &config) { MCF5206E(config, m_maincpu, 40000000); // seems to be a Coldfire of some kind m_maincpu->set_addrmap(AS_PROGRAM, &jpmsys7_state::jpmsys7_map); - MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0); + MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0, m_maincpu); SPEAKER(config, "lspeaker").front_left(); SPEAKER(config, "rspeaker").front_right(); diff --git a/src/mame/drivers/seta2.cpp b/src/mame/drivers/seta2.cpp index 1eb03bd707e..de470e9425e 100644 --- a/src/mame/drivers/seta2.cpp +++ b/src/mame/drivers/seta2.cpp @@ -2508,7 +2508,7 @@ void funcube_state::funcube(machine_config &config) m_sub->set_addrmap(AS_PROGRAM, &funcube_state::funcube_sub_map); m_sub->set_addrmap(AS_IO, &funcube_state::funcube_sub_io); - MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0); + MCF5206E_PERIPHERAL(config, "maincpu_onboard", 0, m_maincpu); FUNCUBE_TOUCHSCREEN(config, "touchscreen", 200).tx_cb().set(":sub:sci1", FUNC(h8_sci_device::rx_w)); -- cgit v1.2.3