User Tools

Site Tools


nes_programming

NES Programming

Architecture

NES uses the 6502 CPU. This is the same chip used in Atari 2600 and Apple II machines.

Reference for 6502 Assembly

Programming

Hello world

On mac, install cc65 with brew install cc65. The ca65 is the assembly compiler.

.segment "HEADER"
    .byte "NES", $1A          ; Magic + iNES version
    .byte 1                   ; 1x 16KB PRG ROM bank (minimal)
    .byte 0                   ; 0x 8KB CHR ROM (or 1 if you add tiles)
    .byte %00000000           ; Mapper 0 (NROM), vertical mirroring, etc.
    .byte %00000000
    ; rest of header zeros

.segment "STARTUP"            ; Your code goes here
reset:
    sei                       ; Disable interrupts
    cld                       ; Clear decimal mode
    ldx #$FF
    txs                       ; Set stack pointer
    ; (Optional: basic PPU/APU init to avoid garbage)
forever:
    jmp forever               ; Infinite loop (does nothing)

.segment "VECTORS"            ; CPU vectors (required)
    .word 0                   ; NMI
    .word reset               ; Reset
    .word 0                   ; IRQ/BRK

.segment "CHARS"              ; Empty CHR if no graphics yet

Then compile and link with the following:

ca65 hello.s -o hello.o
ld65 -C nes.cfg -o hello.nes hello.o

Now there is a ROM named hello.nes.

Audio

  • 2 pulse wave channels
  • 1 triangle wave channel
  • 1 noise channel
  • 1 8-bit PCM channel

You can use FamiTracker or FamiStudio to generate .nsf files that you can use in games. FamiStudio also has the ability to generate a .nes ROM file directly that you can play in an emulator or put on a cartridge.

Emulators

You can get software emulators for most platforms like:

  • PC
  • Browser
  • Raspberry Pi
  • Android Phone/Tablet

Hardware

Aside from the original NES console, there are some modern tools out there

  • Consoles
  • Cartridges
  • Controllers
    • You can get NES-style USB controllers at places like Walmart for about $12 USD.
    • You can also get NES-style controllers with the original connector to fit on an original NES or the Hyperkin RetroN 1 HD. A 2-pack of those controllers runs about $10 USD.
    • There are also wireless models available like 8Bitdo N30 2.4G Wireless Gamepad for Original NES which runs around $30 USD.
    • Hyperkin offers controllers like the Hyperkin “Cadet” Premium Controller for NES with 10 ft. Cable (Gray) for abot $12 USD.
    • Hyperkin also has wireless controller models like Hyperkin “Cadet” Premium BT Controller for NES/ PC/ Mac/ Android running around $32 USD. that has an NES connector or can be used via Bluetooth to other devices like your computer or a Raspberry Pi.
nes_programming.txt · Last modified: by nanodano

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki