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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [rtl/] [core/] [fm_ras_state.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   fm_ras_state.v
7
//
8
// Abstract:
9
//  line distribution
10
//  line is rejected when:
11
//    both vertices are outside +-X, or +-Y plane
12
//
13
// Author:
14 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
15 2 specular
//
16
//======================================================================
17
//
18
// Copyright (c) 2015, Kenji Ishimaru
19
// All rights reserved.
20
//
21
// Redistribution and use in source and binary forms, with or without
22
// modification, are permitted provided that the following conditions are met:
23
//
24
//  -Redistributions of source code must retain the above copyright notice,
25
//   this list of conditions and the following disclaimer.
26
//  -Redistributions in binary form must reproduce the above copyright notice,
27
//   this list of conditions and the following disclaimer in the documentation
28
//   and/or other materials provided with the distribution.
29
//
30
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
34
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41
//
42
// Revision History
43
 
44
`include "fm_3d_define.v"
45
module fm_ras_state (
46
  // system
47
  input         clk_core,
48
  input         rst_x,
49
  // Register Configuration
50
  input [15:0] i_scr_w_m1,  // Screen Width-1
51
  input [15:0] i_scr_h_m1,  // Screen Height-1
52
  // Vertex input
53
  input         i_en,
54
  output        o_ack,
55
  input  [`D3D_FTOI_WIDTH-1:0] i_v0_x,
56
  input  [`D3D_FTOI_WIDTH-1:0] i_v0_y,
57
  input  [`D3D_FTOI_WIDTH-1:0] i_v1_x,
58
  input  [`D3D_FTOI_WIDTH-1:0] i_v1_y,
59
  input  [`D3D_FTOI_WIDTH-1:0] i_v2_x,
60
  input  [`D3D_FTOI_WIDTH-1:0] i_v2_y,
61
  output        o_ras_state,
62
  // Current Line
63
  output        o_en,
64
  input         i_ack,
65
  output [`D3D_FTOI_WIDTH-1:0] o_v0_x,
66
  output [`D3D_FTOI_WIDTH-1:0] o_v0_y,
67
  output [`D3D_FTOI_WIDTH-1:0] o_v1_x,
68
  output [`D3D_FTOI_WIDTH-1:0] o_v1_y,
69
  input         i_state
70
);
71
 
72
localparam P_IDLE = 'd0;
73
localparam P_LINE_0 = 'd1;
74
localparam P_LINE_1 = 'd2;
75
localparam P_LINE_2 = 'd3;
76
 
77
//////////////////////////////////
78
// reg
79
//////////////////////////////////
80
reg [2:0]  r_state;
81
reg [`D3D_FTOI_WIDTH-1:0] r_v0_x;
82
reg [`D3D_FTOI_WIDTH-1:0] r_v0_y;
83
reg [`D3D_FTOI_WIDTH-1:0] r_v1_x;
84
reg [`D3D_FTOI_WIDTH-1:0] r_v1_y;
85
reg [`D3D_FTOI_WIDTH-1:0] r_v2_x;
86
reg [`D3D_FTOI_WIDTH-1:0] r_v2_y;
87
//////////////////////////////////
88
// wire
89
//////////////////////////////////
90
wire w_set_vtx;
91
wire w_reject_l0;
92
wire w_reject_l1;
93
wire w_reject_l2;
94
//////////////////////////////////
95
// assign
96
//////////////////////////////////
97
assign o_en = ((r_state == P_LINE_0) & ~w_reject_l0) |
98
              ((r_state == P_LINE_1) & ~w_reject_l1) |
99
              ((r_state == P_LINE_2) & ~w_reject_l2);
100
assign o_ack = (r_state == P_IDLE);
101
 
102
// LINE 0: v0,v1
103
// LINE 1: v1,v2
104
// LINE 2: v2,v0
105
 
106
assign o_v0_x = (r_state == P_LINE_0) ? r_v0_x :
107
                (r_state == P_LINE_1) ? r_v1_x : r_v2_x;
108
assign o_v0_y = (r_state == P_LINE_0) ? r_v0_y :
109
                (r_state == P_LINE_1) ? r_v1_y : r_v2_y;
110
assign o_v1_x = (r_state == P_LINE_0) ? r_v1_x :
111
                (r_state == P_LINE_1) ? r_v2_x : r_v0_x;
112
assign o_v1_y = (r_state == P_LINE_0) ? r_v1_y :
113
                (r_state == P_LINE_1) ? r_v2_y : r_v0_y;
114
 
115
assign w_set_vtx = (r_state == P_IDLE) & i_en;
116
assign o_ras_state = (r_state == P_IDLE) & i_state;
117
 
118
assign w_reject_l0 = f_reject(r_v0_x,r_v0_y,r_v1_x,r_v1_y,i_scr_w_m1,i_scr_h_m1);
119
assign w_reject_l1 = f_reject(r_v1_x,r_v1_y,r_v2_x,r_v2_y,i_scr_w_m1,i_scr_h_m1);
120
assign w_reject_l2 = f_reject(r_v2_x,r_v2_y,r_v0_x,r_v0_y,i_scr_w_m1,i_scr_h_m1);
121
//////////////////////////////////
122
// always
123
//////////////////////////////////
124
 
125
always @(posedge clk_core) begin
126
  if (w_set_vtx) begin
127
    r_v0_x <= i_v0_x;
128
    r_v0_y <= i_v0_y;
129
    r_v1_x <= i_v1_x;
130
    r_v1_y <= i_v1_y;
131
    r_v2_x <= i_v2_x;
132
    r_v2_y <= i_v2_y;
133
  end
134
end
135
 
136
`ifdef D3D_SYNC_RESET
137
always @(posedge clk_core) begin
138
`else
139
always @(posedge clk_core or negedge rst_x) begin
140
`endif
141
  if (rst_x == `D3D_RESET_POL) begin
142
    r_state <= P_IDLE;
143
  end else begin
144
    case (r_state)
145
      P_IDLE: begin
146
        if (i_en) r_state <= P_LINE_0;
147
      end
148
      P_LINE_0: begin
149
        if (i_ack | w_reject_l0) r_state <= P_LINE_1;
150
      end
151
      P_LINE_1: begin
152
        if (i_ack | w_reject_l1) r_state <= P_LINE_2;
153
      end
154
      P_LINE_2: begin
155
        if (i_ack | w_reject_l2) r_state <= P_IDLE;
156
      end
157
    endcase
158
  end
159
end
160
 
161
function f_reject;
162
  input [`D3D_FTOI_WIDTH-1:0] v0_x;
163
  input [`D3D_FTOI_WIDTH-1:0] v0_y;
164
  input [`D3D_FTOI_WIDTH-1:0] v1_x;
165
  input [`D3D_FTOI_WIDTH-1:0] v1_y;
166
  input [15:0] scr_w;
167
  input [15:0] scr_h;
168
  reg result;
169
  begin
170
    result = 1'b0;
171
    if (v0_x[`D3D_FTOI_WIDTH-1] & v1_x[`D3D_FTOI_WIDTH-1]) result = 1'b1;  // negative
172
    if (v0_y[`D3D_FTOI_WIDTH-1] & v1_y[`D3D_FTOI_WIDTH-1]) result = 1'b1;
173
    if ((~v0_x[`D3D_FTOI_WIDTH-1] & (v0_x[`D3D_FTOI_WIDTH-2:0] > scr_w))&
174
        (~v1_x[`D3D_FTOI_WIDTH-1] & (v1_x[`D3D_FTOI_WIDTH-2:0] > scr_w))) result = 1'b1;
175
    if ((~v0_y[`D3D_FTOI_WIDTH-1] & (v0_y[`D3D_FTOI_WIDTH-2:0] > scr_h))&
176
        (~v1_y[`D3D_FTOI_WIDTH-1] & (v1_y[`D3D_FTOI_WIDTH-2:0] > scr_h))) result = 1'b1;
177
    f_reject = result;
178
  end
179
endfunction
180
 
181
endmodule

powered by: WebSVN 2.1.0

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