1
0
mirror of https://github.com/jborza/emu6502.git synced 2024-11-22 14:32:27 +00:00

CLC, SEC, CLD, SEC, CLI, SEI, CLV + tests

This commit is contained in:
jborza 2019-04-15 23:44:07 +02:00
parent b1e7516541
commit 1ebb7da6c3
2 changed files with 122 additions and 8 deletions

14
cpu.c
View File

@ -223,10 +223,10 @@ int emulate_6502_op(State6502 * state) {
case BRK: state->running = 0; case BRK: state->running = 0;
state->flags.b = 1; state->flags.b = 1;
break; //BRK break; //BRK
case CLC: unimplemented_instruction(state); break; case CLC: state->flags.c = 0; break;
case CLD: unimplemented_instruction(state); break; case CLD: state->flags.d = 0; break;
case CLI: unimplemented_instruction(state); break; case CLI: state->flags.i = 0; break;
case CLV: unimplemented_instruction(state); break; case CLV: state->flags.v = 0; break;
case NOP: break; //NOP case NOP: break; //NOP
case PHA: unimplemented_instruction(state); break; case PHA: unimplemented_instruction(state); break;
case PLA: unimplemented_instruction(state); break; case PLA: unimplemented_instruction(state); break;
@ -238,9 +238,9 @@ int emulate_6502_op(State6502 * state) {
unimplemented_instruction(state); break; unimplemented_instruction(state); break;
case RTI: unimplemented_instruction(state); break; case RTI: unimplemented_instruction(state); break;
case RTS: unimplemented_instruction(state); break; case RTS: unimplemented_instruction(state); break;
case SEC: unimplemented_instruction(state); break; case SEC: state->flags.c = 1; break;
case SED: unimplemented_instruction(state); break; case SED: state->flags.d = 1; break;
case SEI: unimplemented_instruction(state); break; case SEI: state->flags.i = 1; break;
case TAX: state->x = state->a; set_NZ_flags(state, state->x); break; //TODO test case TAX: state->x = state->a; set_NZ_flags(state, state->x); break; //TODO test
case TXA: state->a = state->x; set_NZ_flags(state, state->a); break; //TODO test case TXA: state->a = state->x; set_NZ_flags(state, state->a); break; //TODO test
case TAY: state->y = state->a; set_NZ_flags(state, state->y); break; //TODO test case TAY: state->y = state->a; set_NZ_flags(state, state->y); break; //TODO test

View File

@ -97,6 +97,33 @@ void assert_flag_z(State6502 * state, byte expected) {
} }
} }
void assert_flag_c(State6502* state, byte expected) {
if (state->flags.c != expected) {
printf("Unexpected value in flag C, expected %d, was %d", expected, state->flags.c);
exit(1);
}
}
void assert_flag_i(State6502* state, byte expected) {
if (state->flags.i != expected) {
printf("Unexpected value in flag I, expected %d, was %d", expected, state->flags.i);
exit(1);
}
}
void assert_flag_d(State6502* state, byte expected) {
if (state->flags.d != expected) {
printf("Unexpected value in flag D, expected %d, was %d", expected, state->flags.d);
exit(1);
}
}
void assert_flag_v(State6502* state, byte expected) {
if (state->flags.v != expected) {
printf("Unexpected value in flag D, expected %d, was %d", expected, state->flags.v);
exit(1);
}
}
//////////////////////////////////////// ////////////////////////////////////////
@ -1237,6 +1264,92 @@ void test_DEC_ZP_wraparound() {
test_cleanup(&state); test_cleanup(&state);
} }
// FLAGS
void test_SEC() {
State6502 state = create_blank_state();
char program[] = { SEC };
memcpy(state.memory, program, sizeof(program));
test_step(&state);
assert_flag_c(&state, 1);
test_cleanup(&state);
}
void test_CLC() {
State6502 state = create_blank_state();
state.flags.c = 1;
char program[] = { CLC };
memcpy(state.memory, program, sizeof(program));
test_step(&state);
assert_flag_c(&state, 0);
test_cleanup(&state);
}
void test_SED() {
State6502 state = create_blank_state();
char program[] = { SED };
memcpy(state.memory, program, sizeof(program));
test_step(&state);
assert_flag_d(&state, 1);
test_cleanup(&state);
}
void test_CLD() {
State6502 state = create_blank_state();
state.flags.d = 1;
char program[] = { CLD };
memcpy(state.memory, program, sizeof(program));
test_step(&state);
assert_flag_d(&state, 0);
test_cleanup(&state);
}
void test_SEI() {
State6502 state = create_blank_state();
char program[] = { SEI };
memcpy(state.memory, program, sizeof(program));
test_step(&state);
assert_flag_i(&state, 1);
test_cleanup(&state);
}
void test_CLI() {
State6502 state = create_blank_state();
state.flags.i = 1;
char program[] = { CLI };
memcpy(state.memory, program, sizeof(program));
test_step(&state);
assert_flag_i(&state, 0);
test_cleanup(&state);
}
void test_CLV() {
State6502 state = create_blank_state();
state.flags.v = 1;
char program[] = { CLV };
memcpy(state.memory, program, sizeof(program));
test_step(&state);
assert_flag_v(&state, 0);
test_cleanup(&state);
}
///////////////////// /////////////////////
typedef void fp(); typedef void fp();
@ -1250,7 +1363,7 @@ fp* tests_sty[] = { test_STY_ZP, test_STY_ZPX, test_STY_ABS };
fp* tests_inx_iny_dex_dey[] = { test_DEX, test_DEX_wraparound, test_DEY, test_DEY_wraparound, test_INX, test_INX_wraparound, test_INY, test_INY_wraparound }; fp* tests_inx_iny_dex_dey[] = { test_DEX, test_DEX_wraparound, test_DEY, test_DEY_wraparound, test_INX, test_INX_wraparound, test_INY, test_INY_wraparound };
fp* tests_txa_etc[] = { test_TXA, test_TAX, test_TYA, test_TAY }; fp* tests_txa_etc[] = { test_TXA, test_TAX, test_TYA, test_TAY };
fp* tests_inc_dec[] = { test_INC_ZP, test_INC_ZP_wraparound, test_INC_ZPX, test_INC_ABS, test_INC_ABSX, test_DEC_ZP, test_DEC_ZP_wraparound }; fp* tests_inc_dec[] = { test_INC_ZP, test_INC_ZP_wraparound, test_INC_ZPX, test_INC_ABS, test_INC_ABSX, test_DEC_ZP, test_DEC_ZP_wraparound };
fp* tests_flags[] = { test_CLC, test_SEC, test_CLD, test_SED, test_SEI, test_CLI, test_CLV };
#define RUN(suite) run_suite(suite, sizeof(suite)/sizeof(fp*)) #define RUN(suite) run_suite(suite, sizeof(suite)/sizeof(fp*))
void run_suite(fp * *suite, int size) { void run_suite(fp * *suite, int size) {
@ -1270,4 +1383,5 @@ void run_tests() {
RUN(tests_inx_iny_dex_dey); RUN(tests_inx_iny_dex_dey);
RUN(tests_txa_etc); RUN(tests_txa_etc);
RUN(tests_inc_dec); RUN(tests_inc_dec);
RUN(tests_flags);
} }