From 473e0e2636f6649c7c123981caf2d1f394733eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Sun, 22 Jan 2017 13:07:21 +0100 Subject: [PATCH] Add INX, INY emulation and test cases. Some comments while here. --- src/65c02isa.csv | 4 ++-- src/emulation.c | 20 ++++++++++++++++++++ src/rk65c02.c | 4 ++++ test/Makefile | 1 + test/test_emulation.c | 31 +++++++++++++++++++++++++++++++ test/test_emulation_inx.s | 3 +++ test/test_emulation_iny.s | 3 +++ 7 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 test/test_emulation_inx.s create mode 100644 test/test_emulation_iny.s diff --git a/src/65c02isa.csv b/src/65c02isa.csv index 7536420..fd038fa 100644 --- a/src/65c02isa.csv +++ b/src/65c02isa.csv @@ -199,7 +199,7 @@ OP_CPY_ZP,"cpy",ZP,2,NULL OP_CMP_ZP,"cmp",ZP,2,NULL OP_DEC_ZP,"dec",ZP,2,NULL OP_SMB4_ZP,"smb4",ZP,2,NULL -OP_INY,"iny",IMPLIED,1,NULL +OP_INY,"iny",IMPLIED,1,emul_iny OP_CMP_IMM,"cmp",IMMEDIATE,2,NULL OP_DEX,"dex",IMPLIED,1,NULL OP_WAI,"wai",IMPLIED,1,NULL @@ -231,7 +231,7 @@ OP_CPX_ZP,"cpx",ZP,2,NULL OP_SBC_ZP,"sbc",ZP,2,NULL OP_INC_ZP,"inc",ZP,2,NULL OP_SMB6_ZP,"smb6",ZP,2,NULL -OP_INX,"inx",IMPLIED,1,NULL +OP_INX,"inx",IMPLIED,1,emul_inx OP_SBC_IMM,"sbc",IMMEDIATE,2,NULL OP_NOP,"nop",IMPLIED,1,emul_nop OP_NOPI_EC,"nop",IMPLIED,1,NULL diff --git a/src/emulation.c b/src/emulation.c index 96204e3..6f18935 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -15,6 +15,26 @@ emul_and(rk65c02emu_t *e, void *id, instruction_t *i) instruction_status_adjust_negative(e, e->regs.A); } +/* INX - increment X */ +void +emul_inx(rk65c02emu_t *e, void *id, instruction_t *i) +{ + e->regs.X++; + + instruction_status_adjust_zero(e, e->regs.X); + instruction_status_adjust_negative(e, e->regs.X); +} + +/* INY - increment Y */ +void +emul_iny(rk65c02emu_t *e, void *id, instruction_t *i) +{ + e->regs.Y++; + + instruction_status_adjust_zero(e, e->regs.Y); + instruction_status_adjust_negative(e, e->regs.Y); +} + /* LDA - load to accumulator */ void emul_lda(rk65c02emu_t *e, void *id, instruction_t *i) diff --git a/src/rk65c02.c b/src/rk65c02.c index 50417d9..a64ec1b 100644 --- a/src/rk65c02.c +++ b/src/rk65c02.c @@ -28,7 +28,11 @@ rk65c02_start(rk65c02emu_t *e) { e->state = RUNNING; while (e->state == RUNNING) { + /* XXX: handle breakpoints and watch points */ + + /* if disassembly-when-running enabled */ disassemble(e->bus, e->regs.PC); + i = instruction_fetch(e->bus, e->regs.PC); id = instruction_decode(i.opcode); diff --git a/test/Makefile b/test/Makefile index e5731f3..5a96420 100644 --- a/test/Makefile +++ b/test/Makefile @@ -6,6 +6,7 @@ VASMFLAGS=-Fbin -c02 TESTS=test_bus test_emulation TESTROMS=test_emulation_and_imm.rom \ + test_emulation_inx.rom test_emulation_iny.rom \ test_emulation_pha.rom test_emulation_pla.rom \ test_emulation_nop.rom \ test_emulation_lda_imm.rom test_emulation_lda_zp.rom \ diff --git a/test/test_emulation.c b/test/test_emulation.c index de645e7..3c9982b 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -22,6 +22,36 @@ rom_start(rk65c02emu_t *e, const char *name) return true; } +ATF_TC_WITHOUT_HEAD(emul_inx_iny); +ATF_TC_BODY(emul_inx_iny, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init(); + e = rk65c02_init(&b); + + /* INX */ + e.regs.X = 0; + ATF_REQUIRE(rom_start(&e, "test_emulation_inx.rom")); + ATF_CHECK(e.regs.X == 0x1); + /* INX overflow */ + e.regs.X = 0xFF; + ATF_REQUIRE(rom_start(&e, "test_emulation_inx.rom")); + ATF_CHECK(e.regs.X == 0x0); + + /* INY */ + e.regs.Y = 0; + ATF_REQUIRE(rom_start(&e, "test_emulation_iny.rom")); + ATF_CHECK(e.regs.Y == 0x1); + /* INY overflow */ + e.regs.Y = 0xFF; + ATF_REQUIRE(rom_start(&e, "test_emulation_iny.rom")); + ATF_CHECK(e.regs.Y == 0x0); + + bus_finish(&b); +} + ATF_TC_WITHOUT_HEAD(emul_lda); ATF_TC_BODY(emul_lda, tc) { @@ -149,6 +179,7 @@ ATF_TC_BODY(emul_stack, tc) ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, emul_and); + ATF_TP_ADD_TC(tp, emul_inx_iny); ATF_TP_ADD_TC(tp, emul_lda); ATF_TP_ADD_TC(tp, emul_nop); ATF_TP_ADD_TC(tp, emul_stz); diff --git a/test/test_emulation_inx.s b/test/test_emulation_inx.s new file mode 100644 index 0000000..150facb --- /dev/null +++ b/test/test_emulation_inx.s @@ -0,0 +1,3 @@ +start: inx + stp + diff --git a/test/test_emulation_iny.s b/test/test_emulation_iny.s new file mode 100644 index 0000000..9689383 --- /dev/null +++ b/test/test_emulation_iny.s @@ -0,0 +1,3 @@ +start: iny + stp +