parse cart header
This commit is contained in:
parent
8185243582
commit
5fe3d2ef2e
|
@ -100,8 +100,11 @@ fn main() {
|
||||||
*v = args.verbose;
|
*v = args.verbose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let rom: ROM = ROM::load(fs::read(args.rom).expect("Could not load ROM"));
|
||||||
|
let bootrom: Vec<u8> = fs::read(args.bootrom).expect("Could not load BootROM");
|
||||||
|
|
||||||
let mut window = Window::new(
|
let mut window = Window::new(
|
||||||
"Gameboy",
|
format!("{}", rom.get_title()).as_str(),
|
||||||
WIDTH * FACTOR,
|
WIDTH * FACTOR,
|
||||||
HEIGHT * FACTOR,
|
HEIGHT * FACTOR,
|
||||||
WindowOptions::default(),
|
WindowOptions::default(),
|
||||||
|
@ -114,9 +117,6 @@ fn main() {
|
||||||
|
|
||||||
window.topmost(true);
|
window.topmost(true);
|
||||||
|
|
||||||
let rom: ROM = ROM::load(fs::read(args.rom).expect("Could not load ROM"));
|
|
||||||
let bootrom: Vec<u8> = fs::read(args.bootrom).expect("Could not load BootROM");
|
|
||||||
|
|
||||||
let mut cpu = CPU::new(Memory::init(bootrom, args.run_bootrom, rom), window);
|
let mut cpu = CPU::new(Memory::init(bootrom, args.run_bootrom, rom), window);
|
||||||
|
|
||||||
if !args.run_bootrom {
|
if !args.run_bootrom {
|
||||||
|
|
|
@ -1,12 +1,42 @@
|
||||||
use crate::processor::memory::Address;
|
use crate::processor::memory::Address;
|
||||||
|
use std::str::from_utf8_unchecked;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum MBC {
|
||||||
|
ROM,
|
||||||
|
MBC1,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ROM {
|
pub struct ROM {
|
||||||
|
title: String,
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
|
mbc: MBC,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ROM {
|
impl ROM {
|
||||||
pub fn load(data: Vec<u8>) -> Self {
|
pub fn load(data: Vec<u8>) -> Self {
|
||||||
Self { data }
|
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 {
|
pub(super) fn get(&self, address: Address) -> u8 {
|
||||||
|
|
Loading…
Reference in a new issue