diff --git a/Cargo.lock b/Cargo.lock index 9b914dc..ed750a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -627,6 +627,8 @@ dependencies = [ "clap", "fundsp", "log", + "num-derive", + "num-traits", "tokio", "wgpu", "winit", @@ -1113,6 +1115,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfb77679af88f8b125209d354a202862602672222e7f2313fdd6dc349bad4712" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "num-integer" version = "0.1.45" diff --git a/Cargo.toml b/Cargo.toml index cfcb20f..2d5f32f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } \ No newline at end of file +bytemuck = { version = "1.14.0", features = ["derive"] } +num-traits = "0.2" +num-derive = "0.4" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 477a712..a982a49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate num_derive; + use crate::context::Context; use crate::cpu::CPU; use crate::mode::GBMode; @@ -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; diff --git a/src/mbc/mod.rs b/src/mbc/mod.rs new file mode 100644 index 0000000..4677d4c --- /dev/null +++ b/src/mbc/mod.rs @@ -0,0 +1 @@ +mod mode; \ No newline at end of file diff --git a/src/mbc/mode.rs b/src/mbc/mode.rs new file mode 100644 index 0000000..6f385e4 --- /dev/null +++ b/src/mbc/mode.rs @@ -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 +} \ No newline at end of file