chore: remove duplicate Instruction::INC match

This commit is contained in:
Rekai Nyangadzayi Musuka 2020-12-23 01:11:03 -06:00
parent 5187cbed76
commit 9cd4c4ea11
1 changed files with 44 additions and 34 deletions

View File

@ -315,45 +315,55 @@ impl Instruction {
} }
_ => unreachable!(), _ => unreachable!(),
}, },
Instruction::INC(Registers::Word(pair)) => { Instruction::INC(registers) => {
// INC rp[p] | Increment Register Pair match registers {
match pair { Registers::Byte(reg) => {
RegisterPair::BC | RegisterPair::DE | RegisterPair::HL | RegisterPair::SP => { // INC r[y] | Increment Register
let value = cpu.register_pair(pair); let mut flags: Flags = cpu.register(Register::Flag).into();
cpu.set_register_pair(pair, value + 1); let cycles: Cycles;
}
_ => unreachable!(),
}
Cycles(8)
}
Instruction::INC(Registers::Byte(reg)) => {
// INC r[y] | Increment Register
let mut flags: Flags = cpu.register(Register::Flag).into();
let cycles: Cycles;
match reg { match reg {
InstrRegister::B InstrRegister::B
| InstrRegister::C | InstrRegister::C
| InstrRegister::D | InstrRegister::D
| InstrRegister::E | InstrRegister::E
| InstrRegister::H | InstrRegister::H
| InstrRegister::L | InstrRegister::L
| InstrRegister::A => { | InstrRegister::A => {
let reg = Register::try_from(reg).unwrap(); let reg = Register::try_from(reg).unwrap();
let value = cpu.register(reg); let value = cpu.register(reg);
cpu.set_register(reg, Self::inc_register(value, &mut flags)); cpu.set_register(reg, Self::inc_register(value, &mut flags));
cycles = Cycles(4) cycles = Cycles(4)
}
InstrRegister::IndirectHL => {
let addr = cpu.register_pair(RegisterPair::HL);
cpu.write_byte(
addr,
Self::inc_register(cpu.read_byte(addr), &mut flags),
);
cycles = Cycles(12)
}
InstrRegister::IndirectC => unreachable!(),
}
cpu.set_register(Register::Flag, flags.into());
cycles
} }
InstrRegister::IndirectHL => { Registers::Word(pair) => {
let addr = cpu.register_pair(RegisterPair::HL); // INC rp[p] | Increment Register Pair
cpu.write_byte(addr, Self::inc_register(cpu.read_byte(addr), &mut flags)); match pair {
cycles = Cycles(12) RegisterPair::BC
| RegisterPair::DE
| RegisterPair::HL
| RegisterPair::SP => {
let value = cpu.register_pair(pair);
cpu.set_register_pair(pair, value + 1);
}
_ => unreachable!(),
}
Cycles(8)
} }
InstrRegister::IndirectC => unreachable!(),
} }
cpu.set_register(Register::Flag, flags.into());
cycles
} }
Instruction::DEC(Registers::Word(pair)) => { Instruction::DEC(Registers::Word(pair)) => {
// DEC rp[p] | Decrement Register Pair // DEC rp[p] | Decrement Register Pair