fix clippy warnings

This commit is contained in:
Denis-Cosmin Nutiu 2024-12-11 19:51:35 +02:00
parent 0fbb74b431
commit 083318bdc0
4 changed files with 34 additions and 38 deletions

View file

@ -45,7 +45,7 @@ impl Display for TerminalDisplay {
print!(" ") print!(" ")
} }
} }
print!("\n") println!()
} }
} }
} }

View file

@ -5,7 +5,7 @@ use crate::instruction::{Instruction, ProcessorInstruction};
use crate::sound::SoundModule; use crate::sound::SoundModule;
use crate::stack::Stack; use crate::stack::Stack;
use anyhow::anyhow; use anyhow::anyhow;
use log::{info, trace, warn}; use log::{debug, info, trace, warn};
use rand::Rng; use rand::Rng;
use std::io::Read; use std::io::Read;
use std::sync::mpsc; use std::sync::mpsc;
@ -116,12 +116,12 @@ where
T: Read, T: Read,
{ {
self.load_rom(rom)?; self.load_rom(rom)?;
self.emulation_loop::<T>()?; self.emulation_loop()?;
Ok(()) Ok(())
} }
/// Emulation loop executes the fetch -> decode -> execute pipeline /// Emulation loop executes the fetch -> decode -> execute pipeline
fn emulation_loop<T>(&mut self) -> Result<(), anyhow::Error> { fn emulation_loop(&mut self) -> Result<(), anyhow::Error> {
let mut tick_timer = Instant::now(); let mut tick_timer = Instant::now();
let target_fps: u128 = 60; let target_fps: u128 = 60;
@ -465,7 +465,9 @@ where
where where
T: Read, T: Read,
{ {
rom.read(&mut self.memory[0x200..])?; let amount = rom.read(&mut self.memory[0x200..])?;
debug!("Loaded ROM of size {amount} into memory");
// Set program counter to start of memory // Set program counter to start of memory
self.program_counter = 0x200; self.program_counter = 0x200;

View file

@ -47,39 +47,34 @@ impl InputModule for CrossTermInput {
// It's guaranteed that read() won't block if `poll` returns `Ok(true)` // It's guaranteed that read() won't block if `poll` returns `Ok(true)`
let read_result = read(); let read_result = read();
if let Ok(event) = read_result { if let Ok(Event::Key(key_event)) = read_result {
match event { match key_event.code {
Event::Key(key_event) => match key_event.code { KeyCode::Esc => {
KeyCode::Esc => { return Some(0xFF);
return Some(0xFF); }
KeyCode::Char(character) => {
if let Some(char) = character.to_lowercase().next() {
return match char {
'1' => Some(1),
'2' => Some(2),
'3' => Some(3),
'4' => Some(0xC),
'q' => Some(4),
'w' => Some(5),
'e' => Some(6),
'r' => Some(0xD),
'a' => Some(7),
's' => Some(8),
'd' => Some(9),
'f' => Some(0xE),
'z' => Some(0xA),
'x' => Some(0),
'c' => Some(0xB),
'v' => Some(0xF),
_ => None,
};
} }
KeyCode::Char(character) => { }
let lowercase_character = character.to_lowercase();
for char in lowercase_character {
return match char {
'1' => Some(1),
'2' => Some(2),
'3' => Some(3),
'4' => Some(0xC),
'q' => Some(4),
'w' => Some(5),
'e' => Some(6),
'r' => Some(0xD),
'a' => Some(7),
's' => Some(8),
'd' => Some(9),
'f' => Some(0xE),
'z' => Some(0xA),
'x' => Some(0),
'c' => Some(0xB),
'v' => Some(0xF),
_ => None,
};
}
}
_ => {}
},
// ignore non key events
_ => {} _ => {}
} }
} }

View file

@ -3,7 +3,6 @@ use crate::emulator::Emulator;
use crate::input::CrossTermInput; use crate::input::CrossTermInput;
use crate::sound::TerminalSound; use crate::sound::TerminalSound;
use clap::Parser; use clap::Parser;
use env_logger;
use std::fs::File; use std::fs::File;
mod display; mod display;