summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author R. Belmont <rb6502@users.noreply.github.com>2017-03-24 16:06:08 -0400
committer GitHub <noreply@github.com>2017-03-24 16:06:08 -0400
commit2da11384b0267b1cc9e0ba5e128fc2e652f701d9 (patch)
tree0b5edd9c9fbe9732619036e5adbc647ba5900469 /src
parent2f895beea14d5ac0aff5261abc43daf624a77d89 (diff)
parentcff6d3299b3b18c8ea66895853cad5ddb2504e5e (diff)
Merge pull request #2173 from npwoods/pia_cplusplus
Incremental C++-ification of 6821pia.cpp
Diffstat (limited to 'src')
-rw-r--r--src/devices/machine/6821pia.cpp105
-rw-r--r--src/devices/machine/6821pia.h23
2 files changed, 74 insertions, 54 deletions
diff --git a/src/devices/machine/6821pia.cpp b/src/devices/machine/6821pia.cpp
index 37edfc6449b..1681c58da2d 100644
--- a/src/devices/machine/6821pia.cpp
+++ b/src/devices/machine/6821pia.cpp
@@ -34,21 +34,6 @@
#define PIA_IRQ1 (0x80)
#define PIA_IRQ2 (0x40)
-#define IRQ1_ENABLED(c) ( (((c) >> 0) & 0x01))
-#define C1_LOW_TO_HIGH(c) ( (((c) >> 1) & 0x01))
-#define C1_HIGH_TO_LOW(c) (!(((c) >> 1) & 0x01))
-#define OUTPUT_SELECTED(c) ( (((c) >> 2) & 0x01))
-#define IRQ2_ENABLED(c) ( (((c) >> 3) & 0x01))
-#define STROBE_E_RESET(c) ( (((c) >> 3) & 0x01))
-#define STROBE_C1_RESET(c) (!(((c) >> 3) & 0x01))
-#define C2_SET(c) ( (((c) >> 3) & 0x01))
-#define C2_LOW_TO_HIGH(c) ( (((c) >> 4) & 0x01))
-#define C2_HIGH_TO_LOW(c) (!(((c) >> 4) & 0x01))
-#define C2_SET_MODE(c) ( (((c) >> 4) & 0x01))
-#define C2_STROBE_MODE(c) (!(((c) >> 4) & 0x01))
-#define C2_OUTPUT(c) ( (((c) >> 5) & 0x01))
-#define C2_INPUT(c) (!(((c) >> 5) & 0x01))
-
//**************************************************************************
// LIVE DEVICE
@@ -211,7 +196,7 @@ void pia6821_device::device_reset()
void pia6821_device::update_interrupts()
{
// start with IRQ A
- int new_state = (m_irq_a1 && IRQ1_ENABLED(m_ctl_a)) || (m_irq_a2 && IRQ2_ENABLED(m_ctl_a));
+ int new_state = (m_irq_a1 && irq1_enabled(m_ctl_a)) || (m_irq_a2 && irq2_enabled(m_ctl_a));
if (new_state != m_irq_a_state)
{
@@ -220,7 +205,7 @@ void pia6821_device::update_interrupts()
}
// then do IRQ B
- new_state = (m_irq_b1 && IRQ1_ENABLED(m_ctl_b)) || (m_irq_b2 && IRQ2_ENABLED(m_ctl_b));
+ new_state = (m_irq_b1 && irq1_enabled(m_ctl_b)) || (m_irq_b2 && irq2_enabled(m_ctl_b));
if (new_state != m_irq_b_state)
{
@@ -430,13 +415,13 @@ uint8_t pia6821_device::port_a_r()
update_interrupts();
// CA2 is configured as output and in read strobe mode
- if(C2_OUTPUT(m_ctl_a) && C2_STROBE_MODE(m_ctl_a))
+ if(c2_output(m_ctl_a) && c2_strobe_mode(m_ctl_a))
{
// this will cause a transition low
set_out_ca2(false);
// if the CA2 strobe is cleared by the E, reset it right away
- if(STROBE_E_RESET(m_ctl_a))
+ if(strobe_e_reset(m_ctl_a))
{
set_out_ca2(true);
}
@@ -474,7 +459,7 @@ uint8_t pia6821_device::port_b_r()
// 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(m_irq_b1 && C2_STROBE_MODE(m_ctl_b) && STROBE_C1_RESET(m_ctl_b))
+ if(m_irq_b1 && c2_strobe_mode(m_ctl_b) && strobe_c1_reset(m_ctl_b))
{
set_out_cb2(true);
}
@@ -527,7 +512,7 @@ uint8_t pia6821_device::control_a_r()
{
ca2_w(m_in_ca2_handler());
}
- else if ( !m_logged_ca2_not_connected && C2_INPUT(m_ctl_a) && !m_in_ca2_pushed)
+ 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", tag());
m_logged_ca2_not_connected = true;
@@ -542,7 +527,7 @@ uint8_t pia6821_device::control_a_r()
ret |= PIA_IRQ1;
}
- if(m_irq_a2 && C2_INPUT(m_ctl_a))
+ if(m_irq_a2 && c2_input(m_ctl_a))
{
ret |= PIA_IRQ2;
}
@@ -572,7 +557,7 @@ uint8_t pia6821_device::control_b_r()
m_logged_cb1_not_connected = true;
}
- if(!m_logged_cb2_not_connected && C2_INPUT(m_ctl_b) && !m_in_cb2_pushed)
+ if(!m_logged_cb2_not_connected && c2_input(m_ctl_b) && !m_in_cb2_pushed)
{
logerror("PIA #%s: Error! Three-state pin is undefined\n", tag());
m_logged_cb2_not_connected = true;
@@ -587,7 +572,7 @@ uint8_t pia6821_device::control_b_r()
ret |= PIA_IRQ1;
}
- if(m_irq_b2 && C2_INPUT(m_ctl_b))
+ if(m_irq_b2 && c2_input(m_ctl_b))
{
ret |= PIA_IRQ2;
}
@@ -610,7 +595,7 @@ uint8_t pia6821_device::reg_r(uint8_t offset)
{
default: // impossible
case 0x00:
- if (OUTPUT_SELECTED(m_ctl_a))
+ if (output_selected(m_ctl_a))
{
ret = port_a_r();
}
@@ -625,7 +610,7 @@ uint8_t pia6821_device::reg_r(uint8_t offset)
break;
case 0x02:
- if (OUTPUT_SELECTED(m_ctl_b))
+ if (output_selected(m_ctl_b))
{
ret = port_b_r();
}
@@ -753,13 +738,13 @@ void pia6821_device::port_b_w(uint8_t data)
send_to_out_b_func("port B write");
// CB2 in write strobe mode
- if(C2_STROBE_MODE(m_ctl_b))
+ if(c2_strobe_mode(m_ctl_b))
{
// this will cause a transition low
set_out_cb2(false);
// if the CB2 strobe is cleared by the E, reset it right away
- if(STROBE_E_RESET(m_ctl_b))
+ if(strobe_e_reset(m_ctl_b))
{
set_out_cb2(true);
}
@@ -811,14 +796,14 @@ void pia6821_device::control_a_w(uint8_t data)
m_ctl_a = data;
// CA2 is configured as output
- if(C2_OUTPUT(m_ctl_a))
+ if(c2_output(m_ctl_a))
{
- int temp;
+ bool temp;
- if(C2_SET_MODE(m_ctl_a))
+ if(c2_set_mode(m_ctl_a))
{
// set/reset mode - bit value determines the new output
- temp = C2_SET(m_ctl_a);
+ temp = c2_set(m_ctl_a);
}
else
{
@@ -840,7 +825,7 @@ void pia6821_device::control_a_w(uint8_t data)
void pia6821_device::control_b_w(uint8_t data)
{
- int temp;
+ bool temp;
// bit 7 and 6 are read only
data &= 0x3f;
@@ -850,10 +835,10 @@ void pia6821_device::control_b_w(uint8_t data)
// update the control register
m_ctl_b = data;
- if (C2_SET_MODE(m_ctl_b))
+ if (c2_set_mode(m_ctl_b))
{
// set/reset mode - bit value determines the new output
- temp = C2_SET(m_ctl_b);
+ temp = c2_set(m_ctl_b);
}
else
{
@@ -878,7 +863,7 @@ void pia6821_device::reg_w(uint8_t offset, uint8_t data)
{
default: // impossible
case 0x00:
- if (OUTPUT_SELECTED(m_ctl_a))
+ if (output_selected(m_ctl_a))
{
port_a_w(data);
}
@@ -893,7 +878,7 @@ void pia6821_device::reg_w(uint8_t offset, uint8_t data)
break;
case 0x02:
- if(OUTPUT_SELECTED(m_ctl_b))
+ if(output_selected(m_ctl_b))
{
port_b_w(data);
}
@@ -957,7 +942,7 @@ WRITE_LINE_MEMBER( pia6821_device::ca1_w )
LOGCA1("PIA #%s: set input CA1 = %d\n", tag(), state);
// the new state has caused a transition
- if((m_in_ca1 != state) && ((state && C1_LOW_TO_HIGH(m_ctl_a)) || (!state && C1_HIGH_TO_LOW(m_ctl_a))))
+ if((m_in_ca1 != state) && ((state && c1_low_to_high(m_ctl_a)) || (!state && c1_high_to_low(m_ctl_a))))
{
LOGCA1("PIA #%s: CA1 triggering\n", tag());
@@ -968,7 +953,7 @@ WRITE_LINE_MEMBER( pia6821_device::ca1_w )
update_interrupts();
// CA2 is configured as output and in read strobe mode and cleared by a CA1 transition
- if(C2_OUTPUT(m_ctl_a) && C2_STROBE_MODE(m_ctl_a) && STROBE_C1_RESET(m_ctl_a))
+ if(c2_output(m_ctl_a) && c2_strobe_mode(m_ctl_a) && strobe_c1_reset(m_ctl_a))
{
set_out_ca2(true);
}
@@ -989,7 +974,7 @@ WRITE_LINE_MEMBER( pia6821_device::ca2_w )
LOG("PIA #%s: set input CA2 = %d\n", tag(), state);
// if input mode and the new state has caused a transition
- 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))))
+ 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", tag());
@@ -1010,7 +995,7 @@ WRITE_LINE_MEMBER( pia6821_device::ca2_w )
// ca2_output
//-------------------------------------------------
-int pia6821_device::ca2_output()
+bool pia6821_device::ca2_output()
{
m_out_ca2_needs_pulled = false;
@@ -1023,13 +1008,13 @@ int pia6821_device::ca2_output()
// takes account of internal pullup resistor
//-------------------------------------------------
-int pia6821_device::ca2_output_z()
+bool pia6821_device::ca2_output_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 m_out_ca2 | C2_INPUT(m_ctl_a);
+ return m_out_ca2 | c2_input(m_ctl_a);
}
@@ -1069,7 +1054,7 @@ WRITE_LINE_MEMBER( pia6821_device::cb1_w )
LOG("PIA #%s: set input CB1 = %d\n", tag(), state);
// the new state has caused a transition
- if((m_in_cb1 != state) && ((state && C1_LOW_TO_HIGH(m_ctl_b)) || (!state && C1_HIGH_TO_LOW(m_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", tag());
@@ -1100,9 +1085,9 @@ WRITE_LINE_MEMBER( pia6821_device::cb2_w )
LOG("PIA #%s: set input CB2 = %d\n", tag(), state);
// if input mode and the new state has caused a transition
- if (C2_INPUT(m_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))))
+ ((state && c2_low_to_high(m_ctl_b)) || (!state && c2_high_to_low(m_ctl_b))))
{
LOG("PIA #%s: CB2 triggering\n", tag());
@@ -1123,10 +1108,10 @@ WRITE_LINE_MEMBER( pia6821_device::cb2_w )
// output_cb2
//-------------------------------------------------
-int pia6821_device::cb2_output()
+bool pia6821_device::cb2_output()
{
m_out_cb2_needs_pulled = false;
-
+
return m_out_cb2;
}
@@ -1135,7 +1120,27 @@ int pia6821_device::cb2_output()
// cb2_output_z
//-------------------------------------------------
-int pia6821_device::cb2_output_z()
+bool pia6821_device::cb2_output_z()
{
- return !C2_OUTPUT(m_ctl_b);
+ return !c2_output(m_ctl_b);
}
+
+
+//-------------------------------------------------
+// control byte wrappers
+//-------------------------------------------------
+
+bool pia6821_device::irq1_enabled(uint8_t c) { return (c >> 0) & 0x01 ? true : false; }
+bool pia6821_device::c1_low_to_high(uint8_t c) { return (c >> 1) & 0x01 ? true : false; }
+bool pia6821_device::c1_high_to_low(uint8_t c) { return !(c >> 1) & 0x01 ? true : false; }
+bool pia6821_device::output_selected(uint8_t c) { return (c >> 2) & 0x01 ? true : false; }
+bool pia6821_device::irq2_enabled(uint8_t c) { return (c >> 3) & 0x01 ? true : false; }
+bool pia6821_device::strobe_e_reset(uint8_t c) { return (c >> 3) & 0x01 ? true : false; }
+bool pia6821_device::strobe_c1_reset(uint8_t c) { return !(c >> 3) & 0x01 ? true : false; }
+bool pia6821_device::c2_set(uint8_t c) { return (c >> 3) & 0x01 ? true : false; }
+bool pia6821_device::c2_low_to_high(uint8_t c) { return (c >> 4) & 0x01 ? true : false; }
+bool pia6821_device::c2_high_to_low(uint8_t c) { return !(c >> 4) & 0x01 ? true : false; }
+bool pia6821_device::c2_set_mode(uint8_t c) { return (c >> 4) & 0x01 ? true : false; }
+bool pia6821_device::c2_strobe_mode(uint8_t c) { return !(c >> 4) & 0x01 ? true : false; }
+bool pia6821_device::c2_output(uint8_t c) { return (c >> 5) & 0x01 ? true : false; }
+bool pia6821_device::c2_input(uint8_t c) { return !(c >> 5) & 0x01 ? true : false; }
diff --git a/src/devices/machine/6821pia.h b/src/devices/machine/6821pia.h
index 156d1d65b0c..8c017b786fb 100644
--- a/src/devices/machine/6821pia.h
+++ b/src/devices/machine/6821pia.h
@@ -112,8 +112,8 @@ public:
DECLARE_WRITE_LINE_MEMBER( ca1_w );
DECLARE_WRITE_LINE_MEMBER( ca2_w );
- int ca2_output();
- int ca2_output_z();
+ bool ca2_output();
+ bool ca2_output_z();
DECLARE_WRITE8_MEMBER( portb_w ) { portb_w(data); }
void portb_w(uint8_t data);
@@ -122,8 +122,8 @@ public:
DECLARE_WRITE_LINE_MEMBER( cb1_w );
DECLARE_WRITE_LINE_MEMBER( cb2_w );
- int cb2_output();
- int cb2_output_z();
+ bool cb2_output();
+ bool cb2_output_z();
int irq_a_state() const { return m_irq_a_state; }
int irq_b_state() const { return m_irq_b_state; }
@@ -168,6 +168,21 @@ private:
void control_a_w(uint8_t data);
void control_b_w(uint8_t data);
+ static bool irq1_enabled(uint8_t c);
+ static bool c1_low_to_high(uint8_t c);
+ static bool c1_high_to_low(uint8_t c);
+ static bool output_selected(uint8_t c);
+ static bool irq2_enabled(uint8_t c);
+ static bool strobe_e_reset(uint8_t c);
+ static bool strobe_c1_reset(uint8_t c);
+ static bool c2_set(uint8_t c);
+ static bool c2_low_to_high(uint8_t c);
+ static bool c2_high_to_low(uint8_t c);
+ static bool c2_set_mode(uint8_t c);
+ static bool c2_strobe_mode(uint8_t c);
+ static bool c2_output(uint8_t c);
+ static bool c2_input(uint8_t c);
+
devcb_read8 m_in_a_handler;
devcb_read8 m_in_b_handler;
devcb_read_line m_in_ca1_handler;