Slide 1

Slide 1 text

GAME DEVELOPMENT 
 IN EIGHT BITS Kevin Zurawel | https://famicom.party

Slide 2

Slide 2 text

A.K.A.
 “STUPID NES TRICKS”

Slide 3

Slide 3 text

WHAT IS A “NES”?

Slide 4

Slide 4 text

NINTENDO ENTERTAINMENT SYSTEM (1985)

Slide 5

Slide 5 text

DONKEY KONG (Arcade, 1981)

Slide 6

Slide 6 text

DONKEY KONG (Arcade, 1981)

Slide 7

Slide 7 text

ATARI VCS / 2600 (1977)

Slide 8

Slide 8 text

COMBAT (ATARI VCS, 1977)

Slide 9

Slide 9 text

COMBAT (ATARI VCS, 1977)

Slide 10

Slide 10 text

NES TARGET PRICE:
 ¥9800 $40 (1980)
 $120 (2019)

Slide 11

Slide 11 text

NES TECH SPECS ➤ MOS Technologies 6502 CPU (1.79MHz) ➤ Custom Ricoh “Picture Processing Unit”
 (256x240 resolution, 64 colors)

Slide 12

Slide 12 text

NES TECH SPECS ➤ 2KB work RAM + 2KB video RAM ➤ No permanent storage ➤ Read-only cartridges;
 32KB code, 8KB graphics data

Slide 13

Slide 13 text

WHAT IS “8-BIT”?

Slide 14

Slide 14 text

“ Bit: a binary digit,
 representing either a 0 or 1.

Slide 15

Slide 15 text

Number of bits Possible values 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256

Slide 16

Slide 16 text

As far as the NES is concerned, everything is a number between zero and 255.

Slide 17

Slide 17 text

LET’S DIG IN!

Slide 18

Slide 18 text

DRAWING GRAPHICS

Slide 19

Slide 19 text

256 pixels wide
 × 240 pixels tall

Slide 20

Slide 20 text

256 pixels wide
 × 240 pixels tall 61,440 pixels
 per screen

Slide 21

Slide 21 text

256 pixels wide
 × 240 pixels tall 61,440 pixels
 per screen ÷ 4 pixels per byte

Slide 22

Slide 22 text

256 pixels wide
 × 240 pixels tall 61,440 pixels
 per screen ÷ 4 pixels per byte 15 KB
 per screen

Slide 23

Slide 23 text

256 pixels wide
 × 240 pixels tall 61,440 pixels
 per screen ÷ 4 pixels per byte 15 KB
 per screen (!!!)

Slide 24

Slide 24 text

PROBLEM #1 How do you draw a screen of graphics
 in less than 2KB?

Slide 25

Slide 25 text

SOLUTION: GET ABSTRACT

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

BACKGROUND SPRITES

Slide 28

Slide 28 text

BACKGROUNDS

Slide 29

Slide 29 text

BACKGROUNDS 32 x 30 grid of tiles 8x8 pixels per tile 960 tiles per screen 1 byte per tile 960 bytes per screen

Slide 30

Slide 30 text

PATTERN TABLES (“8KB GRAPHICS DATA”)

Slide 31

Slide 31 text

64 POSSIBLE COLORS

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

SPRITES

Slide 34

Slide 34 text

SPRITES 256 bytes of sprite RAM
 ÷ 4 bytes per sprite 
 (tile #, x/y, palette #) 64 sprites at a time

Slide 35

Slide 35 text

…AND ONE MORE THING No more than 8 sprites
 visible per scanline

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

PROBLEM #2 How do you show a lot of action
 with only 8 sprites per line?

Slide 38

Slide 38 text

SOLUTION: FLICKERING

Slide 39

Slide 39 text

SOLUTION: FLICKERING

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

GOING BEYOND 
 ONE SCREEN:
 LEVEL STORAGE

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

14 screens of graphics
 × 960 bytes per screen ~13 KB graphics data

Slide 44

Slide 44 text

14 screens of graphics
 × 960 bytes per screen ~13 KB graphics data … for World 1-1 alone

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

×4 !!!

Slide 48

Slide 48 text

PROBLEM #3 How do you store a big game
 in 32KB or less?

Slide 49

Slide 49 text

1. MAKE USE OF DEFAULT COLOR 228
 non-default 
 tiles
 
 (23.75% of
 the screen)

Slide 50

Slide 50 text

2. MAKE USE OF REPEATED META-OBJECTS Instead of storing 24 tiles, store “pipe, height 6” and write code that draws pipes

Slide 51

Slide 51 text

3. USE BASIC COMPRESSION (RUN-LENGTH ENCODING) Instead of storing 96 tiles, store “brick tile repeats 32 times” for three rows

Slide 52

Slide 52 text

SUPER MARIO BROS.: GET EVEN MORE ABSTRACT "set decoration” (3 screens wide)

Slide 53

Slide 53 text

{ {

Slide 54

Slide 54 text

;level 1–1 
 L_GroundArea6: .db $50, $21
 .db $07, $81, $47, $24, $57, $00, $63, $01, $77, $01
 .db $c9, $71, $68, $f2, $e7, $73, $97, $fb, $06, $83 
 .db $5c, $01, $d7, $22, $e7, $00, $03, $a7, $6c, $02 
 .db $b3, $22, $e3, $01, $e7, $07, $47, $a0, $57, $06 
 .db $a7, $01, $d3, $00, $d7, $01, $07, $81, $67, $20 
 .db $93, $22, $03, $a3, $1c, $61, $17, $21, $6f, $33 
 .db $c7, $63, $d8, $62, $e9, $61, $fa, $60, $4f, $b3 
 .db $87, $63, $9c, $01, $b7, $63, $c8, $62, $d9, $61 
 .db $ea, $60, $39, $f1, $87, $21, $a7, $01, $b7, $20 
 .db $39, $f1, $5f, $38, $6d, $c1, $af, $26
 .db $fd World 1-1… in 101 bytes! "I AM ERROR", p.131

Slide 55

Slide 55 text

;level 1–1 
 L_GroundArea6: .db $50, $21
 .db $07, $81, $47, $24, $57, $00, $63, $01, $77, $01
 .db $c9, $71, $68, $f2, $e7, $73, $97, $fb, $06, $83 
 .db $5c, $01, $d7, $22, $e7, $00, $03, $a7, $6c, $02 
 .db $b3, $22, $e3, $01, $e7, $07, $47, $a0, $57, $06 
 .db $a7, $01, $d3, $00, $d7, $01, $07, $81, $67, $20 
 .db $93, $22, $03, $a3, $1c, $61, $17, $21, $6f, $33 
 .db $c7, $63, $d8, $62, $e9, $61, $fa, $60, $4f, $b3 
 .db $87, $63, $9c, $01, $b7, $63, $c8, $62, $d9, $61 
 .db $ea, $60, $39, $f1, $87, $21, $a7, $01, $b7, $20 
 .db $39, $f1, $5f, $38, $6d, $c1, $af, $26
 .db $fd World 1-1… in 101 bytes! Header Footer "I AM ERROR", p.131

Slide 56

Slide 56 text

;level 1–1 
 L_GroundArea6: .db $50, $21
 .db $07, $81, $47, $24, $57, $00, $63, $01, $77, $01
 .db $c9, $71, $68, $f2, $e7, $73, $97, $fb, $06, $83 
 .db $5c, $01, $d7, $22, $e7, $00, $03, $a7, $6c, $02 
 .db $b3, $22, $e3, $01, $e7, $07, $47, $a0, $57, $06 
 .db $a7, $01, $d3, $00, $d7, $01, $07, $81, $67, $20 
 .db $93, $22, $03, $a3, $1c, $61, $17, $21, $6f, $33 
 .db $c7, $63, $d8, $62, $e9, $61, $fa, $60, $4f, $b3 
 .db $87, $63, $9c, $01, $b7, $63, $c8, $62, $d9, $61 
 .db $ea, $60, $39, $f1, $87, $21, $a7, $01, $b7, $20 
 .db $39, $f1, $5f, $38, $6d, $c1, $af, $26
 .db $fd World 1-1… in 101 bytes! Header Footer Byte pairs (screen location, metatile) "I AM ERROR", p.131

Slide 57

Slide 57 text

Byte pair Column/Row Description $07, $81 0, 7 (start new screen) 
 "?" block w/ coin $47, $24 4, 7 row of bricks, length 4 $57, $00 5, 7 "?" block 
 w/ power-up item $63, $01 6, 3 "?" block w/ coin "I AM ERROR", p.133

Slide 58

Slide 58 text

8-BIT PHYSICS

Slide 59

Slide 59 text

THE “STANDARD” 2D JUMP ALGORITHM Height at time t = vertical velocity + (acceleration from gravity2 / 2)

Slide 60

Slide 60 text

MATH ON THE 6502 CPU ADC SBC ASL LSR Add (with Carry) Subtract (with Carry) Arithmetic Shift Left (“multiply by 2”) Logical Shift Right (“divide by 2”)

Slide 61

Slide 61 text

PROBLEM #4 How do you handle jump physics with only addition and subtraction?

Slide 62

Slide 62 text

SOLUTION: DON’T USE PHYSICS ➤ When player presses jump button,
 check if player is on the ground ➤ If yes, move player up n pixels per frame ➤ Stop moving up when default jump height reached ➤ Then, move player down n pixels per frame ➤ Check for collision with the ground each frame

Slide 63

Slide 63 text

EVEN MORE PHYSICS:
 COLLISION DETECTION

Slide 64

Slide 64 text

CONSIDER CONTRA (1988)…

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

https://ericleong.me/research/circle-circle/

Slide 68

Slide 68 text

PROBLEM #5 How do you handle collisions between
 lots of objects in real-time?

Slide 69

Slide 69 text

Image by Allan Blomquist, http://tomorrowcorporation.com/posts/retro-game-internals-contra-collision-detection

Slide 70

Slide 70 text

RANDOM NUMBERS

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

“Math.floor(
 Math.random() * 255
 ); - JavaScript

Slide 76

Slide 76 text

THE NES DOESN’T HAVE A RANDOM NUMBER GENERATOR.

Slide 77

Slide 77 text

PROBLEM #6 How do you make random numbers
 without a system-wide RNG?

Slide 78

Slide 78 text

THE TETRIS SOLUTION: DO IT WITH MATH 16-bit Fibonacci linear feedback shift register (LFSR) (XOR bits 1 and 9, store in bit 16, shift right) https://meatfighter.com/nintendotetrisai/#Picking_Tetriminos

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

NASIR GEBELLI http://allincolorforaquarter.blogspot.ca/2015/08/nasir-gebelli-and-early-days-of-sirius.html

Slide 81

Slide 81 text

THE FINAL FANTASY SOLUTION: USE A LOOKUP TABLE AE D0 38 8A ED 60 DB 72 5C 59 27 D8 0A 4A F4 34 08 A9 C3 96 56 3B F1 55 F8 6B 31 EF 6D 28 AC 41 68 1E 2A C1 E5 8F 50 F5 3E 7B B7 4C 14 39 12 CD B2 62 8B 82 3C BA 63 85 3A 17 B8 2E B5 BE 20 CB 46 51 2C CF 03 78 53 97 06 69 EB 77 86 E6 EA 74 0C 21 E2 40 D4 5A 3D C7 2B 94 D5 8C 44 FD EE D2 43 00 BB FA C6 1D 98 A0 D3 54 5F 5E DC A8 00 AF 93 A1 E1 6C 04 DE B6 D7 36 16 C5 C8 C4 E4 0F 02 AB E8 33 99 73 11 6A 09 67 F3 FF A2 DF 32 0E 1F 0D 90 25 64 75 B3 65 2F C9 B0 DA 5D 9F EC 29 CE E3 F0 91 7A 58 45 24 1C 47 A4 89 18 2D CC BD 6F 80 F6 81 22 E9 07 70 FB DD AD 35 A6 61 B4 A3 FE B1 30 4B 15 48 6E 4F 5B 13 9C 83 92 01 C2 19 7F 1A 1B 71 B9 3F 4E 9B BF 9E 87 0B 10 57 F2 26 79 9A 05 C0 E0 F7 4D 7D CA 52 9D F9 BC AA FC 8D 7E D1 A5 42 E7 D6 76 A7 84 8E 66 7C 23 88 37 49 D9

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

“Contra has a single global 8-bit value that it uses as the source of randomness throughout the game. …[T]he next random value is generated by spinning in a tight loop during the time that the game is idle and waiting for the next display frame to begin. -Allan Blomquist THE CONTRA SOLUTION: DO SOME REALLY FAST MATH, ALL THE TIME

Slide 84

Slide 84 text

SAVING PROGRESS

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

PROBLEM #7 How do you save a player’s progress on a read-only cartridge?

Slide 88

Slide 88 text

SOLUTION: PASSWORD SYSTEMS

Slide 89

Slide 89 text

SOLUTION: PASSWORD SYSTEMS

Slide 90

Slide 90 text

https://tomorrowcorporation.com/posts/retro-game-internals-punch-out-passwords

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

https://strategywiki.org/wiki/Mega_Man_2/Password_Mechanics

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

AN ALTERNATIVE…

Slide 96

Slide 96 text

SOLUTION: STOP USING READ-ONLY CARTRIDGES (1986) FAMICOM DISK SYSTEM

Slide 97

Slide 97 text

MITSUMI QUICKDISK (1986, 2.8”)

Slide 98

Slide 98 text

http://www.famicomdisksystem.com/disks/

Slide 99

Slide 99 text

PROBLEM #8 How do you make writable game media
 that users can’t easily copy?

Slide 100

Slide 100 text

SOLUTION: ADD BATTERY-BACKED MEMORY TO THE CARTRIDGE

Slide 101

Slide 101 text

“HOLD RESET BEFORE TURNING OFF POWER”

Slide 102

Slide 102 text

PROBLEM #9 How do you ensure that save data
 hasn’t been corrupted?

Slide 103

Slide 103 text

SOLUTION: WRITE SAVES MULTIPLE TIMES ➤ Store multiple copies of
 the save data with a 
 CRC code (checksum) ➤ On load, check saves one
 by one until you find one 
 that is intact Dragon Warrior (1989)

Slide 104

Slide 104 text

SO WHAT’S THE POINT?

Slide 105

Slide 105 text

“EMBRACE THE STUPID”

Slide 106

Slide 106 text

NINTENDO / VIDEO GAME HISTORY BOOKS ➤ Altice, Nathan. “I AM ERROR”. MIT Press, 2015. ➤ Bogost, Ian and Montfort, Nick. “Racing the Beam: The 
 Atari Video Computer System”. MIT Press, 2009. ➤ Bagnall, Brian. “On the Edge: The spectacular rise and fall of Commodore”. Variant Press, 2005. ➤ Sheff, David. “Game Over: How Nintendo zapped an American industry, captured your dollars, and enslaved your children”. Random House, 1993.

Slide 107

Slide 107 text

HTTPS://BOOK.FAMICOM.PARTY

Slide 108

Slide 108 text

THANK YOU! Get in touch: kevin@famicom.party Slides: bit.ly/gd8b-abs2