From a464c008368d667211efadb49a9faa9f04fdc6e6 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Tue, 10 Dec 2024 19:02:31 +0200 Subject: [PATCH] c-like struct for SetIndexRegister instruction --- src/emulator.rs | 2 +- src/instruction.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/emulator.rs b/src/emulator.rs index be0ff85..8a4e414 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -217,7 +217,7 @@ where let (result, _) = self.registers[register as usize].overflowing_add(value); self.registers[register as usize] = result; } - ProcessorInstruction::SetIndexRegister(data) => { + ProcessorInstruction::SetIndexRegister { data } => { trace!("Set index register to data {:04x}", data); self.index_register = data; } diff --git a/src/instruction.rs b/src/instruction.rs index 0f5ea32..b59b041 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -23,7 +23,7 @@ pub enum ProcessorInstruction { /// Adds the value to the register AddValueToRegister { register: u8, value: u8 }, /// Sets the index register - SetIndexRegister(u16), + SetIndexRegister { data: u16 }, /// Draws to the screen. Draw(u8, u8, u8), /// Call sets PC to the address and saves the return address on the stack @@ -146,7 +146,9 @@ impl Instruction { } } // Set index register - (0xA, _, _, _) => ProcessorInstruction::SetIndexRegister(Self::grab_inner_data(data)), + (0xA, _, _, _) => ProcessorInstruction::SetIndexRegister { + data: Self::grab_inner_data(data), + }, // Draw on screen (0xD, _, _, _) => { // DXYN @@ -500,7 +502,7 @@ mod tests { let instruction = Instruction::new([0xAA, 0xBC]); assert_eq!( instruction.processor_instruction, - ProcessorInstruction::SetIndexRegister(0xABC) + ProcessorInstruction::SetIndexRegister { data: 0xABC } ) }