diff --git a/CHANGES.txt b/CHANGES.txt index a8a5f03..680076c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -29,6 +29,11 @@ Next Release Overflow (V) flag. This fixes a failure in Rob Finch's test suite. Closes #6. + - Applied patch from Ed Spittles so that SBC now properly sets the + Carry (C) and Zero (Z) flags. This fixes failures caught by Ed's + own tests (see http://forum.6502.org/viewtopic.php?p=8854#8854). + Closes #15. + - A new "save" command has been added to the monitor that will save a range of memory to a binary file. diff --git a/src/py65/devices/mpu6502.py b/src/py65/devices/mpu6502.py index 9df3bda..566e8a8 100644 --- a/src/py65/devices/mpu6502.py +++ b/src/py65/devices/mpu6502.py @@ -382,17 +382,17 @@ class MPU: else: borrow = 1 - result = self.a - data - borrow + result = self.a + (~data & 0xFF) + (self.p & self.CARRY) self.p &= ~(self.CARRY + self.ZERO + self.OVERFLOW + self.NEGATIVE) if ( (self.a ^ data) & (self.a ^ result) ) & 0x80: self.p |= self.OVERFLOW - data = result + data = result & 0xFF if data == 0: - self.p |= self.ZERO + self.CARRY - elif data > 0: + self.p |= self.ZERO + if result & 0x100: self.p |= self.CARRY self.p |= data & self.NEGATIVE - self.a = data & 0xFF + self.a = data def opDECR(self, x): if x is None: