summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author hap <happppp@users.noreply.github.com>2020-04-23 01:21:39 +0200
committer hap <happppp@users.noreply.github.com>2020-04-23 01:22:00 +0200
commit68f42bc6debf2fb8c05737ec2698bbdcc514eac7 (patch)
tree7d16ec456f346b158940c21d024e37a2095ae2a3
parent859d4943d63df5f6510ff277ae8dda4d849cd146 (diff)
hmcs40: change stack op (nw)
-rw-r--r--src/devices/cpu/hmcs40/hmcs40.cpp1
-rw-r--r--src/devices/cpu/hmcs40/hmcs40.h2
-rw-r--r--src/devices/cpu/hmcs40/hmcs40op.cpp20
3 files changed, 17 insertions, 6 deletions
diff --git a/src/devices/cpu/hmcs40/hmcs40.cpp b/src/devices/cpu/hmcs40/hmcs40.cpp
index c11d25bff56..867530f456e 100644
--- a/src/devices/cpu/hmcs40/hmcs40.cpp
+++ b/src/devices/cpu/hmcs40/hmcs40.cpp
@@ -215,6 +215,7 @@ void hmcs40_cpu_device::device_start()
// zerofill
memset(m_stack, 0, sizeof(m_stack));
+ m_sp = 0;
m_op = 0;
m_prev_op = 0;
m_i = 0;
diff --git a/src/devices/cpu/hmcs40/hmcs40.h b/src/devices/cpu/hmcs40/hmcs40.h
index 38ea2490c80..9b622c7139a 100644
--- a/src/devices/cpu/hmcs40/hmcs40.h
+++ b/src/devices/cpu/hmcs40/hmcs40.h
@@ -144,6 +144,7 @@ protected:
u16 m_polarity; // i/o polarity (pmos vs cmos)
int m_stack_levels; // number of callstack levels
u16 m_stack[4]; // max 4
+ int m_sp; // internal 'stackpointer'
u16 m_op; // current opcode
u16 m_prev_op;
u8 m_i; // 4-bit immediate opcode param
@@ -185,6 +186,7 @@ protected:
u8 ram_r();
void ram_w(u8 data);
+ void exc_stack();
void pop_stack();
void push_stack();
diff --git a/src/devices/cpu/hmcs40/hmcs40op.cpp b/src/devices/cpu/hmcs40/hmcs40op.cpp
index a10629cf639..a0c6c6efb5c 100644
--- a/src/devices/cpu/hmcs40/hmcs40op.cpp
+++ b/src/devices/cpu/hmcs40/hmcs40op.cpp
@@ -21,18 +21,26 @@ inline void hmcs40_cpu_device::ram_w(u8 data)
m_data->write_byte(address, data & 0xf);
}
+void hmcs40_cpu_device::exc_stack()
+{
+ // exchange stack/pc
+ u16 pc = m_stack[m_sp] & m_pcmask;
+ m_stack[m_sp] = m_pc;
+ m_pc = pc;
+}
+
void hmcs40_cpu_device::pop_stack()
{
- m_pc = m_stack[0] & m_pcmask;
- for (int i = 0; i < m_stack_levels-1; i++)
- m_stack[i] = m_stack[i+1];
+ if (++m_sp >= m_stack_levels)
+ m_sp = 0;
+ exc_stack();
}
void hmcs40_cpu_device::push_stack()
{
- for (int i = m_stack_levels-1; i >= 1; i--)
- m_stack[i] = m_stack[i-1];
- m_stack[0] = m_pc;
+ exc_stack();
+ if (--m_sp < 0)
+ m_sp = m_stack_levels - 1;
}