-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathuxn_core.h
51 lines (41 loc) · 1.73 KB
/
uxn_core.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
#ifndef __UXN_CORE_H__
#define __UXN_CORE_H__
/*
Copyright (c) 2022-2023 Devine Lu Linvega, Andrew Richards
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 UxnU8;
typedef signed char UxnI8;
typedef unsigned short UxnU16;
typedef struct UxnStack {
UxnU8 num, mem[255];
} UxnStack;
typedef struct UxnCore {
UxnU8 *ram;
UxnStack *wst, *rst;
UxnU8 (*dei)(struct UxnCore *u, unsigned int address);
void (*deo)(struct UxnCore *u, unsigned int address, unsigned int value);
UxnU16 pc, fault;
} UxnCore;
#define UXN_FAULT_DONE 1
#define UXN_FAULT_STACK_UNDERFLOW 2
#define UXN_FAULT_STACK_OVERFLOW 3
#define UXN_FAULT_DIVIDE_BY_ZERO 4
/* Runs up to 'limit' number of Uxn instructions.
Returns limit - (number of instructions executed).
Execution starts at address 'u->pc', so set it (or leave it) as needed.
`u->fault` should be set to 0 before calling.
After returning, `u->fault` indicates the reason execution ended:
0: Instruction limit was reached before executing a halt instruction.
The program needs to execute more before it finishes.
1: The program halted normally after executing a halt instruction.
x: The program halted after an error was encountered.
`u->ram` should point to a buffer 0x10001 bytes in size. The extra byte
prevents 16-bit POKE and PEEK instructions with address 0xFFFF going out
of bounds. Uxn does not wrap those high byte accesses to 0x0. */
unsigned int UxnExec(UxnCore *u, unsigned int limit);
#endif