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.
|
|
|
|
*/
|
|
|
|
|
2022-03-26 21:32:46 -04:00
|
|
|
/* clang-format off */
|
|
|
|
|
2023-08-17 12:27:33 -04:00
|
|
|
#define POKE2(d, v) { *(d) = (v) >> 8; (d)[1] = (v); }
|
|
|
|
#define PEEK2(d) (*(d) << 8 | (d)[1])
|
|
|
|
#define DEI(p) (u->dei_masks[p] ? emu_dei(u, (p)) : u->dev[(p)])
|
|
|
|
#define DEO(p, v) { u->dev[p] = v; if(u->deo_masks[p]) emu_deo(u, p); }
|
2023-04-10 13:08:40 -04:00
|
|
|
|
2022-03-26 21:32:46 -04:00
|
|
|
/* clang-format on */
|
2022-03-26 20:23:52 -04:00
|
|
|
|
2023-08-08 19:26:13 -04:00
|
|
|
#define PAGE_PROGRAM 0x0100
|
|
|
|
|
2023-04-10 14:32:16 -04:00
|
|
|
typedef unsigned char Uint8;
|
|
|
|
typedef signed char Sint8;
|
|
|
|
typedef unsigned short Uint16;
|
|
|
|
typedef signed short Sint16;
|
|
|
|
typedef unsigned int Uint32;
|
|
|
|
|
2022-03-26 20:23:52 -04:00
|
|
|
typedef struct {
|
2023-08-17 12:27:33 -04:00
|
|
|
Uint8 dat[0x100], ptr;
|
2022-03-26 21:32:46 -04:00
|
|
|
} Stack;
|
2022-03-26 20:23:52 -04:00
|
|
|
|
|
|
|
typedef struct Uxn {
|
2023-08-17 12:27:33 -04:00
|
|
|
Uint8 *ram, dev[0x100], dei_masks[0x100], deo_masks[0x100];
|
2023-04-11 12:25:31 -04:00
|
|
|
Stack wst, rst;
|
2022-03-26 20:23:52 -04:00
|
|
|
} Uxn;
|
|
|
|
|
2023-04-10 14:32:16 -04:00
|
|
|
/* required functions */
|
|
|
|
|
2023-08-01 23:32:42 -04: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 19:26:13 -04:00
|
|
|
extern Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10];
|
2023-04-10 14:32:16 -04:00
|
|
|
|
|
|
|
/* built-ins */
|
2022-06-13 15:06:16 -04:00
|
|
|
|
2023-04-30 14:43:33 -04:00
|
|
|
int uxn_eval(Uxn *u, Uint16 pc);
|