summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2019-12-02 12:01:06 -0500
committer AJR <ajrhacker@users.noreply.github.com>2019-12-02 12:01:06 -0500
commit39b1fcb6ed1c17f9ef549f0b39eff625f2b4e241 (patch)
treeaba486619f87d08138ae4496856c045a5a33f499 /src/devices
parent9ab60d550a340822bd109e5e23b845b67cb8ab80 (diff)
dp8344: Emulate timer (nw)
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/cpu/bcp/dp8344.cpp38
-rw-r--r--src/devices/cpu/bcp/dp8344.h6
2 files changed, 32 insertions, 12 deletions
diff --git a/src/devices/cpu/bcp/dp8344.cpp b/src/devices/cpu/bcp/dp8344.cpp
index 2006a1ad711..7572f3dd90f 100644
--- a/src/devices/cpu/bcp/dp8344.cpp
+++ b/src/devices/cpu/bcp/dp8344.cpp
@@ -95,6 +95,8 @@ dp8344_device::dp8344_device(const machine_config &mconfig, device_type type, co
, m_gp_alt{0, 0, 0, 0}
, m_ir{0, 0, 0, 0}
, m_tr(0)
+ , m_tclk(0)
+ , m_tcount(0)
, m_as{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
, m_ds{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
, m_asp(0)
@@ -214,6 +216,7 @@ void dp8344_device::device_start()
for (int i = 8; i < 16; i++)
state_add(BCP_GP8 + i - 8, string_format("GP%d", i).c_str(), m_gp_main[i]);
state_add(BCP_TR, "TR", m_tr);
+ state_add(BCP_COUNT, "COUNT", m_tcount);
state_add(BCP_ASP, "ASP", m_asp).mask(0xf);
state_add(BCP_DSP, "DSP", m_dsp).mask(0xf);
@@ -237,6 +240,8 @@ void dp8344_device::device_start()
save_item(NAME(m_gp_alt));
save_item(NAME(m_ir));
save_item(NAME(m_tr));
+ save_item(NAME(m_tclk));
+ save_item(NAME(m_tcount));
save_item(NAME(m_asp));
save_item(NAME(m_dsp));
save_item(NAME(m_as)); // 12-word Address Stack
@@ -483,7 +488,7 @@ void dp8344_device::set_auxiliary_control(u8 data)
else if (BIT(data, 7) && !BIT(m_acr, 7))
{
unsigned prescale = (BIT(m_dcr, 7) ? 2 : 1) * (BIT(data, 5) ? 2 : 16);
- logerror("%04X: Timer Start (TO Period = %.2f kHz)\n",
+ logerror("%04X: Timer Start (TO Period = %.3f kHz)\n",
m_ppc,
clocks_to_attotime(prescale * (m_tr == 0 ? 65536 : m_tr)).as_khz());
}
@@ -491,6 +496,7 @@ void dp8344_device::set_auxiliary_control(u8 data)
if (BIT(data, 6))
{
logerror("%04X: Timer Load (TR = %d)\n", m_ppc, m_tr);
+ m_tcount = m_tr;
// TODO: only cleared when load pulse finishes
data &= 0xbf;
@@ -510,12 +516,12 @@ void dp8344_device::set_device_control(u8 data)
if ((data & 0xe0) != (m_dcr & 0xe0))
{
if ((data & 0x60) == 0x60)
- logerror("%04X: CPU Clock = OCLK%s (%.3f MHz); Transceiver Clock = X-TCLK\n",
+ logerror("%04X: CPU Clock = OCLK%s (%.4f MHz); Transceiver Clock = X-TCLK\n",
m_ppc,
BIT(data, 7) ? "/2" : "",
clocks_to_attotime(BIT(data, 7) ? 2 : 1).as_mhz());
else
- logerror("%04X: CPU Clock = OCLK%s (%.3f MHz); Transceiver Clock = OCLK%s (%.3f MHz)\n",
+ logerror("%04X: CPU Clock = OCLK%s (%.4f MHz); Transceiver Clock = OCLK%s (%.4f MHz)\n",
m_ppc,
BIT(data, 7) ? "/2" : "",
clocks_to_attotime(BIT(data, 7) ? 2 : 1).as_mhz(),
@@ -701,14 +707,19 @@ void dp8344_device::state_string_export(const device_state_entry &entry, std::st
//**************************************************************************
//-------------------------------------------------
-// get_timer_count - return current count status
-// of the timer
+// timer_count - count down on timer
//-------------------------------------------------
-u16 dp8344_device::get_timer_count()
+void dp8344_device::timer_count()
{
- // TODO
- return 0;
+ // Count down to zero
+ if (--m_tcount == 0)
+ {
+ set_timer_interrupt(true);
+
+ // Count automatically reloads
+ m_tcount = m_tr;
+ }
}
@@ -1220,10 +1231,10 @@ u8 dp8344_device::read_register(unsigned reg)
return m_gp_main[15];
case 28: // TRL count status
- return get_timer_count() & 0x00ff;
+ return m_tcount & 0x00ff;
case 29: // TRH count status
- return get_timer_count() >> 8;
+ return (m_tcount & 0xff00) >> 8;
case 30: // Internal Stack Pointer
return (m_asp << 4) | m_dsp;
@@ -1998,6 +2009,13 @@ void dp8344_device::execute_run()
break;
}
+ // If the timer is started, run it
+ if (BIT(m_acr, 7))
+ {
+ if ((m_tclk++ & (BIT(m_acr, 5) ? 1 : 15)) == 0)
+ timer_count();
+ }
+
m_icount--;
}
}
diff --git a/src/devices/cpu/bcp/dp8344.h b/src/devices/cpu/bcp/dp8344.h
index 4a62583279b..b6561c13519 100644
--- a/src/devices/cpu/bcp/dp8344.h
+++ b/src/devices/cpu/bcp/dp8344.h
@@ -41,7 +41,7 @@ public:
BCP_IW, BCP_IX, BCP_IY, BCP_IZ,
BCP_IWLO, BCP_IXLO, BCP_IYLO, BCP_IZLO,
BCP_IWHI, BCP_IXHI, BCP_IYHI, BCP_IZHI,
- BCP_TR,
+ BCP_TR, BCP_COUNT,
BCP_ASP, BCP_DSP
};
@@ -112,7 +112,7 @@ private:
static u8 rotate_right(u8 data, u8 b);
u8 add_nzcv(u8 s1, u8 s2, bool carry_in);
u8 sub_nzcv(u8 s1, u8 s2, bool carry_in);
- u16 get_timer_count();
+ void timer_count();
void address_stack_push();
void address_stack_pop(u8 g, bool rf);
void set_stack_pointer(u8 data);
@@ -187,6 +187,8 @@ private:
// timer registers
u16 m_tr;
+ u8 m_tclk;
+ u16 m_tcount;
// internal stacks
u32 m_as[12];