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

Subversion Repositories rtfbitmapcontroller

[/] [rtfbitmapcontroller/] [trunk/] [rtl/] [verilog/] [gfx_CalcAddress6.v] - Diff between revs 23 and 24

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 23 Rev 24
Line 1... Line 1...
// ============================================================================
// ============================================================================
//        __
//        __
//   \\__/ o\    (C) 2015-2018  Robert Finch, Waterloo
//   \\__/ o\    (C) 2015-2019  Robert Finch, Waterloo
//    \  __ /    All rights reserved.
//    \  __ /    All rights reserved.
//     \/_//     robfinch<remove>@finitron.ca
//     \/_//     robfinch<remove>@finitron.ca
//       ||
//       ||
//
//
//
//
Line 25... Line 25...
//
//
// Compute the graphics address
// Compute the graphics address
//
//
module gfx_CalcAddress6(clk, base_address_i, color_depth_i, hdisplayed_i, x_coord_i, y_coord_i,
module gfx_CalcAddress6(clk, base_address_i, color_depth_i, hdisplayed_i, x_coord_i, y_coord_i,
        address_o, mb_o, me_o, ce_o);
        address_o, mb_o, me_o, ce_o);
 
parameter SW = 128;             // strip width in bits
 
parameter BN = SW==128 ? 6 : SW==64 ? 5 : 4;
input clk;
input clk;
input [31:0] base_address_i;
input [31:0] base_address_i;
input [2:0] color_depth_i;
input [2:0] color_depth_i;
input [11:0] hdisplayed_i;       // pixel per line
input [11:0] hdisplayed_i;       // pixel per line
input [11:0] x_coord_i;
input [11:0] x_coord_i;
input [11:0] y_coord_i;
input [11:0] y_coord_i;
output [31:0] address_o;
output [31:0] address_o;
output [5:0] mb_o;                                       // mask begin
output [BN:0] mb_o;                                      // mask begin
output [5:0] me_o;                                       // mask end
output [BN:0] me_o;                                      // mask end
output [5:0] ce_o;                                       // color bits end
output [BN:0] ce_o;                                      // color bits end
 
 
parameter BPP4 = 3'd0;
parameter BPP4 = 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;
Line 48... Line 50...
// This coefficient is a fixed point fraction representing the inverse of the
// 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
// number of pixels per strip. The inverse (reciprocal) is used for a high
// speed divide operation.
// speed divide operation.
reg [15:0] coeff;
reg [15:0] coeff;
always @(color_depth_i)
always @(color_depth_i)
 
case(SW)
 
128:
 
        case(color_depth_i)
 
        BPP4: coeff = 2048; // 1/32 * 65536
 
        BPP8:   coeff = 4096;   // 1/16 * 65536
 
        BPP12:  coeff = 6554;   // 1/10 * 65536
 
        BPP16:  coeff = 8192;   // 1/8 * 65536
 
        BPP20:  coeff = 10923;  // 1/6 * 65536
 
        BPP32:  coeff = 16384;  // 1/4 * 65536
 
        default:        coeff = 8192;
 
        endcase
 
64:
case(color_depth_i)
case(color_depth_i)
BPP4: coeff = 4096; // 1/16 * 65536
BPP4: coeff = 4096; // 1/16 * 65536
BPP8:   coeff = 8192;   // 1/8 * 65536
BPP8:   coeff = 8192;   // 1/8 * 65536
BPP12: coeff = 13107;   // 1/5 * 65536
BPP12: coeff = 13107;   // 1/5 * 65536
BPP16:  coeff = 16384;  // 1/4 * 65536
BPP16:  coeff = 16384;  // 1/4 * 65536
BPP20:  coeff = 21845;  // 1/3 * 65536
BPP20:  coeff = 21845;  // 1/3 * 65536
BPP32:  coeff = 32768;  // 1/2 * 65536
        BPP32:  coeff = 32767;  // 1/2 * 65536
default: coeff = 16384;
default: coeff = 16384;
endcase
endcase
 
32:
 
        case(color_depth_i)
 
        BPP4: coeff = 8192; // 1/8 * 65536
 
        BPP8:   coeff = 16384;  // 1/4 * 65536
 
        BPP12: coeff = 32767;   // 1/2 * 65536
 
        BPP16:  coeff = 32767;  // 1/2 * 65536
 
        BPP20:  coeff = 65535;  // 1/1 * 65536
 
        BPP32:  coeff = 65535;  // 1/1 * 65536
 
        default: coeff = 32767;
 
        endcase
 
default:        // 128
 
        case(color_depth_i)
 
        BPP4: coeff = 2048; // 1/32 * 65536
 
        BPP8:   coeff = 4096;   // 1/16 * 65536
 
        BPP12:  coeff = 6554;   // 1/10 * 65536
 
        BPP16:  coeff = 8192;   // 1/8 * 65536
 
        BPP20:  coeff = 10923;  // 1/6 * 65536
 
        BPP32:  coeff = 16384;  // 1/4 * 65536
 
        default:        coeff = 8192;
 
        endcase
 
endcase
 
 
// Bits per pixel minus one.
// 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)
Line 86... Line 121...
default:        cbpp = 11;
default:        cbpp = 11;
endcase
endcase
 
 
// This coefficient is the number of bits used by all pixels in the strip. 
// This coefficient is the number of bits used by all pixels in the strip. 
// Used to determine pixel placement in the strip.
// Used to determine pixel placement in the strip.
reg [6:0] coeff2;
reg [7:0] coeff2;
always @(color_depth_i)
always @(color_depth_i)
case(color_depth_i)
case(color_depth_i)
BPP4: coeff2 = 64;
BPP4: coeff2 = SW;
BPP8:   coeff2 = 64;
BPP8:   coeff2 = SW;
BPP12: coeff2 = 60;
BPP12: coeff2 = SW==128 ? 120 : SW==64 ? 60 : 24;
BPP16:  coeff2 = 64;
BPP16:  coeff2 = SW;
BPP20:  coeff2 = 60;
BPP20:  coeff2 = SW==128 ? 120 : SW==64 ? 60 : 20;
BPP32:  coeff2 = 64;
BPP32:  coeff2 = SW;
default:        coeff2 = 64;
default:        coeff2 = SW;
endcase
endcase
 
 
// Compute the fixed point horizonal strip number value. This has 16 binary
// Compute the fixed point horizonal strip number value. This has 16 binary
// point places.
// point places.
wire [27:0] strip_num65k = x_coord_i * coeff;
wire [27:0] strip_num65k = x_coord_i * coeff;
Line 108... Line 143...
wire [13:0] strip_num = strip_num65k[27:16];
wire [13:0] strip_num = strip_num65k[27:16];
// Calculate pixel position within strip using the fractional part of the
// Calculate pixel position within strip using the fractional part of the
// horizontal strip number.
// horizontal strip number.
wire [15:0] strip_fract = strip_num65k[15:0]+16'h7F;  // +7F to round
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
// Pixel beginning bit is ratio of pixel # into all bits used by pixels
wire [14:0] ndx = strip_fract[15:7] * coeff2;
wire [15:0] ndx = strip_fract[15:7] * coeff2;
assign mb_o = ndx[12:7];  // Get whole pixel position (discard fraction)
assign mb_o = ndx[15:9];  // Get whole pixel position (discard fraction)
assign me_o = mb_o + bpp; // Set high order position for mask
assign me_o = mb_o + bpp; // Set high order position for mask
assign ce_o = mb_o + cbpp;
assign ce_o = mb_o + cbpp;
// 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 [11:0] num_strips = num_strips65k[27:16];
wire [11:0] num_strips = num_strips65k[27:16];
 
 
wire [31:0] offset = {(({4'b0,num_strips} * y_coord_i) + strip_num),3'h0};
wire [31:0] offset = {(({4'b0,num_strips} * y_coord_i) + strip_num),SW==128 ? 4'h0 : SW==64 ? 3'h0 : 2'd0};
assign address_o = base_address_i + offset;
assign address_o = base_address_i + offset;
 
 
endmodule
endmodule
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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