Share
Embed
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
Transcript
17 slides
-
Programming the Nintendo Entertainment System Levi D. Smith Codestock 2014
@GaTechGrad levidsmith.com -
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 -
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 -
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 -
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 -
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 -
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 -
Palettes • Less than 60 total colors • PPU IO
ports: $2006, $2007 • Sprite palette: $3F10 • Background palette: $3F00 Source: Nerdy Nights at NintendoAge -
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 -
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 -
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 -
.NES ROM image • Generate with NES assembler – NESASM3
• Play with NES emulator – FCEUXD • Tools exist for playing on actual NES hardware -
My Game • Classic shooter “Space Dude” • Ruby scripts
to generate assembly -
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/ -
My Contact Information • Twitter: @GaTechGrad • Web: levidsmith.com •
Facebook: LeviDSmithSoftware • My games: http://www.ludumdare.com/compo/author/gatechgrad/ XBox (360) Live Indie Games