home *** CD-ROM | disk | FTP | other *** search
- Unit MCGA03;
-
- interface
-
- Procedure SetGraphMode (Num:Byte);
- Procedure SetPixel (X,Y:Integer;Color:Byte);
-
- Procedure LineEqu (X1,Y1,X2,Y2:Integer;Color:Byte);
- Procedure LineIndiv (X1,Y1,X2,Y2:Integer;Color:Byte);
- Procedure Line (X1,Y1,X2,Y2:Integer;Color:Byte);
-
- implementation
-
- var
- ScreenWide : Integer;
- ScreenAddr : Word;
-
- Procedure SetGraphMode (Num:Byte);
- begin
- asm
- mov al,Num
- mov ah,0
- int 10h
- end;
- Case Num of
- $13 : ScreenWide := 320;
- end;
- ScreenAddr := $A000;
- end;
-
- Procedure SetPixel (X,Y:Integer;Color:Byte);
- begin
- asm
- push ds
- mov ax,ScreenAddr
- mov ds,ax
-
- mov ax,Y
- mov bx,320
- mul bx
- mov bx,X
- add bx,ax
-
- mov al,Color
- mov byte ptr ds:[bx],al
- pop ds
- end;
- end;
-
- Procedure LineEqu (X1,Y1,X2,Y2:Integer;Color:Byte);
- var
- Slope : Real;
- D,X,Y : Integer;
- begin
- If (X1 = X2) or (Y1 = Y2) then Exit;
- If X1 > X2 then begin
- D := X1;
- X1 := X2;
- X2 := D;
- D := Y1;
- Y1 := Y2;
- Y2 := D;
- end;
- Slope := (Y2-Y1)/(X2-X1);
- If Abs(Y2-Y1) > Abs(X2-X1) then begin
- Slope := (X2-X1)/(Y2-Y1);
- For Y := Y1 to X2 do
- SetPixel (Trunc(Slope*(Y-Y1)+X1),Y,Color);
- end
- Else begin
- Slope := (Y2-Y1)/(X2-X1);
- For X := X1 to X2 do
- SetPixel (X,Trunc(Slope*(X-X1)+Y1),Color);
- end;
- end;
-
- Procedure LineIndiv (X1,Y1,X2,Y2:Integer;Color:Byte);
- var
- X,Y,
- YIncr,
- D,DX,DY,
- AIncr,BIncr : Integer;
- Ofs : Word;
- begin
- If X1 > X2 then begin
- D := X1;
- X1 := X2;
- X2 := D;
- D := Y1;
- Y1 := Y2;
- Y2 := D;
- end;
- If Y2 > Y1 then YIncr := 1
- else YIncr := -1;
- DX := X2 - X1;
- DY := Abs (Y2-Y1);
- D := 2 * DY - DX;
- AIncr := 2 * (DY - DX);
- BIncr := 2 * DY;
-
- X := X1;
- Y := Y1;
- SetPixel (X,Y,Color);
-
- For X := X1 + 1 to X2 do begin
- If D >= 0 then begin
- Inc (Y,YIncr);
- Inc (D,AIncr);
- end
- Else Inc (D,BIncr);
- SetPixel (X,Y,Color);
- end;
- end;
-
- Procedure Line (X1,Y1,X2,Y2:Integer;Color:Byte);
- var
- I,
- YIncr,
- D,DX,DY,
- AIncr,BIncr : Integer;
- Ofs : Word;
- begin
- If X1 > X2 then begin
- D := X1;
- X1 := X2;
- X2 := D;
- D := Y1;
- Y1 := Y2;
- Y2 := D;
- end;
- If Y2 > Y1 then YIncr := 320
- else YIncr := -320;
- DX := X2 - X1;
- DY := Abs (Y2-Y1);
- D := 2 * DY - DX;
- AIncr := 2 * (DY - DX);
- BIncr := 2 * DY;
-
- Ofs := Word(Y1) * 320 + Word(X1);
-
- Mem [$A000:Ofs] := Color;
-
- For I := X1 + 1 to X2 do begin
- If D >= 0 then begin
- Inc (Ofs,YIncr);
- Inc (D,AIncr);
- end
- Else Inc (D,BIncr);
- Inc (Ofs);
- Mem [$A000:Ofs] := Color;
- end;
- end;
-
- Begin
- End.
-