added palette.set_rgb()

This commit is contained in:
Irmen de Jong 2021-01-29 02:46:07 +01:00
parent 2395863e7e
commit 51bc539468

View File

@ -13,30 +13,40 @@ palette {
cx16.vpoke(1, $fa01+index*2, msb(color)) cx16.vpoke(1, $fa01+index*2, msb(color))
} }
sub set_rgb4(uword palletteptr, uword num_colors) { sub set_rgb4(uword palette_bytes_ptr, uword num_colors) {
; 2 bytes per color entry, the Vera uses this, but the R/GB bytes order is swapped ; 2 bytes per color entry, the Vera uses this, but the R/GB bytes order is swapped
vera_palette_ptr = $fa00 vera_palette_ptr = $fa00
repeat num_colors { repeat num_colors {
cx16.vpoke(1, vera_palette_ptr+1, @(palletteptr)) cx16.vpoke(1, vera_palette_ptr+1, @(palette_bytes_ptr))
palletteptr++ palette_bytes_ptr++
cx16.vpoke(1, vera_palette_ptr, @(palletteptr)) cx16.vpoke(1, vera_palette_ptr, @(palette_bytes_ptr))
palletteptr++ palette_bytes_ptr++
vera_palette_ptr+=2 vera_palette_ptr+=2
} }
} }
sub set_rgb8(uword palletteptr, uword num_colors) { sub set_rgb(uword palette_words_ptr, uword num_colors) {
; 1 word per color entry (in little endian format so $gb0r)
vera_palette_ptr = $fa00
repeat num_colors*2 {
cx16.vpoke(1, vera_palette_ptr, @(palette_words_ptr))
palette_words_ptr++
vera_palette_ptr++
}
}
sub set_rgb8(uword palette_bytes_ptr, uword num_colors) {
; 3 bytes per color entry, adjust color depth from 8 to 4 bits per channel. ; 3 bytes per color entry, adjust color depth from 8 to 4 bits per channel.
vera_palette_ptr = $fa00 vera_palette_ptr = $fa00
ubyte red ubyte red
ubyte greenblue ubyte greenblue
repeat num_colors { repeat num_colors {
red = @(palletteptr) >> 4 red = @(palette_bytes_ptr) >> 4
palletteptr++ palette_bytes_ptr++
greenblue = @(palletteptr) & %11110000 greenblue = @(palette_bytes_ptr) & %11110000
palletteptr++ palette_bytes_ptr++
greenblue |= @(palletteptr) >> 4 ; add Blue greenblue |= @(palette_bytes_ptr) >> 4 ; add Blue
palletteptr++ palette_bytes_ptr++
cx16.vpoke(1, vera_palette_ptr, greenblue) cx16.vpoke(1, vera_palette_ptr, greenblue)
vera_palette_ptr++ vera_palette_ptr++
cx16.vpoke(1, vera_palette_ptr, red) cx16.vpoke(1, vera_palette_ptr, red)