; Original By Sahara Surfers, thx dudes

MODEL LARGE, PASCAL
.386P

.Code

BUFWIDTH = 320				; buffer width in pixels
BUFHEIGHT = 200 			; buffer height in pixels

SRCWIDTH = 310                          ; zoom source width - zooming
SRCHEIGHT = 190                         ; zoom source height

Public ZoomBuffer 

;*****************************************************************************
;*
;*  Procedure ZoomBuffer(srcSeg,destSeg : word; xOffset,yOffset : integer);
;*
;*  Description:  Zoom data from one buffer to another and to screen
;*
;*  Input:	  ushort srcSeg		 source buffer segment
;*		  ushort destSeg 	 destination buffer segment
;*		  int xOffset		 zooming center X offset
;* 	 	  int yOffset		 zooming center Y offset
;*
;****************************************************************************/

ZoomBuffer Proc Far Uses ds si di, srcSeg : word, destSeg : word, xOffset : word, yOffset : word
           Local   yIncWhole : word, yIncFract : word, y : word, yFract : word, yCount : word

	   mov	ax,[yOffset]
	   add	ax,(BUFHEIGHT / 2) - (SRCHEIGHT / 2)
	   mov	[y],ax
	   mov	[yFract],0
	   mov	eax,SRCHEIGHT * 65536
	   xor	edx,edx
	   mov	ebx,BUFHEIGHT
	   div	ebx
	   mov	[yIncFract],ax
	   shr	eax,16
	   mov	[yIncWhole],ax

           mov     ax,cs
           mov     es,ax

           mov     eax,SRCWIDTH * 65536
	   xor	edx,edx
	   mov	ebx,BUFWIDTH
	   div	ebx

           mov     bx,ax
           shr     eax,16
           mov     cx,ax
           mov     ax,(BUFWIDTH / 2) - (SRCWIDTH / 2)
           add     ax,[xOffset]
           xor     dx,dx
           mov     di,offset @@xlp
           mov     si,BUFWIDTH/2

   @@makex:
           mov     es:[di+2],ax
           add     dx,bx
           adc     ax,cx
           mov     es:[di+6],ax
           add     dx,bx
           adc     ax,cx
           add     di,17
           dec     si
           jnz     @@makex

	   mov	[yCount],BUFHEIGHT
	   mov	ds,[srcSeg]
	   mov	es,[destSeg]
	   xor	di,di

	   mov	ax,0A000h
	   mov	gs,ax

   @@ylp:	mov	ax,BUFWIDTH
	   mul	[y]
	   mov	si,ax

   @@xlp:
	   REPT	BUFWIDTH/2

           DB      8Ah, 84h, 34h, 12h              ; mov     al,[ds:si+1234h]
           DB      8Ah, 0A4h, 34h, 12h             ; mov     ah,[ds:si+1234h]
           DB      26h, 89h, 05h                   ; mov     [es:di],ax
           DB      65h, 89h, 05h                   ; mov     [gs:di],ax
           DB      83h, 0C7h, 02h                  ; add     di,2

	   ENDM

	   mov	ax,[yIncFract]
	   add	[yFract],ax
	   mov	ax,[yIncWhole]
	   adc	[y],ax

	   dec	[yCount]
	   jnz	@@ylp

	   ret
ZoomBuffer EndP

END
