/* Hello, Emacs, this is -*-C-*-
 * $Id: v384.trm,v 1.12 2006/07/21 02:35:48 sfeam Exp $
 *
 */

/* GNUPLOT - v384.trm */

/*[
 * Copyright 1990 - 1993, 1998, 2004
 *
 * 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 complete modified source code.  Modifications are to
 * be distributed as patches to the released version.  Permission to
 * distribute binaries produced by compiling modified sources is granted,
 * provided you
 *   1. distribute the corresponding source modifications from the
 *    released version in the form of a patch file along with the binaries,
 *   2. add special version identification to distinguish your version
 *    in addition to the base release version number,
 *   3. provide your name and address as the primary contact for the
 *    support of your modified version, and
 *   4. retain our contact information in regard to use of the base
 *    software.
 * Permission to distribute the released version of the source code along
 * with corresponding source modifications in the form of a patch file is
 * granted with same provisions 2 through 4 for binary distributions.
 *
 * This software is provided "as is" without express or implied warranty
 * to the extent permitted by applicable law.
]*/

/*
 * This file is included by ../term.c.
 *
 * This terminal driver supports:
 *  Vectrix 384 - works with tandy color printer as well
 *
 * AUTHORS
 *   roland@moncskermit.OZ (Roland Yap)
 *
 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
 *
 */

/*
 *	Vectrix 384 driver - works with tandy color printer as well
 *  in reverse printing 8 color mode.
 *  This doesn't work on Vectrix 128 because it redefines the
 *  color table. It can be hacked to work on the 128 by changing
 *  the colours but then it will probably not print best. The color
 *  table is purposely designed so that it will print well
 *
 */

/*
 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
 */

#include "driver.h"

#ifdef TERM_REGISTER
register_term(vx384)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void V384_init __PROTO((void));
TERM_PUBLIC void V384_graphics __PROTO((void));
TERM_PUBLIC void V384_text __PROTO((void));
TERM_PUBLIC void V384_linetype __PROTO((int linetype));
TERM_PUBLIC void V384_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void V384_vector __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void V384_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
TERM_PUBLIC void V384_reset __PROTO((void));

#define V384_XMAX 630
#define V384_YMAX 480

#define V384_XLAST (V384_XMAX - 1)
#define V384_YLAST (V384_YMAX - 1)

#define V384_VCHAR	12
#define V384_HCHAR	7
#define V384_VTIC	8
#define V384_HTIC	7
#endif /* TERM_PROTO */

#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY

TERM_PUBLIC void
V384_init()
{
    fprintf(gpoutfile, "%c%c  G0   \n\
Q 0 8\n\
0 0 0\n\
255 0 0\n\
0 255 0\n\
0 0 255\n\
0 255 255\n\
255 0 255\n\
255 255 0\n\
255 255 255\n",
	    27, 18);
}


TERM_PUBLIC void
V384_graphics()
{
    fprintf(gpoutfile, "%c%c E0 RE N 65535\n", 27, 18);
}


TERM_PUBLIC void
V384_text()
{
    fprintf(gpoutfile, "%c%c\n", 27, 17);
}


TERM_PUBLIC void
V384_linetype(int linetype)
{
    static int color[] =
    {
	1 /* red */ ,
	2 /* green */ ,
	3 /* blue */ ,
	4 /* cyan */ ,
	5 /* magenta */ ,
	6 /* yellow */ ,	/* not a good color so not in use at the moment */
	7 /* white */
    };

    if (linetype < 0)
	linetype = 6;
    else
	linetype %= 5;

    fprintf(gpoutfile, "C %d\n", color[linetype]);
}


TERM_PUBLIC void
V384_move(unsigned int x, unsigned int y)
{
    fprintf(gpoutfile, "M %d %d\n", x + 20, y);
}


TERM_PUBLIC void
V384_vector(unsigned int x, unsigned int y)
{
    fprintf(gpoutfile, "L %d %d\n", x + 20, y);
}


TERM_PUBLIC void
V384_put_text(unsigned int x, unsigned int y, const char str[])
{
    V384_move(x, y + V384_VCHAR / 2);
    fprintf(gpoutfile, "$%s\n", str);
}


TERM_PUBLIC void
V384_reset()
{
}

#endif /* TERM_BODY */

#ifdef TERM_TABLE
TERM_TABLE_START(vx384_driver)
    "vx384", "Vectrix 384 and Tandy color printer",
    V384_XMAX, V384_YMAX, V384_VCHAR, V384_HCHAR,
    V384_VTIC, V384_HTIC, options_null, V384_init, V384_reset,
    V384_text, null_scale, V384_graphics, V384_move, V384_vector,
    V384_linetype, V384_put_text, null_text_angle,
    null_justify_text, do_point, do_arrow, set_font_null
TERM_TABLE_END(vx384_driver)

#undef LAST_TERM
#define LAST_TERM vx384_driver

#endif /* TERM_TABLE */
#endif /* TERM_PROTO_ONLY */

#ifdef TERM_HELP
START_HELP(vx384)
"1 vx384",
"?commands set terminal vx384",
"?set terminal vx384",
"?set term vx384",
"?terminal vx384",
"?term vx384",
"?vx384",
" The `vx384` terminal driver supports the Vectrix 384 and Tandy color",
" printers.  It has no options."
END_HELP(vx384)
#endif
