From 3bcc7bb096f35435569afc8deeca6fa748a82f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Fri, 20 Jan 2017 10:25:19 +0100 Subject: [PATCH] Introduce instruction-independent status adjustment functions. For now only for negative and zero. Also use them in LDA emulation. --- src/emulation.c | 12 ++---------- src/instruction.c | 18 ++++++++++++++++++ src/instruction.h | 2 ++ 3 files changed, 22 insertions(+), 10 deletions(-) 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_ */