emuforge

Cartridges

A cartridge has the game's ROM, and often a chip for saves. The ROM, SRAM and FlashRAM are on the parallel bus (PI). EEPROM and a clock are on the joybus, with the controllers. This page is about files, the parallel bus, and how n64emu finds out what a game saves to. The code is crates/n64-cart.

It rests on pages of n64brew.dev that were saved on 2026-12-01: Parallel Interface, Memory map, Flash and ROM Header. Nothing here was compared with a console, and no game was used to write or test it.

PageUsedNot used, and why
Parallel Interfacethe bus, its 16 bits, open bus, writes to the ROM, and where domain 1's settings come fromthe PI's registers, DMA and timing, which are the console's
Memory mapwhere saves and ROM areits domain for the 64DD, which is another one on Parallel Interface. The rest is the console's
Flashcommands, modes, times and the two chips that its authors measuredthe IDs of five other chips, the bus settings, and how several chips are mapped: the last is from the SDK, and the others have no origin
ROM Headerthe usual first four bytes, the letter at 3Eh (from a count of files), and homebrew's own headereverything else, as its origin is not clear: some of it cites libultra

Files

A file can have its bytes in three orders. The usual first four bytes tell them apart:

OrderFirst bytesOften called
the console's own80 37 12 40.z64
each 16 bits the other way round37 80 40 12.v64
each 32 bits the other way round40 12 37 80.n64

The file's name does not count. A game can have other first bytes, as the last three are settings for the bus. Then the order is a guess, and the app can say so:

  • An order fits when the first byte is 80h, as in all known commercial games, and the boot address at 8h is in the 8 MB of memory (80000000h to 807FFFFFh).
  • The first of the three orders that fits is used, beginning with the console's own. When none does, it is the console's own, as n64brew says.

A file needs at least 4 KB, which is the header and the boot code. There is no other limit. If it is in one of the two other orders and ends inside 32 bits, the missing bytes are taken as 0 before they are turned around (a guess). All of the data, in the console's order, is what the game's id is made from. So it is the same for all three files.

What is read from the header

WhereWhatFrom
0 to 3hthe bus settings for domain 1Parallel Interface says that the PIF's boot program takes all four from there, and that official ROMs have 64, 18, 7 and 3. 80 37 12 40 shows where each is
8hthe boot address, only for the byte orderPIF-NUS
34h to 3Fhwhat homebrew says of itself, if 3Ch has "ED"below
3Eha letter for the region, only to choose the console's regiona count of files
40h to FFFhthe boot code (IPL3). It is copied and never looked intoPIF-NUS

Not used: the ROM Header page gives no origin for the title, the game's code and the version, and cites libultra for the clock rate and the version of libultra. The checksum at 10h is for the boot code itself. No field is used to recognise a game.

What homebrew says

The "Advanced Homebrew ROM Header" is homebrew's own convention. The page says that EverDrive introduced it and that the community extended it, and names no other source for that section. It is what a developer declared: what the game saves to, whether it uses the clock, which regions and controllers it is for, and what it does with the Expansion Pak. 768K of SRAM with banks and 1M of SRAM can be declared, but are not emulated. n64emu then finds out for itself what the game saves to.

The bus

The PI puts an address on the bus, and then reads or writes 16 bits at a time. The cartridge counts up by itself. During a DMA, the PI puts a new address on the bus at each page of its settings. So read and write get the last address that was put on the bus, and how many bytes were moved since. Nothing is remembered in between, so the console can move that stretch in any pieces, and the data and state come out the same. A test does that with random pieces.

For example, a game reads 600 bytes from 10000100h by DMA, with pages of 512 bytes:

  1. The PI puts 10000100h on the bus. The next page begins at 10000200h, so it moves 256 bytes.
  2. At 10000200h it puts that address on the bus, and moves the other 344 bytes.
  3. The console can ask for these in blocks, such as 128 bytes each. The second block of step 1 is read with the address 10000100h and the offset 128.
AddressWhat
05000000h to 07FFFFFFhthe 64DD. It is not the cartridge's, and is not emulated yet. open_bus gives what is read there without one
08000000h to 0FFFFFFFhsaves: SRAM or FlashRAM
10000000h and upROM

Where nothing answers, a read gives the low 16 bits of the last address on the bus, again and again. That is true for direct reads and for DMA. Writes to the ROM or to nothing do nothing (Parallel Interface).

Guesses about the ROM:

  • Past its end, nothing answers, and it does not repeat.
  • It goes on counting across its own pages. The Flash page says that ROM chips have a limit of 512 bytes and SRAM one of 32 KB, but not what happens there, or who measured that. It only matters if a game sets larger pages.
  • If it ends inside 16 bits, the missing byte is 0.

SRAM

It has 32 KB, at 08000000h. Above that, nothing answers, and writes do nothing (a guess). So a write to a place that we do not understand can never overwrite a save. It is counted. New memory has FFh in it (a guess).

SRAM of 768K has banks, and no allowed source says where they are. A game that uses it would show as writes outside of the chip, in Counts::outside_writes, with the lowest and highest address.

FlashRAM

It has 128 KB, in 8 sectors of 128 pages, with 128 bytes each. A game writes a 32-bit command to 08010000h, and that changes what it reads at 08000000h:

CommandWhat it does
F0000000reads give the memory. This is so after power-on
E1000000reads give the chip's ID, 8 bytes
D2000000reads give the status, as the low byte of each 16 bits
B4000000reads and writes are for a buffer of 128 bytes, which starts as all FFh
A5000pppprograms page p with the buffer, and empties the buffer
4B000ppp, 3C000000the next erase is for the sector with page p, or for the whole chip
78000000erases. Without one of the two before it, it does nothing

Bits 10 to 23 of the commands with a page are ignored. A program or an erase changes to the status by itself:

BitStatus
7ready
3, 2the last erase, and the last program, worked
1, 0it is erasing, or programming

The Flash page tells what its authors saw two chips do, and these two are here. A game finds out by the ID which one it has:

MX29L1100 (the default)MN63F8MPN
Addresses count16-bit wordsbytes
To program, and to erase3.5 ms, 85 ms300 us, 280 ms for a sector and 300 ms for all. The page has "less than about" in front of these
A read of more than 8 bytes of the IDgoes on from its startrepeats its last 16 bits
An ID read at 08010000hgives the ID toogives open bus until the next command
A write to the bufferputs the value thereonly clears bits
Clearing the statusa 0 written to address 0. Both "worked" bits are then 1any write. They are then 0

On both, a status read at 08010000h gives open bus, and so does each read after it until the next command. A read that goes on past 256 pages continues at their start. The memory is kept in the order of its bytes, which is the same for both chips.

Why a chip is the default is a guess: the page calls those that count words the older ones. A game cannot know a chip that came after it, so an old one fits more games. These are guesses as well:

  • Programming and erasing always work. The memory changes when they begin, and what reads give while the chip is busy is not known.
  • Programming a page that was not erased clears more bits. While the chip is busy, other such commands are ignored.
  • Any other command between the choice of what to erase and the erase takes that choice away.
  • An address above the buffer is in the buffer again, and one above 0801FFFFh is nothing.

Not emulated: the page says that the MX29L1100 can need two writes before it gives the ID or the status, and that its first status read has 16 bits of what was there before. When that happens is not clear. The page also has IDs of five other chips and bus settings, and does not say where they are from. They are not used.

What a game saves to

The console does not know this, as the chips are simply there. A file has only the ROM. n64emu has no list of games. It looks at what the game does, and the player can always choose.

Who decides

  1. The player's choice wins, and is kept with the save.
  2. Then it is what a homebrew game declares.
  3. Then it is what was found before, and kept with the save.
  4. Otherwise it is found out while the game runs. This only adds chips, and never takes one away.

setup puts these together when the console is turned on. Its result is an input, like the buttons, so a movie or a test has to fix it.

What shows what

The game does thisIt has
writes a FlashRAM command to 08010000h, with nothing in its unused bitsFlashRAM, also when SRAM was found before
writes anything else to the first 32 KB of the savesSRAM
reads or writes a block of the EEPROMEEPROM
does so with a block above 63EEPROM of 16K

Asking what is on the joybus shows nothing, and neither do reads on the parallel bus.

When one of them was written to and nothing was found on the other bus, the other one looks empty the next time that the console is turned on. Reading is not enough for that. A game that read its EEPROM keeps it, also when it wrote to something on the parallel bus. Otherwise it could lose the chip that it saves to. What looks empty on the parallel bus is found again when the game writes there.

What a game could see

A real cartridge has its chips from the start, so none of this is how the console behaves. Without a choice or a declaration, a game could see:

What it seesWhenWho could notice
an EEPROM that its cartridge does not have, of 4Kat firsta game that checks that there is none, or that uses any that it finds
4K where its cartridge has 16Kuntil it uses a block above 63a game that looks for 16K. It may then never use it, and cannot save. The player has to choose 16K
16K where its cartridge has 4Kafter it used a block above 63a game that expects the first 64 blocks to repeat
FFh on the parallel bus instead of open busuntil something is found, and also later when nothing isa game that checks that there is no chip
SRAM that its cartridge does not haveafter its first write therea game that writes there to check for a chip
FFh in new SRAMuntil it is written tonobody should rely on it, as a real chip can have anything
open bus first, and then SRAM or FlashRAMit saved to EEPROM before, and writes to the parallel bus only nowa game that read there before
SRAM that becomes FlashRAMwhen a command comes after another writea game with SRAM that writes such a value there itself

An unknown chip on the parallel bus gives FFh, as both empty kinds do here. So what a game read before its first write is still the same after it, for either kind.

How often this happens is not known yet. Counts in both crates counts each of these cases since power-on. They are in no state and in no battery data.

No save is lost

  • Each chip has its own memory. The battery data has the memory of each one that was ever written to, whatever the type is now. If the type was wrong, choosing the right one brings its data back. A test changes the type and changes it back.
  • An EEPROM of 4K is the first 512 bytes of the one of 16K, so nothing moves when it grows.
  • The EEPROM is in n64-pif's battery data. SRAM, FlashRAM and the choice are in n64-cart's. Both have a version, and newer builds read older ones. Memory that is shorter than a chip is filled up with FFh.
  • If the data is damaged, from a newer build, or larger than the chip, it is refused and nothing changes. The app must then not write over that file.
  • A savestate has the chips' memory in it. So before it loads one, the app keeps a copy of the save. A state does not change the player's choice. After it is loaded, the counter of changes shows that the save is another one.

What is missing

  • SRAM of 768K with banks, SRAM of 1M, and the 64DD.
  • FlashRAM's quirks that are listed above, and its other chips.
  • Importing or exporting save files of other programs.
  • Every guess on this page needs a measurement. Which chip a game expects also needs a count with real games.

From commit 9ba9172cfa64. Edit this page