From a4e2942eeaac3e710424f6b648d8833e17452001 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Tue, 10 Dec 2024 23:57:22 +0200 Subject: [PATCH] use c-like struct for Set instruction --- src/emulator.rs | 2 +- src/instruction.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/emulator.rs b/src/emulator.rs index 91635aa..dc39c60 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -270,7 +270,7 @@ where // Set PC to subroutine address self.program_counter = address; } - ProcessorInstruction::Set(vx, vy) => { + ProcessorInstruction::Set { vx, vy } => { trace!("Set VX={vx:04x} VY={vy:04x}"); self.registers[vx as usize] = self.registers[vy as usize]; } diff --git a/src/instruction.rs b/src/instruction.rs index b3bb595..07dfc6b 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -31,7 +31,7 @@ pub enum ProcessorInstruction { /// Pops the stack and sets the PC Return, /// Set VX to the value of VY - Set(u8, u8), + Set { vx: u8, vy: u8 }, /// Or VX with VY and store in VX. BinaryOr(u8, u8), /// And VX with VY and store in VX. @@ -162,10 +162,10 @@ impl Instruction { (0x2, _, _, _) => ProcessorInstruction::Call { address: Self::grab_inner_data(data), }, - (0x8, _, _, 0x0) => ProcessorInstruction::Set( - Self::grab_first_nibble(data), - Self::grab_middle_nibble(data), - ), + (0x8, _, _, 0x0) => ProcessorInstruction::Set { + vx: Self::grab_first_nibble(data), + vy: Self::grab_middle_nibble(data), + }, (0x8, _, _, 0x1) => ProcessorInstruction::BinaryOr( Self::grab_first_nibble(data), Self::grab_middle_nibble(data), @@ -423,7 +423,7 @@ mod tests { let instruction = Instruction::new([0x81, 0x40]); assert_eq!( instruction.processor_instruction, - ProcessorInstruction::Set(1, 4) + ProcessorInstruction::Set { vx: 1, vy: 4 } ) }