aboutsummaryrefslogtreecommitdiffstats
path: root/src/uxn.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/uxn.h')
-rw-r--r--src/uxn.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/uxn.h b/src/uxn.h
new file mode 100644
index 0000000..a4ab428
--- /dev/null
+++ b/src/uxn.h
@@ -0,0 +1,56 @@
1#ifndef UXNGBA_UXN_H
2#define UXNGBA_UXN_H
3
4#include <stdio.h>
5
6/*
7Copyright (c) 2021 Devine Lu Linvega
8
9Permission to use, copy, modify, and distribute this software for any
10purpose with or without fee is hereby granted, provided that the above
11copyright notice and this permission notice appear in all copies.
12
13THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14WITH REGARD TO THIS SOFTWARE.
15*/
16
17#define PAGE_PROGRAM 0x0100
18
19typedef struct {
20 u8 ptr, kptr, error;
21 u8 dat[256];
22} Stack;
23
24typedef struct {
25 u16 ptr;
26 u8 *dat;
27} Memory;
28
29typedef struct Device {
30 struct Uxn *u;
31 u8 addr, dat[16], *mem;
32 void (*talk)(struct Device *d, u8, u8);
33} Device;
34
35typedef struct Uxn {
36 Stack wst, rst, *src, *dst;
37 Memory ram;
38 Device dev[16];
39} Uxn;
40
41struct Uxn;
42
43static inline void mempoke8(u8 *m, u16 a, u8 b) { m[a] = b; }
44static inline u8 mempeek8(u8 *m, u16 a) { return m[a]; }
45static inline void mempoke16(u8 *m, u16 a, u16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); }
46static inline u16 mempeek16(u8 *m, u16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); }
47static inline void devpoke8(Device *d, u8 a, u8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); }
48static inline u8 devpeek8(Device *d, u8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; }
49static inline void devpoke16(Device *d, u8 a, u16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); }
50static inline u16 devpeek16(Device *d, u16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); }
51
52int loaduxn(Uxn *c, char *filepath);
53int bootuxn(Uxn *c);
54int evaluxn(Uxn *u, u16 vec);
55Device *portuxn(Uxn *u, u8 id, char *name, void (*talkfn)(Device *, u8, u8));
56#endif // UXNGBA_UXN_H