The Famicom Disk System has a fixed 8 KiB BIOS at $E000–$FFFF. It controls the Famicom at power-on and reset, dispatches NMI and IRQ, and offers a call interface to the data on disk (the disk format). Routines for common tasks such as reading controllers and handling the PPU are included for convenience, so they turn up in games ported from disk to cartridge. Addresses below are from the wiki’s table; the code for the routines is not given on this page.
Power-on and reset
The reset handler initialises the FDS and PPU registers (including a PPU warm-up loop, see PPU power-up state), then checks for an inserted or loaded disk. A basic interface shows an error message if disk loading fails. When the disk has loaded (or the reset flag and type are set as described under the vector controls), execution jumps to the game’s reset vector. On power-on and reset the BIOS sets the nametable arrangement to vertical (“horizontal mirroring”), turns the drive motor off, sets the stack pointer to $FF, sets the APU frame counter to $C0 (5-step mode, IRQs disabled) and clears the interrupt-disable flag. System RAM is filled with values the BIOS uses; PRG RAM is uninitialised except where files have been loaded.
Approval check
- The 224-byte string at PPU
$2800–$28DFmust match the data in the BIOS starting at$ED37. It is an English licensing message in the character encoding of Super Mario Bros. and Zelda; the BIOS checks it is in the nametable and shows it for several seconds after the boot files are loaded. - Traditionally the first file on a disk is a nametable file loaded to
$2800and namedKYODAKU-(“approval”); it must be a boot file, or the licence test fails with error$20before the program runs. - Bypass: the licence screen test and display can be skipped by using a boot file to enable NMIs, which interrupts the boot loading early. Unlicensed titles (such as those from I2 and Hacker International) and licensed Namco titles do this (Namco’s check for an IPL interface before showing a fake licence screen). The wiki’s stub for it is in the programming notes below.
Zero-page variables and vector controls
$00..$0F temporary variables
$F1..$F8 used by the controller reading routines
[$F9] mirror of $4026 ($FF on reset)
[$FA] mirror of $4025 ($2E on reset)
[$FB] mirror of $4016 ($00 on reset)
[$FC] mirror of $2005, second write ($00 on reset)
[$FD] mirror of $2005, first write ($00 on reset)
[$FE] mirror of $2001 ($06 on reset)
[$FF] mirror of $2000 ($10 on reset)
Four bytes at the bottom of the stack page control what the interrupt and reset vectors do:
[$0100] PC action on NMI; $C0 (NMI #3) on reset
[$0101] PC action on IRQ; $80 (BIOS acknowledge and delay) on reset
[$0102] RESET flag; $35 on reset after the boot files have loaded
[$0103] RESET type; $AC = first boot of the game, $53 = soft reset by the user
Disk programs must not overwrite these (watch init code, nested subroutines and stack manipulation). The vectors used:
| Vector | Target | When |
|---|---|---|
NMI ($FFFA) | BIOS NMI | always runs |
$E19D BIOS VINTWait handler | [$0100] = %00xxxxxx | |
($DFF6) disk game NMI vector 1 | [$0100] = %01xxxxxx | |
($DFF8) disk game NMI vector 2 | [$0100] = %10xxxxxx | |
($DFFA) disk game NMI vector 3 | [$0100] = %11xxxxxx | |
RESET ($FFFC) | BIOS RESET | always runs |
($DFFC) disk game RESET vector | [$0102] = $35 and [$0103] = $53 or $AC | |
IRQ ($FFFE) | BIOS IRQ | always runs |
$E1D9 BIOS disk skip bytes | [$0101] = %00nnnnnn (n = number of bytes to skip) | |
$E1CE BIOS disk transfer | [$0101] = %01xxxxxx | |
$E1EF BIOS acknowledge and delay | [$0101] = %10xxxxxx | |
($DFFE) disk game IRQ vector | [$0101] = %11xxxxxx |
Calling convention and disk access routines
Some routines take one or two pointers (little endian) placed inline right after the JSR (“direct pointers”); the routine fetches them from the return address on the stack and fixes the return address to the byte after them. Example: jsr LoadFiles followed by .dw DiskID and .dw FileList.
Warnings and facts for the disk access routines:
- They do not initialise PPUCTRL nor disable IRQs: disable NMIs, set the VRAM increment to +1 (for example by calling VINTWait with bit 2 of
$FFclear) and disable the timer, DMC and APU frame IRQ sources first. The value at [$0101] is preserved on entry and restored on exit. Zero page$00–$0Fis affected. - The FDS has no intelligent tracking: every BIOS load or save accesses the whole disk whatever data is asked for. A custom loader that forces the file count lower avoids touching later files.
- Loads are dummy loads (contents ignored) if the destination is below CPU
$2000(except$x200–$x7FF) or if address plus size would overflow 16 bits; loads starting at$0200–$07FFand its mirror$1200–$17FFare allowed. The cut-off at$2000is probably a bug;$6000(start of PRG RAM) would have prevented stray register accesses. - On return A = 0 is success, any other number is the error (see the error list); test with BEQ (success) or BNE (error).
| Address | Name | Input | Output | What it does |
|---|---|---|---|---|
$E1F8 | LoadFiles | direct pointers: Disk ID, File List | A = error, Y = files loaded | Loads the files named by the list into memory from disk, trying twice before returning an error. Load addresses come from each file’s header. At most 20 file IDs per list, shorter lists end with $FF; a list that is only $FF loads the files whose IDs are less than or equal to the boot read file code of the disk info block (used by the BIOS at start-up). Files load in disk order, not list order. |
$E237 | AppendFile | direct pointers: Disk ID, File Header | A = error | Appends the file to the end of the disk, increments the file count, then reads the file back to verify; if verification fails the count is decremented (hiding the file). |
$E239 | WriteFile | direct pointers: Disk ID, File Header; A = file number | A = error | As AppendFile but writes at sequential position A (0 is first) and sets the disk’s file count to A, logically hiding any later files. |
$E2B7 | CheckFileCount | direct pointer: Disk ID; A = count to set | A = error | Reads the disk’s file count, compares it with A and sets it to A; error 31 if A is greater than the original count. |
$E2BB | AdjustFileCount | direct pointer: Disk ID; A = amount to reduce by | A = error | Reads the file count, decrements it by A and writes it back; error 31 if A is greater than the original count. |
$E301 | SetFileCount1 | direct pointer: Disk ID; A = last file’s number (count minus one) | A = error | Sets the file count to A plus 1. |
$E305 | SetFileCount | direct pointer: Disk ID; A = count | A = error | Sets the file count to A. |
$E32A | GetDiskInfo | direct pointer: Disk ID | A = error | Fills the given location with the current disk’s Disk ID data. |
Low-level disk routines
| Address | Name | Input | Output | What it does |
|---|---|---|---|---|
$E445 | CheckDiskHeader | $00–$01 = pointer to a 10-byte string | Checks that the *NINTENDO-HVC* string is on the disk, then compares the Disk ID structure with the data pointed to. A $FF in a field skips that byte’s comparison. A failed comparison gives the matching error. | |
$E484 | GetNumFiles | $06 = number of files | Reads the number of files from the file amount block. | |
$E492 | SetNumFiles | A = number of files | Writes A to the file amount block. | |
$E4A0 | FileMatchTest | $02–$03 = pointer to a file ID list | Searches the list for the file’s ID; on an exact match [$09] is set to 0 and [$0E] incremented; if there is no match within 20 bytes or a $FF entry is reached [$09] is set to $FF. If the first byte of the list is $FF, the boot ID is used (any file ID not greater than it matches). | |
$E4DA | SkipFiles | $06 = number of files to skip | Skips over that many files. |
Using LoadFiles and WriteFile
Loading: save $FF ANDed with %00111011 back to $FF (NMIs off, increment +1), call VINTWait so the change takes effect, then JSR LoadFiles with the Disk ID and file list; BNE means an error: print the error (with side and disk change prompts), wait until the disk is ejected and inserted again (poll $4032 bit 0) and retry. After a successful load compare Y with the expected file count. Saving is the same with WriteFile and a file header; the saved file should be the last on the disk side or later files are hidden. In both cases non-disk IRQ sources must be off. The Disk ID in the wiki’s example is licensee $01, a 3-letter game code plus a space for a normal disk, version 0, side 1, disk 0, type 0 and one unknown byte.
Structures
Disk ID
Bytes $0F to $18 of the disk’s info block, right after the *NINTENDO-HVC* string. CheckDiskHeader compares these 10 bytes; an $FF in a field skips it (the BIOS, when booting, sets every field to $FF except disk side and disk number, which must match 0).
| Offset | Size | Error | Field |
|---|---|---|---|
| 0 | 1 | $04 | licensee code |
| 1 | 4 | $05 | game ASCII name string and game type |
| 5 | 1 | $06 | game version |
| 6 | 1 | $07 | disk side number |
| 7 | 1 | $08 | disk number |
| 8 | 1 | $09 | disk type |
| 9 | 1 | $10 | unknown |
GetDiskInfo returns these 10 bytes followed by: 1 byte number of files (from the file amount block), then for each file 1 byte file ID and 8 bytes ASCII file name, then 2 bytes disk size (high byte then low byte; the size is the sum of each file’s size entry plus 261 per file).
File List
A list of one-byte file IDs to load, at most 20, ended by $FF (so an ID can never be $FF). Every file matching any ID is loaded, in the order they are on the disk.
File Header
Given when a file is written. The first 14 bytes give the data for the file header block, the next 3 bytes concern the file data block (the file count is passed separately, for example in A to WriteFile).
| Offset | Size | Meaning |
|---|---|---|
$00 | 1 | file ID code |
$01 | 8 | file name |
$09 | 2 | load address |
$0B | 2 | file data size |
$0D | 1 | file type ($00 program, $01 character, $02 nametable) |
$0E | 2 | source address of the file data (not written to disk) |
$10 | 1 | source address type ($00 RAM, $01 VRAM; not written to disk) |
Error list
Error numbers are BCD, returned by the disk I/O routines. The message is what the BIOS shows, where it shows one.
| Error | Message | Explanation |
|---|---|---|
$00 | success | |
$01 | disk set | $4032 bit 0: disk not set |
$02 | battery | $4033 bit 7: power supply failure |
$03 | $4032 bit 2: disk is write protected | |
$04 | wrong licensee code | |
$05 | wrong game ASCII name string or game type | |
$06 | wrong game version | |
$07 | a,b side | wrong side number |
$08 | disk no. | wrong disk number |
$09 | wrong disk type | |
$10 | wrong value for the unknown field | |
$20 | disk trouble | approval check failed |
$21 | disk trouble | the *NINTENDO-HVC* string in the disk info block does not match |
$22 | disk trouble | disk info block expected |
$23 | disk trouble | file amount block expected |
$24 | disk trouble | file header block expected |
$25 | disk trouble | file data block expected |
$26 | disk trouble | AppendFile or WriteFile: readback verification failed after writing |
$27 | disk trouble | $4030 bit 4: block failed CRC |
$28 | disk trouble | $4030 bit 6: file ends prematurely during a read (the disk is full) |
$29 | disk trouble | $4030 bit 6: file ends prematurely during a write (the disk is full) |
$30 | disk trouble | $4032 bit 1: file ends prematurely during CRC writes (the disk is full) |
$31 | disk trouble | CheckFileCount or AdjustFileCount: A is greater than the original file count |
Software-specific errors: $35 in the FMC Disk Card Checker: test data block verification failed; $40 LoadFiles: Y is not the expected file count (not all files in the list could be loaded; commercial games use it that way); $41 and above unknown (Kineko II’s manual mentions one).
Other BIOS calls
| Address | Name | Input | Output | Description |
|---|---|---|---|---|
$E149 | Delay131 | A 131-cycle delay (counting the JSR) used by the “acknowledge and delay” IRQ handler, meant to refresh DRAM rows when the DRAM refresh watchdog has expired. | ||
$E153 | Delayms | Y = delay in ms (approx.) | X, Y changed | The time in CPU cycles is 1790 times Y plus 5; Y = 0 means 256. |
$E161 | DisPFObj | $FE = PPUMASK value | Disables sprite and background rendering. | |
$E16B | EnPFObj | $FE | Enables sprite and background rendering. | |
$E171 | DisObj | $FE | Disables sprite rendering. | |
$E178 | EnObj | $FE | Enables sprite rendering. | |
$E17E | DisPF | $FE | Disables background rendering. | |
$E185 | EnPF | $FE | Enables background rendering. | |
$E1B2 | VINTWait | $FF = PPUCTRL value | Waits for the next vblank NMI, disables NMIs, reads PPUSTATUS to clear the vblank flag and returns (for programs that do everything in main). The NMI vector selection at $0100 is kept but further NMIs are disabled; the interrupt-disable flag is not restored and stays set from the NMI entry. Clear the vblank flag before calling it if its state is unknown. | |
$E7BB | VRAMStructWrite | direct pointer: VRAM structure; $FF = PPUCTRL value | Sets VRAM increment to 1 (clears bit 2 of the PPUCTRL mirror) and transfers a VRAM structure to VRAM. | |
$E844 | FetchDirectPtr | $00–$01 = pointer | Fetches a direct pointer placed after the caller’s return address, saves it at ($00) and fixes the return address. | |
$E86A | WriteVRAMBuffer | $FF; $0302–$03FF = write buffer | Transfers the VRAM write buffer at $0302 to VRAM. | |
$E8B3 | ReadVRAMBuffer | X = start of the read buffer, Y = bytes to read | buffer at $0300+X | Reads Y bytes from VRAM into the read buffer. |
$E8D2 | PrepareVRAMString | A = high VRAM address, X = low, Y = length, direct pointer = data | A = $FF success, $01 did not fit | Copies the data into the write buffer at $0302; data that does not fit (by the maximum index in $0300) is rejected. |
$E8E1 | PrepareVRAMStrings | A = high VRAM address, X = low, direct pointer = data | A = $FF success, $01 did not fit | Copies a 2-D string into the write buffer as several 1-D strings; the first data byte is the size (upper nybble height, lower nybble width in tiles). |
$E94F | GetVRAMBufferByte | X = start of the read buffer, Y = read structure to check (from 1), $00–$01 = VRAM address | carry clear: byte in A; carry set: none read | Compares the address with the Y-th read structure at $0300+X+(Y-1)*3; on a match clears carry and returns the stored byte, otherwise overwrites the target address with ($00) and sets carry so the program calls ReadVRAMBuffer. Probably meant to avoid repeated VRAM reads. |
$E97D | Pixel2NamConv | $02 = pixel Y, $03 = pixel X | $00–$01 = nametable address | Converts screen pixel coordinates to a nametable address (no scrolling; first nametable at $2000). |
$E997 | Nam2PixelConv | $00–$01 = nametable address | $02 = Y, $03 = X | Converts a nametable address to pixel coordinates (no scrolling). |
$E9B1 | Random | X = start of the shift register bytes, Y = their count (normally 2) | A shift-register pseudo-random generator: each call shifts the bytes right by one bit; seed them with nonzero values. | |
$E9C8 | SpriteDMA | OAM DMA from RAM $0200–$02FF. | ||
$E9D3 | CounterLogic | X = first counter, A = last of the middle counters, Y = last counter (all zero-page addresses) | Decrements counters in zero page: the first (at X) is a decimal counter 9 to 0 and wraps to 9; the counters X+1 to A just decrement and stay at 0; the counters A+1 to Y decrement when the first counter wraps from 0 to 9 and stay at 0. | |
$E9EB | ReadPads | $FB = controller latch bits | $F5 pad 1, $F6 pad 2, $00 expansion 1, $01 expansion 2 | Reads the hard-wired and expansion port joypads (read the expansion data elsewhere afterwards, or other BIOS calls clobber it). |
$EA0D | OrPads | the ReadPads outputs | $F5 = pad 1 OR exp 1, $F6 = pad 2 OR exp 2 | Combines the joypad and expansion inputs; call after ReadPads. |
$EA1A | ReadDownPads | $FB | $F5/$F6 up-to-down transitions of pads 1/2, $F7/$F8 their data | Reads the hard-wired joypads and detects up to down transitions. |
$EA1F | ReadOrDownPads | $FB | as above | Reads both hard-wired and expansion joypads and detects transitions. |
$EA36 | ReadDownVerifyPads | $FB | as above | As ReadDownPads, reading until two consecutive reads match (a DMC glitch workaround). |
$EA4C | ReadOrDownVerifyPads | $FB | as above | As ReadOrDownPads with the verify loop; it may still give false reads because the reread loop for two controllers plus the expansion port is too slow for the longest DMC fetch period (a page-cross penalty in the loop’s branch may mask the problem; the wiki says this is still to be measured). Tetris (Nintendo) and Dr. Mario reuse these routines. |
$EA68 | ReadDownExpPads | $FB | $F1–$F4 transitions, $F5–$F8 data, in the order pad 1, pad 2, expansion 1, expansion 2 | Reads all four joypads and keeps their data separate instead of ORing; not DMC-safe. |
$EA84 | VRAMFill | A = high VRAM address (tile row), X = fill value, Y = tile rows or attribute fill data, $FF | If A is below $20 fills pattern data with X for 16 times Y tiles; otherwise fills the nametable with X and the attribute table with Y. | |
$EAD2 | MemFill | A = value, X = first page, Y = last page | Fills RAM pages with A. | |
$EAEA | SetScroll | $FC = Y scroll, $FD = X scroll, $FF | Reads PPUSTATUS (clearing the write latch and the vblank flag), then writes PPUSCROLL with [$FD] and [$FC] and PPUCTRL with [$FF]; call in vblank after VRAM updates. | |
$EAFD | JumpEngine | A = jump table entry | The calling instruction is followed by a jump table of up to 128 little-endian 16-bit pointers; A picks the entry, jumped to through the return address. | |
$EB13 | ReadKeyboard | $FB | A = $FF success, $00 no keyboard; data at $00–$08 | Reads the Family BASIC Keyboard (see the keyboard section); the data is stored from row 8 downwards ($00 is row 8, $01 row 7 and so on), column 0 in the low nybble and column 1 in the high nybble; a set bit is a pressed key. |
$EBAF | LoadTileset | A = low VRAM address and flags, Y = high VRAM address, X = tiles to transfer, direct pointer = RAM source or destination, $FF | Reads or writes 2-bit-plane and 1-bit-plane tile sets to or from VRAM (flags below). | |
$EC22 | UploadObject | $00–$01 = pointer to an object structure | Uploads an object to OAM RAM at $0200–$02FF (structure below). |
VRAM transfer structure and buffers
2 bytes VRAM address (big endian; the high byte is in $00..$3F)
1 byte bits 0-5 length of data ($0 means 64); bit 6: 0 copy, 1 fill; bit 7: 0 increment by 1, 1 increment by 32
n bytes data (in fill mode one byte, repeated)
... repeated as needed
1 byte bit 7 set ($FF is common) ends the structure
A $4C (JMP) byte is a “call”: the two bytes after it (little endian) give a sub-structure address; the call pushes a return address, so nesting depth must be limited like JSR calls to protect the vector controls. A $60 (RTS) byte ends a sub-structure and returns to three bytes after the call byte. The length differs from the similar stripe-image RLE format. Example from the wiki: address $2000, length 4 copy, the data “TEST”, a call to a sub-structure that fills 30 bytes at $2400 with $AA in increment-32 mode and returns, then $FF.
Write buffer. The VRAM buffer lies at $0300+: $0300 holds the maximum index (size minus 1, initialised to $7D, so the buffer is $0300–$037F; the largest value is $FD, $0300–$03FF) and $0301 the current end index; the buffer itself starts at $0302. Its format is that of the VRAM structure without sub-structures, the increment-32 flag or the fill flag, so it can serve as a sub-structure; WriteVRAMBuffer is faster than VRAMStructWrite on $0302 with the same effect.
Read buffer. A read buffer can be placed in $0300–$03FF but must not overlap the write buffer; $0300 is the boundary. The read routines are incomplete and their intended use is partly speculation (probably one-off reads of attribute table bytes for read-modify-write of single 16 by 16 squares). Each byte to read takes a 3-byte structure: 2 bytes target VRAM address (big endian) and 1 byte returned data. The wiki suggests keeping attribute mirrors in system RAM instead of reading VRAM.
LoadTileset flags (AAAA MMIT): T fill bit; I transfer direction (0 write tiles, 1 read tiles); MM the bit-plane type; AAAA the low VRAM address (tile number within a row). Type 0: first plane data, second plane data plus 8 (normal 2-plane graphics). Type 1: first plane data, second plane the fill bit (single plane; fill bit clear uses colours 0 and 1, set uses 2 and 3). Type 2: first plane the fill bit, second plane data (colours 0 and 2, or 1 and 3). Type 3: first plane data XOR fill bit, second plane data (colours 0 and 3, or 1 and 2). Single-plane graphics cannot be loaded from disk straight to VRAM; load into PRG RAM first. In read mode all non-data planes are dummy reads.
Object structure (UploadObject)
1 byte render flag: $00 render, $01-$7F skip rendering, $80-$FF hide the object
1 byte Y position of the upper left
1 byte fractional part of Y (8 bits)
1 byte X position of the upper left
1 byte fractional part of X (8 bits)
1 byte animation frame
2 bytes tile arrangement pointer (big endian)
1 byte flags: bit 4 flip horizontally, bit 0 flip vertically
1 byte palette
1 byte upper nybble height, lower nybble width (in tiles)
1 byte index of the object in OAM
X and Y correspond to OAM positions; the fraction bytes are not used by $EC22 and may serve any purpose. Tiles are arranged column by column, in one of two ways. If the pointer is below $100 it is the upper-left tile ID, to which animation frame times width times height is added to get the first tile (a 3 by 3 object with pointer $0010 and frame 1 is tile $19, $1A, $1B in the first column, $1C, $1D, $1E in the second, $1F, $20, $21 in the third). Otherwise it points to arrangement data, one block of width times height tile numbers per frame (for 2 by 3 sprites at $6000 holding $00 $01 $02 $03 $04 $05, then $FF $FE $FD $FC $FB $FA, then $22 $33 $44 $55 $66 $77, frame 0 shows the columns $00 $01 $02 and $03 $04 $05).
Writing and porting disk programs
Notes from the wiki’s “Programming the FDS” page (a work in progress, little tested by others, it says). Terms: a boot file has a file ID less than or equal to the boot read file code and loads during the initial load (primary PRG and CHR data, title and licence screens); a non-boot file (save data, overlays) loads only through LoadFiles.
- cc65 (ca65 and ld65) is recommended since it can define file load addresses and sizes for the file headers. Bypass the licence screen.
$0100–$0103must hold valid values at all times; the bypass stub sets$0102–$0103and jumps to the BIOS reset, which sets$0100–$0101. Nametable arrangement is set by$4025bit 3 (use the mirror at$FAto keep other bits):$26horizontal arrangement (“vertical mirroring”),$2Evertical arrangement (the BIOS’s reset setting).- BIOS routines expect its RAM layout:
$00–$0Ftemporaries,$F1–$F8controller routines,$F9–$FFregister mirrors,$0100–$0103the flags,$0200–$02FFthe OAM DMA buffer,$0300–$03FFthe VRAM buffer,$0400–$07FFthe pattern transfer buffer of LoadTileset calls before the initial load. Cycle-timed NMI handlers must allow for the cycles the BIOS NMI handler spends, and custom IRQ handlers ($0101=$C0) for the timer IRQ, the BIOS IRQ cycles and the DRAM refresh watchdog. Reading$4030to acknowledge IRQs conflicts with DPCM. - Reset handler tasks: clear the interrupt-disable flag (the BIOS does a CLI before handing over); set the timer IRQ if wanted (the BIOS sets
$4022to 0 and leaves the reload value in$4020/$4021); set$4017to$40if the sound driver wants 4-step mode (the BIOS sets$C0); set the nametable arrangement; initialise RAM without touching the BIOS variables ($0100=$C0,$0101=$80,$0102=$35,$0103=$ACor$53); initialise the PPU registers, palettes and nametables (the BIOS sets PPUCTRL$10, PPUMASK$06, scroll 0,0 and runs a warm-up loop); initialise unused pattern table areas, which keep whatever the BIOS loaded. - Most relevant registers:
$4025write (nametable bit 3),$4020–$4022timer IRQ,$4030read (acknowledge: bit 0 timer, bit 1 DRAM refresh watchdog),$4032read bit 0 (0 disk inserted, 1 ejected),$4040–$408AFDS audio. - DRAM refresh watchdog:
$4030bit 1 reports a watchdog that raises IRQs from CPU cycles spent accessing DRAM and refreshing it; single-instruction infinite loops and long stretches of PRG-RAM code starve it of row refreshes. Ignoring it (SEI or disabling it) lets the DRAM decay in an analogue way. The safest way is to keep$4023equal to$83from the BIOS reset handler, check$4030bit 1 in the IRQ handler and call Delay131 when it is set; games with no IRQ use can CLI in the reset handler (and perhaps on NMI entry) and keep the BIOS’s default IRQ selection$80. To wait for NMIs without the watchdog IRQs, commercial “everything in NMI” games loop onlda $00andjmp(a system RAM read increments the 7-bit refresh counter: 6 cycles times 128 loops is 768 cycles, enough to refresh all rows and reload the 12-bit cycle timer); “everything in main” games wrap VINTWait withbit $2002before it (clearing the vblank flag to avoid the vblank NMI bug) andcliafter it (it returns with the I flag set, executing from BIOS ROM refreshes DRAM). A custom IRQ handler reads$4030, keeps bits 0 and 1, handles the timer (disable it by writing 0 to$4022) and for the watchdog calls$E149. - Disk I/O: LoadFiles loads overlays after the initial load (Super Mario Bros. 2 (J) loads overlays for worlds 1 to 4, 5 to 8 and A to D); WriteFile overwrites a specific file number and AppendFile adds one, and both mark the written file as the last of the side, so game saves must be the final file on a side and the only safely modifiable file; multiple save slots must be concatenated into one file, and verification of save data plus the error codes is recommended. Layouts: single-sided: main data, overlays, save data; double-sided: side A title screen and save management, extra overlays, save data; side B main data and overlays.
- Licence screen bypass: put a stub (the NMI 3 vector at
$DFFApoints to it) in a boot file loaded before the NMIs are enabled: it writes 0 to$2000, stores the real NMI handler address at$DFFA–$DFFB, writes$35to$0102and$ACto$0103, and jumps through($FFFC). The final boot file then enables NMIs by loading PPUCTRL, and the initial load is stalled until an NMI fires either by appending large non-boot files and raising the file count in the file amount block (keeps disk I/O working; the PowerPak’s BIOS may seek too fast for small files) or by raising the count by 1 without adding a file (no extra files, but later disk I/O breaks). Another method hijacks the disk drive IRQ. - Porting cartridge games: NROM (16 or 32 KiB PRG ROM and 8 KiB CHR ROM) is mostly compatible with the FDS layout of 32 KiB PRG RAM and 8 KiB CHR RAM. Assemble the PRG code into
$6000–$DFFF($E000–$FFFFis the BIOS) with the vectors in$DFFA–$DFFF($DFF6and$DFF8can hold alternate NMI vectors), adjust reset and main code, then build the disk: info block, file amount block, the PRG data as a boot file of type 0 (CPU RAM), the CHR data as a boot file of type 1 (PPU CHR) and the licence bypass. Loadable once on boot: mapper 185 (without the chip select check) and mapper 218 (if mirrored accesses are avoided); with infrequent loading: CNROM-like, GNROM-like, UNROM and MMC1 (SEROM, SHROM and SH1ROM most compatible; SNROM and SKROM were common targets of disk-to-cartridge ports such as Metroid, Kid Icarus and The Legend of Zelda). A PRG of 16 KiB or less with code confined to$8000–$BFFFfits PRG RAM as is with duplicated vectors at$DFFA–$DFFF. Writes aimed at the PRG ROM or CHR ROM areas (mapper registers, harmless writes such as in Door Door, game bugs) must be dealt with.
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 copied: the wiki’s example assembly code (loading, saving, the licence bypass stub, the IRQ handler and the object arrangement examples are described above in words), the example programs and the BIOS disassembly references. The register behaviour of the drive is on the Famicom Disk System page.