Slide 1

Slide 1 text

Programming the Nintendo Entertainment System Levi D. Smith Codestock 2014 @GaTechGrad levidsmith.com

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Architecture Source: Nerdy Nights at NintendoAge

Slide 4

Slide 4 text

CPU / PPU address space Source: Nerdy Nights at NintendoAge CPU PPU

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Palettes • Less than 60 total colors • PPU IO ports: $2006, $2007 • Sprite palette: $3F10 • Background palette: $3F00 Source: Nerdy Nights at NintendoAge

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

.NES ROM image • Generate with NES assembler – NESASM3 • Play with NES emulator – FCEUXD • Tools exist for playing on actual NES hardware

Slide 15

Slide 15 text

My Game • Classic shooter “Space Dude” • Ruby scripts to generate assembly

Slide 16

Slide 16 text

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/

Slide 17

Slide 17 text

My Contact Information • Twitter: @GaTechGrad • Web: levidsmith.com • Facebook: LeviDSmithSoftware • My games: http://www.ludumdare.com/compo/author/gatechgrad/ XBox (360) Live Indie Games