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

Subversion Repositories rtfbitmapcontroller

[/] [rtfbitmapcontroller/] [trunk/] [rtl/] [verilog/] [gfx_CalcAddress4.v] - Blame information for rev 19

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

Line No. Rev Author Line
1 19 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2015-2016  Robert Finch, Stratford
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//
9
// This source file is free software: you can redistribute it and/or modify 
10
// it under the terms of the GNU Lesser General Public License as published 
11
// by the Free Software Foundation, either version 3 of the License, or     
12
// (at your option) any later version.                                      
13
//                                                                          
14
// This source file is distributed in the hope that it will be useful,      
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
17
// GNU General Public License for more details.                             
18
//                                                                          
19
// You should have received a copy of the GNU General Public License        
20
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
21
//                                                                          
22
//      Verilog 1995
23
//
24
// ref: XC7a100t-1CSG324
25
// ============================================================================
26
//
27
// Compute the graphics address
28
//
29
module gfx_CalcAddress(clk, base_address_i, color_depth_i, hdisplayed_i, x_coord_i, y_coord_i,
30
        address_o, mb_o, me_o);
31
input clk;
32
input [31:0] base_address_i;
33
input [3:0] color_depth_i;
34
input [11:0] hdisplayed_i;       // pixel per line
35
input [11:0] x_coord_i;
36
input [11:0] y_coord_i;
37
output [31:0] address_o;
38
output [6:0] mb_o;
39
output [6:0] me_o;
40
 
41
parameter BPP8 = 3'd1;
42
parameter BPP12 = 3'd2;
43
parameter BPP16 = 3'd3;
44
parameter BPP24 = 3'd4;
45
parameter BPP32 = 3'd5;
46
 
47
reg [15:0] coeff;
48
always @(color_depth_i)
49
case(color_depth_i)
50
BPP8:   coeff = 4096;   // 1/16 * 65536
51
BPP12:  coeff = 6554;   // 1/10 * 65536
52
BPP16:  coeff = 8192;   // 1/8 * 65536
53
BPP24:  coeff = 13107;  // 1/5 * 65536
54
BPP32:  coeff = 16384;  // 1/4 * 65536
55
endcase
56
 
57
reg [5:0] bpp;
58
always @(color_depth_i)
59
case(color_depth_i)
60
BPP8:   bpp = 7;
61
BPP12:  bpp = 11;
62
BPP16:  bpp = 15;
63
BPP24:  bpp = 23;
64
BPP32:  bpp = 31;
65
endcase
66
 
67
reg [7:0] coeff2;
68
always @(color_depth_i)
69
case(color_depth_i)
70
BPP8:   coeff2 = 128;
71
BPP12:  coeff2 = 120;
72
BPP16:  coeff2 = 128;
73
BPP24:  coeff2 = 120;
74
BPP32:  coeff2 = 128;
75
endcase
76
 
77
wire [27:0] strip_num65k = x_coord_i * coeff;
78
wire [15:0] strip_fract = strip_num65k[15:0]+16'h7F;
79
wire [15:0] ndx = strip_fract[15:7] * coeff2;
80
assign mb_o = ndx[15:9];
81
assign me_o = mb_o + bpp;
82
// num_strips is essentially a constant value unless the screen resolution changes.
83
// Gain performance here by regstering the multiply so that there aren't two
84
// cascaded multiplies when calculating the offset.
85
reg [27:0] num_strips65k;
86
always @(posedge clk)
87
        num_strips65k <= hdisplayed_i * coeff;
88
wire [13:0] strip_num = strip_num65k[27:16];
89
wire [13:0] num_strips = num_strips65k[27:16];
90
 
91
wire [31:0] offset = {{4'b0,num_strips} * y_coord_i + strip_num,4'h0};
92
assign address_o = base_address_i + offset;
93
 
94
endmodule

powered by: WebSVN 2.1.0

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