1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: djsvga.trm,v 1.20.2.1 2007/06/04 21:02:36 mikulik Exp $
5 /* GNUPLOT - djsvga.trm */
8 * Copyright 1992 - 1993, 1998, 2004
10 * Permission to use, copy, and distribute this software and its
11 * documentation for any purpose with or without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and
13 * that both that copyright notice and this permission notice appear
14 * in supporting documentation.
16 * Permission to modify the software is granted, but not the right to
17 * distribute the complete modified source code. Modifications are to
18 * be distributed as patches to the released version. Permission to
19 * distribute binaries produced by compiling modified sources is granted,
21 * 1. distribute the corresponding source modifications from the
22 * released version in the form of a patch file along with the binaries,
23 * 2. add special version identification to distinguish your version
24 * in addition to the base release version number,
25 * 3. provide your name and address as the primary contact for the
26 * support of your modified version, and
27 * 4. retain our contact information in regard to use of the base
29 * Permission to distribute the released version of the source code along
30 * with corresponding source modifications in the form of a patch file is
31 * granted with same provisions 2 through 4 for binary distributions.
33 * This software is provided "as is" without express or implied warranty
34 * to the extent permitted by applicable law.
38 * This file is included by ../term.c.
40 * This terminal driver supports:
45 * Edzer Pebesma (gnuplot 3.6: new terminal layout, fonts, grx20)
46 * Hans-Bernhard Broeker (several improvements)
48 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
52 /* HBB: A new version, called grx21a was released recently. To
53 * tell gnuplot you have it, add '-DGRX21' to your compilation flags.
54 * Currently, that only enables the drawing of wide lines. Maybe more
61 register_term(djsvga) /* no ; */
65 #define DJSVGA_XMAX 640
66 #define DJSVGA_YMAX 480
68 #define DJSVGA_XLAST (DJSVGA_XMAX - 1)
69 #define DJSVGA_YLAST (DJSVGA_YMAX - 1)
71 #define DJSVGA_VCHAR 16
72 #define DJSVGA_HCHAR 8
76 TERM_PUBLIC void DJSVGA_init __PROTO((void));
77 TERM_PUBLIC void DJSVGA_graphics __PROTO((void));
78 TERM_PUBLIC void DJSVGA_text __PROTO((void));
79 TERM_PUBLIC void DJSVGA_reset __PROTO((void));
80 TERM_PUBLIC void DJSVGA_options __PROTO((void));
81 TERM_PUBLIC void DJSVGA_linetype __PROTO((int linetype));
82 TERM_PUBLIC void DJSVGA_move __PROTO((unsigned int x, unsigned int y));
83 TERM_PUBLIC void DJSVGA_vector __PROTO((unsigned int x, unsigned int y));
84 TERM_PUBLIC int DJSVGA_angle __PROTO((int ang));
85 TERM_PUBLIC int DJSVGA_justify_text __PROTO((enum JUSTIFY mode));
86 TERM_PUBLIC void DJSVGA_put_text __PROTO((unsigned int x, unsigned int y,
88 TERM_PUBLIC int DJSVGA_set_font __PROTO((const char *fontname));
89 TERM_PUBLIC void DJSVGA_suspend __PROTO((void));
90 TERM_PUBLIC void DJSVGA_resume __PROTO((void));
91 /* clear part of multiplot */
92 TERM_PUBLIC void DJSVGA_fillbox __PROTO((int style, unsigned int x1,
93 unsigned int y1, unsigned int width,
94 unsigned int height));
95 TERM_PUBLIC void DJSVGA_linewidth __PROTO((double linewidth));
97 #define GOT_DJSVGA_PROTO
98 #endif /* TERM_PROTO */
100 #ifndef TERM_PROTO_ONLY
103 /* SVGA driver using DJGPP */
108 /* use grx20.h for DJGPP V1 / GRX V2 combo as well */
115 static int dj_startx, dj_starty;
116 static int dj_xlast, dj_ylast;
117 #define DJNUMCOLOR 15
118 /* HBB: Let's just use long for GRX1 as well */
119 static long dj_color;
120 static long svga256color[DJNUMCOLOR] =
121 /* old sequence: {7, 8, 2, 3, 4, 5, 9, 14, 12, 15, 13, 10, 11, 1, 6}; */
123 7 /*black*/, 8 /*grey*/,
124 #if 0 /* prefer dark colors */
125 4 /*dark red*/, 2 /*dark green*/, 1 /*dark blue*/, 5 /*dark magenta*/, 3 /*dark cyan*/,
126 14 /*yellow*/, 15 /*white*/,
127 12 /*red*/, 9 /*blue*/, 13 /*magenta*/, 10 /*green*/, 11 /*cyan*/,
129 #else /* prefer light colors */
130 12 /*red*/, 10 /*green*/, 9 /*blue*/, 13 /*magenta*/, 11 /*cyan*/,
131 14 /*yellow*/, 15 /*white*/,
132 4 /*dark red*/, 1 /*dark blue*/, 5 /*dark magenta*/, 2 /*dark green*/, 3 /*dark cyan*/,
136 static long dj_colors[DJNUMCOLOR];
138 /* Save, Restore: for 16 color mode! */
139 static void *DJSVGA_colorbuf = NULL;
141 static GrTextOption DJSVGA_TextOption;
142 /* HBB: I think we should use GR_NAMEWIDTH (=16), instead of MAX_ID_LEN,
143 * which has nothing to do with GRX at all */
145 char DJSVGA_fontname[MAX_ID_LEN + 1] = "";
147 char DJSVGA_fontname[MAX_ID_LEN + 1] = "@:pc8x14.fnt"; /* EGA bios font */
149 static GrContext *DJSVGA_context = 0; /* save screen for suspend/resume */
150 static char *dj_textsave = 0; /* for text-screen-saving */
151 static int dj_cursorx, dj_cursory;
152 static int dj_width, dj_height;
154 static double dj_linewidth; /* store linewidth assignments here */
161 if (!END_OF_COMMAND && isstring(c_token)) {
162 quote_str(DJSVGA_fontname, c_token, MAX_ID_LEN);
165 sprintf(term_options, "\"%s\"", DJSVGA_fontname);
171 int i, on, r, g, b, medium = 170, low = 85;
175 font = &GrDefaultFont;
177 /* HBB: save textscreen contents and cursor-position */
178 dj_textsave = gp_alloc(ScreenRows() * ScreenCols() * 2, "djsvga term scrbuf");
179 ScreenRetrieve(dj_textsave);
180 dj_width = ScreenCols();
181 dj_height = ScreenRows();
182 ScreenGetCursor(&dj_cursory, &dj_cursorx);
183 GrSetMode(GR_default_graphics);
186 /* Allocate colors */
187 for (i = 0; i < DJNUMCOLOR; i++) {
188 on = (svga256color[i] & 8) ? 255 : medium;
189 r = (svga256color[i] & 4) ? on : 0;
190 g = (svga256color[i] & 2) ? on : 0;
191 b = (svga256color[i] & 1) ? on : 0;
192 if (svga256color[i] == 8)
194 dj_colors[i] = GrAllocColor(r, g, b);
196 /* Get the screen size: */
198 term->xmax = dj_xlast + 1;
200 term->ymax = dj_ylast + 1;
201 /* if GRX 1.x loads an GRX 2.x save'd file: */
202 if (font == NULL && DJSVGA_fontname[0] == '\0')
203 sprintf(DJSVGA_fontname, "@:pc8x14.fnt");
205 if (DJSVGA_fontname[0] != '\0')
206 font = GrLoadFont(DJSVGA_fontname);
208 font = GrLoadFont("@:pc8x14.fnt"); /* try EGA bios font */
210 font = GrLoadFont("@:pc8x16.fnt"); /* try VGA bios font */
212 * HBB: There are cases when we reach this point with font still NULL,
213 * eg. when the GRXFONT env.variable points to the GRX V1 fonts, but
214 * GRX V2 is used for this program: some fonts will *fail* to load in
215 * that setup (e.g. cour20b)! So IMHO, there should be some error
216 * treatment here..., like int_error("Couldn't load font!");
218 DJSVGA_TextOption.txo_font = font;
219 DJSVGA_TextOption.txo_direct = GR_TEXT_RIGHT;
220 DJSVGA_TextOption.txo_xalign = GR_ALIGN_LEFT;
221 DJSVGA_TextOption.txo_yalign = GR_ALIGN_CENTER;
222 DJSVGA_TextOption.txo_chrtype = GR_BYTE_TEXT;
223 DJSVGA_TextOption.txo_bgcolor.v = GrNOCOLOR;
225 DJSVGA_TextOption.txo_xmag = 1;
226 DJSVGA_TextOption.txo_ymag = 1;
228 /* HBB: this version should work in all configurations */
229 term->v_char = font->h.height;
230 term->h_char = font->h.width;
233 if (DJSVGA_colorbuf == NULL)
234 DJSVGA_colorbuf = (void *) gp_alloc(GrColorSaveBufferSize(), "djsvga term colorbuf");
235 GrSaveColors(DJSVGA_colorbuf);
237 GrSetMode(GR_default_text);
238 ScreenUpdate(dj_textsave);
239 ScreenSetCursor(dj_cursory, dj_cursorx);
243 * HBB: make these two inline, as they're called by other routines
244 * inside this module, and -finline-functions (normally switched
245 * on by 'gcc -O3') doesn't work for compiling term.c
251 ScreenRetrieve(dj_textsave); /* HBB: save text screen contents */
252 ScreenGetCursor(&dj_cursory, &dj_cursorx);
253 GrSetMode(GR_default_graphics);
255 GrRestoreColors(DJSVGA_colorbuf);
264 GrSetMode(GR_width_height_text, dj_width, dj_height);
265 ScreenUpdate(dj_textsave); /* HBB: restore text screen */
266 ScreenSetCursor(dj_cursory, dj_cursorx);
277 DJSVGA_linetype(int linetype)
283 /* HBB: set the TextOption color variable right here (faster) */
284 DJSVGA_TextOption.txo_fgcolor.v = dj_color = dj_colors[linetype + 2];
288 DJSVGA_move(unsigned int x, unsigned int y)
296 DJSVGA_vector(unsigned int x, unsigned int y)
299 GrLineOption dj_lineoption =
300 {dj_color, dj_linewidth, 0, ""};
302 GrCustomLine(dj_startx, dj_ylast - dj_starty, x, dj_ylast - y, &dj_lineoption);
304 GrLine(dj_startx, dj_ylast - dj_starty, x, dj_ylast - y, dj_color);
311 * HBB: IMHO, the previous version was seriously flawed. E.g.
312 * in the termentry, _justify_text was pointing to the
313 * null_justify_text dummy routine, so DJSVGA_justify wasn't
314 * ever called at all. I copied the routines from my (now
315 * otherwise pointless) own private driver, djgrx.trm, to
319 DJSVGA_angle(int ang)
322 DJSVGA_TextOption.txo_direct = GR_TEXT_UP;
324 DJSVGA_TextOption.txo_direct = GR_TEXT_RIGHT;
330 DJSVGA_justify_text(enum JUSTIFY mode)
332 if (DJSVGA_TextOption.txo_direct == GR_TEXT_RIGHT) {
333 DJSVGA_TextOption.txo_yalign = GR_ALIGN_CENTER;
336 DJSVGA_TextOption.txo_xalign = GR_ALIGN_LEFT;
339 DJSVGA_TextOption.txo_xalign = GR_ALIGN_CENTER;
342 DJSVGA_TextOption.txo_xalign = GR_ALIGN_RIGHT;
346 DJSVGA_TextOption.txo_xalign = GR_ALIGN_CENTER;
349 DJSVGA_TextOption.txo_yalign = GR_ALIGN_BOTTOM;
352 DJSVGA_TextOption.txo_yalign = GR_ALIGN_CENTER;
355 DJSVGA_TextOption.txo_yalign = GR_ALIGN_TOP;
363 DJSVGA_set_font(const char *fontname)
367 if (!fontname || !fontname[0])
369 safe_strncpy(DJSVGA_fontname, fontname, sizeof(DJSVGA_fontname));
370 cp = strstr(DJSVGA_fontname, ",");
373 font = GrLoadFont(DJSVGA_fontname);
374 /*HBB: if no font found, do *not* report success! */
376 GrUnloadFont(DJSVGA_TextOption.txo_font);
377 DJSVGA_TextOption.txo_font = font;
380 graph_error("Font not found");
386 DJSVGA_put_text(unsigned int x, unsigned int y, const char *str)
388 /* HBB: why isn't font!=NULL ensured elsewhere? Testing it at
389 * this point doesn't really make much sense (we're in graphics
390 * mode, so we can't even print out a useful error message!) */
391 /*if (DJSVGA_TextOption.txo_font != NULL) */
392 GrDrawString(str, strlen(str), x, dj_ylast - y, &DJSVGA_TextOption);
398 DJSVGA_context = GrCreateContext(GrSizeX(), GrSizeY(), 0, 0);
399 GrBitBltNC(DJSVGA_context, 0, 0, 0, 0, 0, GrMaxX(), GrMaxY(), GrWRITE);
407 GrBitBltNC(0, 0, 0, DJSVGA_context, 0, 0, GrMaxX(), GrMaxY(), GrWRITE);
408 GrDestroyContext(DJSVGA_context);
414 unsigned int left, unsigned int bottom,
415 unsigned int width, unsigned height)
419 /* HBB: prize question: should it be 'width-1' instead? */
420 /* HBB: fill with GRX Color '0', which *should* be black : */
421 /* ULIG: the style parameter is now used for the fillboxes style */
422 /* (not implemented here), see the documentation */
424 GrFilledBox(left, dj_ylast - bottom, left + width, dj_ylast - bottom - height, 0);
428 DJSVGA_linewidth(double linewidth)
431 dj_linewidth = linewidth;
435 #endif /* TERM_BODY */
439 /* HBB: I think \" is more readable than \042. BTW: why is this
440 * option 'documented' here, but not in the Help node? */
441 TERM_TABLE_START(djsvga_driver)
442 "svga", "IBM PC/Clone with Super VGA graphics board [\"fontname\"]",
443 DJSVGA_XMAX, DJSVGA_YMAX, DJSVGA_VCHAR, DJSVGA_HCHAR,
444 DJSVGA_VTIC, DJSVGA_HTIC,
446 DJSVGA_init, DJSVGA_reset, DJSVGA_text,
447 null_scale, DJSVGA_graphics, DJSVGA_move, DJSVGA_vector,
448 DJSVGA_linetype, DJSVGA_put_text,
449 DJSVGA_angle, DJSVGA_justify_text,
450 do_point, do_arrow, DJSVGA_set_font,
451 0, /* no pointsize() */
453 DJSVGA_suspend, DJSVGA_resume,
454 DJSVGA_fillbox, DJSVGA_linewidth
455 TERM_TABLE_END(djsvga_driver)
458 #define LAST_TERM djsvga_driver
460 #endif /* TERM_TABLE */
461 #endif /* TERM_PROTO_ONLY */
464 * HBB: I think this documentation should be at least a *bit* longer
465 * (E.g., the "fontname" parameter is claimed to be non-existent!)
467 /* RCC: Not any more...
468 * If you have other ideas about what could be in the help section,
469 * please let me know (rccrawford@lanl.gov) --- particularly info
470 * about what fonts are permitted, if there is such a list.
475 "?commands set terminal svga",
476 "?set terminal svga",
481 " The `svga` terminal driver supports PCs with SVGA graphics. It can only be",
482 " used if it is compiled with DJGPP. Its only option is the font.",
485 " set terminal svga {\"<fontname>\"}"
487 #endif /* TERM_HELP */