2021-02-08 15:16:39 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
|
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-02-08 15:16:39 -05:00
|
|
|
|
2021-02-08 17:08:58 -05:00
|
|
|
#define FLAG_HALT 0x01
|
|
|
|
#define FLAG_SHORT 0x02
|
|
|
|
#define FLAG_SIGN 0x04
|
|
|
|
#define FLAG_COND 0x08
|
|
|
|
|
2021-02-08 15:16:39 -05:00
|
|
|
typedef struct {
|
|
|
|
Uint8 ptr;
|
|
|
|
Uint8 dat[256];
|
2021-02-15 13:12:44 -05:00
|
|
|
} Stack;
|
2021-02-08 15:16:39 -05:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Uint16 ptr;
|
|
|
|
Uint8 dat[65536];
|
|
|
|
} Memory;
|
|
|
|
|
2021-02-09 13:58:06 -05:00
|
|
|
typedef struct Device {
|
2021-02-26 22:46:56 -05:00
|
|
|
Uint16 addr;
|
2021-02-26 19:38:20 -05:00
|
|
|
Uint8 (*peek)(Uint8 *, Uint16, Uint8, Uint8);
|
|
|
|
Uint8 (*poke)(Uint8 *, Uint16, Uint8, Uint8);
|
2021-02-09 00:59:46 -05:00
|
|
|
} Device;
|
|
|
|
|
|
|
|
typedef struct {
|
2021-02-26 23:00:01 -05:00
|
|
|
Uint8 literal, status, devices;
|
2021-02-27 11:18:57 -05:00
|
|
|
Uint16 counter, vreset, vframe, verror;
|
2021-02-15 13:12:44 -05:00
|
|
|
Stack wst, rst;
|
2021-02-08 15:16:39 -05:00
|
|
|
Memory 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
|
|
|
|
2021-02-08 17:08:58 -05:00
|
|
|
void setflag(Uint8 *status, char flag, int b);
|
|
|
|
int getflag(Uint8 *status, char flag);
|
2021-02-08 18:46:52 -05:00
|
|
|
int loaduxn(Uxn *c, char *filepath);
|
|
|
|
int bootuxn(Uxn *c);
|
2021-02-09 00:59:46 -05:00
|
|
|
int evaluxn(Uxn *u, Uint16 vec);
|
2021-02-26 22:46:56 -05:00
|
|
|
Device *portuxn(Uxn *u, char *name, Uint8 (*pefn)(Uint8 *, Uint16, Uint8, Uint8), Uint8 (*pofn)(Uint8 *, Uint16, Uint8, Uint8));
|