From 7ffbd45c6c418063e270d659556b952834d713da Mon Sep 17 00:00:00 2001 From: AJR Date: Sat, 16 Apr 2016 16:37:31 -0400 Subject: [PATCH] Critical fixes (nw) - Prevent tmpz84c015_device::irq_priority_w from crashing or corrupting the daisy chain - Eliminate the need for TMPZ84C015_DAISY_INTERNAL by not overwriting elements in the daisy list - Removed leftover MCFG_SEGAZ80_SET_DECRYPTED_TAG from macros in system1.cpp, which lets all drivers validate without crashing --- src/devices/cpu/z80/tmpz84c015.cpp | 4 ++- src/devices/cpu/z80/tmpz84c015.h | 3 --- src/devices/cpu/z80/z80daisy.cpp | 40 +++++++++++++++++++++++++++--- src/devices/cpu/z80/z80daisy.h | 1 + src/mame/drivers/pve500.cpp | 1 - src/mame/drivers/system1.cpp | 6 ++--- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/devices/cpu/z80/tmpz84c015.cpp b/src/devices/cpu/z80/tmpz84c015.cpp index 6c1f88c087a..3586001e2c6 100644 --- a/src/devices/cpu/z80/tmpz84c015.cpp +++ b/src/devices/cpu/z80/tmpz84c015.cpp @@ -155,7 +155,7 @@ WRITE8_MEMBER(tmpz84c015_device::irq_priority_w) { 1, 2, 0 } // 5: sio -> pio -> ctc -> ext }; - // reconfigure first 3 entries in daisy chain + // reconfigure daisy chain const z80_daisy_config daisy_chain[] = { { dev[prio[data][0]] }, @@ -163,6 +163,8 @@ WRITE8_MEMBER(tmpz84c015_device::irq_priority_w) { dev[prio[data][2]] }, { nullptr } }; + + // insert these 3 entries in order before any externally linked devices daisy_init(daisy_chain); m_irq_priority = data; diff --git a/src/devices/cpu/z80/tmpz84c015.h b/src/devices/cpu/z80/tmpz84c015.h index 559d7350602..2578f6a92ef 100644 --- a/src/devices/cpu/z80/tmpz84c015.h +++ b/src/devices/cpu/z80/tmpz84c015.h @@ -23,9 +23,6 @@ DEVICE CONFIGURATION MACROS ***************************************************************************/ -// If an external daisy chain is used, insert this before your own device tags: -#define TMPZ84C015_DAISY_INTERNAL { "tmpz84c015_ctc" }, { "tmpz84c015_sio" }, { "tmpz84c015_pio" } - // SIO callbacks #define MCFG_TMPZ84C015_OUT_TXDA_CB(_devcb) \ devcb = &tmpz84c015_device::set_out_txda_callback(*device, DEVCB_##_devcb); diff --git a/src/devices/cpu/z80/z80daisy.cpp b/src/devices/cpu/z80/z80daisy.cpp index 9d06fe1c9fc..82e41c42e1a 100644 --- a/src/devices/cpu/z80/z80daisy.cpp +++ b/src/devices/cpu/z80/z80daisy.cpp @@ -87,6 +87,8 @@ void z80_daisy_chain_interface::interface_post_start() void z80_daisy_chain_interface::daisy_init(const z80_daisy_config *daisy) { + assert(daisy != nullptr); + // create a linked list of devices device_z80daisy_interface **tailptr = &m_chain; for ( ; daisy->devname != nullptr; daisy++) @@ -105,12 +107,23 @@ void z80_daisy_chain_interface::daisy_init(const z80_daisy_config *daisy) if (!target->interface(intf)) fatalerror("Device '%s' does not implement the z80daisy interface!\n", daisy->devname); - // append to the end, or overwrite existing entry - device_z80daisy_interface *next = (*tailptr != nullptr) ? (*tailptr)->m_daisy_next : nullptr; + // splice it out of the list if it was previously added + device_z80daisy_interface **oldtailptr = tailptr; + while (*oldtailptr != nullptr) + { + if (*oldtailptr == intf) + *oldtailptr = (*oldtailptr)->m_daisy_next; + else + oldtailptr = &(*oldtailptr)->m_daisy_next; + } + + // add the interface to the list + intf->m_daisy_next = *tailptr; *tailptr = intf; - (*tailptr)->m_daisy_next = next; tailptr = &(*tailptr)->m_daisy_next; } + + osd_printf_verbose("Daisy chain = %s\n", daisy_show_chain().c_str()); } @@ -193,3 +206,24 @@ void z80_daisy_chain_interface::daisy_call_reti_device() } //logerror("z80daisy_call_reti_device: failed to find an device to reti!\n"); } + + +//------------------------------------------------- +// daisy_show_chain - list devices in the chain +// in string format (for debugging purposes) +//------------------------------------------------- + +std::string z80_daisy_chain_interface::daisy_show_chain() const +{ + std::ostringstream result; + + // loop over all devices + for (device_z80daisy_interface *intf = m_chain; intf != nullptr; intf = intf->m_daisy_next) + { + if (intf != m_chain) + result << " -> "; + result << intf->device().tag(); + } + + return result.str(); +} diff --git a/src/devices/cpu/z80/z80daisy.h b/src/devices/cpu/z80/z80daisy.h index 9248c31c6da..11d17dc36eb 100644 --- a/src/devices/cpu/z80/z80daisy.h +++ b/src/devices/cpu/z80/z80daisy.h @@ -85,6 +85,7 @@ public: // getters bool daisy_chain_present() const { return (m_chain != nullptr); } + std::string daisy_show_chain() const; protected: // interface-level overrides diff --git a/src/mame/drivers/pve500.cpp b/src/mame/drivers/pve500.cpp index 7c87ca636d0..52c05d15912 100644 --- a/src/mame/drivers/pve500.cpp +++ b/src/mame/drivers/pve500.cpp @@ -102,7 +102,6 @@ WRITE_LINE_MEMBER( pve500_state::external_monitor_w ) static const z80_daisy_config maincpu_daisy_chain[] = { - TMPZ84C015_DAISY_INTERNAL, { "external_ctc" }, { "external_sio" }, { nullptr } diff --git a/src/mame/drivers/system1.cpp b/src/mame/drivers/system1.cpp index 50395d17607..8169a0d16d0 100644 --- a/src/mame/drivers/system1.cpp +++ b/src/mame/drivers/system1.cpp @@ -2222,15 +2222,13 @@ MACHINE_CONFIG_END MCFG_CPU_PROGRAM_MAP(system1_map) \ MCFG_CPU_DECRYPTED_OPCODES_MAP(decrypted_opcodes_map) \ MCFG_CPU_IO_MAP(system1_ppi_io_map) \ - MCFG_CPU_VBLANK_INT_DRIVER("screen", system1_state, irq0_line_hold) \ - MCFG_SEGAZ80_SET_DECRYPTED_TAG(":decrypted_opcodes") + MCFG_CPU_VBLANK_INT_DRIVER("screen", system1_state, irq0_line_hold) #define ENCRYPTED_SYS1PIO_MAPS \ MCFG_CPU_PROGRAM_MAP(system1_map) \ MCFG_CPU_DECRYPTED_OPCODES_MAP(decrypted_opcodes_map) \ MCFG_CPU_IO_MAP(system1_pio_io_map) \ - MCFG_CPU_VBLANK_INT_DRIVER("screen", system1_state, irq0_line_hold) \ - MCFG_SEGAZ80_SET_DECRYPTED_TAG(":decrypted_opcodes") + MCFG_CPU_VBLANK_INT_DRIVER("screen", system1_state, irq0_line_hold) static MACHINE_CONFIG_DERIVED( sys1ppix_315_5178, sys1ppi )