use crate::processor::memory::Address; use std::str::from_utf8_unchecked; #[derive(Debug)] enum MBC { ROM, MBC1, } pub struct ROM { title: String, data: Vec, mbc: MBC, } impl ROM { pub fn load(data: Vec) -> Self { let mut title_length = 0x143; for i in 0x134..0x143 { title_length = i; if data[i] == 0x0 { break; } } let title = unsafe { from_utf8_unchecked(&data[0x134..title_length]).to_string() }; let _gbc_flag = data[0x143]; let _sgb_flag = data[0x146]; let _rom_size = data[0x148]; let _ram_size = data[0x149]; let mbc = match data[0x147] { 0x00 => MBC::ROM, 0x01 => MBC::MBC1, _ => panic!("unimplemented mbc: {:#X}", data[0x147]), }; Self { title, data, mbc } } pub fn get_title(&self) -> &String { &self.title } pub(super) fn get(&self, address: Address) -> u8 { self.data[address as usize] } }