Re: [stella] Euchre: a tight fit

Subject: Re: [stella] Euchre: a tight fit
From: Thomas Jentzsch <tjentzsch@xxxxxx>
Date: Tue, 4 Sep 2001 00:19:58 +0200
At 03.09.2001, 23:01, Erik J. Eid wrote:
> What I need from readers of the list is some advice as to what I can trim
> from my code.  I'm looking for a general strategy, though advice about 
> specific segments of code is certainly welcome.

After having a quick look at your code, I can't show
you a general strategy, but i think there is plenty of
room for many little optimizations which should result
in saving the bytes you'll need. 

Some general hints:
- check your code for unoptimized parts again and again
- use bxx instead of jmp where possible
- avoid all subroutines that are only called once.
(yes, the result will be spaghetti code, but you're
always wasting 4 bytes here, and sometimes you will
discover unoptimized code easier)
- use X as an index for (zeropage) RAM tables and Y as
an index for ROM tables, because ZP,X is one byte
shorter than ZP,Y
- try to use a smaller random generator (i.E. River
Raid)
- try to avoid extra tables for the letter pointers,
you should be able so calculate them quite simply
- if you need pointer tables, try put all the data into
one page, so that the high byte is constant and store
only the low byte.
- with pointer tables, you can reduce the size of the
data they are pointing at, by overlapping the data
there 

Some examples to should you, what I mean.
1st example (29 bytes):
    lda T1
    and #DispSuitMask
    lsr
    lsr
    lsr
    tax
    ldy T3
    jsr GetSuitImage

GetSuitImage
    txa
    asl
    tax
    lda SuitImageTable,x
    sta $00,y
    lda SuitImageTable+1,x
    sta $01,y
    rts

Change to (17 bytes):
    lda T1
    and #DispSuitMask
    lsr
    lsr
    tay
    ldx T3
    lda SuitImageTable,y
    sta $00,x
    lda #>SuitImageHeart ;assuming SuitImageXXX are on the same page
    sta $01,x

This saves 12 of 29 bytes.

2nd example:
DB3a
    txa
    cmp #$09            ; Do we have nine points?
    bne DB3b            ; No, move on...
    tya
    cmp #$08            ; Does the other team have eight or more points?
    bpl DB3b            ; Yes, go to next check
    cmp #$06            ; Does the other team have six or seven points?
    bmi DB3b            ; No, go to next check
    lda #ChoiceCall     ; With score 9-6 or 9-7, it's better to risk a euchre

Here you should use cpx and cpy instead of txa/tya,
cmp. Another two bytes saved here.

3rd example:
DecideBid
    lda Stage
    cmp #StageBidding1  ; Is this the first round of bidding?
    bne DB0a            ; No
    lda Dealer
    eor Turn            ; Bit 0 will be set if the upcard goes to an opponent
    and #$01            ; Does upcard belong to opponent?
    beq DB0a            ; No...
    lda #$01            ; Yes!
    jmp DB0b
DB0a
    lda #$00           ;
DB0b

Change to:
DecideBid
    lda Stage
    cmp #StageBidding1  ; Is this the first round of bidding?
    bne DB0a            ; No
    lda Dealer
    eor Turn            ; Bit 0 will be set if the upcard goes to an opponent
    and #$01            ; Does upcard belong to opponent?
    bne DB0b            ; Yes!
DB0a
    lda #$00           ;  this is only needed because
    the branch above
DB0b

5 more bytes saved.

Have a look at the archives for the development of Qb
and you will see, that we found a lot of space, even
after Andrew was quite sure, it wasn't possible.

Have fun!
Thomas                            
_______________________________________________________
Thomas Jentzsch         | *** Every bit is sacred ! ***
tjentzsch at web dot de |


-
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/

Current Thread