aboutsummaryrefslogtreecommitdiffstats
path: root/src/uxn.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-01-23 13:36:05 +0100
committerBad Diode <bd@badd10de.dev>2023-01-23 13:36:05 +0100
commit2c9b9630b38e7e890daf65ef7b65beb1f5a5783f (patch)
tree979cd45ae5a3ff85d5e8abb2aa13de1780b7bc62 /src/uxn.h
parent0af009f1c78fd678869a0313078c7d747510a989 (diff)
downloaduxngba-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.h52
1 files changed, 18 insertions, 34 deletions
diff --git a/src/uxn.h b/src/uxn.h
index 5d68528..f9bee16 100644
--- a/src/uxn.h
+++ b/src/uxn.h
@@ -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/*
7Copyright (c) 2021 Devine Lu Linvega 4Copyright (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
21typedef struct { 16/* clang-format off */
22 u8 ptr, kptr, error;
23 u8 dat[256];
24} Stack;
25 17
26typedef 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
31typedef struct Device { 22/* clang-format on */
32 struct Uxn *u; 23
33 u8 addr, dat[16], *mem; 24typedef struct {
34 u16 vector; 25 u8 dat[255], ptr;
35 void (*talk)(struct Device *d, u8, u8); 26} Stack;
36} Device;
37 27
38typedef struct Uxn { 28typedef 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
44struct Uxn; 35typedef u8 Dei(Uxn *u, u8 addr);
45 36typedef void Deo(Uxn *u, u8 addr, u8 value);
46static inline void mempoke8(u8 *m, u16 a, u8 b) { m[a] = b; }
47static inline u8 mempeek8(u8 *m, u16 a) { return m[a]; }
48static inline void mempoke16(u8 *m, u16 a, u16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); }
49static inline u16 mempeek16(u8 *m, u16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); }
50static inline void devpoke8(Device *d, u8 a, u8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); }
51static inline u8 devpeek8(Device *d, u8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; }
52static inline void devpoke16(Device *d, u8 a, u16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); }
53static inline u16 devpeek16(Device *d, u16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); }
54 37
55int uxn_eval(Uxn *u, u16 vec); 38int uxn_halt(Uxn *u, u8 instr, u8 err, u16 addr);
56Device *uxn_port(Uxn *u, u8 id, char *name, void (*talkfn)(Device *, u8, u8)); 39int uxn_boot(Uxn *u, u8 *ram, Dei *dei, Deo *deo);
40int uxn_eval(Uxn *u, u16 pc);
57#endif // UXNGBA_UXN_H 41#endif // UXNGBA_UXN_H