gzshtri.s
7.12 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
/*---------------------------------------------------------------------
$Id: gzshtri.s,v 1.1.1.1 2002/05/02 03:29:12 blythe Exp $
File : gzshtri.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 Trignale/Quadrangle ------
#
# +-----------+-----------+
# | Hdr | RDP cmd 1 |
# +-----+-----+--+--+--+--+
# Vtx 0 | X | Y |R |G |B |A |
# +-----+-----+--+--+--+--+
# Vtx 1 | X | Y |R |G |B |A |
# +-----+-----+--+--+--+--+
# Vtx 2 | X | Y |R |G |B |A |
# +-----+-----+--+--+--+--+
#
# +-----+-----+--+--+--+--+
# Vtx 3 | X | Y |R |G |B |A |
# +-----+-----+--+--+--+--+
#
Assign(objpSave, 2)
Assign(yieldchk, 5)
AssignForDMAproc
ZObj_ShQuad:
# objp の保存 & クリア
lw objpSave, oRZ_HEADER(zBuf)
sw zero, oRZ_HEADER(zBuf)
.symbol adrs_ZObj_ShQuad, ZObj_ShQuad+0x8000
ZObj_ShTri:
Assign(keys, v2)
Assign(vtx1sv, v3)
Assign(vtx2sv, v4)
Assign(key1, v5)
Assign(vtx0, v6)
#
# v2, v3 に zBuf+16, zBuf+32 からの値が代入されている
#
# lqv keys[0], oRZ_SHTRI_VTX1(zBuf) # 16bytes 整列
luv vtx1sv[0], oRZ_SHTRI_VTX1(zBuf)
luv vtx2sv[0], oRZ_SHTRI_VTX2(zBuf)
luv vtx0[0], oRZ_SHTRI_VTX0(zBuf)
# Y sort Key 作成
vadd key1, vzero, keys[1] lw gfx1, oRZ_RDPCMD_1(zBuf) # 移動してきた
# 座標値のロード & カラー値の桁あわせ
vmudm vtx1sv, vtx1sv, _0x0200 andi yieldchk, zStat0, SP_STATUS_YIELD # 移動してきた
vmudm vtx2sv, vtx2sv, _0x0200 llv vtx1sv[0], oRZ_SHTRI_VTX1(zBuf)
vmudm vtx0, vtx0, _0x0200 llv vtx2sv[0], oRZ_SHTRI_VTX2(zBuf)
llv vtx0[0], oRZ_SHTRI_VTX0(zBuf)
# Y Sort 開始 # key1 と keys を保存のこと
ZObj_ShTri_0:
Assign(vtx1, v7)
Assign(vtx2, v8)
Assign(keyAl, v9)
Assign(keyAg, v10)
Assign(vtxAl, v11)
Assign(vtxAg, v12)
Assign(keyBg, v13)
Assign(vtxBg, v14)
vlt keyAl, key1, keys[5]
vge keyAg, key1, keys[5] bne yieldchk, zero, RSPyield_B # Yield 判定
/* 遅延 */ lw sys0, RSP_STATUS_RDPCMD_1(zero) # RDPCMD 1 の処理
vmrg vtxAl, vtx2sv, vtx1sv sw gfx1, RSP_STATUS_RDPCMD_1(zero) # RDPCMD 1 の保存
vmrg vtxAg, vtx1sv, vtx2sv lw objp, oRZ_HEADER(zBuf) # 次の ZObject の取得
vge keyBg, keyAl, vtx0[1] bne gfx1, sys0, case_G_RDPCHUNK_1 # 新規 CMD なら出力
_forward_adrs(adrs_ZObj_ShTri_1, 1)
/* 遅延 */ _li (zStat0, adrs_ZObj_ShTri_1+0xf000) # 終了飛び先(負)
ZObj_ShTri_1:
vmrg vtxBg, vtxAl, vtx0 _mov (dmem_adrs, zBuf)
vmrg vtx0, vtx0, vtxAl and dram_adrs, objp, zMask
vge keyBg, keyAg, keyBg andi zType, objp, 7
/* V */ lbu dma_len, RSP_ZOBJ_SIZE(zType)
_forward_adrs(adrs_ZObj_ShTri_2, 6)
vmrg vtx1, vtxBg, vtxAg _li (return, adrs_ZObj_ShTri_2)
vmrg vtx2, vtxAg, vtxBg bne dram_adrs, zero, DMAread # 読み込み開始
/* 遅延 */ _liu (zStat1, ZObj_Launch_A) # 終了Jump先(正)
/* 条件分岐時の処理 */ _liu (zStat1, ZObj_NextLink) # 終了Jump先(正)
EndAssign(keyAl, v9)
EndAssign(keyAg, v10)
EndAssign(vtxAl, v11)
EndAssign(vtxAg, v12)
EndAssign(keyBg, v13)
EndAssign(vtxBg, v14)
ZObj_ShTri_2:
Assign(vD10, v9)
Assign(vD20, v10)
Assign(vD02, v11)
Assign(vD21, v12)
Assign(xmin, 3)
Assign(xmid, 4)
# 座標差分の計算 # X 座標の設定
vsub vD10, vtx1, vtx0 ssv vtx0[2], 6(outp)
vsub vD20, vtx2, vtx0 mfc2 xmin, vtx0[0] # X 座標の取得
vsub vD02, vtx0, vtx2 ssv vtx1[2], 4(outp)
vsub vD21, vtx2, vtx1 sll zType, zType, 1
Assign(invDyf, v13)
Assign(invDyi, v14)
Assign(ri, v15)
Assign(rf, v16)
# Dy の逆数計算 (1)
vrcp invDyf[2], vD10[1] mfc2 xmid, vtx1[0]
# 外積値の計算 r[1] = 外積値 # vD21 に X の差分を集める
vmudh vtmp, vD10, vD20[0] slv vD10[0], oRSPZS_VSCRATCH+0(vecptr) # Dy の桁合わせ
vmadh vtmp, vD02, vD10[0] sll xmin, xmin, 14
vsar ri, ri, ri[0] ssv vD20[0], oRSPZS_VSCRATCH+2(vecptr)
vsar rf, rf, rf[1] llv vD21[4], oRSPZS_VSCRATCH+0(vecptr)
# vD10 を 8 倍する
vmudh vD10, vD10, _0x0008 ssv vtx2[2], 2(outp)
# Dy の逆数計算 (2)
vrcph invDyi[2], _0x0000 sll xmid, xmid, 14
vrcp invDyf[3], vD20[1] mfc2 sys0, ri[1]
vrcph invDyi[3], _0x0000 sdv vtx0[8], 0+32(outp)
# 4 角形の処理で必要
vrcp invDyf[0], vD21[1] luv vtx0[0], oRZ_SHTRI_VTX3(zBuf) # 頂点 3 を vtx0 に代入
vrcph invDyi[0], _0x0000 lw gfx1, RSP_STATUS_RDPCMD_1(zero) # RDPCMD_1 の設定
Assign(Dxi, v17)
Assign(Dxf, v18)
Assign(vtx3xy, v20)
# Dx の桁合わせ
vmudm Dxi, vD21, _0x4000 llv vtx3xy[0], oRZ_SHTRI_VTX3(zBuf) # vtx3.xy の取得
vmadn Dxf, vconst, _0x0000 # 空き
EndAssign(vD21, v12)
# 1/Dy の桁合わせ
vmudl invDyf, invDyf, _0x0008 # 空き
vmadm invDyi, invDyi, _0x0008 andi sys0, sys0, 0x80
vmadn invDyf, vconst, _0x0000 ori sys0, sys0, 0x0c00
Assign(invri, v12)
Assign(invrf, v19)
# 外積値の逆数計算
vrcph vtmp[1], ri[1] sh sys0, 0(outp)
vrcpl invrf[1], rf[1] sw xmid, 8(outp)
vrcph invri[1], _0x0000 sw xmin, 16(outp)
EndAssign(ri, v15)
EndAssign(rf, v16)
Assign(DxDyi, v15)
Assign(DxDyf, v16)
# Dx/Dy の計算
vmudm vtmp, invDyi, Dxf sw xmin, 24(outp)
vmadl vtmp, invDyf, Dxf sdv vzero[0], 16+32(outp)
vmadn DxDyf, invDyf, Dxi sdv vzero[0], 40+32(outp)
vmadh DxDyi, invDyi, Dxi sdv vzero[0], 56+32(outp)
EndAssign(xmin, 3)
EndAssign(xmid, 4)
EndAssign(Dxi, v17)
EndAssign(Dxf, v18)
Assign(DaDxi, v17)
Assign(DaDxf, v18)
# Da/Dx の計算(1) (A20*y10 - A10*y20)*2
vmudh vtmp, vD20, vD10[1] mfc0 zStat0, SP_STATUS
vmadh vtmp, vD10, vD02[1] _mov (return, zStat1)
vsar DaDxf, vconst, vconst[1] addiu outp, outp, 32+64
vsar DaDxi, vconst, vconst[0] ssv DxDyf[0], 14-96(outp)
EndAssign(vD10, v9)
EndAssign(vD02, v11)
Assign(DaDei, v9)
Assign(DaDef, v11)
# Da/De の計算 [4|5|6|7]
vmudm vtmp, vD20, invDyf[3] ssv DxDyi[0], 12-96(outp)
vmadn DaDef, vconst, _0x0000 ssv DxDyf[6], 22-96(outp)
vmadh DaDei, vD20, invDyi[3] ssv DxDyi[6], 20-96(outp)
EndAssign(invDyi, v14)
EndAssign(invDyf, v13)
EndAssign(vD20, v10)
# Da/Dx の計算(2)
vmudl vtmp, DaDxf, invrf[1] ssv DxDyi[4], 28-96(outp)
vmadm vtmp, DaDxi, invrf[1] ssv DxDyf[4], 30-96(outp)
vmadn DaDxf, DaDxf, invri[1] sdv DaDef[8], 48+32-96(outp)
vmadh DaDxi, DaDxi, invri[1] sdv DaDei[8], 32+32-96(outp)
vmudm vtx0, vtx0, _0x0200 mfc0 zStat1, DMA_BUSY
vmov vtx0[0], vtx3xy[0] sdv DaDxf[8], 24+32-96(outp)
vmov vtx0[1], vtx3xy[1] bgtz zObjHdr, OutputClose # 4 角形のときは Skip
sdv DaDxi[8], 8+32-96(outp)
EndAssign(vtx3xy, v20)
EndAssign(invri, v12)
EndAssign(invrf, v19)
EndAssign(DxDyi, v15)
EndAssign(DxDyf, v16)
EndAssign(DaDei, v9)
EndAssign(DaDef, v11)
EndAssign(DaDxi, v17)
EndAssign(DaDxf, v18)
#------ 4 角形の処理 ------
# objp を元に戻す
sw objpSave, oRZ_HEADER(zBuf)
# 3 角形描画ルーチンへ Jump # 3 角形描画フラグ On
j ZObj_ShTri_0 _li (zObjHdr, 1)
EndAssign(keys, v2)
EndAssign(vtx1sv, v3)
EndAssign(vtx2sv, v4)
EndAssign(key1, v5)
EndAssign(vtx0, v6)
EndAssign(vtx1, v7)
EndAssign(vtx2, v8)
EndAssign(objpSave, 2)
EndAssign(yieldchk, 5)
EndAssignForDMAproc
/*======== End of gzshtri.s ========*/