65C816 assembly loading data to table in memory not working as expected

54 views Asked by At

Any ASM experts want to help explain something? I have this (commented out secondary colors):

;
; --- Tables for setting SCB and color tables for color --------
;
    ENTRY logocolor
logocolor   DC.W $00B0
    ;$ DC.W $0AD9
    DC.W $0FF0
    ;$ DC.W $0FFB
    DC.W $0F60
    ;$ DC.W $0FA7
    DC.W $0E10
    ;$ DC.W $0E99
    DC.W $0F0A
    ;$ DC.W $0E7C
    DC.W $000D
    ;$ DC.W $0AAE

    ENTRY scanbyte
scanbyte    DC.B 1
    DC.B 1
    DC.B 1
    DC.B 2
    DC.B 3
    DC.B 4
    DC.B 5
    DC.B 6

And the routine that loads the colors:

InitPalette PROC

    jsr startup 

    ldx #7
lop200  phx Save.

    lda scanbyte,x
    ldy #scrnInfo
    ora [<data],y
    and #$00FF
    inx
    inx
    phx Scan line number.
    pha Scan byte value.
    _SetSCB

    plx Restore counter.
    dex
    bpl lop200

    pea 0
    jsr pushColorTable
    _GetColorTable

    ldx #6
    ldy #10

lop202  phx Save.
    phy Save.

    lda logocolor,y
    ldy #ColorTable+2
    sta [<data],y
    ldy <screenmode
    beq ok202

    ldy #ColorTable+10
    sta [<data],y
    ldy #ColorTable+18
    sta [<data],y
    ldy #ColorTable+26
    sta [<data],y

ok202   phx Table number.
    jsr pushColorTable
    _SetColorTable

    ply Restore.
    plx Restore.
    dey
    dey
    dex
    bne lop202

    brl pop0bytes   no error

    ENDP

and this results in the correct main colors in the palettes:

…
$E19E20: 00 00 B0 00 F0 00 FF 0F 00 00 B0 00 F0 0F FF 0F
$E19E30: 00 00 B0 00 F0 00 FF 0F 00 00 B0 00 F0 0F FF 0F
$E19E40: 00 00 F0 0F F0 00 FF 0F 00 00 F0 0F F0 0F FF 0F
…etc

However, when I uncomment my secondary colors, and try loading them into the ColorTable, say by adding:

ldy #ColorTable+3
    sta [<data],y

…I'm shifting things around in ways I'm not expecting. I need to have the secondary colors loaded immediately following the primary like:

…
$E19E20: 00 00 B0 00 D9 0A FF 0F 00 00 B0 00 D9 0A FF 0F
…

Looking at this a bit more, I mapped out what's going on (think) in the code comments. I'm completely new to asm…

ldx #6 ;I thnink this is keeping track of each line of the logo
    ldy #22 ;this used to be 10, but we have 6 more colors

lop202  phx Save.
    phy Save.
    ;each time we loop back y is decreased by 2, x by 1
    lda logocolor,y ; Load defined color value in the table, using y as index into a
    ldy #ColorTable+2 ; Load value of ColorTable + 2
    sta [<data],y ; Store read defined color
    ;
    ;--- here we need some operation to get the next color in the table -----
    ;
    ldy #ColorTable+4 ; then load value of ColorTable + 4
    sta [<data],y ; Store read defined color from our imagary operation
    ldy <screenmode
    beq ok202
    
    ;640 mode??? Yes, most certainly is for 640 mode. Need to add the second color here as well.
    ldy #ColorTable+10
    sta [<data],y
    ldy #ColorTable+18
    sta [<data],y
    ldy #ColorTable+26
    sta [<data],y

ok202   phx Table number.
    jsr pushColorTable
    _SetColorTable

    ply Restore.
    plx Restore.
    dey
    dey
    dex
    bne lop202

    brl pop0bytes   no error

    ENDP

But I need something in the ;--- here we need some operation to get the next color in the table ----- space…

but I'm out of registers…

So what should I do?

Or does this all need to be refactored for efficiency instead of trying to jam in loading another value off the table?

0

There are 0 answers