mirror of
https://github.com/rkujawa/rk65c02.git
synced 2024-12-04 04:51:27 +00:00
Add emulation of PHP, PLP instructions and test cases for them.
This commit is contained in:
parent
074ecdccc3
commit
5eede9333b
@ -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
|
||||
|
|
@ -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)
|
||||
|
@ -17,6 +17,7 @@ rk65c02_init(bus_t *b)
|
||||
|
||||
e.bus = b;
|
||||
e.state = STOPPED;
|
||||
e.regs.P = P_UNDEFINED;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
|
3
test/test_emulation_php.s
Normal file
3
test/test_emulation_php.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: php
|
||||
stp
|
||||
|
3
test/test_emulation_plp.s
Normal file
3
test/test_emulation_plp.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: plp
|
||||
stp
|
||||
|
Loading…
Reference in New Issue
Block a user