Subject: v18i061: GL Graphics Library for AT-clone Unix, Part03/07 Newsgroups: comp.sources.unix Sender: sources Approved: rsalz@uunet.UU.NET Submitted-by: umix!m-net!dtlewis!lewis Posting-number: Volume 18, Issue 61 Archive-name: gl_plot/part03 # To recover, type "sh archive" echo restoring bitmaps.h sed 's/^X//' > bitmaps.h < cellfont.h < g_pixctl.c < graphics.h < machdep.c < X#include "config.h" X#include "bitmaps.h" X#include "gf_types.h" X#include "graphics.h" X#if MIX_C X#include X#else X#include X#include X#if MS_DOS X#include X#endif /* MS_DOS */ X#endif /* MIX_C */ X X#ifndef M_PI X#define M_PI 3.14159265358979323846 X#endif /* M_PI */ X X#define PTR_OK_STAT (0x90) X#define BIOS_PTR_INT (0x17) X#define DOS_KBY_STAT 0x0b X Xextern struct GL_graphics graphics; X X#if MS_DOS Xstatic REGISTERS inreg, outreg; X#endif /* MS_DOS */ X X/* The next two routines can take the place of macros defined in */ X/* graphics.h, for compilers that can't use them. */ X X#if N_TO_P_MACRO X#else X Xint n_to_p_x(x) Xint x; X{ X long lval; X lval = x; X lval *= graphics.x_extent; X lval /= NRM_X_RANGE; X return (lval); X} X Xint n_to_p_y(y) Xint y; X{ X long lval; X lval = y; X lval *= graphics.y_extent; X lval /= NRM_Y_RANGE; X return (lval); X} X#endif /* N_TO_P_MACRO */ X X#if HAS_FMOD X#else X/* fmod(3M) replacement for MIX-C compiler, MS-DOS. */ X Xdouble fmod(x,y) Xdouble x, y; X{ X /* x = i*y + f for some value i such that |f| < |y|. */ X /* Solve for f. */ X X long lval; X double dval; X X /* Check for zero or overflow */ X if (x == 0L || y == 0L) return(0L); X X dval = x / y; X lval = (long)dval; X return (x - (double)lval * y); X} X#endif /* HAS_FMOD */ X X#if HAS_ATAN2 X#else X/* atan2(3M) replacement for MIX-C compiler, MS-DOS. */ X/* Returns arctan of y/x. */ X Xdouble atan2(y,x) Xdouble y, x; X{ X if (x>=0) { X /* atan() works fine when angle is in */ X /* 1st or 4th quadrant. */ X return (atan (y/x)); X } X else { X if (y<0) { X /* 3rd quadrant */ X return ( -(M_PI - atan (y/x))); X } X else { X /* 2nd quadrant */ X return (M_PI - atan (y/x)); X } X } X} X#endif /* HAS_ATAN2 */ X X#if HAS_SLEEP X#else X/* Replacement for the sleep() function (for some MS-DOS compilers). */ X Xint sleep(seconds) Xint seconds; X{ X/* It's OK for this to be inefficient, since we are only wasting */ X/* time anyhow. Therefore, use the DOS call rather than BIOS. That */ X/* way, we don't screw up the DOS system clock if we call BIOS at */ X/* midnight. */ X#define TICKS_PER_SEC 18.2 X#define A_BIG_NUMBER 360000 X long time_to_return; X long now; X /* Get the current time using DOS function 0x2c */ X inreg.AH = DOS_GET_TIME; X DO_BIOS(DOS, &inreg, &outreg); X time_to_return = outreg.DL /* Hundredths */ X + (outreg.DH * 100) /* Seconds */ X + (outreg.CL * 6000) /* Minutes */ X + (outreg.CH * 360000) /* Hours */ X + (seconds * 100); /* Add delay time */ X now = 0L; X while (now < time_to_return) { X /* Check the time until done. */ X inreg.AH = DOS_GET_TIME; X DO_BIOS(DOS, &inreg, &outreg); X now = outreg.DL /* Hundredths */ X + (outreg.DH * 100) /* Seconds */ X + (outreg.CL * 6000) /* Minutes */ X + (outreg.CH * 360000); /* Hours */ X /* Check for rollover at midnight */ X if ((time_to_return - now) > A_BIG_NUMBER) { X /* Subtract 24 hours */ X time_to_return -= 360000 * 24; X } X } X return (0); X} X X#endif /* HAS_SLEEP */ X X#if MS_DOS X/* Routines to get and set video modes for MS-DOS. See the defines in */ X/* config.h to understand how the register assignments work. */ X Xint g_setmod(mode) Xint mode; X{ X /* BIOS interrupt 0x10 function 0 */ X inreg.AH = SET_VIDEO_MODE; X inreg.AL = mode; /* Video mode */ X DO_BIOS(VIDEO_BIOS, &inreg, &outreg); X return (0); X} X Xint g_getmod() X{ X /* BIOS interrupt 0x10 function 0x0f */ X inreg.AH = GET_VIDEO_MODE; X DO_BIOS(VIDEO_BIOS, &inreg, &outreg); X return (outreg.AL); X} X Xint bios_print(buffer, itemsize, no_of_items) Xchar *buffer; Xint itemsize; Xint no_of_items; X{ X int idx, jdx; X int pstat = 0; X int size = itemsize * no_of_items; X for (idx=0 ;idx < size; idx++) X { X /* Wait for printer ready status */ X for (jdx = 0, pstat = -1; pstat != PTR_OK_STAT; jdx++) X { X inreg.AH = 2; X DO_BIOS(BIOS_PTR_INT, &inreg, &outreg); X pstat = (0xf8) & (outreg.AH); X if (jdx > 30000) X { X fprintf(stderr,"Timeout on printer device\n",0); X return(0); X } X } X X /* Send a byte */ X inreg.AH = 0; X inreg.AL = buffer[idx]; X DO_BIOS(BIOS_PTR_INT, &inreg, &outreg); X X /* Call to get keyboard status, so DOS can check for */ X /* interrupt signal (^C). */ X inreg.AH = DOS_KBY_STAT; X DO_BIOS(DOS, &inreg, &outreg); X } X return(no_of_items); X} X X#endif /* MS_DOS */ X X XxX--EOF--XxX