xyw.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#ifndef XYW_H
#define XYW_H
#define XYW_MODE_X 0x80
#define XYW_MODE_Y 0x40
#define XYW_MODE_W 0x20
#define XYW_TOTAL_INSTRUCTIONS 0x20
#define XYW_TOTAL_DEVICES 0x10
#define XYW_ARGUMENT_SEPARATOR 0x1E
#define XYW_END_OF_ARGUMENTS 0x1D
typedef unsigned char xyw_byte;
typedef unsigned short xyw_word;
// clang-format off
#define XYW_PEEKW(d) (*(d) << 8 | (d)[1])
#define XYW_POKEW(d, v) { *(d) = (v) >> 8; (d)[1] = (v); }
#define XYW_DBG(...) do { if (xyw_debug) fprintf(stdout, __VA_ARGS__); } while(0)
// clang-format on
// Devices API
typedef xyw_byte (*xyw_input)(xyw_byte *data, xyw_byte addr, xyw_byte *error);
typedef void (*xyw_output)(xyw_byte *data, xyw_byte addr, xyw_byte *error);
typedef void (*xyw_setup)(xyw_byte *data);
typedef void (*xyw_teardown)(xyw_byte *data);
typedef struct xyw_device
{
xyw_byte *data;
xyw_setup setup;
xyw_input input;
xyw_output output;
xyw_teardown teardown;
} xyw_device;
typedef struct
{
xyw_word handler;
int pending;
} xyw_vector_slot;
void xyw_request_vector(xyw_word handler);
// Main Globals
extern xyw_device xyw_devices[XYW_TOTAL_DEVICES];
extern const char xyw_instructions[][4];
extern int xyw_debug;
extern int xyw_argc;
extern char *xyw_argv[];
extern int xyw_argv_processed;
// Main public API
int xyw_assemble(const char *input, const char *output);
int xyw_run(const char *input);
int xyw_eval(xyw_word pc);
#endif // XYW_H
|