home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_07 / 8n07050a < prev    next >
Text File  |  1990-06-19  |  6KB  |  193 lines

  1.  
  2. /*  Program to Replace Print Screen Function  */
  3.  
  4. #include <stdio.h>
  5. #include <dos.h>
  6. #include <bios.h>
  7. char put_out(char character);
  8. char status();
  9. void printrow(int y,int screen);
  10.  
  11. int i, j, attr, buffer[80][2];
  12. unsigned char far *new_chars;
  13. char output1,output2;
  14.  
  15. void interrupt print_handler()
  16. {
  17.     put_out(0x02);   /*Enter graphics mode*/
  18.     put_out(0x4C);   /*Enter landscape mode*/
  19.     for (j=0; j<3; j++)
  20.     {
  21.         put_out(0x1B);
  22.         put_out(0x4F);
  23.         put_out(0x00);
  24.         put_out(0xD4);
  25.         put_out(0x00);
  26.         put_out(0x24);      
  27.         /*Set origin to row 228 and column 36*/
  28.         for (i=0; i<25; i++)
  29.             printrow(i,j);
  30.         if (j<2)
  31.             put_out(0x0C);  /*Advance color panel*/
  32.     }
  33.     put_out(0x04);     /*Eject printed sheet*/
  34. }
  35.  
  36. char put_out(char character)
  37. {
  38.     char status=1;
  39.     int port;
  40.  
  41.     port = 0x378;
  42.     /*Send character to parallel port*/
  43.     outp(port,character);         
  44.     /*Wait for printer to be ready*/
  45.     while (!(status=inp(port+1) & 0x80));  
  46.     outp(port+2,0x0D);   /*Start output strobe*/
  47.     outp(port+2,0x0C);   /*End output strobe*/
  48. }
  49.  
  50.  
  51. void printrow(int y,int screen)
  52. {
  53.     int i,j,k,m,temp,ch,offset,tester;
  54.     char far *address;
  55.     unsigned char char_test,char_or;
  56.  
  57.     for (i=0; i<80; i++)
  58.     {
  59.         offset = 2*(80*y + i);
  60.         address = 0xB8000000L + offset;
  61.         attr = *(address+1);     /*get attribute*/
  62.         ch = *address;           /*get character*/
  63.         buffer[i][0] = ch;     /*character to first buffer*/
  64.         temp = attr & 0x07;
  65.         buffer[i][1] = 0;
  66.         if ((screen == 0) && ((temp%2) == 0))
  67.             buffer[i][1] = 1;
  68.         if ((screen == 2) && (temp <4))
  69.             buffer[i][1] = 1;
  70.         if ((screen == 1) && ((temp == 0) || (temp == 1) ||
  71.             (temp == 4) || (temp == 5)))
  72.             buffer[i][1] = 1;
  73.         temp = (attr & 0x70)>>4;
  74.         if ((screen == 0) && ((temp%2) == 0))
  75.             buffer[i][1] += 2;
  76.         if ((screen == 2) && (temp <4))
  77.             buffer[i][1] += 2;
  78.         if ((screen == 1) && ((temp == 0) || (temp == 1) ||
  79.             (temp == 4) || (temp == 5)))
  80.             buffer[i][1] += 2; /*set 2nd buffer to show printing */
  81.                                /*of foreground and background */
  82.     }
  83.  
  84.     for (i=0; i<14; i++)
  85.     {
  86.         for (k=0; k<3; k++)
  87.         {
  88.             put_out(0x1B);
  89.             put_out(0x4B);    /*Raster data follows*/
  90.             put_out(0x00);
  91.             put_out(0xA0);   /*160 bytes to be output*/
  92.             for (j=0; j<80; j++)
  93.             {
  94.                 /*determine what bits to set for*/
  95.                 /*correct color*/
  96.                 switch(buffer[j][1])    
  97.                 {
  98.                 case 0:     /*Color not printed*/
  99.                         put_out(0x00);
  100.                         put_out(0x00);
  101.                         break;
  102.                 case 1:     /*Foreground on ly printed*/
  103.                         output1 = 0x00;
  104.                         output2 = 0x00;
  105.                         tester = 0;
  106.                         for (m=0; m<4; m++)
  107.                         {
  108.                             char_test = 0x80 >> m;
  109.                             char_or = 0xC0 >> tester;
  110.                             if ((*(new_chars+buffer[j][0]*14+i) &
  111.                                 char_test) != 0)
  112.                             output1 = output1 | char_or;
  113.                             tester += 2;
  114.                         }
  115.                         tester = 0;
  116.                         for (m=0; m<4; m++)
  117.                         {
  118.                             char_test = 0x80 >> (m+4);
  119.                             char_or = 0xC0 >> tester;
  120.                             if ((*(new_chars+buffer[j][0]*14+i) &
  121.                                 char_test) != 0)
  122.                             output2 = output2 | char_or;
  123.                             tester += 2;
  124.                         }
  125.                         put_out(output1);
  126.                         put_out(output2);
  127.                         break;
  128.                 case 2:     /*Background only printed*/
  129.                         output1 = 0x00;
  130.                         output2 = 0x00;
  131.                         tester = 0;
  132.                         for (m=0; m<4; m++)
  133.                         {
  134.                             char_test = 0x80 >> m;
  135.                             char_or = 0xC0 >> tester;
  136.                             if ((*(new_chars+buffer[j][0]*14+i) &
  137.                                 char_test) == 0)
  138.                             output1 = output1 | char_or;
  139.                             tester += 2;
  140.                         }
  141.                         tester = 0;
  142.                         for (m=0; m<4; m++)
  143.                         {
  144.                             char_test = 0x80 >> (m+4);
  145.                             char_or = 0xC0 >> tester;
  146.                             if ((*(new_chars+buffer[j][0]*14+i) &
  147.                                 char_test) == 0)
  148.                             output2 = output2 | char_or;
  149.                             tester += 2;
  150.                         }
  151.                         put_out(output1);
  152.                         put_out(output2);
  153.                         break;
  154.                 case 3:     /*Solid color printed*/
  155.                         put_out(0xFF);
  156.                         put_out(0xFF);
  157.                         break;
  158.                 }
  159.             }
  160.         }
  161.     }
  162. }
  163.  
  164. main()
  165. {
  166.     char far *address;
  167.     unsigned char check;
  168.     union REGS reg;
  169.     struct SREGS inreg;
  170.     address =  0x00000017;
  171.     check = *address;
  172.     if (check == 0xF0)  /*Check if still address in ROM BIOS*/
  173.     {
  174.         setvect(5,print_handler);  /*Replace interrupt address*/
  175.                                    /*with that of print_handler*/
  176.  
  177.         _BH = 2;
  178.         _AH = 0x11;
  179.         _AL = 0x30;
  180.         geninterrupt(0x10);  /*Get address of character table*/
  181.         new_chars = (unsigned char far *) (_ES*0x10000 +_BP);
  182.         printf("\nText Screen Printing Routine for"
  183.              " PlotMaster Installed\n");
  184.  
  185.         keep(0,0x200);   /*Terminate and stay resident*/
  186.     }
  187.     else
  188.         printf("\nAlternate Print Screen Routine Has"
  189.             " Already Been Installed\n");
  190.  
  191. }
  192.  
  193.