my first schip rom works in my schip emulator.
BUGFIX: Corrects runaway after drawing in my first schip rom scroll down, left, right all test with test rom assembler now assembles to the expected output it seems fixes incorrect loading of schip font to memory replaces schip font from new chatgpt feedback
This commit is contained in:
@@ -1,18 +1,38 @@
|
||||
use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
use crate::support::gemma_egui_support::{EGuiFileList, GemmaEguiSupport};
|
||||
use eframe::egui;
|
||||
use egui::Key;
|
||||
use gemma::chip8::computer::Chip8Computer;
|
||||
use gemma::chip8::computer_manager::Chip8ComputerManager;
|
||||
use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
|
||||
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)]
|
||||
[
|
||||
(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)]
|
||||
@@ -88,29 +108,40 @@ fn main() -> eframe::Result {
|
||||
// state.is_running = false;
|
||||
}
|
||||
if ui.button("Reset").clicked() {
|
||||
computer.reset();
|
||||
computer.reset(computer.quirks_mode());
|
||||
// state.is_running = false;
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
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_new_program_to_system_memory(read_bin);
|
||||
};
|
||||
EGuiFileList::display_path(PathBuf::from("resources/roms"), &mut state.selected_filename, ui);
|
||||
EGuiFileList::display_path(
|
||||
PathBuf::from("resources/roms"),
|
||||
&mut state.selected_filename,
|
||||
ui,
|
||||
);
|
||||
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");
|
||||
// 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");
|
||||
// println!("KEY {keypad_key:02x} up");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::Chip8Computer;
|
||||
use egui::Rect;
|
||||
use egui::Ui;
|
||||
use egui::Vec2;
|
||||
use egui::{Align, Color32, ComboBox, Pos2};
|
||||
use std::fs::read_dir;
|
||||
use std::path::PathBuf;
|
||||
use egui::{Align, Color32, ComboBox, Pos2, TextBuffer};
|
||||
use egui::Rect;
|
||||
use egui::Vec2;
|
||||
use egui::Ui;
|
||||
use crate::Chip8Computer;
|
||||
|
||||
const CELL_WIDTH: f32 = 5.0;
|
||||
const CELL_HEIGHT: f32 = 5.0;
|
||||
@@ -14,21 +14,26 @@ impl EGuiFileList {
|
||||
pub fn display_path(root: PathBuf, selected_filename: &mut String, ui: &mut Ui) {
|
||||
let working_filename = selected_filename.clone();
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||
// ui.label(format!("Displaying {}", root.to_str().unwrap_or("Unable to Load Path")));
|
||||
// ui.label(format!("Displaying {}", root.to_str().unwrap_or("Unable to Load Path")));
|
||||
ComboBox::from_label("Select ROM")
|
||||
.selected_text(selected_filename.clone())
|
||||
.show_ui(ui, |ui| {
|
||||
|
||||
let mut sorted_options = vec![];
|
||||
for option in read_dir(root.as_path()).unwrap() {
|
||||
let to_push = option.unwrap().file_name().into_string().unwrap_or( String::new());
|
||||
let to_push = option
|
||||
.unwrap()
|
||||
.file_name()
|
||||
.into_string()
|
||||
.unwrap_or(String::new());
|
||||
sorted_options.push(to_push);
|
||||
}
|
||||
|
||||
sorted_options.sort();
|
||||
for item in sorted_options {
|
||||
// Add each option to the ComboBox
|
||||
if ui.selectable_label(selected_filename.eq(&item.as_str()), item.clone()).clicked()
|
||||
// Add each option to the ComboBox
|
||||
if ui
|
||||
.selectable_label(selected_filename.eq(&item.as_str()), item.clone())
|
||||
.clicked()
|
||||
{
|
||||
*selected_filename = item;
|
||||
}
|
||||
@@ -43,36 +48,41 @@ pub struct GemmaEguiSupport {}
|
||||
|
||||
impl GemmaEguiSupport {
|
||||
pub fn controls_view(system: &mut Chip8Computer, ui: &mut Ui) {
|
||||
|
||||
ui.with_layout(egui::Layout::left_to_right(Align::TOP), |ui| {
|
||||
// ui.checkbox(&mut state.display_memory, "Display Memory");
|
||||
// ui.checkbox(&mut state.display_video, "Display Video");
|
||||
// ui.checkbox(&mut state.display_registers, "Display Registers");
|
||||
// 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!(
|
||||
"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!(
|
||||
"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()
|
||||
));
|
||||
ui.label(format!("PC: {:04x}\tI: {:04x}", system.registers.peek_pc(), system.registers.peek_i()));
|
||||
}
|
||||
|
||||
pub fn video_view(system: &Chip8Computer, ui: &mut Ui) {
|
||||
@@ -95,7 +105,7 @@ impl GemmaEguiSupport {
|
||||
// system.video_memory.peek(data_offset));
|
||||
}
|
||||
}
|
||||
// thread::sleep(Duration::from_secs(1));
|
||||
// thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
pub fn memory_view(system: &Chip8Computer, ui: &mut Ui) {
|
||||
|
||||
Reference in New Issue
Block a user