home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug094.arc / DRAW.I < prev    next >
Text File  |  1979-12-31  |  3KB  |  118 lines

  1.  
  2. Procedure draw(x0,y0,x1,y1,colour:integer);
  3.  
  4. {Colour => 0= reset ; 1= set ; 2 = invert}
  5. var
  6.   a1,a2,s1,s2,d1,d2,d3,n1:integer;
  7.   ok:boolean;
  8.  
  9.      { dda algorithm program
  10.       adapted from byte august 21 1981
  11.      all variables names have been retained.}
  12.  
  13.  
  14. Procedure SetUpValues;
  15.  
  16.      {***********************************
  17.       ** setup values                  **
  18.       ***********************************
  19.       setup the x difference and the y difference dy,dx }
  20. begin
  21.      d1 := x1 - x0;
  22.      d2 := y1 - y0;
  23.      { initialise scratch variables  }
  24.      s1 := 0;
  25.      s2 := 1;
  26.      a1 := 1;
  27.      a2 := 0;
  28.      if d1 < 0 then
  29.         begin
  30.           a1 := -1 ; { we will be decrementing x0 later}
  31.           d1 := abs(d1)
  32.         end;
  33.      if d2 < 0
  34.         then begin
  35.             s2:= -1 ; { we will decrement y0 later}
  36.             d2:= abs(d2)
  37.            end;
  38.      { if d2 has a greater magnitude then make it the governing var}
  39.      if d1 < d2 then
  40.         begin
  41.            n1:=d1 ;{swap d1 and d2}
  42.            d1:=d2;
  43.            d2:=n1;
  44.            s1:=a1;
  45.            a1:=0;
  46.            a2:=s2;
  47.            s2:=0
  48.          end;
  49.       d3 := d1 shr 1;
  50.       n1 := 1
  51. end;
  52.  
  53. Procedure ddamc;
  54.  
  55. begin
  56.   inline($2A/N1/         {LD    HL,N1}
  57.          $23/            {INC   HL   }
  58.          $22/N1/         {LD    N1,HL}
  59.  
  60.          $2A/X0/         {LD    HL,X0}
  61.          $ED/$5B/A1/     {LD    DE,A1}
  62.          $19/            {ADD   HL,DE}
  63.          $22/X0/         {LD    X0,HL}
  64.  
  65.          $2A/Y0/         {LD    HL,Y0}
  66.          $ED/$5B/A2/     {LD    DE,A2}
  67.          $19/            {ADD   HL,DE}
  68.          $22/Y0/         {LD    Y0,HL}
  69.  
  70.          $2A/D3/         {LD    HL,D3}
  71.          $ED/$5B/D2/     {LD    DE,D2}
  72.          $19/            {ADD   HL,DE}
  73.          $22/D3/         {LD    D3,HL}
  74.  
  75.          $B7/            {OR A,A ;CLEAR CARRY}
  76.          $ED/$5B/D1/     {LD    DE,D1}
  77.          $ED/$52/        {SBC   HL,DE}
  78.  
  79.          $CA/*+40/       {JP    Z,FINISH}
  80.          $DA/*+37/       {JP    C,FINISH}
  81.  
  82.          $2A/X0/         {LD    HL,X0}
  83.          $ED/$5B/S1/     {LD    DE,S1}
  84.          $19/            {ADD   HL,DE}
  85.          $22/X0/         {LD    X0,HL}
  86.  
  87.          $2A/Y0/         {LD    HL,Y0}
  88.          $ED/$5B/S2/     {LD    DE,S2}
  89.          $19/            {ADD   HL,DE}
  90.          $22/Y0/         {LD    Y0,HL}
  91.  
  92.          $2A/D3/         {LD    HL,D3}
  93.          $ED/$5B/D1/     {LD    DE,D1}
  94.          $B7/            {OR    A ;CLEAR CARRY}
  95.          $ED/$52/        {SBC   HL,DE}
  96.          $22/D3/         {LD    D3,HL}
  97.          $00/0/0/0/0)     {FINISH NOP}
  98. end;
  99.  
  100.  
  101. Var Count:byte;
  102.  
  103. begin {main}
  104.   SetUpValues;
  105.   ok:=HiDot(x0,y0,colour);
  106.   While n1<=d1 do
  107.        begin
  108.          DDAMC;
  109.          ok:=HiDot(x0,y0,Colour)
  110.        end
  111. end;
  112.  
  113. function HiPlot(x0,y0,x1,y1,colour:integer):Boolean;
  114.  
  115. begin
  116.     draw(x0,y0,x1,y1,colour);
  117.     HiPlot:=True
  118. end;