summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/ccpu/ccpu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/cpu/ccpu/ccpu.cpp')
-rw-r--r--src/devices/cpu/ccpu/ccpu.cpp77
1 files changed, 41 insertions, 36 deletions
diff --git a/src/devices/cpu/ccpu/ccpu.cpp b/src/devices/cpu/ccpu/ccpu.cpp
index 740c803ad44..367df58c595 100644
--- a/src/devices/cpu/ccpu/ccpu.cpp
+++ b/src/devices/cpu/ccpu/ccpu.cpp
@@ -13,7 +13,6 @@
#include "emu.h"
#include "ccpu.h"
#include "ccpudasm.h"
-#include "debugger.h"
DEFINE_DEVICE_TYPE(CCPU, ccpu_cpu_device, "ccpu", "Cinematronics CPU")
@@ -23,18 +22,18 @@ DEFINE_DEVICE_TYPE(CCPU, ccpu_cpu_device, "ccpu", "Cinematronics CPU")
MACROS
***************************************************************************/
-#define READOP(a) (m_cache->read_byte(a))
+#define READOP(a) (m_cache.read_byte(a))
-#define RDMEM(a) (m_data->read_word((a) & 0xfff))
-#define WRMEM(a,v) (m_data->write_word((a), (v)))
+#define RDMEM(a) (m_data.read_word((a) & 0xfff))
+#define WRMEM(a,v) (m_data.write_word((a), (v)))
-#define READPORT(a) (m_io->read_byte(a))
-#define WRITEPORT(a,v) (m_io->write_byte((a), (v)))
+#define READPORT(a) (m_io.read_byte(a))
+#define WRITEPORT(a,v) (m_io.write_byte((a), (v)))
#define SET_A0 do { m_a0flag = m_A; } while (0)
-#define SET_CMP_VAL(x) do { m_cmpacc = *m_acc; m_cmpval = (x) & 0xfff; } while (0)
-#define SET_NC(a) do { m_ncflag = ~(a); } while (0)
-#define SET_MI(a) do { m_nextnextmiflag = (a); } while (0)
+#define SET_CMP_VAL(x) do { m_cmpacc = *m_acc; m_cmpval = (x) & 0xfff; } while (0)
+#define SET_NC(a) do { m_ncflag = ~(a); } while (0)
+#define SET_MI(a) do { m_nextnextmiflag = (a); } while (0)
#define TEST_A0 (m_a0flag & 1)
#define TEST_NC ((m_ncflag >> 12) & 1)
@@ -46,15 +45,17 @@ DEFINE_DEVICE_TYPE(CCPU, ccpu_cpu_device, "ccpu", "Cinematronics CPU")
#define NEXT_ACC_A do { SET_MI(*m_acc); m_acc = &m_A; } while (0)
#define NEXT_ACC_B do { SET_MI(*m_acc); if (m_acc == &m_A) m_acc = &m_B; else m_acc = &m_A; } while (0)
-#define CYCLES(x) do { m_icount -= (x); } while (0)
+#define CYCLES(x) do { m_icount -= (x); } while (0)
+
+#define ASR(x) (((x) >> 1) | ((x) & 0x800))
#define STANDARD_ACC_OP(resexp,cmpval) \
do { \
uint16_t result = resexp; \
- SET_A0; /* set the A0 bit based on the previous 'A' value */ \
- SET_CMP_VAL(cmpval); /* set the compare values to the previous accumulator and the cmpval */ \
- SET_NC(result); /* set the NC flag based on the unmasked result */ \
- *m_acc = result & 0xfff; /* store the low 12 bits of the new value */ \
+ SET_A0; /* set the A0 bit based on the previous 'A' value */ \
+ SET_CMP_VAL(cmpval); /* set the compare values to the previous accumulator and the cmpval */ \
+ SET_NC(result); /* set the NC flag based on the unmasked result */ \
+ *m_acc = result & 0xfff; /* store the low 12 bits of the new value */ \
} while (0)
@@ -68,7 +69,8 @@ ccpu_cpu_device::ccpu_cpu_device(const machine_config &mconfig, const char *tag,
, m_program_config("program", ENDIANNESS_BIG, 8, 15, 0)
, m_data_config("data", ENDIANNESS_BIG, 16, 32, -1)
, m_io_config("io", ENDIANNESS_BIG, 8, 5, 0)
- , m_external_input(*this)
+ , m_external_input(*this, 0)
+ , m_vector_callback(*this)
, m_flags(0)
{
}
@@ -82,7 +84,7 @@ device_memory_interface::space_config_vector ccpu_cpu_device::memory_space_confi
};
}
-READ8_MEMBER( ccpu_cpu_device::read_jmi )
+uint8_t ccpu_cpu_device::read_jmi()
{
/* this routine is called when there is no external input */
/* and the JMI jumper is present */
@@ -90,26 +92,27 @@ READ8_MEMBER( ccpu_cpu_device::read_jmi )
}
-void ccpu_cpu_device::wdt_timer_trigger()
+void ccpu_cpu_device::wdt_trigger(int state)
{
+ if (!state)
+ return;
+
m_waiting = false;
m_watchdog++;
if (m_watchdog >= 3)
- m_PC = 0;
+ device_reset();
}
void ccpu_cpu_device::device_start()
{
/* copy input params */
- m_external_input.resolve_safe(0);
- m_vector_callback.bind_relative_to(*owner());
- assert(!m_vector_callback.isnull());
+ m_vector_callback.resolve_safe();
- m_program = &space(AS_PROGRAM);
- m_cache = m_program->cache<0, 0, ENDIANNESS_BIG>();
- m_data = &space(AS_DATA);
- m_io = &space(AS_IO);
+ space(AS_PROGRAM).cache(m_cache);
+ space(AS_PROGRAM).specific(m_program);
+ space(AS_DATA).specific(m_data);
+ space(AS_IO).specific(m_io);
save_item(NAME(m_PC));
save_item(NAME(m_A));
@@ -203,6 +206,7 @@ void ccpu_cpu_device::execute_run()
{
if (m_waiting)
{
+ debugger_wait_hook();
m_icount = 0;
return;
}
@@ -478,8 +482,8 @@ void ccpu_cpu_device::execute_run()
/* DV */
case 0xe0:
{
- int16_t stopX = (int16_t)(m_A << 4) >> 4;
- int16_t stopY = (int16_t)(m_B << 4) >> 4;
+ int16_t stopX = util::sext(m_A, 12);
+ int16_t stopY = util::sext(m_B, 12);
stopX = ((int16_t)(stopX - m_X) >> m_T) + m_X;
stopY = ((int16_t)(stopY - m_Y) >> m_T) + m_Y;
@@ -527,7 +531,7 @@ void ccpu_cpu_device::execute_run()
uint16_t result;
m_cmpacc = m_B;
m_A = (m_A >> 1) | ((m_B << 11) & 0x800);
- m_B = ((int16_t)(m_B << 4) >> 5) & 0xfff;
+ m_B = ASR(m_B);
result = m_B + tempval;
SET_NC(result);
SET_MI(result);
@@ -539,7 +543,7 @@ void ccpu_cpu_device::execute_run()
m_cmpacc = m_A;
result = m_A + tempval;
m_A = (m_A >> 1) | ((m_B << 11) & 0x800);
- m_B = ((int16_t)(m_B << 4) >> 5) & 0xfff;
+ m_B = ASR(m_B);
SET_NC(result);
SET_MI(result);
}
@@ -548,7 +552,7 @@ void ccpu_cpu_device::execute_run()
{
uint16_t result;
m_cmpacc = m_B;
- m_B = ((int16_t)(m_B << 4) >> 5) & 0xfff;
+ m_B = ASR(m_B);
result = m_B + tempval;
SET_NC(result);
SET_MI(result);
@@ -598,6 +602,7 @@ void ccpu_cpu_device::execute_run()
/* CST */
case 0xf7:
m_watchdog = 0;
+ [[fallthrough]];
/* ADDP */
case 0xe7:
tempval = RDMEM(m_I);
@@ -632,7 +637,7 @@ void ccpu_cpu_device::execute_run()
/* SHR */
case 0xeb:
case 0xfb:
- tempval = ((m_acc == &m_A) ? (m_A >> 1) : ((int16_t)(m_B << 4) >> 5)) & 0xfff;
+ tempval = (m_acc == &m_A) ? (m_A >> 1) : ASR(m_B);
tempval |= (*m_acc + (0xb0b | (opcode & 0xf0))) & 0x1000;
STANDARD_ACC_OP(tempval, 0xb0b | (opcode & 0xf0));
NEXT_ACC_A; CYCLES(1);
@@ -650,7 +655,7 @@ void ccpu_cpu_device::execute_run()
/* ASR */
case 0xed:
case 0xfd:
- tempval = ((int16_t)(*m_acc << 4) >> 5) & 0xfff;
+ tempval = ASR(*m_acc);
STANDARD_ACC_OP(tempval, 0xd0d | (opcode & 0xf0));
NEXT_ACC_A; CYCLES(1);
break;
@@ -661,10 +666,10 @@ void ccpu_cpu_device::execute_run()
if (m_acc == &m_A)
{
tempval = (m_A >> 1) | ((m_B << 11) & 0x800);
- m_B = ((int16_t)(m_B << 4) >> 5) & 0xfff;
+ m_B = ASR(m_B);
}
else
- tempval = ((int16_t)(m_B << 4) >> 5) & 0xfff;
+ tempval = ASR(m_B);
tempval |= (*m_acc + (0xe0e | (opcode & 0xf0))) & 0x1000;
STANDARD_ACC_OP(tempval, 0xe0e | (opcode & 0xf0));
NEXT_ACC_A; CYCLES(1);
@@ -687,8 +692,8 @@ void ccpu_cpu_device::execute_run()
/* IV */
case 0xf0:
- m_X = (int16_t)(m_A << 4) >> 4;
- m_Y = (int16_t)(m_B << 4) >> 4;
+ m_X = util::sext(m_A, 12);
+ m_Y = util::sext(m_B, 12);
NEXT_ACC_A; CYCLES(1);
break;
}