PD plot(4) librarys (and hercules driver for interactive 386) part 7 of 9

Roland van Hout hot at integow.uucp
Sun Oct 28 14:57:48 AEST 1990


#!/bin/sh
# This is part 07 of a multipart archive
if touch 2>&1 | fgrep '[-amc]' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= libplot/cgi/libCGI.c ==============
echo "x - extracting libplot/cgi/libCGI.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > libplot/cgi/libCGI.c &&
X
X/* plot(4) graphics library for the SCO  CGI library under xenix*/
X
X
X#include <stdio.h>	/* for fprintf on stderr	*/
X#include <ctype.h>	/*	we are using tolower()	*/
X#define MAIN	1	/* causes declarations in the .h files to occur here */
X#include "cgistuff.h"	/*	includes cgitypes.h and cgifctns.h	*/
X#include "ctest.h"
X#include <signal.h>
X
X/*VOID close_gin_device( VOID );	/*	in gintests.c	*/
X
Xstatic char cgidisplay[]="CGIDISP ";
Xstatic char cgiprinter[]="CGIPRNT ";
Xchar * cgidevice = cgidisplay;
Xstatic void usage_message();
Xint vsl_type_returns;
X
X
X
X
Xfloat gxscrunch,gyscrunch;
Xfloat pitograd;
Xint CGIoffx,CGIoffy;
X
X# include <stdio.h>
X# include <fcntl.h>
X# include "CGI.h"
X# include <math.h>
X
X	herc_args	CGIhv,CGIcurpos;
X
X/* #define DEBUG   /* turn on if no driver calls should be made!*/
X
Xopenpl()
X{
X
X	int strlen( char * );
X#ifndef NO_DEBUGGING
X#ifndef MSDOS
X#ifdef CGIVER
X	extern int scodebug;	/* declared in the bindings in v_opnwk.c */
X#else
X	extern int cgidebug;	/* declared in the bindings in v_opnwk.c */
X#endif
X#endif
X#endif
X				/* setting to TRUE will cause the bindings */
X				/* to print out the execl command rather */
X				/* than executing it when they are forking */
X				/* the agents.	*/
X	/* local variables */
X	SINT16	coord_xform_mode;
X	char	*char_pointer;
X	register SINT16	i;
X	char * char_ptr;
X	int defer_mode;
X	int use_defaults;
X
X
X
X	use_defaults = TRUE;
X
X	manual_operation = FALSE;	/* m flag */
X	do_timings = FALSE;		/* t flag */
X	defer_mode = ASAP;	/* b flag sets to (BNI), or a sets to (ASTI) */
X	coord_xform_mode = 0;	/* selected with 0, 1, 2, or 3	*/
X
X
X#ifndef NO_DEBUGGING
X#ifndef MSDOS
X#ifdef CGIVER
X	if ( scodebug )
X	{
X		printf( "\nExecute the desired agent with these 4 arguments on a console screen:\n" );
X	}
X	else
X#else
X	if ( cgidebug )
X	{
X		printf( "\nExecute the desired agent with these 4 arguments on a console screen:\n" );
X	}
X	else
X#endif
X#endif
X#endif
X
X	ok_to_use_graphtext = FALSE;
X
X	if ( cgistart( coord_xform_mode, defer_mode )	)
X	{
X		fprintf( stderr, "plotcgi: message: open failed, ctest will exit.\n" );
X		fprintf( stderr, "plotcgi: requires environment variables:\n" );
X		fprintf( stderr, "CGIPATH=   <- specify pathname for location of CGI agents.\n" );
X		fprintf( stderr, "CGIDISP=   <- specify agent name for display\n" );
X/*		fprintf( stderr, "or CGIPRNT=  <- alternate agent name when running plotcgi with -p option.\n" );*/
X		fprintf( stderr, "(instead of CGIPATH, you may need VDIPATH for CGI ver. 1.0 bindings.)\n" );
X		exit (-1);
X	}
X
X	/*	set up the color palettes	*/
X	original_palette();
X	normal_graphtext();	/* adjusts graphtext size	*/
X
X
X	/*	CGI starts up in graphics mode	*/
X	ok_to_use_graphtext = TRUE;
X
X	/*	The workstation should already be clear at this time.	*/
X
X        CGIcurpos=CGIhv;
X	linemod("solid");
X}
X
Xclosepl()
X{
X#ifndef DEBUG
X	if (isatty(0)) getchar(); /* stdin is a tty then leave the 
X		screen until a character is pressed */
X	/* close the workstation*/
X	if ( v_clswk(dev_handle) < 0 )
X		report_cgi_error( "v_clswk" );
X#endif
X}
X
Xspace(x0,y0,x1,y1)
Xint x0,y0,x1,y1;
X{
Xint x,y;
Xpitograd=(180.0/M_PI);
X
Xif (x1>0 && y1>0 && y0<y1 && x0<x1) {
X	x=x1-x0;y=y1-y0;
X	gxscrunch=(VDC_X/(float) x);gyscrunch=(VDC_Y/(float) y);
X	CGIoffx = (-1 *(x0*gxscrunch) + 1);
X	CGIoffy=(y0*gyscrunch)-1;
X}
X
X#ifdef DEBUG
Xprintf("offx=%d, offy=%d\n",CGIoffx,CGIoffy);
X#endif
X
X}
X
Xerase()
X{
X#ifndef DEBUG
X	if (isatty(0)) getchar(); /* stdin is a tty then leave the 
X		screen until a character is pressed */
X	v_clrwk(dev_handle);
X#endif
X}
X
Xlabel(s)
Xchar *s;
X{
X#ifndef DEBUG
X	v_gtext(dev_handle, CGIcurpos.x1,CGIcurpos.y1,s);
X#else
X	printf("str=%s, x=%d, y=%d\n",s,CGIhv.x1,CGIhv.y1);
X#endif
X}
X
Xmove(x,y)
Xint x,y;
X{
XSINT16 row,column;
X	x = x*gxscrunch;
X	y = y*gyscrunch;
X	y += CGIoffy ;
X	x +=  CGIoffx ;
X	CGIcurpos.x1 = x;  CGIcurpos.y1 = y;
X	column = x; row = y;
X	vs_curaddress(dev_handle,row,column);
X#ifdef DEBUG
X	printf("move %d, %d\n",x,y);
X#endif
X
X}
X
Xcont(x,y)
Xint x,y;
X{
X	int xo,yo;
X
X	int line_spacing;
X	int start_line;
X	SINT16 polyline_array[256];
X
X	xo = x*gxscrunch;
X	yo = y*gyscrunch;
X	yo += CGIoffy ;
X	xo +=  CGIoffx ;
X	/*	leave room for 5 lines of text at the top	*/
X	start_line = VDC_Y - (5 * cell_height);
X	line_spacing = start_line / (LINE_TYPES+1);
X
X
X	/* draw each line type across the screen in default color */
X	polyline_array[0] = CGIcurpos.x1;	/* x1 */
X	polyline_array[2] = xo;	/* x2 */
X	polyline_array[1] = CGIcurpos.y1;/*y1*/
X	polyline_array[3] = yo;	/* y2 */
X	CGIhv.c = CGIcurpos.c;
X#ifndef DEBUG
X	if ( v_pline( dev_handle, 2, polyline_array ) < 0 )
X		report_cgi_error( "v_pline" );
X#else
X		printf("cont = line from %d,%d to %d,%d\n",CGIhv.x1,CGIhv.y1,CGIhv.x2,CGIhv.y2);
X#endif
X		CGIcurpos.x1=xo;CGIcurpos.x2=yo;
X}
X
Xline (x1, y1, x2, y2)
Xint x1,y1,x2,y2;
X{
X	move(x1,y1);
X	cont(x2,y2);
X}
Xcircle(x,y,r)
Xint x,y,r;
X{
XSINT16 xo,yo,ro;
X	xo=(x*gxscrunch);yo=(y*gyscrunch);
X	yo = CGIoffy + yo;
X	xo =  CGIoffx + xo;
X	ro = (r * gxscrunch);
X	v_circle(dev_handle,xo,yo,ro);
X}
X
Xarc(x,y,x0,y0,x1,y1)
Xint x,y,x0,y0,x1,y1;
X{
X#ifdef ARC
Xfloat a1,a2,r1,r2;
XSINT16 xo,yo,c1,c2,r;
X	if ((x-x0) > 0) {
X		r1=(y-y0)/(x-x0);
X		a1=atan(r1);
X		c1=(a1*pitograd*10);
X	}
X	else {
X		c1=1800;
X	}
X	if ((x-x1) > 0) {
X		r2=(y-y1)/(x-x1);
X		a2=atan(r2);
X		c2=(a2*pitograd*10);
X	}
X	else {
X		c2=1800;
X	}
X	
X	xo=(x0*gxscrunch);yo=(y0*gyscrunch);
X	yo = CGIoffy + yo;
X	xo =  CGIoffx + xo;
X	v_arc(dev_handle, xo,yo, ,c1,c2);
X#endif
X}
X
Xdot(xi,yi,dx,n,pat)
Xint xi,yi,dx,n,pat[256];
X{
X}
X
Xpoint(x,y)
Xint x,y;
X{
Xint xo,yo;
X	xo = x*gxscrunch;
X	yo = y*gyscrunch;
X	yo += CGIoffy ;
X	xo +=  CGIoffx ;
X	CGIcurpos.x1 = xo; CGIcurpos.y1 = yo;
X#ifndef DEBUG
X	move(x,y);
X	cont(x,y);
X#else
X		printf("point %d,%d\n",x,y);
X#endif
X}
X
Xlinemod(s)
Xchar *s;
X{
XSINT16 line_type;
X  if (strcmp(s,"dotted")==0) {
X	line_type = 3;
X	  }
X  else if (strcmp(s,"solid")==0) {
X	line_type = 1;
X	  }
X	  else if (strcmp(s,"longdashed")==0) {
X		line_type = 2;
X		  }
X		 else if (strcmp(s,"shortdashed")==0) {
X			line_type = 7;
X			 }
X			else if (strcmp(s,"dotdashed")==0) {
X				line_type = 4;
X				}
Xif ( (vsl_type_returns = vsl_type( dev_handle, line_type )) < 0)
X	report_cgi_error( "vsl_type" );
X}
X
X
Xbox(x0, y0, x1, y1)
X{
X	move(x0, y0);
X	cont(x0, y1);
X	cont(x1, y1);
X	cont(x1, y0);
X	cont(x0, y0);
X	move(x1, y1);
X}
SHAR_EOF
$TOUCH -am 1014213390 libplot/cgi/libCGI.c &&
chmod 0666 libplot/cgi/libCGI.c ||
echo "restore of libplot/cgi/libCGI.c failed"
set `wc -c libplot/cgi/libCGI.c`;Wc_c=$1
if test "$Wc_c" != "6196"; then
	echo original size 6196, current size $Wc_c
fi
# ============= libplot/cgi/README ==============
echo "x - extracting libplot/cgi/README (Text)"
sed 's/^X//' << 'SHAR_EOF' > libplot/cgi/README &&
XThe following files are not included because of SCO copyrights:
Xcgifctns.h cgistart.c cgistuff.c cgistuff.h cgitypes.h ctest.h gtexttests.c
XIf you get Xenix with CGI you will get these files anyway.
SHAR_EOF
$TOUCH -am 1014213590 libplot/cgi/README &&
chmod 0644 libplot/cgi/README ||
echo "restore of libplot/cgi/README failed"
set `wc -c libplot/cgi/README`;Wc_c=$1
if test "$Wc_c" != "199"; then
	echo original size 199, current size $Wc_c
fi
# ============= libplot/cgi/h.c ==============
echo "x - extracting libplot/cgi/h.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > libplot/cgi/h.c &&
X# include <stdio.h>
X# include <fcntl.h>
X# include <math.h>
X
Xmain(argc, argv)
Xint	argc;
Xchar	*argv[];
X{
X	int	i,j;
X	char	strbuff[90];
X
X	openpl();space(0,0,720,350);
X	for (j=1;j<=100;j++) {
X	erase();
X	move(280,280);
X	/* Do some random dots */
X	label("Some random dots.");
X	for (i = 0; i < 100; i ++)
X	{
X		point( abs(lrand48() % 719),abs(lrand48() % 347));
X	};
X/*	sleep(10);
X	/* Do some random lines */
X	erase();
X	move(280,280);
X	/* Do some random dots */
X	label("Some random lines.");
X	for (i = 0; i < 50; i ++)
X	{
X	line( abs(lrand48() % 719),abs(lrand48() % 347),abs(lrand48() % 719),abs(lrand48() % 347));
X	};
X	}
X	closepl();
X}	
SHAR_EOF
$TOUCH -am 0511152090 libplot/cgi/h.c &&
chmod 0666 libplot/cgi/h.c ||
echo "restore of libplot/cgi/h.c failed"
set `wc -c libplot/cgi/h.c`;Wc_c=$1
if test "$Wc_c" != "627"; then
	echo original size 627, current size $Wc_c
fi
# ============= lp.c ==============
echo "x - extracting lp.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > lp.c &&
X/*	@(#)driver.c	5.1		*/
X#include <stdio.h>
X#include <math.h>
X#include <errno.h>
X#include "plotlpus.h"
X
Xfloat deltx = 4095.0;
Xfloat delty = 4095.0;
X
Xmain(argc,argv)  char **argv; {
X	int std=1;
X	FILE *fin;
X
X	while(argc-- > 1) {
X		if(*argv[1] == '-')
X			switch(argv[1][1]) {
X				case 'l':
X					deltx = atoi(&argv[1][2]) - 1;
X					break;
X				case 'w':
X					delty = atoi(&argv[1][2]) - 1;
X					break;
X				case 's':
X					printer=LASERLOW;
X					break;
X				case 'm':
X					printer=LASERMED;
X					break;
X				case 'h':
X					printer=LASERHIGH;
X					break;
X				case 'i':
X					printer=IBM_PRO;
X					break;
X				case 'e':
X					printer=EPSON;
X					break;
X				}
X
X		else {
X			std = 0;
X			if ((fin = fopen(argv[1], "r")) == NULL) {
X				fprintf(stderr, "can't open %s\n", argv[1]);
X				exit(1);
X				}
X			fplt(fin);
X			}
X		argv++;
X		}
X	if (std)
X		fplt( stdin );
X	exit(0);
X	}
X
X
Xfplt(fin)  FILE *fin; {
X	int c;
X	char s[256];
X	int xi,yi,x0,y0,x1,y1,r,dx,n,i;
X	int pat[256];
X
X	openpl();
X	while((c=getc(fin)) != EOF){
X		switch(c){
X		case 'm':
X			xi = getsi(fin);
X			yi = getsi(fin);
X			move(xi,yi);
X			break;
X		case 'l':
X			x0 = getsi(fin);
X			y0 = getsi(fin);
X			x1 = getsi(fin);
X			y1 = getsi(fin);
X			line(x0,y0,x1,y1);
X			break;
X		case 't':
X			getsd(s,fin);
X			label(s);
X			break;
X		case 'e':
X			erase();
X			break;
X		case 'p':
X			xi = getsi(fin);
X			yi = getsi(fin);
X			point(xi,yi);
X			break;
X		case 'n':
X			xi = getsi(fin);
X			yi = getsi(fin);
X			cont(xi,yi);
X			break;
X		case 's':
X			x0 = getsi(fin);
X			y0 = getsi(fin);
X			x1 = getsi(fin);
X			y1 = getsi(fin);
X			space(x0,y0,x1,y1);
X			break;
X		case 'a':
X			xi = getsi(fin);
X			yi = getsi(fin);
X			x0 = getsi(fin);
X			y0 = getsi(fin);
X			x1 = getsi(fin);
X			y1 = getsi(fin);
X			arc(xi,yi,x0,y0,x1,y1);
X			break;
X		case 'c':
X			xi = getsi(fin);
X			yi = getsi(fin);
X			r = getsi(fin);
X			circle(xi,yi,r);
X			break;
X		case 'f':
X			getsd(s,fin);
X			linemod(s);
X			break;
X		case 'd':
X			xi = getsi(fin);
X			yi = getsi(fin);
X			dx = getsi(fin);
X			n = getsi(fin);
X			for(i=0; i<n; i++)pat[i] = getsi(fin);
X			dot(xi,yi,dx,n,pat);
X			break;
X			}
X		}
X	closepl();
X	}
Xgetsi(fin)  FILE *fin; {	/* get an integer stored in 2 ascii bytes. */
X	short a, b;
X	if((b = getc(fin)) == EOF)
X		return(EOF);
X	if((a = getc(fin)) == EOF)
X		return(EOF);
X	a = a<<8;
X	return(a|b);
X}
Xgetsd(s,fin)  char *s;  FILE *fin; {
X	for( ; *s = getc(fin); s++)
X		if(*s == '\n')
X			break;
X	*s = '\0';
X	return;
X}
X
X
Xmatherr(x)
Xstruct exception *x;
X{
Xif(x->type==DOMAIN)
X	{errno=EDOM;
X	if(!strcmp("log",x->name))x->retval = (-HUGE);
X	else x->retval = 0;
X	return(1);
X	}
Xelse  if ((x->type)==SING)
X	{errno=EDOM;
X	x->retval = (-HUGE);
X	return(1);
X	}
Xelse return(0);
X}
X
X
SHAR_EOF
$TOUCH -am 1014215790 lp.c &&
chmod 0644 lp.c ||
echo "restore of lp.c failed"
set `wc -c lp.c`;Wc_c=$1
if test "$Wc_c" != "2654"; then
	echo original size 2654, current size $Wc_c
fi
# ============= herc/Makefile ==============
if test ! -d 'herc'; then
    echo "x - creating directory herc"
    mkdir 'herc'
fi
echo "x - extracting herc/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/Makefile &&
X# define IX386 for Interactive 386
XDEFINES=-DIX386
XCFLAGS=$(DEFINES)
X
Xherc.o: herc.c herc.h
X	cc -c $(DEFINES) -DINKERNEL herc.c
X
X# must be root to make install
Xinstall: herc.o 
X	cp herc.o herc.c herc.h config Makefile /etc/atconf/modules/herc
X	mkunix
X	mv /etc/atconf/kernels/unix.std.* /unix.test
X
X# must be root to make filesys
X# also edit /etc/atconf/systems/system.std to enter herc as device with 
X# major device number 15
Xfilesys:
X	mknod /dev/herc c 15 0
X	chmod ugo+rwx /dev/herc
X	mkdir /etc/atconf/modules/herc
X
Xtest: test.o  herc.h
X	cc -o test $(DEFINES) test.o 
X
Xprint:
X	srcpub herc.h test.c herc.c config Makefile >PRINT
X	trj PRINT
X	offjet tr.PRINT
SHAR_EOF
$TOUCH -am 1014125090 herc/Makefile &&
chmod 0644 herc/Makefile ||
echo "restore of herc/Makefile failed"
set `wc -c herc/Makefile`;Wc_c=$1
if test "$Wc_c" != "658"; then
	echo original size 658, current size $Wc_c
fi
# ============= herc/bitset.h ==============
echo "x - extracting herc/bitset.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/bitset.h &&
Xstatic char SCCS_x[] = "%W% %G% %U%";
X/*+++
X	bitset.h
X 
X	PURPOSE : bit manipulation macros
X
X	DATE	: 2/15/90
X
X	AUTHOR  : W. Hatch
X
X	PROJECT : WEH Software
X			
X	COMPANY : Computational Engineering
X		  14504 Greenview Drive Suite 500
X		  Laurel, Maryland 20708
X		  Phone (301)470-3839
X		  FAX (301)776-5461
X
X	CREDITS : Harbison And Steele, A C Reference Manual
X		  Prentice Hall, 1984, Pages 172-180
X
X---*/ 
X/*
X------------------------------------------------------------------------
X  MODIFICATIONS
XDATE-PROGRAMMER	DESCRIPTION
X------------------------------------------------------------------------
X*/
X
X#define	SET		unsigned long
X#define SET_BITS	(sizeof(SET) * 8)	/* number of bits in SET */
X
X#define VALIDBIT(i)	((i) < SET_BITS && (i) >= 0)
X
X#define	EMPTYSET		((SET) 0)
X#define SINGLESET(i)		(((SET) 1) << (i))
X#define DOSET(set,i)		((set | (SINGLESET(i))))
X#define AND(set1,set2)		((set1) & (set2))
X#define OR(set1, set2)		((set1) | (set2))
X#define XOR(set1, set2)		((set1) ^ (set2))
X#define ISSET(i,set)		(SINGLESET((i)) & (set))
X#define MASKSET(set,mask)	((set) & (mask) == (mask))
SHAR_EOF
$TOUCH -am 1013182190 herc/bitset.h &&
chmod 0644 herc/bitset.h ||
echo "restore of herc/bitset.h failed"
set `wc -c herc/bitset.h`;Wc_c=$1
if test "$Wc_c" != "1086"; then
	echo original size 1086, current size $Wc_c
fi
# ============= herc/config ==============
echo "x - extracting herc/config (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/config &&
X* 1 "herc/config.c
X
X*ident	"@(#)config	
X
Xcharacter(9)
X
Xprefix = herc
X
Xfunctions = init, open, close, read, write, ioctl
X
SHAR_EOF
$TOUCH -am 1013182190 herc/config &&
chmod 0644 herc/config ||
echo "restore of herc/config failed"
set `wc -c herc/config`;Wc_c=$1
if test "$Wc_c" != "121"; then
	echo original size 121, current size $Wc_c
fi
# ============= herc/herc.c ==============
echo "x - extracting herc/herc.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > herc/herc.c &&
Xstatic char SCCS_hercdent[] = "%W% %G% %U%";
X/*======================================================================*/
X/*  herc.c - hercules graphics card driver for Microport V386/3.0e	*/
X/*									*/
X/*	2/5/90								*/
X/*	Bill Hatch							*/
X/*	uunet!bts!bill							*/
X/*	Computational Engineering					*/
X/*	14504 Greenview Drive Suite 500					*/
X/*	Laurel, Maryland 20708						*/
X/*	Phone (301)470-3839						*/
X/*									*/
X/*	see herc.h for credits to other programmers and authors		*/
X/*======================================================================*/
X#include "herc.h"
Xextern char *sptalloc();
Xextern int  sptfree();
Xextern unsigned char inb();
X
X/*----------------------------------------------------------------------*/
X/* settings for 6845 chips data registers for graphics and text modes	*/
X/*----------------------------------------------------------------------*/
Xstatic int gdata[12] = {0x35, 0x2d, 0x2e, 0x7, 0x5b, 0x2, 0x57, 0x57, 0x2,
X	0x3, 0x0, 0x0};
Xstatic int tdata[12] = {0x61, 0x50, 0x52, 0xf, 0x19, 0x6, 0x19, 0x19, 0x2,
X	0xd, 0xb, 0xc};
X
Xstatic char *myvaddr;
Xstatic char *vaddr0;
Xstatic char *vaddr1;
Xstatic int g_mode();
Xstatic int t_mode();
X
Xstatic int clearscreen();
Xstatic int wait_for_retrace();
X
X/*======================================================================*/
X/* hercinit - nothing done						*/
X/*======================================================================*/
Xhercinit(dev)
Xint dev;
X{
X	u.u_error = 0;
X	return;
X}
X/*======================================================================*/
X/* hercopen - enable graphics and clear screen				*/
X/*======================================================================*/
Xhercopen(dev,flag)
Xint dev;
Xint flag;
X{
X	int i;
X
X	/*--------------------------------------------------------------*/
X	/* map herc graphics pages to virtual memory and set myvaddr	*/
X	/* to page 0							*/
X	/*--------------------------------------------------------------*/
X	if((vaddr0=sptalloc(HERC_SIZE,PG_P, HERC_PAGE_0,0)) == (char *)0 ||
X		(vaddr1=sptalloc(HERC_SIZE,PG_P, HERC_PAGE_1,0)) == (char *)0)
X	{
X		KERROR("hercopen: sptalloc() failed");
X		u.u_error = 1;
X		return;
X	}
X	myvaddr = vaddr0;
X	/*--------------------------------------------------------------*/
X	/* clear both pages of graphics memory				*/
X	/*--------------------------------------------------------------*/
X#ifdef DBUG
X	printf("hercopen: vaddr0: %d, vaddr1: %d, \n", vaddr0, vaddr1);
X#endif
X	/*--------------------------------------------------------------*/
X	/* switch to graphics mode					*/
X	/*--------------------------------------------------------------*/
X	if(g_mode() < 0)
X	{
X		KERROR("hercopen: g_mode() failed");
X		u.u_error = 1;
X		return;
X	}
X	clearscreen(vaddr0);
X	clearscreen(vaddr1);
X	u.u_error = 0;
X	return;
X}
X/*======================================================================*/
X/* hercclose - close the herc device					*/
X/*======================================================================*/
Xhercclose(dev)
Xint dev;
X{
X	clearscreen(vaddr0);
X	clearscreen(vaddr1);
X	/*--------------------------------------------------------------*/
X	/* switch to text mode						*/
X	/*--------------------------------------------------------------*/
X	t_mode();
X	/*--------------------------------------------------------------*/
X	/* free mapped virtual memory					*/
X	/*--------------------------------------------------------------*/
X	sptfree(vaddr0, HERC_SIZE,0);
X	sptfree(vaddr1, HERC_SIZE,0);
X
X#ifdef DBUG
X	printf("hercclose:\n");
X#endif
X	u.u_error = 0;
X	return;
X}
X/*======================================================================*/
X/* hercioctl - does nothing						*/
X/*======================================================================*/
Xhercioctl(dev, cmd, arg)
Xint dev;
Xint cmd;
XHERC *arg;
X{
X
X	u.u_error = 0;
X	return;
X}
Xhercread(dev)
Xint dev;
X{
X}
X/*======================================================================*/
X/* hercwrite - perform all herc graphics operations			*/
X/*======================================================================*/
Xhercwrite(dev)
Xint dev;
X{
X	HERC	*arg;
X	HERC herc;
X	unsigned char *pc;
X	int x;
X	int y;
X	int cmd;
X	int i;
X
X	unsigned char byte;
X	int byteloc;
X	int myint;
X
X	pc = (unsigned char *)(&herc);
X	arg = (&herc);
X	for(i=0; i < sizeof(HERC); i++)
X	{
X		if( (myint = cpass()) < 0)
X		{
X			printf("i= %d\n", i);
X			KERROR("hercwrite: cpass failed");
X			u.u_error = 1;
X			return;
X		}
X		pc[i] = myint;
X	}
X	/************ an alternate, untested way of accomplishing the above
X	if(copyin(&u.u_base, arg, sizeof(HERC)) != SUCCESS)
X	{
X		printf("u.u_count: %d, u.u_base: %d, u.u_offset: %d\n",
X			u.u_count, u.u_base, u.u_offset);
X		printf("sizeof(HERC): %d\n", sizeof(HERC));
X		KERROR("hercwrite: copyin() failed");
X		u.u_error = 1;
X		return;
X	}
X	**********/
X#ifdef DBUG
X	printf("hercwrite: x: %d, y: %d, cmd: %d\n",
X		arg->phys_x, arg->phys_y, arg->cmd);
X#endif
X	/*--------------------------------------------------------------*/
X	/* extract and validate HERC contents				*/
X	/*--------------------------------------------------------------*/
X	if((x=arg->phys_x) > PHYS_X_MAX || x < PHYS_X_MIN
X		|| (y=arg->phys_y) > PHYS_Y_MAX || y < PHYS_Y_MIN)
X	{
X		KERROR("hercwrite: illegal arg");
X			printf("arg: %d, cmd: %d, x: %d, y: %d\n", 
X				arg, arg->cmd, x, y);
X		u.u_error = 1;
X		return;
X	}
X	cmd = arg->cmd;
X	/*--------------------------------------------------------------*/
X	/* compute offset of byte to be acted on			*/
X	/*--------------------------------------------------------------*/
X	if(cmd == SET_PIXEL || cmd == CLEAR_PIXEL || cmd == REVERSE_PIXEL)
X	{
X		byteloc = BYTE_OFFSET(x,y);
X	}	
X	
X	/*--------------------------------------------------------------*/
X	/* perform action						*/
X	/*--------------------------------------------------------------*/
X	switch(cmd)
X	{
X		case SET_PIXEL:	
X				SET_BIT(myvaddr[byteloc], x);
X				break;
X
X		case CLEAR_PIXEL: 
X				CLEAR_BIT(myvaddr[byteloc], x);
X				break;
X
X		case REVERSE_PIXEL: 
X				REVERSE_BIT(myvaddr[byteloc], x);
X				break;
X
X		case CLEAR_SCREEN_0:
X				clearscreen(vaddr0);
X				break;
X
X		case CLEAR_SCREEN_1:
X				clearscreen(vaddr1);
X				break;
X				
X		/* this switch screen does not work, any comments or 	*/
X		/* suggestions are welcome  WEH 2/17/90			*/
X		case SWITCH_SCREEN_0:
X				myvaddr = vaddr0;
X				wait_for_retrace();
X				if(outb(DMC_PORT, DMC_PAGE_0) == FAILURE)
X				{
X					KERROR("hercwrite: outb() failed ");
X					return(FAILURE);
X				}
X				break;
X
X		case SWITCH_SCREEN_1:
X				myvaddr = vaddr1;
X				wait_for_retrace();
X				if(outb(DMC_PORT, DMC_PAGE_1) == FAILURE)
X				{
X					KERROR("hercwrite: outb() failed ");
X					return(FAILURE);
X				}
X				break;
X	}
X	u.u_error = 0;
X	return;
X}
X/*======================================================================*/
X/* clearscreen - turn all pixels off					*/
X/*======================================================================*/
Xstatic int clearscreen(vaddr)
Xchar *vaddr;
X{
X	unsigned int i;
X	for(i = 0; i < HERC_PAGE_BYTES; i++)
X	{
X		vaddr[i] = 0;
X	}
X	return(SUCCESS);
X}
X/*======================================================================*/
X/* g_mode - switch to graphics mode					*/
X/*======================================================================*/
Xstatic int g_mode()
X{
X	int i; 	
X	unsigned char dmcbyte = (DMC_GRAPHICS|DMC_ON_SCREEN|DMC_PAGE_0);
X	/*--------------------------------------------------------------*/
X	/* enable both graphics pages and turn display off		*/
X	/*--------------------------------------------------------------*/
X	wait_for_retrace();
X	if(outb(CONFIG_SWITCH, CF_PAGE_0) == FAILURE ||
X		outb(DMC_PORT, DMC_OFF_SCREEN) == FAILURE)
X	{
X		KERROR("g_mode: outb() to DMC_PORT or CONFIG_SWITCH failed");
X		return(FAILURE);
X	}
X	/*--------------------------------------------------------------*/
X	/* set hardware parameters for graphics mode, failure to do this*/
X	/* may damage the video tube					*/
X	/*--------------------------------------------------------------*/
X	for(i = 0; i < 12; i++)
X	{
X		if(outb(INDEX_REG_6845, i) == FAILURE ||
X			outb(DATA_REG_6845, gdata[i]) == FAILURE)
X		{
X			KERROR("g_mode: outb() to DATA or INDEX REG failed");
X			return(FAILURE);
X		}
X	}
X	/*--------------------------------------------------------------*/
X	/* on retrace, enable graphics and turn display on		*/
X	/*--------------------------------------------------------------*/
X	wait_for_retrace();
X	if(outb(DMC_PORT, dmcbyte) == FAILURE)
X	{
X		KERROR("g_mode: outb(DMC_PORT, DMC_GRAPHICS) failed ");
X		return(FAILURE);
X	}
X	return(SUCCESS);
X}
X/*======================================================================*/
X/* t_mode - switch to text mode						*/
X/*======================================================================*/
Xstatic int t_mode()
X{
X	int i;
X	unsigned char dmcbyte = (DMC_ON_SCREEN|DMC_TEXT);
X	/*--------------------------------------------------------------*/
X	/* turn display off						*/
X	/*--------------------------------------------------------------*/
X	if(outb(DMC_PORT, DMC_OFF_SCREEN) == FAILURE)
X	{
X		KERROR("t_mode: outb to DMC_PORTT) failed ");
X		return(FAILURE);
X		
X	}
X	/*--------------------------------------------------------------*/
X	/* set hardware parameters for text mode			*/
X	/*--------------------------------------------------------------*/
X	for(i = 0; i < 12; i++)		/* set hw sweep rate etc.	*/
X	{
X		if(outb(INDEX_REG_6845, i) == FAILURE ||
X			outb(DATA_REG_6845, tdata[i]) == FAILURE)
X		{
X			KERROR("t_mode: outb() to 6845 failed");
X			return(FAILURE);
X		}
X	}
X	delay(0);
X	/*--------------------------------------------------------------*/
X	/* set text mode, turn display on				*/
X	/*--------------------------------------------------------------*/
X	if(outb(DMC_PORT, dmcbyte) == FAILURE)
X	{
X		KERROR("t_mode: outb(DMC_PORT, dmcbyte) failed");
X		return(FAILURE);
X	}
X	/*--------------------------------------------------------------*/
X	/* enable text mode						*/
X	/*--------------------------------------------------------------*/
X	if(outb(CONFIG_SWITCH, CF_TEXT_ONLY) == FAILURE)
X	{
X		KERROR("t_mode: outb(CONFIG_SWITCH, CF_TEXT_ONLY) failed");
X		return(FAILURE);
X	}
X	return(SUCCESS);
X}
X/*======================================================================*/
X/* wait_for_retrace - loop until vertical retrace			*/
X/*======================================================================*/
Xstatic int wait_for_retrace()
X{
X	unsigned char byte;
X	byte = inb(DS_PORT);
X	while(byte & DS_RETRACE)
X	{
X		delay(0);
X		byte = inb(DS_PORT);
X	}
X}
SHAR_EOF
$TOUCH -am 1013182190 herc/herc.c &&
chmod 0644 herc/herc.c ||
echo "restore of herc/herc.c failed"
set `wc -c herc/herc.c`;Wc_c=$1
if test "$Wc_c" != "10419"; then
	echo original size 10419, current size $Wc_c
fi
echo "End of part 7, continue with part 8"
exit 0




-- 
UUCP: ..!uunet!mcsun!hp4nl!integow!hot	or  hot at integow.UUCP or hot at hot.mug
Roland van Hout, Sr. software engineer, Integrity software consultants, 
         Pelmolenlaan 16, 3447 GW Woerden, Netherlands,
            tel +31 3480-30131, fax +31 3480-30182



More information about the Alt.sources mailing list