--------------------------------------------------------------------------
Command Packets, Data Register.
--------------------------------------------------------------------------
Primitive command packets use an 8 bit command value which is present in
all packets. They contain a 3 bit type block and a 5 bit option block of
which the meaning of the bits depend on the type. Layout is as follows:
Type:
000 GPU command
001 Polygon primitive
010 Line primitive
011 Sprite primitive
100 Transfer command
111 Environment command
Configuration of the option blocks for the primitives is as follows:
Polygon:
| 7 6 5 | 4 | 3 | 2 | 1 | 0 |
| 0 0 1 |IIP|3/4|Tme|Abe|Tge|
Line:
| 7 6 5 | 4 | 3 | 2 | 1 | 0 |
| 0 1 0 |IIP|Pll| 0 |Abe| 0 |
Sprite:
| 7 6 5 | 4 3 | 2 | 1 | 0 |
| 1 0 0 | Size |Tme|Abe| 0 |
IIP 0 Flat Shading
1 Gouroud Shading
3/4 0 3 vertex polygon
1 4 vertex polygon
Tme 0 Texture mapping off
1 on
Abe 0 Semi transparency off
1 on
Tge 0 Brightness calculation at time of texture mapping on
1 off. (draw texture as is)
Size 00 Free size (Specified by W/H)
01 1 x 1
10 8 x 8
11 16 x 16
Pll 0 Single line (2 vertices)
1 Polyline (n vertices)
+---+-+-+-+-+-+
|001|0|0|0|0|0| = 0x20
+---+-+-+-+-+-+
Bits 5 - 7 = 001 (Polygon)
Bit 4 = 0 (Flat shading)
Bit 3 = 0 (3 points)
Bit 2 = 0 (No texture)
Bit 1 = 0 (No semi trans mode)
Bit 0 = 0 (Use original color, of course!)
void processSemiTrans(unsigned char sTransMode, unsigned char *colDest, unsigned char *colSrc)
{
int r, g, b; //For saturation (up/down) SLOW (but not with MMX :)
//Float -> Color value
//1.0f -> 255
//0.5f -> 128
//0.25f -> 64
//Where B is the source (screen) and F is current color that you
//want to apply transparency to.
r = colDest[COL_R];
g = colDest[COL_G];
b = colDest[COL_B];
switch (sTransMode)
{
case 0: //0.5 x B + 0.5 x F
r >>= 1;
b >>= 1;
g >>= 1;
//Add unsigned with saturation
r += colSrc[COL_R] >> 1;
g += colSrc[COL_G] >> 1;
b += colSrc[COL_B] >> 1;
break;
case 1: //1.0 x B + 1.0 x F
r += colSrc[COL_R];
g += colSrc[COL_G];
b += colSrc[COL_B];
break;
case 2: //1.0 x B - 1.0 x F
r -= colSrc[COL_R];
g -= colSrc[COL_G];
b -= colSrc[COL_B];
break;
case 3: //1.0 x B +0.25 x F
r += colSrc[COL_R] >> 2;
g += colSrc[COL_G] >> 2;
b += colSrc[COL_B] >> 2;
break;
}
//Simulated saturation
if (r > 255)
r = 255;
else if (r < 0)
r = 0;
if (g > 255)
g = 255;
else if (g < 0)
g = 0;
if (b > 255)
b = 255;
else if (b < 0)
b = 0;
//Store result to be used when drawing to the screen
colDest[COL_R] = (unsigned char)r;
colDest[COL_G] = (unsigned char)g;
colDest[COL_B] = (unsigned char)b;
}