use std::fs::File; use std::io::{self, Read}; use std::path::Path; #[derive(Debug, Clone)] pub struct Cartridge { memory: Vec, } impl Cartridge { pub fn new + ?Sized>(path: &P) -> io::Result { let mut memory = vec![]; let mut rom = File::open(path)?; rom.read_to_end(&mut memory)?; Ok(Self { memory }) } pub fn read_byte(&self, addr: u16) -> u8 { self.memory[addr as usize] } pub fn read_word(&self, addr: u16) -> u16 { (self.memory[(addr + 1) as usize] as u16) << 8 | self.memory[addr as usize] as u16 } }