aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/runrom/src/main.rs63
-rw-r--r--lib/vnf/src/lib.rs318
-rwxr-xr-xscripts/test-e2e.sh15
-rw-r--r--tests/expected/runrom/mmc3-basic.txt94
-rw-r--r--tests/expected/runrom/mmc3-no-wram.txt71
-rw-r--r--tests/expected/runrom/mmc3-no-writes.txt72
-rw-r--r--tests/runrom/mmc3/basic.s241
-rw-r--r--tests/runrom/mmc3/mmc3.cfg92
8 files changed, 935 insertions, 31 deletions
diff --git a/crates/runrom/src/main.rs b/crates/runrom/src/main.rs
index d758e01..7eea82f 100644
--- a/crates/runrom/src/main.rs
+++ b/crates/runrom/src/main.rs
@@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader, ErrorKind, Read, Seek, SeekFrom};
use std::path::{Path, PathBuf};
-use vnf::{Machine, MemoryPolicy, fetch_nasm_addresses};
+use vnf::{Machine, MemoryMapperChip, MemoryPolicy, Mmc3, Mmc3BankMode, fetch_nasm_addresses};
/// Version for this program.
const VERSION: &str = "0.1.0";
@@ -18,6 +18,7 @@ struct Args {
until_address: u16,
halt_on_brk: bool,
cycle_limit: Option<usize>,
+ mmc: Option<MemoryMapperChip>,
}
fn print_help() {
@@ -30,6 +31,7 @@ fn print_help() {
println!(" -d, --dump-memory\t\tShow the memory that has changed after a run.");
println!(" -f, --function\t\tRun the code by assuming it's a function.");
println!(" -h, --help\t\t\tPrint this message and quit.");
+ println!(" --mmc <CONFIG>\t\tProvide the configuration for a memory mapper chip.");
println!(" -n, --nasm-directory <PATH>\tPath to the .nasm/ directory.");
println!(" --no-halting-brk\t\tDo not halt execution after a brk instruction.");
println!(" -s, --start\t\t\tAddress from where to start (default: reset vector).");
@@ -145,6 +147,44 @@ fn parse_hex_or_reference(
}
}
+fn parse_mmc(line: &str) -> MemoryMapperChip {
+ let map: HashMap<String, String> = line
+ .split(';')
+ .filter_map(|pair| pair.split_once('='))
+ .map(|(k, v)| (k.trim().to_lowercase(), v.trim().to_lowercase()))
+ .collect();
+
+ match map.get("kind").map(|s| s.as_str()) {
+ Some("mmc3") => {
+ let parse_field = |key: &str| -> usize {
+ map.get(key)
+ .unwrap_or_else(|| {
+ die(format!("missing required field '{key}' in '--mmc' flag"))
+ })
+ .parse::<usize>()
+ .unwrap_or_else(|_| die(format!("invalid integer for '{key}' in '--mmc' flag")))
+ };
+
+ MemoryMapperChip::Mmc3(Mmc3 {
+ prg_rom_mode: if parse_field("prg_rom_mode") == 0 {
+ Mmc3BankMode::FirstSwappable
+ } else {
+ Mmc3BankMode::SecondSwappable
+ },
+ r6: parse_field("r6"),
+ r7: parse_field("r7"),
+ prg_ram_enabled: parse_field("prg_ram_enabled") == 1,
+ prg_ram_writes_allowed: parse_field("prg_ram_writes_allowed") == 1,
+ next_register_update: 0,
+ })
+ }
+ Some(mmc) => die(format!(
+ "unknown memory mapper kind '{mmc}' in the '--mmc' flag"
+ )),
+ None => die("you need to specify the 'kind' in the '--mmc' flag".to_string()),
+ }
+}
+
fn parse_arguments() -> Args {
let mut args = std::env::args();
let mut res = Args::default();
@@ -193,6 +233,10 @@ fn parse_arguments() -> Args {
"-f" | "--function" => {
res.assume_function = true;
}
+ "--mmc" => match args.next() {
+ Some(c) => res.mmc = Some(parse_mmc(&c)),
+ None => die("you need to specify a configuration for the '--mmc' flag".to_string()),
+ },
"-n" | "--nasm" => match args.next() {
Some(a) => {
let pb = PathBuf::from(a.clone());
@@ -318,6 +362,7 @@ fn run(file: &Path, start: u16, args: Args) -> Result<(), String> {
machine.halt_on_brk = args.halt_on_brk;
machine.cycle_limit = args.cycle_limit;
machine.addresses = addresses;
+ machine.mapper_chip = args.mmc;
machine.until_address(args.until_address)?;
@@ -344,6 +389,22 @@ fn run(file: &Path, start: u16, args: Args) -> Result<(), String> {
}
}
}
+ for (idx, cell) in machine.working_ram.iter().enumerate() {
+ if cell.reads > 0 || cell.writes > 0 {
+ if !title {
+ println!("\n== Memory dump ==\n");
+ title = true;
+ }
+
+ println!(
+ "[${:04X}] = ${:02X} [reads={}, writes={}]",
+ idx + 0x6000,
+ cell.value,
+ cell.reads,
+ cell.writes
+ );
+ }
+ }
}
Ok(())
diff --git a/lib/vnf/src/lib.rs b/lib/vnf/src/lib.rs
index de18452..b9a5fd2 100644
--- a/lib/vnf/src/lib.rs
+++ b/lib/vnf/src/lib.rs
@@ -300,6 +300,63 @@ impl Joypad {
}
}
+/// The banking mode for the MMC3 mapper chip (i.e. bit D6 on the 'Bank select'
+/// register).
+#[derive(Debug)]
+pub enum Mmc3BankMode {
+ FirstSwappable,
+ SecondSwappable,
+}
+
+/// All the needed info to run the 'Machine' with the MMC3 chip.
+#[derive(Debug)]
+pub struct Mmc3 {
+ pub prg_rom_mode: Mmc3BankMode,
+ pub next_register_update: usize,
+ pub r6: usize,
+ pub r7: usize,
+ pub prg_ram_enabled: bool,
+ pub prg_ram_writes_allowed: bool,
+}
+
+impl std::fmt::Display for Mmc3 {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ let mode = match self.prg_rom_mode {
+ Mmc3BankMode::FirstSwappable => 0,
+ Mmc3BankMode::SecondSwappable => 1,
+ };
+ let enabled = if self.prg_ram_enabled {
+ "enabled"
+ } else {
+ "disabled"
+ };
+ let allowed = if self.prg_ram_writes_allowed {
+ "allowed"
+ } else {
+ "disallowed"
+ };
+ write!(
+ f,
+ "[MMC3] PRG ROM mode: {}, R6: {}, R7: {}, PRG RAM {}, writes {}",
+ mode, self.r6, self.r7, enabled, allowed
+ )
+ }
+}
+
+/// Supported memory mapper chips.
+#[derive(Debug)]
+pub enum MemoryMapperChip {
+ Mmc3(Mmc3),
+}
+
+impl std::fmt::Display for MemoryMapperChip {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ match self {
+ MemoryMapperChip::Mmc3(mmc3) => write!(f, "{}", mmc3),
+ }
+ }
+}
+
/// The core structure for the virtual machine. Use this structure to read and
/// run a ROM file. At each step it will hold the current status of the machine
/// so it can be inspected programatically in full detail.
@@ -350,6 +407,10 @@ pub struct Machine {
/// read/write policies and statistics.
pub ram: Vec<MemoryCell>,
+ /// The Working RAM for this machine. You should either provide it yourself,
+ /// or let the flow of configuring a memory chip to handle it.
+ pub working_ram: Vec<MemoryCell>,
+
/// The 'a' register.
pub a: u8,
@@ -382,6 +443,12 @@ pub struct Machine {
/// detects a change on the PPU.
should_report_ppu: bool,
+ /// When 'verbose' is true, whether the memory mapper should also be
+ /// included into the output. This is enabled/disabled automatically
+ /// whenever the machine detects a change on one of the registers from the
+ /// memory mapper (if any).
+ should_report_mmc: bool,
+
/// The initial value for the stack register. Used to detect stack
/// under/over flows.
initial_stack_value: u8,
@@ -405,6 +472,14 @@ pub struct Machine {
/// bounds. This is used to detect overflows/underflows and any kind of bad
/// indexed access.
pub addresses: Vec<xixanta::assembler::Range>,
+
+ /// Memory mapper chip currently enabled for the Machine. If None, then an
+ /// NROM cartridge is assumed.
+ pub mapper_chip: Option<MemoryMapperChip>,
+
+ /// Chunks with which PRG ROM space is structured on a given memory mapper
+ /// chip.
+ chunks: Vec<[u8; 8192]>,
}
// On success, returns a vector of MemoryCell representing the RAM for a
@@ -511,17 +586,21 @@ impl Machine {
s: 0xFD, // NOTE: as per 6502 initialization process.
initial_stack_value: 0xFD,
ram: init_memory(&policy)?,
+ working_ram: vec![],
status_register: StatusRegister::default(),
apu: APU::default(),
ppu: PPU::default(),
verbose: false,
should_report_apu: false,
should_report_ppu: false,
+ should_report_mmc: false,
policy,
joypads: [Joypad::default(), Joypad::default()],
halt_on_brk: true,
cycle_limit: None,
addresses: vec![],
+ mapper_chip: None,
+ chunks: vec![],
})
}
@@ -604,6 +683,9 @@ impl Machine {
self.ppu.oam_dma,
);
self.should_report_ppu = false;
+ } else if self.should_report_mmc {
+ println!("\t\t{}\n", self.mapper_chip.as_ref().unwrap());
+ self.should_report_mmc = false;
}
if !self.active {
@@ -684,6 +766,74 @@ impl Machine {
Ok(())
}
+ // Translate the given 'address' to the proper location inside of
+ // 'self.prg_rom'. This will also take care of translating addresses
+ // depending on the current configuration of memory mappers.
+ //
+ // Returns three bytes, containing the byte for the actual translated
+ // address in ROM space, plus two consecutive bytes if possible (otherwise
+ // we zero-pad the returned byte). It's up to the caller to decide how many
+ // bytes are expected and if it makes sense to use them all or not.
+ fn translate_rom_address(&mut self, address: usize) -> Result<[u8; 3], String> {
+ assert!((0x8000..=0xFFFF).contains(&address));
+
+ let translated_address = match &mut self.mapper_chip {
+ Some(MemoryMapperChip::Mmc3(m)) => {
+ // If we haven't already, let's divide the PRG ROM space into
+ // 8KB chunks, which is how regions are mapped.
+ if self.chunks.is_empty() {
+ let (chunks, remainder) = self.prg_rom.as_chunks::<{ 8 * 1024 }>();
+ if !remainder.is_empty() {
+ return Err(
+ "malformed ROM file: PRG ROM size is not a multiple of 8KB".to_string()
+ );
+ }
+ self.chunks = chunks.to_vec();
+ }
+
+ // And now, depending on the address and the PRG ROM mapping
+ // mode, let's translate the address into an 'in_chunk_address',
+ // and then apply bank data value from the proper register.
+ match address {
+ 0x8000..0xA000 => {
+ let in_chunk_address = address - 0x8000;
+ match m.prg_rom_mode {
+ Mmc3BankMode::FirstSwappable => in_chunk_address + (m.r6 * 8192),
+ Mmc3BankMode::SecondSwappable => {
+ in_chunk_address + ((self.chunks.len() - 2) * 8192)
+ }
+ }
+ }
+ 0xA000..0xC000 => {
+ let in_chunk_address = address - 0xA000;
+ in_chunk_address + (m.r7 * 8192)
+ }
+ 0xC000..0xE000 => {
+ let in_chunk_address = address - 0xC000;
+ match m.prg_rom_mode {
+ Mmc3BankMode::FirstSwappable => {
+ in_chunk_address + ((self.chunks.len() - 2) * 8192)
+ }
+ Mmc3BankMode::SecondSwappable => in_chunk_address + (m.r6 * 8192),
+ }
+ }
+ _ => {
+ // The last bank is always fixed to the last 8KB region.
+ let in_chunk_address = address - 0xE000;
+ in_chunk_address + ((self.chunks.len() - 1) * 8192)
+ }
+ }
+ }
+ None => address - 0x8000,
+ };
+
+ Ok([
+ *self.prg_rom.get(translated_address).unwrap_or(&0),
+ *self.prg_rom.get(translated_address + 1).unwrap_or(&0),
+ *self.prg_rom.get(translated_address + 2).unwrap_or(&0),
+ ])
+ }
+
/// Step the execution of the machine by one instruction. It will return an
/// error if the execution fails for whatever reason, but also if this
/// machine is no longer active. Hence, if the machine has been deactivated
@@ -740,15 +890,16 @@ impl Machine {
return Err("out of bounds: program counter is pointing below ROM space".to_string());
}
- // Fetch the next instruction.
- let address = self.pc - 0x8000;
- let opcode = self.prg_rom.get(address).unwrap();
- self.current_instruction = match OPCODES.get(opcode) {
+ // Fetch the next instruction. Picking from the current PC, the opcode
+ // will be the first byte, and the tentative arguments will be placed
+ // afterwards.
+ let bytes = self.translate_rom_address(self.pc)?;
+ self.current_instruction = match OPCODES.get(&bytes[0]) {
Some(instr) => instr.clone(),
None => {
return Err(format!(
"could not find instruction with opcode <{:02X}>",
- opcode
+ bytes[0]
));
}
};
@@ -756,12 +907,12 @@ impl Machine {
// Fetch the bytes for the current instruction.
match self.current_instruction.size {
2 => {
- self.current_instruction.bytes[0] = *self.prg_rom.get(address + 1).unwrap();
+ self.current_instruction.bytes[0] = bytes[1];
self.current_instruction.bytes[1] = 0;
}
3 => {
- self.current_instruction.bytes[0] = *self.prg_rom.get(address + 1).unwrap();
- self.current_instruction.bytes[1] = *self.prg_rom.get(address + 2).unwrap();
+ self.current_instruction.bytes[0] = bytes[1];
+ self.current_instruction.bytes[1] = bytes[2];
}
_ => {
self.current_instruction.bytes = [0, 0];
@@ -790,7 +941,22 @@ impl Machine {
// if you want this read to be accounted on the statistics of reads of the
// given address, false otherwise.
fn read_memory(&mut self, address: u16, account_read: bool) -> Result<u8, String> {
- let cell = self.ram.get_mut(address as usize).unwrap();
+ // Get the memory cell from the given address. Whether this is working
+ // RAM or normal RAM is decided based on the actual address.
+ let cell = if (0x6000..0x8000).contains(&address) {
+ if self.working_ram.is_empty() {
+ return Err(format!(
+ "reading was not allowed on address '${:04X}'",
+ address
+ ));
+ }
+ self.working_ram.get_mut(address as usize - 0x6000).unwrap()
+ } else {
+ // NOTE: 0x0800 until 0x2000 are simply mirrors of the first
+ // 2KB. Let's mask out the upper bits.
+ let real = address & 0x07FF;
+ self.ram.get_mut(real as usize).unwrap()
+ };
if !cell.read_allowed {
return Err(format!(
@@ -807,7 +973,22 @@ impl Machine {
// Perform a write to the given memory 'address' with the given 'value'.
fn write_memory(&mut self, address: u16, value: u8) -> Result<(), String> {
- let cell = self.ram.get_mut(address as usize).unwrap();
+ // Get the memory cell from the given address. Whether this is working
+ // RAM or normal RAM is decided based on the actual address.
+ let cell = if (0x6000..0x8000).contains(&address) {
+ if self.working_ram.is_empty() {
+ return Err(format!(
+ "writing was not allowed on address '${:04X}'",
+ address
+ ));
+ }
+ self.working_ram.get_mut(address as usize - 0x6000).unwrap()
+ } else {
+ // NOTE: 0x0800 until 0x2000 are simply mirrors of the first
+ // 2KB. Let's mask out the upper bits.
+ let real = address & 0x07FF;
+ self.ram.get_mut(real as usize).unwrap()
+ };
if !cell.write_allowed {
return Err(format!(
@@ -1395,6 +1576,7 @@ impl Machine {
let address = self.target_address()?;
match address {
+ 0x00..0x2000 => self.read_memory(address as u16, true)?,
0x2000 => self.ppu.control,
0x2001 => self.ppu.mask,
0x2002 => {
@@ -1409,21 +1591,13 @@ impl Machine {
0x2007 => self.ppu.data,
0x4010 => self.apu.dmc,
0x4014 => self.ppu.oam_dma, // TODO: maybe read fault
- 0x00..0x2000 => {
- // NOTE: 0x0800 until 0x2000 are simply mirrors of the first
- // 2KB. Let's mask out the upper bits.
- let real = address & 0x07FF;
- self.read_memory(real as u16, true)?
- }
- 0x8000..=0xFFFF => {
- let real = address - 0x8000;
- *self.prg_rom.get(real).unwrap()
- }
0x4016 => self.joypad_read(0)?,
// NOTE: the joypad 2 and the APU frame counter share the same
// address, but read is only reserved for joypad 2.
0x4017 => self.joypad_read(1)?,
- _ => todo!(),
+ 0x6000..0x8000 => self.read_memory(address as u16, true)?,
+ 0x8000..=0xFFFF => self.translate_rom_address(address)?[0],
+ _ => return Err(format!("unallowed read at address ${:04X}", address)),
}
};
@@ -1511,6 +1685,9 @@ impl Machine {
let address = self.target_address()?;
match address {
+ 0x00..0x2000 => {
+ self.write_memory(address as u16, value)?;
+ }
0x2000 => {
self.ppu.control = value;
self.should_report_ppu = self.verbose;
@@ -1557,18 +1734,99 @@ impl Machine {
self.joypad_write(1, value)?;
}
- 0x00..0x2000 => {
- // NOTE: 0x0800 until 0x2000 are simply mirrors of the first
- // 2KB. Let's mask out the upper bits.
- let real = address & 0x07FF;
- self.write_memory(real as u16, value)?;
+ 0x6000..0x8000 => self.write_memory(address as u16, value)?,
+ _ => match &mut self.mapper_chip {
+ Some(MemoryMapperChip::Mmc3(_)) => self.handle_mmc3_store(address as u16, value)?,
+ None => return Err(format!("unallowed write to address ${:04X}", address)),
+ },
+ };
+
+ Ok(())
+ }
+
+ // Handle a store operation onto one if the registers from the MMC3 chip.
+ fn handle_mmc3_store(&mut self, address: u16, value: u8) -> Result<(), String> {
+ // The MMC3 has a total of eight registers. These registers are selected
+ // from bits 0, 13 and 14 of the address. Another way to express it is
+ // that they are selected based on bits 13 and 14 on even vs odd ranges
+ // from the address (i.e. this is how it's described on the NESDev
+ // wiki).
+ let select = address & 0x6001;
+ let MemoryMapperChip::Mmc3(chip) = self.mapper_chip.as_mut().unwrap();
+
+ match select {
+ 0x0000 => {
+ chip.next_register_update = (value & 0x07) as usize;
+
+ if (value & 0x40) == 0x00 {
+ chip.prg_rom_mode = Mmc3BankMode::FirstSwappable;
+ } else {
+ chip.prg_rom_mode = Mmc3BankMode::SecondSwappable;
+ }
+ }
+ 0x0001 => {
+ if chip.next_register_update == 6 {
+ chip.r6 = value as usize;
+ } else if chip.next_register_update == 7 {
+ chip.r7 = value as usize;
+ }
+ // NOTE: other registers are ignored.
+ }
+ 0x2000 => {
+ // NOTE: nametable arrangement. Since this is a headless
+ // emulator, this is blatantly ignored.
+ }
+ 0x2001 => {
+ let before = chip.prg_ram_writes_allowed;
+
+ chip.prg_ram_enabled = (value & 0x80) == 0x80;
+ chip.prg_ram_writes_allowed = (value & 0x40) == 0x00;
+
+ if chip.prg_ram_enabled {
+ // Initialize the working RAM if it's empty. Otherwise, if
+ // it's not empty, check if we need to update the write
+ // permission.
+ if self.working_ram.is_empty() {
+ let cell = MemoryCell {
+ value: match self.policy.initial_value {
+ MemoryInitialValue::Fixed(n) => n,
+ MemoryInitialValue::Random => rand::random(),
+ },
+ write_allowed: chip.prg_ram_writes_allowed,
+ read_allowed: true,
+ reads: 0,
+ writes: 0,
+ };
+ self.working_ram = vec![cell; 0x2000];
+ } else if before != chip.prg_ram_writes_allowed {
+ for i in 0..0x2000 {
+ self.working_ram[i].write_allowed = chip.prg_ram_writes_allowed;
+ }
+ }
+ } else {
+ self.working_ram = vec![];
+ }
+ }
+ 0x4000 => {
+ // NOTE: IRQ handling is not supported for now.
+ }
+ 0x4001 => {
+ // NOTE: IRQ handling is not supported for now.
+ }
+ 0x6000 => {
+ // NOTE: IRQ handling is not supported for now.
+ }
+ 0x6001 => {
+ // NOTE: IRQ handling is not supported for now.
}
_ => {
- self.report();
- todo!()
+ return Err(format!(
+ "bad address write for the MMC3 chip (${:04X})",
+ address
+ ));
}
- };
-
+ }
+ self.should_report_mmc = true;
Ok(())
}
}
diff --git a/scripts/test-e2e.sh b/scripts/test-e2e.sh
index 17766a4..99dc27d 100755
--- a/scripts/test-e2e.sh
+++ b/scripts/test-e2e.sh
@@ -370,6 +370,21 @@ exit_code=$((exit_code + $?))
diff tests/out/overflow-data-indexing.txt tests/expected/runrom/overflow-data-indexing.txt
exit_code=$((exit_code + $?))
+echo "test: runrom => mmc3/basic.nes"
+./target/debug/nasm -Werror --asan --write-info -c tests/runrom/mmc3/mmc3.cfg -o tests/out/mmc3.nes -w tests/runrom/mmc3/basic.s
+
+./target/debug/runrom --nasm .nasm/ --dump-memory --function --start basic --mmc "kind=mmc3; prg_rom_mode=0; prg_ram_enabled=1; prg_ram_writes_allowed=1; r6=0; r7=1" tests/out/mmc3.nes &> tests/out/mmc3-basic.txt
+diff tests/out/mmc3-basic.txt tests/expected/runrom/mmc3-basic.txt
+exit_code=$((exit_code + $?))
+
+./target/debug/runrom --nasm .nasm/ --dump-memory --function --start no_writes_allowed --mmc "kind=mmc3; prg_rom_mode=0; prg_ram_enabled=1; prg_ram_writes_allowed=1; r6=0; r7=1" tests/out/mmc3.nes &> tests/out/mmc3-no-writes.txt
+diff tests/out/mmc3-no-writes.txt tests/expected/runrom/mmc3-no-writes.txt
+exit_code=$((exit_code + $?))
+
+./target/debug/runrom --nasm .nasm/ --dump-memory --function --start no_wram --mmc "kind=mmc3; prg_rom_mode=0; prg_ram_enabled=1; prg_ram_writes_allowed=1; r6=0; r7=1" tests/out/mmc3.nes &> tests/out/mmc3-no-wram.txt
+diff tests/out/mmc3-no-wram.txt tests/expected/runrom/mmc3-no-wram.txt
+exit_code=$((exit_code + $?))
+
##
# vnf-tests
diff --git a/tests/expected/runrom/mmc3-basic.txt b/tests/expected/runrom/mmc3-basic.txt
new file mode 100644
index 0000000..886f97a
--- /dev/null
+++ b/tests/expected/runrom/mmc3-basic.txt
@@ -0,0 +1,94 @@
+<start> PC: $E045, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I--
+ [STACK]: 47 E0 00 00
+jsr $E000 PC: $E000, cycles: 13, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----I--
+bit $2002 PC: $E003, cycles: 17, registers: [a: $00, x: $00, y: $00, sp: $FB], status: N---IZ-
+lda #$00 PC: $E005, cycles: 19, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $2006 PC: $E008, cycles: 23, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E00B, cycles: 27, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$10 PC: $E00D, cycles: 29, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+sta $2006 PC: $E010, cycles: 33, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E013, cycles: 37, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$00 PC: $E015, cycles: 39, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $2006 PC: $E018, cycles: 43, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E01B, cycles: 47, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$10 PC: $E01D, cycles: 49, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+sta $2006 PC: $E020, cycles: 53, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E023, cycles: 57, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$00 PC: $E025, cycles: 59, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $A000 PC: $E028, cycles: 63, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+sta $E000 PC: $E02B, cycles: 67, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$80 PC: $E02D, cycles: 69, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I--
+sta $A001 PC: $E030, cycles: 73, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$06 PC: $E032, cycles: 75, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I--
+sta $8000 PC: $E035, cycles: 79, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$00 PC: $E037, cycles: 81, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $8001 PC: $E03A, cycles: 85, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$07 PC: $E03C, cycles: 87, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I--
+sta $8000 PC: $E03F, cycles: 91, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$01 PC: $E041, cycles: 93, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+sta $8001 PC: $E044, cycles: 97, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+ [STACK]: 00 00
+rts PC: $E048, cycles: 103, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I--
+ [STACK]: 4A E0 00 00
+jsr $8000 PC: $8000, cycles: 109, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+clc PC: $8001, cycles: 111, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+adc $6000 PC: $8004, cycles: 115, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+sta $6000 PC: $8007, cycles: 119, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+ [STACK]: 00 00
+rts PC: $E04B, cycles: 125, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I--
+lda #$06 PC: $E04D, cycles: 127, registers: [a: $06, x: $00, y: $00, sp: $FD], status: ----I--
+sta $8000 PC: $E050, cycles: 131, registers: [a: $06, x: $00, y: $00, sp: $FD], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$01 PC: $E052, cycles: 133, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I--
+sta $8001 PC: $E055, cycles: 137, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 1, R7: 1, PRG RAM enabled, writes allowed
+
+ [STACK]: 57 E0 00 00
+jsr $8000 PC: $8000, cycles: 143, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+inc $6000 PC: $8003, cycles: 149, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+ [STACK]: 00 00
+rts PC: $E058, cycles: 155, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I--
+ [STACK]: 5A E0 00 00
+jsr $8000 PC: $8000, cycles: 161, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+inc $6000 PC: $8003, cycles: 167, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+ [STACK]: 00 00
+rts PC: $E05B, cycles: 173, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I--
+rts PC: $E05C, cycles: 179, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I--
+<end>
+
+== Memory dump ==
+
+[$02FC] = $5A [reads=4, writes=4]
+[$02FD] = $E0 [reads=4, writes=4]
+[$6000] = $03 [reads=3, writes=3]
diff --git a/tests/expected/runrom/mmc3-no-wram.txt b/tests/expected/runrom/mmc3-no-wram.txt
new file mode 100644
index 0000000..fd4977e
--- /dev/null
+++ b/tests/expected/runrom/mmc3-no-wram.txt
@@ -0,0 +1,71 @@
+<start> PC: $E067, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I--
+ [STACK]: 69 E0 00 00
+jsr $E000 PC: $E000, cycles: 13, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----I--
+bit $2002 PC: $E003, cycles: 17, registers: [a: $00, x: $00, y: $00, sp: $FB], status: N---IZ-
+lda #$00 PC: $E005, cycles: 19, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $2006 PC: $E008, cycles: 23, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E00B, cycles: 27, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$10 PC: $E00D, cycles: 29, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+sta $2006 PC: $E010, cycles: 33, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E013, cycles: 37, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$00 PC: $E015, cycles: 39, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $2006 PC: $E018, cycles: 43, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E01B, cycles: 47, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$10 PC: $E01D, cycles: 49, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+sta $2006 PC: $E020, cycles: 53, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E023, cycles: 57, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$00 PC: $E025, cycles: 59, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $A000 PC: $E028, cycles: 63, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+sta $E000 PC: $E02B, cycles: 67, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$80 PC: $E02D, cycles: 69, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I--
+sta $A001 PC: $E030, cycles: 73, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$06 PC: $E032, cycles: 75, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I--
+sta $8000 PC: $E035, cycles: 79, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$00 PC: $E037, cycles: 81, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $8001 PC: $E03A, cycles: 85, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$07 PC: $E03C, cycles: 87, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I--
+sta $8000 PC: $E03F, cycles: 91, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$01 PC: $E041, cycles: 93, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+sta $8001 PC: $E044, cycles: 97, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+ [STACK]: 00 00
+rts PC: $E06A, cycles: 103, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I--
+lda #$00 PC: $E06C, cycles: 105, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ-
+sta $A001 PC: $E06F, cycles: 109, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM disabled, writes allowed
+
+jmp $8000 PC: $8000, cycles: 112, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ-
+clc PC: $8001, cycles: 114, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ-
+
+@:
+adc $6000 PC: $8001, cycles: 114, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ-
+error: reading was not allowed on address '$6000'
diff --git a/tests/expected/runrom/mmc3-no-writes.txt b/tests/expected/runrom/mmc3-no-writes.txt
new file mode 100644
index 0000000..1dcb644
--- /dev/null
+++ b/tests/expected/runrom/mmc3-no-writes.txt
@@ -0,0 +1,72 @@
+<start> PC: $E05C, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I--
+ [STACK]: 5E E0 00 00
+jsr $E000 PC: $E000, cycles: 13, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----I--
+bit $2002 PC: $E003, cycles: 17, registers: [a: $00, x: $00, y: $00, sp: $FB], status: N---IZ-
+lda #$00 PC: $E005, cycles: 19, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $2006 PC: $E008, cycles: 23, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E00B, cycles: 27, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$10 PC: $E00D, cycles: 29, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+sta $2006 PC: $E010, cycles: 33, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E013, cycles: 37, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$00 PC: $E015, cycles: 39, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $2006 PC: $E018, cycles: 43, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E01B, cycles: 47, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $00, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$10 PC: $E01D, cycles: 49, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+sta $2006 PC: $E020, cycles: 53, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+sta $2006 PC: $E023, cycles: 57, registers: [a: $10, x: $00, y: $00, sp: $FB], status: ----I--
+ [PPU] Control: $00, Mask: $00, Status: $80, Scroll: $00, Address: $10, Data: $00, OAM addr: $00, OAM DMA: $00
+
+lda #$00 PC: $E025, cycles: 59, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $A000 PC: $E028, cycles: 63, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+sta $E000 PC: $E02B, cycles: 67, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$80 PC: $E02D, cycles: 69, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I--
+sta $A001 PC: $E030, cycles: 73, registers: [a: $80, x: $00, y: $00, sp: $FB], status: N---I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$06 PC: $E032, cycles: 75, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I--
+sta $8000 PC: $E035, cycles: 79, registers: [a: $06, x: $00, y: $00, sp: $FB], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$00 PC: $E037, cycles: 81, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+sta $8001 PC: $E03A, cycles: 85, registers: [a: $00, x: $00, y: $00, sp: $FB], status: ----IZ-
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$07 PC: $E03C, cycles: 87, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I--
+sta $8000 PC: $E03F, cycles: 91, registers: [a: $07, x: $00, y: $00, sp: $FB], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+lda #$01 PC: $E041, cycles: 93, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+sta $8001 PC: $E044, cycles: 97, registers: [a: $01, x: $00, y: $00, sp: $FB], status: ----I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes allowed
+
+ [STACK]: 00 00
+rts PC: $E05F, cycles: 103, registers: [a: $01, x: $00, y: $00, sp: $FD], status: ----I--
+lda #$C0 PC: $E061, cycles: 105, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I--
+sta $A001 PC: $E064, cycles: 109, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I--
+ [MMC3] PRG ROM mode: 0, R6: 0, R7: 1, PRG RAM enabled, writes disallowed
+
+jmp $8000 PC: $8000, cycles: 112, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I--
+clc PC: $8001, cycles: 114, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I--
+adc $6000 PC: $8004, cycles: 118, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I--
+
+@:
+sta $6000 PC: $8004, cycles: 118, registers: [a: $C0, x: $00, y: $00, sp: $FD], status: N---I--
+error: writing was not allowed on address '$6000'
diff --git a/tests/runrom/mmc3/basic.s b/tests/runrom/mmc3/basic.s
new file mode 100644
index 0000000..f97fe3f
--- /dev/null
+++ b/tests/runrom/mmc3/basic.s
@@ -0,0 +1,241 @@
+.segment "HEADER"
+ .byte 'N', 'E', 'S', $1A
+ .byte $10, $10
+ .byte $43
+ .byte $08
+ .byte $00
+ .byte $00
+ .byte $70
+ .res $05, $00
+
+.segment "TAIL"
+;;; asan:stack full
+
+;;; TODO: into another segment, writing to WRAM clc; adc wr_whatever; sta wr_whatever; this is then called via different segments
+
+.scope PPU
+ m_status = $2002
+ m_address = $2006
+.endscope
+
+.scope MMC3
+ m_bank_select = $8000
+ m_bank_data = $8001
+ m_mirroring = $A000
+ m_ram_protect = $A001
+ m_irq_disable = $E000
+.endscope
+
+.macro BANK_REGISTER_SET REGISTER_ID, REGISTER_VALUE
+ lda #REGISTER_ID
+ sta MMC3::m_bank_select
+ lda #REGISTER_VALUE
+ sta MMC3::m_bank_data
+.endmacro
+
+.proc regular_mmc3_init
+ ;; Init scanline counter.
+ bit PPU::m_status
+
+ lda #$00
+ sta PPU::m_address
+ sta PPU::m_address
+ lda #$10
+ sta PPU::m_address
+ sta PPU::m_address
+
+ lda #$00
+ sta PPU::m_address
+ sta PPU::m_address
+ lda #$10
+ sta PPU::m_address
+ sta PPU::m_address
+
+ ;; Setup mirroring.
+ lda #$00
+ sta MMC3::m_mirroring
+
+ ;; Disable interrupts.
+ sta MMC3::m_irq_disable
+
+ ;; Enable PRG RAM and allow writes to it.
+ lda #$80
+ sta MMC3::m_ram_protect
+
+ ;; PRG banking setup.
+ BANK_REGISTER_SET 6, 0
+ BANK_REGISTER_SET 7, 1
+
+ rts
+.endproc
+
+.proc basic
+ jsr regular_mmc3_init
+
+ jsr foo ; asan:safe
+
+ BANK_REGISTER_SET 6, 1
+
+ ;; NOTE: this is actually not safe, as it will call another_foo() instead :)
+ jsr foo ; asan:safe
+
+ ;; NOTE: calling a different address but it's the same function as per the
+ ;; previous mapping :)
+ jsr another_foo ; asan:safe
+
+ rts
+.endproc
+
+.proc no_writes_allowed
+ jsr regular_mmc3_init
+
+ lda #$C0
+ sta MMC3::m_ram_protect
+
+ jmp foo ; asan:safe
+.endproc
+
+.proc no_wram
+ jsr regular_mmc3_init
+
+ lda #$00
+ sta MMC3::m_ram_protect
+
+ jmp foo ; asan:safe
+.endproc
+
+.proc reset
+ ;; NOTE: avoid warnings from unused functions.
+ jsr basic
+ jsr no_writes_allowed
+ jsr no_wram
+
+ rts
+.endproc
+
+.proc nmi
+ rti
+.endproc
+
+.proc irq
+ rti
+.endproc
+
+.segment "PRG0_00"
+
+wr_value = $6000
+
+.proc foo
+ clc
+ adc wr_value
+ sta wr_value
+ rts
+.endproc
+
+.segment "PRG0_01"
+
+.proc another_foo
+ inc wr_value
+ rts
+.endproc
+
+.segment "CHARS"
+.res $F000, $00
+.res $F000, $00
+.res $2000, $00
+
+.segment "VECTORS"
+ .addr nmi, reset, irq
+
+.segment "PRG0_00"
+.byte $00
+
+.segment "PRG0_01"
+.byte $00
+
+.segment "PRG0_02"
+.byte $00
+
+.segment "PRG0_03"
+.byte $00
+
+.segment "PRG0_04"
+.byte $00
+
+.segment "PRG0_05"
+.byte $00
+
+.segment "PRG0_06"
+.byte $00
+
+.segment "PRG0_07"
+.byte $00
+
+.segment "PRG0_08"
+.byte $00
+
+.segment "PRG0_09"
+.byte $00
+
+.segment "PRG0_0A"
+.byte $00
+
+.segment "PRG0_0B"
+.byte $00
+
+.segment "PRG0_0C"
+.byte $00
+
+.segment "PRG0_0D"
+.byte $00
+
+.segment "PRG0_0E"
+.byte $00
+
+.segment "PRG1_00"
+.byte $00
+
+.segment "PRG1_01"
+.byte $00
+
+.segment "PRG1_02"
+.byte $00
+
+.segment "PRG1_03"
+.byte $00
+
+.segment "PRG1_04"
+.byte $00
+
+.segment "PRG1_05"
+.byte $00
+
+.segment "PRG1_06"
+.byte $00
+
+.segment "PRG1_07"
+.byte $00
+
+.segment "PRG1_08"
+.byte $00
+
+.segment "PRG1_09"
+.byte $00
+
+.segment "PRG1_0A"
+.byte $00
+
+.segment "PRG1_0B"
+.byte $00
+
+.segment "PRG1_0C"
+.byte $00
+
+.segment "PRG1_0D"
+.byte $00
+
+.segment "PRG1_0E"
+.byte $00
+
+.segment "FIXED"
+.byte $00
diff --git a/tests/runrom/mmc3/mmc3.cfg b/tests/runrom/mmc3/mmc3.cfg
new file mode 100644
index 0000000..56f6314
--- /dev/null
+++ b/tests/runrom/mmc3/mmc3.cfg
@@ -0,0 +1,92 @@
+MEMORY {
+ # iNES header
+ HEADER: file = %O, start = $0000, size = $0010, fill = yes;
+
+ # First 15 switchable banks at $8000.
+ PRG0_00: start = $8000, size = $2000, file = %O, fill = yes, fillval = $00;
+ PRG0_01: start = $8000, size = $2000, file = %O, fill = yes, fillval = $01;
+ PRG0_02: start = $8000, size = $2000, file = %O, fill = yes, fillval = $02;
+ PRG0_03: start = $8000, size = $2000, file = %O, fill = yes, fillval = $03;
+ PRG0_04: start = $8000, size = $2000, file = %O, fill = yes, fillval = $04;
+ PRG0_05: start = $8000, size = $2000, file = %O, fill = yes, fillval = $05;
+ PRG0_06: start = $8000, size = $2000, file = %O, fill = yes, fillval = $06;
+ PRG0_07: start = $8000, size = $2000, file = %O, fill = yes, fillval = $07;
+ PRG0_08: start = $8000, size = $2000, file = %O, fill = yes, fillval = $08;
+ PRG0_09: start = $8000, size = $2000, file = %O, fill = yes, fillval = $09;
+ PRG0_0A: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0A;
+ PRG0_0B: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0B;
+ PRG0_0C: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0C;
+ PRG0_0D: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0D;
+ PRG0_0E: start = $8000, size = $2000, file = %O, fill = yes, fillval = $0E;
+
+ # Last 15 switchable banks at $A000.
+ PRG1_00: start = $A000, size = $2000, file = %O, fill = yes, fillval = $10;
+ PRG1_01: start = $A000, size = $2000, file = %O, fill = yes, fillval = $11;
+ PRG1_02: start = $A000, size = $2000, file = %O, fill = yes, fillval = $12;
+ PRG1_03: start = $A000, size = $2000, file = %O, fill = yes, fillval = $13;
+ PRG1_04: start = $A000, size = $2000, file = %O, fill = yes, fillval = $14;
+ PRG1_05: start = $A000, size = $2000, file = %O, fill = yes, fillval = $15;
+ PRG1_06: start = $A000, size = $2000, file = %O, fill = yes, fillval = $16;
+ PRG1_07: start = $A000, size = $2000, file = %O, fill = yes, fillval = $17;
+ PRG1_08: start = $A000, size = $2000, file = %O, fill = yes, fillval = $18;
+ PRG1_09: start = $A000, size = $2000, file = %O, fill = yes, fillval = $19;
+ PRG1_0A: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1A;
+ PRG1_0B: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1B;
+ PRG1_0C: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1C;
+ PRG1_0D: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1D;
+ PRG1_0E: start = $A000, size = $2000, file = %O, fill = yes, fillval = $1E;
+
+ # Last two fixed banks + vectors.
+ FIXED: start = $C000, size = $2000, fill = yes, fillval = $FA, define = yes;
+ TAIL: start = $E000, size = $1FFA, fill = yes, fillval = $FB, define = yes;
+ ROMV: start = $FFFA, size = $0006, fill = yes, fillval = $FC, define = yes;
+
+ # CHR ROM.
+ CHARS: start = $0000, size = $20000, file = %O, fill = no;
+}
+
+SEGMENTS {
+ HEADER: load = HEADER, type = ro;
+
+ # 15 first switchable banks.
+ PRG0_00: load = PRG0_00, type = ro;
+ PRG0_01: load = PRG0_01, type = ro;
+ PRG0_02: load = PRG0_02, type = ro;
+ PRG0_03: load = PRG0_03, type = ro;
+ PRG0_04: load = PRG0_04, type = ro;
+ PRG0_05: load = PRG0_05, type = ro;
+ PRG0_06: load = PRG0_06, type = ro;
+ PRG0_07: load = PRG0_07, type = ro;
+ PRG0_08: load = PRG0_08, type = ro;
+ PRG0_09: load = PRG0_09, type = ro;
+ PRG0_0A: load = PRG0_0A, type = ro;
+ PRG0_0B: load = PRG0_0B, type = ro;
+ PRG0_0C: load = PRG0_0C, type = ro;
+ PRG0_0D: load = PRG0_0D, type = ro;
+ PRG0_0E: load = PRG0_0E, type = ro;
+
+ # 15 last switchable banks.
+ PRG1_00: load = PRG1_00, type = ro;
+ PRG1_01: load = PRG1_01, type = ro;
+ PRG1_02: load = PRG1_02, type = ro;
+ PRG1_03: load = PRG1_03, type = ro;
+ PRG1_04: load = PRG1_04, type = ro;
+ PRG1_05: load = PRG1_05, type = ro;
+ PRG1_06: load = PRG1_06, type = ro;
+ PRG1_07: load = PRG1_07, type = ro;
+ PRG1_08: load = PRG1_08, type = ro;
+ PRG1_09: load = PRG1_09, type = ro;
+ PRG1_0A: load = PRG1_0A, type = ro;
+ PRG1_0B: load = PRG1_0B, type = ro;
+ PRG1_0C: load = PRG1_0C, type = ro;
+ PRG1_0D: load = PRG1_0D, type = ro;
+ PRG1_0E: load = PRG1_0E, type = ro;
+
+ # Last two fixed banks + vectors.
+ FIXED: load = FIXED, type = ro;
+ TAIL: load = TAIL, type = ro;
+ VECTORS: load = ROMV, type = ro;
+
+ # CHR-ROM is groupped all together.
+ CHARS: load = CHARS, type = ro;
+}