Re: [stella] single digit scoring...

Subject: Re: [stella] single digit scoring...
From: "Andrew Davie" <atari2600@xxxxxxxxxxxxx>
Date: Wed, 27 Aug 2003 00:00:26 +1000
> LDA p0score ;accumulator = score
> ASL ;accumulator = score * 2
> ASL ;accumulator = score * 4
> ADC p0score  ;accumulator = (score * 4) + score = score * 5
> ADC #15 ;why do I need this??
> STA pointerP0Score
> LDA #>Score0Graphic
> STA pointerP0Score+1
>
> That "ADC #15" is a hack that puts the pointer on the correct digit.
> I have no idea why I need that, but it seems to work for all my
> numbers. Any idea? Full source at http://alienbill.com/joustpong/ ,
> I slipped it in as yesterday's entry at the bottom.



The problem is probably that you are assuming that the table starts on a
page boundary, where the low byte of the 16-bit address is 0.  If your table
doesn't start exactly on a page boundary, then you need to include the
following (instead of the 15)...

    adc #<Score0Graphic

Since you may, in doing this, 'cross' a page boundary, you need to change it
to something like this...

    lda p0score
    asl
    asl
    adc p0score            ; 5x, carry now clear

    adc #<Score0Graphic
    sta pointerP0Score

    lda #>Score0Graphic
    adc #0                                ; will mostly add nothing, but IF
the previous add crossed
                                              ; a page, makes sure that the
high byte goes to the subsequent page.
    sta pointerP0Score+1


Another way to do this is have a table of pointers to graphics data, and use
the score as an index to the table.


SIZEOFDIGITDATA    = 5        ; or whatever
ScorePtrLow
.OFFSET    SET Score0Graphic
    REPEAT 10                ; digits
    .byte <.OFFSET
.OFFSET    SET .OFFSET + SIZEOFDIGITDATA
    REPEND
ScorePtrHi
.OFFSET    SET Score0Graphic
    REPEAT 10                ; digits
    .byte <.OFFSET
.OFFSET    SET .OFFSET + SIZEOFDIGITDATA
    REPEND

Score0Graphic
    ; put your digit data here!



;then code to use this...

    ldy p0score
    lda ScorePtrLow,y                ; get low byte of data address from
table
    sta pointerP0Score
    lda ScorePtrHi,y                    ; get high byte of data address from
table
    sta pointerP0Score


---
The point I'm trying to make here - put your calculations into tables, and
save the cycles.  The above code is just snazzy use of assembler ability to
auto-build tables of pointers, using a temporary label which has a value
reassigned inside a loop which is actually expanded at compile time by the
compiler.  Have a look at sample output from the above code...


  1357  ff00         00 05    SIZEOFDIGITDATA = 5 ; or whatever
   1358  ff00       ScorePtrLow
   1359  ff00       ;SEG
   1360  ff00       .OFFSET    SET Score0Graphic
   1361  ff00           REPEAT 10 ; digits
   1362  ff00         14        .byte.b <.OFFSET
   1363  ff00       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1361  ff00           REPEND
   1362  ff01         19        .byte.b <.OFFSET
   1363  ff01       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1361  ff01           REPEND
   1362  ff02         1e        .byte.b <.OFFSET
   1363  ff02       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1361  ff02           REPEND
   1362  ff03         23        .byte.b <.OFFSET
   1363  ff03       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1361  ff03           REPEND
   1362  ff04         28        .byte.b <.OFFSET
   1363  ff04       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1361  ff04           REPEND
   1362  ff05         2d        .byte.b <.OFFSET
   1363  ff05       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1361  ff05           REPEND
   1362  ff06         32        .byte.b <.OFFSET
   1363  ff06       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1361  ff06           REPEND
   1362  ff07         37        .byte.b <.OFFSET
   1363  ff07       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1361  ff07           REPEND
   1362  ff08         3c        .byte.b <.OFFSET
   1363  ff08       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1361  ff08           REPEND
   1362  ff09         41        .byte.b <.OFFSET
   1363  ff09       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1364  ff0a           REPEND
   1365  ff0a       ScorePtrHi
   1366  ff0a       ;SEG
   1367  ff0a       .OFFSET    SET Score0Graphic
   1368  ff0a           REPEAT 10 ; digits
   1369  ff0a         14        .byte.b <.OFFSET
   1370  ff0a       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1368  ff0a           REPEND
   1369  ff0b         19        .byte.b <.OFFSET
   1370  ff0b       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1368  ff0b           REPEND
   1369  ff0c         1e        .byte.b <.OFFSET
   1370  ff0c       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1368  ff0c           REPEND
   1369  ff0d         23        .byte.b <.OFFSET
   1370  ff0d       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1368  ff0d           REPEND
   1369  ff0e         28        .byte.b <.OFFSET
   1370  ff0e       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1368  ff0e           REPEND
   1369  ff0f         2d        .byte.b <.OFFSET
   1370  ff0f       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1368  ff0f           REPEND
   1369  ff10         32        .byte.b <.OFFSET
   1370  ff10       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1368  ff10           REPEND
   1369  ff11         37        .byte.b <.OFFSET
   1370  ff11       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1368  ff11           REPEND
   1369  ff12         3c        .byte.b <.OFFSET
   1370  ff12       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1368  ff12           REPEND
   1369  ff13         41        .byte.b <.OFFSET
   1370  ff13       .OFFSET    SET .OFFSET + SIZEOFDIGITDATA
   1371  ff14           REPEND
   1372  ff14
   1373  ff14       Score0Graphic
   1374  ff14
   1375  ff14       ;then code to use this...
   1376  ff14
   1377  ff14         a4 a3        ldy p0score
   1378  ff16         b9 00 ff        lda ScorePtrLow,y ; get low byte of
data address from table
   1379  ff19         85 a4        sta pointerP0Score
   1380  ff1b         b9 0a ff        lda ScorePtrHi,y ; get high byte of
data address from table
   1381  ff1e         85 a4        sta pointerP0Score



See how the low byte table is filled with $14, $19, etc., and the
Score0Graphic label starts at $FF14.

Cheers
A



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


Current Thread