fix: replace MathTarget::HL and ::SP with already-existing enums

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-01-19 02:05:04 -06:00
parent b70c398e14
commit 842e670807
3 changed files with 12 additions and 15 deletions

View File

@ -74,12 +74,13 @@ impl Cpu {
pub fn step(&mut self) -> Cycles { pub fn step(&mut self) -> Cycles {
let opcode = self.fetch(); let opcode = self.fetch();
let instr = self.decode(opcode); let instr = self.decode(opcode);
let cycles = self.execute(instr);
// println!( println!(
// "Addr: {:#06X} | Opcode: {:#04X} | Instr: {:X?}", "Addr: {:#06X} | Opcode: {:#04X} | Instr: {:X?}",
// self.reg.pc, opcode, instr self.reg.pc, opcode, instr
// ); );
let cycles = self.execute(instr);
self.bus.step(cycles); self.bus.step(cycles);

View File

@ -63,8 +63,6 @@ pub enum Registers {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum MATHTarget { pub enum MATHTarget {
HL,
SP,
Register(InstrRegister), Register(InstrRegister),
RegisterPair(RegisterPair), RegisterPair(RegisterPair),
ImmediateByte(u8), ImmediateByte(u8),
@ -1649,11 +1647,11 @@ impl Instruction {
fn from_unprefixed_byte(cpu: &mut Cpu, opcode: u8) -> Self { fn from_unprefixed_byte(cpu: &mut Cpu, opcode: u8) -> Self {
// https://gb-archive.github.io/salvage/decoding_gbz80_opcodes/Decoding%20Gamboy%20Z80%20Opcodes.html // https://gb-archive.github.io/salvage/decoding_gbz80_opcodes/Decoding%20Gamboy%20Z80%20Opcodes.html
let x = (opcode >> 6) & 0b00000011; let x = (opcode >> 6) & 0x03;
let y = (opcode >> 3) & 0b00000111; let y = (opcode >> 3) & 0x07;
let z = opcode & 0b00000111; let z = opcode & 0x07;
let p = y >> 1; let p = y >> 1;
let q = y & 0b00000001; let q = y & 0x01;
let pc = cpu.register_pair(RegisterPair::PC); let pc = cpu.register_pair(RegisterPair::PC);
@ -1674,7 +1672,7 @@ impl Instruction {
), ),
(0, 1, 1, _, _) => Self::ADD( (0, 1, 1, _, _) => Self::ADD(
// ADD HL, rp[p] // ADD HL, rp[p]
MATHTarget::HL, MATHTarget::RegisterPair(RegisterPair::HL),
MATHTarget::RegisterPair(Table::rp(p)), MATHTarget::RegisterPair(Table::rp(p)),
), ),
(0, 2, 0, _, 0) => Self::LD( (0, 2, 0, _, 0) => Self::LD(
@ -2053,8 +2051,6 @@ impl std::fmt::Debug for LDTarget {
impl std::fmt::Debug for MATHTarget { impl std::fmt::Debug for MATHTarget {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self { match *self {
MATHTarget::HL => f.write_str("HL"),
MATHTarget::SP => f.write_str("SP"),
MATHTarget::Register(reg) => write!(f, "{:?}", reg), MATHTarget::Register(reg) => write!(f, "{:?}", reg),
MATHTarget::RegisterPair(pair) => write!(f, "{:?}", pair), MATHTarget::RegisterPair(pair) => write!(f, "{:?}", pair),
MATHTarget::ImmediateByte(byte) => write!(f, "{:#04X}", byte), MATHTarget::ImmediateByte(byte) => write!(f, "{:#04X}", byte),

View File

@ -19,7 +19,7 @@ fn main() -> Result<()> {
let mut input = WinitInputHelper::new(); let mut input = WinitInputHelper::new();
let window = create_window(&event_loop)?; let window = create_window(&event_loop)?;
let mut pixels = create_pixels(&window)?; let mut pixels = create_pixels(&window)?;
let mut game_boy = LR35902::boot_new(); let mut game_boy = LR35902::new();
game_boy.load_cartridge("bin/cpu_instrs.gb"); game_boy.load_cartridge("bin/cpu_instrs.gb");
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {