appease clippy

This commit is contained in:
Martin Löffler 2023-01-25 22:45:50 +01:00
parent 17a8509898
commit 7737ab8de5
Signed by: FatalErrorCoded
GPG key ID: FFEF368AC076566A
4 changed files with 13 additions and 15 deletions
src
disassembler
emulator

View file

@ -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| {

View file

@ -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(&register, state) as u16 + state.a as u16 + if state.cc.c { 1 } else { 0 };
let result = get_register(&register, 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;
}

View file

@ -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 {

View file

@ -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!(),
}