LibDCPU16
dcpu.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "bool.h"
4 #include "hardware.h"
5 #include "register.h"
6 
7 #include <stdint.h>
8 #include <stdlib.h>
9 
10 #ifdef WASM
11 #define DLLEXPORT
12 #else
13 #define DLLEXPORT __declspec(dllexport)
14 #endif
15 
17 #define DCPU_HARDWARE_CAPACITY 16
18 
20 #define DCPU_MEMORY_SIZE 131072 // 65536 (0x10000) words * 2 bytes per word
21 
23 struct dcpu;
24 
26 typedef struct dcpu* DCPU;
27 
29 {
32 };
33 
34 typedef enum dcpu_error DCPU_ERROR;
35 
41 typedef void(*dcpu_error_handler)(DCPU dcpu, DCPU_ERROR error);
42 
47 DLLEXPORT DCPU dcpu_create(void);
48 
53 DLLEXPORT void dcpu_destroy(DCPU dcpu);
54 
59 DLLEXPORT void dcpu_reset(DCPU dcpu);
60 
65 DLLEXPORT void dcpu_power_on(DCPU dcpu);
66 
71 DLLEXPORT void dcpu_power_off(DCPU dcpu);
72 
82 DLLEXPORT void dcpu_flash(DCPU dcpu, char* bytes, size_t length);
83 
93 
99 DLLEXPORT void dcpu_cycle(DCPU dcpu);
100 
107 DLLEXPORT void dcpu_process(DCPU dcpu, size_t cycles);
108 
118 DLLEXPORT void dcpu_interrupt(DCPU dcpu, uint16_t message);
119 
127 DLLEXPORT void dcpu_set_register(DCPU dcpu, enum Register r, uint16_t value);
128 
136 DLLEXPORT uint16_t dcpu_get_register(DCPU dcpu, enum Register r);
137 
143 DLLEXPORT uint16_t* dcpu_memory(DCPU dcpu);
144 
149 DLLEXPORT void dcpu_tick(DCPU dcpu);
150 
155 DLLEXPORT void dcpu_on_error(dcpu_error_handler error_handler);
156 
157 size_t dcpu_queue_size(DCPU dcpu);
enum dcpu_error DCPU_ERROR
Definition: dcpu.h:34
DLLEXPORT DCPU dcpu_create(void)
Definition: dcpu.c:208
Definition: dcpu.h:31
Definition: hardware.h:50
DLLEXPORT void dcpu_power_on(DCPU dcpu)
Definition: dcpu.c:292
DLLEXPORT void dcpu_set_register(DCPU dcpu, enum Register r, uint16_t value)
Definition: dcpu.c:1015
DLLEXPORT void dcpu_process(DCPU dcpu, size_t cycles)
Definition: dcpu.c:979
DLLEXPORT void dcpu_flash(DCPU dcpu, char *bytes, size_t length)
Definition: dcpu.c:322
DLLEXPORT void dcpu_interrupt(DCPU dcpu, uint16_t message)
Definition: dcpu.c:997
DLLEXPORT void dcpu_tick(DCPU dcpu)
Definition: dcpu.c:1060
Definition: dcpu.h:30
DLLEXPORT void dcpu_on_error(dcpu_error_handler error_handler)
Definition: dcpu.c:1078
DLLEXPORT uint16_t * dcpu_memory(DCPU dcpu)
Definition: dcpu.c:1045
Definition: dcpu.c:177
DLLEXPORT void dcpu_power_off(DCPU dcpu)
Definition: dcpu.c:307
DLLEXPORT void dcpu_cycle(DCPU dcpu)
Definition: dcpu.c:485
size_t dcpu_queue_size(DCPU dcpu)
Definition: dcpu.c:1083
DLLEXPORT HARDWARE dcpu_attach(DCPU dcpu)
Definition: dcpu.c:349
struct dcpu * DCPU
Definition: dcpu.h:26
DLLEXPORT void dcpu_reset(DCPU dcpu)
Definition: dcpu.c:251
DLLEXPORT uint16_t dcpu_get_register(DCPU dcpu, enum Register r)
Definition: dcpu.c:1030
#define DLLEXPORT
Definition: dcpu.h:13
void(* dcpu_error_handler)(DCPU dcpu, DCPU_ERROR error)
Definition: dcpu.h:41
Register
Definition: register.h:4
DLLEXPORT void dcpu_destroy(DCPU dcpu)
Definition: dcpu.c:230
dcpu_error
Definition: dcpu.h:28