Skip to content

Commit

Permalink
feat: bandai mappers 016, 153, 157, 159 (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukexor authored Oct 10, 2024
1 parent 0001765 commit f555ea4
Show file tree
Hide file tree
Showing 23 changed files with 1,198 additions and 241 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,18 @@ Support for the following mappers is currently implemented or in development:
| 007 | AxROM | Battletoads, Marble Madness | ~75 | ~3% |
| 009 | PxROM/MMC2 | Punch Out!! | 1 | <0.01% |
| 010 | FxROM/MMC4 | Fire Emblem Gaiden | 3 | <0.01% |
| 011 | Color Dreams | Crystal Mines, Metal Fighter | 34 | ~1% |
| 011 | Color Dreams | Crystal Mines, Metal Fighter | 15 | ~1% |
| 016 | Bandai FCG | Dragon Ball: Daimaou Fukkatsu | 14 | ~1% |
| 024 | VRC6a | Akumajou Densetsu | 1 | <0.01% |
| 026 | VRC6b | Madara, Esper Dream 2 | 2 | <0.01% |
| 034 | BNROM/NINA-001 | Deadly Towers, Impossible Mission II | 3 | <0.01% |
| 066 | GxROM/MxROM | Super Mario Bros. + Duck Hunt | ~17 | <0.01% |
| 071 | Camerica/Codemasters | Firehawk, Bee 52, MiG 29 - Soviet Fighter | ~15 | <0.01% |
| 153 | Bandai FCG | Famicom Jump II: Saikyou no 7-nin | 1 | <0.01% |
| 157 | Bandai FCG | SD Gundam Wars | 7 | <0.01% |
| 155 | SxROM/MMC1A | Tatakae!! Ramen Man: Sakuretsu Choujin | 2 | <0.01% |
| | | | ~2128 / 2447 | ~87.0% |
| 159 | Bandai FCG | Dragon Ball Z: Kyoushuu! Saiya-jin | 4 | <0.01% |
| | | | ~2155 / 2447 | ~88.0% |

<!-- markdownlint-enable line-length -->

Expand Down
2 changes: 1 addition & 1 deletion tetanes-core/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ mod test {
let mut cart = Cart::empty();
cart.chr_rom = vec![0x66; 0x2000];
// Cnrom doesn't provide CHR-RAM
cart.mapper = Cnrom::load(&mut cart);
cart.mapper = Cnrom::load(&mut cart).unwrap();
bus.load_cart(cart);

bus.write(0x2006, 0x00, Access::Write);
Expand Down
53 changes: 31 additions & 22 deletions tetanes-core/src/cart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{
common::{NesRegion, Regional},
fs,
mapper::{
m024_m026_vrc6::Revision as Vrc6Revision, m034_nina001::Nina001, Axrom, Bf909x, Bnrom,
Cnrom, ColorDreams, Exrom, Fxrom, Gxrom, Mapper, Mmc1Revision, Nrom, Pxrom, Sxrom, Txrom,
Uxrom, Vrc6,
self, m024_m026_vrc6::Revision as Vrc6Revision, m034_nina001::Nina001, Axrom, BandaiFCG,
Bf909x, Bnrom, Cnrom, ColorDreams, Exrom, Fxrom, Gxrom, Mapper, Mmc1Revision, Nrom, Pxrom,
Sxrom, Txrom, Uxrom, Vrc6,
},
mem::RamState,
ppu::Mirroring,
Expand Down Expand Up @@ -34,6 +34,8 @@ pub enum Error {
value: u8,
message: String,
},
#[error("mapper: {0}")]
InvalidMapper(#[from] mapper::Error),
#[error("{context}: {source:?}")]
Io {
context: String,
Expand All @@ -58,7 +60,6 @@ pub struct GameRegion {
}

/// An NES cartridge.
#[derive(Default)]
#[must_use]
pub struct Cart {
name: String,
Expand All @@ -73,6 +74,12 @@ pub struct Cart {
pub(crate) ex_ram: Vec<u8>, // Internal Extra RAM
}

impl Default for Cart {
fn default() -> Self {
Self::empty()
}
}

impl Cart {
pub fn empty() -> Self {
let mut empty = Self {
Expand All @@ -87,7 +94,7 @@ impl Cart {
prg_ram: vec![],
ex_ram: vec![],
};
empty.mapper = Nrom::load(&mut empty);
empty.mapper = Nrom::load(&mut empty).expect("valid empty mapper");
empty
}

Expand Down Expand Up @@ -119,6 +126,7 @@ impl Cart {
{
let name = name.to_string();
let header = NesHeader::load(&mut rom_data)?;
debug!("{header:?}");

let prg_rom_len = (header.prg_rom_banks as usize) * PRG_ROM_BANK_SIZE;
let mut prg_rom = vec![0x00; prg_rom_len];
Expand Down Expand Up @@ -188,29 +196,30 @@ impl Cart {
ex_ram: vec![],
};
cart.mapper = match cart.header.mapper_num {
0 => Nrom::load(&mut cart),
1 => Sxrom::load(&mut cart, Mmc1Revision::BC),
2 => Uxrom::load(&mut cart),
3 => Cnrom::load(&mut cart),
4 => Txrom::load(&mut cart),
5 => Exrom::load(&mut cart),
7 => Axrom::load(&mut cart),
9 => Pxrom::load(&mut cart),
10 => Fxrom::load(&mut cart),
11 => ColorDreams::load(&mut cart),
24 => Vrc6::load(&mut cart, Vrc6Revision::A),
26 => Vrc6::load(&mut cart, Vrc6Revision::B),
0 => Nrom::load(&mut cart)?,
1 => Sxrom::load(&mut cart, Mmc1Revision::BC)?,
2 => Uxrom::load(&mut cart)?,
3 => Cnrom::load(&mut cart)?,
4 => Txrom::load(&mut cart)?,
5 => Exrom::load(&mut cart)?,
7 => Axrom::load(&mut cart)?,
9 => Pxrom::load(&mut cart)?,
10 => Fxrom::load(&mut cart)?,
11 => ColorDreams::load(&mut cart)?,
16 | 153 | 157 | 159 => BandaiFCG::load(&mut cart)?,
24 => Vrc6::load(&mut cart, Vrc6Revision::A)?,
26 => Vrc6::load(&mut cart, Vrc6Revision::B)?,
34 => {
// ≥ 16K implies NINA-001; ≤ 8K implies BNROM
if cart.has_chr_rom() && cart.chr_rom.len() >= 0x4000 {
Nina001::load(&mut cart)
Nina001::load(&mut cart)?
} else {
Bnrom::load(&mut cart)
Bnrom::load(&mut cart)?
}
}
66 => Gxrom::load(&mut cart),
71 => Bf909x::load(&mut cart),
155 => Sxrom::load(&mut cart, Mmc1Revision::A),
66 => Gxrom::load(&mut cart)?,
71 => Bf909x::load(&mut cart)?,
155 => Sxrom::load(&mut cart, Mmc1Revision::A)?,
_ => Mapper::none(),
};

Expand Down
Loading

0 comments on commit f555ea4

Please sign in to comment.