diff --git a/src/cpu.rs b/src/cpu.rs index 93b3137..3815cf0 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -39,7 +39,7 @@ impl Processor { /// # Panics /// Panics if an internal error occurred within the CPU. These are always bugs. pub fn run_instruction(&mut self, instruction: &RunnableInstruction) { - let run_res = run::run_instruction(self, &instruction.instruction); + let run_res = run::run_instruction(self, instruction.instruction); if let Err(err) = run_res { panic!("Fatal CPU error occured: {err}") } diff --git a/src/cpu/instructions.rs b/src/cpu/instructions.rs index 3d56527..a0b3c99 100644 --- a/src/cpu/instructions.rs +++ b/src/cpu/instructions.rs @@ -10,7 +10,7 @@ pub mod load8; // these are indexed with the instruction numbers in this manual // http://marc.rawer.de/Gameboy/Docs/GBCPUman.pdf -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub enum Instruction { EightBitLoad(load8::EightBitLoadInstruction), SixteenBitLoad(load16::SixteenBitLoadInstruction), diff --git a/src/cpu/instructions/arith8.rs b/src/cpu/instructions/arith8.rs index 9585c35..96c184c 100644 --- a/src/cpu/instructions/arith8.rs +++ b/src/cpu/instructions/arith8.rs @@ -3,7 +3,7 @@ use crate::register; // `EightBitAddInstruction` represents one of the Gameboy's instructions for performing addition on // eight bit numbers -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub enum EightBitAddInstruction { AddSingleRegisterToA { src: register::SingleEightBit }, AddImmediateToA { n: u8 }, @@ -15,7 +15,7 @@ pub enum EightBitAddInstruction { // `EightBitSubInstruction` represents one of the Gameboy's instructions for performing addition on // eight bit numbers -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub enum EightBitSubInstruction { SubSingleRegisterFromA { src: register::SingleEightBit }, SubHLAddressFromA, diff --git a/src/cpu/instructions/load16.rs b/src/cpu/instructions/load16.rs index f4a99d3..a198954 100644 --- a/src/cpu/instructions/load16.rs +++ b/src/cpu/instructions/load16.rs @@ -2,7 +2,7 @@ use crate::register; /// `SixteenBitLoadInstruction` represents one of the Gameboy's instructions for loading /// a sixteen bit value either into a register or into memory -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub enum SixteenBitLoadInstruction { // 3.3.2.1 LoadImmediateToRegister { diff --git a/src/cpu/instructions/load8.rs b/src/cpu/instructions/load8.rs index 0319ecc..85b04d8 100644 --- a/src/cpu/instructions/load8.rs +++ b/src/cpu/instructions/load8.rs @@ -2,7 +2,7 @@ use crate::register; /// `EightBitLoadInstruction` represents one of the Gameboy's instructions for loading /// an eight bit value either into a register or into memory -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub enum EightBitLoadInstruction { // 3.3.1.1 LoadImmediateToRegister { diff --git a/src/cpu/run.rs b/src/cpu/run.rs index f748bea..03f8fec 100644 --- a/src/cpu/run.rs +++ b/src/cpu/run.rs @@ -27,13 +27,13 @@ pub enum Error { } /// `InstructionRunner` takes a single instruction and runs it on the given processor. -trait InstructionRunner { - fn run_instruction(processor: &mut Processor, instruction: &I) -> Result<(), Error>; +trait InstructionRunner { + fn run_instruction(processor: &mut Processor, instruction: I) -> Result<(), Error>; } /// `run_instruction` will run the given instruction on the processor. #[allow(clippy::module_name_repetitions)] -pub fn run_instruction(processor: &mut Processor, instruction: &Instruction) -> Result<(), Error> { +pub fn run_instruction(processor: &mut Processor, instruction: Instruction) -> Result<(), Error> { match instruction { Instruction::EightBitLoad(load_instruction) => { load8::EightBitLoadRunner::run_instruction(processor, load_instruction) diff --git a/src/cpu/run/arith8/add.rs b/src/cpu/run/arith8/add.rs index 2907d87..ca10b4f 100644 --- a/src/cpu/run/arith8/add.rs +++ b/src/cpu/run/arith8/add.rs @@ -35,9 +35,9 @@ impl EightBitAddRunner { impl InstructionRunner for EightBitAddRunner { fn run_instruction( processor: &mut Processor, - instruction: &EightBitAddInstruction, + instruction: EightBitAddInstruction, ) -> Result<(), Error> { - match *instruction { + match instruction { EightBitAddInstruction::AddSingleRegisterToA { src } => { let (lhs, rhs) = super::gather_operands( processor, diff --git a/src/cpu/run/arith8/sub.rs b/src/cpu/run/arith8/sub.rs index 6d1eabc..0ceab47 100644 --- a/src/cpu/run/arith8/sub.rs +++ b/src/cpu/run/arith8/sub.rs @@ -35,9 +35,9 @@ impl EightBitSubRunner { impl InstructionRunner for EightBitSubRunner { fn run_instruction( processor: &mut Processor, - instruction: &EightBitSubInstruction, + instruction: EightBitSubInstruction, ) -> Result<(), Error> { - match *instruction { + match instruction { EightBitSubInstruction::SubSingleRegisterFromA { src } => { let (lhs, rhs) = super::gather_operands( processor, diff --git a/src/cpu/run/load16.rs b/src/cpu/run/load16.rs index c7f1d01..e942ec1 100644 --- a/src/cpu/run/load16.rs +++ b/src/cpu/run/load16.rs @@ -10,9 +10,9 @@ impl InstructionRunner for SixteenBitLoadRunner { #[allow(clippy::too_many_lines)] fn run_instruction( processor: &mut Processor, - instruction: &SixteenBitLoadInstruction, + instruction: SixteenBitLoadInstruction, ) -> Result<(), Error> { - match *instruction { + match instruction { SixteenBitLoadInstruction::LoadImmediateToRegister { dst, value } => { processor.registers.set_16bit_register(dst, value); diff --git a/src/cpu/run/load8.rs b/src/cpu/run/load8.rs index 9082f5a..169f81a 100644 --- a/src/cpu/run/load8.rs +++ b/src/cpu/run/load8.rs @@ -11,9 +11,9 @@ impl InstructionRunner for EightBitLoadRunner { #[allow(clippy::too_many_lines)] fn run_instruction( processor: &mut Processor, - instruction: &EightBitLoadInstruction, + instruction: EightBitLoadInstruction, ) -> Result<(), Error> { - match *instruction { + match instruction { EightBitLoadInstruction::LoadImmediateToRegister { value, register } => { processor .registers