
	.align	4
	.arm

@****: gehe linie (mit reverse korrektion)
@:
@: r0 = x1 , r1 = y
@: r3 = x2 , r4 = y2
@:
@: r2 = &fkt(x (r0) ,y (r1) )		-> bei return r2=0 break
@:
@: r12 = fkt(r0,r1)  ( r0,r1,r6,r12 for free use )
@: 


	.global		goline
	.type		goline,function

goline:
	stmfd	sp!,{r0-r12,lr}
	
	@ für Quadrant 3/2 und 6/7 gilt
	
	subs	r5,r3,r0
	rsblt	r5,r5,#0	@betrag von r5
	subs	r6,r4,r1
	rsblt	r6,r6,#0	@betrag von r6

	mov	r11,#0
	
	cmp	r5,r6		@swap /
	bge	swapNot_AB_XY
	
	mov	r11,#0b01
	
	eor	r0,r0,r1
	eor	r1,r1,r0
	eor	r0,r0,r1
	
	eor	r3,r3,r4
	eor	r4,r4,r3
	eor	r3,r3,r4
	
swapNot_AB_XY:
	
	@ für Quadrant 4 und 5 gilt
	
	subs	r5,r3,r0	@dx:=x2-x1 , dx negative ?
	orrlt	r11,r11,#0b10	@reversmode anschalten
	
	subge	r5,r3,r0	@dx=x2-x1		@in + richtung
	sublt	r5,r0,r3	@dx=x1-x2		@in - richtung	(reversmode)
	sub	r6,r4,r1	@dy=y2-y1

	@ für Quadrant 8 und 1 gilt

	cmp	r6,#0		@dy negativ ?
	mvnlt	r9,#0		@0 = -1 da 2komplement
	rsblt	r6,r6,#0	@-r6
	movge	r9,#1
	
	sub	r10,r6,r5	@dy-dx
	
	add	r7,r6,r6	@incE=2*dy
	add	r8,r10,r10	@incNE=2*(dy-dx)@
	
	add	r10,r6,r6	@d=2*dy-dx@
	sub	r10,r10,r5

	@x = x1 = r0
	@y = y1 = r1
			
go_loop:
	
	tst	r11,#0b10		@reverse ?
	beq	ptest			@ ->
	cmp	r3,r0			@solange x2<=x
	b	ntest			@ <-
ptest:	cmp	r0,r3			@solange x<=x2
ntest:	bhi	stop_go
	
		
	@**** set
		
	mov	r4,r0			@x'
	mov	r5,r1			@y'
			
	tst	r11,#0b01		@/ swap?
	movne	r1,r4
	movne	r0,r5
	
	mov	lr,pc
	bx	r2			@r12 = fkt
	cmp	r2,#0			@r12 = 0?
	beq	stop_go			@
	
	mov	r0,r4
	mov	r1,r5	
	
	@****
	
	cmp	r10,#0			@d == 0?
	addlt	r10,r10,r7		@<  d:=d+incE@
	addge	r10,r10,r8		@>= d:=d+incNE@
	addge	r1,r1,r9		@>= y++	
		
	tst	r11,#0b10		@reverse mode
	addeq	r0,r0,#1		@x++ (no)
	subne	r0,r0,#1		@x-- (yes)
	
	b	go_loop
stop_go:	
	
	ldmfd	sp!,{r0-r12,lr}
	bx	lr
	
	.end


