home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / web2c / mf / MFwindow / tek.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-28  |  3.2 KB  |  140 lines

  1. /* Tektronix terminal window interface for Metafont.  */
  2.  
  3. #define    EXTERN    extern
  4. #include "../mfd.h"
  5.  
  6. #ifdef TEKTRONIXWIN        /* Whole file */
  7.  
  8. #define FORMFEED    12
  9. #define ESCAPE        27
  10. #define GS        29
  11. #define US        31
  12. #define TRUE        1
  13. #define FALSE        0
  14. #define WIDTH        1024    /* Screen width */
  15. #define HEIGHT        780    /* Screen height */
  16. #define WIDTHINBYTES    (WIDTH/8)   /* Only works if WIDTH % 8 == 0 */
  17. #define SETBIT(row,col) screen_pixel[row*WIDTHINBYTES+col/8] |= 1 << 7-col%8
  18. #define CLEARBIT(row,col) screen_pixel[row*WIDTHINBYTES+col/8] &= \
  19.                 ~(1 << 7-col%8)
  20. #define ISSET(row,col) (screen_pixel[row*WIDTHINBYTES+col/8] & 1 << 7-col%8)
  21.  
  22. char    screen_pixel[WIDTHINBYTES*HEIGHT];
  23. char    zero_array[WIDTHINBYTES];
  24.  
  25. /* 
  26.  *    function init_screen: boolean;
  27.  *
  28.  *        Return true if window operations legal.
  29.  *        We always return true.
  30.  */
  31.  
  32. mf_tektronix_initscreen()
  33. {
  34.     bzero(zero_array, sizeof(zero_array));
  35.     return 1;
  36. }
  37.  
  38. /*
  39.  *    procedure updatescreen;
  40.  *
  41.  *        Print out the screen bitmap.
  42.  */
  43. mf_tektronix_updatescreen()
  44. {
  45.     int r, c, startc, makingline;
  46.  
  47.     printf("%c%c", ESCAPE, FORMFEED);
  48.     for (r = 0; r < HEIGHT; r++) {
  49.     makingline = FALSE;
  50.     if (bcmp(&screen_pixel[r*WIDTHINBYTES],zero_array,WIDTHINBYTES) == 0)
  51.         continue;
  52.     for (c = 0; c < WIDTH; c++) {
  53.         if (ISSET(r, c)) {
  54.         if (!makingline) {
  55.             makingline = TRUE;
  56.             startc = c;
  57.         }
  58.         } else if (makingline) {
  59.         putchar(GS);
  60.         putchar(0x20|((HEIGHT-1)-r)>>5);
  61.         putchar(0x60|((HEIGHT-1)-r)&0x1F);
  62.         putchar(0x20|startc>>5);
  63.         putchar(0x40|startc&0x1F);
  64.         putchar(0x60|((HEIGHT-1)-r)&0x1F); /* Don't send high y */
  65.         putchar(0x20|c>>5);
  66.         putchar(0x40|c&0x1F);
  67.         makingline = FALSE;
  68.         }
  69.     }
  70.     if (makingline)  {
  71.         putchar(GS);
  72.         putchar(0x20|((HEIGHT-1)-r)>>5);
  73.         putchar(0x60|((HEIGHT-1)-r)&0x1F);
  74.         putchar(0x20|startc>>5);
  75.         putchar(0x40|startc&0x1F);
  76.         putchar(0x60|((HEIGHT-1)-r)&0x1F); /* Don't send high y */
  77.         putchar(0x20|c>>5);
  78.         putchar(0x40|c&0x1F);
  79.     }
  80.     }
  81.     printf("%c%c%c%c%c", GS, 0x23, 0x66, 0x20, 0x40);
  82.     putchar(US);
  83.     fflush(stdout);
  84. }
  85.  
  86. /*
  87.  *    procedure blankrectangle(left, right, top, bottom: integer);
  88.  *
  89.  *        Blanks out a port of the screen.
  90.  */
  91. mf_tektronix_blankrectangle(left, right, top, bottom)
  92. screencol left, right;
  93. screenrow top, bottom;
  94. {
  95.     int    r, c;
  96.  
  97.     if (left == 0 && right == WIDTH && top == 0 && bottom == HEIGHT)
  98.     bzero(screen_pixel, sizeof(screen_pixel));
  99.     else 
  100.     for (r = top; r < bottom; r++)
  101.         for (c = left; c < right; c++)
  102.         CLEARBIT(r, c);
  103. }
  104.  
  105. /*
  106.  *    procedure paintrow(
  107.  *            row:        screenrow;
  108.  *            init_color:    pixelcolor;
  109.  *        var    trans_vector:    transspec;
  110.  *            vector_size:    screencol);
  111.  *
  112.  *        Paint "row" starting with color "init_color", up to next
  113.  *        transition specified by "transition_vector", switch colors,
  114.  *        and continue for "vector_size" transitions.
  115.  */
  116. mf_tektronix_paintrow(row, init_color, transition_vector, vector_size)
  117. screenrow   row;
  118. pixelcolor  init_color;
  119. transspec   transition_vector;
  120. screencol   vector_size;
  121. {
  122.     int k = 0;
  123.     int c = transition_vector[0];
  124.  
  125.     do {
  126.     k++;
  127.     do {
  128.         if (init_color)
  129.         SETBIT(row, c);
  130.         else
  131.         CLEARBIT(row, c);
  132.     } while (++c != transition_vector[k]);
  133.     init_color = !init_color;
  134.     } while (k != vector_size);
  135. }
  136.  
  137. #else
  138. int tek_dummy;
  139. #endif    /* TEKTRONIXWIN */
  140.