Since the schematic above of the BCD correction circuitry might look a bit odd and confusing
to some of the readers, I think I should clarify what brought me into drawing them.
If you are using FPGAs, your best bet for implementing BCD correction would be "flipping the Bits"
with XOR gates, like the NMOS 6502 does as described on the homepage of
this guy.
Don't mind the odd notation for some of the signals,
this article was written some years before there was Visual6502.
;---
If you are not using FPGAs, but maybe TTL ICs instead,
implementing a BCD correction depends on some more factors,
like which "function blocks" already are in the binary part of the ALU,
which parts you are able to buy and how they could be wired up,
how this fits into the PCB layout, etc.
Since the binary part of the ALU in OurCPU makes use of a
carry skip adder topology,
we already might have 4 Bit adders with their input carry tied to low.
To describe the concept more into detail:
For 4 Bit, there are two 74283 adders with their A,B inputs tied together.
One adder has the carry input tied to low, the other adder has the input tied to high.
A 74157 2:1 multiplexer then switches between both adder outputs according to the carry
that is supposed to go _into_ those 4 Bits.
The multiplexer tends to be faster than the adder when it comes to the propagation delay
from carry input to carry output. (Note, that you would need another multiplexer
controlled by the carry input that switches between the carry outputs of both adders
for generating the final 4 Bit carry output.)
;---
So it was tempting to tap into the outputs of the adders with the carry tied to low
for feeding the BCD correction circuitry to avoid the propagation delay of those 2:1 multiplexers.
The logic which decides whether a BCD correction is neccessary or not becomes a bit more complicated, of course.
If you have an 8 Bit ALU consisting of 4 Bit "chunks" with a complete and intact carry chain,
for SBC, you just test the binary adder output carry of a nibble, and do a correction if the output carry is 0.
For ADC, you just test if the adder result is >$9, or if the output carry is 1.
If you _don't_ have a complete and intact carry chain, but just two 4 Bit binary adders with the carry input
tied to low, "floating in nowhere", then detecting if a BCD correction is neccessary becomes more complicated.
For ADC, you have to test if the adder carry output is 1,
if the carry that goes into the nibble is 0 and the adder output is >$9,
or if the carry that goes into the nibble is 1 and the adder output is >$8...
because the adder won't "see" the input carry, of course.
For SBC, it's a bit more complicated, because you have to test the input carry...
and depending on it, you might have to test if the adder output is $F.
As a last step during the "BCD correction", you have to add that input carry to the nibble of course.
;---
BTW: The circuitry in the schematic makes use of 74CBT multiplexers for deciding if a correction is neccessary.
TI 74AC151 propagation delay: select to Y output 4.7ns to 16.5ns, data input to Y output 3.5ns to 12.3ns.
TI 74CBT3251 propagation delay: select to output 2ns to 5.5ns, data input to output
0.24ns maximum.So the idea is to stack a "pyramid" of 74CBT multiplexers, and to make the time critical signal ripple through the multiplexers
from data input to data output.
It was Jeff's idea to use such a circuitry for the BCD correction of Bit 7..4.
What eventually brought me into drawing the schematic above was that Jeff seemed to have doubts
that his circuitry could be "expanded" to handle all the 8 Bits instead of only Bit 7..4.
I hope, this description was helpful to the readers.