Adds 'name' and 'operand' to Chip8Instruction

This commit is contained in:
2024-10-18 15:34:49 -04:00
parent 1eeb746ccf
commit be6e652982
3 changed files with 243 additions and 99 deletions
+39 -12
View File
@@ -8,24 +8,50 @@ use gemma::chip8::computer_manager::Chip8ComputerManager;
mod support;
#[derive(Default)]
struct DisplayOptions {
pub video: bool,
pub registers: bool,
pub memory: bool
}
pub struct GemmaViewerState {
pub selected_file_index: i32,
pub selected_filename: String,
pub display_options: DisplayOptions
}
impl Default for GemmaViewerState {
fn default() -> Self {
GemmaViewerState {
selected_file_index: -1,
selected_filename: String::new(),
display_options: Default::default()
}
}
}
impl GemmaViewerState {
pub fn new() -> GemmaViewerState {
GemmaViewerState {
..Default::default()
}
}
}
fn main() -> eframe::Result {
println!("Taxation is Theft");
let mut computer = Chip8ComputerManager::new();
let mut state = GemmaViewerState::new();
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
..Default::default()
};
// let mut state = GemmaEGuiState::default();
let mut computer = Chip8ComputerManager::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| {
eframe::run_simple_native("EGUI Gemma", options, move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
computer.tick();
let local_computer = computer.state();
//if state.display_video {
GemmaEguiSupport::video_view(local_computer, ui);
@@ -40,7 +66,6 @@ fn main() -> eframe::Result {
// if state.display_registers {
GemmaEguiSupport::registers_view(&local_computer, ui);
// }
computer.tick();
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
if ui.button("Start").clicked() {
computer.core_should_run = true;
@@ -58,8 +83,10 @@ fn main() -> eframe::Result {
// state.is_running = false;
}
});
//
// if ui.button(format!("Load {}", state.selected_rom_filename)).clicked() {
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.
+61
View File
@@ -0,0 +1,61 @@
use egui::Ui;
use gemma::chip8::instructions::Chip8CpuInstructions;
/// GemmaEGui - Viewer
///
///
/// This program lets a user open a CH8 file and it will be decoded
/// as Chip-8 Instructions.
/// Colour variants for instructions show colours for
/// -> Jumps
/// -> Load
/// -> Store
/// -> Timers
/// -> Math (Add, Sub)
/// -> Logic
/// -> Video
fn display_instruction(offset: i32, to_display: &Chip8CpuInstructions, ui: &mut Ui) {
ui.label(format!("{offset:04x} {}", to_display.name()));
ui.label(format!("{}", to_display.operands()));
ui.end_row();
}
fn display_instructions(base_offset: i32, instructions: Vec<Chip8CpuInstructions>, ui: &mut Ui) {
egui::Grid::new("my_grid")
.min_col_width(200.0)
.show(ui, |ui| {
for (index, instruction) in instructions.iter().enumerate() {
display_instruction(base_offset + index as i32, instruction, ui);
}
});
}
fn main() -> eframe::Result {
let mut edit_space: String = String::new();
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 480.0]),
..Default::default()
};
eframe::run_simple_native("Gemma - Chip8 Machine Code Viewer", options, move |ctx, frame| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("Taxation is Theft");
// file picker
ui.vertical_centered(|ui| {
if ui.button("Load File").clicked() {
println!("Clicked load file");
}
});
ui.label("File Picker Herre");
ui.label("display of file here");
ui.vertical(|ui| {
display_instruction(0x010, &Chip8CpuInstructions::AddIVx(0x01), ui);
display_instruction(0x012, &Chip8CpuInstructions::RndVxByte(0x01, 0x02), ui);
});
ui.text_edit_multiline(&mut edit_space);
});
})
}