
18
only be written to. Bit 7 of £2000 can be used to disable NMIs. Remember that this type of
interrupt is generated whenever a V-Blank occurs and is unaffected by the interrupt disable
flag of the status register. Clearing this bit will prevent an NMI from occurring on V-Blank.
Since the NES supports both 8x8 and 8x16 sprites, setting bit 5 of $2000 will switch to 8x16
sprites. The next address in PPU memory to read or write from will be incremented after
each I/O occurs. The value to increment by is adjusted by setting the value of bit 2 of $2000.
If this is clear, the address is incremented by 1 (horizontal), otherwise the increment is 32
(vertical). Using $2001, the background can be hidden by clearing bit 3 and, similarly, the
sprites can be hidden by clearing bit 4.
The PPU Status Register is located at $2002 and is read only. The register is used by the
PPU to report its status to the CPU. The programs will frequently cause the CPU to read
from this location in order to ascertain the PPU’s status. Bit 7 is set by the PPU to indicate
that V-Blank is occurring. Bit 6 and bit 7 relate to sprites and are described later. Bit 4
indicates whether the PPU is willing to accept writes to VRAM, if it clear then writes are
ignored. When a read from $2002 occurs, bit 7 is reset to 0 as are $2005 and $2006.
3.3.1 Direct Memory Access
When transferring a large amount of data between devices it is inefficient to transfer this
through the processor. To transfer data from CPU memory to sprite memory, for example,
takes the following steps:
1. Load required SPR-RAM address into CPU.
2. Write required SPR-RAM address to $2003.
3. Load byte into CPU.
4. Write byte to $2004.
When filling the contents of sprite memory, this technique would have to be repeated 256
times. Direct Memory Access (DMA) is a technique which allows more efficient copying of
data from CPU memory to sprite memory. Using DMA, the whole of sprite memory can be
filled by using a single instruction, a write to $4014. The starting address in CPU memory is
specified by the operand for the write multiplied by $100. The 256 bytes starting at this
address are copied directly into sprite memory without the further involvement of the CPU.
When the DMA is occurring, the memory bus is in use, preventing the CPU from accessing
memory and, therefore, preventing it from accessing any more instructions. This is referred
to as cycle stealing and the CPU has to wait until the DMA transfer is complete. On the NES,
the DMA takes the equivalent of 512 cycles (about 4.5 scanlines worth) after which the CPU
can resume. This is considerably less than would be required to copy manually through the
CPU.
3.4 Colour Palette
The NES has a colour palette containing 52 colours although there is actually room for 64.
However, not all of these can be displayed at a given time. The NES uses two palettes, each
with 16 entries, the image palette ($3F00-$3F0F) and the sprite palette ($3F10-$3F1F). The
image palette shows the colours currently available for background tiles. The sprite palette
shows the colours currently available for sprites. These palettes do not store the actual
colour values but rather the index of the colour in the system palette. Since only 64 unique
values are needed, bits 6 and 7 can be ignored.
The palette entry at $3F00 is the background colour and is used for transparency. Mirroring
is used so that every four bytes in the palettes is a copy of $3F00. Therefore $3F04, $3F08,
$3F0C, $3F10, $3F14, $3F18 and $3F1C are just copies of $3F00 and the total number of