From 0dc7dac6a3e1000154e08b53ff475ab7eabce04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Fri, 20 Jan 2017 22:26:13 +0100 Subject: [PATCH] Add PLA, PHA emulation. --- src/65c02isa.csv | 4 ++-- src/emulation.c | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/65c02isa.csv b/src/65c02isa.csv index c832670..61bd066 100644 --- a/src/65c02isa.csv +++ b/src/65c02isa.csv @@ -70,7 +70,7 @@ OP_NOPI_45,"nop",ZP,2,NULL OP_EOR_ZP,"eor",ZP,2,NULL OP_LSR_ZP,"lsr",ZP,2,NULL OP_RMB4_ZP,"rmb4",ZP,2,NULL -OP_PHA,"pha",IMPLIED,1,NULL +OP_PHA,"pha",IMPLIED,1,emul_pha OP_EOR_IMM,"eor",IMMEDIATE,2,NULL OP_LSR,"lsr",ACCUMULATOR,1,NULL OP_NOPI_4C,"nop",IMPLIED,1,NULL @@ -102,7 +102,7 @@ OP_STZ_ZP,"stz",ZP,2,NULL OP_ADC_ZP,"adc",ZP,2,NULL OP_ROR_ZP,"ror",ZP,2,NULL OP_RMB6_ZP,"rmb6",ZP,2,NULL -OP_PLA,"pla",IMPLIED,1,NULL +OP_PLA,"pla",IMPLIED,1,emul_pla OP_ADC_IMM,"adc",IMMEDIATE,2,NULL OP_ROR,"ror",ACCUMULATOR,1,NULL OP_NOPI_6C,"nop",IMPLIED,1,NULL diff --git a/src/emulation.c b/src/emulation.c index 4cffcc4..c14c886 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -2,13 +2,15 @@ #include "emulation.h" +/* AND - logical AND */ void emul_and(rk65c02emu_t *e, instruction_t *i) { instrdef_t id; - id = instruction_decode(i->opcode); uint8_t rv; + id = instruction_decode(i->opcode); + rv = e->regs.A & (instruction_data_read_1(e, &id, i)); e->regs.A = rv; @@ -16,10 +18,12 @@ emul_and(rk65c02emu_t *e, instruction_t *i) instruction_status_adjust_negative(e, e->regs.A); } +/* LDA - load to accumulator */ void emul_lda(rk65c02emu_t *e, instruction_t *i) { instrdef_t id; + id = instruction_decode(i->opcode); e->regs.A = instruction_data_read_1(e, &id, i); @@ -28,12 +32,31 @@ emul_lda(rk65c02emu_t *e, instruction_t *i) instruction_status_adjust_negative(e, e->regs.A); } +/* NOP - do nothing */ void emul_nop(rk65c02emu_t *e, instruction_t *i) { /* printf("nop!\n"); */ } +/* PHA - push accumulator to stack */ +void +emul_pha(rk6502emu_t *e, instruction_t *i) +{ + stack_push(e, e->regs.A); +} + +/* PLA - pull from stack to accumulator */ +void +emul_pla(rk65c02emu_t *e, instruciton_t *i) +{ + e->regs.A = stack_pop(e); + + instruction_status_adjust_zero(e, e->regs.A); + instruction_status_adjust_negative(e, e->regs.A); +} + +/* STP - stop the processor */ void emul_stp(rk65c02emu_t *e, instruction_t *i) {