From 1c4e2f45b5a0e5640906bef12f6ed399c200874c Mon Sep 17 00:00:00 2001 From: jborza Date: Fri, 19 Apr 2019 10:36:14 +0200 Subject: [PATCH] added tests for CPX, CPY --- cpu.c | 6 +++--- test6502.c | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cpu.c b/cpu.c index c5f6a1a..c893ef9 100644 --- a/cpu.c +++ b/cpu.c @@ -326,10 +326,10 @@ int emulate_6502_op(State6502 * state) { case TYA: state->a = state->y; set_NZ_flags(state, state->a); break; case TSX: state->x = state->sp; set_NZ_flags(state, state->x); break; case TXS: state->sp = state->x; set_NZ_flags(state, state->x); break; - case CMP_IMM: CMP(state, pop_byte(state)); break; - case CMP_ZP: CMP(state, get_byte_zero_page(state)); break; + case CMP_IMM: CMP(state, pop_byte(state)); break; //TODO test + case CMP_ZP: CMP(state, get_byte_zero_page(state)); break; //TODO test case CMP_ZPX: CMP(state, get_byte_zero_page_x(state)); break; //TODO test - case CMP_ABS: CMP(state, get_byte_absolute(state)); break;//TODO test + case CMP_ABS: CMP(state, get_byte_absolute(state)); break; case CMP_ABSX: CMP(state, get_byte_absolute_x(state)); break;//TODO test case CMP_ABSY: CMP(state, get_byte_absolute_y(state)); break;//TODO test case CMP_INDX: CMP(state, get_byte_indirect_x(state)); break;//TODO test diff --git a/test6502.c b/test6502.c index 7f6d0c3..edca8c3 100644 --- a/test6502.c +++ b/test6502.c @@ -1933,7 +1933,6 @@ void test_CMP_ABS_greater_2() { test_cleanup(&state); } - void test_CMP_ABS_less_than() { State6502 state = create_blank_state(); state.a = 0x08; @@ -1950,6 +1949,41 @@ void test_CMP_ABS_less_than() { test_cleanup(&state); } +// CPX, CPY +void test_CPX_ABS() { + State6502 state = create_blank_state(); + state.x = 0x82; + state.flags.n = 1; + + char program[] = { CPX_ABS, 0x45, 0x03 }; + memcpy(state.memory, program, sizeof(program)); + state.memory[0x0345] = 0x1A; + test_step(&state); + + assert_flag_z(&state, 0x00); // 0x82 != 0x1A + assert_flag_n(&state, 0x00); + assert_flag_c(&state, 0x01); // 0x82 > 0x1A + + test_cleanup(&state); +} + +void test_CPY_ABS() { + State6502 state = create_blank_state(); + state.y = 0x82; + state.flags.n = 1; + + char program[] = { CPY_ABS, 0x45, 0x03 }; + memcpy(state.memory, program, sizeof(program)); + state.memory[0x0345] = 0x1A; + test_step(&state); + + assert_flag_z(&state, 0x00); // 0x82 != 0x1A + assert_flag_n(&state, 0x00); + assert_flag_c(&state, 0x01); // 0x82 > 0x1A + + test_cleanup(&state); +} + ///////////////////// typedef void fp(); @@ -1970,7 +2004,7 @@ fp* tests_pha_pla[] = { test_PHA, test_PLA, test_PHA_PLA }; fp* tests_txs_tsx[] = { test_TXS, test_TSX }; fp* tests_php_plp[] = { test_PHP, test_PLP }; fp* tests_jmp[] = { test_JMP, test_JMP_IND, test_JMP_IND_wrap }; -fp* tests_cmp[] = { test_CMP_ABS_equal, test_CMP_ABS_greater, test_CMP_ABS_greater_2, test_CMP_ABS_less_than }; +fp* tests_cmp[] = { test_CMP_ABS_equal, test_CMP_ABS_greater, test_CMP_ABS_greater_2, test_CMP_ABS_less_than, test_CPX_ABS, test_CPY_ABS }; #define RUN(suite) run_suite(suite, sizeof(suite)/sizeof(fp*))