Graphics Library (part 3 of 5)

Dave Lewis lewis at m2-net.UUCP
Fri Jul 1 14:07:31 AEST 1988


------------------------------  cut here  ------------------------------
# To recover, type "sh archive"
echo restoring Makefile
sed 's/^X//' > Makefile <<XxX--EOF--XxX
XCFLAGS = -c -Ml -O
XLDFLAGS = -Ml
XOBJS = testpat.o clear.o movpen.o draw.o box.o linedraw.o write_pix.o init.o grafchar.o grafstr.o finish.o cellchar.o cellstr.o cursor.o pix_mode.o pix_color.o
X
Xall:	demo xdemo mode 
X
Xmode: mode.c setmode.c 
X	cc -o mode mode.c setmode.c
X	chmod +x mode.sh
X	#
X	# If you have an EGA or CGA, you can use mode.sh instead of
X	# the mode.c program (mv mode.sh mode)."  If you have a Hercules
X	# or Everex Edge, use mode.c.  For other adapters, you may have
X	# to modify mode.c.
X	#
X	# If you use mode.c, you must make it suid and owned by root.
X	# Put it in a safe path, of course.
X	#
X	# Don't forget to create your video shared memory using 
X	# shmcreate(1).  This should be in your /etc/rc.d/shm.rc file.
X	#
X	# Try running demo and xdemo to see how things work.
X
Xdemo:	demo.o \$(OBJS)
X	cc demo.o -o demo \$(LDFLAGS) $(OBJS)
X
Xxdemo:	xdemo.o \$(OBJS)
X	cc xdemo.o -o xdemo \$(LDFLAGS) $(OBJS)
X
Xdemo.o: demo.c
X	cc \$(CFLAGS) demo.c
X
Xtestpat.o: testpat.c
X	cc \$(CFLAGS) testpat.c
X
Xclear.o: clear.c
X	cc \$(CFLAGS) clear.c
X
Xmovpen.o: movpen.c
X	cc \$(CFLAGS) movpen.c
X
Xdraw.o: draw.c
X	cc \$(CFLAGS) draw.c
X
Xbox.o: box.c
X	cc \$(CFLAGS) box.c
X
Xlinedraw.o: linedraw.c
X	cc \$(CFLAGS) linedraw.c
X
Xwrite_pix.o: write_pix.c
X	cc \$(CFLAGS) write_pix.c
X
Xinit.o: init.c
X	cc \$(CFLAGS) init.c
X
Xgrafchar.o: grafchar.c
X	cc \$(CFLAGS) grafchar.c
X
Xgrafstr.o: grafstr.c
X	cc \$(CFLAGS) grafstr.c
X
Xfinish.o: finish.c
X	cc \$(CFLAGS) finish.c
X
Xcellchar.o: cellchar.c
X	cc \$(CFLAGS) cellchar.c
X
Xcellstr.o: cellstr.c
X	cc \$(CFLAGS) cellstr.c
X
Xcursor.o: cursor.c
X	cc \$(CFLAGS) cursor.c
X
Xpix_mode.o: pix_mode.c
X	cc \$(CFLAGS) pix_mode.c
X
Xpix_color.o: pix_color.c
X	cc \$(CFLAGS) pix_color.c
X
X
XxX--EOF--XxX
echo restoring demo.c
sed 's/^X//' > demo.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) demo.c 4.6 88/06/19";
X#endif
X
X/*
X *	Copyright (c) David T. Lewis 1987, 1988
X *	All rights reserved.
X *
X *	Permission is granted to use this for any personal noncommercial use.
X *	You may not distribute source or executable code for profit, nor
X *	may you distribute it with a commercial product without the written
X *	consent of the author.  Please send modifications to the author for
X *	inclusion in updates to the program.  Thanks.
X */
X
X#include <signal.h>
X#include <sys/types.h>
X#include <ctype.h>
X#include <sys/ipc.h>
X#include <stdio.h>
X
X/*  Sun Nov 29 16:20:03 EST 1987 */
X/*  Sat Mar 21 22:59:10 EST 1987 */
X/*  Sun Feb 21 11:50:45 EST 1988 */
X
X#include "graphics.h"
X
Xextern struct SVAT_graphics graphics;
X
Xmain(argc,argv)  
Xint argc;
Xchar *argv[];
X{
X	int testpattern();
X
X	char *mode_to_use[8];
X	int idx;
X	int init(), grafstr(), finish(), istat;
X	void null_function(); 
X
X	if (argc < 2)  {
X		printf ("Usage:  demo <mode>\n\nWhere <mode> can be 4, 6, 8, EGA or print)\n");
X		exit(0);
X		}
X
X	if (strcmp(argv[1],"4") == 0) {
X		graphics.grafmode = CGA_COLOR_MODE;
X		strcpy(mode_to_use,"mode 4");
X	}
X	else if (strcmp(argv[1],"6") == 0) {
X		graphics.grafmode = CGA_HI_RES_MODE;
X		strcpy(mode_to_use,"mode 6");
X	}
X	else if (strcmp(argv[1],"8") == 0) {
X		graphics.grafmode = HERC_GRAF_MODE;
X		strcpy(mode_to_use,"mode 8");
X	}
X	else if (strcmp(argv[1],"16") == 0) {
X		graphics.grafmode = EGA_COLOR_MODE;
X		strcpy(mode_to_use,"mode 16");
X	}
X	else if (strcmp(argv[1],"EGA") == 0) { 
X		graphics.grafmode = EGA_COLOR_MODE;
X		strcpy(mode_to_use,"mode 16");
X	}
X	else if (strcmp(argv[1],"print") == 0) { 
X		graphics.grafmode = IBM_PRINTER;
X		strcpy(mode_to_use," ");
X	}
X	else  {
X		printf ("Valid modes are 4, 6, 8, EGA, and print.\n");
X		exit (1);
X	}
X
X        /* Set video mode. */
X
X	istat = init(graphics.grafmode);
X
X	system(mode_to_use);
X
X	istat = clear();
X
X	istat = testpattern();
X
X	if (graphics.grafmode != IBM_PRINTER)  {
X
X		/* Kill some time... */
X		signal(SIGALRM,null_function);
X		alarm(4);
X		pause();
X
X		istat = clear();
X
X		/* void grafstr(strng,x,y,vsize,hsize,spacing)  */
X		istat = grafstr("AbCdEfGhIjKlMnOpQrStUvWxYz",10,10000,400,180,1250);
X		istat = grafstr("AbCdEfGhIjKlMnOpQrStUvWxYz",100,25000,150,80,667);
X		istat = grafstr("AbCdEfGhIjKlMnO",100,15000,800,360,2500);
X
X		istat = grafstr("Z#\$%^&*()+",100,20000,600,400,2600);
X
X	if (graphics.grafmode != IBM_PRINTER)  {
X		/* Kill some time... */
X		signal(SIGALRM,null_function);
X		alarm(4);
X		pause();
X	}
X
X		istat = clear();
X
X		istat = cursor(1,1);
X		istat = cellstr("This should be (1,1)");
X
X		istat = cursor(2,30);
X		istat = cellstr("This should be (2,30)");
X
X		istat = cursor(3,60);
X		istat = cellstr("This should be (3,60)");
X
X		istat = cursor(10,40);
X		istat = cellstr("This should be (10,40)");
X
X		istat = cursor(25,40);
X		cellstr("X");
X
X		istat = cursor(25,80);
X		cellstr("X");
X
X		istat = cursor(43,90);
X		cellstr("X");
X
X		cursor(2,1); cellstr("This");
X		cursor(3,1); cellstr(" Is ");
X		cursor(4,1); cellstr("  A ");
X		cursor(5,1); cellstr("TEST");
X		cursor(6,1); cellstr("XXXX");
X		cursor(7,1); cellstr("XXXX");
X
X		for (idx=1;idx<=43;idx++)  {
X			cursor(idx,20);
X			cellstr("XHIHX");
X		}
X
X		/* Kill some time... */
X		signal(SIGALRM,null_function);
X		alarm(4);
X		pause();
X
X		system ("mode 2");
X	}
X
X	istat = finish();
X}
X
Xstatic void null_function()  {
X	/* Do nothing.  Dummy signal handling routine for SIGALRM. */
X}
X
XxX--EOF--XxX
echo restoring finish.c
sed 's/^X//' > finish.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) finish.c 4.6 88/06/19";
X#endif
X
X/*
X *	Copyright (c) David T. Lewis 1987, 1988
X *	All rights reserved.
X *
X *	Permission is granted to use this for any personal noncommercial use.
X *	You may not distribute source or executable code for profit, nor
X *	may you distribute it with a commercial product without the written
X *	consent of the author.  Please send modifications to the author for
X *	inclusion in updates to the program.  Thanks.
X */
X
X
X/* Wed Feb 10 20:58:37 EST 1988						*/
X/* Detach shared memory and do any other clean up chores.		*/
X/* If printing, the print job is dispatched to the print spooler.	*/
X/* This routine is specific to Microport System V/AT, and presumes 	*/
X/* that shared memory segments have been defined (usually at system 	*/
X/* boot time) such that	the shared memory keys are "B8000L" for CGA 	*/
X/* adapter, and so on. */
X
X#define TEXTPITCH(fp) fputc(033,fp);fputc('A',fp);fputc(014,fp);fputc(033,fp);fputc('2',fp);
X#define GRAFPITCH(fp) fputc(033,fp); fputc('1',fp);
X#define GRAFSTART(fp) fputc(033,fp); fputc('L',fp); fputc(0300,fp);fputc(03,fp);
X#define CRLF(fp) fputc(015,fp); fputc(012,fp);
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/ipc.h>
X#include <string.h>
X#include "graphics.h"
X
Xint finish()
X
X{
X	extern struct SVAT_graphics graphics;
X	int shmdt(), fprintf(), fputs(), fwrite();
X	int shmid;
X	int clear();
X	void free();
X	char *getenv();
X	extern errno;
X	int idx;
X	char printprog[60];
X	char *envptr;
X
X	FILE *popen(), *fhandle;
X	int pclose();
X
X	switch (graphics.grafmode)  {
X
X		case CGA_HI_RES_MODE:
X			/* Erase graphics memory.		*/
X			if (clear()) return(1);
X			/* Detach the shared memory segment.	*/
X			if (shmdt(graphics.cgamem) < 0) return(errno);
X			break;
X
X		case CGA_COLOR_MODE:
X			/* Erase graphics memory.		*/
X			if (clear()) return(1);
X			/* Detach the shared memory segment.	*/
X			if (shmdt(graphics.cgamem) < 0) return(errno);
X			break;
X
X		case EGA_COLOR_MODE:
X			/* Erase graphics memory.		*/
X			if (clear()) return(1);
X			/* Detach the shared memory segment.	*/
X			if (shmdt(graphics.egamem) < 0) return(errno);
X			break;
X
X		case HERC_GRAF_MODE:
X			/* Erase graphics memory.		*/
X			if (clear()) return(1);
X			/* Detach the shared memory segment.	*/
X			if (shmdt(graphics.hercmem) < 0) return(errno);
X			break;
X
X		case IBM_PRINTER:
X	
X			/* Print the buffer */
X
X			/* Use the environment variable PLOTDEV if set. */
X
X			strcpy(printprog, PRINTPROG);
X			strcat(printprog, " ");
X			if ((envptr = getenv("PLOTDEV")) != NULL)  {
X				strcat(printprog, "-d");
X				strcat(printprog, envptr);
X			}
X	
X			if ((fhandle = popen(printprog, "w")) == NULL) {
X				fprintf(stderr,
X					"finish():  Error piping to %s\n", 
X					printprog);
X				return(1); 
X				}
X
X			/* Dump the print image to the file */
X
X			/* Set line feed pitch to 7/72" */
X
X			GRAFPITCH(fhandle);
X
X			/* Write the lines of data (3 buffers full) */
X			for (idx=0; idx<PRINTLINES; idx++)  {
X				GRAFSTART(fhandle);
X				fwrite(&(graphics.printbuf1->buf[idx][0]),
X					sizeof(char), PRINTDENSITY, fhandle);
X				CRLF(fhandle);
X			}
X			for (idx=0; idx<PRINTLINES; idx++)  {
X				GRAFSTART(fhandle);
X				fwrite(&(graphics.printbuf2->buf[idx][0]),
X					sizeof(char), PRINTDENSITY, fhandle);
X				CRLF(fhandle);
X			}
X			for (idx=0; idx<PRINTLINES; idx++)  {
X				GRAFSTART(fhandle);
X				fwrite(&(graphics.printbuf3->buf[idx][0]),
X					sizeof(char), PRINTDENSITY, fhandle);
X				CRLF(fhandle);
X			}
X
X			/* Set line feed pitch back to 12/72" for text */
X			TEXTPITCH(fhandle);
X
X			if (pclose(fhandle) < 0) return(1);
X
X			/* Free the allocated memory. */
X			free(graphics.printbuf1);
X			free(graphics.printbuf2);
X			free(graphics.printbuf3);
X
X			break;
X
X		default:
X			return(1);
X	}
X	return(0);
X}
X
X
XxX--EOF--XxX
echo restoring linedraw.c
sed 's/^X//' > linedraw.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) linedraw.c 4.4 88/06/20";
X#endif
X
X/*
X *	Copyright (c) David T. Lewis 1987, 1988
X *	All rights reserved.
X *
X *	Permission is granted to use this for any personal noncommercial use.
X *	You may not distribute source or executable code for profit, nor
X *	may you distribute it with a commercial product without the written
X *	consent of the author.  Please send modifications to the author for
X *	inclusion in updates to the program.  Thanks.
X */
X
X/* Fri Jul  3 23:43:36 EDT 1987
X** dtlewis
X** Routine to draw a line.
X*/
X
Xint linedraw(x1,y1,x2,y2)  
X	int x1, y1, x2, y2;
X{
X	int movepen(), draw();
X	if (movepen(x1,y1)) return(1);
X	if (draw(x2,y2)) return(1);
X	return(0);
X}
XxX--EOF--XxX
echo restoring mode.c
sed 's/^X//' > mode.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) mode.c 4.4 88/06/19";
X#endif
X
X/*
X *	Copyright (c) David T. Lewis 1987, 1988
X *	All rights reserved.
X *
X *	Permission is granted to use this for any personal noncommercial use.
X *	You may not distribute source or executable code for profit, nor
X *	may you distribute it with a commercial product without the written
X *	consent of the author.  Please send modifications to the author for
X *	inclusion in updates to the program.  Thanks.
X */
X
X/* dtlewis 7-13-1987 
X** Take command line argument to set graphics mode.  If no argument, then
X** read standard input until end of file.
X*/
X
X#define NORMAL_MODE 2
X
X#include <stdio.h>
X
Xmain(argc,argv) 
Xint argc;
Xchar *argv[];
X{
X	int setmode();
X	int modevalue, stat;
X	char *inbuf[20];
X
X	if (argc > 2) {
X		printf("Usage:  mode n\n");
X		exit(0);
X	}
X
X	else if (argc == 2)  {
X		modevalue = atoi(argv[1]);
X		if (modevalue < 0 || modevalue > 11) {
X			printf("Mode must be between 0 and 11\n");
X			exit(0);
X		}
X		setmode(modevalue);
X	}
X	else if (argc == 1)  {
X#ifdef DEBUG
X		for ( ; ; ) {
X			stat=scanf("%d", &modevalue);
X			if (stat == EOF) exit(0);
X			/* Clear input stream if bad read. */
X			if (stat == 0) gets(inbuf, 20, stdin); 
X			if (stat == 1 && modevalue >= 0 && modevalue <=11) 
X				setmode(modevalue);
X			}
X#endif /* DEBUG */
X		setmode(NORMAL_MODE);
X		}
X	}
XxX--EOF--XxX
echo restoring mode.sh
sed 's/^X//' > mode.sh <<XxX--EOF--XxX
X:
X#  Contributed by Denis Fortin, April 1988.
X#
X#  mode - This trivial little command file is used to set the graphics mode
X#	  of the console on Microport System V/AT.
X#
X#  Usage:
X#		mode [value]
X#
X# 	where: value is an integer used to select the current display
X#		     mode.  If it is omitted, the screen is returned to
X#		     normal text mode.
X#
X#  Examples:
X#	mode
X#		Returns to normal text mode
X#
X#	mode 16
X#		Puts an EGA card with Enhanced Display adapter in 640x350
X#		graphics mode.
X#
X#	mode 6
X#		Puts a CGA card in 640x200 graphics mode.
X#
Xif [ \$# -lt 1 ] 
Xthen
X	echo "\033[=h\c"
Xelse
X	echo "\033[=\${1}h\c"
Xfi
XxX--EOF--XxX
echo restoring movpen.c
sed 's/^X//' > movpen.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) movpen.c 4.3 88/06/19";
X#endif
X
X/*
X *	Copyright (c) David T. Lewis 1987, 1988
X *	All rights reserved.
X *
X *	Permission is granted to use this for any personal noncommercial use.
X *	You may not distribute source or executable code for profit, nor
X *	may you distribute it with a commercial product without the written
X *	consent of the author.  Please send modifications to the author for
X *	inclusion in updates to the program.  Thanks.
X */
X
X/* dtlewis Fri Jul  3 23:12:40 EDT 1987 
X** Routine to move the logical graphics cursor to the indicated (x,y)
X** position.
X*/
X
X#include "graphics.h"
X
Xextern struct SVAT_graphics graphics;
X
Xint movepen(x,y)  
X	int x,y;
X{
X        /* Set the graphics cursor to the indicated position. */
X        /* X and y are in normalized 2-D coordinates (0 to 32767). */
X        if ((graphics.x_cursor = x) < 0 ) return(1);
X        if ((graphics.y_cursor = y) < 0 ) return(1);
X	return(0);
X}
XxX--EOF--XxX
echo restoring setmode.c
sed 's/^X//' > setmode.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) setmode.c 4.3 88/06/19";
X#endif
X#define MSDOS 0
X#define UNIX 1
X/*
X *	Module	:	mode
X *	Date	:	8705.20
X *	Author	:	Jeffrey A. Turner
X *	Purpose	:	Set cga video modes (0-6) when active Unix display
X *			is an mda.  Modified to support modes 7 and 8
X *			on Everex Edge.
X *
X *	Modifications:	dtlewis 8-16-1987 Changes to support mode 7 and to
X *			support Hercules operation on an Everex Edge.
X *			Hercules 720 x 348 (page 0) is referred to as
X *			mode 8 for this routine, and Hercules page 1 is
X *			referred to as mode 9.  Note that these are for
X *			convenience, and conflict with the PCjr mode
X *			assignments, which I presume to be non-reusable
X *			and obsolete.
X *
X *			Split modeset() off from the main routine to make
X *			it callable from any program.
X *
X *			Renamed the function to setmode().
X *
X *	Useage:		int setmode(modenumber)
X *			int modenumber
X *
X *	\$Log$
X */
X
X#include <stdio.h>
X#if UNIX
X#include <sys/types.h>
X#include <sys/io_op.h>
X#endif
X
Xextern	errno;
X
Xint	fd;
X
X/* Define the mode register settings. */
Xunsigned char	creg[12] = {
X	0x2c, 0x28, 0x2d, 0x2d, 0x2a, 0x2e, 0x1e, 0x2d, 0x0e, 0x8e, 0x2d, 0x2d
X};
X/* Define the Everex extended graphics register settings */
Xunsigned char	ext_graf_reg[12] = {
X	0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x06, 0x06
X};
X
Xunsigned char	params[192] = {
X/*0*/	0x38, 0x28, 0x2d, 0x0a, 0x1f, 0x06, 0x19, 0x1c,   /* 40x25 b/w */
X	0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
X
X/*1*/	0x38, 0x28, 0x2d, 0x0a, 0x1f, 0x06, 0x19, 0x1c,   /* 40x25 color */
X	0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
X
X/*2*/	0x61, 0x50, 0x52, 0x0f, 0x19, 0x06, 0x19, 0x19,	  /* 80x25 b/w */
X	0x02, 0x0d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00,
X
X/*3*/	0x71, 0x50, 0x5a, 0x0a, 0x1f, 0x06, 0x19, 0x1c,	  /* 80x25 color */
X	0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
X
X/*4*/	0x38, 0x28, 0x2d, 0x0a, 0x7f, 0x06, 0x64, 0x70,	  /* 320x200 color */
X	0x02, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
X
X/*5*/	0x38, 0x28, 0x2d, 0x0a, 0x7f, 0x06, 0x64, 0x70,	  /* 320x200 b/w */
X	0x02, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
X
X/*6*/	0x38, 0x28, 0x2d, 0x0a, 0x7f, 0x06, 0x64, 0x70,	  /* 640x200 b/w */
X	0x02, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
X
X/*7*/	0x61, 0x50, 0x52, 0x0f, 0x19, 0x06, 0x19, 0x19,	  /* mono */
X	0x02, 0x0d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00,
X
X/*8*/	0x36, 0x2d, 0x2e, 0x07, 0x5a, 0x02, 0x57, 0x57,   /* Hercules 720x348 */
X	0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X
X/*9*/	0x37, 0x2d, 0x2f, 0x05, 0x57, 0x00, 0x57, 0x57,   /* Hercules 720x348 */
X	0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X
X/*10*/	0x9a, 0x84, 0x86, 0x0f, 0x19, 0x06, 0x19, 0x19,   /* Everex 132x25b&w */
X	0x02, 0x0d, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
X
X/*11*/	0x9a, 0x84, 0x86, 0x0f, 0x2d, 0x02, 0x2c, 0x2c,   /* Everex 132x44b&w */
X	0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00
X};
X
Xsetmode(mode)
Xint	mode;
X{
X	int	i;
X	int	j;
X	int	bport;
X	int	cgaaddr  = 0x3d4;		/* cga 6845 port address */
X	int	monoaddr = 0x3b4;		/* mda 6845 port address */
X
X#if UNIX
X	if ((fd = open("/dev/mem", 2)) < 0) {
X		fprintf(stderr, "mode: open of /dev/mem failed\n");
X		perror("mode");
X		exit(1);
X		}
X#endif
X	if ((mode == 2 | mode == 7) | (mode == 8) | (mode == 9) |
X			(mode == 10) | (mode == 11))  {
X		/* Select mono mode on Everex Edge. */
X		bport = cgaaddr;
X		outb(bport+9, 2);		/* Extended Graphics Register */
X		bport = monoaddr;
X		}
X	else  {
X		/* Select CGA mode on Everex Edge. */
X		bport = monoaddr;
X		outb(bport+9, 0);		/* Extended Graphics Register */
X		bport = cgaaddr;
X		}
X
X	outb(bport+4, 0);			/* Reset mode register */
X
X	outb(bport+11, 0x06);			/* Enable all 64k of Everex 
X						** Edge video memory, for mono 
X						** adapter. 
X						*/
X
X	outb(bport+9, ext_graf_reg[mode]);	/* set Everex "extended 
X						graphics register" */
X	j = (mode+1)*16;
X	for(i=mode*16; i < j; i++) {
X		outb(bport, i);			/* select register */
X		outb(bport+1, params[i]);	/* send value */
X		}
X
X	outb(bport+4, creg[mode]);		/* enable */
X	if (mode == 6)
X		outb(bport+5, 0x3f);	/* set overscan for 640x200 */
X	else
X		outb(bport+5, 0x30);	/* set normal overscan */
X	close(fd);
X	return(0);
X}
X
X#if UNIX
Xoutb(portno, data)
Xint	portno;
Xint	data;
X{
X	io_op_t	iop;
X
X	iop.io_port = portno;
X	iop.io_byte = data;
X	if (ioctl(fd, IOCIOP_WB, &iop) < 0) {
X		fprintf(stderr, "mode: error on IOCIOP_WB\n");
X		perror("mode");
X		exit(1);
X	}
X}
X#endif
X
X
X#if MSDOS
Xoutb(portno, data)
Xint portno;
Xint data;
X{
X	outp(portno,data);
X}
X#endif
X
XxX--EOF--XxX
echo restoring testpat.c
sed 's/^X//' > testpat.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) testpat.c 4.5 88/06/20";
X#endif
X#include "graphics.h"
Xextern struct SVAT_graphics graphics;
X
Xint testpattern()  {
X
X	int pix_color();
X
X        /* Put a test pattern on the screen. */
X
X	int linedraw(), movepen(), draw(), box();
X
X	if (linedraw(4000,4000,20000,20000)) return(1);
X
X        if (movepen(6000,6000)) return(1);
X        if (draw(12000,6000)) return(1);
X        if (draw(12000,12000)) return(1);
X        if (draw(6000,12000)) return(1);
X        if (draw(6000,6000)) return(1);
X
X        if (movepen(6000,6000)) return(1);
X        if (draw(12000,12000)) return(1);
X
X	pix_color(3);
X
X	if (box(700,700,900,1200)) return(1);
X	if (box(900,1200,1100,1700)) return(1);
X	if (box(20000,20000,30000,30000)) return(1);
X
X	if (box(1000,10000,12000,12000)) return(1);
X	if (box(9000,9000,13000,13000)) return(1);
X	if (box(8000,8000,14000,14000)) return(1);
X	if (box(7000,7000,15000,15000)) return(1);
X	if (box(6000,6000,16000,16000)) return(1);
X
X        if (movepen(2000,13000)) return(1);
X        if (draw(4000,13000)) return(1);
X        if (movepen(4000,13300)) return(1);
X        if (draw(2000,13300)) return(1);
X
X	pix_color(2);
X
X        if (movepen(2000,14000)) return(1);
X        if (draw(30000,14400)) return(1);
X        if (draw(2000,14800)) return(1);
X        if (draw(30000,15200)) return(1);
X        if (draw(2000,15600)) return(1);
X        if (draw(30000,16000)) return(1);
X        if (draw(2000,16400)) return(1);
X        if (draw(30000,16800)) return(1);
X        if (draw(2000,17200)) return(1);
X        if (draw(30000,17600)) return(1);
X        if (draw(2000,18000)) return(1);
X        if (draw(30000,18400)) return(1);
X        if (draw(0,18800)) return(1);
X        if (draw(32000,19200)) return(1);
X        if (draw(0,19600)) return(1);
X        if (draw(32000,20000)) return(1);
X        if (draw(0,20400)) return(1);
X        if (draw(32000,20800)) return(1);
X        if (draw(0,21200)) return(1);
X        if (draw(32000,21600)) return(1);
X        if (draw(0,22000)) return(1);
X        if (draw(32000,22400)) return(1);
X
X        if (movepen(6000,4000)) return(1);
X        if (draw(6200,30000)) return(1);
X        if (draw(6400,4000)) return(1);
X        if (draw(6600,30000)) return(1);
X        if (draw(6800,4000)) return(1);
X        if (draw(7000,30000)) return(1);
X        if (draw(7200,4000)) return(1);
X        if (draw(7400,30000)) return(1);
X        if (draw(7600,4000)) return(1);
X        if (draw(7800,30000)) return(1);
X        if (draw(8000,4000)) return(1);
X        if (draw(8200,30000)) return(1);
X        if (draw(8400,4000)) return(1);
X
X	pix_color(1);
X
X        if (movepen(2000,2000)) return(1);
X        if (draw(32000,4000)) return(1);
X        if (draw(31000,32000)) return(1);
X        if (draw(1000,30000)) return(1);
X        if (draw(2000,2000)) return(1);
X        if (draw(31000,32000)) return(1);
X
X        if (movepen(0,0)) return(1);
X        if (draw(32767,0)) return(1);
X        if (draw(32767,32767)) return(1);
X        if (draw(0,32767)) return(1);
X        if (draw(0,0)) return(1);
X        if (draw(32767,32767)) return(1);
X        if (movepen(0,32767)) return(1);
X        if (draw(32767,0)) return(1);
X
X	return(0);
X}
XxX--EOF--XxX
echo restoring write_pix.c
sed 's/^X//' > write_pix.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) write_pix.c 4.9 88/06/19";
X#endif
X
X/*
X *	Copyright (c) David T. Lewis 1987, 1988
X *	All rights reserved.
X *
X *	Permission is granted to use this for any personal noncommercial use.
X *	You may not distribute source or executable code for profit, nor
X *	may you distribute it with a commercial product without the written
X *	consent of the author.  Please send modifications to the author for
X *	inclusion in updates to the program.  Thanks.
X */
X
X#include "graphics.h"
X/*
X *	The following routine writes a pixel dot on a CGA in modes 4
X *	and 6 and on Hercules for Microport System V/AT.
X *	Also writes to pixel buffer for printer support.
X *	Note: Operation of the "color" variable is untested; I have
X *	an Everex Edge with mono display.  Probably will work, though.
X *	I have used this in a program which does line drawing graphics,
X *	and it runs much faster than the equivalent MS-DOS program
X *	calling BIOS.  (Tested under MS-DOS with Mix-C compiler).
X */
X
Xint write_pix(x,y)  
X	int x, y;
X{
X
X/*	Mon Mar 23 00:14:50 EST 1987
X *	Sun Mar 13 22:21:46 EST 1988
X *	system5 dtlewis 2 1.3 AT
X *
X *	Compile with large memory model.
X *
X *	This routine currently supports modes 4, 6, and Hercules (arbitrarily
X *	defined as mode 8), as well as buffer for printer graphics.
X */
X
Xextern struct SVAT_graphics graphics;
X
Xstatic int row, col, page;
Xunsigned register char bitmask;
Xregister char shiftcount;
X
Xswitch (graphics.grafmode) {
X
X	case CGA_COLOR_MODE:
X
X		row = y >> 1;
X		col = x >> 2;
X
X		/* Select a color mask, consisting of four 2 bit patterns. */
X		switch (graphics.color) {
X			case 0:	bitmask = 0;
X				break;
X			case 1: bitmask = 0x055;
X				break;
X			case 2: bitmask = 0x0AA;
X				break;
X			case 3:	bitmask = 0x0FF;
X				break;
X			default:bitmask = 0x0FF;
X		}
X
X		/* Apply the color mask to the two bit pixel of interest. */
X		switch (x & 0x0003)  {
X			case 0:	bitmask &= PIX0;
X				break;
X			case 1:	bitmask &= PIX1;
X				break;
X			case 2:	bitmask &= PIX2;
X				break;
X			case 3:	bitmask &= PIX3;
X				break;
X		}
X
X		/* Write pixel to the appropriate page for this line. */
X		if (y & 0x0001) 
X			switch (graphics.wrt_mode)  {
X				case OR:
X					(graphics.cgamem)->page2[row][col] 
X						|= bitmask;
X					break;
X				case XOR:
X					(graphics.cgamem)->page2[row][col] 
X						^= bitmask;
X					break;
X			}
X		else
X			switch (graphics.wrt_mode)  {
X				case OR:
X					(graphics.cgamem)->page1[row][col] 
X						|= bitmask;
X					break;
X				case XOR:
X					(graphics.cgamem)->page1[row][col] 
X						^= bitmask;
X					break;
X			}
X		break;
X
X	case CGA_HI_RES_MODE:
X
X		row = y >> 1;
X		col = x >> 3;
X
X		bitmask = 0x80;
X		shiftcount = x & 0x0007;
X		bitmask = bitmask >> shiftcount;
X
X		if (y & 0x0001) {
X			switch (graphics.wrt_mode)  {
X				case OR:
X					(graphics.cgamem)->page2[row][col] 
X						|= bitmask;
X					break;
X				case XOR:
X					(graphics.cgamem)->page2[row][col] 
X						^= bitmask;
X					break;
X			}
X		}
X		else {
X			switch (graphics.wrt_mode)  {
X				case OR:
X					(graphics.cgamem)->page1[row][col] 
X						|= bitmask;
X					break;
X				case XOR:
X					(graphics.cgamem)->page1[row][col] 
X						^= bitmask;
X					break;
X			}
X		}
X		break;
X
X	case EGA_COLOR_MODE:
X
X		col = x >> 3;
X
X		bitmask = 0x80;
X		shiftcount = x & 0x0007;
X		bitmask = bitmask >> shiftcount;
X
X		(graphics.egamem)->mem[y][col] |= bitmask;
X		break;
X
X	case HERC_GRAF_MODE:
X
X		row = y >> 2;
X		col = x >> 3;
X
X		bitmask = 0x80 >> (x & 0x0007);
X
X		switch (y & 0x0003) {
X
X			case 0:
X				switch (graphics.wrt_mode)  {
X					case OR:
X						(graphics.hercmem)
X						->page1[row][col] 
X						|= bitmask;
X						break;
X					case XOR:
X						(graphics.hercmem)
X						->page1[row][col] 
X						^= bitmask;
X						break;
X				}
X				break;
X			case 1:
X				switch (graphics.wrt_mode)  {
X					case OR:
X						(graphics.hercmem)
X						->page2[row][col] 
X						|= bitmask;
X						break;
X					case XOR:
X						(graphics.hercmem)
X						->page2[row][col] 
X						^= bitmask;
X						break;
X				}
X				break;
X			case 2:
X				switch (graphics.wrt_mode)  {
X					case OR:
X						(graphics.hercmem)
X						->page3[row][col] 
X						|= bitmask;
X						break;
X					case XOR:
X						(graphics.hercmem)
X						->page3[row][col] 
X						^= bitmask;
X						break;
X				}
X				break;
X			case 3:
X				switch (graphics.wrt_mode)  {
X					case OR:
X						(graphics.hercmem)
X						->page4[row][col] 
X						|= bitmask;
X						break;
X					case XOR:
X						(graphics.hercmem)
X						->page4[row][col] 
X						^= bitmask;
X						break;
X				}
X				break;
X		}
X		break;
X
X	case IBM_PRINTER:
X
X		col = PRINTDENSITY - y - 1;
X
X		row = (x >> 3);
X		page = 0;
X		while (row >= PRINTLINES)  {
X			row -= PRINTLINES;
X			++page;
X		}
X
X		bitmask = 0x80 >> (x & 0x0007);
X
X		switch (page) {
X
X			case 0:	/* Page 0 */
X				switch (graphics.wrt_mode)  {
X					case OR:
X						(graphics.printbuf1)
X						->buf[row][col] 
X						|= bitmask;
X						break;
X					case XOR:
X						(graphics.printbuf1)
X						->buf[row][col] 
X						^= bitmask;
X						break;
X					}
X				break;
X			case 1:	/* Page 1 */
X				switch (graphics.wrt_mode)  {
X					case OR:
X						(graphics.printbuf2)
X						->buf[row][col] 
X						|= bitmask;
X						break;
X					case XOR:
X						(graphics.printbuf2)
X						->buf[row][col] 
X						^= bitmask;
X						break;
X					}
X				break;
X			case 2: /* Page 2 */
X				switch (graphics.wrt_mode)  {
X					case OR:
X						(graphics.printbuf3)
X						->buf[row][col] 
X						|= bitmask;
X						break;
X					case XOR:
X						(graphics.printbuf3)
X						->buf[row][col] 
X						^= bitmask;
X						break;
X					}
X				break;
X		}
X		break;
X	default:
X		return(1);
X	}
X	return(0);
X}
XxX--EOF--XxX
-- 
Dave Lewis
Ann Arbor, MI
...![ itivax umix ]!m-net!dtlewis!lewis



More information about the Comp.unix.microport mailing list