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.
|
|
|
|
*/
|
|
|
|
|
2023-01-01 21:19:40 +00:00
|
|
|
/* clang-format off */
|
2023-01-01 19:31:14 +00:00
|
|
|
|
2023-03-12 22:25:52 +00:00
|
|
|
#define POKE2(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); }
|
|
|
|
#define PEEK2(d) ((d)[0] << 8 | (d)[1])
|
2023-08-08 16:23:11 +00:00
|
|
|
#define DEO(p, v) { u->dev[p] = v; if((deo_mask[p >> 4] >> (p & 0xf)) & 0x1) emu_deo(u, p); }
|
2023-08-07 23:12:12 +00:00
|
|
|
#define DEI(p) ((dei_mask[(p) >> 4] >> ((p) & 0xf)) & 0x1 ? emu_dei(u, (p)) : u->dev[(p)])
|
2023-03-01 18:35:42 +00:00
|
|
|
|
2022-01-03 21:23:57 +00:00
|
|
|
/* clang-format on */
|
|
|
|
|
2023-08-08 22:31:48 +00:00
|
|
|
#define PAGE_PROGRAM 0x0100
|
|
|
|
|
2023-03-01 18:35:42 +00:00
|
|
|
typedef unsigned char Uint8;
|
|
|
|
typedef signed char Sint8;
|
|
|
|
typedef unsigned short Uint16;
|
|
|
|
typedef signed short Sint16;
|
|
|
|
typedef unsigned int Uint32;
|
|
|
|
|
2021-02-08 20:16:39 +00:00
|
|
|
typedef struct {
|
2023-01-13 04:35:42 +00:00
|
|
|
Uint8 dat[255], ptr;
|
2021-02-15 18:12:44 +00:00
|
|
|
} Stack;
|
2021-02-08 20:16:39 +00:00
|
|
|
|
2021-03-22 21:22:06 +00:00
|
|
|
typedef struct Uxn {
|
2023-03-12 21:56:44 +00:00
|
|
|
Uint8 *ram, dev[256];
|
2023-04-11 17:14:29 +00:00
|
|
|
Stack wst, rst;
|
2023-01-01 20:04:54 +00:00
|
|
|
Uint8 (*dei)(struct Uxn *u, Uint8 addr);
|
2023-03-04 04:37:43 +00:00
|
|
|
void (*deo)(struct Uxn *u, Uint8 addr);
|
2021-02-08 22:18:01 +00:00
|
|
|
} Uxn;
|
2021-02-08 20:16:39 +00:00
|
|
|
|
2023-03-05 18:44:23 +00:00
|
|
|
/* required functions */
|
2023-01-01 20:04:54 +00:00
|
|
|
|
2023-07-24 02:18:11 +00:00
|
|
|
extern Uint8 emu_dei(Uxn *u, Uint8 addr);
|
|
|
|
extern void emu_deo(Uxn *u, Uint8 addr);
|
|
|
|
extern int emu_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr);
|
2023-08-08 21:44:17 +00:00
|
|
|
extern Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10];
|
2023-03-05 18:44:23 +00:00
|
|
|
|
|
|
|
/* built-ins */
|
|
|
|
|
|
|
|
int uxn_eval(Uxn *u, Uint16 pc);
|