Step 1 of 5 · Reading · ~3 min
Read
CHIP-8 Architecture
What CHIP-8 Is
CHIP-8 is a tiny virtual computer, designed in 1977 for hobby machines such as the RCA COSMAC VIP. You will build an emulator for it: a program that behaves like that computer, so that a real CHIP-8 game file runs on your screen. It is a good first emulator because the whole machine fits on one page and real games exist for it.
After this lesson you can read the machine's memory map and say, for any address, what lives there. The rest of the course fills the map in.
The machine
- 4096 bytes of RAM, addresses 0x000 to 0xFFF. An address is 12 bits.
- 16 registers, V0 to VF, one byte each. VF doubles as a flag that arithmetic and drawing set.
- I, a 12-bit register that points into RAM, and PC, the address of the next instruction.
- A stack of 16 return addresses, for subroutine calls.
- Two timers, a delay timer and a sound timer, counting down 60 times a second.
- A 64 by 32 black-and-white display and a 16-key hex keypad.
One instruction is two bytes
Every instruction is two bytes, stored high byte first. A program, called a ROM, is nothing but those bytes: no header, no checksum. The first ten bytes of the famous IBM logo ROM are:
00 E0 clear the screen
A2 2A point I at address 0x22A
60 0C V0 = 0x0C
61 08 V1 = 0x08
D0 1F draw 15 rows of the sprite at I, at position (V0, V1)
You will write the code that decodes those pairs in the next lesson. For now notice two things: the program tells the machine where its picture data lives (A22A), and it never says how to draw a pixel. The interpreter does that.
The memory map
A ROM is copied into RAM starting at 0x200, and the PC starts there. The first 512 bytes were originally occupied by the interpreter itself, which is why programs begin at 0x200 to this day: every ROM ever written assumes it.
0x000 - 0x04F interpreter area
0x050 - 0x09F the font: 16 hex digits x 5 bytes (placed here by convention)
0x0A0 - 0x1FF interpreter area
0x200 - ... the ROM, then free RAM up to 0xFFF
The most RAM a ROM can use is 0xFFF - 0x200 + 1 = 3584 bytes. A ROM of n bytes occupies the addresses 0x200 through 0x200 + n - 1; the first address after that is free.
This course puts the font at 0x050. Any spot below 0x200 would work as long as the FX29 instruction points at it, but 0x050 is the common choice and the one the later lessons assume.
Common mistakes
- Reading the addresses as decimal. They are hexadecimal, and
1FFis 511. - Getting the end of the ROM wrong by one. For a ROM of 6 bytes the last ROM address is 0x205, and 0x206 is free.
- Calling the font or the interpreter area "ROM". Only the bytes copied from the file are ROM.
- Treating 0x1000 as valid. RAM stops at 0xFFF.
Your exercise
The first input line is the size of a ROM in bytes. Each later line is a hex address, and you name the region it falls in. The starter reads the input and prints the answers; you write the function that classifies one address.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…