#ifndef UXNGBA_UXN_H #define UXNGBA_UXN_H #include /* 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; #define PAGE_PROGRAM 0x0100 typedef struct { Uint8 ptr, kptr, error; Uint8 dat[256]; } Stack; typedef struct { Uint16 ptr; Uint8 *dat; } Memory; typedef struct Device { struct Uxn *u; Uint8 addr, dat[16], *mem; void (*talk)(struct Device *d, Uint8, Uint8); } Device; typedef struct Uxn { Stack wst, rst, *src, *dst; Memory ram; Device dev[16]; } Uxn; struct Uxn; static inline void mempoke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; } static inline Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; } static inline void mempoke16(Uint8 *m, Uint16 a, Uint16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); } static inline Uint16 mempeek16(Uint8 *m, Uint16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); } static inline void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } static inline Uint8 devpeek8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } static inline void devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } static inline Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); } int loaduxn(Uxn *c, char *filepath); int bootuxn(Uxn *c); int evaluxn(Uxn *u, Uint16 vec); Device *portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *, Uint8, Uint8)); #endif // UXNGBA_UXN_H