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:
@@ -1,5 +1,5 @@
|
||||
use crate::support::GemmaEGuiSupport::GemmaEGui;
|
||||
use crate::support::EmmaEGuiState::EmmaEGuiState;
|
||||
use crate::support::gemma_egui_support::GemmaEguiSupport;
|
||||
use crate::support::gemma_egui_state::GemmaEGuiState;
|
||||
use eframe::egui;
|
||||
use egui::Ui;
|
||||
use gemma::chip8::computer::Chip8Computer;
|
||||
@@ -14,25 +14,24 @@ fn main() -> eframe::Result {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut state = EmmaEGuiState::default();
|
||||
let mut state = GemmaEGuiState::default();
|
||||
let mut computer = Chip8Computer::new();
|
||||
|
||||
eframe::run_simple_native("EGUI Emma", options, move |ctx, _frame| {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Gemma");
|
||||
ui.heading("EGUI Gemma");
|
||||
|
||||
GemmaEGui::controls_view(&mut computer, &mut state, ui);
|
||||
|
||||
if state.display_memory {
|
||||
GemmaEGui::memory_view(&computer, ui);
|
||||
}
|
||||
GemmaEguiSupport::controls_view(&mut computer, &mut state, ui);
|
||||
|
||||
if state.display_video {
|
||||
GemmaEGui::video_view(&computer, ui);
|
||||
GemmaEguiSupport::video_view(&computer, ui);
|
||||
}
|
||||
if state.display_memory {
|
||||
GemmaEguiSupport::memory_view(&computer, &mut state, ui);
|
||||
}
|
||||
|
||||
if state.display_registers {
|
||||
GemmaEGui::registers_view(&computer, ui);
|
||||
GemmaEguiSupport::registers_view(&computer, ui);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
use egui::Color32;
|
||||
use egui::Rect;
|
||||
use egui::Pos2;
|
||||
use egui::Vec2;
|
||||
use egui::Ui;
|
||||
use crate::support::EmmaEGuiState::EmmaEGuiState;
|
||||
use crate::Chip8Computer;
|
||||
|
||||
pub struct GemmaEGui {}
|
||||
impl GemmaEGui {
|
||||
pub fn controls_view(mut system: &mut Chip8Computer, state: &mut EmmaEGuiState, ui: &mut Ui) {
|
||||
if ui.button("Step").clicked() {
|
||||
system.step_system();
|
||||
}
|
||||
if ui.button("Start").clicked() {
|
||||
println!("Start");
|
||||
}
|
||||
if ui.button("Stop").clicked() {
|
||||
println!("STOP");
|
||||
}
|
||||
if ui.button("Reset").clicked() {}
|
||||
|
||||
ui.checkbox(&mut state.display_memory, "Display Memory");
|
||||
ui.checkbox(&mut state.display_video, "Display Video");
|
||||
ui.checkbox(&mut state.display_registers, "Display Registers");
|
||||
}
|
||||
|
||||
pub fn registers_view(system: &Chip8Computer, ui: &mut Ui) {
|
||||
ui.label(format!("V0-7: {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} ",
|
||||
system.registers.peek(0x00),
|
||||
system.registers.peek(0x01),
|
||||
system.registers.peek(0x02),
|
||||
system.registers.peek(0x03),
|
||||
system.registers.peek(0x04),
|
||||
system.registers.peek(0x05),
|
||||
system.registers.peek(0x06),
|
||||
system.registers.peek(0x07)
|
||||
));
|
||||
ui.label(format!("V8-F: {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} ",
|
||||
system.registers.peek(0x08),
|
||||
system.registers.peek(0x09),
|
||||
system.registers.peek(0x0A),
|
||||
system.registers.peek(0x0B),
|
||||
system.registers.peek(0x0C),
|
||||
system.registers.peek(0x0D),
|
||||
system.registers.peek(0x0E),
|
||||
system.registers.peek(0x0F)
|
||||
));
|
||||
ui.label(format!("PC: {:04x}\tI: {:04x}", system.registers.peek_pc(), system.registers.peek_i()));
|
||||
}
|
||||
|
||||
pub fn video_view(system: &Chip8Computer, ui: &mut Ui) {
|
||||
ui.label("Video goes here");
|
||||
let (resp, painter) = ui.allocate_painter(Vec2::new(400.0, 500.0), egui::Sense::hover());
|
||||
for current_row in 0..32 {
|
||||
for current_col in 0..64 {
|
||||
let data_offset = current_row * 32 + current_col;
|
||||
let origin = ui.next_widget_position();
|
||||
let colour = if system.video_memory.peek(data_offset) {
|
||||
Color32::RED
|
||||
} else {
|
||||
Color32::BLUE
|
||||
};
|
||||
let rect = Rect::from_min_size(origin, Vec2::new(10.0, 10.0));
|
||||
painter.rect_filled(rect, 0.0, colour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn memory_view(system: &Chip8Computer, ui: &mut Ui) {
|
||||
ui.label("Memory View");
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -1,16 +1,20 @@
|
||||
|
||||
pub struct EmmaEGuiState {
|
||||
pub struct GemmaEGuiState {
|
||||
pub display_video: bool,
|
||||
pub display_memory: bool,
|
||||
pub display_registers: bool,
|
||||
pub memory_view_min: i32,
|
||||
pub memory_view_max: i32
|
||||
}
|
||||
|
||||
impl Default for EmmaEGuiState {
|
||||
impl Default for GemmaEGuiState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
display_video: true,
|
||||
display_memory: true,
|
||||
display_registers: true,
|
||||
memory_view_min: 0x00,
|
||||
memory_view_max: 0x100
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
use std::fs::read_dir;
|
||||
use std::ops::Index;
|
||||
use std::path::{Display, PathBuf};
|
||||
use egui::{Align, Color32, ComboBox, Direction, Pos2};
|
||||
use egui::Rect;
|
||||
use egui::Vec2;
|
||||
use egui::Ui;
|
||||
use crate::support::gemma_egui_state::GemmaEGuiState;
|
||||
use crate::Chip8Computer;
|
||||
|
||||
const CELL_WIDTH: f32 = 5.0;
|
||||
const CELL_HEIGHT: f32 = 5.0;
|
||||
|
||||
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")));
|
||||
|
||||
egui::ComboBox::from_label(format!(
|
||||
"Currently selected string: {}",
|
||||
selected_filename
|
||||
))
|
||||
.selected_text(selected_filename.clone())
|
||||
.show_ui(ui, |ui| {
|
||||
for option in read_dir(root.as_path()).unwrap() {
|
||||
ui.label(format!("{:?}", option.unwrap().file_name()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
}
|
||||
if ui.button("Step").clicked() {
|
||||
system.step_system();
|
||||
}
|
||||
|
||||
if ui.button("Stop").clicked() {
|
||||
println!("STOP");
|
||||
}
|
||||
if ui.button("Reset").clicked() {
|
||||
system.reset();
|
||||
system.video_memory = system.video_memory.reset();
|
||||
}
|
||||
|
||||
if ui.button("Load initial rom").clicked() {
|
||||
println!("CLICK ON LOAD");
|
||||
// load the bin...
|
||||
let read_bin = std::fs::read(PathBuf::from("resources/roms/1-chip8-logo.ch8")).unwrap();
|
||||
// ...then feed the system.
|
||||
system.load_bytes_to_memory(0x200, &read_bin);
|
||||
}
|
||||
});
|
||||
|
||||
ui.checkbox(&mut state.display_memory, "Display Memory");
|
||||
ui.checkbox(&mut state.display_video, "Display Video");
|
||||
ui.checkbox(&mut state.display_registers, "Display Registers");
|
||||
}
|
||||
|
||||
pub fn registers_view(system: &Chip8Computer, ui: &mut Ui) {
|
||||
ui.label(format!("V0-7: {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} ",
|
||||
system.registers.peek(0x00),
|
||||
system.registers.peek(0x01),
|
||||
system.registers.peek(0x02),
|
||||
system.registers.peek(0x03),
|
||||
system.registers.peek(0x04),
|
||||
system.registers.peek(0x05),
|
||||
system.registers.peek(0x06),
|
||||
system.registers.peek(0x07)
|
||||
));
|
||||
ui.label(format!("V8-F: {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} {:02x} ",
|
||||
system.registers.peek(0x08),
|
||||
system.registers.peek(0x09),
|
||||
system.registers.peek(0x0A),
|
||||
system.registers.peek(0x0B),
|
||||
system.registers.peek(0x0C),
|
||||
system.registers.peek(0x0D),
|
||||
system.registers.peek(0x0E),
|
||||
system.registers.peek(0x0F)
|
||||
));
|
||||
ui.label(format!("PC: {:04x}\tI: {:04x}", system.registers.peek_pc(), system.registers.peek_i()));
|
||||
}
|
||||
|
||||
pub fn video_view(system: &Chip8Computer, ui: &mut Ui) {
|
||||
ui.label("Video goes here");
|
||||
let (resp, painter) = ui.allocate_painter(Vec2::new(400.0, 500.0), egui::Sense::hover());
|
||||
for current_row in 0..64 {
|
||||
for current_col in 0..32 {
|
||||
let data_offset = current_row * 32 + current_col;
|
||||
let x_offset = current_col as f32 * CELL_WIDTH;
|
||||
let y_offset = current_row as f32 * CELL_HEIGHT;
|
||||
let origin = Pos2::new(x_offset, y_offset);
|
||||
let colour = if system.video_memory.peek(data_offset) {
|
||||
Color32::RED
|
||||
} else {
|
||||
Color32::WHITE
|
||||
};
|
||||
let rect = Rect::from_min_size(origin, Vec2::new(CELL_WIDTH, CELL_HEIGHT));
|
||||
painter.rect_filled(rect, 0.0, colour);
|
||||
// println!("DataOffset: [{:04x}] X_Offset: [{:04x}] Y_Offset: [{:04x}] Origin: [{:04x}]x[{:04x}]",
|
||||
// data_offset as u16,
|
||||
// x_offset as u16,
|
||||
// y_offset as u16,
|
||||
// origin.x as u16, origin.y as u16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn memory_view(system: &Chip8Computer, gui_state: &mut GemmaEGuiState, ui: &mut Ui) {
|
||||
ui.label("Memory View");
|
||||
|
||||
for i in (gui_state.memory_view_min..gui_state.memory_view_max).step_by(16) {
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||
for y in 0..16 {
|
||||
ui.label(format!("{:02x}", system.memory.peek((i + y) as u16)).as_str());
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.label("Should have **something** to adjust the 'memory window'");
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
pub mod EmmaEGuiState;
|
||||
pub mod GemmaEGuiSupport;
|
||||
pub mod gemma_egui_state;
|
||||
pub mod gemma_egui_support;
|
||||
|
||||
Reference in New Issue
Block a user