Skip to content
Snippets Groups Projects
Verified Commit 4b80e173 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: support for rom name

parent 1f3be783
No related branches found
No related tags found
No related merge requests found
Pipeline #605 passed
...@@ -84,7 +84,6 @@ impl BeepCallback { ...@@ -84,7 +84,6 @@ impl BeepCallback {
pub struct State { pub struct State {
system: Chip8, system: Chip8,
rom_loaded: bool,
logic_frequency: u32, logic_frequency: u32,
visual_frequency: u32, visual_frequency: u32,
idle_frequency: u32, idle_frequency: u32,
...@@ -96,6 +95,8 @@ pub struct State { ...@@ -96,6 +95,8 @@ pub struct State {
pixel_color: [u8; 3], pixel_color: [u8; 3],
pixel_color_index: u32, pixel_color_index: u32,
title: String, title: String,
rom_name: String,
rom_loaded: bool,
diagnostics: bool, diagnostics: bool,
} }
...@@ -110,7 +111,6 @@ fn main() { ...@@ -110,7 +111,6 @@ fn main() {
// is going to logically represent the CHIP-8 // is going to logically represent the CHIP-8
let mut state = State { let mut state = State {
system: Chip8::new(), system: Chip8::new(),
rom_loaded: false,
logic_frequency: LOGIC_HZ, logic_frequency: LOGIC_HZ,
visual_frequency: VISUAL_HZ, visual_frequency: VISUAL_HZ,
idle_frequency: IDLE_HZ, idle_frequency: IDLE_HZ,
...@@ -122,6 +122,8 @@ fn main() { ...@@ -122,6 +122,8 @@ fn main() {
pixel_color: COLORS[0], pixel_color: COLORS[0],
pixel_color_index: 0, pixel_color_index: 0,
title: String::from(TITLE_INITIAL), title: String::from(TITLE_INITIAL),
rom_name: String::from("unloaded"),
rom_loaded: false,
diagnostics: false, diagnostics: false,
}; };
...@@ -204,6 +206,10 @@ fn main() { ...@@ -204,6 +206,10 @@ fn main() {
.unwrap(); .unwrap();
'main: loop { 'main: loop {
if state.timer_frequency < state.visual_frequency {
panic!("timer frequency must be higher or equal to visual frequency")
}
while let Some(event) = event_pump.poll_event() { while let Some(event) = event_pump.poll_event() {
match event { match event {
Event::Quit { .. } => break 'main, Event::Quit { .. } => break 'main,
...@@ -256,14 +262,15 @@ fn main() { ...@@ -256,14 +262,15 @@ fn main() {
Event::DropFile { filename, .. } => { Event::DropFile { filename, .. } => {
let rom = read_file(&filename); let rom = read_file(&filename);
let filebase = Path::new(&filename).file_name().unwrap().to_str().unwrap(); let rom_name = Path::new(&filename).file_name().unwrap().to_str().unwrap();
state.system.reset_hard(); state.system.reset_hard();
state.system.load_rom(&rom); state.system.load_rom(&rom);
state.rom_name = String::from(rom_name);
state.rom_loaded = true; state.rom_loaded = true;
state.set_title(&format!("{} [Currently playing: {}]", TITLE, filebase)); state.set_title(&format!("{} [Currently playing: {}]", TITLE, rom_name));
None None
} }
...@@ -373,7 +380,8 @@ fn main() { ...@@ -373,7 +380,8 @@ fn main() {
let mut y = 12; let mut y = 12;
let padding = 2; let padding = 2;
let text = format!( let text = format!(
"Frequency: {} Hz\nDisplay: {} fps\nPC: 0x{:04x}\nSP: 0x{:04x}", "ROM: {}\nFrequency: {} Hz\nDisplay: {} fps\nPC: 0x{:04x}\nSP: 0x{:04x}",
state.rom_name,
state.logic_frequency, state.logic_frequency,
state.visual_frequency, state.visual_frequency,
state.system.pc(), state.system.pc(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment