Skip to main content
gamedev.net
🔒 Locked

midpoint line algorithm

Started by Sloat Jul 4, 2000 at 2:39 AM 0 replies 1k views
Original Post
Sloat
Sloat
i''m having some trouble with an assembly implementation of the midpoint line algorithm. i think the problem occurs with the sign testing, but i''m not really sure. thanks in advance. line PROC near LOCAL a :WORD LOCAL b :WORD LOCAL G :WORD LOCAL D1 :WORD LOCAL D2 :WORD push bp mov bp, sp pusha mov ax, 199 ;y2 sub ax, 0 ;y1 mov a, ax mov ax, 319 ;x2 sub ax, 0 ;x1 mov b, ax mov ax, a shl ax, 1 mov D2, ax sub ax, b mov G, ax mov ax, a sub ax, b shl ax, 1 mov D1, ax mov bx, 0 ;y1 mov si, bx xchg bh, bl shl si, 6 add si, bx add si, 0 ;x1 mov di, 0 ;x1 push 0A000h pop es mov ax, D1 mov bx, D2 mov cx, G mov dl, 0Fh ;linecol mov es:[si], dl plot1: or cx, cx ;test if signed jle plot2 ;this is the problem i think add cx, ax add si, 321 jmp plot3 plot2: add cx, bx inc si plot3: mov es:[si], dl inc di cmp di, 319 ;x2 jb plot1 exitp: popa pop bp ret 9 ENDP
Gladiator
Gladiator
    
x1 dw 50
x2 dw 100
y1 dw 100
y2 dw 200
midx dw ?
midy dw ?

; y1+(y2-y1)/2
; x1+(x2-x1)/2

mov ax, [y2]
sub ax, [y1]
sar ax, 1
add ax, [y1]
mov [midy], ax

mov ax, [x2]
sub ax, [x1]
sar ax, 1
mov [midx], ax
add ax, [x1]


Now you have the mid point in (midx, midy)

Hope this is what you were looking for.. i havent looked through your code so i dont know what it does exacty... i just read what you need..

btw, that wouldn''t get the correct results if x2 < x1 of course... so you gotta check for the sign.. the sign is stored in the most significant bit, so if you wanna check if it''s negative you just test if the most significant bit is set...

test ax, 8000h
jz possitive_sign
...
possitive_sign:
...

..-=ViKtOr=-..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.