data/full_repos/permissive/504677412/src/color_bar.v
1: b'%Error: data/full_repos/permissive/504677412/src/color_bar.v:3: Cannot find include file: defines.v\n`include "defines.v" \n         ^~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/504677412/src,data/full_repos/permissive/504677412/defines.v\n             data/full_repos/permissive/504677412/src,data/full_repos/permissive/504677412/defines.v.v\n             data/full_repos/permissive/504677412/src,data/full_repos/permissive/504677412/defines.v.sv\n             defines.v\n             defines.v.v\n             defines.v.sv\n             obj_dir/defines.v\n             obj_dir/defines.v.v\n             obj_dir/defines.v.sv\n%Error: Exiting due to 1 error(s)\n'
module color_bar (
  clk,
  rst,
  en_cam,
  hs,
  vs,
  de,
  data
);
  input  wire                       clk;
  input  wire                       rst;
  input  wire                       en_cam;
  output wire                       hs;
  output wire                       vs;
  output wire                       de;
  output wire [7:0]                 data;
  



















  parameter H_ACTIVE              = 16'd1280;
  parameter H_FP                  = 16'd66;
  parameter H_SYNC                = 16'd50;
  parameter H_BP                  = 16'd132; 
  parameter V_ACTIVE              = 16'd400;
  parameter V_FP                  = 16'd89;
  parameter V_SYNC                = 16'd322;
  parameter V_BP                  = 16'd89;
  
  parameter H_TOTAL               = H_ACTIVE + H_FP + H_SYNC + H_BP;
  parameter V_TOTAL               = V_ACTIVE + V_FP + V_SYNC + V_BP;

  parameter WHITE_R               = 8'hff;
  parameter WHITE_G               = 8'hff;
  parameter WHITE_B               = 8'hff;
  parameter YELLOW_R              = 8'hff;
  parameter YELLOW_G              = 8'hff;
  parameter YELLOW_B              = 8'h00;                                
  parameter CYAN_R                = 8'h00;
  parameter CYAN_G                = 8'hff;
  parameter CYAN_B                = 8'hff;                               
  parameter GREEN_R               = 8'h00;
  parameter GREEN_G               = 8'hff;
  parameter GREEN_B               = 8'h00;
  parameter MAGENTA_R             = 8'hff;
  parameter MAGENTA_G             = 8'h00;
  parameter MAGENTA_B             = 8'hff;
  parameter RED_R                 = 8'hff;
  parameter RED_G                 = 8'h00;
  parameter RED_B                 = 8'h00;
  parameter BLUE_R                = 8'h00;
  parameter BLUE_G                = 8'h00;
  parameter BLUE_B                = 8'hff;
  parameter BLACK_R               = 8'h00;
  parameter BLACK_G               = 8'h00;
  parameter BLACK_B               = 8'h00;

  reg                               hs_reg;
  reg                               vs_reg;
  reg                               hs_reg_d0;

  reg                               vs_reg_d0;
  reg  [11:0]                       h_cnt;
  reg  [11:0]                       v_cnt;
  reg  [11:0]                       active_x;
  reg  [11:0]                       active_y;
  reg  [7:0]                        rgb_r_reg;
  reg  [7:0]                        rgb_g_reg;
  reg  [7:0]                        rgb_b_reg;
  reg  [1:0]                        data_cntr;
  reg  [1:0]                        data_cntr_d1;
  reg                               h_active;
  reg                               v_active;
  wire                              video_active;
  reg                               video_active_d0;
  reg                               en_cam_d1;
  reg                               en_cam_sync;
  
  wire [15:0]                       Y_i;
  wire [15:0]                       Cb_i;
  wire [15:0]                       Cr_i;
  
  wire [10:0]                       rom_addr;
  wire [7:0]                        rom_dout;
  reg  [7:0]                        line_cntr;
  reg  [7:0]                        rom_dout_d1;
  wire                              eol;
  
  assign hs = hs_reg_d0;
  assign vs = vs_reg_d0;

  assign video_active = h_active & v_active;
  assign de = video_active_d0;



  always@(posedge clk) begin
    en_cam_d1   <= en_cam;
    en_cam_sync <= en_cam_d1;
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      hs_reg_d0 <= 1'b0;
      vs_reg_d0 <= 1'b0;
      video_active_d0 <= 1'b0;
    end else begin
      hs_reg_d0 <= hs_reg;
      vs_reg_d0 <= vs_reg;
      video_active_d0 <= video_active;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      data_cntr <= 2'b0;
    end else if(video_active) begin
      data_cntr <= data_cntr + 1;
    end else begin
      data_cntr <= 2'b0;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      data_cntr_d1 <= 2'b0;
    end else begin
      data_cntr_d1 <= data_cntr;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      h_cnt <= 12'd0;
    end else if (en_cam_sync) begin
      if(h_cnt == H_TOTAL - 1) begin
        h_cnt <= 12'd0;
      end else begin
        h_cnt <= h_cnt + 12'd1;
      end
    end else begin
      h_cnt <= 12'd0;
    end
  end
  
  `ifdef BAR_PATTERN
    reg[11:0] bar_cnt;
    always@(posedge clk or posedge rst) begin
      if(rst) begin
        bar_cnt <= 12'd0;
      end else if (video_active) begin
        bar_cnt <= bar_cnt + 12'd1;
      end else begin
        bar_cnt <= 12'd0;
      end
    end
  `else
    wire [11:0] bar_cnt;
    `ifdef WHITE_OLED
      assign bar_cnt = 12'd0;
    `elsif BLACK_OLED
      assign bar_cnt = (H_ACTIVE/8) * 7;
    `elsif BLUE_OLED
      assign bar_cnt = (H_ACTIVE/8) * 6;
    `else
      assign bar_cnt = 12'd0;
    `endif
  `endif
  











  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      active_x <= 12'd0;
    end else if(h_cnt >= H_FP + H_SYNC + H_BP - 1) begin
      active_x <= h_cnt - (H_FP[11:0] + H_SYNC[11:0] + H_BP[11:0] - 12'd1);
    end else begin
      active_x <= active_x;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      v_cnt <= 12'd0;
    end else if(h_cnt == H_FP  - 1) begin
      if(v_cnt == V_TOTAL - 1) begin
        v_cnt <= 12'd0;
      end else begin
        v_cnt <= v_cnt + 12'd1;
      end
    end else begin
      v_cnt <= v_cnt;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      hs_reg <= 1'b0;
    end else if(h_cnt == H_FP - 1) begin
      hs_reg <= 1'b1;
    end else if(h_cnt == H_FP + H_SYNC - 1) begin
      hs_reg <= 1'b0;
    end else begin
      hs_reg <= hs_reg;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      h_active <= 1'b0;
    end else if(h_cnt == H_FP + H_SYNC + H_BP - 1) begin
      h_active <= 1'b1;
    end else if(h_cnt == H_TOTAL - 1) begin
      h_active <= 1'b0;
    end else begin
      h_active <= h_active;
    end 
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      vs_reg <= 1'd0;
    end else if((v_cnt == V_FP - 1) && (h_cnt == H_FP - 1)) begin
      vs_reg <= 1'b1;
    end else if((v_cnt == V_FP + V_SYNC - 1) && (h_cnt == H_FP - 1)) begin
      vs_reg <= 1'b0;  
    end else begin
      vs_reg <= vs_reg;
    end
  end
  
  always@(posedge clk or posedge rst)
  begin
    if(rst) begin
      v_active <= 1'd0;
    end else if((v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1)) begin
      v_active <= 1'b1;
    end else if((v_cnt == V_TOTAL - 1) && (h_cnt == H_FP - 1)) begin
      v_active <= 1'b0;  
    end else begin
      v_active <= v_active;
    end 
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      rgb_r_reg <= 8'h00;
      rgb_g_reg <= 8'h00;
      rgb_b_reg <= 8'h00;
    end else begin

      `ifdef YELLOW_CROSS
      if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= YELLOW_R;
        rgb_g_reg <= YELLOW_G;
        rgb_b_reg <= YELLOW_B;
      end else `elsif WHITE_CROSS if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= WHITE_R;
        rgb_g_reg <= WHITE_G;
        rgb_b_reg <= WHITE_B;
      end else `elsif RED_CROSS if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= RED_R;
        rgb_g_reg <= RED_G;
        rgb_b_reg <= RED_B;
      end else `elsif BLUE_CROSS if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= BLUE_R;
        rgb_g_reg <= BLUE_G;
        rgb_b_reg <= BLUE_B;
      end else `elsif GREEN_CROSS if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= GREEN_R;
        rgb_g_reg <= GREEN_G;
        rgb_b_reg <= GREEN_B;
      end else `endif if(bar_cnt == 12'd0) begin
        rgb_r_reg <= WHITE_R;
        rgb_g_reg <= WHITE_G;
        rgb_b_reg <= WHITE_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 1) begin
        rgb_r_reg <= YELLOW_R;
        rgb_g_reg <= YELLOW_G;
        rgb_b_reg <= YELLOW_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 2) begin
        rgb_r_reg <= CYAN_R;
        rgb_g_reg <= CYAN_G;
        rgb_b_reg <= CYAN_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 3) begin
        rgb_r_reg <= GREEN_R;
        rgb_g_reg <= GREEN_G;
        rgb_b_reg <= GREEN_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 4) begin
        rgb_r_reg <= MAGENTA_R;
        rgb_g_reg <= MAGENTA_G;
        rgb_b_reg <= MAGENTA_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 5) begin
        rgb_r_reg <= RED_R;
        rgb_g_reg <= RED_G;
        rgb_b_reg <= RED_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 6) begin
        rgb_r_reg <= BLUE_R;
        rgb_g_reg <= BLUE_G;
        rgb_b_reg <= BLUE_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 7) begin
        rgb_r_reg <= BLACK_R;
        rgb_g_reg <= BLACK_G;
        rgb_b_reg <= BLACK_B;
      end 
    end
  end

  assign Y_i  = 16'd16  + (((rgb_r_reg<<6)+(rgb_r_reg<<1)+(rgb_g_reg<<7)+rgb_g_reg+(rgb_b_reg<<4)+(rgb_b_reg<<3)+rgb_b_reg)>>8);
  assign Cb_i = 16'd128 + ((-((rgb_r_reg<<5)+(rgb_r_reg<<2)+(rgb_r_reg<<1))-((rgb_g_reg<<6)+(rgb_g_reg<<3)+(rgb_g_reg<<1))+(rgb_b_reg<<7)-(rgb_b_reg<<4))>>8);
  assign Cr_i = 16'd128 + (((rgb_r_reg<<7)-(rgb_r_reg<<4)-((rgb_g_reg<<6)+(rgb_g_reg<<5)-(rgb_g_reg<<1))-((rgb_b_reg<<4)+(rgb_b_reg<<1)))>>8);
   
  `ifdef GAO_BAR_PATTERN

    
    assign rom_addr = active_x < 1280 ? active_x[10:0] : 11'b0;
    rom_8x1280 i_rom_8x1280 (
        .dout    (rom_dout ),
        .clk     (clk      ),
        .oce     (1'b1     ),
        .ce      (1'b1     ),
        .reset   (rst      ),
        .ad      (rom_addr )
    );
    always@(posedge clk or posedge rst) begin
      if(rst) begin
        rom_dout_d1 <= 8'd0;
      end else begin
        rom_dout_d1 <= rom_dout;
      end
    end
    
    assign eol = !video_active && video_active_d0;
    
    always@(posedge clk or posedge rst) begin
      if(rst) begin
        line_cntr <= 8'd1;
      end else if(v_active) begin
        if(line_cntr == 201) begin
          line_cntr <= 8'd1;
        end else if(eol) begin
          line_cntr <= line_cntr + 8'd1;
        end
      end else begin
        line_cntr <= 8'd1;
      end
    end
    
    assign data = rom_addr == 11'd1 ? line_cntr : rom_dout_d1;
  `else
    assign data = data_cntr_d1 == 2'b01 ? Cb_i :
                  data_cntr_d1 == 2'b11 ? Cr_i :
                                          Y_i;  
  `endif
  
endmodule
module color_bar (
  clk,
  rst,
  en_cam,
  hs,
  vs,
  de,
  data
);

  input  wire                       clk;
  input  wire                       rst;
  input  wire                       en_cam;
  output wire                       hs;
  output wire                       vs;
  output wire                       de;
  output wire [7:0]                 data;
  



















  parameter H_ACTIVE              = 16'd1280;
  parameter H_FP                  = 16'd66;
  parameter H_SYNC                = 16'd50;
  parameter H_BP                  = 16'd132; 
  parameter V_ACTIVE              = 16'd400;
  parameter V_FP                  = 16'd89;
  parameter V_SYNC                = 16'd322;
  parameter V_BP                  = 16'd89;
  
  parameter H_TOTAL               = H_ACTIVE + H_FP + H_SYNC + H_BP;
  parameter V_TOTAL               = V_ACTIVE + V_FP + V_SYNC + V_BP;

  parameter WHITE_R               = 8'hff;
  parameter WHITE_G               = 8'hff;
  parameter WHITE_B               = 8'hff;
  parameter YELLOW_R              = 8'hff;
  parameter YELLOW_G              = 8'hff;
  parameter YELLOW_B              = 8'h00;                                
  parameter CYAN_R                = 8'h00;
  parameter CYAN_G                = 8'hff;
  parameter CYAN_B                = 8'hff;                               
  parameter GREEN_R               = 8'h00;
  parameter GREEN_G               = 8'hff;
  parameter GREEN_B               = 8'h00;
  parameter MAGENTA_R             = 8'hff;
  parameter MAGENTA_G             = 8'h00;
  parameter MAGENTA_B             = 8'hff;
  parameter RED_R                 = 8'hff;
  parameter RED_G                 = 8'h00;
  parameter RED_B                 = 8'h00;
  parameter BLUE_R                = 8'h00;
  parameter BLUE_G                = 8'h00;
  parameter BLUE_B                = 8'hff;
  parameter BLACK_R               = 8'h00;
  parameter BLACK_G               = 8'h00;
  parameter BLACK_B               = 8'h00;

  reg                               hs_reg;
  reg                               vs_reg;
  reg                               hs_reg_d0;

  reg                               vs_reg_d0;
  reg  [11:0]                       h_cnt;
  reg  [11:0]                       v_cnt;
  reg  [11:0]                       active_x;
  reg  [11:0]                       active_y;
  reg  [7:0]                        rgb_r_reg;
  reg  [7:0]                        rgb_g_reg;
  reg  [7:0]                        rgb_b_reg;
  reg  [1:0]                        data_cntr;
  reg  [1:0]                        data_cntr_d1;
  reg                               h_active;
  reg                               v_active;
  wire                              video_active;
  reg                               video_active_d0;
  reg                               en_cam_d1;
  reg                               en_cam_sync;
  
  wire [15:0]                       Y_i;
  wire [15:0]                       Cb_i;
  wire [15:0]                       Cr_i;
  
  wire [10:0]                       rom_addr;
  wire [7:0]                        rom_dout;
  reg  [7:0]                        line_cntr;
  reg  [7:0]                        rom_dout_d1;
  wire                              eol;
  
  assign hs = hs_reg_d0;
  assign vs = vs_reg_d0;

  assign video_active = h_active & v_active;
  assign de = video_active_d0;



  always@(posedge clk) begin
    en_cam_d1   <= en_cam;
    en_cam_sync <= en_cam_d1;
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      hs_reg_d0 <= 1'b0;
      vs_reg_d0 <= 1'b0;
      video_active_d0 <= 1'b0;
    end else begin
      hs_reg_d0 <= hs_reg;
      vs_reg_d0 <= vs_reg;
      video_active_d0 <= video_active;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      data_cntr <= 2'b0;
    end else if(video_active) begin
      data_cntr <= data_cntr + 1;
    end else begin
      data_cntr <= 2'b0;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      data_cntr_d1 <= 2'b0;
    end else begin
      data_cntr_d1 <= data_cntr;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      h_cnt <= 12'd0;
    end else if (en_cam_sync) begin
      if(h_cnt == H_TOTAL - 1) begin
        h_cnt <= 12'd0;
      end else begin
        h_cnt <= h_cnt + 12'd1;
      end
    end else begin
      h_cnt <= 12'd0;
    end
  end
  
  `ifdef BAR_PATTERN
    reg[11:0] bar_cnt;
    always@(posedge clk or posedge rst) begin
      if(rst) begin
        bar_cnt <= 12'd0;
      end else if (video_active) begin
        bar_cnt <= bar_cnt + 12'd1;
      end else begin
        bar_cnt <= 12'd0;
      end
    end
  `else
    wire [11:0] bar_cnt;
    `ifdef WHITE_OLED
      assign bar_cnt = 12'd0;
    `elsif BLACK_OLED
      assign bar_cnt = (H_ACTIVE/8) * 7;
    `elsif BLUE_OLED
      assign bar_cnt = (H_ACTIVE/8) * 6;
    `else
      assign bar_cnt = 12'd0;
    `endif
  `endif
  











  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      active_x <= 12'd0;
    end else if(h_cnt >= H_FP + H_SYNC + H_BP - 1) begin
      active_x <= h_cnt - (H_FP[11:0] + H_SYNC[11:0] + H_BP[11:0] - 12'd1);
    end else begin
      active_x <= active_x;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      v_cnt <= 12'd0;
    end else if(h_cnt == H_FP  - 1) begin
      if(v_cnt == V_TOTAL - 1) begin
        v_cnt <= 12'd0;
      end else begin
        v_cnt <= v_cnt + 12'd1;
      end
    end else begin
      v_cnt <= v_cnt;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      hs_reg <= 1'b0;
    end else if(h_cnt == H_FP - 1) begin
      hs_reg <= 1'b1;
    end else if(h_cnt == H_FP + H_SYNC - 1) begin
      hs_reg <= 1'b0;
    end else begin
      hs_reg <= hs_reg;
    end
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      h_active <= 1'b0;
    end else if(h_cnt == H_FP + H_SYNC + H_BP - 1) begin
      h_active <= 1'b1;
    end else if(h_cnt == H_TOTAL - 1) begin
      h_active <= 1'b0;
    end else begin
      h_active <= h_active;
    end 
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      vs_reg <= 1'd0;
    end else if((v_cnt == V_FP - 1) && (h_cnt == H_FP - 1)) begin
      vs_reg <= 1'b1;
    end else if((v_cnt == V_FP + V_SYNC - 1) && (h_cnt == H_FP - 1)) begin
      vs_reg <= 1'b0;  
    end else begin
      vs_reg <= vs_reg;
    end
  end
  
  always@(posedge clk or posedge rst)
  begin
    if(rst) begin
      v_active <= 1'd0;
    end else if((v_cnt == V_FP + V_SYNC + V_BP - 1) && (h_cnt == H_FP - 1)) begin
      v_active <= 1'b1;
    end else if((v_cnt == V_TOTAL - 1) && (h_cnt == H_FP - 1)) begin
      v_active <= 1'b0;  
    end else begin
      v_active <= v_active;
    end 
  end
  
  always@(posedge clk or posedge rst) begin
    if(rst) begin
      rgb_r_reg <= 8'h00;
      rgb_g_reg <= 8'h00;
      rgb_b_reg <= 8'h00;
    end else begin

      `ifdef YELLOW_CROSS
      if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= YELLOW_R;
        rgb_g_reg <= YELLOW_G;
        rgb_b_reg <= YELLOW_B;
      end else `elsif WHITE_CROSS if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= WHITE_R;
        rgb_g_reg <= WHITE_G;
        rgb_b_reg <= WHITE_B;
      end else `elsif RED_CROSS if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= RED_R;
        rgb_g_reg <= RED_G;
        rgb_b_reg <= RED_B;
      end else `elsif BLUE_CROSS if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= BLUE_R;
        rgb_g_reg <= BLUE_G;
        rgb_b_reg <= BLUE_B;
      end else `elsif GREEN_CROSS if(v_cnt == `CROSS_LINE_NUM || (h_cnt >= `CROSS_PIX_START && h_cnt <= `CROSS_PIX_END)) begin
        rgb_r_reg <= GREEN_R;
        rgb_g_reg <= GREEN_G;
        rgb_b_reg <= GREEN_B;
      end else `endif if(bar_cnt == 12'd0) begin
        rgb_r_reg <= WHITE_R;
        rgb_g_reg <= WHITE_G;
        rgb_b_reg <= WHITE_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 1) begin
        rgb_r_reg <= YELLOW_R;
        rgb_g_reg <= YELLOW_G;
        rgb_b_reg <= YELLOW_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 2) begin
        rgb_r_reg <= CYAN_R;
        rgb_g_reg <= CYAN_G;
        rgb_b_reg <= CYAN_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 3) begin
        rgb_r_reg <= GREEN_R;
        rgb_g_reg <= GREEN_G;
        rgb_b_reg <= GREEN_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 4) begin
        rgb_r_reg <= MAGENTA_R;
        rgb_g_reg <= MAGENTA_G;
        rgb_b_reg <= MAGENTA_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 5) begin
        rgb_r_reg <= RED_R;
        rgb_g_reg <= RED_G;
        rgb_b_reg <= RED_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 6) begin
        rgb_r_reg <= BLUE_R;
        rgb_g_reg <= BLUE_G;
        rgb_b_reg <= BLUE_B;
      end else if(bar_cnt == (H_ACTIVE/8) * 7) begin
        rgb_r_reg <= BLACK_R;
        rgb_g_reg <= BLACK_G;
        rgb_b_reg <= BLACK_B;
      end 
    end
  end

  assign Y_i  = 16'd16  + (((rgb_r_reg<<6)+(rgb_r_reg<<1)+(rgb_g_reg<<7)+rgb_g_reg+(rgb_b_reg<<4)+(rgb_b_reg<<3)+rgb_b_reg)>>8);
  assign Cb_i = 16'd128 + ((-((rgb_r_reg<<5)+(rgb_r_reg<<2)+(rgb_r_reg<<1))-((rgb_g_reg<<6)+(rgb_g_reg<<3)+(rgb_g_reg<<1))+(rgb_b_reg<<7)-(rgb_b_reg<<4))>>8);
  assign Cr_i = 16'd128 + (((rgb_r_reg<<7)-(rgb_r_reg<<4)-((rgb_g_reg<<6)+(rgb_g_reg<<5)-(rgb_g_reg<<1))-((rgb_b_reg<<4)+(rgb_b_reg<<1)))>>8);
   
  `ifdef GAO_BAR_PATTERN

    
    assign rom_addr = active_x < 1280 ? active_x[10:0] : 11'b0;
    rom_8x1280 i_rom_8x1280 (
        .dout    (rom_dout ),
        .clk     (clk      ),
        .oce     (1'b1     ),
        .ce      (1'b1     ),
        .reset   (rst      ),
        .ad      (rom_addr )
    );
    always@(posedge clk or posedge rst) begin
      if(rst) begin
        rom_dout_d1 <= 8'd0;
      end else begin
        rom_dout_d1 <= rom_dout;
      end
    end
    
    assign eol = !video_active && video_active_d0;
    
    always@(posedge clk or posedge rst) begin
      if(rst) begin
        line_cntr <= 8'd1;
      end else if(v_active) begin
        if(line_cntr == 201) begin
          line_cntr <= 8'd1;
        end else if(eol) begin
          line_cntr <= line_cntr + 8'd1;
        end
      end else begin
        line_cntr <= 8'd1;
      end
    end
    
    assign data = rom_addr == 11'd1 ? line_cntr : rom_dout_d1;
  `else
    assign data = data_cntr_d1 == 2'b01 ? Cb_i :
                  data_cntr_d1 == 2'b11 ? Cr_i :
                                          Y_i;  
  `endif
  
endmodule