Skip to content

mxnwafor/chip8-emulator-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Just Another Chip-8 Emulator

Chip-8 is an interpreted programming language from the 1970s, it ran on microcomputers like the COSMAC VIP. During the boot process of the processor chip8 ROM files will be transferred onto the main memory of the processor. The processor will also allow for save states and restoring of states. The processor will handle keyboard inputs and output graphics and sound.

Layout

Registers

Chip8 has 16 8-bit registers: V0 , V1, V2 ... V15. Each one can store a number between 0 and 255 (0x00–0xFF)

VF

VF register is used as a flag register by some instructions but is not to be used by programs. The VF register (AKA V15 register) is frequently used for storing carry values from a subtraction or addition action, and also specifies whether a particular pixel is to be drawn on the screen.

Stack

The stack is made up of 16-bit registers to store the return address of functions.

Program Counter

A 16-bit program counter points to the memory address of the instruction to run. This is incremented by 2 since every instruction takes 2 bytes (16 bits).

Timers

An 8-bit delay timer, and an 8-bit sound timer.

Stack Pointer

A stack pointer (SP) is a register (a small, fast piece of memory inside the CPU) that keeps track of the top of the stack — that is, where the most recent item was pushed. In short: The stack pointer tells the CPU where to read or write the next value on the stack.

Index Register

index_register is a special-purpose 16-bit register that holds a memory address — usually pointing to where sprite data, constants, or other data reside in memory.

You can think of it like a pointer or base address register in modern CPUs.

Memory

Memory (RAM) is 4KB or 4096 bytes. First 512 bytes of memory 0x000 - 0x1FF is reserved for the interpreter.

Display

The 64x32 bit framebuffer is an addressable memory array that designates whether a pixel is currently on or off.

Keypad

This is represented as an array of 16 boolean switches to denote the 16 keys on the Chip-8 spec.

Fonts

A sprite is a group of bytes which are a binary representation of the desired picture. Chip-8 sprites may be up to 15 bytes, for a possible sprite size of 8x15.

Chip-8 programs refer to 5-byte sprites that represent fonts. Memory locations 0x000 to 0x080 are reserved for font set. Each sprite is 8 pixels wide, and can be between 1–15 pixels tall (typically 5 for built-in fonts). Let's say we have this byte: 0b11110000 → 1 1 1 1 0 0 0 0, that means the sprite row looks like: ⬛⬛⬛⬛⬜⬜⬜⬜ (black = on, white = off). Drawing uses XOR, so pixels can toggle off when drawn over (used for collision detection). Either ON or OFF, never both.

So a sprite that’s 5 bytes tall looks like 5 of those stacked vertically.

Wish to implement yours?

r3zz's Another Chip-8 Emulator (in Rust)
Chip-8 Design Specification
Cowgod's Technical Reference ROMS

About

Just another Chip-8 emulator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages