more passing tests. almost have coverage of instructions back
This commit is contained in:
@@ -2,7 +2,7 @@ use gemma::constants::CHIP8_KEYBOARD;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
use imgui::{Condition, ImColor32, Ui};
|
||||
use imgui::{CollapsingHeader, Condition, ImColor32, Ui};
|
||||
use log::debug;
|
||||
use gemma::chip8::computer::Chip8Computer;
|
||||
use gemma::chip8::computer_manager::Chip8ComputerManager;
|
||||
@@ -46,44 +46,44 @@ impl GemmaImguiSupport {
|
||||
let cell_width = ((draw_area_size[0] as i32 / width) * 6) / 10;
|
||||
let cell_height = ((draw_area_size[1] as i32 / height) * 6) / 10;
|
||||
|
||||
let origin = ui.cursor_pos();
|
||||
let fg = ui.get_foreground_draw_list();
|
||||
if system_to_control.video_memory.is_highres() {
|
||||
// ui.text("High Def Video here");
|
||||
for current_row in 0..=height {
|
||||
let y_offset = origin[1] as i32 + (current_row * cell_height);
|
||||
for current_column in 0..=width {
|
||||
let x_offset = origin[0] as i32 + (current_column * cell_width);
|
||||
let current_origin = [x_offset as f32, y_offset as f32];
|
||||
let current_limit = [(x_offset + cell_width) as f32, (y_offset + cell_height) as f32];
|
||||
let memory_offset = (current_row * width + current_column) as u16;
|
||||
let to_render = system_to_control.video_memory.peek(memory_offset);
|
||||
let color: ImColor32 = if to_render {
|
||||
gui_state.on_colour
|
||||
} else {
|
||||
gui_state.off_colour
|
||||
};
|
||||
fg.add_rect_filled_multicolor(current_origin, current_limit, color, color, color, color);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for current_row in 0..height {
|
||||
let y_offset = origin[1] as i32 + (current_row * cell_height);
|
||||
for current_column in 0..width {
|
||||
let x_offset = origin[0] as i32 + (current_column * cell_width);
|
||||
let current_origin = [x_offset as f32, y_offset as f32];
|
||||
let current_limit = [(x_offset + cell_width) as f32, (y_offset + cell_height) as f32];
|
||||
let memory_offset = (current_row * width + current_column) as u16;
|
||||
let to_render = system_to_control.video_memory.peek(memory_offset);
|
||||
let color: ImColor32 = if to_render {
|
||||
gui_state.on_colour
|
||||
} else {
|
||||
gui_state.off_colour
|
||||
};
|
||||
fg.add_rect_filled_multicolor(current_origin, current_limit, color, color, color, color);
|
||||
}
|
||||
let origin = ui.cursor_pos();
|
||||
let fg = ui.get_foreground_draw_list();
|
||||
if system_to_control.video_memory.is_highres() {
|
||||
// ui.text("High Def Video here");
|
||||
for current_row in 0..=height {
|
||||
let y_offset = origin[1] as i32 + (current_row * cell_height);
|
||||
for current_column in 0..=width {
|
||||
let x_offset = origin[0] as i32 + (current_column * cell_width);
|
||||
let current_origin = [x_offset as f32, y_offset as f32];
|
||||
let current_limit = [(x_offset + cell_width) as f32, (y_offset + cell_height) as f32];
|
||||
let memory_offset = (current_row * width + current_column) as u16;
|
||||
let to_render = system_to_control.video_memory.peek(memory_offset);
|
||||
let color: ImColor32 = if to_render {
|
||||
gui_state.on_colour
|
||||
} else {
|
||||
gui_state.off_colour
|
||||
};
|
||||
fg.add_rect_filled_multicolor(current_origin, current_limit, color, color, color, color);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for current_row in 0..height {
|
||||
let y_offset = origin[1] as i32 + (current_row * cell_height);
|
||||
for current_column in 0..width {
|
||||
let x_offset = origin[0] as i32 + (current_column * cell_width);
|
||||
let current_origin = [x_offset as f32, y_offset as f32];
|
||||
let current_limit = [(x_offset + cell_width) as f32, (y_offset + cell_height) as f32];
|
||||
let memory_offset = (current_row * width + current_column) as u16;
|
||||
let to_render = system_to_control.video_memory.peek(memory_offset);
|
||||
let color: ImColor32 = if to_render {
|
||||
gui_state.on_colour
|
||||
} else {
|
||||
gui_state.off_colour
|
||||
};
|
||||
fg.add_rect_filled_multicolor(current_origin, current_limit, color, color, color, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn system_controls(system_to_control: &mut Chip8ComputerManager, gui_state: &mut ImGuiUiState, ui: &Ui) {
|
||||
// let mut state: Chip8Computer = system_to_control;
|
||||
@@ -94,58 +94,71 @@ impl GemmaImguiSupport {
|
||||
ui.text(format!("Step {:04x}", system_to_control.num_cycles()).as_str());
|
||||
|
||||
/* ROM Lister */
|
||||
let new_filename = GuiFileList::display_path(PathBuf::from(ROM_ROOT), &gui_state.filename_to_load, ui);
|
||||
if !new_filename.is_empty() {
|
||||
if new_filename != gui_state.filename_to_load {
|
||||
debug!("NEW FILENAME SELECTED -> {new_filename}");
|
||||
gui_state.filename_to_load = new_filename;
|
||||
}
|
||||
if ui.button("Load Program") {
|
||||
let mut buffer = Vec::new();
|
||||
debug!("PREPARING TO LOAD {}", gui_state.filename_to_load);
|
||||
// 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(&(ROM_ROOT.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_system_memory((&*buffer).into());
|
||||
if CollapsingHeader::new("Roms").build(ui) {
|
||||
let new_filename = GuiFileList::display_path(PathBuf::from(ROM_ROOT), &gui_state.filename_to_load, ui);
|
||||
if !new_filename.is_empty() {
|
||||
if new_filename != gui_state.filename_to_load {
|
||||
debug!("NEW FILENAME SELECTED -> {new_filename}");
|
||||
gui_state.filename_to_load = new_filename;
|
||||
}
|
||||
if ui.button("Load Program") {
|
||||
let mut buffer = Vec::new();
|
||||
debug!("PREPARING TO LOAD {}", gui_state.filename_to_load);
|
||||
// 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(&(ROM_ROOT.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_new_program_to_system_memory((&*buffer).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
// if the system has no program loaded hide the buttons.
|
||||
if system_to_control.state().memory.peek(0x200) != 0x00 {
|
||||
if ui.button("Step") {
|
||||
system_to_control.step();
|
||||
};
|
||||
ui.same_line();
|
||||
if ui.button("Run") {
|
||||
system_to_control.start();
|
||||
}
|
||||
}
|
||||
ui.same_line();
|
||||
if ui.button("Stop") {
|
||||
system_to_control.stop();
|
||||
}
|
||||
ui.same_line();
|
||||
if ui.button("Reset") {
|
||||
system_to_control.reset();
|
||||
}
|
||||
if ui.button("Dump Video Memory") {
|
||||
println!("{}", system_to_control.dump_to_string(Video));
|
||||
}
|
||||
ui.same_line();
|
||||
if ui.button("Dump Keypad State") {
|
||||
debug!("{}", system_to_control.dump_to_string(Keyboard));
|
||||
}
|
||||
ui.same_line();
|
||||
if ui.button("Dump Registers") {
|
||||
debug!("{}", system_to_control.dump_to_string(Registers));
|
||||
}
|
||||
ui.separator();
|
||||
|
||||
ui.checkbox("Show Memory", &mut gui_state.show_memory);
|
||||
ui.same_line();
|
||||
ui.checkbox("Show Video", &mut gui_state.show_video);
|
||||
ui.same_line();
|
||||
ui.checkbox("Show Registers", &mut gui_state.show_registers);
|
||||
if CollapsingHeader::new("Controls").build(ui) {
|
||||
// if the system has no program loaded hide the buttons.
|
||||
let bytes: [u8; 2] = [
|
||||
system_to_control.state().memory.peek(0x200),
|
||||
system_to_control.state().memory.peek(0x201)
|
||||
];
|
||||
let mut show_buttons = bytes[0] != 0 || bytes[1] == 0xe0;
|
||||
|
||||
if show_buttons {
|
||||
if ui.button("Step") {
|
||||
system_to_control.step();
|
||||
};
|
||||
ui.same_line();
|
||||
if ui.button("Run") {
|
||||
system_to_control.start();
|
||||
}
|
||||
}
|
||||
ui.same_line();
|
||||
if ui.button("Stop") {
|
||||
system_to_control.stop();
|
||||
}
|
||||
ui.same_line();
|
||||
if ui.button("Reset") {
|
||||
system_to_control.reset();
|
||||
}
|
||||
if ui.button("Dump Video Memory") {
|
||||
println!("{}", system_to_control.dump_to_string(Video));
|
||||
}
|
||||
ui.same_line();
|
||||
if ui.button("Dump Keypad State") {
|
||||
debug!("{}", system_to_control.dump_to_string(Keyboard));
|
||||
}
|
||||
ui.same_line();
|
||||
if ui.button("Dump Registers") {
|
||||
debug!("{}", system_to_control.dump_to_string(Registers));
|
||||
}
|
||||
}
|
||||
|
||||
if CollapsingHeader::new("Options").build(ui) {
|
||||
ui.checkbox("Show Memory", &mut gui_state.show_memory);
|
||||
ui.same_line();
|
||||
ui.checkbox("Show Video", &mut gui_state.show_video);
|
||||
ui.same_line();
|
||||
ui.checkbox("Show Registers", &mut gui_state.show_registers);
|
||||
ui.same_line();
|
||||
ui.checkbox("Show Keypad", &mut gui_state.show_keypad);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -177,53 +190,53 @@ impl GemmaImguiSupport {
|
||||
ui.window("System Memory")
|
||||
.position([100.0, 640.0], Condition::FirstUseEver)
|
||||
.build(|| {
|
||||
let mut current_x_hover: i32 = 0;
|
||||
let mut current_y_hover: i32 = 0;
|
||||
// display a block of data
|
||||
for current_row in 0..rows {
|
||||
ui.text(format!("{:02x}", current_row * cols));
|
||||
ui.same_line();
|
||||
for current_column in 0..cols {
|
||||
let data_offset = current_row * cols + current_column;
|
||||
let formatted_text = format!("{:02x}", bytes.peek(data_offset as u16));
|
||||
let text_location = ui.cursor_screen_pos();
|
||||
let text_size = ui.calc_text_size(formatted_text.clone());
|
||||
let bounding_box = imgui::sys::ImVec2 {
|
||||
x: text_location[0] + text_size[0],
|
||||
y: text_location[1] + text_size[1],
|
||||
};
|
||||
let mut current_x_hover: i32 = 0;
|
||||
let mut current_y_hover: i32 = 0;
|
||||
// display a block of data
|
||||
for current_row in 0..rows {
|
||||
ui.text(format!("{:02x}", current_row * cols));
|
||||
ui.same_line();
|
||||
for current_column in 0..cols {
|
||||
let data_offset = current_row * cols + current_column;
|
||||
let formatted_text = format!("{:02x}", bytes.peek(data_offset as u16));
|
||||
let text_location = ui.cursor_screen_pos();
|
||||
let text_size = ui.calc_text_size(formatted_text.clone());
|
||||
let bounding_box = imgui::sys::ImVec2 {
|
||||
x: text_location[0] + text_size[0],
|
||||
y: text_location[1] + text_size[1],
|
||||
};
|
||||
|
||||
let hovering = ui.is_mouse_hovering_rect(text_location, [bounding_box.x, bounding_box.y]);
|
||||
let is_active = data_offset == active as i32;
|
||||
let hovering = ui.is_mouse_hovering_rect(text_location, [bounding_box.x, bounding_box.y]);
|
||||
let is_active = data_offset == active as i32;
|
||||
|
||||
ui.text_colored(if hovering {
|
||||
[0., 1., 1., 1.]
|
||||
} else if is_active {
|
||||
[1., 0., 1., 1.]
|
||||
} else {
|
||||
[1., 1., 0., 1.]
|
||||
}, formatted_text.clone());
|
||||
ui.text_colored(if hovering {
|
||||
[0., 1., 1., 1.]
|
||||
} else if is_active {
|
||||
[1., 0., 1., 1.]
|
||||
} else {
|
||||
[1., 1., 0., 1.]
|
||||
}, formatted_text.clone());
|
||||
|
||||
// if we are hovering show that at the bottom...
|
||||
if hovering {
|
||||
// Optionally change the text color to indicate it's interactable
|
||||
current_x_hover = current_column;
|
||||
current_y_hover = current_row;
|
||||
// if we are hovering show that at the bottom...
|
||||
if hovering {
|
||||
// Optionally change the text color to indicate it's interactable
|
||||
current_x_hover = current_column;
|
||||
current_y_hover = current_row;
|
||||
|
||||
// Check if the left mouse button is clicked while hovering over the text
|
||||
if ui.is_mouse_clicked(imgui::MouseButton::Left) {
|
||||
debug!("Offset: [{}] [0x{:02x}] Value: [{}]", data_offset, data_offset, formatted_text.clone());
|
||||
// Perform any action here, e.g., call a function, trigger an event, etc.
|
||||
}
|
||||
}
|
||||
|
||||
// are we on the same line?
|
||||
if current_column != (cols - 1) {
|
||||
ui.same_line();
|
||||
// Check if the left mouse button is clicked while hovering over the text
|
||||
if ui.is_mouse_clicked(imgui::MouseButton::Left) {
|
||||
debug!("Offset: [{}] [0x{:02x}] Value: [{}]", data_offset, data_offset, formatted_text.clone());
|
||||
// Perform any action here, e.g., call a function, trigger an event, etc.
|
||||
}
|
||||
}
|
||||
|
||||
// are we on the same line?
|
||||
if current_column != (cols - 1) {
|
||||
ui.same_line();
|
||||
}
|
||||
}
|
||||
ui.text(format!("Offset 0x{:03x}", current_x_hover * cols + current_y_hover));
|
||||
}
|
||||
ui.text(format!("Offset 0x{:03x}", current_x_hover * cols + current_y_hover));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ impl GuiFileList {
|
||||
|
||||
let mut known_files: Vec<OsString> = vec![];
|
||||
|
||||
println!("STARTING AT {:?}", std::env::current_dir());
|
||||
// println!("STARTING AT {:?}", std::env::current_dir());
|
||||
for entry in read_dir(root.as_path()).unwrap() {
|
||||
known_files.push(entry.unwrap().file_name());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user