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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [rtl/] [core/] [fm_geo_viewport.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_geo_viewport.v
7
//
8
// Abstract:
9
//   Viewport mapping
10
//    v->x = ((v->x)+1)*m_vp_width/2+m_vp_x;
11
//    v->y = ((v->y)+1)*m_vp_height/2+m_vp_y;
12
//
13
//    m_vp_x = 0, m_vp_y =0
14
//    v->x = ((v->x)+1)*m_vp_width/2
15
//    v->y = ((v->y)+1)*m_vp_height/2
16
//
17
//    this module calc except /2:
18
//    v->x = ((v->x)+1)*m_vp_width
19
//    v->y = ((v->y)+1)*m_vp_height
20
//
21
// Author:
22 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
23 2 specular
//
24
//======================================================================
25
//
26
// Copyright (c) 2015, Kenji Ishimaru
27
// All rights reserved.
28
//
29
// Redistribution and use in source and binary forms, with or without
30
// modification, are permitted provided that the following conditions are met:
31
//
32
//  -Redistributions of source code must retain the above copyright notice,
33
//   this list of conditions and the following disclaimer.
34
//  -Redistributions in binary form must reproduce the above copyright notice,
35
//   this list of conditions and the following disclaimer in the documentation
36
//   and/or other materials provided with the distribution.
37
//
38
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
40
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
42
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
43
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
44
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
45
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
46
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
47
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
48
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
//
50
// Revision History
51
 
52
`include "fm_3d_define.v"
53
module fm_geo_viewport (
54
  input         clk_core,
55
  input         rst_x,
56
  output        o_state,
57
  // register configuration
58
  input [21:0]  i_vw,
59
  input [21:0]  i_vh,
60
  // vertex input
61
  input         i_en,
62
  output        o_ack,
63
  input  [5:0]  i_outcode,
64
  input  [21:0] i_vx,
65
  input  [21:0] i_vy,
66
  // vertex output
67
  output        o_en,
68
  input         i_ack,
69
  output [5:0]  o_outcode,
70
  output [21:0] o_vx,
71
  output [21:0] o_vy
72
);
73
localparam P_IDLE    = 'd0;
74
localparam P_Y_IN    = 'd1;
75
localparam P_WADD2   = 'd2;
76
localparam P_WMUL0   = 'd3;
77
localparam P_WMUL1   = 'd4;
78
localparam P_WMUL2   = 'd5;
79
localparam P_WMUL3   = 'd6;
80
localparam P_WAIT    = 'd7;
81
localparam P_DONE    = 'd8;
82
 
83
parameter P_1F              = 22'hf8000;
84
parameter P_SCREEN_WIDTH      = 22'h18a000;    // 640
85
parameter P_SCREEN_HEIGHT     = 22'h17f000;   // 480
86
parameter P_SCREEN_WIDTH_HALF = 22'h17a000;    // 640/2 = 320
87
parameter P_SCREEN_HEIGHT_HALF = 22'h16f000;   // 480 / 2 = 240
88
 
89
//////////////////////////////////
90
// regs 
91
//////////////////////////////////
92
reg [3:0]      r_state;
93
reg [21:0]     r_vx;
94
reg [21:0]     r_vy;
95
reg [5:0]      r_outcode;
96
 
97
//////////////////////////////////
98
// wire
99
//////////////////////////////////
100
wire [21:0] w_fadd_a;
101
wire [21:0] w_fadd_b;
102
wire [21:0] w_fadd_out;
103
wire [21:0] w_fmul_b;
104
wire [21:0] w_fmul_out;
105
 
106
wire        w_set_outcode;
107
wire        w_set_vx;
108
wire        w_set_vy;
109
//////////////////////////////////
110
// assign
111
//////////////////////////////////
112
assign o_state = (r_state == P_IDLE);
113
assign w_fadd_a = (r_state == P_IDLE) ? i_vx : i_vy;
114
assign w_fadd_b = P_1F;
115
assign w_fmul_b = (r_state == P_WMUL0) ? i_vw :
116
                                         i_vh ;
117
assign w_set_vx = (r_state == P_WMUL3);
118
assign w_set_vy = (r_state == P_WAIT);
119
assign o_vx = r_vx;
120
assign o_vy = r_vy;
121
assign o_en = (r_state == P_DONE);
122
assign o_ack = (r_state == P_IDLE);
123
assign w_set_outcode = (r_state == P_IDLE);
124
assign o_outcode = r_outcode;
125
 
126
//////////////////////////////////
127
// always
128
//////////////////////////////////
129
always @(posedge clk_core) begin
130
  if (w_set_outcode) r_outcode <= i_outcode;
131
  if (w_set_vx) r_vx <= w_fmul_out;
132
  if (w_set_vy) r_vy <= w_fmul_out;
133
end
134
 
135
`ifdef D3D_SYNC_RESET
136
always @(posedge clk_core) begin
137
`else
138
always @(posedge clk_core or negedge rst_x) begin
139
`endif
140
  if (rst_x == `D3D_RESET_POL) begin
141
    r_state <= P_IDLE;
142
  end else begin
143
    case (r_state)
144
      P_IDLE: begin
145
       if (i_en) r_state <= P_Y_IN;
146
      end
147
      P_Y_IN: r_state <= P_WADD2;
148
      P_WADD2: r_state <= P_WMUL0;
149
      P_WMUL0: r_state <= P_WMUL1;
150
      P_WMUL1: r_state <= P_WMUL2;
151
      P_WMUL2: r_state <= P_WMUL3;
152
      P_WMUL3: r_state <= P_WAIT;
153
      P_WAIT:  r_state <= P_DONE;
154
      P_DONE: begin
155
       if (i_ack) r_state <= P_IDLE;
156
      end
157
    endcase
158
  end
159
end
160
 
161
//////////////////////////////////
162
// module instance
163
//////////////////////////////////
164
fm_3d_fadd u_fadd (
165
  .clk_core(clk_core),
166
  .i_en(1'b1),
167
  .i_adsb(1'b0),
168
  .i_a(w_fadd_a),
169
  .i_b(w_fadd_b),
170
  .o_c(w_fadd_out)
171
);
172
 
173
fm_3d_fmul u_fmul (
174
  .clk_core(clk_core),
175
  .i_en(1'b1),
176
  .i_a(w_fadd_out),
177
  .i_b(w_fmul_b),
178
  .o_c(w_fmul_out)
179
);
180
 
181
 
182
endmodule

powered by: WebSVN 2.1.0

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