| 1 | /* (c) 2021 Aaron Taylor <ataylor at subgeniuskitty dot com> */ |
| 2 | /* See LICENSE.txt file for copyright and license details. */ |
| 3 | |
| 4 | #include <stdbool.h> |
| 5 | #include "./a.out.h" |
| 6 | |
| 7 | /* Bytes per word. */ |
| 8 | #define BPW 4 |
| 9 | |
| 10 | /* Syllables per word. */ |
| 11 | #define SPW 5 |
| 12 | |
| 13 | /* Storage definitions. */ |
| 14 | #define STACK_LENGTH 65536 |
| 15 | #define RAM_LENGTH 67108864 |
| 16 | #define RAM_BASE_ADDRESS 0x20000000 |
| 17 | |
| 18 | struct NEDpsw { |
| 19 | bool zero; |
| 20 | bool negative; |
| 21 | }; |
| 22 | |
| 23 | struct 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 | |
| 31 | struct NEDhack { |
| 32 | uint32_t iw; |
| 33 | bool resume_word; |
| 34 | }; |
| 35 | |
| 36 | struct NEDstate { |
| 37 | bool halted; |
| 38 | uint8_t ram[RAM_LENGTH]; |
| 39 | /* Although NED is multi-threaded, this screensaver is restricted to a single thread. */ |
| 40 | struct NEDthread * thread[1]; |
| 41 | struct NEDthread * active_thread; |
| 42 | struct NEDhack * hack; |
| 43 | }; |
| 44 | |
| 45 | enum 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 | |
| 64 | struct NEDstate * init_simulator(char * input_file); |
| 65 | struct NEDstate * run_simulator(struct NEDstate * state); |
| 66 | uint32_t ram_r_word(struct NEDstate * state, uint32_t address); |
| 67 | |