home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Oakland CPM Archive
/
oakcpm.iso
/
cpm
/
graphics
/
draw630.lbr
/
DIABLO.LQB
/
DIABLO.LIB
Wrap
Text File
|
1986-12-07
|
6KB
|
171 lines
{*****************************************************************************}
{* *}
{* DIABLO LIBRARY *}
{* *}
{* Written by Tim Meekins *}
{* April 7, 1986 *}
{* *}
{* This Turbo Pascal (tm) file contains all functions required *}
{* to use a Diablo 630 printer or comapatible like a plotter. *}
{* An 8 1/2 by 11 sheet of paper is approx 500 x 500. *}
{* *}
{* Version 1.00 - Initial release version. April 7, 1986. *}
{* Version 1.01 - Added Diablo_reset procedure. April 8, 1986. *}
{* Version 1.02 - Added DrawTo procedure. April 9, 1986. *}
{* Version 1.10 - Added Circle procedure. June 24, 1986. *}
{* Version 1.11 - Modified Move for fast -x change. June 28, 1986 *}
{* Version 1.12 - Removed Form Feed from init_diablo. July 13, 1986 *}
{* Version 1.20 - Added procedure poly, circle routine was *}
{* re-written for use with poly and quicker drawing *}
{* when doing small circles. August 1, 1986 *}
{* *}
{*****************************************************************************}
CONST
formfeed = #12; { Form feed printer }
vmi = #27#30; { Vertical Motion Index }
hmi = #27#31; { Horizontal Motion Index }
backup = #8; { Backspace character }
linefeed = #10; { Line feed }
revfeed = #27#10; { Reverse/Neagative Line feed }
reset = #27#13'P'; { RESET/Initialization }
cr = #13; { Carriage return }
VAR
cur_x,cur_y : integer; { Current cursor positions }
PROCEDURE init_diablo; { Initialize printer for graphics }
BEGIN
write(lst,hmi,#3); { Set Horizontal Motion Index to 3 }
write(lst,vmi,#2); { Set Vertical Motion Index to 2 }
cur_x := 0;
cur_y := 0
END;
PROCEDURE reset_diablo; { Reset printer and form feed }
BEGIN
write(lst,formfeed,reset)
END;
PROCEDURE dot; { Print a dot on the printer }
BEGIN
write(lst,'.');
cur_x := cur_x + 1
END;
PROCEDURE up; { Move up }
BEGIN
write(lst,revfeed);
cur_y := cur_y - 1
END;
PROCEDURE down; { Move down }
BEGIN
write(lst,linefeed);
cur_y := cur_y + 1
END;
PROCEDURE right; { Move right }
BEGIN
write(lst,' ');
cur_x := cur_x + 1
END;
PROCEDURE left; { Move left }
BEGIN
write(lst,backup);
cur_x := cur_x - 1
END;
PROCEDURE move(x,y : integer); { Move to position x,y }
BEGIN
WHILE (cur_y <> y) DO
BEGIN
IF y < cur_y THEN
up
ELSE
down
END;
IF (x<cur_x) and (cur_x-x>x) THEN
BEGIN
write(lst,cr);
cur_x := 0
END;
WHILE (cur_x <> x) DO
BEGIN
IF x < cur_x THEN
left
ELSE
right
END
END;
PROCEDURE plot(x,y : integer); { Plot a dot at x,y }
BEGIN
move(x,y);
dot
END;
PROCEDURE draw(x1,y1,x2,y2 : integer);{ Draw a line from x1,y1 to x2,y2 }
VAR { Based on the Quadrantal Digital }
err,m,n,dx,dy : integer; { Differential Analyzer. }
BEGIN
err := 0;
m := 1;
n := 1;
dx := x2 - x1;
IF dx < 0 THEN
BEGIN
m := -1;
dx := -dx
END
ELSE
IF dx = 0 THEN
err := -1;
dy := y2 - y1;
IF dy < 0 THEN
BEGIN
n := -1;
dy := -dy
END;
WHILE (x1<>x2) OR (y1<>y2) DO
BEGIN
plot(x1,y1);
IF err < 0 THEN
BEGIN
y1 := y1 + n;
err := err + dx
END
ELSE
BEGIN
x1 := x1 + m;
err := err - dy
END
END
END;
PROCEDURE drawto(x,y:integer); { Draws a line from current position to }
BEGIN { the coordinates x,y. }
draw(cur_x,cur_y,x,y)
END;
PROCEDURE poly(x,y,rad,side:integer); { Draw a polygon of side sides at x,y }
CONST { with a radius of rad }
twopi = 6.283185307; { High accuracy draws a better polygon }
VAR
anginc,theta : real;
BEGIN
move(x+rad,y);
anginc := twopi/side;
theta := anginc;
REPEAT
drawto(round(x+rad*cos(theta)),round(y-rad*sin(theta)));
theta := theta + anginc
UNTIL theta > twopi
END;
PROCEDURE circle(x,y,rad:integer); { Draws a circle at center x,y with a }
BEGIN { radius of rad }
poly(x,y,rad,rad*2)
END;