Advertisement
kevinking0814

Untitled

Dec 7th, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2.  
  3. module picturereader(
  4.   input wire clk,
  5.   input wire rd_en,
  6.   input wire rd_en2,
  7.   input wire rd_en3,
  8.   input wire rd_enp1win,
  9.   input wire rd_enp2win,
  10.   output wire [3:0] r,
  11.   output wire [3:0] g,
  12.   output wire [3:0] b,
  13.  
  14.   output wire [3:0] p1r,
  15.   output wire [3:0] p1g,
  16.   output wire [3:0] p1b,
  17.  
  18.   output wire [3:0] p2r,
  19.   output wire [3:0] p2g,
  20.   output wire [3:0] p2b,
  21.  
  22.   output wire [3:0] p1wr,
  23.   output wire [3:0] p1wg,
  24.   output wire [3:0] p1wb,
  25.  
  26.   output wire [3:0] p2wr,
  27.   output wire [3:0] p2wg,
  28.   output wire [3:0] p2wb
  29. );
  30.  
  31.   // Memory addresses for different memory blocks
  32.   reg [14:0] address = 15'd0;
  33.   reg [15:0] p1address = 16'd0;
  34.   reg [15:0] p2address = 16'd0;
  35.   reg [18:0] p1waddress = 19'd0;
  36.   reg [18:0] p2waddress = 19'd0;
  37.  
  38.   // Pixel data from different memory blocks
  39.   wire [11:0] pixel;
  40.   wire [11:0] p1pixel;
  41.   wire [11:0] p2pixel;
  42.   wire [11:0] p1wpixel;
  43.  
  44.   // Parameterized sizes for different memory blocks
  45.   parameter PIC_SIZE = 15'd18400;
  46.   parameter p1PIC_SIZE = 16'd62500;
  47.   parameter p2PIC_SIZE = 16'd62500;
  48.   parameter p1wPIC_SIZE = 19'd360000;
  49.   parameter p2wPIC_SIZE = 19'd360000;
  50.  
  51.   // Extract RGB components from pixel data
  52.   assign r = pixel[11:8];
  53.   assign g = pixel[7:4];
  54.   assign b = pixel[3:0];
  55.  
  56.   assign p1r = p1pixel[11:8];
  57.   assign p1g = p1pixel[7:4];
  58.   assign p1b = p1pixel[3:0];
  59.  
  60.   assign p2r = p2pixel[11:8];
  61.   assign p2g = p2pixel[7:4];
  62.   assign p2b = p2pixel[3:0];
  63.  
  64.   assign p1wr = p1wpixel[11:8];
  65.   assign p1wg = p1wpixel[7:4];
  66.   assign p1wb = p1wpixel[3:0];
  67.  
  68.   assign p2wr = p2wpixel[11:8];
  69.   assign p2wg = p2wpixel[7:4];
  70.   assign p2wb = p2wpixel[3:0];
  71.  
  72.   // Logic for address incrementing
  73.   always @(posedge clk) begin
  74.     if (address == (PIC_SIZE - 1))
  75.       address <= 15'd0;
  76.     else if (rd_en) begin
  77.       address <= address + 1;
  78.     end
  79.  
  80.     if (p1address == (p1PIC_SIZE - 1))
  81.       p1address <= 16'd0;
  82.     else if (rd_en2) begin
  83.       p1address <= p1address + 1;
  84.     end
  85.  
  86.     if (p2address == (p2PIC_SIZE - 1))
  87.       p2address <= 16'd0;
  88.     else if (rd_en3) begin
  89.       p2address <= p2address + 1;
  90.     end
  91.  
  92.     if (p1waddress == (p1wPIC_SIZE - 1))
  93.       p1waddress <= 19'd0;
  94.     else if (rd_enp1win) begin
  95.       p1waddress <= p1waddress + 1;
  96.     end
  97.  
  98.     if (p2waddress == (p2wPIC_SIZE - 1))
  99.       p2waddress <= 19'd0;
  100.     else if (rd_enp2win) begin
  101.       p2waddress <= p2waddress + 1;
  102.     end
  103.   end
  104.  
  105.   // Instantiate memory modules for different blocks
  106.   picture_1 picture (.clka(clk), .addra(address), .douta(pixel));
  107.   blk_mem_gen_0 p1 (.clka(clk), .addra(p1address), .douta(p1pixel));
  108.   blk_mem_gen_1 p2 (.clka(clk), .addra(p2address), .douta(p2pixel));
  109.   p1win p1win (.clka(clk), .addra(p1waddress), .douta(p1wpixel));
  110.   blk_mem_gen_2 p2win (.clka(clk), .addra(p2waddress), .douta(p2wpixel));
  111.  
  112. endmodule
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement