mirror of
https://github.com/jborza/emu6502.git
synced 2025-02-19 07:30:57 +00:00
implemented the remaining branching instructions
This commit is contained in:
parent
b4e260d3d4
commit
4ad8a47739
56
cpu.c
56
cpu.c
@ -285,6 +285,48 @@ void BEQ(State6502* state) {
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
void BNE(State6502* state) {
|
||||
word address = get_address_relative(state);
|
||||
if (!state->flags.z)
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
void BCC(State6502* state) {
|
||||
word address = get_address_relative(state);
|
||||
if (!state->flags.c)
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
void BCS(State6502* state) {
|
||||
word address = get_address_relative(state);
|
||||
if (state->flags.c)
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
void BMI(State6502* state) {
|
||||
word address = get_address_relative(state);
|
||||
if (state->flags.n)
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
void BPL(State6502* state) {
|
||||
word address = get_address_relative(state);
|
||||
if (!state->flags.n)
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
void BVS(State6502* state) {
|
||||
word address = get_address_relative(state);
|
||||
if (state->flags.v)
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
void BVC(State6502* state) {
|
||||
word address = get_address_relative(state);
|
||||
if (!state->flags.v)
|
||||
state->pc = address;
|
||||
}
|
||||
|
||||
word pop_word(State6502 * state) {
|
||||
byte low = pop_byte(state);
|
||||
byte high = pop_byte(state);
|
||||
@ -316,14 +358,14 @@ int emulate_6502_op(State6502 * state) {
|
||||
case ASL_ZPX: ASL_MEM(state, get_address_zero_page_x(state)); break;
|
||||
case ASL_ABS: ASL_MEM(state, get_address_absolute(state)); break;
|
||||
case ASL_ABSX: ASL_MEM(state, get_address_absolute_x(state)); break;
|
||||
case BCC_REL: unimplemented_instruction(state); break;
|
||||
case BCS_REL: unimplemented_instruction(state); break;
|
||||
case BCC_REL: BCC(state); break;
|
||||
case BCS_REL: BCS(state); break;
|
||||
case BEQ_REL: BEQ(state); break;
|
||||
case BMI_REL: unimplemented_instruction(state); break;
|
||||
case BNE_REL: unimplemented_instruction(state); break;
|
||||
case BPL_REL: unimplemented_instruction(state); break;
|
||||
case BVC_REL: unimplemented_instruction(state); break;
|
||||
case BVS_REL: unimplemented_instruction(state); break;
|
||||
case BMI_REL: BMI(state); break;
|
||||
case BNE_REL: BNE(state); break;
|
||||
case BPL_REL: BPL(state); break;
|
||||
case BVC_REL: BVC(state); break;
|
||||
case BVS_REL: BVS(state); break;
|
||||
case BIT_ZP: BIT(state, get_byte_zero_page(state)); break;
|
||||
case BIT_ABS: BIT(state, get_byte_absolute(state)); break;
|
||||
case BRK: state->running = 0;
|
||||
|
@ -2266,7 +2266,7 @@ void test_BRK() {
|
||||
void test_branch(byte opcode, byte n, byte v, byte z, byte c, word expected_pc){
|
||||
State6502 state = create_blank_state();
|
||||
state.flags.n = n;
|
||||
state.flags.v = n;
|
||||
state.flags.v = v;
|
||||
state.flags.z = z;
|
||||
state.flags.c = c;
|
||||
char program[] = { opcode, 0xFE };
|
||||
@ -2284,8 +2284,8 @@ void test_branching_multiple() {
|
||||
test_branch(BNE_REL, /*N*/ 0, /*V*/ 0, /*Z*/ 1, /*C*/ 0, /*EXP_PC*/0x02);
|
||||
test_branch(BCC_REL, /*N*/ 0, /*V*/ 0, /*Z*/ 0, /*C*/ 0, /*EXP_PC*/0x00);
|
||||
test_branch(BCC_REL, /*N*/ 0, /*V*/ 0, /*Z*/ 0, /*C*/ 1, /*EXP_PC*/0x02);
|
||||
test_branch(BCS_REL, /*N*/ 0, /*V*/ 0, /*Z*/ 0, /*C*/ 0, /*EXP_PC*/0x00);
|
||||
test_branch(BCS_REL, /*N*/ 0, /*V*/ 0, /*Z*/ 0, /*C*/ 1, /*EXP_PC*/0x02);
|
||||
test_branch(BCS_REL, /*N*/ 0, /*V*/ 0, /*Z*/ 0, /*C*/ 1, /*EXP_PC*/0x00);
|
||||
test_branch(BCS_REL, /*N*/ 0, /*V*/ 0, /*Z*/ 0, /*C*/ 0, /*EXP_PC*/0x02);
|
||||
test_branch(BMI_REL, /*N*/ 1, /*V*/ 0, /*Z*/ 0, /*C*/ 0, /*EXP_PC*/0x00);
|
||||
test_branch(BMI_REL, /*N*/ 0, /*V*/ 0, /*Z*/ 0, /*C*/ 0, /*EXP_PC*/0x02);
|
||||
test_branch(BPL_REL, /*N*/ 0, /*V*/ 0, /*Z*/ 0, /*C*/ 0, /*EXP_PC*/0x00);
|
||||
|
Loading…
x
Reference in New Issue
Block a user