Mercurial > hg > old > magoroku_racing
view vu1code/basic.vsm @ 58:1cccf6d964b7
*** empty log message ***
author | gongo |
---|---|
date | Thu, 09 Nov 2006 01:43:07 +0000 |
parents | 0fae5658fb0b |
children |
line wrap: on
line source
; --------------------------------------------------------------------- ; ; ; vu1 micro code for basic sample ; ; ; VF01 - VF04 : perspective + transformation matrix ; VF05 - VF08 : light color matrix ; VF09 - VF12 : X light vector matrix(3 lighting vector + 1 ambient) ; VF15 : gif tag ; VF20 : source vertex ; VF21 : source normal ; VF22 : source st ; VF23 : source color ; ; ; VI00 : 0 (定数レジスタ) ; VI01 : ポインタ ; VI02 : pointer for gif tag / for XGKICK ; VI03 : pointer for vertex ; VI04 : pointer for normal ; VI05 : pointer for st ; VI06 : pointer for color ; VI07 : store pointer for RGBAQ ; VI08 : store pointer for ST ; VI09 : store pointer for XYZF2 ; VI10 : counter for vertices ; ; クリッピングの処理に使用します ; ----------------------------------- ; VI14 : vertex counter ; ; VI15 : リンクレジスタ ; ; --------------------------------------------------------------------- NOP IADDIU VI01, VI00, 0 NOP IADDIU VI02, VI00, 4 NOP IADDIU VI03, VI00, 16 ; screen matrix X object matrix NOP BAL VI15, MulMatrix NOP NOP NOP LOI 255.0 ; iレジスタ即値ロード MULi.w VF16, VF00, I NOP; vf00 (0.0, 0.0, 0.0, 1.0) ; ------------------------------------------------------------ ; クリッピング用の初期値を設定 ; ------------------------------------------------------------ NOP LOI -2048.0 ADDi.xy VF29,VF00, I NOP NOP LOI -8388608.0 ADDi.z VF29,VF00, I NOP ADDw.xy VF30,VF00, VF00 NOP NOP LOI 0.00012207 ADDi.z VF30,VF00,I NOP NOP LOI 1024.0 MULi.w VF30,VF00,I NOP ;------------------------------------------------------------------ NOP IADDIU VI01, VI00, 8 NOP LQI VF09, (VI01++) ; (8) load light color matrix NOP LQI VF10, (VI01++) NOP LQI VF11, (VI01++) NOP LQI VF12, (VI01++) NOP LQI VF05, (VI01++) ; (12) load light vector matrix NOP LQI VF06, (VI01++) NOP LQI VF07, (VI01++) NOP LQI VF08, (VI01++) NOP LQI VF01, (VI01++) ; (16) load screen x transformation matrix NOP LQI VF02, (VI01++) NOP LQI VF03, (VI01++) NOP LQI VF04, (VI01++) NOP IADDIU VI12,VI00,0x7fff ; VI12: 0x7fff NOP IADDIU VI13,VI12,0x0001 ; VI13: 0x8000 NOP[E] NOP NOP NOP START0: NOP XTOP VI01 ; VI01にVIFのTOPレジスタ値をロード NOP ILWR.x VI10, (VI01)x ; copy to VI10 NOP IADDIU VI11, VI00, 0x7fff ; set mask NOP IAND VI10, VI11, VI10 ; mask. VI10 is counter for vertices. NOP LQ VF19, 0(VI01) ; load gif tag NOP IADDIU VI03, VI01, 1 ; pointer for vertices NOP IADD VI04, VI03, VI10 ; pointer for normal NOP IADD VI05, VI04, VI10 ; pointer for color NOP IADD VI06, VI05, VI10 ; pointer for st NOP IADD VI02, VI06, VI10 ; set XGKICK pointer NOP SQ VF19, 0(VI02) ; store gif tag NOP IADDIU VI07, VI02, 2 ; set store pointer for RGBAQ NOP IADDIU VI08, VI02, 1 ; set store pointer for ST NOP IADDIU VI09, VI02, 3 ; set store pointer for XYZF2 NOP IAND VI14, VI14, VI00 ; NOP IADDIU VI14, VI00, 3 ; VI14(counter)に3をセット NOP FCSET 0x000000 ; クリッピングフラグ初期化 LOOP: NOP LQI VF20, (VI03++) ; load vertex NOP LQI VF21, (VI04++) ; load normal NOP LQI VF22, (VI05++) ; load color NOP LQI VF23, (VI06++) ; load st ; ------------------------------------------------------------------ ; counter--; ; if (counter==0) goto CLEAR2 // counter(VI14) は頂点数のカウンタ ; else goto CLEAR1 ; ------------------------------------------------------------------ NOP IADDI VI14, VI14, -1 ; VI14(counter)をデクリメント NOP IBEQ VI14, VI00, CLEAR2 ; VI14==0ならCLEAR2:へジャンプ NOP NOP NOP B CLEAR1 ; NOP NOP CLEAR2: NOP IADDIU VI14, VI00, 2 ; VI14(counter)を初期化 NOP FCSET 0x000000 ; クリッピングフラグをクリア ;------------------------------------------------------------------ CLEAR1: ; --- rotation/translation/perspective transform --- MULAx.xyzw ACC, VF01, VF20x NOP ; rot/trans/pers MADDAy.xyzw ACC, VF02, VF20y NOP MADDAz.xyzw ACC, VF03, VF20z NOP MADDw.xyzw VF25, VF04, VF20w NOP NOP NOP NOP NOP NOP NOP NOP DIV Q, VF00w, VF25w ; --- light matrix X normal --- MULAx.xyzw ACC, VF05, VF21x NOP ; dot products MADDAy.xyzw ACC, VF06, VF21y NOP MADDAz.xyzw ACC, VF07, VF21z NOP MADDw.xyzw VF13, VF08, VF21w NOP NOP NOP NOP NOP NOP NOP MAXx.xyzw VF13, VF13, VF00x NOP ; cut under 0.0f ; --- calc transformed position and store it --- MULq VF28, VF25, Q NOP NOP NOP NOP NOP NOP NOP FTOI4 VF27, VF28 NOP ADD VF31,VF28,VF29 NOP MUL VF31,VF31,VF30 NOP ; ------------------------------------------------------------------ ; Triangleは3頂点ごとに描画キックするので、3頂点カウンタを設けたい ; 3頂点の内、どれか1つにでもFCが立てばそれを保持したい ; ------------------------------------------------------------------ NOP FCAND VI01, 0x03fff ; FCの2回前までの結果をVI01に NOP IBEQ VI01, VI00, CLIP1 ; (FC==0)ではみ出し無し NOP NOP NOP B CLIP0 ; NOP NOP CLIP1: CLIPw VF31,VF30w NOP ; クリッピング検査 NOP NOP NOP NOP ; ------------------------------------------------------------------ CLIP0: ; --- store XYZF2 --- NOP SQ VF27, 0(VI09) NOP FCAND VI01,0x03fff NOP IADDIU VI11,VI01,0x7fff ; NOP IADDIU VI01, VI00, 0x8000 ; NOP IAND VI11,VI11,VI01 NOP IAND VI11,VI11,VI13 NOP ISW.w VI11,0(VI09) NOP IADDIU VI09, VI09, 3 ; --- load st and store it --- MULq.xyz VF27, VF23, Q NOP NOP NOP NOP NOP NOP NOP NOP SQ VF27, 0(VI08) NOP IADDIU VI08, VI08, 3 NOP NOP NOP NOP ; --- color * dot-product --- MULAx.xyzw ACC, VF09, VF13x NOP MADDAy.xyzw ACC, VF10, VF13y NOP MADDAz.xyzw ACC, VF11, VF13z NOP MADDw.xyzw VF14, VF12, VF13w NOP NOP NOP NOP NOP NOP NOP MUL.xyzw VF27, VF22, VF14 NOP NOP NOP NOP NOP NOP NOP MINI.w VF27, VF27, VF16w NOP NOP NOP NOP NOP NOP NOP FTOI0 VF26, VF27 NOP NOP NOP NOP NOP NOP NOP NOP SQ VF26, 0(VI07) NOP IADDIU VI07, VI07, 3 ; --- decrement loop --- NOP IADDI VI10, VI10, -1 NOP IBNE VI10, VI00, LOOP ; --- send result to GIF and stop --- NOP NOP NOP XGKICK VI02 NOP[E] NOP NOP NOP NOP B START0 NOP NOP ;Take care!! Don't forget. ; ------------------------------------------------------------------- ; MulMatrix ; VI01 : address of source matrix ; VI02 : address of source matrix ; VI03 : address of destination matrix ; MulMatrix: NOP LQI.xyzw VF08, (VI02++) NOP LQI.xyzw VF04, (VI01++) NOP LQI.xyzw VF05, (VI01++) NOP LQI.xyzw VF06, (VI01++) NOP LQI.xyzw VF07, (VI01++) MULAx.xyzw ACC, VF04, VF08x LQI.xyzw VF09, (VI02++) MADDAy.xyzw ACC, VF05, VF08y NOP MADDAz.xyzw ACC, VF06, VF08z NOP MADDw.xyzw VF12, VF07, VF08w NOP MULAx.xyzw ACC, VF04, VF09x LQI.xyzw VF10, (VI02++) MADDAy.xyzw ACC, VF05, VF09y NOP MADDAz.xyzw ACC, VF06, VF09z NOP MADDw.xyzw VF13, VF07, VF09w SQI.xyzw VF12, (VI03++) MULAx.xyzw ACC, VF04, VF10x LQI.xyzw VF11, (VI02++) MADDAy.xyzw ACC, VF05, VF10y NOP MADDAz.xyzw ACC, VF06, VF10z NOP MADDw.xyzw VF14, VF07, VF10w SQI.xyzw VF13, (VI03++) MULAx.xyzw ACC, VF04, VF11x NOP MADDAy.xyzw ACC, VF05, VF11y NOP MADDAz.xyzw ACC, VF06, VF11z NOP MADDw.xyzw VF15, VF07, VF11w SQI.xyzw VF14, (VI03++) NOP NOP NOP NOP NOP NOP NOP SQI.xyzw VF15, (VI03++) NOP NOP NOP JR VI15 NOP NOP