From 6df5c3f7e6f30d97e60860d9db6a9ade0f9087a4 Mon Sep 17 00:00:00 2001 From: jborza Date: Sat, 27 Apr 2019 19:22:06 +0200 Subject: [PATCH] fixed RTS --- cpu.c | 6 +----- test6502.c | 14 +++++++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/cpu.c b/cpu.c index dbe36dc..2a8eef5 100644 --- a/cpu.c +++ b/cpu.c @@ -20,9 +20,7 @@ void set_z_flag(State6502 * state, byte value) { } void set_NV_flags(State6502 * state, byte value) { - //N flag state->flags.n = is_negative(value); - //TODO implement NV flags state->flags.v = ((1 << 6) & value) != 0; } @@ -53,8 +51,6 @@ void clear_state(State6502 * state) { state->running = 1; } - - void push_byte_to_stack(State6502 * state, byte value) { //stack located between $0100 to $01FF state->memory[STACK_HOME + state->sp--] = value; @@ -72,7 +68,7 @@ byte pop_byte_from_stack(State6502 * state) { word pop_word_from_stack(State6502* state) { byte low = pop_byte_from_stack(state); byte high = pop_byte_from_stack(state); - return low + ((word)high >> 8); + return low + ((word)high << 8); } //bitwise or with accumulator diff --git a/test6502.c b/test6502.c index 5bcec44..f913081 100644 --- a/test6502.c +++ b/test6502.c @@ -2273,17 +2273,16 @@ void test_JSR() { void test_RTS() { State6502 state = create_blank_state(); + state.memory[STACK_HOME + 0xFF] = 0x01; + state.memory[STACK_HOME + 0xFE] = 0x23; state.sp = 0xFD; - char program[] = { NOP, JSR_ABS, 0x23, 0x01 }; + char program[] = { RTS }; memcpy(state.memory, program, sizeof(program)); //act test_step(&state); - test_step(&state); //assert - assert_pc(&state, 0x0123); - assert_memory(&state, 0x1FF, 0x00); - assert_memory(&state, 0x1FE, 0x03); - assert_sp(&state, 0xFD); + assert_pc(&state, 0x0124); + assert_sp(&state, 0xFF); } void test_JSR_RTS() { @@ -2369,7 +2368,7 @@ fp* tests_cmp[] = { test_CMP_ABS_equal, test_CMP_ABS_greater, test_CMP_ABS_great fp* tests_sbc[] = { test_SBC_IMM_multiple }; fp* tests_adc[] = { test_ADC_IMM_multiple }; fp* tests_bit[] = { test_BIT_multiple }; -fp* tests_jsr_rts[] = { test_JSR, test_JSR_RTS }; +fp* tests_jsr_rts[] = { test_JSR, test_JSR_RTS, test_RTS }; fp* tests_brk[] = { test_BRK }; fp* tests_branch[] = { test_branching_multiple }; @@ -2408,4 +2407,5 @@ void run_tests() { RUN(tests_jmp); RUN(tests_php_plp); RUN(tests_cmp); + printf("All tests succeeded.\n"); } \ No newline at end of file