linie zeichnen (VGA)



  • Hi Leute 🙂

    ich habe mal versucht einen simplen Linienzeichenalgorithmus (Bresham glaub ich)
    von C nach asm zu übersetzen.
    Der Algorithmus in C ist zu finden unter: http://66.249.93.104/search?q=cache:w4vXfvRZoPUJ:www.iwr.uni-heidelberg.de/groups/ngg/Vorlesung/Kapitel3.pdf+zeichenalgorithmen&hl=de
    und zwar unter Punkt 3.1

    meine Übersetzung sieht wie folgt aus:

    line:              ; line(int x0, int y0, int x1, int y1);
                       ;      [bp+4] , [bp+6] , [bp+8] , [bp+10]
    	jmp short line_start
    
    mx:			dw 0
    my:			dw 0
    mdx:		dw 0
    mdy:		dw 0
    md:			dw 0
    mincrE:		dw 0
    mincrNE:	dw 0
    
    line_start:
    	push bp
    	mov bp,sp
    
    	mov ax,[bp+8] 
    	sub ax,[bp+4]
    	mov [mdx],ax
    
    	mov ax,[bp+10]
    	sub ax,[bp+6]
    	mov [mdy],ax
    
    	mov bx,2
    
    	mov ax,[mdy]
    	mul bx
    	sub ax,[mdx]
    	mov [md],ax
    
    	mov ax,[mdy]
    	mul bx
    	mov [mincrE],ax
    
    	mov ax,[mdy]
    	sub ax,[mdx]
    	mul bx
    	mov [mincrNE],ax
    
    	mov ax,[bp+4]
    	mov [mx],ax
    	mov ax,[bp+6]
    	mov [my],ax
    
    	mov ax,[mx]
    	mov bx,[my]
    	call writepixel
    
    schleife:
    	mov ax,[mx]
    	cmp ax,[bp+8]
    	;jae short line_end
    	jbe short line_end
    	mov ax,[md]
    	cmp ax,0
    	ja short gross_md
    	;jb short gross_md
    	mov ax,[md]
    	add ax,[mincrE]
    	mov [md],ax
    	mov ax,[mx]
    	inc ax
    	mov [mx],ax
    	jmp short zeichnen_call
    gross_md:
    	mov ax,[md]
    	add ax,[mincrNE]
    	mov [md],ax
    	mov ax,[mx]
    	inc ax
    	mov [mx],ax
    	mov ax,[my]
    	inc ax
    	mov [my],ax
    zeichnen_call:
    	mov ax,[mx]
    	mov bx,[my]
    	call writepixel
    	jmp short schleife
    
    line_end:
    	pop bp
    	ret
    

    nun wenn ich die funktion unter VGA so aufrufe:

    push 1
    	push 1
    	push 30
    	push 30
    	call line
    

    ..., dann erwarte ich eigentlich eine diagonale Linie welche von der Oberen Ecke ausgeht. Stattdessen sehe ich mehrere Diagonale linien, welche von verschiedenen
    Punkten des BS ausgehen.
    Wo steckt der Fehler?

    für Eure Hilfe wäre ich sehr dankbar 🙂

    gruss



  • Falls jemand denn code (die function) testen möchte, hier ein startup-code:

    org 100h
    
    	push cs
    	pop ds
    
    	mov ax,0013h ; VGA-Modus
    	int 10h
    
    	mov ax,0b00h ; Hintergrundfarbe
    	xor bh,bh
    	int 10h
    
    	push 1
    	push 1
    	push 30
    	push 30
    	call line  ; Aufruf der besagten function
    
    	mov ah,00h ; warte auf Zeichendruck
    	int 16h
    
    	mov ax,0003h ; wider textmodus 80x25x16
    	int 10h
    
    	mov ah,4ch  ; msdos
    	int 21h
    
    writepixel:
    	mov dx,ax
    	mov cx,bx
    	mov ah,0ch
    	mov al,3
    	mov bx,1
    	int 10h
    	ret
    

    gruss 🙂


Anmelden zum Antworten