		.386p
		ASSUME	CS:CODE
		INCLUDE	YGHASM.H

		PUBLIC	YGH_putZoom

;putZoom(short *dat,int lx,int ly,int x1,int y1,int x2,int y2)
;{
;    int x,y,sx,sy,mb,mi;
;
;    sx=x2-x1+1;
;    sy=y2-y1+1;
;    for(y=y1; y<y2; y++)
;    {
;        mb=(y-y1)*ly/sy*lx;
;        for(x=x1; x<x2; x++)
;        {
;            mi=(x-x1)*lx/sx;
;            if(dat[mb+mi]==0)continue;
;            YGB_color(egb,dat[mb+mi]);
;            YGB_pset(egb,x,y);
;        }
;    }
;}
CODE		SEGMENT
YGH_putZoom	PROC
#Y2		EQU	EBP+36
#X2		EQU	EBP+32
#Y1		EQU	EBP+28
#X1		EQU	EBP+24
#LY		EQU	EBP+20
#LX		EQU	EBP+16
#DAT		EQU	EBP+12
#PAGE		EQU	EBP+8
#RETADR		EQU	EBP+4
#EBP		EQU	EBP
#ADR		EQU	EBP-4
#ODW		EQU	EBP-8
#YCOUNT		EQU	EBP-12
#YD		EQU	EBP-16
#YS		EQU	EBP-20
#XCOUNT		EQU	EBP-24
#XD		EQU	EBP-28
#XS		EQU	EBP-32
#SY		EQU	EBP-36
#SX		EQU	EBP-40
#ESPOFS		EQU	40
#MAPYTBL	EQU	EBP-44

#MAPXTBL	EQU	ESP+16
#ESI		EQU	ESP+12
#EDI		EQU	ESP+8
#EBX		EQU	ESP+4
#ES		EQU	ESP


		PUSH	EBP
		MOV	EBP,ESP
		SUB	ESP,#ESPOFS

		MOV	EAX,[#PAGE]
		MOV	ECX,[EAX+YGH_WDX]
		ADD	ECX,[EAX+YGH_WDY]
		LEA	ECX,[ECX*4]
		SUB	ESP,ECX

		PUSH	ESI
		PUSH	EDI
		PUSH	EBX
		PUSH	ES

		MOV	EDI,[#PAGE]
		MOV	ESI,[#DAT]
		MOV	EAX,[#X1]
		MOV	EBX,[#Y1]
		MOV	ECX,[#X2]
		MOV	EDX,[#Y2]

		CMP	EAX,ECX
		JL	#X2isLarger
		XCHG	EAX,ECX
#X2isLarger:
		CMP	EBX,EDX
		JL	#Y2isLarger
		XCHG	EBX,EDX
#Y2isLarger:
		CMP	ECX,[EDI+YGH_VX1]
		JL	#EXIT
		CMP	EAX,[EDI+YGH_VX2]
		JG	#EXIT
		CMP	EDX,[EDI+YGH_VY1]
		JL	#EXIT
		CMP	EBX,[EDI+YGH_VY2]
		JG	#EXIT

		MOV	[#X1],EAX
		MOV	[#Y1],EBX
		MOV	[#X2],ECX
		MOV	[#Y2],EDX

		SUB	ECX,EAX
		INC	ECX
		MOV	[#SX],ECX
		SUB	EDX,EBX
		INC	EDX
		MOV	[#SY],EDX

		CMP	EBX,[EDI+YGH_VY1]
		JG	#Y1fixed
		MOV	EBX,[EDI+YGH_VY1]
#Y1fixed:
		MOV	EDX,[#Y2]
		CMP	EDX,[EDI+YGH_VY2]
		JL	#Y2fixed
		MOV	EDX,[EDI+YGH_VY2]
#Y2fixed:
		MOV	[#YS],EBX
		MOV	[#YD],EDX
		SUB	EDX,EBX
		INC	EDX
		MOV	[#YCOUNT],EDX

		CMP	EAX,[EDI+YGH_VX1]
		JG	#X1fixed
		MOV	EAX,[EDI+YGH_VX1]
#X1fixed:
		MOV	ECX,[#X2]
		CMP	ECX,[EDI+YGH_VX2]
		JL	#X2fixed
		MOV	ECX,[EDI+YGH_VX2]
#X2fixed:
		MOV	[#XS],EAX
		MOV	[#XD],ECX
		SUB	ECX,EAX
		INC	ECX
		MOV	[#XCOUNT],ECX

		MOV	EAX,[EDI+YGH_SEG]
		MOV	ES,AX
		MOV	EAX,[EDI+YGH_ADR]
		MOV	[#ADR],EAX
		MOV	EAX,[EDI+YGH_ODW]
		MOV	[#ODW],EAX		;EDI:free


		MOV	EBX,[#YS]
		NEG	EBX
		MOV	EDI,[#LY]
		NEG	EDI			;(Y-Y1)*LY 仺 (-Y+Y1)*(-LY)
		MOV	ECX,[#YCOUNT]
		ALIGN	4
#MAKEYTBL:	MOV	EAX,EBX
		ADD	EAX,[#Y1]
		IMUL	EDI
		DIV	DWORD PTR [#SY]
		IMUL	EAX,[#LX]
		LEA	EAX,[ESI+EAX*2]		;not Y*LX Tbl But Address Table
		MOV	[#MAPYTBL+EBX*4],EAX
		DEC	EBX
		LOOP	#MAKEYTBL		;ESI:free


		MOV	EBX,[#XS]
		MOV	EDI,[#LX]
		MOV	ECX,[#XCOUNT]
		MOV	ESI,[#X1]
		NEG	ESI
		ALIGN	4
#MAKEXTBL:	LEA	EAX,[EBX+ESI]
		IMUL	EDI
		DIV	DWORD PTR [#SX]
		LEA	EAX,[EAX*2]		;not X Table but Address Table
		MOV	[#MAPXTBL+EBX*4],EAX
		INC	EBX
		LOOP	#MAKEXTBL


		MOV	EDX,[#YD]		;YD:Destin. of Y
		IMUL	EDX,[#ODW]		;   伀
		ADD	EDX,[#ADR]		;   伀
		MOV	[#YD],EDX		;YD:Destin. of VRAM line top

		MOV	ESI,[#YS]
		MOV	EDI,ESI
		IMUL	EDI,[#ODW]
		ADD	EDI,[#ADR]
		NEG	ESI

		ALIGN	4
#LOOP0:		MOV	EDX,[#MAPYTBL+ESI*4]

		MOV	EBX,[#XS]
		MOV	ECX,[#XCOUNT]
		ALIGN	4			;昁嶦僷儔儗儖儖乕僾
#LOOP1:		MOV	EAX,[#MAPXTBL+EBX*4]	;倃奼戝偺帪偵摿偵懍偄(偼偢)
		INC	EBX
		MOV	AX,[EDX+EAX]
		AND	AX,AX
		JE	SHORT #LOOP2OUT
#LOOP1OUT:	MOV	ES:[EDI+EBX*2],AX
		LOOP	#LOOP1
		JMP	#LOOP0OUT

		ALIGN	4
#LOOP2:		MOV	EAX,[#MAPXTBL+EBX*4]
		INC	EBX
		CMP	[EDX+EAX],WORD PTR 0
#LOOP2OUT:	LOOPZ	#LOOP2
		MOV	AX,[EDX+EAX]
		AND	ECX,ECX
		JNE	SHORT #LOOP1OUT


#LOOP0OUT:	DEC	ESI
		ADD	EDI,[#ODW]
		CMP	EDI,[#YD]
		JLE	#LOOP0


#EXIT:		POP	ES
		POP	EBX
		POP	EDI
		POP	ESI
		MOV	ESP,EBP
		POP	EBP
		RET
YGH_putZoom	ENDP

CODE		ENDS
		END
