- fix for busy loop in console_posix (due to poll with 0ms timeout)

- disable kw11-l interrupt when emulation is not running
This commit is contained in:
folkert van heusden 2022-06-26 01:41:58 +02:00
parent ea8edbf0c7
commit 2717799df4
7 changed files with 26 additions and 12 deletions

View file

@ -181,14 +181,14 @@ void setup() {
Serial.println(F("Connect CPU to BUS"));
b->add_cpu(c);
Serial.println(F("Start line-frequency interrupt"));
kw11_l *lf = new kw11_l(b);
c->setEmulateMFPT(true);
Serial.println(F("Init console"));
cnsl = new console_esp32(&stop_event, b);
Serial.println(F("Start line-frequency interrupt"));
kw11_l *lf = new kw11_l(b, cnsl);
running = cnsl->get_running_flag();
Serial.println(F("Init TTY"));

View file

@ -32,7 +32,7 @@ int console_posix::wait_for_char_ll(const short timeout)
{
struct pollfd fds[] = { { STDIN_FILENO, POLLIN, timeout } };
if (poll(fds, 1, 0) == 1 && fds[0].revents)
if (poll(fds, 1, timeout) == 1 && fds[0].revents)
return getchar();
return -1;

View file

@ -2232,6 +2232,10 @@ void cpu::step_b()
try {
uint16_t instr = b->readWord(temp_pc);
// FILE *fh = fopen("/home/folkert/kek.dat", "a+");
// fprintf(fh, "%06o %06o\n", temp_pc, instr);
// fclose(fh);
addRegister(7, false, 2);
if (double_operand_instructions(instr))

View file

@ -1,10 +1,12 @@
#include <unistd.h>
#include "console.h"
#include "cpu.h"
#include "kw11-l.h"
#include "utils.h"
kw11_l::kw11_l(bus *const b) : b(b)
kw11_l::kw11_l(bus *const b, console *const cnsl) : b(b), cnsl(cnsl)
{
th = new std::thread(std::ref(*this));
}
@ -21,11 +23,16 @@ kw11_l::~kw11_l()
void kw11_l::operator()()
{
while(!stop_flag) {
b->set_lf_crs_b7();
if (*cnsl->get_running_flag()) {
b->set_lf_crs_b7();
if (b->get_lf_crs() & 64)
b->getCpu()->queue_interrupt(6, 0100);
if (b->get_lf_crs() & 64)
b->getCpu()->queue_interrupt(6, 0100);
usleep(1000000 / 50);
myusleep(1000000 / 50);
}
else {
myusleep(1000000 / 10);
}
}
}

View file

@ -8,11 +8,13 @@ class kw11_l
{
private:
bus *const b { nullptr };
console *const cnsl { nullptr };
std::thread * th { nullptr };
std::atomic_bool stop_flag { false };
public:
kw11_l(bus *const b);
kw11_l(bus *const b, console *const cnsl);
virtual ~kw11_l();
void operator()();

View file

@ -168,8 +168,6 @@ int main(int argc, char *argv[])
c->set_34(mode_34);
kw11_l *lf = new kw11_l(b);
c->setEmulateMFPT(true);
std::atomic_bool interrupt_emulation { false };
@ -235,6 +233,8 @@ int main(int argc, char *argv[])
return 0;
#endif
kw11_l *lf = new kw11_l(b, cnsl);
cnsl->start_thread();
if (run_debugger)

View file

@ -83,6 +83,7 @@ void myusleep(uint64_t us)
struct timespec rem { 0, 0 };
int rc = nanosleep(&req, &rem);
if (rc == 0 || (rc == -1 && errno != EINTR))
break;