diff --git a/test/test_emulation.c b/test/test_emulation.c index f31ef0b..f0f897c 100644 --- a/test/test_emulation.c +++ b/test/test_emulation.c @@ -891,10 +891,128 @@ ATF_TC_BODY(emul_jsr_rts, tc) } +ATF_TC_WITHOUT_HEAD(emul_branch); +ATF_TC_BODY(emul_branch, tc) +{ + rk65c02emu_t e; + bus_t b; + + b = bus_init(); + e = rk65c02_init(&b); + + /* BCC */ + e.regs.PC = ROM_LOAD_ADDR; + ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR, + rom_path("test_emulation_bcc.rom", tc))); + + e.regs.P &= ~P_CARRY; + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC005); + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC003); + rk65c02_start(&e); + + /* BCS */ + e.regs.PC = ROM_LOAD_ADDR; + ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR, + rom_path("test_emulation_bcs.rom", tc))); + + e.regs.P |= P_CARRY; + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC005); + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC003); + rk65c02_start(&e); + + /* BRA */ + e.regs.PC = ROM_LOAD_ADDR; + ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR, + rom_path("test_emulation_bra.rom", tc))); + + rk65c02_step(&e, 1); + ATF_CHECK(e.regs.PC = 0xC004); + rk65c02_start(&e); + + /* BEQ */ + e.regs.PC = ROM_LOAD_ADDR; + ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR, + rom_path("test_emulation_beq.rom", tc))); + + e.regs.P |= P_ZERO; + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC005); + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC003); + rk65c02_start(&e); + + /* BMI */ + e.regs.PC = ROM_LOAD_ADDR; + ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR, + rom_path("test_emulation_bmi.rom", tc))); + + e.regs.P |= P_NEGATIVE; + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC005); + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC003); + rk65c02_start(&e); + + /* BNE */ + e.regs.PC = ROM_LOAD_ADDR; + ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR, + rom_path("test_emulation_bne.rom", tc))); + + e.regs.P |= P_NEGATIVE; + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC005); + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC003); + rk65c02_start(&e); + + /* BPL */ + e.regs.PC = ROM_LOAD_ADDR; + ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR, + rom_path("test_emulation_bpl.rom", tc))); + + e.regs.P &= ~P_NEGATIVE; + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC005); + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC003); + rk65c02_start(&e); + + /* BVC */ + e.regs.PC = ROM_LOAD_ADDR; + ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR, + rom_path("test_emulation_bvc.rom", tc))); + + e.regs.P &= ~P_SIGN_OVERFLOW; + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC005); + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC003); + rk65c02_start(&e); + + /* BVS */ + e.regs.PC = ROM_LOAD_ADDR; + ATF_REQUIRE(bus_load_file(&b, ROM_LOAD_ADDR, + rom_path("test_emulation_bvs.rom", tc))); + + e.regs.P |= P_SIGN_OVERFLOW; + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC005); + rk65c02_step(&e, 2); + ATF_CHECK(e.regs.PC = 0xC003); + rk65c02_start(&e); + + +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, emul_and); ATF_TP_ADD_TC(tp, emul_bit); + ATF_TP_ADD_TC(tp, emul_branch); ATF_TP_ADD_TC(tp, emul_cmp); ATF_TP_ADD_TC(tp, emul_cpx); ATF_TP_ADD_TC(tp, emul_cpy); diff --git a/test/test_emulation_bcc.s b/test/test_emulation_bcc.s new file mode 100644 index 0000000..10bee23 --- /dev/null +++ b/test/test_emulation_bcc.s @@ -0,0 +1,10 @@ +.org 0xC000 + +start: nop + bcc foo2 +foo: nop + stp +foo2: nop + bcc foo + nop + diff --git a/test/test_emulation_bcs.s b/test/test_emulation_bcs.s new file mode 100644 index 0000000..cefd736 --- /dev/null +++ b/test/test_emulation_bcs.s @@ -0,0 +1,10 @@ +.org 0xC000 + +start: nop + bcs foo2 +foo: nop + stp +foo2: nop + bcs foo + nop + diff --git a/test/test_emulation_beq.s b/test/test_emulation_beq.s new file mode 100644 index 0000000..127dd99 --- /dev/null +++ b/test/test_emulation_beq.s @@ -0,0 +1,10 @@ +.org 0xC000 + +start: nop + beq foo2 +foo: nop + stp +foo2: nop + beq foo + nop + diff --git a/test/test_emulation_bmi.s b/test/test_emulation_bmi.s new file mode 100644 index 0000000..c738d7d --- /dev/null +++ b/test/test_emulation_bmi.s @@ -0,0 +1,10 @@ +.org 0xC000 + +start: nop + bmi foo2 +foo: nop + stp +foo2: nop + bmi foo + nop + diff --git a/test/test_emulation_bne.s b/test/test_emulation_bne.s new file mode 100644 index 0000000..ff621d9 --- /dev/null +++ b/test/test_emulation_bne.s @@ -0,0 +1,10 @@ +.org 0xC000 + +start: nop + bne foo2 +foo: nop + stp +foo2: nop + bne foo + nop + diff --git a/test/test_emulation_bpl.s b/test/test_emulation_bpl.s new file mode 100644 index 0000000..d9f409e --- /dev/null +++ b/test/test_emulation_bpl.s @@ -0,0 +1,10 @@ +.org 0xC000 + +start: nop + bpl foo2 +foo: nop + stp +foo2: nop + bpl foo + nop + diff --git a/test/test_emulation_bra.s b/test/test_emulation_bra.s new file mode 100644 index 0000000..203eebd --- /dev/null +++ b/test/test_emulation_bra.s @@ -0,0 +1,9 @@ +.org 0xC000 + +start: bra foo + nop + nop +foo: nop + stp + + diff --git a/test/test_emulation_bvc.s b/test/test_emulation_bvc.s new file mode 100644 index 0000000..31fa37f --- /dev/null +++ b/test/test_emulation_bvc.s @@ -0,0 +1,10 @@ +.org 0xC000 + +start: nop + bvc foo2 +foo: nop + stp +foo2: nop + bvc foo + nop + diff --git a/test/test_emulation_bvs.s b/test/test_emulation_bvs.s new file mode 100644 index 0000000..def1ff0 --- /dev/null +++ b/test/test_emulation_bvs.s @@ -0,0 +1,10 @@ +.org 0xC000 + +start: nop + bvs foo2 +foo: nop + stp +foo2: nop + bvs foo + nop +