start of computer integration tests

This commit is contained in:
Trevor Merritt 2024-10-11 08:51:44 -04:00
parent 4fc0bfd3d8
commit 2ef8a78c32
4 changed files with 53 additions and 14 deletions

View File

@ -6,4 +6,11 @@ fn smoke() { assert!(true) }
#[test] #[test]
fn test_rom_1_works() { fn test_rom_1_works() {
let mut x = Chip8Computer::new(); let mut x = Chip8Computer::new();
// Load the IBM rom and run it...
// ...then verify that the current video memory of the chip-8
// simulator matches what we expect it to be
assert_eq!(x.dump_video_to_string(), );
} }

View File

@ -10,6 +10,7 @@ use sys::{ImColor, ImVec2, ImVector_ImU32};
use rand::random; use rand::random;
use gemma::chip8::system_memory::Chip8SystemMemory; use gemma::chip8::system_memory::Chip8SystemMemory;
use support::emmagui_support::EmmaGui; use support::emmagui_support::EmmaGui;
mod support; mod support;
struct UiState { struct UiState {
@ -17,10 +18,10 @@ struct UiState {
pub show_memory: bool, pub show_memory: bool,
pub show_video: bool, pub show_video: bool,
pub filename_to_load: String, pub filename_to_load: String,
pub on_colour: ImColor32, pub on_colour: ImColor32,
pub off_colour: ImColor32, pub off_colour: ImColor32,
pub is_running: bool, pub is_running: bool,
pub frame_time: f32 pub frame_time: f32,
} }
impl Clone for UiState { impl Clone for UiState {
@ -33,7 +34,7 @@ impl Clone for UiState {
on_colour: self.on_colour, on_colour: self.on_colour,
off_colour: self.off_colour, off_colour: self.off_colour,
is_running: self.is_running, is_running: self.is_running,
frame_time: self.frame_time frame_time: self.frame_time,
} }
} }
} }
@ -48,7 +49,7 @@ impl Default for UiState {
on_colour: ImColor32::from_rgb(0xff, 0xff, 0x00), on_colour: ImColor32::from_rgb(0xff, 0xff, 0x00),
off_colour: ImColor32::from_rgb(0x00, 0xff, 0xff), off_colour: ImColor32::from_rgb(0x00, 0xff, 0xff),
is_running: false, is_running: false,
frame_time: 10.0 frame_time: 10.0,
} }
} }
} }

View File

@ -10,7 +10,6 @@ use gemma::chip8::system_memory::Chip8SystemMemory;
use gemma::constants::{CHIP8_VIDEO_HEIGHT, CHIP8_VIDEO_WIDTH}; use gemma::constants::{CHIP8_VIDEO_HEIGHT, CHIP8_VIDEO_WIDTH};
use crate::UiState; use crate::UiState;
pub struct EmmaGui {} pub struct EmmaGui {}
const CELL_WIDTH: i32 = 5i32; const CELL_WIDTH: i32 = 5i32;
@ -78,13 +77,13 @@ impl EmmaGui {
let new_filename = GuiFileList::display_path(PathBuf::from("resources/roms"), &gui_state.filename_to_load, ui); let new_filename = GuiFileList::display_path(PathBuf::from("resources/roms"), &gui_state.filename_to_load, ui);
if !new_filename.is_empty() { if !new_filename.is_empty() {
if new_filename != gui_state.filename_to_load { if new_filename != gui_state.filename_to_load {
println!("NEW FILENAME SELECTED -> {new_filename}"); debug!("NEW FILENAME SELECTED -> {new_filename}");
gui_state.filename_to_load = new_filename; gui_state.filename_to_load = new_filename;
} }
if ui.button("Load Program") { if ui.button("Load Program") {
let mut buffer = Vec::new(); let mut buffer = Vec::new();
println!("PREPARING TO LOAD {}", gui_state.filename_to_load); debug!("PREPARING TO LOAD {}", gui_state.filename_to_load);
// let mut input_file = File::open(Path::new("./1-chip8-logo.ch8")).expect("put 1-chip8-logo.ch8 in this directory"); // let mut input_file = File::open(Path::new("./1-chip8-logo.ch8")).expect("put 1-chip8-logo.ch8 in this directory");
let mut input_file = File::open(Path::new(&("resources/roms/".to_string() + &gui_state.filename_to_load))).expect("put 1-chip8-logo.ch8 in this directory"); let mut input_file = File::open(Path::new(&("resources/roms/".to_string() + &gui_state.filename_to_load))).expect("put 1-chip8-logo.ch8 in this directory");
input_file.read_to_end(&mut buffer).expect("unable to read file"); input_file.read_to_end(&mut buffer).expect("unable to read file");
@ -97,26 +96,26 @@ impl EmmaGui {
}; };
if ui.button("Run") { if ui.button("Run") {
gui_state.is_running = true; gui_state.is_running = true;
println!("STARTING THE SYSTEM"); debug!("STARTING THE SYSTEM");
} }
if ui.button("Stop") { if ui.button("Stop") {
gui_state.is_running = false; gui_state.is_running = false;
println!("STOPPING THE SYSTEM"); debug!("STOPPING THE SYSTEM");
} }
ui.same_line(); ui.same_line();
if ui.button("Reset") { if ui.button("Reset") {
*system_to_control = Chip8Computer::new(); *system_to_control = Chip8Computer::new();
} }
if ui.button("Dump Video Memory") { if ui.button("Dump Video Memory") {
println!("{}", system_to_control.dump_video_to_string()); debug!("{}", system_to_control.dump_video_to_string());
} }
ui.same_line(); ui.same_line();
if ui.button("Dump Keypad State") { if ui.button("Dump Keypad State") {
println!("{}", system_to_control.dump_keypad_to_string()); debug!("{}", system_to_control.dump_keypad_to_string());
} }
ui.same_line(); ui.same_line();
if ui.button("Dump Registers") { if ui.button("Dump Registers") {
println!("{}", system_to_control.dump_registers_to_string()); debug!("{}", system_to_control.dump_registers_to_string());
} }
ui.separator(); ui.separator();
@ -193,7 +192,7 @@ impl EmmaGui {
// Check if the left mouse button is clicked while hovering over the text // Check if the left mouse button is clicked while hovering over the text
if ui.is_mouse_clicked(imgui::MouseButton::Left) { if ui.is_mouse_clicked(imgui::MouseButton::Left) {
println!("Offset: [{}] [0x{:02x}] Value: [{}]", data_offset, data_offset, formatted_text.clone()); debug!("Offset: [{}] [0x{:02x}] Value: [{}]", data_offset, data_offset, formatted_text.clone());
// Perform any action here, e.g., call a function, trigger an event, etc. // Perform any action here, e.g., call a function, trigger an event, etc.
} }
} }

View File

@ -0,0 +1,32 @@
******** ********* ***** ***** * *
* *
******** *********** ****** ****** *
**** *** *** ***** ***** * *
***
**** ******* ******* ******* *
*
**** ******* *** ******* ***
*
**** *** *** *** ***** ***
***
******** *********** ***** *** ***** *
**
******** ********* ***** * ***** ***