1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sgpdrive.cpp,v 1.3 2000/06/19 19:04:05 kevin Exp $
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License (version 2) as
9 ** published by the Free Software Foundation.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ******************************************************************************/
21 /* Device Driver for IBM PC Kevin Rosenberg March 84 */
26 #include "ctsupport.h"
30 static int init_prt(void);
31 static void term_prt(void);
33 /*===========================================================*/
34 /* fundamental device drivers */
35 /*===========================================================*/
37 #define XCHARSIZ (1.0 / 80.0) /* size of standard characters */
38 #define YCHARSIZ (1.0 / 25.0) /* on screen in NDC */
40 #define CRTASPT (0.75) /* for IBM ECD */
42 /*-------------------*/
43 /* print buffer data */
44 /*-------------------*/
50 #define PRTMODE 1 /* Epson 120 dot/in graphic mode */
51 #define PRTASPT (120.0 / 72.0) /* dots/in vectical / horizontal */
53 static DEVICE crt, prt;
55 static GRFSTATE state;
60 * gp_init Initialize graphics package
68 _sgp2_init_dev (SGP_ID cwin)
71 initdevice (CRTDEV, GM_ENHANCED, 0, 0);
72 initdevice (PRTDEV, PRTMODE, (int) (PRTSIZE * PRTASPT), PRTSIZE);
74 setlinestyle (LS_SOLID);
76 _sgp2_set_text (XCHARSIZ, YCHARSIZ, 0.0, 0);
79 gp_set_aspect (CRTDEV, CRTASPT);
80 gp_set_aspect (PRTDEV, 1.0);
83 state.xndc = 10.; /* to guarntee a move */
84 _sgp2_stylus (cwin, 0.0,0.0,0); /* move to starting corner */
91 * gp_initdev Initializes graphic device
94 * initdevice (dev, mode, xsize, ysize)
95 * int dev Device handle
96 * int mode Mode for device (device specific)
97 * int xsize Size of x buffer for PRTDEV
98 * int ysize Size of y buffer for PRTDEV
102 initdevice (int dev, int mode, int xsize, int ysize)
106 // crt.dotfunc = crt_wdot;
107 // crt.linefunc = crt_line;
157 case GM_1024x768x256:
168 // crt_set_mode (crt.mode, TRUE); /* Initialize device */
172 if (prt.open == TRUE)
173 closedevice (PRTDEV);
182 if (xsize > 1 && ysize > 1) {
187 prt.xmax = prt.xsize - 1;
188 prt.ymax = prt.ysize - 1;
192 // prt.dotfunc = prtdot;
193 // prt.linefunc = prtline;
195 init_prt (); /* Initialize the device */
203 * gp_opendev Open device for output
207 * int dev Device handle
208 * devices are number in powers of two
225 * gp_closedev Close device for output
229 * int dev Device handle
232 * Temporarily suspends output from going to a device
236 closedevice (int dev)
238 if (dev & CRTDEV) /* close crt */
253 static int init_prt(void)
259 static void term_prt(void)
263 /*===========================================================*/
264 /* stylus draws a line to the absolute point x,y in NDC's */
265 /* t=0 for move, t=1 for draw */
266 /*===========================================================*/
268 _sgp2_stylus (SGP_ID cwin, double x, double y, int beam)
272 if ((state.xndc == x) && (state.yndc == y) && (beam == 0))
273 return; /* no need to move */
275 state.xndc = x; /* save current beam location */
279 xp = (int) (x * cwin->pw_xsize + 0.5);
280 yp = (int) (y * cwin->pw_ysize + 0.5);
283 g2_line (cwin->g2_id, (double) cwin->phys_curx, (double) cwin->phys_cury, (double) xp, (double) yp);
285 cwin->phys_curx = xp;
286 cwin->phys_cury = yp;
291 pntndc (SGP_ID cwin, double x, double y)
293 _sgp2_stylus (cwin, x, y, 0); /* move to point */
294 // if (crt.open == TRUE)
295 // cpix_set (crt.icurx, crt.icury, crt.color);
299 markndc (SGP_ID cwin, double x, double y)
301 _sgp2_stylus (cwin, x, y, 0); /* move to point */
303 if (crt.open == TRUE)
304 wrtsymbol (state.marktype, crt.icurx, crt.icury, &crt);
306 if (prt.open == TRUE)
307 wrtsymbol (state.marktype, prt.icurx, prt.icury, &prt);
317 gp_set_aspect (int dev, double asp)
328 setlinestyle (int style)
330 if (style == state.linestyle)
333 state.linestyle = style;
338 // crt_line_style (crt.style);
342 setlinewidth (int wid)
344 state.linewidth = wid;
352 else if (dev & PRTDEV)
358 /*===========================================================*/
360 /*===========================================================*/
362 _sgp2_set_text ( SGP_ID cwin,
364 double height, /* size of character in NDC */
365 double textangle, /* text angle */
366 int font /* text font */
372 g2_set_font_size(cwin->g2_id, (height * cwin->pw_ysize));
374 height = clamp (height, 0.0, 1.0);
375 width = clamp (width, 0.0, 1.0);
376 /* textangle = textangle - (2 * PI * (int) (textangle / (2 * PI)));
379 cspec.height = height;
380 cspec.textangle = textangle;
383 if (textangle > - HALFPI / 2 && textangle < HALFPI / 2) {
385 cspec.textdir = XPLUS;
386 } else if (textangle > HALFPI / 2 && textangle < 3 * HALFPI / 2) {
387 cspec.updir = XMINUS;
388 cspec.textdir = YPLUS;
389 } else if (textangle > 3 * HALFPI / 2 && textangle < 5 * HALFPI / 2) {
390 cspec.updir = YMINUS;
391 cspec.textdir = XMINUS;
392 } else if (textangle > 5 * HALFPI / 2 && textangle < 7 * HALFPI / 2) {
394 cspec.textdir = YMINUS;
397 cspec.textdir = XPLUS;
400 if (cspec.updir == XMINUS || cspec.updir == XPLUS) {
406 crt.icwidth = (int) (width * crt.xsize + 0.5);
407 crt.icheight = (int) (height * crt.ysize + 0.5);
408 crt.icwidth = clamp (crt.icwidth, 8, crt.xsize);
409 crt.icheight = clamp (crt.icheight, 8, crt.ysize);
411 prt.icwidth = (int) (width * prt.xsize + 0.5);
412 prt.icheight = (int) (height * prt.ysize + 0.5);
413 prt.icwidth = clamp (prt.icwidth, 8, prt.xsize);
414 prt.icheight = clamp (prt.icheight, 8, prt.ysize);
418 settextclr (int fore, int back)
424 prt.cfore = clamp (fore, 0, prt.colormax);
433 state.foregnd = fore;
434 back = state.backgnd;
435 crtcolor (crt.mode, &fore, &back); /* set colors on crt */
437 prt.color = clamp (fore, 0, prt.colormax);
445 state.backgnd = back;
446 fore = state.foregnd;
447 crtcolor (crt.mode, &fore, &back);
451 * INITMARKER (<SYMBOL>)
453 * Sets the current marker symbol (cross, square, diamond..)
456 initmarker (int marker, int color)
458 if (marker > NMARKERS || marker < 0)
461 state.marktype = marker;
462 state.markcolor = color;
465 } /* end initmarker */
468 * SETCHARDIR ( <DIRECTION> )
470 * indicates in which direction a string should be printed, e.g.:
471 * direction = YPLUS -> print on the horizontal from left to right
472 * direction = YMINUS -> print upside-down characters from right to left
473 * direction = XMINUS -> print on the vertical from down to up
474 * direction = XPLUS -> print on the vertical from up to down
478 int direction /* direction flag */
482 if (direction != XPLUS &&
483 direction != XMINUS &&
484 direction != YPLUS &&
485 direction != YMINUS ) {
486 printf("Error in character direction: %d\n", direction);
489 cspec.textdir = direction;
490 charsize (cspec.width, cspec.height);
493 } /* end setchardir */
497 _sgp2_dev_text (SGP_ID cwin, char *message)
500 g2_string (cwin->g2_id, cwin->phys_curx, cwin->phys_cury, message);
504 /*===========================================================*/
505 /* terminate graphics to current device */
506 /* close any files, and output any buffers */
507 /*===========================================================*/
511 if (prt.open == TRUE) {
512 flushdevice (PRTDEV);
513 closedevice (PRTDEV);
517 if (crt.open == TRUE) {
518 closedevice (CRTDEV);
524 flushdevice (int dev)
527 // prtline (PRTTERM, 0, 0, 0, 0, 0, 0); /* print contents of printer buffer */