OpenCores
URL https://opencores.org/ocsvn/theia_gpu/theia_gpu/trunk

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_1.1/] [rtl/] [MEM/] [Module_ROM.v] - Blame information for rev 124

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 diegovalve
 
2
 
3
`define ONE (32'h1 << `SCALE)
4
 
5
`timescale 1ns / 1ps
6
`include "aDefinitions.v"
7
/**********************************************************************************
8
Theia, Ray Cast Programable graphic Processing Unit.
9
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
10
 
11
This program is free software; you can redistribute it and/or
12
modify it under the terms of the GNU General Public License
13
as published by the Free Software Foundation; either version 2
14
of the License, or (at your option) any later version.
15
 
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
GNU General Public License for more details.
20
 
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24
 
25
***********************************************************************************/
26
 
27
 
28
 
29
 
30
//--------------------------------------------------------
31
module ROM
32
(
33
        input  wire[`ROM_ADDRESS_WIDTH-1:0]              Address,
34
        output reg [`INSTRUCTION_WIDTH-1:0]              I
35
);
36
 
37
 
38
always @( Address )
39
begin
40
                        case (Address)
41
 
42
//Hardcoded stuff :(
43
`define RAY_INSIDE_BOX                          `R3
44
`define CURRENT_LIGHT_POS `CREG_FIRST_LIGTH  //TODO: CAHNEG T 
45
`define CURRENT_LIGHT_DIFFUSE 16'h6
46
 
47
//-----------------------------------------------------------------
48
`define LABEL_DEBUG_PRINT_REGS 16'd221
49
`define TAG_DEBUG_LOG_REGISTERS 16'd221
50
`define TAG_PSU_UCODE_ADRESS2 16'd212
51
`define TAG_PSU_UCODE_ADRESS 16'd196
52
`define LABEL_TCC_EXIT 16'd195
53
`define TAG_TCC_UCODE_ADDRESS 16'd154
54
`define LABEL_BIU4 16'd153
55
`define LABEL_BIU3 16'd143
56
`define LABEL_BIU2 16'd140
57
`define LABEL_BIU1 16'd138
58
`define TAG_BIU_UCODE_ADDRESS 16'd121
59
`define LABEL_HIT 16'd119
60
`define LABEL15 16'd117
61
`define LABEL14 16'd115
62
`define LABEL13 16'd113
63
`define LABEL_TEST_XY_PLANE 16'd108
64
`define LABEL12 16'd106
65
`define LABEL11 16'd104
66
`define LABEL10 16'd102
67
`define LABEL_TEST_XZ_PLANE 16'd96
68
`define LABEL9 16'd94
69
`define LABEL8 16'd92
70
`define LABEL7 16'd90
71
`define LABEL_TEST_YZ_PLANE 16'd84
72
`define LABEL_RAY_INSIDE_BOX 16'd81
73
`define LABEL_ELSEZ 16'd80
74
`define LABEL6 16'd77
75
`define LABEL_ELESE_IFZ 16'd73
76
`define LABEL5 16'd70
77
`define LABEL_TEST_RAY_Z_ORIGEN 16'd66
78
`define LABEL_ELSEY 16'd65
79
`define LABEL4 16'd62
80
`define LABEL_ELESE_IFY 16'd58
81
`define LABEL3 16'd55
82
`define LABEL_TEST_RAY_Y_ORIGEN 16'd51
83
`define LABEL_ELSEX 16'd50
84
`define LABEL2 16'd47
85
`define LABEL_ELSE_IFX 16'd43
86
`define LABEL1 16'd40
87
`define LABEL_TEST_RAY_X_ORIGEN 16'd36
88
`define TAG_AABBIU_UCODE_ADDRESS 16'd33
89
`define LABEL_NPG_NEXT_ROW 16'd30
90
`define TAG_NPG_UCODE_ADDRESS 16'd24
91
`define TAG_RGU_UCODE_ADDRESS 16'd17
92
`define TAG_CPPU_UCODE_ADDRESS 16'd14
93
//This is the Code that loads in THEIAs ROM
94
 
95
//-------------------------------------------------------------------------
96
//Default values for some registers after reset
97
 
98
 
99
 
100
0: I = { `ZERO ,`CREG_LAST_t ,`VOID ,`VOID };
101
 //Set the last 't' to very positive value(500) 
102
1: I = { `SETX ,`CREG_LAST_t ,32'h1F40000  };
103
2: I = { `ZERO ,`OREG_PIXEL_COLOR ,`VOID ,`VOID };
104
3: I =  { `NOP ,`RT_FALSE   }; //{ `ZERO ,`CREG_PIXEL_2D_POSITION ,`VOID ,`VOID }; 
105
4: I = { `ZERO ,`OREG_PIXEL_PITCH ,`VOID,`VOID};
106
5: I = { `ZERO ,`R1 ,`VOID ,`VOID };
107
6: I = { `ZERO ,`R2 ,`VOID ,`VOID };
108
7: I = { `ZERO ,`R3 ,`VOID ,`VOID };
109
8: I = { `ZERO ,`R4 ,`VOID ,`VOID };
110
9: I = { `ZERO ,`R5 ,`VOID ,`VOID };
111
 //Harode texture size for now ...
112
10: I = { `NOP ,`RT_FALSE   };//{ `SETX ,`CREG_TEXTURE_SIZE ,32'h1FE0000  }; 
113
11: I = { `NOP ,`RT_FALSE   };//{ `SETY ,`CREG_TEXTURE_SIZE ,32'h1FE0000  }; 
114
12: I = { `NOP ,`RT_FALSE   };//{ `SETZ ,`CREG_TEXTURE_SIZE ,32'h1FE0000  }; 
115
13: I = { `RETURN ,`RT_TRUE   };
116
 
117
 
118
//----------------------------------------------------------------------          
119
//Micro code for CPPU
120
//TAG_CPPU_UCODE_ADDRESS:
121
 
122
 
123
14: I = { `SUB ,`R1 ,`CREG_PROJECTION_WINDOW_MAX ,`CREG_PROJECTION_WINDOW_MIN };
124
15: I = { `DIV ,`CREG_PROJECTION_WINDOW_SCALE ,`R1 ,`CREG_RESOLUTION };
125
16: I = { `RETURN ,`RT_FALSE   };
126
 
127
//----------------------------------------------------------------------          
128
//Micro code for RGU
129
//TAG_RGU_UCODE_ADDRESS:
130
 
131
 
132
17: I = { `MUL ,`R1 ,`CREG_PIXEL_2D_POSITION ,`CREG_PROJECTION_WINDOW_SCALE };
133
18: I = { `ADD ,`R1 ,`R1 ,`CREG_PROJECTION_WINDOW_MIN };
134
19: I = { `SUB ,`CREG_UNORMALIZED_DIRECTION ,`R1 ,`CREG_CAMERA_POSITION };
135
20: I = { `MAG ,`R2 ,`CREG_UNORMALIZED_DIRECTION ,`VOID };
136
21: I = { `DIV ,`CREG_RAY_DIRECTION ,`CREG_UNORMALIZED_DIRECTION ,`R2 };
137
22: I = { `DEC,`CREG_LAST_COL,`CREG_RESOLUTION,`VOID};//{ `ZERO ,`R3 ,`VOID ,`VOID }; 
138
23: I = { `RETURN ,`RT_FALSE   };
139
//----------------------------------------------------------------------
140
//Next Pixel generation Code (NPG)
141
//TAG_NPG_UCODE_ADDRESS:
142
 
143
24: I = { `ZERO ,`R1 ,`VOID ,`VOID };
144
25: I = { `SETX ,`R1 ,32'h00003  };
145
26: I = { `ADD ,`OREG_PIXEL_PITCH ,`OREG_PIXEL_PITCH ,`R1 };
146
 
147
27: I = { `JEQX ,`LABEL_NPG_NEXT_ROW ,`CREG_PIXEL_2D_POSITION ,`CREG_LAST_COL }; //HERE WE ARE CALCULATING ELEMENT 200 :(
148
28: I = { `INCX ,`CREG_PIXEL_2D_POSITION ,`CREG_PIXEL_2D_POSITION ,`VOID };
149
29: I = { `RETURN ,`RT_TRUE   };
150
//LABEL_NPG_NEXT_ROW:
151
30: I = { `SETX ,`CREG_PIXEL_2D_POSITION ,32'h0  };
152
31: I = { `INCY ,`CREG_PIXEL_2D_POSITION ,`CREG_PIXEL_2D_POSITION,`VOID  };
153
32: I = { `RETURN ,`RT_TRUE   };
154
 
155
//----------------------------------------------------------------------
156
//Micro code for AABBIU
157
//TAG_AABBIU_UCODE_ADDRESS:
158
 
159
33: I = { `ZERO ,`R3 ,`VOID ,`VOID };
160
34: I = { `ZERO ,`R5 ,`VOID ,`VOID };
161
35: I = { `NOP ,`RT_FALSE   };
162
 
163
//LABEL_TEST_RAY_X_ORIGEN:
164
36: I = { `JGEX ,`LABEL_ELSE_IFX ,`CREG_CAMERA_POSITION ,`CREG_AABBMIN };
165
37: I = { `SUB ,`R1 ,`CREG_AABBMIN ,`CREG_CAMERA_POSITION };
166
38: I = { `JLEX ,`LABEL1 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
167
39: I = { `RETURN ,`RT_FALSE   };
168
 
169
//LABEL1:
170
40: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
171
41: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
172
42: I = { `JMP ,`LABEL_TEST_RAY_Y_ORIGEN ,`VOID ,`VOID };
173
 
174
//LABEL_ELSE_IFX:
175
43: I = { `JLEX ,`LABEL_ELSEX ,`CREG_CAMERA_POSITION ,`CREG_AABBMAX };
176
44: I = { `SUB ,`R1 ,`CREG_AABBMAX ,`CREG_CAMERA_POSITION };
177
45: I = { `JGEX ,`LABEL2 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
178
46: I = { `RETURN ,`RT_FALSE   };
179
 
180
//LABEL2:
181
47: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
182
48: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
183
49: I = { `JMP ,`LABEL_TEST_RAY_Y_ORIGEN ,`VOID ,`VOID };
184
//LABEL_ELSEX:
185
50: I = { `SETX ,`R5 ,32'b1  };
186
 
187
//LABEL_TEST_RAY_Y_ORIGEN:
188
51: I = { `JGEY ,`LABEL_ELESE_IFY ,`CREG_CAMERA_POSITION ,`CREG_AABBMIN };
189
52: I = { `SUB ,`R1 ,`CREG_AABBMIN ,`CREG_CAMERA_POSITION };
190
53: I = { `JLEY ,`LABEL3 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
191
54: I = { `RETURN ,`RT_FALSE   };
192
 
193
//LABEL3:
194
55: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
195
56: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
196
57: I = { `JMP ,`LABEL_TEST_RAY_Z_ORIGEN ,`VOID ,`VOID };
197
 
198
//LABEL_ELESE_IFY:
199
58: I = { `JLEY ,`LABEL_ELSEY ,`CREG_CAMERA_POSITION ,`CREG_AABBMAX };
200
59: I = { `SUB ,`R1 ,`CREG_AABBMAX ,`CREG_CAMERA_POSITION };
201
60: I = { `JGEY ,`LABEL4 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
202
61: I = { `RETURN ,`RT_FALSE   };
203
 
204
//LABEL4:
205
62: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
206
63: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
207
64: I = { `JMP ,`LABEL_TEST_RAY_Z_ORIGEN ,`VOID ,`VOID };
208
 
209
//LABEL_ELSEY:
210
65: I = { `SETY ,`R5 ,32'b1  };
211
 
212
//LABEL_TEST_RAY_Z_ORIGEN:
213
66: I = { `JGEZ ,`LABEL_ELESE_IFZ ,`CREG_CAMERA_POSITION ,`CREG_AABBMIN };
214
67: I = { `SUB ,`R1 ,`CREG_AABBMIN ,`CREG_CAMERA_POSITION };
215
68: I = { `JLEZ ,`LABEL5 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
216
69: I = { `RETURN ,`RT_FALSE   };
217
 
218
//LABEL5:
219
70: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
220
71: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
221
72: I = { `JMP ,`LABEL_RAY_INSIDE_BOX ,`VOID ,`VOID };
222
 
223
//LABEL_ELESE_IFZ:
224
73: I = { `JLEZ ,`LABEL_ELSEZ ,`CREG_CAMERA_POSITION ,`CREG_AABBMAX };
225
74: I = { `SUB ,`R1 ,`CREG_AABBMAX ,`CREG_CAMERA_POSITION };
226
75: I = { `JGEZ ,`LABEL6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
227
76: I = { `RETURN ,`RT_FALSE   };
228
 
229
//LABEL6:
230
77: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
231
78: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
232
79: I = { `JMP ,`LABEL_RAY_INSIDE_BOX ,`VOID ,`VOID };
233
 
234
//LABEL_ELSEZ:
235
80: I = { `SETZ ,`R5 ,32'b1  };
236
 
237
//LABEL_RAY_INSIDE_BOX:
238
81: I = { `ZERO ,`R1 ,`VOID ,`VOID };
239
82: I = { `JEQX ,`LABEL_TEST_YZ_PLANE ,`R1 ,`RAY_INSIDE_BOX };
240
83: I = { `RETURN ,`RT_TRUE   };
241
 
242
//LABEL_TEST_YZ_PLANE:
243
84: I = { `JNEX ,`LABEL_TEST_XZ_PLANE ,`R5 ,`R1 };
244
85: I = { `SWIZZLE3D ,`R6 ,`SWIZZLE_XXX  };
245
86: I = { `MUL ,`R2 ,`CREG_UNORMALIZED_DIRECTION ,`R6 };
246
87: I = { `ADD ,`R2 ,`R2 ,`CREG_CAMERA_POSITION };
247
88: I = { `JGEY ,`LABEL7 ,`R2 ,`CREG_AABBMIN };
248
89: I = { `RETURN ,`RT_FALSE   };
249
 
250
//LABEL7:
251
90: I = { `JLEY ,`LABEL8 ,`R2 ,`CREG_AABBMAX };
252
91: I = { `RETURN ,`RT_FALSE   };
253
 
254
//LABEL8:
255
92: I = { `JGEZ ,`LABEL9 ,`R2 ,`CREG_AABBMIN };
256
93: I = { `RETURN ,`RT_FALSE   };
257
 
258
//LABEL9:
259
94: I = { `JLEZ ,`LABEL_TEST_XZ_PLANE ,`R2 ,`CREG_AABBMAX };
260
95: I = { `RETURN ,`RT_FALSE   };
261
 
262
//LABEL_TEST_XZ_PLANE:
263
96: I = { `JNEY ,`LABEL_TEST_XY_PLANE ,`R5 ,`R1 };
264
97: I = { `SWIZZLE3D ,`R6 ,`SWIZZLE_YYY  };
265
98: I = { `MUL ,`R2 ,`CREG_UNORMALIZED_DIRECTION ,`R6 };
266
99: I = { `ADD ,`R2 ,`R2 ,`CREG_CAMERA_POSITION };
267
100: I = { `JGEX ,`LABEL10 ,`R2 ,`CREG_AABBMIN };
268
101: I = { `RETURN ,`RT_FALSE   };
269
 
270
//LABEL10:
271
102: I = { `JLEX ,`LABEL11 ,`R2 ,`CREG_AABBMAX };
272
103: I = { `RETURN ,`RT_FALSE   };
273
 
274
//LABEL11:
275
104: I = { `JGEZ ,`LABEL12 ,`R2 ,`CREG_AABBMIN };
276
105: I = { `RETURN ,`RT_FALSE   };
277
 
278
//LABEL12:
279
106: I = { `JLEZ ,`LABEL_TEST_XY_PLANE ,`R2 ,`CREG_AABBMAX };
280
107: I = { `RETURN ,`RT_FALSE   };
281
 
282
//LABEL_TEST_XY_PLANE:
283
108: I = { `SWIZZLE3D ,`R6 ,`SWIZZLE_ZZZ  };
284
109: I = { `MUL ,`R2 ,`CREG_UNORMALIZED_DIRECTION ,`R6 };
285
110: I = { `ADD ,`R2 ,`R2 ,`CREG_CAMERA_POSITION };
286
111: I = { `JGEX ,`LABEL13 ,`R2 ,`CREG_AABBMIN };
287
112: I = { `RETURN ,`RT_FALSE   };
288
 
289
//LABEL13:
290
113: I = { `JLEX ,`LABEL14 ,`R2 ,`CREG_AABBMAX };
291
114: I = { `RETURN ,`RT_FALSE   };
292
 
293
//LABEL14:
294
115: I = { `JGEY ,`LABEL15 ,`R2 ,`CREG_AABBMIN };
295
116: I = { `RETURN ,`RT_FALSE   };
296
 
297
//LABEL15:
298
117: I = { `JLEY ,`LABEL_HIT ,`R2 ,`CREG_AABBMAX };
299
118: I = { `RETURN ,`RT_FALSE   };
300
 
301
//LABEL_HIT:
302
119: I = { `SETX ,`CREG_LAST_t ,32'h1F40000  };
303
120: I = { `RETURN ,`RT_TRUE   };
304
 
305
 //------------------------------------------------------------------------
306
 //BIU Micro code
307
//TAG_BIU_UCODE_ADDRESS:
308
 
309
121: I = { `ZERO ,`OREG_PIXEL_COLOR ,`VOID ,`VOID };
310
122: I = { `SETX ,`R3 ,`ONE  };
311
123: I = { `SETX ,`R1 ,32'h00000  };
312
124: I = { `SUB ,`CREG_E1 ,`CREG_V1 ,`CREG_V0 };
313
125: I = { `SUB ,`CREG_E2 ,`CREG_V2 ,`CREG_V0 };
314
126: I = { `SUB ,`CREG_T ,`CREG_CAMERA_POSITION ,`CREG_V0 };
315
127: I = { `CROSS ,`CREG_P ,`CREG_RAY_DIRECTION ,`CREG_E2 };
316
128: I = { `CROSS ,`CREG_Q ,`CREG_T ,`CREG_E1 };
317
129: I = { `DOT ,`CREG_H1 ,`CREG_Q ,`CREG_E2 };
318
130: I = { `DOT ,`CREG_H2 ,`CREG_P ,`CREG_T };
319
131: I = { `DOT ,`CREG_H3 ,`CREG_Q ,`CREG_RAY_DIRECTION };
320
132: I = { `DOT ,`CREG_DELTA ,`CREG_P ,`CREG_E1 };
321
133: I = { `DIV ,`CREG_t ,`CREG_H1 ,`CREG_DELTA };
322
134: I = { `DIV ,`CREG_u ,`CREG_H2 ,`CREG_DELTA };
323
135: I = { `DIV ,`CREG_v ,`CREG_H3 ,`CREG_DELTA };
324
136: I = { `JGEX ,`LABEL_BIU1 ,`CREG_u ,`R1 };
325
137: I = { `RETURN ,`RT_FALSE   };
326
 
327
//LABEL_BIU1:
328
138: I = { `JGEX ,`LABEL_BIU2 ,`CREG_v ,`R1 };
329
139: I = { `RETURN ,`RT_FALSE   };
330
 
331
//LABEL_BIU2:
332
140: I = { `ADD ,`R2 ,`CREG_u ,`CREG_v };
333
141: I = { `JLEX ,`LABEL_BIU3 ,`R2 ,`R3 };
334
142: I = { `RETURN ,`RT_FALSE   };
335
 
336
//LABEL_BIU3:
337
143: I = { `JGEX ,`LABEL_BIU4 ,`CREG_t ,`CREG_LAST_t };
338
144: I = { `COPY ,`CREG_LAST_t ,`CREG_t ,`VOID };
339
145: I = { `COPY ,`CREG_LAST_u ,`CREG_u ,`VOID };
340
146: I = { `COPY ,`CREG_LAST_v ,`CREG_v ,`VOID };
341
147: I = { `COPY ,`CREG_E1_LAST ,`CREG_E1 ,`VOID };
342
148: I = { `COPY ,`CREG_E2_LAST ,`CREG_E2 ,`VOID };
343
149: I = { `COPY ,`CREG_UV0_LAST ,`CREG_UV0 ,`VOID };
344
150: I = { `COPY ,`CREG_UV1_LAST ,`CREG_UV1 ,`VOID };
345
151: I = { `COPY ,`CREG_UV2_LAST ,`CREG_UV2 ,`VOID };
346
152: I = { `COPY ,`CREG_TRI_DIFFUSE_LAST ,`CREG_TRI_DIFFUSE ,`VOID };
347
//LABEL_BIU4:
348
153: I = { `RETURN ,`RT_TRUE   };
349
 
350
 
351
//-------------------------------------------------------------------------
352
//Calculate the adress of the texure coordiantes.
353
 
354
//TAG_TCC_UCODE_ADDRESS:
355
//Do this calculation only if this triangle is the one closest to the camera
356
154: I = { `JGX ,`LABEL_TCC_EXIT ,`CREG_t ,`CREG_LAST_t };
357
 
358
//First get the UV coodrinates and store in R1
359
//R1x: u_coordinate = U0 + last_u * (U1 - U0) + last_v * (U2 - U0);
360
//R1y: v_coordinate = V0 + last_u * (V1 - V0) + last_v * (V2 - V0);
361
//R1z: 0
362
 
363
155: I = { `SUB ,`R1 ,`CREG_UV1_LAST ,`CREG_UV0_LAST };
364
156: I = { `SUB ,`R2 ,`CREG_UV2_LAST ,`CREG_UV0_LAST };
365
157: I = { `MUL ,`R1 ,`CREG_LAST_u ,`R1 };
366
158: I = { `MUL ,`R2 ,`CREG_LAST_v ,`R2 };
367
159: I = { `ADD ,`R1 ,`R1 ,`R2 };
368
160: I = { `ADD ,`R1 ,`R1 ,`CREG_UV0 };
369
 
370
//R7x : fu = (u_coordinate) * gTexture.mWidth;
371
//R7y : fv = (v_coordinate) * gTexture.mWidth;
372
//R7z : 0
373
161: I = { `MUL ,`R7 ,`R1 ,`CREG_TEXTURE_SIZE };
374
 
375
//R1x: u1 = ((int)fu) % gTexture.mWidth;
376
//R1y: v1 = ((int)fv) % gTexture.mHeight;
377
//R1z: 0
378
//R2x: u2 = (u1 + 1 ) % gTexture.mWidth;
379
//R2y: v2 = (v2 + 1 ) % gTexture.mHeight;
380
//R2z: 0
381
// Notice MOD2 only operates over
382
// numbers that are power of 2, also notice that the
383
// textures are assumed to be squares!
384
//x % 2^n == x & (2^n - 1).
385
 
386
162: I = { `MOD ,`R1 ,`R7 ,`CREG_TEXTURE_SIZE };
387
163: I = { `INC ,`R2 ,`R1 ,`VOID };
388
164: I = { `MOD ,`R2 ,`R2 ,`CREG_TEXTURE_SIZE };
389
 
390
//Cool, now we should store the values in the appropiate registers
391
//OREG_TEX_COORD1.x = u1 + v1 * gTexture.mWidth
392
//OREG_TEX_COORD1.y = u2 + v1 * gTexture.mWidth
393
//OREG_TEX_COORD1.z = 0
394
//OREG_TEX_COORD2.x = u1 + v2 * gTexture.mWidth
395
//OREG_TEX_COORD2.y = u2 + v2 * gTexture.mWidth
396
//OREG_TEX_COORD1.z = 0
397
 
398
//R1= [u1, v1, 0]
399
//R2= [u2, v2, 0]
400
 
401
//R2 = [v2, u2, 0]
402
165: I = { `SWIZZLE3D ,`R2 ,`SWIZZLE_YXZ  };
403
 
404
//R3 = [v2 v1 0]
405
166: I = { `XCHANGEX ,`R3 ,`R1 ,`R2 };
406
 
407
 
408
//R4 = [u1, u2 0]
409
167: I = { `XCHANGEX ,`R4 ,`R2 ,`R1 };
410
 
411
//R2 = [v2*H, v1*H, 0]
412
//R2 = FixedToInteger(R3*CREG_TEXTURE_SIZE)
413
168: I = { `UNSCALE ,`R9 ,`R3 ,`VOID };
414
169: I = { `UNSCALE ,`R8 ,`CREG_TEXTURE_SIZE ,`VOID };
415
170: I = { `IMUL ,`R2 ,`R9 ,`R8 };
416
 
417
//OREG_TEX_COORD1 = [u1 + v2*H, u2 + v1*H, 0]
418
//R4 = FixedToIinteger(R4)
419
171: I = { `UNSCALE ,`R4 ,`R4 ,`VOID };
420
172: I = { `ADD ,`OREG_TEX_COORD1 ,`R2 ,`R4 };
421
173: I = { `SETX ,`R5 ,32'h3  };
422
174: I = { `SETY ,`R5 ,32'h3  };
423
175: I = { `SETZ ,`R5 ,32'h3  };
424
//Multiply by 3 (the pitch)
425
176: I = { `IMUL ,`OREG_TEX_COORD1 ,`OREG_TEX_COORD1 ,`R5 };
426
 
427
//R4 = [u2 u1 0]
428
177: I = { `SWIZZLE3D ,`R4 ,`SWIZZLE_YXZ  };
429
 
430
 
431
//OREG_TEX_COORD2 [u2 + v2*H, u1 + v1*H, 0]
432
178: I = { `ADD ,`OREG_TEX_COORD2 ,`R2 ,`R4 };
433
//Multiply by 3 (the pitch)
434
179: I = { `IMUL ,`OREG_TEX_COORD2 ,`OREG_TEX_COORD2 ,`R5 };
435
 
436
 
437
//Cool now get the weights
438
 
439
//w1 = (1 - fracu) * (1 - fracv);
440
//w2 = fracu * (1 - fracv);
441
//w3 = (1 - fracu) * fracv;
442
//w4 = fracu *  fracv;
443
 
444
//R4x: fracu 
445
//R4y: fracv 
446
//R4z: 0
447
180: I = { `FRAC ,`R4 ,`R7 ,`VOID };
448
 
449
//R5x: fracv 
450
//R5y: fracu 
451
//R5z: 0 
452
181: I = { `COPY ,`R5 ,`R4 ,`VOID };
453
182: I = { `SWIZZLE3D ,`R5 ,`SWIZZLE_YXZ  };
454
 
455
 
456
//R5x: 1 - fracv 
457
//R5y: 1 - fracu 
458
//R5y: 1
459
183: I = { `NEG ,`R5 ,`R5 ,`VOID };
460
184: I = { `INC ,`R5 ,`R5 ,`VOID };
461
 
462
//R5x: 1 - fracv 
463
//R5y: 1 - fracu 
464
//R5y: (1 - fracv)(1 - fracu) 
465
185: I = { `MULP ,`OREG_TEXWEIGHT1 ,`R5 ,`VOID };
466
 
467
//OREG_TEXWEIGHT1.x = (1 - fracv)(1 - fracu) 
468
//OREG_TEXWEIGHT1.y = (1 - fracv)(1 - fracu) 
469
//OREG_TEXWEIGHT1.z = (1 - fracv)(1 - fracu) 
470
186: I = { `SWIZZLE3D ,`OREG_TEXWEIGHT1 ,`SWIZZLE_ZZZ  };
471
 
472
 
473
//R6x: w2: fracu * (1 - fracv )
474
//R6y: w3: fracv * (1 - fracu )
475
//R6z: 0
476
187: I = { `MUL ,`R6 ,`R4 ,`R5 };
477
 
478
//OREG_TEXWEIGHT2.x = fracu * (1 - fracv )
479
//OREG_TEXWEIGHT2.y = fracu * (1 - fracv )
480
//OREG_TEXWEIGHT2.z = fracu * (1 - fracv )
481
188: I = { `COPY ,`OREG_TEXWEIGHT2 ,`R6 ,`VOID };
482
189: I = { `SWIZZLE3D ,`OREG_TEXWEIGHT2 ,`SWIZZLE_XXX  };
483
 
484
//OREG_TEXWEIGHT3.x = fracv * (1 - fracu )
485
//OREG_TEXWEIGHT3.y = fracv * (1 - fracu )
486
//OREG_TEXWEIGHT3.z = fracv * (1 - fracu )
487
190: I = { `COPY ,`OREG_TEXWEIGHT3 ,`R6 ,`VOID };
488
191: I = { `SWIZZLE3D ,`OREG_TEXWEIGHT3 ,`SWIZZLE_YYY  };
489
 
490
 
491
//R4x: fracu
492
//R4y: fracv
493
//R4z: fracu * fracv
494
192: I = { `MULP ,`R4 ,`R4 ,`VOID };
495
 
496
//OREG_TEXWEIGHT4.x = fracv * fracu 
497
//OREG_TEXWEIGHT4.y = fracv * fracu 
498
//OREG_TEXWEIGHT4.z = fracv * fracu 
499
193: I = { `COPY ,`OREG_TEXWEIGHT4 ,`R4 ,`VOID };
500
194: I = { `SWIZZLE3D ,`OREG_TEXWEIGHT4 ,`SWIZZLE_ZZZ  };
501
 
502
 
503
//LABEL_TCC_EXIT:
504
195: I = { `RETURN ,`RT_TRUE   };
505
 
506
 
507
//-------------------------------------------------------------------------
508
//TAG_PSU_UCODE_ADRESS:
509
//Pixel Shader #1
510
//This pixel shader has diffuse light but no textures
511
 
512
 
513
196: I = { `CROSS ,`R1 ,`CREG_E1_LAST ,`CREG_E2_LAST };
514
197: I = { `MAG ,`R2 ,`R1 ,`VOID };
515
198: I = { `DIV ,`R1 ,`R1 ,`R2 };
516
199: I = { `MUL ,`R2 ,`CREG_RAY_DIRECTION ,`CREG_LAST_t };
517
200: I = { `ADD ,`R2 ,`R2 ,`CREG_CAMERA_POSITION };
518
201: I = { `SUB ,`R2 ,`CURRENT_LIGHT_POS ,`R2 };
519
202: I = { `MAG ,`R3 ,`R2 ,`VOID };
520
203: I = { `DIV ,`R2 ,`R2 ,`R3 };
521
204: I = { `DOT ,`R3 ,`R2 ,`R1 };
522
205: I = { `MUL ,`COLOR_ACC ,`CREG_TRI_DIFFUSE_LAST ,`CURRENT_LIGHT_DIFFUSE };
523
206: I = { `MUL ,`COLOR_ACC ,`COLOR_ACC ,`R3 };
524
207: I = { `COPY ,`OREG_PIXEL_COLOR ,`COLOR_ACC ,`VOID };
525
208: I = { `JLEX ,`LABEL_DEBUG_PRINT_REGS ,`COLOR_ACC ,`R3 };
526
209: I = { `JMP ,`LABEL_DEBUG_PRINT_REGS ,`VOID ,`VOID };
527
210: I = { `NOP ,`RT_FALSE   };//{ `INC ,`OREG_PIXEL_PITCH ,`VOID  }; 
528
211: I = { `RETURN ,`RT_TRUE   };
529
 
530
//-------------------------------------------------------------------------
531
//Pixel Shader #2
532
//TAG_PSU_UCODE_ADRESS2:
533
 
534
 
535
//This Pixel Shader has no light but it does texturinng 
536
//with bi-linear interpolation
537
 
538
//CColor TextureColor;
539
//TextureColor.R = c1.R * w1 + c2.R * w2 + c3.R * w3 + c4.R * w4;
540
//TextureColor.G = c1.G * w1 + c2.G * w2 + c3.G * w3 + c4.G * w4;
541
//TextureColor.B = c1.B * w1 + c2.B * w2 + c3.B * w3 + c4.B * w4;
542
 
543
212: I = { `MUL ,`R1 ,`CREG_TEX_COLOR5 ,`OREG_TEXWEIGHT1 };
544
213: I = { `MUL ,`R2 ,`CREG_TEX_COLOR2 ,`OREG_TEXWEIGHT2 };
545
214: I = { `MUL ,`R3 ,`CREG_TEX_COLOR1 ,`OREG_TEXWEIGHT3 };
546
215: I = { `MUL ,`R4 ,`CREG_TEX_COLOR4 ,`OREG_TEXWEIGHT4 };
547
216: I = { `ADD ,`OREG_PIXEL_COLOR ,`R1 ,`R2 };
548
217: I = { `ADD ,`OREG_PIXEL_COLOR ,`OREG_PIXEL_COLOR ,`R3 };
549
218: I = { `ADD ,`OREG_PIXEL_COLOR ,`OREG_PIXEL_COLOR ,`R4 };
550
219: I = { `RETURN ,`RT_TRUE   }; //{ `INC ,`OREG_PIXEL_PITCH ,`VOID  }; 
551
 
552
 
553
220: I = { `RETURN ,`RT_TRUE   };
554
 
555
 
556
//-------------------------------------------------------------------------
557
//Debug Code
558
//TAG_DEBUG_LOG_REGISTERS:
559
 
560
//LABEL_DEBUG_PRINT_REGS:
561
/*
562
221: I = { `DEBUG_PRINT ,`CREG_PIXEL_2D_POSITION ,`CREG_PIXEL_2D_POSITION ,`VOID };
563
222: I = { `DEBUG_PRINT ,`COLOR_ACC ,`COLOR_ACC ,`VOID };
564
223: I = { `DEBUG_PRINT ,`CREG_LAST_t ,`CREG_LAST_t ,`VOID };
565
224: I = { `DEBUG_PRINT ,`CREG_E1_LAST ,`CREG_E1_LAST ,`VOID };
566
225: I = { `DEBUG_PRINT ,`CREG_E2_LAST ,`CREG_E2_LAST ,`VOID };
567
226: I = { `DEBUG_PRINT ,`CREG_RAY_DIRECTION ,`CREG_RAY_DIRECTION ,`VOID };
568
227: I = { `DEBUG_PRINT ,`CREG_CAMERA_POSITION ,`CREG_CAMERA_POSITION ,`VOID };
569
228: I = { `DEBUG_PRINT ,`CREG_V0 ,`CREG_V0 ,`VOID };
570
229: I = { `DEBUG_PRINT ,`CREG_V1 ,`CREG_V1 ,`VOID };
571
230: I = { `DEBUG_PRINT ,`CREG_V2 ,`CREG_V2 ,`VOID };
572
231: I = { `RETURN ,`RT_TRUE   };
573
*/
574
 
575
//-------------------------------------------------------------------------             
576
 
577
 
578
                        default:
579
                        begin
580
 
581
                        `ifdef DEBUG
582
                        $display("Error: Reached undefined address in instruction Memory: %d!!!!",Address);
583
                        $stop();
584
                        `endif
585
                        I = {`INSTRUCTION_OP_LENGTH'hFF,16'hFFFF,32'hFFFFFFFF};
586
                        end
587
                        endcase
588
        end
589
endmodule
590
//--------------------------------------------------------

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.