CLEANUP: cleans up dependencies to use workspace version
CLEANUP: standardizes on pretty_env_logger NEWBIN: Adds gemmarat to use Ratatui as an interface CLEANUP: removes debugging display from computer.rs ENHANCEMENT: Constants for locations of test roms built from environment BUGFIX: SoundTimer was using i32 internally when it needs to be u8 CLEANUP: removes commented code used during diagnostics
This commit is contained in:
+4
-6
@@ -7,13 +7,11 @@ autobenches = true
|
||||
[dependencies]
|
||||
pretty_env_logger.workspace = true
|
||||
rand.workspace = true
|
||||
log.workspace = true
|
||||
# beep = "0.3.0"
|
||||
chrono.workspace = true
|
||||
dimensioned.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
flate2 = "1.0"
|
||||
clap = { version = "4.5.20", features = ["derive"] }
|
||||
hex = "0.4.3"
|
||||
env_logger = "0.10.2"
|
||||
flate2.workspace = true
|
||||
clap.workspace = true
|
||||
hex.workspace = true
|
||||
log.workspace = true
|
||||
@@ -103,7 +103,7 @@ fn decompress_file(input_path: &PathBuf) -> io::Result<()> {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
pretty_env_logger::init();
|
||||
|
||||
let cli = Cli::parse();
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ impl Chip8Computer {
|
||||
|
||||
|
||||
pub fn step_system(&mut self) -> &mut Chip8Computer {
|
||||
println!("Stepping System 1 Step");
|
||||
// println!("Stepping System 1 Step");
|
||||
// read the next instruction
|
||||
let local_memory = &self.memory;
|
||||
|
||||
|
||||
@@ -1019,7 +1019,7 @@ impl Chip8CpuInstructions {
|
||||
}
|
||||
Chip8CpuInstructions::LDIS(new_time) => {
|
||||
let new_value = input.registers.peek(*new_time);
|
||||
input.sound_timer.set_timer(new_value as i32);
|
||||
input.sound_timer.set_timer(new_value);
|
||||
}
|
||||
Chip8CpuInstructions::ADDI(x) => {
|
||||
// Fx1E - ADD I, Vx
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use log::trace;
|
||||
extern crate pretty_env_logger;
|
||||
|
||||
use log::warn;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
|
||||
pub struct SoundTimer {
|
||||
counter: i32,
|
||||
counter: u8,
|
||||
}
|
||||
|
||||
impl Default for SoundTimer {
|
||||
@@ -13,32 +15,25 @@ impl Default for SoundTimer {
|
||||
}
|
||||
|
||||
impl SoundTimer {
|
||||
pub fn current(&self) -> i32 {
|
||||
pub fn current(&self) -> u8 {
|
||||
self.counter
|
||||
}
|
||||
pub fn new() -> Self {
|
||||
SoundTimer { counter: 0 }
|
||||
}
|
||||
pub fn set_timer(&mut self, new_value: i32) {
|
||||
trace!("SETTING SOUND TIMER TO {new_value}");
|
||||
pub fn set_timer(&mut self, new_value: u8) {
|
||||
warn!("SETTING SOUND TIMER TO {new_value}");
|
||||
self.counter = new_value
|
||||
}
|
||||
|
||||
pub fn tick(&mut self) {
|
||||
trace!(
|
||||
warn!(
|
||||
"TICKING SOUND FROM {} to {}",
|
||||
self.counter,
|
||||
self.counter - 1
|
||||
);
|
||||
if self.counter > 0 {
|
||||
self.counter -= 1;
|
||||
/*
|
||||
todo: this breaks tests. maybe its wrong?
|
||||
if let good_thread = thread::spawn(|| {
|
||||
beep(440).expect("Unable to beep");
|
||||
thread::sleep(time::Duration::from_millis(500));
|
||||
}).join().unwrap().
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
use std::borrow::ToOwned;
|
||||
use std::clone::Clone;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::string::ToString;
|
||||
|
||||
pub const CHIP8_REGISTER_COUNT: i32 = 16;
|
||||
pub const CHIP8_MEMORY_SIZE: i32 = 4096i32;
|
||||
pub const CHIP8_VIDEO_WIDTH: i32 = 64i32;
|
||||
@@ -9,9 +14,10 @@ pub const LABEL_QUIRK_CHIP8: &str = "Chip8";
|
||||
pub const LABEL_QUIRK_XOCHIP: &str = "XO Chip";
|
||||
pub const LABEL_QUIRK_SCHIP: &str = "SChip-Modern";
|
||||
|
||||
pub const RESOURCES_ROOT: &str = "../resources";
|
||||
pub const TESTS_ROOT: &str = "../resources/test/";
|
||||
pub const TEST_ROM_ROOT: &str = "../resources/test/roms";
|
||||
pub const BASE_ROOT: &'static str = &(env!("CARGO_MANIFEST_DIR"));
|
||||
pub const RESOURCES_ROOT: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/../resources");
|
||||
pub const TESTS_ROOT: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/../resources/test");
|
||||
pub const TEST_ROM_ROOT: &'static str =concat!(env!("CARGO_MANIFEST_DIR"), "/../resources/test/roms");
|
||||
|
||||
pub const CHIP8_KEYBOARD: [[u8; 4]; 4] = [
|
||||
[0x01, 0x02, 0x03, 0x0C],
|
||||
|
||||
@@ -6,7 +6,7 @@ use gemma::chip8::computer_manager::Chip8ComputerManager;
|
||||
use gemma::chip8::quirk_modes::QuirkMode;
|
||||
use gemma::chip8::quirk_modes::QuirkMode::{Chip8, SChipModern, XOChip};
|
||||
use gemma::chip8::registers::Chip8Registers;
|
||||
use gemma::constants::{CHIP8_VIDEO_MEMORY, TESTS_ROOT};
|
||||
use gemma::constants::{CHIP8_VIDEO_MEMORY, TESTS_ROOT, TEST_ROM_ROOT};
|
||||
use crate::test_utils::{load_compressed_result, load_result, load_rom};
|
||||
|
||||
#[test]
|
||||
@@ -187,7 +187,7 @@ fn quirks_mode_test() {
|
||||
fn load_rom_allows_starting() {
|
||||
let mut new_manager = Chip8ComputerManager::default();
|
||||
assert!(!new_manager.core_should_run);
|
||||
let p = format!("{}/../resources/test/roms/1-chip8-logo.ch8" , std::env::current_dir().unwrap().display());
|
||||
let p = TEST_ROM_ROOT.to_string() + "/1-chip8-logo.ch8";
|
||||
let full_path = Path::new(p.as_str());
|
||||
new_manager.load_new_program_from_disk_to_system_memory(full_path);
|
||||
assert!(new_manager.core_should_run)
|
||||
|
||||
@@ -11,20 +11,6 @@ fn load_result(to_load: &str) -> String {
|
||||
std::fs::read_to_string(full_path).unwrap()
|
||||
}
|
||||
|
||||
// fn load_compressed_result(file_path: &str) -> io::Result<String> {
|
||||
// // Load the compressed file contents
|
||||
// let compressed_data = fs::read(file_path)?;
|
||||
//
|
||||
// // Create a GzDecoder to uncompress the data
|
||||
// let mut decoder = GzDecoder::new(&mut compressed_data[..]);
|
||||
// let mut decompressed_data = String::new();
|
||||
//
|
||||
// // Read the decompressed data directly into a String
|
||||
// decoder.read_to_string(&mut decompressed_data)?;
|
||||
//
|
||||
// Ok(decompressed_data)
|
||||
// }
|
||||
|
||||
fn load_rom(to_load: &str) -> Vec<u8> {
|
||||
fs::read(format!("resources/test/roms/{}", to_load)).unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user