libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
chip8.h File Reference
#include "common.h"
#include "graphics.h"
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  C8
 Represents current state of the CHIP-8 interpreter. More...
 

Macros

#define C8_CLOCK_SPEED   1000
 Maximum instructions to execute per second.
 
#define C8_STACK_SIZE   16
 Maximum stack size.
 
#define C8_MODE_CHIP8   0
 CHIP-8 execution mode. SCHIP and XO-CHIP instructions will throw an error.
 
#define C8_MODE_SCHIP   1
 SCHIP execution mode.
 
#define C8_MODE_XOCHIP   2
 XO-CHIP execution mode.
 
#define C8_FLAG_DEBUG   0x1
 Enable debug mode.
 
#define C8_FLAG_VERBOSE   0x2
 Print all instructions as they are executed.
 
#define C8_FLAG_QUIRK_BITWISE   0x4
 Enable the 'b' quirk (see main page/README).
 
#define C8_FLAG_QUIRK_DRAW   0x8
 Enable the 'd' quirk (see main page/README).
 
#define C8_FLAG_QUIRK_LOADSTORE   0x10
 Enable the 'l' quirk (see main page/README).
 
#define C8_FLAG_QUIRK_SHIFT   0x20
 Enable the 's' quirk (see main page/README).
 
#define C8_FLAG_QUIRK_JUMP   0x40
 Enable the 'j' quirk (see main page/README).
 

Functions

void c8_deinit (C8 *)
 Deinitialize graphics and free c8.
 
C8c8_init (const char *, int)
 Initialize and return a C8 with the given flags.
 
int c8_load_palette_s (C8 *, char *)
 Load palette from the given string into colors.
 
int c8_load_palette_f (C8 *, const char *)
 Load palette from the given path into colors.
 
void c8_load_quirks (C8 *, const char *)
 Load quirk flags from string.
 
int c8_load_rom (C8 *, const char *)
 Load a ROM to c8->mem at path addr.
 
const char * c8_version (void)
 Get the version of libc8.
 
void c8_simulate (C8 *)
 Main interpreter simulation loop. Exits when c8->running is 0.
 

Detailed Description

Stuff for simulating and modifying CHIP8s.

Macro Definition Documentation

◆ C8_CLOCK_SPEED

#define C8_CLOCK_SPEED   1000

Maximum instructions to execute per second.

◆ C8_FLAG_DEBUG

#define C8_FLAG_DEBUG   0x1

Enable debug mode.

◆ C8_FLAG_QUIRK_BITWISE

#define C8_FLAG_QUIRK_BITWISE   0x4

Enable the 'b' quirk (see main page/README).

◆ C8_FLAG_QUIRK_DRAW

#define C8_FLAG_QUIRK_DRAW   0x8

Enable the 'd' quirk (see main page/README).

◆ C8_FLAG_QUIRK_JUMP

#define C8_FLAG_QUIRK_JUMP   0x40

Enable the 'j' quirk (see main page/README).

◆ C8_FLAG_QUIRK_LOADSTORE

#define C8_FLAG_QUIRK_LOADSTORE   0x10

Enable the 'l' quirk (see main page/README).

◆ C8_FLAG_QUIRK_SHIFT

#define C8_FLAG_QUIRK_SHIFT   0x20

Enable the 's' quirk (see main page/README).

◆ C8_FLAG_VERBOSE

#define C8_FLAG_VERBOSE   0x2

Print all instructions as they are executed.

◆ C8_MODE_CHIP8

#define C8_MODE_CHIP8   0

CHIP-8 execution mode. SCHIP and XO-CHIP instructions will throw an error.

◆ C8_MODE_SCHIP

#define C8_MODE_SCHIP   1

SCHIP execution mode.

◆ C8_MODE_XOCHIP

#define C8_MODE_XOCHIP   2

XO-CHIP execution mode.

◆ C8_STACK_SIZE

#define C8_STACK_SIZE   16

Maximum stack size.

Function Documentation

◆ c8_deinit()

void c8_deinit ( C8 c8)

Deinitialize graphics and free c8.

Parameters
c8C8 to deinitialize

◆ c8_init()

C8 * c8_init ( const char *  path,
int  flags 
)

Initialize and return a C8 with the given flags.

This function allocates memory for a new C8 with all values set to 0 or their default values, adds the font to memory, inititializes the graphics system, and returns a pointer to the C8.

Parameters
pathpath to ROM file
flagsflags
Returns
pointer to initialized C8.

◆ c8_load_palette_f()

int c8_load_palette_f ( C8 c8,
const char *  path 
)

Load palette from the given path into colors.

Parameters
c8where to store the color codes
pathpalette file location
Returns
1 if success

◆ c8_load_palette_s()

int c8_load_palette_s ( C8 c8,
char *  s 
)

Load palette from the given string into colors.

Parameters
c8where to store the color codes
sstring to load
Returns
1 if success

◆ c8_load_quirks()

void c8_load_quirks ( C8 c8,
const char *  s 
)

Load quirk flags from string.

Parameters
c8where to store flags
sstring to get quirks from

◆ c8_load_rom()

int c8_load_rom ( C8 c8,
const char *  addr 
)

Load a ROM to c8->mem at path addr.

Parameters
c8C8 to store the ROM's contents
addrpath to the ROM
Returns
1 if success.

◆ c8_simulate()

void c8_simulate ( C8 c8)

Main interpreter simulation loop. Exits when c8->running is 0.

Parameters
c8the C8 to simulate

◆ c8_version()

const char * c8_version ( void  )

Get the version of libc8.

Returns
const char* version string