more roms to play with

egui now renders the video correctly
This commit is contained in:
Trevor Merritt 2024-10-12 14:16:14 -04:00
parent 6be443fa2b
commit 683b0fc51a
7 changed files with 35 additions and 21 deletions

View File

@ -43,13 +43,15 @@ impl Chip8Video {
pub fn poke(&mut self, address: u16, new_value: bool) -> Self {
trace!("OFFSET: {address} - POKING {new_value}");
let effective_address = if address > 2048 {
let effective_address = if address >= 2048 {
address - 2048
} else {
address
};
let old_value = self.memory[effective_address as usize];
if old_value != new_value {
let value_to_poke = new_value ^ old_value;
if old_value != value_to_poke {
trace!("**VIDEO** TOGGLING");
self.has_frame_changed = true;
} else {
@ -97,6 +99,10 @@ impl Chip8Video {
output
}
pub fn tick(&mut self) {
self.has_frame_changed = false;
}
}
impl Default for Chip8Video {

View File

@ -19,13 +19,14 @@ fn main() -> eframe::Result {
eframe::run_simple_native("EGUI Emma", options, move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("EGUI Gemma");
GemmaEguiSupport::controls_view(&mut computer, &mut state, ui);
if state.display_video {
GemmaEguiSupport::video_view(&computer, ui);
}
ui.heading("EGUI Gemma");
GemmaEguiSupport::controls_view(&mut computer, &mut state, ui);
if state.display_memory {
GemmaEguiSupport::memory_view(&computer, &mut state, ui);
}

View File

@ -1,6 +1,8 @@
use std::fs::read_dir;
use std::ops::Index;
use std::path::{Display, PathBuf};
use std::thread;
use std::time::Duration;
use egui::{Align, Color32, ComboBox, Direction, Pos2};
use egui::Rect;
use egui::Vec2;
@ -90,11 +92,10 @@ impl GemmaEguiSupport {
}
pub fn video_view(system: &Chip8Computer, ui: &mut Ui) {
ui.label("Video goes here");
let (resp, painter) = ui.allocate_painter(Vec2::new(400.0, 500.0), egui::Sense::hover());
for current_row in 0..64 {
for current_col in 0..32 {
let data_offset = current_row * 32 + current_col;
let (_resp, painter) = ui.allocate_painter(Vec2::new(350.0, 165.0), egui::Sense::hover());
for current_row in 0..32 {
for current_col in 0..64 {
let data_offset = current_row * 64 + current_col;
let x_offset = current_col as f32 * CELL_WIDTH;
let y_offset = current_row as f32 * CELL_HEIGHT;
let origin = Pos2::new(x_offset, y_offset);
@ -105,13 +106,12 @@ impl GemmaEguiSupport {
};
let rect = Rect::from_min_size(origin, Vec2::new(CELL_WIDTH, CELL_HEIGHT));
painter.rect_filled(rect, 0.0, colour);
// println!("DataOffset: [{:04x}] X_Offset: [{:04x}] Y_Offset: [{:04x}] Origin: [{:04x}]x[{:04x}]",
// data_offset as u16,
// x_offset as u16,
// y_offset as u16,
// origin.x as u16, origin.y as u16);
// println!("Cell {current_col}x{current_row} at {}x{} -> {}",
// origin.x, origin.y,
// system.video_memory.peek(data_offset));
}
}
// thread::sleep(Duration::from_secs(1));
}
pub fn memory_view(system: &Chip8Computer, gui_state: &mut GemmaEGuiState, ui: &mut Ui) {

View File

@ -22,7 +22,7 @@ mod support;
const LIN_KEYS: [(u16, u8); 0x10] = [(537, 0x01),(538, 0x02),(539, 0x03),(540, 0x0c),
(562, 0x04),(568, 0x05),(550, 0x06),(563, 0x0d),
(546, 7),(564, 8),(549, 9),(551, 0xe),
(571, 0xa),(569, 0),(548, 0xb),(569, 0xf)];
(571, 0xa),(569, 0),(548, 0xb),(567, 0xf)];
fn main() {
pretty_env_logger::init();
@ -34,6 +34,11 @@ fn main() {
// Key Checks
let down_keys = ui.io().keys_down;
for (idx, val) in down_keys.iter().enumerate() {
if *val {
println!("{idx} = {val}");
}
}
for (key_code, key_reg) in LIN_KEYS {
if down_keys[key_code as usize] {
system.keypad.push_key(key_reg);
@ -66,15 +71,17 @@ fn main() {
}
// GUI Parts
if ui_state.show_video {
GemmaImguiSupport::video_display(&system, &ui_state, ui);
}
GemmaImguiSupport::system_controls(&mut system, &mut ui_state, ui);
if ui_state.show_registers {
GemmaImguiSupport::registers_view(&system, ui);
}
if ui_state.show_video {
GemmaImguiSupport::video_display(&system, &ui_state, ui);
}
if ui_state.show_memory {
let active_instruction = system.registers.peek_pc();

View File

@ -42,7 +42,7 @@ impl Default for ImGuiUiState {
on_colour: ImColor32::from_rgb(0xff, 0xff, 0x00),
off_colour: ImColor32::from_rgb(0x00, 0xff, 0xff),
is_running: false,
frame_time: 10.0,
frame_time: 1.0,
last_frame_instant: Instant::now()
}
}

BIN
resources/roms/br8kout.ch8 Normal file

Binary file not shown.

BIN
resources/roms/snake.ch8 Normal file

Binary file not shown.