From f3205e72723418bb4b5223ffb7d50d5d37339ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kujawa?= Date: Sat, 28 Jan 2017 11:19:34 +0100 Subject: [PATCH] Add CLI and SEI emulation and test case. --- src/65c02isa.csv | 4 ++-- src/emulation.c | 14 ++++++++++++++ test/test_emulation.c | 20 ++++++++++++++++++++ test/test_emulation_cli.s | 3 +++ test/test_emulation_sei.s | 3 +++ 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/test_emulation_cli.s create mode 100644 test/test_emulation_sei.s diff --git a/src/65c02isa.csv b/src/65c02isa.csv index 6bca62f..07ef7dc 100644 --- a/src/65c02isa.csv +++ b/src/65c02isa.csv @@ -87,7 +87,7 @@ OP_NOPI_55,"nop",ZPX,2,NULL,false OP_EOR_ZPX,"eor",ZPX,2,emul_eor,false OP_LSR_ZPX,"lsr",ZPX,2,emul_lsr,false OP_RMB5_ZP,"rmb5",ZP,2,emul_rmb5,false -OP_CLI,"cli",IMPLIED,1,NULL,false +OP_CLI,"cli",IMPLIED,1,emul_cli,false OP_EOR_ABSY,"eor",ABSOLUTEY,3,emul_eor,false OP_PHY,"phy",IMPLIED,1,emul_phy,false OP_NOPI_5C,"nop",IMPLIED,1,NULL,false @@ -119,7 +119,7 @@ OP_STZ_ZPX,"stz",ZPX,2,emul_stz,false OP_ADC_ZPX,"adc",ZPX,2,NULL,false OP_ROR_ZPX,"ror",ZPX,2,emul_ror,false OP_RMB7_ZP,"rmb7",ZP,2,emul_rmb7,false -OP_SEI,"sei",IMPLIED,1,NULL,false +OP_SEI,"sei",IMPLIED,1,emul_sei,false OP_ADC_ABSY,"adc",ABSOLUTEY,3,NULL,false OP_PLY,"ply",IMPLIED,1,emul_ply,false OP_NOPI_7C,"nop",IMPLIED,1,NULL,false diff --git a/src/emulation.c b/src/emulation.c index e0bb186..04c3cd7 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -72,6 +72,13 @@ emul_clc(rk65c02emu_t *e, void *id, instruction_t *i) e->regs.P &= ~P_CARRY; } +/* CLI - clear interrupt disable flag */ +void +emul_cli(rk65c02emu_t *e, void *id, instruction_t *i) +{ + e->regs.P &= ~P_IRQ_DISABLE; +} + /* CLV - clear overflow flag */ void emul_clv(rk65c02emu_t *e, void *id, instruction_t *i) @@ -446,6 +453,13 @@ emul_sec(rk65c02emu_t *e, void *id, instruction_t *i) e->regs.P |= P_CARRY; } +/* SEI - set the interrupt disable flag */ +void +emul_sei(rk65c02emu_t *e, void *id, instruction_t *i) +{ + e->regs.P |= P_IRQ_DISABLE; +} + /* STP - stop the processor */ void emul_stp(rk65c02emu_t *e, void *id, instruction_t *i) diff --git a/test/test_emulation.c b/test/test_emulation.c index 202eeda..5775f66 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -324,6 +324,25 @@ ATF_TC_BODY(emul_clc_sec, tc) bus_finish(&b); } +ATF_TC_WITHOUT_HEAD(emul_cli_sei); +ATF_TC_BODY(emul_cli_sei, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init(); + e = rk65c02_init(&b); + + /* CLI */ + ATF_REQUIRE(rom_start(&e, "test_emulation_cli.rom", tc)); + ATF_CHECK(!(e.regs.P & P_IRQ_DISABLE)); + /* SEI */ + ATF_REQUIRE(rom_start(&e, "test_emulation_sei.rom", tc)); + ATF_CHECK(e.regs.P & P_IRQ_DISABLE); + + bus_finish(&b); +} + ATF_TC_WITHOUT_HEAD(emul_and); ATF_TC_BODY(emul_and, tc) { @@ -682,6 +701,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, emul_dec); ATF_TP_ADD_TC(tp, emul_dex_dey); ATF_TP_ADD_TC(tp, emul_clc_sec); + ATF_TP_ADD_TC(tp, emul_cli_sei); ATF_TP_ADD_TC(tp, emul_clv); ATF_TP_ADD_TC(tp, emul_inc); ATF_TP_ADD_TC(tp, emul_inx_iny); diff --git a/test/test_emulation_cli.s b/test/test_emulation_cli.s new file mode 100644 index 0000000..c061932 --- /dev/null +++ b/test/test_emulation_cli.s @@ -0,0 +1,3 @@ +start: cli + stp + diff --git a/test/test_emulation_sei.s b/test/test_emulation_sei.s new file mode 100644 index 0000000..7050152 --- /dev/null +++ b/test/test_emulation_sei.s @@ -0,0 +1,3 @@ +start: sei + stp +