gztxtri.s
11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*---------------------------------------------------------------------
$Id: gztxtri.s,v 1.1.1.1 2002/05/02 03:29:12 blythe Exp $
File : gztxtri.s
Coded by Yoshitaka Yasumoto. Jun 23, 1997.
Copyright by Nintendo, Co., Ltd. 1997.
---------------------------------------------------------------------*/
#!Reserved (0,1,11,12,13,14,15)
#!Reserved (16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)
#!Reserved (v0,v1,v29,v30,v31)
#------ Smooth Shaded Textured Triangle/Quadrangle ------
#
# +-----------+-----------+-----------+-----------+
# | Hdr | RDP cmd 1 | RDP cmd 2 | RDP cmd 3 |
# +-----+-----+--+--+--+--+-----+-----+-----+-----+
# Vtx 0 | X | Y |R |G |B |A | S | T |invWi|invWf|
# +-----+-----+--+--+--+--+-----+-----+-----+-----+
# Vtx 1 | X | Y |R |G |B |A | S | T |invWi|invWf|
# +-----+-----+--+--+--+--+-----+-----+-----+-----+
# Vtx 2 | X | Y |R |G |B |A | S | T |invWi|invWf|
# +-----+-----+--+--+--+--+-----+-----+-----+-----+
#
# +-----+-----+--+--+--+--+-----+-----+-----+-----+
# Vtx 3 | X | Y |R |G |B |A | S | T |invWi|invWf|
# +-----+-----+--+--+--+--+-----+-----+-----+-----+
#
AssignForDMAproc
Assign(objpSave, 2)
ZObj_TxQuad:
# objp の保存 & クリア
lw objpSave, oRZ_HEADER(zBuf)
sw zero, oRZ_HEADER(zBuf)
.symbol adrs_ZObj_TxQuad, ZObj_TxQuad+0x8000
ZObj_TxTri:
FixedAssign(vtx0, v2)
FixedAssign(vtx1sv, v3)
Assign(vtx2sv, v4)
Assign(key0, v5)
FixedAssign(invWi, v6)
Assign(invWf, v7)
#
# v2, v3 に zBuf+16, zBuf+32 からの値が代入されている
#
# invWi データ/Y sort Key 作成 # Yield 判定
vmov invWi[7], vtx0[6] andi sys1, zStat0, SP_STATUS_YIELD
vadd key0, vzero, vtx0[1] bne sys1, zero, RSPyield_B
# 頂点データのの取得
/* 遅延 */ lqv vtx2sv[0], oRZ_TXTRI_VTX2_X(zBuf)
ZObj_TxTri_0:
Assign(cmdsv1, 3)
# invW の最大値の取得(1) # RDPCMD 1 の処理
vsubc vtmp, vtx0, vtx1sv[7] lw gfx1, oRZ_RDPCMD_1(zBuf)
vge invWi, invWi, vtx1sv[6] lw cmdsv1, RSP_STATUS_RDPCMD_1(zero)
_forward_adrs(adrs_ZObj_TxTri_1, 9)
vmrg invWf, vtx0, vtx1sv[7] _li (zStat0, adrs_ZObj_TxTri_1+0xf000) # 終了飛び先(負)
Assign(keyAl, v8)
Assign(keyAg, v9)
Assign(vtxAl, v10)
Assign(vtxAg, v11)
Assign(keyBg, v12)
Assign(vtxBg, v13)
Assign(cmdsv2, 4)
# Y Sort (1)
vlt keyAl, key0, vtx1sv[1] lw cmdsv2, RSP_STATUS_RDPCMD_2(zero)
vge keyAg, key0, vtx1sv[1] sw gfx1, RSP_STATUS_RDPCMD_1(zero) # RDPCMD 1 の保存
vmrg vtxAl, vtx1sv, vtx0 bne gfx1, cmdsv1, case_G_RDPCHUNK_1 # 新規 CMD なら出力
vmrg vtxAg, vtx0, vtx1sv /* 遅延 */
EndAssign(cmdsv1, 3)
ZObj_TxTri_1:
# invW の最大値の取得(2) # RDPCMD 2 の処理
vsubc vtmp, invWf, vtx2sv[7] lw gfx1, oRZ_RDPCMD_2(zBuf)
_forward_adrs(adrs_ZObj_TxTri_2, 9)
vge invWi, invWi, vtx2sv[6] _li (zStat0, adrs_ZObj_TxTri_2+0xf000) # 終了飛び先(負)
vmrg invWf, invWf, vtx2sv[7] lw objp, oRZ_HEADER(zBuf) # 次の ZObject の取得
# Y Sort (2)
vge keyBg, keyAl, vtx2sv[1] sw gfx1, RSP_STATUS_RDPCMD_2(zero) # RDPCMD 2 の保存
vmrg vtxBg, vtxAl, vtx2sv bne gfx1, cmdsv2, case_G_RDPCHUNK_1 # 新規 CMD なら出力
vmrg vtx0, vtx2sv, vtxAl /* 遅延 */
EndAssign(cmdsv2, 4)
Assign(cmdsv3, 3)
Assign(cmdmask, 4)
Assign(vtx1, v14)
Assign(vtx2, v15)
ZObj_TxTri_2:
# nearW の値の取得 (1) # RDPCMD 3 の処理
vrcph vtmp[0], invWi[7] lw gfx1, oRZ_RDPCMD_3(zBuf)
# Y Sort (3)
vge keyBg, keyAg, keyBg lw cmdsv3, RSP_STATUS_RDPCMD_3(zero)
vmrg vtx1, vtxBg, vtxAg andi zType, objp, 7 # 次の zType の取得
vmrg vtx2, vtxAg, vtxBg sltiu cmdmask, gfx1, 1 # gfx1 が 0 なら 1
EndAssign(keyAl, v8)
EndAssign(keyAg, v9)
EndAssign(vtxAl, v10)
EndAssign(vtxAg, v11)
EndAssign(keyBg, v12)
EndAssign(vtxBg, v13)
Assign(atr0i, v8)
Assign(atr1i, v9)
Assign(atr2i, v10)
# nearW の値の取得 (2)
vrcpl invWf[0], invWf[7] sqv vtx0[0], oRZ_TXTRI_VTX0_X+ 0(zBuf)
vrcph invWi[0], _0x0000 luv atr0i[12], oRZ_TXTRI_VTX0_X+ 0(zBuf) # atr0i[0..3]=RGBA0
Assign(vD10, v11)
Assign(vD20, v12)
Assign(vD02, v13)
Assign(vD21, v16)
Assign(vD01, v17)
# 座標差分の計算
vsub vD10, vtx1, vtx0 sqv vtx1[12], oRZ_TXTRI_VTX1_X+ 0(zBuf)
vsub vD20, vtx2, vtx0 luv atr1i[8], oRZ_TXTRI_VTX1_X+ 0(zBuf) # atr1i[0..3]=RGBA1
vsub vD02, vtx0, vtx2 sqv vtx2[0], oRZ_TXTRI_VTX2_X+ 0(zBuf)
vsub vD21, vtx2, vtx1 addi sys0, zBuf, 4
vsub vD01, vtx0, vtx1 ldv invWi[8], oRZ_TXTRI_VTX0_X+ 8(sys0) # invWi[4|6] =iWi0,1
Assign(invri, v18)
Assign(invrf, v19)
# 外積値の計算
vmudh vtmp, vD10, vD20[0] ldv vtx2[6], oRZ_TXTRI_VTX0_X+ 8(sys0) # vtx2[4|6] =iWf0,1
vmadh vtmp, vD02, vD10[0] lsv invWi[14], oRZ_TXTRI_VTX2_X+12(zBuf) # invWi[7] =iWi2
vsar invri, invri, invri[0] luv atr2i[12], oRZ_TXTRI_VTX2_X+ 0(zBuf) # atr2i[0..3]=RGBA2
vsar invrf, invrf, invrf[1] llv atr0i[8], oRZ_TXTRI_VTX0_X+ 8(zBuf) # atr0i[4|5] =ST0
# invW/W 値の計算
vmudl vtmp, vtx2, invWf[0] llv atr1i[8], oRZ_TXTRI_VTX1_X+12(zBuf) # atr1i[4|5] =ST1
vmadm vtmp, invWi, invWf[0] llv atr2i[8], oRZ_TXTRI_VTX2_X+ 8(zBuf) # atr2i[4|5] =ST2
vmadn invWf, vtx2, invWi[0] lsv atr0i[12], oRSPZS_0x7fff(vecptr) # atr0i[6] =0x7fff
vmadh invWi, invWi, invWi[0] addi cmdmask, cmdmask, -1 # cmdsv3 のマスク値
Assign(header, 5)
# 外積値の逆数計算
vrcph vtmp[0], invri[1] lsv atr1i[12], oRSPZS_0x7fff(vecptr) # atr1i[6] =0x7fff
vrcpl invrf[0], invrf[1] mfc2 header, invri[1] # 外積値の符号取得
vrcph invri[0], _0x0000 lsv atr2i[12], oRSPZS_0x7fff(vecptr) # atr2i[6] =0x7fff
Assign(invDyi, v20)
Assign(invDyf, v21)
# Dy の逆数計算 (1)
vrcp invDyf[0], vD21[1] ldv invWf[0], oRSPZS_INVWF(vecptr)
vrcph invDyi[0], _0x0000 ldv invWi[0], oRSPZS_INVWI(vecptr)
vrcp invDyf[2], vD10[1] and cmdsv3, cmdsv3, cmdmask # cmdsv3 のマスク
_forward_adrs(adrs_ZObj_TxTri_3, 7)
vrcph invDyi[2], _0x0000 _li (zStat0, adrs_ZObj_TxTri_3+0xf000) # 終了飛び先(負)
vrcp invDyf[3], vD20[1] sw gfx1, RSP_STATUS_RDPCMD_3(zero) # RDPCMD 3 の保存
vrcph invDyi[3], _0x0000 bne gfx1, cmdsv3, case_G_RDPCHUNK_1 # 新規 CMD なら出力
vmudm vtmp, atr0i, invWf[0h] /* 遅延 */
EndAssign(cmdsv3, 3)
EndAssign(cmdmask, 4)
ZObj_TxTri_3:
Assign(atr0f, v22)
Assign(atr1f, v23)
Assign(atr2f, v24)
# atr?[0..3]=RGBA atr?[4|5|6]=STW
# S,T,W に nearW/W を乗じる # 新規 ZObject の DMA
vmadn atr0f, vconst, _0x0000 _mov (dmem_adrs, zBuf)
vmadh atr0i, atr0i, invWi[0h] and dram_adrs, objp, zMask
vmudm vtmp, atr1i, invWf[2h] lbu dma_len, RSP_ZOBJ_SIZE(zType)
vmadn atr1f, vconst, _0x0000 _liu (zStat1, ZObj_Launch_A) # 終了Jump先(正)
_forward_adrs(adrs_ZObj_TxTri_4, 6)
vmadh atr1i, atr1i, invWi[2h] _liu (return, adrs_ZObj_TxTri_4)
vmudm vtmp, atr2i, invWf[3h] bne dram_adrs, zero, DMAread # 読み込み開始
vmadn atr2f, vconst, _0x0000 /* 遅延 */
/* 条件分岐時の処理 */ _liu (zStat1, ZObj_NextLink) # 終了Jump先(正)
ZObj_TxTri_4:
vmadh atr2i, atr2i, invWi[3h] ssv vD10[0], oRSPZS_VSCRATCH+0(vecptr) # X 差分をまとめる
EndAssign(invWf, v7)
EndAssign(invWi, v6)
# 1/Dy の桁合わせ
vmudl invDyf, invDyf, _0x0008 ssv vD20[0], oRSPZS_VSCRATCH+2(vecptr)
vmadm invDyi, invDyi, _0x0008 llv vD21[4], oRSPZS_VSCRATCH+0(vecptr)
vmadn invDyf, vconst, _0x0000 ssv vtx2[2], 2(outp) # データ出力
Assign(xmin, 3)
Assign(xmid, 4)
# 外積値の逆数 桁合わせ
vmudn invrf, invrf, _0x0008 sll zType, zType, 1
vmadh invri, invri, _0x0008 ssv vtx1[2], 4(outp)
Assign(DxDyi, v6)
Assign(DxDyf, v7)
# Dx の桁合わせ
vmudm DxDyi, vD21, _0x4000 mfc2 xmin, vtx0[0]
vmadn DxDyf, vconst, _0x0000 mfc2 xmid, vtx1[0]
EndAssign(vD21, v16)
EndAssign(vtx1, v14)
EndAssign(vtx2, v15)
Assign(aD20f, v14)
Assign(aD20i, v15)
Assign(aD10f, v16)
Assign(aD10i, v25)
# Da の計算
vsubc aD10f, atr1f, atr0f andi header, header, 0x80
vsub aD10i, atr1i, atr0i ori header, header, 0x0e00
vsubc aD20f, atr2f, atr0f ssv vtx0[2], 6(outp)
vsub aD20i, atr2i, atr0i sh header, 0(outp)
EndAssign(atr1i, v9)
EndAssign(atr1f, v23)
EndAssign(atr2i, v10)
EndAssign(atr2f, v24)
# Dx/Dy の計算 # 4 角形描画時のための vtx3 の読み込み
vmudm vtmp, invDyi, DxDyf lqv vtx0[0], oRZ_TXTRI_VTX3_X(zBuf)
vmadl vtmp, invDyf, DxDyf sll xmin, xmin, 14
vmadn DxDyf, invDyf, DxDyi sll xmid, xmid, 14
vmadh DxDyi, invDyi, DxDyi sw xmid, 8(outp)
Assign(DaDef, v9)
Assign(DaDei, v10)
# Da/De の計算 [A20/y20]
vmudl vtmp, aD20f, invDyf[3] sw xmin, 16(outp)
vmadm vtmp, aD20i, invDyf[3] sw xmin, 24(outp)
vmadn DaDef, aD20f, invDyi[3] ssv DxDyf[0], 14(outp)
vmadh DaDei, aD20i, invDyi[3] ssv DxDyf[6], 22(outp)
EndAssign(header, 5)
EndAssign(xmid, 4)
EndAssign(xmin, 3)
EndAssign(invDyi, v20)
EndAssign(invDyf, v21)
# Da/Dx の計算 (1) [(A20*y10 - A10*y20)/r]
vmudn vtmp, aD20f, vD10[1] ssv DxDyf[4], 30(outp)
vmadh vtmp, aD20i, vD10[1] ssv DxDyi[0], 12(outp)
vmadn vtmp, aD10f, vD02[1] ssv DxDyi[6], 20(outp)
vmadh vtmp, aD10i, vD02[1] ssv DxDyi[4], 28(outp)
EndAssign(vD10, v11)
EndAssign(vD02, v13)
EndAssign(DxDyi, v6)
EndAssign(DxDyf, v7)
Assign(DaDxi, v6)
Assign(DaDxf, v7)
vsar DaDxf, vconst, vconst[1] sdv DaDef[0], 48+32(outp)
vsar DaDxi, vconst, vconst[0] sdv DaDef[8], 48+96(outp)
# Da/Dy の計算 (2) [(A10*x20 - A20*x10)/r]
vmudn vtmp, aD10f, vD20[0] sdv DaDei[0], 32+32(outp)
vmadh vtmp, aD10i, vD20[0] sdv DaDei[8], 32+96(outp)
vmadn vtmp, aD20f, vD01[0] sdv vzero[0], 40+32(outp)
vmadh vtmp, aD20i, vD01[0] sdv vzero[0], 56+32(outp)
EndAssign(aD10f, v16)
EndAssign(aD10i, v25)
EndAssign(aD20f, v14)
EndAssign(aD20i, v15)
EndAssign(DaDef, v9)
EndAssign(DaDei, v10)
EndAssign(vD20, v12)
EndAssign(vD01, v17)
Assign(DaDyi, v9)
Assign(DaDyf, v10)
vsar DaDyf, vconst, vconst[1] sdv atr0i[0], 0+32(outp)
vsar DaDyi, vconst, vconst[0] sdv vzero[0], 16+32(outp)
# Da/Dx の計算 (2)
vmudl vtmp, DaDxf, invrf[0] mfc0 zStat0, SP_STATUS
vmadm vtmp, DaDxi, invrf[0] sdv atr0i[8], 0+96(outp)
vmadn DaDxf, DaDxf, invri[0] _mov (return, zStat1)
vmadh DaDxi, DaDxi, invri[0] mfc0 zStat1, DMA_BUSY
# Da/Dy の計算 (2)
vmudl vtmp, DaDyf, invrf[0] sdv atr0f[8], 16+96(outp)
vmadm vtmp, DaDyi, invrf[0] addiu outp, outp, 160
vmadn DaDyf, DaDyf, invri[0] sdv DaDxf[0], 24+32-160(outp)
vmadh DaDyi, DaDyi, invri[0] sdv DaDxi[0], 8+32-160(outp)
EndAssign(atr0i, v8)
EndAssign(atr0f, v22)
EndAssign(invri, v18)
EndAssign(invrf, v19)
sdv DaDxf[8], 24+96-160(outp)
sdv DaDxi[8], 8+96-160(outp)
sdv DaDyf[8], 56+96-160(outp)
bgtz zObjHdr, OutputClose # 4 角形のときは Skip
sdv DaDyi[8], 40+96-160(outp)
EndAssign(DaDxf, v7)
EndAssign(DaDxi, v6)
EndAssign(DaDyf, v10)
EndAssign(DaDyi, v9)
FixedAssign(invWi, v6)
#------ 4 角形の処理 ------
# invWi データ作成 # objp を元に戻す
vmov invWi[7], vtx0[6] sw objpSave, oRZ_HEADER(zBuf)
# Y sort Key 作成 # 3 角形描画ルーチンへ Jump
vadd key0, vzero, vtx0[1] j ZObj_TxTri_0
# 3 角形描画フラグ On
_li (zObjHdr, 1)
EndAssignForDMAproc
EndAssign(key0, v5)
EndAssign(invWi, v6)
EndAssign(vtx0, v2)
EndAssign(vtx1sv, v3)
EndAssign(vtx2sv, v4)
EndAssign(objpSave, 2)
/*======== End of gztxtri.s ========*/