summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2020-08-15 12:58:01 -0400
committer AJR <ajrhacker@users.noreply.github.com>2020-08-15 12:58:01 -0400
commit3d0632bab74f6bd883e9aeefc57ab086c3b6c8d4 (patch)
tree170d05c90a3f9ce494b08f634aa90d553f60d801
parent120ae6a73bfdad5dbe9b700c95caa929ac5c12fd (diff)
upd7810: Fix semantics of SKIT NMI and SKNIT NMI; simplify analog input code
-rw-r--r--src/devices/cpu/upd7810/upd7810.cpp88
-rw-r--r--src/devices/cpu/upd7810/upd7810.h32
-rw-r--r--src/devices/cpu/upd7810/upd7810_macros.h5
-rw-r--r--src/devices/cpu/upd7810/upd7810_opcodes.cpp26
4 files changed, 47 insertions, 104 deletions
diff --git a/src/devices/cpu/upd7810/upd7810.cpp b/src/devices/cpu/upd7810/upd7810.cpp
index 49d3bd5e437..1e212dfe24e 100644
--- a/src/devices/cpu/upd7810/upd7810.cpp
+++ b/src/devices/cpu/upd7810/upd7810.cpp
@@ -406,14 +406,7 @@ upd7810_device::upd7810_device(const machine_config &mconfig, device_type type,
, m_co1_func(*this)
, m_txd_func(*this)
, m_rxd_func(*this)
- , m_an0_func(*this)
- , m_an1_func(*this)
- , m_an2_func(*this)
- , m_an3_func(*this)
- , m_an4_func(*this)
- , m_an5_func(*this)
- , m_an6_func(*this)
- , m_an7_func(*this)
+ , m_an_func(*this)
, m_pa_in_cb(*this)
, m_pb_in_cb(*this)
, m_pc_in_cb(*this)
@@ -749,16 +742,16 @@ void upd7810_device::upd7810_take_irq()
int irqline = 0;
/* global interrupt disable? */
- if (0 == IFF && !(IRR & INTNMI))
+ if (0 == IFF && !(IRR & INTFNMI))
return;
/* check the interrupts in priority sequence */
- if (IRR & INTNMI)
+ if (IRR & INTFNMI)
{
/* Nonmaskable interrupt */
irqline = INPUT_LINE_NMI;
vector = 0x0004;
- IRR &= ~INTNMI;
+ IRR &= ~INTFNMI;
}
else
if ((IRR & INTFT0) && 0 == (MKL & 0x02))
@@ -1492,30 +1485,13 @@ void upd7810_device::handle_timers(int cycles)
/* select mode */
if (m_shdone == 0)
{
- switch (m_adin)
- {
- case 0: m_tmpcr = m_an0_func(); break;
- case 1: m_tmpcr = m_an1_func(); break;
- case 2: m_tmpcr = m_an2_func(); break;
- case 3: m_tmpcr = m_an3_func(); break;
- case 4: m_tmpcr = m_an4_func(); break;
- case 5: m_tmpcr = m_an5_func(); break;
- case 6: m_tmpcr = m_an6_func(); break;
- case 7: m_tmpcr = m_an7_func(); break;
- }
+ m_tmpcr = m_an_func[m_adin]();
m_shdone = 1;
}
if (m_adcnt > m_adtot)
{
m_adcnt -= m_adtot;
- switch (m_adout)
- {
- // volfied code checks bit 0x80, old code set bit 0x01, TODO: verify which bits are set on real hw
- case 0: CR0 = m_tmpcr; break;
- case 1: CR1 = m_tmpcr; break;
- case 2: CR2 = m_tmpcr; break;
- case 3: CR3 = m_tmpcr; break;
- }
+ CR[m_adout] = m_tmpcr;
m_adout = (m_adout + 1) & 0x03;
if (m_adout == 0)
IRR |= INTFAD;
@@ -1527,29 +1503,13 @@ void upd7810_device::handle_timers(int cycles)
/* scan mode */
if (m_shdone == 0)
{
- switch (m_adin | m_adrange)
- {
- case 0: m_tmpcr = m_an0_func(); break;
- case 1: m_tmpcr = m_an1_func(); break;
- case 2: m_tmpcr = m_an2_func(); break;
- case 3: m_tmpcr = m_an3_func(); break;
- case 4: m_tmpcr = m_an4_func(); break;
- case 5: m_tmpcr = m_an5_func(); break;
- case 6: m_tmpcr = m_an6_func(); break;
- case 7: m_tmpcr = m_an7_func(); break;
- }
+ m_tmpcr = m_an_func[m_adin | m_adrange]();
m_shdone = 1;
}
if (m_adcnt > m_adtot)
{
m_adcnt -= m_adtot;
- switch (m_adout)
- {
- case 0: CR0 = m_tmpcr; break;
- case 1: CR1 = m_tmpcr; break;
- case 2: CR2 = m_tmpcr; break;
- case 3: CR3 = m_tmpcr; break;
- }
+ CR[m_adout] = m_tmpcr;
m_adin = (m_adin + 1) & 0x03; // should loop from 0 to 3 for AN0-AN3 or AN4-AN7
m_adout = (m_adout + 1) & 0x03;
if (m_adout == 0)
@@ -1611,14 +1571,7 @@ void upd7810_device::base_device_start()
m_co1_func.resolve_safe();
m_txd_func.resolve_safe();
m_rxd_func.resolve_safe(1);
- m_an0_func.resolve_safe(0);
- m_an1_func.resolve_safe(0);
- m_an2_func.resolve_safe(0);
- m_an3_func.resolve_safe(0);
- m_an4_func.resolve_safe(0);
- m_an5_func.resolve_safe(0);
- m_an6_func.resolve_safe(0);
- m_an7_func.resolve_safe(0);
+ m_an_func.resolve_all_safe(0);
m_pa_in_cb.resolve();
m_pb_in_cb.resolve();
@@ -1679,10 +1632,7 @@ void upd7810_device::base_device_start()
save_item(NAME(m_pc_out));
save_item(NAME(m_pd_out));
save_item(NAME(m_pf_out));
- save_item(NAME(m_cr0));
- save_item(NAME(m_cr1));
- save_item(NAME(m_cr2));
- save_item(NAME(m_cr3));
+ save_item(NAME(m_cr));
save_item(NAME(m_txb));
save_item(NAME(m_rxb));
save_item(NAME(m_txd));
@@ -1751,10 +1701,10 @@ void upd7810_device::device_start()
state_add( UPD7810_MKL, "MKL", m_mkl).formatstr("%02X");
state_add( UPD7810_MKH, "MKH", m_mkh).formatstr("%02X");
state_add( UPD7810_ZCM, "ZCM", m_zcm).formatstr("%02X");
- state_add( UPD7810_CR0, "CR0", m_cr0).formatstr("%02X");
- state_add( UPD7810_CR1, "CR1", m_cr1).formatstr("%02X");
- state_add( UPD7810_CR2, "CR2", m_cr2).formatstr("%02X");
- state_add( UPD7810_CR3, "CR3", m_cr3).formatstr("%02X");
+ state_add( UPD7810_CR0, "CR0", m_cr[0]).formatstr("%02X");
+ state_add( UPD7810_CR1, "CR1", m_cr[1]).formatstr("%02X");
+ state_add( UPD7810_CR2, "CR2", m_cr[2]).formatstr("%02X");
+ state_add( UPD7810_CR3, "CR3", m_cr[3]).formatstr("%02X");
state_add( UPD7810_RXB, "RXB", m_rxb).formatstr("%02X");
state_add( UPD7810_TXB, "TXB", m_txb).formatstr("%02X");
state_add( UPD7810_TXD, "TXD", m_txd).formatstr("%3u");
@@ -1871,10 +1821,10 @@ void upd7810_device::device_reset()
m_pc_out = 0;
m_pd_out = 0;
m_pf_out = 0;
- m_cr0 = 0;
- m_cr1 = 0;
- m_cr2 = 0;
- m_cr3 = 0;
+ m_cr[0] = 0;
+ m_cr[1] = 0;
+ m_cr[2] = 0;
+ m_cr[3] = 0;
m_txb = 0;
m_rxb = 0;
m_txd = 0;
@@ -2060,7 +2010,7 @@ void upd7810_device::execute_set_input(int irqline, int state)
case INPUT_LINE_NMI:
/* NMI is falling edge sensitive */
if ( m_nmi == CLEAR_LINE && state == ASSERT_LINE )
- IRR |= INTNMI;
+ IRR |= INTFNMI;
m_nmi = state;
break;
diff --git a/src/devices/cpu/upd7810/upd7810.h b/src/devices/cpu/upd7810/upd7810.h
index 84b86bb3e99..ee8d139a275 100644
--- a/src/devices/cpu/upd7810/upd7810.h
+++ b/src/devices/cpu/upd7810/upd7810.h
@@ -49,14 +49,14 @@ public:
auto co1_func() { return m_co1_func.bind(); }
auto txd_func() { return m_txd_func.bind(); }
auto rxd_func() { return m_rxd_func.bind(); }
- auto an0_func() { return m_an0_func.bind(); }
- auto an1_func() { return m_an1_func.bind(); }
- auto an2_func() { return m_an2_func.bind(); }
- auto an3_func() { return m_an3_func.bind(); }
- auto an4_func() { return m_an4_func.bind(); }
- auto an5_func() { return m_an5_func.bind(); }
- auto an6_func() { return m_an6_func.bind(); }
- auto an7_func() { return m_an7_func.bind(); }
+ auto an0_func() { return m_an_func[0].bind(); }
+ auto an1_func() { return m_an_func[1].bind(); }
+ auto an2_func() { return m_an_func[2].bind(); }
+ auto an3_func() { return m_an_func[3].bind(); }
+ auto an4_func() { return m_an_func[4].bind(); }
+ auto an5_func() { return m_an_func[5].bind(); }
+ auto an6_func() { return m_an_func[6].bind(); }
+ auto an7_func() { return m_an_func[7].bind(); }
auto pa_in_cb() { return m_pa_in_cb.bind(); }
auto pb_in_cb() { return m_pb_in_cb.bind(); }
@@ -104,7 +104,7 @@ protected:
// IRR flags
enum
{
- INTNMI = 0x0001,
+ INTFNMI = 0x0001,
INTFT0 = 0x0002,
INTFT1 = 0x0004,
INTF1 = 0x0008,
@@ -169,14 +169,7 @@ protected:
devcb_write_line m_co1_func;
devcb_write_line m_txd_func;
devcb_read_line m_rxd_func;
- devcb_read8 m_an0_func;
- devcb_read8 m_an1_func;
- devcb_read8 m_an2_func;
- devcb_read8 m_an3_func;
- devcb_read8 m_an4_func;
- devcb_read8 m_an5_func;
- devcb_read8 m_an6_func;
- devcb_read8 m_an7_func;
+ devcb_read8::array<8> m_an_func;
devcb_read8 m_pa_in_cb;
devcb_read8 m_pb_in_cb;
@@ -293,10 +286,7 @@ protected:
uint8_t m_pc_pullups;
uint8_t m_pd_pullups;
uint8_t m_pf_pullups;
- uint8_t m_cr0; /* analog digital conversion register 0 */
- uint8_t m_cr1; /* analog digital conversion register 1 */
- uint8_t m_cr2; /* analog digital conversion register 2 */
- uint8_t m_cr3; /* analog digital conversion register 3 */
+ uint8_t m_cr[4]; /* analog digital conversion registers */
uint8_t m_txb; /* transmitter buffer */
uint8_t m_rxb; /* receiver buffer */
uint8_t m_txd; /* port C control line states */
diff --git a/src/devices/cpu/upd7810/upd7810_macros.h b/src/devices/cpu/upd7810/upd7810_macros.h
index 0ae44c63243..1bd092849e4 100644
--- a/src/devices/cpu/upd7810/upd7810_macros.h
+++ b/src/devices/cpu/upd7810/upd7810_macros.h
@@ -79,10 +79,7 @@
#define MKH m_mkh
#define ZCM m_zcm
-#define CR0 m_cr0
-#define CR1 m_cr1
-#define CR2 m_cr2
-#define CR3 m_cr3
+#define CR m_cr
#define RXB m_rxb
#define TXB m_txb
diff --git a/src/devices/cpu/upd7810/upd7810_opcodes.cpp b/src/devices/cpu/upd7810/upd7810_opcodes.cpp
index 3bb2233df21..dd610a40ff1 100644
--- a/src/devices/cpu/upd7810/upd7810_opcodes.cpp
+++ b/src/devices/cpu/upd7810/upd7810_opcodes.cpp
@@ -323,7 +323,10 @@ void upd7810_device::DIV_B()
B = remainder;
}
else
- EA = 0xffff; /* guess */
+ {
+ B = EAL;
+ EA = 0xffff;
+ }
}
/* 48 3f: 0100 1000 0011 1111 */
@@ -337,15 +340,18 @@ void upd7810_device::DIV_C()
C = remainder;
}
else
- EA = 0xffff; /* guess */
+ {
+ C = EAL;
+ EA = 0xffff;
+ }
}
/* 48 40: 0100 1000 0100 0000 */
void upd7810_device::SKIT_NMI()
{
- if (IRR & INTNMI)
+ if (m_nmi == CLEAR_LINE) // 1 pin level
PSW |= SK;
- IRR &= ~INTNMI;
+ // INTFNMI is not tested or changed
}
/* 48 41: 0100 1000 0100 0001 */
@@ -487,9 +493,9 @@ void upd7810_device::SKIT_SB()
/* 48 60: 0100 1000 0110 0000 */
void upd7810_device::SKNIT_NMI()
{
- if (0 == (IRR & INTNMI))
+ if (m_nmi == ASSERT_LINE) // 0 pin level
PSW |= SK;
- IRR &= ~INTNMI;
+ // INTFNMI is not tested or changed
}
/* 48 61: 0100 1000 0110 0001 */
@@ -931,25 +937,25 @@ void upd7810_device::MOV_A_RXB()
/* 4c e0: 0100 1100 1110 0000 */
void upd7810_device::MOV_A_CR0()
{
- A = CR0;
+ A = CR[0];
}
/* 4c e1: 0100 1100 1110 0001 */
void upd7810_device::MOV_A_CR1()
{
- A = CR1;
+ A = CR[1];
}
/* 4c e2: 0100 1100 1110 0010 */
void upd7810_device::MOV_A_CR2()
{
- A = CR2;
+ A = CR[2];
}
/* 4c e3: 0100 1100 1110 0011 */
void upd7810_device::MOV_A_CR3()
{
- A = CR3;
+ A = CR[3];
}
/* prefix 4D */