These two behaviours matter to anyone writing a mapper or an emulator, and several rows on iNES: mappers and on the submappers page refer to them.
Bus conflicts
A bus conflict is two logic devices driving different values onto the same bus line. When two signals are at the same voltage, the one with lower impedance generally wins. On the NES this usually happens when a program writes to a mapper whose registers overlap ROM, and the ROM does not turn its output off, so the CPU and the ROM both drive the PRG data bus. Most ASIC mappers disable the ROM output during writes (putting it in high impedance), so there is no conflict. Many mappers, especially discrete logic ones, do not. The list of such mappers is the wiki’s “Mappers with bus conflicts” category; on this site the row of each mapper says it, and the NES 2.0 submappers distinguish the variants with and without.
Programming around them
Make every device on the bus drive the same value: write to a ROM location that already holds the value you are writing. To switch to bank 5 on UNROM or UOROM, write 5 to a ROM byte that is 5. Two common ways from the wiki:
; load an immediate value and store it over the operand
@loadInstruction:
ldy #5
sty @loadInstruction+1
; a table of bank numbers, indexed
lda curMapBank
tax
sta bankBytes,x
; ...
bankBytes:
.byt $00, $01, $02, $03, $04, $05, $06, $07
Emulating them
- Many emulators wrongly assumed the CPU “wins” every conflict. Quite a few early iNES programs were written without knowing of bus conflicts, and fail on real hardware. They can run if ROM-disabling circuitry like ANROM’s, or the positive chip enable of the AOROM ROM chips, is added. NES 2.0 submappers can say that such a program must run without bus conflicts.
- Classes of iNES files that often contain conflict bugs: old homebrew (old documents did not mention conflicts); mapper hacks (early RAM cartridges such as those by Front Fareast run mapper 2 and 3 without conflicts; several games on the FFE CD are ports of MMC1 games to this mapper 2 variant, which GoodNES lists as
[hM02]; early English translations of Final Fantasy II ran on it too); and buggy games, homebrew or hacks (wrong tables, or a jump that lands outside code). - Tests show that both the CPU and the mask ROMs of the era drive a 0 more strongly than a 1. The Sunsoft UNROM games Shanghai II and Pescatore exploit this by writing the bank register at
$C000where the ROM holds$07. An emulator should therefore use the bitwise AND of the CPU value and the ROM value. Programmers must not rely on this undefined behaviour. Logging a warning when a conflict happens helps to find bugs.
Open bus
When the CPU reads an address that no device decodes, the result is open bus. The value is officially undefined but predictable on specific hardware. Clones and flash cartridges (PowerPak, Everdrive) can differ from a standard NES. It commonly affects the controller ports $4016 and $4017, game bugs that read $4020–$7FFF where nothing is mapped, and CNROM-variant games (iNES 185) that unmap CHR to test PPU open bus as copy protection.
CPU open bus
On a standard NES a read of open bus repeats the last value that was on the bus. The cases:
- Absolute addressing: the last byte read is the high byte of the address (the last byte of the operand).
- Indexed addressing: the high byte of the base address from the operand; the index does not apply yet.
- Indirect addressing: the high byte of the pointer is fetched last; the Y index does not apply yet.
- A DMC DMA that interrupts an instruction can change the last value read.
- Open bus can cover only part of a byte. The controller ports
$4016and$4017drive bits 4 to 0 only; bits 7 to 5 repeat the previous read, usually010from the high byte$40.
Few commercial games rely on it, and where they do it is usually a programming mistake. A few read $6000–$7FFF with no WRAM present. That is a problem for emulators because the original iNES format could not say “no WRAM”, so an emulator supplied WRAM by default; the NES 2.0 format has a WRAM size field. Some cartridges have a weak, non-deterministic effect on open bus reads: it looks like an OR, forcing bits (especially D7) to 1, and is more frequent near the end of a 256-byte page.
Example: LDA ($04),Y with $05,$04 = $73FA and Y = $31
The target is $73FA + $31 = $742B.
| Cycle | Operation | Address read | Value read |
|---|---|---|---|
| 1 | read opcode | PC | $B1 |
| 2 | read operand | PC | $04 |
| 3 | read low byte of pointer | $0004 | $FA |
| 4 | read high byte of pointer | $0005 | $73 |
| 5 | read indirect value before carry correction | $732B | $73 (open bus) |
| 6 | read carry-corrected value | $742B | $73 (open bus) |
Both open-bus reads return the last value on the bus, the pointer’s high byte, although their addresses depend on Y.
Games affected
- Low G Man: WRAM instead of open bus may crash in chapter 1 scene 3B, a few seconds into the boss fight music, or glitch graphics with the boomerang.
- Battletoads & Double Dragon: at the end of the first level it reads values from about
$600Xwhen Abobo has destroyed the wall; reading$00there crashes the game. - Captain Planet, Dirty Harry, Infiltrator, Mad Max, Paperboy, The Last Starfighter (Mindscape): rely on the controller port reading exactly
$41for a button press. - Castlevania: after the introduction reads a few values from about
$7FFXbefore the first stage. Harmless.
PPU open bus
The PPU has two data buses with different open bus rules: the I/O bus, used to talk to the CPU, and the video memory bus.
- A write to any PPU port, even the read-only
$2002, puts the value on the I/O bus. - A read of
$2004or$2007puts a byte from OAM, video memory or palette on it. - A read of the status port
$2002loads bits 7 to 5 of the bus and leaves the rest as they were. - A read of any PPU port, including the write-only
$2000,$2001,$2003,$2005,$2006, returns the value of the I/O bus. - On the video memory bus, the data lines are shared with the low byte of the address (pins 31 to 38), so reading an address with no memory usually returns the low byte of the address. A few games with a CNROM configuration use it as copy protection.
The electrical reason
A data bus behaves as a dynamic latch: once each line is driven low or high, the capacitance of the long traces lets it float at that level to be read again. Each memory or I/O circuit has enable pins; its three-state outputs stay in high impedance until all enables are right (a 6264 RAM needs /CE1 low, CE2 high and /OE low). A decoder makes the enables from address signals. In the console the 74LS139 decoder (U3 on the Famicom schematic) decodes the cartridge ROM at $8000–$FFFF, the work RAM at $0000–$1FFF and PPU I/O at $2000–$3FFF from M2 and CPU A15–A13. The CPU itself decodes reads of $4015 and $4016–$4017. Nothing decodes reads of $4000–$4014 or $4018–$7FFF; cartridges with WRAM at $6000–$7FFF add their own decoder, alone or in a mapper. With no decoder, the CPU sees whatever was left floating on the bus.
Sources
The NESdev Wiki text is available under CC BY-SA 3.0. This page is written in our own words from the raw wikitext kept in samples/nes/sources/hardware. Not covered: the wiki’s lists of mappers with and without bus conflicts (they are on each mapper’s row), and its forum references.