Mercurial > hg > old > magoroku_racing
comparison vu1code/basic.vsm @ 0:0fae5658fb0b
Initial revision
author | gongo |
---|---|
date | Thu, 02 Nov 2006 08:55:19 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0fae5658fb0b |
---|---|
1 ; --------------------------------------------------------------------- | |
2 ; | |
3 ; | |
4 ; vu1 micro code for basic sample | |
5 ; | |
6 ; | |
7 ; VF01 - VF04 : perspective + transformation matrix | |
8 ; VF05 - VF08 : light color matrix | |
9 ; VF09 - VF12 : X light vector matrix(3 lighting vector + 1 ambient) | |
10 ; VF15 : gif tag | |
11 ; VF20 : source vertex | |
12 ; VF21 : source normal | |
13 ; VF22 : source st | |
14 ; VF23 : source color | |
15 ; | |
16 ; | |
17 ; VI00 : 0 (定数レジスタ) | |
18 ; VI01 : ポインタ | |
19 ; VI02 : pointer for gif tag / for XGKICK | |
20 ; VI03 : pointer for vertex | |
21 ; VI04 : pointer for normal | |
22 ; VI05 : pointer for st | |
23 ; VI06 : pointer for color | |
24 ; VI07 : store pointer for RGBAQ | |
25 ; VI08 : store pointer for ST | |
26 ; VI09 : store pointer for XYZF2 | |
27 ; VI10 : counter for vertices | |
28 ; | |
29 ; クリッピングの処理に使用します | |
30 ; ----------------------------------- | |
31 ; VI14 : vertex counter | |
32 ; | |
33 ; VI15 : リンクレジスタ | |
34 ; | |
35 ; --------------------------------------------------------------------- | |
36 NOP IADDIU VI01, VI00, 0 | |
37 NOP IADDIU VI02, VI00, 4 | |
38 NOP IADDIU VI03, VI00, 16 ; screen matrix X object matrix | |
39 NOP BAL VI15, MulMatrix | |
40 NOP NOP | |
41 | |
42 NOP LOI 255.0 ; iレジスタ即値ロード | |
43 MULi.w VF16, VF00, I NOP; vf00 (0.0, 0.0, 0.0, 1.0) | |
44 | |
45 ; ------------------------------------------------------------ | |
46 ; クリッピング用の初期値を設定 | |
47 ; ------------------------------------------------------------ | |
48 NOP LOI -2048.0 | |
49 ADDi.xy VF29,VF00, I NOP | |
50 NOP LOI -8388608.0 | |
51 ADDi.z VF29,VF00, I NOP | |
52 ADDw.xy VF30,VF00, VF00 NOP | |
53 NOP LOI 0.00012207 | |
54 ADDi.z VF30,VF00,I NOP | |
55 NOP LOI 1024.0 | |
56 MULi.w VF30,VF00,I NOP | |
57 ;------------------------------------------------------------------ | |
58 | |
59 NOP IADDIU VI01, VI00, 8 | |
60 NOP LQI VF09, (VI01++) ; (8) load light color matrix | |
61 NOP LQI VF10, (VI01++) | |
62 NOP LQI VF11, (VI01++) | |
63 NOP LQI VF12, (VI01++) | |
64 NOP LQI VF05, (VI01++) ; (12) load light vector matrix | |
65 NOP LQI VF06, (VI01++) | |
66 NOP LQI VF07, (VI01++) | |
67 NOP LQI VF08, (VI01++) | |
68 NOP LQI VF01, (VI01++) ; (16) load screen x transformation matrix | |
69 NOP LQI VF02, (VI01++) | |
70 NOP LQI VF03, (VI01++) | |
71 NOP LQI VF04, (VI01++) | |
72 | |
73 NOP IADDIU VI12,VI00,0x7fff ; VI12: 0x7fff | |
74 NOP IADDIU VI13,VI12,0x0001 ; VI13: 0x8000 | |
75 | |
76 NOP[E] NOP | |
77 NOP NOP | |
78 | |
79 START0: | |
80 NOP XTOP VI01 ; VI01にVIFのTOPレジスタ値をロード | |
81 NOP ILWR.x VI10, (VI01)x ; copy to VI10 | |
82 NOP IADDIU VI11, VI00, 0x7fff ; set mask | |
83 NOP IAND VI10, VI11, VI10 ; mask. VI10 is counter for vertices. | |
84 NOP LQ VF19, 0(VI01) ; load gif tag | |
85 NOP IADDIU VI03, VI01, 1 ; pointer for vertices | |
86 NOP IADD VI04, VI03, VI10 ; pointer for normal | |
87 NOP IADD VI05, VI04, VI10 ; pointer for color | |
88 NOP IADD VI06, VI05, VI10 ; pointer for st | |
89 NOP IADD VI02, VI06, VI10 ; set XGKICK pointer | |
90 NOP SQ VF19, 0(VI02) ; store gif tag | |
91 NOP IADDIU VI07, VI02, 2 ; set store pointer for RGBAQ | |
92 NOP IADDIU VI08, VI02, 1 ; set store pointer for ST | |
93 NOP IADDIU VI09, VI02, 3 ; set store pointer for XYZF2 | |
94 NOP IAND VI14, VI14, VI00 ; | |
95 NOP IADDIU VI14, VI00, 3 ; VI14(counter)に3をセット | |
96 NOP FCSET 0x000000 ; クリッピングフラグ初期化 | |
97 LOOP: | |
98 NOP LQI VF20, (VI03++) ; load vertex | |
99 NOP LQI VF21, (VI04++) ; load normal | |
100 NOP LQI VF22, (VI05++) ; load color | |
101 NOP LQI VF23, (VI06++) ; load st | |
102 ; ------------------------------------------------------------------ | |
103 ; counter--; | |
104 ; if (counter==0) goto CLEAR2 // counter(VI14) は頂点数のカウンタ | |
105 ; else goto CLEAR1 | |
106 ; ------------------------------------------------------------------ | |
107 NOP IADDI VI14, VI14, -1 ; VI14(counter)をデクリメント | |
108 NOP IBEQ VI14, VI00, CLEAR2 ; VI14==0ならCLEAR2:へジャンプ | |
109 NOP NOP | |
110 NOP B CLEAR1 ; | |
111 NOP NOP | |
112 CLEAR2: | |
113 NOP IADDIU VI14, VI00, 2 ; VI14(counter)を初期化 | |
114 NOP FCSET 0x000000 ; クリッピングフラグをクリア | |
115 ;------------------------------------------------------------------ | |
116 CLEAR1: | |
117 | |
118 ; --- rotation/translation/perspective transform --- | |
119 MULAx.xyzw ACC, VF01, VF20x NOP ; rot/trans/pers | |
120 MADDAy.xyzw ACC, VF02, VF20y NOP | |
121 MADDAz.xyzw ACC, VF03, VF20z NOP | |
122 MADDw.xyzw VF25, VF04, VF20w NOP | |
123 NOP NOP | |
124 NOP NOP | |
125 NOP NOP | |
126 NOP DIV Q, VF00w, VF25w | |
127 | |
128 ; --- light matrix X normal --- | |
129 MULAx.xyzw ACC, VF05, VF21x NOP ; dot products | |
130 MADDAy.xyzw ACC, VF06, VF21y NOP | |
131 MADDAz.xyzw ACC, VF07, VF21z NOP | |
132 MADDw.xyzw VF13, VF08, VF21w NOP | |
133 NOP NOP | |
134 NOP NOP | |
135 NOP NOP | |
136 MAXx.xyzw VF13, VF13, VF00x NOP ; cut under 0.0f | |
137 | |
138 ; --- calc transformed position and store it --- | |
139 MULq VF28, VF25, Q NOP | |
140 NOP NOP | |
141 NOP NOP | |
142 NOP NOP | |
143 FTOI4 VF27, VF28 NOP | |
144 | |
145 ADD VF31,VF28,VF29 NOP | |
146 MUL VF31,VF31,VF30 NOP | |
147 | |
148 ; ------------------------------------------------------------------ | |
149 ; Triangleは3頂点ごとに描画キックするので、3頂点カウンタを設けたい | |
150 ; 3頂点の内、どれか1つにでもFCが立てばそれを保持したい | |
151 ; ------------------------------------------------------------------ | |
152 NOP FCAND VI01, 0x03fff ; FCの2回前までの結果をVI01に | |
153 NOP IBEQ VI01, VI00, CLIP1 ; (FC==0)ではみ出し無し | |
154 NOP NOP | |
155 NOP B CLIP0 ; | |
156 NOP NOP | |
157 CLIP1: | |
158 CLIPw VF31,VF30w NOP ; クリッピング検査 | |
159 NOP NOP | |
160 NOP NOP | |
161 ; ------------------------------------------------------------------ | |
162 CLIP0: | |
163 ; --- store XYZF2 --- | |
164 NOP SQ VF27, 0(VI09) | |
165 NOP FCAND VI01,0x03fff | |
166 NOP IADDIU VI11,VI01,0x7fff | |
167 ; NOP IADDIU VI01, VI00, 0x8000 | |
168 ; NOP IAND VI11,VI11,VI01 | |
169 NOP IAND VI11,VI11,VI13 | |
170 NOP ISW.w VI11,0(VI09) | |
171 NOP IADDIU VI09, VI09, 3 | |
172 | |
173 ; --- load st and store it --- | |
174 MULq.xyz VF27, VF23, Q NOP | |
175 NOP NOP | |
176 NOP NOP | |
177 NOP NOP | |
178 NOP SQ VF27, 0(VI08) | |
179 NOP IADDIU VI08, VI08, 3 | |
180 NOP NOP | |
181 NOP NOP | |
182 | |
183 ; --- color * dot-product --- | |
184 MULAx.xyzw ACC, VF09, VF13x NOP | |
185 MADDAy.xyzw ACC, VF10, VF13y NOP | |
186 MADDAz.xyzw ACC, VF11, VF13z NOP | |
187 MADDw.xyzw VF14, VF12, VF13w NOP | |
188 NOP NOP | |
189 NOP NOP | |
190 NOP NOP | |
191 MUL.xyzw VF27, VF22, VF14 NOP | |
192 NOP NOP | |
193 NOP NOP | |
194 NOP NOP | |
195 MINI.w VF27, VF27, VF16w NOP | |
196 NOP NOP | |
197 NOP NOP | |
198 NOP NOP | |
199 FTOI0 VF26, VF27 NOP | |
200 NOP NOP | |
201 NOP NOP | |
202 NOP NOP | |
203 NOP SQ VF26, 0(VI07) | |
204 NOP IADDIU VI07, VI07, 3 | |
205 | |
206 ; --- decrement loop --- | |
207 NOP IADDI VI10, VI10, -1 | |
208 NOP IBNE VI10, VI00, LOOP | |
209 | |
210 ; --- send result to GIF and stop --- | |
211 NOP NOP | |
212 NOP XGKICK VI02 | |
213 NOP[E] NOP | |
214 NOP NOP | |
215 NOP B START0 | |
216 NOP NOP ;Take care!! Don't forget. | |
217 | |
218 | |
219 ; ------------------------------------------------------------------- | |
220 ; MulMatrix | |
221 ; VI01 : address of source matrix | |
222 ; VI02 : address of source matrix | |
223 ; VI03 : address of destination matrix | |
224 ; | |
225 | |
226 MulMatrix: | |
227 NOP LQI.xyzw VF08, (VI02++) | |
228 NOP LQI.xyzw VF04, (VI01++) | |
229 NOP LQI.xyzw VF05, (VI01++) | |
230 NOP LQI.xyzw VF06, (VI01++) | |
231 NOP LQI.xyzw VF07, (VI01++) | |
232 MULAx.xyzw ACC, VF04, VF08x LQI.xyzw VF09, (VI02++) | |
233 MADDAy.xyzw ACC, VF05, VF08y NOP | |
234 MADDAz.xyzw ACC, VF06, VF08z NOP | |
235 MADDw.xyzw VF12, VF07, VF08w NOP | |
236 MULAx.xyzw ACC, VF04, VF09x LQI.xyzw VF10, (VI02++) | |
237 MADDAy.xyzw ACC, VF05, VF09y NOP | |
238 MADDAz.xyzw ACC, VF06, VF09z NOP | |
239 MADDw.xyzw VF13, VF07, VF09w SQI.xyzw VF12, (VI03++) | |
240 MULAx.xyzw ACC, VF04, VF10x LQI.xyzw VF11, (VI02++) | |
241 MADDAy.xyzw ACC, VF05, VF10y NOP | |
242 MADDAz.xyzw ACC, VF06, VF10z NOP | |
243 MADDw.xyzw VF14, VF07, VF10w SQI.xyzw VF13, (VI03++) | |
244 MULAx.xyzw ACC, VF04, VF11x NOP | |
245 MADDAy.xyzw ACC, VF05, VF11y NOP | |
246 MADDAz.xyzw ACC, VF06, VF11z NOP | |
247 MADDw.xyzw VF15, VF07, VF11w SQI.xyzw VF14, (VI03++) | |
248 NOP NOP | |
249 NOP NOP | |
250 NOP NOP | |
251 NOP SQI.xyzw VF15, (VI03++) | |
252 NOP NOP | |
253 NOP JR VI15 | |
254 NOP NOP |