		.386p
		ASSUME	CS:CODE
		INCLUDE	YGHASM.H

		PUBLIC	YGH_pageCopy

CODE		SEGMENT
;YGH_pageCopy(PAGE *d,PAGE *s);
YGH_pageCopy	PROC
#SRC		EQU	ESP+24
#DST		EQU	ESP+20
#RETADR		EQU	ESP+16
#EBP		EQU	ESP+12
#ESI		EQU	ESP+8
#EDI		EQU	ESP+4
#EBX		EQU	ESP

		PUSH	EBP
		PUSH	ESI
		PUSH	EDI
		PUSH	EBX

		MOV	ESI,[#SRC]
		MOV	EDI,[#DST]

		MOV	EAX,[ESI+YGH_WDX]
		CMP	EAX,[EDI+YGH_WDX]
		JG	#P1ISLARGE
		JL	#P2ISLARGE
		CALL	SAMEXSIZE
		POP	EBX
		POP	EDI
		POP	ESI
		POP	EBP
		MOV	EAX,0
		RET
		
#P1ISLARGE:	CALL	P1ISLARGE
		POP	EBX
		POP	EDI
		POP	ESI
		POP	EBP
		MOV	EAX,0
		RET


#P2ISLARGE:	CALL	P2ISLARGE
		POP	EBX
		POP	EDI
		POP	ESI
		POP	EBP
		MOV	EAX,0
		RET
YGH_pageCopy	ENDP





;ESI:OriginalPage EDI=DestinationPage
SAMEXSIZE	PROC
		PUSH	ES
		PUSH	DS

		MOV	ECX,[ESI+YGH_WDY]
		CMP	ECX,[EDI+YGH_WDY]
		JL	#WDYisSET
		MOV	ECX,[EDI+YGH_WDY]
#WDYisSET:	IMUL	ECX,[EDI+YGH_WDX]

		MOV	EBX,[ESI+YGH_SEG]
		MOV	EDX,[EDI+YGH_SEG]
		MOV	ESI,[ESI+YGH_ADR]
		MOV	EDI,[EDI+YGH_ADR]
		MOV	DS,BX
		MOV	ES,DX

		MOV	EAX,ECX
		SHR	ECX,1
		REP	MOVSD
		AND	AL,1
		JE	#EXIT
		MOVSW

#EXIT:		POP	DS
		POP	ES
		RET
SAMEXSIZE	ENDP




;ESI:OriginalPage EDI=DestinationPage
P1ISLARGE	PROC
		PUSH	ES
		PUSH	DS
		MOV	EDX,[ESI+YGH_WDY]
		CMP	EDX,[EDI+YGH_WDY]
		JL	#WDYisSET
		MOV	EDX,[EDI+YGH_WDY]	;EDX:YCOUNT
#WDYisSET:	MOV	EBX,[EDI+YGH_WDX]	;EBX:XCOUNT

		MOV	EBP,[ESI+YGH_WDX]
		SUB	EBP,EBX

		MOV	EAX,[ESI+YGH_SEG]
		MOV	ECX,[EDI+YGH_SEG]
		MOV	ESI,[ESI+YGH_ADR]
		MOV	EDI,[EDI+YGH_ADR]
		MOV	DS,AX
		MOV	ES,CX

#LOOP0:		MOV	ECX,EBX
		SHR	ECX,1
		REP	MOVSD
		BT	EBX,0
		JNC	#LOOP0OUT
		MOVSW
#LOOP0OUT:	LEA	ESI,[ESI+EBP*2]
		DEC	EDX
		JNE	#LOOP0

		POP	DS
		POP	ES
		RET
P1ISLARGE	ENDP





;ESI:OriginalPage EDI=DestinationPage
P2ISLARGE	PROC
		PUSH	ES
		PUSH	DS
		MOV	EDX,[ESI+YGH_WDY]
		CMP	EDX,[EDI+YGH_WDY]
		JL	#WDYisSET
		MOV	EDX,[EDI+YGH_WDY]	;EDX:YCOUNT
#WDYisSET:	MOV	EBX,[ESI+YGH_WDX]	;EBX:XCOUNT

		MOV	EBP,[EDI+YGH_WDX]
		SUB	EBP,EBX

		MOV	EAX,[ESI+YGH_SEG]
		MOV	ECX,[EDI+YGH_SEG]
		MOV	ESI,[ESI+YGH_ADR]
		MOV	EDI,[EDI+YGH_ADR]
		MOV	DS,AX
		MOV	ES,CX

#LOOP0:		MOV	ECX,EBX
		SHR	ECX,1
		REP	MOVSD
		BT	EBX,0
		JNC	#LOOP0OUT
		MOVSW
#LOOP0OUT:	LEA	EDI,[EDI+EBP*2]
		DEC	EDX
		JNE	#LOOP0

		POP	DS
		POP	ES
		RET
P2ISLARGE	ENDP
CODE		ENDS
		END
