diff --git a/cpu.c b/cpu.c index 50c2d92..93d04e8 100644 --- a/cpu.c +++ b/cpu.c @@ -411,7 +411,7 @@ int emulate_6502_op(State6502 * state) { case TAY: state->y = state->a; set_NZ_flags(state, state->y); break; 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 TXS: state->sp = state->x; break; case CMP_IMM: CMP(state, fetch_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 diff --git a/test6502.c b/test6502.c index 019c197..3832ea2 100644 --- a/test6502.c +++ b/test6502.c @@ -1960,6 +1960,23 @@ void test_TXS() { test_cleanup(&state); } +void test_TXS_Z() { + State6502 state = create_blank_state(); + //initial state of Z and N = 1 + state.flags.z = 1; + state.flags.n = 1; + state.x = 0x00; + char program[] = { TXS }; + memcpy(state.memory, program, sizeof(program)); + test_step(&state); + + assert_sp(&state, 0x00); + assert_flag_n(&state, 1); + assert_flag_z(&state, 1); + + test_cleanup(&state); +} + void test_TSX() { State6502 state = create_blank_state(); state.sp = 0xBB; @@ -2476,7 +2493,7 @@ fp* tests_flags[] = { test_CLC, test_SEC, test_CLD, test_SED, test_SEI, test_CLI fp* tests_eor[] = { test_EOR_IMM, test_EOR_ZP, test_EOR_ZPX, test_EOR_ABS, test_EOR_ABSX, test_EOR_ABSY, test_EOR_INDX, test_EOR_INDY, test_EOR_IMM_Z }; fp* tests_sta[] = { test_STA_ZP, test_STA_ZPX, test_STA_ABS, test_STA_ABSX, test_STA_ABSY, test_STA_INDX, test_STA_INDY }; fp* tests_pha_pla[] = { test_PHA, test_PLA, test_PLA_N, test_PLA_Z, test_PHA_PLA }; -fp* tests_txs_tsx[] = { test_TXS, test_TSX }; +fp* tests_txs_tsx[] = { test_TXS, test_TSX, test_TXS_Z }; fp* tests_php_plp[] = { test_PHP, test_PLP, test_PLP2 }; 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, test_CPX_ABS, test_CPY_ABS };