diff options
author | Bad Diode <bd@badd10de.dev> | 2023-01-23 13:36:05 +0100 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-01-23 13:36:05 +0100 |
commit | 2c9b9630b38e7e890daf65ef7b65beb1f5a5783f (patch) | |
tree | 979cd45ae5a3ff85d5e8abb2aa13de1780b7bc62 /src/uxn.h | |
parent | 0af009f1c78fd678869a0313078c7d747510a989 (diff) | |
download | uxngba-2c9b9630b38e7e890daf65ef7b65beb1f5a5783f.tar.gz uxngba-2c9b9630b38e7e890daf65ef7b65beb1f5a5783f.zip |
Update UXN core to latest version
This modernizes the uxn core and emulator approach (dei/deo instead of
_talk), forgoing the previous uxn-fast core implementation. As
a consequence, there are some performance regressions. That tradeoff
gives us an easier way of keeping uxngba up to date as it follows more
closely the upstream version.
Diffstat (limited to 'src/uxn.h')
-rw-r--r-- | src/uxn.h | 52 |
1 files changed, 18 insertions, 34 deletions
@@ -1,8 +1,5 @@ | |||
1 | #ifndef UXNGBA_UXN_H | 1 | #ifndef UXNGBA_UXN_H |
2 | #define UXNGBA_UXN_H | 2 | #define UXNGBA_UXN_H |
3 | |||
4 | #include <stdio.h> | ||
5 | |||
6 | /* | 3 | /* |
7 | Copyright (c) 2021 Devine Lu Linvega | 4 | Copyright (c) 2021 Devine Lu Linvega |
8 | 5 | ||
@@ -15,43 +12,30 @@ WITH REGARD TO THIS SOFTWARE. | |||
15 | */ | 12 | */ |
16 | 13 | ||
17 | #define PAGE_PROGRAM 0x0100 | 14 | #define PAGE_PROGRAM 0x0100 |
18 | #define DEVPEEK16(o, x) { (o) = (d->dat[(x)] << 8) + d->dat[(x) + 1]; } | ||
19 | #define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); } | ||
20 | 15 | ||
21 | typedef struct { | 16 | /* clang-format off */ |
22 | u8 ptr, kptr, error; | ||
23 | u8 dat[256]; | ||
24 | } Stack; | ||
25 | 17 | ||
26 | typedef struct { | 18 | #define GETVEC(d) ((d)[0] << 8 | (d)[1]) |
27 | u16 ptr; | 19 | #define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); } |
28 | u8 *dat; | 20 | #define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; } |
29 | } Memory; | ||
30 | 21 | ||
31 | typedef struct Device { | 22 | /* clang-format on */ |
32 | struct Uxn *u; | 23 | |
33 | u8 addr, dat[16], *mem; | 24 | typedef struct { |
34 | u16 vector; | 25 | u8 dat[255], ptr; |
35 | void (*talk)(struct Device *d, u8, u8); | 26 | } Stack; |
36 | } Device; | ||
37 | 27 | ||
38 | typedef struct Uxn { | 28 | typedef struct Uxn { |
39 | Stack wst, rst, *src, *dst; | 29 | u8 *ram, *dev; |
40 | Memory ram; | 30 | Stack *wst, *rst; |
41 | Device dev[16]; | 31 | u8 (*dei)(struct Uxn *u, u8 addr); |
32 | void (*deo)(struct Uxn *u, u8 addr, u8 value); | ||
42 | } Uxn; | 33 | } Uxn; |
43 | 34 | ||
44 | struct Uxn; | 35 | typedef u8 Dei(Uxn *u, u8 addr); |
45 | 36 | typedef void Deo(Uxn *u, u8 addr, u8 value); | |
46 | static inline void mempoke8(u8 *m, u16 a, u8 b) { m[a] = b; } | ||
47 | static inline u8 mempeek8(u8 *m, u16 a) { return m[a]; } | ||
48 | static inline void mempoke16(u8 *m, u16 a, u16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); } | ||
49 | static inline u16 mempeek16(u8 *m, u16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); } | ||
50 | static inline void devpoke8(Device *d, u8 a, u8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } | ||
51 | static inline u8 devpeek8(Device *d, u8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } | ||
52 | static inline void devpoke16(Device *d, u8 a, u16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } | ||
53 | static inline u16 devpeek16(Device *d, u16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); } | ||
54 | 37 | ||
55 | int uxn_eval(Uxn *u, u16 vec); | 38 | int uxn_halt(Uxn *u, u8 instr, u8 err, u16 addr); |
56 | Device *uxn_port(Uxn *u, u8 id, char *name, void (*talkfn)(Device *, u8, u8)); | 39 | int uxn_boot(Uxn *u, u8 *ram, Dei *dei, Deo *deo); |
40 | int uxn_eval(Uxn *u, u16 pc); | ||
57 | #endif // UXNGBA_UXN_H | 41 | #endif // UXNGBA_UXN_H |