Line 36... |
Line 36... |
input [11:0] y_coord_i;
|
input [11:0] y_coord_i;
|
output [31:0] address_o;
|
output [31:0] address_o;
|
output [6:0] mb_o;
|
output [6:0] mb_o;
|
output [6:0] me_o;
|
output [6:0] me_o;
|
|
|
|
parameter BPP6 = 3'd0;
|
parameter BPP8 = 3'd1;
|
parameter BPP8 = 3'd1;
|
parameter BPP12 = 3'd2;
|
parameter BPP12 = 3'd2;
|
parameter BPP16 = 3'd3;
|
parameter BPP16 = 3'd3;
|
parameter BPP24 = 3'd4;
|
parameter BPP24 = 3'd4;
|
parameter BPP32 = 3'd5;
|
parameter BPP32 = 3'd5;
|
|
|
|
// This coefficient is a fixed point fraction representing the inverse of the
|
|
// number of pixels per strip. The inverse (reciprocal) is used for a high
|
|
// speed divide operation.
|
reg [15:0] coeff;
|
reg [15:0] coeff;
|
always @(color_depth_i)
|
always @(color_depth_i)
|
case(color_depth_i)
|
case(color_depth_i)
|
|
BPP6: coeff = 3121; // 1/21 * 65536
|
BPP8: coeff = 4096; // 1/16 * 65536
|
BPP8: coeff = 4096; // 1/16 * 65536
|
BPP12: coeff = 6554; // 1/10 * 65536
|
BPP12: coeff = 6554; // 1/10 * 65536
|
BPP16: coeff = 8192; // 1/8 * 65536
|
BPP16: coeff = 8192; // 1/8 * 65536
|
BPP24: coeff = 13107; // 1/5 * 65536
|
BPP24: coeff = 13107; // 1/5 * 65536
|
BPP32: coeff = 16384; // 1/4 * 65536
|
BPP32: coeff = 16384; // 1/4 * 65536
|
endcase
|
endcase
|
|
|
|
// Bits per pixel minus one.
|
reg [5:0] bpp;
|
reg [5:0] bpp;
|
always @(color_depth_i)
|
always @(color_depth_i)
|
case(color_depth_i)
|
case(color_depth_i)
|
|
BPP6: bpp = 5;
|
BPP8: bpp = 7;
|
BPP8: bpp = 7;
|
BPP12: bpp = 11;
|
BPP12: bpp = 11;
|
BPP16: bpp = 15;
|
BPP16: bpp = 15;
|
BPP24: bpp = 23;
|
BPP24: bpp = 23;
|
BPP32: bpp = 31;
|
BPP32: bpp = 31;
|
endcase
|
endcase
|
|
|
|
// This coefficient is the number of bits used by all pixels in the strip.
|
|
// Used to determine pixel placement in the strip.
|
reg [7:0] coeff2;
|
reg [7:0] coeff2;
|
always @(color_depth_i)
|
always @(color_depth_i)
|
case(color_depth_i)
|
case(color_depth_i)
|
|
BPP6: coeff2 = 126;
|
BPP8: coeff2 = 128;
|
BPP8: coeff2 = 128;
|
BPP12: coeff2 = 120;
|
BPP12: coeff2 = 120;
|
BPP16: coeff2 = 128;
|
BPP16: coeff2 = 128;
|
BPP24: coeff2 = 120;
|
BPP24: coeff2 = 120;
|
BPP32: coeff2 = 128;
|
BPP32: coeff2 = 128;
|
endcase
|
endcase
|
|
|
|
// Compute the fixed point horizonal strip number value. This has 16 binary
|
|
// point places.
|
wire [27:0] strip_num65k = x_coord_i * coeff;
|
wire [27:0] strip_num65k = x_coord_i * coeff;
|
wire [15:0] strip_fract = strip_num65k[15:0]+16'h7F;
|
// Truncate off the binary fraction to get the strip number. The strip
|
|
// number will be used to form part of the address.
|
|
wire [13:0] strip_num = strip_num65k[27:16];
|
|
// Calculate pixel position within strip using the fractional part of the
|
|
// horizontal strip number.
|
|
wire [15:0] strip_fract = strip_num65k[15:0]+16'h7F; // +7F to round
|
|
// Pixel beginning bit is ratio of pixel # into all bits used by pixels
|
wire [15:0] ndx = strip_fract[15:7] * coeff2;
|
wire [15:0] ndx = strip_fract[15:7] * coeff2;
|
assign mb_o = ndx[15:9];
|
assign mb_o = ndx[15:9]; // Get whole pixel position (discard fraction)
|
assign me_o = mb_o + bpp;
|
assign me_o = mb_o + bpp; // Set high order position for mask
|
// num_strips is essentially a constant value unless the screen resolution changes.
|
// num_strips is essentially a constant value unless the screen resolution changes.
|
// Gain performance here by regstering the multiply so that there aren't two
|
// Gain performance here by regstering the multiply so that there aren't two
|
// cascaded multiplies when calculating the offset.
|
// cascaded multiplies when calculating the offset.
|
reg [27:0] num_strips65k;
|
reg [27:0] num_strips65k;
|
always @(posedge clk)
|
always @(posedge clk)
|
num_strips65k <= hdisplayed_i * coeff;
|
num_strips65k <= hdisplayed_i * coeff;
|
wire [13:0] strip_num = strip_num65k[27:16];
|
|
wire [13:0] num_strips = num_strips65k[27:16];
|
wire [13:0] num_strips = num_strips65k[27:16];
|
|
|
wire [31:0] offset = {{4'b0,num_strips} * y_coord_i + strip_num,4'h0};
|
wire [31:0] offset = {{4'b0,num_strips} * y_coord_i + strip_num,4'h0};
|
assign address_o = base_address_i + offset;
|
assign address_o = base_address_i + offset;
|
|
|