diff --git a/cpu.cpp b/cpu.cpp index 7ccc82a..ef72593 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -247,15 +247,17 @@ int cpu::getPSW_spl() const return (psw >> 5) & 7; } -void cpu::setPSW(uint16_t v, const bool limited) +void cpu::setPSW(const uint16_t v, const bool limited) { if (limited) { - v &= 0174037; + psw |= v & 0174000; // current & previous mode can only be increased, 11 can only be set - v |= psw & 0174340; + psw &= 0174000; // retain upper 5 bit + psw |= v & ~0174000; + } + else { + psw = v; } - - psw = v; } bool cpu::check_queued_interrupts() @@ -1628,15 +1630,10 @@ bool cpu::misc_operations(const uint16_t instr) case 0b0000000000000001: // WAIT return true; - case 0b0000000000000010: { // RTI + case 0b0000000000000010: // RTI setPC(popStack()); - - uint16_t replacement_psw = popStack(); - - setPSW(replacement_psw, true); - + setPSW(popStack(), !!((getPSW() >> 12) & 3)); return true; - } case 0b0000000000000011: // BPT trap(014); @@ -1646,15 +1643,10 @@ bool cpu::misc_operations(const uint16_t instr) trap(020); return true; - case 0b0000000000000110: { // RTT + case 0b0000000000000110: // RTT setPC(popStack()); - - uint16_t replacement_psw = popStack(); - - setPSW(replacement_psw, true); - + setPSW(popStack(), !!((getPSW() >> 12) & 3)); return true; - } case 0b0000000000000111: // MFPT if (emulateMFPT) diff --git a/cpu.h b/cpu.h index ec10c89..01508df 100644 --- a/cpu.h +++ b/cpu.h @@ -117,7 +117,7 @@ public: void setBitPSW(const int bit, const bool v); uint16_t getPSW() const { return psw; } - void setPSW(uint16_t v, const bool limited); + void setPSW(const uint16_t v, const bool limited); uint16_t getStackLimitRegister() { return stackLimitRegister; } void setStackLimitRegister(const uint16_t v) { stackLimitRegister = v; }