From 2842c55cf8255117c89c6205247a8984d3d04cc3 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Wed, 11 Dec 2024 00:05:35 +0200 Subject: [PATCH] use c-like struct for JumpWithOffset 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 7f4cda2..07c3e24 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -335,7 +335,7 @@ where self.registers[0xF] = self.registers[vx as usize] & 0x1; self.registers[vx as usize] >>= 1; } - ProcessorInstruction::JumpWithOffset(address) => { + ProcessorInstruction::JumpWithOffset { address } => { let offset = self.registers[0x0]; trace!("Jump With offset Address={address:04x} Offset={offset:04x}"); diff --git a/src/instruction.rs b/src/instruction.rs index 2fd037a..32e46ab 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -51,7 +51,7 @@ pub enum ProcessorInstruction { /// This instruction has different behaviour on CHIP-48 and SUPER-CHIP. ShiftLeft { vx: u8, vy: u8 }, /// Jumps to the address and adds V0 offset. - JumpWithOffset(u16), + JumpWithOffset { address: u16 }, /// Generates a random number ANDed with the data and stores it in VX. GenerateRandomNumber(u8, u8), /// Skips the next instruction if VX is equal to data. @@ -198,7 +198,9 @@ impl Instruction { vx: Self::grab_first_nibble(data), vy: Self::grab_middle_nibble(data), }, - (0xB, _, _, _) => ProcessorInstruction::JumpWithOffset(Self::grab_inner_data(data)), + (0xB, _, _, _) => ProcessorInstruction::JumpWithOffset { + address: Self::grab_inner_data(data), + }, (0xC, _, _, _) => ProcessorInstruction::GenerateRandomNumber( Self::grab_first_nibble(data), Self::grab_last_byte(data), @@ -513,7 +515,7 @@ mod tests { let instruction = Instruction::new([0xBA, 0xBC]); assert_eq!( instruction.processor_instruction, - ProcessorInstruction::JumpWithOffset(0xABC) + ProcessorInstruction::JumpWithOffset { address: 0xABC } ) }