VB icon

Graphics Unit for Turbo Pascal 7.0

Email
Submitted on: 1/1/2015 5:44:00 AM
By: Patrick B.^ (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: Pre Delphi 4
Views: 5052
 
     I didnt know were else on the site this could go, this isnt delphi, its actually for good old Turbo Pascal. Does stuff like get into graphics mode , draw lines,rectangles,circles etc.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
!**************************************
! Name: Graphics Unit for Turbo Pascal 7.0
! Description:I didnt know were else on the site this could go, this isnt delphi, its actually for good old Turbo Pascal. Does stuff like get into graphics mode , draw lines,rectangles,circles etc.
! By: Patrick B.^ (from psc cd)
!**************************************

{ this is for Turbo Pascal.. not Delphi }
unit mgraphic;
interface
const vga = $a000; { video memory address }
procedure setpixel ( x,y: longint; color: byte);
procedure putpixel (x,y : Integer; Col : Byte);
procedure lineto (x,x2,y: longint; color: byte);
procedure rectangle(x, x2, y, y2: integer; color: byte);
procedure circle (oX,oY,rad:longint;Col:Byte);
procedure SetBkColor( Color: Byte);
procedure SetGraphicMode;
procedure SetTextMode;
implementation
{ set a specific pixel to a color (fast) }
procedure setpixel ( x,y: longint; color: byte);
begin
mem [vga:x+(y*320)]:=color;
end;
{ put a pixel the slow interupts way }
procedure putpixel (x,y : Integer; Col : Byte);
begin
asm
movah,0Ch
moval,[col]
movcx,[x]
movdx,[y]
movbx,[1]
int10h
end;
end;
{ draw line.. this algorithm draws a straight line }
procedure lineto (x,x2,y: longint; color: byte);
var count: integer;
begin
for count := x to x2 do
begin
setpixel ( count,y,color);
end;
end;
{ draw a rectangle.. this algorithm draws a rectangle }
procedure rectangle(x, x2, y, y2: integer; color: byte);
var
count: integer;
begin
for count := y to y2 do
begin
lineto(x,x2,count,color);
end;
end;
{ this procedure draws a circle }
procedure circle (oX,oY,rad:longint;Col:Byte);
 VAR deg:real;
 X,Y:integer;
begin
deg:=0;
repeat
 X:=round(rad*COS (deg));
 Y:=round(rad*sin (deg));
 setpixel (x+ox,y+oy,Col);
 deg:=deg+0.005;
until (deg>6.4);
end;
{ set the screen to a color }
procedure SetBkColor( Color: Byte);
begin
fillchar(mem[$a000:0],64000,Color);
end;
{ send a interupt to DOS, to set it into Graphic Mode }
procedure SetGraphicMode;
begin
asm
mov ax,0013h
int 10h
end;
end;
{ send a interupt to DOS, to set it into Text Mode }
procedure SetTextMode;
begin
asm
mov ax,0003h
int 10h
end;
end;
end.


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.