can choose cgb mode

This commit is contained in:
Alex Janka 2023-04-20 12:29:22 +10:00
parent 1d09a2500a
commit 1678372c2b
6 changed files with 50 additions and 18 deletions

View file

@ -40,7 +40,7 @@ struct Args {
bootrom: Option<String>, bootrom: Option<String>,
/// Connect the serial port output to stdout /// Connect the serial port output to stdout
#[arg(short, long)] #[arg(long)]
connect_serial: bool, connect_serial: bool,
/// Show cycle count /// Show cycle count
@ -62,6 +62,10 @@ struct Args {
/// Run debug console /// Run debug console
#[arg(short, long)] #[arg(short, long)]
debug: bool, debug: bool,
/// Force CGB mode
#[arg(short, long)]
cgb: bool,
} }
fn main() { fn main() {
@ -109,7 +113,8 @@ fn main() {
}) })
.with_bootrom(args.bootrom.map(RomFile::Path)) .with_bootrom(args.bootrom.map(RomFile::Path))
.with_no_save(args.no_save) .with_no_save(args.no_save)
.with_tile_window(tile_window); .with_tile_window(tile_window)
.with_cgb_mode(args.cgb);
let mut core = EmulatorCore::init(receiver, options); let mut core = EmulatorCore::init(receiver, options);

View file

@ -166,6 +166,7 @@ where
pub(crate) no_save: bool, pub(crate) no_save: bool,
pub(crate) bootrom: Option<RomFile>, pub(crate) bootrom: Option<RomFile>,
pub(crate) serial_target: SerialTarget, pub(crate) serial_target: SerialTarget,
pub(crate) cgb_mode: bool,
spooky: PhantomData<ColourFormat>, spooky: PhantomData<ColourFormat>,
} }
@ -185,6 +186,7 @@ where
no_save: false, no_save: false,
bootrom: None, bootrom: None,
serial_target: SerialTarget::None, serial_target: SerialTarget::None,
cgb_mode: false,
spooky: PhantomData, spooky: PhantomData,
} }
} }
@ -207,6 +209,7 @@ where
no_save: false, no_save: false,
bootrom: None, bootrom: None,
serial_target: SerialTarget::None, serial_target: SerialTarget::None,
cgb_mode: false,
spooky: PhantomData, spooky: PhantomData,
} }
} }
@ -245,4 +248,9 @@ where
self.tile_window = window; self.tile_window = window;
self self
} }
pub fn with_cgb_mode(mut self, cgb_mode: bool) -> Self {
self.cgb_mode = cgb_mode;
self
}
} }

View file

@ -1,7 +1,10 @@
use crate::processor::memory::rom::CgbRomType;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
// Hz // Hz
pub const CLOCK_SPEED: usize = 4194304; pub const CLOCK_SPEED: usize = 4194304;
pub(crate) static IS_CGB: OnceCell<CgbRomType> = OnceCell::new(); pub(crate) static STATIC_IS_CGB: OnceCell<bool> = OnceCell::new();
pub(crate) fn is_cgb() -> bool {
STATIC_IS_CGB.get().copied().unwrap_or(false)
}

View file

@ -8,8 +8,9 @@ use connect::{
AudioOutput, CameraWrapper, CameraWrapperRef, EmulatorMessage, EmulatorOptions, NoCamera, AudioOutput, CameraWrapper, CameraWrapperRef, EmulatorMessage, EmulatorOptions, NoCamera,
PocketCamera, Renderer, RomFile, SerialTarget, PocketCamera, Renderer, RomFile, SerialTarget,
}; };
use constants::{is_cgb, STATIC_IS_CGB};
use processor::{ use processor::{
memory::{mmio::gpu::Colour, Rom}, memory::{mmio::gpu::Colour, rom::CgbRomType, Rom},
Cpu, CpuSaveState, Cpu, CpuSaveState,
}; };
use std::{ use std::{
@ -76,10 +77,15 @@ where
RomFile::Raw(data) => Rom::load(data, None, camera.clone()), RomFile::Raw(data) => Rom::load(data, None, camera.clone()),
}; };
let _ = STATIC_IS_CGB.set(rom.rom_type == CgbRomType::CgbOnly || options.cgb_mode);
options.window.prepare(WIDTH, HEIGHT); options.window.prepare(WIDTH, HEIGHT);
options options.window.set_title(format!(
.window "{} on {} on {}",
.set_title(format!("{} on {}", rom.get_title(), rom.mbc_type())); rom.get_title(),
rom.mbc_type(),
if is_cgb() { "CGB" } else { "DMG" }
));
let bootrom_enabled = options.bootrom.is_some(); let bootrom_enabled = options.bootrom.is_some();
let bootrom: Option<Vec<u8>> = options.bootrom.map(|v| match v { let bootrom: Option<Vec<u8>> = options.bootrom.map(|v| match v {

View file

@ -11,6 +11,7 @@ use self::{
}; };
use crate::{ use crate::{
connect::{AudioOutput, CameraWrapperRef, JoypadState, PocketCamera, Renderer, SerialTarget}, connect::{AudioOutput, CameraWrapperRef, JoypadState, PocketCamera, Renderer, SerialTarget},
constants::is_cgb,
Cpu, Cpu,
}; };
@ -243,7 +244,13 @@ where
0xFF4B => self.gpu.get_wx(), 0xFF4B => self.gpu.get_wx(),
0x0..0xFF40 | 0xFF4C..=0xFFFF => unreachable!(), 0x0..0xFF40 | 0xFF4C..=0xFFFF => unreachable!(),
}, },
IoAddress::Cgb(_) => todo!(), IoAddress::Cgb(_) => {
if is_cgb() {
todo!();
} else {
0xFF
}
}
IoAddress::Unused(_) => 0xFF, IoAddress::Unused(_) => 0xFF,
} }
} }
@ -283,7 +290,11 @@ where
0xFF4B => self.gpu.update_wx(data), 0xFF4B => self.gpu.update_wx(data),
0x0..0xFF40 | 0xFF4C..=0xFFFF => unreachable!(), 0x0..0xFF40 | 0xFF4C..=0xFFFF => unreachable!(),
}, },
IoAddress::Cgb(_) => todo!(), IoAddress::Cgb(_) => {
if is_cgb() {
todo!()
}
}
IoAddress::Unused(_) => {} IoAddress::Unused(_) => {}
} }
} }

View file

@ -1,9 +1,5 @@
use crate::connect::{CameraWrapperRef, PocketCamera as PocketCameraTrait};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{
connect::{CameraWrapperRef, PocketCamera as PocketCameraTrait},
constants::IS_CGB,
};
use std::{ use std::{
fs::{File, OpenOptions}, fs::{File, OpenOptions},
io::{Read, Seek, SeekFrom, Write}, io::{Read, Seek, SeekFrom, Write},
@ -127,7 +123,7 @@ impl Drop for MaybeBufferedSram {
} }
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize, Debug, PartialEq)]
pub(crate) enum CgbRomType { pub(crate) enum CgbRomType {
Dmg, Dmg,
CgbOptional, CgbOptional,
@ -140,6 +136,7 @@ where
{ {
title: String, title: String,
mbc: Box<dyn Mbc>, mbc: Box<dyn Mbc>,
pub(crate) rom_type: CgbRomType,
spooky: PhantomData<C>, spooky: PhantomData<C>,
} }
@ -207,7 +204,7 @@ where
.expect("Error parsing title") .expect("Error parsing title")
.to_string(); .to_string();
let _ = IS_CGB.set(get_cgb_rom_type(data[0x143])); let rom_type = get_cgb_rom_type(data[0x143]);
let _sgb_flag = data[0x146]; let _sgb_flag = data[0x146];
let rom_size = data[0x148]; let rom_size = data[0x148];
@ -238,6 +235,7 @@ where
Self { Self {
title, title,
mbc, mbc,
rom_type,
spooky: PhantomData, spooky: PhantomData,
} }
} }
@ -247,10 +245,11 @@ where
data: Vec<u8>, data: Vec<u8>,
camera: CameraWrapperRef<C>, camera: CameraWrapperRef<C>,
) -> Self { ) -> Self {
let _ = IS_CGB.set(get_cgb_rom_type(data[0x143])); let rom_type = get_cgb_rom_type(data[0x143]);
Self { Self {
title: state.title, title: state.title,
mbc: state.mbc.get_mbc(data, camera), mbc: state.mbc.get_mbc(data, camera),
rom_type,
spooky: PhantomData, spooky: PhantomData,
} }
} }