SHARE
TWEET

Untitled

a guest Sep 5th, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer:
  5. //
  6. // Create Date: 06.04.2019 12:36:06
  7. // Design Name:
  8. // Module Name: draw_rect_char
  9. // Project Name:
  10. // Target Devices:
  11. // Tool Versions:
  12. // Description:
  13. //
  14. // Draws a char whose font is provided by font_rom module.
  15. // The combinational part for rgb is based on the following concept:
  16. // 'char_pixels' give us 8 bits for the one vertical line of the char -
  17. //          if bit=1, the pixel should be printed with a different colour, to create a char (later on)
  18. // 'hcount_in[2:0]' may vary from 0..7 and indicates current vert. position "in the printed char"
  19. // the sum of currently printed pixel (index of "char_pixels": 0..7) and "hcount_in[2:0]" is always equal to 7;
  20. // e.g. if hcount_in[2:0]=3'b000, then we print (if 1) the first component of the char, which is char_pixels[7];
  21. // if hcount_in[2:0]=3'b001, then we move on and print char_pixels[6]...
  22. // Dependencies:
  23. //
  24. // Additional Comments:
  25. //
  26. //////////////////////////////////////////////////////////////////////////////////
  27.  
  28. module draw_rect_char #(
  29.     parameter XPOS = 0,
  30.     parameter YPOS = 0
  31. )
  32. (
  33.    input wire clk,
  34.    input wire rst,
  35.    input wire enable,
  36.    input wire [10:0] hcount_in,
  37.    input wire hsync_in,
  38.    input wire hblank_in,
  39.    input wire [10:0] vcount_in,
  40.    input wire vsync_in,
  41.    input wire vblank_in,
  42.    input wire [11:0] rgb_in,
  43.    input wire [7:0] char_pixels,    
  44.    
  45.    output reg [10:0]  hcount_out,
  46.    output reg hsync_out,
  47.    output reg hblank_out,
  48.    output reg [10:0] vcount_out,
  49.    output reg vsync_out,
  50.    output reg vblank_out,
  51.    output reg [11:0] rgb_out,
  52.    output wire [7:0] char_yx,           //char position in the rectangle
  53.    output wire [3:0] char_line          //line of the char
  54. );
  55.  
  56. localparam WIDTH = 128;
  57. localparam HEIGHT = 256;
  58.  
  59. reg [10:0] char_x, char_x_del, char_y;
  60. reg [11:0] rgb_out_nxt, rgb_temp;
  61. reg [10:0] hcount_temp, vcount_temp;
  62. reg hsync_temp, vsync_temp, hblank_temp, vblank_temp;  
  63.  
  64. always @(posedge clk) begin
  65.  if (rst) begin
  66.          hsync_out <= 0;
  67.          vsync_out <= 0;
  68.          hblank_out <= 0;
  69.          vblank_out <= 0;
  70.          hcount_out <= 0;
  71.          vcount_out <= 0;
  72.          
  73.          hsync_temp <= 0;
  74.          vsync_temp <= 0;
  75.          hblank_temp <= 0;
  76.          vblank_temp <= 0;
  77.          hcount_temp <= 0;
  78.          vcount_temp <= 0;  
  79. end
  80. else begin
  81.         hcount_out <= hcount_temp;
  82.         vcount_out <= vcount_temp;
  83.         hsync_out <= hsync_temp;
  84.         vsync_out <= vsync_temp;
  85.         hblank_out <= hblank_temp;
  86.         vblank_out <= vblank_temp;
  87.         rgb_out <= rgb_out_nxt;
  88.        
  89.         hcount_temp <= hcount_in;
  90.         vcount_temp <= vcount_in;
  91.         hsync_temp <= hsync_in;
  92.         vsync_temp <= vsync_in;
  93.         hblank_temp <= hblank_in;
  94.         vblank_temp <= vblank_in;
  95.         rgb_temp <= rgb_in;
  96.    end
  97. end
  98.  
  99. assign char_line = char_y[3:0];
  100. assign char_yx = {char_y[7:4],char_x[6:3]};          //{y_char,x_char}
  101.  
  102. //print char
  103. always @* begin
  104.     if (enable) begin
  105.          char_y = vcount_in-YPOS;
  106.          char_x = hcount_in-XPOS;
  107.          char_x_del = hcount_temp-XPOS;
  108.          if (hcount_temp >= XPOS && hcount_temp < (WIDTH + XPOS)
  109.              && vcount_temp >= YPOS && vcount_temp < (HEIGHT + YPOS)
  110.              && (char_pixels[7 - char_x_del[2:0]]))       // 'char' rectangle
  111.                  rgb_out_nxt = {vcount_temp,1'b1};
  112.          else if (hcount_temp >= (XPOS - 50) && hcount_temp < (WIDTH + XPOS + 100)
  113.                  && vcount_temp >= (YPOS - 200) && vcount_temp < (YPOS + 50)
  114.                  && (char_pixels[7 - char_x_del[2:0]]))
  115.                     rgb_out_nxt = 12'h000;
  116.          else    //'non-char' area
  117.                  rgb_out_nxt = rgb_temp;
  118.     end
  119.     else
  120.                  rgb_out_nxt = rgb_temp;
  121. end
  122.  
  123. endmodule
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top