Advertisement
kevinking0814

Untitled

Dec 7th, 2023
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module drawfinish(
  2.     input clk,                        // Input clock signal
  3.     input [1:0] state_transition,     // State transition input
  4.     input [10:0] draw_x,              // X-coordinate input
  5.     input [9:0] draw_y,               // Y-coordinate input
  6.     input [3:0] p1wr, p1wg, p1wb,     // Player 1 color inputs
  7.     input [3:0] p2wr, p2wg, p2wb,     // Player 2 color inputs
  8.     output [3:0] out_r, out_g, out_b,  // RGB output
  9.     output reg [1:0] rd_enp1win,       // Player 1 window read enable
  10.     output reg [1:0] rd_enp2win        // Player 2 window read enable
  11.     );
  12.  
  13.     reg [3:0] r, g, b;                  // RGB values for output
  14.     reg [3:0] pic_r, pic_g, pic_b;      // Player 1 window color
  15.     reg [3:0] p2_r, p2_g, p2_b;         // Player 2 window color
  16.  
  17.     wire rd_enp1win;                   // Player 1 window read enable (wire)
  18.     wire rd_enp2win;                   // Player 2 window read enable (wire)
  19.  
  20.     // Player 1 window read enable logic
  21.     assign rd_enp1win = ((draw_x >= 240) && (draw_x <= 1039) && (draw_y >= 175) && (draw_y <= 624));
  22.  
  23.     // Player 2 window read enable logic
  24.     assign rd_enp2win = ((draw_x >= 240) && (draw_x <= 1039) && (draw_y >= 175) && (draw_y <= 624));
  25.  
  26.     // Player 1 window color logic
  27.     always @(posedge clk) begin
  28.         if (rd_enp1win == 1'd1 && p1wb > 4'd0000) begin
  29.             pic_r <= 4'b1111;
  30.             pic_g <= 4'b1111; // pic
  31.             pic_b <= 4'b1111;
  32.         end
  33.         else begin
  34.             pic_r = 4'b1111;
  35.             pic_g = 4'b1111; // pic
  36.             pic_b = 4'b1111;
  37.         end
  38.     end
  39.  
  40.     // Player 2 window color logic
  41.     always @(posedge clk) begin
  42.         if (rd_enp2win == 1'd1 && p2wb > 4'd0000) begin
  43.             p2_r <= 4'b1111;
  44.             p2_g <= 4'b1111; // pic
  45.             p2_b <= 4'b1111;
  46.         end
  47.         else begin
  48.             p2_r = 4'b1111;
  49.             p2_g = 4'b1111; // pic
  50.             p2_b = 4'b1111;
  51.         end
  52.     end
  53.  
  54.     // Output color logic based on state transition
  55.     always @* begin
  56.         if (state_transition == 1) // Player 1 wins
  57.             if (rd_enp1win == 1'd1) begin
  58.                 // If block color is non-zero, assign it to the RGB outputs
  59.                 r = pic_b;
  60.                 g = pic_b;
  61.                 b = pic_b;
  62.             end
  63.             else begin
  64.                 r = 4'b1111;
  65.                 g = 4'b1111;
  66.                 b = 4'b1111;
  67.             end
  68.         else begin
  69.             if (rd_enp2win == 1'd1) begin // Player 2 wins
  70.                 // If block color is non-zero, assign it to the RGB outputs
  71.                 r = p2_b;
  72.                 g = p2_b;
  73.                 b = p2_b;
  74.             end
  75.             else begin
  76.                 r = 4'b1111;
  77.                 g = 4'b1111;
  78.                 b = 4'b1111;
  79.             end
  80.         end
  81.     end
  82.  
  83.     // Assign output values
  84.     assign out_r = r;
  85.     assign out_g = g;
  86.     assign out_b = b;
  87.  
  88. endmodule
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement