uxn11/src/uxn.h

55 lines
1.5 KiB
C
Raw Normal View History

2022-03-26 20:23:52 -04: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.
*/
typedef unsigned char Uint8;
typedef signed char Sint8;
typedef unsigned short Uint16;
typedef signed short Sint16;
typedef unsigned int Uint32;
#define PAGE_PROGRAM 0x0100
2022-03-26 21:32:46 -04: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); }
#define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1])
2022-04-05 12:17:08 -04:00
2022-04-05 12:10:29 -04:00
#define GETVEC(d) ((d)[0] << 8 | (d)[1])
2022-04-05 12:17:08 -04:00
#define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
2022-04-05 12:22:33 -04:00
#define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }
2022-03-26 21:32:46 -04:00
/* clang-format on */
2022-03-26 20:23:52 -04:00
typedef struct {
2022-03-30 13:37:47 -04:00
Uint8 dat[255],ptr;
2022-03-26 21:32:46 -04:00
} Stack;
2022-03-26 20:23:52 -04:00
typedef struct Device {
struct Uxn *u;
2022-03-26 21:32:46 -04:00
Uint8 dat[16];
2022-03-26 20:23:52 -04:00
Uint8 (*dei)(struct Device *d, Uint8);
void (*deo)(struct Device *d, Uint8);
} Device;
typedef struct Uxn {
2022-04-04 23:04:32 -04:00
Uint8 *ram;
2022-03-30 13:37:47 -04:00
Stack *wst, *rst;
2022-04-04 22:57:44 -04:00
Uint8 (*dei)(struct Uxn *u, Uint8 address);
void (*deo)(struct Uxn *u, Uint8 address, Uint8 value);
2022-03-26 20:23:52 -04:00
Device dev[16];
} Uxn;
2022-03-26 21:32:46 -04:00
int uxn_boot(Uxn *u, Uint8 *ram);
int uxn_eval(Uxn *u, Uint16 pc);
int uxn_halt(Uxn *u, Uint8 error, Uint16 addr);
2022-03-26 20:23:52 -04:00
Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));