
	.align	4
	.arm	
@:
@: r0        = x
@: r1   	    = y
@: r2        = searchvalue
@: r12       = &suchgebiet
@: r11       = breite
@: r10       = &buffer (8tel der gr. von Suchgebiet)
@:

	.global		star_test
	.type		star_test,function

star_test:

	stmfd	sp!,{r3,r4,r10,r11,r12,lr}
	
	sub	r0,r0,#1		@x-1
	sub	r1,r1,#1		@y-1
	
	add	r4,r0,r0		@x*2
	add	r3,r1,r1		@y*2
	
	mla	r4,r11,r3,r4		@y*br+x		
	add	r4,r4,r12
	
	add	r11,r11,r11		@breite *2 (wegen addition später)
	
	@123 1=start
	@4x5
	@678 
	
	ldrh	r3,[r4]			@1
	cmp	r3,r2
	beq	star_found
	
	add	r0,r0,#1		@x+1
	
	ldrh	r3,[r4,#2]		@2
	cmp	r3,r2
	beq	star_found	
	
	add	r0,r0,#1		@x+1
	
	ldrh	r3,[r4,#4]		@3
	cmp	r3,r2
	beq	star_found	
	
	add	r4,r4,r11		@nächste zeile
	sub	r0,r0,#2		@x-2
	add	r1,r1,#1		@y+1
		
	ldrh	r3,[r4]			@4
	cmp	r3,r2
	beq	star_found
	
	add	r0,r0,#2		@x+2
	
	ldrh	r3,[r4,#4]		@5
	cmp	r3,r2
	beq	star_found	
	
	add	r4,r4,r11		@nächste zeile
	sub	r0,r0,#2		@x-2
	add	r1,r1,#1		@y+1
	
	ldrh	r3,[r4]			@6
	cmp	r3,r2
	beq	star_found
	
	add	r0,r0,#1		@x+1
	
	ldrh	r3,[r4,#2]		@7
	cmp	r3,r2
	beq	star_found	
	
	add	r0,r0,#1		@x+1
	
	ldrh	r3,[r4,#4]		@8
	cmp	r3,r2
	beq	star_found	
	
star_found:	
	ldmfd	sp!,{r3,r4,r10,r11,r12,pc}
	

@:
@: r0        = x
@: r1   	    = y
@: r2	    = erweiterte bearbeitung  r2(r5) free register r3,r6,r7
@: r9[7-0]   = suchziel
@: r9[8]	    = 8 fach modus
@: r9[31-24] = nand filter für pixel (byte)
@: r11       = breite
@:
@: r12       = &suchgebiet
@: r10       = &buffer (8tel der gr. von Suchgebiet)
@:

	.global		rek
	.type		rek,function

rek:
	stmfd	sp!,{r2,r9,r10,r11,r12,lr}

	ldr r4,=stacksave
	str	sp,[r4]
	bl	rek_standard
	
ende_rek_standard:

	ldr r4,=stacksave
	ldr	sp,[r4]			@fuer long jump retstack


	ldmfd	sp!,{r2,r9,r10,r11,r12,pc}
	

@:
@: r0        = x
@: r1   	    = y
@: r2[7-0]   = leer feld  
@: r9[7-0]   = suchziel
@: r9[8]	    = 8 fach modus
@: r9[31-24] = nand filter für pixel (byte)
@: r11       = breite
@:
@: r12       = &suchgebiet
@: r10       = &buffer (8tel der gr. von Suchgebiet)
@:
@:
	
rek_standard:

	orr	r8,r0,r1, lsl #16
	stmfd	sp!,{r8,lr}
	
	@bl	ntscw
				
	add	r4,r0,r0		@x*2
	add	r3,r1,r1		@y*2
	
	mla	r4,r11,r3,r4		@y*br+x		
	
	
	
	@**** richtiger test
	
	ldrh	r5,[r4,r12]
	
	@**** extern function
	
	cmp	r2,#0
	movne	lr,pc
	bxne	r2
	
	
	bic	r5,r5,r9, lsr #24		@nand filter [31-24]
	
	and	r6,r9,#0xff		@ziel [7..0]
	cmp	r5,r6			@ziel
	beq	ende_rek_standard
	
	cmp	r5,#0			
	bne	found

	@mov	r5,#5
	@strh	r5,{r4,r12}

	@**** pre test (buffer abfragen ob schon da)
	
	mov	r6,r4, lsr #1		@/2 (byte)
	mov	r3,#1
	and	r6,r6,#0x7		@nur 8bits

	mov	r7,r4, lsr #4		@/(8*2)
	ldrb	r5,[r7,r10]		@buffer
	tst	r5,r3, lsl r6		@teste bit an stelle r6
	bne	found
	
	orr	r5,r5,r3, lsl r6		@setze es
	strb	r5,[r7,r10]		@buffer
	
	@-x-
	@xsx
	@-x-
	
	sub	r0,r0,#1		@x-1
	bl	rek_standard	
	
	add	r0,r0,#2		@x+1
	bl	rek_standard			
	
	sub	r0,r0,#1		@y+1			
	add	r1,r1,#1
	bl	rek_standard	
					
	sub	r1,r1,#2		@y-1
	bl	rek_standard			
	
	@xsx
	@---
	@x-x
	
	tst	r9,#0x100
	beq	nicht8fach
	
	sub	r0,r0,#1		@x-1,y-1
	bl	rek_standard	
	
	add	r0,r0,#2		@x+1,y-1
	bl	rek_standard	
			
	add	r1,r1,#2		@x+1,y+1
	bl	rek_standard	
					
	sub	r0,r0,#2		@x-1,y+1
	bl	rek_standard

nicht8fach:
	
	@mov	r5,#3
	@strh	r5,{r4,r12}

found:	
	ldmfd	sp!,{r8}
	
	mov	r1,r8, lsr #16
	mov	r0,r8, lsl #16
	mov	r0,r0, lsr #16
	
	ldmfd	sp!,{pc}

	.end