summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/am9513.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/am9513.cpp')
-rw-r--r--src/devices/machine/am9513.cpp92
1 files changed, 50 insertions, 42 deletions
diff --git a/src/devices/machine/am9513.cpp b/src/devices/machine/am9513.cpp
index 6506510369f..5baf568ca3b 100644
--- a/src/devices/machine/am9513.cpp
+++ b/src/devices/machine/am9513.cpp
@@ -27,13 +27,12 @@
**********************************************************************/
#include "emu.h"
-#include "machine/am9513.h"
+#include "am9513.h"
-#define LOG_GENERAL (1U << 0)
-#define LOG_MODE (1U << 1)
+#define LOG_MODE (1U << 1)
#define LOG_INPUT (1U << 2)
-#define LOG_TC (1U << 3)
-#define VERBOSE (LOG_GENERAL | LOG_MODE)
+#define LOG_TC (1U << 3)
+//#define VERBOSE (LOG_GENERAL | LOG_MODE)
#include "logmacro.h"
@@ -55,10 +54,10 @@ DEFINE_DEVICE_TYPE(AM9513A, am9513a_device, "am9513a", "Am9513A STC")
//-------------------------------------------------
am9513_device::am9513_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, bool is_am9513a)
- : device_t(mconfig, type, tag, owner, clock),
- m_out_cb{{*this}, {*this}, {*this}, {*this}, {*this}},
- m_fout_cb(*this),
- m_is_am9513a(is_am9513a)
+ : device_t(mconfig, type, tag, owner, clock)
+ , m_out_cb(*this)
+ , m_fout_cb(*this)
+ , m_is_am9513a(is_am9513a)
{
}
@@ -79,11 +78,6 @@ am9513a_device::am9513a_device(const machine_config &mconfig, const char *tag, d
void am9513_device::device_start()
{
- // Resolve callbacks
- for (auto &cb : m_out_cb)
- cb.resolve_safe();
- m_fout_cb.resolve();
-
// Power-on reset
m_dpr = 0x1f;
m_mmr = 0;
@@ -114,8 +108,8 @@ void am9513_device::device_start()
// Set up frequency timers
for (int f = 0; f < 5; f++)
{
- m_freq_timer[f] = timer_alloc(TIMER_F1 + f);
- m_freq_timer_selected[f] = (f == 0) ? (m_fout_cb.isnull() ? 0x3e : 0x3f) : 0;
+ m_freq_timer[f] = timer_alloc(FUNC(am9513_device::timer_tick), this);
+ m_freq_timer_selected[f] = (f == 0) ? (m_fout_cb.isunset() ? 0x3e : 0x3f) : 0;
m_freq_timer_cycle[f] = 0;
}
@@ -206,12 +200,12 @@ void am9513_device::init_freq_timer(int f)
attotime freq = clocks_to_attotime(scale);
if (m_freq_timer_cycle[f] == 0)
- m_freq_timer[f]->adjust(freq, 0, freq);
+ m_freq_timer[f]->adjust(freq, f, freq);
else
- m_freq_timer[f]->adjust(freq / 2, 0, freq / 2);
+ m_freq_timer[f]->adjust(freq / 2, f, freq / 2);
m_freq_timer[f]->enable(m_freq_timer_selected[f] != 0);
- LOGMASKED(LOG_GENERAL, "F%d = %f Hz (%s cycle emulation)\n", f + 1, double(clock()) / scale,
+ LOG("F%d = %f Hz (%s cycle emulation)\n", f + 1, double(clock()) / scale,
m_freq_timer_selected[f] == 0 ? "no" : m_freq_timer_cycle[f] == 0 ? "partial" : "full");
}
@@ -229,21 +223,18 @@ void am9513_device::device_clock_changed()
//-------------------------------------------------
-// device_timer - called whenever a device timer
-// fires
+// timer_tick - advance our counters
//-------------------------------------------------
-void am9513_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
+TIMER_CALLBACK_MEMBER(am9513_device::timer_tick)
{
- assert(id >= TIMER_F1 && id <= TIMER_F5);
-
- int cycle = m_freq_timer_cycle[id - TIMER_F1] == 0 ? 2 : 1;
+ int cycle = m_freq_timer_cycle[param] == 0 ? 2 : 1;
while (cycle-- > 0)
{
- m_f ^= 1 << (id - TIMER_F1);
- bool level = BIT(m_f, id - TIMER_F1);
+ m_f ^= 1 << param;
+ bool level = BIT(m_f, param);
- int source = id - TIMER_F1 + 11;
+ int source = param + 11;
for (int c = 0; c < 5; c++)
{
if ((m_counter_mode[c] & 0x0f00) >> 8 == source && BIT(m_counter_mode[c], 12) == !level)
@@ -251,7 +242,7 @@ void am9513_device::device_timer(emu_timer &timer, device_timer_id id, int param
}
// FOUT Source = Fn
- if ((m_mmr & 0x00f0) >> 4 == source || ((m_mmr & 0x00f0) == 0 && id == TIMER_F1))
+ if ((m_mmr & 0x00f0) >> 4 == source || ((m_mmr & 0x00f0) == 0 && param == 0))
fout_tick();
}
}
@@ -330,7 +321,7 @@ void am9513_device::set_master_mode(u16 data)
if (source >= 11 && source <= 15)
{
LOGMASKED(LOG_MODE, "FOUT = F%d / %d\n", source - 10, divider);
- select_freq_timer(source - 11, 0, !m_fout_cb.isnull(), BIT(divider, 0));
+ select_freq_timer(source - 11, 0, !m_fout_cb.isunset(), BIT(divider, 0));
}
else if (source >= 6 && source <= 10)
LOGMASKED(LOG_MODE, "FOUT = GATE %d / %d\n", source - 5, divider);
@@ -451,13 +442,13 @@ void am9513_device::set_counter_mode(int c, u16 data)
else if (source >= 6 && source <= 10)
LOGMASKED(LOG_MODE, "Counter %d: Count on %s edge of GATE %d\n", c + 1, BIT(data, 12) ? "falling" : "rising", source - 5);
else if (source == 0)
- LOGMASKED(LOG_MODE, "Counter %d: Count on %s edge of TC%d\n", c + 1, BIT(data, 12) ? "falling" : "rising", c - 1);
+ LOGMASKED(LOG_MODE, "Counter %d: Count on %s edge of TC%d\n", c + 1, BIT(data, 12) ? "falling" : "rising", c);
else
LOGMASKED(LOG_MODE, "Counter %d: Count on %s edge of SRC %d\n", c + 1, BIT(data, 12) ? "falling" : "rising", source);
}
if ((data & 0x0018) != (m_counter_mode[c] & 0x0018))
- LOGMASKED(LOG_MODE, "Counter %d: %s %s count\n", c + 1, BIT(data, 4) ? "BCD" : "Binary", BIT(data, 3) ? "up" : "down");
+ LOGMASKED(LOG_MODE, "Counter %d: %s %s count %s\n", c + 1, BIT(data, 4) ? "BCD" : "Binary", BIT(data, 3) ? "up" : "down", BIT(data, 5) ? "repetitively" : "once");
if ((data & 0x0007) != (m_counter_mode[c] & 0x0007))
{
@@ -522,7 +513,7 @@ void am9513_device::arm_counter(int c)
{
if (!m_counter_armed[c])
{
- LOGMASKED(LOG_GENERAL, "Counter %d: Arming counter\n", c + 1);
+ LOG("Counter %d: Arming counter\n", c + 1);
m_counter_armed[c] = true;
// Count starts upon first active gate edge after arming in Modes C, F, I, L, O, R, X
@@ -540,7 +531,7 @@ void am9513_device::disarm_counter(int c)
{
if (m_counter_armed[c])
{
- LOGMASKED(LOG_GENERAL, "Counter %d: Disarming counter\n", c + 1);
+ LOG("Counter %d: Disarming counter\n", c + 1);
m_counter_armed[c] = false;
m_counter_running[c] = false;
}
@@ -554,7 +545,7 @@ void am9513_device::disarm_counter(int c)
void am9513_device::save_counter(int c)
{
m_counter_hold[c] = m_count[c];
- LOGMASKED(LOG_GENERAL, "Counter %d: Count %u saved\n", c + 1, m_count[c]);
+ LOG("Counter %d: Count %u saved\n", c + 1, m_count[c]);
}
@@ -629,8 +620,13 @@ void am9513_device::set_tc(int c, bool state)
// TC cascading
if ((m_counter_mode[d] & 0x1f00) == (state ? 0x0000 : 0x1000))
+ {
+ LOGMASKED(LOG_TC, "Counter %d: TC cascade Next Count %u \n", c + 1, m_count[d]);
+
count_edge(d);
+ }
+
// TC gating
if ((m_counter_mode[d] & 0xe000) == 0x2000)
gate_count(d, state && (bus_is_16_bit() || m_gate_alt[d]));
@@ -873,7 +869,7 @@ void am9513_device::step_counter(int c, bool force_load)
if (force_load)
{
m_count[c] = reload_from_hold(c) ? m_counter_hold[c] : m_counter_load[c];
- LOGMASKED(LOG_GENERAL, "Counter %d: %u loaded\n", c + 1, m_count[c]);
+ LOG("Counter %d: %u loaded\n", c + 1, m_count[c]);
}
}
@@ -1116,7 +1112,7 @@ void am9513_device::internal_write(u16 data)
case 0x07: // Alarm 1 register
case 0x0f: // Alarm 2 register
if (m_alarm[BIT(m_dpr, 3)] != data)
- LOGMASKED(LOG_GENERAL, "Counter %d: Alarm = %u\n", BIT(m_dpr, 3) ? 2 : 1, data);
+ LOG("Counter %d: Alarm = %u\n", BIT(m_dpr, 3) ? 2 : 1, data);
m_alarm[BIT(m_dpr, 3)] = data;
break;
case 0x01: // Counter 1 mode register
@@ -1125,7 +1121,7 @@ void am9513_device::internal_write(u16 data)
case 0x04: // Counter 4 mode register
case 0x05: // Counter 5 mode register
if (m_counter_mode[(m_dpr & 7) - 1] != data)
- LOGMASKED(LOG_GENERAL, "Counter %d: Mode = %04X\n", m_dpr & 7, data);
+ LOG("Counter %d: Mode = %04X\n", m_dpr & 7, data);
set_counter_mode((m_dpr & 7) - 1, data);
break;
case 0x09: // Counter 1 load register
@@ -1134,7 +1130,7 @@ void am9513_device::internal_write(u16 data)
case 0x0c: // Counter 4 load register
case 0x0d: // Counter 5 load register
if (m_counter_load[(m_dpr & 7) - 1] != data)
- LOGMASKED(LOG_GENERAL, "Counter %d: Load = %u\n", m_dpr & 7, data);
+ LOG("Counter %d: Load = %u\n", m_dpr & 7, data);
m_counter_load[(m_dpr & 7) - 1] = data;
break;
case 0x11: case 0x19: // Counter 1 hold register
@@ -1143,7 +1139,7 @@ void am9513_device::internal_write(u16 data)
case 0x14: case 0x1c: // Counter 4 hold register
case 0x15: case 0x1d: // Counter 5 hold register
if (m_counter_hold[(m_dpr & 7) - 1] != data)
- LOGMASKED(LOG_GENERAL, "Counter %d: Hold = %u\n", m_dpr & 7, data);
+ LOG("Counter %d: Hold = %u\n", m_dpr & 7, data);
m_counter_hold[(m_dpr & 7) - 1] = data;
break;
default: // Invalid register
@@ -1247,7 +1243,10 @@ void am9513_device::command_write(u8 data)
if (BIT(data, 6))
step_counter(c, true);
if (BIT(data, 5))
+ {
+ LOGMASKED(LOG_MODE, "Arm Counter %d\n", c + 1);
arm_counter(c);
+ }
}
}
break;
@@ -1260,9 +1259,15 @@ void am9513_device::command_write(u8 data)
if (BIT(data, c))
{
if (!BIT(data, 5))
+ {
+ LOGMASKED(LOG_MODE, "Disarm Counter %d\n", c + 1);
disarm_counter(c);
+ }
if (!BIT(data, 6))
+ {
+ LOGMASKED(LOG_MODE, "Save Counter %d\n", c + 1);
save_counter(c);
+ }
}
}
break;
@@ -1279,6 +1284,7 @@ void am9513_device::command_write(u8 data)
case 0xe3: case 0xeb: // Clear/set toggle out for counter 3
case 0xe4: case 0xec: // Clear/set toggle out for counter 4
case 0xe5: case 0xed: // Clear/set toggle out for counter 5
+ LOGMASKED(LOG_MODE, "Counter %d: %s output\n", data & 7, BIT(data, 3) ? "Set" : "Clear");
set_toggle((data & 7) - 1, BIT(data, 3));
break;
case 0xe6: case 0xee: // Clear/set MM12 (FOUT gate on/FOUT gate off)
@@ -1286,6 +1292,7 @@ void am9513_device::command_write(u8 data)
m_mmr = ((m_mmr & ~(1 << 12)) | BIT(data, 3) << 12);
break;
case 0xe7: case 0xef: // Clear/set MM13 (8-bit bus/16-bit bus)
+ LOGMASKED(LOG_MODE, "Data Bus Width = %d-Bit\n", BIT(data, 3) ? 16 : 8);
m_mmr = ((m_mmr & ~(1 << 13)) | BIT(data, 3) << 13);
break;
case 0xf1: // Step counter 1
@@ -1293,6 +1300,7 @@ void am9513_device::command_write(u8 data)
case 0xf3: // Step counter 3
case 0xf4: // Step counter 4
case 0xf5: // Step counter 5
+ LOGMASKED(LOG_MODE, "Counter %d: Step\n", data & 7);
step_counter((data & 7) - 1, false);
break;
case 0xff: // Master reset
@@ -1305,7 +1313,7 @@ void am9513_device::command_write(u8 data)
m_write_prefetch = !BIT(data, 0);
break;
}
- // else fall through
+ [[fallthrough]];
default:
logerror("Invalid command: %02X\n", data);
break;
@@ -1465,7 +1473,7 @@ void am9513_device::fout_tick()
m_fout = !m_fout;
// Check whether the FOUT gate is on
- if (!BIT(m_mmr, 12) && !m_fout_cb.isnull())
+ if (!BIT(m_mmr, 12) && !m_fout_cb.isunset())
m_fout_cb(m_fout);
// Reload the counter