1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: pc.trm,v 1.23 2006/07/21 02:35:47 sfeam Exp $
9 * Copyright 1990 - 1993, 1998, 2004
11 * Permission to use, copy, and distribute this software and its
12 * documentation for any purpose with or without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and
14 * that both that copyright notice and this permission notice appear
15 * in supporting documentation.
17 * Permission to modify the software is granted, but not the right to
18 * distribute the complete modified source code. Modifications are to
19 * be distributed as patches to the released version. Permission to
20 * distribute binaries produced by compiling modified sources is granted,
22 * 1. distribute the corresponding source modifications from the
23 * released version in the form of a patch file along with the binaries,
24 * 2. add special version identification to distinguish your version
25 * in addition to the base release version number,
26 * 3. provide your name and address as the primary contact for the
27 * support of your modified version, and
28 * 4. retain our contact information in regard to use of the base
30 * Permission to distribute the released version of the source code along
31 * with corresponding source modifications in the form of a patch file is
32 * granted with same provisions 2 through 4 for binary distributions.
34 * This software is provided "as is" without express or implied warranty
35 * to the extent permitted by applicable law.
39 * This file is included by ../term.c.
41 * This terminal driver supports:
43 * cga, egabios, egalib, vgabios, hercules, corona325, att
45 * cga, ega/vga, vgamono, svga, mcga, hercules, att
47 * cga, ega/vga, vgamono, svga, mcga, hercules, ???
50 * Colin Kelley, Thomas Williams, William Wilson, Russell Lang
51 * modified by David J. Liu (liu@csb.yale.edu) for version 3.6
53 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
55 * Because only one compiler is used to generate gnuplot.exe
56 * and the type of the single graphics board is auto-detected,
57 * we can combine all these parts into one terminal type: PC
58 * and let the computer take care of the rest. -- DJL
60 * Since I don't have MicroSoft C, I assume it would define MSC.
61 * Please correct it if you are using MS C. Thank you. -- DJL
66 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
76 TERM_PUBLIC void PC_text __PROTO((void));
77 TERM_PUBLIC void PC_reset __PROTO((void));
78 TERM_PUBLIC void PC_init __PROTO((void));
79 TERM_PUBLIC void PC_graphics __PROTO((void));
80 TERM_PUBLIC void PC_linetype __PROTO((int linetype));
81 TERM_PUBLIC void PC_move __PROTO((unsigned int x, unsigned int y));
82 TERM_PUBLIC void PC_vector __PROTO((unsigned int x, unsigned int y));
83 TERM_PUBLIC void PC_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
84 TERM_PUBLIC int PC_text_angle __PROTO((int ang));
85 TERM_PUBLIC int PC_justify_text __PROTO((enum JUSTIFY ang));
87 #define PC_HCHAR FNT5X9_HCHAR
88 #define PC_VCHAR FNT5X9_VCHAR
91 #define PC_XMAX 100 /* These two entries are just place holders. */
92 #define PC_YMAX 100 /* The actual values will be found in init. */
93 #endif /* TERM_PROTO */
95 #ifndef TERM_PROTO_ONLY
99 static int huge detect_svga __PROTO((void));
100 #endif /* __TURBOC__ */
105 #include <graphics.h>
108 #endif /* __TURBOC__ */
110 # include <conio.h> /* for getch() */
117 static unsigned int pattern[] ={ 0xffff, 0x0f0f, 0xffff, 0xaaaa, 0x3333, 0x3f3f, 0x0f0f };
118 static int vga_color[] ={ 7, 8, 2, 3, 4, 5, 9, 14, 12, 15, 13, 10, 11, 1, 6 };
120 static int pc_driver, pc_mode;
121 static int graphics_on = FALSE, pc_graphics = FALSE;
122 static int startx, starty, pc_lastx, pc_lasty, pc_colors;
123 static int pc_angle, pc_hjustify, pc_vjustify, pc_text_size, pc_text_dir, pc_corscreen = -1;
127 extern int far _Cdecl SVGA_driver_far[];
128 #endif /* __TURBOC__ */
137 if (ang == HORIZ_DIR) {
138 _settextorient(1, 0);
140 _settextorient(0, 1);
148 return 0; /* the default mode, just a place holder */
153 { /* called from the beginning of main() */
157 struct videoconfig VC;
160 /* First link all BRI dribers, then detect the display card. */
161 /* If environment PCTRM is set, try initiate the card/mode. */
163 /* special instruction on mode */
164 safe_strncpy(pc_modename, getenv("PCTRM"), 8);
167 /* Some of this code including BGI drivers are copyright Borland Intl. */
168 registerfarbgidriver(EGAVGA_driver_far);
169 registerfarbgidriver(CGA_driver_far);
170 registerfarbgidriver(Herc_driver_far);
171 registerfarbgidriver(ATT_driver_far);
172 registerfarbgidriver(PC3270_driver_far);
174 detectgraph(&pc_driver, &pc_mode);
176 fputs("Unable to initialize graphics.\n", stderr);
180 /* the highest standard pc_driver value, see graphics.h */
182 /* the last mode of the SVGA.BGI */
183 #define LAST_SVGA_MODE 6
184 /* test SVGA if we have VGA */
185 if ((pc_driver == VGA) && (pc_modename[0] == 'S')) {
186 installuserdriver(BGI_NAME, &detect_svga);
187 registerfarbgidriver(SVGA_driver_far);
189 initgraph(&pc_driver, &pc_mode, "");
190 /* The following code, which is independent of the actual SVGA.BGI
191 * used, tries to find a mode of width defined in the environment
193 if (pc_driver > LAST_BGI) { /* success */
194 sscanf(pc_modename, "S%d", &t);
203 t = 640; /* 640x480 */
205 for (i = 0; i <= LAST_SVGA_MODE; i++) {
207 if ((getmaxx() + 1 == t) && (getmaxcolor() > 14))
210 setgraphmode(pc_mode);
211 if (graphresult()) { /* error, go back to VGA */
217 if (pc_driver <= LAST_BGI)
218 #endif /* BGI_NAME */
219 initgraph(&pc_driver, &pc_mode, "");
220 pc_colors = getmaxcolor() + 1;
221 pc_lastx = getmaxx();
222 pc_lasty = getmaxy();
225 #endif /* __TURBOC__ */
227 _getvideoconfig(&VC);
228 if ((pc_driver = VC.adapter) == 0) {
229 fprintf(stderr, "Unable to initialize graphics.\n");
232 switch (pc_driver = VC.adapter) {
240 pc_mode = _MRES256COLOR;
243 pc_mode = (VC.monitor == _MONO ? _ERESCOLOR : _ERESNOCOLOR);
246 pc_mode = _VRES16COLOR;
249 if (pc_modename[0] == 'S') { /* test SVGA resolution */
250 sscanf(pc_modename, "S%d", &t);
253 pc_mode = _SVRES256COLOR;
256 pc_mode = _XRES256COLOR;
259 pc_mode = _XRES256COLOR + 2;
261 /* Someone help me, who knows, how a newer Watcom calls that */
264 pc_mode = _VRES256COLOR; /* 640x480 */
266 while (_setvideomode(pc_mode) == 0)
271 fputs("Unable to initialize graphics.\n", stderr);
274 _setvideomode(pc_mode);
275 _getvideoconfig(&VC);
276 pc_lastx = VC.numxpixels - 1;
277 pc_lasty = VC.numypixels - 1;
278 pc_colors = VC.numcolors;
279 _setvideomode(_DEFAULTMODE);
283 fprintf(stderr, "\tScreen of %d x %d pixels and %d colors.\n",
297 fputs("Unable to initialize graphics.\n", stderr);
301 /* Double the tic/font sizes. */
302 pc_text_size = (pc_lasty > 590) ? 2 : 1;
303 term->h_char = PC_HCHAR;
304 term->v_char = PC_VCHAR;
305 term->h_tic = PC_HTIC * pc_text_size;
306 term->v_tic = PC_VTIC * pc_text_size;
307 term->xmax = pc_lastx + 1;
308 term->ymax = pc_lasty + 1;
310 setgraphmode(pc_mode);
311 settextstyle(DEFAULT_FONT, HORIZ_DIR, pc_text_size);
312 settextjustify(pc_hjustify, pc_vjustify);
313 term->h_char = textheight("X"); /* overriding the default */
314 term->v_char = textwidth("X"); /* overriding the default */
315 #endif /* __TURBOC__ */
317 _setvideomode(pc_mode);
318 _settextang(HORIZ_DIR);
319 _settextalign(pc_hjustify, pc_vjustify);
320 _setcharsize(pc_text_size * PC_HCHAR, pc_text_size * PC_VCHAR);
322 term->h_char = fi.avgwidth;
323 term->v_char = fi.pixheight * 1.5;
334 setgraphmode(pc_mode);
335 #endif /* __TURBOC__ */
337 _setvideomode(pc_mode);
340 if (pc_corscreen == -1)
350 PC_linetype(int linetype)
355 if (pc_colors > 14) { /* 16 or more colors */
359 setcolor(vga_color[linetype + 2]);
360 #endif /* __TURBOC__ */
362 _setcolor(vga_color[linetype + 2]);
370 setlinestyle(4, pattern[linetype + 2], 1);
371 #endif /* __TURBOC__ */
373 _setlinestyle(pattern[linetype + 2]);
376 if (pc_corscreen != -1)
377 Cor_mask(pattern[linetype + 2]);
383 PC_move(unsigned int x, unsigned int y)
386 moveto(x, pc_lasty - y);
387 #endif /* __TURBOC__ */
389 _moveto(x, pc_lasty - y);
398 PC_vector(unsigned int x, unsigned int y)
401 lineto(x, pc_lasty - y);
402 #endif /* __TURBOC__ */
404 _lineto(x, pc_lasty - y);
407 if (pc_corscreen != -1)
408 Cor_line(startx, COR_YLAST - starty, x, COR_YLAST - y);
421 #endif /* __TURBOC__ */
423 _setvideomode(_DEFAULTMODE);
439 #endif /* __TURBOC__ */
441 _setvideomode(_DEFAULTMODE);
444 if (pc_corscreen != -1) {
454 PC_text_angle(int ang)
458 pc_text_dir = HORIZ_DIR;
462 pc_text_dir = VERT_DIR;
469 PC_justify_text(enum JUSTIFY just)
471 #if defined(__TURBOC__)
474 pc_hjustify = LEFT_TEXT;
475 pc_vjustify = CENTER_TEXT;
478 pc_hjustify = CENTER_TEXT;
479 pc_vjustify = CENTER_TEXT;
482 pc_hjustify = RIGHT_TEXT;
483 pc_vjustify = CENTER_TEXT;
486 settextjustify(pc_hjustify, pc_vjustify);
488 #elif defined(__WATCOMC__)
495 pc_hjustify = _CENTER;
499 pc_hjustify = _RIGHT;
503 _settextalign(pc_hjustify, pc_vjustify);
506 return (just == LEFT);
511 PC_put_text(unsigned int x, unsigned int y, const char *str)
514 settextstyle(DEFAULT_FONT, pc_text_dir, pc_text_size);
515 settextjustify(pc_hjustify, pc_vjustify);
516 outtextxy(x, pc_lasty - y, str);
517 #endif /* __TURBOC__ */
519 _setcharsize(pc_text_size * PC_VCHAR, pc_text_size * PC_HCHAR);
520 _settextang(pc_text_dir);
521 _settextalign(pc_hjustify, pc_vjustify);
522 _grtext(x, pc_lasty - y, str);
528 #endif /* TERM_BODY */
532 TERM_TABLE_START(dospc_driver)
533 "dospc", "IBM PC/Clone running DOS",
534 PC_XMAX, PC_YMAX, PC_VCHAR, PC_HCHAR,
535 PC_VTIC, PC_HTIC, options_null, PC_init, PC_reset,
536 PC_text, null_scale, PC_graphics, PC_move, PC_vector,
537 PC_linetype, PC_put_text, PC_text_angle,
538 PC_justify_text, line_and_point, do_arrow, set_font_null
539 TERM_TABLE_END(dospc_driver)
542 #define LAST_TERM dospc_driver
544 #endif /* TERM_TABLE */
545 #endif /* TERM_PROTO_ONLY */
550 "?commands set terminal dospc",
551 "?set terminal dospc",
556 " The `dospc` terminal driver supports PCs with arbitrary graphics boards,",
557 " which will be automatically detected. It should be used only if you are",
558 " not using the gcc or Zortec C/C++ compilers."
560 #endif /* TERM_HELP */