# Kawari Raster Palette Switch (KRPS)

This is a proof of concept for a 320x200 video mode that can display 16 unique colors per rasterline. This is only possible on Kawari VIC-II replacement PCBs on firmware 1.16 or higher.

The mode is achieved by registering a raster line interrupt on line 50 and installing a custom color palette before each raster line is drawn.  We 'chase' the beam down the 200 lines of screen using instructions that take exactly 65 cycles per line (for PAL). The bitmap image and palettes are pre-computed and loaded into the Kawari's extended memory.  A Kawari DMA transfer is used to install the palette into kawari registers. (1.16 only)

This demo is PAL only.  Although the looped code can be modified for NTSC if necessary.

There are two different versions, one for RGB based video output (DVI, Analog RGB) and one for HSV based video output (composite, s-video).  

It should be possible to install both palettes in one program but this has not been done yet. So chose the prg depending on what output type you have connected.  Otherwise, you will see a garbage image.

The loop code is different between RGB and HSV.  I'm not entirely sure why but it seems the value of something loaded into the accumulator makes a difference (64 vs 48) so the cycle count is different.

## Notes

The quality of the image is better in RGB than HSV.  This might be due to RGB having a better dynamic range than the HSV output. The color conversion utility from RGB to HSV is also not that great.  In both versions, the image has a horizontal 'sliced' look to it because the palette is chosen per raster line.  So there are noticible color changes from line to line.  This could probably be improved with a better conversion algorithm.

Please note this is a proof of concept only for the sake of interest.  It is not a polished utility that can view any arbitrary jpg from the C64.  The tools here were hastily put together and not everything is documented.

## Format

Pixel image format is 320x200 whereby each byte represents two pixels.
Each nibble represents an index into the color palette. There are 160 bytes
on each line representing 320 pixels.  160*200 = 32000 bytes.  This file is
split into two 16k chunks img1.bin and img2.bin (with 2 load bytes at the
beginning of each file that are ignored).

img1.bin 16386 (first 16k of img + 2 load bytes)
img2.bin 15618 (remaining 32000-16384 + 2 load bytes)

RGB color format is simply 4 bytes for each color (red, green, blue values
ranging from 0-63 (the 4th byte is ignored).  The rgb.bin file also has two
load bytes prepended that are ignored. Every palette has 64 bytes and is loaded into extended registers 0x40 - 0x80.

rgb.bin  12802 (64 * 200 + 2 load bytes)

HSV color format is 3 bytes for each color (luma 0-63, phase 0-255, amplitude 0-15).  Every palette has 48 bytes and are loaded into extended registers
0xa0 - 0xcf.

hsv.bin 9602 (48 * 200 + 2 load bytes)
