Picasso Basics David Gohler Village Tronic 1993 Introduction --------------------------------------------------------------------- What kind of graphic board is the "Picasso"? Is it a frame buffer, or a real graphic accelerator? A frame buffer is only an amount of video RAM, to which you can write and perhaps read from. The bits in the video memory represent some colors, which are displayed on the monitor. A real graphic accelerator card has some extra hardware to speed up display actions like copying data from one place to another, drawing lines and circles, filling regions and so on. The Picasso is something in between. It has a blitter, which speeds up fill and copy actions, but cannot draw lines or circles. But the blitter and the CPU can act together as a pair of drawing units. As the blitter cannot draw lines, the CPU has to do the job. To do that, the CPU can directly write to the video memory. Reading from the display memory is possible, but not recommended, because reading from the card can cause some wait states. Depending from the chosen color depth the byte organisation of the display memory is different. Thus, to handle the video memory, you need some knowledge in which way the pixel are represented in memory. This is the next topic. Video Memory Organization -------------------------------------------------------------------------- The Picasso has 4 different video modes: 1. Planar (up to 16 colors) 2. Packed Pixel (256 colors, also known as Chunky Pixel) 3. Two 16-Bit-Modes (32768 and 65536 colors) 4. TrueColor (16777216 colors) Each mode has a different video memory organization. 1. Planar -------------------------------------------------------------------------- This is the most familiar mode for Amiga programmers: the memory organisatioin is like the Amiga organizes its graphic RAM. The color information for one pixel is spread as single bits over multiple bitplanes. If you collect all bits from the same location of each bitplane you will have all bits of ONE pixel. Put the collected bits into one byte and you will get an index to a color palette entry. There you will find the values for red, green and blue of that pixel. These three values will be sent to the monitor and will be seen by you as a color. The bitplane with the lowest number holds the lowest bit from the resulting index to the color palette. The intuition driver chooses this mode to run the Workbench on a Picasso. 2. Packed Pixel -------------------------------------------------------------------------- The planar organization has a big disadvantage: to collect the information of one pixel in a 256 color mode, you have to read eight locations (each location for one bit!). This takes some time even on fast machines. Nowadays there are different and better ways to store the information: one byte, one pixel. All bits are held together in one byte. That byte is the index to a color palette entry. To read or write one pixel, you have to do only one read oder write to the video memory. This organization form is called Packed or Chunky Pixel. It allows to display up to 256 colors on a monitor at the same time. But this mode has a disadvantage too. Even if you need only 4 colors onscreen, you have to spend a whole byte for each pixel. Using 4 colors in Planar Mode will occupy only a quarter of display memory as in Packed Pixel mode. 3. 16 Bit Modes (Also Known As HiColor) -------------------------------------------------------------------------- Sometimes you may need more than 256 different colors. Therefore there are two 16-Bit modes, called HiColor. Each word consists of three 5 bit slices, which are not indices to a color palette entry, but the values themselves. 5 multiplied by 3 gives 15. One bit - the MSB - is free and should be zero. That's the first HiColor mode. The second uses the 16th bit to expand the bits of the green value to 6 bits: _ R R R R R G G|G G G B B B B B ^ LowByte HighByte ^ 15 Bit Mode (HiColor) | | Bit 15 ... ... ... Bit 0 R R R R R G G G|G G G B B B B B ^ LowByte HighByte ^ 16 Bit Mode (HiColor 2) | | Bit 15 ... ... ... Bit 0 The bytes have a reverse order in the video memory. The first (lower) byte contains the red bits, the second (higher) contains the blue bits. For a better understanding have a look at the demo program sources. 4. TrueColor (24Bit) -------------------------------------------------------------------------- The two HiColor modes have some disadvantages. First, you can only use 5 bits for each color component. You have 32768 colors out of 32768! In Chunky Pixel mode you have 256 colors out of 262144! Second, the bit shiftings take a lot of time. It might be easier and faster to put each color component into one byte. That's TrueColor. Each pixel occupies 3 Bytes. The first byte holds the "blue" bits, the second the "green" bits and the third the "red" bits. The fourth byte is not free, it holds the "blue" bits from the next pixel. In this mode you can display 16,777,216 different colors. This mode needs a lot of RAM. As a result, it is not possible to use high resolution screens and TrueColor together. The graphic board has not infinite amounts of RAM and the video output speed is limited too. Apart from that, even in low resolution pictures look like TV-images in TrueColor. Opening A Special Screen -------------------------------------------------------------------------- The Picasso is capable of using all described modes. To open a screen you have to start the intuition driver (double click on the monitor file!). The two functions OpenVillageScreen (...) and CloseVillageScreen(...) handle the opening and closing of special screens. The functions only work for Chunky Pixel, HiColor and TrueColor modes. If you want to open a planar screen, please use the normal AmigaOS functions like "OpenScreenTags(...)" (for more information how to use OS functions have a look into the Amiga ROM Kernel Reference Manual:Libraries). OpenVillageScreen() needs one parameter: a pointer to a "struct Dimensions" structure. In this structure you have to fill in the desired width, height and color depth of the screen, you wish to open, e.g. the values 800, 600 and 8 for a screen with 800 x 600 pixel and 256 different colors (2^8 = 256). Available resolutions are 640 x 480 800 x 600 1024 x 768 1120 x 8321 1152 x 9001 1280 x 10241 (1 only with better monitors) Available color depths are 8 (up to 1280 x 1024) 15 (up to 800 x 600 noninterlaced) 16 (up to 800 x 600 noninterlaced) 24 (only 640 x 480) You cannot freely combine resolutions and color depths. There are some limitations, you have to remember - look at the "up to ..." notes in the parentheses. If you choose an unmentioned resolution OpenVillageScreen() will round up the values for width, height and color depth until the screen fits into one of the six fixed resolutions. For example, if you want a screen with 64 different colors and 600 x 700 pixels, you will get a screen with 256 colors and a resolution of 1024 x 768 pixels. If all went ok, you will get back a pointer to a normal screen structure. But the screen is not normal! The intuition and graphics functions will work (!), but they will not draw anything on a special Village screen. As a result, you can open a window on a special screen to get IntuiMessages about e.g. mouse movements, but you will see nothing. Drawing -------------------------------------------------------------------------- You have to do the drawings by yourself! First, you have to lock a Village screen before drawing. This is important, because you may open as many special screens as screens fit into the Amiga memory. The graphic board has only one or two MByte RAM. If the user wants to cycle through screens, the intuition driver moves the screens from the board to system memory and vice versa. But this should not happen, while you are drawing into a screen. To prevent the intuition driver from movements, you have to lock a screen before drawing and to unlock the screen after drawing. The intuition driver will not move any screen, while a screen is visible and locked. As a result of "LockVillageScreen(screenpointer)" you will get the start address of the display memory for the specified screen. This can be an address on the Picasso board or an address in system memory. In the last case, the screen is not visible and you cannot use the blitter for on screen movements. After drawing you have to call "UnLockVillageScreen(screenpointer)". After that, the address of the display memory is no longer valid. If you want to draw again, you have to call "LockVillageScreen()" again and use the address you got from the latest call to "LockVillageScreen()". A Short Example: ---------------------------------------------------------------------- #include #include "vilintuisup.h" void HandleVillageCard() { struct Screen *ScreenPointer; struct Dimensions dm = { 0, 800, 600, 8 }; UBYTE *VideoMemStartAddress; if (ScreenPointer = OpenVillageScreen(&dm)) { VideoMemStartAddress = LockVillageScreen(ScreenPointer); // ... draw into the screen UnLockVillageScreen(ScreenPointer); // ... wait for user actions CloseVillageScreen(ScreenPointer); } else { PutStr("Can't open desired Village screen\n"); } } ---------------------------------------------------------------------- Before using the mentioned functions, you have to open the "vilintuisup.library" via "OpenLibrary("vilintuisup.library",0)". The example program opens a special screen with a resolution of 800 x 600 pixels in a Chunky Pixel mode. The first pixel in the display memory is the pixel in the top left corner. The next pixel is the right neighbour. A pixel occupies one, two or three bytes, depending on the display mode. The right neighbour of the last pixel in a line is the leftmost pixel of the next line. In easy words: The pixels are running from left to right, the lines are running from top to bottom. Some Additional Support Functions ---------------------------------------------------------------------- To show you, how easy the programming of the Picasso is, we made some demo programs and some additional functions, which might be useful. The most simple functions are void SetTrueColorPixel(Screen, x, y, r, g, b); void SetPackedPixel (Screen, x, y, color); void Set15BitPixel (Screen, x, y, r, g, b); void Set16BitPixel (Screen, x, y, r, g, b); to set one pixel in each mode. You have to do the locking before using this functions! Some people -- maybe -- want to draw some lines. There are two functions: one for the Chunky Pixel mode and one for the TrueColor mode: void LinePacked (Screen,xstart,ystart,xend,yend,color); void LineTrueColor (Screen,xstart,ystart,xend,yend,rgbcolor); The locking is done inside. You do not need to do this before using the line drawing functions. For more details have a look inside the file "vilintuisup.doc" and the demo source files, we supplied for you. A Last Sentence ---------------------------------------------------------------------- My English is not one of the best. Please excuse my faults. If you cannot understand some explanations, feel absolutly free to call us, send us a snail or electronic mail or send a fax. We want to support you the best way we can. So, do not hesitate, if you have a problem. We can help you! Our address is VillageTronic Marketing GmbH Wellweg 95 D 31157 Sarstedt Germany Tel: +49 / 50 66 / 70 13 - 0 Fax: +49 / 50 66 / 70 13 - 49 Box: +49 / 50 66 / 70 13 - 40 email goehler@arkon.adsp.sub.org (David Gohler, software and documentation) email crest@arkon.adsp.sub.org (Klaus Burkert, hardware development) .