This commit is contained in:
Trevor Merritt 2024-09-11 13:39:20 -04:00
parent 1a59524f02
commit 95d4e6c32c
10 changed files with 132 additions and 51 deletions

5
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/trevors_chip8_toy.iml" filepath="$PROJECT_DIR$/.idea/trevors_chip8_toy.iml" />
</modules>
</component>
</project>

13
.idea/trevors_chip8_toy.iml generated Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/chip8_core/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/chip8_toy/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/emma/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -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();
}
}

View File

@ -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!();
}
}
}

View File

@ -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]
));
});
});
}

View File

@ -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;
}
}
});
}
}

View File

@ -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;

View File

@ -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 {