From 92914d4aa0bc8100d54329429aa9b77bf8667f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Wed, 18 Jan 2017 22:37:00 +0100 Subject: [PATCH] Experiment with emulating opcode requring operands. Immediate lda now works. --- src/65c02isa.csv | 2 +- src/emulation.c | 20 +++++++++++++++++--- src/emulation.h | 1 + test/test_emulation.c | 36 ++++++++++++++++++++++++++++++------ 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/65c02isa.csv b/src/65c02isa.csv index c1ff680..623ea5a 100644 --- a/src/65c02isa.csv +++ b/src/65c02isa.csv @@ -167,7 +167,7 @@ OP_LDA_ZP,"lda",ZP,2,NULL OP_LDX_ZP,"ldx",ZP,2,NULL OP_SMB2_ZP,"smb2",ZP,2,NULL OP_TAY,"tay",IMPLIED,1,NULL -OP_LDA_IMM,"lda",IMMEDIATE,2,NULL +OP_LDA_IMM,"lda",IMMEDIATE,2,emul_lda OP_TAX,"tax",IMPLIED,1,NULL OP_NOPI_AC,"nop",IMPLIED,1,NULL OP_LDY_ABS,"ldy",ABSOLUTE,3,NULL diff --git a/src/emulation.c b/src/emulation.c index 0f72e46..749bf0a 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -2,12 +2,25 @@ #include "emulation.h" +void +emul_lda(rk65c02emu_t *e, instruction_t *i) +{ + instrdef_t id; + + id = instruction_decode(i->opcode); + + printf("A: %x", e->regs.A); + + e->regs.A = i->op1; + + printf("A: %x", e->regs.A); + +} + void emul_nop(rk65c02emu_t *e, instruction_t *i) { - printf("nop!\n"); - printf("nop!\n"); - printf("nop!\n"); + /* printf("nop!\n"); */ } void @@ -15,3 +28,4 @@ emul_stp(rk65c02emu_t *e, instruction_t *i) { e->state = STOPPED; } + diff --git a/src/emulation.h b/src/emulation.h index e65562c..afef57d 100644 --- a/src/emulation.h +++ b/src/emulation.h @@ -4,6 +4,7 @@ #include "rk65c02.h" #include "instruction.h" +void emul_lda(rk65c02emu_t *, instruction_t *); void emul_nop(rk65c02emu_t *, instruction_t *); void emul_stp(rk65c02emu_t *, instruction_t *); diff --git a/test/test_emulation.c b/test/test_emulation.c index 2771cee..3005e5f 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -6,8 +6,8 @@ #include "bus.h" #include "rk65c02.h" -ATF_TC_WITHOUT_HEAD(emulation_nop); -ATF_TC_BODY(emulation_nop, tc) +ATF_TC_WITHOUT_HEAD(emul_lda); +ATF_TC_BODY(emul_lda, tc) { rk65c02emu_t e; bus_t b; @@ -17,19 +17,43 @@ ATF_TC_BODY(emulation_nop, tc) e.regs.PC = 0; - bus_write_1(&b, 0, 0xEA); - bus_write_1(&b, 1, 0xDB); + bus_write_1(&b, 0, 0xA9); + bus_write_1(&b, 1, 0xAF); + bus_write_1(&b, 2, 0xDB); rk65c02_start(&e); - ATF_CHECK(e.regs.PC == 2); + ATF_CHECK(e.regs.PC == 3); + ATF_CHECK(e.regs.A == 0xAF); + + bus_finish(&b); +} + +ATF_TC_WITHOUT_HEAD(emul_nop); +ATF_TC_BODY(emul_nop, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init(); + e = rk65c02_init(&b); + + e.regs.PC = 0xC000; + + bus_write_1(&b, 0xC000, 0xEA); + bus_write_1(&b, 0xC001, 0xDB); + + rk65c02_start(&e); + + ATF_CHECK(e.regs.PC == 0xC002); bus_finish(&b); } ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, emulation_nop); + ATF_TP_ADD_TC(tp, emul_lda); + ATF_TP_ADD_TC(tp, emul_nop); return (atf_no_error()); }