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

chore: renamed game boy mode

parent 9d55eb6c
No related branches found
No related tags found
1 merge request!16Support for Game Boy Color (CGB) 😎🖍️
Pipeline #2558 failed
...@@ -7,7 +7,7 @@ pub mod graphics; ...@@ -7,7 +7,7 @@ pub mod graphics;
use audio::Audio; use audio::Audio;
use boytacean::{ use boytacean::{
devices::printer::PrinterDevice, devices::printer::PrinterDevice,
gb::{AudioProvider, GBMode, GameBoy}, gb::{AudioProvider, GameBoyMode, GameBoy},
pad::PadKey, pad::PadKey,
ppu::{PaletteInfo, PpuMode, DISPLAY_HEIGHT, DISPLAY_WIDTH}, ppu::{PaletteInfo, PpuMode, DISPLAY_HEIGHT, DISPLAY_WIDTH},
}; };
...@@ -446,7 +446,7 @@ impl Emulator { ...@@ -446,7 +446,7 @@ impl Emulator {
fn main() { fn main() {
// creates a new Game Boy instance and loads both the boot ROM // creates a new Game Boy instance and loads both the boot ROM
// and the initial game ROM to "start the engine" // and the initial game ROM to "start the engine"
let mut game_boy = GameBoy::new(GBMode::Cgb); let mut game_boy = GameBoy::new(GameBoyMode::Dmg);
let mut printer = Box::<PrinterDevice>::default(); let mut printer = Box::<PrinterDevice>::default();
printer.set_callback(|image_buffer| { printer.set_callback(|image_buffer| {
let file_name = format!("printer-{}.png", Utc::now().format("%Y%m%d-%H%M%S")); let file_name = format!("printer-{}.png", Utc::now().format("%Y%m%d-%H%M%S"));
......
...@@ -32,9 +32,12 @@ use std::{ ...@@ -32,9 +32,12 @@ use std::{
/// Enumeration that describes the multiple running /// Enumeration that describes the multiple running
// modes of the Game Boy emulator. // modes of the Game Boy emulator.
// DMG = Original Game Boy
// CGB = Game Boy Color
// SGB = Super Game Boy
#[cfg_attr(feature = "wasm", wasm_bindgen)] #[cfg_attr(feature = "wasm", wasm_bindgen)]
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum GBMode { pub enum GameBoyMode {
Dmg = 1, Dmg = 1,
Cgb = 2, Cgb = 2,
Sgb = 3, Sgb = 3,
...@@ -46,7 +49,7 @@ pub struct GameBoyConfig { ...@@ -46,7 +49,7 @@ pub struct GameBoyConfig {
/// The current running mode of the emulator, this /// The current running mode of the emulator, this
/// may affect many aspects of the emulation, like /// may affect many aspects of the emulation, like
/// CPU frequency, PPU frequency, Boot rome size, etc. /// CPU frequency, PPU frequency, Boot rome size, etc.
mode: GBMode, mode: GameBoyMode,
/// If the PPU is enabled, it will be clocked. /// If the PPU is enabled, it will be clocked.
ppu_enabled: bool, ppu_enabled: bool,
...@@ -73,26 +76,26 @@ pub struct GameBoyConfig { ...@@ -73,26 +76,26 @@ pub struct GameBoyConfig {
impl GameBoyConfig { impl GameBoyConfig {
#[inline(always)] #[inline(always)]
pub fn is_dmg(&self) -> bool { pub fn is_dmg(&self) -> bool {
self.mode == GBMode::Dmg self.mode == GameBoyMode::Dmg
} }
#[inline(always)] #[inline(always)]
pub fn is_cgb(&self) -> bool { pub fn is_cgb(&self) -> bool {
self.mode == GBMode::Cgb self.mode == GameBoyMode::Cgb
} }
#[inline(always)] #[inline(always)]
pub fn is_sgb(&self) -> bool { pub fn is_sgb(&self) -> bool {
self.mode == GBMode::Sgb self.mode == GameBoyMode::Sgb
} }
#[inline(always)] #[inline(always)]
pub fn mode(&self) -> GBMode { pub fn mode(&self) -> GameBoyMode {
self.mode self.mode
} }
#[inline(always)] #[inline(always)]
pub fn set_mode(&mut self, value: GBMode) { pub fn set_mode(&mut self, value: GameBoyMode) {
self.mode = value; self.mode = value;
} }
...@@ -189,7 +192,7 @@ pub trait AudioProvider { ...@@ -189,7 +192,7 @@ pub trait AudioProvider {
#[cfg_attr(feature = "wasm", wasm_bindgen)] #[cfg_attr(feature = "wasm", wasm_bindgen)]
impl GameBoy { impl GameBoy {
#[cfg_attr(feature = "wasm", wasm_bindgen(constructor))] #[cfg_attr(feature = "wasm", wasm_bindgen(constructor))]
pub fn new(mode: GBMode) -> Self { pub fn new(mode: GameBoyMode) -> Self {
let gbc = Rc::new(RefCell::new(GameBoyConfig { let gbc = Rc::new(RefCell::new(GameBoyConfig {
mode, mode,
ppu_enabled: true, ppu_enabled: true,
...@@ -282,9 +285,9 @@ impl GameBoy { ...@@ -282,9 +285,9 @@ impl GameBoy {
pub fn load(&mut self, boot: bool) { pub fn load(&mut self, boot: bool) {
match self.mode() { match self.mode() {
GBMode::Dmg => self.load_dmg(boot), GameBoyMode::Dmg => self.load_dmg(boot),
GBMode::Cgb => self.load_cgb(boot), GameBoyMode::Cgb => self.load_cgb(boot),
GBMode::Sgb => todo!(), GameBoyMode::Sgb => todo!(),
} }
} }
...@@ -446,11 +449,11 @@ impl GameBoy { ...@@ -446,11 +449,11 @@ impl GameBoy {
} }
#[inline(always)] #[inline(always)]
pub fn mode(&self) -> GBMode { pub fn mode(&self) -> GameBoyMode {
(*self.gbc).borrow().mode() (*self.gbc).borrow().mode()
} }
pub fn set_mode(&mut self, value: GBMode) { pub fn set_mode(&mut self, value: GameBoyMode) {
(*self.gbc).borrow_mut().set_mode(value); (*self.gbc).borrow_mut().set_mode(value);
} }
...@@ -718,6 +721,6 @@ impl AudioProvider for GameBoy { ...@@ -718,6 +721,6 @@ impl AudioProvider for GameBoy {
impl Default for GameBoy { impl Default for GameBoy {
fn default() -> Self { fn default() -> Self {
Self::new(GBMode::Dmg) Self::new(GameBoyMode::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