mirror of
https://github.com/jborza/emu6502.git
synced 2024-11-21 08:31:23 +00:00
attempted to fix flag handling of PLP
This commit is contained in:
parent
5ae9274ab9
commit
de70338f49
3
cpu.c
3
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) {
|
||||
|
28
test6502.c
28
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);
|
||||
|
Loading…
Reference in New Issue
Block a user