Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

COLOR

Keyword
Abbreviation Token (hex) Version(s) Classification
COLOR CO{Shift+L} E7 3.5 Command and Statement
COLOR COL{Shift+O} E7 7.0 Command and Statement 
ERR$ E{Shift+R} E7 4.7 Function

Syntax  
COLOR colorSource chipColor [ , chipLuminance ]
 
Parameters Type Legal Value(s) Default Value Note(s)
colorSource Integer 
0 to 5 (version 3.5)
0 to 6 (version 7.0) 
values 2 and 3 not used in high-resolution bitmap mode
values 1 to 3 not used in text mode
chipColor  Integer 1 to 16 (see table below)
chipLuminance* Integer 0 to 7  see table below
* The chipLuminance is only supported by the TED chip (v3.5).  In v7.0, any value from 0 to 255 is accepted.
 
 
Purpose  
Bitmap graphics state management; primarily set the chipColor to be used when plotting bitmap pixels using a colorSource.
Some colorSources refer to a global chip color; changing them has an immediate effect (as opposed to internal state just mentioned).

 
 
Remarks  
Although the TED and VIC chips have over a dozen colors, they are both limited to using only 2 colors within a color cell (similar to an MPEG macro block) for high-resolution bitmaps or only 4 colors per cell for a multi-color bitmap (and then one of them is a global/shared color).  The main reason for this is to decrease the amount memory required to store a bitmap; For the VIC, which has only 16 colors, this results in a 4-to-1 or 4-to-2 "compression" (high-res or multi-color mode).  For the TED, which has over a hundred colors, this jumps to about 7-to-1 or 7-to-2..
 
Said another way, each pixel in the bitmap is stored primarily as a single bit (high-resolution mode) or as pair of bits (multi-color mode).  Each possible bit(pair) value may be assigned any of the colors the chip has to offer, but with only 1 or 2 bits, not much variety is possible (which is why the concept of color cells is used).  With color cells, the bitmap pixels are clustered together into rectangular regions (which actually correspond with the area for each character in text mode) and each cell may have its own chipColor (and for TED chipLuminance) assigned to each of the possible bit (pair) values.  Well actually one of the 4 multi-color values is shared over the full screen and can not be set for each color cell.
 
Anyway, BASIC uses the colorSource to specify which bit value (or bit-pair value) to be written into the bitmap for each pixel plotted by the bitmap routines.  It also looks-up the chipColor assigned to the colorSource that is being plotted and stores that value in the color cell.  Now if you define 2 (high-resolution) or 4 (multi-color) chipColors to the 2 (or 4) different colorSources, and you never change those assignments while generating your bitmap image, you have a "static" color map; or you could say all 2 (or 4) chipColors are global... the memory of the color cells isn't even really needed in that case.
 
For nice looking images, you probably do want to change chipColors that are assigned while generating a bitmap image.  You just need to space your color changes apart on the bitmap so that a color change in one cell does not affect nearby pixels.  Failure to do this will result in distotion of the bitmap image when you plot a new chipColor assignment in a cell that was using a previous chipColor assignment (for the same colorSource).  Arrr!  Its really hard to describe with words, but once you see it happen a few times while playing with the bitmap commands, I think you will understand!
 
The first parameter, the colorSource specifies what graphic element is to changed by the COLOR command as a shown here:
colorSource Refers to Real or Mapping Note(s)
0 background 
Real (text and multi-color)
Mapping (high-resolution)
 
1 foreground* Mapping
2 multi-color A Mapping
3 multi-color B  Mapping   
4 border  Real 
text color  Mapping  v7.0 only; the active text editor (40 or 80 column display)
6 background and border  Real v7.0 only; 80-column display 
* The "foreground" is the default colorSource for bitmap commands, although ironically the VIC-II sprites consider such multi-color pixels as background!
 
The chipColor specifies which of the "primary" colors that can be generated by the video chip is assigned to the colorSource.  The TED chip has more colors than the VIC-II and these are specified with the optional chipLuminance parameter.  If omitted, the chipLuminance defaults to 7; the table below shows the luminance values that correspond to the text mode colors (accessible with {Control + Number} or {C= + Number} key combinations).  The table also includes the control code (CHR$ value) that may be used to change text colors with PRINT.
chipColor CHR$
value
TED
Name
TED
appearance
TED
luminance
VDC
Name
VDC
appearance
VIC-II
Name
VIC-II
appearance
1 144 black   0 black   black  
2 5 white   7 white   white  
3 28 red   3 red   red  
4 159 cyan   6 cyan   cyan  
5 156 purple   4 purple   purple  
6 30 green   3 green   green  
7 31 blue   4 blue   blue  
8 158 yellow   7 yellow   yellow  
9 129 orange   4 dark purple   orange  
10 149 brown   2 brown   brown  
11 150 puke   5 light red   light red  
12 151 pink   6 dark cyan   dark gray  
13 152 sea green   5 dark gray   medium gray  
14 153 indigo   6 light green   light green  
15 154 grape   2 light blue   light blue  
16 155 lime   5 light gray   light gray  
 
Any floating-point numbers will first be converted to integers (see INT).  If any value is out-of-range (see above) an ILLEGAL QUANTITY ERROR is generated.  Specifiying a string for any parameter will generate a TYPE MISMATCH ERROR.
 
Examples:
COLOR 0,1 : REM set background to black (bitmap or 40-column text screen)
COLOR 1,6 : REM set bitmap foreground to green (high-res or multi-color)
COLOR 2,7 : REM set multi-color A to blue
COLOR 3,3 : REM set multi-color B to red
COLOR 4,5 : REM set border to purple (magenta)
COLOR 5,2 : REM set current text color to white (v7.0 only)
COLOR 6,12 : REM set 80-column background to dark cyan (v7.0 only)
  
Compare With  
  
Contrast With  
  
See Also  

© H2Obsession, 2014
Comments