Jmstein7 wrote:
One thing I would love to have is a simple way to figure the overflow flag on SBC.
Jon
that is one i also struggled with, you can find it in my core, hidden deep inside the "ADDER" subcircuit.
because you can switch between Binary and BCD mode my simulated core has 2 seperate Adder and Overflow circuits.
with the bianry one i split the 8-bit Adder into 2 parts, a 7-bit Adder for the lower bits 0-6, and a 1-bit Adder for the upper 7th bit.
the Carry output of the 7-bit Adder went directly to the Carry input of the 1-bit Adder, forming a complete 8-bit Adder while giving me access to the 6th bit Carry.
you then take the Carry from both Adders and XOR them together, the output the Overflow flag.
so basically, whenever the 6th bit overflows into the 7th bit, or the 7th overflows without the 6th overflowing as well, the Overflow bit gets set.
Attachment:
javaw_2021-11-07_19-16-53.png [ 103.33 KiB | Viewed 1331 times ]
for BCD the whole circuit is a lot more complex.
just talking about the Overflow flag though, i basically did:
take bit 7 of Input A and XOR it with bit 7 of Input B
take bit 7 of Input A and XOR it with bit 7 of the Output
then take the output of both XOR's and NAND them together.
the output of the NAND is the Overflow flag when BCD is enabled.
honestly i couldn't tell you what is happening in that circuit, but it seems to work. BCD is weird.
barrym95838 wrote:
I suppose the one caveat is that you need the nines complement instead of the ones complement if D is set
isn't the 65C02 using two's Complement in Bianry mode?