1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-11 09:29:30 +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:
kris 2017-05-11 22:43:08 +01:00
parent 32896cc139
commit 666cd9cd99

View File

@ -315,11 +315,14 @@ class MPU:
# the ALU outputs are not decimally adjusted
nibble0 = nibble0 & 0xf
nibble1 = nibble1 & 0xf
aluresult = (nibble1 << 4) + nibble0
# the final A contents will be decimally adjusted
nibble0 = (nibble0 + adjust0) & 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)
if aluresult == 0:
self.p |= self.ZERO
@ -420,6 +423,9 @@ class MPU:
nibble0 = (aluresult + adjust0) & 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)
if aluresult == 0:
self.p |= self.ZERO