Sustain Comparator - libsidplayfp/SID_schematics GitHub Wiki
This is the sustain comparator, located under each counter bit:
images/sustain_comparator_IC.png
The counter and sustain bits are simply XORed:
The sustain register is only 4 bit and is compared with both counter nibbles giving sixteen sustain levels: $00, $11 ... $ff. The signal counter=sustain is thus high when the counter value matches the sustain level, but only during the decay phase when R0 and /R1 are low.