ORA tests

This commit is contained in:
Aaron Culliney 2014-03-15 14:37:15 -07:00
parent 1439dbc773
commit 512c06f250

View File

@ -4547,6 +4547,364 @@ TEST test_NOP() {
PASS();
}
// ----------------------------------------------------------------------------
// ORA instructions
static void logic_ORA(/*uint8_t*/int _a, /*uint8_t*/int _b, uint8_t *result, uint8_t *flags) {
uint8_t a = (uint8_t)_a;
uint8_t b = (uint8_t)_b;
uint8_t res = a | b;
if ((res & 0xff) == 0x0) {
*flags |= fZ;
}
if (res & 0x80) {
*flags |= fN;
}
*result = res;
}
TEST test_ORA_imm(uint8_t regA, uint8_t val) {
HEADER0();
logic_ORA(regA, val, &result, &flags);
testcpu_set_opcode2(0x09, val);
cpu65_current.a = regA;
cpu65_current.x = 0x03;
cpu65_current.y = 0x04;
cpu65_current.sp = 0x80;
cpu65_current.f = 0x00;
cpu65_run();
ASSERT(cpu65_current.pc == TEST_LOC+2);
ASSERT(cpu65_current.x == 0x03);
ASSERT(cpu65_current.y == 0x04);
ASSERT(cpu65_current.sp == 0x80);
snprintf(msgbuf, MSG_SIZE, MSG_FLAGS0, regA, val, result, buf0, cpu65_current.a, buf1);
ASSERTm(msgbuf, cpu65_current.a == result);
VERIFY_FLAGS();
ASSERT(cpu65_debug.ea == TEST_LOC+1);
ASSERT(cpu65_debug.d == 0xff);
ASSERT(cpu65_debug.rw == RW_READ);
ASSERT(cpu65_debug.opcode == 0x09);
ASSERT(cpu65_debug.opcycles == (2));
PASS();
}
TEST test_ORA_zpage(uint8_t regA, uint8_t val, uint8_t arg0) {
HEADER0();
logic_ORA(regA, val, &result, &flags);
testcpu_set_opcode2(0x05, arg0);
apple_ii_64k[0][arg0] = val;
cpu65_current.a = regA;
cpu65_current.x = 0x03;
cpu65_current.y = 0x04;
cpu65_current.sp = 0x80;
cpu65_current.f = 0x00;
cpu65_run();
ASSERT(cpu65_current.pc == TEST_LOC+2);
ASSERT(cpu65_current.x == 0x03);
ASSERT(cpu65_current.y == 0x04);
ASSERT(cpu65_current.sp == 0x80);
ASSERT(cpu65_current.a == result);
VERIFY_FLAGS();
ASSERT(cpu65_debug.ea == arg0);
ASSERT(cpu65_debug.d == 0xff);
ASSERT(cpu65_debug.rw == RW_READ);
ASSERT(cpu65_debug.opcode == 0x05);
ASSERT(cpu65_debug.opcycles == (3));
PASS();
}
TEST test_ORA_zpage_x(uint8_t regA, uint8_t val, uint8_t arg0, uint8_t regX) {
HEADER0();
logic_ORA(regA, val, &result, &flags);
testcpu_set_opcode2(0x15, arg0);
uint8_t idx = arg0+regX;
apple_ii_64k[0][idx] = val;
cpu65_current.a = regA;
cpu65_current.x = regX;
cpu65_current.y = 0x05;
cpu65_current.sp = 0x81;
cpu65_current.f = 0x00;
cpu65_run();
ASSERT(cpu65_current.pc == TEST_LOC+2);
ASSERT(cpu65_current.x == regX);
ASSERT(cpu65_current.y == 0x05);
ASSERT(cpu65_current.sp == 0x81);
ASSERT(cpu65_current.a == result);
VERIFY_FLAGS();
ASSERT(cpu65_debug.ea == idx);
ASSERT(cpu65_debug.d == 0xff);
ASSERT(cpu65_debug.rw == RW_READ);
ASSERT(cpu65_debug.opcode == 0x15);
ASSERT(cpu65_debug.opcycles == (4));
PASS();
}
TEST test_ORA_abs(uint8_t regA, uint8_t val, uint8_t lobyte, uint8_t hibyte) {
HEADER0();
logic_ORA(regA, val, &result, &flags);
testcpu_set_opcode3(0x0d, lobyte, hibyte);
uint16_t addrs = lobyte | (hibyte<<8);
apple_ii_64k[0][addrs] = val;
cpu65_current.a = regA;
cpu65_current.x = 0xf4;
cpu65_current.y = 0x05;
cpu65_current.sp = 0x81;
cpu65_current.f = 0x00;
cpu65_run();
ASSERT(cpu65_current.pc == TEST_LOC+3);
ASSERT(cpu65_current.x == 0xf4);
ASSERT(cpu65_current.y == 0x05);
ASSERT(cpu65_current.sp == 0x81);
ASSERT(cpu65_current.a == result);
VERIFY_FLAGS();
ASSERT(cpu65_debug.ea == addrs);
ASSERT(cpu65_debug.d == 0xff);
ASSERT(cpu65_debug.rw == RW_READ);
ASSERT(cpu65_debug.opcode == 0x0d);
ASSERT(cpu65_debug.opcycles == (4));
PASS();
}
TEST test_ORA_abs_x(uint8_t regA, uint8_t val, uint8_t regX, uint8_t lobyte, uint8_t hibyte) {
HEADER0();
logic_ORA(regA, val, &result, &flags);
testcpu_set_opcode3(0x1d, lobyte, hibyte);
uint8_t cycle_count = 4;
uint16_t addrs = lobyte | (hibyte<<8);
addrs = addrs + regX;
if ((uint8_t)((addrs>>8)&0xff) != (uint8_t)hibyte) {
++cycle_count;
}
apple_ii_64k[0][addrs] = val;
cpu65_current.a = regA;
cpu65_current.x = regX;
cpu65_current.y = 0x05;
cpu65_current.sp = 0x81;
cpu65_current.f = 0x00;
cpu65_run();
ASSERT(cpu65_current.pc == TEST_LOC+3);
ASSERT(cpu65_current.x == regX);
ASSERT(cpu65_current.y == 0x05);
ASSERT(cpu65_current.sp == 0x81);
ASSERT(cpu65_current.a == result);
VERIFY_FLAGS();
ASSERT(cpu65_debug.ea == addrs);
ASSERT(cpu65_debug.d == 0xff);
ASSERT(cpu65_debug.rw == RW_READ);
ASSERT(cpu65_debug.opcode == 0x1d);
ASSERT(cpu65_debug.opcycles == cycle_count);
PASS();
}
TEST test_ORA_abs_y(uint8_t regA, uint8_t val, uint8_t regY, uint8_t lobyte, uint8_t hibyte) {
HEADER0();
logic_ORA(regA, val, &result, &flags);
testcpu_set_opcode3(0x19, lobyte, hibyte);
uint8_t cycle_count = 4;
uint16_t addrs = lobyte | (hibyte<<8);
addrs = addrs + regY;
if ((uint8_t)((addrs>>8)&0xff) != (uint8_t)hibyte) {
++cycle_count;
}
apple_ii_64k[0][addrs] = val;
cpu65_current.a = regA;
cpu65_current.x = 0x02;
cpu65_current.y = regY;
cpu65_current.sp = 0x81;
cpu65_current.f = 0x00;
cpu65_run();
ASSERT(cpu65_current.pc == TEST_LOC+3);
ASSERT(cpu65_current.x == 0x02);
ASSERT(cpu65_current.y == regY);
ASSERT(cpu65_current.sp == 0x81);
ASSERT(cpu65_current.a == result);
VERIFY_FLAGS();
ASSERT(cpu65_debug.ea == addrs);
ASSERT(cpu65_debug.d == 0xff);
ASSERT(cpu65_debug.rw == RW_READ);
ASSERT(cpu65_debug.opcode == 0x19);
ASSERT(cpu65_debug.opcycles == cycle_count);
PASS();
}
TEST test_ORA_ind_x(uint8_t regA, uint8_t val, uint8_t arg0, uint8_t regX, uint8_t lobyte, uint8_t hibyte) {
HEADER0();
logic_ORA(regA, val, &result, &flags);
testcpu_set_opcode2(0x01, arg0);
uint8_t idx_lo = arg0 + regX;
uint8_t idx_hi = idx_lo+1;
uint16_t addrs = lobyte | (hibyte<<8);
apple_ii_64k[0][idx_lo] = lobyte;
apple_ii_64k[0][idx_hi] = hibyte;
apple_ii_64k[0][addrs] = val;
cpu65_current.a = regA;
cpu65_current.x = regX;
cpu65_current.y = 0x15;
cpu65_current.sp = 0x81;
cpu65_current.f = 0x00;
cpu65_run();
ASSERT(cpu65_current.pc == TEST_LOC+2);
ASSERT(cpu65_current.x == regX);
ASSERT(cpu65_current.y == 0x15);
ASSERT(cpu65_current.sp == 0x81);
ASSERT(cpu65_current.a == result);
VERIFY_FLAGS();
ASSERT(cpu65_debug.ea == addrs);
ASSERT(cpu65_debug.d == 0xff);
ASSERT(cpu65_debug.rw == RW_READ);
ASSERT(cpu65_debug.opcode == 0x01);
ASSERT(cpu65_debug.opcycles == (6));
PASS();
}
TEST test_ORA_ind_y(uint8_t regA, uint8_t val, uint8_t arg0, uint8_t regY, uint8_t val_zp0, uint8_t val_zp1) {
HEADER0();
logic_ORA(regA, val, &result, &flags);
testcpu_set_opcode2(0x11, arg0);
uint8_t idx0 = arg0;
uint8_t idx1 = arg0+1;
apple_ii_64k[0][idx0] = val_zp0;
apple_ii_64k[0][idx1] = val_zp1;
uint8_t cycle_count = 5;
uint16_t addrs = val_zp0 | (val_zp1<<8);
addrs += (uint8_t)regY;
if ((uint8_t)((addrs>>8)&0xff) != (uint8_t)val_zp1) {
++cycle_count;
}
apple_ii_64k[0][addrs] = val;
cpu65_current.a = regA;
cpu65_current.x = 0x84;
cpu65_current.y = regY;
cpu65_current.sp = 0x81;
cpu65_current.f = 0x00;
cpu65_run();
ASSERT(cpu65_current.pc == TEST_LOC+2);
ASSERT(cpu65_current.x == 0x84);
ASSERT(cpu65_current.y == regY);
ASSERT(cpu65_current.sp == 0x81);
ASSERT(cpu65_current.a == result);
VERIFY_FLAGS();
ASSERT(cpu65_debug.ea == addrs);
ASSERT(cpu65_debug.d == 0xff);
ASSERT(cpu65_debug.rw == RW_READ);
ASSERT(cpu65_debug.opcode == 0x11);
ASSERT(cpu65_debug.opcycles == cycle_count);
PASS();
}
// 65c02 : 0x12
TEST test_ORA_ind_zpage(uint8_t regA, uint8_t val, uint8_t arg0, uint8_t lobyte, uint8_t hibyte) {
HEADER0();
logic_ORA(regA, val, &result, &flags);
testcpu_set_opcode2(0x12, arg0);
uint8_t idx0 = arg0;
uint8_t idx1 = arg0+1;
apple_ii_64k[0][idx0] = lobyte;
apple_ii_64k[0][idx1] = hibyte;
uint16_t addrs = lobyte | (hibyte<<8);
apple_ii_64k[0][addrs] = val;
cpu65_current.a = regA;
cpu65_current.x = 0x14;
cpu65_current.y = 0x85;
cpu65_current.sp = 0x81;
cpu65_current.f = 0x00;
cpu65_run();
ASSERT(cpu65_current.pc == TEST_LOC+2);
ASSERT(cpu65_current.x == 0x14);
ASSERT(cpu65_current.y == 0x85);
ASSERT(cpu65_current.sp == 0x81);
ASSERT(cpu65_current.a == result);
VERIFY_FLAGS();
ASSERT(cpu65_debug.ea == addrs);
ASSERT(cpu65_debug.d == 0xff);
ASSERT(cpu65_debug.rw == RW_READ);
ASSERT(cpu65_debug.opcode == 0x12);
ASSERT(cpu65_debug.opcycles == (5));
PASS();
}
// ----------------------------------------------------------------------------
// SBC instructions
@ -5102,6 +5460,7 @@ GREATEST_SUITE(test_suite_cpu) {
A2_ADD_TEST(test_LDA_imm);
A2_ADD_TEST(test_LDX_imm);
A2_ADD_TEST(test_LDY_imm);
A2_ADD_TEST(test_ORA_imm);
A2_ADD_TEST(test_SBC_imm);
HASH_ITER(hh, test_funcs, func, tmp) {
fprintf(GREATEST_STDOUT, "\n%s (SILENCED OUTPUT) :\n", func->name);
@ -5175,6 +5534,7 @@ GREATEST_SUITE(test_suite_cpu) {
A2_ADD_TEST(test_LDX_zpage);
A2_ADD_TEST(test_LDY_zpage);
A2_ADD_TEST(test_LSR_zpage);
A2_ADD_TEST(test_ORA_zpage);
A2_ADD_TEST(test_SBC_zpage);
HASH_ITER(hh, test_funcs, func, tmp) {
fprintf(GREATEST_STDOUT, "\n%s :\n", func->name);
@ -5205,6 +5565,7 @@ GREATEST_SUITE(test_suite_cpu) {
A2_ADD_TEST(test_LDX_zpage_y); // ...y
A2_ADD_TEST(test_LDY_zpage_x);
A2_ADD_TEST(test_LSR_zpage_x);
A2_ADD_TEST(test_ORA_zpage_x);
A2_ADD_TEST(test_SBC_zpage_x);
HASH_ITER(hh, test_funcs, func, tmp) {
fprintf(GREATEST_STDOUT, "\n%s :\n", func->name);
@ -5235,6 +5596,7 @@ GREATEST_SUITE(test_suite_cpu) {
A2_ADD_TEST(test_LDX_abs);
A2_ADD_TEST(test_LDY_abs);
A2_ADD_TEST(test_LSR_abs);
A2_ADD_TEST(test_ORA_abs);
A2_ADD_TEST(test_SBC_abs);
HASH_ITER(hh, test_funcs, func, tmp) {
fprintf(GREATEST_STDOUT, "\n%s :\n", func->name);
@ -5263,6 +5625,7 @@ GREATEST_SUITE(test_suite_cpu) {
A2_ADD_TEST(test_LDA_abs_x);
A2_ADD_TEST(test_LDY_abs_x);
A2_ADD_TEST(test_LSR_abs_x);
A2_ADD_TEST(test_ORA_abs_x);
A2_ADD_TEST(test_SBC_abs_x);
HASH_ITER(hh, test_funcs, func, tmp) {
fprintf(GREATEST_STDOUT, "\n%s :\n", func->name);
@ -5288,6 +5651,7 @@ GREATEST_SUITE(test_suite_cpu) {
A2_ADD_TEST(test_EOR_abs_y);
A2_ADD_TEST(test_LDA_abs_y);
A2_ADD_TEST(test_LDX_abs_y);
A2_ADD_TEST(test_ORA_abs_y);
A2_ADD_TEST(test_SBC_abs_y);
HASH_ITER(hh, test_funcs, func, tmp) {
fprintf(GREATEST_STDOUT, "\n%s :\n", func->name);
@ -5312,6 +5676,7 @@ GREATEST_SUITE(test_suite_cpu) {
A2_ADD_TEST(test_CMP_ind_x);
A2_ADD_TEST(test_EOR_ind_x);
A2_ADD_TEST(test_LDA_ind_x);
A2_ADD_TEST(test_ORA_ind_x);
A2_ADD_TEST(test_SBC_ind_x);
HASH_ITER(hh, test_funcs, func, tmp) {
fprintf(GREATEST_STDOUT, "\n%s :\n", func->name);
@ -5336,6 +5701,7 @@ GREATEST_SUITE(test_suite_cpu) {
A2_ADD_TEST(test_CMP_ind_y);
A2_ADD_TEST(test_EOR_ind_y);
A2_ADD_TEST(test_LDA_ind_y);
A2_ADD_TEST(test_ORA_ind_y);
A2_ADD_TEST(test_SBC_ind_y);
HASH_ITER(hh, test_funcs, func, tmp) {
fprintf(GREATEST_STDOUT, "\n%s :\n", func->name);
@ -5355,6 +5721,7 @@ GREATEST_SUITE(test_suite_cpu) {
A2_ADD_TEST(test_CMP_ind_zpage);
A2_ADD_TEST(test_EOR_ind_zpage);
A2_ADD_TEST(test_LDA_ind_zpage);
A2_ADD_TEST(test_ORA_ind_zpage);
A2_ADD_TEST(test_SBC_ind_zpage);
HASH_ITER(hh, test_funcs, func, tmp) {
fprintf(GREATEST_STDOUT, "\n%s :\n", func->name);