From fb7d4b28e78cda673072514de2bc33d673196dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Sun, 22 Jan 2017 22:35:50 +0100 Subject: [PATCH] Add DEX, DEY emulation and test cases for them. --- src/65c02isa.csv | 4 ++-- src/emulation.c | 20 ++++++++++++++++++++ test/Makefile | 1 + test/test_emulation.c | 29 +++++++++++++++++++++++++++++ test/test_emulation_dex.s | 3 +++ test/test_emulation_dey.s | 3 +++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 test/test_emulation_dex.s create mode 100644 test/test_emulation_dey.s diff --git a/src/65c02isa.csv b/src/65c02isa.csv index 08503c4..02c9d4f 100644 --- a/src/65c02isa.csv +++ b/src/65c02isa.csv @@ -135,7 +135,7 @@ OP_STY_ZP,"sty",ZP,2,NULL OP_STA_ZP,"sta",ZP,2,NULL OP_STX_ZP,"stx",ZP,2,NULL OP_SMB0_ZP,"smb0",ZP,2,NULL -OP_DEY,"dey",IMPLIED,1,NULL +OP_DEY,"dey",IMPLIED,1,emul_dey OP_BIT_IMM,"bit",IMMEDIATE,2,NULL OP_TXA,"txa",IMPLIED,1,NULL OP_NOPI_8C,"nop",IMPLIED,1,NULL @@ -201,7 +201,7 @@ OP_DEC_ZP,"dec",ZP,2,NULL OP_SMB4_ZP,"smb4",ZP,2,NULL OP_INY,"iny",IMPLIED,1,emul_iny OP_CMP_IMM,"cmp",IMMEDIATE,2,NULL -OP_DEX,"dex",IMPLIED,1,NULL +OP_DEX,"dex",IMPLIED,1,emul_dex OP_WAI,"wai",IMPLIED,1,NULL OP_CPY_ABS,"cpy",ABSOLUTE,3,NULL OP_CMP_ABS,"cmp",ABSOLUTE,3,NULL diff --git a/src/emulation.c b/src/emulation.c index 4ecfa2d..2366c47 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -22,6 +22,26 @@ emul_clc(rk65c02emu_t *e, void *id, instruction_t *i) e->regs.P &= ~P_CARRY; } +/* DNX - decrement X */ +void +emul_dex(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); +} + +/* DNY - decrement Y */ +void +emul_dey(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); +} + /* INX - increment X */ void emul_inx(rk65c02emu_t *e, void *id, instruction_t *i) diff --git a/test/Makefile b/test/Makefile index c96e6b8..86f4e66 100644 --- a/test/Makefile +++ b/test/Makefile @@ -7,6 +7,7 @@ VASMFLAGS=-Fbin -c02 TESTS=test_bus test_emulation TESTROMS=test_emulation_and_imm.rom \ test_emulation_clc.rom test_emulation_sec.rom \ + test_emulation_dex.rom test_emulation_dey.rom \ test_emulation_inx.rom test_emulation_iny.rom \ test_emulation_pha.rom test_emulation_pla.rom \ test_emulation_nop.rom \ diff --git a/test/test_emulation.c b/test/test_emulation.c index 2a7983a..7bc4319 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -22,6 +22,34 @@ rom_start(rk65c02emu_t *e, const char *name) return true; } +ATF_TC_WITHOUT_HEAD(emul_dex_dey); +ATF_TC_BODY(emul_dex_dey, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init(); + e = rk65c02_init(&b); + + /* DEX */ + e.regs.X = 0x1; + ATF_REQUIRE(rom_start(&e, "test_emulation_dex.rom")); + ATF_CHECK(e.regs.X == 0x0); + /* DEX underflow */ + ATF_REQUIRE(rom_start(&e, "test_emulation_dex.rom")); + ATF_CHECK(e.regs.X == 0xFF); + + /* DEY */ + e.regs.Y = 0x1; + ATF_REQUIRE(rom_start(&e, "test_emulation_dey.rom")); + ATF_CHECK(e.regs.Y == 0x0); + /* DEY underflow */ + ATF_REQUIRE(rom_start(&e, "test_emulation_dey.rom")); + ATF_CHECK(e.regs.Y == 0xFF); + + bus_finish(&b); +} + ATF_TC_WITHOUT_HEAD(emul_inx_iny); ATF_TC_BODY(emul_inx_iny, tc) { @@ -199,6 +227,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_dex_dey); ATF_TP_ADD_TC(tp, emul_clc_sec); ATF_TP_ADD_TC(tp, emul_inx_iny); ATF_TP_ADD_TC(tp, emul_lda); diff --git a/test/test_emulation_dex.s b/test/test_emulation_dex.s new file mode 100644 index 0000000..dbb3161 --- /dev/null +++ b/test/test_emulation_dex.s @@ -0,0 +1,3 @@ +start: dex + stp + diff --git a/test/test_emulation_dey.s b/test/test_emulation_dey.s new file mode 100644 index 0000000..67475ed --- /dev/null +++ b/test/test_emulation_dey.s @@ -0,0 +1,3 @@ +start: dey + stp +