data/full_repos/permissive/152986713/ice40/racing_game_cpu.v
1: b'%Error: data/full_repos/permissive/152986713/ice40/racing_game_cpu.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_cpu.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_cpu.v:4: Cannot find include file: sprite_renderer.v\n`include "sprite_renderer.v" \n         ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/152986713/ice40/racing_game_cpu.v:5: Cannot find include file: cpu8.v\n`include "cpu8.v" \n         ^~~~~~~~\n%Error: Exiting due to 4 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;
  
  parameter PADDLE_X = 0;
  parameter PADDLE_Y = 1;
  parameter PLAYER_X = 2;
  parameter PLAYER_Y = 3;
  parameter ENEMY_X = 4;
  parameter ENEMY_Y = 5;
  parameter ENEMY_DIR = 6;
  parameter SPEED = 7;
  parameter TRACKPOS_LO = 8;
  parameter TRACKPOS_HI = 9;

  parameter IN_HPOS = 8'h40;
  parameter IN_VPOS = 8'h41;

  parameter IN_FLAGS = 8'h42;

  reg [7:0] ram[0:15];
  reg [7:0] rom[0:127];
  
  wire [7:0] address_bus;
  reg  [7:0] to_cpu;
  wire [7:0] from_cpu;
  wire write_enable;
  
  reg clk2;
  always @(posedge clk) begin
    clk2 <= !clk2;
  end


  CPU cpu(.clk(clk2),
          .reset(reset),
          .address(address_bus),
          .data_in(to_cpu),
          .data_out(from_cpu),
          .write(write_enable));


  always @(posedge clk2)
    if (write_enable)
      ram[address_bus[5:0]] <= from_cpu;
  

  always @(*)
    casez (address_bus)

      8'b00??????: to_cpu = ram[address_bus[5:0]];

      IN_HPOS:  to_cpu = hpos[7:0];
      IN_VPOS:  to_cpu = vpos[7:0];
      IN_FLAGS: to_cpu = {2'b0, frame_collision,
                          vsync, hsync, vpaddle, hpaddle, display_on};

      8'b1???????: to_cpu = rom[address_bus[6:0]];
      default: to_cpu = 8'bxxxxxxxx;
    endcase


  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 player_vstart = {1'b0,ram[PLAYER_Y]} == vpos;
  wire player_hstart = {1'b0,ram[PLAYER_X]} == hpos;
  wire player_gfx;
  wire player_is_drawing;


  wire enemy_vstart = {1'b0,ram[ENEMY_Y]} == vpos;
  wire enemy_hstart = {1'b0,ram[ENEMY_X]} == hpos;
  wire enemy_gfx;
  wire enemy_is_drawing;


  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));
  

  sprite_renderer player_renderer(
    .clk(clk2),
    .reset(reset),
    .vstart(player_vstart),
    .hstart(player_hstart),
    .load(player_load),
    .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),
    .hstart(enemy_hstart),
    .load(enemy_load),
    .rom_addr(enemy_sprite_yofs),
    .rom_bits(car_sprite_bits),
    .gfx(enemy_gfx),
    .in_progress(enemy_is_drawing));


  reg frame_collision;
  always @(posedge clk2)
    if (player_gfx && (enemy_gfx || track_gfx))
      frame_collision <= 1;
    else if (vpos==0)
      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]!=ram[TRACKPOS_LO][5:1]) && track_offside;
  

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

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


  initial begin
    $readmemh("racing.hex", rom);
  end
  
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;
  
  parameter PADDLE_X = 0;
  parameter PADDLE_Y = 1;
  parameter PLAYER_X = 2;
  parameter PLAYER_Y = 3;
  parameter ENEMY_X = 4;
  parameter ENEMY_Y = 5;
  parameter ENEMY_DIR = 6;
  parameter SPEED = 7;
  parameter TRACKPOS_LO = 8;
  parameter TRACKPOS_HI = 9;

  parameter IN_HPOS = 8'h40;
  parameter IN_VPOS = 8'h41;

  parameter IN_FLAGS = 8'h42;

  reg [7:0] ram[0:15];
  reg [7:0] rom[0:127];
  
  wire [7:0] address_bus;
  reg  [7:0] to_cpu;
  wire [7:0] from_cpu;
  wire write_enable;
  
  reg clk2;
  always @(posedge clk) begin
    clk2 <= !clk2;
  end


  CPU cpu(.clk(clk2),
          .reset(reset),
          .address(address_bus),
          .data_in(to_cpu),
          .data_out(from_cpu),
          .write(write_enable));


  always @(posedge clk2)
    if (write_enable)
      ram[address_bus[5:0]] <= from_cpu;
  

  always @(*)
    casez (address_bus)

      8'b00??????: to_cpu = ram[address_bus[5:0]];

      IN_HPOS:  to_cpu = hpos[7:0];
      IN_VPOS:  to_cpu = vpos[7:0];
      IN_FLAGS: to_cpu = {2'b0, frame_collision,
                          vsync, hsync, vpaddle, hpaddle, display_on};

      8'b1???????: to_cpu = rom[address_bus[6:0]];
      default: to_cpu = 8'bxxxxxxxx;
    endcase


  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 player_vstart = {1'b0,ram[PLAYER_Y]} == vpos;
  wire player_hstart = {1'b0,ram[PLAYER_X]} == hpos;
  wire player_gfx;
  wire player_is_drawing;


  wire enemy_vstart = {1'b0,ram[ENEMY_Y]} == vpos;
  wire enemy_hstart = {1'b0,ram[ENEMY_X]} == hpos;
  wire enemy_gfx;
  wire enemy_is_drawing;


  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));
  

  sprite_renderer player_renderer(
    .clk(clk2),
    .reset(reset),
    .vstart(player_vstart),
    .hstart(player_hstart),
    .load(player_load),
    .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),
    .hstart(enemy_hstart),
    .load(enemy_load),
    .rom_addr(enemy_sprite_yofs),
    .rom_bits(car_sprite_bits),
    .gfx(enemy_gfx),
    .in_progress(enemy_is_drawing));


  reg frame_collision;
  always @(posedge clk2)
    if (player_gfx && (enemy_gfx || track_gfx))
      frame_collision <= 1;
    else if (vpos==0)
      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]!=ram[TRACKPOS_LO][5:1]) && track_offside;
  

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

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


  initial begin
    $readmemh("racing.hex", rom);
  end
  
endmodule