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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_1.2/] [rtl/] [CONTROL/] [Unit_Control.v] - Blame information for rev 81

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

Line No. Rev Author Line
1 18 diegovalve
/**********************************************************************************
2
Theia, Ray Cast Programable graphic Processing Unit.
3
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
4
 
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
9
 
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14
 
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 
19
***********************************************************************************/
20
/**********************************************************************************
21
Description:
22
 
23
This is the main Finite State Machine.
24
 
25
**********************************************************************************/
26
 
27
`timescale 1ns / 1ps
28
`include "aDefinitions.v"
29
 
30
`define CU_AFTER_RESET_STATE 0
31
`define CU_WAIT_FOR_INITIAL_CONFIGURATION 1
32
`define CU_TRIGGER_CONFIGURATION_DATA_READ 2
33
`define CU_WAIT_FOR_CONFIG_DATA_READ    3
34
`define CU_ACK_CONFIG_DATA_READ 4
35
`define CU_PRECALCULATE_CONSTANTS 5
36
`define CU_WAIT_FOR_CONSTANT 6
37
`define CU_ACK_PRECALCULATE_CONSTANTS 7
38
`define CU_WAIT_FOR_TASK 8
39
`define CU_READ_TASK_DATA 9
40
`define CU_WAIT_TASK_DATA_READ 10
41
`define CU_ACK_TASK_DATA_READ 11
42
`define CU_TRIGGER_RGU 12
43
`define CU_WAIT_FOR_RGU 13
44
`define CU_ACK_RGU 14
45
`define CU_TRIGGER_GEO 15
46
`define CU_WAIT_FOR_GEO_SYNC 16
47
//`define CU_CHECK_AABBIU_REQUEST 17
48
`define CU_TRIGGER_TCC 17
49
//`define CU_CHECK_BIU_REQUEST 18
50
`define CU_TRIGGER_TFF 18
51
//`define CU_CHECK_GEO_DONE 19
52
`define CU_WAIT_FOR_TFF 19
53
`define CU_TRIGGER_AABBIU 20
54
`define CU_WAIT_FOR_AABBIU 21
55
`define CU_TRIGGER_BIU 22
56
`define CU_WAIT_FOR_BIU 23
57
`define CU_ACK_UCODE 24
58
`define CU_TRIGGER_PSU 25
59
`define CU_WAIT_FOR_PSU 26
60
`define CU_ACK_PSU 27
61
`define CU_TRIGGER_PCU 28
62
`define CU_WAIT_FOR_PCU 29
63
`define CU_ACK_PCU 30
64
`define CU_CHECK_HIT 31
65
`define CU_CLEAR_REGISTERS 32
66
`define CU_WAIT_CLEAR_REGISTERS 33
67
`define CU_ACK_CLEAR_REGISTERS  34
68
`define CU_TRIGGER_PSU_WITH_TEXTURE 35
69
`define WAIT_FOR_TCC 36
70
`define CU_TRIGGER_NPU 37
71
`define CU_WAIT_NPU 38
72
`define CU_ACK_NPU 39
73
`define CU_PERFORM_INTIAL_CONFIGURATION 40
74
`define CU_SET_PICTH 41
75 63 diegovalve
`define CU_TRIGGER_USERCONSTANTS 42
76
`define CU_WAIT_USERCONSTANTS           43
77
`define CU_ACK_USERCONSTANTS 44
78
`define CU_TRIGGER_USERPIXELSHADER 45
79
`define CU_WAIT_FOR_USERPIXELSHADER 46
80 76 diegovalve
`define CU_ACK_USERPIXELSHADER 47
81
`define CU_DONE 48
82
`define CU_WAIT_FOR_RENDER_ENABLE 49
83 18 diegovalve
 
84
//--------------------------------------------------------------
85
module ControlUnit
86
(
87
 
88
input  wire                                  Clock,
89
input  wire                                  Reset,
90
input  wire[15:0]                            iControlRegister,
91
output reg                                   oGFUEnable,
92
input    wire                                  iTriggerAABBIURequest,
93
input   wire                                   iTriggerBIURequest,
94
input wire                                   iTriggertTCCRequest,
95
output reg                                   oUCodeEnable,
96 60 diegovalve
output reg[`ROM_ADDRESS_WIDTH-1:0]           oCodeInstructioPointer,
97 18 diegovalve
input   wire                                   iUCodeDone,
98
input wire                                   iUCodeReturnValue,
99
input wire                                   iGFUDone,
100
input wire                                   iGEOSync,
101
output reg                                   oTriggerTFF,
102
input wire                                   iTFFDone,
103
input wire                                   MST_I,
104
output reg[2:0]                              oRamBusOwner,
105
input wire                                   iIODone,
106
output reg                                   oSetCurrentPitch,
107 71 diegovalve
output reg                                   oFlipMemEnabled,
108
output reg                                   oFlipMem,
109 76 diegovalve
output reg                                   oIOWritePixel,
110
input wire                                  iRenderEnable,
111
 
112
`ifdef DEBUG
113
input wire[`MAX_CORES-1:0]                  iDebug_CoreID,
114
`endif
115
 
116
output reg                                   oDone
117 18 diegovalve
 
118
);
119
 
120
//Internal State Machine varibles
121
reg     [5:0]    CurrentState;
122
reg     [5:0]    NextState;
123
integer ucode_file;
124
reg rResetHitFlop,rHitFlopEnable;
125
wire wHit;
126
 
127
`ifdef DUMP_CODE
128
        integer log;
129
 
130
        initial
131
        begin
132
 
133 76 diegovalve
        //$display("Opening ucode dump file....\n");
134 18 diegovalve
        ucode_file = $fopen("CU.log","w");
135
        end
136
 
137
`endif
138
 
139
//--------------------------------------------------------------
140
FFToggleOnce_1Bit FFTO1
141
(
142
        .Clock( Clock ),
143
        .Reset( rResetHitFlop ),
144
        .Enable( rHitFlopEnable && iUCodeDone ),
145
        .S( iUCodeReturnValue ),
146
        .Q( wHit )
147
);
148
//--------------------------------------------------------------
149
 
150 81 diegovalve
`ifdef DEBUG_CU
151 18 diegovalve
        always @ ( wHit )
152
        begin
153
                `LOGME "*** Triangle HIT ***\n");
154
        end
155
`endif
156
 
157
//Next states logic and Reset sequence
158
always @(posedge Clock or posedge Reset)
159
  begin
160
 
161
    if (Reset)
162
                CurrentState <= `CU_AFTER_RESET_STATE;
163
    else
164
                CurrentState <= NextState;
165
 
166
  end
167
 
168
//--------------------------------------------------------------
169
always @ ( * )
170
begin
171
        case (CurrentState)
172
        //-----------------------------------------
173
        `CU_AFTER_RESET_STATE:
174
        begin
175
 
176 81 diegovalve
        `ifdef DEBUG_CU
177 18 diegovalve
                `LOGME"%d CU_AFTER_RESET_STATE\n",$time);
178
        `endif
179
 
180
                oRamBusOwner                            <= 0;
181 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_INITIAL;
182 18 diegovalve
                oGFUEnable                                      <= 0;
183
                oUCodeEnable                            <= 0;
184
                oIOWritePixel                           <= 0;
185
                rResetHitFlop                           <= 1;
186
                rHitFlopEnable                          <= 0;
187
                oTriggerTFF             <= 0;
188
                oSetCurrentPitch        <= 1;
189 71 diegovalve
                oFlipMemEnabled         <= 0;
190 76 diegovalve
                oFlipMem                                                <= 0;
191
                oDone                   <= 0;
192 18 diegovalve
                //oIncCurrentPitch        <= 0;
193
 
194
                NextState                                       <= `CU_WAIT_FOR_INITIAL_CONFIGURATION;
195
 
196
        end
197
        //-----------------------------------------
198
 
199
        `CU_WAIT_FOR_INITIAL_CONFIGURATION:
200
        begin
201 76 diegovalve
        //$display("CORE: %d CU_WAIT_FOR_INITIAL_CONFIGURATION", iDebug_CoreID);
202 81 diegovalve
//              `ifdef DEBUG_CU
203 18 diegovalve
//                      `LOGME"%d Control: CU_WAIT_FOR_INITIAL_CONFIGURATION\n",$time);
204
//              `endif
205
 
206
                oRamBusOwner                            <= 0;
207 60 diegovalve
                oCodeInstructioPointer  <= 0;
208 18 diegovalve
                oGFUEnable                                      <= 0;
209
                oUCodeEnable                            <= 0;
210
                oIOWritePixel                           <= 0;
211
                rResetHitFlop                           <= 1;
212
                rHitFlopEnable                          <= 0;
213
      oTriggerTFF             <= 0;
214
                oSetCurrentPitch        <= 0;
215 71 diegovalve
                oFlipMemEnabled         <= 0;
216 76 diegovalve
                oFlipMem                                                <= 0;
217
                oDone                   <= 0;
218 18 diegovalve
                //oIncCurrentPitch        <= 0;         
219
 
220
                if ( MST_I  )
221
                        NextState <= `CU_PERFORM_INTIAL_CONFIGURATION;//`CU_WAIT_FOR_CONFIG_DATA_READ;
222
                else
223
                        NextState <= `CU_WAIT_FOR_INITIAL_CONFIGURATION;
224
 
225
 
226
        end
227
        //-----------------------------------------
228
        `CU_PERFORM_INTIAL_CONFIGURATION:
229 76 diegovalve
        begin
230
        //$display("CORE: %d CU_PERFORM_INTIAL_CONFIGURATION", iDebug_CoreID);
231 18 diegovalve
        oRamBusOwner                            <= 0;
232 60 diegovalve
                oCodeInstructioPointer  <= 0;
233 18 diegovalve
                oGFUEnable                                      <= 0;
234
                oUCodeEnable                            <= 0;
235
                oIOWritePixel                           <= 0;
236
                rResetHitFlop                           <= 1;
237
                rHitFlopEnable                          <= 0;
238
      oTriggerTFF             <= 0;
239
                oSetCurrentPitch        <= 0;
240 71 diegovalve
                oFlipMemEnabled         <= 0;
241 76 diegovalve
                oFlipMem                                                <= 0;
242
                oDone                   <= 0;
243 18 diegovalve
                //oIncCurrentPitch        <= 0;         
244
 
245 76 diegovalve
                if ( MST_I  == 0 && iRenderEnable == 1'b1)
246
                        NextState <= `CU_CLEAR_REGISTERS;//`CU_WAIT_FOR_CONFIG_DATA_READ;
247
                else
248
                        NextState <= `CU_PERFORM_INTIAL_CONFIGURATION;
249
 
250 18 diegovalve
 
251
        end
252
        //-----------------------------------------
253
        `CU_CLEAR_REGISTERS:
254 76 diegovalve
        begin
255
        //$display("CORE: %d CU_CLEAR_REGISTERS", iDebug_CoreID);
256 81 diegovalve
        `ifdef DEBUG_CU
257 18 diegovalve
                `LOGME"%d CU_CLEAR_REGISTERS\n",$time);
258
        `endif
259
 
260
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
261 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_INITIAL;
262 18 diegovalve
                oGFUEnable                                      <= 0;
263
                oUCodeEnable                            <= 1;   //*
264
                oIOWritePixel                           <= 0;
265
                rResetHitFlop                           <= 0;
266
                rHitFlopEnable                          <= 0;
267
                oTriggerTFF             <= 0;
268
                oSetCurrentPitch        <= 0;
269 71 diegovalve
                oFlipMemEnabled         <= 1;
270 76 diegovalve
                oFlipMem                                                <= 1;
271
                oDone                   <= 0;
272
                ////$display("\n\n %d XOXOXOXOX FLIP XOXOXOXOXOX\n\n",$time);
273 18 diegovalve
                //oIncCurrentPitch        <= 0;
274
 
275
                NextState                                       <= `CU_WAIT_CLEAR_REGISTERS;
276
        end
277
//-----------------------------------------     
278
        `CU_WAIT_CLEAR_REGISTERS:
279
        begin
280 81 diegovalve
//      `ifdef DEBUG_CU
281 18 diegovalve
//              `LOGME"%d CU_WAIT_CLEAR_REGISTERS\n",$time);
282
//      `endif  
283 76 diegovalve
                //$display("CORE: %d CU_WAIT_CLEAR_REGISTERS", iDebug_CoreID);
284 18 diegovalve
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
285 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_INITIAL;
286 18 diegovalve
                oGFUEnable                                      <= 0;
287
                oUCodeEnable                            <= 0;
288
                oIOWritePixel                           <= 0;
289
                rResetHitFlop                           <= 0;
290
                rHitFlopEnable                          <= 0;
291
      oTriggerTFF             <= 0;
292
                oSetCurrentPitch        <= 0;
293 71 diegovalve
                oFlipMemEnabled         <= 1;
294 76 diegovalve
                oFlipMem                                                <= 0;
295
                oDone                   <= 0;
296 18 diegovalve
                //oIncCurrentPitch        <= 0;
297
 
298
                if ( iUCodeDone )
299
                        NextState <= `CU_ACK_CLEAR_REGISTERS;
300
                else
301
                        NextState <= `CU_WAIT_CLEAR_REGISTERS;
302
 
303
        end
304
        //-----------------------------------------
305
        `CU_ACK_CLEAR_REGISTERS:
306 76 diegovalve
        begin
307
 
308 81 diegovalve
        `ifdef DEBUG_CU
309 18 diegovalve
                `LOGME"%d CU_ACK_CLEAR_REGISTERS\n", $time);
310
        `endif
311 76 diegovalve
 
312
        //$display("CORE: %d CU_ACK_CLEAR_REGISTERS", iDebug_CoreID);
313 18 diegovalve
 
314
                oRamBusOwner                            <= 0;
315 60 diegovalve
                oCodeInstructioPointer  <= 0;
316 18 diegovalve
                oGFUEnable                                      <= 0;
317
                oUCodeEnable                            <= 0; //*        
318
                oIOWritePixel                           <= 0;
319
                rResetHitFlop                           <= 0;
320
                rHitFlopEnable                          <= 0;
321
      oTriggerTFF             <= 0;
322
                oSetCurrentPitch        <= 0;
323 71 diegovalve
                oFlipMemEnabled         <= 0;
324 76 diegovalve
                oFlipMem                                                <= 0;
325
                oDone                   <= 0;
326 18 diegovalve
                //oIncCurrentPitch        <= 0;
327
 
328
                NextState <= `CU_WAIT_FOR_CONFIG_DATA_READ;
329
        end
330
 
331
 
332
 
333
        //-----------------------------------------
334
        `CU_WAIT_FOR_CONFIG_DATA_READ:
335
        begin
336 76 diegovalve
 
337 81 diegovalve
//              `ifdef DEBUG_CU
338 18 diegovalve
//                      `LOGME"%d Control: CU_WAIT_FOR_CONFIG_DATA_READ\n",$time);
339
//              `endif
340 76 diegovalve
 
341
 
342
//$display("CORE: %d CU_WAIT_FOR_CONFIG_DATA_READ", iDebug_CoreID);
343 18 diegovalve
 
344
                oRamBusOwner                            <= 0;//`REG_BUS_OWNED_BY_BCU;
345 60 diegovalve
                oCodeInstructioPointer  <= 0;
346 18 diegovalve
                oGFUEnable                                      <= 0;
347
                oUCodeEnable                            <= 0;
348
                oIOWritePixel                           <= 0;
349
                rResetHitFlop                           <= 0;
350
                rHitFlopEnable                          <= 0;
351
      oTriggerTFF             <= 0;
352
                oSetCurrentPitch        <= 0;
353 71 diegovalve
                oFlipMemEnabled         <= 0;
354 76 diegovalve
                oFlipMem                                                <= 0;
355
                oDone                   <= 0;
356 18 diegovalve
                //oIncCurrentPitch        <= 0;
357
 
358
                if ( MST_I == 0  )
359
                        NextState <= `CU_PRECALCULATE_CONSTANTS;
360
                else
361
                        NextState <= `CU_WAIT_FOR_CONFIG_DATA_READ;
362
 
363
        end
364
        //-----------------------------------------
365
        `CU_PRECALCULATE_CONSTANTS:
366
        begin
367 76 diegovalve
//$display("CORE: %d CU_PRECALCULATE_CONSTANTS", iDebug_CoreID);
368 81 diegovalve
        `ifdef DEBUG_CU
369 18 diegovalve
                `LOGME"%d Control: CU_PRECALCULATE_CONSTANTS\n", $time);
370
        `endif
371
 
372
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
373 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_CPPU;
374 18 diegovalve
                oGFUEnable                              <= 0;
375
                oUCodeEnable                            <= 1; //*       
376
                oIOWritePixel                           <= 0;
377
                rResetHitFlop                           <= 0;
378
                rHitFlopEnable                          <= 0;
379
      oTriggerTFF             <= 0;
380
                oSetCurrentPitch        <= 0;
381 71 diegovalve
                oFlipMemEnabled         <= 0;
382 76 diegovalve
                oFlipMem                                                <= 0;
383
                oDone                   <= 0;
384 18 diegovalve
                //oIncCurrentPitch        <= 0;
385
 
386
                NextState <= `CU_WAIT_FOR_CONSTANT;
387
 
388
        end
389
        //-----------------------------------------
390
        `CU_WAIT_FOR_CONSTANT:
391
        begin
392 81 diegovalve
//      `ifdef DEBUG_CU
393 18 diegovalve
//              `LOGME"%d Control: CU_WAIT_FOR_CONSTANT\n", $time);
394
//      `endif
395
 
396
 
397
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
398 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_CPPU;
399 18 diegovalve
                oGFUEnable                                 <= 0;
400
                oUCodeEnable                            <= 0; //*        
401
                oIOWritePixel                           <= 0;
402
                rResetHitFlop                           <= 0;
403
                rHitFlopEnable                          <= 0;
404
      oTriggerTFF             <= 0;
405
                oSetCurrentPitch        <= 0;
406 71 diegovalve
                oFlipMemEnabled         <= 0;
407 76 diegovalve
                oFlipMem                                                <= 0;
408
                oDone                   <= 0;
409 18 diegovalve
                //oIncCurrentPitch        <= 0;
410
 
411
                if ( iUCodeDone )
412
                        NextState <= `CU_ACK_PRECALCULATE_CONSTANTS;
413
                else
414
                        NextState <= `CU_WAIT_FOR_CONSTANT;
415
 
416
        end
417
        //-----------------------------------------
418
        `CU_ACK_PRECALCULATE_CONSTANTS:
419
        begin
420 76 diegovalve
        //$display("CORE: %d CU_ACK_PRECALCULATE_CONSTANTS", iDebug_CoreID);
421 81 diegovalve
        `ifdef DEBUG_CU
422 18 diegovalve
                `LOGME"%d Control: CU_ACK_PRECALCULATE_CONSTANTS\n", $time);
423
        `endif
424
 
425
 
426
                oRamBusOwner                            <= 0;//`REG_BUS_OWNED_BY_BCU;
427 60 diegovalve
                oCodeInstructioPointer  <= 0;
428 18 diegovalve
                oGFUEnable                                 <= 0;
429
                oUCodeEnable                            <= 0; //*        
430
                oIOWritePixel                           <= 0;
431
                rResetHitFlop                           <= 0;
432
                rHitFlopEnable                          <= 0;
433
      oTriggerTFF             <= 0;
434
                oSetCurrentPitch        <= 0;
435 71 diegovalve
                oFlipMemEnabled         <= 0;
436 76 diegovalve
                oFlipMem                                                <= 0;
437
                oDone                   <= 0;
438 18 diegovalve
                //oIncCurrentPitch        <= 0;
439
 
440 63 diegovalve
                NextState <= `CU_TRIGGER_USERCONSTANTS;//CU_WAIT_FOR_TASK;
441 18 diegovalve
 
442
        end
443
        //-----------------------------------------
444 71 diegovalve
 
445 63 diegovalve
        `CU_TRIGGER_USERCONSTANTS:
446
        begin
447 81 diegovalve
        `ifdef DEBUG_CU
448
                `LOGME"%d Control: CU_TRIGGER_USERCONSTANTS\n",$time);
449 63 diegovalve
        `endif
450 76 diegovalve
 
451
                //$display("CORE: %d CU_TRIGGER_USERCONSTANTS", iDebug_CoreID);
452 63 diegovalve
 
453
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
454
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_USERCONSTANTS;
455
                oGFUEnable                                      <= 0;
456
                oUCodeEnable                            <= 1;   //*
457
                oIOWritePixel                           <= 0;
458
                rResetHitFlop                           <= 0;
459
                rHitFlopEnable                          <= 0;
460
      oTriggerTFF             <= 0;
461
                oSetCurrentPitch        <= 0;
462 71 diegovalve
                oFlipMemEnabled         <= 0;
463 76 diegovalve
                oFlipMem                                                <= 0;
464
                oDone                   <= 0;
465 63 diegovalve
                //oIncCurrentPitch        <= 0;
466
 
467
                NextState <= `CU_WAIT_USERCONSTANTS;
468
        end
469
        //-----------------------------------------
470
        `CU_WAIT_USERCONSTANTS:
471
        begin
472
 
473 81 diegovalve
//      `ifdef DEBUG_CU
474 63 diegovalve
//              `LOGME"%d Control: CU_WAIT_FOR_RGU\n",$time);
475
//      `endif
476
 
477
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
478
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_USERCONSTANTS;
479
                oGFUEnable                                      <= 0;
480
                oUCodeEnable                            <= 0;
481
                oIOWritePixel                           <= 0;
482
                rResetHitFlop                           <= 0;
483
                rHitFlopEnable                          <= 0;
484
      oTriggerTFF             <= 0;
485
                oSetCurrentPitch        <= 0;
486 71 diegovalve
                oFlipMemEnabled         <= 0;
487 76 diegovalve
                oFlipMem                                                <= 0;
488
                oDone                   <= 0;
489 63 diegovalve
                //oIncCurrentPitch        <= 0;
490
 
491
                if ( iUCodeDone )
492
                        NextState <= `CU_ACK_USERCONSTANTS;
493
                else
494
                        NextState <= `CU_WAIT_USERCONSTANTS;
495
        end
496
        //-----------------------------------------
497
        `CU_ACK_USERCONSTANTS:
498
        begin
499
 
500 81 diegovalve
        `ifdef DEBUG_CU
501 63 diegovalve
                `LOGME"%d Control: CU_ACK_RGU\n",$time);
502 76 diegovalve
        `endif
503
 
504
        //$display("CORE: %d CU_ACK_USERCONSTANTS", iDebug_CoreID);
505
 
506 63 diegovalve
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
507
                oCodeInstructioPointer  <= 0;
508
                oGFUEnable                                      <= 0;
509
                oUCodeEnable                            <= 0; //*        
510
                oIOWritePixel                           <= 0;
511
                rResetHitFlop                           <= 0;
512
                rHitFlopEnable                          <= 0;
513
      oTriggerTFF             <= 0;
514
                oSetCurrentPitch        <= 0;
515 71 diegovalve
                oFlipMemEnabled         <= 0;
516 76 diegovalve
                oFlipMem                                                <= 0;
517
                oDone                   <= 0;
518 63 diegovalve
                //oIncCurrentPitch        <= 0;
519
 
520
                if ( iUCodeDone  == 0)
521 76 diegovalve
                        NextState <= `CU_WAIT_FOR_RENDER_ENABLE;
522 63 diegovalve
                else
523
                        NextState <= `CU_ACK_USERCONSTANTS;
524
 
525
        end
526 76 diegovalve
        //-----------------------------------------
527
        `CU_WAIT_FOR_RENDER_ENABLE:
528
        begin
529 81 diegovalve
        `ifdef DEBUG_CU
530
        $display("CORE: %d CU_WAIT_FOR_RENDER_ENABLE", iDebug_CoreID);
531
        `endif
532 76 diegovalve
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
533
                oCodeInstructioPointer  <= 0;
534
                oGFUEnable                                      <= 0;
535
                oUCodeEnable                            <= 0; //*        
536
                oIOWritePixel                           <= 0;
537
                rResetHitFlop                           <= 0;
538
                rHitFlopEnable                          <= 0;
539
      oTriggerTFF             <= 0;
540
                oSetCurrentPitch        <= 0;
541
                oFlipMemEnabled         <= 0;
542
                oFlipMem                                                <= 0;
543
                oDone                   <= 0;
544
                //oIncCurrentPitch        <= 0;
545
 
546
                if ( iRenderEnable)
547
                        NextState <= `CU_TRIGGER_RGU;
548
                else
549
                        NextState <= `CU_WAIT_FOR_RENDER_ENABLE;
550
        end
551 63 diegovalve
        //-----------------------------------------
552 18 diegovalve
        `CU_TRIGGER_RGU:
553
        begin
554
 
555 81 diegovalve
        `ifdef DEBUG_CU
556
                `LOGME"CORE: %d CU_TRIGGER_RGU", iDebug_CoreID);
557 76 diegovalve
        `endif
558 81 diegovalve
 
559 18 diegovalve
 
560
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
561 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_RGU;
562 18 diegovalve
                oGFUEnable                                      <= 0;
563
                oUCodeEnable                            <= 1;   //*
564
                oIOWritePixel                           <= 0;
565
                rResetHitFlop                           <= 0;
566
                rHitFlopEnable                          <= 0;
567
      oTriggerTFF             <= 0;
568
                oSetCurrentPitch        <= 0;
569 71 diegovalve
                oFlipMemEnabled         <= 0;
570 76 diegovalve
                oFlipMem                                                <= 0;
571
                oDone                   <= 0;
572 18 diegovalve
                //oIncCurrentPitch        <= 0;
573
 
574
                NextState <= `CU_WAIT_FOR_RGU;
575
        end
576
        //-----------------------------------------
577
        `CU_WAIT_FOR_RGU:
578
        begin
579
 
580 81 diegovalve
//      `ifdef DEBUG_CU
581 18 diegovalve
//              `LOGME"%d Control: CU_WAIT_FOR_RGU\n",$time);
582
//      `endif
583
 
584
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
585 60 diegovalve
                oCodeInstructioPointer  <= 0;
586 18 diegovalve
                oGFUEnable                                      <= 0;
587
                oUCodeEnable                            <= 0;
588
                oIOWritePixel                           <= 0;
589
                rResetHitFlop                           <= 0;
590
                rHitFlopEnable                          <= 0;
591
      oTriggerTFF             <= 0;
592
                oSetCurrentPitch        <= 0;
593 71 diegovalve
                oFlipMemEnabled         <= 0;
594 76 diegovalve
                oFlipMem                                                <= 0;
595
                oDone                   <= 0;
596 18 diegovalve
                //oIncCurrentPitch        <= 0;
597
 
598
                if ( iUCodeDone )
599
                        NextState <= `CU_ACK_RGU;
600
                else
601
                        NextState <= `CU_WAIT_FOR_RGU;
602
        end
603
        //-----------------------------------------
604
        `CU_ACK_RGU:
605 81 diegovalve
        begin
606 18 diegovalve
 
607 81 diegovalve
 
608
        `ifdef DEBUG_CU
609
                `LOGME"CORE: %d CU_ACK_RGU", iDebug_CoreID);
610 18 diegovalve
        `endif
611
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
612 60 diegovalve
                oCodeInstructioPointer  <= 0;
613 18 diegovalve
                oGFUEnable                                      <= 0;
614
                oUCodeEnable                            <= 0; //*        
615
                oIOWritePixel                           <= 0;
616
                rResetHitFlop                           <= 0;
617
                rHitFlopEnable                          <= 0;
618
      oTriggerTFF             <= 0;
619
                oSetCurrentPitch        <= 0;
620 71 diegovalve
                oFlipMemEnabled         <= 0;
621 76 diegovalve
                oFlipMem                                                <= 0;
622
                oDone                   <= 0;
623 18 diegovalve
                //oIncCurrentPitch        <= 0;
624
 
625
                if ( iUCodeDone  == 0)
626
                        NextState <= `CU_TRIGGER_GEO;
627
                else
628
                        NextState <= `CU_ACK_RGU;
629
 
630
        end
631
        //-----------------------------------------
632
        `CU_TRIGGER_GEO:
633
        begin
634 76 diegovalve
 
635 18 diegovalve
 
636 81 diegovalve
        `ifdef DEBUG_CU
637
                `LOGME"CORE: %d CU_TRIGGER_GEO", iDebug_CoreID);
638 18 diegovalve
        `endif
639
 
640
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
641 60 diegovalve
                oCodeInstructioPointer  <= 0;
642 18 diegovalve
                oUCodeEnable                            <= 0;
643
                oGFUEnable                                      <= 1;
644
                oIOWritePixel                           <= 0;
645
                rResetHitFlop                           <= 1;   //*
646
                rHitFlopEnable                          <= 0;
647
      oTriggerTFF             <= 0;
648
                oSetCurrentPitch        <= 0;
649 71 diegovalve
                oFlipMemEnabled         <= 0;
650 76 diegovalve
                oFlipMem                                                <= 0;
651
                oDone                   <= 0;
652 18 diegovalve
                //oIncCurrentPitch        <= 0;
653
 
654
                NextState <= `CU_WAIT_FOR_GEO_SYNC;
655
 
656
        end
657
        //-----------------------------------------
658
        `CU_WAIT_FOR_GEO_SYNC:
659 81 diegovalve
        begin
660
 
661 18 diegovalve
 
662 81 diegovalve
 
663
        `ifdef DEBUG_CU
664
                `LOGME"%d CORE %d Control: CU_WAIT_FOR_GEO_SYNC\n",$time,iDebug_CoreID);
665 18 diegovalve
        `endif
666
 
667
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
668 60 diegovalve
                oCodeInstructioPointer  <= 0;
669 18 diegovalve
                oUCodeEnable                            <= 0;
670
                oGFUEnable                                      <= 0; //Change AUg 15
671
                oIOWritePixel                           <= 0;
672
                rResetHitFlop                           <= 0;
673
                rHitFlopEnable                          <= 0;
674
      oTriggerTFF             <= 0;
675
                oSetCurrentPitch        <= 0;
676 71 diegovalve
                oFlipMemEnabled         <= 0;
677 76 diegovalve
                oFlipMem                                                <= 0;
678
                oDone                   <= 0;
679 18 diegovalve
                //oIncCurrentPitch        <= 0;
680
 
681
        if (iGEOSync & iTriggerAABBIURequest )
682
                NextState <= `CU_TRIGGER_AABBIU;
683
        else if (iGEOSync & iTriggerBIURequest)
684
                NextState <= `CU_TRIGGER_BIU;
685
        else if (iGEOSync & iTriggertTCCRequest )
686
      NextState <= `CU_TRIGGER_TCC;
687
   else if (iGEOSync & iGFUDone )
688
      NextState <= `CU_CHECK_HIT;
689
   else
690
      NextState <= `CU_WAIT_FOR_GEO_SYNC;
691
 
692
        end
693
        //-----------------------------------------
694
        `CU_TRIGGER_TCC:
695
        begin
696 76 diegovalve
        ////$display("CU_TRIGGER_TCC");
697 81 diegovalve
        `ifdef DEBUG_CU
698
                `LOGME"%d CORE %d Control: CU_TRIGGER_TCC\n",$time,iDebug_CoreID);
699 18 diegovalve
        `endif
700
 
701
           oRamBusOwner                                 <= `REG_BUS_OWNED_BY_UCODE;
702 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_TCC;
703 18 diegovalve
                oUCodeEnable                            <= 1;   //*
704
                oGFUEnable                                      <= 0;
705
                oIOWritePixel                           <= 0;
706
                rResetHitFlop                           <= 0;
707
                rHitFlopEnable                          <= 0;
708
      oTriggerTFF             <= 0;
709
                oSetCurrentPitch        <= 0;
710 71 diegovalve
                oFlipMemEnabled         <= 1;
711
                oFlipMem                                                <= 1; //We need u,v from last IO read cycle
712 76 diegovalve
                ////$display("\n\n %d XOXOXOXOX FLIP XOXOXOXOXOX\n\n",$time);
713 18 diegovalve
                //oIncCurrentPitch        <= 0;
714 76 diegovalve
                oDone                   <= 0;
715 18 diegovalve
 
716
          NextState  <= `WAIT_FOR_TCC;
717
        end
718
        //-----------------------------------------
719
        `WAIT_FOR_TCC:
720
        begin
721
 
722 76 diegovalve
        ////$display("WAIT_FOR_TCC");
723 18 diegovalve
           oRamBusOwner                                 <= `REG_BUS_OWNED_BY_UCODE;
724 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_TCC;
725 18 diegovalve
                oUCodeEnable                            <= 0;    //*
726
                oGFUEnable                                      <= 0;
727
                oIOWritePixel                           <= 0;
728
                rResetHitFlop                           <= 0;
729
                rHitFlopEnable                          <= 0;
730
      oTriggerTFF             <= 0;
731
                oSetCurrentPitch        <= 0;
732 71 diegovalve
                oFlipMemEnabled         <= 1;
733 76 diegovalve
                oFlipMem                                                <= 0;
734
                oDone                   <= 0;
735 18 diegovalve
                //oIncCurrentPitch        <= 0;
736
 
737
           if ( iUCodeDone )
738
                        NextState <= `CU_ACK_UCODE;
739
                else
740
                        NextState <= `WAIT_FOR_TCC;
741
 
742
        end
743
        //-----------------------------------------
744
        /*
745
        Was there any hit at all?
746
        At this point, all the triangles in the list
747
        have been traversed looking for a hit with our ray.
748
        There are 3 possibilities:
749
        1) The was not a single hit, then just paint a black
750
        pixel on the screen and send it via PCU.
751
        2)There was a hit and Texturing is not enabled, then trigger the PSU with
752
        no texturing
753
        2) There was a hit and Texturing is enabled, then fetch the texture
754
        values corresponding to the triangle that we hitted.
755
        */
756
        `CU_CHECK_HIT:
757
        begin
758
 
759 81 diegovalve
        `ifdef DEBUG_CU
760
                `LOGME"%d CORE %d Control: CU_CHECK_HIT\n",$time,iDebug_CoreID);
761 18 diegovalve
        `endif
762
 
763
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
764 60 diegovalve
                oCodeInstructioPointer  <= 0;
765 18 diegovalve
                oUCodeEnable                            <= 0;
766
                oGFUEnable                                      <= 0;    ///CHANGED Aug 15
767
                oIOWritePixel                           <= 0;
768
                rResetHitFlop                           <= 0;
769
                rHitFlopEnable                          <= 0;
770
           oTriggerTFF             <= 0;
771
                oSetCurrentPitch        <= 0;
772 71 diegovalve
                oFlipMemEnabled         <= 1;
773 76 diegovalve
                oFlipMem                                                <= 1;
774
                oDone                   <= 0;
775
                ////$display("\n\n %d XOXOXOXOX FLIP XOXOXOXOXOX\n\n",$time);
776 18 diegovalve
                //oIncCurrentPitch        <= 0;
777
 
778
                if (wHit && !iControlRegister[`CR_EN_TEXTURE] )
779
                        NextState <= `CU_TRIGGER_PSU;
780
                else if (wHit && iControlRegister[`CR_EN_TEXTURE])
781
                        NextState <= `CU_TRIGGER_TFF;           //Fetch the texture values from external RAM
782
                else
783
                        NextState <= `CU_TRIGGER_PCU;           //Make sure contents of the OUT_REG are ZERo!
784
        end
785
        //-----------------------------------------
786
        /*
787
        Get the texture values from external RAM.
788
        GFU already took care of calculating the correct
789
        texture addresses for the 4 coordinates so now lets
790
        just ask for them.
791
        */
792
        `CU_TRIGGER_TFF:
793
        begin
794 81 diegovalve
        `ifdef DEBUG_CU
795
                `LOGME"%d CORE %d Control: CU_TRIGGER_TFF\n",$time,iDebug_CoreID);
796 18 diegovalve
        `endif
797
 
798 76 diegovalve
        ////$display("CU_TRIGGER_TFF");
799 18 diegovalve
 
800
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
801 60 diegovalve
                oCodeInstructioPointer  <= 0;
802 18 diegovalve
                oUCodeEnable                            <= 0;
803
                oGFUEnable                                      <= 1;
804
                oIOWritePixel                           <= 0;
805
                rResetHitFlop                           <= 0;
806
                rHitFlopEnable                          <= 0;
807
                oTriggerTFF             <= 1;       //*
808 71 diegovalve
           oSetCurrentPitch        <= 0;
809
                oFlipMemEnabled         <= 1;
810
                oFlipMem                                                <= 0;  //NO need, we did this n check hit
811 18 diegovalve
                //oIncCurrentPitch        <= 0;
812 76 diegovalve
                oDone                   <= 0;
813 18 diegovalve
 
814
                NextState <= `CU_WAIT_FOR_TFF;
815
        end
816
        //-----------------------------------------
817
        `CU_WAIT_FOR_TFF:
818 81 diegovalve
        begin
819
        `ifdef DEBUG_CU
820
        `LOGME"%d CORE %d Control: CU_WAIT_FOR_TFF\n",$time,iDebug_CoreID);
821
        `endif
822 18 diegovalve
           oRamBusOwner                                 <= `REG_BUS_OWNED_BY_GFU;
823 60 diegovalve
                oCodeInstructioPointer  <= 0;
824 18 diegovalve
                oUCodeEnable                            <= 0;
825
                oGFUEnable                                      <= 0;     //Changed Aug 14
826
                oIOWritePixel                           <= 0;
827
                rResetHitFlop                           <= 0;
828
                rHitFlopEnable                          <= 0;
829
                oTriggerTFF             <= 0;
830
                oSetCurrentPitch        <= 0;
831 71 diegovalve
                oFlipMemEnabled         <= 1;
832
                oFlipMem                                                <= 0;
833 76 diegovalve
                oDone                   <= 0;
834
 
835 18 diegovalve
                //oIncCurrentPitch        <= 0;
836
 
837
        if (iTFFDone)
838
                NextState <= `CU_TRIGGER_PSU_WITH_TEXTURE;
839
        else
840
                NextState <= `CU_WAIT_FOR_TFF;
841
 
842
        end
843
        //-----------------------------------------
844
        `CU_TRIGGER_PSU_WITH_TEXTURE:
845
        begin
846
 
847 81 diegovalve
        `ifdef DEBUG_CU
848 18 diegovalve
                `LOGME"%d Control: CU_TRIGGER_PSU_WITH_TEXTURE\n",$time);
849
        `endif
850
 
851
           oRamBusOwner                                 <= `REG_BUS_OWNED_BY_UCODE;
852 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_PSU2;
853 18 diegovalve
                oUCodeEnable                            <= 1;
854
                oGFUEnable                                      <= 0;
855
                oIOWritePixel                           <= 0;
856
                rResetHitFlop                           <= 0;
857
                rHitFlopEnable                          <= 0;
858
                oTriggerTFF             <= 0;
859
                oSetCurrentPitch        <= 0;
860 71 diegovalve
                oFlipMemEnabled         <= 1;
861 76 diegovalve
                oFlipMem                                                <= 1;
862
                oDone                   <= 0;
863
                ////$display("\n\n %d XOXOXOXOX FLIP XOXOXOXOXOX\n\n",$time);
864 18 diegovalve
           //oIncCurrentPitch        <= 0;
865
 
866
                NextState <= `CU_WAIT_FOR_PSU;
867
        end
868
        //-----------------------------------------
869
        `CU_TRIGGER_AABBIU:
870
        begin
871
 
872 81 diegovalve
        `ifdef DEBUG_CU
873 18 diegovalve
                `LOGME"%d Control: CU_TRIGGER_AABBIU\n",$time);
874
        `endif
875
//      $stop();
876 60 diegovalve
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
877 18 diegovalve
 
878 60 diegovalve
                oCodeInstructioPointer  <=`ENTRYPOINT_INDEX_AABBIU;
879 18 diegovalve
                oUCodeEnable                            <= 1;
880
                oGFUEnable                                      <= 1;
881
                oIOWritePixel                           <= 0;
882
                rResetHitFlop                           <= 0;
883
                rHitFlopEnable                          <= 0;
884
      oTriggerTFF             <= 0;
885
                oSetCurrentPitch        <= 0;
886 71 diegovalve
                oFlipMemEnabled         <= 1;
887 76 diegovalve
                oFlipMem                                                <= 1;
888
                oDone                   <= 0;
889
                ////$display("\n\n %d XOXOXOXOX FLIP XOXOXOXOXOX\n\n",$time);
890 18 diegovalve
                //oIncCurrentPitch        <= 0;
891
 
892
                NextState <= `CU_WAIT_FOR_AABBIU;
893
        end
894
        //-----------------------------------------
895
        `CU_WAIT_FOR_AABBIU:
896
        begin
897
 
898
 
899 81 diegovalve
//      `ifdef DEBUG_CU
900 18 diegovalve
//              `LOGME"%d Control: CU_WAIT_FOR_AABBIU\n",$time);
901
//      `endif
902
 
903
 
904 76 diegovalve
//      //$display("iUCodeDone",iUCodeDone);
905 18 diegovalve
 
906
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
907 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_AABBIU;
908 18 diegovalve
                oUCodeEnable                            <= 0;
909
                oGFUEnable                                      <= 1;
910
                oIOWritePixel                           <= 0;
911
                rResetHitFlop                           <= 0;
912
                rHitFlopEnable                          <= 0;
913
      oTriggerTFF             <= 0;
914
                oSetCurrentPitch        <= 0;
915 71 diegovalve
                oFlipMemEnabled         <= 0;
916 76 diegovalve
                oFlipMem                                                <= 0;
917
                oDone                   <= 0;
918 18 diegovalve
                //oIncCurrentPitch        <= 0;
919
 
920
                if ( iUCodeDone )
921
                begin
922 76 diegovalve
        //         //$display("iUCodeDone\n",iUCodeDone);
923 18 diegovalve
        //              $stop();
924
                        NextState <= `CU_ACK_UCODE;
925
                end
926
                else
927
                        NextState <= `CU_WAIT_FOR_AABBIU;
928
        end
929
        //-----------------------------------------
930
        `CU_TRIGGER_BIU:
931
        begin
932 81 diegovalve
        `ifdef DEBUG_CU
933
                `LOGME"%d CORE: %d Control: CU_TRIGGER_BIU\n",$time,iDebug_CoreID);
934 18 diegovalve
        `endif
935
 
936
                        oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
937 60 diegovalve
                        oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_BIU;
938 18 diegovalve
                        oUCodeEnable                            <= 1;
939
                        oGFUEnable                                      <= 1;
940
                        oIOWritePixel                           <= 0;
941
                        rResetHitFlop                           <= 0;//1;        
942
                        rHitFlopEnable                          <= 1;
943
         oTriggerTFF             <= 0;
944
                        oSetCurrentPitch        <= 0;
945 71 diegovalve
                        oFlipMemEnabled         <= 1;
946 76 diegovalve
                        oFlipMem                                                <= 1;
947
                        oDone                   <= 0;
948
                        ////$display("\n\n %d XOXOXOXOX FLIP XOXOXOXOXOX\n\n",$time);
949 18 diegovalve
                        //oIncCurrentPitch        <= 0;
950
                //      $stop();
951
 
952
                        NextState <= `CU_WAIT_FOR_BIU;
953
 
954
        end
955
        //-----------------------------------------
956
        `CU_WAIT_FOR_BIU:
957
        begin
958 81 diegovalve
//      `ifdef DEBUG_CU
959 18 diegovalve
//              `LOGME"%d Control: CU_WAIT_FOR_BIU\n",$time);
960
//      `endif
961
 
962
                        oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
963 60 diegovalve
                        oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_BIU;
964 18 diegovalve
                        oUCodeEnable                            <= 0;
965
                        oGFUEnable                                      <= 1;
966
                        oIOWritePixel                           <= 0;
967
                        rResetHitFlop                           <= 0;
968
                        rHitFlopEnable                          <= 1;
969
         oTriggerTFF             <= 0;
970
                        oSetCurrentPitch        <= 0;
971 71 diegovalve
                        oFlipMemEnabled         <= 1;
972 76 diegovalve
                        oFlipMem                                                <= 0;
973
                        oDone                   <= 0;
974 18 diegovalve
                        //oIncCurrentPitch        <= 0;
975
 
976
                if ( iUCodeDone )
977
                        NextState <= `CU_ACK_UCODE;
978
                else
979
                        NextState <= `CU_WAIT_FOR_BIU;
980
        end
981
        //-----------------------------------------
982
        /*
983
                ACK UCODE by setting oUCodeEnable = 0
984
        */
985
        `CU_ACK_UCODE:
986
        begin
987 81 diegovalve
        `ifdef DEBUG_CU
988
                `LOGME"%d CORE: %d Control: CU_ACK_UCODE\n",$time, iDebug_CoreID);
989 18 diegovalve
        `endif
990
 
991
                        oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
992 60 diegovalve
                        oCodeInstructioPointer  <= 0; //*
993 18 diegovalve
                        oUCodeEnable                            <= 0;    //*
994
                        oGFUEnable                                      <= 0; //Changed Aug 15
995
                        oIOWritePixel                           <= 0;
996
                        rResetHitFlop                           <= 0;
997
                        rHitFlopEnable                          <= 0;
998
         oTriggerTFF             <= 0;
999
                        oSetCurrentPitch        <= 0;
1000 71 diegovalve
                        oFlipMemEnabled         <= 0;
1001 76 diegovalve
                        oFlipMem                                                <= 0;
1002
                        oDone                   <= 0;
1003 18 diegovalve
                        //oIncCurrentPitch        <= 0;
1004
 
1005
        //              $stop();
1006
 
1007
                        if ( iUCodeDone == 0 )
1008
                                NextState <= `CU_WAIT_FOR_GEO_SYNC;
1009
                        else
1010
                                NextState <= `CU_ACK_UCODE;
1011
        end
1012
        //-----------------------------------------
1013
        /*
1014
        Here we no longer use GFU so set Enable to zero
1015
        */
1016
        `CU_TRIGGER_PSU:
1017
        begin
1018 81 diegovalve
        `ifdef DEBUG_CU
1019
                `LOGME"%d CORE: %d Control: CU_TRIGGER_PSU\n",$time, iDebug_CoreID);
1020 18 diegovalve
        `endif
1021
 
1022
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1023 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_PSU;
1024 18 diegovalve
                oUCodeEnable                            <= 1;
1025
                oGFUEnable                                      <= 0;//*
1026
                oIOWritePixel                           <= 0;
1027
                rResetHitFlop                           <= 0;
1028
                rHitFlopEnable                          <= 0;
1029
                oTriggerTFF             <= 0;
1030
                oSetCurrentPitch        <= 0;
1031 71 diegovalve
                oFlipMemEnabled         <= 1;
1032 76 diegovalve
                oFlipMem                                                <= 1;
1033
                oDone                   <= 0;
1034
                ////$display("\n\n %d XOXOXOXOX FLIP XOXOXOXOXOX\n\n",$time);
1035 18 diegovalve
                //oIncCurrentPitch        <= 0;
1036
 
1037
 
1038
                NextState <= `CU_WAIT_FOR_PSU;
1039
        end
1040
        //-----------------------------------------
1041
        `CU_WAIT_FOR_PSU:
1042
        begin
1043
 
1044 81 diegovalve
//      `ifdef DEBUG_CU
1045 18 diegovalve
//              `LOGME"%d Control: CU_TRIGGER_PSU\n",$time);
1046
//      `endif
1047
 
1048
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1049 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_PSU;
1050 18 diegovalve
                oUCodeEnable                            <= 0;
1051
                oGFUEnable                                      <= 0;
1052
                oIOWritePixel                           <= 0;
1053
                rResetHitFlop                           <= 0;
1054
                rHitFlopEnable                          <= 0;
1055
                oTriggerTFF             <= 0;
1056
                oSetCurrentPitch        <= 0;
1057 71 diegovalve
                oFlipMemEnabled         <= 1;
1058 76 diegovalve
                oFlipMem                                                <= 0;
1059
                oDone                   <= 0;
1060 18 diegovalve
                //oIncCurrentPitch        <= 0;
1061
 
1062
 
1063
                if ( iUCodeDone )
1064
                        NextState <= `CU_ACK_PSU;
1065
                else
1066
                        NextState <= `CU_WAIT_FOR_PSU;
1067
 
1068
        end
1069
        //-----------------------------------------
1070
        `CU_ACK_PSU:
1071
        begin
1072 81 diegovalve
        `ifdef DEBUG_CU
1073
                `LOGME"%d CORE: %d Control: CU_ACK_PSU\n",$time, iDebug_CoreID);
1074 18 diegovalve
        `endif
1075
 
1076
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1077 60 diegovalve
                oCodeInstructioPointer  <= 0;    //*
1078 18 diegovalve
                oUCodeEnable                            <= 0;    //*
1079
                oGFUEnable                                      <= 0;
1080
                oIOWritePixel                           <= 0;
1081
                rResetHitFlop                           <= 0;
1082
                rHitFlopEnable                          <= 0;
1083
      oTriggerTFF             <= 0;
1084
                oSetCurrentPitch        <= 0;
1085 71 diegovalve
                oFlipMemEnabled         <= 1;
1086 76 diegovalve
                oFlipMem                                                <= 0;
1087
                oDone                   <= 0;
1088 18 diegovalve
                //oIncCurrentPitch        <= 0;
1089
 
1090
                if ( iUCodeDone  == 0)
1091 63 diegovalve
                        NextState <= `CU_TRIGGER_USERPIXELSHADER;
1092 18 diegovalve
                else
1093
                        NextState <= `CU_ACK_PSU;
1094
 
1095
 
1096
        end
1097
        //-----------------------------------------
1098
        /*
1099
                Trigger the Pixel Commit.
1100
        */
1101
        `CU_TRIGGER_PCU:
1102
        begin
1103
 
1104 81 diegovalve
        `ifdef DEBUG_CU
1105
                `LOGME"%d CORE: %d Control: CU_TRIGGER_PCU\n",$time, iDebug_CoreID);
1106 18 diegovalve
        `endif
1107
 
1108
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
1109 60 diegovalve
                oCodeInstructioPointer  <= 0;    //*
1110 18 diegovalve
                oUCodeEnable                            <= 0;    //*
1111
                oGFUEnable                                      <= 0;
1112
                oIOWritePixel                           <= 1; //*
1113
                rResetHitFlop                           <= 0;
1114
                rHitFlopEnable                          <= 0;
1115
      oTriggerTFF             <= 0;
1116
                oSetCurrentPitch        <= 0;
1117 71 diegovalve
                oFlipMemEnabled         <= 1;
1118 76 diegovalve
                oFlipMem                                                <= 1;
1119
                oDone                   <= 0;
1120
                ////$display("\n\n %d XOXOXOXOX FLIP XOXOXOXOXOX\n\n",$time);
1121 18 diegovalve
                //oIncCurrentPitch        <= 0;
1122
 
1123
 
1124
                NextState <= `CU_SET_PICTH;
1125
 
1126
        end
1127
        //-----------------------------------------
1128
        `CU_SET_PICTH:
1129 81 diegovalve
        begin
1130
 
1131
        `ifdef DEBUG_CU
1132
                `LOGME"%d CORE: %d Control: CU_SET_PICTH\n",$time, iDebug_CoreID);
1133
        `endif
1134
 
1135
 
1136 18 diegovalve
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
1137 60 diegovalve
                oCodeInstructioPointer  <= 0;    //*
1138 18 diegovalve
                oUCodeEnable                            <= 0;    //*
1139
                oGFUEnable                                      <= 0;
1140
                oIOWritePixel                           <= 1; //*
1141
                rResetHitFlop                           <= 0;
1142
                rHitFlopEnable                          <= 0;
1143
      oTriggerTFF             <= 0;
1144
                oSetCurrentPitch        <= 1; //*
1145 71 diegovalve
                oFlipMemEnabled         <= 1;
1146 76 diegovalve
                oFlipMem                                                <= 0;
1147
                oDone                   <= 0;
1148 18 diegovalve
                //oIncCurrentPitch        <= 0;
1149
 
1150
 
1151
                NextState <= `CU_WAIT_FOR_PCU;
1152
        end
1153
        //-----------------------------------------
1154
        `CU_WAIT_FOR_PCU:
1155
        begin
1156
 
1157 81 diegovalve
//      `ifdef DEBUG_CU
1158 18 diegovalve
//              `LOGME"%d Control: CU_WAIT_FOR_PCU\n",$time);
1159
//      `endif
1160
 
1161
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
1162 60 diegovalve
                oCodeInstructioPointer  <= 0;    //*
1163 18 diegovalve
                oUCodeEnable                            <= 0;    //*
1164
                oGFUEnable                                      <= 0;
1165
                oIOWritePixel                           <= 1;
1166
                rResetHitFlop                           <= 0;
1167
                rHitFlopEnable                          <= 0;
1168
      oTriggerTFF             <= 0;
1169
                oSetCurrentPitch        <= 0;
1170 71 diegovalve
                oFlipMemEnabled         <= 1;
1171 76 diegovalve
                oFlipMem                                                <= 0;
1172
                oDone                   <= 0;
1173 18 diegovalve
                //oIncCurrentPitch        <= 0;
1174
 
1175
                if ( iIODone )
1176
                        NextState <= `CU_ACK_PCU;
1177
                else
1178
                        NextState <= `CU_WAIT_FOR_PCU;
1179
 
1180
        end
1181
        //-----------------------------------------
1182
        `CU_ACK_PCU:
1183
        begin
1184
 
1185 81 diegovalve
        `ifdef DEBUG_CU
1186
                `LOGME"%d CORE: %d Control: CU_ACK_PCU\n",$time, iDebug_CoreID);
1187
        `endif
1188
 
1189 18 diegovalve
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_GFU;
1190 60 diegovalve
                oCodeInstructioPointer  <= 0;    //*
1191 18 diegovalve
                oUCodeEnable                            <= 0;    //*
1192
                oGFUEnable                                      <= 0;
1193
                oIOWritePixel                           <= 0;
1194
                rResetHitFlop                           <= 0;
1195
                rHitFlopEnable                          <= 0;
1196
      oTriggerTFF             <= 0;
1197
                oSetCurrentPitch        <= 0;
1198 71 diegovalve
                oFlipMemEnabled         <= 1;
1199 76 diegovalve
                oFlipMem                                                <= 0;
1200
                oDone                   <= 0;
1201 18 diegovalve
                //oIncCurrentPitch        <= 0;
1202
 
1203
                NextState <= `CU_TRIGGER_NPU;
1204
 
1205
        end
1206
        //-----------------------------------------
1207
        `CU_TRIGGER_NPU: //Next Pixel Unit
1208
        begin
1209 81 diegovalve
        `ifdef DEBUG_CU
1210
                `LOGME"%d CORE: %d Control: CU_TRIGGER_NPU\n",$time, iDebug_CoreID);
1211
        `endif
1212
 
1213
 
1214 18 diegovalve
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1215 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_NPG;       //*
1216 18 diegovalve
                oUCodeEnable                            <= 1;   //*
1217
                oGFUEnable                                      <= 0;
1218
                oIOWritePixel                           <= 0;
1219
                rResetHitFlop                           <= 0;
1220
                rHitFlopEnable                          <= 0;
1221
      oTriggerTFF             <= 0;
1222
                oSetCurrentPitch        <= 0;
1223 71 diegovalve
                oFlipMemEnabled         <= 1;
1224 76 diegovalve
                oFlipMem                                                <= 0;
1225
                oDone                   <= 0;
1226 18 diegovalve
                //oIncCurrentPitch        <= 0;
1227
 
1228
                NextState <= `CU_WAIT_NPU;
1229
        end
1230
        //-----------------------------------------
1231
        `CU_WAIT_NPU:
1232
        begin
1233
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1234 60 diegovalve
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_NPG;
1235 18 diegovalve
                oUCodeEnable                            <= 0;
1236
                oGFUEnable                                      <= 0;
1237
                oIOWritePixel                           <= 0;
1238
                rResetHitFlop                           <= 0;
1239
                rHitFlopEnable                          <= 0;
1240
                oTriggerTFF             <= 0;
1241
                oSetCurrentPitch        <= 0;
1242 71 diegovalve
                oFlipMemEnabled         <= 1;
1243 76 diegovalve
                oFlipMem                                                <= 0;
1244
                oDone                   <= 0;
1245 18 diegovalve
                //oIncCurrentPitch        <= 0;
1246
 
1247
                if ( iUCodeDone )
1248
                        NextState <= `CU_ACK_NPU;
1249
                else
1250
                        NextState <= `CU_WAIT_NPU;
1251
        end
1252 76 diegovalve
        //-----------------------------------------
1253
        /*
1254
        Next Pixel generation: here we either goto
1255
        to RGU for the next pixel, or we have no
1256
        more pixels so we are done we our picture!
1257
        */
1258 18 diegovalve
        `CU_ACK_NPU:
1259
        begin
1260 81 diegovalve
        `ifdef DEBUG_CU
1261
                `LOGME"%d CORE: %d Control: CU_ACK_NPU\n",$time, iDebug_CoreID);
1262 18 diegovalve
        `endif
1263
 
1264
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1265 60 diegovalve
                oCodeInstructioPointer  <= 0;    //*
1266 18 diegovalve
                oUCodeEnable                            <= 0;    //*
1267
                oGFUEnable                                      <= 0;
1268
                oIOWritePixel                           <= 0;
1269
                rResetHitFlop                           <= 0;
1270
                rHitFlopEnable                          <= 0;
1271
      oTriggerTFF             <= 0;
1272
                oSetCurrentPitch        <= 0;
1273 71 diegovalve
                oFlipMemEnabled         <= 1;
1274 76 diegovalve
                oFlipMem                                                <= 0;
1275
                oDone                   <= 0;
1276 18 diegovalve
                //oIncCurrentPitch        <= 0;
1277
 
1278 76 diegovalve
                if ( iUCodeDone  == 0 && iUCodeReturnValue == 1)
1279
                        NextState <= `CU_TRIGGER_RGU;
1280
                else if (iUCodeDone == 0 && iUCodeReturnValue == 0)
1281
                        NextState <= `CU_DONE;
1282 18 diegovalve
                else
1283
                        NextState <= `CU_ACK_NPU;
1284
 
1285
 
1286
        end
1287 76 diegovalve
        //-----------------------------------------
1288
        `CU_DONE:
1289
        begin
1290
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1291
                oCodeInstructioPointer  <= 0;
1292
                oUCodeEnable                            <= 0;
1293
                oGFUEnable                                      <= 0;
1294
                oIOWritePixel                           <= 0;
1295
                rResetHitFlop                           <= 0;
1296
                rHitFlopEnable                          <= 0;
1297
      oTriggerTFF             <= 0;
1298
                oSetCurrentPitch        <= 0;
1299
                oFlipMemEnabled         <= 0;
1300
                oFlipMem                                                <= 0;
1301
                oDone                   <= 1;
1302
                //oIncCurrentPitch        <= 0;
1303
 
1304
 
1305
                NextState <= `CU_DONE;
1306
 
1307
        end
1308 18 diegovalve
        //-----------------------------------------
1309 63 diegovalve
        /*
1310
        Here we no longer use GFU so set Enable to zero
1311
        */
1312
        `CU_TRIGGER_USERPIXELSHADER:
1313
        begin
1314 81 diegovalve
        `ifdef DEBUG_CU
1315 63 diegovalve
                `LOGME"%d Control: CU_TRIGGER_PSU\n",$time);
1316
        `endif
1317
 
1318
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1319
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_PIXELSHADER;
1320
                oUCodeEnable                            <= 1;
1321
                oGFUEnable                                      <= 0;//*
1322
                oIOWritePixel                           <= 0;
1323
                rResetHitFlop                           <= 0;
1324
                rHitFlopEnable                          <= 0;
1325
                oTriggerTFF             <= 0;
1326
                oSetCurrentPitch        <= 0;
1327 71 diegovalve
                oFlipMemEnabled         <= 1;
1328 76 diegovalve
                oFlipMem                                                <= 0;
1329
                oDone                   <= 0;
1330 63 diegovalve
                //oIncCurrentPitch        <= 0;
1331
 
1332
 
1333
                NextState <= `CU_WAIT_FOR_USERPIXELSHADER;
1334
        end
1335
        //-----------------------------------------
1336
        `CU_WAIT_FOR_USERPIXELSHADER:
1337
        begin
1338
 
1339 81 diegovalve
//      `ifdef DEBUG_CU
1340 63 diegovalve
//              `LOGME"%d Control: CU_TRIGGER_PSU\n",$time);
1341
//      `endif
1342
 
1343
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1344
                oCodeInstructioPointer  <= `ENTRYPOINT_INDEX_PIXELSHADER;
1345
                oUCodeEnable                            <= 0;
1346
                oGFUEnable                                      <= 0;
1347
                oIOWritePixel                           <= 0;
1348
                rResetHitFlop                           <= 0;
1349
                rHitFlopEnable                          <= 0;
1350
                oTriggerTFF             <= 0;
1351
                oSetCurrentPitch        <= 0;
1352 71 diegovalve
                oFlipMemEnabled         <= 1;
1353 76 diegovalve
                oFlipMem                                                <= 0;
1354
                oDone                   <= 0;
1355 63 diegovalve
                //oIncCurrentPitch        <= 0;
1356
 
1357
 
1358
                if ( iUCodeDone )
1359
                        NextState <= `CU_ACK_USERPIXELSHADER;
1360
                else
1361
                        NextState <= `CU_WAIT_FOR_USERPIXELSHADER;
1362
 
1363
        end
1364
        //-----------------------------------------
1365
        `CU_ACK_USERPIXELSHADER:
1366
        begin
1367 81 diegovalve
        `ifdef DEBUG_CU
1368 63 diegovalve
                `LOGME"%d Control: CU_ACK_PSU\n",$time);
1369
        `endif
1370
 
1371
                oRamBusOwner                            <= `REG_BUS_OWNED_BY_UCODE;
1372
                oCodeInstructioPointer  <= 0;    //*
1373
                oUCodeEnable                            <= 0;    //*
1374
                oGFUEnable                                      <= 0;
1375
                oIOWritePixel                           <= 0;
1376
                rResetHitFlop                           <= 0;
1377
                rHitFlopEnable                          <= 0;
1378
      oTriggerTFF             <= 0;
1379
                oSetCurrentPitch        <= 0;
1380 71 diegovalve
                oFlipMemEnabled         <= 1;
1381 76 diegovalve
                oFlipMem                                                <= 0;
1382
                oDone                   <= 0;
1383 63 diegovalve
                //oIncCurrentPitch        <= 0;
1384
 
1385
                if ( iUCodeDone  == 0)
1386
                        NextState <= `CU_TRIGGER_PCU;
1387
                else
1388
                        NextState <= `CU_ACK_USERPIXELSHADER;
1389
 
1390
 
1391
        end
1392
        //---------------------------------------------------
1393 18 diegovalve
        default:
1394
        begin
1395
 
1396 81 diegovalve
        `ifdef DEBUG_CU
1397 18 diegovalve
                `LOGME"%d Control: ERRO Undefined State\n",$time);
1398
        `endif
1399
 
1400
                oRamBusOwner                            <= 0;
1401 60 diegovalve
                oCodeInstructioPointer  <= 0;
1402 18 diegovalve
                oUCodeEnable                            <= 0;
1403
                oGFUEnable                                      <= 0;
1404
                oIOWritePixel                           <= 0;
1405
                rResetHitFlop                           <= 0;
1406
                rHitFlopEnable                          <= 0;
1407
      oTriggerTFF             <= 0;
1408
                oSetCurrentPitch        <= 0;
1409 71 diegovalve
                oFlipMemEnabled         <= 0;
1410 76 diegovalve
                oFlipMem                                                <= 0;
1411
                oDone                   <= 0;
1412 18 diegovalve
                //oIncCurrentPitch        <= 0;
1413
 
1414
                NextState <= `CU_AFTER_RESET_STATE;
1415
        end
1416
        //-----------------------------------------
1417
 
1418
        endcase
1419
 
1420
end //always    
1421
endmodule

powered by: WebSVN 2.1.0

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