mirror of
https://github.com/mnaberez/py65.git
synced 2024-10-31 22:06:12 +00:00
Use the decimally adjusted aluresult to compute the value of flags.
This fixes various bugs with ADC/SBC in decimal mode found by Klaus Dormann's test suite.
This commit is contained in:
parent
32896cc139
commit
666cd9cd99
@ -315,11 +315,14 @@ class MPU:
|
|||||||
# the ALU outputs are not decimally adjusted
|
# the ALU outputs are not decimally adjusted
|
||||||
nibble0 = nibble0 & 0xf
|
nibble0 = nibble0 & 0xf
|
||||||
nibble1 = nibble1 & 0xf
|
nibble1 = nibble1 & 0xf
|
||||||
aluresult = (nibble1 << 4) + nibble0
|
|
||||||
|
|
||||||
# the final A contents will be decimally adjusted
|
# the final A contents will be decimally adjusted
|
||||||
nibble0 = (nibble0 + adjust0) & 0xf
|
nibble0 = (nibble0 + adjust0) & 0xf
|
||||||
nibble1 = (nibble1 + adjust1) & 0xf
|
nibble1 = (nibble1 + adjust1) & 0xf
|
||||||
|
|
||||||
|
# Update result for use in setting flags below
|
||||||
|
aluresult = (nibble1 << 4) + nibble0
|
||||||
|
|
||||||
self.p &= ~(self.CARRY | self.OVERFLOW | self.NEGATIVE | self.ZERO)
|
self.p &= ~(self.CARRY | self.OVERFLOW | self.NEGATIVE | self.ZERO)
|
||||||
if aluresult == 0:
|
if aluresult == 0:
|
||||||
self.p |= self.ZERO
|
self.p |= self.ZERO
|
||||||
@ -420,6 +423,9 @@ class MPU:
|
|||||||
nibble0 = (aluresult + adjust0) & 0xf
|
nibble0 = (aluresult + adjust0) & 0xf
|
||||||
nibble1 = ((aluresult + adjust1) >> 4) & 0xf
|
nibble1 = ((aluresult + adjust1) >> 4) & 0xf
|
||||||
|
|
||||||
|
# Update result for use in setting flags below
|
||||||
|
aluresult = (nibble1 << 4) + nibble0
|
||||||
|
|
||||||
self.p &= ~(self.CARRY | self.ZERO | self.NEGATIVE | self.OVERFLOW)
|
self.p &= ~(self.CARRY | self.ZERO | self.NEGATIVE | self.OVERFLOW)
|
||||||
if aluresult == 0:
|
if aluresult == 0:
|
||||||
self.p |= self.ZERO
|
self.p |= self.ZERO
|
||||||
|
Loading…
Reference in New Issue
Block a user