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

Subversion Repositories rf6809

[/] [rf6809/] [trunk/] [rtl/] [noc/] [video/] [gfx_calc_address.sv] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2015-2022  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
//
37
// Compute the graphics address
38
//
39
import gfx_pkg::*;
40
 
41
module gfx_calc_address(clk, base_address_i, color_depth_i, bmp_width_i, x_coord_i, y_coord_i,
42
        address_o, mb_o, me_o, ce_o);
43
parameter SW = 96;              // strip width in bits
44
parameter BN = 6;
45
input clk;
46
input [31:0] base_address_i;
47
input [3:0] color_depth_i;
48
input [15:0] bmp_width_i;       // pixel per line
49
input [15:0] x_coord_i;
50
input [15:0] y_coord_i;
51
output [31:0] address_o;
52
output [BN:0] mb_o;                                     // mask begin
53
output [BN:0] me_o;                                     // mask end
54
output [BN:0] ce_o;                                     // color bits end
55
 
56
// This coefficient is a fixed point fraction representing the inverse of the
57
// number of pixels per strip. The inverse (reciprocal) is used for a high
58
// speed divide operation.
59
reg [15:0] coeff;
60
always @(color_depth_i)
61
        case(color_depth_i)
62
        BPP6: coeff = 65536*6/SW;
63
        BPP8:   coeff = 65536*8/SW;
64
        BPP12:  coeff = 65536*12/SW;
65
        BPP16:  coeff = 65536*16/SW;
66
        BPP18:  coeff = 65536*18/SW;
67
        BPP21:  coeff = 65536*21/SW;
68
        BPP24:  coeff = 65536*24/SW;
69
        BPP27:  coeff = 65536*27/SW;
70
        BPP32:  coeff = 65536*32/SW;
71
        BPP33:  coeff = 65536*33/SW;
72
        default:        coeff = 65536*16/SW;
73
        endcase
74
 
75
// Bits per pixel minus one.
76
reg [5:0] bpp;
77
always @(color_depth_i)
78
case(color_depth_i)
79
BPP6: bpp = 5;
80
BPP8:   bpp = 7;
81
BPP12: bpp = 11;
82
BPP16:  bpp = 15;
83
BPP18:  bpp = 17;
84
BPP21:  bpp = 20;
85
BPP24:  bpp = 23;
86
BPP27:  bpp = 26;
87
BPP32:  bpp = 31;
88
BPP33:  bpp = 32;
89
default:        bpp = 15;
90
endcase
91
 
92
// Color bits per pixel minus one.
93
reg [5:0] cbpp;
94
always @(color_depth_i)
95
case(color_depth_i)
96
BPP6: cbpp = 2;
97
BPP8:   cbpp = 4;
98
BPP12: cbpp = 8;
99
BPP16:  cbpp = 11;
100
BPP18:  cbpp = 14;
101
BPP21:  cbpp = 17;
102
BPP24:  cbpp = 20;
103
BPP27:  cbpp = 23;
104
BPP32:  cbpp = 26;
105
BPP33:  cbpp = 29;
106
default:        cbpp = 11;
107
endcase
108
 
109
// This coefficient is the number of bits used by all pixels in the strip.
110
// Used to determine pixel placement in the strip.
111
reg [7:0] coeff2;
112
always @(color_depth_i)
113
case(color_depth_i)
114
BPP6: coeff2 = SW-(SW % 6);
115
BPP8:   coeff2 = SW-(SW % 8);
116
BPP12: coeff2 = SW-(SW % 12);
117
BPP16:  coeff2 = SW-(SW % 16);
118
BPP18:  coeff2 = SW-(SW % 18);
119
BPP21:  coeff2 = SW-(SW % 21);
120
BPP24:  coeff2 = SW-(SW % 24);
121
BPP27:  coeff2 = SW-(SW % 27);
122
BPP32:  coeff2 = SW-(SW % 32);
123
BPP33:  coeff2 = SW-(SW % 33);
124
default:        coeff2 = SW-(SW % 16);
125
endcase
126
 
127
// Compute the fixed point horizonal strip number value. This has 16 binary
128
// point places.
129
wire [31:0] strip_num65k = x_coord_i * coeff;
130
// Truncate off the binary fraction to get the strip number. The strip
131
// number will be used to form part of the address.
132
wire [17:0] strip_num = strip_num65k[31:16];
133
// Calculate pixel position within strip using the fractional part of the
134
// horizontal strip number.
135
wire [15:0] strip_fract = strip_num65k[15:0]+16'h7F;  // +7F to round
136
// Pixel beginning bit is ratio of pixel # into all bits used by pixels
137
wire [15:0] ndx = strip_fract[15:7] * coeff2;
138
assign mb_o = ndx[15:9];  // Get whole pixel position (discard fraction)
139
assign me_o = mb_o + bpp; // Set high order position for mask
140
assign ce_o = mb_o + cbpp;
141
// num_strips is essentially a constant value unless the screen resolution changes.
142
// Gain performance here by regstering the multiply so that there aren't two
143
// cascaded multiplies when calculating the offset.
144
reg [31:0] num_strips65k;
145
always @(posedge clk)
146
        num_strips65k <= bmp_width_i * coeff;
147
wire [15:0] num_strips = num_strips65k[31:16];
148
 
149
wire [31:0] offset = {(({4'b0,num_strips} * y_coord_i) + strip_num),4'h0};
150
 
151
assign address_o = base_address_i + offset;
152
 
153
endmodule

powered by: WebSVN 2.1.0

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