evolve egui interface
move more control back up to the ComputerManager
This commit is contained in:
@@ -1,23 +1,31 @@
|
||||
use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
use crate::support::gemma_egui_support::{EGuiFileList, GemmaEguiSupport};
|
||||
use crate::support::gemma_egui_state::GemmaEGuiState;
|
||||
use eframe::egui;
|
||||
use egui::Ui;
|
||||
use egui::{Key, Ui};
|
||||
use gemma::chip8::computer::Chip8Computer;
|
||||
use gemma::chip8::computer_manager::Chip8ComputerManager;
|
||||
|
||||
mod support;
|
||||
|
||||
const LIN_KEYS: [[(Key, u8); 4]; 4] = [
|
||||
[(Key::Num1, 0x01), (Key::Num2, 0x02), (Key::Num3, 0x03), (Key::Num4, 0x0c)],
|
||||
[(Key::Q, 0x04), (Key::W, 0x05), (Key::E, 0x06), (Key::R, 0x0d)],
|
||||
[(Key::A, 0x07), (Key::S, 0x08), (Key::D, 0x09), (Key::F, 0x0e)],
|
||||
[(Key::Z, 0x0a), (Key::X, 0x00), (Key::C, 0x0b), (Key::V, 0x0F)]
|
||||
];
|
||||
|
||||
#[derive(Default)]
|
||||
struct DisplayOptions {
|
||||
pub video: bool,
|
||||
pub registers: bool,
|
||||
pub memory: bool
|
||||
pub memory: bool,
|
||||
}
|
||||
pub struct GemmaViewerState {
|
||||
pub selected_file_index: i32,
|
||||
pub selected_filename: String,
|
||||
pub display_options: DisplayOptions
|
||||
pub display_options: DisplayOptions,
|
||||
}
|
||||
|
||||
impl Default for GemmaViewerState {
|
||||
@@ -25,7 +33,7 @@ impl Default for GemmaViewerState {
|
||||
GemmaViewerState {
|
||||
selected_file_index: -1,
|
||||
selected_filename: String::new(),
|
||||
display_options: Default::default()
|
||||
display_options: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,28 +62,28 @@ fn main() -> eframe::Result {
|
||||
computer.tick();
|
||||
let local_computer = computer.state();
|
||||
//if state.display_video {
|
||||
GemmaEguiSupport::video_view(local_computer, ui);
|
||||
// }
|
||||
GemmaEguiSupport::video_view(local_computer, ui);
|
||||
// }
|
||||
|
||||
ui.heading("EGUI Gemma");
|
||||
|
||||
// if state.display_memory {
|
||||
GemmaEguiSupport::memory_view(&local_computer, ui);
|
||||
// }
|
||||
// if state.display_memory {
|
||||
GemmaEguiSupport::memory_view(&local_computer, ui);
|
||||
// }
|
||||
|
||||
// if state.display_registers {
|
||||
GemmaEguiSupport::registers_view(&local_computer, ui);
|
||||
// }
|
||||
// if state.display_registers {
|
||||
GemmaEguiSupport::registers_view(&local_computer, ui);
|
||||
// }
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||
if ui.button("Start").clicked() {
|
||||
computer.core_should_run = true;
|
||||
computer.start();
|
||||
}
|
||||
if ui.button("Step").clicked() {
|
||||
computer.one_step = true;
|
||||
computer.step();
|
||||
}
|
||||
|
||||
if ui.button("Stop").clicked() {
|
||||
computer.core_should_run = false;
|
||||
computer.stop();
|
||||
// state.is_running = false;
|
||||
}
|
||||
if ui.button("Reset").clicked() {
|
||||
@@ -84,17 +92,31 @@ fn main() -> eframe::Result {
|
||||
}
|
||||
});
|
||||
|
||||
if ui.button(format!("Load {}", state.selected_filename)).clicked() {
|
||||
|
||||
}
|
||||
// // load the bin...
|
||||
// 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);
|
||||
// }
|
||||
// EGuiFileList::display_path(PathBuf::from("resources/roms"), &mut state.selected_rom_filename, ui);
|
||||
if ui.button(format!("Load {}", state.selected_filename)).clicked() {
|
||||
// println!("Should load the bin now");
|
||||
let read_bin = std::fs::read(PathBuf::from(format!("resources/roms/{}", state.selected_filename))).unwrap();
|
||||
computer.load_bytes_to_system_memory(read_bin);
|
||||
};
|
||||
EGuiFileList::display_path(PathBuf::from("resources/roms"), &mut state.selected_filename, ui);
|
||||
let input = ctx.input(|input| {
|
||||
// loop through the keys we are checking...
|
||||
for row in LIN_KEYS {
|
||||
for (keyboard_key, keypad_key) in row {
|
||||
if input.key_pressed(keyboard_key) {
|
||||
computer.press_key(keypad_key);
|
||||
// println!("KEY {keypad_key:02x} DOWN");
|
||||
} else {
|
||||
// release it if the user just did
|
||||
if computer.is_key_pressed(keypad_key) {
|
||||
computer.release_key(keypad_key);
|
||||
// println!("KEY {keypad_key:02x} up");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ctx.request_repaint();
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user