From f275ed96ea83b21462b150ede9f8975734fd6924 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 24 Feb 2021 00:01:27 +0100 Subject: [PATCH] optimized palette.set_color() --- compiler/res/prog8lib/cx16/palette.p8 | 6 ++++-- examples/cx16/rasterbars.p8 | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/compiler/res/prog8lib/cx16/palette.p8 b/compiler/res/prog8lib/cx16/palette.p8 index 6d9ba794c..fc1ac0aa1 100644 --- a/compiler/res/prog8lib/cx16/palette.p8 +++ b/compiler/res/prog8lib/cx16/palette.p8 @@ -9,8 +9,10 @@ palette { ubyte c sub set_color(ubyte index, uword color) { - cx16.vpoke(1, $fa00+index*2, lsb(color)) - cx16.vpoke(1, $fa01+index*2, msb(color)) + vera_palette_ptr = $fa00+index*2 + cx16.vpoke(1, vera_palette_ptr, lsb(color)) + vera_palette_ptr++ + cx16.vpoke(1, vera_palette_ptr, msb(color)) } sub set_rgb4(uword palette_bytes_ptr, uword num_colors) { diff --git a/examples/cx16/rasterbars.p8 b/examples/cx16/rasterbars.p8 index c918a4b70..950b6da7e 100644 --- a/examples/cx16/rasterbars.p8 +++ b/examples/cx16/rasterbars.p8 @@ -1,4 +1,5 @@ %import textio +%import palette main { @@ -17,14 +18,14 @@ main { irq { uword[32] colors = [ - $011, $112, $213, $214, - $315, $316, $417, $418, - $519, $51a, $62b, $62c, - $73d, $73e, $84f, $94f, - $93e, $83d, $82c, $72b, - $71a, $619, $618, $517, - $516, $415, $414, $313, - $312, $211, $100, $000 + $011, $112, $213, $214, + $315, $316, $417, $418, + $519, $51a, $62b, $62c, + $73d, $73e, $84f, $94f, + $93e, $83d, $82c, $72b, + $71a, $619, $618, $517, + $516, $415, $414, $313, + $312, $211, $100, $000 ] uword next_irq_line = 0 @@ -44,9 +45,7 @@ irq { next_irq_line += barheight } - ; set new screen background color - cx16.vpoke(1, $fa00, lsb(c)) - cx16.vpoke(1, $fa01, msb(c)) + palette.set_color(0, c) cx16.set_rasterline(next_irq_line) }