2017-12-04 02:19:17 +00:00
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
|
|
|
#include "mos6502.h"
|
|
|
|
#include "mos6502.enums.h"
|
2017-12-06 21:57:15 +00:00
|
|
|
#include "mos6502.tests.h"
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
TestSuite(mos6502_branch, .init = setup, .fini = teardown);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_branch, bcc)
|
|
|
|
{
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bcc(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_eq(cpu->PC, 2);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-24 02:41:48 +00:00
|
|
|
cpu->P &= ~MOS_CARRY;
|
|
|
|
cpu->eff_addr = 128;
|
|
|
|
mos6502_handle_bcc(cpu, 3);
|
|
|
|
cr_assert_eq(cpu->PC, 128);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_branch, bcs)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bcs(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_eq(cpu->PC, 123);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-24 02:41:48 +00:00
|
|
|
cpu->P &= ~MOS_CARRY;
|
|
|
|
cpu->eff_addr = 200;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bcs(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->PC, 125);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_branch, beq)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_beq(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_eq(cpu->PC, 123);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-24 02:41:48 +00:00
|
|
|
cpu->P &= ~MOS_ZERO;
|
|
|
|
cpu->eff_addr = 150;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_beq(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_neq(cpu->PC, 150);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_branch, bmi)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bmi(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_eq(cpu->PC, 123);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-24 02:41:48 +00:00
|
|
|
cpu->P &= ~MOS_NEGATIVE;
|
|
|
|
cpu->eff_addr = 150;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bmi(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_neq(cpu->PC, 150);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_branch, bne)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bne(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_neq(cpu->PC, 123);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-24 02:41:48 +00:00
|
|
|
cpu->P &= ~MOS_ZERO;
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 125;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bne(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_eq(cpu->PC, 125);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_branch, bpl)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bpl(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_neq(cpu->PC, 123);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-24 02:41:48 +00:00
|
|
|
cpu->P &= ~MOS_NEGATIVE;
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 125;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bpl(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_eq(cpu->PC, 125);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:57:21 +00:00
|
|
|
Test(mos6502_branch, bra)
|
|
|
|
{
|
|
|
|
cr_assert_eq(cpu->PC, 0);
|
|
|
|
cpu->eff_addr = 123;
|
|
|
|
mos6502_handle_bra(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->PC, 123);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_branch, bvc)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bvc(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_neq(cpu->PC, 123);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-24 02:41:48 +00:00
|
|
|
cpu->P &= ~MOS_OVERFLOW;
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 125;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bvc(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_eq(cpu->PC, 125);
|
2017-12-04 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:57:15 +00:00
|
|
|
Test(mos6502_branch, bvs)
|
2017-12-04 02:19:17 +00:00
|
|
|
{
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 123;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bvs(cpu, 0);
|
2018-01-24 02:41:48 +00:00
|
|
|
cr_assert_eq(cpu->PC, 123);
|
2017-12-04 02:19:17 +00:00
|
|
|
|
2018-01-24 02:41:48 +00:00
|
|
|
cpu->P &= ~MOS_OVERFLOW;
|
2018-01-12 19:57:48 +00:00
|
|
|
cpu->eff_addr = 125;
|
2017-12-04 02:19:17 +00:00
|
|
|
mos6502_handle_bvs(cpu, 0);
|
|
|
|
cr_assert_eq(cpu->PC, 125);
|
|
|
|
}
|