diff --git a/src/emulation.c b/src/emulation.c index c29c0dd..5803f1b 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -10,16 +10,8 @@ emul_lda(rk65c02emu_t *e, instruction_t *i) e->regs.A = instruction_data_read_1(e, &id, i); - /* adjust status flags */ - if (e->regs.A & NEGATIVE) - e->regs.P |= P_NEGATIVE; - else - e->regs.P &= ~P_NEGATIVE; - - if (e->regs.A == 0) - e->regs.P |= P_ZERO; - else - e->regs.P &= ~P_ZERO; + instruction_status_adjust_zero(e->regs.A); + instruction_status_adjust_negative(e->regs.A); } void diff --git a/src/instruction.c b/src/instruction.c index 6c492c6..40b4824 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -144,6 +144,24 @@ instruction_decode(uint8_t opcode) return id; } +void +instruction_status_adjust_zero(rk65c02emu_t *e, uint8_t regval) +{ + if (regval == 0) + e->regs.P |= P_ZERO; + else + e->regs.P &= ~P_ZERO; +} + +void +instruction_status_adjust_negative(rk65c02emu_t *e, uint8_t regval) +{ + if (regval & NEGATIVE) + e->regs.P |= P_NEGATIVE; + else + e->regs.P &= ~P_NEGATIVE; +} + uint8_t instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i) { diff --git a/src/instruction.h b/src/instruction.h index 4075cae..71760a2 100644 --- a/src/instruction.h +++ b/src/instruction.h @@ -44,6 +44,8 @@ instrdef_t instruction_decode(uint8_t); void instruction_print(instruction_t *); void disassemble(bus_t *, uint16_t); uint8_t instruction_data_read_1(rk65c02emu_t *, instrdef_t *, instruction_t *); +void instruction_status_adjust_zero(rk65c02emu_t *, uint8_t); +void instruction_status_adjust_negative(rk65c02emu_t *, uint8_t); //void instruction_execute(rk65c02emu_t *, instruction_t *); #endif /* _INSTRUCTION_H_ */