libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
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 1000
16#define C8_STACK_SIZE 16
17
18#define C8_MODE_CHIP8 0
19#define C8_MODE_SCHIP 1
20#define C8_MODE_XOCHIP 2
21
22#define C8_FLAG_DEBUG 0x1
23#define C8_FLAG_VERBOSE 0x2
24#define C8_FLAG_QUIRK_BITWISE 0x4
25#define C8_FLAG_QUIRK_DRAW 0x8
26#define C8_FLAG_QUIRK_LOADSTORE 0x10
27#define C8_FLAG_QUIRK_SHIFT 0x20
28#define C8_FLAG_QUIRK_JUMP 0x40
29
56typedef struct {
57 uint8_t mem[C8_MEMSIZE];
58 uint8_t R[8];
59 uint8_t V[16];
60 uint8_t sp;
61 uint8_t dt;
62 uint8_t st;
63 uint16_t stack[C8_STACK_SIZE];
64 uint16_t pc;
65 uint16_t I;
66 int key[18];
67 int VK;
68 int cs;
72 int flags;
73 int breakpoints[C8_MEMSIZE];
74 int colors[2];
75 int fonts[2];
76 int draw;
77 int mode;
78} c8_t;
79
80void c8_deinit(c8_t*);
81c8_t* c8_init(const char*, int);
82int c8_load_palette_s(c8_t*, char*);
83int c8_load_palette_f(c8_t*, const char*);
84void c8_load_quirks(c8_t*, const char*);
85void c8_simulate(c8_t*);
86
87#endif
int c8_load_palette_f(c8_t *, const char *)
Load palette from the given path into colors.
Definition: chip8.c:115
void c8_deinit(c8_t *)
Deinitialize graphics and free c8.
Definition: chip8.c:32
void c8_simulate(c8_t *)
Main interpreter simulation loop. Exits when c8->running is 0.
Definition: chip8.c:163
#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:80
void c8_load_quirks(c8_t *, const char *)
Load quirk flags from string.
Definition: chip8.c:145
c8_t * c8_init(const char *, int)
Initialize and return a c8_t with the given flags.
Definition: chip8.c:49
#define C8_MEMSIZE
Definition: defs.h:25
Definition: graphics.h:37
Represents current state of the CHIP-8 interpreter.
Definition: chip8.h:56
int draw
Definition: chip8.h:76
uint16_t I
Definition: chip8.h:65
int mode
Definition: chip8.h:77
int waitingForKey
Definition: chip8.h:69
int running
Definition: chip8.h:70
int VK
Definition: chip8.h:67
c8_display_t display
Definition: chip8.h:71
int flags
Definition: chip8.h:72
int cs
Definition: chip8.h:68
uint8_t dt
Definition: chip8.h:61
uint8_t sp
Definition: chip8.h:60
uint16_t pc
Definition: chip8.h:64
uint8_t st
Definition: chip8.h:62