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_TICK_SPEED (12 * 60)
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_VF_RESET 0x4
54
58#define C8_FLAG_QUIRK_MEMORY 0x8
59
63#define C8_FLAG_QUIRK_CLIPPING 0x10
64
68#define C8_FLAG_QUIRK_SHIFTING 0x20
69
73#define C8_FLAG_QUIRK_JUMPING 0x40
74
78#define C8_FLAG_QUIRK_VBLANK 0x80
79
84typedef struct {
85 uint8_t mem[C8_MEMSIZE];
86 uint8_t R[8];
87 uint8_t V[16];
88 uint8_t sp;
89 uint8_t dt;
90 uint8_t st;
91 uint16_t stack[C8_STACK_SIZE];
92 uint16_t pc;
93 uint16_t I;
94 int key[18];
95 int VK;
99 int running;
101 int flags;
102 int breakpoints[C8_MEMSIZE];
103 int colors[2];
104 int fonts[2];
105 int mode;
106} C8;
107
108void c8_deinit(C8*);
109C8* c8_init(const char*, int);
110int c8_load_palette_s(C8*, char*);
111int c8_load_palette_f(C8*, const char*);
112int c8_load_quirks(C8*, const char*);
113int c8_load_rom(C8*, const char*);
114int c8_simulate(C8*);
115int c8_validate(const C8*);
116const char* c8_version(void);
117
118#endif
C8 * c8_init(const char *, int)
Initialize and return a C8 with the given flags.
Definition: chip8.c:51
void c8_deinit(C8 *)
Deinitialize graphics and free c8.
Definition: chip8.c:34
int c8_load_palette_s(C8 *, char *)
Load palette from the given string into colors.
Definition: chip8.c:81
#define C8_STACK_SIZE
Maximum stack size.
Definition: chip8.h:23
int c8_simulate(C8 *)
Main interpreter simulation loop. Exits when c8->running is 0.
Definition: chip8.c:229
int c8_load_quirks(C8 *, const char *)
Load quirk flags from string.
Definition: chip8.c:156
int c8_load_palette_f(C8 *, const char *)
Load palette from the given path into colors.
Definition: chip8.c:116
int c8_validate(const C8 *)
Validate the state of the chip8 emulator.
Definition: chip8.c:348
int c8_load_rom(C8 *, const char *)
Load a ROM to c8->mem at path addr.
Definition: chip8.c:193
const char * c8_version(void)
Get the version of libc8.
Definition: chip8.c:391
#define C8_MEMSIZE
Total memory size.
Definition: common.h:74
Represents a graphics display.
Definition: graphics.h:60
Represents current state of the CHIP-8 interpreter.
Definition: chip8.h:84
uint16_t I
Address register.
Definition: chip8.h:93
int mode
Interpreter mode (C8_MODE_CHIP8, C8_MODE_SCHIP, C8_MODE_XOCHIP)
Definition: chip8.h:105
int waitingForDraw
Waiting for draw? (For r quirk)
Definition: chip8.h:98
int waitingForKey
Waiting for keypress?
Definition: chip8.h:97
C8_Display display
Graphics display.
Definition: chip8.h:100
int running
Interpreter running state.
Definition: chip8.h:99
int VK
Register to store next keypress.
Definition: chip8.h:95
int flags
CLI flags.
Definition: chip8.h:101
int tickSpeed
Instructions to execute per second.
Definition: chip8.h:96
uint8_t dt
Delay timer.
Definition: chip8.h:89
uint8_t sp
Stack pointer.
Definition: chip8.h:88
uint16_t pc
Program counter.
Definition: chip8.h:92
uint8_t st
Sound timer.
Definition: chip8.h:90