1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-25 03:34:05 +00:00

fixed ball_paddle.v

This commit is contained in:
Steven Hugg 2018-10-09 19:37:38 -04:00
parent 706a24c96a
commit 24d681cbb8
3 changed files with 70 additions and 66 deletions

View File

@ -63,13 +63,23 @@ module ball_paddle_top(clk, reset, hpaddle, out);
// scoreboard // scoreboard
wire score_gfx; // output from score generator wire score_gfx; // output from score generator
player_stats stats(.reset(reset), player_stats stats(
.score0(score0), .score1(score1), .incscore(incscore), .reset(reset),
.lives(lives), .declives(declives)); .score0(score0),
.score1(score1),
.incscore(incscore),
.lives(lives),
.declives(declives)
);
scoreboard_generator score_gen( scoreboard_generator score_gen(
.score0(score0), .score1(score1), .lives(lives), .score0(score0),
.vpos(vpos), .hpos(hpos), .score1(score1),
.board_gfx(score_gfx)); .lives(lives),
.vpos(vpos),
.hpos(hpos),
.board_gfx(score_gfx)
);
wire [5:0] hcell = hpos[8:3]; // horizontal brick index wire [5:0] hcell = hpos[8:3]; // horizontal brick index
wire [5:0] vcell = vpos[8:3]; // vertical brick index wire [5:0] vcell = vpos[8:3]; // vertical brick index
@ -108,7 +118,7 @@ module ball_paddle_top(clk, reset, hpaddle, out);
// every 17th pixel // every 17th pixel
else if (hpos[3:0] == 9) begin else if (hpos[3:0] == 9) begin
// load brick bit from array // load brick bit from array
brick_present <= brick_array[brick_index]; brick_present <= !brick_array[brick_index];
end end
end else begin end else begin
brick_present <= 0; brick_present <= 0;
@ -123,29 +133,33 @@ module ball_paddle_top(clk, reset, hpaddle, out);
// 1 when ball signal intersects main (brick + border) signal // 1 when ball signal intersects main (brick + border) signal
wire ball_pixel_collide = main_gfx & ball_gfx; wire ball_pixel_collide = main_gfx & ball_gfx;
/* verilator lint_off MULTIDRIVEN */
reg ball_collide_paddle = 0; reg ball_collide_paddle = 0;
reg [3:0] ball_collide_bits = 0; reg [3:0] ball_collide_bits = 0;
/* verilator lint_on MULTIDRIVEN */
// compute ball collisions with paddle and playfield // compute ball collisions with paddle and playfield
always @(posedge clk2) always @(posedge clk2)
if (ball_pixel_collide) begin // clear all collide bits for frame
// did we collide w/ paddle? if (vsync) begin
if (paddle_gfx) begin ball_collide_bits <= 0;
ball_collide_paddle <= 1; ball_collide_paddle <= 0;
end else begin
if (ball_pixel_collide) begin
// did we collide w/ paddle?
if (paddle_gfx) begin
ball_collide_paddle <= 1;
end
// ball has 4 collision quadrants
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
// ball has 4 collision quadrants
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
// compute ball collisions with brick and increment score // compute ball collisions with brick and increment score
always @(posedge clk2) always @(posedge clk2)
if (ball_pixel_collide && brick_present) begin if (ball_pixel_collide && brick_present) begin
brick_array[brick_index] <= 0; brick_array[brick_index] <= 1;
incscore <= 1; // increment score incscore <= 1; // increment score
end else begin end else begin
incscore <= 0; // reset incscore incscore <= 0; // reset incscore
@ -192,8 +206,6 @@ module ball_paddle_top(clk, reset, hpaddle, out);
default: ; default: ;
endcase endcase
end end
ball_collide_bits <= 0; // clear all collide bits for frame
ball_collide_paddle <= 0;
end end
// ball motion: update ball position // ball motion: update ball position
@ -217,19 +229,10 @@ module ball_paddle_top(clk, reset, hpaddle, out);
always @(*) always @(*)
begin begin
case (vpos[8:3]) case (vpos[8:3])
0: main_gfx = score_gfx; // scoreboard 0,1,2: main_gfx = score_gfx; // scoreboard
1: main_gfx = score_gfx;
2: main_gfx = score_gfx;
3: main_gfx = 0; 3: main_gfx = 0;
4: main_gfx = 1; // top border 4: main_gfx = 1; // top border
8: main_gfx = brick_gfx; // 1st brick row 8,9,10,11,12,13,14,15: main_gfx = brick_gfx; // brick rows 1-8
9: main_gfx = brick_gfx; // ...
10: main_gfx = brick_gfx;
11: main_gfx = brick_gfx;
12: main_gfx = brick_gfx;
13: main_gfx = brick_gfx;
14: main_gfx = brick_gfx;
15: main_gfx = brick_gfx; // 8th brick row
28: main_gfx = paddle_gfx | lr_border; // paddle 28: main_gfx = paddle_gfx | lr_border; // paddle
29: main_gfx = hpos[0] ^ vpos[0]; // bottom border 29: main_gfx = hpos[0] ^ vpos[0]; // bottom border
default: main_gfx = lr_border; // left/right borders default: main_gfx = lr_border; // left/right borders

View File

@ -4,8 +4,6 @@
#include <ctype.h> #include <ctype.h>
#include <conio.h> #include <conio.h>
#pragma static-locals(1);
int main (void) int main (void)
{ {
printf("\nHello! Press a key to reboot...\n"); printf("\nHello! Press a key to reboot...\n");

View File

@ -58,13 +58,23 @@ module ball_paddle_top(clk, reset, hpaddle, hsync, vsync, rgb);
// scoreboard // scoreboard
wire score_gfx; // output from score generator wire score_gfx; // output from score generator
player_stats stats(.reset(reset), player_stats stats(
.score0(score0), .score1(score1), .incscore(incscore), .reset(reset),
.lives(lives), .declives(declives)); .score0(score0),
.score1(score1),
.incscore(incscore),
.lives(lives),
.declives(declives)
);
scoreboard_generator score_gen( scoreboard_generator score_gen(
.score0(score0), .score1(score1), .lives(lives), .score0(score0),
.vpos(vpos), .hpos(hpos), .score1(score1),
.board_gfx(score_gfx)); .lives(lives),
.vpos(vpos),
.hpos(hpos),
.board_gfx(score_gfx)
);
wire [5:0] hcell = hpos[8:3]; // horizontal brick index wire [5:0] hcell = hpos[8:3]; // horizontal brick index
wire [5:0] vcell = vpos[8:3]; // vertical brick index wire [5:0] vcell = vpos[8:3]; // vertical brick index
@ -103,7 +113,7 @@ module ball_paddle_top(clk, reset, hpaddle, hsync, vsync, rgb);
// every 17th pixel // every 17th pixel
else if (hpos[3:0] == 9) begin else if (hpos[3:0] == 9) begin
// load brick bit from array // load brick bit from array
brick_present <= brick_array[brick_index]; brick_present <= !brick_array[brick_index];
end end
end else begin end else begin
brick_present <= 0; brick_present <= 0;
@ -118,29 +128,33 @@ module ball_paddle_top(clk, reset, hpaddle, hsync, vsync, rgb);
// 1 when ball signal intersects main (brick + border) signal // 1 when ball signal intersects main (brick + border) signal
wire ball_pixel_collide = main_gfx & ball_gfx; wire ball_pixel_collide = main_gfx & ball_gfx;
/* verilator lint_off MULTIDRIVEN */
reg ball_collide_paddle = 0; reg ball_collide_paddle = 0;
reg [3:0] ball_collide_bits = 0; reg [3:0] ball_collide_bits = 0;
/* verilator lint_on MULTIDRIVEN */
// compute ball collisions with paddle and playfield // compute ball collisions with paddle and playfield
always @(posedge clk) always @(posedge clk)
if (ball_pixel_collide) begin // clear all collide bits for frame
// did we collide w/ paddle? if (vsync) begin
if (paddle_gfx) begin ball_collide_bits <= 0;
ball_collide_paddle <= 1; ball_collide_paddle <= 0;
end else begin
if (ball_pixel_collide) begin
// did we collide w/ paddle?
if (paddle_gfx) begin
ball_collide_paddle <= 1;
end
// ball has 4 collision quadrants
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
// ball has 4 collision quadrants
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
// compute ball collisions with brick and increment score // compute ball collisions with brick and increment score
always @(posedge clk) always @(posedge clk)
if (ball_pixel_collide && brick_present) begin if (ball_pixel_collide && brick_present) begin
brick_array[brick_index] <= 0; brick_array[brick_index] <= 1;
incscore <= 1; // increment score incscore <= 1; // increment score
end else begin end else begin
incscore <= 0; // reset incscore incscore <= 0; // reset incscore
@ -187,8 +201,6 @@ module ball_paddle_top(clk, reset, hpaddle, hsync, vsync, rgb);
default: ; default: ;
endcase endcase
end end
ball_collide_bits <= 0; // clear all collide bits for frame
ball_collide_paddle <= 0;
end end
// ball motion: update ball position // ball motion: update ball position
@ -212,19 +224,10 @@ module ball_paddle_top(clk, reset, hpaddle, hsync, vsync, rgb);
always @(*) always @(*)
begin begin
case (vpos[8:3]) case (vpos[8:3])
0: main_gfx = score_gfx; // scoreboard 0,1,2: main_gfx = score_gfx; // scoreboard
1: main_gfx = score_gfx;
2: main_gfx = score_gfx;
3: main_gfx = 0; 3: main_gfx = 0;
4: main_gfx = 1; // top border 4: main_gfx = 1; // top border
8: main_gfx = brick_gfx; // 1st brick row 8,9,10,11,12,13,14,15: main_gfx = brick_gfx; // brick rows 1-8
9: main_gfx = brick_gfx; // ...
10: main_gfx = brick_gfx;
11: main_gfx = brick_gfx;
12: main_gfx = brick_gfx;
13: main_gfx = brick_gfx;
14: main_gfx = brick_gfx;
15: main_gfx = brick_gfx; // 8th brick row
28: main_gfx = paddle_gfx | lr_border; // paddle 28: main_gfx = paddle_gfx | lr_border; // paddle
29: main_gfx = hpos[0] ^ vpos[0]; // bottom border 29: main_gfx = hpos[0] ^ vpos[0]; // bottom border
default: main_gfx = lr_border; // left/right borders default: main_gfx = lr_border; // left/right borders