Famicom Keyboard picture
20A01 — Famicom Keyboard

The famicom is an 8bit video game console by Nintendo.

The famicom notes were created during the production of the NES release of donsol and nespaint, to learn more about programming for the console, see assembly.

NES System Architecture

The NES screen resolution is 256x240.

6502 Processor Overview

$0000-0800Internal RAM, 2KB chip in the NES
$2000-2007PPU access ports
$4000-4017Audio and controller access ports
$6000-7FFFOptional WRAM inside the game cart
$8000-FFFFGame cart ROM


To make graphics on the screen you must write graphic data to the PPU memory, but you can't write directly to PPU memory, you have to use PPU ports $2006 and $2007. By using $2006 you declare the address of PPU memory then by using $2007 you write the desired value to that address, PPU Memory addresses are 16bit starting from $0000~$3FFF(0000-1fff = tiles & 2000-23ff = nametable 0).

Hexhigh byte($4A)low byte($0F)

So you need to write twice to $2006 to declare it's address, the first write declares high byte of address, the second write declares the low byte of address. Each time you write a value to $2007, the PPU address is automatically adjusted to the next address, so you don't need to declare the PPU address with $2006 for sequential PPU memory addresses.

  LDA #$20   ; high byte
  STA $2006
  LDA #$00   ; low byte
  STA $2006
  LDA #$04   ; sprite-id
  STA $2007

Calculate at what address to draw it: $2000 plus 32 times the vertical position of the tile (in 8-pixel units) plus the horizontal position of the tile (in 8-pixel units), write the high byte of the address to $2006: this is usually values $20 to $23, and write the low byte of the address to $2006. In other words, calculate the tile offset (TileY * 32 + TileX) and then add the base address. This will give you a pointer you can use to access any part of the map.

Controller Ports

The controllers are accessed through memory port addresses $4016 and $4017. First you have to write the value $01 then the value $00 to port $4016. This tells the controllers to latch the current button positions. Then you read from $4016 for first player or $4017 for second player. The buttons are sent one at a time, in bit 0. If bit 0 is 0, the button is not pressed. If bit 0 is 1, the button is pressed.

Button status for each controller is returned in the following order: A, B, Select, Start, Up, Down, Left, Right.

Palette Codes

00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F


Some cartridges have a CHR ROM, which holds a fixed set of graphics tile data available to the PPU from the moment it turns on. Other cartridges have a CHR RAM that holds data that the CPU has copied from PRG ROM through a port on the PPU.

nromNROM consists of a 16 kilobyte or 32 kilobyte program ROM, a 4 kilobyte or 8 kilobyte graphics ROM, and an NES lockout chip. The address pins on the NES are wired directly to the ROM with no mapper hardware intervening. There is no support for extra work RAM. Any ROM with a size of 40 KB or less is most likely an NROM.
cnromCNROM is similar to NROM except that writes to the program area of the ROM go to a 74LS161 register that controls the most significant bits of the graphics ROM's address bus, allowing it to be bankswitched in 8 KB chunks. There are also some somewhat sneaky ways to stream map data out of the graphics ROM, making for a larger game. With a ROM size of 32 KB and a graphics ROM size of 16 KB or 32 KB (or higher on the Panesian CNROM clone), most CNROMs are 64 KB or smaller.
unromUsing RAM instead of ROM in a system designed for ROM fonts was the main innovation of UNROM. Programs would write through the PPU to the graphics RAM whenever the screen was turned off (such as during vblank or slight pauses in the action). UNROM let game maps get big. It also allowed for RLE compression of graphics data, as graphics no longer had to be stored in the raw form needed by the PPU.

Found a mistake? Submit an edit to famicom.

OPN2 Cartridge picture
19V10 — OPN2 Cartridge

incoming(2): nespaint donsol famicom

Last update on 20A01, edited 2 times. +5/13fh○○○○○●