home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / graphics / draw630.lbr / DIABLO.LQB / DIABLO.LIB
Text File  |  1986-12-07  |  6KB  |  171 lines

  1. {*****************************************************************************}
  2. {*                                                                           *}
  3. {*                        DIABLO LIBRARY                                     *}
  4. {*                                                                           *}
  5. {*                    Written by Tim Meekins                                 *}
  6. {*                         April 7, 1986                                     *}
  7. {*                                                                           *}
  8. {*         This Turbo Pascal (tm) file contains all functions required       *}
  9. {*         to use a Diablo 630 printer or comapatible  like a plotter.       *}
  10. {*         An 8 1/2 by 11 sheet of paper is approx 500 x 500.                *}
  11. {*                                                                           *}
  12. {*         Version 1.00  - Initial release version. April 7, 1986.           *}
  13. {*         Version 1.01  - Added Diablo_reset procedure. April 8, 1986.      *}
  14. {*         Version 1.02  - Added DrawTo procedure. April 9, 1986.            *}
  15. {*         Version 1.10  - Added Circle procedure. June 24, 1986.            *}
  16. {*         Version 1.11  - Modified Move for fast -x change. June 28, 1986   *}
  17. {*         Version 1.12  - Removed Form Feed from init_diablo. July 13, 1986 *}
  18. {*         Version 1.20  - Added procedure poly, circle routine was          *}
  19. {*                         re-written for use with poly and quicker drawing  *}
  20. {*                         when doing small circles. August 1, 1986          *}
  21. {*                                                                           *}
  22. {*****************************************************************************}
  23.  
  24. CONST
  25.   formfeed = #12;                     { Form feed printer                     }
  26.   vmi      = #27#30;                  { Vertical Motion Index                 }
  27.   hmi      = #27#31;                  { Horizontal Motion Index               }
  28.   backup   = #8;                      { Backspace character                   }
  29.   linefeed = #10;                     { Line feed                             }
  30.   revfeed  = #27#10;                  { Reverse/Neagative Line feed           }
  31.   reset    = #27#13'P';               { RESET/Initialization                  }
  32.   cr       = #13;                     { Carriage return                       }
  33.  
  34. VAR
  35.   cur_x,cur_y : integer;              { Current cursor positions              }
  36.  
  37.  
  38. PROCEDURE init_diablo;                { Initialize printer for graphics       }
  39.   BEGIN
  40.     write(lst,hmi,#3);                { Set Horizontal Motion Index to 3      }
  41.     write(lst,vmi,#2);                { Set Vertical Motion Index to 2        }
  42.     cur_x := 0;
  43.     cur_y := 0
  44.   END;
  45.  
  46. PROCEDURE reset_diablo;               { Reset printer and form feed           }
  47.   BEGIN
  48.     write(lst,formfeed,reset)
  49.   END;
  50.  
  51. PROCEDURE dot;                        { Print a dot on the printer            }
  52.   BEGIN
  53.     write(lst,'.');
  54.     cur_x := cur_x + 1
  55.   END;
  56.  
  57. PROCEDURE up;                         { Move up                               }
  58.   BEGIN
  59.     write(lst,revfeed);
  60.     cur_y := cur_y - 1
  61.   END;
  62.  
  63. PROCEDURE down;                       { Move down                             }
  64.   BEGIN
  65.     write(lst,linefeed);
  66.     cur_y := cur_y + 1
  67.   END;
  68.  
  69. PROCEDURE right;                      { Move right                            }
  70.   BEGIN
  71.     write(lst,' ');
  72.     cur_x := cur_x + 1
  73.   END;
  74.  
  75. PROCEDURE left;                       { Move left                             }
  76.   BEGIN
  77.     write(lst,backup);
  78.     cur_x := cur_x - 1
  79.   END;
  80.  
  81. PROCEDURE move(x,y : integer);        { Move to position x,y                  }
  82.   BEGIN
  83.     WHILE (cur_y <> y) DO
  84.       BEGIN
  85.         IF y < cur_y THEN
  86.           up
  87.         ELSE
  88.           down
  89.       END;
  90.     IF (x<cur_x) and (cur_x-x>x) THEN
  91.       BEGIN
  92.         write(lst,cr);
  93.         cur_x := 0
  94.       END;
  95.     WHILE (cur_x <> x) DO
  96.       BEGIN
  97.         IF x < cur_x THEN
  98.           left
  99.         ELSE
  100.           right
  101.       END
  102.   END;
  103.  
  104. PROCEDURE plot(x,y : integer);        { Plot a dot at x,y                     }
  105.   BEGIN
  106.     move(x,y);
  107.     dot
  108.   END;
  109.  
  110. PROCEDURE draw(x1,y1,x2,y2 : integer);{ Draw a line from x1,y1 to x2,y2       }
  111.   VAR                                 { Based on the Quadrantal Digital       }
  112.     err,m,n,dx,dy : integer;          { Differential Analyzer.                }
  113.   BEGIN
  114.     err := 0;
  115.     m := 1;
  116.     n := 1;
  117.     dx := x2 - x1;
  118.     IF dx < 0 THEN
  119.       BEGIN
  120.         m := -1;
  121.         dx := -dx
  122.       END
  123.     ELSE
  124.       IF dx = 0 THEN
  125.         err := -1;
  126.     dy := y2 - y1;
  127.     IF dy < 0 THEN
  128.       BEGIN
  129.         n := -1;
  130.         dy := -dy
  131.       END;
  132.     WHILE (x1<>x2) OR (y1<>y2) DO
  133.       BEGIN
  134.         plot(x1,y1);
  135.         IF err < 0 THEN
  136.           BEGIN
  137.             y1 := y1 + n;
  138.             err := err + dx
  139.           END
  140.         ELSE
  141.           BEGIN
  142.             x1 := x1 + m;
  143.             err := err - dy
  144.           END
  145.       END
  146.   END;
  147.  
  148. PROCEDURE drawto(x,y:integer);        { Draws a line from current position to }
  149.   BEGIN                               { the coordinates x,y.                  }
  150.     draw(cur_x,cur_y,x,y)
  151.   END;
  152.  
  153. PROCEDURE poly(x,y,rad,side:integer); { Draw a polygon of side sides at x,y   }
  154.   CONST                               { with a radius of rad                  }
  155.     twopi = 6.283185307;              { High accuracy draws a better polygon  }
  156.   VAR
  157.     anginc,theta : real;
  158.   BEGIN
  159.     move(x+rad,y);
  160.     anginc := twopi/side;
  161.     theta := anginc;
  162.     REPEAT
  163.       drawto(round(x+rad*cos(theta)),round(y-rad*sin(theta)));
  164.       theta := theta + anginc
  165.     UNTIL theta > twopi
  166.   END;
  167.  
  168. PROCEDURE circle(x,y,rad:integer); { Draws a circle at center x,y with a   }
  169.   BEGIN                            { radius of rad                         }
  170.     poly(x,y,rad,rad*2)
  171.   END;