2021-02-08 20:17:50 +00: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 20:16:39 +00:00
|
|
|
typedef unsigned char Uint8;
|
2021-02-13 00:18:52 +00:00
|
|
|
typedef signed char Sint8;
|
2021-02-08 20:16:39 +00:00
|
|
|
typedef unsigned short Uint16;
|
2021-02-13 00:18:52 +00:00
|
|
|
typedef signed short Sint16;
|
2021-12-25 22:29:36 +00:00
|
|
|
typedef unsigned int Uint32;
|
2021-02-08 20:16:39 +00:00
|
|
|
|
2021-04-20 21:30:26 +00:00
|
|
|
#define PAGE_PROGRAM 0x0100
|
2022-01-07 03:20:50 +00:00
|
|
|
#define VISOR_DEV 0xfa00
|
|
|
|
#define VISOR_WST 0xfb00
|
|
|
|
#define VISOR_RST 0xfc00
|
2022-01-07 02:49:54 +00:00
|
|
|
#define PAGE_DEV 0xfd00
|
2022-01-07 01:29:34 +00:00
|
|
|
#define PAGE_WST 0xfe00
|
|
|
|
#define PAGE_RST 0xff00
|
2021-04-20 21:30:26 +00:00
|
|
|
|
2022-01-03 21:23:57 +00:00
|
|
|
/* clang-format off */
|
|
|
|
|
|
|
|
#define DEVPEEK16(o, x) { (o) = (d->dat[(x)] << 8) + d->dat[(x) + 1]; }
|
|
|
|
#define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
|
2022-01-08 00:46:50 +00:00
|
|
|
#define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1])
|
2022-01-03 21:23:57 +00:00
|
|
|
|
|
|
|
/* clang-format on */
|
|
|
|
|
2021-02-08 20:16:39 +00:00
|
|
|
typedef struct {
|
2022-01-07 03:20:50 +00:00
|
|
|
Uint8 ptr, dat[255];
|
2021-02-15 18:12:44 +00:00
|
|
|
} Stack;
|
2021-02-08 20:16:39 +00:00
|
|
|
|
2021-02-09 18:58:06 +00:00
|
|
|
typedef struct Device {
|
2021-04-27 20:10:58 +00:00
|
|
|
struct Uxn *u;
|
2022-01-07 03:20:50 +00:00
|
|
|
Uint8 *dat, *mem;
|
2021-11-04 16:38:32 +00:00
|
|
|
Uint8 (*dei)(struct Device *d, Uint8);
|
|
|
|
void (*deo)(struct Device *d, Uint8);
|
2021-02-09 05:59:46 +00:00
|
|
|
} Device;
|
|
|
|
|
2021-03-22 21:22:06 +00:00
|
|
|
typedef struct Uxn {
|
2022-01-07 03:20:50 +00:00
|
|
|
Uint8 *ram, *devpage;
|
2022-01-06 03:48:51 +00:00
|
|
|
Stack *wst, *rst;
|
2021-02-28 19:41:28 +00:00
|
|
|
Device dev[16];
|
2021-02-08 22:18:01 +00:00
|
|
|
} Uxn;
|
2021-02-08 20:16:39 +00:00
|
|
|
|
2022-01-07 03:20:50 +00:00
|
|
|
int uxn_boot(Uxn *u, Uint8 *ram, Uint8 *devpage, Stack *wst, Stack *rst);
|
2022-01-04 01:36:21 +00:00
|
|
|
int uxn_eval(Uxn *u, Uint16 pc);
|
2022-01-05 13:06:22 +00:00
|
|
|
int uxn_halt(Uxn *u, Uint8 error, Uint16 addr);
|
2022-01-07 19:48:09 +00:00
|
|
|
Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));
|