-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavr11.cpp
103 lines (91 loc) · 2.27 KB
/
avr11.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <assert.h>
#include <cstdlib>
#include <setjmp.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "avr11.h"
#include "kb11.h"
#include <M5Core2.h>
#include <ESP32Time.h>
KB11 cpu;
int kbdelay = 0;
int clkdelay = 0;
uint64_t systime,nowtime,clkdiv;
ESP32Time SystemTime;
int runFlag = 0, btcntr = 0;
float btlvl;
int RLTYPE;
void setup( char *rkfile, char *rlfile, int bootdev)
{
if (cpu.unibus.rk11.rk05)
return;
cpu.unibus.rk11.rk05 = SD.open(rkfile,"rb+");
cpu.unibus.rl11.rl02 = SD.open(rlfile,"rb+");
RLTYPE = 035;
if (strcasestr(rlfile, ".rl02"))
RLTYPE = 0235;
clkdiv = (uint64_t)1000000 / (uint64_t)60;
systime = SystemTime.getMillis();
cpu.reset(02002,bootdev);
Serial.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() {
char bbfr[32];
M5.Lcd.setTextColor(TFT_ORANGE, TFT_BLACK);
while (true) {
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
}
if (!cpu.wtstate)
cpu.step();
cpu.unibus.rk11.step();
cpu.unibus.rl11.step();
if (kbdelay++ == 1000) {
cpu.unibus.cons.poll();
cpu.unibus.dl11.poll();
kbdelay = 0;
nowtime = SystemTime.getMillis();
M5.update();
if (btcntr++ == 1000) {
btcntr = 0;
btlvl = M5.Axp.GetBatteryLevel();
sprintf(bbfr, "%3d%%", (int)btlvl);
M5.Lcd.fillCircle(160, 165, 30, GREEN);
M5.Lcd.setCursor(135, 170);
M5.Lcd.print(bbfr);
}
}
if (nowtime-systime > 20) {
cpu.unibus.kw11.tick();
systime = nowtime;
}
}
}
int startup( char *rkfile, char *rlfile, int bootdev)
{
setup(rkfile,rlfile,bootdev);
runFlag++;
while (1)
loop();
}
void panic() {
cpu.printstate();
std::abort();
}