		.386p
		ASSUME	CS:CODE
		INCLUDE	YGHASM.H

		PUBLIC	YGH_get

CODE		SEGMENT
;int   YGH_get(PAGE *p,char *dat,int x1,int y1,int x2,int y2);
YGH_get		PROC
#Y2		EQU	ESP+60
#X2		EQU	ESP+56
#Y1		EQU	ESP+52
#X1		EQU	ESP+48
#DAT		EQU	ESP+44
#PAGE		EQU	ESP+40
#RETADR		EQU	ESP+36
#EBP		EQU	ESP+32
#ESI		EQU	ESP+28
#EDI		EQU	ESP+24
#EBX		EQU	ESP+20
#ES		EQU	ESP+16
#DS		EQU	ESP+12
#ESPOFS		EQU	12
#LY		EQU	ESP+8
#LX		EQU	ESP+4
#ESIOFS		EQU	ESP


		PUSH	EBP
		PUSH	ESI
		PUSH	EDI
		PUSH	EBX
		PUSH	ES
		PUSH	DS		
		SUB	ESP,#ESPOFS

		MOV	EDI,[#PAGE]

		PUSH	DS
		POP	ES
		MOV	EAX,[EDI+YGH_SEG]
		MOV	DS,AX

		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:

		AND	EAX,EAX
		JL	#EXIT
		AND	EBX,EBX
		JL	#EXIT
		CMP	ECX,ES:[EDI+YGH_WDX]
		JGE	#EXIT
		CMP	EDX,ES:[EDI+YGH_WDY]
		JGE	#EXIT

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

		SUB	ECX,EAX
		INC	ECX
		MOV	[#LX],ECX
		SUB	EDX,EBX
		INC	EDX
		MOV	[#LY],EDX

		MOV	ECX,ES:[EDI+YGH_WDX]
		SUB	ECX,[#LX]
		LEA	ECX,[ECX*2]
		MOV	[#ESIOFS],ECX

		MOV	EAX,[#X1]
		MOV	EBX,[#Y1]
		IMUL	EBX,ES:[EDI+YGH_ODW]
		ADD	EBX,ES:[EDI+YGH_ADR]
		LEA	ESI,[EBX+EAX*2]		;ESI:VRAM address
		MOV	EDI,[#DAT]		;EDI:Data address
		MOV	EAX,[#LX]
		MOV	EDX,EAX			;EDX:odd?
		SHR	EAX,1			;EAX:X count
		MOV	EBX,[#LY]		;EBX:Y count

#LOOP0:		MOV	ECX,EAX
		REP	MOVSD
		AND	DL,1
		JE	#LOOP0OUT
		MOVSW
#LOOP0OUT:	ADD	ESI,[#ESIOFS]
		DEC	EBX
		JNE	#LOOP0

		MOV	EAX,0
#EXIT:		ADD	ESP,#ESPOFS
		POP	DS
		POP	ES
		POP	EBX
		POP	EDI
		POP	ESI
		POP	EBP
		RET

#ERROR1:	MOV	EAX,1
		JMP	#EXIT
YGH_get		ENDP
CODE		ENDS
		END
