|
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)...
PT2
lda NumTrumps
cmp #$02 ; Does hand have more than two trumps?
bcc PT3 ; No, move on to next check
sec
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
two)
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...
PT2
lda NumTrumps
cmp #2
bcc PT3
sbc #1
adc PossibleTricks
sta PossibleTricks
We've saved two bytes :)
Cheers
A
-
Andrew Davie, TwoHeaded Software
adavie@xxxxxxxxxxxxx
-
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [stella] Euchre: a tight fit, TwoHeaded Software | Thread | Re: [stella] Euchre: a tight fit, TwoHeaded Software |
| Re: [stella] Stella at 20, Rob | Date | Re: [stella] Stella at 20, nj bloodline |
| Month |