Introduction to CHIP-8

While I was doing research for the Space Invaders emulator, I found a forum post somewhere that said something like "if CHIP-8 is too easy for you, try Space Invaders". I'd never heard of CHIP-8 before, so I looked into it and it's very interesting.

It was designed for people to program really early home microcomputers. Instead of using actual microprocessor opcodes, it was always designed to be a virtual language and be interpreted at runtime. The Wikipedia article says that CHIP-8 enjoyed a renaissance when people started using it to program HP48 calculators.

The original CHIP-8 machine code is only 35 different instructions. Following a similar method that I outlined before for the 8080, I was able to write a CHIP-8 disassembler and emulator to run CHIP-8 programs in only 8-10 hours. A lot of that time was spent running different programs to work out problems in my emulation.

If you haven't read this site's Introduction sections yet, please look through them to get the background you'll need to follow this section.

Introduction to Binary and Hex

A quick introduction to a CPU

Logical Operations

Introduction to Assembly Language

Stacks

Diving In to CHIP-8

Compared to the 8080 or other processors, the information about CHIP-8 is pretty sparse. I mostly used the Wikipedia article about CHIP-8 to learn about it and look at the instructions. The hex code of a CHIP-8 program looks like this:

   $ hexdump -v "Fishie.ch8"    

   0000000 00 e0 a2 20 62 08 60 f8 70 08 61 10 40 20 12 0e    
   0000010 d1 08 f2 1e 71 08 41 30 12 08 12 10 00 00 00 00    
   0000020 00 00 00 00 00 18 3c 3c 00 00 00 00 00 00 00 00    
   0000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    
   0000040 3e 3f 3f 3b 39 38 38 38 00 00 80 c1 e7 ff 7e 3c    
   0000050 00 1f ff f9 c0 80 03 03 00 80 e0 f0 78 38 1c 1c    
   0000060 38 38 39 3b 3f 3f 3e 3c 78 fc fe cf 87 03 01 00    
   0000070 00 00 00 00 80 e3 ff 7f 1c 38 38 70 f0 e0 c0 00    
   0000080 3c 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00    
   0000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    
   00000a0    

The wikipedia article says that all CHIP-8 instructions are 2 bytes each. Using their instruction table to decode the instructions by hand shows:

   addr op   notes    
   ---- ---- -------------    
   0000 00e0 Clear the screen    
   0002 a220 Set I to address $220    
   0004 6208 V2 = #$08    
   0006 60f8 V0 = #$f8    
   0008 7008 V0 = V0 + #$08    
   000a 6110 V1 = #$10    

In the next section, I'll make a disassembler for CHIP-8 programs. After that I'll go through the instructions to get an idea of how to implement the emulator.

← Prev: iphone-port-pt-6---eye-candy   Next: chip-8-disassembler →


Post questions or comments on Twitter @realemulator101, or if you find issues in the code, file them on the github repository.