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

Subversion Repositories rtfbitmapcontroller

[/] [rtfbitmapcontroller/] [trunk/] [rtl/] [verilog/] [gfx_CalcAddress6.v] - Blame information for rev 23

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

Line No. Rev Author Line
1 23 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2015-2018  Robert Finch, Waterloo
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
// ============================================================================
25
//
26
// Compute the graphics address
27
//
28
module gfx_CalcAddress6(clk, base_address_i, color_depth_i, hdisplayed_i, x_coord_i, y_coord_i,
29
        address_o, mb_o, me_o, ce_o);
30
input clk;
31
input [31:0] base_address_i;
32
input [2:0] color_depth_i;
33
input [11:0] hdisplayed_i;       // pixel per line
34
input [11:0] x_coord_i;
35
input [11:0] y_coord_i;
36
output [31:0] address_o;
37
output [5:0] mb_o;                                       // mask begin
38
output [5:0] me_o;                                       // mask end
39
output [5:0] ce_o;                                       // color bits end
40
 
41
parameter BPP4 = 3'd0;
42
parameter BPP8 = 3'd1;
43
parameter BPP12 = 3'd2;
44
parameter BPP16 = 3'd3;
45
parameter BPP20 = 3'd4;
46
parameter BPP32 = 3'd5;
47
 
48
// This coefficient is a fixed point fraction representing the inverse of the
49
// number of pixels per strip. The inverse (reciprocal) is used for a high
50
// speed divide operation.
51
reg [15:0] coeff;
52
always @(color_depth_i)
53
case(color_depth_i)
54
BPP4: coeff = 4096; // 1/16 * 65536
55
BPP8:   coeff = 8192;   // 1/8 * 65536
56
BPP12: coeff = 13107;   // 1/5 * 65536
57
BPP16:  coeff = 16384;  // 1/4 * 65536
58
BPP20:  coeff = 21845;  // 1/3 * 65536
59
BPP32:  coeff = 32768;  // 1/2 * 65536
60
default: coeff = 16384;
61
endcase
62
 
63
// Bits per pixel minus one.
64
reg [5:0] bpp;
65
always @(color_depth_i)
66
case(color_depth_i)
67
BPP4: bpp = 3;
68
BPP8:   bpp = 7;
69
BPP12: bpp = 11;
70
BPP16:  bpp = 15;
71
BPP20:  bpp = 19;
72
BPP32:  bpp = 31;
73
default:        bpp = 15;
74
endcase
75
 
76
// Color bits per pixel minus one.
77
reg [5:0] cbpp;
78
always @(color_depth_i)
79
case(color_depth_i)
80
BPP4: cbpp = 2;
81
BPP8:   cbpp = 5;
82
BPP12: cbpp = 8;
83
BPP16:  cbpp = 11;
84
BPP20:  cbpp = 14;
85
BPP32:  cbpp = 23;
86
default:        cbpp = 11;
87
endcase
88
 
89
// This coefficient is the number of bits used by all pixels in the strip. 
90
// Used to determine pixel placement in the strip.
91
reg [6:0] coeff2;
92
always @(color_depth_i)
93
case(color_depth_i)
94
BPP4: coeff2 = 64;
95
BPP8:   coeff2 = 64;
96
BPP12: coeff2 = 60;
97
BPP16:  coeff2 = 64;
98
BPP20:  coeff2 = 60;
99
BPP32:  coeff2 = 64;
100
default:        coeff2 = 64;
101
endcase
102
 
103
// Compute the fixed point horizonal strip number value. This has 16 binary
104
// point places.
105
wire [27:0] strip_num65k = x_coord_i * coeff;
106
// Truncate off the binary fraction to get the strip number. The strip
107
// number will be used to form part of the address.
108
wire [13:0] strip_num = strip_num65k[27:16];
109
// Calculate pixel position within strip using the fractional part of the
110
// horizontal strip number.
111
wire [15:0] strip_fract = strip_num65k[15:0]+16'h7F;  // +7F to round
112
// Pixel beginning bit is ratio of pixel # into all bits used by pixels
113
wire [14:0] ndx = strip_fract[15:7] * coeff2;
114
assign mb_o = ndx[12:7];  // Get whole pixel position (discard fraction)
115
assign me_o = mb_o + bpp; // Set high order position for mask
116
assign ce_o = mb_o + cbpp;
117
// num_strips is essentially a constant value unless the screen resolution changes.
118
// Gain performance here by regstering the multiply so that there aren't two
119
// cascaded multiplies when calculating the offset.
120
reg [27:0] num_strips65k;
121
always @(posedge clk)
122
        num_strips65k <= hdisplayed_i * coeff;
123
wire [11:0] num_strips = num_strips65k[27:16];
124
 
125
wire [31:0] offset = {(({4'b0,num_strips} * y_coord_i) + strip_num),3'h0};
126
assign address_o = base_address_i + offset;
127
 
128
endmodule

powered by: WebSVN 2.1.0

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