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

chore: support for "fake" speed switching

This is a temporary hack until a real speed switch is available.
parent c019116c
No related branches found
No related tags found
1 merge request!16Support for Game Boy Color (CGB) 😎🖍️
Pipeline #2630 failed
......@@ -541,7 +541,11 @@ impl Cpu {
#[inline(always)]
pub fn stop(&mut self) {
panic!("STOP is not implemented");
let mmu = self.mmu();
if mmu.switching {
mmu.switching = false;
mmu.speed = mmu.speed.switch();
}
}
#[inline(always)]
......
......@@ -89,6 +89,36 @@ pub enum GameBoySpeed {
Double = 1,
}
impl GameBoySpeed {
pub fn description(&self) -> &'static str {
match self {
GameBoySpeed::Normal => "Normal Speed",
GameBoySpeed::Double => "Double Speed",
}
}
pub fn switch(&self) -> GameBoySpeed {
match self {
GameBoySpeed::Normal => GameBoySpeed::Double,
GameBoySpeed::Double => GameBoySpeed::Normal,
}
}
pub fn from_u8(value: u8) -> GameBoySpeed {
match value {
0 => GameBoySpeed::Normal,
1 => GameBoySpeed::Double,
_ => panic!("Invalid speed value: {}", value),
}
}
}
impl Display for GameBoySpeed {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.description())
}
}
#[cfg_attr(feature = "wasm", wasm_bindgen)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct GameBoyConfig {
......
......@@ -31,6 +31,8 @@ pub struct Mmu {
pub speed: GameBoySpeed,
pub switching: bool,
/// Reference to the PPU (Pixel Processing Unit) that is going
/// to be used both for VRAM reading/writing and to forward
/// some of the access operations.
......@@ -113,6 +115,7 @@ impl Mmu {
ie: 0x0,
key0: 0x0,
speed: GameBoySpeed::Normal,
switching: false,
mode,
gbc,
}
......@@ -127,6 +130,8 @@ impl Mmu {
self.ram_offset = 0x1000;
self.ie = 0x0;
self.key0 = 0x0;
self.speed = GameBoySpeed::Normal;
self.switching = false;
}
pub fn allocate_default(&mut self) {
......@@ -345,7 +350,13 @@ impl Mmu {
0x4c => self.key0 = value,
// 0xFF4D - KEY1 (CGB only)
0x4d => todo!("CGB speed switch WRITE"),
0x4d => {
// @TODO: The switching of CPU speed is not yet
// implemented and required more work to be done.
// Inclusive the propagation of the speed to the
// controller emulator.
self.switching = value & 0x01 == 0x01;
}
// 0xFF50 - Boot active flag
0x50 => self.boot_active = false,
......
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