Overview
- What is Chip8
- What is Octo
- Awesome for Emulator Developers
- Awesome for Game Developers
- References
What is Chip-8
- Simple interpreted bytecode created by Joseph Weisbecker in the 70's
- Designed with video games in mind
- Spawned multiple variants (SuperChip, XO-Chip,...)
- Someone has probably already written an interpreter for your toaster
What is Octo
- High-level assembler for the Chip-8 VM
- Includes an online version (https://johnearnest.github.io/Octo/) with:
- Assembler
- Disassembler
- Emulator/Interpreter
- Sprite Editor
- Social Sharing
Awesome for Emulator Developers
- Simple architecture
- Simple instruction set
- Simple registers
- Simple memory layout
- Simple keyboard
- Simple display
- Sound = Buzzer
- Lots of games to test with
Instruction Set
- RISC: 34 Instructions
- Fixed Instruction size: 2 bytes (4 nibbles)
- All instructions are 16-bit aligned
Registers
- 16x 8-bit general purpose registers: V0 - VF (VF also holds the carry flag)
- 1x 16-bit program counter: PC
- 1x 8-bit address pointer: I
- 1x 8-bit stack pointer: SP
- 2x 8-bit timed registers (Dec. at 60Hz): DT (Delay) and ST (Sound)
Keyboard
Bytecode | Command | Description |
Ex9E | SKP Vx | Skip instruction if Vx is pressed |
ExA1 | SKNP Vx | Skip instruction if Vx is not pressed |
Fx0A | LD Vx K | Waits for a key and stores it in Vx |
Memory Layout
- 4096 Bytes
- 0x000 - 0x1FF: Reserved space (512 Bytes)
- Includes 16 8x5 character sprites (0-F)
- 0x200 - 0xFFF: Program + Data (3584 Bytes)
Display
- 64x32 monochrome display
- 8x7 sprites (variable number of lines)
- Rending a sprite = XOR
Awesome for Game Developers
Octo's Syntax
Octo's syntax looks like a high-level programming language
:alias px v3
:alias py v4
: main
px := random 0b0011111
py := random 0b0001111
i := person
sprite px py 8
loop
sprite px py 8
v0 := 5 if v0 key then py += -1 # keyboard W
v0 := 8 if v0 key then py += 1 # keyboard S
sprite px py 8
again
: person
0x70 0x70 0x20 0x70 0xA8 0x20 0x50 0x50
Registers
- 16x 8-bit general purpose registers (no need to spill a lot)
- Constant framerate is easy using DT (delay timer)
Special Instructions
Bytecode | Command | Description |
00E0 | CLS | Clears the screen |
Dxyn | DRW Vx Vy n | Draws a sprite (I) with n lines at (Vx,Vy) |
Cxkk | RND Vx k | Stores a masked random number in Vx (rand AND k) |
Fx29 | LD F Vx | Points I to a sprite with the character Vx (0 to F) |
Fx33 | LD B Vx | Stores the BCD representation of Vx in memory |
Special Instructions (in Octo)
Command | Description |
clear | Clears the screen |
sprite vx vy n | Draws a sprite (I) with n lines at (Vx,Vy) |
vx := random k | Stores a masked random number in Vx (rand AND k) |
i := hex vx | Points I to a sprite with the character Vx (0 to F) |
bcd vx | Stores the BCD representation of Vx in memory |
Display
- The draw instruction includes collision detection
- No need to worry about VSync
- No need to count instructions (usually)