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

Subversion Repositories rtfbitmapcontroller

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

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

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

powered by: WebSVN 2.1.0

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