more roms
This commit is contained in:
@@ -96,6 +96,7 @@ impl Chip8Computer {
|
||||
Chip8CpuStates::WaitingForInstruction => {
|
||||
self.sound_timer.tick();
|
||||
self.delay_timer.tick();
|
||||
self.video_memory.tick();
|
||||
}
|
||||
Chip8CpuStates::WaitingForKey => {
|
||||
println!("waiting for a key press...");
|
||||
|
||||
@@ -695,7 +695,7 @@ impl Chip8CpuInstructions {
|
||||
|
||||
debug!("PPOOSSTT -> CHIP8CPUINSTRUCTION:DRAWVXNIBBLE -> {}", input.video_memory.format_as_string());
|
||||
|
||||
let mut did_change: bool = false;
|
||||
let mut did_change: bool = input.video_memory.has_frame_changed;
|
||||
|
||||
if did_change {
|
||||
input.registers.poke(0xf, 1u8);
|
||||
|
||||
+41
-10
@@ -42,22 +42,22 @@ impl Chip8Video {
|
||||
}
|
||||
|
||||
pub fn poke(&mut self, address: u16, new_value: bool) -> Self {
|
||||
trace!("OFFSET: {address} - POKING {new_value}");
|
||||
// println!("OFFSET: {address} - POKING {new_value}");
|
||||
|
||||
// Loop the address
|
||||
let effective_address = if address >= 2048 {
|
||||
address - 2048
|
||||
} else {
|
||||
address
|
||||
};
|
||||
let old_value = self.memory[effective_address as usize];
|
||||
let value_to_poke = new_value ^ old_value;
|
||||
|
||||
if old_value != value_to_poke {
|
||||
trace!("**VIDEO** TOGGLING");
|
||||
self.has_frame_changed = true;
|
||||
} else {
|
||||
trace!("NOT TOGGLING");
|
||||
}
|
||||
self.memory[effective_address as usize] = new_value ^ old_value;
|
||||
let old_value = self.memory[effective_address as usize];
|
||||
let xored_value = new_value ^ old_value; // XOR of the video
|
||||
let value_changed = old_value != xored_value; // From True to False is a change.
|
||||
|
||||
self.has_frame_changed = if xored_value && value_changed { false } else { true };
|
||||
|
||||
self.memory[effective_address as usize] = xored_value;
|
||||
self.to_owned()
|
||||
}
|
||||
|
||||
@@ -369,6 +369,7 @@ mod test {
|
||||
fn verify_change_registered() {
|
||||
let mut v = Chip8Video::default();
|
||||
v.poke(0x01, true);
|
||||
v.poke(0x01, true);
|
||||
assert!(v.has_frame_changed);
|
||||
|
||||
v.start_frame();
|
||||
@@ -423,4 +424,34 @@ mod test {
|
||||
x = x.reset();
|
||||
assert_eq!(x.format_as_string(), read_test_result("test_reset_clears_video.asc"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collision_test() {
|
||||
// Setup: Set 0xFF to 0x00 with a new frame ready
|
||||
// Action: Run Poke to the same area
|
||||
// Test: Verify the 'changed' flag is tripped
|
||||
let mut x = Chip8Video::default();
|
||||
x.poke_byte(0x00, 0xff);
|
||||
x.tick();
|
||||
// set the cell thats already set...
|
||||
x.poke(0x00, true);
|
||||
// it becomes unset and theres a frame changed
|
||||
assert_eq!(false, x.peek(0x00));
|
||||
|
||||
assert_eq!(true, x.has_frame_changed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collision_test2() {
|
||||
let mut x = Chip8Video::default();
|
||||
x.poke_byte(0x00, 0b11110000);
|
||||
assert_eq!(true, x.has_frame_changed);
|
||||
x.tick();
|
||||
assert_eq!(false, x.has_frame_changed);
|
||||
// clear the 'has changed' flag
|
||||
|
||||
// now set a no-collision value
|
||||
x.poke_byte(0x00, 0b00001111);
|
||||
assert_eq!(false, x.has_frame_changed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ pub struct GemmaEguiSupport {}
|
||||
|
||||
impl GemmaEguiSupport {
|
||||
pub fn controls_view(mut system: &mut Chip8Computer, state: &mut GemmaEGuiState, ui: &mut Ui) {
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||
if ui.button("Start").clicked() {
|
||||
println!("Start");
|
||||
|
||||
@@ -62,9 +62,12 @@ impl GemmaEguiSupport {
|
||||
}
|
||||
});
|
||||
|
||||
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.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");
|
||||
});
|
||||
}
|
||||
|
||||
pub fn registers_view(system: &Chip8Computer, ui: &mut Ui) {
|
||||
|
||||
@@ -8,6 +8,7 @@ use gemma::{
|
||||
use imgui::*;
|
||||
use sys::{ImColor, ImVec2, ImVector_ImU32};
|
||||
use rand::random;
|
||||
use gemma::chip8::cpu_states::Chip8CpuStates::WaitingForInstruction;
|
||||
use gemma::chip8::system_memory::Chip8SystemMemory;
|
||||
use support::{emmagui_support::GemmaImguiSupport, ui_state::ImGuiUiState};
|
||||
|
||||
@@ -42,6 +43,7 @@ fn main() {
|
||||
for (key_code, key_reg) in LIN_KEYS {
|
||||
if down_keys[key_code as usize] {
|
||||
system.keypad.push_key(key_reg);
|
||||
system.state = WaitingForInstruction;
|
||||
} else {
|
||||
// do we need to release it?
|
||||
if system.keypad.pressed(key_reg) {
|
||||
|
||||
@@ -2,7 +2,6 @@ use gemma::constants::CHIP8_KEYBOARD;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use imgui::{Condition, ImColor32, Ui};
|
||||
use log::debug;
|
||||
@@ -61,7 +60,7 @@ impl GemmaImguiSupport {
|
||||
pub fn video_display(system_to_control: &Chip8Computer, gui_state: &ImGuiUiState, ui: &Ui) {
|
||||
// draw area size
|
||||
let draw_area_size = ui.io().display_size;
|
||||
println!("DRAW_AREA_SIZE = {}x{}", draw_area_size[0], draw_area_size[1]);
|
||||
// println!("DRAW_AREA_SIZE = {}x{}", draw_area_size[0], draw_area_size[1]);
|
||||
let cell_width = ((draw_area_size[0] as i32 / 64) * 6) / 10;
|
||||
let cell_height = ((draw_area_size[1] as i32 / 32) * 6) / 10;
|
||||
|
||||
@@ -177,7 +176,6 @@ impl GemmaImguiSupport {
|
||||
let cols = position.1;
|
||||
ui.window("System Memory")
|
||||
.size([400.0, 300.0], Condition::FirstUseEver)
|
||||
.position([500.0, 300.0], Condition::Always)
|
||||
.build(|| {
|
||||
let mut current_x_hover: i32 = 0;
|
||||
let mut current_y_hover: i32 = 0;
|
||||
@@ -230,33 +228,4 @@ impl GemmaImguiSupport {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn system_memory_render(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;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
`
|
||||
ef
|
||||
ghabcd`
|
||||
¢xÐVp
|
||||
¢~Ðfp
|
||||
¢„Ðvp
|
||||
¢ŠÐ†jú`
|
||||
¢xÐVEaÿEa…ÐVp
|
||||
¢~ÐfFbÿFb†$Ðfp
|
||||
¢„ÐvGcÿGc‡4Ðvp
|
||||
¢ŠÐ†HdÿHdˆDІ*ÿ0ÀÿÿÀÀüÀÿðÌÌðÌÃ<ÃÃÃÃ<
|
||||
Reference in New Issue
Block a user