; Multiprocessor--compatible Mandelbrot scanner
; By and (c) Neil A Carson, RiscBSD kernel team, 1995 A.D.

R0  RN 0
R1  RN 1
R2  RN 2
R3  RN 3
R4  RN 4
R5  RN 5
R6  RN 6
R7  RN 7
R8  RN 8
R9  RN 9
R10 RN 10
R11 RN 11
R12 RN 12
R13 RN 13
R14 RN 14
R15 RN 15

sem RN 0
ptr RN 7
cnt RN 8

pc  RN 15
lr  RN 14
sp  RN 13

OS_Exit		*	&11

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;
; extern int scan(result_data_t *data); Well it was anyway. Now kludged
; for the Hydra, which assumes that the data starts 8Mb up the memory map.
; We also do a fake entry point here called _scan, so that, when finished,
; we can use SWI OS_Exit to return to the calling environment.
;

;
; Number of squares to plod through
;
count_val
	DCD	0
scan
	;
	; data points to an array of structs, containing:
	;	calculated (False), x, y, s, bx, by, bs.
	; for the final one, x = -1. We terminate by returning.
	;
	MOV	ptr, #8*1024*1024
	LDR	cnt, count_val

|get_next|
	;
	; See if we have finished or not
	;
	SUB	cnt, cnt, #1
	CMP	cnt, #0
	SWILT	OS_Exit

	;
	; We mark a block as 1 if it has been calculated.
	;
	MOV	sem, #1
	SWP	sem, sem, [ptr]
	ADD	ptr, ptr, #4

	;
	; If we have got a 1 back, then someone else has got this block
	; first, so go on to the next
	;
	CMP	sem, #0
	ADDNE	ptr, ptr, #24			; go on to next one
	BNE	|get_next|

	;
	; Calculate it now we have marked it as ours
	;
	LDMIA	ptr!, {R0-R5}			; Get arguments
	BL	iterate_square			; Start things moving
	B	|get_next|			; And carry on

	END
