During my adventures in emulator's land I found numerous discussions and many valuable articles about implementing ADC/SBC routines in 6502. Finally I was able to create something that should be - in my humble opinion - a sweet spot between a general description like:
Code:
if AL >= $0A, then AL = ((AL + $06) & $0F) + $10
and
Code:
DS3 = ( ((BS1 | BS2) & DAA) | (~BS1 | ~BS2) & DSA) ^ BS3
(in my opinion first version hides operations on particular nybbles by mixing $06 and $10 on AL, that suggest "lower part" - and second is too cumbersome for many to understood).
My attempt is available here:
https://github.com/aniou/morfeo/blob/master/doc/6502-ADC-SBC-implementation.rst and I will be glad for Your opinions and suggestions. Code itself successfully passed two test suites - "classic" Clark's suite and SingleStepTests for 65C02 and 65C816 in both native and emulation mode. 6502 was not tested, but should work after small adjustments in flag checking.
Code itself is not too performant nor smart, but was created in this form intentionally - as clear and illustrative to particular CPU behaviors as possible. It is - surprisingly even to me - very compact and universal.
In worst case at least "Bibliography" section should be useful for someone.