		.386p
		ASSUME	CS:CODE
		PUBLIC	MazeLinearAsm,MazeLinearC

OFST		EQU	16

MDL_PROLOGUE	MACRO
		PUSH	EBP
		PUSH	ESI
		PUSH	EDI
		PUSH	EBX
		ENDM

MDL_EPILOGUE	MACRO
		POP	EBX
		POP	EDI
		POP	ESI
		POP	EBP
		RET
		ENDM

CALCLINEAR	MACRO
		SUB	EDX,EBX		;EDX=Y2-Y1
		SUB	ECX,EAX		;ECX=X2-X1
		SUB	EAX,EDI		;EAX=(X1-X)*-1
		NEG	EAX		;   = X-X1
		IMUL	EDX		;EAX:EDX=(X-X1)(Y2-Y1)
		IDIV	ECX		;EAX=(X-X1)(Y2-Y1)/(X2-X1)
		ADD	EBX,EAX		;EBX=(X-X1)(Y2-Y1)/(X2-X1)+Y1
		MOV	EAX,EDI
		ENDM



CODE		SEGMENT
		ALIGN	4
MazeLinearC	PROC
		MDL_PROLOGUE
		MOV	EDI,[ESP+OFST+4]
		MOV	EAX,[ESP+OFST+8]
		MOV	EBX,[ESP+OFST+12]
		MOV	ECX,[ESP+OFST+16]
		MOV	EDX,[ESP+OFST+20]
		CALCLINEAR
		MOV	EAX,EBX
		MDL_EPILOGUE
MazeLinearC	ENDP


		ALIGN	4
MazeLinearAsm	PROC
;Y=(X-X1)(Y2-Y1)/(X2-X1)+Y1
		PUSH	ECX
		PUSH	EDX
		CALCLINEAR
		POP	EDX
		POP	ECX
		RET
MazeLinearAsm	ENDP
CODE		ENDS
		END


