/* * * rgep.c by Aaron Contorer for NCSA * * graphics routines for drawing on Epson printer * Input coordinate space = 0..4095 by 0..4095 * MUST BE COMPILED WITH LARGE MEMORY MODEL! * */ #include /* used for debugging only */ #include #ifdef MSC #ifdef __TURBOC__ #include #else #include #endif #endif #include "externs.h" #define TRUE 1 #define FALSE 0 #define INXMAX 4096 #define INYMAX 4096 #define SCRNXHI 719 #define ROWS 90 #define SCRNYHI 929 #define LINEBYTE 930 #define MAXRW 1 /* max. number of real windows */ static int EPSactive; /* number of currently active window */ static unsigned char EPSpbit[SCRNXHI+1]; #ifdef OLD_WAY static unsigned char power2[8]={1,2,4,8,16,32,64,128}; #endif static char *EPSname="Epson, IBM, or compatible printer"; static int EPSxmax=720; static int EPSymax=LINEBYTE; #ifdef OLD_WAY static int EPSbytes=80; /* number of bytes per line */ #endif static unsigned char *EPSram[ROWS]; static void (*EPSoutfunc)(char c); static void signore(char c); static void EPSpoint(int x,int y); static void EPSdump(void ); static void EPSsetup(void ); /* Current status of an EPS window */ struct EPSWIN { char inuse; /* true if window in use */ int pencolor, rotation, size; int winbot,winleft,wintall,winwide; /* position of the window in virtual space */ }; static struct EPSWIN EPSwins[MAXRW]; /* prepare variables for use in other functions */ static void EPSsetup(void ) { int x; EPSpbit[0]=128; EPSpbit[1]=64; EPSpbit[2]=32; EPSpbit[3]=16; EPSpbit[4]=8; EPSpbit[5]=4; EPSpbit[6]=2; EPSpbit[7]=1; for(x=8; x<=SCRNXHI; x++) EPSpbit[x]=EPSpbit[x&7]; } /* go into EPS graphics mode */ void RGEPgmode(void ) { } /* go into EPS text mode */ void RGEPtmode(void ) { } /* Clear the screen. */ void RGEPclrscr(int w) { if(w==EPSactive) EPSsetup(); } /* Set up a new window; return its number. Returns -1 if cannot create window. */ int RGEPnewwin(void ) { int w=0; int x,y; for(x=0; x=0; x--) free(EPSram[x]); return(-1); } /* end if */ for(y=0; y>3])[y]|=EPSpbit[x]; } /* draw a line from (x0,y0) to (x1,y1) */ /* uses Bresenham's Line Algorithm */ void RGEPdrawline(int w,int x0,int y0,int x1,int y1) { int x,y,dx,dy,d,temp, dx2,dy2, /* 2dx and 2dy */ direction; /* +1 or -1, used for slope */ char transpose; /* true if switching x and y for vertical-ish line */ if(w!=EPSactive) return; x0=(int)((long)x0*EPSxmax/INXMAX); y0=(int)((long)y0*EPSymax/INYMAX); x1=(int)((long)x1*EPSxmax/INXMAX); y1=(int)((long)y1*EPSymax/INYMAX); if(abs(y1-y0)>abs(x1-x0)) { /* transpose vertical-ish to horizontal-ish */ temp=x1; x1=y1; y1=temp; temp=x0; x0=y0; y0=temp; transpose=TRUE; } else transpose=FALSE; /* make sure line is left to right */ if(x1 1 POINT */ x=x0; y=y0; dx=x1-x0; if(y1>=y0) { dy=y1-y0; direction=1; } else { dy=y0-y1; direction=-1; } dx2=dx<<1; dy2=dy<<1; d=(dy<<1)-dx; if(transpose) { /* CASE OF VERTICALISH (TRANSPOSED) LINES */ while(x<=x1) { if(y>=0&&y=0&&x=0) { y+=direction; d-=dx2; } d+=dy2; x++; } } else { /* CASE OF HORIZONTALISH LINES */ while(x<=x1) { if(x>=0&&x=0&&y=0){ y+=direction; d-=dx2; } d+=dy2; x++; } } /* end horizontalish */ } /* end RGEPdrawline() */ /* Ring bell in window w */ void RGEPbell(int w) { w=w; } /* return name of device that this RG supports */ char *RGEPdevname(void ) { return(EPSname); } /* Ignore the character pointer passed here. */ static void signore(char s) { s=s; } /* initialize all RGEP variables */ void RGEPinit(void ) { int i; EPSsetup(); for(i=0; i>8)); /* send a line of bit image data */ for(y=0; y