-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm.h
87 lines (68 loc) · 1.39 KB
/
vm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef VM_H
#define VM_H
#include <stdint.h>
#include <time.h>
#include "timing.h"
#define STACK_SIZE 64
#define SCREEN_WIDTH 64
#define SCREEN_HEIGHT 32
#define SCREEN_WIDTH_HIRES 128
#define SCREEN_HEIGHT_HIRES 64
#define SCREEN_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT)
#define SCREEN_SIZE_HIRES (SCREEN_WIDTH_HIRES * SCREEN_HEIGHT_HIRES)
#define MEMORY_SIZE 4096
#define NOINP_KEYCODE -1
#define HALT_KEYCODE -2
#define MEMDUMP_KEYCODE -3
#define REFRESH_KEYCODE -4
#define DELAY_HZ 60
typedef enum
{
CHIP8 = 0,
SCHIP,
XOCHIP
} extensions_t;
typedef enum
{
LORES = 0,
HIRES
} graphicsmode_t;
typedef struct
{
extensions_t extensions;
uint16_t stack[STACK_SIZE];
union
{
uint8_t screen[SCREEN_SIZE];
uint8_t screenhr[SCREEN_SIZE_HIRES];
};
uint8_t *mem;
uint8_t V[16];
uint16_t I;
uint16_t PC;
uint16_t SP;
uint16_t op;
graphicsmode_t graphicsmode;
uint8_t halt;
uint8_t delay;
uint8_t sound;
timing_t fstart;
timing_t dstart;
uint8_t redrawscreen;
} vm_t;
typedef enum
{
ST_OK = 0,
ST_STACKOVERFLOW,
ST_STACKUNDERFLOW,
ST_SEGFAULT,
ST_QUIRK_UNDEFINED,
ST_OP_UNDEFINED
} status_t;
uint16_t pop(vm_t *vm);
void push(vm_t *vm, uint16_t val);
status_t step(vm_t *vm);
char *sttocstr(status_t st);
char *exttocstr(extensions_t ext);
void draw(vm_t *vm, int x, int y, int n);
#endif