From 13ef3e2d0826337356d241e27399d08d96a0760a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Wed, 25 Jan 2017 13:14:00 +0100 Subject: [PATCH] Add PHX, PLX, PHY, PLY emulation and test cases. --- src/65c02isa.csv | 8 +++---- src/emulation.c | 28 +++++++++++++++++++++++ test/test_emulation.c | 47 +++++++++++++++++++++++++++++++++++++++ test/test_emulation_phx.s | 3 +++ test/test_emulation_phy.s | 3 +++ test/test_emulation_plx.s | 3 +++ test/test_emulation_ply.s | 3 +++ 7 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 test/test_emulation_phx.s create mode 100644 test/test_emulation_phy.s create mode 100644 test/test_emulation_plx.s create mode 100644 test/test_emulation_ply.s diff --git a/src/65c02isa.csv b/src/65c02isa.csv index c602e34..fd3f4df 100644 --- a/src/65c02isa.csv +++ b/src/65c02isa.csv @@ -89,7 +89,7 @@ OP_LSR_ZPX,"lsr",ZPX,2,NULL OP_RMB5_ZP,"rmb5",ZP,2,NULL OP_CLI,"cli",IMPLIED,1,NULL OP_EOR_ABSY,"eor",ABSOLUTEY,3,emul_eor -OP_PHY,"phy",IMPLIED,1,NULL +OP_PHY,"phy",IMPLIED,1,emul_phy OP_NOPI_5C,"nop",IMPLIED,1,NULL OP_NOPI_5D,"nop",ABSOLUTE,3,NULL OP_EOR_ABSX,"eor",ABSOLUTEX,3,emul_eor @@ -121,7 +121,7 @@ OP_ROR_ZPX,"ror",ZPX,2,emul_ror OP_RMB7_ZP,"rmb7",ZP,2,NULL OP_SEI,"sei",IMPLIED,1,NULL OP_ADC_ABSY,"adc",ABSOLUTEY,3,NULL -OP_PLY,"ply",IMPLIED,1,NULL +OP_PLY,"ply",IMPLIED,1,emul_ply OP_NOPI_7C,"nop",IMPLIED,1,NULL OP_JMP_IABSX,"jmp",IABSOLUTEX,3,NULL OP_ADC_ABSX,"adc",ABSOLUTEX,3,NULL @@ -217,7 +217,7 @@ OP_DEC_ZPX,"dec",ZPX,2,NULL OP_SMB5_ZP,"smb5",ZP,2,NULL OP_CLD,"cld",IMPLIED,1,NULL OP_CMP_ABSY,"cmp",ABSOLUTEY,3,NULL -OP_PHX,"phx",IMPLIED,1,NULL +OP_PHX,"phx",IMPLIED,1,emul_phx OP_STP,"stp",IMPLIED,1,emul_stp OP_NOPI_DD,"nop",ABSOLUTE,3,NULL OP_CMP_ABSX,"cmp",ABSOLUTEX,3,NULL @@ -249,7 +249,7 @@ OP_INC_ZPX,"inc",ZPX,2,NULL OP_SMB7_ZP,"smb7",ZP,2,NULL OP_SED,"sed",IMPLIED,1,NULL OP_SBC_ABSY,"sbc",ABSOLUTEY,3,NULL -OP_PLX,"plx",IMPLIED,1,NULL +OP_PLX,"plx",IMPLIED,1,emul_plx OP_NOPI_FC,"nop",IMPLIED,1,NULL OP_NOPI_FD,"nop",ABSOLUTE,3,NULL OP_SBC_ABSX,"sbc",ABSOLUTEX,3,NULL diff --git a/src/emulation.c b/src/emulation.c index 5d70c81..97ba34d 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -153,6 +153,20 @@ emul_php(rk65c02emu_t *e, void *id, instruction_t *i) stack_push(e, e->regs.P); } +/* PHX - push X to stack */ +void +emul_phx(rk65c02emu_t *e, void *id, instruction_t *i) +{ + stack_push(e, e->regs.X); +} + +/* PHY - push Y to stack */ +void +emul_phy(rk65c02emu_t *e, void *id, instruction_t *i) +{ + stack_push(e, e->regs.Y); +} + /* PLA - pull from stack to accumulator */ void emul_pla(rk65c02emu_t *e, void *id, instruction_t *i) @@ -170,6 +184,20 @@ emul_plp(rk65c02emu_t *e, void *id, instruction_t *i) e->regs.P = stack_pop(e) | P_UNDEFINED; } +/* PLX - pull from stack to X */ +void +emul_plx(rk65c02emu_t *e, void *id, instruction_t *i) +{ + e->regs.X = stack_pop(e); +} + +/* PLY - pull from stack to X */ +void +emul_ply(rk65c02emu_t *e, void *id, instruction_t *i) +{ + e->regs.Y = stack_pop(e); +} + /* ROL - rotate left */ void emul_rol(rk65c02emu_t *e, void *id, instruction_t *i) diff --git a/test/test_emulation.c b/test/test_emulation.c index 696e31d..3d59293 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -470,6 +470,52 @@ ATF_TC_BODY(emul_php_plp, tc) bus_finish(&b); } +ATF_TC_WITHOUT_HEAD(emul_phx_phy_plx_ply); +ATF_TC_BODY(emul_phx_phy_plx_ply, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init(); + e = rk65c02_init(&b); + + /* check push X to stack */ + e.regs.X = 0xAA; + e.regs.SP = 0xFF; + + ATF_REQUIRE(rom_start(&e, "test_emulation_phx.rom")); + + ATF_CHECK(e.regs.SP == 0xFE); + ATF_CHECK(bus_read_1(e.bus, STACK_END) == 0xAA); + + /* check pull X from stack */ + e.regs.X = 0; + + ATF_REQUIRE(rom_start(&e, "test_emulation_plx.rom")); + + ATF_CHECK(e.regs.SP == 0xFF); + ATF_CHECK(e.regs.X == 0xAA); + + /* check push Y to stack */ + e.regs.Y = 0x55; + e.regs.SP = 0xFF; + + ATF_REQUIRE(rom_start(&e, "test_emulation_phy.rom")); + + ATF_CHECK(e.regs.SP == 0xFE); + ATF_CHECK(bus_read_1(e.bus, STACK_END) == 0x55); + + /* check pull X from stack */ + e.regs.Y = 0xFF; + + ATF_REQUIRE(rom_start(&e, "test_emulation_ply.rom")); + + ATF_CHECK(e.regs.SP == 0xFF); + ATF_CHECK(e.regs.Y == 0x55); + + bus_finish(&b); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, emul_and); @@ -482,6 +528,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, emul_ora); ATF_TP_ADD_TC(tp, emul_stz); ATF_TP_ADD_TC(tp, emul_php_plp); + ATF_TP_ADD_TC(tp, emul_phx_phy_plx_ply); ATF_TP_ADD_TC(tp, emul_stack); ATF_TP_ADD_TC(tp, emul_txa_tya_tax_tay); ATF_TP_ADD_TC(tp, emul_sta); diff --git a/test/test_emulation_phx.s b/test/test_emulation_phx.s new file mode 100644 index 0000000..7828f4c --- /dev/null +++ b/test/test_emulation_phx.s @@ -0,0 +1,3 @@ +start: phx + stp + diff --git a/test/test_emulation_phy.s b/test/test_emulation_phy.s new file mode 100644 index 0000000..1306baa --- /dev/null +++ b/test/test_emulation_phy.s @@ -0,0 +1,3 @@ +start: phy + stp + diff --git a/test/test_emulation_plx.s b/test/test_emulation_plx.s new file mode 100644 index 0000000..81eb23a --- /dev/null +++ b/test/test_emulation_plx.s @@ -0,0 +1,3 @@ +start: plx + stp + diff --git a/test/test_emulation_ply.s b/test/test_emulation_ply.s new file mode 100644 index 0000000..db01602 --- /dev/null +++ b/test/test_emulation_ply.s @@ -0,0 +1,3 @@ +start: ply + stp +