aboutsummaryrefslogtreecommitdiffstats
path: root/src/uxn.h
blob: f9bee16fd5abb2c28693bc689dd6b2474eb57804 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef UXNGBA_UXN_H
#define UXNGBA_UXN_H
/*
Copyright (c) 2021 Devine Lu Linvega

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/

#define PAGE_PROGRAM 0x0100

/* clang-format off */

#define GETVEC(d) ((d)[0] << 8 | (d)[1])
#define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
#define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }

/* clang-format on */

typedef struct {
	u8 dat[255], ptr;
} Stack;

typedef struct Uxn {
	u8 *ram, *dev;
	Stack *wst, *rst;
	u8 (*dei)(struct Uxn *u, u8 addr);
	void (*deo)(struct Uxn *u, u8 addr, u8 value);
} Uxn;

typedef u8 Dei(Uxn *u, u8 addr);
typedef void Deo(Uxn *u, u8 addr, u8 value);

int uxn_halt(Uxn *u, u8 instr, u8 err, u16 addr);
int uxn_boot(Uxn *u, u8 *ram, Dei *dei, Deo *deo);
int uxn_eval(Uxn *u, u16 pc);
#endif // UXNGBA_UXN_H