diff --git a/src/65c02isa.csv b/src/65c02isa.csv index fcc0591..8162b9b 100644 --- a/src/65c02isa.csv +++ b/src/65c02isa.csv @@ -7,7 +7,7 @@ OP_TSB_ZP,"tsb",ZP,2,NULL OP_ORA_ZP,"ora",ZP,2,NULL OP_ASL_ZP,"asl",ZP,2,NULL OP_RMB0_ZP,"rmb0",ZP,2,NULL -OP_PHP,"php",IMPLIED,1,NULL +OP_PHP,"php",IMPLIED,1,emul_php OP_ORA_IMM,"ora",IMMEDIATE,2,NULL OP_ASL,"asl",ACCUMULATOR,1,NULL OP_NOPI_C,"nop",IMPLIED,1,NULL @@ -39,7 +39,7 @@ OP_BIT_ZP,"bit",ZP,2,NULL OP_AND_ZP,"and",ZP,2,emul_and OP_ROL_ZP,"rol",ZP,2,NULL OP_RMB2_ZP,"rmb2",ZP,2,NULL -OP_PLP,"plp",IMPLIED,1,NULL +OP_PLP,"plp",IMPLIED,1,emul_plp OP_AND_IMM,"and",IMMEDIATE,2,emul_and OP_ROL,"rol",ACCUMULATOR,1,NULL OP_NOPI_2C,"nop",IMPLIED,1,NULL diff --git a/src/emulation.c b/src/emulation.c index 2366c47..4ff5e41 100644 --- a/src/emulation.c +++ b/src/emulation.c @@ -85,6 +85,13 @@ emul_pha(rk65c02emu_t *e, void *id, instruction_t *i) stack_push(e, e->regs.A); } +/* PHP - push processor flags to stack */ +void +emul_php(rk65c02emu_t *e, void *id, instruction_t *i) +{ + stack_push(e, e->regs.P); +} + /* PLA - pull from stack to accumulator */ void emul_pla(rk65c02emu_t *e, void *id, instruction_t *i) @@ -95,6 +102,13 @@ emul_pla(rk65c02emu_t *e, void *id, instruction_t *i) instruction_status_adjust_negative(e, e->regs.A); } +/* PLA - pull from stack to processor flags */ +void +emul_plp(rk65c02emu_t *e, void *id, instruction_t *i) +{ + e->regs.P = stack_pop(e) | P_UNDEFINED; +} + /* SEC - set the carry flag */ void emul_sec(rk65c02emu_t *e, void *id, instruction_t *i) diff --git a/src/rk65c02.c b/src/rk65c02.c index a64ec1b..77be08b 100644 --- a/src/rk65c02.c +++ b/src/rk65c02.c @@ -17,6 +17,7 @@ rk65c02_init(bus_t *b) e.bus = b; e.state = STOPPED; + e.regs.P = P_UNDEFINED; return e; } diff --git a/test/Makefile b/test/Makefile index 86f4e66..afcd293 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,6 +10,7 @@ TESTROMS=test_emulation_and_imm.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_php.rom test_emulation_plp.rom \ test_emulation_nop.rom \ test_emulation_lda_imm.rom test_emulation_lda_zp.rom \ test_emulation_stz_zp.rom diff --git a/test/test_emulation.c b/test/test_emulation.c index 7bc4319..ebb5963 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -224,6 +224,35 @@ ATF_TC_BODY(emul_stack, tc) bus_finish(&b); } +ATF_TC_WITHOUT_HEAD(emul_php_plp); +ATF_TC_BODY(emul_php_plp, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init(); + e = rk65c02_init(&b); + + e.regs.SP = 0xFF; + e.regs.P |= P_CARRY|P_ZERO|P_UNDEFINED; + + ATF_REQUIRE(rom_start(&e, "test_emulation_php.rom")); + + ATF_CHECK(e.regs.SP == 0xFE); + ATF_CHECK(bus_read_1(e.bus, STACK_END) == (P_CARRY|P_ZERO|P_UNDEFINED)); + + /* + * Now let's see if loading back into accumulator works. + */ + bus_write_1(e.bus, STACK_END, P_CARRY|P_DECIMAL); + ATF_REQUIRE(rom_start(&e, "test_emulation_plp.rom")); + + ATF_CHECK(e.regs.SP == 0xFF); + ATF_CHECK(e.regs.P == (P_CARRY|P_DECIMAL|P_UNDEFINED)); + + bus_finish(&b); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, emul_and); @@ -233,7 +262,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, emul_lda); ATF_TP_ADD_TC(tp, emul_nop); ATF_TP_ADD_TC(tp, emul_stz); - + ATF_TP_ADD_TC(tp, emul_php_plp); ATF_TP_ADD_TC(tp, emul_stack); return (atf_no_error()); diff --git a/test/test_emulation_php.s b/test/test_emulation_php.s new file mode 100644 index 0000000..2dbbc60 --- /dev/null +++ b/test/test_emulation_php.s @@ -0,0 +1,3 @@ +start: php + stp + diff --git a/test/test_emulation_plp.s b/test/test_emulation_plp.s new file mode 100644 index 0000000..212c1fa --- /dev/null +++ b/test/test_emulation_plp.s @@ -0,0 +1,3 @@ +start: plp + stp +