feat: don't embed gb boot rom in emulator

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-01-27 22:07:31 -06:00
parent c29c71a8c2
commit b053260c8b
3 changed files with 18 additions and 5 deletions

View File

@ -7,6 +7,7 @@ use super::serial::Serial;
use super::sound::Sound; use super::sound::Sound;
use super::timer::Timer; use super::timer::Timer;
use super::work_ram::{VariableWorkRAM, WorkRAM}; use super::work_ram::{VariableWorkRAM, WorkRAM};
use std::{convert::TryInto, fs::File, io::Read};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Bus { pub struct Bus {
@ -40,9 +41,15 @@ impl Default for Bus {
} }
impl Bus { impl Bus {
pub fn with_boot() -> Self { pub fn with_boot(path: &str) -> Self {
let mut file = File::open(path).unwrap();
let mut buf = Vec::with_capacity(256);
file.read_to_end(&mut buf).unwrap();
let boot_rom: [u8; 256] = buf.try_into().unwrap();
Self { Self {
boot: Some(include_bytes!("../bin/DMG_ROM.bin").to_owned()), boot: Some(boot_rom),
..Default::default() ..Default::default()
} }
} }

View File

@ -34,9 +34,9 @@ impl Cpu {
} }
} }
pub fn boot_new() -> Self { pub fn boot_new(path: &str) -> Self {
Self { Self {
bus: Bus::with_boot(), bus: Bus::with_boot(path),
..Default::default() ..Default::default()
} }
} }

View File

@ -1,6 +1,7 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use gb::cpu::Cpu as LR35902; use gb::cpu::Cpu as LR35902;
use pixels::{Pixels, SurfaceTexture}; use pixels::{Pixels, SurfaceTexture};
use std::env::args;
use winit::{ use winit::{
dpi::LogicalSize, dpi::LogicalSize,
event::{Event, VirtualKeyCode}, event::{Event, VirtualKeyCode},
@ -19,7 +20,12 @@ fn main() -> Result<()> {
let mut input = WinitInputHelper::new(); let mut input = WinitInputHelper::new();
let window = create_window(&event_loop)?; let window = create_window(&event_loop)?;
let mut pixels = create_pixels(&window)?; let mut pixels = create_pixels(&window)?;
let mut game_boy = LR35902::new();
let mut game_boy = match args().nth(1) {
Some(boot_path) => LR35902::boot_new(&boot_path),
None => LR35902::new(),
};
game_boy.load_cartridge("bin/cpu_instrs.gb"); game_boy.load_cartridge("bin/cpu_instrs.gb");
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {