diff --git a/console.cpp b/console.cpp index 532fbda..3cea48b 100644 --- a/console.cpp +++ b/console.cpp @@ -102,6 +102,7 @@ void console::operator()() if (c == 3) // ^c *terminate = true; else if (c == 12) { // ^l + // FIXME for other consoles (e.g. ncurses) this doesn't work too well put_string_ll(format("\033[2J\033[?7l")); fprintf(stderr, "%d %d\n", tx, ty); diff --git a/console_ncurses.cpp b/console_ncurses.cpp index 3a6587e..821bb90 100644 --- a/console_ncurses.cpp +++ b/console_ncurses.cpp @@ -116,8 +116,12 @@ void console_ncurses::panel_update_thread() { cpu *const c = b->getCpu(); + uint64_t prev_instr_cnt = c->get_instructions_executed_count(); + + constexpr int refresh_rate = 50; + while(!*terminate) { - myusleep(1000000 / 50); // 50 updates/sec + myusleep(1000000 / refresh_rate); // note that these are approximately as there's no mutex on the emulation uint16_t current_PC = c->getPC(); @@ -151,6 +155,12 @@ void console_ncurses::panel_update_thread() wattron(w_panel->win, COLOR_PAIR(0)); + uint64_t cur_instr_cnt = c->get_instructions_executed_count(); + + mvwprintw(w_panel->win, 1, 1 + 39, "%8ld", (cur_instr_cnt - prev_instr_cnt) * refresh_rate); + + prev_instr_cnt = cur_instr_cnt; + wmove(w_main->win, ty, tx); mydoupdate(); diff --git a/cpu.cpp b/cpu.cpp index ffad491..a6b9031 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -23,6 +23,19 @@ cpu::~cpu() { } +void cpu::emulation_start() +{ + running_since = get_ms(); +} + +uint64_t cpu::get_instructions_executed_count() +{ + // this may wreck havoc as it is not protected by a mutex + // but a mutex would slow things down too much (as would + // do an atomic) + return instruction_count; +} + void cpu::reset() { memset(regs0_5, 0x00, sizeof regs0_5); @@ -1800,6 +1813,8 @@ void cpu::disassemble() void cpu::step() { + instruction_count++; + check_queued_interrupts(); if (scheduled_trap) { diff --git a/cpu.h b/cpu.h index 5663cb6..ec89a7a 100644 --- a/cpu.h +++ b/cpu.h @@ -20,8 +20,10 @@ private: uint16_t fpsr { 0 }; uint16_t stackLimitRegister { 0 }; uint8_t scheduled_trap { 0 }; - bool runMode { false }; - bool emulateMFPT { false }; + bool runMode { false }; + bool emulateMFPT { false }; + uint64_t instruction_count { 0 }; + uint64_t running_since { 0 }; // level, vector std::map > queued_interrupts; @@ -58,6 +60,9 @@ public: bus *getBus() { return b; } + void emulation_start(); + uint64_t get_instructions_executed_count(); + void reset(); void step(); diff --git a/main.cpp b/main.cpp index 125f92d..1875add 100644 --- a/main.cpp +++ b/main.cpp @@ -259,6 +259,8 @@ int main(int argc, char *argv[]) *running = true; + c->emulation_start(); // for statistics + for(;;) { c->step();