translate.s 2.32 KB
/************************************************************************
 Copyright (C) 1998,1999 NINTENDO CO,Ltd,
 Copyright (C) 1998,1999 MONEGI CORPORATION,
	All Rights Reserved
This program is a trade secret of NINTENDO CO,Ltd and MONEGI Corp. 
and it is not to be reproduced, published, disclosed to others, copied,
adapted, distributed, or displayed without the prior authorization of 
NINTENDO CO,Ltd. and MONEGI Corp. Licensee agrees to attach or embed 
this Notice on all copies of the program, including partial copies or 
modified versions thereof.
*************************************************************************/
/************************************************************************
 $Date: 2002/10/29 08:06:43 $
 $Revision: 1.1.1.1 $
 $Author: blythe $
************************************************************************/
#include <asm.h>
#include <regdef.h>

/* 
  void guTranslate(Mtx *m, float x, float y, float z)
	m:	a0
	x:	a1
	y:	a2
	z	a3		
 */

#define	SIZE_OF_MTX	64	/* sizeof( Mtx ) */
#define FLOAT_0x10000	6.5536e+04	/* (float)0x00010000) */

	.text
	.align	5
LEAF( guTranslate )
	.set reorder

	li.s	ft0, FLOAT_0x10000	/* (float)0x00010000 */

	mtc1		a1, ft1
	mul.s		ft2, ft1, ft0
	trunc.w.s	ft3, ft2
	mfc1		t1, ft3		/* t1 = FTOFIX32(x) */

	mtc1		a2, ft1
	mul.s		ft2, ft1, ft0
	trunc.w.s	ft3, ft2
	mfc1		t3, ft3		/* t3 = FTOFIX32(y) */

		/* t1とt3の値は小数処理が終わるまでは保存すること! */

	srl	t2, t1, 16		/* t0の上位にxの整数部 */
	sll	t0, t2, 16
	srl	t2, t3, 16		/* t2の下位にyの整数部 */
	or	t0, t0, t2		/* t0に合成 */
	sw	t0, 24(a0)

	sll	t0,t1,16		/* t0の上位にxの小数部 */
	sll	t2,t3,16
	srl	t2,t2,16		/* t2の下位にyの小数部 */
	or	t0,t0,t2		/* t0に合成 */
	sw	t0,24+32(a0)

	
	mtc1		a3, ft1
	mul.s		ft2, ft1, ft0
	trunc.w.s	ft3, ft2
	mfc1		t1, ft3		/* t1 = FTOFIX32(z) */

	srl	t2,t1,16
	sll	t0,t2,16		/* t0の上位にzの整数部 */
	addiu	t0,t0,1			/* t0の下位に0x0001を入れる */
	sw	t0,28(a0)

	sll	t2,t1,16		/* t2の上位にzの小数部 */
	sw	t2,28+32(a0)

	sw	zero, 0(a0)
	sw	zero, 4(a0)
	sw	zero, 8(a0)
	sw	zero, 12(a0)
	sw	zero, 16(a0)
	sw	zero, 20(a0)
	sw	zero, 0+32(a0)
	sw	zero, 4+32(a0)
	sw	zero, 8+32(a0)
	sw	zero, 12+32(a0)
	sw	zero, 16+32(a0)
	sw	zero, 20+32(a0)

	lui	t0,0x0001
	ori	t0,0x0000
	sw	t0,0(a0)
	sw	t0,20(a0)
	
	lui	t0,0x0000
	ori	t0,0x0001
	sw	t0,8(a0)
	
	j	ra
	
	END( guTranslate )
/* end of file */