org 256

	mov ah,0fh
	int 10h
	cbw
	push ax
	mov al,13h
	int 10h

        std
	cwd
	xor bx,bx
	mov cx,0ffffh
	mov si,diff+8
	mov es,[si]
step	add dh,[si]
	add cx,[si-2]
part	mov ax,1010h
	int 10h
	inc bx
	test bl,03fh
	jnz step
;	lodsb
	lodsw
	and bh,bh
	jz part

	xor cx,cx
draw:
	mov dx,320			; main move
	mov di,1			; accidental move
	mov ax,cx			; ax=abs(x0-x1)..
	mov bl,199			; bx=D

	push cx				; test even
	shr cl,1
	pop cx
	jnc even

	mov si,256			; odd: down, hp=320, vp=1,-1, K=abs(x0-x1), D=199
	sub ax,192			; abs(x0-x1)=abs(256-(64+color))=abs(192-color)
	jnc line			; jump for x0>x1 - set
	neg di				; else is x0<x1 and  accidental is -1
	neg ax				; ax=abs(x0-x1)
	jmp line


even:					; up, hp=-320,1, vp=1,-320, K=x1,199, D=199,x1
	not al				; ax=255-cl=K
	neg dx				; dx=-320
	mov si,63681			; point left below
	cmp al,bl
	jc line				; jump for (x1-x0)<199 - set
	xchg dx,di			; else exchange hp with vp and K with D
	xchg ax,bx

line:
	mov bp,ax			; bp=K, ax=longitudinaly
	mov ch,bl			; ch=D+1
	inc ch

cycle:
	mov [es:si],cl

	add si,dx			; point=point+hp
	push bx				; bx/2
	shr bl,1
	cmp ax,bx			; ? ax>D/2
	pop bx
	jl continuation
	add si,di			; point=point+vp
	sub ax,bx			; contin=contin-D

continuation:
	add ax,bp
	dec ch
	jnz cycle

	inc cl
	jnz draw			; color from 0 to 255, end at 256(=0)


	mov ah,8
	int 21h

	pop ax
	int 10h


	ret

diff    db 0,0,1,1,-1,-1,1,0,0,0a0h
