/* GNUPLOT - linux.trm */
/*
 * Copyright (C) 1990
 *
 * 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:
 *  VGA 640x480x16 for PC's running the Linux Operating System 
 *
 * AUTHOR
 *  Tommy Frandsen (frandsen@diku.dk)
 *
 * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
 *
 */

#include <vga.h>

#define LINUX_XMAX 640
#define LINUX_YMAX 480

#define LINUX_XLAST (LINUX_XMAX - 1)
#define LINUX_YLAST (LINUX_YMAX - 1)

#define LINUX_VCHAR FNT5X9_VCHAR
#define LINUX_HCHAR FNT5X9_HCHAR

#define LINUX_VTIC 5
#define LINUX_HTIC 5

static int graphics_on = FALSE;

int startx, starty;
int linux_angle;

static int vgacolor[] = {7,8,2,3,4,5,9,14,12,15,13,10,11,1,6};


LINUX_text()
{
	int c;

	if (graphics_on) {
		graphics_on = FALSE;
		vga_getch();
	}
	vga_setmode(TEXT);
}


LINUX_reset()
{
	vga_setmode(TEXT);
}


LINUX_putc(x,y,c,ang,line_func)
unsigned int x,y;
char c;
int ang;
FUNC_PTR line_func;
{
int i, j, k;
unsigned int pixelon;
	i = (int)(c) - 32;
	for (j=0; j<FNT5X9_VBITS; j++) {
		for (k=0; k<FNT5X9_HBITS; k++) {
			pixelon = (((unsigned int)(fnt5x9[i][j])) >> k & 1);
			if (pixelon) {
				switch(ang) {
					case 0 : (*line_func)(x+k+1,y-j,x+k+1,y-j);
							break;
					case 1 : (*line_func)(x-j,y-k-1,x-j,y-k-1);
							break;
				}
			}
		}
	}
}


int LINUX_text_angle(ang)
int ang;
{
	linux_angle=ang;
	return TRUE;
}


LINUX_init()
{
}


LINUX_graphics()
{
	graphics_on = TRUE;
	vga_setmode(G640x480x16);
}


LINUX_linetype(linetype)
{
	if (linetype >= 13)
		linetype %= 13;
	vga_setcolor(vgacolor[linetype+2]); 
}

LINUX_move(x,y)
{
	startx = x;
	starty = y;
}


LINUX_vector(x,y)
{
	vga_drawline(startx,LINUX_YLAST-starty,x,LINUX_YLAST-y); 
	startx = x;
	starty = y;
}


LINUX_put_text(x,y,str)
unsigned int x, y;
char *str;
{
int i;
	switch(linux_angle) {
		case 0 : y -= LINUX_VCHAR/2;
				break;
		case 1 : x += LINUX_VCHAR/2;
				break;
	}
	for (i=0;str[i];i++) {
		LINUX_putc(x,LINUX_YLAST-y,str[i],linux_angle,vga_drawline); 
		switch(linux_angle) {
			case 0 : x+=LINUX_HCHAR ;
					break;
			case 1 : y+=LINUX_HCHAR ;
					break;
		}
	}
}


