home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / MBUG / MBUG035.ARC / GRAFUTIL.C < prev    next >
Text File  |  1979-12-31  |  3KB  |  175 lines

  1.  
  2. /********************************************************/
  3. /*                            */
  4. /*    Utility Routines for MX-80 Bit-Plot Graphics    */
  5. /*                            */
  6. /*    Don Brittain        3 January 1983        */
  7. /*                            */
  8. /********************************************************/
  9.  
  10. #define HSIZE 320
  11. #define VSIZE 328
  12. #define NO 0
  13. #define YES 1
  14. #define LIST 5
  15. #define ESC 27
  16.  
  17. short grafbuf[HSIZE][VSIZE/8];        /* MUST be EXTERNAL */
  18. extern int horsize, versize, flag;
  19. extern int pixplot(), unpixplot();
  20.  
  21.  
  22. init(h,v)    /* Clears or fills the user area of the graph matrix */
  23.         /* depending on the status of the external var "flag" */
  24. int h,v;
  25.  
  26. {
  27.     register i, j;
  28.     int fill=0;
  29.  
  30.     if(flag==NO) fill=255;
  31.     v=(v+7)/8;
  32.     for(j=1; j<v; j++)
  33.     for(i=0; i<h; i++)
  34.         grafbuf[i][j]=fill;
  35.     if(flag)
  36.     for(i=0; i<h; i++)
  37.         grafbuf[i][0]=0;
  38.     else            /* Cluge resulting because the graph is */
  39.     {            /* defined bit-wise, but initializing */
  40.     switch(versize%8) {    /* is much quicker byte-wise */
  41.         case 1 :
  42.         fill=1;
  43.         break;
  44.         case 2 :
  45.         fill=3;
  46.         break;
  47.         case 3 :
  48.         fill=7;
  49.         break;
  50.         case 4 :
  51.             fill=15;
  52.             break;
  53.         case 5 :
  54.         fill=31;
  55.         break;
  56.         case 6 :
  57.         fill=63;
  58.         break;
  59.         case 7 :
  60.         fill=127;
  61.         break;
  62.         case 0 :
  63.         fill=255;    }
  64.     for(i=0; i<h; i++)
  65.         grafbuf[i][0]=fill;
  66.     }
  67.     flag=YES;        /* functions that use flag always reset it */
  68. }
  69.  
  70.  
  71. grafprnt(n)    /* routine to send the graph RAM image to the MX-80 */
  72.  
  73. int n;
  74.  
  75. {
  76.     register i, j;
  77.     int v;
  78.     
  79.     setline(8);
  80.     clmar(n);
  81.     v=(versize+7)/8;
  82.     for(j=0; j<v; j++)    {
  83.     bitmode(horsize);
  84.     for(i=0; i<horsize; i++)
  85.         bdos(LIST, grafbuf[i][j]);
  86.     clmar(n);    }
  87.     setline(12);
  88. }
  89.  
  90. border()    /* puts a border around the graph */
  91. {
  92.     register i;
  93.     int rside, top;
  94.     
  95.     rside=horsize-1;
  96.     top=versize-1;
  97.     
  98.     if(flag)
  99.     {
  100.     for(i=0; i<horsize; i++)    {
  101.         pixplot(i,0);
  102.         pixplot(i,top);        }
  103.     for(i=0; i<versize; i++)    {
  104.         pixplot(0,i);
  105.         pixplot(rside,i);        }
  106.     }   
  107.  else
  108.     {
  109.     for(i=0; i<horsize; i++)    {
  110.         unpixplot(i,0);
  111.         unpixplot(i,top);        }
  112.     for(i=0; i<versize; i++)    {
  113.         unpixplot(0,i);
  114.         unpixplot(rside,i);        }
  115.     }
  116.     flag=YES;
  117. }
  118.  
  119.  
  120. setline(n)    /* routine to set the line-spacing on the MX-80 */
  121. int n;
  122. {
  123.     bdos(LIST,ESC);
  124.     bdos(LIST,'A');
  125.     bdos(LIST,n);
  126. }
  127.  
  128. bitmode(n)    /* sets n chars of dot graphics (480 dots/line) on MX-80 */
  129. int n;
  130. {
  131.     bdos(LIST,ESC);
  132.     bdos(LIST,'K');
  133.     if(n<256)
  134.     {
  135.     bdos(LIST,n);
  136.     bdos(LIST,0);
  137.     }
  138.     else
  139.     {
  140.     bdos(LIST,n-256);
  141.     bdos(LIST,1);
  142.     }
  143. }
  144.  
  145.  
  146. crlf(n)        /* printer carriage-return-linefeed */
  147. int n;
  148. {
  149. int i;
  150. for(i=0; i<n; i++)
  151.     {
  152.     bdos(LIST,13);
  153.     bdos(LIST,10);
  154.     }
  155. }
  156.  
  157.  
  158. margin(n)    /* printer left-margin */
  159. int n;
  160. {
  161. int i;
  162. for(i=0; i<n; i++)
  163.     bdos(LIST,' ');
  164. }
  165.  
  166.  
  167. clmar(n)    /* single CRLF then n-space margin to printer */
  168. int n;
  169. {
  170.     crlf(1);
  171.     margin(n);
  172. }
  173.     
  174.  
  175.