Chip8.Interpreter (chip8 v0.1.0)

An interpreter for the Chip-8 language.

The interpreter uses the following components to run a program:

DisplayA monochrome display used to render graphics. See Chip8.Interpreter.Display for more information.
MemoryA memory space of 4Kb used to store programs and data. See Chip8.Interpreter.Memory for more information.
Delay TimerA timer used to coordinate events within a program, usually referred to as dt. See Chip8.Interpreter.Timer for more information.
Sound TimerA timer used to emit a monotone sound while it's active, usually referred to as st. See Chip8.Interpreter.Timer for more information.
StackA stack to store and retrieve memory addresses when calling and returning from subroutines.
Program CounterA 16-bit integer that points to the memory address of the current instruction, and is usually referred to as pc.
IA 16-bit register used to point to memory locations, usually to render sprites.
Variable Registers16 8-bit registers to store and retrieve variable data. See Chip8.Interpreter.VRegisters for more information.

Note that some of the components above are only accessible to programs through specific instructions (e.g. display and memory components) and some are not accessible at all (i.e. program counter).

cycle

Cycle

At each cycle, the interpreter performs the same sequence of steps until the the program reaches its end:

  1. Fetch 2 bytes of memory from the address that pc is pointing at;
  2. Decode the fetched bytes into an opcode with its operands;
  3. Execute the opcode by updating the interpreter state based on the opcode specification.

All programs are executed through this simple routine, so to prevent the interpreter to stop running they create an infinite loop (either a direct or indirect one) and keep executing until the user quits the application.

Link to this section Summary

Link to this section Types

Link to this section Functions

Link to this function

cycle(interpreter)

@spec cycle(t()) :: {:ok, t()} | {:error, atom()}
Link to this function

get_font_character_address(character)

@spec get_font_character_address(0..15) :: non_neg_integer()
Link to this function

initialize(program, opts \\ [])

@spec initialize(bitstring(), Keyword.t()) :: t()
Link to this function

load_font(interpreter, font_data)

@spec load_font(t(), Chip8.Interpreter.Memory.data()) :: t()
Link to this function

load_program(interpreter, program)

@spec load_program(t(), bitstring()) :: t()
Link to this function

new(opts \\ [])

@spec new(Keyword.t()) :: t()
Link to this function

pixelmap(interpreter)

@spec pixelmap(t()) :: Chip8.Interpreter.Display.pixelmap()
Link to this function

press_key(interpreter, key)

@spec press_key(t(), Chip8.Interpreter.Keyboard.key()) :: t()
Link to this function

release_key(interpreter, key)

@spec release_key(t(), Chip8.Interpreter.Keyboard.key()) :: t()
Link to this function

tick_timers(interpreter)

@spec tick_timers(t()) :: t()
Link to this function

to_next_instruction(interpreter)

@spec to_next_instruction(t()) :: t()
Link to this function

to_previous_instruction(interpreter)

@spec to_previous_instruction(t()) :: t()