Make all Instructions Copy

old-bit-manip
Nick Krichevsky 2023-05-07 16:38:23 -04:00
parent 4fb9144c6d
commit 85253e2576
10 changed files with 17 additions and 17 deletions

View File

@ -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}")
}

View File

@ -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),

View File

@ -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,

View File

@ -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 {

View File

@ -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 {

View File

@ -27,13 +27,13 @@ pub enum Error {
}
/// `InstructionRunner` takes a single instruction and runs it on the given processor.
trait InstructionRunner<I> {
fn run_instruction(processor: &mut Processor, instruction: &I) -> Result<(), Error>;
trait InstructionRunner<I: Copy> {
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)

View File

@ -35,9 +35,9 @@ impl EightBitAddRunner {
impl InstructionRunner<EightBitAddInstruction> 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,

View File

@ -35,9 +35,9 @@ impl EightBitSubRunner {
impl InstructionRunner<EightBitSubInstruction> 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,

View File

@ -10,9 +10,9 @@ impl InstructionRunner<SixteenBitLoadInstruction> 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);

View File

@ -11,9 +11,9 @@ impl InstructionRunner<EightBitLoadInstruction> 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