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

feat: better re-usage of rom

parent 3fc17e5e
No related branches found
No related tags found
1 merge request!2Support for diagnostics text
use chip_ahoyto::chip8::Chip8; use chip_ahoyto::{chip8::Chip8, util::read_file};
use std::{fs::File, io::Read};
use time::Instant; use time::Instant;
const CYCLE_COUNT: u64 = 10_000_000_000; const CYCLE_COUNT: u64 = 10_000_000_000;
...@@ -27,10 +26,3 @@ fn main() { ...@@ -27,10 +26,3 @@ fn main() {
println!("Took {} seconds or {:.2} MHz CPU", duration_s, mega_second); println!("Took {} seconds or {:.2} MHz CPU", duration_s, mega_second);
} }
fn read_file(path: &str) -> Vec<u8> {
let mut file = File::open(path).unwrap();
let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
data
}
use chip_ahoyto::chip8::{Chip8, SCREEN_PIXEL_HEIGHT, SCREEN_PIXEL_WIDTH}; use chip_ahoyto::{
chip8::Chip8, chip8::SCREEN_PIXEL_HEIGHT, chip8::SCREEN_PIXEL_WIDTH, util::read_file,
};
use sdl2::{ use sdl2::{
audio::AudioCallback, audio::AudioSpecDesired, event::Event, image::LoadSurface, audio::AudioCallback, audio::AudioSpecDesired, event::Event, image::LoadSurface,
keyboard::Keycode, pixels::Color, pixels::PixelFormatEnum, rect::Rect, render::TextureQuery, keyboard::Keycode, pixels::Color, pixels::PixelFormatEnum, rect::Rect, render::TextureQuery,
surface::Surface, ttf::Hinting, surface::Surface, ttf::Hinting,
}; };
use std::{fs::File, io::Read, path::Path}; use std::path::Path;
// handle the annoying Rect i32 // handle the annoying Rect i32
macro_rules! rect( macro_rules! rect(
...@@ -378,10 +380,3 @@ fn key_to_btn(keycode: Keycode) -> Option<u8> { ...@@ -378,10 +380,3 @@ fn key_to_btn(keycode: Keycode) -> Option<u8> {
_ => None, _ => None,
} }
} }
fn read_file(path: &str) -> Vec<u8> {
let mut file = File::open(path).unwrap();
let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
data
}
...@@ -250,7 +250,7 @@ impl Chip8 { ...@@ -250,7 +250,7 @@ impl Chip8 {
self.registers[0xf] = (self.registers[x] > self.registers[y]) as u8; self.registers[0xf] = (self.registers[x] > self.registers[y]) as u8;
self.registers[x].saturating_sub(self.registers[y]) self.registers[x].saturating_sub(self.registers[y])
} }
#[inline(always)] #[inline(always)]
fn call_subroutine(&mut self, addr: u16) { fn call_subroutine(&mut self, addr: u16) {
self.stack[self.sp as usize] = self.pc; self.stack[self.sp as usize] = self.pc;
......
pub struct Chip8Neo { pub struct Chip8Neo {
vram: [u8] vram: [u8],
} }
pub mod chip8; pub mod chip8;
pub mod chip8_neo; pub mod chip8_neo;
pub mod util;
use std::{fs::File, io::Read};
pub fn read_file(path: &str) -> Vec<u8> {
let mut file = File::open(path).unwrap();
let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
data
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment