
	.align	4
	.arm
	
;**** zeichne kreis
;
; r0 = x  , r1 = y
; r2 = &point(r0,r1) 
; r3 = r
;

;

	.global		draw_circle
	.type		draw_circle,function

draw_circle

	stmfd	sp!,{r0-r12,lr}
	
	mov	r10,r0		;save x
	mov	r11,r1		;save y

	mov	r4,#0		;xh = 0
	mov	r5,r3		;yh = r

	rsb	r6,r3,#1	;d   = 1-r
	mov	r7,#3		;dx  = 3
	
	;dxy = -2*r + 5
	
	rsb	r8,r3,#0	;-r
	mov	r8,r8,lsl #1	;*2
	add	r8,r8,#5	;+5

rep_circle	
	cmp	r5,r4		;WHILE(yh >= xh)
	blt	stop_circle
	
	add	r0,r10,r4	;PSET(x+xh,y+yh)
	add	r1,r11,r5
	mov	lr,pc
	bx	r2
	
	add	r0,r10,r5	;PSET(x+yh,y+xh)
	add	r1,r11,r4
	mov	lr,pc
	bx	r2
	
	add	r0,r10,r5	;PSET(x+yh,y-xh)
	sub	r1,r11,r4
	mov	lr,pc
	bx	r2
	
	add	r0,r10,r4	;PSET(x+xh,y-yh)
	sub	r1,r11,r5
	mov	lr,pc
	bx	r2
	
	sub	r0,r10,r4	;PSET(x-xh,y-yh)
	sub	r1,r11,r5
	mov	lr,pc
	bx	r2
	
	sub	r0,r10,r5	;PSET(x-yh,y-xh)
	sub	r1,r11,r4
	mov	lr,pc
	bx	r2
	
	sub	r0,r10,r5	;PSET(x-yh,y+xh)
	add	r1,r11,r4
	mov	lr,pc
	bx	r2
	
	sub	r0,r10,r4	;PSET(x-xh,y+yh)
	add	r1,r11,r5
	mov	lr,pc
	bx	r2
	
	teq	r6,#0		;IF d<0 THEN
	
	addmi	r6,r6,r7	;d=d+dx
	addmi	r7,r7,#2	;dx=dx+2
	addmi	r8,r8,#2	;dxy=dxy+2
	addmi	r4,r4,#1	;xh=xh+1
				;ELSE
	addpl	r6,r6,r8	;d=d+dxy
	addpl	r7,r7,#2	;dx=dx+2
	addpl	r8,r8,#4	;dxy=dxy+4
	addpl	r4,r4,#1	;xh=xh+1
	subpl	r5,r5,#1	;yh=yh-1
				
	b	rep_circle	
	
stop_circle	
	
	ldmfd	sp!,{r0-r12,pc}


;**** setpoint im mode 4
; r9  = x
; r10 = y

	.global		circle_point_mode4
	.type		circle_point_mode4,function

circle_point_mode4	
			
	stmfd	sp!,{r12}		
					
	add	r11,r9,#$6000000	;+x
	add	r11,r11,r10, lsl #8	;+y*256
	sub	r11,r11,r10, lsl #4	;-y*16
				
	tst	r11,#1			;adresse gerade ?
	bic	r11,r11,#1		;mache gerade	
	
	ldrh	r12,[r11]		;hole wort
	
	orreq	r12,r12,#1		;
	orrne	r12,r12,#$100		;
	
	strh	r12,[r11]		;schreibe wort
	
	ldmfd	sp!,{r12}
	bx	lr	
	
	.end