diff options
author | Bad Diode <bd@badd10de.dev> | 2021-05-28 21:05:49 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-05-28 21:05:49 +0200 |
commit | 1fabc50056826ba54ad2a613e5509f3047414cae (patch) | |
tree | 02df450e9d741e3b08d527bf318807c10d0e0ff1 /src/uxn.h | |
parent | 9f3f6720e6ae92641d05b3126cf5b7ce6842d64d (diff) | |
download | uxngba-1fabc50056826ba54ad2a613e5509f3047414cae.tar.gz uxngba-1fabc50056826ba54ad2a613e5509f3047414cae.zip |
Rename source files for flat directory structure
Diffstat (limited to 'src/uxn.h')
-rw-r--r-- | src/uxn.h | 56 |
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 | /* | ||
7 | Copyright (c) 2021 Devine Lu Linvega | ||
8 | |||
9 | Permission to use, copy, modify, and distribute this software for any | ||
10 | purpose with or without fee is hereby granted, provided that the above | ||
11 | copyright notice and this permission notice appear in all copies. | ||
12 | |||
13 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
14 | WITH REGARD TO THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #define PAGE_PROGRAM 0x0100 | ||
18 | |||
19 | typedef struct { | ||
20 | u8 ptr, kptr, error; | ||
21 | u8 dat[256]; | ||
22 | } Stack; | ||
23 | |||
24 | typedef struct { | ||
25 | u16 ptr; | ||
26 | u8 *dat; | ||
27 | } Memory; | ||
28 | |||
29 | typedef struct Device { | ||
30 | struct Uxn *u; | ||
31 | u8 addr, dat[16], *mem; | ||
32 | void (*talk)(struct Device *d, u8, u8); | ||
33 | } Device; | ||
34 | |||
35 | typedef struct Uxn { | ||
36 | Stack wst, rst, *src, *dst; | ||
37 | Memory ram; | ||
38 | Device dev[16]; | ||
39 | } Uxn; | ||
40 | |||
41 | struct Uxn; | ||
42 | |||
43 | static inline void mempoke8(u8 *m, u16 a, u8 b) { m[a] = b; } | ||
44 | static inline u8 mempeek8(u8 *m, u16 a) { return m[a]; } | ||
45 | static inline void mempoke16(u8 *m, u16 a, u16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); } | ||
46 | static inline u16 mempeek16(u8 *m, u16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); } | ||
47 | static inline void devpoke8(Device *d, u8 a, u8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } | ||
48 | static inline u8 devpeek8(Device *d, u8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } | ||
49 | static inline void devpoke16(Device *d, u8 a, u16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } | ||
50 | static inline u16 devpeek16(Device *d, u16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); } | ||
51 | |||
52 | int loaduxn(Uxn *c, char *filepath); | ||
53 | int bootuxn(Uxn *c); | ||
54 | int evaluxn(Uxn *u, u16 vec); | ||
55 | Device *portuxn(Uxn *u, u8 id, char *name, void (*talkfn)(Device *, u8, u8)); | ||
56 | #endif // UXNGBA_UXN_H | ||