Skip to content

Commit

Permalink
MBC modes
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Dec 14, 2023
1 parent a246d17 commit 72f9b91
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ bitflags = "2.4.1"
log = "0.4.20"
wgpu = "0.18.0"
tokio = { version = "1.34.0", features = ["full"] }
bytemuck = { version = "1.14.0", features = ["derive"] }
bytemuck = { version = "1.14.0", features = ["derive"] }
num-traits = "0.2"
num-derive = "0.4"
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[macro_use]
extern crate num_derive;

use crate::context::Context;
use crate::cpu::CPU;
use crate::mode::GBMode;
Expand All @@ -21,6 +24,7 @@ mod registers;
mod ppu;
mod serial;
mod timer;
mod mbc;

pub const CLOCK_FREQUENCY: u32 = 4_194_304;
pub const STEP_TIME: u32 = 16;
Expand Down
1 change: 1 addition & 0 deletions src/mbc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod mode;
79 changes: 79 additions & 0 deletions src/mbc/mode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#[derive(Clone, Copy, PartialEq, FromPrimitive)]
pub enum CartTypes {
RomOnly = 0x00,
MBC1 = 0x01,
MBC1Ram = 0x02,
MBC1RamBat = 0x03,
MBC2 = 0x05,
MBC2Bat = 0x06,
// Unused
RomRam = 0x08,
// Unused
RomRamBat = 0x09,
MMM01 = 0x0B,
MMM01Ram = 0x0C,
MMM01RamBat = 0x0D,
MBC3TimerBat = 0x0F,
MBC3TimerRamBat = 0x10,
MBC3 = 0x11,
MBC3Ram = 0x12,
MBC3RamBat = 0x13,
MBC5 = 0x19,
MBC5Ram = 0x1A,
MBC5RamBat = 0x1B,
MBC5Rumble = 0x1C,
MBC5RumbleRam = 0x1D,
MBC5RumbleRamBat = 0x1E,
MBC6 = 0x20,
MBC7SensorRumbleRamBat = 0x22,
PocketCamera = 0xFC,
BandaiTAMA5 = 0xFD,
HuC3 = 0xFE,
HuC1RamBat = 0xFF
}

impl CartTypes {
pub fn get_mbc(&self) -> MBCMode {
match self {
CartTypes::RomOnly => MBCMode::RomOnly,
CartTypes::MBC1 => MBCMode::MBC1,
CartTypes::MBC1Ram => MBCMode::MBC1,
CartTypes::MBC1RamBat => MBCMode::MBC1,
CartTypes::MBC2 => MBCMode::MBC2,
CartTypes::MBC2Bat => MBCMode::MBC2,
CartTypes::RomRam => MBCMode::RomOnly,
CartTypes::RomRamBat => MBCMode::RomOnly,
CartTypes::MMM01 => MBCMode::RomOnly,
CartTypes::MMM01Ram => MBCMode::RomOnly,
CartTypes::MMM01RamBat => MBCMode::RomOnly,
CartTypes::MBC3TimerBat => MBCMode::MBC3,
CartTypes::MBC3TimerRamBat => MBCMode::MBC3,
CartTypes::MBC3 => MBCMode::MBC3,
CartTypes::MBC3Ram => MBCMode::MBC3,
CartTypes::MBC3RamBat => MBCMode::MBC3,
CartTypes::MBC5 => MBCMode::MBC5,
CartTypes::MBC5Ram => MBCMode::MBC5,
CartTypes::MBC5RamBat => MBCMode::MBC5,
CartTypes::MBC5Rumble => MBCMode::MBC5,
CartTypes::MBC5RumbleRam => MBCMode::MBC5,
CartTypes::MBC5RumbleRamBat => MBCMode::MBC5,
// All further type unimplemented
CartTypes::MBC6 => MBCMode::Unsupported,
CartTypes::MBC7SensorRumbleRamBat => MBCMode::Unsupported,
CartTypes::PocketCamera => MBCMode::Unsupported,
CartTypes::BandaiTAMA5 => MBCMode::Unsupported,
CartTypes::HuC3 => MBCMode::Unsupported,
CartTypes::HuC1RamBat => MBCMode::Unsupported,
}
}
}

#[derive(Clone, Copy, PartialEq)]
pub enum MBCMode {
RomOnly,
MBC1,
MBC2,
MBC3,
MBC5,
Unsupported
}

0 comments on commit 72f9b91

Please sign in to comment.