diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4644b2a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/trevors_chip8_toy.iml b/.idea/trevors_chip8_toy.iml new file mode 100644 index 0000000..eafc13e --- /dev/null +++ b/.idea/trevors_chip8_toy.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/chip8_core/src/chip8_mnemonics.rs b/chip8_core/src/chip8_mnemonics.rs index 36e7fc2..eb12cf2 100644 --- a/chip8_core/src/chip8_mnemonics.rs +++ b/chip8_core/src/chip8_mnemonics.rs @@ -178,18 +178,30 @@ struct Chip8Cpu {} struct Chip8System { registers: Chip8Registers, - screen: Chip8Display, + system_memory: [u8; 2048] } impl Chip8System { - pub fn tick(self: Self) { + pub fn tick(mut self) { println!(" Ticking Chip8System"); - // Fetch... - // ...Decode... - // ...Execute + let next_instruction = self.system_memory[self.registers.ProgramCounter as usize] as u16; + println!("READ INSTRUCTION {next_instruction}"); + self.registers.ProgramCounter += 0x2; + + &self.delay_timer_tick(); + &self.sound_timer_tick(); + + // self.screen.tick(); + } + + fn delay_timer_tick(&mut self) { + self.registers.DelayTimer = self.registers.DelayTimer - 1; + + } + + fn sound_timer_tick(&mut self) { + self.registers.SoundTimer = self.registers.SoundTimer - 1; - // self.registers.tick(); - self.screen.tick(); } } diff --git a/chip8_core/src/parts/Display.rs b/chip8_core/src/parts/Display.rs index c3c5471..4ba3222 100644 --- a/chip8_core/src/parts/Display.rs +++ b/chip8_core/src/parts/Display.rs @@ -15,13 +15,13 @@ impl Chip8Display { // ...64 columns for index_col in 0..=64 { let offset = (index_row * 64) + index_col; - if (to_render.memory[offset]) { + if to_render.memory[offset] { print!("*") } else { print!(" ") }; } - println!(""); + println!(); } } } diff --git a/emma/src/bin/emmagui.rs b/emma/src/bin/emmagui.rs index 2939fc9..c681283 100644 --- a/emma/src/bin/emmagui.rs +++ b/emma/src/bin/emmagui.rs @@ -5,31 +5,44 @@ use emmaemu::{ use imgui::*; use ratatui::symbols::half_block; use sys::{ImColor, ImVec2, ImVector_ImU32}; - +use support::emmagui_support::EmmaGui; mod support; -fn main() { - let system = Chip8Computer::default(); + +fn hello_world_window(ui: &Ui) { + let mut value = 1; let choices = ["test test this is 1", "test test this is 2"]; - support::simple_init(file!(), move |_, ui| { - ui.window("EmmaGui") - .size([300.0, 110.0], Condition::FirstUseEver) - .build(|| { - system.memory.gui_render(ui); - ui.text_wrapped("Hello world!"); - ui.text_wrapped("こんにちは世界!"); - if ui.button(choices[value]) { - value += 1; - value %= 2; - } + ui.window("EmmaGui") + .size([300.0, 110.0], Condition::FirstUseEver) + .build(|| { + ui.text_wrapped("Hello world!"); + ui.text_wrapped("こんにちは世界!"); + if ui.button(choices[value]) { + value += 1; + value %= 2; + } + + ui.button("This...is...imgui-rs!"); + ui.separator(); + let mouse_pos = ui.io().mouse_pos; + ui.text(format!( + "Mouse Position: ({:.1},{:.1})", + mouse_pos[0], mouse_pos[1] + )); + }); +} + + +fn main() { + let system = Chip8Computer::default(); + support::simple_init(file!(), move |_, ui| { + + hello_world_window(ui); + + EmmaGui::SystemMemoryRender(system.memory, ui); + + + system.memory.gui_render(ui); - ui.button("This...is...imgui-rs!"); - ui.separator(); - let mouse_pos = ui.io().mouse_pos; - ui.text(format!( - "Mouse Position: ({:.1},{:.1})", - mouse_pos[0], mouse_pos[1] - )); - }); }); } diff --git a/emma/src/bin/support/emmagui_support.rs b/emma/src/bin/support/emmagui_support.rs new file mode 100644 index 0000000..e4bcf32 --- /dev/null +++ b/emma/src/bin/support/emmagui_support.rs @@ -0,0 +1,40 @@ +use imgui::{Condition, ImColor32, Ui}; +use emmaemu::chip8::system_memory::Chip8SystemMemory; +use emmaemu::constants::{CHIP8_VIDEO_HEIGHT, CHIP8_VIDEO_WIDTH}; + +pub struct EmmaGui {} +const cell_width: i32 = 5i32; +const cell_height: i32 = 5i32; + +impl EmmaGui { + pub fn SystemMemoryRender(memory: Chip8SystemMemory, ui: &Ui) { + ui.window("System Memory") + .size([300.0, 100.0], Condition::FirstUseEver) + .build(|| { + ui.text("Rendering System Memory Here"); + let draw_list = ui.get_foreground_draw_list(); + let mut idx = 0; + for row in 0..CHIP8_VIDEO_HEIGHT { + for column in 0..CHIP8_VIDEO_WIDTH { + let x_offset = column * cell_width; + let y_offset = row * cell_width; + let start_point = [x_offset as f32, y_offset as f32]; + let end_point = [(x_offset + cell_width) as f32, + (y_offset + cell_height) as f32 + ]; + let memory_offset = (row * CHIP8_VIDEO_WIDTH) + column; + let target_color = if memory.peek(memory_offset as u16) == 0 { + ImColor32::BLACK + } else { + ImColor32::WHITE + }; + draw_list.add_rect([x_offset as f32, y_offset as f32], + [(x_offset + cell_width) as f32, (y_offset + cell_height) as f32], + target_color).build(); + idx += 1; + } + } + + }); + } +} \ No newline at end of file diff --git a/emma/src/bin/support/mod.rs b/emma/src/bin/support/mod.rs index c989f43..2819e41 100644 --- a/emma/src/bin/support/mod.rs +++ b/emma/src/bin/support/mod.rs @@ -11,6 +11,7 @@ use std::path::Path; use std::time::Instant; pub mod clipboard; +pub mod emmagui_support; pub const FONT_SIZE: f32 = 13.0; diff --git a/emma/src/chip8/system_memory.rs b/emma/src/chip8/system_memory.rs index 41f5fe1..de8dfa2 100644 --- a/emma/src/chip8/system_memory.rs +++ b/emma/src/chip8/system_memory.rs @@ -1,4 +1,6 @@ -use imgui::Ui; +use glium::RawUniformValue::Vec2; +use imgui::sys::ImColor; +use imgui::{ImColor32, Ui}; use ratatui::{style::Style, widgets::Widget}; use crate::constants::{CHIP8_MEMORY_SIZE, CHIP8_VIDEO_HEIGHT, CHIP8_VIDEO_WIDTH}; @@ -52,25 +54,6 @@ const cell_height: i32 = 5i32; impl Chip8SystemMemory { pub fn gui_render(self, ui: &Ui) { - let draw_list = ui.get_foreground_draw_list(); - let mut idx = 0; - for row in 0..CHIP8_VIDEO_HEIGHT { - for column in 0..CHIP8_VIDEO_HEIGHT { - let x_offset = (row * cell_width) + column; - let y_offset = (row * cell_width); - let memory_offset = (row * CHIP8_VIDEO_WIDTH) + column; - println!( - "DRAWING IDX: {} {}x{} to {}x{} with {}", - idx, - x_offset, - y_offset, - x_offset + cell_width, - y_offset + cell_height, - self.memory[memory_offset as usize] - ); - idx += 1; - } - } } pub fn peek(self, address: u16) -> u8 {