Commit | Line | Data |
---|---|---|
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 | 5 | |
84b74595 AT |
6 | /* Bytes per word. */ |
7 | #define BPW 4 | |
8 | ||
6d0028fd AT |
9 | /* Syllables per word. */ |
10 | #define SPW 5 | |
84b74595 | 11 | |
6d0028fd AT |
12 | /* Storage definitions. */ |
13 | #define STACK_LENGTH 65536 | |
14 | #define RAM_LENGTH 67108864 | |
d87b1e06 | 15 | #define RAM_BASE_ADDRESS 0x20000000 |
84b74595 | 16 | |
84b74595 AT |
17 | struct NEDpsw { |
18 | bool zero; | |
19 | bool negative; | |
20 | }; | |
21 | ||
22 | struct NEDthread { | |
23 | uint32_t stack[STACK_LENGTH]; | |
24 | uint32_t sp; | |
25 | uint32_t pc; | |
26 | uint8_t sc; | |
27 | struct NEDpsw * psw; | |
28 | }; | |
29 | ||
30 | struct NEDhack { | |
31 | uint32_t iw; | |
32 | bool resume_word; | |
33 | }; | |
34 | ||
84b74595 AT |
35 | struct NEDstate { |
36 | bool halted; | |
37 | uint8_t ram[RAM_LENGTH]; | |
d87b1e06 AT |
38 | /* Although NED is multi-threaded, this screensaver is restricted to a single thread. */ |
39 | struct NEDthread * thread[1]; | |
84b74595 AT |
40 | struct NEDthread * active_thread; |
41 | struct NEDhack * hack; | |
42 | }; | |
43 | ||
44 | enum syllables { | |
45 | MVSTCK = 0b00001111, | |
46 | JMP = 0b00001110, | |
47 | SWAP = 0b00001101, | |
48 | ADD = 0b00001100, | |
49 | XOR = 0b00001011, | |
50 | NOT = 0b00001010, | |
51 | OR = 0b00001001, | |
52 | AND = 0b00001000, | |
53 | BRZ = 0b00000111, | |
54 | TEST = 0b00000110, | |
55 | CMPSWP = 0b00000101, | |
56 | SHIFT = 0b00000100, | |
57 | STORE = 0b00000011, | |
58 | LOAD = 0b00000010, | |
59 | NOP = 0b00000001, | |
60 | HALT = 0b00000000 | |
61 | }; | |
62 | ||
5923644e | 63 | struct NEDstate * init_simulator(char * input_file); |
84b74595 AT |
64 | struct NEDstate * run_simulator(struct NEDstate * state); |
65 | uint32_t ram_r_word(struct NEDstate * state, uint32_t address); | |
66 |