#ident "@(#)VOGLE:driver/hpgt.c - VOGLE driver for HP Graphics Terminals"
#ident "@(#)VOGLE:author - John S. Urban"
#ident "@(#)VOGLE:version - 1.0, Mar 1999"
/*
#define BSD 1
*/
#include
#ifdef BSD
#include
#else
#include
#endif
#include "vogle.h"
#define HPGT_X_SIZE 640
#define HPGT_Y_SIZE 400
#include
static int click, tlstx, tlsty;
extern FILE *fp;
extern FILE *_voutfile();
/*
* HPGT_init
*
* set up the graphics mode.
*/
HPGT_init()
{
/*
* Find out if we are mono or colour.
* and what our resolution currently is.
*/
/*
char buf[128];
*/
int i, b1, b2, b3, llx=0, lly=0, urx=0, ury=0;
click = 0;
fp = _voutfile();
/*
fprintf(fp, "\033*s5^");
fgets(buf, 128, stdin);
sscanf(buf, "%d,%d,%d,%d\n", &llx, &lly, &urx, &ury);
vdevice.depth = 1;
fprintf(fp, "\033*s6^");
fgets(buf, 128, stdin);
sscanf(buf, "%d,%d,%d", &b1, &b2, &b3);
if (b3 == 0)
vdevice.depth = 1;
else
vdevice.depth = 3;
*/
vdevice.depth = 3;
fprintf(fp, "\033*dC");
fprintf(fp, "\033*dF");
/*
* Solid area fills
*/
fprintf(fp, "\033*m1g");
/*
* Clear graphics memory
*/
fprintf(fp, "\033*dA");
vdevice.sizeSx = urx - llx;
vdevice.sizeSy = ury - lly;
vdevice.sizeSx = HPGT_X_SIZE;
vdevice.sizeSy = HPGT_Y_SIZE;
vdevice.sizeX = vdevice.sizeY = vdevice.sizeSy;
tlstx = tlsty = -1;
HPGT_font("5x7");
fflush(fp);
return(1);
}
/*
* HPGT_exit
*
* cleans up before going back to normal mode
*/
HPGT_exit()
{
/*
* Graphics display off
* Alpha display on.
*/
fprintf(fp, "\033*dD\033*dE");
return(0);
}
/*
* HPGT_draw
*
* draw from the current graphics position to the new one (x, y)
*/
HPGT_draw(x, y)
int x, y;
{
fprintf(fp, "\033*pa%d,%d", vdevice.cpVx, vdevice.cpVy);
fprintf(fp, " %d,%dZ", x, y);
tlstx = x;
tlsty = y;
return(0);
}
/*
* HPGT_getkey
*
* return the next key typed.
*/
int
HPGT_getkey()
{
#ifdef BSD
struct sgttyb oldtty, newtty;
char c;
fflush(fp);
ioctl(0, TIOCGETP, &oldtty);
newtty = oldtty;
newtty.sg_flags = RAW;
ioctl(0, TIOCSETP, &newtty);
read(0, &c, 1);
ioctl(0, TIOCSETP, &oldtty);
#else
struct termio oldtty, newtty;
char c;
fflush(fp);
ioctl(0, TCGETA, &oldtty);
newtty = oldtty;
newtty.c_iflag = BRKINT | IXON | ISTRIP;
newtty.c_lflag = 0;
newtty.c_cc[VEOF] = 1;
ioctl(0, TCSETA, &newtty);
read(0, &c, 1);
ioctl(0, TCSETA, &oldtty);
#endif
return(c);
}
/*
* HPGT_locator
*
* get the position of the crosshairs. This gets a bit sticky since
* we have no mouse, and the crosshairs do not behave like a mouse - even a rat!
* In this case the keys 1 to 9 are used, with each one returning a power of
* two.
*/
int
HPGT_locator(x, y)
int *x, *y;
{
int c, i;
char buf[50];
if (click) { /* for compatibility with other devs */
click = 0;
return(0);
}
click = 1;
c = -1;
if (fp == stdout) {
fprintf(fp, "\033*s4^");
fgets(buf, 50, stdin);
sscanf(buf, "%d,%d,%d", x, y, &c);
}
return(1 << (c - '1'));
}
/*
* HPGT_clear
*
* clear the screen.
*
*/
HPGT_clear()
{
/*
* A rectangular fill absolute
if (vdevice.depth == 3)
fprintf(fp, "\033*m0,0,%d,%de", vdevice.sizeSx, vdevice.sizeSy);
else
*/
/*
* Clear graphics memory
*/
fprintf(fp, "\033*dA");
tlstx = tlsty = -1;
return(0);
}
HPGT_color(i)
int i;
{
/* Select 1 of the standard colours from the system pallete */
if (vdevice.depth == 1)
return(0);
i %= 8;
fprintf(fp, "\033*m%dx", i);
/*... and the graphics text */
fprintf(fp, "\033*n%dx", i);
fprintf(fp, "\033*e%dx", i);
fflush(fp);
return(0);
}
/*
* HPGT_font
*
* set for large or small mode.
*/
int
HPGT_font(font)
char *font;
{
int size;
vdevice.hwidth = 5.0;
vdevice.hheight = 7.0;
size = 2;
if (strcmp(font, "5x7") == 0)
size = 1;
else if ((strcmp(font, "10x14") == 0) || (strcmp(font, "small") == 0))
size = 2;
else if ((strcmp(font, "15x21") == 0) || (strcmp(font, "large") == 0))
size = 3;
else if (strcmp(font, "20x28") == 0)
size = 4;
else if (strcmp(font, "25x35") == 0)
size = 5;
else if (strcmp(font, "30x42") == 0)
size = 6;
else if (strcmp(font, "35x49") == 0)
size = 7;
else if (strcmp(font, "40x56") == 0)
size = 8;
vdevice.hwidth *= size;
vdevice.hheight *= size;
fprintf(fp, "\033*m%dm", size);
tlstx = tlsty = -1;
fflush(fp);
return(1);
}
/*
* HPGT_char
*
* outputs one char
*/
int HPGT_char(char c) {
/*
* Output a label.
*/
if (tlstx != vdevice.cpVx || tlsty != vdevice.cpVy)
fprintf(fp, "\033*pa%d,%dZ", vdevice.cpVx, vdevice.cpVy);
fprintf(fp, "\033*l%c\015", c);
tlstx = vdevice.cpVx += (int)vdevice.hwidth;
fflush(fp);
return(0);
}
/*
* HPGT_string
*
* outputs a string
*/
HPGT_string(s)
char *s;
{
if (tlstx != vdevice.cpVx || tlsty != vdevice.cpVy)
fprintf(fp, "\033*pa%d,%dZ", vdevice.cpVx, vdevice.cpVy);
fprintf(fp, "\033*l%s\015", s);
fflush(fp);
tlstx = vdevice.cpVx += (int)strlen(s) * (int)vdevice.hwidth;
return(0);
}
/*
* HPGT_fill
*
* "fill" a polygon
*/
HPGT_fill(n, x, y)
int n, x[], y[];
{
int i;
fprintf(fp, "\033*pas");
for (i = 0; i < n; i++)
fprintf(fp, "%d,%d ", x[i], y[i]);
fprintf(fp, "T");
fflush(fp);
return(0);
}
/*
* Flush/sync the graphics
*/
HPGT_sync()
{
fflush(fp);
return(0);
}
/* no operations - do nothing but return -1 */
static int noop(void) { return(-1); }
static int noop1(int x) { return(-1); }
static int noop4(int a, int b, int c, int d) { return(-1); }
/*
* the device entry
*/
static DevEntry hpgtdev = {
"hpgt", /* name of device */
"large", /* name of large font */
"small", /* name of small font */
noop, /* Set drawing in back buffer */
HPGT_char, /* Draw a hardware character */
noop, /* HPGT_checkkey, Check if a key was hit */
HPGT_clear, /* Clear the screen to current color */
HPGT_color, /* Set current color */
HPGT_draw, /* Draw a line */
HPGT_exit, /* Exit graphics */
HPGT_fill, /* Fill a polygon */
HPGT_font, /* Set hardware font */
noop, /* Set drawing in front buffer */
HPGT_getkey, /* Wait for and get the next key hit */
HPGT_init, /* Initialize the device */
HPGT_locator, /* Get mouse/cross hair position */
noop4, /* HPGT_mapcolor, Set color indices */
noop1, /* Set line width */
HPGT_string, /* Draw a hardware string */
noop, /* Swap front and back buffers */
HPGT_sync /* Syncronize the display */
};
/*
* _HPGT_devcpy
*
* copy the tektronix device into vdevice.dev.
*/
_HPGT_devcpy()
{
vdevice.dev = hpgtdev;
return(0);
}