1
0
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:
Radosław Kujawa 2017-01-22 23:01:24 +01:00
parent 074ecdccc3
commit 5eede9333b
7 changed files with 54 additions and 3 deletions

View File

@ -7,7 +7,7 @@ OP_TSB_ZP,"tsb",ZP,2,NULL
OP_ORA_ZP,"ora",ZP,2,NULL OP_ORA_ZP,"ora",ZP,2,NULL
OP_ASL_ZP,"asl",ZP,2,NULL OP_ASL_ZP,"asl",ZP,2,NULL
OP_RMB0_ZP,"rmb0",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_ORA_IMM,"ora",IMMEDIATE,2,NULL
OP_ASL,"asl",ACCUMULATOR,1,NULL OP_ASL,"asl",ACCUMULATOR,1,NULL
OP_NOPI_C,"nop",IMPLIED,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_AND_ZP,"and",ZP,2,emul_and
OP_ROL_ZP,"rol",ZP,2,NULL OP_ROL_ZP,"rol",ZP,2,NULL
OP_RMB2_ZP,"rmb2",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_AND_IMM,"and",IMMEDIATE,2,emul_and
OP_ROL,"rol",ACCUMULATOR,1,NULL OP_ROL,"rol",ACCUMULATOR,1,NULL
OP_NOPI_2C,"nop",IMPLIED,1,NULL OP_NOPI_2C,"nop",IMPLIED,1,NULL

1 opcode_id mnemonic addressing size emulation
7 OP_ORA_ZP ora ZP 2 NULL
8 OP_ASL_ZP asl ZP 2 NULL
9 OP_RMB0_ZP rmb0 ZP 2 NULL
10 OP_PHP php IMPLIED 1 NULL emul_php
11 OP_ORA_IMM ora IMMEDIATE 2 NULL
12 OP_ASL asl ACCUMULATOR 1 NULL
13 OP_NOPI_C nop IMPLIED 1 NULL
39 OP_AND_ZP and ZP 2 emul_and
40 OP_ROL_ZP rol ZP 2 NULL
41 OP_RMB2_ZP rmb2 ZP 2 NULL
42 OP_PLP plp IMPLIED 1 NULL emul_plp
43 OP_AND_IMM and IMMEDIATE 2 emul_and
44 OP_ROL rol ACCUMULATOR 1 NULL
45 OP_NOPI_2C nop IMPLIED 1 NULL

View File

@ -85,6 +85,13 @@ emul_pha(rk65c02emu_t *e, void *id, instruction_t *i)
stack_push(e, e->regs.A); 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 */ /* PLA - pull from stack to accumulator */
void void
emul_pla(rk65c02emu_t *e, void *id, instruction_t *i) 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); 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 */ /* SEC - set the carry flag */
void void
emul_sec(rk65c02emu_t *e, void *id, instruction_t *i) emul_sec(rk65c02emu_t *e, void *id, instruction_t *i)

View File

@ -17,6 +17,7 @@ rk65c02_init(bus_t *b)
e.bus = b; e.bus = b;
e.state = STOPPED; e.state = STOPPED;
e.regs.P = P_UNDEFINED;
return e; return e;
} }

View File

@ -10,6 +10,7 @@ TESTROMS=test_emulation_and_imm.rom \
test_emulation_dex.rom test_emulation_dey.rom \ test_emulation_dex.rom test_emulation_dey.rom \
test_emulation_inx.rom test_emulation_iny.rom \ test_emulation_inx.rom test_emulation_iny.rom \
test_emulation_pha.rom test_emulation_pla.rom \ test_emulation_pha.rom test_emulation_pla.rom \
test_emulation_php.rom test_emulation_plp.rom \
test_emulation_nop.rom \ test_emulation_nop.rom \
test_emulation_lda_imm.rom test_emulation_lda_zp.rom \ test_emulation_lda_imm.rom test_emulation_lda_zp.rom \
test_emulation_stz_zp.rom test_emulation_stz_zp.rom

View File

@ -224,6 +224,35 @@ ATF_TC_BODY(emul_stack, tc)
bus_finish(&b); 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_TCS(tp)
{ {
ATF_TP_ADD_TC(tp, emul_and); 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_lda);
ATF_TP_ADD_TC(tp, emul_nop); ATF_TP_ADD_TC(tp, emul_nop);
ATF_TP_ADD_TC(tp, emul_stz); ATF_TP_ADD_TC(tp, emul_stz);
ATF_TP_ADD_TC(tp, emul_php_plp);
ATF_TP_ADD_TC(tp, emul_stack); ATF_TP_ADD_TC(tp, emul_stack);
return (atf_no_error()); return (atf_no_error());

View File

@ -0,0 +1,3 @@
start: php
stp

View File

@ -0,0 +1,3 @@
start: plp
stp