Select application Welcome to TsaBros web site Work in progress Articles and technical documentations CLie discussion board Frequently asked questions Download area Links to others good sites Us
Video memory location
MQ1100 overview
assembly
jogdial events
Page flipping
Geronimo sucks
Color palette
Color palette
 

The palmOS features a standard palette. It is quite good for several purposes (says Yoyo) but sometimes, you realy need your own colors. There is one official solution for this, use the system function:
WinPalette (UInt8 operation, Int16 startIndex,UInt16 paletteEntries, RGBColorType *tableP)
but quickly you will realise this function is slow. I mean really slow. It takes about 2 seconds to change the whole palette. The reason why is very important: when you change a color using this function, a conversion table is rebuilt. This will be useful to remap any picture with its own color palette into the current one. this is used when you perform a WinPaintBitmap or when you draw a character. To make it short, the time you lose when you change the palette you win it when the system remaps a bitmap. This is performed quite quickly.

But sometimes you need to change the palette quickly, on the fly. Wanna make the screen flash? or use any of the palette switching tricks from back in the 80's ? then you gotta dive closer to the metal.

Color Palette is located in the registers area of the memory linked to the MQ1100. Read the article about the Video Memory location. Once you done with it you know your BaseAdress (example: 0x1F000000). Consider that everything next is relative to your BaseAdress. For instance when I talk about offset 0x40800 it means BaseAdress+0x40800 (ex: 0x1F040800).

Ok, the Clie palette is done of 256 colors. Each color is defined by 64 shades of red green and blue. Then, in the 8bits per pixel video mode, the default one, each pixel of the sceen is described by a 8bit index that tells what color in the palette the pixel is refering to. For instance, if a pixel has a value of 18, this means it will be rendered with the color described in the palette register number 18.

Each of those register is 32bits. They are documented as CP00 to CPFF (for Color Palette) and stored sequentially.
the Red, green and blue values are defined on 6 bits each.

24
16
8
0
5
4
3
2
1
0
x
x
5
4
3
2
1
0
x
x
5
4
3
2
1
0
x
x
x
x
x
x
x
x
x
x

you will note this is not the same description than in the MQ1100 datasheet. This is because of the bit order variation. Read Geronimo sucks for further information.

Now where is it stored? The first color 0, CP00 is at offset 0x40800, the next, CP01 is 4 bytes further, 0x40804

Caution: the emulator behavior is not very accurate about this. Even if values reading is ok, writing is not reliable. You can try writing one UInt16 at a time instead of a UInt32 for a color register, but even this way it is not very reliable.

The color change happens when you write to the register. There is no delay. then you can switch the color evey pixel if you wish. Use the page flipping (see article) to synchronise with the begining of the display (top to bottom) or the line counter. This will be explained in further articles.

Don't forget the color remap function of the OS, if you change the color using this low level system, the OS will still believe the palette hasn't change. My advise is: set the palette once at the begining of your app using WinPalette, then change it dynamicaly in the main loop.

well whatever, enjoy it!

 

WM.


 
-

14853 visits since 2002.02.28 | Last Update : 2003, July 15th | suggestions, bugs to Webmaster | original S8Forum by Kelli Shaver