flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > Another Draw Line rutine

Author
Thread Post new topic Reply to topic
pabloreda



Joined: 24 Jan 2007
Posts: 116
Location: Argentina
pabloreda 04 Oct 2013, 22:47
I make a line draw with fixed point aproach, parameters in registers.

XRES is framebuffer width
SYSFRAME is framebuffer adress (32 bits color)
color is constant $ff00

Code:
;*******************************************
LINEA:  ; eax=x1 ebx=y1 ecx=x2 edx=y2
        cmp ebx,edx
        je horizontal
        jg .noswap
        xchg eax,ecx
        xchg ebx,edx
.noswap:
        shl eax,16
        shl ecx,16
        sub eax,ecx
        push ebx
        push edx
        sub ebx,edx
        add ebx,1
        cdq
        idiv ebx
        mov esi,eax
        add ecx,$7fff
        pop ebx
        pop edx
.lineas:
        mov eax,ecx
        add eax,esi
        push ebx
        push eax
        shr ecx,16
        shr eax,16
        call horizontal
        pop ecx
        pop ebx
        add ebx,1
        cmp ebx,edx
        jle .lineas
        ret

horizontal:  ; eax=x1 ebx=y1 ecx=x2
        cmp ecx,eax
        jg .m
        xchg ecx,eax
.m:
        sub ecx,eax
        jnz .n
        add ecx,1
.n:
        imul ebx,ebx,XRES
        add eax,ebx
        lea edi,[SYSFRAME+eax*4]
.l:
        mov dword [edi],$ff00
        add edi,4
        sub ecx,1
        jnz .l
        ret
    
Post 04 Oct 2013, 22:47
View user's profile Send private message Visit poster's website Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 346
Location: Poland
macgub 15 Oct 2013, 06:48
Pablo, you implemented in assembler algo paining line using horizontal line drawing in inner loop. Nice.
I think instead:
Code:
.l:
        mov dword [edi],$ff00
        add edi,4
        sub ecx,1
        jnz .l
     

it can be:
Code:
       push eax
       mov  eax,$ff00
       cld
       rep   stosd   
       pop   eax
    
Post 15 Oct 2013, 06:48
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.