1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-06-12 00:29:32 +00:00

Add INX, INY emulation and test cases.

Some comments while here.
This commit is contained in:
Radosław Kujawa 2017-01-22 13:07:21 +01:00
parent e763ca0d3a
commit 473e0e2636
7 changed files with 64 additions and 2 deletions

View File

@ -199,7 +199,7 @@ OP_CPY_ZP,"cpy",ZP,2,NULL
OP_CMP_ZP,"cmp",ZP,2,NULL
OP_DEC_ZP,"dec",ZP,2,NULL
OP_SMB4_ZP,"smb4",ZP,2,NULL
OP_INY,"iny",IMPLIED,1,NULL
OP_INY,"iny",IMPLIED,1,emul_iny
OP_CMP_IMM,"cmp",IMMEDIATE,2,NULL
OP_DEX,"dex",IMPLIED,1,NULL
OP_WAI,"wai",IMPLIED,1,NULL
@ -231,7 +231,7 @@ OP_CPX_ZP,"cpx",ZP,2,NULL
OP_SBC_ZP,"sbc",ZP,2,NULL
OP_INC_ZP,"inc",ZP,2,NULL
OP_SMB6_ZP,"smb6",ZP,2,NULL
OP_INX,"inx",IMPLIED,1,NULL
OP_INX,"inx",IMPLIED,1,emul_inx
OP_SBC_IMM,"sbc",IMMEDIATE,2,NULL
OP_NOP,"nop",IMPLIED,1,emul_nop
OP_NOPI_EC,"nop",IMPLIED,1,NULL

1 opcode_id mnemonic addressing size emulation
199 OP_CMP_ZP cmp ZP 2 NULL
200 OP_DEC_ZP dec ZP 2 NULL
201 OP_SMB4_ZP smb4 ZP 2 NULL
202 OP_INY iny IMPLIED 1 NULL emul_iny
203 OP_CMP_IMM cmp IMMEDIATE 2 NULL
204 OP_DEX dex IMPLIED 1 NULL
205 OP_WAI wai IMPLIED 1 NULL
231 OP_SBC_ZP sbc ZP 2 NULL
232 OP_INC_ZP inc ZP 2 NULL
233 OP_SMB6_ZP smb6 ZP 2 NULL
234 OP_INX inx IMPLIED 1 NULL emul_inx
235 OP_SBC_IMM sbc IMMEDIATE 2 NULL
236 OP_NOP nop IMPLIED 1 emul_nop
237 OP_NOPI_EC nop IMPLIED 1 NULL

View File

@ -15,6 +15,26 @@ emul_and(rk65c02emu_t *e, void *id, instruction_t *i)
instruction_status_adjust_negative(e, e->regs.A);
}
/* INX - increment X */
void
emul_inx(rk65c02emu_t *e, void *id, instruction_t *i)
{
e->regs.X++;
instruction_status_adjust_zero(e, e->regs.X);
instruction_status_adjust_negative(e, e->regs.X);
}
/* INY - increment Y */
void
emul_iny(rk65c02emu_t *e, void *id, instruction_t *i)
{
e->regs.Y++;
instruction_status_adjust_zero(e, e->regs.Y);
instruction_status_adjust_negative(e, e->regs.Y);
}
/* LDA - load to accumulator */
void
emul_lda(rk65c02emu_t *e, void *id, instruction_t *i)

View File

@ -28,7 +28,11 @@ rk65c02_start(rk65c02emu_t *e) {
e->state = RUNNING;
while (e->state == RUNNING) {
/* XXX: handle breakpoints and watch points */
/* if disassembly-when-running enabled */
disassemble(e->bus, e->regs.PC);
i = instruction_fetch(e->bus, e->regs.PC);
id = instruction_decode(i.opcode);

View File

@ -6,6 +6,7 @@ VASMFLAGS=-Fbin -c02
TESTS=test_bus test_emulation
TESTROMS=test_emulation_and_imm.rom \
test_emulation_inx.rom test_emulation_iny.rom \
test_emulation_pha.rom test_emulation_pla.rom \
test_emulation_nop.rom \
test_emulation_lda_imm.rom test_emulation_lda_zp.rom \

View File

@ -22,6 +22,36 @@ rom_start(rk65c02emu_t *e, const char *name)
return true;
}
ATF_TC_WITHOUT_HEAD(emul_inx_iny);
ATF_TC_BODY(emul_inx_iny, tc)
{
rk65c02emu_t e;
bus_t b;
b = bus_init();
e = rk65c02_init(&b);
/* INX */
e.regs.X = 0;
ATF_REQUIRE(rom_start(&e, "test_emulation_inx.rom"));
ATF_CHECK(e.regs.X == 0x1);
/* INX overflow */
e.regs.X = 0xFF;
ATF_REQUIRE(rom_start(&e, "test_emulation_inx.rom"));
ATF_CHECK(e.regs.X == 0x0);
/* INY */
e.regs.Y = 0;
ATF_REQUIRE(rom_start(&e, "test_emulation_iny.rom"));
ATF_CHECK(e.regs.Y == 0x1);
/* INY overflow */
e.regs.Y = 0xFF;
ATF_REQUIRE(rom_start(&e, "test_emulation_iny.rom"));
ATF_CHECK(e.regs.Y == 0x0);
bus_finish(&b);
}
ATF_TC_WITHOUT_HEAD(emul_lda);
ATF_TC_BODY(emul_lda, tc)
{
@ -149,6 +179,7 @@ ATF_TC_BODY(emul_stack, tc)
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, emul_and);
ATF_TP_ADD_TC(tp, emul_inx_iny);
ATF_TP_ADD_TC(tp, emul_lda);
ATF_TP_ADD_TC(tp, emul_nop);
ATF_TP_ADD_TC(tp, emul_stz);

View File

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

View File

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