From 7737ab8de555f650f517b0e096084125a92074db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B6ffler?= Date: Wed, 25 Jan 2023 22:45:50 +0100 Subject: [PATCH] appease clippy --- src/disassembler/main.rs | 2 +- src/emulator/instructions/arithmetic.rs | 5 ++--- src/emulator/main.rs | 7 +++---- src/emulator/structs.rs | 14 +++++++------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/disassembler/main.rs b/src/disassembler/main.rs index b216374..ab6a0f9 100644 --- a/src/disassembler/main.rs +++ b/src/disassembler/main.rs @@ -15,7 +15,7 @@ fn main() { let mut index: u32 = 0; while let Some(byte) = data.next() { - let current_index = index.clone(); + let current_index = index; index += 1; let mut next = |len: u8| { diff --git a/src/emulator/instructions/arithmetic.rs b/src/emulator/instructions/arithmetic.rs index e0944f4..d3ec5c4 100644 --- a/src/emulator/instructions/arithmetic.rs +++ b/src/emulator/instructions/arithmetic.rs @@ -34,15 +34,14 @@ pub fn adi(byte: u8, state: &mut EmulatorState) { /// Add values of `register` and `A` and add +1 if carry bit is set pub fn adc(register: Register, state: &mut EmulatorState) { - let result = - get_register(®ister, state) as u16 + state.a as u16 + if state.cc.c { 1 } else { 0 }; + let result = get_register(®ister, state) as u16 + state.a as u16 + u16::from(state.cc.c); set_cc(state, result, 0b1111); state.a = (result & 0xff) as u8; } /// Add values of input byte and `A` and add +1 if carry bit is set pub fn aci(byte: u8, state: &mut EmulatorState) { - let result = state.a as u16 + byte as u16 + if state.cc.c { 1 } else { 0 }; + let result = state.a as u16 + byte as u16 + u16::from(state.cc.c); set_cc(state, result, 0b1111); state.a = result as u8; } diff --git a/src/emulator/main.rs b/src/emulator/main.rs index c6699df..925aef5 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -36,9 +36,8 @@ fn main() { .expect("Provide a path to a ROM file to emulate as an argument"); let file = fs::read(filename).expect("where file"); - for i in 0..(MEMORY_SIZE.min(file.len())) { - state.memory[i] = file[i]; - } + let to_copy = MEMORY_SIZE.min(file.len()); + state.memory[..to_copy].copy_from_slice(&file[..to_copy]); while state.pc < MEMORY_SIZE as u16 { tick(&mut state); @@ -53,7 +52,7 @@ fn tick(state: &mut EmulatorState) { let mut next_byte = || { state.pc += 1; - return state.memory[state.pc as usize]; + state.memory[state.pc as usize] }; match instruction { diff --git a/src/emulator/structs.rs b/src/emulator/structs.rs index 7c94e2b..c51c3c3 100644 --- a/src/emulator/structs.rs +++ b/src/emulator/structs.rs @@ -65,13 +65,13 @@ pub fn register_from_num(b: u8) -> Register { pub fn get_register(register: &Register, state: &EmulatorState) -> u8 { match register { - Register::B => state.b as u8, - Register::C => state.c as u8, - Register::D => state.d as u8, - Register::E => state.e as u8, - Register::H => state.h as u8, - Register::L => state.l as u8, - Register::A => state.a as u8, + Register::B => state.b, + Register::C => state.c, + Register::D => state.d, + Register::E => state.e, + Register::H => state.h, + Register::L => state.l, + Register::A => state.a, Register::M => state.memory[u16::from_le_bytes([state.l, state.h]) as usize], Register::SP => unreachable!(), }