Make all Instructions Copy
parent
4fb9144c6d
commit
85253e2576
|
@ -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}")
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue