From 11c7ee45933f3c7d52b848e3ec5035821a64c962 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 12 Jun 2022 20:24:29 +0200 Subject: [PATCH 1/6] locking of input_buffer --- console.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/console.cpp b/console.cpp index 3dbaf77..e739496 100644 --- a/console.cpp +++ b/console.cpp @@ -88,6 +88,8 @@ int console::wait_char(const int timeout_ms) void console::flush_input() { + std::unique_lock lck(input_lock); + input_buffer.clear(); } @@ -229,6 +231,8 @@ void console::operator()() else if (running_flag == false && c == 12) // ^l refresh_virtual_terminal(); else { + std::unique_lock lck(input_lock); + input_buffer.push_back(c); have_data.notify_all(); From 6e17f4b747ba59dfb6a6b696ec526273b52a0d75 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 12 Jun 2022 21:00:26 +0200 Subject: [PATCH 2/6] The disassembler uses peekWord() which would do a real read on i/o devices. That is now replaced by a return 012345 so that the (emulated) devices don't get confused (e.g. the tty would miss characters). --- bus.cpp | 3 +++ bus.h | 2 +- console.cpp | 4 ++-- utils.cpp | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bus.cpp b/bus.cpp index bed9dcb..62e401c 100644 --- a/bus.cpp +++ b/bus.cpp @@ -59,6 +59,9 @@ uint16_t bus::read(const uint16_t a, const bool word_mode, const bool use_prev, if (word_mode) DOLOG(debug, false, "READ I/O %06o in byte mode", a); + if (peek_only) + return 012345; + if (a == 0177750) { // MAINT DOLOG(debug, !peek_only, "read MAINT"); return 1; // POWER OK diff --git a/bus.h b/bus.h index eb50428..0a6dbf2 100644 --- a/bus.h +++ b/bus.h @@ -52,7 +52,7 @@ public: void add_tm11(tm_11 *tm11) { this -> tm11 = tm11; } void add_rk05(rk05 *rk05_) { this -> rk05_ = rk05_; } void add_rl02(rl02 *rl02_) { this -> rl02_ = rl02_; } - void add_tty(tty *tty_) { this -> tty_ = tty_; } + void add_tty(tty *tty_) { this -> tty_ = tty_; } cpu *getCpu() { return this->c; } diff --git a/console.cpp b/console.cpp index e739496..f0d5b1e 100644 --- a/console.cpp +++ b/console.cpp @@ -212,7 +212,7 @@ void console::put_string(const std::string & what) void console::operator()() { - DOLOG(::debug, true, "Console thread started"); + DOLOG(::info, true, "Console thread started"); set_thread_name("kek::console"); @@ -239,5 +239,5 @@ void console::operator()() } } - DOLOG(::debug, true, "Console thread terminating"); + DOLOG(::info, true, "Console thread terminating"); } diff --git a/utils.cpp b/utils.cpp index 213684b..a8435cb 100644 --- a/utils.cpp +++ b/utils.cpp @@ -66,7 +66,7 @@ uint64_t get_us() int parity(int v) { - return __builtin_parity(v); // FIXME + return __builtin_parity(v); // TODO } void myusleep(uint64_t us) From 93e7af7705fd5e87c6be204319254ae4e8cfbb78 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 12 Jun 2022 21:25:11 +0200 Subject: [PATCH 3/6] Only return 012345 for tty (bus). --- bus.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bus.cpp b/bus.cpp index 62e401c..315c070 100644 --- a/bus.cpp +++ b/bus.cpp @@ -59,9 +59,6 @@ uint16_t bus::read(const uint16_t a, const bool word_mode, const bool use_prev, if (word_mode) DOLOG(debug, false, "READ I/O %06o in byte mode", a); - if (peek_only) - return 012345; - if (a == 0177750) { // MAINT DOLOG(debug, !peek_only, "read MAINT"); return 1; // POWER OK @@ -258,8 +255,12 @@ uint16_t bus::read(const uint16_t a, const bool word_mode, const bool use_prev, if (rl02_ && a >= RL02_BASE && a < RL02_END) return word_mode ? rl02_ -> readByte(a) : rl02_ -> readWord(a); - if (tty_ && a >= PDP11TTY_BASE && a < PDP11TTY_END) + if (tty_ && a >= PDP11TTY_BASE && a < PDP11TTY_END) { + if (peek_only) + return 012345; + return word_mode ? tty_ -> readByte(a) : tty_ -> readWord(a); + } // LO size register field must be all 1s, so subtract 1 const uint32_t system_size = n_pages * 8192 / 64 - 1; @@ -375,7 +376,6 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c } else { m_offset = a; - DOLOG(debug, !peek_only, "virtual address %06o maps to physical address %08o", a, m_offset); } return m_offset; From 710cf2bbadb20cddbc0cef7a75d18c214e6c5ce9 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 12 Jun 2022 22:00:45 +0200 Subject: [PATCH 4/6] SBC for registers fix --- cpu.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpu.cpp b/cpu.cpp index b34cdb7..719d542 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -1053,6 +1053,8 @@ bool cpu::single_operand_instructions(const uint16_t instr) if (IS_0(vo, word_mode) && org_c) setPSW_c(true); + + setRegister(dst_reg, false, v); } else { uint16_t a = getGAMAddress(dst_mode, dst_reg, word_mode, false); From ff8f8be672a70ecff7050d8b36cdb7cb62d3a701 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 12 Jun 2022 22:08:11 +0200 Subject: [PATCH 5/6] ADC v flag fix --- cpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu.cpp b/cpu.cpp index 719d542..a8a8ca9 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -1011,7 +1011,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) setPSW_n(SIGN(v, word_mode)); setPSW_z(IS_0(v, word_mode)); - setPSW_v((word_mode ? (vo & 0xff) == 0x80 : vo == 0x8000) && org_c); + setPSW_v((word_mode ? (vo & 0xff) == 0x7f : vo == 0x7fff) && org_c); setPSW_c((word_mode ? (vo & 0xff) == 0xff : vo == 0xffff) && org_c); setRegister(dst_reg, false, v); From 9b3cb02064df27113557f18401b145d357f0b951 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 12 Jun 2022 22:13:04 +0200 Subject: [PATCH 6/6] ADC/SBC fixes --- cpu.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cpu.cpp b/cpu.cpp index a8a8ca9..9680a5b 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -1029,7 +1029,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) if (set_flags) { setPSW_n(SIGN(v, word_mode)); setPSW_z(IS_0(v, word_mode)); - setPSW_v((word_mode ? (vo & 0xff) == 0x80 : vo == 0x8000) && org_c); + setPSW_v((word_mode ? (vo & 0xff) == 0x7f : vo == 0x7fff) && org_c); setPSW_c((word_mode ? (vo & 0xff) == 0xff : vo == 0xffff) && org_c); } } @@ -1049,10 +1049,12 @@ bool cpu::single_operand_instructions(const uint16_t instr) setPSW_n(SIGN(v, word_mode)); setPSW_z(IS_0(v, word_mode)); - setPSW_v(word_mode ? (v & 0xff) == 0x80 : v == 0x8000); + setPSW_v(word_mode ? (vo & 0xff) == 0x80 : vo == 0x8000); if (IS_0(vo, word_mode) && org_c) setPSW_c(true); + else + setPSW_c(false); setRegister(dst_reg, false, v); } @@ -1069,10 +1071,12 @@ bool cpu::single_operand_instructions(const uint16_t instr) if (set_flags) { setPSW_n(SIGN(v, word_mode)); setPSW_z(IS_0(v, word_mode)); - setPSW_v(word_mode? (v & 0xff) == 0x80 : v == 0x8000); + setPSW_v(word_mode? (vo & 0xff) == 0x80 : v == 0x8000); if (IS_0(vo, word_mode) && org_c) setPSW_c(true); + else + setPSW_c(false); } } break;