Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

A.K.A.
 “STUPID NES TRICKS”

Slide 4

Slide 4 text

WHAT IS A “NES”?

Slide 5

Slide 5 text

NINTENDO ENTERTAINMENT SYSTEM (1985)

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

$871.00
 + labor 
 + shipping (~$2600+ in 2019) MISSILE COMMAND (ATARI, 1980)

Slide 10

Slide 10 text

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) ➤ Custom Ricoh “Audio Processing Unit”
 embedded in CPU (five tone generators)

Slide 12

Slide 12 text

NES TECH SPECS ➤ 2 KB 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

“8-Bit: A CPU architecture based on registers, address buses, or data buses of that size.

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

LET’S DIG IN!

Slide 19

Slide 19 text

DRAWING GRAPHICS

Slide 20

Slide 20 text

256 pixels wide
 × 240 pixels tall

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

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

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

SOLUTION: GET ABSTRACT

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

BACKGROUND SPRITES

Slide 29

Slide 29 text

BACKGROUNDS

Slide 30

Slide 30 text

BACKGROUNDS

Slide 31

Slide 31 text

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

Slide 32

Slide 32 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 33

Slide 33 text

PATTERN TABLES (“8KB GRAPHICS DATA”)

Slide 34

Slide 34 text

WHERE’S THE COLOR?

Slide 35

Slide 35 text

64 POSSIBLE COLORS

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

SPRITES

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

SOLUTION: FLICKERING

Slide 44

Slide 44 text

SOLUTION: FLICKERING

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

GOING BEYOND 
 ONE SCREEN:
 LEVEL STORAGE

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

×4 !!!

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

{ {

Slide 60

Slide 60 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 61

Slide 61 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 62

Slide 62 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 63

Slide 63 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 64

Slide 64 text

A DIFFERENT APPROACH: PITFALL! (ATARI 2600, 1982) 256 screens 4KB cartridge size 128 bytes RAM

Slide 65

Slide 65 text

“RANDOM” LEVEL GENERATION Use a random number generator algorithm with a fixed seed value
 to generate a predictable
 (and reversible!) stream of bytes Algorithm + seed: 50 bytes

Slide 66

Slide 66 text

https://www.youtube.com/watch?v=MBT1OK6VAIU

Slide 67

Slide 67 text

8-BIT PHYSICS

Slide 68

Slide 68 text

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

Slide 69

Slide 69 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 70

Slide 70 text

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

Slide 71

Slide 71 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

Slide 72

Slide 72 text

MORE PHYSICS: ACCELERATION

Slide 73

Slide 73 text

MORE PHYSICS: ACCELERATION

Slide 74

Slide 74 text

PROBLEM #5 How do you give objects realistic
 acceleration without physics?

Slide 75

Slide 75 text

SUB-PIXEL POSITIONING (“8.8 FIXED-POINT” FORMAT) Represent sprite positions with two bytes ➤ Actual pixel position on screen (0-255) ➤ Fraction of a pixel offset (0-255) Two bytes for X, two bytes for Y
 Calculate X and Y movement separately

Slide 76

Slide 76 text

if (on_ground) { if (button_a) velocity_y = -500; // jump if (dpad_left) velocity_x -= 5; // accelerate left if (dpad_right) velocity_x += 5; // accelerate right } position_x += velocity_x; resolve_horizontal_collision(); position_y += velocity_y; resolve_vertical_collision(); velocity_y += 10; // apply gravity http://forums.nesdev.com/viewtopic.php?f=2&t=12434

Slide 77

Slide 77 text

EVEN MORE PHYSICS:
 COLLISION DETECTION

Slide 78

Slide 78 text

CONSIDER CONTRA (1988)…

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

“A POSTERIORI” COLLISION DETECTION WITH WALL EJECTION

Slide 85

Slide 85 text

“A POSTERIORI” COLLISION DETECTION WITH WALL EJECTION

Slide 86

Slide 86 text

RANDOM NUMBERS

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

Math.random() Call the operating system’s
 random number generator

Slide 93

Slide 93 text

THE NES DOESN’T HAVE A RANDOM NUMBER GENERATOR.

Slide 94

Slide 94 text

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

Slide 95

Slide 95 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 96

Slide 96 text

No content

Slide 97

Slide 97 text

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

Slide 98

Slide 98 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 99

Slide 99 text

No content

Slide 100

Slide 100 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 101

Slide 101 text

SAVING PROGRESS

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

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

Slide 105

Slide 105 text

SOLUTION: PASSWORD SYSTEMS

Slide 106

Slide 106 text

SOLUTION: PASSWORD SYSTEMS

Slide 107

Slide 107 text

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

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

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

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

AN ALTERNATIVE…

Slide 113

Slide 113 text

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

Slide 114

Slide 114 text

MITSUMI QUICKDISK (1986, 2.8”)

Slide 115

Slide 115 text

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

Slide 116

Slide 116 text

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

Slide 117

Slide 117 text

SOLUTION: ADD BATTERY-BACKED MEMORY TO THE CARTRIDGE

Slide 118

Slide 118 text

“HOLD RESET BEFORE TURNING OFF POWER”

Slide 119

Slide 119 text

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

Slide 120

Slide 120 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 121

Slide 121 text

“WHATEVER HAPPENED
 TO BABY NES?”

Slide 122

Slide 122 text

DONKEY KONG (FAMICOM, 1983)

Slide 123

Slide 123 text

DONKEY KONG (FAMICOM, 1983)

Slide 124

Slide 124 text

KIRBY’S ADVENTURE (1993)

Slide 125

Slide 125 text

KIRBY’S ADVENTURE (1993)

Slide 126

Slide 126 text

KIRBY’S ADVENTURE (1993), STAGE 2-1 (40 STAGES IN TOTAL)

Slide 127

Slide 127 text

NES-101 “TOP LOADER” (1993)

Slide 128

Slide 128 text

PROBLEM #11 How do you expand the NES’ capabilities without changing the console?

Slide 129

Slide 129 text

SOLUTION:
 CHANGE THE CARTRIDGE

Slide 130

Slide 130 text

MMC1 (1987; 225 LICENSED US GAMES) PRG-ROM: up to 512KB PRG-RAM: optional, 8KB w/ battery CHR-ROM: up to 128KB Mirroring: switchable on-the-fly

Slide 131

Slide 131 text

No content

Slide 132

Slide 132 text

CPU PPU CHR-ROM (graphics) PRG-ROM (code) NES CONSOLE CARTRIDGE RAM MMC1

Slide 133

Slide 133 text

MMC3 (1988; 195 LICENSED US GAMES) PRG-ROM: up to 512KB PRG-RAM: optional, 8KB w/ battery CHR-ROM: up to 256KB Mirroring: switchable or 4-screen VRAM

Slide 134

Slide 134 text

NINJA GAIDEN II: DARK SWORD OF CHAOS (1990, MMC3) Scanline IRQs
 to modify
 background
 scroll http://www.dustmop.io/blog/2015/12/18/nes-graphics-part-3/ Sprites

Slide 135

Slide 135 text

NINJA GAIDEN II: DARK SWORD OF CHAOS (1990, MMC3) Scanline IRQs
 to modify
 background
 scroll http://www.dustmop.io/blog/2015/12/18/nes-graphics-part-3/ Sprites

Slide 136

Slide 136 text

DONKEY KONG (NES, 1985)

Slide 137

Slide 137 text

KIRBY’S ADVENTURE (1993)

Slide 138

Slide 138 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 139

Slide 139 text

NESDEV.COM (WIKI AND FORUM)

Slide 140

Slide 140 text

HTTPS://BOOK.FAMICOM.PARTY

Slide 141

Slide 141 text

THANK YOU! Get in touch: [email protected]