/* GNUPLOT - fg.trm */
/*
 * Copyright (C) 1990, 1991, 1992
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted, 
 * provided that the above copyright notice appear in all copies and 
 * that both that copyright notice and this permission notice appear 
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the modified code.  Modifications are to be distributed 
 * as patches to released version.
 *
 * This software  is provided "as is" without express or implied warranty.
 *
 * This file is included by ../term.c.
 *
 * This terminal driver supports:
 *	Under Zortech C
 *      egalib, vgalib, vgamono, svga, mcga, cga, hercules, att
 *
 * AUTHORS
 *		  Gnuplot for DOS 386/flash graphics
 *				  Clifton T. Liu
 *
 * There is a mailing list for gnuplot users. Note, however, that the
 * newsgroup 
 *	comp.graphics.gnuplot 
 * is identical to the mailing list (they
 * both carry the same set of messages). We prefer that you read the
 * messages through that newsgroup, to subscribing to the mailing list.
 * (If you can read that newsgroup, and are already on the mailing list,
 * please send a message info-gnuplot-request@dartmouth.edu, asking to be
 * removed from the mailing list.)
 *
 * The address for mailing to list members is
 *	   info-gnuplot@dartmouth.edu
 * and for mailing administrative requests is 
 *	   info-gnuplot-request@dartmouth.edu
 * The mailing list for bug reports is 
 *	   bug-gnuplot@dartmouth.edu
 * The list of those interested in beta-test versions is
 *	   info-gnuplot-beta@dartmouth.edu
 */
/* The modifications to allow Gnuplot to compile with Zortech C/C++   */
/* 3.1 /Flash Graphics	were made by Clifton T. Liu 				  */
/* (cliu@merlin.appmath.columbia.edu)		 20 Feb 1993			  */

#include <fg.h>

static int pattern[] = {0xffff, 0x0f0f, 0xffff, 0xaaaa, 0x3333, 0x3f3f, 0x0f0f};

static int graphics_on = FALSE;
int startx, starty;
/*
int pc_angle;
#define PC_VCHAR FNT5X9_VCHAR
#define PC_HCHAR FNT5X9_HCHAR
*/
pause()		/* press any key to continue... */
{
	(void) getch();
}


PC_text()
{
	if (graphics_on) {
		graphics_on = FALSE;
		pause();
	}
   fg_term();
}

PC_reset()
{
}



/* all of the FlashGraphics C routines for the different graphics devices go here */


#define HERC_XMAX 720
#define HERC_YMAX 348

#define HERC_XLAST (HERC_XMAX - 1)
#define HERC_YLAST (HERC_YMAX - 1)

#define HERC_VCHAR 10
#define HERC_HCHAR 8
#define HERC_VTIC 5
#define HERC_HTIC 5



#define EGA_XMAX 640
#define EGA_YMAX 350

#define EGA_XLAST (EGA_XMAX - 1)
#define EGA_YLAST (EGA_YMAX - 1)

#define EGA_VCHAR 18
#define EGA_HCHAR 8
#define EGA_VTIC 5
#define EGA_HTIC 5


#define VGA_XMAX 640
#define VGA_YMAX 480

#define VGA_XLAST (VGA_XMAX - 1)
#define VGA_YLAST (VGA_YMAX - 1)

#define VGA_VCHAR 24
#define VGA_HCHAR 8
#define VGA_VTIC 5
#define VGA_HTIC 5


#define SVGA_XMAX 800
#define SVGA_YMAX 600

#define SVGA_XLAST (SVGA_XMAX - 1)
#define SVGA_YLAST (SVGA_YMAX - 1)

#define SVGA_VCHAR 24
#define SVGA_HCHAR 8
#define SVGA_VTIC 5
#define SVGA_HTIC 5

#define SSVGA_XMAX 1024
#define SSVGA_YMAX 768

#define SSVGA_XLAST (SSVGA_XMAX - 1)
#define SSVGA_YLAST (SSVGA_YMAX - 1)

#define SSVGA_VCHAR 24
#define SSVGA_HCHAR 8
#define SSVGA_VTIC 5
#define SSVGA_HTIC 5


static int vga256color[] = {7,8,2,3,4,5,9,14,12,15,13,10,11,1,6};
static int *vgacolor = vga256color;
static fg_color_t vga_color;
static int text_angle;
static fg_line_t line_to_draw;

int VGA_text_angle(ang)
int ang;
{
	text_angle = ang;
	return TRUE;
}

int VGA_justify_text(mode)
enum JUSTIFY mode;
{
	return FALSE;
}

int VGA_init()
{
	   if (fg_init() == FG_NULL)  {
		   fprintf(stderr,"Graphics card not detected.\n");
		   exit(1);
	  }
}

int HERC_graphics()
{
   fg_init_herc();
   graphics_on = TRUE;
}

int EGAMONO_graphics()
{
   fg_init_egamono();
   graphics_on = TRUE;
}

int EGA_graphics()
{
   fg_init_egaecd();
   graphics_on = TRUE;
}

int VGA_graphics()
{
   fg_init_vga12();
   graphics_on = TRUE;
}

int VGAMONO_graphics()
{
   fg_init_vga11();
   graphics_on = TRUE;
}

int SVGA_graphics()
{
   fg_init_vesa6a();
   graphics_on = TRUE;
}

int SSVGA_graphics()
{
   fg_init_vesa5();
   graphics_on = TRUE;
}

int VGA_linetype(linetype)
{
 { /* 13 replaces 15 */
   if (linetype >= 13)
       linetype %= 13;
       vga_color = fg.color[vgacolor[linetype+2]];
}

int VGA_put_text(x,y,str)
unsigned int x, y;
char *str;
{
   fg_puts(vga_color, FG_MODE_SET,	~0,  text_angle, x, y, str, fg.displaybox);
}

int VGA_move(x,y)
{
	 line_to_draw[FG_X1] = x;
	 line_to_draw[FG_Y1] = y;
}


int VGA_vector(x,y)
{
	 line_to_draw[FG_X2] = x;
	 line_to_draw[FG_Y2] = y;
	 fg_drawline(vga_color, FG_MODE_SET, ~0, FG_LINE_SOLID, line_to_draw);
	 line_to_draw[FG_X1] = x;
	 line_to_draw[FG_Y1] = y;
}

int VGA_text()
{
	if (graphics_on) {
		graphics_on = FALSE;
		fg_flush();
		pause();
	}
   fg_term();
}

int VGA_reset()
{
   fg_term();
}
