hmcs40: change stack op (nw)

This commit is contained in:
hap 2020-04-23 01:21:39 +02:00
parent 859d4943d6
commit 68f42bc6de
3 changed files with 17 additions and 6 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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;
}