diff options
Diffstat (limited to 'GPU/hdl/GPU_IF.v')
-rw-r--r-- | GPU/hdl/GPU_IF.v | 139 |
1 files changed, 81 insertions, 58 deletions
diff --git a/GPU/hdl/GPU_IF.v b/GPU/hdl/GPU_IF.v index f32de1e..16c234d 100644 --- a/GPU/hdl/GPU_IF.v +++ b/GPU/hdl/GPU_IF.v @@ -27,10 +27,10 @@ module gpuv2 #( ); - reg [9:0] ball_x; - reg [8:0] ball_y; - reg [8:0] bat0_y; - reg [8:0] bat1_y; + reg [9:0] sprite_x; + reg [9:0] sprite_y; + reg [9:0] bat0_y; + reg [9:0] bat1_y; reg [15:0] sprite[0:15]; @@ -38,18 +38,24 @@ module gpuv2 #( assign reg_addr = address[6:2]; + wire [9:0] offset; + + assign offset = 10'h80; reg [2:0] sprite_red; reg [2:0] sprite_green; reg [2:0] sprite_blue; + reg blanking; + always @(posedge clk or negedge rst_n) begin if (rst_n == 0) begin - ball_x <= 10'd127; - ball_y <= 10'd127; - bat0_y <= 10'd100; - bat1_y <= 10'd200; + blanking <= 0; + sprite_x <= 10'd127+offset; + sprite_y <= 10'd127+offset; + bat0_y <= 10'd100+offset; + bat1_y <= 10'd200+offset; sprite[0]=16'b1111111111111111; sprite[1]=16'b1000000000000001; @@ -77,15 +83,17 @@ module gpuv2 #( sprite[reg_addr[3:0]]<=data[15:0]; end else begin case (reg_addr[2:0]) - 3'b000: - ball_x <= data[9:0]; - 3'b001: - ball_y <= data[8:0]; - 3'b010: - bat0_y <= data[8:0]; - 3'b011: - bat1_y <= data[8:0]; - 3'b100: + 3'd0: + blanking <= data[0]; + 3'd1: + sprite_x <= data[9:0]; + 3'd2: + sprite_y <= data[9:0]; + 3'd3: + bat0_y <= data[9:0]; + 3'd4: + bat1_y <= data[9:0]; + 3'd5: begin sprite_red <= data[8:6]; sprite_green <= data[5:3]; @@ -110,13 +118,13 @@ module gpuv2 #( always @ (posedge vga_clk or negedge rst_n) begin if(!rst_n) - vector_x <= 10'd0; + vector_x <= offset; else if(trig_25M) begin - if(vector_x != 10'd799) - vector_x <= vector_x + 1'b1; + if(vector_x != (10'd799 + offset)) + vector_x <= vector_x + 1'b1; else - vector_x <= 10'd0; + vector_x <= offset; end end @@ -124,15 +132,15 @@ module gpuv2 #( always @ (posedge vga_clk or negedge rst_n) begin if(!rst_n) - vector_y <= 10'd0; + vector_y <= offset; else if(trig_25M) begin - if(vector_x == 10'd799) + if(vector_x == (10'd799 + offset)) begin - if(vector_y != 10'd524) + if(vector_y != (10'd524 + offset)) vector_y <= vector_y + 1'b1; else - vector_y <= 10'd0; + vector_y <= offset; end end end @@ -143,7 +151,7 @@ module gpuv2 #( vga_hs <= 1'b0; else if(trig_25M) begin - if(vector_x >= 10'd656 && vector_x < 10'd752) + if(vector_x >= (10'd656 + offset) && vector_x < (10'd752+offset)) vga_hs <= 1'b0; else vga_hs <= 1'b1; @@ -156,7 +164,7 @@ module gpuv2 #( vga_vs <= 1'b0; else if(trig_25M) begin - if(vector_y >= 10'd490 && vector_y < 10'd492) + if(vector_y >= (10'd490+offset) && vector_y < (10'd492+offset)) vga_vs <= 1'b0; else vga_vs <= 1'b1; @@ -165,52 +173,67 @@ module gpuv2 #( - reg [2:0] index; + reg px_bat; + reg px_net; + reg px_sprite; + reg px_blank; + always @ (posedge vga_clk or negedge rst_n) begin - if(!rst_n) - index <= 3'b000; - else if(trig_25M) - begin - if(vector_x < 10'd640 && vector_y < 10'd480) - if(vector_x >= (ball_x - 8 )&& vector_x <=( ball_x + 7 ) - && vector_y >= (ball_y - 8) && vector_y <= (ball_y + 7)) begin - if (sprite[(vector_y - (ball_y - 8)) & 15 ][(vector_x - (ball_x -8))& 15 ]) - index <= 3'b001; - else - index <= 3'b000; - end else if (vector_x < 10'd4) - if (vector_y >=( bat0_y - 20 ) && vector_y <= (bat0_y + 20) ) - index <= 3'b111; - else - index <= 3'b000; - else if (vector_x >= 10'd318 && vector_x < 10'd322) - index <= {3{vector_y[3]}}; - else if (vector_x >= 10'd636 && vector_x < 10'd640) - if (vector_y >=( bat1_y - 20 ) && vector_y <= (bat1_y + 20) ) - index <= 3'b111; - else - index <= 3'b000; - else - index <= 3'b000; - else - index <= 3'b000; + if(!rst_n) begin + px_bat <= 0; + px_net <= 0; + px_sprite <= 0; + px_blank <= 1; + end else if(trig_25M) begin + if(vector_x>= offset && vector_x < (10'd640+offset) && vector_y >= offset && vector_y < (10'd480+offset)) + px_blank<= blanking; + else + px_blank<=1; + + if(vector_x >= (sprite_x - 8 )&& vector_x <=( sprite_x + 7 ) + && vector_y >= (sprite_y - 8) && vector_y <= (sprite_y + 7)) + px_sprite <= sprite[(vector_y - (sprite_y - 8)) & 15 ][(vector_x - (sprite_x -8))& 15 ]; + else + px_sprite <= 0; + + if (vector_x < (10'd4+offset) && vector_y >=( bat0_y - 20 ) && vector_y <= (bat0_y + 20) ) + px_bat <= 1; + else if (vector_x >= (10'd636 + offset) && vector_y >=( bat1_y - 20 ) && vector_y <= (bat1_y + 20) ) + px_bat <=1 ; + else + px_bat <=0; + + + if (vector_x >= (10'd318 +offset) && vector_x < (10'd322+offset)) + px_net <= {3{vector_y[3]}}; + else + px_net <= 0; + end end always begin - if (index == 3'b000) begin + if (px_blank) begin vga_red = 3'b000; vga_green = 3'b000; vga_blue = 3'b000; - end else if (index == 3'b001) begin + end else if (px_bat) begin + vga_red= 3'b111; + vga_green=3'b111; + vga_blue=3'b111; + end else if (px_sprite) begin vga_red = sprite_red; vga_green= sprite_green; vga_blue = sprite_blue; - end else begin + end else if (px_net) begin vga_red= 3'b111; vga_green=3'b111; vga_blue=3'b111; + end else begin + vga_red = 3'b000; + vga_green = 3'b000; + vga_blue = 3'b000; end |