DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T g

⟦d15abdd1b⟧ TextFile

    Length: 5266 (0x1492)
    Types: TextFile
    Names: »gdevega.h«

Derivation

└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
    └─⟦ff23ba0e6⟧ »./ghostscript-1.3.tar.Z« 
        └─⟦a24a58cd3⟧ 
            └─⟦this⟧ »gdevega.h« 

TextFile

/* Copyright (C) 1989 Aladdin Enterprises.  All rights reserved.
   Distributed by Free Software Foundation, Inc.

This file is part of Ghostscript.

Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.  Refer
to the Ghostscript General Public License for full details.

Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License.  A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities.  It should be in a file named COPYING.  Among other
things, the copyright notice and this notice must be preserved on all
copies.  */

/* gdevega.h */
/* Common parts of EGA driver for GhostScript */
/* Note that this header file includes executable code, */
/* and assumes an ANSI-compatible compiler. */
#define interrupt			/* patch ANSI incompatibility */
#include <dos.h>
typedef union REGS registers;
#include "gs.h"
#include "gsmatrix.h"			/* for gxdevice.h */
#include "gxbitmap.h"
#include "gxdevice.h"

/* Define whether we are treating the EGA as a monochrome device */
#define ega_mono_only 0

typedef struct gx_device_s gx_device;

/* Dimensions of screen */
#define size_x 640
#define size_y 350
#define raster_x 80
/* Range of r-g-b values */
#if ega_mono_only
#  define rgb_max 1
#else
#  define rgb_max 2
#endif

/* Procedures */

	/* See gxdevice.h for the definitions of the procedures. */

int ega_open(P1(gx_device *));

int ega_close(P1(gx_device *));

gx_color_index ega_map_rgb_color(P4(gx_device *, ushort, ushort, ushort));

int ega_map_color_rgb(P3(gx_device *, gx_color_index, ushort *));

int ega_sync(P1(gx_device *));

int ega_fill_rectangle(P6(gx_device *, int, int, int, int, gx_color_index));

int ega_tile_rectangle(P8(gx_device *, gx_bitmap *, int, int, int, int, gx_color_index, gx_color_index));

int ega_write_dot(P4(gx_device *, int, int, gx_color_index));

int ega_copy_mono(P10(gx_device *, unsigned char *, int, int, int, int, int, int, gx_color_index, gx_color_index));

int ega_copy_color(P8(gx_device *, unsigned char *, int, int, int, int, int, int));

/* The device descriptor */
private gx_device_procs ega_procs = {
	ega_open,
	ega_close,
	ega_map_rgb_color,
	ega_map_color_rgb,
	ega_sync,
	ega_fill_rectangle,
	ega_tile_rectangle,
	ega_copy_mono,
	ega_copy_color,
	gx_default_draw_line,
	gx_default_fill_trapezoid,
	gx_default_tile_trapezoid
};
gx_device ega_device = {
	sizeof(gx_device),
	&ega_procs,
	identity_matrix_body,
	size_x, size_y,
	!ega_mono_only,		/* has_color */
	rgb_max,
	4,			/* bits per color pixel */
	1,			/* bit-big-endian */
	0			/* not opened yet */
};

/* Define the color spectrum */
#define black 0
#define blue 1
#define green 2
#define cyan 3
#define red 4
#define magenta 5
#define brown 6
#define white 7
/*#define dgray 8*/			/* dark gray is not usable */
#define lblue 9
#define lgreen 10
#define lcyan 11
#define lred 12
#define lmagenta 13
#define yellow 14
#define bwhite 15

/* Forward declarations */
private int ega_get_mode();
private void ega_set_mode(int);

/* Save the EGA mode */
private int ega_save_mode = -1;

/* Reinitialize the EGA for text mode */
int
ega_close(gx_device *dev)
{	if ( ega_save_mode >= 0 ) ega_set_mode(ega_save_mode);
	return 0;
}

/* Map a r-g-b color to an EGA color code. */
/* r, g, b are between 0 and 2. */
private char rgb_color[3][3][3] =
	{ { { black, blue, lblue },
	    { green, cyan, lcyan },
	    { lgreen, lcyan, lcyan } },
	  { { red, magenta, lmagenta },
	    { brown, white, lblue },
	    { yellow, yellow, bwhite } },
	  { { lred, lmagenta, lmagenta },
	    { yellow, yellow, lmagenta },
	    { yellow, yellow, bwhite } }
	};
gx_color_index
ega_map_rgb_color(gx_device *dev, ushort r, ushort g, ushort b)
{
#if ega_mono_only
	return (r+g+b >= 2 ? (gx_color_index)bwhite : (gx_color_index)black);
#else
	return (gx_color_index)rgb_color[r][g][b];
#endif
}

/* Map a color code to r-g-b.  Surprisingly enough, this is algorithmic. */
int
ega_map_color_rgb(gx_device *dev, gx_color_index color, ushort *prgb)
{	int on = (color & 8 ? rgb_max : 1);
	prgb[0] = (color & 4 ? on : 0);
	prgb[1] = (color & 2 ? on : 0);
	prgb[2] = (color & 1 ? on : 0);
	return 0;
}

/* "Synchronize" the frame buffer.  This is a no-op. */
int
ega_sync(gx_device *dev)
{	return 0;
}

/* Macro for validating dot parameters x, y, color */
#define validate_dot()\
  if ( (unsigned)x >= size_x || (unsigned)y >= size_y || (unsigned)color > 0xf ) return -1

/* Macro for validating rectangle parameters x, y, w, h */
#define validate_rect()\
  if ( w <= 0 || h <= 0 ) return 0;\
  if ( x < 0 || y < 0 || x + w > size_x || y + h > size_y ) return -1

/* ------ Internal routines ------ */

/* Read the device mode */
private int
ega_get_mode()
{	registers regs;
	regs.h.ah = 0xf;
	int86(0x10, &regs, &regs);
	return regs.h.al;
}

/* Set the device mode */
private void
ega_set_mode(int mode)
{	registers regs;
	regs.h.ah = 0;
	regs.h.al = mode;
	int86(0x10, &regs, &regs);
}