more dump of "Emma" for Gemma

Video reset now tests ok
gemma egui interface now implements stupid workaround for video reset
This commit is contained in:
2024-10-12 10:51:57 -04:00
parent c9ef6d4e04
commit bfb615cfe7
19 changed files with 352 additions and 1082 deletions
+13 -11
View File
@@ -9,7 +9,7 @@ use imgui::*;
use sys::{ImColor, ImVec2, ImVector_ImU32};
use rand::random;
use gemma::chip8::system_memory::Chip8SystemMemory;
use support::{emmagui_support::EmmaGui, ui_state::UiState};
use support::{emmagui_support::GemmaImguiSupport, ui_state::ImGuiUiState};
mod support;
@@ -27,12 +27,12 @@ const LIN_KEYS: [(u16, u8); 0x10] = [(537, 0x01),(538, 0x02),(539, 0x03),(540, 0
fn main() {
pretty_env_logger::init();
let mut system = Chip8Computer::default();
let mut ui_state = UiState::default();
let mut last_tick_time = Instant::now();
let mut ui_state = ImGuiUiState::default();
support::simple_init(file!(), move |_, ui| {
let current_time = Instant::now();
// Key Checks
let down_keys = ui.io().keys_down;
for (key_code, key_reg) in LIN_KEYS {
if down_keys[key_code as usize] {
@@ -44,8 +44,9 @@ fn main() {
}
}
}
// println!("KEYS DOWN = {:?}", ui.io().keys_down);
let time_since_last_tick = current_time.duration_since(last_tick_time).as_millis();
// Next Tick Check
let time_since_last_tick = current_time.duration_since(ui_state.last_frame_instant).as_millis();
if ui_state.is_running && time_since_last_tick > ui_state.frame_time as u128 {
match system.state {
gemma::chip8::cpu_states::Chip8CpuStates::WaitingForInstruction => {
@@ -61,26 +62,27 @@ fn main() {
panic!("System in undefined state.");
},
}
last_tick_time = current_time;
ui_state.last_frame_instant = current_time;
}
EmmaGui::system_controls(&mut system, &mut ui_state, ui);
// GUI Parts
GemmaImguiSupport::system_controls(&mut system, &mut ui_state, ui);
if ui_state.show_registers {
EmmaGui::registers_view(&system, ui);
GemmaImguiSupport::registers_view(&system, ui);
}
if ui_state.show_video {
EmmaGui::video_display(&system, &ui_state, ui);
GemmaImguiSupport::video_display(&system, &ui_state, ui);
}
if ui_state.show_memory {
let active_instruction = system.registers.peek_pc();
EmmaGui::hex_memory_display(system.memory.clone(), (0x100, 0x10), active_instruction as i16, ui);
GemmaImguiSupport::hex_memory_display(system.memory.clone(), (0x100, 0x10), active_instruction as i16, ui);
}
if ui_state.show_keypad {
EmmaGui::keypad_display(&system, ui);
GemmaImguiSupport::keypad_display(&system, ui);
}
});
}
@@ -9,11 +9,11 @@ use log::debug;
use gemma::chip8::computer::Chip8Computer;
use gemma::chip8::system_memory::Chip8SystemMemory;
use gemma::constants::{CHIP8_VIDEO_HEIGHT, CHIP8_VIDEO_WIDTH};
use crate::UiState;
use crate::ImGuiUiState;
use super::ui_state;
pub struct EmmaGui {}
pub struct GemmaImguiSupport {}
const CELL_WIDTH: i32 = 5i32;
const CELL_HEIGHT: i32 = 5i32;
@@ -40,8 +40,7 @@ impl GuiFileList {
}
}
impl EmmaGui {
impl GemmaImguiSupport {
pub fn keypad_display(system_to_display: &Chip8Computer, ui: &Ui) {
ui.text("Keypad");
@@ -59,9 +58,10 @@ impl EmmaGui {
}
}
pub fn video_display(system_to_control: &Chip8Computer, gui_state: &UiState, ui: &Ui) {
pub fn video_display(system_to_control: &Chip8Computer, gui_state: &ImGuiUiState, ui: &Ui) {
// draw area size
let draw_area_size = ui.io().display_size;
println!("DRAW_AREA_SIZE = {}x{}", draw_area_size[0], draw_area_size[1]);
let cell_width = ((draw_area_size[0] as i32 / 64) * 6) / 10;
let cell_height = ((draw_area_size[1] as i32 / 32) * 6) / 10;
@@ -89,7 +89,7 @@ impl EmmaGui {
}
});
}
pub fn system_controls(system_to_control: &mut Chip8Computer, gui_state: &mut UiState, ui: &Ui) {
pub fn system_controls(system_to_control: &mut Chip8Computer, gui_state: &mut ImGuiUiState, ui: &Ui) {
ui.window("!!!! CONTROLS !!!!")
.size([345.0, 200.0], Condition::FirstUseEver)
.build(|| {
@@ -107,7 +107,7 @@ impl EmmaGui {
// 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");
input_file.read_to_end(&mut buffer).expect("unable to read file");
system_to_control.load_bytes_to_memory(0x200, buffer.into());
system_to_control.load_bytes_to_memory(0x200, (&buffer).into());
}
}
ui.separator();
+9 -6
View File
@@ -1,7 +1,7 @@
use std::time::Instant;
use imgui::ImColor32;
pub struct UiState {
pub struct ImGuiUiState {
pub show_registers: bool,
pub show_memory: bool,
pub show_video: bool,
@@ -11,11 +11,12 @@ pub struct UiState {
pub off_colour: ImColor32,
pub is_running: bool,
pub frame_time: f32,
pub last_frame_instant: Instant
}
impl Clone for UiState {
impl Clone for ImGuiUiState {
fn clone(&self) -> Self {
UiState {
ImGuiUiState {
show_registers: self.show_registers,
show_memory: self.show_memory,
show_video: self.show_video,
@@ -25,13 +26,14 @@ impl Clone for UiState {
off_colour: self.off_colour,
is_running: self.is_running,
frame_time: self.frame_time,
last_frame_instant: self.last_frame_instant
}
}
}
impl Default for UiState {
impl Default for ImGuiUiState {
fn default() -> Self {
UiState {
ImGuiUiState {
show_registers: false,
show_memory: false,
show_video: true,
@@ -41,6 +43,7 @@ impl Default for UiState {
off_colour: ImColor32::from_rgb(0x00, 0xff, 0xff),
is_running: false,
frame_time: 10.0,
last_frame_instant: Instant::now()
}
}
}