mirror of
https://github.com/jborza/emu6502.git
synced 2024-11-21 23:31:19 +00:00
refactored PHP, PLP, PLA
This commit is contained in:
parent
4ad8a47739
commit
8b841b3227
41
cpu.c
41
cpu.c
@ -279,6 +279,14 @@ void RTS_(State6502* state) {
|
||||
state->pc = address + 1;
|
||||
}
|
||||
|
||||
void RTI_(State6502* state) {
|
||||
//interrupt pushes PC first, then status register
|
||||
//RTI should pull status register and program counter from the stack
|
||||
byte sr = pop_byte_from_stack(state);
|
||||
word address = pop_word_from_stack(state);
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
void BEQ(State6502* state) {
|
||||
word address = get_address_relative(state);
|
||||
if (state->flags.z)
|
||||
@ -327,6 +335,22 @@ void BVC(State6502* state) {
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
void PLA_(State6502* state) {
|
||||
state->a = pop_byte_from_stack(state);
|
||||
set_NZ_flags(state, state->a);
|
||||
}
|
||||
|
||||
void PLP_(State6502* state) {
|
||||
byte value = pop_byte_from_stack(state);
|
||||
memset(&state->flags, value, sizeof(Flags));
|
||||
}
|
||||
|
||||
void PHP_(State6502* state) {
|
||||
byte flags_value;
|
||||
memcpy(&flags_value, &state->flags, sizeof(Flags));
|
||||
push_byte_to_stack(state, flags_value);
|
||||
}
|
||||
|
||||
word pop_word(State6502 * state) {
|
||||
byte low = pop_byte(state);
|
||||
byte high = pop_byte(state);
|
||||
@ -377,19 +401,10 @@ int emulate_6502_op(State6502 * state) {
|
||||
case CLV: state->flags.v = 0; break;
|
||||
case NOP: break; //NOP
|
||||
case PHA: push_byte_to_stack(state, state->a); break; //push accumulator to stack
|
||||
case PLA: state->a = pop_byte_from_stack(state); break; //pull accumulator from stack
|
||||
case PHP: {
|
||||
byte flags_value;
|
||||
memcpy(&flags_value, &state->flags, sizeof(Flags));
|
||||
push_byte_to_stack(state, flags_value);
|
||||
break; //push processor status
|
||||
}
|
||||
case PLP: {
|
||||
byte value = pop_byte_from_stack(state);
|
||||
memset(&state->flags, value, 1);
|
||||
break;
|
||||
}//pull procesor status
|
||||
case RTI: unimplemented_instruction(state); break;
|
||||
case PLA: PLA_(state); break; //pull accumulator from stack
|
||||
case PHP: PHP_(state); break; //push processor status
|
||||
case PLP: PLP_(state); break; //pull procesor status
|
||||
case RTI: RTI_(state); break;
|
||||
case RTS: RTS_(state); break;
|
||||
case SEC: state->flags.c = 1; break;
|
||||
case SED: state->flags.d = 1; break;
|
||||
|
Loading…
Reference in New Issue
Block a user