From 683b0fc51aa9ca1cdfc910eff04e7e6d4c292778 Mon Sep 17 00:00:00 2001 From: Trevor Merritt Date: Sat, 12 Oct 2024 14:16:14 -0400 Subject: [PATCH] more roms to play with egui now renders the video correctly --- gemma/src/chip8/video.rs | 10 +++++++-- gemmaegui/src/bin/gemmaegui.rs | 9 ++++---- .../src/bin/support/gemma_egui_support.rs | 20 +++++++++--------- gemmaimgui/src/bin/gemmaimgui.rs | 15 +++++++++---- gemmaimgui/src/bin/support/ui_state.rs | 2 +- resources/roms/br8kout.ch8 | Bin 0 -> 199 bytes resources/roms/snake.ch8 | Bin 0 -> 1438 bytes 7 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 resources/roms/br8kout.ch8 create mode 100644 resources/roms/snake.ch8 diff --git a/gemma/src/chip8/video.rs b/gemma/src/chip8/video.rs index 75ba19d..a24f43e 100644 --- a/gemma/src/chip8/video.rs +++ b/gemma/src/chip8/video.rs @@ -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 { diff --git a/gemmaegui/src/bin/gemmaegui.rs b/gemmaegui/src/bin/gemmaegui.rs index 10deeb8..56c4559 100644 --- a/gemmaegui/src/bin/gemmaegui.rs +++ b/gemmaegui/src/bin/gemmaegui.rs @@ -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); } diff --git a/gemmaegui/src/bin/support/gemma_egui_support.rs b/gemmaegui/src/bin/support/gemma_egui_support.rs index f5f81c6..ed858de 100644 --- a/gemmaegui/src/bin/support/gemma_egui_support.rs +++ b/gemmaegui/src/bin/support/gemma_egui_support.rs @@ -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) { diff --git a/gemmaimgui/src/bin/gemmaimgui.rs b/gemmaimgui/src/bin/gemmaimgui.rs index bc77279..c64ec11 100644 --- a/gemmaimgui/src/bin/gemmaimgui.rs +++ b/gemmaimgui/src/bin/gemmaimgui.rs @@ -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(); diff --git a/gemmaimgui/src/bin/support/ui_state.rs b/gemmaimgui/src/bin/support/ui_state.rs index a585ab0..f0e317a 100644 --- a/gemmaimgui/src/bin/support/ui_state.rs +++ b/gemmaimgui/src/bin/support/ui_state.rs @@ -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() } } diff --git a/resources/roms/br8kout.ch8 b/resources/roms/br8kout.ch8 new file mode 100644 index 0000000000000000000000000000000000000000..7e675f02405c4d5b99068f0e84de304cf53135d7 GIT binary patch literal 199 zcmWfd|L0G`BBr|s8Qv{oxxElbGAA%4vbHm{30x~I8E2BVjJ#(#fCC1)>rrB;S_3=gv9vP6_vmAI7z8Q%S4w_^~RoX7GHXjiUW mj$F1wmh4GJPln9@8UG<_64)OsRI*Os1d_%|$x4%jwgLe9phWTj literal 0 HcmV?d00001 diff --git a/resources/roms/snake.ch8 b/resources/roms/snake.ch8 new file mode 100644 index 0000000000000000000000000000000000000000..5f83c16807965ce1f250774f2ba9bfbb37141c38 GIT binary patch literal 1438 zcmeHF-)mD>9RHr1n>L10uZ7-p(p|$KmzK1c3e(Pq=47l2Z7_vV@bRSiF_uJg(;{d) z-AO^#Z8FZ@roLRGh5DA274{$_dzr%rjgGaYPp2=V1Bo~3gNowyd-c!QzF)rI^F806 zpY!GDn;ib9|Mmu$5RQ-@GtN1aLI^22vZuJk>%#IfgrtkO5)0EpoxoLozJAL zSZo{`josZ$CV&6*sUMWY@4M}>Pd@nf+dv@D)7x|H*SfR)@X@^3_b2rRLAI)< z7W%2AhR&9JC<+QefpcmhT-3ece#u(^NaoRVCMa}oU!}4P` zkQ>YoMAqG4%3o4b-6dZtP*PF{N`&EGph_raDmA5fsO(QFp_9*U>3@{FlO*&RS`W&B zq#8Pd*2D6FB%(m;Ns=s*q_RYkzC|~wF1b^*0Mp?jOu2>lv|Bt9>7=0yHD%}L6iMTZ X8