summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2019-08-30 23:03:50 -0400
committer AJR <ajrhacker@users.noreply.github.com>2019-08-30 23:05:50 -0400
commitf7f5bedbbe8ecba321a045216d291a02e7fe85e9 (patch)
treebe0b099b50f592695a1c8fc8bc00e38e45d28af6
parent75e748a2967f74878d9ffd50889fdc905ab73590 (diff)
m37710: Internalize timing for A-D converter
-rw-r--r--src/devices/cpu/m37710/m37710.cpp49
-rw-r--r--src/devices/cpu/m37710/m37710.h3
-rw-r--r--src/mame/drivers/namcofl.cpp6
-rw-r--r--src/mame/drivers/namcona1.cpp4
-rw-r--r--src/mame/drivers/namconb1.cpp6
-rw-r--r--src/mame/drivers/namcos11.cpp7
-rw-r--r--src/mame/drivers/namcos22.cpp2
-rw-r--r--src/mame/includes/namcofl.h1
-rw-r--r--src/mame/includes/namconb1.h1
9 files changed, 45 insertions, 34 deletions
diff --git a/src/devices/cpu/m37710/m37710.cpp b/src/devices/cpu/m37710/m37710.cpp
index 949454ccc5b..df78cdafe74 100644
--- a/src/devices/cpu/m37710/m37710.cpp
+++ b/src/devices/cpu/m37710/m37710.cpp
@@ -418,7 +418,7 @@ void m37710_cpu_device::m37710_recalc_timer(int timer)
switch (m_timer_mode[timer] & 0x3)
{
case 0: // timer mode
- time = attotime::from_hz(unscaled_clock()) * tscales[m_timer_mode[timer]>>6];
+ time = clocks_to_attotime(tscales[m_timer_mode[timer]>>6]);
time *= (tval + 1);
LOGMASKED(LOG_TIMER, "Timer %d in timer mode, %f Hz\n", timer, 1.0 / time.as_double());
@@ -445,7 +445,7 @@ void m37710_cpu_device::m37710_recalc_timer(int timer)
switch (m_timer_mode[timer] & 0x3)
{
case 0: // timer mode
- time = attotime::from_hz(unscaled_clock()) * tscales[m_timer_mode[timer]>>6];
+ time = clocks_to_attotime(tscales[m_timer_mode[timer]>>6]);
time *= (tval + 1);
LOGMASKED(LOG_TIMER, "Timer %d in timer mode, %f Hz\n", timer, 1.0 / time.as_double());
@@ -535,9 +535,43 @@ void m37710_cpu_device::ad_control_w(uint8_t data)
{
LOGMASKED(LOG_AD, "ad_control_w %x: A/D control reg = %x\n", data, m_ad_control);
+ if (BIT(data, 6) && !BIT(m_ad_control, 6))
+ {
+ // A-D conversion clock may be selected as f2/4 or f2/2
+ m_ad_timer->adjust(clocks_to_attotime(57 * 2 * (BIT(data, 7) ? 2 : 4)));
+ if (BIT(data, 4))
+ data &= 0xf8;
+ }
+ else if (!BIT(data, 6))
+ m_ad_timer->adjust(attotime::never);
+
m_ad_control = data;
}
+TIMER_CALLBACK_MEMBER(m37710_cpu_device::ad_timer_cb)
+{
+ int line = m_ad_control & 0x07;
+
+ m_ad_result[line] = m_analog_cb[line]();
+
+ if (BIT(m_ad_control, 4))
+ m_ad_control = (m_ad_control & 0xf8) | ((line + 1) & 0x07);
+
+ // repeat or sweep conversion
+ if (BIT(m_ad_control, 3) || (BIT(m_ad_control, 4) && line != (m_ad_sweep & 0x03) * 2 + 1))
+ {
+ LOGMASKED(LOG_AD, "AN%d input converted = %x (repeat/sweep)\n", line, m_ad_result[line]);
+ m_ad_timer->adjust(clocks_to_attotime(57 * 2 * (BIT(m_ad_control, 7) ? 2 : 4)));
+ }
+ else
+ {
+ // interrupt occurs only when conversion stops
+ LOGMASKED(LOG_AD, "AN%d input converted = %x (finished)\n", line, m_ad_result[line]);
+ m37710_set_irq_line(M37710_LINE_ADC, ASSERT_LINE);
+ m_ad_control &= 0xbf;
+ }
+}
+
uint8_t m37710_cpu_device::ad_sweep_r()
{
return m_ad_sweep;
@@ -552,7 +586,7 @@ void m37710_cpu_device::ad_sweep_w(uint8_t data)
uint16_t m37710_cpu_device::ad_result_r(offs_t offset)
{
- uint16_t result = m_analog_cb[offset]();
+ uint16_t result = m_ad_result[offset];
LOGMASKED(LOG_AD, "ad_result_r from %02x: A/D %d = %x (PC=%x)\n", (int)(offset * 2) + 0x20, offset, result, REG_PB<<16 | REG_PC);
@@ -847,10 +881,6 @@ uint8_t m37710_cpu_device::int_control_r(offs_t offset)
uint8_t result = m_int_control[level];
- // A-D IRQ not properly hooked up yet
- if (level == M37710_LINE_ADC)
- result |= 8;
-
return result;
}
@@ -1007,6 +1037,7 @@ void m37710_cpu_device::device_reset()
// A-D
m_ad_control &= 7;
m_ad_sweep = (m_ad_sweep & ~0xdc) | 3;
+ m_ad_timer->reset();
// UARTs
for (i = 0; i < 2; i++)
@@ -1208,6 +1239,7 @@ void m37710_cpu_device::device_start()
std::fill(std::begin(m_port_dir), std::end(m_port_dir), 0);
m_ad_control = 0;
m_ad_sweep = 0;
+ std::fill(std::begin(m_ad_result), std::end(m_ad_result), 0);
std::fill(std::begin(m_uart_mode), std::end(m_uart_mode), 0);
std::fill(std::begin(m_uart_baud), std::end(m_uart_baud), 0);
std::fill(std::begin(m_uart_ctrl_reg0), std::end(m_uart_ctrl_reg0), 0);
@@ -1243,6 +1275,8 @@ void m37710_cpu_device::device_start()
m_timer_out[i] = 0;
}
+ m_ad_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(m37710_cpu_device::ad_timer_cb), this));
+
save_item(NAME(m_a));
save_item(NAME(m_b));
save_item(NAME(m_ba));
@@ -1279,6 +1313,7 @@ void m37710_cpu_device::device_start()
save_item(NAME(m_port_dir));
save_item(NAME(m_ad_control));
save_item(NAME(m_ad_sweep));
+ save_item(NAME(m_ad_result));
save_item(NAME(m_uart_mode));
save_item(NAME(m_uart_baud));
save_item(NAME(m_uart_ctrl_reg0));
diff --git a/src/devices/cpu/m37710/m37710.h b/src/devices/cpu/m37710/m37710.h
index 0dc273ccce4..def929186b5 100644
--- a/src/devices/cpu/m37710/m37710.h
+++ b/src/devices/cpu/m37710/m37710.h
@@ -135,6 +135,7 @@ protected:
void pulse_output_w(offs_t offset, uint8_t data);
uint8_t ad_control_r();
void ad_control_w(uint8_t data);
+ TIMER_CALLBACK_MEMBER(ad_timer_cb);
uint8_t ad_sweep_r();
void ad_sweep_w(uint8_t data);
uint16_t ad_result_r(offs_t offset);
@@ -267,6 +268,8 @@ private:
// A/D
uint8_t m_ad_control;
uint8_t m_ad_sweep;
+ uint16_t m_ad_result[8];
+ emu_timer *m_ad_timer;
// UARTs
uint8_t m_uart_mode[2];
diff --git a/src/mame/drivers/namcofl.cpp b/src/mame/drivers/namcofl.cpp
index 72b1c78d44c..38ca4a7282c 100644
--- a/src/mame/drivers/namcofl.cpp
+++ b/src/mame/drivers/namcofl.cpp
@@ -477,11 +477,6 @@ TIMER_DEVICE_CALLBACK_MEMBER(namcofl_state::mcu_irq2_cb)
m_mcu->set_input_line(M37710_LINE_IRQ2, HOLD_LINE);
}
-TIMER_DEVICE_CALLBACK_MEMBER(namcofl_state::mcu_adc_cb)
-{
- m_mcu->set_input_line(M37710_LINE_ADC, HOLD_LINE);
-}
-
MACHINE_START_MEMBER(namcofl_state,namcofl)
{
@@ -532,7 +527,6 @@ void namcofl_state::namcofl(machine_config &config)
/* TODO: irq generation for these */
TIMER(config, "mcu_irq0").configure_periodic(FUNC(namcofl_state::mcu_irq0_cb), attotime::from_hz(60));
TIMER(config, "mcu_irq2").configure_periodic(FUNC(namcofl_state::mcu_irq2_cb), attotime::from_hz(60));
- TIMER(config, "mcu_adc").configure_periodic(FUNC(namcofl_state::mcu_adc_cb), attotime::from_hz(60));
MCFG_MACHINE_START_OVERRIDE(namcofl_state,namcofl)
MCFG_MACHINE_RESET_OVERRIDE(namcofl_state,namcofl)
diff --git a/src/mame/drivers/namcona1.cpp b/src/mame/drivers/namcona1.cpp
index 97ee86d228b..47f3dd46577 100644
--- a/src/mame/drivers/namcona1.cpp
+++ b/src/mame/drivers/namcona1.cpp
@@ -927,10 +927,6 @@ void namcona1_state::scanline_interrupt(int scanline)
{
const u16 enabled = m_mEnableInterrupts ? ~m_vreg[0x1a / 2] : 0;
- // adc (timing guessed, when does this trigger?)
- if (scanline == 0)
- m_mcu->set_input_line(M37710_LINE_ADC, HOLD_LINE);
-
// vblank
if (scanline == 224)
{
diff --git a/src/mame/drivers/namconb1.cpp b/src/mame/drivers/namconb1.cpp
index 6302af1a95c..7b9ed15aa68 100644
--- a/src/mame/drivers/namconb1.cpp
+++ b/src/mame/drivers/namconb1.cpp
@@ -337,11 +337,6 @@ TIMER_DEVICE_CALLBACK_MEMBER(namconb1_state::mcu_irq2_cb)
m_mcu->set_input_line(M37710_LINE_IRQ2, HOLD_LINE);
}
-TIMER_DEVICE_CALLBACK_MEMBER(namconb1_state::mcu_adc_cb)
-{
- m_mcu->set_input_line(M37710_LINE_ADC, HOLD_LINE);
-}
-
/****************************************************************************/
WRITE8_MEMBER(namconb1_state::namconb1_cpureg_w)
@@ -984,7 +979,6 @@ void namconb1_state::namconb1(machine_config &config)
// has to be 60 hz or music will go crazy in nebulray, vshoot, gslugrs*
TIMER(config, "mcu_irq0").configure_periodic(FUNC(namconb1_state::mcu_irq0_cb), attotime::from_hz(60));
TIMER(config, "mcu_irq2").configure_periodic(FUNC(namconb1_state::mcu_irq2_cb), attotime::from_hz(60));
- TIMER(config, "mcu_adc").configure_periodic(FUNC(namconb1_state::mcu_adc_cb), attotime::from_hz(60));
SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
m_screen->set_raw(MASTER_CLOCK/8, 384, 0, 288, 264, 0, 224);
diff --git a/src/mame/drivers/namcos11.cpp b/src/mame/drivers/namcos11.cpp
index 7113931c598..3b8bea6e11d 100644
--- a/src/mame/drivers/namcos11.cpp
+++ b/src/mame/drivers/namcos11.cpp
@@ -356,7 +356,6 @@ private:
DECLARE_WRITE16_MEMBER(c76_speedup_w);
TIMER_DEVICE_CALLBACK_MEMBER(mcu_irq0_cb);
TIMER_DEVICE_CALLBACK_MEMBER(mcu_irq2_cb);
- TIMER_DEVICE_CALLBACK_MEMBER(mcu_adc_cb);
void c76_map(address_map &map);
void namcos11_map(address_map &map);
@@ -594,11 +593,6 @@ TIMER_DEVICE_CALLBACK_MEMBER(namcos11_state::mcu_irq2_cb)
m_mcu->set_input_line(M37710_LINE_IRQ2, HOLD_LINE);
}
-TIMER_DEVICE_CALLBACK_MEMBER(namcos11_state::mcu_adc_cb)
-{
- m_mcu->set_input_line(M37710_LINE_ADC, HOLD_LINE);
-}
-
void namcos11_state::coh110(machine_config &config)
{
CXD8530CQ(config, m_maincpu, XTAL(67'737'600));
@@ -620,7 +614,6 @@ void namcos11_state::coh110(machine_config &config)
/* TODO: irq generation for these */
TIMER(config, "mcu_irq0").configure_periodic(FUNC(namcos11_state::mcu_irq0_cb), attotime::from_hz(60));
TIMER(config, "mcu_irq2").configure_periodic(FUNC(namcos11_state::mcu_irq2_cb), attotime::from_hz(60));
- TIMER(config, "mcu_adc").configure_periodic(FUNC(namcos11_state::mcu_adc_cb), attotime::from_hz(60));
CXD8561Q(config, "gpu", XTAL(53'693'175), 0x200000, subdevice<psxcpu_device>("maincpu")).set_screen("screen");
diff --git a/src/mame/drivers/namcos22.cpp b/src/mame/drivers/namcos22.cpp
index ba19a296fa9..8ad1f1d5f50 100644
--- a/src/mame/drivers/namcos22.cpp
+++ b/src/mame/drivers/namcos22.cpp
@@ -2736,8 +2736,6 @@ TIMER_DEVICE_CALLBACK_MEMBER(namcos22s_state::mcu_irq)
/* TODO: real sources of these */
if (scanline == 480)
m_mcu->set_input_line(M37710_LINE_IRQ0, HOLD_LINE);
- else if (scanline == 0)
- m_mcu->set_input_line(M37710_LINE_ADC, HOLD_LINE);
else if (scanline == 240)
m_mcu->set_input_line(M37710_LINE_IRQ2, HOLD_LINE);
}
diff --git a/src/mame/includes/namcofl.h b/src/mame/includes/namcofl.h
index e94af8f9010..d3faf9d8741 100644
--- a/src/mame/includes/namcofl.h
+++ b/src/mame/includes/namcofl.h
@@ -91,7 +91,6 @@ private:
TIMER_CALLBACK_MEMBER(raster_interrupt_callback);
TIMER_DEVICE_CALLBACK_MEMBER(mcu_irq0_cb);
TIMER_DEVICE_CALLBACK_MEMBER(mcu_irq2_cb);
- TIMER_DEVICE_CALLBACK_MEMBER(mcu_adc_cb);
void common_init();
int FLobjcode2tile(int code);
void TilemapCB(uint16_t code, int *tile, int *mask);
diff --git a/src/mame/includes/namconb1.h b/src/mame/includes/namconb1.h
index f8fbe040e43..2c05565ed8d 100644
--- a/src/mame/includes/namconb1.h
+++ b/src/mame/includes/namconb1.h
@@ -142,7 +142,6 @@ private:
TIMER_DEVICE_CALLBACK_MEMBER(scantimer);
TIMER_DEVICE_CALLBACK_MEMBER(mcu_irq0_cb);
TIMER_DEVICE_CALLBACK_MEMBER(mcu_irq2_cb);
- TIMER_DEVICE_CALLBACK_MEMBER(mcu_adc_cb);
int NB1objcode2tile(int code);
int NB2objcode2tile_machbrkr(int code);