summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/machine/6821pia.c
diff options
context:
space:
mode:
author Ryan Holtz <rholtz@batcountryentertainment.com>2010-08-23 04:55:40 +0000
committer Ryan Holtz <rholtz@batcountryentertainment.com>2010-08-23 04:55:40 +0000
commit3c0ef980fb784e09c47537d3d64647e471c015b1 (patch)
treee19df6a030ff9c1bd86932de79d41917efad0a01 /src/emu/machine/6821pia.c
parentf65faa60725fb6f66948701dcb93b0ab4c6c347f (diff)
Updated the 6821 PIA device to no longer be legacy. [Harmony]
Not in whatsnew: Tested hstennis andpeggle, verified that they still work properly.
Diffstat (limited to 'src/emu/machine/6821pia.c')
-rw-r--r--src/emu/machine/6821pia.c1135
1 files changed, 619 insertions, 516 deletions
diff --git a/src/emu/machine/6821pia.c b/src/emu/machine/6821pia.c
index c279bdd9c3a..a6913c6a5b6 100644
--- a/src/emu/machine/6821pia.c
+++ b/src/emu/machine/6821pia.c
@@ -9,71 +9,6 @@
/***************************************************************************
- TYPE DEFINITIONS
-***************************************************************************/
-
-typedef struct _pia6821_state pia6821_state;
-struct _pia6821_state
-{
- devcb_resolved_read8 in_a_func;
- devcb_resolved_read8 in_b_func;
- devcb_resolved_read_line in_ca1_func;
- devcb_resolved_read_line in_cb1_func;
- devcb_resolved_read_line in_ca2_func;
- devcb_resolved_read_line in_cb2_func;
- devcb_resolved_write8 out_a_func;
- devcb_resolved_write8 out_b_func;
- devcb_resolved_write_line out_ca2_func;
- devcb_resolved_write_line out_cb2_func;
- devcb_resolved_write_line irq_a_func;
- devcb_resolved_write_line irq_b_func;
-
- UINT8 in_a;
- UINT8 in_ca1;
- UINT8 in_ca2;
- UINT8 out_a;
- UINT8 out_ca2;
- UINT8 port_a_z_mask;
- UINT8 ddr_a;
- UINT8 ctl_a;
- UINT8 irq_a1;
- UINT8 irq_a2;
- UINT8 irq_a_state;
-
- UINT8 in_b;
- UINT8 in_cb1;
- UINT8 in_cb2;
- UINT8 out_b;
- UINT8 out_cb2;
- UINT8 last_out_cb2_z;
- UINT8 ddr_b;
- UINT8 ctl_b;
- UINT8 irq_b1;
- UINT8 irq_b2;
- UINT8 irq_b_state;
-
- /* variables that indicate if access a line externally -
- used to for logging purposes ONLY */
- UINT8 in_a_pushed;
- UINT8 out_a_needs_pulled;
- UINT8 in_ca1_pushed;
- UINT8 in_ca2_pushed;
- UINT8 out_ca2_needs_pulled;
- UINT8 in_b_pushed;
- UINT8 out_b_needs_pulled;
- UINT8 in_cb1_pushed;
- UINT8 in_cb2_pushed;
- UINT8 out_cb2_needs_pulled;
- UINT8 logged_port_a_not_connected;
- UINT8 logged_port_b_not_connected;
- UINT8 logged_ca1_not_connected;
- UINT8 logged_ca2_not_connected;
- UINT8 logged_cb1_not_connected;
- UINT8 logged_cb2_not_connected;
-};
-
-
-/***************************************************************************
MACROS
***************************************************************************/
@@ -101,150 +36,182 @@ struct _pia6821_state
/***************************************************************************
- PROTOTYPES
-***************************************************************************/
-/***************************************************************************
- INLINE FUNCTIONS
+ IMPLEMENTATION
***************************************************************************/
-INLINE pia6821_state *get_token(running_device *device)
+//**************************************************************************
+// DEVICE CONFIGURATION
+//**************************************************************************
+
+//-------------------------------------------------
+// pia6821_device_config - constructor
+//-------------------------------------------------
+
+pia6821_device_config::pia6821_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
+ : device_config(mconfig, static_alloc_device_config, "PIA6821", tag, owner, clock)
{
- assert(device != NULL);
- assert((device->type() == PIA6821) || (device->type() == PIA6822));
- return (pia6821_state *) downcast<legacy_device_base *>(device)->token();
}
-INLINE const pia6821_interface *get_interface(running_device *device)
+//-------------------------------------------------
+// static_alloc_device_config - allocate a new
+// configuration object
+//-------------------------------------------------
+
+device_config *pia6821_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
{
- assert(device != NULL);
- assert((device->type() == PIA6821) || (device->type() == PIA6822));
- return (const pia6821_interface *) device->baseconfig().static_config();
+ return global_alloc(pia6821_device_config(mconfig, tag, owner, clock));
}
-/***************************************************************************
- IMPLEMENTATION
-***************************************************************************/
+//-------------------------------------------------
+// alloc_device - allocate a new device object
+//-------------------------------------------------
-/*-------------------------------------------------
- DEVICE_START( pia6821 )
--------------------------------------------------*/
+device_t *pia6821_device_config::alloc_device(running_machine &machine) const
+{
+ return auto_alloc(&machine, pia6821_device(machine, *this));
+}
+
+
+//-------------------------------------------------
+// device_config_complete - perform any
+// operations now that the configuration is
+// complete
+//-------------------------------------------------
+
+void pia6821_device_config::device_config_complete()
+{
+
+}
+
+
+
+//**************************************************************************
+// LIVE DEVICE
+//**************************************************************************
+
+//-------------------------------------------------
+// pia6821_device - constructor
+//-------------------------------------------------
-static DEVICE_START( pia6821 )
+pia6821_device::pia6821_device(running_machine &_machine, const pia6821_device_config &config)
+ : device_t(_machine, config),
+ m_config(config)
{
- pia6821_state *p = get_token(device);
- const pia6821_interface *intf = get_interface(device);
- /* clear structure */
- memset(p, 0, sizeof(*p));
+}
+
+//-------------------------------------------------
+// device_start - device-specific startup
+//-------------------------------------------------
+void pia6821_device::device_start()
+{
/* resolve callbacks */
- devcb_resolve_read8(&p->in_a_func, &intf->in_a_func, device);
- devcb_resolve_read8(&p->in_b_func, &intf->in_b_func, device);
- devcb_resolve_read_line(&p->in_ca1_func, &intf->in_ca1_func, device);
- devcb_resolve_read_line(&p->in_cb1_func, &intf->in_cb1_func, device);
- devcb_resolve_read_line(&p->in_ca2_func, &intf->in_ca2_func, device);
- devcb_resolve_read_line(&p->in_cb2_func, &intf->in_cb2_func, device);
- devcb_resolve_write8(&p->out_a_func, &intf->out_a_func, device);
- devcb_resolve_write8(&p->out_b_func, &intf->out_b_func, device);
- devcb_resolve_write_line(&p->out_ca2_func, &intf->out_ca2_func, device);
- devcb_resolve_write_line(&p->out_cb2_func, &intf->out_cb2_func, device);
- devcb_resolve_write_line(&p->irq_a_func, &intf->irq_a_func, device);
- devcb_resolve_write_line(&p->irq_b_func, &intf->irq_b_func, device);
-
- state_save_register_device_item(device, 0, p->in_a);
- state_save_register_device_item(device, 0, p->in_ca1);
- state_save_register_device_item(device, 0, p->in_ca2);
- state_save_register_device_item(device, 0, p->out_a);
- state_save_register_device_item(device, 0, p->out_ca2);
- state_save_register_device_item(device, 0, p->port_a_z_mask);
- state_save_register_device_item(device, 0, p->ddr_a);
- state_save_register_device_item(device, 0, p->ctl_a);
- state_save_register_device_item(device, 0, p->irq_a1);
- state_save_register_device_item(device, 0, p->irq_a2);
- state_save_register_device_item(device, 0, p->irq_a_state);
- state_save_register_device_item(device, 0, p->in_b);
- state_save_register_device_item(device, 0, p->in_cb1);
- state_save_register_device_item(device, 0, p->in_cb2);
- state_save_register_device_item(device, 0, p->out_b);
- state_save_register_device_item(device, 0, p->out_cb2);
- state_save_register_device_item(device, 0, p->last_out_cb2_z);
- state_save_register_device_item(device, 0, p->ddr_b);
- state_save_register_device_item(device, 0, p->ctl_b);
- state_save_register_device_item(device, 0, p->irq_b1);
- state_save_register_device_item(device, 0, p->irq_b2);
- state_save_register_device_item(device, 0, p->irq_b_state);
- state_save_register_device_item(device, 0, p->in_a_pushed);
- state_save_register_device_item(device, 0, p->out_a_needs_pulled);
- state_save_register_device_item(device, 0, p->in_ca1_pushed);
- state_save_register_device_item(device, 0, p->in_ca2_pushed);
- state_save_register_device_item(device, 0, p->out_ca2_needs_pulled);
- state_save_register_device_item(device, 0, p->in_b_pushed);
- state_save_register_device_item(device, 0, p->out_b_needs_pulled);
- state_save_register_device_item(device, 0, p->in_cb1_pushed);
- state_save_register_device_item(device, 0, p->in_cb2_pushed);
- state_save_register_device_item(device, 0, p->out_cb2_needs_pulled);
+ devcb_resolve_read8(&m_in_a_func, &m_config.m_in_a_func, this);
+ devcb_resolve_read8(&m_in_b_func, &m_config.m_in_b_func, this);
+ devcb_resolve_read_line(&m_in_ca1_func, &m_config.m_in_ca1_func, this);
+ devcb_resolve_read_line(&m_in_cb1_func, &m_config.m_in_cb1_func, this);
+ devcb_resolve_read_line(&m_in_ca2_func, &m_config.m_in_ca2_func, this);
+ devcb_resolve_read_line(&m_in_cb2_func, &m_config.m_in_cb2_func, this);
+ devcb_resolve_write8(&m_out_a_func, &m_config.m_out_a_func, this);
+ devcb_resolve_write8(&m_out_b_func, &m_config.m_out_b_func, this);
+ devcb_resolve_write_line(&m_out_ca2_func, &m_config.m_out_ca2_func, this);
+ devcb_resolve_write_line(&m_out_cb2_func, &m_config.m_out_cb2_func, this);
+ devcb_resolve_write_line(&m_irq_a_func, &m_config.m_irq_a_func, this);
+ devcb_resolve_write_line(&m_irq_b_func, &m_config.m_irq_b_func, this);
+
+ state_save_register_device_item(this, 0, m_in_a);
+ state_save_register_device_item(this, 0, m_in_ca1);
+ state_save_register_device_item(this, 0, m_in_ca2);
+ state_save_register_device_item(this, 0, m_out_a);
+ state_save_register_device_item(this, 0, m_out_ca2);
+ state_save_register_device_item(this, 0, m_port_a_z_mask);
+ state_save_register_device_item(this, 0, m_ddr_a);
+ state_save_register_device_item(this, 0, m_ctl_a);
+ state_save_register_device_item(this, 0, m_irq_a1);
+ state_save_register_device_item(this, 0, m_irq_a2);
+ state_save_register_device_item(this, 0, m_irq_a_state);
+ state_save_register_device_item(this, 0, m_in_b);
+ state_save_register_device_item(this, 0, m_in_cb1);
+ state_save_register_device_item(this, 0, m_in_cb2);
+ state_save_register_device_item(this, 0, m_out_b);
+ state_save_register_device_item(this, 0, m_out_cb2);
+ state_save_register_device_item(this, 0, m_last_out_cb2_z);
+ state_save_register_device_item(this, 0, m_ddr_b);
+ state_save_register_device_item(this, 0, m_ctl_b);
+ state_save_register_device_item(this, 0, m_irq_b1);
+ state_save_register_device_item(this, 0, m_irq_b2);
+ state_save_register_device_item(this, 0, m_irq_b_state);
+ state_save_register_device_item(this, 0, m_in_a_pushed);
+ state_save_register_device_item(this, 0, m_out_a_needs_pulled);
+ state_save_register_device_item(this, 0, m_in_ca1_pushed);
+ state_save_register_device_item(this, 0, m_in_ca2_pushed);
+ state_save_register_device_item(this, 0, m_out_ca2_needs_pulled);
+ state_save_register_device_item(this, 0, m_in_b_pushed);
+ state_save_register_device_item(this, 0, m_out_b_needs_pulled);
+ state_save_register_device_item(this, 0, m_in_cb1_pushed);
+ state_save_register_device_item(this, 0, m_in_cb2_pushed);
+ state_save_register_device_item(this, 0, m_out_cb2_needs_pulled);
}
-/*-------------------------------------------------
- DEVICE_RESET( pia6821 )
--------------------------------------------------*/
+//-------------------------------------------------
+// device_reset - device-specific reset
+//-------------------------------------------------
-static DEVICE_RESET( pia6821 )
+void pia6821_device::device_reset()
{
- pia6821_state *p = get_token(device);
-
/*
* set default read values.
*
* ports A,CA1,CA2 default to 1
* ports B,CB1,CB2 are three-state and undefined (set to 0)
*/
- p->in_a = 0xff;
- p->in_ca1 = TRUE;
- p->in_ca2 = TRUE;
- p->out_a = 0;
- p->out_ca2 = 0;
- p->port_a_z_mask = 0;
- p->ddr_a = 0;
- p->ctl_a = 0;
- p->irq_a1 = 0;
- p->irq_a2 = 0;
- p->irq_a_state = 0;
- p->in_b = 0;
- p->in_cb1 = 0;
- p->in_cb2 = 0;
- p->out_b = 0;
- p->out_cb2 = 0;
- p->last_out_cb2_z = 0;
- p->ddr_b = 0;
- p->ctl_b = 0;
- p->irq_b1 = 0;
- p->irq_b2 = 0;
- p->irq_b_state = 0;
- p->in_a_pushed = 0;
- p->out_a_needs_pulled = 0;
- p->in_ca1_pushed = 0;
- p->in_ca2_pushed = 0;
- p->out_ca2_needs_pulled = 0;
- p->in_b_pushed = 0;
- p->out_b_needs_pulled = 0;
- p->in_cb1_pushed = 0;
- p->in_cb2_pushed = 0;
- p->out_cb2_needs_pulled = 0;
- p->logged_port_a_not_connected = 0;
- p->logged_port_b_not_connected = 0;
- p->logged_ca1_not_connected = 0;
- p->logged_ca2_not_connected = 0;
- p->logged_cb1_not_connected = 0;
- p->logged_cb2_not_connected = 0;
+ m_in_a = 0xff;
+ m_in_ca1 = TRUE;
+ m_in_ca2 = TRUE;
+ m_out_a = 0;
+ m_out_ca2 = 0;
+ m_port_a_z_mask = 0;
+ m_ddr_a = 0;
+ m_ctl_a = 0;
+ m_irq_a1 = 0;
+ m_irq_a2 = 0;
+ m_irq_a_state = 0;
+ m_in_b = 0;
+ m_in_cb1 = 0;
+ m_in_cb2 = 0;
+ m_out_b = 0;
+ m_out_cb2 = 0;
+ m_last_out_cb2_z = 0;
+ m_ddr_b = 0;
+ m_ctl_b = 0;
+ m_irq_b1 = 0;
+ m_irq_b2 = 0;
+ m_irq_b_state = 0;
+ m_in_a_pushed = 0;
+ m_out_a_needs_pulled = 0;
+ m_in_ca1_pushed = 0;
+ m_in_ca2_pushed = 0;
+ m_out_ca2_needs_pulled = 0;
+ m_in_b_pushed = 0;
+ m_out_b_needs_pulled = 0;
+ m_in_cb1_pushed = 0;
+ m_in_cb2_pushed = 0;
+ m_out_cb2_needs_pulled = 0;
+ m_logged_port_a_not_connected = 0;
+ m_logged_port_b_not_connected = 0;
+ m_logged_ca1_not_connected = 0;
+ m_logged_ca2_not_connected = 0;
+ m_logged_cb1_not_connected = 0;
+ m_logged_cb2_not_connected = 0;
/* clear the IRQs */
- devcb_call_write_line(&p->irq_a_func, FALSE);
- devcb_call_write_line(&p->irq_b_func, FALSE);
+ devcb_call_write_line(&m_irq_a_func, FALSE);
+ devcb_call_write_line(&m_irq_b_func, FALSE);
}
@@ -252,27 +219,24 @@ static DEVICE_RESET( pia6821 )
update_interrupts
-------------------------------------------------*/
-static void update_interrupts(running_device *device)
+void pia6821_device::update_interrupts()
{
- pia6821_state *p = get_token(device);
- int new_state;
-
- /* start with IRQ A */
- new_state = (p->irq_a1 && IRQ1_ENABLED(p->ctl_a)) || (p->irq_a2 && IRQ2_ENABLED(p->ctl_a));
+ /* start with IRQ A */
+ int new_state = (m_irq_a1 && IRQ1_ENABLED(m_ctl_a)) || (m_irq_a2 && IRQ2_ENABLED(m_ctl_a));
- if (new_state != p->irq_a_state)
+ if (new_state != m_irq_a_state)
{
- p->irq_a_state = new_state;
- devcb_call_write_line(&p->irq_a_func, p->irq_a_state);
+ m_irq_a_state = new_state;
+ devcb_call_write_line(&m_irq_a_func, m_irq_a_state);
}
/* then do IRQ B */
- new_state = (p->irq_b1 && IRQ1_ENABLED(p->ctl_b)) || (p->irq_b2 && IRQ2_ENABLED(p->ctl_b));
+ new_state = (m_irq_b1 && IRQ1_ENABLED(m_ctl_b)) || (m_irq_b2 && IRQ2_ENABLED(m_ctl_b));
- if (new_state != p->irq_b_state)
+ if (new_state != m_irq_b_state)
{
- p->irq_b_state = new_state;
- devcb_call_write_line(&p->irq_b_func, p->irq_b_state);
+ m_irq_b_state = new_state;
+ devcb_call_write_line(&m_irq_b_func, m_irq_b_state);
}
}
@@ -281,28 +245,31 @@ static void update_interrupts(running_device *device)
get_in_a_value
-------------------------------------------------*/
-static UINT8 get_in_a_value(running_device *device)
+UINT8 pia6821_device::get_in_a_value()
{
- pia6821_state *p = get_token(device);
UINT8 port_a_data = 0;
UINT8 ret;
/* update the input */
- if (p->in_a_func.read != NULL)
- port_a_data = devcb_call_read8(&p->in_a_func, 0);
+ if (m_in_a_func.read != NULL)
+ {
+ port_a_data = devcb_call_read8(&m_in_a_func, 0);
+ }
else
{
- if (p->in_a_pushed)
- port_a_data = p->in_a;
+ if (m_in_a_pushed)
+ {
+ port_a_data = m_in_a;
+ }
else
{
/* mark all pins disconnected */
- p->port_a_z_mask = 0xff;
+ m_port_a_z_mask = 0xff;
- if (!p->logged_port_a_not_connected && (p->ddr_a != 0xff))
+ if (!m_logged_port_a_not_connected && (m_ddr_a != 0xff))
{
- logerror("PIA #%s: Warning! No port A read handler. Assuming pins 0x%02X not connected\n", device->tag(), p->ddr_a ^ 0xff);
- p->logged_port_a_not_connected = TRUE;
+ logerror("PIA #%s: Warning! No port A read handler. Assuming pins 0x%02X not connected\n", tag(), m_ddr_a ^ 0xff);
+ m_logged_port_a_not_connected = TRUE;
}
}
}
@@ -310,9 +277,9 @@ static UINT8 get_in_a_value(running_device *device)
/* - connected pins are always read
- disconnected pins read the output buffer in output mode
- disconnected pins are HI in input mode */
- ret = (~p->port_a_z_mask & port_a_data) |
- ( p->port_a_z_mask & p->ddr_a & p->out_a) |
- ( p->port_a_z_mask & ~p->ddr_a);
+ ret = (~m_port_a_z_mask & port_a_data) |
+ ( m_port_a_z_mask & m_ddr_a & m_out_a) |
+ ( m_port_a_z_mask & ~m_ddr_a);
return ret;
}
@@ -322,31 +289,36 @@ static UINT8 get_in_a_value(running_device *device)
get_in_b_value
-------------------------------------------------*/
-static UINT8 get_in_b_value(running_device *device)
+UINT8 pia6821_device::get_in_b_value()
{
- pia6821_state *p = get_token(device);
UINT8 ret;
- if (p->ddr_b == 0xff)
+ if (m_ddr_b == 0xff)
+ {
/* all output, just return buffer */
- ret = p->out_b;
+ ret = m_out_b;
+ }
else
{
UINT8 port_b_data;
/* update the input */
- if (p->in_b_func.read != NULL)
- port_b_data = devcb_call_read8(&p->in_b_func, 0);
+ if (m_in_b_func.read != NULL)
+ {
+ port_b_data = devcb_call_read8(&m_in_b_func, 0);
+ }
else
{
- if (p->in_b_pushed)
- port_b_data = p->in_b;
+ if (m_in_b_pushed)
+ {
+ port_b_data = m_in_b;
+ }
else
{
- if (!p->logged_port_b_not_connected && (p->ddr_b != 0xff))
+ if (!m_logged_port_b_not_connected && (m_ddr_b != 0xff))
{
- logerror("PIA #%s: Error! No port B read handler. Three-state pins 0x%02X are undefined\n", device->tag(), p->ddr_b ^ 0xff);
- p->logged_port_b_not_connected = TRUE;
+ logerror("PIA #%s: Error! No port B read handler. Three-state pins 0x%02X are undefined\n", tag(), m_ddr_b ^ 0xff);
+ m_logged_port_b_not_connected = TRUE;
}
/* undefined -- need to return something */
@@ -355,7 +327,7 @@ static UINT8 get_in_b_value(running_device *device)
}
/* the DDR determines if the pin or the output buffer is read */
- ret = (p->out_b & p->ddr_b) | (port_b_data & ~p->ddr_b);
+ ret = (m_out_b & m_ddr_b) | (port_b_data & ~m_ddr_b);
}
return ret;
@@ -366,17 +338,20 @@ static UINT8 get_in_b_value(running_device *device)
get_out_a_value
-------------------------------------------------*/
-static UINT8 get_out_a_value(running_device *device)
+UINT8 pia6821_device::get_out_a_value()
{
- pia6821_state *p = get_token(device);
UINT8 ret;
- if (p->ddr_a == 0xff)
+ if (m_ddr_a == 0xff)
+ {
/* all output */
- ret = p->out_a;
+ ret = m_out_a;
+ }
else
+ {
/* input pins don't change */
- ret = (p->out_a & p->ddr_a) | (get_in_a_value(device) & ~p->ddr_a);
+ ret = (m_out_a & m_ddr_a) | (get_in_a_value() & ~m_ddr_a);
+ }
return ret;
}
@@ -386,12 +361,10 @@ static UINT8 get_out_a_value(running_device *device)
get_out_b_value
-------------------------------------------------*/
-static UINT8 get_out_b_value(running_device *device)
+UINT8 pia6821_device::get_out_b_value()
{
- pia6821_state *p = get_token(device);
-
/* input pins are high-impedance - we just send them as zeros for backwards compatibility */
- return p->out_b & p->ddr_b;
+ return m_out_b & m_ddr_b;
}
@@ -399,23 +372,25 @@ static UINT8 get_out_b_value(running_device *device)
set_out_ca2
-------------------------------------------------*/
-static void set_out_ca2(running_device *device, int data)
+void pia6821_device::set_out_ca2(int data)
{
- pia6821_state *p = get_token(device);
-
- if (data != p->out_ca2)
+ if (data != m_out_ca2)
{
- p->out_ca2 = data;
+ m_out_ca2 = data;
/* send to output function */
- if (p->out_ca2_func.write)
- devcb_call_write_line(&p->out_ca2_func, p->out_ca2);
+ if (m_out_ca2_func.write)
+ {
+ devcb_call_write_line(&m_out_ca2_func, m_out_ca2);
+ }
else
{
- if (p->out_ca2_needs_pulled)
- logerror("PIA #%s: Warning! No port CA2 write handler. Previous value has been lost!\n", device->tag());
+ if (m_out_ca2_needs_pulled)
+ {
+ logerror("PIA #%s: Warning! No port CA2 write handler. Previous value has been lost!\n", tag());
+ }
- p->out_ca2_needs_pulled = TRUE;
+ m_out_ca2_needs_pulled = TRUE;
}
}
}
@@ -425,26 +400,28 @@ static void set_out_ca2(running_device *device, int data)
set_out_cb2
-------------------------------------------------*/
-static void set_out_cb2(running_device *device, int data)
+void pia6821_device::set_out_cb2(int data)
{
- pia6821_state *p = get_token(device);
+ int z = pia6821_get_output_cb2_z(this);
- int z = pia6821_get_output_cb2_z(device);
-
- if ((data != p->out_cb2) || (z != p->last_out_cb2_z))
+ if ((data != m_out_cb2) || (z != m_last_out_cb2_z))
{
- p->out_cb2 = data;
- p->last_out_cb2_z = z;
+ m_out_cb2 = data;
+ m_last_out_cb2_z = z;
/* send to output function */
- if (p->out_cb2_func.write)
- devcb_call_write_line(&p->out_cb2_func, p->out_cb2);
+ if (m_out_cb2_func.write)
+ {
+ devcb_call_write_line(&m_out_cb2_func, m_out_cb2);
+ }
else
{
- if (p->out_cb2_needs_pulled)
- logerror("PIA #%s: Warning! No port CB2 write handler. Previous value has been lost!\n", device->tag());
+ if (m_out_cb2_needs_pulled)
+ {
+ logerror("PIA #%s: Warning! No port CB2 write handler. Previous value has been lost!\n", tag());
+ }
- p->out_cb2_needs_pulled = TRUE;
+ m_out_cb2_needs_pulled = TRUE;
}
}
}
@@ -454,29 +431,29 @@ static void set_out_cb2(running_device *device, int data)
port_a_r
-------------------------------------------------*/
-static UINT8 port_a_r(running_device *device)
+UINT8 pia6821_device::port_a_r()
{
- pia6821_state *p = get_token(device);
-
- UINT8 ret = get_in_a_value(device);
+ UINT8 ret = get_in_a_value();
/* IRQ flags implicitly cleared by a read */
- p->irq_a1 = FALSE;
- p->irq_a2 = FALSE;
- update_interrupts(device);
+ m_irq_a1 = FALSE;
+ m_irq_a2 = FALSE;
+ update_interrupts();
/* CA2 is configured as output and in read strobe mode */
- if (C2_OUTPUT(p->ctl_a) && C2_STROBE_MODE(p->ctl_a))
+ if(C2_OUTPUT(m_ctl_a) && C2_STROBE_MODE(m_ctl_a))
{
/* this will cause a transition low */
- set_out_ca2(device, FALSE);
+ set_out_ca2(FALSE);
/* if the CA2 strobe is cleared by the E, reset it right away */
- if (STROBE_E_RESET(p->ctl_a))
- set_out_ca2(device, TRUE);
+ if(STROBE_E_RESET(m_ctl_a))
+ {
+ set_out_ca2(TRUE);
+ }
}
- LOG(("PIA #%s: port A read = %02X\n", device->tag(), ret));
+ LOG(("PIA #%s: port A read = %02X\n", tag(), ret));
return ret;
}
@@ -486,13 +463,11 @@ static UINT8 port_a_r(running_device *device)
ddr_a_r
-------------------------------------------------*/
-static UINT8 ddr_a_r(running_device *device)
+UINT8 pia6821_device::ddr_a_r()
{
- pia6821_state *p = get_token(device);
+ UINT8 ret = m_ddr_a;
- UINT8 ret = p->ddr_a;
-
- LOG(("PIA #%s: DDR A read = %02X\n", device->tag(), ret));
+ LOG(("PIA #%s: DDR A read = %02X\n", tag(), ret));
return ret;
}
@@ -502,25 +477,25 @@ static UINT8 ddr_a_r(running_device *device)
port_b_r
-------------------------------------------------*/
-static UINT8 port_b_r(running_device *device)
+UINT8 pia6821_device::port_b_r()
{
- pia6821_state *p = get_token(device);
-
- UINT8 ret = get_in_b_value(device);
+ UINT8 ret = get_in_b_value();
/* This read will implicitly clear the IRQ B1 flag. If CB2 is in write-strobe
mode with CB1 restore, and a CB1 active transition set the flag,
clearing it will cause CB2 to go high again. Note that this is different
from what happens with port A. */
- if (p->irq_b1 && C2_STROBE_MODE(p->ctl_b) && STROBE_C1_RESET(p->ctl_b))
- set_out_cb2(device, TRUE);
+ if(m_irq_b1 && C2_STROBE_MODE(m_ctl_b) && STROBE_C1_RESET(m_ctl_b))
+ {
+ set_out_cb2(TRUE);
+ }
/* IRQ flags implicitly cleared by a read */
- p->irq_b1 = FALSE;
- p->irq_b2 = FALSE;
- update_interrupts(device);
+ m_irq_b1 = FALSE;
+ m_irq_b2 = FALSE;
+ update_interrupts();
- LOG(("PIA #%s: port B read = %02X\n", device->tag(), ret));
+ LOG(("PIA #%s: port B read = %02X\n", tag(), ret));
return ret;
}
@@ -530,13 +505,11 @@ static UINT8 port_b_r(running_device *device)
ddr_b_r
-------------------------------------------------*/
-static UINT8 ddr_b_r(running_device *device)
+UINT8 pia6821_device::ddr_b_r()
{
- pia6821_state *p = get_token(device);
-
- UINT8 ret = p->ddr_b;
+ UINT8 ret = m_ddr_b;
- LOG(("PIA #%s: DDR B read = %02X\n", device->tag(), ret));
+ LOG(("PIA #%s: DDR B read = %02X\n", tag(), ret));
return ret;
}
@@ -546,39 +519,46 @@ static UINT8 ddr_b_r(running_device *device)
control_a_r
-------------------------------------------------*/
-static UINT8 control_a_r(running_device *device)
+UINT8 pia6821_device::control_a_r()
{
- pia6821_state *p = get_token(device);
UINT8 ret;
/* update CA1 & CA2 if callback exists, these in turn may update IRQ's */
- if (p->in_ca1_func.read != NULL)
- pia6821_ca1_w(device, devcb_call_read_line(&p->in_ca1_func));
- else if (!p->logged_ca1_not_connected && (!p->in_ca1_pushed))
+ if (m_in_ca1_func.read != NULL)
+ {
+ ca1_w(devcb_call_read_line(&m_in_ca1_func));
+ }
+ else if(!m_logged_ca1_not_connected && (!m_in_ca1_pushed))
{
- logerror("PIA #%s: Warning! No CA1 read handler. Assuming pin not connected\n", device->tag());
- p->logged_ca1_not_connected = TRUE;
+ logerror("PIA #%s: Warning! No CA1 read handler. Assuming pin not connected\n", tag());
+ m_logged_ca1_not_connected = TRUE;
}
- if (p->in_ca2_func.read != NULL)
- pia6821_ca2_w(device, devcb_call_read_line(&p->in_ca2_func));
- else if ( !p->logged_ca2_not_connected && C2_INPUT(p->ctl_a) && !p->in_ca2_pushed)
+ if (m_in_ca2_func.read != NULL)
+ {
+ ca2_w(devcb_call_read_line(&m_in_ca2_func));
+ }
+ else if ( !m_logged_ca2_not_connected && C2_INPUT(m_ctl_a) && !m_in_ca2_pushed)
{
- logerror("PIA #%s: Warning! No CA2 read handler. Assuming pin not connected\n", device->tag());
- p->logged_ca2_not_connected = TRUE;
+ logerror("PIA #%s: Warning! No CA2 read handler. Assuming pin not connected\n", tag());
+ m_logged_ca2_not_connected = TRUE;
}
/* read control register */
- ret = p->ctl_a;
+ ret = m_ctl_a;
/* set the IRQ flags if we have pending IRQs */
- if (p->irq_a1)
+ if(m_irq_a1)
+ {
ret |= PIA_IRQ1;
+ }
- if (p->irq_a2 && C2_INPUT(p->ctl_a))
+ if(m_irq_a2 && C2_INPUT(m_ctl_a))
+ {
ret |= PIA_IRQ2;
+ }
- LOG(("PIA #%s: control A read = %02X\n", device->tag(), ret));
+ LOG(("PIA #%s: control A read = %02X\n", tag(), ret));
return ret;
}
@@ -588,39 +568,46 @@ static UINT8 control_a_r(running_device *device)
control_b_r
-------------------------------------------------*/
-static UINT8 control_b_r(running_device *device)
+UINT8 pia6821_device::control_b_r()
{
- pia6821_state *p = get_token(device);
UINT8 ret;
/* update CB1 & CB2 if callback exists, these in turn may update IRQ's */
- if (p->in_cb1_func.read != NULL)
- pia6821_cb1_w(device, devcb_call_read_line(&p->in_cb1_func));
- else if (!p->logged_cb1_not_connected && !p->in_cb1_pushed)
+ if(m_in_cb1_func.read != NULL)
+ {
+ cb1_w(devcb_call_read_line(&m_in_cb1_func));
+ }
+ else if(!m_logged_cb1_not_connected && !m_in_cb1_pushed)
{
- logerror("PIA #%s: Error! no CB1 read handler. Three-state pin is undefined\n", device->tag());
- p->logged_cb1_not_connected = TRUE;
+ logerror("PIA #%s: Error! no CB1 read handler. Three-state pin is undefined\n", tag());
+ m_logged_cb1_not_connected = TRUE;
}
- if (p->in_cb2_func.read != NULL)
- pia6821_cb2_w(device, devcb_call_read_line(&p->in_cb2_func));
- else if (!p->logged_cb2_not_connected && C2_INPUT(p->ctl_b) && !p->in_cb2_pushed)
+ if(m_in_cb2_func.read != NULL)
+ {
+ cb2_w(devcb_call_read_line(&m_in_cb2_func));
+ }
+ else if(!m_logged_cb2_not_connected && C2_INPUT(m_ctl_b) && !m_in_cb2_pushed)
{
- logerror("PIA #%s: Error! No CB2 read handler. Three-state pin is undefined\n", device->tag());
- p->logged_cb2_not_connected = TRUE;
+ logerror("PIA #%s: Error! No CB2 read handler. Three-state pin is undefined\n", tag());
+ m_logged_cb2_not_connected = TRUE;
}
/* read control register */
- ret = p->ctl_b;
+ ret = m_ctl_b;
/* set the IRQ flags if we have pending IRQs */
- if (p->irq_b1)
+ if(m_irq_b1)
+ {
ret |= PIA_IRQ1;
+ }
- if (p->irq_b2 && C2_INPUT(p->ctl_b))
+ if(m_irq_b2 && C2_INPUT(m_ctl_b))
+ {
ret |= PIA_IRQ2;
+ }
- LOG(("PIA #%s: control B read = %02X\n", device->tag(), ret));
+ LOG(("PIA #%s: control B read = %02X\n", tag(), ret));
return ret;
}
@@ -632,32 +619,45 @@ static UINT8 control_b_r(running_device *device)
READ8_DEVICE_HANDLER( pia6821_r )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->reg_r(offset);
+}
+
+UINT8 pia6821_device::reg_r(UINT8 offset)
+{
UINT8 ret;
switch (offset & 0x03)
{
default: /* impossible */
case 0x00:
- if (OUTPUT_SELECTED(p->ctl_a))
- ret = port_a_r(device);
+ if (OUTPUT_SELECTED(m_ctl_a))
+ {
+ ret = port_a_r();
+ }
else
- ret = ddr_a_r(device);
+ {
+ ret = ddr_a_r();
+ }
break;
case 0x01:
- ret = control_a_r(device);
+ ret = control_a_r();
break;
case 0x02:
- if (OUTPUT_SELECTED(p->ctl_b))
- ret = port_b_r(device);
+ if (OUTPUT_SELECTED(m_ctl_b))
+ {
+ ret = port_b_r();
+ }
else
- ret = ddr_b_r(device);
+ {
+ ret = ddr_b_r();
+ }
break;
case 0x03:
- ret = control_b_r(device);
+ ret = control_b_r();
break;
}
@@ -671,18 +671,25 @@ READ8_DEVICE_HANDLER( pia6821_r )
READ8_DEVICE_HANDLER( pia6821_alt_r )
{
- return pia6821_r(device, ((offset << 1) & 0x02) | ((offset >> 1) & 0x01));
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->reg_r(((offset << 1) & 0x02) | ((offset >> 1) & 0x01));
}
+
/*-------------------------------------------------
pia6821_get_port_b_z_mask
-------------------------------------------------*/
UINT8 pia6821_get_port_b_z_mask(running_device *device)
{
- pia6821_state *p = get_token(device);
- return ~p->ddr_b;
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->get_port_b_z_mask();
+}
+
+UINT8 pia6821_device::get_port_b_z_mask()
+{
+ return ~m_ddr_b;
}
@@ -690,23 +697,25 @@ UINT8 pia6821_get_port_b_z_mask(running_device *device)
send_to_out_a_func
-------------------------------------------------*/
-static void send_to_out_a_func(running_device *device, const char* message)
+void pia6821_device::send_to_out_a_func(const char* message)
{
- pia6821_state *p = get_token(device);
-
/* input pins are pulled high */
- UINT8 data = get_out_a_value(device);
+ UINT8 data = get_out_a_value();
- LOG(("PIA #%s: %s = %02X\n", device->tag(), message, data));
+ LOG(("PIA #%s: %s = %02X\n", tag(), message, data));
- if (p->out_a_func.write != NULL)
- devcb_call_write8(&p->out_a_func, 0, data);
+ if(m_out_a_func.write != NULL)
+ {
+ devcb_call_write8(&m_out_a_func, 0, data);
+ }
else
{
- if (p->out_a_needs_pulled)
- logerror("PIA #%s: Warning! No port A write handler. Previous value has been lost!\n", device->tag());
+ if(m_out_a_needs_pulled)
+ {
+ logerror("PIA #%s: Warning! No port A write handler. Previous value has been lost!\n", tag());
+ }
- p->out_a_needs_pulled = TRUE;
+ m_out_a_needs_pulled = TRUE;
}
}
@@ -715,23 +724,25 @@ static void send_to_out_a_func(running_device *device, const char* message)
send_to_out_b_func
-------------------------------------------------*/
-static void send_to_out_b_func(running_device *device, const char* message)
+void pia6821_device::send_to_out_b_func(const char* message)
{
- pia6821_state *p = get_token(device);
-
/* input pins are high-impedance - we just send them as zeros for backwards compatibility */
- UINT8 data = get_out_b_value(device);
+ UINT8 data = get_out_b_value();
- LOG(("PIA #%s: %s = %02X\n", device->tag(), message, data));
+ LOG(("PIA #%s: %s = %02X\n", tag(), message, data));
- if (p->out_b_func.write != NULL)
- devcb_call_write8(&p->out_b_func, 0, data);
+ if(m_out_b_func.write != NULL)
+ {
+ devcb_call_write8(&m_out_b_func, 0, data);
+ }
else
{
- if (p->out_b_needs_pulled)
- logerror("PIA #%s: Warning! No port B write handler. Previous value has been lost!\n", device->tag());
+ if(m_out_b_needs_pulled)
+ {
+ logerror("PIA #%s: Warning! No port B write handler. Previous value has been lost!\n", tag());
+ }
- p->out_b_needs_pulled = TRUE;
+ m_out_b_needs_pulled = TRUE;
}
}
@@ -740,14 +751,12 @@ static void send_to_out_b_func(running_device *device, const char* message)
port_a_w
-------------------------------------------------*/
-static void port_a_w(running_device *device, UINT8 data)
+void pia6821_device::port_a_w(UINT8 data)
{
- pia6821_state *p = get_token(device);
-
/* buffer the output value */
- p->out_a = data;
+ m_out_a = data;
- send_to_out_a_func(device, "port A write");
+ send_to_out_a_func("port A write");
}
@@ -755,23 +764,27 @@ static void port_a_w(running_device *device, UINT8 data)
ddr_a_w
-------------------------------------------------*/
-static void ddr_a_w(running_device *device, UINT8 data)
+void pia6821_device::ddr_a_w(UINT8 data)
{
- pia6821_state *p = get_token(device);
-
- if (data == 0x00)
- LOG(("PIA #%s: DDR A write = %02X (input mode)\n", device->tag(), data));
- else if (data == 0xff)
- LOG(("PIA #%s: DDR A write = %02X (output mode)\n", device->tag(), data));
+ if(data == 0x00)
+ {
+ LOG(("PIA #%s: DDR A write = %02X (input mode)\n", tag(), data));
+ }
+ else if(data == 0xff)
+ {
+ LOG(("PIA #%s: DDR A write = %02X (output mode)\n", tag(), data));
+ }
else
- LOG(("PIA #%s: DDR A write = %02X (mixed mode)\n", device->tag(), data));
+ {
+ LOG(("PIA #%s: DDR A write = %02X (mixed mode)\n", tag(), data));
+ }
- if (p->ddr_a != data)
+ if(m_ddr_a != data)
{
/* DDR changed, call the callback again */
- p->ddr_a = data;
- p->logged_port_a_not_connected = FALSE;
- send_to_out_a_func(device, "port A write due to DDR change");
+ m_ddr_a = data;
+ m_logged_port_a_not_connected = FALSE;
+ send_to_out_a_func("port A write due to DDR change");
}
}
@@ -780,24 +793,24 @@ static void ddr_a_w(running_device *device, UINT8 data)
port_b_w
-------------------------------------------------*/
-static void port_b_w(running_device *device, UINT8 data)
+void pia6821_device::port_b_w(UINT8 data)
{
- pia6821_state *p = get_token(device);
-
/* buffer the output value */
- p->out_b = data;
+ m_out_b = data;
- send_to_out_b_func(device, "port B write");
+ send_to_out_b_func("port B write");
/* CB2 in write strobe mode */
- if (C2_STROBE_MODE(p->ctl_b))
+ if(C2_STROBE_MODE(m_ctl_b))
{
/* this will cause a transition low */
- set_out_cb2(device, FALSE);
+ set_out_cb2(FALSE);
/* if the CB2 strobe is cleared by the E, reset it right away */
- if (STROBE_E_RESET(p->ctl_b))
- set_out_cb2(device, TRUE);
+ if(STROBE_E_RESET(m_ctl_b))
+ {
+ set_out_cb2(TRUE);
+ }
}
}
@@ -806,23 +819,27 @@ static void port_b_w(running_device *device, UINT8 data)
ddr_b_w
-------------------------------------------------*/
-static void ddr_b_w(running_device *device, UINT8 data)
+void pia6821_device::ddr_b_w(UINT8 data)
{
- pia6821_state *p = get_token(device);
-
if (data == 0x00)
- LOG(("PIA #%s: DDR B write = %02X (input mode)\n", device->tag(), data));
+ {
+ LOG(("PIA #%s: DDR B write = %02X (input mode)\n", tag(), data));
+ }
else if (data == 0xff)
- LOG(("PIA #%s: DDR B write = %02X (output mode)\n", device->tag(), data));
+ {
+ LOG(("PIA #%s: DDR B write = %02X (output mode)\n", tag(), data));
+ }
else
- LOG(("PIA #%s: DDR B write = %02X (mixed mode)\n", device->tag(), data));
+ {
+ LOG(("PIA #%s: DDR B write = %02X (mixed mode)\n", tag(), data));
+ }
- if (p->ddr_b != data)
+ if(m_ddr_b != data)
{
/* DDR changed, call the callback again */
- p->ddr_b = data;
- p->logged_port_b_not_connected = FALSE;
- send_to_out_b_func(device, "port B write due to DDR change");
+ m_ddr_b = data;
+ m_logged_port_b_not_connected = FALSE;
+ send_to_out_b_func("port B write due to DDR change");
}
}
@@ -831,35 +848,37 @@ static void ddr_b_w(running_device *device, UINT8 data)
control_a_w
-------------------------------------------------*/
-static void control_a_w(running_device *device, UINT8 data)
+void pia6821_device::control_a_w(UINT8 data)
{
- pia6821_state *p = get_token(device);
-
/* bit 7 and 6 are read only */
data &= 0x3f;
- LOG(("PIA #%s: control A write = %02X\n", device->tag(), data));
+ LOG(("PIA #%s: control A write = %02X\n", tag(), data));
/* update the control register */
- p->ctl_a = data;
+ m_ctl_a = data;
/* CA2 is configured as output */
- if (C2_OUTPUT(p->ctl_a))
+ if(C2_OUTPUT(m_ctl_a))
{
int temp;
- if (C2_SET_MODE(p->ctl_a))
+ if(C2_SET_MODE(m_ctl_a))
+ {
/* set/reset mode - bit value determines the new output */
- temp = C2_SET(p->ctl_a);
+ temp = C2_SET(m_ctl_a);
+ }
else
+ {
/* strobe mode - output is always high unless strobed */
temp = TRUE;
+ }
- set_out_ca2(device, temp);
+ set_out_ca2(temp);
}
/* update externals */
- update_interrupts(device);
+ update_interrupts();
}
@@ -867,30 +886,33 @@ static void control_a_w(running_device *device, UINT8 data)
control_b_w
-------------------------------------------------*/
-static void control_b_w(running_device *device, UINT8 data)
+void pia6821_device::control_b_w(UINT8 data)
{
- pia6821_state *p = get_token(device);
int temp;
/* bit 7 and 6 are read only */
data &= 0x3f;
- LOG(("PIA #%s: control B write = %02X\n", device->tag(), data));
+ LOG(("PIA #%s: control B write = %02X\n", tag(), data));
/* update the control register */
- p->ctl_b = data;
+ m_ctl_b = data;
- if (C2_SET_MODE(p->ctl_b))
+ if (C2_SET_MODE(m_ctl_b))
+ {
/* set/reset mode - bit value determines the new output */
- temp = C2_SET(p->ctl_b);
+ temp = C2_SET(m_ctl_b);
+ }
else
+ {
/* strobe mode - output is always high unless strobed */
temp = TRUE;
+ }
- set_out_cb2(device, temp);
+ set_out_cb2(temp);
/* update externals */
- update_interrupts(device);
+ update_interrupts();
}
@@ -900,31 +922,43 @@ static void control_b_w(running_device *device, UINT8 data)
WRITE8_DEVICE_HANDLER( pia6821_w )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->reg_w(offset, data);
+}
+void pia6821_device::reg_w(UINT8 offset, UINT8 data)
+{
switch (offset & 0x03)
{
default: /* impossible */
case 0x00:
- if (OUTPUT_SELECTED(p->ctl_a))
- port_a_w(device, data);
+ if (OUTPUT_SELECTED(m_ctl_a))
+ {
+ port_a_w(data);
+ }
else
- ddr_a_w(device, data);
+ {
+ ddr_a_w(data);
+ }
break;
case 0x01:
- control_a_w(device, data);
+ control_a_w( data);
break;
case 0x02:
- if (OUTPUT_SELECTED(p->ctl_b))
- port_b_w(device, data);
+ if(OUTPUT_SELECTED(m_ctl_b))
+ {
+ port_b_w(data);
+ }
else
- ddr_b_w(device, data);
+ {
+ ddr_b_w(data);
+ }
break;
case 0x03:
- control_b_w(device, data);
+ control_b_w(data);
break;
}
}
@@ -936,7 +970,8 @@ WRITE8_DEVICE_HANDLER( pia6821_w )
WRITE8_DEVICE_HANDLER( pia6821_alt_w )
{
- pia6821_w(device, ((offset << 1) & 0x02) | ((offset >> 1) & 0x01), data);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->reg_w(((offset << 1) & 0x02) | ((offset >> 1) & 0x01), data);
}
@@ -946,9 +981,13 @@ WRITE8_DEVICE_HANDLER( pia6821_alt_w )
void pia6821_set_port_a_z_mask(running_device *device, UINT8 data)
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->set_port_a_z_mask(data);
+}
- p->port_a_z_mask = data;
+void pia6821_device::set_port_a_z_mask(UINT8 data)
+{
+ m_port_a_z_mask = data;
}
@@ -958,9 +997,13 @@ void pia6821_set_port_a_z_mask(running_device *device, UINT8 data)
READ8_DEVICE_HANDLER( pia6821_porta_r )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->porta_r();
+}
- return p->in_a;
+UINT8 pia6821_device::porta_r()
+{
+ return m_in_a;
}
@@ -970,15 +1013,19 @@ READ8_DEVICE_HANDLER( pia6821_porta_r )
void pia6821_set_input_a(running_device *device, UINT8 data, UINT8 z_mask)
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->set_input_a(data, z_mask);
+}
- assert_always(p->in_a_func.read == NULL, "pia6821_porta_w() called when in_a_func implemented");
+void pia6821_device::set_input_a(UINT8 data, UINT8 z_mask)
+{
+ assert_always(m_in_a_func.read == NULL, "pia6821_porta_w() called when in_a_func implemented");
- LOG(("PIA #%s: set input port A = %02X\n", device->tag(), data));
+ LOG(("PIA #%s: set input port A = %02X\n", tag(), data));
- p->in_a = data;
- p->port_a_z_mask = z_mask;
- p->in_a_pushed = TRUE;
+ m_in_a = data;
+ m_port_a_z_mask = z_mask;
+ m_in_a_pushed = TRUE;
}
@@ -988,7 +1035,13 @@ void pia6821_set_input_a(running_device *device, UINT8 data, UINT8 z_mask)
WRITE8_DEVICE_HANDLER( pia6821_porta_w )
{
- pia6821_set_input_a(device, data, 0);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->porta_w(data);
+}
+
+void pia6821_device::porta_w(UINT8 data)
+{
+ pia6821_set_input_a(this, data, 0);
}
@@ -998,11 +1051,15 @@ WRITE8_DEVICE_HANDLER( pia6821_porta_w )
UINT8 pia6821_get_output_a(running_device *device)
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->get_output_a();
+}
- p->out_a_needs_pulled = FALSE;
+UINT8 pia6821_device::get_output_a()
+{
+ m_out_a_needs_pulled = FALSE;
- return get_out_a_value(device);
+ return get_out_a_value();
}
@@ -1012,9 +1069,13 @@ UINT8 pia6821_get_output_a(running_device *device)
READ_LINE_DEVICE_HANDLER( pia6821_ca1_r )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->ca1_r();
+}
- return p->in_ca1;
+UINT8 pia6821_device::ca1_r()
+{
+ return m_in_ca1;
}
@@ -1024,30 +1085,35 @@ READ_LINE_DEVICE_HANDLER( pia6821_ca1_r )
WRITE_LINE_DEVICE_HANDLER( pia6821_ca1_w )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->ca1_w(state);
+}
- LOG(("PIA #%s: set input CA1 = %d\n", device->tag(), state));
+void pia6821_device::ca1_w(UINT8 state)
+{
+ LOG(("PIA #%s: set input CA1 = %d\n", tag(), state));
/* the new state has caused a transition */
- if ((p->in_ca1 != state) &&
- ((state && C1_LOW_TO_HIGH(p->ctl_a)) || (!state && C1_HIGH_TO_LOW(p->ctl_a))))
+ if((m_in_ca1 != state) && ((state && C1_LOW_TO_HIGH(m_ctl_a)) || (!state && C1_HIGH_TO_LOW(m_ctl_a))))
{
- LOG(("PIA #%s: CA1 triggering\n", device->tag()));
+ LOG(("PIA #%s: CA1 triggering\n", tag()));
/* mark the IRQ */
- p->irq_a1 = TRUE;
+ m_irq_a1 = TRUE;
/* update externals */
- update_interrupts(device);
+ update_interrupts();
/* CA2 is configured as output and in read strobe mode and cleared by a CA1 transition */
- if (C2_OUTPUT(p->ctl_a) && C2_STROBE_MODE(p->ctl_a) && STROBE_C1_RESET(p->ctl_a))
- set_out_ca2(device, TRUE);
+ if(C2_OUTPUT(m_ctl_a) && C2_STROBE_MODE(m_ctl_a) && STROBE_C1_RESET(m_ctl_a))
+ {
+ set_out_ca2(TRUE);
+ }
}
/* set the new value for CA1 */
- p->in_ca1 = state;
- p->in_ca1_pushed = TRUE;
+ m_in_ca1 = state;
+ m_in_ca1_pushed = TRUE;
}
@@ -1057,9 +1123,13 @@ WRITE_LINE_DEVICE_HANDLER( pia6821_ca1_w )
READ_LINE_DEVICE_HANDLER( pia6821_ca2_r )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->ca2_r();
+}
- return p->in_ca2;
+UINT8 pia6821_device::ca2_r()
+{
+ return m_in_ca2;
}
@@ -1069,27 +1139,29 @@ READ_LINE_DEVICE_HANDLER( pia6821_ca2_r )
WRITE_LINE_DEVICE_HANDLER( pia6821_ca2_w )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->ca2_w(state);
+}
- LOG(("PIA #%s: set input CA2 = %d\n", device->tag(), state));
+void pia6821_device::ca2_w(UINT8 state)
+{
+ LOG(("PIA #%s: set input CA2 = %d\n", tag(), state));
/* if input mode and the new state has caused a transition */
- if (C2_INPUT(p->ctl_a) &&
- (p->in_ca2 != state) &&
- ((state && C2_LOW_TO_HIGH(p->ctl_a)) || (!state && C2_HIGH_TO_LOW(p->ctl_a))))
+ if(C2_INPUT(m_ctl_a) && (m_in_ca2 != state) && ((state && C2_LOW_TO_HIGH(m_ctl_a)) || (!state && C2_HIGH_TO_LOW(m_ctl_a))))
{
- LOG(("PIA #%s: CA2 triggering\n", device->tag()));
+ LOG(("PIA #%s: CA2 triggering\n", tag()));
/* mark the IRQ */
- p->irq_a2 = TRUE;
+ m_irq_a2 = TRUE;
/* update externals */
- update_interrupts(device);
+ update_interrupts();
}
/* set the new value for CA2 */
- p->in_ca2 = state;
- p->in_ca2_pushed = TRUE;
+ m_in_ca2 = state;
+ m_in_ca2_pushed = TRUE;
}
@@ -1099,11 +1171,15 @@ WRITE_LINE_DEVICE_HANDLER( pia6821_ca2_w )
int pia6821_get_output_ca2(running_device *device)
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->get_output_ca2();
+}
- p->out_ca2_needs_pulled = FALSE;
+int pia6821_device::get_output_ca2()
+{
+ m_out_ca2_needs_pulled = FALSE;
- return p->out_ca2;
+ return m_out_ca2;
}
@@ -1115,14 +1191,17 @@ int pia6821_get_output_ca2(running_device *device)
int pia6821_get_output_ca2_z(running_device *device)
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->get_output_ca2_z();
+}
- p->out_ca2_needs_pulled = FALSE;
+int pia6821_device::get_output_ca2_z()
+{
+ m_out_ca2_needs_pulled = FALSE;
// If it's an output, output the bit, if it's an input, it's
// pulled up
- return p->out_ca2 |
- C2_INPUT(p->ctl_a);
+ return m_out_ca2 | C2_INPUT(m_ctl_a);
}
@@ -1132,9 +1211,13 @@ int pia6821_get_output_ca2_z(running_device *device)
READ8_DEVICE_HANDLER( pia6821_portb_r )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->portb_r();
+}
- return p->in_b;
+UINT8 pia6821_device::portb_r()
+{
+ return m_in_b;
}
@@ -1144,14 +1227,18 @@ READ8_DEVICE_HANDLER( pia6821_portb_r )
WRITE8_DEVICE_HANDLER( pia6821_portb_w )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->portb_w(data);
+}
- assert_always(p->in_b_func.read == NULL, "pia_set_input_b() called when in_b_func implemented");
+void pia6821_device::portb_w(UINT8 data)
+{
+ assert_always(m_in_b_func.read == NULL, "pia_set_input_b() called when in_b_func implemented");
- LOG(("PIA #%s: set input port B = %02X\n", device->tag(), data));
+ LOG(("PIA #%s: set input port B = %02X\n", tag(), data));
- p->in_b = data;
- p->in_b_pushed = TRUE;
+ m_in_b = data;
+ m_in_b_pushed = TRUE;
}
@@ -1161,11 +1248,15 @@ WRITE8_DEVICE_HANDLER( pia6821_portb_w )
UINT8 pia6821_get_output_b(running_device *device)
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->get_output_b();
+}
- p->out_b_needs_pulled = FALSE;
+UINT8 pia6821_device::get_output_b()
+{
+ m_out_b_needs_pulled = FALSE;
- return get_out_b_value(device);
+ return get_out_b_value();
}
@@ -1175,9 +1266,13 @@ UINT8 pia6821_get_output_b(running_device *device)
READ_LINE_DEVICE_HANDLER( pia6821_cb1_r )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->cb1_r();
+}
- return p->in_cb1;
+UINT8 pia6821_device::cb1_r()
+{
+ return m_in_cb1;
}
@@ -1187,21 +1282,24 @@ READ_LINE_DEVICE_HANDLER( pia6821_cb1_r )
WRITE_LINE_DEVICE_HANDLER( pia6821_cb1_w )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->cb1_w(state);
+}
- LOG(("PIA #%s: set input CB1 = %d\n", device->tag(), state));
+void pia6821_device::cb1_w(UINT8 state)
+{
+ LOG(("PIA #%s: set input CB1 = %d\n", tag(), state));
/* the new state has caused a transition */
- if ((p->in_cb1 != state) &&
- ((state && C1_LOW_TO_HIGH(p->ctl_b)) || (!state && C1_HIGH_TO_LOW(p->ctl_b))))
+ if((m_in_cb1 != state) && ((state && C1_LOW_TO_HIGH(m_ctl_b)) || (!state && C1_HIGH_TO_LOW(m_ctl_b))))
{
- LOG(("PIA #%s: CB1 triggering\n", device->tag()));
+ LOG(("PIA #%s: CB1 triggering\n", tag()));
/* mark the IRQ */
- p->irq_b1 = 1;
+ m_irq_b1 = 1;
/* update externals */
- update_interrupts(device);
+ update_interrupts();
/* If CB2 is configured as a write-strobe output which is reset by a CB1
transition, this reset will only happen when a read from port B implicitly
@@ -1210,8 +1308,8 @@ WRITE_LINE_DEVICE_HANDLER( pia6821_cb1_w )
}
/* set the new value for CB1 */
- p->in_cb1 = state;
- p->in_cb1_pushed = TRUE;
+ m_in_cb1 = state;
+ m_in_cb1_pushed = TRUE;
}
@@ -1221,9 +1319,13 @@ WRITE_LINE_DEVICE_HANDLER( pia6821_cb1_w )
READ_LINE_DEVICE_HANDLER( pia6821_cb2_r )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->cb2_r();
+}
- return p->in_cb2;
+UINT8 pia6821_device::cb2_r()
+{
+ return m_in_cb2;
}
@@ -1233,27 +1335,31 @@ READ_LINE_DEVICE_HANDLER( pia6821_cb2_r )
WRITE_LINE_DEVICE_HANDLER( pia6821_cb2_w )
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ dev->cb2_w(state);
+}
- LOG(("PIA #%s: set input CB2 = %d\n", device->tag(), state));
+void pia6821_device::cb2_w(UINT8 state)
+{
+ LOG(("PIA #%s: set input CB2 = %d\n", tag(), state));
/* if input mode and the new state has caused a transition */
- if (C2_INPUT(p->ctl_b) &&
- (p->in_cb2 != state) &&
- ((state && C2_LOW_TO_HIGH(p->ctl_b)) || (!state && C2_HIGH_TO_LOW(p->ctl_b))))
+ if (C2_INPUT(m_ctl_b) &&
+ (m_in_cb2 != state) &&
+ ((state && C2_LOW_TO_HIGH(m_ctl_b)) || (!state && C2_HIGH_TO_LOW(m_ctl_b))))
{
- LOG(("PIA #%s: CB2 triggering\n", device->tag()));
+ LOG(("PIA #%s: CB2 triggering\n", tag()));
/* mark the IRQ */
- p->irq_b2 = 1;
+ m_irq_b2 = 1;
/* update externals */
- update_interrupts(device);
+ update_interrupts();
}
/* set the new value for CA2 */
- p->in_cb2 = state;
- p->in_cb2_pushed = TRUE;
+ m_in_cb2 = state;
+ m_in_cb2_pushed = TRUE;
}
@@ -1263,11 +1369,15 @@ WRITE_LINE_DEVICE_HANDLER( pia6821_cb2_w )
int pia6821_get_output_cb2(running_device *device)
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->get_output_cb2();
+}
- p->out_cb2_needs_pulled = FALSE;
+int pia6821_device::get_output_cb2()
+{
+ m_out_cb2_needs_pulled = FALSE;
- return p->out_cb2;
+ return m_out_cb2;
}
@@ -1277,9 +1387,13 @@ int pia6821_get_output_cb2(running_device *device)
int pia6821_get_output_cb2_z(running_device *device)
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->get_output_cb2_z();
+}
- return !C2_OUTPUT(p->ctl_b);
+int pia6821_device::get_output_cb2_z()
+{
+ return !C2_OUTPUT(m_ctl_b);
}
@@ -1289,9 +1403,13 @@ int pia6821_get_output_cb2_z(running_device *device)
int pia6821_get_irq_a(running_device *device)
{
- pia6821_state *p = get_token(device);
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->get_irq_a();
+}
- return p->irq_a_state;
+int pia6821_device::get_irq_a()
+{
+ return m_irq_a_state;
}
@@ -1301,28 +1419,13 @@ int pia6821_get_irq_a(running_device *device)
int pia6821_get_irq_b(running_device *device)
{
- pia6821_state *p = get_token(device);
-
- return p->irq_b_state;
+ pia6821_device *dev = reinterpret_cast<pia6821_device *>(device);
+ return dev->get_irq_b();
}
+int pia6821_device::get_irq_b()
+{
+ return m_irq_b_state;
+}
-/*-------------------------------------------------
- device definition
--------------------------------------------------*/
-
-static const char DEVTEMPLATE_SOURCE[] = __FILE__;
-
-#define DEVTEMPLATE_ID(p,s) p##pia6821##s
-#define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET
-#define DEVTEMPLATE_NAME "6821 PIA"
-#define DEVTEMPLATE_FAMILY "6821 PIA"
-#include "devtempl.h"
-
-#define DEVTEMPLATE_DERIVED_ID(p,s) p##pia6822##s
-#define DEVTEMPLATE_DERIVED_FEATURES 0
-#define DEVTEMPLATE_DERIVED_NAME "6822 PIA"
-#include "devtempl.h"
-
-DEFINE_LEGACY_DEVICE(PIA6821, pia6821);
-DEFINE_LEGACY_DEVICE(PIA6822, pia6822);
+const device_type PIA6821 = pia6821_device_config::static_alloc_device_config;