From 1ea465825756749606fca1e930eca7474d2a6b45 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Thu, 31 Mar 2022 13:19:48 +0200 Subject: [PATCH] SIGN --- cpu.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cpu.cpp b/cpu.cpp index 61b84e8..f05154d 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -723,19 +723,20 @@ bool cpu::single_operand_instructions(const uint16_t instr) uint16_t add = word_mode ? v & 0xff00 : 0; v = (v + 1) & (word_mode ? 0xff : 0xffff); + v |= add; - setPSW_n(word_mode ? v > 127 : v > 32767); + setPSW_n(SIGN(v, word_mode)); setPSW_z(v == 0); setPSW_v(word_mode ? v == 0x80 : v == 0x8000); - setRegister(dst_reg, false, v | add); + setRegister(dst_reg, false, v); } else { uint16_t a = getGAMAddress(dst_mode, dst_reg, word_mode, false); uint16_t v = b -> read(a, word_mode); int32_t vl = (v + 1) & (word_mode ? 0xff : 0xffff); - setPSW_n(word_mode ? vl > 127 : vl > 32767); + setPSW_n(SIGN(vl, word_mode)); setPSW_z(vl == 0); setPSW_v(word_mode ? vl == 0x80 : v == 0x8000); @@ -752,7 +753,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) v = (v - 1) & (word_mode ? 0xff : 0xffff); - setPSW_n(word_mode ? v > 127 : v > 32767); + setPSW_n(SIGN(v, word_mode)); setPSW_z(v == 0); setPSW_v(word_mode ? v == 0x7f : v == 0x7fff); @@ -763,7 +764,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) uint16_t v = b -> read(a, word_mode); int32_t vl = (v - 1) & (word_mode ? 0xff : 0xffff); - setPSW_n(word_mode ? vl > 127 : vl > 32767); + setPSW_n(SIGN(vl, word_mode)); setPSW_z(vl == 0); setPSW_v(word_mode ? vl == 0x7f : vl == 0x7fff); @@ -780,7 +781,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) v = (-v) & (word_mode ? 0xff : 0xffff); - setPSW_n(word_mode ? v > 127 : v > 32767); + setPSW_n(SIGN(v, word_mode)); setPSW_z(v == 0); setPSW_v(word_mode ? v == 0x80 : v == 0x8000); @@ -1028,7 +1029,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) uint16_t v = (vl << 1) & (word_mode ? 0xff : 0xffff); uint16_t add = word_mode ? v & 0xff00 : 0; - setPSW_n(word_mode ? v & 0x80 : v & 0x8000); + setPSW_n(SIGN(v, word_mode)); setPSW_z(v == 0); setPSW_c(word_mode ? vl & 0x80 : vl & 0x8000); setPSW_v(getPSW_n() ^ getPSW_c()); @@ -1040,7 +1041,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) int32_t vl = b -> read(a, word_mode); uint16_t v = (vl << 1) & (word_mode ? 0xff : 0xffff); - setPSW_n(word_mode ? v & 0x80 : v & 0x8000); + setPSW_n(SIGN(v, word_mode)); setPSW_z(v == 0); setPSW_c(word_mode ? vl & 0x80 : vl & 0x8000); setPSW_v(getPSW_n() ^ getPSW_c()); @@ -1055,7 +1056,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) uint16_t a = getGAMAddress(dst_mode, dst_reg, false, false); uint16_t v = b -> read(a, false, true); - setPSW_n(word_mode ? v & 0x80 : v & 0x8000); + setPSW_n(SIGN(v, word_mode)); setPSW_z(v == 0); setPSW_v(false); @@ -1070,7 +1071,7 @@ bool cpu::single_operand_instructions(const uint16_t instr) // retrieve word from '15/14'-stack uint16_t v = popStack(); - setPSW_n(word_mode ? v & 0x80 : v & 0x8000); + setPSW_n(SIGN(v, word_mode)); setPSW_z(v == 0); setPSW_v(false);