		.386p
		ASSUME	CS:CODE
		PUBLIC	MazeScanLineClip

;int MazeScanLineClip(int bl,int *sx,int *sy,int vx,int vy);

VY		EQU	EBP+24
VX		EQU	EBP+20
SYPTR		EQU	EBP+16
SXPTR		EQU	EBP+12
BLOCKL		EQU	EBP+8
_RETADR		EQU	EBP+4
_EBP		EQU	EBP
TX		EQU	EBP-4
TY		EQU	EBP-8
BUFLNG		EQU	    12

CODE		SEGMENT
EXTRN		MazeLinearAsm:NEAR

MazeScanLineClip	PROC	NEAR
		PUSH	EBP
		MOV	EBP,ESP
		SUB	ESP,BUFLNG
		PUSH	ESI
		PUSH	EDI
		PUSH	EBX

		CMP	DWORD PTR [VX],0
		JE	#VX0
		CMP	DWORD PTR [VY],0
		JE	#VY0

		MOV	EAX,[SXPTR]
		MOV	EAX,[EAX]
		MOV	EBX,[SYPTR]
		MOV	EBX,[EBX]
		MOV	ECX,EAX
		ADD	ECX,[VX]
		MOV	EDX,EBX
		ADD	EDX,[VY]
		CMP	DWORD PTR [VX],0
		JG	#VXPLUS
#VXMINUS:	MOV	EDI,0
		CALL	MazeLinearAsm
		CMP	EBX,0
		JL	#VYCHECK
		CMP	EBX,[BLOCKL]
		JGE	#VYCHECK
		MOV	EDI,[SXPTR]
		MOV	[EDI],DWORD PTR 0
		MOV	EDI,[SYPTR]
		MOV	[EDI],EBX
		MOV	EAX,0
		JMP	#EXIT
#VXPLUS:	MOV	EDI,[BLOCKL]
		DEC	EDI
		CALL	MazeLinearAsm
		CMP	EBX,0
		JL	#VYCHECK
		CMP	EBX,[BLOCKL]
		JGE	#VYCHECK
		MOV	EDI,[SXPTR]
		MOV	[EDI],EAX
		MOV	EDI,[SYPTR]
		MOV	[EDI],EBX
		MOV	EAX,0
		JMP	#EXIT


#VYCHECK:	MOV	EAX,[SYPTR]
		MOV	EAX,[EAX]
		MOV	EBX,[SXPTR]
		MOV	EBX,[EBX]
		MOV	ECX,EAX
		ADD	ECX,[VY]
		MOV	EDX,EBX
		ADD	EDX,[VX]

		CMP	DWORD PTR [VY],0
		JG	#VYPLUS
#VYMINUS:	MOV	EDI,0
		CALL	MazeLinearAsm
		MOV	EDI,[SXPTR]
		MOV	[EDI],EBX
		MOV	EDI,[SYPTR]
		MOV	[EDI],EAX
		MOV	EAX,0
		JMP	#EXIT
#VYPLUS:	MOV	EDI,[BLOCKL]
		DEC	EDI
		CALL	MazeLinearAsm
		MOV	EDI,[SXPTR]
		MOV	[EDI],EBX
		MOV	EDI,[SYPTR]
		MOV	[EDI],EAX
		MOV	EAX,0
		JMP	#EXIT


#VX0:		MOV	EDI,[SYPTR]
		MOV	EAX,0
		CMP	DWORD PTR [VY],0
		JL	#VX0VYMINUS
		JG	#VX0VYPLUS
		MOV	EAX,-1
		JMP	#EXIT
#VX0VYMINUS:	MOV	[EDI],DWORD PTR 0
		JMP	#EXIT
#VX0VYPLUS:	MOV	EBX,[BLOCKL]
		DEC	EBX
		MOV	[EDI],EBX
		JMP	#EXIT

#VY0:		MOV	EDI,[SXPTR]
		MOV	EAX,0
		CMP	DWORD PTR [VX],0
		JL	#VY0VXMINUS
		JG	#VY0VXPLUS
		MOV	EAX,-1
		JMP	#EXIT
#VY0VXMINUS:	MOV	[EDI],DWORD PTR 0
		JMP	#EXIT
#VY0VXPLUS:	MOV	EBX,[BLOCKL]
		DEC	EBX
		MOV	[EDI],EBX
		JMP	#EXIT


#EXIT:		POP	EBX
		POP	EDI
		POP	ESI
		MOV	ESP,EBP
		POP	EBP
		RET
MazeScanLineClip	ENDP
CODE		ENDS
		END
