Hercules Graphics Driver (Here it is!)

John Antypas jantypas at hope.UUCP
Sun Jun 19 11:44:45 AEST 1988


Included below is a driver for Microport Sys V/AT providing Hercules
graphics.  The driver isn't very fancy, but it does work.  Read the
herc.readme to find out about warnings.  Don't consider this a finished
product.  I know it needs work -- lots of it, but at least it functions.
All contributions are welcome.  

Incidentally, no Microport source code was used in this driver other 
than that provided with the linkkit.  Nor were any Microport documents
used other than those provided with the linkkit.  A special thanks 
none the less to John Sully/ Dwight/Keith @ Uport as, even though they 
didn't end up in the code, they still put up with my frustration calls.

		John Antypas ...!soft21!jantypas
#--------------------------Cut Here--------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before the "#! /bin/sh" line,
# then unpack it by saving it in a file and typing "sh file."
#
# Wrapped by John Antypas (root) at soft21 on Sat Jun 18 18:06:58 1988
#
# unpacks with default permissions
#
# Contents : herc.readme herc.c test.c
#
if `test ! -s herc.readme`
then
echo "x - herc.readme"
cat > herc.readme << '@\Rogue\Monster\'
	A Hercules Graphics Driver for Microport Unix Sys V/AT

		Graphics code for MIcroport by David L. Smith
		Driver translation by John Antypas

			...!ucsd!ucrmath!soft21!jantypas
			jantypas%soft21.UUCP at garp.MIT.EDU


The code that follows provides simple line graphics for a hercules monographics
card under Microport Unix Sys V/AT.  This code should work with any Sys V/AT
version, but I have only tested it on 2.3.1L.  It provides the full screen
window for graphics (720 x 350) and handles the details of switching the 
console out etc.

The code does NOT lock the console out!  ANY uuer openning /dev/herc will
cause the console to flip to graphics mode.  For this reason, one should only 
use graphics via a library which checks to see if that users termianl
is the console itself to prevent anyone from disturbing the work in progress
on the console displays!

When /dev/herc is openned, the console switches from text to graphics mode.
The screen will then clear.  Commands are sent to the driver as follows:

	int	fd, open();

	fd = open("/dev/herc", O_WRONLY);
	write(fd, "Z", 1);		/* Zap (clear) screen */
	write(fd, "LwwwxxxyyyzzzW", 14);/* Draw line from www,xxx to yyy,zzz
					   WRITE mode -- white on black */
	write(fd, "LwwwxxxyyyzzzE", 14);/* Same as above, but erase */
	write(fd, "PxxxyyyW", 8); 	/* Plot point at xxx,yyy WRITE mode */
	write(fd, "PxxxyyyE", 8);	/* Erase point at xxx,yyy */
	write(fd, "BwwwxxxyyyzzzW",14);	/* Draw box with upper left at
					   www,xxx at lower right @ yyy,zzzz */
	write (fd, "BwwwxxxyyyzzzE", 14); /* Erase above box */
	write( fd, "Cxxxyyyccc",10); 	/* Put char ccc at xxx,yyy */
	write (fd, "Sxxxyyyzzzbbbbbbbbbbb",len)
				/* Write string of zzz chars. at xxx,yyy
			           litteral characters follow. */
	close(fd);		/* Return to console */

A test program is provided that shows these in action.  All integers are 
three digits in length, leading zeros must be provided.  CCC is the ascii
code for a character with leading zeros if needed.  bbbb are litteral letters
of the string ie: "S100100009Hi There!"  means write a (S)tring at 100,100
consisting of the 9 characters "H I <space> T h e r e !"

One notable bug, when the device is closed, the cursor does not appear until
someone hits the console change screen key a few times.  Any ideas why? 

Some warnings.  Driver space is always scarce so no real checking is done
on parameters beyond those which, if they we're wrong, would panic the kernel.
Screen size is:

For graphics: 000 -> 719 X 000 -> 347
For Text:     000 -> 089 X 000 -> 042  { Characters 8x8 }

My master file and dfile look like this (chooise your own device numbers)

herc	0	ocw	c	hg	0	15	1	{ Master }

herc	0	1						{ dfile }

Once again:

Z				--- Zap screen (clear)
Cxxxyyyccc			--- Put char ascii(ccc) at text pos. xxx,yyy
LwwwxxxyyyzzzU			--- Line from (www,xxx) to (yyy,zzz)
BwwwxxxyyyzzzU			--- Box from upper corner (www,xxx) to lower
				    corner (yyy,zzz) 
Sxxxyyyzzzbbbbbbbbbbb.....	--- Plot text string starting at text xxx,yyy
				    and plotting litteral letters (bbbbbb)
				    String is zzz bytes long.  
PxxxyyyU			--- Plot point at xxx,yyy

U is either W or E for WRITE or ERASE (white/black) for now.   

Improvements:

This was done quick and dirty to get it out quickly.  I've wanted it and have
seen that many others do too.  The documentation needs work, I'm working on a
user C library interface that also checks to see if the console is in use,
and the performance (especially slomemset()) could be improved.  Feel free
to change at will so long as I get the patches too! :-)

@\Rogue\Monster\
else
  echo "shar: Will not over write herc.readme"
fi
if `test ! -s herc.c`
then
echo "x - herc.c"
cat > herc.c << '@\Rogue\Monster\'
/* ================= Hercules Graphics Code =========================== */
/* These routines provide basic line drawing graphics for the hercules  */
/* monographics card under Microport Unix Sys V/AT 2.3.  Written by     */
/* John Antypas 12/12/87 and placed in the public domain.               */
/* Property of Microport Inc.                                           */
/*                                                                      */
/* ==================================================================== */

/* Include files */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/mmu.h>
#include <sys/seg.h>
#include <sys/map.h>
#include <sys/signal.h>
#include <sys/dir.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/user.h>
#include <sys/sysmacros.h>

int	herc_state;		/* If !=0 herc in use.		*/
char	command;		/* Command byte			*/
long	herc_base;		/* Memory base			*/

char param_g[12]={		/* parameter table for 6845 video chip */
	0x35, 0x2d, 0x2e, 0x07, 	/* graphics setup */
	0x5b, 0x02, 0x57, 0x57,
	0x02, 0x03, 0x00, 0x00};

char param_t[12]={		/* parameter table for 6845 video chip */
	0x61, 0x50, 0x52, 0x0f,	/* text setup */
	0x19, 0x06, 0x19, 0x19,
	0x02, 0x0d, 0x0b, 0x0c};

char masks[8]={
	0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};

/* RAM-Loadable Character Sets for the IBM PC
 Richard Wilton
 July 1986

/* definitions for 8 by 8 characters 00 through FF */

static char hercchars[2048]={
	0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,	/* 000 */
	0x07E,0x081,0x0A5,0x081,0x0BD,0x099,0x081,0x07E,	/* 001 */
	0x07E,0x0FF,0x000,0x0FF,0x0C3,0x0E7,0x0FF,0x07E,	/* 002 */
	0x06C,0x0FE,0x0FE,0x0FE,0x07C,0x038,0x010,0x000,	/* 003 */
	0x010,0x038,0x07C,0x0FE,0x07C,0x038,0x010,0x000,	/* 004 */
	0x038,0x07C,0x038,0x0FE,0x0FE,0x07C,0x038,0x07C,	/* 005 */
	0x010,0x010,0x038,0x07C,0x0FE,0x07C,0x038,0x07C,	/* 006 */
	0x000,0x000,0x018,0x03C,0x03C,0x018,0x000,0x000,	/* 007 */
	0x0FF,0x0FF,0x0E7,0x0C3,0x0C3,0x0E7,0x0FF,0x0FF,	/* 008 */
	0x000,0x03C,0x066,0x042,0x042,0x066,0x03C,0x000,	/* 009 */
	0x0FF,0x0C3,0x099,0x0BD,0x0BD,0x099,0x0C3,0x0FF,	/* 00A */
	0x00F,0x007,0x00F,0x07D,0x0CC,0x0CC,0x0CC,0x078,	/* 00B */
	0x03C,0x066,0x066,0x066,0x03C,0x018,0x07E,0x018,	/* 00C */
	0x03F,0x033,0x03F,0x030,0x030,0x070,0x0F0,0x0E0,	/* 00D */
	0x07F,0x063,0x07F,0x063,0x063,0x067,0x0E6,0x0C0,	/* 00E */
	0x099,0x05A,0x03C,0x0E7,0x0E7,0x03C,0x05A,0x099,	/* 00F */
	0x080,0x0E0,0x0F8,0x0FE,0x0F8,0x0E0,0x080,0x000,	/* 010 */
	0x002,0x00E,0x03E,0x0FE,0x03E,0x00E,0x002,0x000,	/* 011 */
	0x018,0x03C,0x07E,0x018,0x018,0x07E,0x03C,0x018,	/* 012 */
	0x066,0x066,0x066,0x066,0x066,0x000,0x066,0x000,	/* 013 */
	0x07F,0x000,0x000,0x07B,0x01B,0x01B,0x01B,0x000,	/* 014 */
	0x03E,0x063,0x038,0x06C,0x06C,0x038,0x0CC,0x078,	/* 015 */
	0x000,0x000,0x000,0x000,0x07E,0x07E,0x07E,0x000,	/* 016 */
	0x018,0x03C,0x07E,0x018,0x07E,0x03C,0x018,0x0FF,	/* 017 */
	0x018,0x03C,0x07E,0x018,0x018,0x018,0x018,0x000,	/* 018 */
	0x018,0x018,0x018,0x018,0x07E,0x03C,0x018,0x000,	/* 019 */
	0x000,0x018,0x00C,0x0FE,0x00C,0x018,0x000,0x000,	/* 01A */
	0x000,0x030,0x060,0x0FE,0x060,0x030,0x000,0x000,	/* 01B */
	0x000,0x000,0x0C0,0x0C0,0x0C0,0x0FE,0x000,0x000,	/* 01C */
	0x000,0x024,0x066,0x0FF,0x066,0x024,0x000,0x000,	/* 01D */
	0x000,0x018,0x03C,0x07E,0x0FF,0x0FF,0x000,0x000,	/* 01E */
	0x000,0x0FF,0x0FF,0x07E,0x03C,0x018,0x000,0x000,	/* 01F */
	0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,	/* 020 */
	0x030,0x078,0x078,0x030,0x030,0x000,0x030,0x000,	/* 021 */
	0x06C,0x06C,0x06C,0x000,0x000,0x000,0x000,0x000,	/* 022 */
	0x06C,0x06C,0x0FE,0x06C,0x0FE,0x06C,0x06C,0x000,	/* 023 */
	0x030,0x07C,0x0C0,0x078,0x00C,0x0F8,0x030,0x000,	/* 024 */
	0x000,0x0C6,0x0CC,0x018,0x030,0x066,0x0C6,0x000,	/* 025 */
	0x038,0x06C,0x038,0x076,0x0DC,0x0CC,0x076,0x000,	/* 026 */
	0x060,0x060,0x0C0,0x000,0x000,0x000,0x000,0x000,	/* 027 */
	0x018,0x030,0x060,0x060,0x060,0x030,0x018,0x000,	/* 028 */
	0x060,0x030,0x018,0x018,0x018,0x030,0x060,0x000,	/* 029 */
	0x000,0x066,0x03C,0x0FF,0x03C,0x066,0x000,0x000,	/* 02A */
	0x000,0x030,0x030,0x0FC,0x030,0x030,0x000,0x000,	/* 02B */
	0x000,0x000,0x000,0x000,0x000,0x030,0x030,0x060,	/* 02C */
	0x000,0x000,0x000,0x0FC,0x000,0x000,0x000,0x000,	/* 02D */
	0x000,0x000,0x000,0x000,0x000,0x030,0x030,0x000,	/* 02E */
	0x006,0x00C,0x018,0x030,0x060,0x0C0,0x080,0x000,	/* 02F */
	0x07C,0x0C6,0x0CE,0x0DE,0x0F6,0x0E6,0x07C,0x000,	/* 030 */
	0x030,0x070,0x030,0x030,0x030,0x030,0x0FC,0x000,	/* 031 */
	0x078,0x0CC,0x00C,0x038,0x060,0x0CC,0x0FC,0x000,	/* 032 */
	0x078,0x0CC,0x00C,0x038,0x00C,0x0CC,0x078,0x000,	/* 033 */
	0x01C,0x03C,0x06C,0x0CC,0x0FE,0x00C,0x01E,0x000,	/* 034 */
	0x0FC,0x0C0,0x0F8,0x00C,0x00C,0x0CC,0x078,0x000,	/* 035 */
	0x038,0x060,0x0C0,0x0F8,0x0CC,0x0CC,0x078,0x000,	/* 036 */
	0x0FC,0x0CC,0x00C,0x018,0x030,0x030,0x030,0x000,	/* 037 */
	0x078,0x0CC,0x0CC,0x078,0x0CC,0x0CC,0x078,0x000,	/* 038 */
	0x078,0x0CC,0x0CC,0x07C,0x00C,0x018,0x070,0x000,	/* 039 */
	0x000,0x030,0x030,0x000,0x000,0x030,0x030,0x000,	/* 03A */
	0x000,0x030,0x030,0x000,0x000,0x030,0x030,0x060,	/* 03B */
	0x018,0x030,0x060,0x0C0,0x060,0x030,0x018,0x000,	/* 03C */
	0x000,0x000,0x0FC,0x000,0x000,0x0FC,0x000,0x000,	/* 03D */
	0x060,0x030,0x018,0x00C,0x018,0x030,0x060,0x000,	/* 03E */
	0x078,0x0CC,0x00C,0x018,0x030,0x000,0x030,0x000,	/* 03F */
	0x07C,0x0C6,0x0DE,0x0DE,0x0DE,0x0C0,0x078,0x000,	/* 040 */
	0x030,0x078,0x0CC,0x0CC,0x0FC,0x0CC,0x0CC,0x000,	/* 041 */
	0x0FC,0x066,0x066,0x07C,0x066,0x066,0x0FC,0x000,	/* 042 */
	0x03C,0x066,0x0C0,0x0C0,0x0C0,0x066,0x03C,0x000,	/* 043 */
	0x0F8,0x06C,0x066,0x066,0x066,0x06C,0x0F8,0x000,	/* 044 */
	0x0FE,0x062,0x068,0x078,0x068,0x062,0x0FE,0x000,	/* 045 */
	0x0FE,0x062,0x068,0x078,0x068,0x060,0x0F0,0x000,	/* 046 */
	0x03C,0x066,0x0C0,0x0C0,0x0CE,0x066,0x03E,0x000,	/* 047 */
	0x0CC,0x0CC,0x0CC,0x0FC,0x0CC,0x0CC,0x0CC,0x000,	/* 048 */
	0x078,0x030,0x030,0x030,0x030,0x030,0x078,0x000,	/* 049 */
	0x01E,0x00C,0x00C,0x00C,0x0CC,0x0CC,0x078,0x000,	/* 04A */
	0x0E6,0x066,0x06C,0x078,0x06C,0x066,0x0E6,0x000,	/* 04B */
	0x0F0,0x060,0x060,0x060,0x062,0x066,0x0FE,0x000,	/* 04C */
	0x0C6,0x0EE,0x0FE,0x0FE,0x0D6,0x0C6,0x0C6,0x000,	/* 04D */
	0x0C6,0x0E6,0x0F6,0x0DE,0x0CE,0x0C6,0x0C6,0x000,	/* 04E */
	0x038,0x06C,0x0C6,0x0C6,0x0C6,0x06C,0x038,0x000,	/* 04F */
	0x0FC,0x066,0x066,0x07C,0x060,0x060,0x0F0,0x000,	/* 050 */
	0x078,0x0CC,0x0CC,0x0CC,0x0DC,0x078,0x01C,0x000,	/* 051 */
	0x0FC,0x066,0x066,0x07C,0x06C,0x066,0x0E6,0x000,	/* 052 */
	0x078,0x0CC,0x0E0,0x070,0x01C,0x0CC,0x078,0x000,	/* 053 */
	0x0FC,0x0B4,0x030,0x030,0x030,0x030,0x078,0x000,	/* 054 */
	0x0CC,0x0CC,0x0CC,0x0CC,0x0CC,0x0CC,0x0FC,0x000,	/* 055 */
	0x0CC,0x0CC,0x0CC,0x0CC,0x0CC,0x078,0x030,0x000,	/* 056 */
	0x0C6,0x0C6,0x0C6,0x0D6,0x0FE,0x0EE,0x0C6,0x000,	/* 057 */
	0x0C6,0x0C6,0x06C,0x038,0x038,0x06C,0x0C6,0x000,	/* 058 */
	0x0CC,0x0CC,0x0CC,0x078,0x030,0x030,0x078,0x000,	/* 059 */
	0x0FE,0x0C6,0x08C,0x018,0x032,0x066,0x0FE,0x000,	/* 05A */
	0x078,0x060,0x060,0x060,0x060,0x060,0x078,0x000,	/* 05B */
	0x0C0,0x060,0x030,0x018,0x00C,0x006,0x002,0x000,	/* 05C */
	0x078,0x018,0x018,0x018,0x018,0x018,0x078,0x000,	/* 05D */
	0x010,0x038,0x06C,0x0C6,0x000,0x000,0x000,0x000,	/* 05E */
	0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x0FF,	/* 05F */
	0x030,0x030,0x018,0x000,0x000,0x000,0x000,0x000,	/* 060 */
	0x000,0x000,0x078,0x00C,0x07C,0x0CC,0x076,0x000,	/* 061 */
	0x0E0,0x060,0x060,0x07C,0x066,0x066,0x0DC,0x000,	/* 062 */
	0x000,0x000,0x078,0x0CC,0x0C0,0x0CC,0x078,0x000,	/* 063 */
	0x01C,0x00C,0x00C,0x07C,0x0CC,0x0CC,0x076,0x000,	/* 064 */
	0x000,0x000,0x078,0x0CC,0x0FC,0x0C0,0x078,0x000,	/* 065 */
	0x038,0x06C,0x060,0x0F0,0x060,0x060,0x0F0,0x000,	/* 066 */
	0x000,0x000,0x076,0x0CC,0x0CC,0x07C,0x00C,0x0F8,	/* 067 */
	0x0E0,0x060,0x06C,0x076,0x066,0x066,0x0E6,0x000,	/* 068 */
	0x030,0x000,0x070,0x030,0x030,0x030,0x078,0x000,	/* 069 */
	0x00C,0x000,0x00C,0x00C,0x00C,0x0CC,0x0CC,0x078,	/* 06A */
	0x0E0,0x060,0x066,0x06C,0x078,0x06C,0x0E6,0x000,	/* 06B */
	0x070,0x030,0x030,0x030,0x030,0x030,0x078,0x000,	/* 06C */
	0x000,0x000,0x0CC,0x0FE,0x0FE,0x0D6,0x0C6,0x000,	/* 06D */
	0x000,0x000,0x0F8,0x0CC,0x0CC,0x0CC,0x0CC,0x000,	/* 06E */
	0x000,0x000,0x078,0x0CC,0x0CC,0x0CC,0x078,0x000,	/* 06F */
	0x000,0x000,0x0DC,0x066,0x066,0x07C,0x060,0x0F0,	/* 070 */
	0x000,0x000,0x076,0x0CC,0x0CC,0x07C,0x00C,0x01E,	/* 071 */
	0x000,0x000,0x0DC,0x076,0x066,0x060,0x0F0,0x000,	/* 072 */
	0x000,0x000,0x07C,0x0C0,0x078,0x00C,0x0F8,0x000,	/* 073 */
	0x010,0x030,0x07C,0x030,0x030,0x034,0x018,0x000,	/* 074 */
	0x000,0x000,0x0CC,0x0CC,0x0CC,0x0CC,0x076,0x000,	/* 075 */
	0x000,0x000,0x0CC,0x0CC,0x0CC,0x078,0x030,0x000,	/* 076 */
	0x000,0x000,0x0C6,0x0D6,0x0FE,0x0FE,0x06C,0x000,	/* 077 */
	0x000,0x000,0x0C6,0x06C,0x038,0x06C,0x0C6,0x000,	/* 078 */
	0x000,0x000,0x0CC,0x0CC,0x0CC,0x07C,0x00C,0x0F8,	/* 079 */
	0x000,0x000,0x0FC,0x098,0x030,0x064,0x0FC,0x000,	/* 07A */
	0x01C,0x030,0x030,0x0E0,0x030,0x030,0x01C,0x000,	/* 07B */
	0x018,0x018,0x018,0x000,0x018,0x018,0x018,0x000,	/* 07C */
	0x0E0,0x030,0x030,0x01C,0x030,0x030,0x0E0,0x000,	/* 07D */
	0x076,0x0DC,0x000,0x000,0x000,0x000,0x000,0x000,	/* 07E */
	0x000,0x010,0x038,0x06C,0x0C6,0x0C6,0x0FE,0x000,	/* 07F */
	0x078,0x0CC,0x0C0,0x0CC,0x078,0x018,0x00C,0x078,	/* 080 */
	0x000,0x066,0x000,0x066,0x066,0x066,0x03F,0x000,	/* 081 */
	0x00E,0x000,0x03C,0x066,0x07E,0x060,0x03C,0x000,	/* 082 */
	0x07E,0x0C3,0x03C,0x006,0x03E,0x066,0x03F,0x000,	/* 083 */
	0x066,0x000,0x03C,0x006,0x03E,0x066,0x03F,0x000,	/* 084 */
	0x070,0x000,0x03C,0x006,0x03E,0x066,0x03F,0x000,	/* 085 */
	0x018,0x018,0x03C,0x006,0x03E,0x066,0x03F,0x000,	/* 086 */
	0x000,0x000,0x03C,0x060,0x060,0x03C,0x006,0x01C,	/* 087 */
	0x07E,0x0C3,0x03C,0x066,0x07E,0x060,0x03C,0x000,	/* 088 */
	0x066,0x000,0x03C,0x066,0x07E,0x060,0x03C,0x000,	/* 089 */
	0x070,0x000,0x03C,0x066,0x07E,0x060,0x03C,0x000,	/* 08A */
	0x066,0x000,0x038,0x018,0x018,0x018,0x03C,0x000,	/* 08B */
	0x07C,0x0C6,0x038,0x018,0x018,0x018,0x03C,0x000,	/* 08C */
	0x070,0x000,0x038,0x018,0x018,0x018,0x03C,0x000,	/* 08D */
	0x063,0x01C,0x036,0x063,0x07F,0x063,0x063,0x000,	/* 08E */
	0x018,0x018,0x000,0x03C,0x066,0x07E,0x066,0x000,	/* 08F */
	0x00E,0x000,0x07E,0x030,0x03C,0x030,0x07E,0x000,	/* 090 */
	0x000,0x000,0x07F,0x00C,0x07F,0x0CC,0x07F,0x000,	/* 091 */
	0x01F,0x036,0x066,0x07F,0x066,0x066,0x067,0x000,	/* 092 */
	0x03C,0x066,0x000,0x03C,0x066,0x066,0x03C,0x000,	/* 093 */
	0x000,0x066,0x000,0x03C,0x066,0x066,0x03C,0x000,	/* 094 */
	0x000,0x070,0x000,0x03C,0x066,0x066,0x03C,0x000,	/* 095 */
	0x03C,0x066,0x000,0x066,0x066,0x066,0x03F,0x000,	/* 096 */
	0x000,0x070,0x000,0x066,0x066,0x066,0x03F,0x000,	/* 097 */
	0x000,0x066,0x000,0x066,0x066,0x03E,0x006,0x07C,	/* 098 */
	0x0C3,0x018,0x03C,0x066,0x066,0x03C,0x018,0x000,	/* 099 */
	0x066,0x000,0x066,0x066,0x066,0x066,0x03C,0x000,	/* 09A */
	0x018,0x018,0x07E,0x0C0,0x0C0,0x07E,0x018,0x018,	/* 09B */
	0x01C,0x036,0x032,0x078,0x030,0x073,0x07E,0x000,	/* 09C */
	0x066,0x066,0x03C,0x07E,0x018,0x07E,0x018,0x018,	/* 09D */
	0x0F8,0x0CC,0x0CC,0x0FA,0x0C6,0x0CF,0x0C6,0x0C7,	/* 09E */
	0x00E,0x01B,0x018,0x03C,0x018,0x018,0x0D8,0x070,	/* 09F */
	0x00E,0x000,0x03C,0x006,0x03E,0x066,0x03F,0x000,	/* 0A0 */
	0x01C,0x000,0x038,0x018,0x018,0x018,0x03C,0x000,	/* 0A1 */
	0x000,0x00E,0x000,0x03C,0x066,0x066,0x03C,0x000,	/* 0A2 */
	0x000,0x00E,0x000,0x066,0x066,0x066,0x03F,0x000,	/* 0A3 */
	0x000,0x07C,0x000,0x07C,0x066,0x066,0x066,0x000,	/* 0A4 */
	0x07E,0x000,0x066,0x076,0x07E,0x06E,0x066,0x000,	/* 0A5 */
	0x03C,0x06C,0x06C,0x03E,0x000,0x07E,0x000,0x000,	/* 0A6 */
	0x038,0x06C,0x06C,0x038,0x000,0x07C,0x000,0x000,	/* 0A7 */
	0x018,0x000,0x018,0x030,0x060,0x066,0x03C,0x000,	/* 0A8 */
	0x000,0x000,0x000,0x07E,0x060,0x060,0x000,0x000,	/* 0A9 */
	0x000,0x000,0x000,0x07E,0x006,0x006,0x000,0x000,	/* 0AA */
	0x0C3,0x0C6,0x0CC,0x0DE,0x033,0x066,0x0CC,0x00F,	/* 0AB */
	0x0C3,0x0C6,0x0CC,0x000,0x037,0x06F,0x0CF,0x003,	/* 0AC */
	0x018,0x018,0x000,0x018,0x018,0x018,0x018,0x000,	/* 0AD */
	0x000,0x033,0x066,0x0CC,0x066,0x033,0x000,0x000,	/* 0AE */
	0x000,0x0CC,0x066,0x033,0x066,0x0CC,0x000,0x000,	/* 0AF */
	0x022,0x088,0x022,0x088,0x022,0x088,0x022,0x088,	/* 0B0 */
	0x055,0x0AA,0x055,0x0AA,0x055,0x0AA,0x055,0x0AA,	/* 0B1 */
	0x000,0x077,0x000,0x0EE,0x000,0x077,0x000,0x0EE,	/* 0B2 */
	0x018,0x018,0x018,0x018,0x018,0x018,0x018,0x018,	/* 0B3 */
	0x018,0x018,0x018,0x018,0x0F8,0x018,0x018,0x018,	/* 0B4 */
	0x018,0x018,0x0F8,0x018,0x0F8,0x018,0x018,0x018,	/* 0B5 */
	0x036,0x036,0x036,0x036,0x0F6,0x036,0x036,0x036,	/* 0B6 */
	0x000,0x000,0x000,0x000,0x0FE,0x036,0x036,0x036,	/* 0B7 */
	0x000,0x000,0x0F8,0x018,0x0F8,0x018,0x018,0x018,	/* 0B8 */
	0x036,0x036,0x0F6,0x006,0x0F6,0x036,0x036,0x036,	/* 0B9 */
	0x036,0x036,0x036,0x036,0x036,0x036,0x036,0x036,	/* 0BA */
	0x000,0x000,0x0FE,0x006,0x0F6,0x036,0x036,0x036,	/* 0BB */
	0x036,0x036,0x0F6,0x006,0x0FE,0x000,0x000,0x000,	/* 0BC */
	0x036,0x036,0x036,0x036,0x0FE,0x000,0x000,0x000,	/* 0BD */
	0x018,0x018,0x0F8,0x018,0x0F8,0x000,0x000,0x000,	/* 0BE */
	0x000,0x000,0x000,0x000,0x0F8,0x018,0x018,0x018,	/* 0BF */
	0x018,0x018,0x018,0x018,0x01F,0x000,0x000,0x000,	/* 0C0 */
	0x018,0x018,0x018,0x018,0x0FF,0x000,0x000,0x000,	/* 0C1 */
	0x000,0x000,0x000,0x000,0x0FF,0x018,0x018,0x018,	/* 0C2 */
	0x018,0x018,0x018,0x018,0x01F,0x018,0x018,0x018,	/* 0C3 */
	0x000,0x000,0x000,0x000,0x0FF,0x000,0x000,0x000,	/* 0C4 */
	0x018,0x018,0x018,0x018,0x0FF,0x018,0x018,0x018,	/* 0C5 */
	0x018,0x018,0x01F,0x018,0x01F,0x018,0x018,0x018,	/* 0C6 */
	0x036,0x036,0x036,0x036,0x037,0x036,0x036,0x036,	/* 0C7 */
	0x036,0x036,0x037,0x030,0x03F,0x000,0x000,0x000,	/* 0C8 */
	0x000,0x000,0x03F,0x030,0x037,0x036,0x036,0x036,	/* 0C9 */
	0x036,0x036,0x0F7,0x000,0x0FF,0x000,0x000,0x000,	/* 0CA */
	0x000,0x000,0x0FF,0x000,0x0F7,0x036,0x036,0x036,	/* 0CB */
	0x036,0x036,0x037,0x030,0x037,0x036,0x036,0x036,	/* 0CC */
	0x000,0x000,0x0FF,0x000,0x0FF,0x000,0x000,0x000,	/* 0CD */
	0x036,0x036,0x0F7,0x000,0x0F7,0x036,0x036,0x036,	/* 0CE */
	0x018,0x018,0x0FF,0x000,0x0FF,0x000,0x000,0x000,	/* 0CF */
	0x036,0x036,0x036,0x036,0x0FF,0x000,0x000,0x000,	/* 0D0 */
	0x000,0x000,0x0FF,0x000,0x0FF,0x018,0x018,0x018,	/* 0D1 */
	0x000,0x000,0x000,0x000,0x0FF,0x036,0x036,0x036,	/* 0D2 */
	0x036,0x036,0x036,0x036,0x03F,0x000,0x000,0x000,	/* 0D3 */
	0x018,0x018,0x01F,0x018,0x01F,0x000,0x000,0x000,	/* 0D4 */
	0x000,0x000,0x01F,0x018,0x01F,0x018,0x018,0x018,	/* 0D5 */
	0x000,0x000,0x000,0x000,0x03F,0x036,0x036,0x036,	/* 0D6 */
	0x036,0x036,0x036,0x036,0x0FF,0x036,0x036,0x036,	/* 0D7 */
	0x018,0x018,0x0FF,0x018,0x0FF,0x018,0x018,0x018,	/* 0D8 */
	0x018,0x018,0x018,0x018,0x0F8,0x000,0x000,0x000,	/* 0D9 */
	0x000,0x000,0x000,0x000,0x01F,0x018,0x018,0x018,	/* 0DA */
	0x0FF,0x0FF,0x0FF,0x0FF,0x0FF,0x0FF,0x0FF,0x0FF,	/* 0 */
	0x000,0x000,0x000,0x000,0x0FF,0x0FF,0x0FF,0x0FF,	/* 0DC */
	0x0F0,0x0F0,0x0F0,0x0F0,0x0F0,0x0F0,0x0F0,0x0F0,	/* 0DD */
	0x00F,0x00F,0x00F,0x00F,0x00F,0x00F,0x00F,0x00F,	/* 0DE */
	0x0FF,0x0FF,0x0FF,0x0FF,0x000,0x000,0x000,0x000,	/* 0DF */
	0x000,0x000,0x03B,0x06E,0x064,0x06E,0x03B,0x000,	/* 0E0 */
	0x000,0x03C,0x066,0x07C,0x066,0x07C,0x060,0x060,	/* 0E1 */
	0x000,0x07E,0x066,0x060,0x060,0x060,0x060,0x000,	/* 0E2 */
	0x000,0x07F,0x036,0x036,0x036,0x036,0x036,0x000,	/* 0E3 */
	0x07E,0x066,0x030,0x018,0x030,0x066,0x07E,0x000,	/* 0E4 */
	0x000,0x000,0x03F,0x06C,0x06C,0x06C,0x038,0x000,	/* 0E5 */
	0x000,0x033,0x033,0x033,0x033,0x03E,0x030,0x060,	/* 0E6 */
	0x000,0x03B,0x06E,0x00C,0x00C,0x00C,0x00C,0x000,	/* 0E7 */
	0x07E,0x018,0x03C,0x066,0x066,0x03C,0x018,0x07E,	/* 0E8 */
	0x01C,0x036,0x063,0x07F,0x063,0x036,0x01C,0x000,	/* 0E9 */
	0x01C,0x036,0x063,0x063,0x036,0x036,0x077,0x000,	/* 0EA */
	0x00E,0x018,0x00C,0x03E,0x066,0x066,0x03C,0x000,	/* 0EB */
	0x000,0x000,0x07E,0x000,0x000,0x07E,0x000,0x000,	/* 0EC */
	0x006,0x00C,0x07E,0x000,0x000,0x07E,0x060,0x0C0,	/* 0ED */
	0x01C,0x060,0x0C0,0x0FC,0x0C0,0x060,0x01C,0x000,	/* 0EE */
	0x03C,0x066,0x066,0x066,0x066,0x066,0x066,0x000,	/* 0EF */
	0x000,0x07E,0x000,0x07E,0x000,0x07E,0x000,0x000,	/* 0F0 */
	0x018,0x018,0x07E,0x018,0x018,0x000,0x07E,0x000,	/* 0F1 */
	0x030,0x018,0x00C,0x018,0x030,0x000,0x07E,0x000,	/* 0F2 */
	0x00C,0x018,0x030,0x018,0x00C,0x000,0x07E,0x000,	/* 0F3 */
	0x00E,0x01B,0x01B,0x018,0x018,0x018,0x018,0x018,	/* 0F4 */
	0x018,0x018,0x018,0x018,0x018,0x0D8,0x0D8,0x070,	/* 0F5 */
	0x018,0x018,0x000,0x07E,0x000,0x018,0x018,0x000,	/* 0F6 */
	0x000,0x076,0x0DC,0x000,0x076,0x0DC,0x000,0x000,	/* 0F7 */
	0x038,0x06C,0x06C,0x038,0x000,0x000,0x000,0x000,	/* 0F8 */
	0x000,0x000,0x000,0x018,0x018,0x000,0x000,0x000,	/* 0F9 */
	0x000,0x000,0x000,0x000,0x018,0x000,0x000,0x000,	/* 0FA */
	0x00F,0x00C,0x00C,0x00C,0x0EC,0x06C,0x03C,0x01C,	/* 0FB */
	0x078,0x06C,0x06C,0x06C,0x06C,0x000,0x000,0x000,	/* 0FC */
	0x070,0x018,0x030,0x060,0x078,0x000,0x000,0x000,	/* 0FD */
	0x000,0x000,0x03C,0x03C,0x03C,0x03C,0x000,0x000,	/* 0FE */
	0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000		/* 0FF */
};

static long y_offset[348] = {
	0x00000,0x02000,0x04000,0x06000,0x0005a,0x0205a,0x0405a,
	0x0605a,0x000b4,0x020b4,0x040b4,0x060b4,0x0010e,0x0210e,
	0x0410e,0x0610e,0x00168,0x02168,0x04168,0x06168,0x001c2,
	0x021c2,0x041c2,0x061c2,0x0021c,0x0221c,0x0421c,0x0621c,
	0x00276,0x02276,0x04276,0x06276,0x002d0,0x022d0,0x042d0,
	0x062d0,0x0032a,0x0232a,0x0432a,0x0632a,0x00384,0x02384,
	0x04384,0x06384,0x003de,0x023de,0x043de,0x063de,0x00438,
	0x02438,0x04438,0x06438,0x00492,0x02492,0x04492,0x06492,
	0x004ec,0x024ec,0x044ec,0x064ec,0x00546,0x02546,0x04546,
	0x06546,0x005a0,0x025a0,0x045a0,0x065a0,0x005fa,0x025fa,
	0x045fa,0x065fa,0x00654,0x02654,0x04654,0x06654,0x006ae,
	0x026ae,0x046ae,0x066ae,0x00708,0x02708,0x04708,0x06708,
	0x00762,0x02762,0x04762,0x06762,0x007bc,0x027bc,0x047bc,
	0x067bc,0x00816,0x02816,0x04816,0x06816,0x00870,0x02870,
	0x04870,0x06870,0x008ca,0x028ca,0x048ca,0x068ca,0x00924,
	0x02924,0x04924,0x06924,0x0097e,0x0297e,0x0497e,0x0697e,
	0x009d8,0x029d8,0x049d8,0x069d8,0x00a32,0x02a32,0x04a32,
	0x06a32,0x00a8c,0x02a8c,0x04a8c,0x06a8c,0x00ae6,0x02ae6,
	0x04ae6,0x06ae6,0x00b40,0x02b40,0x04b40,0x06b40,0x00b9a,
	0x02b9a,0x04b9a,0x06b9a,0x00bf4,0x02bf4,0x04bf4,0x06bf4,
	0x00c4e,0x02c4e,0x04c4e,0x06c4e,0x00ca8,0x02ca8,0x04ca8,
	0x06ca8,0x00d02,0x02d02,0x04d02,0x06d02,0x00d5c,0x02d5c,
	0x04d5c,0x06d5c,0x00db6,0x02db6,0x04db6,0x06db6,0x00e10,
	0x02e10,0x04e10,0x06e10,0x00e6a,0x02e6a,0x04e6a,0x06e6a,
	0x00ec4,0x02ec4,0x04ec4,0x06ec4,0x00f1e,0x02f1e,0x04f1e,
	0x06f1e,0x00f78,0x02f78,0x04f78,0x06f78,0x00fd2,0x02fd2,
	0x04fd2,0x06fd2,0x0102c,0x0302c,0x0502c,0x0702c,0x01086,
	0x03086,0x05086,0x07086,0x010e0,0x030e0,0x050e0,0x070e0,
	0x0113a,0x0313a,0x0513a,0x0713a,0x01194,0x03194,0x05194,
	0x07194,0x011ee,0x031ee,0x051ee,0x071ee,0x01248,0x03248,
	0x05248,0x07248,0x012a2,0x032a2,0x052a2,0x072a2,0x012fc,
	0x032fc,0x052fc,0x072fc,0x01356,0x03356,0x05356,0x07356,
	0x013b0,0x033b0,0x053b0,0x073b0,0x0140a,0x0340a,0x0540a,
	0x0740a,0x01464,0x03464,0x05464,0x07464,0x014be,0x034be,
	0x054be,0x074be,0x01518,0x03518,0x05518,0x07518,0x01572,
	0x03572,0x05572,0x07572,0x015cc,0x035cc,0x055cc,0x075cc,
	0x01626,0x03626,0x05626,0x07626,0x01680,0x03680,0x05680,
	0x07680,0x016da,0x036da,0x056da,0x076da,0x01734,0x03734,
	0x05734,0x07734,0x0178e,0x0378e,0x0578e,0x0778e,0x017e8,
	0x037e8,0x057e8,0x077e8,0x01842,0x03842,0x05842,0x07842,
	0x0189c,0x0389c,0x0589c,0x0789c,0x018f6,0x038f6,0x058f6,
	0x078f6,0x01950,0x03950,0x05950,0x07950,0x019aa,0x039aa,
	0x059aa,0x079aa,0x01a04,0x03a04,0x05a04,0x07a04,0x01a5e,
	0x03a5e,0x05a5e,0x07a5e,0x01ab8,0x03ab8,0x05ab8,0x07ab8,
	0x01b12,0x03b12,0x05b12,0x07b12,0x01b6c,0x03b6c,0x05b6c,
	0x07b6c,0x01bc6,0x03bc6,0x05bc6,0x07bc6,0x01c20,0x03c20,
	0x05c20,0x07c20,0x01c7a,0x03c7a,0x05c7a,0x07c7a,0x01cd4,
	0x03cd4,0x05cd4,0x07cd4,0x01d2e,0x03d2e,0x05d2e,0x07d2e,
	0x01d88,0x03d88,0x05d88,0x07d88,0x01de2,0x03de2,0x05de2,
	0x07de2,0x01e3c,0x03e3c,0x05e3c,0x07e3c
};

slomemset()
{
	long	i;

	for (i = 0xb0000; i < 0xb7fff; i ++)
	{ spbyte(i, 0x00); };
}

int gron()
{
	int	i;
	char	c;
	
	/* Allow page flipping and graphics	*/
	/* Now, set graphics bit		*/
	out(0x3bf, 0x03); out(0x3b8, 0x22);
	/* Now, set up the 6845 */
	for(i=0;i<12;i++)
	{ c = i; out(0x3b4, c); c = param_g[i]; out(0x3b5, c); }
	/* Now, turn display back on */
	out(0x3b8, 0x2b);
	/* Clear memory */
	slomemset();
}

int groff()
{
	int	i;
	char	c;

	out(0x3bf, 0x03); out(0x3b8, 0x20);
	/* Now, set up the 6845 */
	out(0x3b4, 0x3b5);
	for(i=0;i<12;i++)
	{ c = i; out(0x3b4, c); c = param_t[i]; out(0x3b5, c); }
	/* Now, turn display back on */
	slomemset();
}

hg_plot(x,y,c)
int x,y;
char c;
{
	long offset;	/* location in graphics buffer */
	char	p;

	if (x<0 || x>719) return(-1);
	if (y<0 || y>347) return(-1);
 	offset=y_offset[y]+(x>>3);
	if (c == 1)
	{
		p = fpbyte(herc_base+offset);
		p ^= masks[x%8]; spbyte(herc_base+offset, p);
	};
	if (c == 0)
	{
		p = fpbyte(herc_base+offset);
		p &= (~masks[x%8]); spbyte(herc_base+offset, p);
	};
	return(0);
}

hg_plotchar(a,b,v)
int a, b, v;
{
	int i,x,y,index;
	long offset;
	char mask, p;
	
	if (( a < 0) || (a > 89)) { return(-1); };
	if (( b < 0) || (b > 42)) { return(-1); };
	x=a*8; y=b*8;
	index=(int)v*8;
	for (i=0;i<8;i++)
	{
		offset=y_offset[y]+(x>>3);
		p = fpbyte(herc_base+offset); mask=hercchars[index+i];
		p ^= mask; spbyte(herc_base+offset, p); y++;
	};
}

hg_line(x1,y1,x2,y2,c)
int x1,y1,x2,y2,c;
{
	int r, ax,sy,dx,dy,i;
	dx=x2-x1; dy=y2-y1; r=dx/2; ax=1; sy=1;
	if (dx<0)
	{ dx= -dx; ax= -1; }
	if (dy<0)
	{ dy= -dy; sy= -1; }
	if (dx!=0)
		for (i=1;i<=dx;i++)
		{
			if (hg_plot(x1,y1,c) == -1) { return(-1); };
			x1=x1+ax; r+=dy;
			if (r>=dx) { y1+=sy; r=r-dx; }
		}
	else
		for(i=1;i<=dy;i++)	/* straight up and down */
		{
			if (hg_plot(x1,y1,c) == -1) { return(-1); };
			y1+=sy;
		}
}

int	hg_box(x1,y1,x2,y2,c)
int	x1,y1,x2,y2,c;	/* Plot box with corners at x1,y2 and x2,y2 as */
{			/* top left and bottom right corners           */

	int	dx,dy;

	dx = x2 - x1;   
	dy = y2 - y1;	/* Get values for hg_line lengths */
	hg_line(x1,y1,x1+dx,y1,c);		/* Right	*/
	hg_line(x1+dx,y1,x1+dx,y2,c);	/* Down		*/
	hg_line(x1+dx,y2,x1,y2,c);		/* Left		*/
	hg_line(x1,y2,x1,y1,c);		/* Back up	*/
	return(0);
}

hgopen(dev, flags)
int	dev, flags;
{
	if (herc_state) 
	{ u.u_error = EMFILE; return; } else { herc_state = 1; };
	herc_base = 0xb0000; gron(); 
	u.u_error = 0; return;
}

hgclose(dev)
int	dev;
{
	if (!herc_state)
	{ u.u_error = ENXIO; return; };
	groff(); herc_state = 0;
	u.u_error = 0; return;
}

hgwrite(dev)
int	dev;
{
	char	c;
	unsigned int i;
	while ((c = cpass()) != -1)
	{
		herc_machine(c);
	};
	return;
}

/* Convert ascii to int.  Ascii must have ALL three decimal digits!! */
int	getint()
{
	int	i, total;
	char	c;

	total = 0;
	c = cpass();	total += (c - '0') * 100;
	c = cpass();	total += (c - '0') * 10;
	c = cpass();	total += (c - '0');
	return(total);
}

herc_plot()
{
	int	x, y;
	char	c;

	x = getint(); y = getint(); c = cpass();
	switch(c)
	{
		case 'W' : { c = 1; break; };
		case 'E' : { c = 0; break; };
		default  : { c = 0; break; };
	};
	hg_plot(x,y,c);
}

herc_line()
{
	int	x1, y1, x2, y2;
	char	c;

	x1 = getint();	y1 = getint();
	x2 = getint();	y2 = getint();
	c  = cpass();
	switch(c)
	{
		case 'W' : { c = 1; break; };
		case 'E' : { c = 0; break; };
		default  : { c = 0; break; };
	};	
	hg_line(x1, y1, x2, y2, c);
}

herc_box()
{

	int	x1, y1, x2, y2;
	char	c;

	x1 = getint();	y1 = getint();
	x2 = getint();	y2 = getint();
	c  = cpass();
	switch(c)
	{
		case 'W' : { c = 1;  break; };
		case 'E' : { c = 0;  break; };
		default  : { c = 0;  break; };
	};
	hg_box(x1, y1, x2, y2, c);
}

herc_char()
{
	int	x,y,c;

	x = getint();	y = getint();
	c = getint();
	hg_plotchar(x, y, c);
}

herc_str()
{

	int	i, x, y, x1, y1, s;
	char	c;
	
	x = getint();	y = getint();	s = getint();
	x1 = x; 
	y1 = y;
	for (i = 0; i<s; i++)
	{ 
		c = cpass(); hg_plotchar(x1+i, y1, c);
	}
}

herc_machine(c)
char	c;
{
	/* Wheeeeee!  I L O V E writing these things */
	/* For each character, read the command,     */
	/* read any arguments needed and send them   */
	/* out.  We can't detect errors.  We just    */
	/* die a sad death.  No one wants me to put  */
	/* a yacc/lex thing in here do they?         */

	switch(c)
	{
		case 'Z' : { slomemset(); break;		}; 
		case 'P' : { herc_plot(); break;		};
		case 'L' : { herc_line(); break;		};
		case 'B' : { herc_box(); break;			};
		case 'C' : { herc_char(); break;		};
		case 'S' : { herc_str(); break;			};
		default  : { /* Ignore command */		};
	};
}	
@\Rogue\Monster\
else
  echo "shar: Will not over write herc.c"
fi
if `test ! -s test.c`
then
echo "x - test.c"
cat > test.c << '@\Rogue\Monster\'
main()
{
	int	fd, open();

	fd = open("/dev/herc",1);
	write(fd,"S000000006A Line", 16);
	write(fd, "L100100200200W",14);
	sleep(5);
	write(fd,"Z",1);
	write(fd,"S000000004An A", 14);
	write(fd,"C030020065",10);
	sleep(5);
	write(fd,"Z",1);
	write(fd,"S000000005A Box", 15);
	write(fd, "B050050500100W",14);
	sleep(5);
	write(fd,"Z",1);
	write(fd,"S020020017That's All Folks!",27);
	sleep(5);
	close(fd);
}
@\Rogue\Monster\
else
  echo "shar: Will not over write test.c"
fi
# to concatenate archives, remove anything after this line
exit 0
John Antypas -- Soft21 --21st Century Software:

UUCP: {buita|garp|killer|pyramid|reed|sdeggo|ucsd!ucrmath|uport}!soft21!jantypas
Internet: jantypas%soft21.uucp@{garp.MIT.EDU, ucsd.EDU} BITNET: jantypas at ucrvms



More information about the Comp.unix.microport mailing list