From e684aaab5439396d19b64a3912cdd65bc586fef2 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Tue, 21 Sep 2004 03:05:53 +0000
Subject: [PATCH] More cleanup... reduce DAC table to 16 colours since that's
 all we use. Don't bother copying the palette since we don't allow changes in
 it. Export CurrMode for use by gettextinfo(). Add the true MONO palette. Use
 an enum for palette selection. Change name of 'colour' member to more
 accurate 'palette'

---
 src/conio/console.c  |  37 ++-------------
 src/conio/console.h  |   5 +-
 src/conio/vidmodes.h | 109 +++++++++++++++++++++----------------------
 src/conio/x_cio.c    |   2 +-
 4 files changed, 59 insertions(+), 94 deletions(-)

diff --git a/src/conio/console.c b/src/conio/console.c
index e7a28a1aec..5b70777908 100644
--- a/src/conio/console.c
+++ b/src/conio/console.c
@@ -60,7 +60,6 @@ int CurrMode;
 sem_t	console_mode_changed;
 int InitCS;
 int InitCE;
-BYTE VideoMode;
 int FW, FH;
 WORD DpyCols;
 BYTE DpyRows;
@@ -118,7 +117,6 @@ struct x11 {
 struct x11 x11;
 
 /* X pixel values for the RGB triples */
-struct dac_colors *dac_rgb;
 DWORD pixels[16];
 
 #define NUMMODES	(sizeof(vparams) / sizeof(struct video_params))
@@ -996,9 +994,9 @@ dac2rgb(XColor *color, int i)
 {
     int m;
 
-    color->red   = dac_rgb[palette[i]].red << 10;
-    color->green = dac_rgb[palette[i]].green << 10;
-    color->blue  = dac_rgb[palette[i]].blue << 10;
+    color->red   = dac_default16[palette[i]].red << 10;
+    color->green = dac_default16[palette[i]].green << 10;
+    color->blue  = dac_default16[palette[i]].blue << 10;
 }
 
 /* Calculate 'pixels[]' from the current DAC table and palette.
@@ -1049,6 +1047,7 @@ init_mode(int mode)
     idx = find_vmode(mode);
     if (idx == -1) {
 		fprintf(stderr,"Cannot initialize selected mode (%d)\n",mode);
+		console_new_mode=NO_NEW_MODE;
 		sem_post(&console_mode_changed);
 		return(-1);
 	}
@@ -1065,7 +1064,7 @@ init_mode(int mode)
 
     /* Point 'palette[]' to the Attribute Controller space. We will only use
        the first 16 slots. */
-	palette = palettes[vmode.colour];
+	palette = palettes[vmode.palette];
 
     /* Load 'pixels[]' from default DAC values. */
     update_pixels();
@@ -1132,28 +1131,6 @@ init_window()
 	return(0);
 }
 
-/* Initialize the VGA emulator
-
-   XXX This is not nearly finished right now.
-*/
-static int
-init_vga(void)
-{
-    int i;
-
-    /* Zero-fill 'dac_rgb' on allocation; the default (EGA) table has only
-       64 entries. */
-    dac_rgb = (struct dac_colors *)calloc(256, sizeof(struct dac_colors));
-    if (dac_rgb == NULL)
-		return(-1);
-
-    /* Copy the default DAC table to a working copy we can trash. */
-	for (i = 0; i < 64; i++)
-		dac_rgb[i] = dac_default64[i]; /* Structure copy */
-
-	return(0);
-}
-
 int
 kbd_init()
 {
@@ -1293,10 +1270,6 @@ video_init()
     if(init_window())
 		return(-1);
 
-   	/* Set VGA emulator to a sane state */
-   	if(init_vga())
-		return(-1);
-
     /* Initialize mode 3 (text, 80x25, 16 colors) */
     if(init_mode(3)) {
 		return(-1);
diff --git a/src/conio/console.h b/src/conio/console.h
index 64202bb834..0951d87992 100644
--- a/src/conio/console.h
+++ b/src/conio/console.h
@@ -50,9 +50,7 @@ struct dac_colors {
     BYTE blue;
 };
 
-/* We need a working copy of the default DAC table. This is filled from
-   'dac_default{64,256}[]' in 'video.c:init_vga()'. */
-extern struct dac_colors *dac_rgb;
+extern int CurrMode;
 
 extern int InitCS;
 extern int InitCE;
@@ -64,7 +62,6 @@ extern BYTE CursCol;
 extern BYTE CursStart;
 extern BYTE CursEnd;
 
-extern BYTE VideoMode;
 extern WORD DpyCols;
 extern BYTE DpyRows;
 
diff --git a/src/conio/vidmodes.h b/src/conio/vidmodes.h
index b5ab6b18de..ef9aed381e 100644
--- a/src/conio/vidmodes.h
+++ b/src/conio/vidmodes.h
@@ -41,7 +41,7 @@
 
 struct  video_params {
 	int	mode;
-	int colour;
+	int palette;
 	int	cols;
 	int rows;
 	int	curs_start;
@@ -50,110 +50,105 @@ struct  video_params {
 	int charwidth;
 };
 
+enum {
+	 MONO_PALETTE
+	,GREYSCALE_PALETTE
+	,COLOUR_PALETTE
+};
+
 struct video_params vparams[] = {
 	/* BW 40x25 */
-	{BW40, 0, 40, 25, 14, 15, 16, 8},
+	{BW40, GREYSCALE_PALETTE, 40, 25, 14, 15, 16, 8},
 	/* CO 40x25 */
-	{C40, 1, 40, 25, 14, 15, 16, 8},
+	{C40, COLOUR_PALETTE, 40, 25, 14, 15, 16, 8},
 	/* BW 80x25 */
-	{BW80, 0, 80, 25, 14, 15, 16, 8},
+	{BW80, GREYSCALE_PALETTE, 80, 25, 14, 15, 16, 8},
 	/* CO 80x25 */
-	{C80, 1, 80, 25, 14, 15, 16, 8},
+	{C80, COLOUR_PALETTE, 80, 25, 14, 15, 16, 8},
 	/* MONO */
 	{MONO, 0, 80, 25, 14, 15, 16, 8},
 	/* CO 40x14 */
-	{C40X14, 1, 40, 14, 14, 15, 16, 8},
+	{C40X14, COLOUR_PALETTE, 40, 14, 14, 15, 16, 8},
 	/* CO 40x21 */
-	{C40X21, 1, 40, 21, 14, 15, 16, 8},
+	{C40X21, COLOUR_PALETTE, 40, 21, 14, 15, 16, 8},
 	/* CO 40x28 */
-	{C40X28, 1, 40, 28, 12, 13, 14, 8},
+	{C40X28, COLOUR_PALETTE, 40, 28, 12, 13, 14, 8},
 	/* CO 40x43 */
-	{C40X43, 1, 40, 43, 7, 7, 8, 8},
+	{C40X43, COLOUR_PALETTE, 40, 43, 7, 7, 8, 8},
 	/* CO 40x50 */
-	{C40X50, 1, 40, 50, 7, 7, 8, 8},
+	{C40X50, COLOUR_PALETTE, 40, 50, 7, 7, 8, 8},
 	/* CO 40x60 */
-	{C40X60, 1, 40, 60, 7, 7, 8, 8},
+	{C40X60, COLOUR_PALETTE, 40, 60, 7, 7, 8, 8},
 	/* CO 80x14 */
-	{C80X14, 1, 80, 14, 14, 15, 16, 8},
+	{C80X14, COLOUR_PALETTE, 80, 14, 14, 15, 16, 8},
 	/* CO 80x21 */
-	{C80X21, 1, 80, 21, 14, 15, 16, 8},
+	{C80X21, COLOUR_PALETTE, 80, 21, 14, 15, 16, 8},
 	/* CO 80x28 */
-	{C80X28, 1, 80, 28, 12, 13, 14, 8},
+	{C80X28, COLOUR_PALETTE, 80, 28, 12, 13, 14, 8},
 	/* CO 80x43 */
-	{C80X43, 1, 80, 43, 7, 7, 8, 8},
+	{C80X43, COLOUR_PALETTE, 80, 43, 7, 7, 8, 8},
 	/* CO 80x50 */
-	{C80X50, 1, 80, 50, 7, 7, 8, 8},
+	{C80X50, COLOUR_PALETTE, 80, 50, 7, 7, 8, 8},
 	/* CO 80x60 */
-	{C80X60, 1, 80, 60, 7, 7, 8, 8},
+	{C80X60, COLOUR_PALETTE, 80, 60, 7, 7, 8, 8},
 	/* B 40x14 */
-	{BW40X14, 0, 40, 14, 14, 15, 16, 8},
+	{BW40X14, GREYSCALE_PALETTE, 40, 14, 14, 15, 16, 8},
 	/* BW 40x21 */
-	{BW40X21, 0, 40, 21, 14, 15, 16, 8},
+	{BW40X21, GREYSCALE_PALETTE, 40, 21, 14, 15, 16, 8},
 	/* BW 40x28 */
-	{BW40X28, 0, 40, 28, 12, 13, 14, 8},
+	{BW40X28, GREYSCALE_PALETTE, 40, 28, 12, 13, 14, 8},
 	/* BW 40x43 */
-	{BW40X43, 0, 40, 43, 7, 7, 8, 8},
+	{BW40X43, GREYSCALE_PALETTE, 40, 43, 7, 7, 8, 8},
 	/* BW 40x50 */
-	{BW40X50, 0, 40, 50, 7, 7, 8, 8},
+	{BW40X50, GREYSCALE_PALETTE, 40, 50, 7, 7, 8, 8},
 	/* BW 40x60 */
-	{BW40X60, 0, 40, 60, 7, 7, 8, 8},
+	{BW40X60, GREYSCALE_PALETTE, 40, 60, 7, 7, 8, 8},
 	/* BW 80x14 */
-	{BW80X14, 0, 80, 14, 14, 15, 16, 8},
+	{BW80X14, GREYSCALE_PALETTE, 80, 14, 14, 15, 16, 8},
 	/* BW 80x21 */
-	{BW80X21, 0, 80, 21, 14, 15, 16, 8},
+	{BW80X21, GREYSCALE_PALETTE, 80, 21, 14, 15, 16, 8},
 	/* BW 80x28 */
-	{BW80X28, 0, 80, 28, 12, 13, 14, 8},
+	{BW80X28, GREYSCALE_PALETTE, 80, 28, 12, 13, 14, 8},
 	/* BW 80x43 */
-	{BW80X43, 0, 80, 43, 7, 7, 8, 8},
+	{BW80X43, GREYSCALE_PALETTE, 80, 43, 7, 7, 8, 8},
 	/* BW 80x50 */
-	{BW80X50, 0, 80, 50, 7, 7, 8, 8},
+	{BW80X50, GREYSCALE_PALETTE, 80, 50, 7, 7, 8, 8},
 	/* BW 80x60 */
-	{BW80X60, 0, 80, 60, 7, 7, 8, 8},
+	{BW80X60, GREYSCALE_PALETTE, 80, 60, 7, 7, 8, 8},
 	/* MONO 80x14 */
-	{MONO14, 0, 80, 14, 14, 15, 16, 8},
+	{MONO14, MONO_PALETTE, 80, 14, 14, 15, 16, 8},
 	/* MONO 80x21 */
-	{MONO21, 0, 80, 21, 14, 15, 16, 8},
+	{MONO21, MONO_PALETTE, 80, 21, 14, 15, 16, 8},
 	/* MONO 80x28 */
-	{MONO28, 0, 80, 28, 12, 13, 14, 8},
+	{MONO28, MONO_PALETTE, 80, 28, 12, 13, 14, 8},
 	/* MONO 80x43 */
-	{MONO43, 0, 80, 43, 7, 7, 8, 8},
+	{MONO43, MONO_PALETTE, 80, 43, 7, 7, 8, 8},
 	/* MONO 80x50 */
-	{MONO50, 0, 80, 50, 7, 7, 8, 8},
+	{MONO50, MONO_PALETTE, 80, 50, 7, 7, 8, 8},
 	/* MONO 80x60 */
-	{MONO60, 0, 80, 60, 7, 7, 8, 8},
+	{MONO60, MONO_PALETTE, 80, 60, 7, 7, 8, 8},
 	/* Magical C4350 Mode */
-	{C4350, 1, 80, 50, 7, 7, 8, 8},
+	{C4350, COLOUR_PALETTE, 80, 50, 7, 7, 8, 8},
 };
 
 unsigned char palettes[][16] = {
+	/* Mono */
+	{ 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
+	  0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
+	},
 	/* Black and White */
-	{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
-	  0x10, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18
+	{ 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
+	  0x08, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f
 	},
 	/* Colour */
-	{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 
-	  0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
+	{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+	  0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
 	}
 };
 
-/* The default DAC table for the EGA and VGA 16 color modes. This table is
-   installed on startup. The values are taken from the output of 'scon -p
-   list'. */
-struct dac_colors dac_default64[] = {
+struct dac_colors dac_default16[] = {
 	{0, 0, 0},    {0, 0, 42},   {0, 42, 0},   {0, 42, 42},
-	{42, 0, 0},   {42, 0, 42},  {42, 42, 0},  {42, 42, 42},
-	{0, 0, 21},   {0, 0, 63},   {0, 42, 21},  {0, 42, 63},
-	{42, 0, 21},  {42, 0, 63},  {42, 42, 21}, {42, 42, 63},
-	{0, 21, 0},   {0, 21, 42},  {0, 63, 0},   {0, 63, 42},
-	{42, 21, 0},  {42, 21, 42}, {42, 63, 0},  {42, 63, 42},
-	{0, 21, 21},  {0, 21, 63},  {0, 63, 21},  {0, 63, 63},
-	{42, 21, 21}, {42, 21, 63}, {42, 63, 21}, {42, 63, 63},
-	{21, 0, 0},   {21, 0, 42},  {21, 42, 0},  {21, 42, 42},
-	{63, 0, 0},   {63, 0, 42},  {63, 42, 0},  {63, 42, 42},
-	{21, 0, 21},  {21, 0, 63},  {21, 42, 21}, {21, 42, 63},
-	{63, 0, 21},  {63, 0, 63},  {63, 42, 21}, {63, 42, 63},
-	{21, 21, 0},  {21, 21, 42}, {21, 63, 0},  {21, 63, 42},
-	{63, 21, 0},  {63, 21, 42}, {63, 63, 0},  {63, 63, 42},
+	{42, 0, 0},   {42, 0, 42},  {42, 21, 0},  {42, 42, 42},
 	{21, 21, 21}, {21, 21, 63}, {21, 63, 21}, {21, 63, 63},
 	{63, 21, 21}, {63, 21, 63}, {63, 63, 21}, {63, 63, 63}
 };
diff --git a/src/conio/x_cio.c b/src/conio/x_cio.c
index e6ec2c5f56..d0bf74e0a5 100644
--- a/src/conio/x_cio.c
+++ b/src/conio/x_cio.c
@@ -177,7 +177,7 @@ void x_gotoxy(int x, int y)
 
 void x_gettextinfo(struct text_info *info)
 {
-	info->currmode=VideoMode;
+	info->currmode=CurrMode;
 	info->screenheight=DpyRows+1;
 	info->screenwidth=DpyCols;
 	info->curx=wherex();
-- 
GitLab