flat assembler
Message board for the users of flat assembler.

Index > DOS > Bresenham line....I think

Author
Thread Post new topic Reply to topic
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 07 Jul 2008, 02:46
Ok, prepare to be amazed by what you are about to see....A LINE DRAWER... Very Happy
DO NOT in any shape, way, or form look deeply into the drawer code because it is such a mess your eyes may explode...Thank you
Can anyone help with the flicker? I know it has to do with vertical retrace, but anywhere i put in a retrace wait it just makes things worse.

BTW, I know there are many errors(like not clearing the kbd buffer, it has been pointed out to me in other threads) but I dont care, This was made to run on my computer as a test, so I didn't care about things like that.

Code:
org 100h

push 0a000h
pop es

mov ax,13h
int 10h

start:
call mouse
call line
call cls

key:
in al,60h
dec al
jnz start
mov ax,03h
int 10h
ret

cls:
        mov cx,0FA00h
        mov al,0
        rep stosb
        ret

mouse:
        pusha
        mov     ax,03h
        int 33h
        shr     cx,1h
        mov     [x2], cx
        mov     [y2], dx
        popa
        ret

line:
        pusha
        mov     ax, [y1]                   
         mov     bx, 320                 
        mul     bx                      
        add     ax, [x1]                
        mov     di, ax                  

        mov     ax, [x2]
        cmp     ax, [x1]
        jae     @1
        sub     [xo], 1
        mov     ax, [x1]
        sub     ax, [x2]
        mov     cx, ax
        jmp     @2
@1:
        mov     ax, [x2]              
        sub     ax, [x1]
        ;mov     cx, ax                  
@2:
        mov     bx, [y2]
        cmp     bx, [y1]
        jae     @3
        sub     [yo],1
        mov     bx, [y1]
        sub     bx, [y2]
        jmp     @4
@3:
        mov     bx, [y2]                
        sub     bx, [y1]
@4:
        cmp     ax, bx
        jae     abc123
        jmp     line1

abc123:
        mov     cx, ax
        mov     si, ax                  
        dec     si

        mov     dl, [colour]           

LoopTop:
        mov     [es:di], dl             
        sub     si, bx                  
        jnl     SkipY                   
        cmp     [yo], 0
        je      @5
        add     di, 320                 
        add     si, ax                  
        jmp SkipY
@5:
        sub     di,320
        add     si,ax
SkipY:
        cmp     [xo],0
        je      @6
        inc     di
        jmp     @7
@6:
        dec     di
@7:
        dec     cx                     
        jnz     LoopTop                 
        popa
        mov     [xo], 1
        mov     [yo], 1
        ret

line1:
        mov     cx, bx
        mov     si, bx                
        dec     si

        mov     dl, [colour]        

LoopTop1:
        mov     [es:di], dl          
        sub     si, ax                
        jnl     SkipX1                 
        cmp     [xo], 0
        je      @51
        inc     di                   
        add     si, bx                
        jmp SkipX1
@51:
        dec     di
        add     si,bx
SkipX1:
        cmp     [yo],0
        je      @61
        add     di, 320
        jmp     @71
@61:
        sub     di, 320
@71:
        dec     cx                       
        jnz     LoopTop1              
        popa
        mov     [xo], 1
        mov     [yo], 1
        ret

x1 dw 160
y1 dw 100
x2 dw 0
y2 dw 0
colour db 1
xo db 1
yo db 1
    

_________________
----> * <---- My star, won HERE
Post 07 Jul 2008, 02:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 07 Jul 2008, 04:14
windwakr wrote:
Can anyone help with the flicker?
You could try using the double buffer technique. Draw to an off screen buffer and then switch the graphics card to the new buffer when then vertical retrace is in progress.
Post 07 Jul 2008, 04:14
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4336
Location: Now
edfed 07 Jul 2008, 05:27
http://board.flatassembler.net/topic.php?t=8870&postdays=0&postorder=asc&start=17

Code:
include 'line.inc'
include 'mode13h.inc'
include 'refresh.inc'
include 'sintable.inc'
include 'keyboard/int9.inc'
    
Post 07 Jul 2008, 05:27
View user's profile Send private message Visit poster's website Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 07 Jul 2008, 18:24
I never thought about using a double buffer. I'll try that.

edfed: neat stuff there, but I like using code that I've written.
Post 07 Jul 2008, 18:24
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4336
Location: Now
edfed 07 Jul 2008, 21:03
windwakr:
normal, me too i'd like to use my own code, but maybe, it can help you to have some help. Wink
Post 07 Jul 2008, 21:03
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.