more validation tests for gemma video rendering

Adds 'doom like' 3dviprmaze-vip for demo (VERY VERY SLOW)
updates egui interface to let user select from files in resources/roms
updates cargo to centralize dependencies
95 passing tests
This commit is contained in:
2024-10-16 10:02:24 -04:00
parent 939fd83e80
commit b4b8bfb24b
21 changed files with 404 additions and 131 deletions
+2 -2
View File
@@ -5,5 +5,5 @@ edition = "2021"
[dependencies]
gemma = { path = "../gemma" }
egui = "0.29.1"
eframe = "0.29.1"
egui.workspace = true
eframe.workspace = true
+34 -13
View File
@@ -1,3 +1,4 @@
use std::time::Instant;
use crate::support::gemma_egui_support::GemmaEguiSupport;
use crate::support::gemma_egui_state::GemmaEGuiState;
use eframe::egui;
@@ -16,26 +17,46 @@ fn main() -> eframe::Result {
let mut state = GemmaEGuiState::default();
let mut computer = Chip8Computer::new();
let mut cps_counter = 0;
let mut last_counter_update = Instant::now();
let cps_refresh = 5;
let mut last_frame_start = Instant::now();
eframe::run_simple_native("EGUI Emma", options, move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
if state.display_video {
GemmaEguiSupport::video_view(&computer, ui);
let should_render_frame = Instant::now().duration_since(last_frame_start).as_millis() >= 10;
if should_render_frame {
last_frame_start = Instant::now();
if state.display_video {
GemmaEguiSupport::video_view(&computer, ui);
}
ui.heading("EGUI Gemma");
GemmaEguiSupport::controls_view(&mut computer, &mut state, ui);
if state.display_memory {
GemmaEguiSupport::memory_view(&computer, &mut state, ui);
}
if state.display_registers {
GemmaEguiSupport::registers_view(&computer, ui);
}
}
ui.heading("EGUI Gemma");
GemmaEguiSupport::controls_view(&mut computer, &mut state, ui);
if state.display_memory {
GemmaEguiSupport::memory_view(&computer, &mut state, ui);
}
if state.display_registers {
GemmaEguiSupport::registers_view(&computer, ui);
}
if state.is_running {
computer.step_system();
cps_counter += 1;
}
let rt = Instant::now();
let ms = rt.duration_since(last_counter_update).as_millis();
if ms > 5000 {
let cps = (cps_counter * 1000) / ms;
println!("Executing {cps} instructions per 5s ({ms}/{cps_counter})");
last_counter_update = rt;
cps_counter = 0;
}
});
})
@@ -5,7 +5,8 @@ pub struct GemmaEGuiState {
pub display_registers: bool,
pub memory_view_min: i32,
pub memory_view_max: i32,
pub is_running: bool
pub is_running: bool,
pub selected_rom_filename: String
}
impl Default for GemmaEGuiState {
@@ -16,7 +17,8 @@ impl Default for GemmaEGuiState {
display_registers: true,
memory_view_min: 0x00,
memory_view_max: 0x100,
is_running: false
is_running: false,
selected_rom_filename: String::new()
}
}
}
+45 -35
View File
@@ -3,10 +3,12 @@ use std::ops::Index;
use std::path::{Display, PathBuf};
use std::thread;
use std::time::Duration;
use egui::{Align, Color32, ComboBox, Direction, Pos2};
use egui::{Align, Color32, ComboBox, Direction, Pos2, Response, TextBuffer};
use egui::accesskit::Role::ListBox;
use egui::Rect;
use egui::Vec2;
use egui::Ui;
use egui::WidgetType::SelectableLabel;
use crate::support::gemma_egui_state::GemmaEGuiState;
use crate::Chip8Computer;
@@ -17,20 +19,29 @@ pub struct EGuiFileList {}
impl EGuiFileList {
pub fn display_path(root: PathBuf, selected_filename: &mut String, ui: &mut Ui) {
let mut working_filename = selected_filename.clone();
ui.label(format!("Displaying {}", root.to_str().unwrap_or("Unable to Load Path")));
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
// ui.label(format!("Displaying {}", root.to_str().unwrap_or("Unable to Load Path")));
ComboBox::from_label("Select ROM")
.selected_text(selected_filename.clone())
.show_ui(ui, |ui| {
ComboBox::from_label("Choose an option")
.selected_text(selected_filename.clone())
.show_ui(ui, |ui| {
for option in read_dir(root.as_path()).unwrap() {
let mut sorted_options = vec![];
for option in read_dir(root.as_path()).unwrap() {
let to_push = option.unwrap().file_name().into_string().unwrap_or( String::new());
sorted_options.push(to_push);
}
sorted_options.sort();
for item in sorted_options {
// Add each option to the ComboBox
let mut label = option.unwrap().file_name();
ui.selectable_value(selected_filename, selected_filename.clone(), label.into_string().unwrap());
}
});
// Display the selected option
ui.label(format!("Selected value: {}", selected_filename));
if ui.selectable_label(selected_filename.eq(&item.as_str()), item.clone()).clicked()
{
*selected_filename = item;
}
}
});
// Display the selected option
});
}
}
@@ -39,34 +50,33 @@ pub struct GemmaEguiSupport {}
impl GemmaEguiSupport {
pub fn controls_view(mut system: &mut Chip8Computer, state: &mut GemmaEGuiState, ui: &mut Ui) {
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
if ui.button("Start").clicked() {
println!("Start");
state.is_running = true;
if ui.button("Start").clicked() {
println!("Start");
state.is_running = true;
}
if ui.button("Step").clicked() {
system.step_system();
}
}
if ui.button("Step").clicked() {
system.step_system();
}
if ui.button("Stop").clicked() {
println!("STOP");
state.is_running = false;
}
if ui.button("Reset").clicked() {
system.reset();
state.is_running = false;
}
});
if ui.button("Stop").clicked() {
println!("STOP");
state.is_running = false;
}
if ui.button("Reset").clicked() {
system.reset();
system.video_memory.reset();
}
if ui.button("Load initial rom").clicked() {
println!("CLICK ON LOAD");
if ui.button(format!("Load {}", state.selected_rom_filename)).clicked() {
// load the bin...
let read_bin = std::fs::read(PathBuf::from("resources/roms/1-chip8-logo.ch8")).unwrap();
let read_bin = std::fs::read(PathBuf::from(format!("resources/roms/{}", state.selected_rom_filename))).unwrap();
// ...then feed the system.
system.load_bytes_to_memory(0x200, &read_bin);
println!("Loaded {}", state.selected_rom_filename);
}
let mut target = String::new();
EGuiFileList::display_path(PathBuf::from("resources/roms"), &mut target, ui);
});
EGuiFileList::display_path(PathBuf::from("resources/roms"), &mut state.selected_rom_filename, ui);
ui.with_layout(egui::Layout::left_to_right(Align::TOP), |ui| {