home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / ega / egapaint.arc / PRINTSCR.C < prev   
Text File  |  1988-05-26  |  6KB  |  214 lines

  1. /***********************************************************
  2.  *                                                           *
  3.  *               PRINT SCREEN UTILITY for Paint            *
  4.  *                                                           *
  5.  *  This was designed for an ALPS 218 seies printer        *
  6.  *   using EPSON emulation.  I do not know how well        *
  7.  *   it will work with other color printers, but it's      *
  8.  *   good for guidelines.                                   *
  9.  *                                                           *
  10.  ***********************************************************/
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <dos.h>
  15. #include <conio.h>
  16. #include <graphics.h>
  17.  
  18. #define WIDTH 80L
  19. #define XMAX 638
  20. #define YMAX 349
  21. #define XMIN 5
  22. #define YMIN 0
  23. #define CHARSOUT 800
  24.  
  25.  
  26. /* set up buffers for each of the colors.  The leading chars set up the
  27.    color.  'C' just assigns memory for the rest of the array
  28. */
  29.  
  30. static unsigned char black_buf[9+CHARSOUT] = {' ',' ',0x1b,'r','0',0x1b,'K',0x5e,0x1};
  31. static unsigned char magenta_buf[9+CHARSOUT] = {' ',' ',0x1b,'r','1',0x1b,'K',0x5e,0x1};
  32. static unsigned char blue_buf[9+CHARSOUT] = {' ',' ',0x1b,'r','2',0x1b,'K',0x5e,0x1};
  33. static unsigned char violet_buf[9+CHARSOUT] = {' ',' ',0x1b,'r','3',0x1b,'K',0x5e,0x1};
  34. static unsigned char yellow_buf[9+CHARSOUT] = {' ',' ',0x1b,'r','4',0x1b,'K',0x5e,0x1};
  35. static unsigned char orange_buf[9+CHARSOUT] = {' ',' ',0x1b,'r','5',0x1b,'K',0x5e,0x1};
  36. static unsigned char green_buf[9+CHARSOUT] = {' ',' ',0x1b,'r','6',0x1b,'K',0x5e,0x1};
  37.  
  38. /* I nuked off the last line of pins to improve symmetry.  I haven't
  39.    seen any ill effects
  40. */
  41.  
  42.  
  43. /* char tank[] = {' ',' ',0x1b,'A',0x8,'\0'};  */
  44. char tank[] = {' ',' ',0x1b,'A',0x7,'\0'};
  45.  
  46. char put_out(char character);
  47.  
  48. void printscr(int reverse)
  49. {
  50.     int x = XMAX, y, i;
  51.     unsigned char mask;
  52.     int c;
  53.  
  54.     /* set flags to see if any data is on the line for that color */
  55.  
  56.     char k_flag, m_flag, b_flag, v_flag, y_flag, o_flag, g_flag;
  57.  
  58.     fputs("\r", stdprn);
  59.     fputs("\n", stdprn);
  60.  
  61.     fputs(tank,stdprn);
  62.  
  63.     fputs("\r", stdprn);
  64.     fputs("\n", stdprn);
  65.  
  66.     while(x > 4) {
  67.         if(kbhit()) {
  68.             fputs("\0x1bA\0x9", stdprn);
  69.             getch();
  70.             break;
  71.         }
  72.  
  73.         /* clear the buffers and flags */
  74.  
  75.         for(i = 9; i < CHARSOUT + 9; i++) black_buf[i] = 0;
  76.         for(i = 9; i < CHARSOUT + 9; i++) magenta_buf[i] = 0;
  77.         for(i = 9; i < CHARSOUT + 9; i++) blue_buf[i] = 0;
  78.         for(i = 9; i < CHARSOUT + 9; i++) violet_buf[i] = 0;
  79.         for(i = 9; i < CHARSOUT + 9; i++) yellow_buf[i] = 0;
  80.         for(i = 9; i < CHARSOUT + 9; i++) orange_buf[i] = 0;
  81.         for(i = 9; i < CHARSOUT + 9; i++) green_buf[i] = 0;
  82.         k_flag = m_flag = b_flag = v_flag = y_flag = o_flag = g_flag = 0;
  83.  
  84. /*        for(i = 0, mask = 0x80; i < 8; i++, mask >>= 1, x--) {  */
  85.         for(i = 0, mask = 0x80; i < 7; i++, mask >>= 1, x--) {
  86.             for(y = 0; y < YMAX; y++) {
  87.                 c = getpixel(x,y);     /* fill bit positions for the colors */
  88.                 switch(c) {
  89.                      case DARKGRAY:     black_buf[y+9] |= mask;
  90.                                     k_flag = 1;
  91.                                        break;
  92.                     case RED:         magenta_buf[y+9] |= mask;
  93.                                     m_flag = 1;
  94.                                     break;
  95.                     case LIGHTRED:  if(y & (x & 1) ? 0 : 1) {
  96.                                         magenta_buf[y+9] |= mask;
  97.                                         m_flag = 1;
  98.                                     }
  99.                                     break;
  100.                     case BLUE:          blue_buf[y+9] |= mask;
  101.                                     b_flag = 1;
  102.                                     break;
  103.                     case CYAN:        blue_buf[y+9] |= mask;
  104.                                     b_flag = 1;
  105.                                     break;
  106.                     case LIGHTBLUE:    if(y & (x & 1) ? 0 : 1) {
  107.                                         blue_buf[y+9] |= mask;
  108.                                         b_flag = 1;
  109.                                     }
  110.                                     break;
  111.                     case LIGHTCYAN:    if(y & (x & 1) ? 0 : 1) {
  112.                                         blue_buf[y+9] |= mask;
  113.                                         b_flag = 1;
  114.                                     }
  115.                                     break;
  116.                     case MAGENTA:    violet_buf[y+9] |= mask;
  117.                                     v_flag = 1;
  118.                                     break;
  119.                     case LIGHTMAGENTA: if(y & (x & 1) ? 0 : 1) {
  120.                                             violet_buf[y+9] |= mask;
  121.                                             v_flag = 1;
  122.                                        }
  123.                                     break;
  124.                     case YELLOW:    yellow_buf[y+9] |= mask;
  125.                                     y_flag = 1;
  126.                                     break;
  127.                     case BROWN:        orange_buf[y+9] |= mask;
  128.                                     o_flag = 1;
  129.                                     break;
  130.                     case GREEN:        green_buf[y+9] |= mask;
  131.                                     g_flag = 1;
  132.                                     break;
  133.                     case LIGHTGREEN: if(y & (x & 1) ? 0 : 1) {
  134.                                         green_buf[y+9] |= mask;
  135.                                         g_flag = 1;
  136.                                      }
  137.                                     break;
  138.                 }
  139.             }
  140.             if(x < XMIN) break;   /* MIN X to keep vestiges from appearing */
  141.         }
  142.         if(k_flag) {           /* print the color only if sometimg is there */
  143.             for(i = 0; i < CHARSOUT+9; i++)
  144.                 put_out(black_buf[i]);
  145.             fputs("\r", stdprn);
  146.         }
  147.         if(m_flag) {
  148.             for(i = 0; i < CHARSOUT+9; i++)
  149.                 put_out(magenta_buf[i]);
  150.             fputs("\r", stdprn);
  151.         }
  152.         if(b_flag) {
  153.             for(i = 0; i < CHARSOUT+9; i++)
  154.                 put_out(blue_buf[i]);
  155.             fputs("\r", stdprn);
  156.         }
  157.         if(v_flag) {
  158.             for(i = 0; i < CHARSOUT+9; i++)
  159.                 put_out(violet_buf[i]);
  160.             fputs("\r", stdprn);
  161.         }
  162.         if(y_flag) {
  163.             for(i = 0; i < CHARSOUT+9; i++)
  164.                 put_out(yellow_buf[i]);
  165.             fputs("\r", stdprn);
  166.         }
  167.         if(o_flag) {
  168.             for(i = 0; i < CHARSOUT+9; i++)
  169.                 put_out(orange_buf[i]);
  170.             fputs("\r", stdprn);
  171.         }
  172.         if(g_flag) {
  173.             for(i = 0; i < CHARSOUT+9; i++)
  174.                 put_out(green_buf[i]);
  175.             fputs("\r", stdprn);
  176.         }
  177.  
  178.  
  179.         fputs("\n", stdprn);
  180.  
  181.     }
  182.     fputs("\x0c", stdprn);
  183.     fflush(stdprn);            /* print the last line */
  184. }
  185.  
  186. /* not used - but someday ??? */
  187.  
  188. char status(void)
  189. {
  190.     union REGS regs;
  191.  
  192.     regs.h.ah = 2;
  193.     regs.x.dx = 0;
  194.     int86(0x17, ®s, ®s);
  195.     return(regs.h.ah & 0x80);
  196. }
  197.  
  198. /* out put to the printer */
  199.  
  200. char put_out(char character)
  201. {
  202.     union REGS regs;
  203.  
  204.     regs.h.ah = 0;
  205.     regs.h.al = character;
  206.     regs.x.dx = 0;
  207.     int86(0x17, ®s, ®s);
  208.     return(regs.h.ah);
  209. }
  210.  
  211.  
  212.  
  213.  
  214.