Redefining single sprite palette colour

Do you live and breathe hexadecimal? Do you like speaking to hardware directly?

Moderator: Programming Moderators

Post Reply
User avatar
SevenFFF
Posts: 211
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Redefining single sprite palette colour

Post by SevenFFF » Thu Feb 22, 2018 3:45 pm

I have some code I wrote last year using sprites, using the default RRRGGBB colour values without any palette redefinitions. The palettes and layer system have got more complicated (and/or more documented) since I wrote it, but I don't want to rewrite it to use a completely custom palette unless I have to.

All I want to do redefine a single colour so I can do a simple colour cycling animation, but I can't get it to work.

The palette index of that colour is $80 (dark red), and for the sake of this question let's say I want to redefine it to white (%111 111 11), and let's assume $80 will never appear anywhere else on that screen.

I'm trying this, and several other variations, but none of them work. I'm missing something obvious! How do I do it?

Code: Select all

                        ld bc, $43                      ; (R/W) 0x43 (67) => Palette Control
                        ld a, %x 110 xxxx               ; 010 = Sprites first palette, %x 110 xxxx = 96
                        out (c), a
                        ld bc, $40                      ; (R/W) 0x40 (64) => Palette Index
                        ld a, $80                       ; $80 = default dark red
                        out (c), a
                        inc c                           ; (R/W) 0x41 (65) => Palette Value (8 bit colour)
                        ld a, %11111111                 ; %11111111 = RRRGGGBB white
                        out (c), a
Last edited by SevenFFF on Thu Feb 22, 2018 4:29 pm, edited 1 time in total.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

User avatar
varmfskii
Posts: 183
Joined: Fri Jun 23, 2017 1:13 pm
Location: Albuquerque, NM USA

Re: Redefining single sprite palette colour

Post by varmfskii » Thu Feb 22, 2018 4:28 pm

I see what your problem is, you are confusing ports and registers. Try this:

Code: Select all

ld bc,$243b ; port to select zx next register
ld a,$43 ; register number, palette control
out (c),a
ld bc,$253b ; port to access register
ld a,%00000000 ; select first ULA palette 
out (c),a
ld bc,$243b
ld a,$40 ; palette index register
out (c),a
ld bc,$253b
ld a,$80 ; index 128
out (c),a
ld bc,$243b
ld a,$41 ; palette value (8 bit) register
out (c),a
ld bc,$253b
ld a,%11111111 ; white
out (c),a
This is why the nextreg op would be really really nice.
Backer #2741 - TS2068, Byte, ZX Evolution

User avatar
SevenFFF
Posts: 211
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Redefining single sprite palette colour

Post by SevenFFF » Thu Feb 22, 2018 4:35 pm

varmfskii wrote:
Thu Feb 22, 2018 4:28 pm
I see what your problem is, you are confusing ports and registers.
Gosh, you are right. I was tired when I wrote this last night lol. It works, thanks!!
varmfskii wrote:
Thu Feb 22, 2018 4:28 pm
This is why the nextreg op would be really really nice.
Yes this is quite a code mouthful, isn't it?!
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

User avatar
varmfskii
Posts: 183
Joined: Fri Jun 23, 2017 1:13 pm
Location: Albuquerque, NM USA

Re: Redefining single sprite palette colour

Post by varmfskii » Thu Feb 22, 2018 4:41 pm

If you are doing a bunch, it would be better to use the exx instruction, so you only have to set bc twice.
Happy programming.
Backer #2741 - TS2068, Byte, ZX Evolution

Post Reply