home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / unixpc.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  16.8 KB  |  616 lines

  1. /*
  2.  * $Id: unixpc.trm,v 1.7 1995/12/20 21:48:18 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - unixpc.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993   
  9.  *
  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.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *  Unix PC's (ATT 3b1)
  26.  *
  27.  * AUTHORS
  28.  *    John Campbell
  29.  * 
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  * 
  32.  */
  33.  
  34. /*
  35. >From: John Campbell (...!arizona!naucse!jdc)
  36.  
  37. I originally ported gnuplot to the ATT 3b1 (ATT7300) on 12/4/88, and then
  38. added the minimal code needed to bring it up to 2.0 level on 1/28/90.  The 
  39. 3b1, as I view it, is a 720x300 bitmapped, monochrome display (often people 
  40. don't use the top 12 scan lines and thus the effective size is 720x288).  I 
  41. tried to maximize the size of the graph area, by using these top 12 lines 
  42. (normally reserved) and set up a signal handler to restore them upon exit, 
  43. abort, etc.
  44.  
  45. Line styles were "fudged" (they do not know the aspect ratio).  The same
  46. line style may look different depending upon the slope of the curve.  Due to
  47. this only 4 line styles were implemented.  While more line types are possible,
  48. the current styles were chosen as distinguishable.
  49.  
  50. The 3b1 has 4 "special" rows at the bottom that I could not use in graphics
  51. mode.  It has been suggested that we use these lines for command prompting.
  52. Others have requested that we have a graphics window and a command window.
  53. My experience with gnuplot only includes relatively dumb graphics devices--
  54. hence gnuplot "looks and feels" normal to me the way I implemented it.
  55. I welcome either of these changes from someone else, however.
  56. */
  57.  
  58. /*
  59.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  60.  */
  61.  
  62. #ifndef GOT_DRIVER_H
  63. #include "driver.h"
  64. #endif
  65.  
  66. #ifdef TERM_REGISTER
  67. register_term(unixpc)
  68. #endif
  69.  
  70. #ifdef TERM_PROTO
  71. TERM_PUBLIC void uPC_init __P((void));
  72. TERM_PUBLIC void uPC_graphics __P((void));
  73. TERM_PUBLIC void uPC_text __P((void));
  74. TERM_PUBLIC void uPC_linetype __P((int linetype));
  75. TERM_PUBLIC void uPC_move __P((unsigned int x, unsigned int y));
  76. TERM_PUBLIC void uPC_vector __P((unsigned int x, unsigned int y));
  77. TERM_PUBLIC void uPC_put_text __P((unsigned int x, unsigned int y, char str[]));
  78. TERM_PUBLIC int uPC_text_angle __P((int ang));
  79. TERM_PUBLIC void uPC_reset __P((void));
  80. #define uPC_XMAX 720
  81. #define uPC_YMAX 300
  82. #define uPC_VCHAR FNT5X9_VCHAR
  83. #define uPC_HCHAR FNT5X9_HCHAR
  84. #define uPC_VTIC  uPC_VCHAR/2  /* Was 8  */
  85. #define uPC_HTIC  uPC_HCHAR    /* Was 12 */
  86. #endif /* TERM_PROTO */
  87.  
  88. #ifndef TERM_PROTO_ONLY
  89. #ifdef TERM_BODY
  90. void uPC_fixwind __P((int signo));
  91. void uPC_putc __P((unsigned int x, unsigned int y, int c, int angle));
  92. void uPC_plot_word __P((unsigned short *a, unsigned short b));
  93. #include <sys/window.h>   /* Started with tam.h--too much trouble. */
  94. #include <sys/signal.h>
  95. #include <errno.h>
  96.  
  97. #define uPC_HIGH_BIT    (0x8000)
  98.  
  99. typedef unsigned short Scr_type;
  100. typedef unsigned char Scr_kluge;
  101.  
  102.  
  103. #define uPC_XSIZE       45 /* Short ints. */
  104. #define uPC_YSIZE uPC_YMAX
  105.  
  106. Scr_type uPC_display[uPC_YSIZE][uPC_XSIZE];
  107. int uPC_width = 2*uPC_XSIZE;
  108. int uPC_sx=0, uPC_sy=0;
  109. int uPC_cur_linetype=0;
  110. int uPC_angle = 0;
  111. unsigned short uPC_raster_count=0;
  112. static Scr_type lookup[] = {
  113.       0x0001, 0x0002, 0x0004, 0x0008,
  114.       0x0010, 0x0020, 0x0040, 0x0080,
  115.       0x0100, 0x0200, 0x0400, 0x0800,
  116.       0x1000, 0x2000, 0x4000, 0x8000,
  117.    };
  118.  
  119. #define uPC_XLAST (uPC_XMAX - 1)
  120. #define uPC_YLAST (uPC_YMAX - 1)
  121.  
  122.  
  123. static struct urdata uPC_ur = {(unsigned short *)uPC_display, 2*uPC_XSIZE, 0, 0,
  124.                            0, 0, 0, 0, uPC_XMAX, uPC_YMAX, SRCSRC, DSTOR, 0};
  125.  
  126. #define IfErrOut(e1,e2,s1,s2) if (e1 e2) {\
  127. fprintf(stderr, "%s:: %s %s\n", sys_errlist[errno], s1, s2);\
  128. uPC_fixwind(0);\
  129. exit(-1);}
  130.  
  131. TERM_PUBLIC void uPC_init()
  132. {
  133. /* This routine will ioctl to change 0 size */
  134.    int i;
  135.    struct uwdata uw;
  136.    int uPC_fixwind();
  137.    short gw;
  138.  
  139. /* Check that we are on the bitmapped window. */
  140.    if (iswind() != 0) {
  141.       fprintf (stderr, "Sorry--must run from the bitmapped terminal\n");
  142.       exit(-1);
  143.    }
  144.    for (i=1; i<=16; i++) {
  145.       if (i != SIGINT && i != SIGFPE)  /* Two are caught in plot.c */
  146.          signal (i, uPC_fixwind);
  147.    }
  148.  
  149. /* Increase the screen size */
  150.    uw.uw_x = 0;
  151.    uw.uw_y = 0;   /* Leave room for top status line. */
  152.    uw.uw_width = uPC_XMAX;      /* 720 */
  153.    uw.uw_height = uPC_YMAX;     /* 288 normal--we clobber 12 (top row)*/
  154.    uw.uw_uflags = 1;         /* Creates with no border */
  155.  
  156.    IfErrOut (ioctl(1, WIOCSETD, &uw), <0, "ioctl failed on", "WIOCSETD");
  157. }
  158.  
  159.  
  160. TERM_PUBLIC void uPC_graphics()
  161. {
  162. /* This routine will clear the uPC_display buffer and window. */
  163.    register Scr_type *j;
  164.    register int i;
  165.  
  166.    j = (Scr_type *)uPC_display;
  167.    i = uPC_YSIZE*uPC_XSIZE + 1;
  168.  
  169.    while (--i)
  170.       *j++ = 0;
  171. /*
  172.    Position the cursor to the bottom of the screen so when we come back to
  173.    text mode we are just below the graph.
  174. */
  175.    printf ("\033[25;1H");
  176.  
  177.    uPC_ur.ur_dstop = DSTSRC;   /* replace (clear screen). */
  178.    IfErrOut (ioctl(1, WIOCRASTOP, &uPC_ur), <0,
  179.       "ioctl failed", "WIOCRASTOP");
  180.    uPC_ur.ur_dstop = DSTOR;   /* Or in (show text) */
  181. }
  182.  
  183.  
  184. TERM_PUBLIC void uPC_text()
  185. {
  186. /* This routine will flush the display. */
  187.  
  188.    IfErrOut (ioctl(1, WIOCRASTOP, &uPC_ur), <0,
  189.       "ioctl failed", "WIOCRASTOP");
  190. }
  191.  
  192.  
  193. TERM_PUBLIC void uPC_linetype(linetype)
  194. int linetype;
  195. {
  196. /* This routine records the current linetype. */
  197.    if (uPC_cur_linetype != linetype) {
  198.       uPC_raster_count = 0;
  199.       uPC_cur_linetype = linetype;
  200.    }
  201. }
  202.  
  203.  
  204. TERM_PUBLIC void uPC_move(x,y)
  205. unsigned int x,y;
  206. {
  207. /* This routine just records x and y in uPC_sx, uPC_sy */
  208.    uPC_sx = x;
  209.    uPC_sy = y;
  210. }
  211.  
  212.  
  213. /* Was just (*(a)|=(b)) */
  214. #define uPC_PLOT(a,b)   (uPC_cur_linetype != 0 ? uPC_plot_word (a,b) :\
  215.                                 (*(a)|=(b)))
  216.  
  217. void uPC_plot_word(a,b)
  218. Scr_type *a, b;
  219. /*
  220.    Weak attempt to make line styles.  The real problem is the aspect
  221.    ratio.  This routine is called only when a bit is to be turned on in
  222.    a horizontal word.  A better line style routine would know something
  223.    about the slope of the line around the current point (in order to
  224.    change weighting).
  225.  
  226.    This yields 3 working linetypes plus a usable axis line type.
  227. */
  228. {
  229. /* Various line types */
  230.    switch (uPC_cur_linetype) {
  231.    case -1:
  232.    /* Distinguish between horizontal and vertical axis. */
  233.       if (uPC_sx > uPC_XMAX/8 && uPC_sx < 7*uPC_XMAX/8) {
  234.       /* Fuzzy tolerance because we don't know exactly where the y axis is */
  235.          if (++uPC_raster_count % 2 == 0) *(a) |= b;
  236.       }
  237.       else {
  238.       /* Due to aspect ratio, take every other y pixel and every third x. */
  239.          *(a) |= (b & 0x9999);
  240.       }
  241.    break;
  242.    case 1:
  243.    case 5:
  244.    /* Make a |    |----|    |----| type of line. */
  245.       if ((1<<uPC_raster_count) & 0xF0F0) *(a) |= b;
  246.       if (++uPC_raster_count > 15) uPC_raster_count = 0;
  247.    break;
  248.    case 2:
  249.    case 6:
  250.    /* Make a |----|----|----|--- |    | type of line. */
  251.       if ((1<<uPC_raster_count) & 0x0EFFF) *(a) |= b;
  252.       if (++uPC_raster_count > 19) uPC_raster_count = 0;
  253.    break;
  254.    case 3:
  255.    case 7:
  256.    /* Make a | -  | -  | -  | -  | type of line. */
  257.       if ((1<<uPC_raster_count) & 0x4444) *(a) |= b;
  258.       if (++uPC_raster_count > 15) uPC_raster_count = 0;
  259.    break;
  260.    case 4:
  261.    case 8:
  262.    default:
  263.       *(a) |= b;
  264.    break;
  265.    }
  266. }
  267.  
  268. TERM_PUBLIC void uPC_vector(x,y)
  269. unsigned int x,y;
  270. {
  271. /* This routine calls line with x,y */
  272.    int x1 = uPC_sx, y1=uPC_sy, x2 = x, y2 = y;
  273.    register int  c, e, dx, dy, width;
  274.    register Scr_type mask, *a;
  275.  
  276. /* Record new sx, sy for next call to the vector routine. */
  277.    uPC_sx = x2;
  278.    uPC_sy = y2;
  279.  
  280.    a = &uPC_display[(uPC_YSIZE - 1) - y1][x1 >> 4];
  281.    mask = lookup[x1 & 0x0f];
  282.    width = uPC_width;
  283.  
  284.    if ((dx = x2 - x1) > 0) {
  285.       if ((dy = y2 - y1) > 0) {
  286.          if (dx > dy) {         /* dx > 0, dy > 0, dx > dy */
  287.             dy <<= 1;
  288.             e = dy - dx;
  289.             c = dx + 2;
  290.             dx <<= 1;
  291.  
  292.             while (--c) {
  293.                uPC_PLOT(a, mask);
  294.                if (e >= 0) {
  295.                   (Scr_kluge *)a -= width;
  296.                   e -= dx;
  297.                }
  298.                if (mask & uPC_HIGH_BIT) {
  299.                   mask = 1;
  300.                   a++;
  301.                } else
  302.                   mask <<= 1;
  303.                e += dy;
  304.             }
  305.          } else {            /* dx > 0, dy > 0, dx <= dy */
  306.             dx <<= 1;
  307.             e = dx - dy;
  308.             c = dy + 2;
  309.             dy <<= 1;
  310.  
  311.             while (--c) {
  312.                uPC_PLOT(a, mask);
  313.                if (e >= 0) {
  314.                   if (mask & uPC_HIGH_BIT) {
  315.                      mask = 1;
  316.                      a++;
  317.                   } else
  318.                      mask <<= 1;
  319.                   e -= dy;
  320.                }
  321.                (Scr_kluge *)a -= width;
  322.                e += dx;
  323.             }
  324.          }
  325.       } else {
  326.          dy = -dy;
  327.          if (dx > dy) {         /* dx > 0, dy <= 0, dx > dy */
  328.             dy <<= 1;
  329.             e = dy - dx;
  330.             c = dx + 2;
  331.             dx <<= 1;
  332.  
  333.             while (--c) {
  334.                uPC_PLOT(a, mask);
  335.                if (e >= 0) {
  336.                   (Scr_kluge *)a += width;
  337.                   e -= dx;
  338.                }
  339.                if (mask & uPC_HIGH_BIT) {
  340.                   mask = 1;
  341.                   a++;
  342.                } else
  343.                   mask <<= 1;
  344.                e += dy;
  345.             }
  346.          } else {            /* dx > 0, dy <= 0, dx <= dy */
  347.             dx <<= 1;
  348.             e = dx - dy;
  349.             c = dy + 2;
  350.             dy <<= 1;
  351.  
  352.             while (--c) {
  353.                uPC_PLOT(a, mask);
  354.                if (e >= 0) {
  355.                   if (mask & uPC_HIGH_BIT) {
  356.                      mask = 1;
  357.                      a++;
  358.                   } else
  359.                      mask <<= 1;
  360.                   e -= dy;
  361.                }
  362.                (Scr_kluge *)a += width;
  363.                e += dx;
  364.             }
  365.          }
  366.       }
  367.    } else {
  368.       dx = -dx;
  369.       if ((dy = y2 - y1) > 0) {
  370.          if (dx > dy) {         /* dx <= 0, dy > 0, dx > dy */
  371.             dy <<= 1;
  372.             e = dy - dx;
  373.             c = dx + 2;
  374.             dx <<= 1;
  375.  
  376.             while (--c) {
  377.                uPC_PLOT(a, mask);
  378.                if (e >= 0) {
  379.                   (Scr_kluge *)a -= width;
  380.                   e -= dx;
  381.                }
  382.                if (mask & 1) {
  383.                   mask = uPC_HIGH_BIT;
  384.                   a--;
  385.                } else
  386.                   mask >>= 1;
  387.                e += dy;
  388.             }
  389.          } else {            /* dx <= 0, dy > 0, dx <= dy */
  390.             dx <<= 1;
  391.             e = dx - dy;
  392.             c = dy + 2;
  393.             dy <<= 1;
  394.  
  395.             while (--c) {
  396.                uPC_PLOT(a, mask);
  397.                if (e >= 0) {
  398.                   if (mask & 1) {
  399.                      mask = uPC_HIGH_BIT;
  400.                      a--;
  401.                   } else
  402.                      mask >>= 1;
  403.                   e -= dy;
  404.                }
  405.                (Scr_kluge *)a -= width;
  406.                e += dx;
  407.             }
  408.          }
  409.       } else {
  410.          dy = -dy;
  411.          if (dx > dy) {         /* dx <= 0, dy <= 0, dx > dy */
  412.             dy <<= 1;
  413.             e = dy - dx;
  414.             c = dx + 2;
  415.             dx <<= 1;
  416.  
  417.             while (--c) {
  418.                uPC_PLOT(a, mask);
  419.                if (e >= 0) {
  420.                   (Scr_kluge *)a += width;
  421.                   e -= dx;
  422.                }
  423.                if (mask & 1) {
  424.                   mask = uPC_HIGH_BIT;
  425.                   a--;
  426.                } else
  427.                   mask >>= 1;
  428.                e += dy;
  429.             }
  430.          } else {            /* dx <= 0, dy <= 0, dx <= dy */
  431.             dx <<= 1;
  432.             e = dx - dy;
  433.             c = dy + 2;
  434.             dy <<= 1;
  435.  
  436.             while (--c) {
  437.                uPC_PLOT(a, mask);
  438.                if (e >= 0) {
  439.                   if (mask & 1) {
  440.                      mask = uPC_HIGH_BIT;
  441.                      a--;
  442.                   } else
  443.                      mask >>= 1;
  444.                   e -= dy;
  445.                }
  446.                (Scr_kluge *)a += width;
  447.                e += dx;
  448.             }
  449.          }
  450.       }
  451.    }
  452. }
  453.  
  454.  
  455. #ifdef uPC_NOT_USED
  456. /* Added by Russell Lang, eln272v@monu1.cc.monash.oz
  457.    This placement to the nearest character cell worked, and I'm leaving
  458.    it here so the calculations involved won't be lost!  (jdc)
  459. */
  460. TERM_PUBLIC void uPC_put_text(x,y,str)
  461. unsigned int x,y;
  462. char str[];
  463. {
  464. /* This routine puts the text at the cursor location nearest
  465.    to (x,y).  Obviously the exact postion would look better */
  466.  
  467. /* Just use the ANSI escape sequence CUP (iswind said that was ok!) */
  468.    printf ("\033[%d;%dH%s\033[25;1H", (int)(24-(y-uPC_VCHAR/2)*25/uPC_YMAX), 
  469.                 (int)(x*80/uPC_XMAX), str); 
  470.    fflush (stdout);
  471. }
  472. #endif
  473.  
  474.  
  475. TERM_PUBLIC void uPC_put_text(x,y,str)
  476. unsigned int x,y;
  477. char str[];
  478. {
  479.    if (uPC_angle == 1)
  480.       x += uPC_VCHAR/2;
  481.    else
  482.       y -= uPC_VCHAR/2;
  483.  
  484.    switch (uPC_angle) {
  485.       case 0:
  486.          for (; *str; ++str, x += uPC_HCHAR)
  487.             uPC_putc (x, y, *str, uPC_angle);
  488.       break;
  489.       case 1:
  490.          for (; *str; ++str, y += uPC_HCHAR)
  491.             uPC_putc (x, y, *str, uPC_angle);
  492.       break;
  493.    }
  494. }
  495.  
  496.  
  497. void uPC_putc (x, y, c, angle)
  498. unsigned int x, y;
  499. int c, angle;
  500. /*
  501.    Put a character at an x,y location in the bit map (using the fnt5x9
  502.    array.  This is mostly just copied from the bitmap.c driver.
  503. */
  504. {
  505.    int i, j, k;
  506.    register Scr_type mask, *a;
  507.    char_row fc;
  508.    unsigned int pixelon;
  509.  
  510.    i = c - ' ';
  511.    for (j=0; j<FNT5X9_VBITS; j++) {
  512.       fc = fnt5x9[i][j];
  513.       for (k=0; k<FNT5X9_HBITS; k++) {
  514.          pixelon = ((unsigned int)(fc))>>k & 1;
  515.          if (pixelon) {
  516.             switch (angle) {
  517.             case 0:
  518.                mask = lookup[x+k+1 & 0x0f];
  519.                a = &uPC_display[(uPC_YSIZE - 1) - (y+j)][(x+k+1) >> 4];
  520.             break;
  521.             case 1:
  522.                mask = lookup[x-j & 0x0f];
  523.                a = &uPC_display[(uPC_YSIZE - 1) - (y+k+1)][(x-j) >> 4];
  524.             break;
  525.             }
  526.             *(a) |= (mask);  /* see uPC_PLOT macro */
  527.          }
  528.       }
  529.    }
  530. }
  531.  
  532.  
  533. TERM_PUBLIC int uPC_text_angle (ang)
  534. int ang;
  535. {
  536.    uPC_angle = ang;
  537.    return TRUE;
  538. }
  539.  
  540.  
  541. TERM_PUBLIC void uPC_reset()
  542. {
  543. /* Reset window to normal size. */
  544.    uPC_fixwind (0);
  545. }
  546.  
  547.  
  548.  
  549. void uPC_fixwind(signo)
  550. int signo;
  551. {
  552.    static struct uwdata wreset = { 0, 12, 720, 288, 0x1};
  553.    struct utdata ut;
  554.  
  555. /* Reset the window to the right size. */
  556.    ioctl(1, WIOCSETD, &wreset);   /* 0, not wncur here! */
  557.  
  558. /* Scroll the screen once. (avoids typing over the same line) */
  559.    fprintf (stderr, "\n");
  560.  
  561.    if (signo) {
  562.       if (signo == SIGILL || signo == SIGTRAP || signo == SIGPWR)
  563.          signal (signo, SIG_DFL);
  564.       kill (0,signo);  /* Redo the signal (as if we never trapped it). */
  565.    }
  566. }
  567. #endif /* TERM_BODY */
  568.  
  569. #ifdef TERM_TABLE
  570.  
  571. TERM_TABLE_START(unixpc_driver)
  572.     "unixpc", "AT&T 3b1 or AT&T 7300 Unix PC",
  573.        uPC_XMAX, uPC_YMAX, uPC_VCHAR, uPC_HCHAR, 
  574.        uPC_VTIC, uPC_HTIC, options_null, uPC_init, uPC_reset, 
  575.        uPC_text, null_scale, uPC_graphics, uPC_move, uPC_vector,
  576.        uPC_linetype, uPC_put_text, uPC_text_angle, 
  577.        null_justify_text, line_and_point, do_arrow, set_font_null
  578. TERM_TABLE_END(unixpc_driver)
  579.  
  580. #undef LAST_TERM
  581. #define LAST_TERM unixpc_driver
  582.  
  583. #endif /* TERM_TABLE */
  584. #endif /* TERM_PROTO_ONLY */
  585.  
  586. /*
  587.  * NAME: unixpc
  588.  *
  589.  * OPTIONS: none
  590.  *
  591.  * SUPPORTS: AR&T 3b1 or AT&T 7300 Unix PC
  592.  *
  593.  * Further Info: from top of file
  594. I originally ported gnuplot to the ATT 3b1 (ATT7300) on 12/4/88, and then
  595. added the minimal code needed to bring it up to 2.0 level on 1/28/90.  The 
  596. 3b1, as I view it, is a 720x300 bitmapped, monochrome display (often people 
  597. don't use the top 12 scan lines and thus the effective size is 720x288).  I 
  598. tried to maximize the size of the graph area, by using these top 12 lines 
  599. (normally reserved) and set up a signal handler to restore them upon exit, 
  600. abort, etc.
  601.  
  602. Line styles were "fudged" (they do not know the aspect ratio).  The same
  603. line style may look different depending upon the slope of the curve.  Due to
  604. this only 4 line styles were implemented.  While more line types are possible,
  605. the current styles were chosen as distinguishable.
  606.  
  607. The 3b1 has 4 "special" rows at the bottom that I could not use in graphics
  608. mode.  It has been suggested that we use these lines for command prompting.
  609. Others have requested that we have a graphics window and a command window.
  610. My experience with gnuplot only includes relatively dumb graphics devices--
  611. hence gnuplot "looks and feels" normal to me the way I implemented it.
  612. I welcome either of these changes from someone else, however.
  613.  
  614. John Campbel
  615.  *
  616.  */