Skip to content

Commit

Permalink
fix: cleaned up mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
lukexor committed Apr 16, 2024
1 parent b611f9f commit 22c97e2
Show file tree
Hide file tree
Showing 23 changed files with 208 additions and 112 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Support for the following mappers is currently implemented or in development:
| 009 | PxROM/MMC2 | Punch Out!! | 1 | <0.01% |
| 024 | VRC6a | Akumajou Densetsu | 1 | <0.01% |
| 026 | VRC6b | Madara, Esper Dream 2 | 2 | <0.01% |
| 034 | BxROM | Deadly Towers, Impossible Mission II | 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% |
| 155 | SxROM/MMC1A | Tatakae!! Ramen Man: Sakuretsu Choujin | 2 | <0.01% |
Expand Down Expand Up @@ -172,8 +172,10 @@ Emulator shortcuts:
| Quit | Ctrl-Q | |
| Reset | Ctrl-R | |
| Power Cycle | Ctrl-P | |
| Increase Speed by 25% | Ctrl-Shift-+ | Right Shoulder |
| Decrease Speed by 25% | Ctrl-Shift-- | Left Shoulder |
| Increase Speed by 25% | = | Right Shoulder |
| Decrease Speed by 25% | - | Left Shoulder |
| Increase UI Scale | Ctrl-= | |
| Decrease UI Scale | Ctrl-- | |
| Fast-Forward 2x | Space (Hold) | |
| Set Save State Slot (1-4) | Ctrl-(1-4) | |
| Save State | Ctrl-S | |
Expand Down
3 changes: 3 additions & 0 deletions tetanes-core/game_database.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@
927C7A3A, NTSC, Mapper 000 - NROM/0, 1, 0, 0, false, Horizontal, "Joust (Japan).nes"
92924548, PAL, Mapper 000 - NROM/0, 1, 0, 0, false, Vertical, "Ice Hockey (Europe).nes"
92A2185C, NTSC, Mapper 009 - PxROM/0, 16, 0, 0, false, Horizontal, "Mike Tyson's Punch-Out!! (Japan, USA).nes"
92A3D007, NTSC, Mapper 034 - BNROM/NINA-001/0, 8, 0, 0, false, Vertical, "Impossible Mission II (USA) (Unl).nes"
92C138E4, NTSC, Mapper 001 - SxROM/MMC1B/C/0, 8, 2, 2, false, Horizontal, "Miracle Piano Teaching System, The (USA).nes"
92DD67EA, NTSC, Mapper 001 - SxROM/MMC1B/C/0, 16, 2, 2, false, Vertical, "Flying Warriors (USA) (Beta).nes"
92F04530, NTSC, Mapper 002 - UxROM/0, 0, 0, 0, false, Vertical, "Goonies 2 - Fratelli Saigo no Chousen (Japan).nes"
Expand Down Expand Up @@ -1405,6 +1406,7 @@
A1FF4E1D, NTSC, Mapper 001 - SxROM/MMC1B/C/0, 16, 2, 2, false, Horizontal, "Swamp Thing (USA).nes"
A20B4983, NTSC, Mapper 000 - NROM/0, 8, 0, 0, false, Horizontal, "Popo Team (Asia) (Unl).nes"
A2194CAD, NTSC, Mapper 002 - UxROM/0, 0, 0, 0, false, Vertical, "Legendary Wings (USA).nes"
A21E675C, NTSC, Mapper 034 - BNROM/NINA-001/0, 0, 0, 0, false, Horizontal, "Mashou (Japan).nes"
A222F5A0, NTSC, Mapper 000 - NROM/0, 1, 0, 0, false, Horizontal, "Ninja-kun - Majou no Bouken (Japan).nes"
A22657FA, NTSC, Mapper 004 - TxROM/MMC3/MMC6/0, 16, 0, 0, false, Horizontal, "Nintendo World Cup (USA).nes"
A23F0A27, NTSC, Mapper 003 - CNROM/0, 4, 0, 0, false, Horizontal, "Exerion (Japan) (En) (Proto) [b].nes"
Expand Down Expand Up @@ -1677,6 +1679,7 @@
C22F3E9F, NTSC, Mapper 001 - SxROM/MMC1B/C/0, 16, 2, 2, true, Vertical, "Advanced Dungeons & Dragons - Heroes of the Lance (USA) (Beta).nes"
C22FF1D8, NTSC, Mapper 001 - SxROM/MMC1B/C/0, 16, 2, 2, false, Horizontal, "RoboCop 2 (Japan).nes"
C247A23D, NTSC, Mapper 004 - TxROM/MMC3/MMC6/0, 32, 0, 0, false, Horizontal, "Batman Returns (USA).nes"
C2730C30, NTSC, Mapper 034 - BNROM/NINA-001/0, 0, 0, 0, false, Horizontal, "Deadly Towers (USA).nes"
C2EF3422, NTSC, Mapper 001 - SxROM/MMC1B/C/0, 0, 2, 2, true, Horizontal, "Best Play Pro Yakyuu II (Japan).nes"
C30848D3, PAL, Mapper 000 - NROM/0, 1, 0, 0, false, Vertical, "Slalom (Europe).nes"
C30C9EC9, NTSC, Mapper 001 - SxROM/MMC1B/C/0, 0, 2, 2, true, Horizontal, "Shoukoushi Ceddie (Japan).nes"
Expand Down
Binary file modified tetanes-core/game_regions.dat
Binary file not shown.
4 changes: 2 additions & 2 deletions tetanes-core/src/apu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ impl std::fmt::Debug for Apu {
// *val = 95.52 / (8_128.0 / (i as f32) + 100.0);
// }
#[rustfmt::skip]
pub(crate) static PULSE_TABLE: [f32; 31] = [
pub static PULSE_TABLE: [f32; 31] = [
0.0, 0.011_609_139, 0.022_939_48, 0.034_000_948, 0.044_803, 0.055_354_66,
0.065_664_53, 0.075_740_82, 0.085_591_4, 0.095_223_75, 0.104_645_04, 0.113_862_15,
0.122_881_64, 0.131_709_8, 0.140_352_64, 0.148_815_96, 0.157_105_25, 0.165_225_88,
Expand All @@ -615,7 +615,7 @@ pub(crate) static PULSE_TABLE: [f32; 31] = [
// *val = 163.67 / (24_329.0 / (i as f32) + 100.0);
// }
#[rustfmt::skip]
static TND_TABLE: [f32; 203] = [
pub static TND_TABLE: [f32; 203] = [
0.0, 0.006_699_824, 0.013_345_02, 0.019_936_256, 0.026_474_18, 0.032_959_443,
0.039_392_676, 0.045_774_5, 0.052_105_535, 0.058_386_38, 0.064_617_634, 0.070_799_87,
0.076_933_69, 0.083_019_62, 0.089_058_26, 0.095_050_134, 0.100_995_794, 0.106_895_77,
Expand Down
8 changes: 6 additions & 2 deletions tetanes-core/src/apu/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,12 @@ impl FilterChain {
pub fn new(region: NesRegion, output_rate: f32) -> Self {
let clock_rate = Cpu::region_clock_rate(region);
let intermediate_sample_rate = output_rate * 2.0 + (PI / 32.0);
let intermediate_cutoff = output_rate * 0.4;

let mut filters = vec![SampledFilter::new(Iir::identity(), 1.0)];
let mut filters = vec![
SampledFilter::new(Iir::identity(), 1.0),
SampledFilter::new(Iir::low_pass(clock_rate, intermediate_cutoff), clock_rate),
];
// first-order high-pass filter at 90 Hz
filters.push(SampledFilter::new(
Iir::high_pass(intermediate_sample_rate, 90.0),
Expand All @@ -253,7 +257,7 @@ impl FilterChain {
// ));

// high-quality low-pass filter
let window_size = 60;
let window_size = 160;
let intermediate_cutoff = output_rate * 0.45;
filters.push(SampledFilter::new(
Fir::low_pass(intermediate_sample_rate, intermediate_cutoff, window_size),
Expand Down
13 changes: 11 additions & 2 deletions tetanes-core/src/cart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::{
common::{NesRegion, Regional},
fs,
mapper::{
m024_m026_vrc6::Vrc6Revision, Axrom, Bf909x, Bnrom, Cnrom, Exrom, Gxrom, Mapper, Mmc1Revision, Nrom, Pxrom, Sxrom, Txrom, Uxrom, Vrc6
m024_m026_vrc6::Revision as Vrc6Revision, m034_nina001::Nina001, Axrom, Bf909x, Bnrom,
Cnrom, Exrom, Gxrom, Mapper, Mmc1Revision, Nrom, Pxrom, Sxrom, Txrom, Uxrom, Vrc6,
},
mem::RamState,
ppu::Mirroring,
Expand Down Expand Up @@ -197,8 +198,15 @@ impl Cart {
9 => Pxrom::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)
} else {
Bnrom::load(&mut cart)
}
}
66 => Gxrom::load(&mut cart),
34 => Bnrom::load(&mut cart),
71 => Bf909x::load(&mut cart),
155 => Sxrom::load(&mut cart, Mmc1Revision::A),
_ => return Err(Error::UnimplementedMapper(cart.header.mapper_num)),
Expand Down Expand Up @@ -597,6 +605,7 @@ impl NesHeader {
9 => "Mapper 009 - PxROM",
24 => "Mapper 024 - Vrc6a",
26 => "Mapper 026 - Vrc6b",
34 => "Mapper 034 - BNROM/NINA-001",
66 => "Mapper 066 - GxROM/MxROM",
71 => "Mapper 071 - Camerica/Codemasters/BF909x",
155 => "Mapper 155 - SxROM/MMC1A",
Expand Down
17 changes: 10 additions & 7 deletions tetanes-core/src/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ use enum_dispatch::enum_dispatch;
use serde::{Deserialize, Serialize};

pub use m000_nrom::Nrom;
pub use m001_sxrom::{Mmc1Revision, Sxrom};
pub use m001_sxrom::{Revision as Mmc1Revision, Sxrom};
pub use m002_uxrom::Uxrom;
pub use m003_cnrom::Cnrom;
pub use m004_txrom::{Mmc3Revision, Txrom};
pub use m004_txrom::{Revision as Mmc3Revision, Txrom};
pub use m005_exrom::Exrom;
pub use m007_axrom::Axrom;
pub use m009_pxrom::Pxrom;
pub use m024_m026_vrc6::Vrc6;
pub use m034_bnrom::Bnrom;
pub use m034_nina001::Nina001;
pub use m066_gxrom::Gxrom;
pub use m071_bf909x::{Bf909Revision, Bf909x};
pub use m071_bf909x::{Bf909x, Revision as Bf909Revision};

pub mod m000_nrom;
pub mod m001_sxrom;
Expand All @@ -32,6 +33,7 @@ pub mod m007_axrom;
pub mod m009_pxrom;
pub mod m024_m026_vrc6;
pub mod m034_bnrom;
pub mod m034_nina001;
pub mod m066_gxrom;
pub mod m071_bf909x;
pub mod vrc_irq;
Expand Down Expand Up @@ -60,6 +62,7 @@ pub enum Mapper {
Pxrom,
Vrc6,
Bnrom,
Nina001,
Gxrom,
Bf909x,
}
Expand All @@ -79,7 +82,7 @@ impl Default for Mapper {
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[must_use]
pub enum MappedRead {
PpuRam,
Bus,
Chr(usize),
CIRam(usize),
ExRam(usize),
Expand All @@ -92,7 +95,7 @@ pub enum MappedRead {
#[must_use]
pub enum MappedWrite {
None,
PpuRam,
Bus,
Chr(usize, u8),
CIRam(usize, u8),
ExRam(usize, u8),
Expand All @@ -107,11 +110,11 @@ pub trait MemMap {
}

fn map_peek(&self, _addr: u16) -> MappedRead {
MappedRead::PpuRam
MappedRead::Bus
}

fn map_write(&mut self, _addr: u16, _val: u8) -> MappedWrite {
MappedWrite::PpuRam
MappedWrite::Bus
}
}

Expand Down
4 changes: 2 additions & 2 deletions tetanes-core/src/mapper/m000_nrom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ impl MemMap for Nrom {
let mirror = if self.mirror_prg_rom { 0x3FFF } else { 0x7FFF };
MappedRead::PrgRom((addr & mirror).into())
}
_ => MappedRead::PpuRam,
_ => MappedRead::Bus,
}
}

fn map_write(&mut self, addr: u16, val: u8) -> MappedWrite {
match addr {
0x0000..=0x1FFF => MappedWrite::Chr(addr.into(), val),
0x6000..=0x7FFF => MappedWrite::PrgRam((addr & 0x1FFF).into(), val),
_ => MappedWrite::PpuRam,
_ => MappedWrite::Bus,
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions tetanes-core/src/mapper/m001_sxrom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[must_use]
pub enum Mmc1Revision {
pub enum Revision {
/// MMC1 Revision A
A,
/// MMC1 Revisions B & C
Expand All @@ -38,7 +38,7 @@ pub struct Sxrom {
pub regs: SxRegs,
pub submapper_num: u8,
pub mirroring: Mirroring,
pub board: Mmc1Revision,
pub revision: Revision,
pub chr_select: bool,
pub chr_banks: MemBanks,
pub prg_ram_banks: MemBanks,
Expand All @@ -62,7 +62,7 @@ impl Sxrom {
const PRG_BANK_MASK: u8 = 0x0F;
const PRG_RAM_DISABLED: u8 = 0x10; // 0b10000

pub fn load(cart: &mut Cart, board: Mmc1Revision) -> Mapper {
pub fn load(cart: &mut Cart, revision: Revision) -> Mapper {
if !cart.has_prg_ram() {
cart.add_prg_ram(Self::PRG_RAM_SIZE);
}
Expand All @@ -85,7 +85,7 @@ impl Sxrom {
},
submapper_num: cart.submapper_num(),
mirroring: Mirroring::SingleScreenA,
board,
revision,
chr_select: cart.prg_rom.len() == 0x80000,
chr_banks: MemBanks::new(0x0000, 0x1FFF, chr_len, Self::CHR_WINDOW),
prg_ram_banks: MemBanks::new(0x6000, 0x7FFF, cart.prg_ram.len(), Self::PRG_RAM_WINDOW),
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Sxrom {
}

pub fn prg_ram_enabled(&self) -> bool {
self.board == Mmc1Revision::A || self.regs.prg & Self::PRG_RAM_DISABLED == 0
self.revision == Revision::A || self.regs.prg & Self::PRG_RAM_DISABLED == 0
}
}

Expand All @@ -179,7 +179,7 @@ impl MemMap for Sxrom {
MappedRead::PrgRam(self.prg_ram_banks.translate(addr))
}
0x8000..=0xFFFF => MappedRead::PrgRom(self.prg_rom_banks.translate(addr)),
_ => MappedRead::PpuRam,
_ => MappedRead::Bus,
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ impl MemMap for Sxrom {
// +----- PRG-RAM chip enable (0: enabled; 1: disabled; ignored on MMC1A)

if self.regs.write_just_occurred > 0 {
return MappedWrite::PpuRam;
return MappedWrite::Bus;
}
self.regs.write_just_occurred = 2;
if val & Self::SHIFT_REG_RESET > 0 {
Expand All @@ -263,9 +263,9 @@ impl MemMap for Sxrom {
self.update_banks(addr);
}
}
MappedWrite::PpuRam
MappedWrite::Bus
}
_ => MappedWrite::PpuRam,
_ => MappedWrite::Bus,
}
}
}
Expand Down Expand Up @@ -299,7 +299,7 @@ impl std::fmt::Debug for Sxrom {
.field("regs", &self.regs)
.field("submapper_num", &self.submapper_num)
.field("mirroring", &self.mirroring)
.field("board", &self.board)
.field("revision", &self.revision)
.field("chr_select", &self.chr_select)
.field("chr_banks", &self.chr_banks)
.field("prg_ram_banks", &self.prg_ram_banks)
Expand Down
6 changes: 3 additions & 3 deletions tetanes-core/src/mapper/m002_uxrom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl MemMap for Uxrom {
match addr {
0x0000..=0x1FFF => MappedRead::Chr(addr.into()),
0x8000..=0xFFFF => MappedRead::PrgRom(self.prg_rom_banks.translate(addr)),
_ => MappedRead::PpuRam,
_ => MappedRead::Bus,
}
}

Expand All @@ -54,9 +54,9 @@ impl MemMap for Uxrom {
0x0000..=0x1FFF => MappedWrite::Chr(addr.into(), val),
0x8000..=0xFFFF => {
self.prg_rom_banks.set(0, val.into());
MappedWrite::PpuRam
MappedWrite::Bus
}
_ => MappedWrite::PpuRam,
_ => MappedWrite::Bus,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tetanes-core/src/mapper/m003_cnrom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ impl MemMap for Cnrom {
let mirror = if self.mirror_prg_rom { 0x3FFF } else { 0x7FFF };
MappedRead::PrgRom((addr & mirror).into())
}
_ => MappedRead::PpuRam,
_ => MappedRead::Bus,
}
}

fn map_write(&mut self, addr: u16, val: u8) -> MappedWrite {
if matches!(addr, 0x8000..=0xFFFF) {
self.chr_banks.set(0, val.into());
}
MappedWrite::PpuRam
MappedWrite::Bus
}
}

Expand Down
Loading

0 comments on commit 22c97e2

Please sign in to comment.