61 lines
1.9 KiB
Rust
61 lines
1.9 KiB
Rust
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::ADDI(0x01), ui);
|
|
display_instruction(0x012, &Chip8CpuInstructions::RND(0x01, 0x02), ui);
|
|
});
|
|
ui.text_edit_multiline(&mut edit_space);
|
|
});
|
|
})
|
|
} |