2020-12-26 12:38:14 +00:00
|
|
|
; Manipulate the Commander X16's display color palette.
|
2023-12-03 16:11:12 +00:00
|
|
|
; Should you want to restore the full default palette, you can call cbm.CINT()
|
|
|
|
; The first 16 colors can be restored to their default with set_default16()
|
2020-12-26 12:38:14 +00:00
|
|
|
|
|
|
|
palette {
|
2023-06-29 22:29:50 +00:00
|
|
|
%option no_symbol_prefixing
|
2020-12-26 12:38:14 +00:00
|
|
|
|
|
|
|
uword vera_palette_ptr
|
|
|
|
|
|
|
|
sub set_color(ubyte index, uword color) {
|
2021-09-28 21:12:59 +00:00
|
|
|
vera_palette_ptr = $fa00+(index as uword * 2)
|
2021-02-23 23:01:27 +00:00
|
|
|
cx16.vpoke(1, vera_palette_ptr, lsb(color))
|
|
|
|
vera_palette_ptr++
|
|
|
|
cx16.vpoke(1, vera_palette_ptr, msb(color))
|
2020-12-26 12:38:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 23:09:37 +00:00
|
|
|
sub set_rgb_be(uword palette_ptr, uword num_colors) {
|
|
|
|
; 1 word per color entry, $0rgb in big endian format
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr = $fa00
|
|
|
|
repeat num_colors {
|
2022-05-31 23:09:37 +00:00
|
|
|
cx16.vpoke(1, vera_palette_ptr+1, @(palette_ptr))
|
|
|
|
palette_ptr++
|
|
|
|
cx16.vpoke(1, vera_palette_ptr, @(palette_ptr))
|
|
|
|
palette_ptr++
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr+=2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 01:46:07 +00:00
|
|
|
sub set_rgb(uword palette_words_ptr, uword num_colors) {
|
2022-11-06 15:38:31 +00:00
|
|
|
; 1 word per color entry (in little endian format as layed out in video memory, so $gb;$0r)
|
2021-01-29 01:46:07 +00:00
|
|
|
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) {
|
2020-12-26 12:38:14 +00:00
|
|
|
; 3 bytes per color entry, adjust color depth from 8 to 4 bits per channel.
|
|
|
|
vera_palette_ptr = $fa00
|
|
|
|
ubyte red
|
|
|
|
ubyte greenblue
|
|
|
|
repeat num_colors {
|
2023-11-14 19:40:48 +00:00
|
|
|
cx16.r1 = color8to4(palette_bytes_ptr)
|
|
|
|
palette_bytes_ptr+=3
|
|
|
|
cx16.vpoke(1, vera_palette_ptr, cx16.r1H) ; $GB
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr++
|
2023-11-14 19:40:48 +00:00
|
|
|
cx16.vpoke(1, vera_palette_ptr, cx16.r1L) ; $0R
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-14 19:40:48 +00:00
|
|
|
sub color8to4(uword colorpointer) -> uword {
|
|
|
|
; accurately convert 24 bits (3 bytes) RGB color, in that order in memory, to 16 bits $GB;$0R colorvalue
|
|
|
|
cx16.r1 = colorpointer
|
|
|
|
cx16.r0 = channel8to4(@(cx16.r1)) ; (red) -> $00:0R
|
|
|
|
cx16.r0H = channel8to4(@(cx16.r1+1))<<4 ; (green) -> $G0:0R
|
|
|
|
cx16.r0H |= channel8to4(@(cx16.r1+2)) ; (blue) -> $GB:0R
|
|
|
|
return cx16.r0
|
|
|
|
}
|
|
|
|
|
|
|
|
sub channel8to4(ubyte channelvalue) -> ubyte {
|
|
|
|
; accurately convert a single 8 bit color channel value to 4 bits, see https://threadlocalmutex.com/?p=48
|
|
|
|
return msb(channelvalue * $000f + 135)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-24 03:05:16 +00:00
|
|
|
sub set_monochrome(uword screencolorRGB, uword drawcolorRGB) {
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr = $fa00
|
2021-01-24 03:05:16 +00:00
|
|
|
cx16.vpoke(1, vera_palette_ptr, lsb(screencolorRGB)) ; G,B
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr++
|
2021-01-24 03:05:16 +00:00
|
|
|
cx16.vpoke(1, vera_palette_ptr, msb(screencolorRGB)) ; R
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr++
|
|
|
|
repeat 255 {
|
2021-01-24 03:05:16 +00:00
|
|
|
cx16.vpoke(1, vera_palette_ptr, lsb(drawcolorRGB)) ; G,B
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr++
|
2021-01-24 03:05:16 +00:00
|
|
|
cx16.vpoke(1, vera_palette_ptr, msb(drawcolorRGB)) ; R
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-08 21:09:38 +00:00
|
|
|
sub set_all_black() {
|
2021-05-26 19:33:18 +00:00
|
|
|
set_monochrome($000, $000)
|
|
|
|
}
|
|
|
|
|
2021-10-08 21:09:38 +00:00
|
|
|
sub set_all_white() {
|
2021-05-26 19:33:18 +00:00
|
|
|
set_monochrome($fff, $fff)
|
|
|
|
}
|
|
|
|
|
2020-12-26 12:38:14 +00:00
|
|
|
sub set_grayscale() {
|
2023-12-03 16:11:12 +00:00
|
|
|
; set first 16 colors to a grayscale gradient from black to white
|
2020-12-26 12:38:14 +00:00
|
|
|
vera_palette_ptr = $fa00
|
2023-12-03 16:11:12 +00:00
|
|
|
cx16.r2L=0
|
2020-12-26 12:38:14 +00:00
|
|
|
repeat 16 {
|
2023-12-03 16:11:12 +00:00
|
|
|
cx16.vpoke(1, vera_palette_ptr, cx16.r2L)
|
2023-11-12 15:40:13 +00:00
|
|
|
vera_palette_ptr++
|
2023-12-03 16:11:12 +00:00
|
|
|
cx16.vpoke(1, vera_palette_ptr, cx16.r2L)
|
2023-11-12 15:40:13 +00:00
|
|
|
vera_palette_ptr++
|
2023-12-03 16:11:12 +00:00
|
|
|
cx16.r2L += $11
|
2020-12-26 12:38:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub set_c64pepto() {
|
2023-12-03 16:11:12 +00:00
|
|
|
; set first 16 colors to the "Pepto" PAL commodore-64 palette http://www.pepto.de/projects/colorvic/
|
|
|
|
uword[] colors = [
|
|
|
|
$000, ; 0 = black
|
|
|
|
$FFF, ; 1 = white
|
|
|
|
$833, ; 2 = red
|
|
|
|
$7cc, ; 3 = cyan
|
|
|
|
$839, ; 4 = purple
|
|
|
|
$5a4, ; 5 = green
|
|
|
|
$229, ; 6 = blue
|
|
|
|
$ef7, ; 7 = yellow
|
|
|
|
$852, ; 8 = orange
|
|
|
|
$530, ; 9 = brown
|
|
|
|
$c67, ; 10 = light red
|
|
|
|
$444, ; 11 = dark grey
|
|
|
|
$777, ; 12 = medium grey
|
|
|
|
$af9, ; 13 = light green
|
|
|
|
$76e, ; 14 = light blue
|
|
|
|
$bbb ; 15 = light grey
|
|
|
|
]
|
|
|
|
set_rgb(colors, len(colors))
|
2020-12-26 12:38:14 +00:00
|
|
|
}
|
|
|
|
|
2023-12-03 16:11:12 +00:00
|
|
|
sub set_c64ntsc() {
|
|
|
|
; set first 16 colors to a NTSC commodore-64 palette
|
|
|
|
uword[] colors = [
|
|
|
|
$000, ; 0 = black
|
|
|
|
$FFF, ; 1 = white
|
|
|
|
$934, ; 2 = red
|
|
|
|
$9ff, ; 3 = cyan
|
|
|
|
$73f, ; 4 = purple
|
|
|
|
$4b1, ; 5 = green
|
|
|
|
$20c, ; 6 = blue
|
|
|
|
$ee6, ; 7 = yellow
|
|
|
|
$b53, ; 8 = orange
|
|
|
|
$830, ; 9 = brown
|
|
|
|
$f8a, ; 10 = light red
|
|
|
|
$444, ; 11 = dark grey
|
|
|
|
$999, ; 12 = medium grey
|
|
|
|
$9f9, ; 13 = light green
|
|
|
|
$36f, ; 14 = light blue
|
|
|
|
$ccc ; 15 = light grey
|
|
|
|
]
|
|
|
|
set_rgb(colors, len(colors))
|
2020-12-26 12:38:14 +00:00
|
|
|
}
|
|
|
|
|
2023-12-03 16:11:12 +00:00
|
|
|
sub set_default16() {
|
|
|
|
; set first 16 colors to the defaults on the X16
|
|
|
|
uword[] colors = [
|
|
|
|
$000, ; 0 = black
|
|
|
|
$fff, ; 1 = white
|
|
|
|
$800, ; 2 = red
|
|
|
|
$afe, ; 3 = cyan
|
|
|
|
$c4c, ; 4 = purple
|
|
|
|
$0c5, ; 5 = green
|
|
|
|
$00a, ; 6 = blue
|
|
|
|
$ee7, ; 7 = yellow
|
|
|
|
$d85, ; 8 = orange
|
|
|
|
$640, ; 9 = brown
|
|
|
|
$f77, ; 10 = light red
|
|
|
|
$333, ; 11 = dark grey
|
|
|
|
$777, ; 12 = medium grey
|
|
|
|
$af6, ; 13 = light green
|
|
|
|
$08f, ; 14 = light blue
|
|
|
|
$bbb ; 15 = light grey
|
|
|
|
]
|
|
|
|
set_rgb(colors, len(colors))
|
2020-12-26 12:38:14 +00:00
|
|
|
}
|
|
|
|
}
|