added branch opcodes

This commit is contained in:
hap 2015-03-06 00:40:54 +01:00
parent b53dab53b0
commit 151bd510c9
3 changed files with 32 additions and 6 deletions

View File

@ -140,8 +140,10 @@ void hmcs40_cpu_device::device_start()
// zerofill // zerofill
memset(m_stack, 0, sizeof(m_stack)); memset(m_stack, 0, sizeof(m_stack));
m_op = 0; m_op = 0;
m_prev_op = 0;
m_arg = 0; m_arg = 0;
m_pc = 0; m_pc = 0;
m_page = 0;
m_a = 0; m_a = 0;
m_b = 0; m_b = 0;
m_x = 0; m_x = 0;
@ -154,8 +156,10 @@ void hmcs40_cpu_device::device_start()
// register for savestates // register for savestates
save_item(NAME(m_stack)); save_item(NAME(m_stack));
save_item(NAME(m_op)); save_item(NAME(m_op));
save_item(NAME(m_prev_op));
save_item(NAME(m_arg)); save_item(NAME(m_arg));
save_item(NAME(m_pc)); save_item(NAME(m_pc));
save_item(NAME(m_page));
save_item(NAME(m_a)); save_item(NAME(m_a));
save_item(NAME(m_b)); save_item(NAME(m_b));
save_item(NAME(m_x)); save_item(NAME(m_x));
@ -216,7 +220,7 @@ inline void hmcs40_cpu_device::increment_pc()
inline void hmcs40_cpu_device::fetch_arg() inline void hmcs40_cpu_device::fetch_arg()
{ {
// P is the only 2-byte opcode // P is the only 2-byte opcode
if (m_op == 0x3ff) if ((m_op & 0x3f8) == 0x368)
{ {
m_icount--; m_icount--;
m_arg = m_program->read_word(m_pc << 1); m_arg = m_program->read_word(m_pc << 1);
@ -230,6 +234,14 @@ void hmcs40_cpu_device::execute_run()
{ {
m_icount--; m_icount--;
// LPU is handled 1 cycle later
if ((m_prev_op & 0x3e0) == 0x340)
m_pc = ((m_page << 6) | (m_pc & 0x3f)) & m_prgmask;
// remember previous opcode
m_prev_op = m_op;
// fetch next opcode
debugger_instruction_hook(this, m_pc << 1); debugger_instruction_hook(this, m_pc << 1);
m_op = m_program->read_word(m_pc << 1); m_op = m_program->read_word(m_pc << 1);
increment_pc(); increment_pc();

View File

@ -72,10 +72,12 @@ protected:
int m_stack_levels; // number of callstack levels int m_stack_levels; // number of callstack levels
UINT16 m_stack[4]; // max 4 UINT16 m_stack[4]; // max 4
UINT16 m_op; UINT16 m_op;
UINT16 m_prev_op;
UINT16 m_arg; UINT16 m_arg;
int m_icount; int m_icount;
UINT16 m_pc; // Program Counter UINT16 m_pc; // Program Counter
UINT8 m_page; // LPU prepared page
UINT8 m_a; // 4-bit Accumulator UINT8 m_a; // 4-bit Accumulator
UINT8 m_b; // 4-bit B register UINT8 m_b; // 4-bit B register
UINT8 m_x; // 1/3/4-bit X register UINT8 m_x; // 1/3/4-bit X register

View File

@ -431,31 +431,43 @@ void hmcs40_cpu_device::op_tm()
void hmcs40_cpu_device::op_br() void hmcs40_cpu_device::op_br()
{ {
// BR a: Branch on Status 1 // BR a: Branch on Status 1
op_illegal(); if (m_s)
m_pc = (m_pc & ~0x3f) | (m_op & 0x3f);
else
m_s = 1;
} }
void hmcs40_cpu_device::op_cal() void hmcs40_cpu_device::op_cal()
{ {
// CAL a: Subroutine Jump on Status 1 // CAL a: Subroutine Jump on Status 1
op_illegal(); if (m_s)
{
push_stack();
m_pc = m_op & 0x3f; // short calls default to page 0
}
else
m_s = 1;
} }
void hmcs40_cpu_device::op_lpu() void hmcs40_cpu_device::op_lpu()
{ {
// LPU u: Load Program Counter Upper on Status 1 // LPU u: Load Program Counter Upper on Status 1
op_illegal(); if (m_s)
m_page = m_op & 0x1f;
else
m_op = 0;
} }
void hmcs40_cpu_device::op_tbr() void hmcs40_cpu_device::op_tbr()
{ {
// TBR p: Table Branch // TBR p: Table Branch
op_illegal(); m_pc = (m_a | m_b << 4 | m_c << 8 | ((m_op & 7) << 9)) & m_prgmask;
} }
void hmcs40_cpu_device::op_rtn() void hmcs40_cpu_device::op_rtn()
{ {
// RTN: Return from Subroutine // RTN: Return from Subroutine
op_illegal(); pop_stack();
} }