Re: [stella] Euchre: a tight fit

Subject: Re: [stella] Euchre: a tight fit
From: "TwoHeaded Software" <adavie@xxxxxxxxxxxxx>
Date: Tue, 4 Sep 2001 13:50:44 +1000
Every now and then I'll pick up this code (euchre) and have a browse
through.  Finding spare bytes is quite relaxing when it's not your baby that
needs them to survive.  Here's another general suggestion for code
reduction... Check this code (from Euchre)...

    lda NumTrumps
    cmp #$02            ; Does hand have more than two trumps?
    bcc PT3             ; No, move on to next check
    sbc #$02            ; Find number of trumps over two...
    clc                 ; then increase the likely tricks by that number
    adc PossibleTricks  ; (there are only seven trumps, so if one hand
    sta PossibleTricks  ; has three, no player is likely to have more than

This code can be improved by paying careful attention to the state of the
carry.  After the first branch (bcc PT3) we know the carry IS NOT clear (the
branch wasn't taken).  ie: it is set.  So we don't need to set it again.
That "sec" can go.   Then we subtract 2.  But we know that the number we're
subtracting from is >= 2, so the subtraction will not change the state of
the carry bit (it will be set after the subtraction).  So if we went on to
add Possibletricks without clearing the carry, we'd have one too many.  So
instead of subtracting 2, let's just subtract 1.  This gives us...

    lda NumTrumps
    cmp #2
    bcc PT3
    sbc #1
    adc PossibleTricks
    sta PossibleTricks

We've saved two bytes :)


Andrew Davie, TwoHeaded Software

Archives (includes files) at
Unsub & more at

Current Thread