Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Programming the Nintendo Entertainment System

Programming the Nintendo Entertainment System

Overview of the NES architecture, 6502 assembly code, and how to create an NES ROM.

LD Smith

July 11, 2014
Tweet

More Decks by LD Smith

Other Decks in Technology

Transcript

  1. Architecture • NES Console – 6502 CPU (Central Processing Unit)

    • 16 bit address bus • 64 KB address space • Four registers (Accumulator, X, Y, Status) – APU (Audio Processing Unit) – PPU (Picture Processing Unit) • 16 KB address space – Lockout chip • Game Cartridge – CHR (Character Memory) ROM or RAM – PRG (Program Memory) ROM – WRAM (optional) and battery – Lockout chip
  2. 6502 Assembly • Directives – Assembler commands – Start with

    a period • Labels – Used to organize code – Like a BASIC line number (for GOTO) – Not indented and followed by a colon • Opcodes – Program instructions – Indented
  3. 6502 Opcodes • Load / Store – Load: LDA, LDX,

    LDY – Store: STA, STX, STY • Math – Add: ADC, CLC – Subtract: SBC, SEC – Increment: INC, DEC, INX, INY, DEX, DEY – Shift: ASL, LSR • Comparison – CMP, CPX, CPY • Control – JMP – BEQ, BNE
  4. Assembly Starter if (num == 5) { //do something }

    IF LDA num CMP #$05 BNE Done ; do something Done: void MyMethod() { //do something } ... MyMethod(); PROCEDURE MyMethod: ; do something RTS ... JSR MyMethod num = 42; ASSIGN LDA #$2A STA num int num; DECLARE VARIABLE .rsset $0000 num .rs 1
  5. Assembly Starter x = 10; x++; y = 32; y--;

    INCREMENT LDA #$0A STX INX LDA #$20 STY DEY void Draw() { //draw code } void Update() { //update code } INTERRUPT METHODS NMI: ; modify sprites ; modify background ; update code RTI x = 0; while (x < 255) { //do something x++; } WHILE LOOP LDA #$00 STX Loop: ; do something INX CPX #$FF BNE Loop
  6. Sprites • Can be created with programs like YY-CHR •

    Each sprite tile is 8 x 8 pixels • Each sprite tile can only have 4 unique colors • Objects are usually composed of multiple sprite tiles • All sprites must fit on a single spritesheet
  7. Palettes • Less than 60 total colors • PPU IO

    ports: $2006, $2007 • Sprite palette: $3F10 • Background palette: $3F00 Source: Nerdy Nights at NintendoAge
  8. Background • 32 x 30 tiles (256 x 240 resolution)

    • Tiles are 8 x 8 pixels • Four colors for every 2 x 2 tiles • Background is static, but can be scrolled • Text is usually background tiles Source: Nerdy Nights at NintendoAge
  9. Controller Input • Call load on Controller port – LDA

    $4016 (player one) – LDA $4017 (player two) • Each call returns the status of the next button – A, B, Select, Start, Up, Down, Left, Right
  10. Playing Sounds • APU 5 channels – Square 1, 2

    – Hollow sound – Triangle – Smooth sound – Noise - Explosions – DMC – Prerecorded, like voices • Write to $4015 to enable sounds • $4000 to $4003 modify sound properties
  11. .NES ROM image • Generate with NES assembler – NESASM3

    • Play with NES emulator – FCEUXD • Tools exist for playing on actual NES hardware
  12. More Information • Nerdy Nights tutorials at NintendoAge – http://www.nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155

    – http://www.retrousb.com/ • NESDEV – http://nesdev.com/ • My post on creating an NES game – http://www.ludumdare.com/compo/2014/06/23/creating-my-first-nes-game/
  13. My Contact Information • Twitter: @GaTechGrad • Web: levidsmith.com •

    Facebook: LeviDSmithSoftware • My games: http://www.ludumdare.com/compo/author/gatechgrad/ XBox (360) Live Indie Games