diff --git a/src/display.rs b/src/display.rs index 1c95df7..6d467e6 100644 --- a/src/display.rs +++ b/src/display.rs @@ -45,7 +45,7 @@ impl Display for TerminalDisplay { print!(" ") } } - print!("\n") + println!() } } } diff --git a/src/emulator.rs b/src/emulator.rs index bf59d36..54e5456 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -5,7 +5,7 @@ use crate::instruction::{Instruction, ProcessorInstruction}; use crate::sound::SoundModule; use crate::stack::Stack; use anyhow::anyhow; -use log::{info, trace, warn}; +use log::{debug, info, trace, warn}; use rand::Rng; use std::io::Read; use std::sync::mpsc; @@ -116,12 +116,12 @@ where T: Read, { self.load_rom(rom)?; - self.emulation_loop::()?; + self.emulation_loop()?; Ok(()) } /// Emulation loop executes the fetch -> decode -> execute pipeline - fn emulation_loop(&mut self) -> Result<(), anyhow::Error> { + fn emulation_loop(&mut self) -> Result<(), anyhow::Error> { let mut tick_timer = Instant::now(); let target_fps: u128 = 60; @@ -465,7 +465,9 @@ where where 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 self.program_counter = 0x200; diff --git a/src/input.rs b/src/input.rs index 9f39d64..6a0c7df 100644 --- a/src/input.rs +++ b/src/input.rs @@ -47,39 +47,34 @@ impl InputModule for CrossTermInput { // It's guaranteed that read() won't block if `poll` returns `Ok(true)` let read_result = read(); - if let Ok(event) = read_result { - match event { - Event::Key(key_event) => match key_event.code { - KeyCode::Esc => { - return Some(0xFF); + if let Ok(Event::Key(key_event)) = read_result { + match key_event.code { + KeyCode::Esc => { + 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 + } _ => {} } } diff --git a/src/main.rs b/src/main.rs index e14ea04..c22ff89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ use crate::emulator::Emulator; use crate::input::CrossTermInput; use crate::sound::TerminalSound; use clap::Parser; -use env_logger; use std::fs::File; mod display;