From de70338f494c4c820c8e0ec1cbf33fc757873484 Mon Sep 17 00:00:00 2001 From: jborza Date: Wed, 1 May 2019 22:59:15 +0200 Subject: [PATCH] attempted to fix flag handling of PLP --- cpu.c | 3 ++- test6502.c | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cpu.c b/cpu.c index e7dd6d3..d1f7345 100644 --- a/cpu.c +++ b/cpu.c @@ -344,6 +344,8 @@ void PLP_(State6502* state) { byte value = pop_byte_from_stack(state); //we don't read the BRK flag value &= ~(1 << 4); + //the bit 5 always comes in as true + value |= 1 << 5; memset(&state->flags, value, sizeof(Flags)); } @@ -353,7 +355,6 @@ void PHP_(State6502* state) { push_byte_to_stack(state, flags_value); } - int emulate_6502_op(State6502 * state) { byte* opcode = &state->memory[state->pc++]; switch (*opcode) { diff --git a/test6502.c b/test6502.c index cf88cb0..79de4d1 100644 --- a/test6502.c +++ b/test6502.c @@ -1987,7 +1987,33 @@ void test_PLP2() { assert_flag_z(&state, 0); assert_flag_v(&state, 0); assert_flag_n(&state, 0); - assert_flag_i(&state, 0); + assert_flag_i(&state, 1); + + //cleanup + test_cleanup(&state); +} + +void test_PHA_PLP() { + State6502 state = create_blank_state(); + + //arrange + char program[] = { LDA_IMM, 0x04, PHA, PLP }; + memcpy(state.memory, program, sizeof(program)); + + //act + test_step(&state); + + assertA(&state, 0x04); + + //assert + assert_sp(&state, 0xFF); + assert_flag_c(&state, 0); + assert_flag_d(&state, 0); + assert_flag_b(&state, 0); + assert_flag_z(&state, 0); + assert_flag_v(&state, 0); + assert_flag_n(&state, 0); + assert_flag_i(&state, 1); //cleanup test_cleanup(&state);