Pruned #includes and made minor cleanups in NEDsim header file.
[screensavers] / hacks / NEDsim / simulator.h
CommitLineData
84b74595
AT
1/* (c) 2021 Aaron Taylor <ataylor at subgeniuskitty dot com> */
2/* See LICENSE.txt file for copyright and license details. */
3
84b74595 4#include <stdbool.h>
84b74595
AT
5#include "./a.out.h"
6
84b74595
AT
7/* Bytes per word. */
8#define BPW 4
9
6d0028fd
AT
10/* Syllables per word. */
11#define SPW 5
84b74595 12
6d0028fd
AT
13/* Storage definitions. */
14#define STACK_LENGTH 65536
15#define RAM_LENGTH 67108864
d87b1e06 16#define RAM_BASE_ADDRESS 0x20000000
84b74595 17
84b74595
AT
18struct NEDpsw {
19 bool zero;
20 bool negative;
21};
22
23struct NEDthread {
24 uint32_t stack[STACK_LENGTH];
25 uint32_t sp;
26 uint32_t pc;
27 uint8_t sc;
28 struct NEDpsw * psw;
29};
30
31struct NEDhack {
32 uint32_t iw;
33 bool resume_word;
34};
35
84b74595
AT
36struct NEDstate {
37 bool halted;
38 uint8_t ram[RAM_LENGTH];
d87b1e06
AT
39 /* Although NED is multi-threaded, this screensaver is restricted to a single thread. */
40 struct NEDthread * thread[1];
84b74595
AT
41 struct NEDthread * active_thread;
42 struct NEDhack * hack;
43};
44
45enum syllables {
46 MVSTCK = 0b00001111,
47 JMP = 0b00001110,
48 SWAP = 0b00001101,
49 ADD = 0b00001100,
50 XOR = 0b00001011,
51 NOT = 0b00001010,
52 OR = 0b00001001,
53 AND = 0b00001000,
54 BRZ = 0b00000111,
55 TEST = 0b00000110,
56 CMPSWP = 0b00000101,
57 SHIFT = 0b00000100,
58 STORE = 0b00000011,
59 LOAD = 0b00000010,
60 NOP = 0b00000001,
61 HALT = 0b00000000
62};
63
5923644e 64struct NEDstate * init_simulator(char * input_file);
84b74595
AT
65struct NEDstate * run_simulator(struct NEDstate * state);
66uint32_t ram_r_word(struct NEDstate * state, uint32_t address);
67