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