߂
; "vrmove.asm" 386native make by r.h 1993/09/02
;
;
;
;	vram move.
;
;
;	void	c2movevr( int xs, int ys, int xl, int yl, int xe, int ye );
;	void	c2movlap( int xs, int ys, int xl, int yl, int xe, int ye );
;	void	c2movlapPltOlSw( int sw );
;	void	c2movlap2x( int p[], int nBoxCount );
;	void	c2scrlup( int xs, int ys, int xl, int yl, int liney );
;
;
;	since.
;		1989/3/21 PC-9801UV11 make by R.H 1989
;		modify 1991/11/15
;		rename 1992/05/15 "ADVMOV.ASM" -> "VRMOVE.ASM"
;
;		"OVLAP.ASM" PC-9801UV11 make by R.H 1990/05/19
;		 modify 1992/08/07 R.H
;
;		"SCROLL.ASM"  1991/11/15 PC-9801UV11 make by R.H 1989
;
; public subroutine.

include	tstset.inc
include	parts.inc

code	segment	public	USE32	'code'

	assume	cs:code,ds:data

public	c1movevr		; vram to vram move.
public	c1movlap		; vram to vram overlap.

extrn	c1tmvset:near		; timer set.
extrn	c1tmvewt:near		; timer end wait.

; ****************************************************
;	vram to vram move.
;
;	void	c2movevr( int xs, int ys, int xl, int yl, int xe, int ye );
;
;	-i- xs,ys : source point.
;	    xl,yl : data size.
;	    xe,ye : dest point.
;
; ****************************************************

func	c2movevr	vx1,vy1,vx2,vy2,vx3,vy3
	;;prv "vx1=",
	;;prv "vy1=",
	;;prv "vx2=",
	;;prv "vy2=",
	;;prv "vx3=",
	;;prv "vy3=",
	call	c1movevr		; vram to vram move.
	fret


; ****************************************************
;	vram to vram overlap.
;
;	void	c2movlap( int xs, int ys, int xl, int yl, int xe, int ye );
;
;	-i- xs,ys : source point.
;	    xl,yl : data size.
;	    xe,ye : dest point.
;
; ****************************************************

func	c2movlap		vx1,vy1,vx2,vy2,vx3,vy3
	call	c1movlap		; vram to vram overlap.
	fret

; ****************************************************
;	overlap palette int switch.
;
;	int	c2movlapPltOlSw( int sw );
;
;	-i- sw     : palette overlap switch 0=OFF,1=ON
;	-o- return : overlap loop count.
;
; ****************************************************

func	c2movlapPltOlSw		edx
	mov	nFlagPaletteOvlap,edx	; flag palette overlap switch.
	fret	8


; ****************************************************
;	vram to vram overlap.
;
;	void	c2movlap2x( int p[], int nBoxCount );
;
;	-i- p[0,1]   : 1source point.
;	    p[2,3]   : 1data size.
;	    p[4,5]   : 1dest point.
;	    p[6,7]   : 2source point.
;	    p[8,9]   : 2data size.
;	    p[10,11] : 2dest point.
;
; ****************************************************

func	c2movlap2x		edx, nBoxCount
	call	c1movlap2x		; vram to vram overlap.
	fret



; ****************************************************
;	vram scroll UP.
;
;	void	c2scrlup( int xs, int ys, int xl, int yl, int liney );
;
;	-i- xs,ys : source point.
;	    xl,yl : data size.
;	    liney : move line.
;
; ****************************************************

func	c2scrlup		vx1,vy1,vx2,vy2,vy3
	call	c1scrlup		; vram scroll UP.
	fret


; ****************************************************
;	vram to vram move.
;	-i- vx1,vy1  : source point.
;	    vx2,vy2  : data size.
;	    vx3,vy3  : dest point.
; ****************************************************

c1movevr	proc	near
	push	ds
	push	ax
	mov4	xx,vx3				; dest x.
	mov4	yy,vy3				; dest y.
	call	vram_adrs_DEST			; vram destination address.
	mov	edi,eax
	mov	ebp,ebx
	mov	es,cx

	mov4	xx,vx1				; source x.
	mov4	yy,vy1				; source y.
	call	vram_adrs_SOUR			; vram source address.
	mov	esi,eax
	mov	eax,vx2				; data size.
	mov	edx,vy2				; data size.
	mov	ds,cx

	sub	ebx,eax
	sub	ebp,eax

c1movevr_loop:
	mov	ecx,eax
	rep	movsb
	add	esi,ebx
	add	edi,ebp
	dec	edx
	jnz	c1movevr_loop
	pop	ax
	pop	ds
	ret
c1movevr	endp


; ****************************************************
;	vram to vram overlap.
;	-i- vx1,vy1  : source point.
;	    vx2,vy2  : data size.
;	    vx3,vy3  : dest point.
; ****************************************************

c1movlap	proc	near
	push	ds
	push	ax

	mov	ecx,8
c1movlap_loop:
	push	ecx
	mov	eax,10				; wait timer count.
	mov	ebx,1				; timer number.
	call	c1tmvset			; timer set.
	push	ds
	push	ax

	mov	nBitMask,1			; overlap mask.
	ror	byte ptr nBitMask,cl

	mov4	xx,vx3				; dest x.
	mov4	yy,vy3				; dest y.
	call	vram_adrs_DEST			; vram destination address.
	mov	edi,eax
	mov	ebp,ebx
	mov	es,cx

	mov4	xx,vx1				; source x.
	mov4	yy,vy1				; source y.
	call	vram_adrs_SOUR			; vram source address.
	mov	esi,eax
	mov	eax,vx2				; data size.
	mov	edx,vy2				; data size.

	push	nBitMask
	mov	ds,cx
	mov	ecx,eax
	pop	eax
	shl	ax,8

	sub	ebx,ecx
	sub	ebp,ecx

c1movlap_loop_y:
	push	ecx
c1movlap_loop_x:
	lodsb
	ror	ah,1				; overlap mask.
	jnc	c1movlap_55
	mov	es:[edi],al
c1movlap_55:
	inc	edi
	loop	c1movlap_loop_x
	pop	ecx
	ror	ah,3				; overlap mask.

	add	esi,ebx
	add	edi,ebp
	dec	edx
	jnz	c1movlap_loop_y

	pop	ax
	pop	ds

	cmp	nFlagPaletteOvlap,0	; flag palette overlap switch.
	je	c1movlap_71		;
	call	PaletteOvlap		; flag palette overlap switch.
c1movlap_71:

	mov	ebx,1				; timer number.
	call	c1tmvewt			; timer end wait.
	pop	ecx
	loopx	c1movlap_loop

	pop	ax
	pop	ds
	ret
c1movlap	endp

; ****************************************************
;	vram to vram overlap.
;	-i- edx  : point table.
; ****************************************************

c1movlap2x	proc	near
	push	ds
	push	ax

	mov	ecx,8
c1movlap2x_loop:
	push	ecx
	push	edx

	push	edx

	mov	eax,4;10				; wait timer count.
	mov	ebx,1				; timer number.
	call	c1tmvset			; timer set.

	mov	nBitMask,1			; overlap mask.
	ror	byte ptr nBitMask,cl

	pop	edx

	mov	ecx,nBoxCount		; box count.
c1movlap2x_loop2:
	push	ecx
	push	edx
	mov4	xxx1,[edx]		; x.
	mov4	yyy1,[edx][4]		; y.
	mov4	xxx2,[edx][8]		; x.
	mov4	yyy2,[edx][12]		; y.
	mov4	xxx3,[edx][16]		; x.
	mov4	yyy3,[edx][20]		; y.
	call	OvLap1box
	pop	edx
	add	edx,6*4
	pop	ecx
	loop	c1movlap2x_loop2

	cmp	nFlagPaletteOvlap,0	; flag palette overlap switch.
	je	c1movlap2x_71		;
	call	PaletteOvlap		; flag palette overlap switch.
c1movlap2x_71:

	mov	ebx,1				; timer number.
	call	c1tmvewt			; timer end wait.

	pop	edx
	pop	ecx
	loopx	c1movlap2x_loop

	pop	ax
	pop	ds
	ret
c1movlap2x	endp


OvLap1box	proc	near
	push	ds
	push	ax

	mov4	xx,xxx3				; dest x.
	mov4	yy,yyy3				; dest y.
	call	vram_adrs_DEST			; vram destination address.
	mov	edi,eax
	mov	ebp,ebx
	mov	es,cx

	mov4	xx,xxx1				; source x.
	mov4	yy,yyy1				; source y.
	call	vram_adrs_SOUR			; vram source address.
	mov	esi,eax
	mov	eax,xxx2			; data size.
	mov	edx,yyy2			; data size.

	push	nBitMask
	mov	ds,cx
	mov	ecx,eax
	pop	eax
	shl	ax,8

	sub	ebx,ecx
	sub	ebp,ecx

OvLap1box_loop_y:
	push	ecx
OvLap1box_loop_x:
	lodsb
	ror	ah,1				; overlap mask.
	jnc	OvLap1box_55
	mov	es:[edi],al
OvLap1box_55:
	inc	edi
	loop	OvLap1box_loop_x
	pop	ecx
	ror	ah,3				; overlap mask.

	add	esi,ebx
	add	edi,ebp
	dec	edx
	jnz	OvLap1box_loop_y

	pop	ax
	pop	ds
	ret
OvLap1box	endp


; ****************************************************
;	vram scroll UP.
;	-i- vx1,vy1  : point.
;	    vx2,vy2  : data size.
;	    vy3      : move line.
; ****************************************************

c1scrlup	proc	near
	push	ds
	push	ax
	mov4	xx,vx1				; point x.
	mov4	yy,vy1				; point y.
	call	vram_adrs_DEST			; vram destination address.
	mov	edi,eax
	mov	ebp,ebx
	mov	es,cx

	mov4	xx,vx1				; point x.
	mov	eax,vy1				; point y.
	inc	eax				;
	inc	eax				;<================2dot line.
	mov	yy,eax				; y.
	call	vram_adrs_DEST			; vram destination address.
	mov	esi,eax
	mov	eax,vx2				; data size.
	mov	edx,vy2				; data size.
	mov	fs,cx

	sub	ebx,eax
	sub	ebp,eax

	mov	ecx,vy3				; move line.
	shr	ecx,1				;<================2dot line.
	jecxz	c1scrlup_loop_e
c1scrlup_loop:
	push	ecx

	push	es
	push	fs
	pushad
	mov	eax,2				; wait timer count.<======
	mov	ebx,1				; timer number.
	call	c1tmvset			; timer set.
	popad
	pop	fs
	pop	es


	push	ds
	push	ax
	push	edx
	push	esi
	push	edi
	mov	cx,fs
	mov	ds,cx
c1scrlup_loop2:
	mov	ecx,eax
	rep	movsb
	add	esi,ebx
	add	edi,ebp
	dec	edx
	jnz	c1scrlup_loop2
	pop	edi
	pop	esi
	pop	edx
	pop	ax
	pop	ds

	push	es
	push	fs
	pushad
	mov	ebx,1				; timer number.
	call	c1tmvewt			; timer end wait.
	popad
	pop	fs
	pop	es

	pop	ecx
	loop	c1scrlup_loop
c1scrlup_loop_e:

	pop	ax
	pop	ds
	ret
c1scrlup	endp


; ****************************************************
;	vram source address.
;	-i- xx  : vram x.
;	    yy  : vram y.
;	-o- cx  : selecta.
;	    eax : offset.
;	    ebx : vram width.
; ****************************************************

vram_adrs_SOUR	proc	near
	mov	eax,yy				; vram y.
	mul	c1vram_address_SOUR[VRAM_Width]	; vram width.
	add	eax,xx				; vram x.
	add	eax,c1vram_address_SOUR[VRAM_Offset]; vram offset.
	mov	ebx,c1vram_address_SOUR[VRAM_Width]; vram width.
	mov	cx,word ptr c1vram_address_SOUR[VRAM_Selecta]; vram selecta.
	ret
vram_adrs_SOUR	endp


; ****************************************************
;	vram destination address.
;	-i- xx  : vram x.
;	    yy  : vram y.
;	-o- cx  : selecta.
;	    eax : offset.
;	    ebx : vram width.
; ****************************************************

vram_adrs_DEST	proc	near
	mov	eax,yy				; vram y.
	mul	c1vram_address_DEST[VRAM_Width]	; vram width.
	add	eax,xx				; vram x.
	add	eax,c1vram_address_DEST[VRAM_Offset]; vram offset.
	mov	ebx,c1vram_address_DEST[VRAM_Width]; vram width.
	mov	cx,word ptr c1vram_address_DEST[VRAM_Selecta]; vram selecta.
	ret
vram_adrs_DEST	endp


; ****************************************************
;	flag palette overlap switch.
; ****************************************************

PaletteOvlap	proc	near
	push	es
	push	ds
	pushad
	callc	OlPalet256xOVLAP
	popad
	pop	ds
	pop	es
	ret
PaletteOvlap	endp


code	ends

data	segment	public	USE32	'data'

extrn	vx1:dword		; source point x1.
extrn	vy1:dword		; source point y1.
extrn	vx2:dword		; length x2.
extrn	vy2:dword		; length y2.
extrn	vx3:dword		; dest point x2.
extrn	vy3:dword		; dest point y2.

xx		dd	0		; x.
yy		dd	0		; y.

nBitMask	dd	0		; overlap mask.

nFlagPaletteOvlap	dd	0	; flag palette overlap switch.

nBoxCount	dd	0		; box count.
xxx1		dd	0		; x.
yyy1		dd	0		; y.
xxx2		dd	0		; x.
yyy2		dd	0		; y.
xxx3		dd	0		; x.
yyy3		dd	0		; y.

data	ends

	end
;
;	end of "vrmove.asm"
;