diff options
Diffstat (limited to 'src/devices/cpu/z80')
-rw-r--r-- | src/devices/cpu/z80/tmpz84c015.cpp | 2 | ||||
-rw-r--r-- | src/devices/cpu/z80/z80.cpp | 17 | ||||
-rw-r--r-- | src/devices/cpu/z80/z80.h | 3 | ||||
-rw-r--r-- | src/devices/cpu/z80/z80daisy.cpp | 110 | ||||
-rw-r--r-- | src/devices/cpu/z80/z80daisy.h | 55 |
5 files changed, 109 insertions, 78 deletions
diff --git a/src/devices/cpu/z80/tmpz84c015.cpp b/src/devices/cpu/z80/tmpz84c015.cpp index d61ae4ef4c5..6c1f88c087a 100644 --- a/src/devices/cpu/z80/tmpz84c015.cpp +++ b/src/devices/cpu/z80/tmpz84c015.cpp @@ -163,7 +163,7 @@ WRITE8_MEMBER(tmpz84c015_device::irq_priority_w) { dev[prio[data][2]] }, { nullptr } }; - m_daisy.init(this, daisy_chain); + daisy_init(daisy_chain); m_irq_priority = data; } diff --git a/src/devices/cpu/z80/z80.cpp b/src/devices/cpu/z80/z80.cpp index 306b1ae49f2..8d30ae2df3d 100644 --- a/src/devices/cpu/z80/z80.cpp +++ b/src/devices/cpu/z80/z80.cpp @@ -110,7 +110,6 @@ #include "emu.h" #include "debugger.h" #include "z80.h" -#include "z80daisy.h" #define VERBOSE 0 @@ -647,7 +646,7 @@ inline void z80_device::reti() pop(m_pc); WZ = PC; m_iff1 = m_iff2; - m_daisy.call_reti_device(); + daisy_call_reti_device(); } /*************************************************************** @@ -3160,8 +3159,8 @@ void z80_device::take_interrupt() m_iff1 = m_iff2 = 0; /* Daisy chain mode? If so, call the requesting device */ - if (m_daisy.present()) - irq_vector = m_daisy.call_ack_device(); + if (daisy_chain_present()) + irq_vector = daisy_call_ack_device(); /* else call back the cpu interface to retrieve the vector */ else @@ -3419,8 +3418,6 @@ void z80_device::device_start() m_decrypted_opcodes_direct = &m_decrypted_opcodes->direct(); m_io = &space(AS_IO); - if (static_config() != nullptr) - m_daisy.init(this, (const z80_daisy_config *)static_config()); m_irq_callback = device_irq_acknowledge_delegate(FUNC(z80_device::standard_irq_callback_member), this); IX = IY = 0xffff; /* IX and IY are FFFF after a reset! */ @@ -3494,8 +3491,6 @@ void z80_device::device_reset() m_iff1 = 0; m_iff2 = 0; - m_daisy.reset(); - WZ=PCD; } @@ -3582,8 +3577,8 @@ void z80_device::execute_set_input(int inputnum, int state) case INPUT_LINE_IRQ0: /* update the IRQ state via the daisy chain */ m_irq_state = state; - if (m_daisy.present()) - m_irq_state = ( m_daisy.update_irq_state() == ASSERT_LINE ) ? ASSERT_LINE : m_irq_state; + if (daisy_chain_present()) + m_irq_state = (daisy_update_irq_state() == ASSERT_LINE ) ? ASSERT_LINE : m_irq_state; /* the main execute loop will take the interrupt */ break; @@ -3700,6 +3695,7 @@ void z80_device::z80_set_cycle_tables(const UINT8 *op, const UINT8 *cb, const UI z80_device::z80_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : cpu_device(mconfig, Z80, "Z80", tag, owner, clock, "z80", __FILE__), + z80_daisy_chain_interface(mconfig, *this), m_program_config("program", ENDIANNESS_LITTLE, 8, 16, 0), m_decrypted_opcodes_config("decrypted_opcodes", ENDIANNESS_LITTLE, 8, 16, 0), m_io_config("io", ENDIANNESS_LITTLE, 8, 16, 0), @@ -3710,6 +3706,7 @@ z80_device::z80_device(const machine_config &mconfig, const char *tag, device_t z80_device::z80_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) : cpu_device(mconfig, type, name, tag, owner, clock, shortname, source), + z80_daisy_chain_interface(mconfig, *this), m_program_config("program", ENDIANNESS_LITTLE, 8, 16, 0), m_decrypted_opcodes_config("decrypted_opcodes", ENDIANNESS_LITTLE, 8, 16, 0), m_io_config("io", ENDIANNESS_LITTLE, 8, 16, 0), diff --git a/src/devices/cpu/z80/z80.h b/src/devices/cpu/z80/z80.h index 38cc207347e..e3733807770 100644 --- a/src/devices/cpu/z80/z80.h +++ b/src/devices/cpu/z80/z80.h @@ -37,7 +37,7 @@ enum Z80_GENPCBASE = STATE_GENPCBASE }; -class z80_device : public cpu_device +class z80_device : public cpu_device, public z80_daisy_chain_interface { public: z80_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); @@ -283,7 +283,6 @@ protected: device_irq_acknowledge_delegate m_irq_callback; int m_icount; - z80_daisy_chain m_daisy; UINT8 m_rtemp; const UINT8 * m_cc_op; const UINT8 * m_cc_cb; diff --git a/src/devices/cpu/z80/z80daisy.cpp b/src/devices/cpu/z80/z80daisy.cpp index 6553760160b..9d06fe1c9fc 100644 --- a/src/devices/cpu/z80/z80daisy.cpp +++ b/src/devices/cpu/z80/z80daisy.cpp @@ -21,7 +21,8 @@ //------------------------------------------------- device_z80daisy_interface::device_z80daisy_interface(const machine_config &mconfig, device_t &device) - : device_interface(device, "z80daisy") + : device_interface(device, "z80daisy"), + m_daisy_next(nullptr) { } @@ -41,31 +42,61 @@ device_z80daisy_interface::~device_z80daisy_interface() //************************************************************************** //------------------------------------------------- -// z80_daisy_chain - constructor +// z80_daisy_chain_interface - constructor //------------------------------------------------- -z80_daisy_chain::z80_daisy_chain() - : m_daisy_list(nullptr) +z80_daisy_chain_interface::z80_daisy_chain_interface(const machine_config &mconfig, device_t &device) + : device_interface(device, "z80daisychain"), + m_daisy_config(nullptr), + m_chain(nullptr) { } //------------------------------------------------- -// init - allocate the daisy chain based on the -// provided configuration +// z80_daisy_chain_interface - destructor //------------------------------------------------- +z80_daisy_chain_interface::~z80_daisy_chain_interface() +{ +} + + +//------------------------------------------------- +// static_set_daisy_config - configuration helper +// to set up the daisy chain +//------------------------------------------------- +void z80_daisy_chain_interface::static_set_daisy_config(device_t &device, const z80_daisy_config *config) +{ + z80_daisy_chain_interface *daisyintf; + if (!device.interface(daisyintf)) + throw emu_fatalerror("MCFG_Z80_DAISY_CHAIN called on device '%s' with no daisy chain interface", device.tag()); + daisyintf->m_daisy_config = config; +} + + +//------------------------------------------------- +// interface_post_start - work to be done after +// actually starting a device +//------------------------------------------------- + +void z80_daisy_chain_interface::interface_post_start() +{ + if (m_daisy_config != nullptr) + daisy_init(m_daisy_config); +} -void z80_daisy_chain::init(device_t *cpudevice, const z80_daisy_config *daisy) +void z80_daisy_chain_interface::daisy_init(const z80_daisy_config *daisy) { // create a linked list of devices - daisy_entry **tailptr = &m_daisy_list; + device_z80daisy_interface **tailptr = &m_chain; for ( ; daisy->devname != nullptr; daisy++) { // find the device - device_t *target; - if ((target = cpudevice->subdevice(daisy->devname)) == nullptr) + device_t *target = device().subdevice(daisy->devname); + if (target == nullptr) { - if ((target = cpudevice->siblingdevice(daisy->devname)) == nullptr) + target = device().siblingdevice(daisy->devname); + if (target == nullptr) fatalerror("Unable to locate device '%s'\n", daisy->devname); } @@ -75,26 +106,24 @@ void z80_daisy_chain::init(device_t *cpudevice, const z80_daisy_config *daisy) fatalerror("Device '%s' does not implement the z80daisy interface!\n", daisy->devname); // append to the end, or overwrite existing entry - daisy_entry *next = (*tailptr) ? (*tailptr)->m_next : nullptr; - if (*tailptr != nullptr) - auto_free(cpudevice->machine(), *tailptr); - *tailptr = auto_alloc(cpudevice->machine(), daisy_entry(target)); - (*tailptr)->m_next = next; - tailptr = &(*tailptr)->m_next; + device_z80daisy_interface *next = (*tailptr != nullptr) ? (*tailptr)->m_daisy_next : nullptr; + *tailptr = intf; + (*tailptr)->m_daisy_next = next; + tailptr = &(*tailptr)->m_daisy_next; } } //------------------------------------------------- -// reset - send a reset signal to all chained -// devices +// interface_post_reset - work to be done after a +// device is reset //------------------------------------------------- -void z80_daisy_chain::reset() +void z80_daisy_chain_interface::interface_post_reset() { - // loop over all devices and call their reset function - for (daisy_entry *daisy = m_daisy_list; daisy != nullptr; daisy = daisy->m_next) - daisy->m_device->reset(); + // loop over all chained devices and call their reset function + for (device_z80daisy_interface *intf = m_chain; intf != nullptr; intf = intf->m_daisy_next) + intf->device().reset(); } @@ -103,13 +132,13 @@ void z80_daisy_chain::reset() // return assert/clear based on the state //------------------------------------------------- -int z80_daisy_chain::update_irq_state() +int z80_daisy_chain_interface::daisy_update_irq_state() { // loop over all devices; dev[0] is highest priority - for (daisy_entry *daisy = m_daisy_list; daisy != nullptr; daisy = daisy->m_next) + for (device_z80daisy_interface *intf = m_chain; intf != nullptr; intf = intf->m_daisy_next) { // if this device is asserting the INT line, that's the one we want - int state = daisy->m_interface->z80daisy_irq_state(); + int state = intf->z80daisy_irq_state(); if (state & Z80_DAISY_INT) return ASSERT_LINE; @@ -126,16 +155,16 @@ int z80_daisy_chain::update_irq_state() // from a chained device and return the vector //------------------------------------------------- -int z80_daisy_chain::call_ack_device() +int z80_daisy_chain_interface::daisy_call_ack_device() { int vector = 0; // loop over all devices; dev[0] is the highest priority - for (daisy_entry *daisy = m_daisy_list; daisy != nullptr; daisy = daisy->m_next) + for (device_z80daisy_interface *intf = m_chain; intf != nullptr; intf = intf->m_daisy_next) { // if this device is asserting the INT line, that's the one we want - int state = daisy->m_interface->z80daisy_irq_state(); - vector = daisy->m_interface->z80daisy_irq_ack(); + int state = intf->z80daisy_irq_state(); + vector = intf->z80daisy_irq_ack(); if (state & Z80_DAISY_INT) return vector; } @@ -149,31 +178,18 @@ int z80_daisy_chain::call_ack_device() // the chain //------------------------------------------------- -void z80_daisy_chain::call_reti_device() +void z80_daisy_chain_interface::daisy_call_reti_device() { // loop over all devices; dev[0] is the highest priority - for (daisy_entry *daisy = m_daisy_list; daisy != nullptr; daisy = daisy->m_next) + for (device_z80daisy_interface *intf = m_chain; intf != nullptr; intf = intf->m_daisy_next) { // if this device is asserting the IEO line, that's the one we want - int state = daisy->m_interface->z80daisy_irq_state(); + int state = intf->z80daisy_irq_state(); if (state & Z80_DAISY_IEO) { - daisy->m_interface->z80daisy_irq_reti(); + intf->z80daisy_irq_reti(); return; } } //logerror("z80daisy_call_reti_device: failed to find an device to reti!\n"); } - - -//------------------------------------------------- -// daisy_entry - constructor -//------------------------------------------------- - -z80_daisy_chain::daisy_entry::daisy_entry(device_t *device) - : m_next(nullptr), - m_device(device), - m_interface(nullptr) -{ - device->interface(m_interface); -} diff --git a/src/devices/cpu/z80/z80daisy.h b/src/devices/cpu/z80/z80daisy.h index 258df6cd017..9248c31c6da 100644 --- a/src/devices/cpu/z80/z80daisy.h +++ b/src/devices/cpu/z80/z80daisy.h @@ -26,6 +26,16 @@ const UINT8 Z80_DAISY_IEO = 0x02; // interrupt disable mask (IEO) //************************************************************************** +// DEVICE CONFIGURATION MACROS +//************************************************************************** + +// configure devices +#define MCFG_Z80_DAISY_CHAIN(_config) \ + z80_daisy_chain_interface::static_set_daisy_config(*device, _config); + + + +//************************************************************************** // TYPE DEFINITIONS //************************************************************************** @@ -43,6 +53,8 @@ struct z80_daisy_config class device_z80daisy_interface : public device_interface { + friend class z80_daisy_chain_interface; + public: // construction/destruction device_z80daisy_interface(const machine_config &mconfig, device_t &device); @@ -52,37 +64,44 @@ public: virtual int z80daisy_irq_state() = 0; virtual int z80daisy_irq_ack() = 0; virtual void z80daisy_irq_reti() = 0; + +private: + device_z80daisy_interface *m_daisy_next; // next device in the chain }; -// ======================> z80_daisy_chain +// ======================> z80_daisy_chain_interface -class z80_daisy_chain +class z80_daisy_chain_interface : public device_interface { public: - z80_daisy_chain(); - void init(device_t *cpudevice, const z80_daisy_config *daisy); + // construction/destruction + z80_daisy_chain_interface(const machine_config &mconfig, device_t &device); + virtual ~z80_daisy_chain_interface(); - bool present() const { return (m_daisy_list != nullptr); } + // configuration helpers + static void static_set_daisy_config(device_t &device, const z80_daisy_config *config); - void reset(); - int update_irq_state(); - int call_ack_device(); - void call_reti_device(); + // getters + bool daisy_chain_present() const { return (m_chain != nullptr); } protected: - class daisy_entry - { - public: - daisy_entry(device_t *device); + // interface-level overrides + virtual void interface_post_start() override; + virtual void interface_post_reset() override; + + // initialization + void daisy_init(const z80_daisy_config *daisy); - daisy_entry * m_next; // next device - device_t * m_device; // associated device - device_z80daisy_interface * m_interface; // associated device's daisy interface - }; + // callbacks + int daisy_update_irq_state(); + int daisy_call_ack_device(); + void daisy_call_reti_device(); - daisy_entry * m_daisy_list; // head of the daisy chain +private: + const z80_daisy_config *m_daisy_config; + device_z80daisy_interface *m_chain; // head of the daisy chain }; |