Update tgidemo.c

TGI color defines should be indices into the default palette
This commit is contained in:
Bob Andrews
2025-06-12 00:35:29 +02:00
committed by GitHub
parent cd769b3a9f
commit 1c71d4c609

View File

@@ -12,8 +12,11 @@
# define DYN_DRV 1
#endif
#define COLOR_BACK 0
#define COLOR_FORE 1
/* TGI colors are indices into the default palette. So keep in mind that, if
you redefine the palette, those names may no more match the actual colors. */
#define COLOR_BACK TGI_COLOR_BLACK
#define COLOR_FORE TGI_COLOR_WHITE
/*****************************************************************************/
@@ -65,17 +68,36 @@ static void DoWarning (void)
#endif
/*
* Note that everywhere else in the TGI API, colors are referred to via TGI_COLOR_
* color indices, which in turn refer to the default TGI palette.
*
* Redefining the colors (changing the palette) is a target dependend operation,
* and the colors/values in the palette itself are not portable.
*
* That said, for some (perhaps most?) targets, the COLOR_ values may work here.
*/
static void DoPalette (int n)
{
static const unsigned char Palette[4][2] = {
/* FIXME: add some ifdefs with proper values for targets that need it */
{ COLOR_BLACK, COLOR_BLUE },
{ COLOR_WHITE, COLOR_BLACK },
{ COLOR_RED, COLOR_BLACK },
{ COLOR_BLACK, COLOR_BLACK }
};
tgi_setpalette (Palette[n]);
}
static void DoCircles (void)
{
static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLUE };
unsigned char I;
unsigned char Color = COLOR_BACK;
const unsigned X = MaxX / 2;
const unsigned Y = MaxY / 2;
const unsigned Limit = (X < Y) ? Y : X;
tgi_setpalette (Palette);
tgi_setcolor (COLOR_FORE);
tgi_clear ();
tgi_line (0, 0, MaxX, MaxY);
@@ -95,11 +117,9 @@ static void DoCircles (void)
static void DoCheckerboard (void)
{
static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
unsigned X, Y;
unsigned char Color = COLOR_BACK;
tgi_setpalette (Palette);
tgi_clear ();
while (1) {
@@ -123,13 +143,11 @@ static void DoCheckerboard (void)
static void DoDiagram (void)
{
static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
int XOrigin, YOrigin;
int Amp;
int X, Y;
unsigned I;
tgi_setpalette (Palette);
tgi_setcolor (COLOR_FORE);
tgi_clear ();
@@ -167,11 +185,9 @@ static void DoDiagram (void)
static void DoLines (void)
{
static const unsigned char Palette[2] = { TGI_COLOR_WHITE, TGI_COLOR_BLACK };
unsigned X;
const unsigned Min = (MaxX < MaxY) ? MaxX : MaxY;
tgi_setpalette (Palette);
tgi_setcolor (COLOR_FORE);
tgi_clear ();
@@ -216,10 +232,12 @@ int main (void)
Border = bordercolor (COLOR_BLACK);
/* Do graphics stuff */
/* first uses the default palette */
DoCircles ();
DoCheckerboard ();
DoDiagram ();
DoLines ();
DoPalette (0); DoCheckerboard ();
DoPalette (1); DoDiagram ();
DoPalette (2); DoLines ();
#if DYN_DRV
/* Unload the driver */