libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
chip8.c File Reference
#include "chip8.h"
#include "decode.h"
#include "font.h"
#include "private/debug.h"
#include "private/exception.h"
#include "private/util.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Macros

#define DEBUG(c)
#define VERBOSE(c)
#define QUIRK_BITWISE(c)
#define QUIRK_DRAW(c)
#define QUIRK_LOADSTORE(c)
#define QUIRK_SHIFT(c)
#define BORROWS(x, y)
#define CARRIES(x, y)

Functions

void c8_deinit (c8_t *c8)
 Deinitialize graphics and free c8.
c8_tc8_init (const char *path, int flags)
 Initialize and return a c8_t with the given flags.
int c8_load_palette_s (c8_t *c8, char *s)
 Load palette from the given string into colors.
int c8_load_palette_f (c8_t *c8, const char *path)
 Load palette from the given path into colors.
void c8_load_quirks (c8_t *c8, const char *s)
 Load quirk flags from string.
void c8_simulate (c8_t *c8)
 Main interpreter simulation loop. Exits when c8->running is 0.

Detailed Description

Stuff for simulating and modifying c8_ts.

Macro Definition Documentation

◆ BORROWS

#define BORROWS ( x,
y )
Value:
((((int) x) - y) < 0)

◆ CARRIES

#define CARRIES ( x,
y )
Value:
((((int) x) + y) > UINT8_MAX)

◆ DEBUG

#define DEBUG ( c)
Value:
(c->flags & C8_FLAG_DEBUG)
#define C8_FLAG_DEBUG
Definition chip8.h:18

◆ QUIRK_BITWISE

#define QUIRK_BITWISE ( c)
Value:
if (c->flags & C8_FLAG_QUIRK_BITWISE) { \
c->V[0xF] = 0; \
}
#define C8_FLAG_QUIRK_BITWISE
Definition chip8.h:20

◆ QUIRK_DRAW

#define QUIRK_DRAW ( c)
Value:
if (c->flags & C8_FLAG_QUIRK_DRAW) { \
if () \
}
#define C8_FLAG_QUIRK_DRAW
Definition chip8.h:21

◆ QUIRK_LOADSTORE

#define QUIRK_LOADSTORE ( c)
Value:
if (c->flags & C8_FLAG_QUIRK_LOADSTORE) { \
c->I += x + 1; \
}
#define C8_FLAG_QUIRK_LOADSTORE
Definition chip8.h:22

◆ QUIRK_SHIFT

#define QUIRK_SHIFT ( c)
Value:
if (c->flags & C8_FLAG_QUIRK_SHIFT) { \
y = x; \
}
#define C8_FLAG_QUIRK_SHIFT
Definition chip8.h:23

◆ VERBOSE

#define VERBOSE ( c)
Value:
(c->flags & C8_FLAG_VERBOSE)
#define C8_FLAG_VERBOSE
Definition chip8.h:19

Function Documentation

◆ c8_deinit()

void c8_deinit ( c8_t * c8)

Deinitialize graphics and free c8.

Parameters
c8c8_t to deinitialize

◆ c8_init()

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

Initialize and return a c8_t with the given flags.

This function allocates memory for a new c8_t 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_t.

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

◆ c8_load_palette_f()

int c8_load_palette_f ( c8_t * 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_t * 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_t * c8,
const char * s )

Load quirk flags from string.

Parameters
c8where to store flags
sstring to get quirks from

◆ c8_simulate()

void c8_simulate ( c8_t * c8)

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

Parameters
c8the c8_t to simulate