;************************************************************************
;*		program start						*
;*			in  : (R1)     <-- H pos			*
;*			      (R2)     <-- min V pos			*
;*			      (R3)     <-- V pos			*
;*			      (R4)     <-- min H pos			*
;*			      (EDTADR) <-- data pointer			*
;************************************************************************
;
ENDTSR		EQU	$
		CACHE
;
		FROM	R1
		ASR
		ASR
		ASR
		TO	R1
		ASR
		FROM	R2
		ASR
		ASR
		ASR
		TO	R2
		ASR
		FROM	R3
		ASR
		ASR
		ASR
		TO	R3
		ASR
		FROM	R4
		ASR
		ASR
		ASR
		TO	R4
		ASR
;
		IBT	R14,#0FFH	;(R14) <-- end code check data
		IWT	R6,#01FFH	;(R6)  <-- pos AND data
		IBT	R7,#016H	;(R7)  <-- X min <--> max size
		IBT	R13,#014H	;(R13) <-- Y min <--> max size
		IBT	R8,#00H		;(R8)  <-- data ON/OFF ram pointer
		IWT	R9,#EDSWBF	;(R9)  <--	  "        address
		IWT	R10,#EDSRBF	;(R10) <-- serach data no. set ram address
;
		LM	R5,EDTADR	;      "     (L,H) set
EDSR10
		LDB	(R9)
		ADD	#00
		BEQ	EDSR20		;set data ? ( no:EDSR20 )
		NOP
;
		WITH	R5
		ADD	#3
		INC	R8
		BRA	EDSR10
		INC	R9
;
EDSR20
		TO	R12
		LDB	(R5)
		INC	R5
		LDB	(R5)
		SWAP
		OR	R12
		MOVE	R12,R0
		SUB	R14
		BEQ	EDSR60		;data end ? ( yes:EDSR60 )
		INC	R5
;
		FROM	R12
		AND	R6
		STW	(R10)		;serach data no. set
		TO	R11
		LDB	(R5)
		INC	R5
;
		FROM	R12
		HIB
		LSR
		MOVE	R12,R0
		SUB	R3
		BNE	EDSR32		;= Y pos ? ( no:EDSR32 )
		FROM	R11
;
		SUB	R4
		BMI	EDSR30		;>= X min ? ( no:EDSR30 )
		SUB	R7
		BMI	EDSR40		;< max ? ( yes:EDSR40 )
;
EDSR30
		FROM	R11
EDSR32
		SUB	R1
		BNE	EDSR50		;= X pos ? ( no:EDSR50 )
		FROM	R12
		SUB	R2
		BMI	EDSR50		;>= Y min ? ( no:EDSR50 )
		SUB	R13
		BPL	EDSR50		;< max ? ( no:EDSR50 )
		NOP
;
;-------------- data find !! ------------------------------------
EDSR40
		INC	R10
		INC	R10
		FROM	R11
		STW	(R10)		;serach enemy X pos set
		INC	R10
		INC	R10
		FROM	R12
		STW	(R10)		;serach enemy Y pos set
		INC	R10
		INC	R10
		FROM	R8
		STW	(R10)		;data ON/OFF ram pointer set
		INC	R10
		INC	R10
		FROM	R14		;	"        "ON" !!
		STB	(R9)
EDSR50
		INC	R8
		BRA	EDSR10
		INC	R9
;
;-------------- end set -----------------------------------------
EDSR60
		FROM	R14
		STW	(R10)		;serach data end set
		STOP

;
