I will post a complete file after this, but I don't have time tonight, I'm at work, and it's super busy.

I will also TEST this, because I haven't done that yet either. This is based on Bresenham's Algorithm for line drawing, as described in Michael Abrash's Book: Zen of Graphics Programming. (VGA)

Take a look, let me know what you all think, and if it can be faster. (or if it will even work...i will log on again during this weekend.)

LineDrawing

mov edi, bitmap ; edi points to 0,0 on bitmap

mov eax, maxx ; load length of row

imul maxy ; times by length of column

shl eax, 2 ; multiply by 4 (32-bits per pixel)

push eax ; store bitmap size at ESP+4 (see next push)

mov eax, maxx ; load length of row

shl eax, 2 ; multiply by 4 (32-bits per pixel)

push eax ; store ROW size at ESP

here:

mov eax, 0 ; x0

add edi, eax ; edi points to (x0,0)

mov ebx, 0 ; y0

pop eax ; restore

push eax ; and save row length

imul ebx ; row length * row of beginning point (ebx = y0)

add edi, eax ; edi points to (x0,y0)

mov eax, 0 ; restore x0

mov ecx, maxx ; x1

mov edx, maxy ; y1

; note that x0,y0,x1,y1 are normally parameters passed in

; or set to variables and then whatever...

cmp ebx, edx ; compare y0 & y1

jle noxchg ; if ebx <= edx jump to avoid xchgs

xchg eax, ecx ; swap x0 & x1

xchg ebx, edx ; swap y0 & y1

noxchg:

sub edx, ebx ; dy = y1-y0

sub ecx, eax ; dx = x1-x0

; note: here eax,ebx are not needed...

mov ebx, 1 ; XDIR set to one

cmp ecx, 0 ; if dx is <= 0 jumps to avoid change

jle xdirfound ; jump here

neg ebx ; XDIR to negative one

xdirfound:

; Variables at this point:

; eax = free ; ebx = XDIR (+or-1) ; ecx = DX ; edx = DY

; EDI points to (x0,y0) ; ESP = ROW SIZE in bytes

; ESP+4 = BITMAP SIZE in bytes

cmp ecx, edx

jle xloopx

; yloop (if we needed a label)...

shl edx, 1 ; EDX = DY*2 (DY2)

movd MM3, edx ; MM3 = DY2

sub edx, ecx ; EDX = DY2 - DX

movd MM2, edx ; MM2 is set to DY2 - DX (Error of line)

sub edx, ecx ; EDX = DY2 - (DX*2) DY2mDX2

movd MM0, edx ; MM0 = DY2mDX2

mov eax, 00FF00FFh ; purple hex color

movd MM1, eax ; MM1 = color of pixel

stosd ; since it's already in EAX, draw eax color to es:edi (stosd)

beginwhiley:

sub ecx, 1 ; while (deltaX--)

jz afterlinexy ; if zero jump to end of while loop

movd eax, MM2 ; set eax to ERROR

cmp eax, 0 ; compare ERROR to ZERO

jl thiselsey ; if less than 0 jump to thiselsey

; otherwise continue

add edi, [esp] ;OR ;pop eax ;push eax ;add edi, eax

paddd MM2, MM0 ; ADD DY2mDX2 to ERROR or line

jmp afterelsey ; skip next step

thiselsey:

paddd MM2, MM3 ; ADD DY2 to ERROR of line.

afterelsey:

add edi, ebx ; ADD XDIR to Pixel point

movd eax, MM1 ; set color in EAX for stosd

stosd ; copy eax to es:edi

jmp beginwhiley ; LOOP UP

xloopx:

shl ecx, 1 ; ECX = DX*2 (DX2)

movd MM3, ecx ; MM3 = DX2

sub ecx, edx ; ECX = DX2 - DY

movd MM2, ecx ; MM2 = DX2-DY (Error)

sub ecx, edx ; ECX = DX2 - (DY*2)

movd MM0, ecx ; MM0 = DX2mDY2

mov eax, 00FF00FFh ; purple hex color

movd MM1, eax ; MM1 = color of pixel

stosd ; since it's already in EAX, draw eax color to es:edi (stosd)

beginwhilex:

sub edx, 1 ; while (deltaY--)

jz afterlinexy ; if zero jump to end of line drawing

movd eax, MM2

cmp eax, 0 ; if Error >= 0

jl thiselsex ; otherwise jump to thiselsex

add edi, ebx ; add ebx (xdir to edi)

paddd MM2, MM0 ; add DX2mDY2 to ERROR

jmp afterelsex

thiselsex:

paddd MM2, MM3 ; just add to error

afterelsex:

add edi, [esp] ; ADD ROW to Pixel point

movd eax, MM1 ; set color in eax for stosd

stosd ; copy eax to es:edi

jmp beginwhilex ; LOOP UP

afterlinexy: ; LINE COMPLETE

Later guys,

Jeff C