data/full_repos/permissive/152986713/ice40/racing_game.v
1: b'%Error: data/full_repos/permissive/152986713/ice40/racing_game.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/racing_game.v:3: Cannot find include file: sprite_bitmap.v\n`include "sprite_bitmap.v" \n         ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/152986713/ice40/racing_game.v:4: Cannot find include file: sprite_renderer.v\n`include "sprite_renderer.v" \n         ^~~~~~~~~~~~~~~~~~~\n%Error: Exiting due to 3 error(s)\n'
module racing_game_top(clk, reset, out, hpaddle, vpaddle);

  input clk, reset;
  input hpaddle, vpaddle;
  output [1:0] out;
  wire hsync, vsync;
  wire display_on;
  wire [8:0] hpos;
  wire [8:0] vpos;


  reg [7:0] player_x;
  reg [7:0] player_y;  

  reg [7:0] paddle_x;
  reg [7:0] paddle_y;

  reg [7:0] enemy_x = 128;
  reg [7:0] enemy_y = 128;

  reg enemy_dir = 0;	
  
  reg [15:0] track_pos = 0;
  reg [7:0] speed = 31;
  
  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)
  );
  

  always @(posedge hsync)
    begin
      if (!hpaddle) paddle_x <= vpos[7:0];
      if (!vpaddle) paddle_y <= vpos[7:0];
    end

  

  wire player_load = (hpos >= 256) && (hpos < 260);
  wire enemy_load = (hpos >= 260);


  wire [3:0] player_sprite_yofs;
  wire [3:0] enemy_sprite_yofs;
  wire [3:0] car_sprite_yofs = player_load ? player_sprite_yofs : enemy_sprite_yofs;  
  wire [7:0] car_sprite_bits;  
  car_bitmap car(
    .yofs(car_sprite_yofs), 
    .bits(car_sprite_bits));
  

  wire player_vstart = {1'b0,player_y} == vpos;
  wire player_hstart = {1'b0,player_x} == hpos;
  wire player_gfx;
  wire player_is_drawing;


  wire enemy_vstart = {1'b0,enemy_y} == vpos;
  wire enemy_hstart = {1'b0,enemy_x} == hpos;
  wire enemy_gfx;
  wire enemy_is_drawing;
  

  sprite_renderer player_renderer(
    .clk(clk2),
    .reset(reset),
    .vstart(player_vstart),
    .load(player_load),
    .hstart(player_hstart),
    .rom_addr(player_sprite_yofs),
    .rom_bits(car_sprite_bits),
    .gfx(player_gfx),
    .in_progress(player_is_drawing));


  sprite_renderer enemy_renderer(
    .clk(clk2),
    .reset(reset),
    .vstart(enemy_vstart),
    .load(enemy_load),
    .hstart(enemy_hstart),
    .rom_addr(enemy_sprite_yofs),
    .rom_bits(car_sprite_bits),
    .gfx(enemy_gfx),
    .in_progress(enemy_is_drawing));


  wire enemy_hit_left = (enemy_x == 64);
  wire enemy_hit_right = (enemy_x == 192);
  wire enemy_hit_edge = enemy_hit_left || enemy_hit_right;
  


  always @(posedge vsync)
    begin
      player_x <= 64;
      player_y <= 180;
      track_pos <= track_pos + {11'b0,speed[7:4]};
      enemy_y <= enemy_y + {3'b0, speed[7:4]};
      if (enemy_hit_edge)
        enemy_dir <= !enemy_dir;
      if (enemy_dir ^ enemy_hit_edge)
        enemy_x <= enemy_x + 1;
      else
        enemy_x <= enemy_x - 1;

      if (frame_collision)
        speed <= 16;
      else if (speed < ~paddle_y)
        speed <= speed + 1;
      else if (speed > 16)
        speed <= speed - 1;
    end
  

  reg frame_collision;
  
  always @(posedge clk2)
    if (player_gfx && (enemy_gfx || track_gfx))
      frame_collision <= 1;
    else if (vsync)
      frame_collision <= 0;
  

  wire track_offside = (hpos[7:5]==0) || (hpos[7:5]==7);
  wire track_shoulder = (hpos[7:3]==3) || (hpos[7:3]==28);
  wire track_gfx = (vpos[5:1]!=track_pos[5:1]) && track_offside;
  

  wire r = display_on && (enemy_gfx || track_shoulder);
  wire g = display_on && (player_gfx || track_gfx);
  wire b = display_on && (player_gfx || track_shoulder);

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

endmodule
module racing_game_top(clk, reset, out, hpaddle, vpaddle);


  input clk, reset;
  input hpaddle, vpaddle;
  output [1:0] out;
  wire hsync, vsync;
  wire display_on;
  wire [8:0] hpos;
  wire [8:0] vpos;


  reg [7:0] player_x;
  reg [7:0] player_y;  

  reg [7:0] paddle_x;
  reg [7:0] paddle_y;

  reg [7:0] enemy_x = 128;
  reg [7:0] enemy_y = 128;

  reg enemy_dir = 0;	
  
  reg [15:0] track_pos = 0;
  reg [7:0] speed = 31;
  
  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)
  );
  

  always @(posedge hsync)
    begin
      if (!hpaddle) paddle_x <= vpos[7:0];
      if (!vpaddle) paddle_y <= vpos[7:0];
    end

  

  wire player_load = (hpos >= 256) && (hpos < 260);
  wire enemy_load = (hpos >= 260);


  wire [3:0] player_sprite_yofs;
  wire [3:0] enemy_sprite_yofs;
  wire [3:0] car_sprite_yofs = player_load ? player_sprite_yofs : enemy_sprite_yofs;  
  wire [7:0] car_sprite_bits;  
  car_bitmap car(
    .yofs(car_sprite_yofs), 
    .bits(car_sprite_bits));
  

  wire player_vstart = {1'b0,player_y} == vpos;
  wire player_hstart = {1'b0,player_x} == hpos;
  wire player_gfx;
  wire player_is_drawing;


  wire enemy_vstart = {1'b0,enemy_y} == vpos;
  wire enemy_hstart = {1'b0,enemy_x} == hpos;
  wire enemy_gfx;
  wire enemy_is_drawing;
  

  sprite_renderer player_renderer(
    .clk(clk2),
    .reset(reset),
    .vstart(player_vstart),
    .load(player_load),
    .hstart(player_hstart),
    .rom_addr(player_sprite_yofs),
    .rom_bits(car_sprite_bits),
    .gfx(player_gfx),
    .in_progress(player_is_drawing));


  sprite_renderer enemy_renderer(
    .clk(clk2),
    .reset(reset),
    .vstart(enemy_vstart),
    .load(enemy_load),
    .hstart(enemy_hstart),
    .rom_addr(enemy_sprite_yofs),
    .rom_bits(car_sprite_bits),
    .gfx(enemy_gfx),
    .in_progress(enemy_is_drawing));


  wire enemy_hit_left = (enemy_x == 64);
  wire enemy_hit_right = (enemy_x == 192);
  wire enemy_hit_edge = enemy_hit_left || enemy_hit_right;
  


  always @(posedge vsync)
    begin
      player_x <= 64;
      player_y <= 180;
      track_pos <= track_pos + {11'b0,speed[7:4]};
      enemy_y <= enemy_y + {3'b0, speed[7:4]};
      if (enemy_hit_edge)
        enemy_dir <= !enemy_dir;
      if (enemy_dir ^ enemy_hit_edge)
        enemy_x <= enemy_x + 1;
      else
        enemy_x <= enemy_x - 1;

      if (frame_collision)
        speed <= 16;
      else if (speed < ~paddle_y)
        speed <= speed + 1;
      else if (speed > 16)
        speed <= speed - 1;
    end
  

  reg frame_collision;
  
  always @(posedge clk2)
    if (player_gfx && (enemy_gfx || track_gfx))
      frame_collision <= 1;
    else if (vsync)
      frame_collision <= 0;
  

  wire track_offside = (hpos[7:5]==0) || (hpos[7:5]==7);
  wire track_shoulder = (hpos[7:3]==3) || (hpos[7:3]==28);
  wire track_gfx = (vpos[5:1]!=track_pos[5:1]) && track_offside;
  

  wire r = display_on && (enemy_gfx || track_shoulder);
  wire g = display_on && (player_gfx || track_gfx);
  wire b = display_on && (player_gfx || track_shoulder);

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

endmodule