home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume18
/
gl_plot
/
part02
< prev
next >
Wrap
Text File
|
1989-03-23
|
35KB
|
1,425 lines
Subject: v18i060: GL Graphics Library for AT-clone Unix, Part02/07
Newsgroups: comp.sources.unix
Sender: sources
Approved: rsalz@uunet.UU.NET
Submitted-by: umix!m-net!dtlewis!lewis
Posting-number: Volume 18, Issue 60
Archive-name: gl_plot/part02
# To recover, type "sh archive"
echo restoring Makefile
sed 's/^X//' > Makefile <<XxX--EOF--XxX
X
X# @(#) Makefile 5.1 89/02/20
X
X# Makefile for UNIX, Xenix, and MS-DOS compiled under Xenix.
X#
X# Edit the config.h file for your system before running make.
X# Uncomment the CFLAGS, LIBS and EXE_SUFFIX defines (below) for your
X# system, by removing the "# " in front of the lines that apply to your
X# system.
X#
X# Run "make" to build the GL library and demo programs.
X# Follow instructions in the INSTALL file before running demos.
X
X# ===> BEGINNING OF USER CONFIGURATIONS <===
X
X# Compiler flags:
X#
X# For Microport 286, use:
XCFLAGS = -Ml -O
X# For Xenix 286, use:
X# (Warning: uSoft optimizer may mess you up; don't use it...)
X# CFLAGS = -Ml -Me
X# For Xenix 286 cross compile to MS-DOS target, use:
X# CFLAGS = -Ml -Me -dos
X
X# Link library flags:
X#
X# For UNIX, use the math library:
XLIBS = -lm
X# For MS-DOS target, no math library needed:
X# LIBS =
X
X# Suffix to stick on the end of the executable program:
X#
X# For UNIX, no suffix:
XEXE_SUFFIX=
X# For MS-DOS target, executables are called *.EXE:
X# EXE_SUFFIX=.exe
X
X# ===> END OF USER CONFIGURATIONS <===
X
XHDR = bitmaps.h cellfont.h config.h font.h graphics.h modes.h gl.h gf_types.h
X
XOBJ = g_clear.o n_mvpen.o n_draw.o n_box.o n_line.o p_wr_pix.o g_init.o n_gfchar.o n_gfstr.o g_finish.o c_cellch.o c_cellst.o c_cursor.o g_pixctl.o n_curves.o n_point.o plot.o g_fntctl.o xform.o trig.o machdep.o g_print.o
X
X# Default make operations, for Microport System V/AT
Xuport: gl.a demo xdemo modeprog
X
X# Make operations for Xenix 286
Xxenix: gl.a demo xdemo
X
X# Make operations for Xenix cross compile to MS-DOS target
Xdos: gl.a demo xdemo
X
Xclean:
X rm \$(OBJ)
X rm mode.o setmode.o
X rm demo.o testpat.o xdemo.o
X
Xclobber:
X rm modeprog demo xdemo gl.a
X rm \$(OBJ)
X rm mode.o setmode.o
X rm demo.o testpat.o xdemo.o
X
Xmodeprog: mode.c setmode.c
X cc -o modeprog\$(EXE_SUFFIX) 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 an Everex
X # Edge, use mode.c (mv modeprog mode). For other adapters, you
X # may have to modify mode.c. A slightly modified version of
X # mode.c may be required for standard hercules graphics.
X #
X # For Xenix 286, use mode.xenix (edit to taste).
X #
X # If you use mode.c, you must make the executable (mode) suid and
X # owned by root. Put it in a safe path, of course.
X # For example, sign as root, then:
X #
X # \$ mv modeprog /usr/bin/mode
X # \$ chmod 4555 /usr/bin/mode
X #
X # Don't forget to create your video shared memory using shmcreate(1)
X # (Microport only). This should be in your /etc/rc.d/shm.rc file.
X #
X # Try running demo and xdemo to see how things work.
X
Xgl.a: \$(OBJ) $(HDR)
X ar rv gl.a \$(OBJ)
X sh -c "if test -x /usr/bin/ranlib -o -x /bin/ranlib;then ranlib gl.a;fi"
X
Xdemo: demo.o testpat.o gl.a
X cc -o demo\$(EXE_SUFFIX) $(CFLAGS) demo.o testpat.o gl.a $(LIBS)
X
Xxdemo: xdemo.o gl.a
X cc -o xdemo\$(EXE_SUFFIX) $(CFLAGS) xdemo.o gl.a $(LIBS)
X
XxX--EOF--XxX
echo restoring g_finish.c
sed 's/^X//' > g_finish.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) g_finish.c 5.1 89/02/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
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 MODULE "g_finish"
X
X#include "config.h"
X#include <stdio.h>
X#if MIX_C
X#else
X#include <sys/types.h>
X#include <string.h>
X#if TCC
X#else
X#include <malloc.h>
X#endif /* TCC */
X#endif /* MIX_C */
X#if MS_DOS
Xextern int g_setmod();
Xextern int g_text;
X#else
X#include <sys/ipc.h>
X#endif /* MS_DOS */
X#if HAS_SIG
X#include <signal.h>
X#endif /* HAS_SIG */
X#include "bitmaps.h"
X#include "graphics.h"
X#include "modes.h"
X
Xextern struct GL_graphics graphics;
Xextern int errno;
Xextern int g_clear();
Xextern char *getenv();
X#if HAS_SIG
Xextern SIG_TYPE (*gl_last_int_handler)();
X#endif /* HAS_SIG */
X
Xstatic FILE *fhandle;
X
Xextern int IBM_send_print();
Xextern int LJ_send_print();
X
Xstatic int open_print()
X{
X char printprog[60];
X char *envptr;
X int istat;
X /* Open a pipe to the print spooler (or straight to printer) */
X
X /* Use the environment variable PLOTDEV if set. */
X
X strcpy(printprog, PRINTPROG);
X strcat(printprog, " ");
X strcat(printprog, LP_DEV_FLAG);
X#if HAS_ENV
X if ((envptr = getenv(GL_PLOT_DEV)) != NULL) {
X strcat(printprog, envptr);
X }
X else {
X strcat(printprog, PRINTDEV);
X }
X#else
X /* Some systems do not understand getenv() */
X strcat(printprog, PRINTDEV);
X#endif /* HAS_ENV */
X
X#if HAS_PIPES /* Pipe to a print spooler program. */
X if ((fhandle = popen(printprog, "w")) == NULL) {
X fprintf(stderr, "%s: Error piping to %s\n", MODULE,printprog);
X return(1);
X }
X#else /* No pipes; write directly to the printer device. */
X#if HAS_STDPRN /* Use predefined value of "stdprn" */
X fhandle = stdprn;
X#else /* Hope that stream I/O works for the printer device */
X if ((fhandle = fopen(DOSPRINTER, "w")) == NULL) {
X fprintf(stderr, "%s: Error opening %s\n", MODULE,DOSPRINTER);
X return(1);
X }
X#endif /* HAS_STDPRN */
X#endif /* HAS_PIPES */
X return(0);
X}
X
Xstatic int close_print()
X{
X int istat;
X#if HAS_PIPES
X if ((istat=pclose(fhandle)) < 0) return(istat);
X#else /* No pipe to close, but close the stream to printer if open */
X#if HAS_STDPRN /* Don't need to do anything -- stdprn stays open */
X#else /* Close the stream pointing at the printer */
X if ((istat=fclose(fhandle)) < 0) return(istat);
X#endif /* HAS_STDPRN */
X#endif /* HAS_PIPES */
X return(0);
X}
X
Xint g_finish()
X{
X int istat;
X
X graphics.initialized = FALSE;
X
X#if HAS_SIG
X#if DO_CLEANUP
X /* Restore the SIGINT signal handler that was in effect prior */
X /* to the call to g_init(). */
X signal(SIGINT, gl_last_int_handler);
X#endif /* DO_CLEANUP */
X#endif /* HAS_SIG */
X
X switch (graphics.grafmode) {
X
X case CGA_HI_RES_MODE:
X /* Erase graphics memory. */
X if (g_clear()) return(1);
X /* Detach the shared memory segment. */
X#if SVAT
X if (shmdt(graphics.cgamem) < 0) return(errno);
X#endif /* SVAT */
X break;
X
X case CGA_COLOR_MODE:
X /* Erase graphics memory. */
X if (g_clear()) return(1);
X /* Detach the shared memory segment. */
X#if SVAT
X if (shmdt(graphics.cgamem) < 0) return(errno);
X#endif /* SVAT */
X break;
X
X case EGA_COLOR_MODE:
X /* Erase graphics memory. */
X if (g_clear()) return(1);
X /* Detach the shared memory segment. */
X#if SVAT
X if (shmdt(graphics.egamem) < 0) return(errno);
X#endif /* SVAT */
X break;
X
X case HERC_P0_MODE:
X case HERC_P1_MODE:
X /* Erase graphics memory. */
X if (g_clear()) return(1);
X /* Detach the shared memory segment. */
X#if SVAT
X if (shmdt(graphics.hercmem) < 0) return(errno);
X#endif /* SVAT */
X break;
X
X case IBM_PRINTER:
X
X /* Print the buffer */
X if ((istat=open_print()) !=0) return(istat);
X if ((istat=IBM_send_print(fhandle)) !=0) return(istat);
X if ((istat=close_print()) !=0) return(istat);
X
X /* Free the allocated memory. */
X free(graphics.printbuf1);
X free(graphics.printbuf2);
X free(graphics.printbuf3);
X
X break;
X
X case LJ_PRINTER:
X
X /* Print the buffer */
X if ((istat=open_print()) !=0) return(istat);
X if ((istat=LJ_send_print(fhandle)) !=0) return(istat);
X if ((istat=close_print()) !=0) return(istat);
X
X /* Free the allocated memory. */
X free(graphics.lj_buf1);
X free(graphics.lj_buf2);
X free(graphics.lj_buf3);
X
X break;
X
X default:
X return(1);
X }
X
X /* Tell the hardware to go back to default (text) mode, using */
X /* the MODEPROG program. The default action of the mode */
X /* program is assumed to be text mode. */
X
X if (graphics.grafmode <= MAXVIDEO) {
X#if MS_DOS
X g_setmod(g_text);
X#else
X system(MODEPROG);
X#endif /* MS_DOS */
X }
X
X return(0);
X}
X
X
XxX--EOF--XxX
echo restoring g_print.c
sed 's/^X//' > g_print.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) g_print.c 5.1 89/02/20";
X#endif
X
X/*
X * Copyright (c) David T. Lewis 1987, 1988, 1989
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/* Sat Feb 18 15:54:14 EST 1989 */
X/* Printer specific code. */
X
X#include <stdio.h>
X#include "config.h"
X#if MS_DOS
X#include <stdlib.h>
X#endif /* MS_DOS */
X#if XENIX_286
X#include <sys/fcntl.h>
X#include <sys/machdep.h>
X#include <sys/sysmacros.h>
X#endif /* XENIX_286 */
X#include "bitmaps.h"
X#include "gf_types.h"
X#include "graphics.h"
X#include "modes.h"
X
X/* Use BIOS output for printer on MS-DOS. */
X#if MS_DOS
Xextern int bios_print();
X#define FWRITE(a,b,c,d) bios_print(a,b,c)
X#else
X#define FWRITE(a,b,c,d) fwrite(a,b,c,d)
X#endif /* MS_DOS */
X
Xextern struct GL_graphics graphics;
X
X#define FORM_FEED (014)
X
X#define EPSON_START_GRAPHICS 033, 'A', 07, 033, 02
X#define IBM_START_GRAPHICS 033, '1'
X#define IBM_PAGE_END 033, 'A', 014, 033, 02
X#define IBM_LINE_START 033, 'L', 0300, 03
X#define IBM_LINE_END 015, 012
X
Xstatic char IBM_pg_top[] = {EPSON_START_GRAPHICS, IBM_START_GRAPHICS};
Xstatic char IBM_pg_end[] = {IBM_PAGE_END};
Xstatic char IBM_pg_ff_end[] = {IBM_PAGE_END, FORM_FEED};
Xstatic char IBM_ln_start[] = {IBM_LINE_START};
Xstatic char IBM_ln_end[] = {IBM_LINE_END};
X
X#define LJ_RESET 033, 'E'
X#define LJ_150_DPI 033, '*', 't', '1', '5', '0', 'R' /* 150 dpi graphics */
X#define LJ_CUR_HOME 033, '&', 'a', '3', 'C' /* Cursor to column 3 */
X#define LJ_START_GRAPHICS 033, '*', 'r', '1', 'A'
X#define LJ_XFER_GRAPHICS 033, '*', 'b', '1', '4', '0', 'W' /* 140 bytes */
X#define LJ_END_GRAPHICS 033, '*', 'r', 'B'
X
Xstatic char LJ_pg_top[]={LJ_RESET, LJ_150_DPI, LJ_CUR_HOME, LJ_START_GRAPHICS};
Xstatic char LJ_pg_end[] = {LJ_END_GRAPHICS, LJ_RESET};
Xstatic char LJ_pg_ff_end[] = {LJ_END_GRAPHICS, LJ_RESET};
Xstatic char LJ_ln_start[] = {LJ_XFER_GRAPHICS};
Xstatic char LJ_ln_end[] = {0}; /* No line end needed */
X
X/* A do-nothing function. The printer function pointers will initially */
X/* point to this, just to avoid core dumps later on. */
X
Xstatic int null_function(fp)
XFILE *fp;
X{
X return(0);
X}
X
X/* For printers, the following four functions send data required to */
X/* start the print, end the print, start each line, and end each line. */
X/* These function pointers are defined globally here, and are used to */
X/* send data to printers in g_finish(). These are initialized to a */
X/* safe value now, and set to the appropriate values for the current */
X/* graphics mode later in g_init(). */
X
Xint (*pr_head)() = null_function;
Xint (*pr_tail)() = null_function;
Xint (*pr_lnst)() = null_function;
Xint (*pr_lnend)() = null_function;
X
X/* Following is the device specific code for each printer (sorry, there */
X/* is only one working so far, but I like to plan ahead). */
X
X/* Start of IBM or Epson compatible dot matrix printer code. */
X
Xint IBM_head(fp)
XFILE *fp;
X{
X /* Begin graphics mode; set line spacing */
X if((FWRITE(IBM_pg_top,sizeof(char),sizeof(IBM_pg_top),fp)) <
X sizeof(IBM_pg_top)) return(1);
X else return(0);
X}
X
Xint IBM_tail(fp)
XFILE *fp;
X{
X /* End of page, begin text mode */
X#if HAS_PIPES
X if((FWRITE(IBM_pg_end,sizeof(char),sizeof(IBM_pg_end),fp)) <
X sizeof(IBM_pg_end)) return(1);
X else return(0);
X#else
X /* If we are not piping to a print spooler program, then we */
X /* need to supply our own form feed command. */
X if((FWRITE(IBM_pg_ff_end,sizeof(char),sizeof(IBM_pg_ff_end),fp)) <
X sizeof(IBM_pg_ff_end)) return(1);
X else return(0);
X#endif /* HAS_PIPES */
X}
X
Xint IBM_lnst(fp)
XFILE *fp;
X{
X /* Start a line of graphics data */
X if((FWRITE(IBM_ln_start,sizeof(char),sizeof(IBM_ln_start),fp)) <
X sizeof(IBM_ln_start)) return(1);
X else return(0);
X}
X
Xint IBM_lnend(fp)
XFILE *fp;
X{
X /* End line of graphics data */
X if((FWRITE(IBM_ln_end,sizeof(char),sizeof(IBM_ln_end),fp)) <
X sizeof(IBM_ln_end)) return(1);
X else return(0);
X}
X
Xint IBM_send_print(fp)
XFILE *fp;
X#define MODULE "IBM_send_print"
X{
X int idx;
X
X /* Dump the print image to the file */
X
X /* Set line feed pitch for graphics */
X
X (*pr_head)(fp);
X
X /* Write the lines of data (3 buffers full) */
X for (idx=0; idx<PRINTLINES; idx++) {
X (*pr_lnst)(fp);
X FWRITE(&(graphics.printbuf1->buf[idx][0]),
X sizeof(char), PRINTDENSITY, fp);
X (*pr_lnend)(fp);
X }
X for (idx=0; idx<PRINTLINES; idx++) {
X (*pr_lnst)(fp);
X FWRITE(&(graphics.printbuf2->buf[idx][0]),
X sizeof(char), PRINTDENSITY, fp);
X (*pr_lnend)(fp);
X }
X for (idx=0; idx<PRINTLINES; idx++) {
X (*pr_lnst)(fp);
X FWRITE(&(graphics.printbuf3->buf[idx][0]),
X sizeof(char), PRINTDENSITY, fp);
X (*pr_lnend)(fp);
X }
X
X /* Set line feed pitch back for text */
X
X if ((*pr_tail)(fp)) {
X fprintf(stderr,"%s: unable to write to printer\n",MODULE);
X return(1);
X }
X return(0);
X}
X
X/* End of IBM or Epson compatible dot matrix printer code. */
X
X
X/* Start of Laserjet+ printer code. */
X
Xint LJ_head(fp)
XFILE *fp;
X{
X /* Begin graphics mode; set line spacing */
X if((FWRITE(LJ_pg_top,sizeof(char),sizeof(LJ_pg_top),fp)) <
X sizeof(LJ_pg_top)) return(1);
X else return(0);
X}
X
Xint LJ_tail(fp)
XFILE *fp;
X{
X /* End of page, reset and eject page */
X if((FWRITE(LJ_pg_end,sizeof(char),sizeof(LJ_pg_end),fp)) <
X sizeof(LJ_pg_end)) return(1);
X else return(0);
X}
X
Xint LJ_lnst(fp)
XFILE *fp;
X{
X /* Start a line of graphics data */
X if((FWRITE(LJ_ln_start,sizeof(char),sizeof(LJ_ln_start),fp)) <
X sizeof(LJ_ln_start)) return(1);
X else return(0);
X}
X
Xint LJ_lnend(fp)
XFILE *fp;
X{
X /* End line of graphics data */
X return(0);
X}
X
Xint LJ_send_print(fp)
XFILE *fp;
X#undef MODULE
X#define MODULE "LJ_send_print"
X{
X int idx;
X
X /* Dump the print image to the file */
X
X /* Start page of graphics */
X
X (*pr_head)(fp);
X
X /* Write the lines of data (3 buffers full) */
X for (idx=0; idx<LJ_LINES; idx++) {
X (*pr_lnst)(fp);
X FWRITE(&(graphics.lj_buf1->buf[idx][0]),
X sizeof(char), LJ_BYTES_PER_LINE, fp);
X (*pr_lnend)(fp);
X }
X for (idx=0; idx<LJ_LINES; idx++) {
X (*pr_lnst)(fp);
X FWRITE(&(graphics.lj_buf2->buf[idx][0]),
X sizeof(char), LJ_BYTES_PER_LINE, fp);
X (*pr_lnend)(fp);
X }
X for (idx=0; idx<LJ_LINES; idx++) {
X (*pr_lnst)(fp);
X FWRITE(&(graphics.lj_buf3->buf[idx][0]),
X sizeof(char), LJ_BYTES_PER_LINE, fp);
X (*pr_lnend)(fp);
X }
X
X /* End of page */
X
X if ((*pr_tail)(fp)) {
X fprintf(stderr,"%s: unable to write to printer\n",MODULE);
X return(1);
X }
X return(0);
X}
X
X/* End of Laserjet+ printer code. */
X
X
XxX--EOF--XxX
echo restoring mode.c
sed 's/^X//' > mode.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) mode.c 5.1 89/02/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/* 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#include "config.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 if (sscanf(argv[1],"%d",&modevalue) != 1) {
X printf("Unknown mode %s\n",argv[1]);
X exit(1);
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 msc.mak
sed 's/^X//' > msc.mak <<XxX--EOF--XxX
X
X# @(#) msc.mak 5.1 89/02/20
X
X# Makefile for MS-DOS with Microsoft C and the Microsoft "make" utility.
X# Use the command "make msc.mak" to build the system.
X#
X# Edit the config.h file for your system before running make.
X# Run "make" to build the GL library and demo programs.
X# Follow instructions in the INSTALL file before running demos.
X
XCC = msc
X# Note: Do NOT use the optimizer! You must compile with the "/Od" switch.
XCFLAGS = /AL /Od
XLIB = lib
X
XHDR = bitmaps.h cellfont.h config.h font.h graphics.h modes.h gl.h gf_types.h
X
XOBJ1= g_clear.obj n_mvpen.obj n_draw.obj n_box.obj n_line.obj p_wr_pix.obj
XOBJ2= n_gfchar.obj n_gfstr.obj g_finish.obj c_cellch.obj c_cellst.obj
XOBJ3= c_cursor.obj g_pixctl.obj n_curves.obj n_point.obj plot.obj g_fntctl.obj
XOBJ4= xform.obj trig.obj machdep.obj g_init.obj g_print.obj
X
X.c.obj:
X \$(CC) $(CFLAGS) $*.c;
X \$(LIB) gl.lib -+$*.obj;
X
Xgl.lib: \$(OBJ1) $(OBJ2) $(OBJ3) $(OBJ4) $(HDR)
X \$(LIB) gl.lib;
X
Xdemo.obj: demo.c \$(HDR)
X \$(CC) $(CFLAGS) $*.c;
X
Xtestpat.obj: testpat.c \$(HDR)
X \$(CC) $(CFLAGS) $*.c;
X
Xxdemo.obj: xdemo.c \$(HDR)
X \$(CC) $(CFLAGS) $*.c;
X
Xg_clear.obj: g_clear.c \$(HDR)
X
Xn_mvpen.obj: n_mvpen.c \$(HDR)
X
Xn_draw.obj: n_draw.c \$(HDR)
X
Xn_box.obj: n_box.c \$(HDR)
X
Xn_line.obj: n_line.c \$(HDR)
X
Xp_wr_pix.obj: p_wr_pix.c \$(HDR)
X
Xn_gfchar.obj: n_gfchar.c \$(HDR)
X
Xn_gfstr.obj: n_gfstr.c \$(HDR)
X
Xg_finish.obj: g_finish.c \$(HDR)
X
Xc_cellch.obj: c_cellch.c \$(HDR)
X
Xc_cellst.obj: c_cellst.c \$(HDR)
X
Xc_cursor.obj: c_cursor.c \$(HDR)
X
Xg_pixctl.obj: g_pixctl.c \$(HDR)
X
Xn_curves.obj: n_curves.c \$(HDR)
X
Xn_point.obj: n_point.c \$(HDR)
X
Xplot.obj: plot.c \$(HDR)
X
Xg_fntctl.obj: g_fntctl.c \$(HDR)
X
Xxform.obj: xform.c \$(HDR)
X
Xtrig.obj: trig.c \$(HDR)
X
Xmachdep.obj: machdep.c \$(HDR)
X
Xg_print.obj: g_print.c \$(HDR)
X
Xg_init.obj: g_init.c \$(HDR)
X
Xdemo.exe: demo.obj testpat.obj gl.lib
X link demo.obj testpat.obj,demo.exe,,gl.lib;
X
Xxdemo.exe: demo.obj testpat.obj gl.lib
X link xdemo.obj ,xdemo.exe,,gl.lib;
X
X
XxX--EOF--XxX
echo restoring n_mvpen.c
sed 's/^X//' > n_mvpen.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) n_mvpen.c 5.1 89/02/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/* 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 "config.h"
X#include "bitmaps.h"
X#include "graphics.h"
X
Xextern struct GL_graphics graphics;
X
Xint n_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
X /* Check for x or y off the screen. */
X#if INT16
X /* 16 bit integers, use simple check. */
X if ((graphics.x_cursor = x) < 0 ) return(1);
X if ((graphics.y_cursor = y) < 0 ) return(1);
X#else
X /* Use explicit check. */
X if (((graphics.x_cursor = x) < 0) || (x > NRM_X_RANGE)) return(1);
X if (((graphics.y_cursor = y) < 0) || (y > NRM_X_RANGE)) return(1);
X#endif /* INT16 */
X
X return(0);
X}
XxX--EOF--XxX
echo restoring p_wr_pix.c
sed 's/^X//' > p_wr_pix.c <<XxX--EOF--XxX
X#ifndef lint
Xstatic char sccsid[] = "@(#) p_wr_pix.c 5.1 89/02/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#include "config.h"
X#include "bitmaps.h"
X#include "gf_types.h"
X#include "graphics.h"
X#include "modes.h"
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 * This routine writes a pixel dot at (x,y), where x and y are
X * pixel coordinates. Operates on bit maps defined in bitmaps.h,
X * and works for video adapter boards (direct write to screen
X * memory) or printers (write to a bitmap allocated in main memory).
X */
X
Xextern struct GL_graphics graphics;
X
Xint p_wr_pix(x,y)
X int x, y;
X{
X
Xint row, col, page;
Xunsigned char bitmask;
Xregister char shiftcount;
X
X/* If this is MIX-C, we have small memory model only, and we can't get */
X/* a 32 bit pointer to the screen. Therefore, cheat and use the BIOS. */
X#if MIX_C
Xwritedot(y, x, graphics.color);
Xreturn (0);
X#endif /* MIX_C */
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_P0_MODE:
X case HERC_P1_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
X case LJ_PRINTER:
X
X col = LJ_BYTES_PER_LINE - (y >> 3) - 1;
X row = x;
X page = 0;
X while (row >= LJ_LINES) {
X row -= LJ_LINES;
X ++page;
X }
X
X bitmask = 0x01 << (y & 0x0007);
X
X switch (page) {
X
X case 0: /* Page 0 */
X switch (graphics.wrt_mode) {
X case OR:
X (graphics.lj_buf1)
X ->buf[row][col]
X |= bitmask;
X break;
X case XOR:
X (graphics.lj_buf1)
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.lj_buf2)
X ->buf[row][col]
X |= bitmask;
X break;
X case XOR:
X (graphics.lj_buf2)
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.lj_buf3)
X ->buf[row][col]
X |= bitmask;
X break;
X case XOR:
X (graphics.lj_buf3)
X ->buf[row][col]
X ^= bitmask;
X break;
X }
X break;
X }
X break;
X
X default:
X return(1);
X }
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 5.1 89/02/20";
X#endif
X#define MS_DOS 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*/ 0x36, 0x2d, 0x2e, 0x07, 0x5a, 0x02, 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, 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
X for(i = mode*16, j = 0; j < 16; i++, j++) {
X outb(bport, j); /* 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 MS_DOS
Xoutb(portno, data)
Xint portno;
Xint data;
X{
X outp(portno,data);
X}
X#endif
X
XxX--EOF--XxX
echo restoring tcc.mak
sed 's/^X//' > tcc.mak <<XxX--EOF--XxX
X
X# @(#) tcc.mak 5.1 89/02/20
X
X# Makefile for MS-DOS with Borland Turbo-C and the Borland "make" utility.
X# Use the command "make -ftcc.mak" to build the system.
X#
X# Edit the config.h file for your system before running make.
X# Run "make" to build the GL library and demo programs.
X# Follow instructions in the INSTALL file before running demos.
X
XCC = tcc
XCFLAGS = -c -ml
XLFLAGS = -ml
XPATHS = -I\TC\INCLUDE -L\TC\LIB
XLIB = tlib
XLINK = tlink
X
XHDR = bitmaps.h cellfont.h config.h font.h graphics.h modes.h gl.h gf_types.h
X
XOBJ1= g_clear.obj n_mvpen.obj n_draw.obj n_box.obj n_line.obj p_wr_pix.obj
XOBJ2= n_gfchar.obj n_gfstr.obj g_finish.obj c_cellch.obj c_cellst.obj
XOBJ3= c_cursor.obj g_pixctl.obj n_curves.obj n_point.obj plot.obj g_fntctl.obj
XOBJ4= xform.obj trig.obj machdep.obj g_init.obj g_print.obj
X
Xall: demo.exe xdemo.exe
X
X.c.obj:
X \$(CC) $(CFLAGS) $(PATHS) $*.c
X \$(LIB) gl.lib -+$*.obj
X
Xgl.lib: \$(OBJ1) $(OBJ2) $(OBJ3) $(OBJ4) $(HDR)
X \$(LIB) gl.lib
X
Xdemo.obj: demo.c \$(HDR)
X \$(CC) $(CFLAGS) $(PATHS) $*.c
X
Xtestpat.obj: testpat.c \$(HDR)
X \$(CC) $(CFLAGS) $(PATHS) $*.c
X
Xxdemo.obj: xdemo.c \$(HDR)
X \$(CC) $(CFLAGS) $(PATHS) $*.c
X
Xg_clear.obj: g_clear.c \$(HDR)
X
Xn_mvpen.obj: n_mvpen.c \$(HDR)
X
Xn_draw.obj: n_draw.c \$(HDR)
X
Xn_box.obj: n_box.c \$(HDR)
X
Xn_line.obj: n_line.c \$(HDR)
X
Xp_wr_pix.obj: p_wr_pix.c \$(HDR)
X
Xn_gfchar.obj: n_gfchar.c \$(HDR)
X
Xn_gfstr.obj: n_gfstr.c \$(HDR)
X
Xg_finish.obj: g_finish.c \$(HDR)
X
Xc_cellch.obj: c_cellch.c \$(HDR)
X
Xc_cellst.obj: c_cellst.c \$(HDR)
X
Xc_cursor.obj: c_cursor.c \$(HDR)
X
Xg_pixctl.obj: g_pixctl.c \$(HDR)
X
Xn_curves.obj: n_curves.c \$(HDR)
X
Xn_point.obj: n_point.c \$(HDR)
X
Xplot.obj: plot.c \$(HDR)
X
Xg_fntctl.obj: g_fntctl.c \$(HDR)
X
Xxform.obj: xform.c \$(HDR)
X
Xtrig.obj: trig.c \$(HDR)
X
Xmachdep.obj: machdep.c \$(HDR)
X
Xg_print.obj: g_print.c \$(HDR)
X
Xg_init.obj: g_init.c \$(HDR)
X
Xdemo.exe: demo.obj testpat.obj gl.lib
X \$(CC) $(LFLAGS) $(PATHS) demo.obj testpat.obj gl.lib
X
Xxdemo.exe: xdemo.obj testpat.obj gl.lib
X \$(CC) $(LFLAGS) $(PATHS) xdemo.obj gl.lib
X
XxX--EOF--XxX