Skip to content
Snippets Groups Projects
Verified Commit d07e7f09 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: better structure for boot loading of CGB

parent a914056c
No related branches found
No related tags found
1 merge request!16Support for Game Boy Color (CGB) 😎🖍️
Pipeline #2554 failed
......@@ -7,7 +7,7 @@ pub mod graphics;
use audio::Audio;
use boytacean::{
devices::printer::PrinterDevice,
gb::{AudioProvider, GameBoy},
gb::{AudioProvider, GBMode, GameBoy},
pad::PadKey,
ppu::{PaletteInfo, PpuMode, DISPLAY_HEIGHT, DISPLAY_WIDTH},
};
......@@ -186,7 +186,7 @@ impl Emulator {
pub fn reset(&mut self) {
self.system.reset();
self.system.load_boot_default();
self.system.load(true);
self.load_rom(None);
}
......@@ -317,7 +317,7 @@ impl Emulator {
}
Event::DropFile { filename, .. } => {
self.system.reset();
self.system.load_boot_cgb();
self.system.load(true);
self.load_rom(Some(&filename));
}
_ => (),
......@@ -446,7 +446,7 @@ impl Emulator {
fn main() {
// creates a new Game Boy instance and loads both the boot ROM
// and the initial game ROM to "start the engine"
let mut game_boy = GameBoy::new();
let mut game_boy = GameBoy::new(GBMode::Cgb);
let mut printer = Box::<PrinterDevice>::default();
printer.set_callback(|image_buffer| {
let file_name = format!("printer-{}.png", Utc::now().format("%Y%m%d-%H%M%S"));
......@@ -460,7 +460,7 @@ fn main() {
.unwrap();
});
game_boy.attach_serial(printer);
game_boy.load_boot_cgb();
game_boy.load(true);
// creates a new generic emulator structure then starts
// both the video and audio sub-systems, loads default
......
......@@ -30,11 +30,24 @@ use std::{
panic::{set_hook, take_hook, PanicInfo},
};
/// Enumeration that describes the multiple running
// modes of the Game Boy emulator.
pub enum GBMode {
Dmg = 1,
Cgb = 2,
Sgb = 3,
}
/// Top level structure that abstracts the usage of the
/// Game Boy system under the Boytacean emulator.
/// Should serve as the main entry-point API.
#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub struct GameBoy {
/// The current running mode of the emulator, this
/// may affect many aspects of the emulation, like
/// CPU frequency, PPU frequency, Boot rome size, etc.
mode: GBMode,
/// Reference to the Game Boy CPU component to be
/// used as the main element of the system, when
/// clocked, the amount of ticks from it will be
......@@ -90,7 +103,7 @@ pub trait AudioProvider {
#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl GameBoy {
#[cfg_attr(feature = "wasm", wasm_bindgen(constructor))]
pub fn new() -> Self {
pub fn new(mode: GBMode) -> Self {
let ppu = Ppu::default();
let apu = Apu::default();
let pad = Pad::default();
......@@ -99,6 +112,7 @@ impl GameBoy {
let mmu = Mmu::new(ppu, apu, pad, timer, serial);
let cpu = Cpu::new(mmu);
Self {
mode,
cpu,
ppu_enabled: true,
apu_enabled: true,
......@@ -178,10 +192,11 @@ impl GameBoy {
self.cpu.boot();
}
pub fn load_default(&mut self, boot: bool) {
self.mmu().allocate_default();
if boot {
self.load_boot_default();
pub fn load(&mut self, boot: bool) {
match self.mode {
GBMode::Dmg => self.load_dmg(boot),
GBMode::Cgb => self.load_cgb(boot),
GBMode::Sgb => todo!(),
}
}
......@@ -601,6 +616,6 @@ impl AudioProvider for GameBoy {
impl Default for GameBoy {
fn default() -> Self {
Self::new()
Self::new(GBMode::Dmg)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment