UŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
       3  Nintendo Entertainment System Documentation v0.40   3
       3            by Y0SHi (yoshi@parodius.com)             3
       3                                                      3
       3             http://nesdev.parodius.com/              3
       AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU



UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 0 3   Introduction   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

                    UŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
                    3 READ ME   READ ME   READ ME 3
                    AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  I'd like to dedicate this document to Alex Krasivsky (Landy on IRC) for
all of his help and moral support throughout the past year regarding the
NES, and issues outside of the console realm. During the good times, and
the bad times, Alex was there. Spasibo, Alex; umnyj russki...

                    UŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
                    3 READ ME   READ ME   READ ME 3
                    AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  There are bound to be contradictory statements in this document. There
are errors, and many problems regarding terminology (VROM vs. CHR-RAM,
etc.). It is *FAR* from perfect. I have not incorporated all the terminology
I would like to incorporate. Give it time and support: it'll get there.

  You will notice severe similarities between Marat Fayzullin's NES Docu-
mentation and mine; I originally based my work on his. Without Marat's
document, I would have never had the desire to create this one.

  Do not Email me about 6502 specifics, or such issues as "I can't figure
out how to do {xxx}." I'm not interested in Emails like this; I know that
sounds negative and rude, but I'm really sick and tired of getting Email
about 6502 issues. Read a book. Libraries are *FULL* of 6502 books. There
are tons of web pages about the 6502. I will not teach you 6502, nor any
assembly language (nor do I teach UNIX). It's up to you to learn it.

  Finally, please, give credit where credit is due. All of the people in
Section #15 helped contribute to this document. Be sure to thank them,
as without their help, this document wouldn't be much more than a waste
of bandwidth.


UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 1 3   Description   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  The NES consists of a custom 6502 CPU, and a PPU (Picture Processing
Unit) used for graphics. Programs can communicate with the NES via
registers (I/O ports, so-to-speak), which allow different things to
happen internally to the NES.

  There are multiple areas of memory on the NES, and they should not be
confused. Terms marked with an asterisk ('*') will be the terms used
from here on.

UŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Term.    3 Description                                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3* PRG-ROM 3 Nintendo of Japan's term for the actual program code area.  3
3          3                                                             3
3          3 It stands for PRoGram ROM.                                  3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3* CHR-RAM 3 Nintendo of Japan's term for the Pattern Table of the PPU's 3
3          3 internal RAM.                                               3
3          3                                                             3
3          3 It stands for CHaRacter RAM.                                3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3* VRAM    3 The RAM internal to the PPU (Picture Processing Unit).      3
3          3 There is 16K of internal VRAM.                              3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3* WRAM    3 This is the memory which is most commonly used for games    3
3          3 which support saving (usually RPGs), such as Zelda 1 & 2,   3
3          3 Crystalis, the Final Fantasy series, and other games.       3
3          3                                                             3
3          3 It stands for Writeable RAM.                                3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3* MMC     3 The microcontrollers used in carts to address memory past   3
3          3 the standard 6502 64K boundary. They can also be used to    3
3          3 address extra VRAM, and may also be used for "special       3
3          3 effects."                                                   3
3          3                                                             3
3          3 MMC stands for Multi-Memory Controller.                     3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3* EXRAM   3 This is the memory which is used in MMC5, to support the    3
3          3 extended colour (Attributes) mode. See Section #10 for more 3
3          3 information on this subject.                                3
3          3                                                             3
3          3 It stands for EXternal RAM.                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 VROM     3 The Pattern Table data kept external to the PPU itself;     3
3          3 standard CHR-RAM data, which is swapped in and out of the   3
3          3 PPU via an MMC.                                             3
3          3                                                             3
3          3 VROM stands for Video ROM.                                  3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 CHR      3 Synonymous with CHR-RAM.                                    3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 PRG      3 Synonymous with PRG-ROM.                                    3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 SRAM     3 Synonymous with WRAM.                                       3
AŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU


UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 2 3   CPU Memory Map   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Size  3 Description                               3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $0000   3 $800  3 RAM                                       3
3 $0800   3 $800  3 RAM (mirrored from $0000)                 3
3 $1000   3 $800  3 RAM (mirrored from $0000)                 3
3 $1800   3 $800  3 RAM (mirrored from $0000)                 3
3 $2000   3 $3000 3 Registers                                 3
3 $5000   3 $1000 3 Expansion Modules                         3
3 $6000   3 $2000 3 WRAM                                      3
3 $8000   3 $4000 3 PRG-ROM (Lower)                           3
3 $C000   3 $4000 3 PRG-ROM (Upper)                           3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  Note the two seperate PRG-ROM sections; they are congruent, but they
also play seperate roles, depending upon the size of the cartridge itself.
Some games only hold one (1) 16K bank of PRG-ROM, which should be loaded
into $C000 (Upper), not $8000 (Lower). Some games which do this are:
Battle City, Mario Brothers, Millipede, Nuts & Milk, and Tennis. There
are others as well.

  Most games load themselves into $8000 (Lower PRG-ROM), using 32K of
PRG-ROM space. The first game (to my knowledge) to use the entire PRG-ROM
space is Super Mario Brothers. However, all games with more than one (1)
16K bank of PRG-ROM load themselves into $8000 as well. These games use
MMCs (see Section #10) to address PRG-ROM past the 32K boundary, and
to access more than 8K of CHR-RAM simultaneously.



UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 3 3   PPU & Sprite Memory Map   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

 PPU Memory Map
UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Size  3 Description                               3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $0000   3 $1000 3 Pattern Table #0     (possibly CHR-RAM)   3
3 $1000   3 $1000 3 Pattern Table #1     (possibly CHR-RAM)   3
3 $2000   3 $3C0  3 Name Table #0                             3
3 $23C0   3 $40   3 Attribute Table #0                        3
3 $2400   3 $3C0  3 Name Table #1                             3
3 $27C0   3 $40   3 Attribute Table #1                        3
3 $2800   3 $3C0  3 Name Table #2        (based on mirroring) 3
3 $2BC0   3 $40   3 Attribute Table #2   (based on mirroring) 3
3 $2C00   3 $3C0  3 Name Table #3        (based on mirroring) 3
3 $2FC0   3 $40   3 Attribute Table #3   (based on mirroring) 3
3 $3000   3 $F00  3 [---EMPTY---]                             3
3 $3F00   3 $10   3 Image Palette                             3
3 $3F10   3 $10   3 Sprite Palette                            3
3 $3F20   3 $E0   3 [---EMPTY---]                             3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

 Sprite RAM
UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Size  3 Description                               3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $0000   3 $100  3 Sprite RAM                                3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  For more information about Sprite RAM, see Sections #6 and #9.

  VRAM is quite unorganized, as shown above. To my knowledge, VRAM is
addressed via 14-bit address, and therefore should wrap back around to
$0000 if the memory boundary passes the end of memory ($3FFF).

  There is only enough VRAM memory to support two (2) Name Tables and
two (2) Attribute Tables. Therefore, Name/Attribute Tables #2 and #3
are mirrors of Name/Attribute Tables #0 and #1. Which Tables are mirrored
depends upon the mirroring bit set inside of the cartridge header (see
Section #12 for more information).

  In a real NES, reading/writing VRAM should only be attempted during
VBlank. Many smaller ROMs have CHR-RAM for the Pattern Tables. In this
case, you won't be able to write into this memory.

  Writing to VRAM
  ŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ
  1) Write upper address byte into $2006
  2) Write lower address byte into $2006
  3) Write data into $2007. After each write, the address will auto-
     increment by 1, or 32 (if Bit #2 of $2000 is 1).

  Reading from VRAM
  ŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ
  1) Write upper address byte into $2006
  2) Write lower address byte into $2006
  3) Read data from $2007. The first read from $2007 is invalid, and
     therefore should be taken care of before actual data is read.
  4) Read data from $2007. From here on, after each read, the address will
     auto-increment by 1, or 32 (if Bit #2 of $2000 is 1).

  The Name Table holds "tile index values." Tiles themselves are 8x8
pixels. The entire Name Table itself is 32x30 tiles (256x240 pixels).
However, due to NTSC and PAL frequencies, the actual displayed resolution
is different.

  For NTSC, the upper and lower 16 pixels are not displayed, therefore the
resolution is 256x224. The Name Table itself keeps a static size of 32x30
tiles (256x240 pixels).

  These values (re: "tile index values") are usually put into the Name
Table via writes to the $2006 register (see Section #6). These values are
used to reference the information stored in the Pattern Table. For you
emulator authors out there, the formulae is quite simple:

        (VALUE * 16) + ScreenPatternTableAddress

  Where VALUE is the value which is written to register $2006, and
ScreenPatternTableAddress is the Screen Pattern Table Address defined in
Bit #2 in register $2000 (see Section #6).

  The NES can only display 16 colours on the screen simultaneously.

  The Pattern Table contains tiles in the following format:

    Contents of                       Colour 
   Pattern Table                      Result
  ŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ                    ŽŽŽŽŽŽŽŽ
  %00010000 = $10 ŽŽ¨                ...1....  Periods are used to rep-
  %00000000 = $00   3                ..2.2...  resent colour 0. Numbers
  %01000100 = $44   3                .3...3..  shown represent colour #.
  %00000000 = $00   AŽŽ Bit 0        2.....2.
  %11111110 = $FE   3                1111111.
  %00000000 = $00   3                2.....2.
  %10000010 = $82   3                3.....3.
  %00000000 = $00 ŽŽU                ........

  %00000000 = $00 ŽŽ¨
  %00101000 = $28   3
  %01000100 = $44   3
  %10000010 = $82   AŽŽ Bit 1
  %00000000 = $00   3
  %10000010 = $82   3
  %10000010 = $82   3
  %00000000 = $00 ŽŽU

  The result of the above Pattern Table is the character 'A', as shown
in the "Colour Result" section in the upper right.

  Only two (2) bits for each pixel of a tile are stored in the Pattern
Table. The other two (2) bits are taken from the Attribute Table. Four (4)
bits make up the entire possible colours on the NES, which therefore shows
that the NES can display 16 colours on the screen simultaneously.

  Each byte in an Attribute Table represents a 4x4 group of tiles on the
screen. There's multiple ways to describe what the function of one (1)
byte in the Attribute Table does:

  * Holds the upper two (2) bits of a 32x32 pixel grid, per 16x16 pixels.
  * Holds the upper two (2) bits of sixteen (16) 8x8 tiles.
  * Holds the upper two (2) bits of four (4) 4x4 tile grids.

  It's confusing as hell, to be honest. A few graphical diagrams may help
those who are confused:

 UŽŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽ¨
 3  Square 0  3  Square 1  3  #0-F represents an 8x8 tile
 3   #0  #1   3   #4  #5   3
 3   #2  #3   3   #6  #7   3  Square [x] represents four (4) 8x8 tiles
 AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'   (i.e. a 16x16 pixel grid)
 3  Square 2  3  Square 3  3
 3   #8  #9   3   #C  #D   3
 3   #A  #B   3   #E  #F   3
 AŽŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽU

   Attribute Byte
  ŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ
     %00000000
      A'A'A'AAŽ Upper two (2) colour bits for Square 0 (Tiles #0/1/2/3)
       3 3 AŽŽŽ Upper two (2) colour bits for Square 1 (Tiles #4/5/6/7)
       3 AŽŽŽŽŽ Upper two (2) colour bits for Square 2 (Tiles #8/9/A/B)
       AŽŽŽŽŽŽŽ Upper two (2) colour bits for Square 3 (Tiles #C/D/E/F)

  Putting all of this information together is a cinch, assuming you can
overlay bit patterns in your head. A similar method is used in the tweaked
graphics modes known as "MODE-X" modes on the PC. Most DOS-oriented emu-
lators use what's known as "MODE-Q", since it's resolution is 256x256x256.
For more information, research "chained graphics modes."

  Two (2) palettes exist; the Image Palette and the Sprite Palette. These
palettes are more of a "lookup table" than an actual palette, since they
do not hold physical RGB values.

  The NES itself uses an NTSC composite video signal, but can be "emulated"
by corrisponding RGB values with the colours on a standard TV set. The
actual 256 RGB palette can be obtained from Loopy (see Section #15).

  Mirroring also occurs between the Image Palette and the Sprite Palette.
Any data which is written to $3F00 is mirrored to $3F04, $3F08, and $3F0C.
Any data which is written to $3F10 is mirrored to $3F14, $3F18, and $3F1C.
Colour #0 in both Palettes defines transparency.



UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 4 3   Background Scrolling   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  It seems there's quite a few questions regarding just how to go about
using Register $2005 (see Section #6) to pan the background. I myself am
still having problems understanding just exactly how this register works.
But, thanks to Pat Mccomack, there is a small explanation which I'll
post here so that those who're having problems can hopefully make use of
this information:

  Horizontal Scrolling             Vertical Scrolling
     0          512
     UŽŽŽŽŽAŽŽŽŽŽ¨                      UŽŽŽŽŽ¨0
     3     3     3                      3     3
     3  A  3  B  3                      3  A  3
     3     3     3                      3     3
     AŽŽŽŽŽAŽŽŽŽŽU                      AŽŽŽŽŽ'
                                        3     3
                                        3  B  3
                                        3     3
                                        AŽŽŽŽŽU512

  Name Table "A" is specified via Bits #0-1 in $2000 (see Section #6),
and "B" is the next to "A", since it's based on mirroring. This doesn't
work for game which use Horizontal & Vertical scrolling at the same time.
Possibly the four-screen VRAM layout fixes this.

  "This stuff is used in smb1 (horizontal scrolling) but it's probably the
same way with other games. Scrolling seems to be scanline based, ie during
refresh the game can write different values to the scroll register (usually
they do this when they detect the sprite 0 hit via reg $2002).  The scroll-
ing screen layout also can change.  With horizontal scrolling, the name
table at the first screen (0-255) is the one specified in reg $2000, and
the name table for the second screen (256-512) is the opposite of the first
one, based on mirroring I guess."

  Thanks for providing this information, Pat. :-)



UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 5 3   Interrupts   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  The 6502 has four interrupts: ABORT, IRQ/BRK, NMI, and RESET.

  Each interrupt has it's own vector, usually pointing to some code
to be executed. A vector is a 16-bit address which specifies a location
to "jump to" when the interrupt is triggered.

  ABORT is not controllable via software, and is a hardware interrupt
which cannot be modified. It has no vector. If you're an emulator author,
don't worry about emulating ABORT, as it's a pin on the 6502 chip itself.

  IRQ/BRK is triggered when the 6502 executes the BRK instruction. BRK
can be used for many things, but is *RARELY* used, since it generally
puts the machine into a state of unhappiness. However, for you emulator
authors out there, be sure to emulate BRK correctly, as some games do
use BRK to force the jump at the IRQ/BRK vector. Super Nintendo (SNES)
games do this as well, but that's a different issue alltogether.

  NMI stands for Non-Maskable Interrupt, and is generated by each
refresh (VBlank/VBL), which occurs at different intervals depending upon
the system used. The PAL version of the NES runs at a 50Hz (50 times/sec)
interval. The NTSC version runs at a 60Hz (60 times/sec) interval.

  RESET is triggered on power-up. The ROM is loaded into memory, and
the 6502 jumps to the address specified in the RESET vector.

  Back to the issue of NMI. NMI is only executed 50 times/sec. when
Bit #7 in $2000 (see Section #6) is set to 1. This tells the NES to
generate interrupts (or more specifically, execute NMI) everytime a
refresh occurs. Interrupt latency on the 6502 is seven (7) cycles; this
means it takes seven (7) cycles to move in and out of an interrupt.

  Most interrupts should return using the RTI instruction. Some NES carts
do not use this method, such as Final Fantasy 1. These carts return from
interrupts in a very odd fashion: by manipulating the stack by hand, and
then doing an RTS. This is technically valid, but morally is "bad." If
you're an emulator author, just be sure you implement all your opcodes
right and you should be fine. The game code will take care of the rest.

  The following interrupts have the following vector-points in ROM:

     UŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽ¨
     3 Vector 3 Interrupt 3
     AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
     3 $FFFA  3 NMI       3
     3 $FFFC  3 RESET     3
     3 $FFFE  3 IRQ/BRK   3
     AŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽU

  Here are the correct interrupt priority orders for the 6502:

     UŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽ¨
     3 Priority 3 Interrupt 3
     AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
     3 Highest  3 RESET     3
     3          3 NMI       3
     3 Lowest   3 IRQ/BRK   3
     AŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽU


UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 6 3   Registers   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  Address: The 16-bit address of the register (in ROM)
    Stats: Each register has different statistics and "aspects" to it.
           These stats are defined as follows:
               R = Register is readable.
               W = Register is writeable.
               2 = A "double-write" register.
               ? = Statistics are unknown, or are possibly wrong.
     Bits: Most registers have bits you can toggle on/off which do
           different things to the NES itself.
     [Label]: Labels I have assigned to each register (for programmers).

UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Stats 3 Bits     3 Description                       [Label]   3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $2000   3  W    3 vhzcpwNN 3 PPU Control Register #1           [PPUCNT0] 3
3         3       3          3                                             3
3         3       3          3  v = Execute NMI on VBlank                  3
3         3       3          3         0 = Disabled                        3
3         3       3          3         1 = Enabled                         3
3         3       3          3  h = Execute NMI on Sprite Hit              3
3         3       3          3         0 = Disabled                        3
3         3       3          3         1 = Enabled                         3
3         3       3          3  z = Sprite Size                            3
3         3       3          3         0 = 8x8                             3
3         3       3          3         1 = 8x16                            3
3         3       3          3  c = Screen Pattern Table Address           3
3         3       3          3         0 = $0000 (VRAM)                    3
3         3       3          3         1 = $1000 (VRAM)                    3
3         3       3          3  p = Sprite Pattern Table Address           3
3         3       3          3         0 = $0000 (VRAM)                    3
3         3       3          3         1 = $1000 (VRAM)                    3
3         3       3          3  w = PPU Address Read/Write Increment       3
3         3       3          3         0 = Increment by 1                  3
3         3       3          3         1 = Increment by 32                 3
3         3       3          3  N = Name Table Select                      3
3         3       3          3        00 = $2000 (VRAM)                    3
3         3       3          3        01 = $2400 (VRAM)                    3
3         3       3          3        10 = $2800 (VRAM)                    3
3         3       3          3        11 = $2C00 (VRAM)                    3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $2001   3  W    3 fffpcSIt 3 PPU Control Register #2           [PPUCNT1] 3
3         3       3          3                                             3
3         3       3          3  f = Full Background Colour                 3
3         3       3          3       000 = None   \                        3
3         3       3          3       001 = Red     \ Select one only       3
3         3       3          3       010 = Green   /                       3
3         3       3          3       100 = Blue   /                        3
3         3       3          3  p = Sprite Display                         3
3         3       3          3         0 = Hide sprites                    3
3         3       3          3         1 = Show sprites                    3
3         3       3          3  c = Screen Display                         3
3         3       3          3         0 = Off (screen off)                3
3         3       3          3         1 = On  (screen on)                 3
3         3       3          3  S = Sprite Clip                            3
3         3       3          3         0 = Don't show sprites in the left  3
3         3       3          3             8-pixel column                  3
3         3       3          3         1 = Show sprites everywhere         3
3         3       3          3  I = Image Clip                             3
3         3       3          3         0 = Don't show the left 8 pixels of 3
3         3       3          3             the screen                      3
3         3       3          3         1 = Show the left 8 pixels          3
3         3       3          3  t = Colour Display                         3
3         3       3          3         0 = Mono-tone display               3
3         3       3          3         1 = Colour display                  3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $2002   3 R     3 vhs00000 3 PPU Status Register               [PPUSTAT] 3
3         3       3          3                                             3
3         3       3          3  v = VBlank Occurance Flag                  3
3         3       3          3         0 = No VBlank                       3
3         3       3          3         1 = VBlank                          3
3         3       3          3  h = Hit Occurance Flag                     3
3         3       3          3         0 = No hit                          3
3         3       3          3         1 = Refresh has hit Sprite #0       3
3         3       3          3  s = Sprite Count Max                       3
3         3       3          3         0 = Less than 8 sprites on the      3
3         3       3          3             current scanline                3
3         3       3          3         1 = More than 8 sprites on the      3
3         3       3          3             current scanline                3
3         3       3          3                                             3
3         3       3          3 NOTE: Reading this register resets Bit 7,   3
3         3       3          3       also also resets the Background       3
3         3       3          3       Scroll Register bits as well.         3
3         3       3          3 NOTE: Bit 6 is reset to 0 at the beginning  3
3         3       3          3       of the next refresh.                  3
3         3       3          3 NOTE: Bit 6 is not set until the first      3
3         3       3          3       actual pixel (i.e. non-transparent)   3
3         3       3          3       is drawn. Therefore, if you have a    3
3         3       3          3       sprite (8x8) which has it's first 4   3
3         3       3          3       pixels as transparent, and it's 5th   3
3         3       3          3       as a non-transparent value, Bit 6     3
3         3       3          3       will be set after the 5th pixel is    3
3         3       3          3       found & drawn.                        3
3         3       3          3 NOTE: If Bit 5 is set, the PPU will NOT let 3
3         3       3          3       you write to VRAM.                    3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $2003   3  W    3 aaaaaaaa 3 Sprite Memory Address             [SPRADDR] 3
3         3       3          3                                             3
3         3       3          3  Specifies the address in Sprite RAM to     3
3         3       3          3  access via $2004 (see Section #9).         3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $2004   3  W    3 dddddddd 3 Sprite I/O Register                 [SPRIO] 3
3         3       3          3                                             3
3         3       3          3  Used to read/write to the address spec-    3
3         3       3          3  ified via $2003 in Sprite RAM.             3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $2005   3  W2   3 dddddddd 3 Background Scroll Register        [BGSCROL] 3
3         3       3          3                                             3
3         3       3          3  Used to scroll the screen vertically and   3
3         3       3          3  horizontally. This is a double-write       3
3         3       3          3  register.                                  3
3         3       3          3                                             3
3         3       3          3  BYTE 1: Horizontal Scroll                  3
3         3       3          3  BYTE 2: Vertical Scroll                    3
3         3       3          3                                             3
3         3       3          3  The scrolled data will span across multip- 3
3         3       3          3  le Name Tables. The layout is as follows:  3
3         3       3          3                                             3
3         3       3          3      UŽŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽ¨            3
3         3       3          3      3 #2 ($2800) 3 #3 ($2C00) 3            3
3         3       3          3      AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'            3
3         3       3          3      3 #0 ($2000) 3 #1 ($2400) 3            3
3         3       3          3      AŽŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽU            3
3         3       3          3                                             3
3         3       3          3 NOTE: If the Vertical Scroll value is >239, 3
3         3       3          3       it will be ignored. Some emulators    3
3         3       3          3       write 0 to the Vertical Scroll if     3
3         3       3          3       the value is >239.                    3
3         3       3          3 NOTE: Remember, there is only enough VRAM   3
3         3       3          3       for two (2) Name Tables.              3
3         3       3          3 NOTE: After a VBL occurs, the next write    3
3         3       3          3       will control the Horizontal Scroll.   3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $2006   3  W2   3 aaaaaaaa 3 PPU Memory Address                [PPUADDR] 3
3         3       3          3                                             3
3         3       3          3  Specifies the address in VRAM in which     3
3         3       3          3  data should be read from or written to.    3
3         3       3          3  This is a double-write register. The high- 3
3         3       3          3  byte of the 16-bit address is written      3
3         3       3          3  first, then the low-byte.                  3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $2007   3 RW    3 dddddddd 3 PPU I/O Register                    [PPUIO] 3
3         3       3          3                                             3
3         3       3          3  Used to read/write to the address spec-    3
3         3       3          3  ified via $2006 in VRAM.                   3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4000   3 RW    3 CChessss 3 Square Wave Control Register #1             3
3         3       3          3                                             3
3         3       3          3   C = Duty Cycle (Positive vs. Negative)    3
3         3       3          3        00 = 87.5%                           3
3         3       3          3        01 = 75.0%                           3
3         3       3          3        10 = 58.0%                           3
3         3       3          3        11 = 25.0%                           3
3         3       3          3   h = Hold Note                             3
3         3       3          3         0 = Don't hold note                 3
3         3       3          3         1 = Hold note                       3
3         3       3          3   e = Envelope Select                       3
3         3       3          3         0 = Envelope Vary                   3
3         3       3          3         1 = Envelope Fixed                  3
3         3       3          3   s = Playback Rate                         3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4001   3 RW    3 fsssHrrr 3 Square Wave Control Register #2             3
3         3       3          3                                             3
3         3       3          3   f = Frequency Fixed/Variable Select       3
3         3       3          3          0 = Fixed  (bits 0-6 disabled)     3
3         3       3          3          1 = Variable (bits 0-6 enabled)    3
3         3       3          3   s = Frequency Change Speed                3
3         3       3          3   H = Low/High Frequency Select             3
3         3       3          3          0 = Low -> High                    3
3         3       3          3          1 = High -> Low                    3
3         3       3          3   r = Frequency Range (0=Min, 7=Max)        3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4002   3 RW    3 dddddddd 3 Square Wave Frequency Value Register #1     3
3         3       3          3                                             3
3         3       3          3   d = Frequency Value Data (lower 8-bits)   3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4003   3 RW    3 tttttddd 3 Square Wave Frequency Value Register #2     3
3         3       3          3                                             3
3         3       3          3   d = Frequency Value Data (upper 3-bits)   3
3         3       3          3   t = Active Time Length                    3
3         3       3          3                                             3
3         3       3          3 NOTE: The Frequency Value is a full 11-bits 3
3         3       3          3       in size; be aware you will need to    3
3         3       3          3       write the upper 3-bits to $4003.      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4004   3 RW    3 CChessss 3 Square Wave Control Register #1             3
3         3       3          3                                             3
3         3       3          3   C = Duty Cycle (Positive vs. Negative)    3
3         3       3          3        00 = 87.5%                           3
3         3       3          3        01 = 75.0%                           3
3         3       3          3        10 = 58.0%                           3
3         3       3          3        11 = 25.0%                           3
3         3       3          3   h = Hold Note                             3
3         3       3          3         0 = Don't hold note                 3
3         3       3          3         1 = Hold note                       3
3         3       3          3   e = Envelope Select                       3
3         3       3          3         0 = Envelope Vary                   3
3         3       3          3         1 = Envelope Fixed                  3
3         3       3          3   s = Playback Rate                         3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4005   3 RW    3 fsssHrrr 3 Square Wave Control Register #2             3
3         3       3          3                                             3
3         3       3          3   f = Frequency Fixed/Variable Select       3
3         3       3          3          0 = Fixed  (bits 0-6 disabled)     3
3         3       3          3          1 = Variable (bits 0-6 enabled)    3
3         3       3          3   s = Frequency Change Speed                3
3         3       3          3   H = Low/High Frequency Select             3
3         3       3          3          0 = Low -> High                    3
3         3       3          3          1 = High -> Low                    3
3         3       3          3   r = Frequency Range (0=Min, 7=Max)        3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4006   3 RW    3 dddddddd 3 Square Wave Frequency Value Register #1     3
3         3       3          3                                             3
3         3       3          3   d = Frequency Value Data (lower 8-bits)   3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4007   3 RW    3 tttttddd 3 Square Wave Frequency Value Register #2     3
3         3       3          3                                             3
3         3       3          3   d = Frequency Value Data (upper 3-bits)   3
3         3       3          3   t = Active Time Length                    3
3         3       3          3                                             3
3         3       3          3 NOTE: The Frequency Value is a full 11-bits 3
3         3       3          3       in size; be aware you will need to    3
3         3       3          3       write the upper 3-bits to $4007.      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4008   3 RW    3 CChessss 3 Triangle Wave Control Register #1           3
3         3       3          3                                             3
3         3       3          3   C = Duty Cycle (Positive vs. Negative)    3
3         3       3          3        00 = 87.5%                           3
3         3       3          3        01 = 75.0%                           3
3         3       3          3        10 = 58.0%                           3
3         3       3          3        11 = 25.0%                           3
3         3       3          3   h = Hold Note                             3
3         3       3          3         0 = Don't hold note                 3
3         3       3          3         1 = Hold note                       3
3         3       3          3   e = Envelope Select                       3
3         3       3          3         0 = Envelope Vary                   3
3         3       3          3         1 = Envelope Fixed                  3
3         3       3          3   s = Playback Rate                         3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4009   3 RW    3 fsssHrrr 3 Triangle Wave Control Register #2           3
3         3       3          3                                             3
3         3       3          3   f = Frequency Fixed/Variable Select       3
3         3       3          3          0 = Fixed  (bits 0-6 disabled)     3
3         3       3          3          1 = Variable (bits 0-6 enabled)    3
3         3       3          3   s = Frequency Change Speed                3
3         3       3          3   H = Low/High Frequency Select             3
3         3       3          3          0 = Low -> High                    3
3         3       3          3          1 = High -> Low                    3
3         3       3          3   r = Frequency Range (0=Min, 7=Max)        3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $400A   3 RW    3 dddddddd 3 Triangle Wave Frequency Value Register #1   3
3         3       3          3                                             3
3         3       3          3   d = Frequency Value Data (lower 8-bits)   3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $400B   3 RW    3 tttttddd 3 Triangle Wave Frequency Value Register #2   3
3         3       3          3                                             3
3         3       3          3   d = Frequency Value Data (upper 3-bits)   3
3         3       3          3   t = Active Time Length                    3
3         3       3          3                                             3
3         3       3          3 NOTE: The Frequency Value is a full 11-bits 3
3         3       3          3       in size; be aware you will need to    3
3         3       3          3       write the upper 3-bits to $400B.      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $400C   3 RW    3 CChessss 3 Noise Control Register #1                   3
3         3       3          3                                             3
3         3       3          3   C = Duty Cycle (Positive vs. Negative)    3
3         3       3          3        00 = 87.5%                           3
3         3       3          3        01 = 75.0%                           3
3         3       3          3        10 = 58.0%                           3
3         3       3          3        11 = 25.0%                           3
3         3       3          3   h = Hold Note                             3
3         3       3          3         0 = Don't hold note                 3
3         3       3          3         1 = Hold note                       3
3         3       3          3   e = Envelope Select                       3
3         3       3          3         0 = Envelope Vary                   3
3         3       3          3         1 = Envelope Fixed                  3
3         3       3          3   s = Playback Rate                         3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $400D   3 RW    3 fsssHrrr 3 Noise Control Register #2                   3
3         3       3          3                                             3
3         3       3          3   f = Frequency Fixed/Variable Select       3
3         3       3          3          0 = Fixed  (bits 0-6 disabled)     3
3         3       3          3          1 = Variable (bits 0-6 enabled)    3
3         3       3          3   s = Frequency Change Speed                3
3         3       3          3   H = Low/High Frequency Select             3
3         3       3          3          0 = Low -> High                    3
3         3       3          3          1 = High -> Low                    3
3         3       3          3   r = Frequency Range (0=Min, 7=Max)        3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $400E   3 RW    3 dddddddd 3 Frequency Value Register #1                 3
3         3       3          3                                             3
3         3       3          3   d = Frequency Value Data (lower 8-bits)   3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $400F   3 RW    3 tttttddd 3 Frequency Value Register #2                 3
3         3       3          3                                             3
3         3       3          3   d = Frequency Value Data (upper 3-bits)   3
3         3       3          3   t = Active Time Length                    3
3         3       3          3                                             3
3         3       3          3 NOTE: The Frequency Value is a full 11-bits 3
3         3       3          3       in size; be aware you will need to    3
3         3       3          3       write the upper 3-bits to $400F.      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4010   3 RW    3 CChessss 3 PCM Control Register #1                     3
3         3       3          3                                             3
3         3       3          3   C = Duty Cycle (Positive vs. Negative)    3
3         3       3          3        00 = 87.5%                           3
3         3       3          3        01 = 75.0%                           3
3         3       3          3        10 = 58.0%                           3
3         3       3          3        11 = 25.0%                           3
3         3       3          3   h = Hold Note                             3
3         3       3          3         0 = Don't hold note                 3
3         3       3          3         1 = Hold note                       3
3         3       3          3   e = Envelope Select                       3
3         3       3          3         0 = Envelope Vary                   3
3         3       3          3         1 = Envelope Fixed                  3
3         3       3          3   s = Playback Rate                         3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4011   3 RW    3 vvvvvvvv 3 PCM Volume Control Register                 3
3         3       3          3                                             3
3         3       3          3   v = Volume                                3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4012   3 RW    3 aaaaaaaa 3 PCM Address Register                        3
3         3       3          3                                             3
3         3       3          3   a = Address                               3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4013   3 RW    3 LLLLLLLL 3 PCM Data Length Register                    3
3         3       3          3                                             3
3         3       3          3   L = Data Size/Length                      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4014   3  W    3          3 Sprite DMA                         [SPRDMA] 3
3         3       3          3                                             3
3         3       3          3  Transfers 256 bytes of memory at address   3
3         3       3          3  $100*N, where N is the value written to    3
3         3       3          3  this register, into Sprite RAM.            3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4015   3 RW    3 000abcde 3 Sound Control Register             [SNDCNT] 3
3         3       3          3                                             3
3         3       3          3  e = Channel 1  (0=Disable, 1=Enable)       3
3         3       3          3  d = Channel 2  (0=Disable, 1=Enable)       3
3         3       3          3  c = Channel 3  (0=Disable, 1=Enable)       3
3         3       3          3  b = Channel 4  (0=Disable, 1=Enable)       3
3         3       3          3  a = Channel 5  (0=Disable, 1=Enable)       3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4016   3 RW    3 ???STeed 3 Joypad #1                         [SPECIO1] 3
3         3       3          3 [READING]                                   3
3         3       3          3                                             3
3         3       3          3  S = Zapper sprite detection                3
3         3       3          3         0 = Sprite not detected             3
3         3       3          3         1 = Sprite detected in front of     3
3         3       3          3             crosshair                       3
3         3       3          3  T = Zapper trigger                         3
3         3       3          3         0 = Pressed                         3
3         3       3          3         1 = Not pressed                     3
3         3       3          3  e = Expansion Port Data                    3
3         3       3          3  d = Joypad Data (see Section #8)           3
3         3       3          AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3         3       3 ?????eej 3 [WRITING]                                   3
3         3       3          3                                             3
3         3       3          3  j = Joypad Strobe                          3
3         3       3          3         0 = Clear joypad strobe             3
3         3       3          3         1 = Reset joypad strobe             3
3         3       3          3                                             3
3         3       3          3  e = Expansion Port Data                    3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $4017   3 R     3 ?????eed 3 Joypad #2                         [SPECIO2] 3
3         3       3          3 [READING]                                   3
3         3       3          3                                             3
3         3       3          3  e = Expansion Port Data                    3
3         3       3          3  d = Joypad Data (see Section #8)           3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU



UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 7 3   VBL/Hit Bits   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

   The VBlank flag is contained in the 7th bit of read-only location $2002.
It indicates whether PPU is scanning the screen, or generating a vertical
blanking impulse. It is set in the end of each frame (scanline 232), and
stays on until the next screen refresh starts from scanline 8. The pro-
gram can reset this bit prematurely by reading $2002.

   The Hit Flag is contained in the 6th bit of read-only location $2002. 
It goes to 1 when PPU starts refreshing the first scanline where sprite#0
is located. For example, if sprite#0's Y coordinate is 34, the Hit flag
will be set in scanline 34. The Hit flag is reset when vertical blanking
impulse starts. The program can reset this bit prematurely by reading from
$2002.



UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 8 3   Joypad/Zapper   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  There are two joysticks which are accessed via locations $4016 and
$4017. To reset joysticks, write first 1, then 0 into $4016. This way, you
will generate a strobe in the joysticks' circuitry. Then, read either from
$4016 (for joystick 0) or from $4017 (for joystick 1).  Each read will
give you the status of a single button in the 0th bit (1 if pressed, 0
otherwise): 

  UŽŽŽŽŽŽŽŽAŽŽŽŽŽAŽŽŽŽŽAŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽAŽŽŽŽŽŽAŽŽŽŽŽŽAŽŽŽŽŽŽŽ¨
  3 Read # 3  1  3  2  3   3    3   4   3 5  3  6   3  7   3   8   3
  AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
           3  A  3  B  3 SELECT 3 START 3 UP 3 DOWN 3 LEFT 3 RIGHT 3
           AŽŽŽŽŽAŽŽŽŽŽAŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽAŽŽŽŽŽŽAŽŽŽŽŽŽAŽŽŽŽŽŽŽU

  Bit 1 indicates whether joystick is connected to the port or not. It is
set to 0 if the joystick is connected, 1 if not. Bits 6 and 7 of $4016
and $4017 also seem to have some significance, which is not clear yet.
The rest of bits is set to zeroes. Some games expect to get *exactly* $41
from $4016/$4017, if a button is pressed, which has to be taken into
account. 

  For Zapper (Light Gun) information, see Section #6.



UŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 9 3   Sprites   3
AŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽU

  There are 64 sprites, which can be either 8x8 or 8x16 pixels. Sprites
patterns are stored in on of the Pattern Tables in the PPU Memory. Sprite
attributes are stored in the Sprite RAM of 256 bytes, which is not a
part of neither CPU nor PPU address space. The entire contents of Sprite
Memory can be written via DMA (see Section #6). Sprite RAM can also be
accessed byte-by-byte by putting the starting address into $2003 and then
writing/reading $2004 (the address will auto-increment). The format of
Sprite RAM is as follows:

UŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Sprite #0 3 Sprite #1 3 ... 3 Sprite #62 3 Sprite #63 3
AŽŽŽŽŽAŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽU
      3    UŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
      AŽŽŽŽ' Byte # 3 Bits     3 Description                             3
           AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
           3   0    3 YYYYYYYY 3 Sprite Y coordinate - 1. Consider the   3
           3        3          3 coordinate the upper-left corner of     3
           3        3          3 the sprite itself.                      3
           3   1    3 IIIIIIII 3 Sprite Tile Index #                     3
           3   2    3 vhp000cc 3 Colour/Attributes                       3
           3        3          3  v = Vertical Flip   (1=Flip)           3
           3        3          3  h = Horizontal Flip (1=Flip)           3
           3        3          3  p = Sprite Priority Bit                3
           3        3          3         0 = Sprite on top of background 3
           3        3          3         1 = Sprite behind background    3
           3        3          3  c = Upper two (2) bits of colour       3
           3   3    3 XXXXXXXX 3 Sprite X coordinate (upper-left corner) 3
           AŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  The Sprite Tile Index # is obtained the same way as Tile Index #s are
in regards to the Name Table (background) picture.

  For 8x16 sprites, the Pattern Table is at $0000 in VRAM, containing 256
8x16 tiles. Bit #3 of $2000 (see Section #6) has no effect on 8x16 sprites.
The Sprite Tile Index # in the Sprite Attribute RAM is rotated right
one (1) bit by the PPU, when drawing. Therefore, a Tile Index # $01 will
draw tile #128, $02 would draw tile #1, $03 would draw tile #129, etc..

  The Sprite Priority bit works as follows: Sprites with a lower Sprite
Tile Index # will have a higher priority (e.g. #0 will be drawn over #1).

  Only eight (8) sprites can be displayed per scan-line. Each Sprite entry
in Sprite RAM is checked to see if it's in a horizontal range with the
other sprites. Remember, this is done on a per scan-line basis, not on a
per sprite basis (e.g. this is done 256 times, not 256/8 or 256/16 times).



UŽŽŽŽAŽŽŽŽŽŽŽŽŽŽ¨
3 10 3   MMCs   3
AŽŽŽŽAŽŽŽŽŽŽŽŽŽŽU

  Each reference number below (e.g. "3)" or "1)") is the iNES Mapper
number. The actual MMC title is printed after, if one is available. Do not
get these confused.


1) Nintendo MMC1

  This mapper is commonly used in 256K carts, such as Bomberman 2,
Destiny Of The Emperor, Megaman 2, Airwolf, Operation Wolf, Castlevania 2,
SilkWorm, and others. It may be used to switch PRG-ROM and CHR-RAM.  This
MMC also supports WRAM.

  MMC1 has four (4) 8 bit registers, which are accessed via following
addresses:

UŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Reg # 3 Range 3 Bits     3 Description                                3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3   0   3 $8000 3 ???sBKpm 3 Mapper Control Register #1                 3
3       3  ...  3          3                                            3
3       3 $9FFF 3          3  s = Size Select                           3
3       3       3          3         0 = Select 8K CHR-RAM at $0000     3
3       3       3          3         1 = Swap 4K at $0000 and $1000     3
3       3       3          3  B = Base Bootup Select                    3
3       3       3          3         0 = $8000 (Note: This is probably  3
3       3       3          3         1 = $C000        incorrect!)       3
3       3       3          3  K = Bank Size                             3
3       3       3          3         0 = 16K                            3
3       3       3          3         1 = 32K                            3
3       3       3          3  p = Panning/Scrolling Enable/Disable      3
3       3       3          3         0 = Enabled                        3
3       3       3          3         1 = Disabled                       3
3       3       3          3  m = Mirror Select                         3
3       3       3          3         0 = Horizontal Mirroring           3
3       3       3          3         1 = Vertical Mirroring             3
3       3       3          3                                            3
3       3       3          3 NOTE: Bit #1, when set to 1, actually just 3
3       3       3          3       mirrors Name Table #0 throughout all 3
3       3       3          3       the other Name Tables.               3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3   1   3 $A000 3 ssssssss 3 CHR-RAM Page Selection Register            3
3       3  ...  3          3                                            3
3       3 $BFFF 3          3  Sets the CHR-RAM page at $0000, with the  3
3       3       3          3  size selected via Register #0.            3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3   2   3 $C000 3 ssssssss 3 CHR-RAM 4K Page Selection Register         3
3       3  ...  3          3                                            3
3       3 $DFFF 3          3  Sets the 4K CHR-RAM page at $1000, but    3
3       3       3          3  only if 4K CHR-RAM pages are selected via 3
3       3       3          3  Register #0 (otherwise ignored).          3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3   3   3 $E000 3 ssssssss 3 PRG-ROM 16K Page Selection Register        3
3       3  ...  3          3                                            3
3       3 $FFFF 3          3  Sets the 16K ROM page at $8000. The page  3
3       3       3          3  at $C000 is hardwired to the last ROM     3
3       3       3          3  page in the cart. Page 0 starts at $8000. 3
AŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

   Before writing to a mapper register for the first time, you need to reset
it by setting bit #7 in each address range base ($8000, $A000, $C000, and
$E000) before writing data to each address range itself. Once you've
done this, you may write the value bit by bit to the appropriate address
range. For example, the following code will write $0C into register 3:

     lda  #%10000000
     sta  $8000      ; Resetting range #0
     sta  $A000      ; Resetting range #1
     sta  $C000      ; Resetting range #2
     sta  $E000      ; Resetting range #3
     lda  #$0C       ; This is our value
     sta  $EFD9      ; Writing bit 0
     lsr  a          ; Shifting
     sta  $EFD9      ; Writing bit 1
     lsr  a          ; Shifting
     sta  $EFD9      ; Writing bit 2
     lsr  a          ; Shifting
     sta  $EFD9      ; Writing bit 3
     lsr  a          ; Shifting
     sta  $EFD9      ; Writing bit 4


2) 74HC161/74HC32 Mapper

  This is a quite simple mapper used in most Konami (Life Force,
Castlevania, Metal Gear) and some other cartridges (Ghosts & Goblins). It
only switches the ROM. All cartridges with this mapper have 8kB CHR-RAM
at $0000. The mapper has a single 8 bit register which can be written via
locations $8000-$FFFF. It contains a number of 16K PRG-ROM page at $8000.
The page at $C000 is always hardwired to the last ROM page in the cart.
The cartridge starts with page 0 at $8000.


3) VROM Switch

  This mapper is used in the Goonies series and many Japanese-only games.
It only allows you to switch 8kB pages of CHR-ROM. The PRG-ROM is either
16K or 32K and is not paged. The mapper has a single 8-bit register which
can be written via locations $8000-$FFFF. It contains a number of the 8K
CHR-ROM page at $0000.


4) Nintendo MMC3

  This MMC is used in many recent cartridges, such as: Batman Returns,
Super Contra, Vindicators, Silver Surfer, Crystalis, Legacy of the Wizard,
and others. This MMC is able to generate it's own interrupts via the IRQ
line, and has a set of commands to switch PRG-ROM and CHR-RAM. CHR-RAM
pages are 1K, PRG-ROM are 8K.


  NOTE: The ROM pages at $C000 and $E000 are hardwired to the last pages
of the ROM, and are not switchable. However, they can be swapped via $E000
though.

UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Stats 3 Bits     3 Description                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $8000   3  W ?  3 as???ddd 3 Function Select Register                    3
3         3       3          3                                             3
3         3       3          3    a = CHR-RAM Base Address Select          3
3         3       3          3         0 = $0000                           3
3         3       3          3         1 = $1000                           3
3         3       3          3    s = CHR-RAM Page Base Select (CMDs 6/7)  3
3         3       3          3         0 = Select $8000 and $A000          3
3         3       3          3         1 = Select $A000 and $C000          3
3         3       3          3  ddd = Function # (0-7)                     3
3         3       3          3                                             3
3         3       3          3 NOTE: Writing to this register resets       3
3         3       3          3       changes made to the $E000 register.   3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $8001   3  W    3 dddddddd 3 Page Number Select Register                 3
3         3       3          3                                             3
3         3       3          3  This register selects the page # to be     3
3         3       3          3  read from (or written to).                 3
3         3       3          3                                             3
3         3       3          3 NOTE: When using CMD 0, Bit #0 of this reg- 3
3         3       3          3       ister is ignored. Therefore, a value  3
3         3       3          3       of 5 will select pages 4 & 5).        3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $A000   3  W    3 ???????m 3 Shadow Select Register                      3
3         3       3          3                                             3
3         3       3          3  m = Shadowing                              3
3         3       3          3         0 = Vertical                        3
3         3       3          3         1 = Horizontal                      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $A001   3  W ?  3 p??????? 3 Pattern Table Control Register              3
3         3       3          3                                             3
3         3       3          3  p = Pattern Table Enable/Disable           3
3         3       3          3         0 = Disable use of $0000-$1FFF in   3
3         3       3          3             VRAM                            3
3         3       3          3         1 = Enable use of $0000-$1FFF in    3
3         3       3          3             VRAM                            3
3         3       3          3                                             3
3         3       3          3 NOTE: Information here could possibly be    3
3         3       3          3       incorrect.                            3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $C000   3       3 dddddddd 3 IRQ Decrement Register                      3
3         3       3          3                                             3
3         3       3          3  A value (1-255) is written here. The chip  3
3         3       3          3  auto-decrements this value at every scan-  3
3         3       3          3  line. Once 0 is hit, IRQ/BRK is executed.  3
3         3       3          3  If 0 is stored, then this feature is dis-  3
3         3       3          3  abled.                                     3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $C001   3  W    3          3 Temporary Latch Register                    3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $E000   3  W    3          3 IRQ Control Register #1                     3
3         3       3          3                                             3
3         3       3          3  Any writes which occur to this register    3
3         3       3          3  will cause the value written to $C001 to   3
3         3       3          3  be copied into $C000. IRQs are also dis-   3
3         3       3          3  abled as well.                             3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $E001   3  W    3          3 IRQ Control Register #2                     3
3         3       3          3                                             3
3         3       3          3  Any writes to this register enable IRQs.   3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  In order to make the MMC function, you must first write a Command Number
(CMD #) into $8000, and then a value (Page Number) into $8001. The follow-
ing CMDs exist:

UŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 CMD # 3 Address 3 Description                                            3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3   0   3 $0000   3 Selects two (2) 1K CHR-RAM pages at the Address.       3
3   1   3 $0800   3 Selects two (2) 1K CHR-RAM pages at the Address.       3
3   2   3 $1000   3 Selects one (1) 1K CHR-RAM pages at the Address.       3
3   3   3 $1400   3 Selects one (1) 1K CHR-RAM pages at the Address.       3
3   4   3 $1800   3 Selects one (1) 1K CHR-RAM pages at the Address.       3
3   5   3 $1C00   3 Selects one (1) 1K CHR-RAM pages at the Address.       3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3   6   3 N/A     3 Selects one (1) 8K PRG-ROM Page at the CHR-RAM Page    3
3       3         3 Base Select. Initial value is 0.                       3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3   7   3 N/A     3 Selects one (1) 8K PRG-ROM Page at the CHR-RAM Page    3
3       3         3 Base Select. Initial value is 1.                       3
AŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  NOTE: For CMDs 0-5, see MMC Register $8001. For CMDs 6-7, see MMC Reg-
ister $8000.

  NOTE: Address is really "CHR-RAM Base Address XOR (Address)". Therefore,
if the CHR-RAM Base Address is set to $1000, then using CMD #4 would
result in a transfer to $2800 in VRAM.


5) Nintendo MMC5

  This mapper is used in Castlevania III. It supports a four-screen Name
Table layout, allowing four (4) physical Name Tables to be used.

  This mapper supports a 1K section of external RAM (EXRAM), which is
mapped to $5C00-$5FFF. EXRAM holds one (1) byte corrisponding to each of
the 960 8x8 tiles. The format of an EXRAM byte is:

UŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Bits     3 Description                                     3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 ccIIIIII 3 c = Colour Expansion                            3
3          3                                                 3
3          3       Used to remove the annoying 4x4 tile      3
3          3       Attribute Bit limitation. Using these     3
3          3       bits is optional.                         3
3          3                                                 3
3          3 I = Index Expansion                             3
3          3                                                 3
3          3       Extends the maximum Index Tile #s from    3
3          3       256 to 16384 (8-bits to 14-bits), by      3
3          3       using these six (6) in the Name Table,    3
3          3       e.g.:                                     3
3          3                                                 3
3          3        IIIIIInnnnnnnn                           3
3          3        AŽŽAŽUAŽŽŽAŽŽU                           3
3          3           3      AŽŽŽ Name Table                3
3          3           AŽŽŽŽŽŽŽŽŽŽ Index Expansion           3
AŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  A register at $5104 can control whether the CPU can write to EXRAM or
not, and also controls if the Colour Expansion bits in the EXRAM are used
or not

  It also seems MMC5 has a register which can flip between Vertical and
Horizontal mirroring. This register is definitely used in Castlevania III.


6) FFE F4xxx Mapper

  (Thanks to FanWen for this information!)

  This mapper allows swapping of PRG-ROM, and supports four (4) Pattern
Tables. This mapper was invented by FFE (Front Far East), and seems to
only be used on F4xxx-style games, such as the famous Wai Wai World
("Konami World"), and others. It also supports IRQ and counter registers,
resembling that of Nintendo's MMC3.

  Two styles of data can be written here, but most of the time, the format
of the more commonly used data (used in "Wai Wai World") is:

UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Stats 3 Bits     3 Description                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $42FC   3  W    3 pppppppp 3 PRG-ROM Write Enable                        3
3 $42FD   3  W    3 mmmmmmmm 3 Mirroring Write Enable                      3
3 $42FE   3  W    3 ???p???? 3 PRG-ROM Swap                                3
3 $42FF   3  W    3 ???m???? 3 Mirroring Select                            3
3         3       3          3    m = Mirroring Select                     3
3         3       3          3        0 = Vertical                         3
3         3       3          3        1 = Horizontal                       3
3 $43FE   3  W    3 CCCCCCpp 3 4mb PRG-ROM/CHR-RAM Select                  3
3 $4500   3 RW    3 eXssWPPP 3 Configuration Register                      3
3         3       3          3    e = Disk/Cart Mode                       3
3         3       3          3          0 = Famicom Disk game              3
3         3       3          3          1 = Famicom cart                   3
3         3       3          3    X = Execute Mode                         3
3         3       3          3          0 = Do nothing                     3
3         3       3          3          1 = Execute game                   3
3         3       3          3    s = SRAM Availability                    3
3         3       3          3          0 = Not used                       3
3         3       3          3          1 = SRAM used                      3
3         3       3          3    W = SW Pin                               3
3         3       3          3  PPP = PPU Mode                             3
3         3       3          3        010 = 256K                           3
3         3       3          3        101 = 2M + Extended VRAM             3
3         3       3          3        111 = 2M                             3
3 $4501   3  W    3 iiiiiiii 3 IRQ Disable                                 3
3 $4502   3  W    3 iiiiiiii 3 IRQ Increment Register (low byte)           3
3 $4503   3  W    3 iiiiiiii 3 IRQ Enable & Increment Register (high byte) 3
3 $8000   3 RW    3 00ppppCC 3 PRG-ROM/CHR-RAM Control Register            3
3 $A000   3       3          3                                             3
3 $C000   3       3          3    p = 16K PRG-ROM Select                   3
3 $E000   3       3          3         Selects 16K PRG-ROM bank at $8000   3
3         3       3          3   CC = Pattern Table Select                 3
3         3       3          3         Selects Pattern Table #0-3          3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  The support of an IRQ counter is very similar to that of MMC3, except
that it is incremented and not decremented. When the value reaches $FFFF,
it will be reset to $0000. To enable the use of the IRQ counter, store
the value $0000 into $4503.

  This mapper also supports the use of a trainer. The trainer is loaded at
$7000-71FF. Each described item below is actual 6502 code, and not a
vector (e.g. JMP $xxxx). The address itself *IS* the vector.

UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Description                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $7000   3 NMI                                         3
3 $7003   3 Game Setup code                             3
3 $7006   3 Mirroring Switch                            3
3 $7009   3 Other trainer routines                      3
3  ...    3                                             3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  NOTE: It seems most these images are purely PRG-ROM; i.e. no CHR-RAM. All
the CHR-RAM is kept inside the PRG-ROM, which is swapped in and out during
runtime via the MMC.

  The documentation here is still not complete; for a more accurate and
detailed documentation, please check out FanWen's document regarding
Mapper #6 via this URLL

  http://nesdev.parodius.com/mapper6.txt


7) ROM Switch

   This mapper is used in Wizards & Warriors (1 & 2) and Deadly Towers.

   Writes to $8000-$FFFF select the 32K PRG-ROM bank at $8000. Bit #4
controls which Name Table and Attribute Table to use; the other Name Tables
and Attribute Tables mirror the table selected using Bit #4.


8) FFE F3xxx Mapper

   No information is currently available.


9) Nintendo MMC2

  This MMC is used in the American version of the "Mike Tyson's Punch-Out!"
cart. It supports switching of PRG-ROM and CHR-RAM.

  All PRG-ROM banks are 8K (vs. 16K) in size, with a base ROM address of
$8000. CHR-RAM banks appear to be 4K in size, 

UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Stats 3 Bits     3 Description                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $A000   3  W    3 dddddddd 3 PRG-ROM 8K Page Select Register             3
3  ...    3       3          3                                             3
3 $AFFF   3       3          3    d = 8K PRG-ROM Select                    3
3         3       3          3         Selects 8K PRG-ROM bank at $8000.   3
3         3       3          3                                             3
3 $B000   3  W    3 dddddddd 3 CHR-RAM 4K Page Select Register #1          3
3 $C000   3       3          3                                             3
3         3       3          3    d = 4K CHR-RAM Select                    3
3         3       3          3         Selects 4K CHR-RAM bank at VRAM     3
3         3       3          3         address $0000.                      3
3         3       3          3                                             3
3 $D000   3  W    3 dddddddd 3 CHR-RAM 4K Page Select Register #2          3
3 $E000   3       3          3                                             3
3         3       3          3    d = 4K CHR-RAM Select                    3
3         3       3          3         Selects 4K CHR-RAM bank at VRAM     3
3         3       3          3         address $1000.                      3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  The last three (3) PRG-ROM banks in the cart itself are hardwired to the
last three (3) 8K sections of ROM. For instance, in the case of "Mike
Tyson's Punch-Out!" which has sixteen (16) 8K PRG-ROM banks, PRG-ROM
bank #13, #14, and #15 would be mapped to $A000, $C000, and $E000, respec-
tively.

  NOTE: The CHR-RAM 4K Page Select Register seem to work in congruency;
by this I mean, when data is written to $B000, $D000 will function, but
$E000 will not (and therefore, the same rules apply to $C000/$E000 where
$D000 will not work).


10) [Unused]

11) Color Dreams Mapper

  This mapper is commonly used in Color Dreams games, but not all of
them will function correctly when using this mapper.

  PRG-ROM banks are 32K in size, and CHR-RAM banks are 8K.

UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Stats 3 Bits     3 Description                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $8000   3  W    3 CCCCpppp 3 PRG-ROM/CHR-RAM Page Select Register        3
3  ...    3       3          3                                             3
3 $FFFF   3       3          3    C = 8K CHR-RAM Select                    3
3         3       3          3         Selects 8K CHR-RAM bank at VRAM     3
3         3       3          3         address $0000.                      3
3         3       3          3    p = 32K PRG-ROM Select                   3
3         3       3          3         Selects 32K PRG-ROM bank at $8000.  3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU


12) [Unused]

13) [Unused]

14) [Unused]

15) 100-in-1 Mapper

   NOTE: Assume ROM16k[] is an array of 16K PRG-ROM Banks.
   NOTE: Unlike other MMCs, the 16K of PRG-ROM loaded into $C000 on startup
         is the second 16K PRG-ROM page, not the last 16K PRG-ROM page.

UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Stats 3 Bits     3 Description                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $8000   3  W ?  3 smNNNNNN 3 PRG-ROM Control Register #1                 3
3         3       3          3                                             3
3         3       3          3    s = Swap 8K Pages                        3
3         3       3          3         Swaps 8K at $8000 and $A000         3
3         3       3          3         Swaps 8K at $C000 and $E000         3
3         3       3          3    m = Mirroring Control                    3
3         3       3          3         0 = Vertical                        3
3         3       3          3         1 = Horizontal                      3
3         3       3          3    N = PRG-ROM Page Select                  3
3         3       3          3         $8000 now holds ROM16k[N]           3
3         3       3          3         $C000 now holds ROM16k[N+1]         3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $8001   3  W    3 s?NNNNNN 3 PRG-ROM Control Register #2                 3
3         3       3          3                                             3
3         3       3          3    s = Swap 8K Pages                        3
3         3       3          3         Swaps 8K at $C000 and $E000         3
3         3       3          3    N = PRG-ROM Page Select                  3
3         3       3          3         $C000 now holds ROM16k[N]           3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $8002   3  W    3 S?NNNNNN 3 PRG-ROM Control Register #3                 3
3         3       3          3                                             3
3         3       3          3    S = Upper/Lower 8K Select                3
3         3       3          3         0 = Select Lower 8K of 16K segment  3
3         3       3          3         1 = Select Upper 8K of 16K segment  3
3         3       3          3    N = 8K PRG-ROM Page Select               3
3         3       3          3         $8000 now holds ROM16k[N]           3
3         3       3          3         $A000 now holds ROM16k[N]           3
3         3       3          3         $C000 now holds ROM16k[N]           3
3         3       3          3         $E000 now holds ROM16k[N]           3
3         3       3          3                                             3
3         3       3          3 NOTE: Bit 7 handles only Bits 0-5 of this   3
3         3       3          3       register, and does not affect any     3
3         3       3          3       other registers.                      3
3         3       3          3                                             3
3         3       3          3 NOTE: Bits 0-5 base their 8K Selection on   3
3         3       3          3       Bit 7. Keep this in mind.             3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $8003   3  W    3 smNNNNNN 3 PRG-ROM Control Register #4                 3
3         3       3          3                                             3
3         3       3          3    s = Swap 8K Pages                        3
3         3       3          3         Swaps 8K at $C000 and $E000         3
3         3       3          3    m = Mirroring Control                    3
3         3       3          3         0 = Vertical                        3
3         3       3          3         1 = Horizontal                      3
3         3       3          3    N = ROM Page Select                      3
3         3       3          3         $C000 now holds ROM16k[N]           3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU


??) Nintendo MMC4

  (Thanks to FanWen for the information!)

  This MMC is used in the Japanese version of the "Mike Tyson's Punch-Out!"
cart. It supports switching of PRG-ROM and CHR-RAM.

  PRG-ROM banks are 16K in size, and CHR-RAM banks are 4K.

UŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Address 3 Stats 3 Bits     3 Description                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $A000   3  W    3 pppppppp 3 PRG-ROM Page Select Register                3
3         3       3          3                                             3
3         3       3          3    p = 32K PRG-ROM Select                   3
3         3       3          3         Selects 16K PRG-ROM bank at $8000.  3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $B000   3  W    3 CCCCCCCC 3 CHR-RAM Page Select Register #1             3
3         3       3          3                                             3
3         3       3          3    C = 4K CHR-RAM Select                    3
3         3       3          3         Selects 4K CHR-RAM bank at VRAM     3
3         3       3          3         address $0000.                      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $C000   3  W    3 CCCCCCCC 3 CHR-RAM Page Select Register #2             3
3         3       3          3                                             3
3         3       3          3    C = 4K CHR-RAM Select                    3
3         3       3          3         Selects 4K CHR-RAM bank at VRAM     3
3         3       3          3         address $1000.                      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $D000   3  W    3 CCCCCCCC 3 CHR-RAM Page Select Register #3             3
3         3       3          3                                             3
3         3       3          3    C = 4K CHR-RAM Select                    3
3         3       3          3         Selects 4K CHR-RAM bank at VRAM     3
3         3       3          3         address $0000.                      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $E000   3  W    3 CCCCCCCC 3 CHR-RAM Page Select Register #4             3
3         3       3          3                                             3
3         3       3          3    C = 4K CHR-RAM Select                    3
3         3       3          3         Selects 4K CHR-RAM bank at VRAM     3
3         3       3          3         address $1000.                      3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $F000   3  W    3 dddddddd 3 Mirroring Select Register                   3
3         3       3          3                                             3
3         3       3          3    d = Mirroring Select                     3
3         3       3          3         0 = Horizontal                      3
3         3       3          3         1 = Vertical                        3
AŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  This mapper has some very peculiar aspects, especially when it comes to
accessing VRAM. The CHR-RAM Page Select Registers listed above are auto-
matically "enabled" and "disabled" depending upon which address(es) in
VRAM you access.

UŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 VRAM Address Range 3 Description                                 3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 $0FD8-0FDF         3 Switches VRAM $0000-0FFF swapping to $C000  3
3 $0FE8-0FEF         3 Switches VRAM $0000-0FFF swapping to $B000  3
3 $1FD8-1FDF         3 Switches VRAM $1000-1FFF swapping to $E000  3
3 $1FE8-1FEF         3 Switches VRAM $1000-1FFF swapping to $D000  3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU



UŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽ¨
3 11 3   Sound   3
AŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽU

  One of the most interesting aspects of the NES is it's sound support,
which is very analogue, excluding the PCM register.

  There seem to be formulaes which allow accurate playback of the NES's
sound, using the following formulaes:

    P = 111860.78 / (CHx + 1).

  Where "P" is the actual played data, and CHx is the channel played.
The channel formulaes are the following:

    CH1 = $4002 + ($4003 & 7) * 256   (Square Wave #1)
    CH2 = $4006 + ($4007 & 7) * 256   (Square Wave #2)
    CH3 = $400A + ($400B & 7) * 256   (Triangle Wave)

  Where the $400x values are actual values written to that register.

  Formulaes for the Noise and PCM Channels are probably not necessary,
but I'm not positive. Any information is appriciated.



UŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 12 3   .NES File Format   3
AŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  This is the .NES File Format, created by Marat Fayzullin (author of
iNES).

UŽŽŽŽŽŽŽŽAŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Offset 3 Size 3 Content(s)                                           3
AŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3   0    3  3   3 'NES'                                                3
3   3    3  1   3 $1A                                                  3
3   4    3  1   3 Number of 16K PRG-ROM banks                          3
3   5    3  1   3 Number of 8K CHR-RAM banks                           3
3   6    3  1   3 ROM Control Byte                                     3
3        3      3   %00000000                                          3
3        3      3    AŽAU333AŽ 0=Horizontal Mirroring                  3
3        3      3      3 333   1=Vertical Mirroring                    3
3        3      3      3 33AŽŽ 1=WRAM located at $6000-7FFF            3
3        3      3      3 3AŽŽŽ 1=512-byte trainer present              3
3        3      3      3 AŽŽŽŽ 1=Four-screen VRAM layout               3
3        3      3      3                                               3
3        3      3      AŽŽŽŽŽŽ iNES Mapper #                           3
3        3      3                                                      3
3  7-15  3  9   3 [Reserved for expansion, should be $00]              3
3 16-..  3      3 PRG-ROM banks (in ascending order). A trainer pre-   3
3        3      3 cedes the first bank, if a trainer exists.           3
3 ..-EOF 3      3 CHR-RAM banks (in ascending order).                  3
AŽŽŽŽŽŽŽŽAŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  The previously mentioned 512-byte trainer is interesting, since it has
different implementations depending upon which iNES Mapper is used in the
cart. See Section #10 for more information about MMC-dependant trainers.



UŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 13 3   Famicom Disk System Format (.DKA/.DKB/.500)   3
AŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  This is the file format for Famicom Disk System images; the only
emulator at this time to support them is Pasowing, which is the
emulator which these images are based off of.

   The format for the .DKA/.DKB (DisK side-A and DisK side-B) files
is somewhat undocumented (as shown). .DKA and .DKB files are 64K in
size (65536 bytes). The format for the file is as follows:

UŽŽŽŽŽŽŽŽAŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 Offset 3 Size 3 Content(s)                                           3
AŽŽŽŽŽŽŽŽAŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ'
3 [IMAGE HEADER]                                                       3
3                                                                      3
3   0    3  1   3 [Unknown]                                            3
3   1    3  3   3 Disk ID                                              3
3   6    3  1   3 Disk #                                               3
3   38   3  1   3 Disk # (???)                                         3
3   63   3  1   3 Amount of data blocks                                3
3                                                                      3
3 [DATA BLOCK HEADER]                                                  3
3                                                                      3
3   64   3  1   3 $03                                                  3
3   65   3  1   3 Block #                                              3
3   66   3  1   3 ???                                                  3
3   67   3  8   3 Name                                                 3
3   75   3  2   3 Destination                                          3
3   77   3  2   3 Size of data                                         3
3   79   3  1   3 Data Type                                            3
3        3      3 AŽŽŽAŽŽŽU                                            3
3        3      3     3                                                3
3        3      3     AŽŽŽŽŽŽ $00 = PRG-ROM                            3
3        3      3             $01 = CHR-RAM                            3
3        3      3             $02 = [Unknown]                          3
3 79-..  3      3 Data                                                 3
3        3      3                                                      3
3 ..-EOF 3      3 Repeat loading DATA BLOCKS HEADERS as shown above;   3
3        3      3 continue loading until EOF is reached.               3
AŽŽŽŽŽŽŽŽAŽŽŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU



UŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 14 3   Notes to emulator authors   3
AŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  The NES is a 6502 (NMOS) CPU. It is not a 65C02 (CMOS) CPU as rumoured.
  
  Ignore opcodes which are "bad" (not in the 6502 instruction set); a lot
of ROMs available are flawed, due to bad backup units or readers. I've
noticed this in the "Twinbee" and "Adventure of Lolo" ROMs floating around.

  If a trainer is present in the .NES image, your emulator should load the
trainer into it's respective memory range, as well as PRG-ROM and CHR-RAM.
Begin executing code at $7000, not at the RESET vector.

  The Four-screen VRAM layout is used within other mappers, not just iNES
Mapper #5 (MMC5). I have seen it used in iNES Mapper #15 and others.

  A reminder: MMC != iNES Mapper.

  When the NES screen is turned off, programmers do not have to wait for
the VBL to occur. This may be pointless information to you, but for some
of you, it may be vital :-).



UŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 15 3   Thanks   3
AŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽU

  Thanks to the following people for helping make this document what it
has become today. In alphabetical order:

  Acey                (d0p@sofi.ah.dk)
  Alex Krasivsky      (bcat@lapkin.rosprint.ru)
  Avatar Z            (swahlen@nfinity.com)
  Bloodlust Software  (bldlust@southwind.net)
  CiXeL               (N/A)
  D                   (d@animal.blarg.net)
  Dan Boris           (dan.boris@coat.com)
  FanWen              (yangfanw@ms4.hinet.net)
  Kevin Horton        (khorton@iquest.net)
  Loopy               (loopy@itsnet.com)
  Marat Fayzullin     (fms@freeflight.com)
  Mark Knibbs         (markk@netcomuk.co.uk)
  Mike Perry          (mj-perry@uiuc.edu)
  MindRape            (mindrape@goodnet.com)
  Moo!                (danmcc@injersey.com)
  Neill Corlett       (corlett@elwha.nrrc.ncsu.edu)
  Pat Mccomack        (splat@primenet.com)
  Paul Robson         (AutismUK@aol.com)
  star69              (mr6v@andrew.cmu.edu)
  Stumble             (stumble@alpha.pulsar.net)
  Tony Young          (KBAAA@aol.com)
  Typhoon Z           (typhoonz@parodius.com)
  Vince Indriolo      (indriolo@nm.picker.com)



UŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽ¨
3 16 3   Revision History   3
AŽŽŽŽAŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽŽU

  v0.40: [---] Section #15 ("Relative URLs") removed.
         [---] Section #11 shifted down one (1) to allow for the
               addition of "Sound".
         [ #0] Updated.
         [ #1] Updated.
         [ #4] Updated.
         [ #6] PPUCNT1 is now PPUCNT0.
         [ #6] PPUCNT2 is now PPUCNT1.
         [ #6] BGSCROL ($2005) updated.
         [ #6] SNDCNT ($4015) updated.
         [ #8] Updated.
         [#10] MMC1 updated.
         [#10] Mapper #3 updated.
         [#10] MMC3 updated.
         [#10] MMC5 updated.
         [#10] Mapper #6 updated.
         [#10] Mapper #11 updated.
         [#11] Section added ("Sound").
         [#13] Updated.
         [#14] Updated.
         [#15] Updated.
  v0.34: [---] Private release.
  v0.33: [ #0] Section added.
         [#10] MMC3 layout changed.
         [#10] MMC4 added.
         [#10] Mapper #6 updated.
         [#12] Data block description updated.
         [#15] Section added.
  v0.32: [---] Private release.
  v0.31: [#10] MMC2 added.
         [#10] Mapper #11 added.
         [#10] Mapper #6 updated.

  v0.30: [---] First public release.