From 9faba4a2b6e52d5f6b35250984155f044399f9ca Mon Sep 17 00:00:00 2001 From: Folkert van Heusden Date: Wed, 9 Apr 2025 08:52:59 +0200 Subject: [PATCH] PSW magic --- cpu.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cpu.cpp b/cpu.cpp index a068758..93f3dce 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -316,10 +316,14 @@ int cpu::getPSW_spl() const void cpu::setPSW(const uint16_t v, const bool limited) { - if (limited) - psw = (psw & 0174340) | (v & 037); - else + if (limited) { + int cur_mode = std::max( v >> 14, psw >> 14); + int prev_mode = std::max((v >> 12) & 3, (psw >> 12) & 3); + psw = (psw & 004340) | (v & 037) | (cur_mode << 14) | (prev_mode << 12); + } + else { psw = v & 0174377; // mask off reserved bits + } } void cpu::setPSW_flags_nzv(const uint16_t value, const word_mode_t word_mode)