2021-02-08 15:17:50 -05:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-02-08 15:16:39 -05:00
|
|
|
typedef unsigned char Uint8;
|
2021-02-12 19:18:52 -05:00
|
|
|
typedef signed char Sint8;
|
2021-02-08 15:16:39 -05:00
|
|
|
typedef unsigned short Uint16;
|
2021-02-12 19:18:52 -05:00
|
|
|
typedef signed short Sint16;
|
2021-12-25 17:29:36 -05:00
|
|
|
typedef unsigned int Uint32;
|
2021-02-08 15:16:39 -05:00
|
|
|
|
2021-04-20 17:30:26 -04:00
|
|
|
#define PAGE_PROGRAM 0x0100
|
|
|
|
|
2023-01-01 16:19:40 -05:00
|
|
|
/* clang-format off */
|
2023-01-01 14:31:14 -05:00
|
|
|
|
|
|
|
#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]; }
|
|
|
|
|
2022-01-03 16:23:57 -05:00
|
|
|
/* clang-format on */
|
|
|
|
|
2021-02-08 15:16:39 -05:00
|
|
|
typedef struct {
|
2023-01-12 23:35:42 -05:00
|
|
|
Uint8 dat[255], ptr;
|
2021-02-15 13:12:44 -05:00
|
|
|
} Stack;
|
2021-02-08 15:16:39 -05:00
|
|
|
|
2021-03-22 17:22:06 -04:00
|
|
|
typedef struct Uxn {
|
2023-01-01 15:21:30 -05:00
|
|
|
Uint8 *ram, *dev;
|
2023-01-01 16:19:40 -05:00
|
|
|
Stack *wst, *rst;
|
2023-01-01 15:04:54 -05:00
|
|
|
Uint8 (*dei)(struct Uxn *u, Uint8 addr);
|
|
|
|
void (*deo)(struct Uxn *u, Uint8 addr, Uint8 value);
|
2021-02-08 17:18:01 -05:00
|
|
|
} Uxn;
|
2021-02-08 15:16:39 -05:00
|
|
|
|
2023-01-01 15:04:54 -05:00
|
|
|
typedef Uint8 Dei(Uxn *u, Uint8 addr);
|
|
|
|
typedef void Deo(Uxn *u, Uint8 addr, Uint8 value);
|
|
|
|
|
2023-01-01 21:26:28 -05:00
|
|
|
int uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr);
|
2023-01-01 15:04:54 -05:00
|
|
|
int uxn_boot(Uxn *u, Uint8 *ram, Dei *dei, Deo *deo);
|
2022-01-03 20:36:21 -05:00
|
|
|
int uxn_eval(Uxn *u, Uint16 pc);
|