data/full_repos/permissive/152986713/ice40/ball_paddle.v
 line:236: before: "]"
1: b'%Error: data/full_repos/permissive/152986713/ice40/ball_paddle.v:2: Cannot find include file: hvsync_generator.v\n`include "hvsync_generator.v" \n         ^~~~~~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/152986713/ice40,data/full_repos/permissive/152986713/hvsync_generator.v\n             data/full_repos/permissive/152986713/ice40,data/full_repos/permissive/152986713/hvsync_generator.v.v\n             data/full_repos/permissive/152986713/ice40,data/full_repos/permissive/152986713/hvsync_generator.v.sv\n             hvsync_generator.v\n             hvsync_generator.v.v\n             hvsync_generator.v.sv\n             obj_dir/hvsync_generator.v\n             obj_dir/hvsync_generator.v.v\n             obj_dir/hvsync_generator.v.sv\n%Error: data/full_repos/permissive/152986713/ice40/ball_paddle.v:3: Cannot find include file: digits10.v\n`include "digits10.v" \n         ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/152986713/ice40/ball_paddle.v:4: Cannot find include file: scoreboard.v\n`include "scoreboard.v" \n         ^~~~~~~~~~~~~~\n%Error: Exiting due to 3 error(s)\n'
module ball_paddle_top(clk, reset, hpaddle, out);

  input clk;
  input reset;
  input hpaddle;
  wire hsync, vsync;
  output [1:0] out;
  
  wire display_on;
  wire [8:0] hpos;
  wire [8:0] vpos;
  
  reg [8:0] paddle_pos;
  
  reg [8:0] ball_x;
  reg [8:0] ball_y;
  reg ball_dir_x;
  reg ball_speed_x;
  reg ball_dir_y;
  
  reg brick_array [0:BRICKS_H*BRICKS_V-1];

  wire [3:0] score0;
  wire [3:0] score1;
  wire [3:0] lives;
  reg incscore;
  reg declives = 0;
  
  localparam BRICKS_H = 16;
  localparam BRICKS_V = 8;

  localparam BALL_DIR_LEFT = 0;
  localparam BALL_DIR_RIGHT = 1;
  localparam BALL_DIR_DOWN = 1;
  localparam BALL_DIR_UP = 0;
  
  localparam PADDLE_WIDTH = 31;
  localparam BALL_SIZE = 6;

  reg clk2;
  always @(posedge clk) begin
    clk2 <= !clk2;
  end

  hvsync_generator #(256,60,40,25) hvsync_gen(
    .clk(clk2),
    .reset(reset),
    .hsync(hsync),
    .vsync(vsync),
    .display_on(display_on),
    .hpos(hpos),
    .vpos(vpos)
  );
  

  wire score_gfx;
  player_stats stats(
    .reset(reset),
    .score0(score0),
    .score1(score1),
    .incscore(incscore),
    .lives(lives),
    .declives(declives)
  );

  scoreboard_generator score_gen(
    .score0(score0),
    .score1(score1),
    .lives(lives),
    .vpos(vpos),
    .hpos(hpos), 
    .board_gfx(score_gfx)
  );

  wire [5:0] hcell = hpos[8:3];
  wire [5:0] vcell = vpos[8:3];
  wire lr_border = hcell==0 || hcell==31;


  wire [8:0] paddle_rel_x = ((hpos-paddle_pos) & 9'h1ff);


  wire paddle_gfx = (vcell == 28) && (paddle_rel_x < PADDLE_WIDTH);


  wire [8:0] ball_rel_x = (hpos - ball_x);
  wire [8:0] ball_rel_y = (vpos - ball_y);


  wire ball_gfx = ball_rel_x < BALL_SIZE
  	       && ball_rel_y < BALL_SIZE;

  reg main_gfx;
  reg brick_present;
  reg [6:0] brick_index;

  wire brick_gfx = lr_border || (brick_present && vpos[2:0] != 0 && hpos[3:1] != 4);
  

  always @(posedge clk2)

    if (vpos[8:6] == 1 && !lr_border)
    begin

      if (hpos[3:0] == 8) begin

        brick_index <= {vpos[5:3], hpos[7:4]};
      end

      else if (hpos[3:0] == 9) begin

        brick_present <= !brick_array[brick_index];
      end
    end else begin
      brick_present <= 0;
    end
  


  always @(posedge hsync)
    if (!hpaddle)
      paddle_pos <= vpos;


  wire ball_pixel_collide = main_gfx & ball_gfx;
  
  reg ball_collide_paddle = 0;
  reg [3:0] ball_collide_bits = 0;


  always @(posedge clk2)

    if (vsync) begin
      ball_collide_bits <= 0; 
      ball_collide_paddle <= 0;
    end else begin
      if (ball_pixel_collide) begin

        if (paddle_gfx) begin
          ball_collide_paddle <= 1;
        end

        if (!ball_rel_x[2] & !ball_rel_y[2]) ball_collide_bits[0] <= 1;
        if (ball_rel_x[2] & !ball_rel_y[2]) ball_collide_bits[1] <= 1;
        if (!ball_rel_x[2] & ball_rel_y[2]) ball_collide_bits[2] <= 1;
        if (ball_rel_x[2] & ball_rel_y[2]) ball_collide_bits[3] <= 1;
      end
    end


  always @(posedge clk2)
    if (ball_pixel_collide && brick_present) begin
      brick_array[brick_index] <= 1;
      incscore <= 1;
    end else begin
      incscore <= 0;
    end


  wire signed [8:0] ball_paddle_dx = ball_x - paddle_pos + 8;


  always @(posedge vsync or posedge reset)
    begin
      if (reset) begin
        ball_dir_y <= BALL_DIR_DOWN;
      end else

      if (ball_collide_paddle) begin 

        ball_dir_y <= BALL_DIR_UP;

        ball_dir_x <= (ball_paddle_dx < 20) ? BALL_DIR_LEFT : BALL_DIR_RIGHT;

        ball_speed_x <= ball_collide_bits[3:0] != 4'b1100;
      end else begin



        casez (ball_collide_bits[3:0])
          4'b01?1: ball_dir_x <= BALL_DIR_RIGHT;
          4'b1101: ball_dir_x <= BALL_DIR_RIGHT;
          4'b101?: ball_dir_x <= BALL_DIR_LEFT;
          4'b1110: ball_dir_x <= BALL_DIR_LEFT;
          default: ;
        endcase

        casez (ball_collide_bits[3:0])
          4'b1011: ball_dir_y <= BALL_DIR_DOWN;
          4'b0111: ball_dir_y <= BALL_DIR_DOWN;
          4'b001?: ball_dir_y <= BALL_DIR_DOWN;
          4'b0001: ball_dir_y <= BALL_DIR_DOWN;
          4'b0100: ball_dir_y <= BALL_DIR_UP;
          4'b1?00: ball_dir_y <= BALL_DIR_UP;
          4'b1101: ball_dir_y <= BALL_DIR_UP;
          4'b1110: ball_dir_y <= BALL_DIR_UP;
          default: ;
        endcase
      end
    end
  

  always @(negedge vsync or posedge reset)
    begin
      if (reset) begin

        ball_x <= 128;
        ball_y <= 180;
      end else begin

        if (ball_dir_x == BALL_DIR_RIGHT)
          ball_x <= ball_x + (ball_speed_x?1:0) + 1;
        else
          ball_x <= ball_x - (ball_speed_x?1:0) - 1;
        ball_y <= ball_y + (ball_dir_y==BALL_DIR_DOWN?1:-1);
      end
    end
  

  always @(*)
    begin
      case (vpos[8:3])
        0,1,2: main_gfx = score_gfx;
        3: main_gfx = 0;
        4: main_gfx = 1;
        8,9,10,11,12,13,14,15: main_gfx = brick_gfx;
        28: main_gfx = paddle_gfx | lr_border;
        29: main_gfx = hpos[0] ^ vpos[0];
        default: main_gfx = lr_border;
      endcase
    end


  wire r = display_on && (ball_gfx | paddle_gfx);
  wire g = display_on && (main_gfx | ball_gfx);
  wire b = display_on && (ball_gfx | brick_present);

  assign out = (hsync||vsync) ? 0 : (1+g+(r|b));

endmodule
module ball_paddle_top(clk, reset, hpaddle, out);


  input clk;
  input reset;
  input hpaddle;
  wire hsync, vsync;
  output [1:0] out;
  
  wire display_on;
  wire [8:0] hpos;
  wire [8:0] vpos;
  
  reg [8:0] paddle_pos;
  
  reg [8:0] ball_x;
  reg [8:0] ball_y;
  reg ball_dir_x;
  reg ball_speed_x;
  reg ball_dir_y;
  
  reg brick_array [0:BRICKS_H*BRICKS_V-1];

  wire [3:0] score0;
  wire [3:0] score1;
  wire [3:0] lives;
  reg incscore;
  reg declives = 0;
  
  localparam BRICKS_H = 16;
  localparam BRICKS_V = 8;

  localparam BALL_DIR_LEFT = 0;
  localparam BALL_DIR_RIGHT = 1;
  localparam BALL_DIR_DOWN = 1;
  localparam BALL_DIR_UP = 0;
  
  localparam PADDLE_WIDTH = 31;
  localparam BALL_SIZE = 6;

  reg clk2;
  always @(posedge clk) begin
    clk2 <= !clk2;
  end

  hvsync_generator #(256,60,40,25) hvsync_gen(
    .clk(clk2),
    .reset(reset),
    .hsync(hsync),
    .vsync(vsync),
    .display_on(display_on),
    .hpos(hpos),
    .vpos(vpos)
  );
  

  wire score_gfx;
  player_stats stats(
    .reset(reset),
    .score0(score0),
    .score1(score1),
    .incscore(incscore),
    .lives(lives),
    .declives(declives)
  );

  scoreboard_generator score_gen(
    .score0(score0),
    .score1(score1),
    .lives(lives),
    .vpos(vpos),
    .hpos(hpos), 
    .board_gfx(score_gfx)
  );

  wire [5:0] hcell = hpos[8:3];
  wire [5:0] vcell = vpos[8:3];
  wire lr_border = hcell==0 || hcell==31;


  wire [8:0] paddle_rel_x = ((hpos-paddle_pos) & 9'h1ff);


  wire paddle_gfx = (vcell == 28) && (paddle_rel_x < PADDLE_WIDTH);


  wire [8:0] ball_rel_x = (hpos - ball_x);
  wire [8:0] ball_rel_y = (vpos - ball_y);


  wire ball_gfx = ball_rel_x < BALL_SIZE
  	       && ball_rel_y < BALL_SIZE;

  reg main_gfx;
  reg brick_present;
  reg [6:0] brick_index;

  wire brick_gfx = lr_border || (brick_present && vpos[2:0] != 0 && hpos[3:1] != 4);
  

  always @(posedge clk2)

    if (vpos[8:6] == 1 && !lr_border)
    begin

      if (hpos[3:0] == 8) begin

        brick_index <= {vpos[5:3], hpos[7:4]};
      end

      else if (hpos[3:0] == 9) begin

        brick_present <= !brick_array[brick_index];
      end
    end else begin
      brick_present <= 0;
    end
  


  always @(posedge hsync)
    if (!hpaddle)
      paddle_pos <= vpos;


  wire ball_pixel_collide = main_gfx & ball_gfx;
  
  reg ball_collide_paddle = 0;
  reg [3:0] ball_collide_bits = 0;


  always @(posedge clk2)

    if (vsync) begin
      ball_collide_bits <= 0; 
      ball_collide_paddle <= 0;
    end else begin
      if (ball_pixel_collide) begin

        if (paddle_gfx) begin
          ball_collide_paddle <= 1;
        end

        if (!ball_rel_x[2] & !ball_rel_y[2]) ball_collide_bits[0] <= 1;
        if (ball_rel_x[2] & !ball_rel_y[2]) ball_collide_bits[1] <= 1;
        if (!ball_rel_x[2] & ball_rel_y[2]) ball_collide_bits[2] <= 1;
        if (ball_rel_x[2] & ball_rel_y[2]) ball_collide_bits[3] <= 1;
      end
    end


  always @(posedge clk2)
    if (ball_pixel_collide && brick_present) begin
      brick_array[brick_index] <= 1;
      incscore <= 1;
    end else begin
      incscore <= 0;
    end


  wire signed [8:0] ball_paddle_dx = ball_x - paddle_pos + 8;


  always @(posedge vsync or posedge reset)
    begin
      if (reset) begin
        ball_dir_y <= BALL_DIR_DOWN;
      end else

      if (ball_collide_paddle) begin 

        ball_dir_y <= BALL_DIR_UP;

        ball_dir_x <= (ball_paddle_dx < 20) ? BALL_DIR_LEFT : BALL_DIR_RIGHT;

        ball_speed_x <= ball_collide_bits[3:0] != 4'b1100;
      end else begin



        casez (ball_collide_bits[3:0])
          4'b01?1: ball_dir_x <= BALL_DIR_RIGHT;
          4'b1101: ball_dir_x <= BALL_DIR_RIGHT;
          4'b101?: ball_dir_x <= BALL_DIR_LEFT;
          4'b1110: ball_dir_x <= BALL_DIR_LEFT;
          default: ;
        endcase

        casez (ball_collide_bits[3:0])
          4'b1011: ball_dir_y <= BALL_DIR_DOWN;
          4'b0111: ball_dir_y <= BALL_DIR_DOWN;
          4'b001?: ball_dir_y <= BALL_DIR_DOWN;
          4'b0001: ball_dir_y <= BALL_DIR_DOWN;
          4'b0100: ball_dir_y <= BALL_DIR_UP;
          4'b1?00: ball_dir_y <= BALL_DIR_UP;
          4'b1101: ball_dir_y <= BALL_DIR_UP;
          4'b1110: ball_dir_y <= BALL_DIR_UP;
          default: ;
        endcase
      end
    end
  

  always @(negedge vsync or posedge reset)
    begin
      if (reset) begin

        ball_x <= 128;
        ball_y <= 180;
      end else begin

        if (ball_dir_x == BALL_DIR_RIGHT)
          ball_x <= ball_x + (ball_speed_x?1:0) + 1;
        else
          ball_x <= ball_x - (ball_speed_x?1:0) - 1;
        ball_y <= ball_y + (ball_dir_y==BALL_DIR_DOWN?1:-1);
      end
    end
  

  always @(*)
    begin
      case (vpos[8:3])
        0,1,2: main_gfx = score_gfx;
        3: main_gfx = 0;
        4: main_gfx = 1;
        8,9,10,11,12,13,14,15: main_gfx = brick_gfx;
        28: main_gfx = paddle_gfx | lr_border;
        29: main_gfx = hpos[0] ^ vpos[0];
        default: main_gfx = lr_border;
      endcase
    end


  wire r = display_on && (ball_gfx | paddle_gfx);
  wire g = display_on && (main_gfx | ball_gfx);
  wire b = display_on && (ball_gfx | brick_present);

  assign out = (hsync||vsync) ? 0 : (1+g+(r|b));

endmodule