Link to home
Start Free TrialLog in
Avatar of Hamidreza Vakilian
Hamidreza Vakilian

asked on

Line Drawing Algorithm

Hi Experts!

I Want To Write a Procedure That Draws a Line In Graphic Mode 640x480.
I Know That TP7.0 Has This Procedure in Graph.tpu But Because I'm Writing My New OS With Assembly,So I Have To Write a New Proc For Drawing Line.

I Have Read Bresenham's Line Algorithm But It Has a Lot Of Problems Like:
When Y is bigger then X The Procedure Draws Just a Straight Line.

Please Help Me.
(USE PUTPIXEL IN YOUR EXAMPLE)

Bye
Programmer-x
 
Avatar of yans
yans

ASKER CERTIFIED SOLUTION
Avatar of MrT-RSI
MrT-RSI

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hamidreza Vakilian

ASKER

Hi MrT-RSI!

Thanks For Your Code.
Can You Convert it To Assembly?
If You Do That,I Will Give 50 Points More.

Bye
Programmer-x
I have an almost complete graphicengine/unit that you can use if you like, I wanted to use graphic
functions that were very optimized for speed in the graphicmodes I wanted to use...
so most of the routines I wrote in assembler and optimized them for mode 13 and
some other Vesa 2.0 modes,

/Hypo
make that 150 and I'll do it !
Hi MrT-RSI!

All Right.I Have Converted It To Assembler,But It Has Some Errors When I Use it In My Program.If You Tell What I'm Doing Wrong I Will Give You That 50 Points More.(50+50=100)
**************************************************************
LINE      MACRO      X1,Y1,X2,Y2
LOCAL      CON1,CON2,OK,IF1,IF2,FIN
X21      DW      0
Y21      DW      0
D1X      DW      0
D1Y      DW      0
D2X      DW      0
D2Y      DW      0
MAX21      DW      0
MIN21      DW      0
DUM      DW      0
X      DW      X1
Y      DW      Y1
XX      DW      X2
YY      DW      Y2
PUSHA

MOV      AX,XX
SUB      AX,X
MOV      X21,AX

MOV      AX,YY
SUB      AX,Y
MOV      Y21,AX

SIGN      X21
MOV      D1X,AX

SIGN      Y21
MOV      D1Y,AX

MOV      AX,D1X
MOV      D2X,AX

MOV      D2Y,0

ABS      X21      
MOV      MAX21,AX

ABS      Y21
MOV      MIN21,AX

MOV      AX,MAX21

CMP      AX,MIN21
JL      CON1

JMP      OK

CON1:
MOV      D2X,0
MOV      AX,D1Y
MOV      D2Y,AX

MOV      AX,MAX21
MOV      DUM,AX

MOV      AX,MIN21
MOV      MAX21,AX

MOV      AX,DUM
MOV      MIN21,AX

OK:

MOV      AX,MAX21
SHR      AX,1
MOV      DUM,AX

MOV      CX,MAX21

CON2:            

PIXEL      X,Y

MOV      AX,DUM
ADD      AX,MIN21
MOV      DUM,AX

CMP      AX,MAX21
JGE      IF1
JMP      IF2

IF1:
MOV      AX,DUM
SUB      AX,MAX21
MOV      DUM,AX

MOV      AX,X
ADD      AX,D1X
MOV      X,AX

MOV      AX,Y
ADD      AX,D1Y
MOV      Y,AX

JMP      FIN

IF2:
MOV      AX,X
ADD      AX,D2X
MOV      X,AX

MOV      AX,Y
ADD      AX,D2Y
MOV      Y,AX

FIN:
LOOP      CON2      

POPA
ENDM
**************************************************************
Best Wishes...
Programmer-x
Hi MrT-RSI!

I Understood My Problem.I Converted It To ASM and It Works Very Good...

Best Wishes...
Programmer-x