libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
chip8.h
Go to the documentation of this file.
1
7#ifndef C8_CHIP8_H
8#define C8_CHIP8_H
9
10#include "common.h"
11#include "graphics.h"
12
13#include <stdint.h>
14
18#define C8_CLOCK_SPEED 1000
19
23#define C8_STACK_SIZE 16
24
28#define C8_MODE_CHIP8 0
29
33#define C8_MODE_SCHIP 1
34
38#define C8_MODE_XOCHIP 2
39
43#define C8_FLAG_DEBUG 0x1
44
48#define C8_FLAG_VERBOSE 0x2
49
53#define C8_FLAG_QUIRK_BITWISE 0x4
54
58#define C8_FLAG_QUIRK_DRAW 0x8
59
63#define C8_FLAG_QUIRK_LOADSTORE 0x10
64
68#define C8_FLAG_QUIRK_SHIFT 0x20
69
73#define C8_FLAG_QUIRK_JUMP 0x40
74
79typedef struct {
80 uint8_t mem[C8_MEMSIZE];
81 uint8_t R[8];
82 uint8_t V[16];
83 uint8_t sp;
84 uint8_t dt;
85 uint8_t st;
86 uint16_t stack[C8_STACK_SIZE];
87 uint16_t pc;
88 uint16_t I;
89 int key[18];
90 int VK;
91 int cs;
93 int running;
95 int flags;
96 int breakpoints[C8_MEMSIZE];
97 int colors[2];
98 int fonts[2];
99 int draw;
100 int mode;
101} C8;
102
103void c8_deinit(C8*);
104C8* c8_init(const char*, int);
105int c8_load_palette_s(C8*, char*);
106int c8_load_palette_f(C8*, const char*);
107void c8_load_quirks(C8*, const char*);
108int c8_load_rom(C8*, const char*);
109const char* c8_version(void);
110void c8_simulate(C8*);
111
112#endif
C8 * c8_init(const char *, int)
Initialize and return a C8 with the given flags.
Definition: chip8.c:46
void c8_deinit(C8 *)
Deinitialize graphics and free c8.
Definition: chip8.c:29
int c8_load_palette_s(C8 *, char *)
Load palette from the given string into colors.
Definition: chip8.c:78
void c8_load_quirks(C8 *, const char *)
Load quirk flags from string.
Definition: chip8.c:143
#define C8_STACK_SIZE
Maximum stack size.
Definition: chip8.h:23
void c8_simulate(C8 *)
Main interpreter simulation loop. Exits when c8->running is 0.
Definition: chip8.c:208
int c8_load_palette_f(C8 *, const char *)
Load palette from the given path into colors.
Definition: chip8.c:111
int c8_load_rom(C8 *, const char *)
Load a ROM to c8->mem at path addr.
Definition: chip8.c:175
const char * c8_version(void)
Get the version of libc8.
Definition: chip8.c:295
#define C8_MEMSIZE
Total memory size.
Definition: common.h:74
Represents a graphics display.
Definition: graphics.h:70
Represents current state of the CHIP-8 interpreter.
Definition: chip8.h:79
int draw
Need to draw? (1 or 0)
Definition: chip8.h:99
uint16_t I
Address register.
Definition: chip8.h:88
int mode
Interpreter mode (C8_MODE_CHIP8, C8_MODE_SCHIP, C8_MODE_XOCHIP)
Definition: chip8.h:100
int waitingForKey
Waiting for keypress?
Definition: chip8.h:92
C8_Display display
Graphics display.
Definition: chip8.h:94
int running
Interpreter running state.
Definition: chip8.h:93
int VK
Register to store next keypress.
Definition: chip8.h:90
int flags
CLI flags.
Definition: chip8.h:95
int cs
Instructions to execute per second.
Definition: chip8.h:91
uint8_t dt
Delay timer.
Definition: chip8.h:84
uint8_t sp
Stack pointer.
Definition: chip8.h:83
uint16_t pc
Program counter.
Definition: chip8.h:87
uint8_t st
Sound timer.
Definition: chip8.h:85