Logic to load a rom file

This commit is contained in:
Franco Colmenarez 2021-10-12 19:11:52 -05:00
parent 1e363187f1
commit 1902884df9
5 changed files with 30 additions and 3 deletions

BIN
roms/cpu_instrs.gb Normal file

Binary file not shown.

View File

@ -1,4 +1,7 @@
fn main() {
println!("TEST");
println!("{}", false as u8);
use rust_boy::rom::ROM;
fn main() -> std::io::Result<()> {
let myrom = ROM::load_file("roms/cpu_instrs.gb".to_string())?;
myrom.print_content();
Ok(())
}

View File

@ -1,2 +1,3 @@
pub mod utils;
pub mod cpu;
pub mod rom;

21
src/rom.rs Normal file
View File

@ -0,0 +1,21 @@
use std::fs::File;
use std::io::Read;
pub struct ROM {
bytes: Vec<u8>,
}
impl ROM {
pub fn load_file(filename: String) -> std::io::Result<Self> {
let mut file = File::open(filename)?;
let mut bytes = vec![];
file.read_to_end(&mut bytes)?;
Ok(Self {
bytes,
})
}
pub fn print_content(&self) {
println!("{:02X?}", self.bytes);
}
}

View File

@ -1,3 +1,5 @@
pub struct AddressRange(u16, u16);
pub enum BitIndex {
I0,
I1,