libc8
CHIP-8 utility library
chip8.h
Go to the documentation of this file.
1
7#ifndef LIBC8_CHIP8_H
8#define LIBC8_CHIP8_H
9
10#include "graphics.h"
11#include "defs.h"
12
13#include <stdint.h>
14
15#define C8_CLOCK_SPEED 500
16#define C8_STACK_SIZE 16
17
18#define C8_FLAG_DEBUG 0x1
19#define C8_FLAG_VERBOSE 0x2
20#define C8_FLAG_QUIRK_BITWISE 0x4
21#define C8_FLAG_QUIRK_DRAW 0x8
22#define C8_FLAG_QUIRK_LOADSTORE 0x10
23#define C8_FLAG_QUIRK_SHIFT 0x20
24#define C8_FLAG_QUIRK_JUMP 0x40
25
51typedef struct {
52 uint8_t mem[C8_MEMSIZE];
53 uint8_t R[8];
54 uint8_t V[16];
55 uint8_t sp;
56 uint8_t dt;
57 uint8_t st;
58 uint16_t stack[C8_STACK_SIZE];
59 uint16_t pc;
60 uint16_t I;
61 int key[18];
62 int VK;
63 int cs;
67 int flags;
68 int breakpoints[C8_MEMSIZE];
69 int colors[2];
70 int fonts[2];
71 int draw;
72} c8_t;
73
74void c8_deinit(c8_t *);
75c8_t *c8_init(const char *, int);
76int c8_load_palette_s(c8_t *, char *);
77int c8_load_palette_f(c8_t *, const char *);
78void c8_load_quirks(c8_t *, const char *);
79void c8_simulate(c8_t *);
80
81#endif
int c8_load_palette_f(c8_t *, const char *)
Load palette from the given path into colors.
Definition: chip8.c:129
void c8_deinit(c8_t *)
Deinitialize graphics and free c8.
Definition: chip8.c:55
void c8_simulate(c8_t *)
Main interpreter simulation loop. Exits when c8->running is 0.
Definition: chip8.c:183
#define C8_STACK_SIZE
Definition: chip8.h:16
int c8_load_palette_s(c8_t *, char *)
Load palette from the given string into colors.
Definition: chip8.c:95
void c8_load_quirks(c8_t *, const char *)
Load quirk flags from string.
Definition: chip8.c:162
c8_t * c8_init(const char *, int)
Initialize and return a c8_t with the given flags.
Definition: chip8.c:72
#define C8_MEMSIZE
Definition: defs.h:25
Definition: graphics.h:37
Represents current state of the CHIP-8 interpreter.
Definition: chip8.h:51
int draw
Definition: chip8.h:71
uint16_t I
Definition: chip8.h:60
int waitingForKey
Definition: chip8.h:64
int running
Definition: chip8.h:65
int VK
Definition: chip8.h:62
c8_display_t display
Definition: chip8.h:66
int flags
Definition: chip8.h:67
int cs
Definition: chip8.h:63
uint8_t dt
Definition: chip8.h:56
uint8_t sp
Definition: chip8.h:55
uint16_t pc
Definition: chip8.h:59
uint8_t st
Definition: chip8.h:57