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
|
|
|
|
|
2022-01-03 16:23:57 -05: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); }
|
|
|
|
|
|
|
|
/* clang-format on */
|
|
|
|
|
2021-02-08 15:16:39 -05:00
|
|
|
typedef struct {
|
2022-01-02 18:26:13 -05:00
|
|
|
Uint8 ptr;
|
2022-01-05 23:44:33 -05:00
|
|
|
Uint8 dat[255];
|
2021-02-15 13:12:44 -05:00
|
|
|
} Stack;
|
2021-02-08 15:16:39 -05:00
|
|
|
|
2021-02-09 13:58:06 -05:00
|
|
|
typedef struct Device {
|
2021-04-27 16:10:58 -04:00
|
|
|
struct Uxn *u;
|
2021-04-20 23:38:15 -04:00
|
|
|
Uint8 addr, dat[16], *mem;
|
2021-09-22 15:16:16 -04:00
|
|
|
Uint16 vector;
|
2021-11-04 12:38:32 -04:00
|
|
|
Uint8 (*dei)(struct Device *d, Uint8);
|
|
|
|
void (*deo)(struct Device *d, Uint8);
|
2021-02-09 00:59:46 -05:00
|
|
|
} Device;
|
|
|
|
|
2021-03-22 17:22:06 -04:00
|
|
|
typedef struct Uxn {
|
2022-01-05 22:48:51 -05:00
|
|
|
Stack *wst, *rst;
|
2022-01-03 20:36:21 -05:00
|
|
|
Uint8 *ram;
|
2021-02-28 14:41:28 -05:00
|
|
|
Device dev[16];
|
2021-02-08 17:18:01 -05:00
|
|
|
} Uxn;
|
2021-02-08 15:16:39 -05:00
|
|
|
|
2022-01-05 22:48:51 -05:00
|
|
|
int uxn_boot(Uxn *u, Stack *wst, Stack *rst, Uint8 *memory);
|
2022-01-03 20:36:21 -05:00
|
|
|
int uxn_eval(Uxn *u, Uint16 pc);
|
2022-01-05 08:06:22 -05:00
|
|
|
int uxn_halt(Uxn *u, Uint8 error, Uint16 addr);
|
2021-11-04 12:38:32 -04:00
|
|
|
Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));
|