Skip to content

Commit

Permalink
SPC700: implement BBC/BBS
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Nov 23, 2023
1 parent a4d96da commit a51e648
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
30 changes: 30 additions & 0 deletions src/snes/cpu_spc700/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ where
self.tick_bus(2)
}
InstructionType::TCALL => self.op_tcall(instr),
InstructionType::BBC => self.op_bbx(instr, false),
InstructionType::BBS => self.op_bbx(instr, true),
_ => todo!(),
}
}
Expand Down Expand Up @@ -820,4 +822,32 @@ where
self.regs.write(Register::PC, addr);
Ok(())
}

/// BBC/BBS
fn op_bbx(&mut self, instr: &Instruction, setclr: bool) -> Result<()> {
// NOTE: Immediate values for these instructions are SWAPPED
let (_, val, _) = self.resolve_value(instr, 0, 1)?;
let Operand::DirectPageBit(bit) = instr.def.operands[0] else {
unreachable!()
};

// Internal cycle
self.tick_bus(1)?;

if (val & (1 << bit) != 0) != setclr {
// Branch not taken
return Ok(());
}

// Branch taken
let newpc = self
.regs
.read(Register::PC)
.wrapping_add_signed(instr.imm8(0) as i8 as i16);
self.regs.write(Register::PC, newpc);

// Internal cycles
self.tick_bus(2)?;
Ok(())
}
}
32 changes: 16 additions & 16 deletions src/test/processortests_spc700.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn run_testcase(testcase: &Value, check_trace: bool, multi_steps: bool) {
cpu_test!(instr_00, 0x00);
cpu_test!(instr_01, 0x01);
cpu_test!(instr_02, 0x02);
//cpu_test!(instr_03, 0x03);
cpu_test_no_trace!(instr_03, 0x03);
cpu_test!(instr_04, 0x04);
cpu_test!(instr_05, 0x05);
cpu_test!(instr_06, 0x06);
Expand All @@ -196,7 +196,7 @@ cpu_test!(instr_0d, 0x0d);
//cpu_test!(instr_10, 0x10);
cpu_test!(instr_11, 0x11);
cpu_test!(instr_12, 0x12);
//cpu_test!(instr_13, 0x13);
cpu_test_no_trace!(instr_13, 0x13);
cpu_test!(instr_14, 0x14);
cpu_test!(instr_15, 0x15);
cpu_test!(instr_16, 0x16);
Expand All @@ -214,7 +214,7 @@ cpu_test!(instr_1e, 0x1e);
cpu_test!(instr_20, 0x20);
cpu_test!(instr_21, 0x21);
cpu_test!(instr_22, 0x22);
//cpu_test!(instr_23, 0x23);
cpu_test_no_trace!(instr_23, 0x23);
cpu_test!(instr_24, 0x24);
cpu_test!(instr_25, 0x25);
cpu_test!(instr_26, 0x26);
Expand All @@ -232,7 +232,7 @@ cpu_test!(instr_2d, 0x2d);
//cpu_test!(instr_30, 0x30);
cpu_test!(instr_31, 0x31);
cpu_test!(instr_32, 0x32);
//cpu_test!(instr_33, 0x33);
cpu_test_no_trace!(instr_33, 0x33);
cpu_test!(instr_34, 0x34);
cpu_test!(instr_35, 0x35);
cpu_test!(instr_36, 0x36);
Expand All @@ -250,7 +250,7 @@ cpu_test!(instr_3f, 0x3f);
cpu_test!(instr_40, 0x40);
cpu_test!(instr_41, 0x41);
cpu_test!(instr_42, 0x42);
//cpu_test!(instr_43, 0x43);
cpu_test_no_trace!(instr_43, 0x43);
cpu_test!(instr_44, 0x44);
cpu_test!(instr_45, 0x45);
cpu_test!(instr_46, 0x46);
Expand All @@ -268,7 +268,7 @@ cpu_test!(instr_4d, 0x4d);
//cpu_test!(instr_50, 0x50);
cpu_test!(instr_51, 0x51);
cpu_test!(instr_52, 0x52);
//cpu_test!(instr_53, 0x53);
cpu_test_no_trace!(instr_53, 0x53);
cpu_test!(instr_54, 0x54);
cpu_test!(instr_55, 0x55);
cpu_test!(instr_56, 0x56);
Expand All @@ -286,7 +286,7 @@ cpu_test!(instr_5e, 0x5e);
cpu_test!(instr_60, 0x60);
cpu_test!(instr_61, 0x61);
cpu_test!(instr_62, 0x62);
//cpu_test!(instr_63, 0x63);
cpu_test_no_trace!(instr_63, 0x63);
cpu_test!(instr_64, 0x64);
cpu_test!(instr_65, 0x65);
cpu_test!(instr_66, 0x66);
Expand All @@ -303,7 +303,7 @@ cpu_test!(instr_6d, 0x6d);
//cpu_test!(instr_70, 0x70);
cpu_test!(instr_71, 0x71);
cpu_test!(instr_72, 0x72);
//cpu_test!(instr_73, 0x73);
cpu_test_no_trace!(instr_73, 0x73);
cpu_test!(instr_74, 0x74);
cpu_test!(instr_75, 0x75);
cpu_test!(instr_76, 0x76);
Expand All @@ -320,7 +320,7 @@ cpu_test!(instr_7e, 0x7e);
cpu_test!(instr_80, 0x80);
cpu_test!(instr_81, 0x81);
cpu_test!(instr_82, 0x82);
//cpu_test!(instr_83, 0x83);
cpu_test_no_trace!(instr_83, 0x83);
cpu_test!(instr_84, 0x84);
cpu_test!(instr_85, 0x85);
cpu_test!(instr_86, 0x86);
Expand All @@ -337,7 +337,7 @@ cpu_test!(instr_8f, 0x8f);
//cpu_test!(instr_90, 0x90);
cpu_test!(instr_91, 0x91);
cpu_test!(instr_92, 0x92);
//cpu_test!(instr_93, 0x93);
cpu_test_no_trace!(instr_93, 0x93);
cpu_test!(instr_94, 0x94);
cpu_test!(instr_95, 0x95);
cpu_test!(instr_96, 0x96);
Expand All @@ -354,7 +354,7 @@ cpu_test!(instr_9f, 0x9f);
cpu_test!(instr_a0, 0xa0);
cpu_test!(instr_a1, 0xa1);
cpu_test!(instr_a2, 0xa2);
//cpu_test!(instr_a3, 0xa3);
cpu_test_no_trace!(instr_a3, 0xa3);
cpu_test!(instr_a4, 0xa4);
cpu_test!(instr_a5, 0xa5);
cpu_test!(instr_a6, 0xa6);
Expand All @@ -372,7 +372,7 @@ cpu_test_no_trace!(instr_af, 0xaf);
//cpu_test!(instr_b0, 0xb0);
cpu_test!(instr_b1, 0xb1);
cpu_test!(instr_b2, 0xb2);
//cpu_test!(instr_b3, 0xb3);
cpu_test_no_trace!(instr_b3, 0xb3);
cpu_test!(instr_b4, 0xb4);
cpu_test!(instr_b5, 0xb5);
cpu_test!(instr_b6, 0xb6);
Expand All @@ -389,7 +389,7 @@ cpu_test!(instr_bf, 0xbf);
cpu_test!(instr_c0, 0xc0);
cpu_test!(instr_c1, 0xc1);
cpu_test!(instr_c2, 0xc2);
//cpu_test!(instr_c3, 0xc3);
cpu_test_no_trace!(instr_c3, 0xc3);
cpu_test!(instr_c4, 0xc4);
cpu_test!(instr_c5, 0xc5);
cpu_test!(instr_c6, 0xc6);
Expand All @@ -405,7 +405,7 @@ cpu_test!(instr_ce, 0xce);
//cpu_test!(instr_d0, 0xd0);
cpu_test!(instr_d1, 0xd1);
cpu_test!(instr_d2, 0xd2);
//cpu_test!(instr_d3, 0xd3);
cpu_test_no_trace!(instr_d3, 0xd3);
cpu_test!(instr_d4, 0xd4);
cpu_test!(instr_d5, 0xd5);
cpu_test!(instr_d6, 0xd6);
Expand All @@ -422,7 +422,7 @@ cpu_test!(instr_dd, 0xdd);
cpu_test!(instr_e0, 0xe0);
cpu_test!(instr_e1, 0xe1);
cpu_test!(instr_e2, 0xe2);
//cpu_test!(instr_e3, 0xe3);
cpu_test_no_trace!(instr_e3, 0xe3);
cpu_test!(instr_e4, 0xe4);
cpu_test!(instr_e5, 0xe5);
cpu_test!(instr_e6, 0xe6);
Expand All @@ -438,7 +438,7 @@ cpu_test!(instr_ee, 0xee);
//cpu_test!(instr_f0, 0xf0);
cpu_test!(instr_f1, 0xf1);
cpu_test!(instr_f2, 0xf2);
//cpu_test!(instr_f3, 0xf3);
cpu_test_no_trace!(instr_f3, 0xf3);
cpu_test!(instr_f4, 0xf4);
cpu_test!(instr_f5, 0xf5);
cpu_test!(instr_f6, 0xf6);
Expand Down

0 comments on commit a51e648

Please sign in to comment.