-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathavr11.cc
76 lines (62 loc) · 1.63 KB
/
avr11.cc
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <assert.h>
#include <cstdlib>
#include <setjmp.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include "avr11.h"
#include "kb11.h"
KB11 cpu;
void setup(char *disk) {
struct termios old_terminal_settings, new_terminal_settings;
// Get the current terminal settings
if (tcgetattr(0, &old_terminal_settings) < 0)
perror("tcgetattr()");
memcpy(&new_terminal_settings, &old_terminal_settings,
sizeof(struct termios));
// disable canonical mode processing in the line discipline driver
new_terminal_settings.c_iflag &= ~ICRNL;
new_terminal_settings.c_lflag &= ~ICANON;
new_terminal_settings.c_lflag &= ~ECHO;
// apply our new settings
if (tcsetattr(0, TCSANOW, &new_terminal_settings) < 0)
perror("tcsetattr ICANON");
cpu.unibus.rk11.rkdata = fopen(disk, "rb+");
cpu.reset();
printf("Ready\n");
}
jmp_buf trapbuf;
void loop0();
[[noreturn]] void trap(uint16_t vec) { longjmp(trapbuf, vec); }
void loop() {
auto vec = setjmp(trapbuf);
if (vec == 0) {
loop0();
} else {
cpu.trapat(vec);
}
}
void loop0() {
while (true) {
cpu.step();
if ((cpu.itab[0].vec > 0) && (cpu.itab[0].pri >= cpu.priority())) {
cpu.trapat(cpu.itab[0].vec);
cpu.popirq();
return; // exit from loop to reset trapbuf
}
cpu.unibus.rk11.step();
cpu.unibus.cons.poll();
}
}
int main(int argc, char *argv[]) {
assert(argc > 1);
setup(argv[1]);
while (1)
loop();
}
void panic() {
cpu.printstate();
std::abort();
}