Skip to content

Commit

Permalink
fixed visual artifacts, restructured
Browse files Browse the repository at this point in the history
  • Loading branch information
azzeloof committed Dec 8, 2020
1 parent 5fbd6e2 commit 87bc178
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 22 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions foodgen.v → gateware/foodgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ module foodgen(
output food_loc
);

wire food_loc;
reg food_loc;
reg [4:0] food_h;
reg [4:0] food_v;

assign food_loc = (hpos > food_h*20) & (hpos < (food_h+1)*20) & (vpos > food_v*20) & (vpos < (food_v+1)*20);

//Pseudo-random number generators
//https://electronics.stackexchange.com/questions/30521/random-bit-sequence-using-verilog
reg [4:0] rng0 = 1;
Expand All @@ -39,6 +37,7 @@ module foodgen(
food_h <= rng0;
food_v <= rng1;
end
food_loc <= (hpos > food_h*20) & (hpos < (food_h+1)*20) & (vpos > food_v*20) & (vpos < (food_v+1)*20);
end

endmodule
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions pins.pcf → gateware/pins.pcf
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@

# Left side of board
set_io --warn-no-port --warn-no-port PIN_1 A2
set_io --warn-no-port -pullup yes PIN_2 A1
set_io --warn-no-port -pullup yes PIN_3 B1
set_io --warn-no-port PIN_2 A1
set_io --warn-no-port PIN_3 B1
set_io --warn-no-port PIN_4 C2
set_io --warn-no-port PIN_5 C1
set_io --warn-no-port -pullup yes PIN_6 D2
set_io --warn-no-port PIN_6 D2
set_io --warn-no-port PIN_7 D1
set_io --warn-no-port PIN_8 E2
set_io --warn-no-port PIN_9 E1
Expand All @@ -63,7 +63,7 @@ set_io --warn-no-port PIN_20 A8
set_io --warn-no-port PIN_21 B7
set_io --warn-no-port PIN_22 A7
set_io --warn-no-port PIN_23 B6
set_io --warn-no-port -pullup yes PIN_24 A6
set_io --warn-no-port PIN_24 A6

# SPI flash interface on bottom of board
set_io --warn-no-port SPI_SS F7
Expand Down
13 changes: 8 additions & 5 deletions snek.v → gateware/snek.v
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ module snek(

// I think we're running at 640x480
// Let's use a grid 32x24 (x20 factor)

// Connect all of the graphics wires
wire r = display_on & ((splash_r & ~gamestate) | (gamestate & ~(snek_loc)));
wire g = display_on & ((splash_g & ~gamestate) | (gamestate & ~(food_loc & ~deadsnek)));
wire b = display_on & ((splash_b & ~gamestate) | (gamestate & ~(snek_loc ^ (food_loc & ~deadsnek))));

reg r;
reg g;
reg b;

assign rgb = {r, g, b};

Expand Down Expand Up @@ -184,6 +183,10 @@ module snek(
if (food_v > 23) begin
new_food_flag <= 1;
end
r <= display_on & ((splash_r & ~gamestate) | (gamestate & ~(snek_loc)));
g <= display_on & ((splash_g & ~gamestate) | (gamestate & ~(food_loc & ~deadsnek)));
b <= display_on & ((splash_b & ~gamestate) | (gamestate & ~(snek_loc ^ (food_loc & ~deadsnek))));
end


endmodule
18 changes: 8 additions & 10 deletions snekgen.v → gateware/snekgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module snekgen(

genvar j; // index for generate-block for loops
reg [11:0] i; // index for initial/always for loops
reg [11:0] k;

reg [5:0] body_h [maxlen-1:0];
reg [5:0] body_v [maxlen-1:0];
Expand All @@ -47,17 +48,10 @@ module snekgen(
assign head_v = body_v[0];

// Each bit corresponds to one segment of the snek body
wire [maxlen-1:0] snec_locs; // Bits HIGH when hpos and vpos intersect with the segment location
//wire [maxlen-1:0] snek_locs; // Bits HIGH when hpos and vpos intersect with the segment location
reg [maxlen-1:0] snek_locs;
reg snek_loc;

generate
for (j=0; j<maxlen; j=j+1) begin
assign snec_locs[j] = (hpos > body_h[j]*20) & (hpos < (body_h[j]+1)*20) & (vpos > body_v[j]*20) & (vpos < (body_v[j]+1)*20);
end
endgenerate

wire snek_loc;
assign snek_loc = |snec_locs; // OR all of the locations togethor to be displayed

reg dead;
reg do_grow;
reg did_grow;
Expand All @@ -69,6 +63,10 @@ module snekgen(
if (did_grow) begin
do_grow <= 0;
end
for (k=0; k<maxlen; k=k+1) begin
snek_locs[k] <= (hpos > body_h[k]*20) & (hpos < (body_h[k]+1)*20) & (vpos > body_v[k]*20) & (vpos < (body_v[k]+1)*20);
end
snek_loc = |snek_locs;
end

always @(posedge frame_clk) begin
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 87bc178

Please sign in to comment.