fixed RTS

This commit is contained in:
jborza 2019-04-27 19:22:06 +02:00
parent ddac9a14d0
commit 6df5c3f7e6
2 changed files with 8 additions and 12 deletions

6
cpu.c
View File

@ -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

View File

@ -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");
}