From: Pierre C. <Sup...@us...> - 2010-01-31 18:05:59
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot-resources". The branch, master has been updated via 71889e232097e5870459effdc465bb904ebd04fa (commit) via d9aeea08f2e273be6e743427a0dd6a543b27da40 (commit) from 1e545ef9f7ae38acea030fec3f15b1c1a9fb5e58 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 71889e232097e5870459effdc465bb904ebd04fa Author: chambart <cha...@cr...> Date: Sun Jan 31 19:05:07 2010 +0100 pong is still useless but working ! commit d9aeea08f2e273be6e743427a0dd6a543b27da40 Author: chambart <cha...@cr...> Date: Thu Jan 28 23:26:57 2010 +0100 draw more things on pong ----------------------------------------------------------------------- Changes: diff --git a/fpga/examples/pong/draw.vhd b/fpga/examples/pong/draw.vhd index 57fe679..7fbe3b3 100644 --- a/fpga/examples/pong/draw.vhd +++ b/fpga/examples/pong/draw.vhd @@ -6,94 +6,70 @@ use ieee.std_logic_arith.all; entity draw is generic ( size_x : positive := 400; - size_y : positive := 400 + size_y : positive := 400; + palet_width : positive := 5; + palet_height : positive := 20 ); port ( - update : in std_logic; - x_pos : in integer range 0 to 639; - y_pos : in integer range 0 to 479; + x_pixel : in integer range 0 to 639; + y_pixel : in integer range 0 to 479; ball_x : in integer range 0 to size_x - 1; ball_y : in integer range 0 to size_y - 1; - + palet_l : in integer range 0 to size_y - 1; + palet_r : in integer range 0 to size_y - 1; color : out std_logic_vector (7 downto 0)); end draw; architecture draw of draw is type rom_type is array (0 to 3, 0 to 3) of integer range 0 to 3; + + constant left_empty : natural := palet_width * 2; + constant up_empty : natural := 20; + constant ball_radius : natural := 3; + constant width_border : natural := 2; + + signal current_x : integer; + signal current_y : integer; + signal px : integer; signal py : integer; - signal locx : integer range 0 to 3; - signal locy : integer range 0 to 3; signal tmpx : natural; signal tmpy : natural; - constant rom : rom_type := - ((1,3,0,0), - (2,1,3,0), - (0,2,1,3), - (0,0,0,1)); + + signal in_ball : std_logic; + signal in_palet_l : std_logic; + signal in_palet_r : std_logic; + signal in_border : std_logic; begin + current_x <= x_pixel - left_empty; + current_y <= y_pixel - up_empty; + px <= ball_x; py <= ball_y; - tmpx <= abs (x_pos - px); - tmpy <= abs (y_pos - py); + tmpx <= abs (current_x - px); + tmpy <= abs (current_y - py); - - --locx <= tmpx when tmpx <= 3 else 3; - --locy <= tmpy when tmpy <= 3 else 0; + in_ball <= '1' when (tmpx*tmpx + tmpy*tmpy <= ball_radius*ball_radius) + else '0'; - --with rom(locx,locy) select - -- color <= - -- "00000000" when 0, - -- "11100000" when 1, - -- "00011100" when 2, - -- "00000011" when 3; + in_palet_l <= '1' when current_x <= 0 + and current_x >= -palet_width + and abs ( current_y - palet_l ) <= palet_height / 2 + else '0'; + in_palet_r <= '1' when current_x >= size_x + and current_x <= size_x + palet_width + and abs ( current_y - palet_r ) <= palet_height / 2 + else '0'; - color <= "11111111" when (tmpx <= 3) and (tmpy <= 3) - else "00000000"; - ---update_process: process (update) --- variable x : integer := 100; --- variable y : integer := 100; --- variable direction_x : std_logic := '1'; --- variable direction_y : std_logic := '1'; ---begin --- if rising_edge(update) then --- if x >= 639 and direction_x = '1' --- then --- direction_x := '0'; --- end if; --- if x <= 0 and direction_x = '0' --- then --- direction_x := '1'; --- end if; --- if y >= 479 and direction_y = '1' --- then --- direction_y := '0'; --- end if; --- if y <= 0 and direction_y = '0' --- then --- direction_y := '1'; --- end if; - --- if direction_x = '0' then --- x := x - 1; --- else --- x := x + 1; --- end if; --- if direction_y = '0' then --- y := y - 1; --- else --- y := y + 1; --- end if; + in_border <= '1' when current_x >= 0 and current_x < size_x + and ( ( current_y <= 0 and current_y > -width_border ) + or ( current_y > size_y and current_y < size_y + width_border ) ) + else '0'; --- end if; - --- px <= x; --- py <= y; - ---end process update_process; + color <= "00111000" when in_ball = '1' or in_palet_l = '1' or in_palet_r = '1' or in_border = '1' + else "00000000"; end draw; diff --git a/fpga/examples/pong/game.vhd b/fpga/examples/pong/game.vhd index d3da725..1655583 100644 --- a/fpga/examples/pong/game.vhd +++ b/fpga/examples/pong/game.vhd @@ -6,73 +6,83 @@ use ieee.std_logic_arith.all; entity game is generic ( size_x : positive := 400; - size_y : positive := 400); + size_y : positive := 400; + palet_width : positive := 5; + palet_height : positive := 20); port ( clk : in std_logic; - scan_code : in std_logic_vector ( 7 downto 0 ); - up_key : in std_logic; - extended_key : in std_logic; - key_int : in std_logic; + key_up_l : in std_logic; + key_down_l : in std_logic; + key_up_r : in std_logic; + key_down_r : in std_logic; ball_x : out integer range 0 to size_x - 1; ball_y : out integer range 0 to size_y - 1; - keys : out std_logic_vector ( 3 downto 0 ) + palet_l : out integer range 0 to size_y - 1; + palet_r : out integer range 0 to size_y - 1; + score_l : out integer range 0 to 255; + score_r : out integer range 0 to 255 +-- keys : out std_logic_vector ( 3 downto 0 ) ); end entity game; architecture game of game is + + constant init_x : integer := size_x / 2; + constant init_y : integer := size_y / 3; + signal game_clk : std_logic; - signal key_up : std_logic; - signal key_down : std_logic; - signal key_left : std_logic; - signal key_right : std_logic; - signal px : integer; - signal py : integer; + --signal key_up : std_logic; + --signal key_down : std_logic; + --signal key_left : std_logic; + --signal key_right : std_logic; + signal px : integer range 0 to size_x - 1; + signal py : integer range 0 to size_y - 1; begin - keys <= key_up & key_down & key_left & key_right; +-- keys <= key_up & key_down & key_left & key_right; ball_x <= px; ball_y <= py; - process (key_int) - variable up : std_logic := '0'; - variable down : std_logic := '0'; - variable left_dir : std_logic := '0'; - variable right_dir : std_logic := '0'; - begin - if rising_edge(key_int) then - if (up_key = '0' and scan_code = "0111"&"0101" ) then - up := '1'; - end if; - if (up_key = '1' and scan_code = "0111"&"0101" ) then - up := '0'; - end if; - if (up_key = '0' and scan_code = "0111"&"0010" ) then - down := '1'; - end if; - if (up_key = '1' and scan_code = "0111"&"0010" ) then - down := '0'; - end if; - if (up_key = '0' and scan_code = "0111"&"0100" ) then - right_dir := '1'; - end if; - if (up_key = '1' and scan_code = "0111"&"0100" ) then - right_dir := '0'; - end if; - if (up_key = '0' and scan_code = "0110"&"1011" ) then - left_dir := '1'; - end if; - if (up_key = '1' and scan_code = "0110"&"1011" ) then - left_dir := '0'; - end if; - end if; + --process (key_int) + -- variable up : std_logic := '0'; + -- variable down : std_logic := '0'; + -- variable left_dir : std_logic := '0'; + -- variable right_dir : std_logic := '0'; + --begin + -- if rising_edge(key_int) then + -- if (up_key = '0' and scan_code = "0111"&"0101" ) then + -- up := '1'; + -- end if; + -- if (up_key = '1' and scan_code = "0111"&"0101" ) then + -- up := '0'; + -- end if; + -- if (up_key = '0' and scan_code = "0111"&"0010" ) then + -- down := '1'; + -- end if; + -- if (up_key = '1' and scan_code = "0111"&"0010" ) then + -- down := '0'; + -- end if; + -- if (up_key = '0' and scan_code = "0111"&"0100" ) then + -- right_dir := '1'; + -- end if; + -- if (up_key = '1' and scan_code = "0111"&"0100" ) then + -- right_dir := '0'; + -- end if; + -- if (up_key = '0' and scan_code = "0110"&"1011" ) then + -- left_dir := '1'; + -- end if; + -- if (up_key = '1' and scan_code = "0110"&"1011" ) then + -- left_dir := '0'; + -- end if; + -- end if; - key_up <= up; - key_down <= down; - key_left <= left_dir; - key_right <= right_dir; + -- key_up <= up; + -- key_down <= down; + -- key_left <= left_dir; + -- key_right <= right_dir; - end process; + --end process; process (clk) @@ -91,29 +101,88 @@ begin end process; update_process: process (game_clk) - variable x : integer := 100; + variable x : integer := 50; variable y : integer := 100; + variable v_x : integer := 2; + variable v_y : integer := 2; + variable y_l : integer := 100; + variable y_r : integer := 100; + variable v_score_l : integer range 0 to 255 := 0; + variable v_score_r : integer range 0 to 255 := 0; + begin if rising_edge(game_clk) then - if key_up = '1' and y > 0 then - y := y - 1; + -- begin bounce on palet + if x >= size_x-1 + and v_x > 0 + and abs ( y - y_r ) < palet_height + then + v_x := -v_x; end if; - if key_down = '1' and y < size_y then - y := y + 1; + if x <= 0 + and v_x < 0 + and abs ( y - y_l ) < palet_height + then + v_x := -v_x; end if; - if key_left = '1' and x > 0 then - x := x - 1; + -- end bounce on palet + + -- begin bounce on up wall + if ( (y >= size_y-1 and v_y > 0) + or (y <= 0 and v_y < 0) ) + then + v_y := -v_y; end if; - if key_right = '1' and x < size_x then - x := x + 1; + -- end bounce on up wall + + -- begin move ball + x := x + v_x; + y := y + v_y; + -- end move ball + + -- begin loose + if x >= size_x + palet_width + then + v_score_l := 1 + v_score_l; + x := init_x; + y := init_y; end if; + if x < 0 - palet_width + then + v_score_r := 1 + v_score_r; + x := init_x; + y := init_y; + end if; + -- end loose + + + -- begin move palet + if key_up_l = '1' and y_l > palet_height then + y_l := y_l - 1; + end if; + if key_down_l = '1' and y_l < size_y - palet_height then + y_l := y_l + 1; + end if; + if key_up_r = '1' and y_r > palet_height then + y_r := y_r - 1; + end if; + if key_down_r = '1' and y_r < size_y - palet_height then + y_r := y_r + 1; + end if; + -- end move palet end if; + palet_l <= y_l; + palet_r <= y_r; + px <= x; py <= y; + score_l <= v_score_l; + score_r <= v_score_r; + end process update_process; diff --git a/fpga/examples/pong/pong.ucf b/fpga/examples/pong/pong.ucf index 785eb95..e53079a 100644 --- a/fpga/examples/pong/pong.ucf +++ b/fpga/examples/pong/pong.ucf @@ -7,10 +7,10 @@ # NET "sw<6>" LOC= "N17"; # NET "sw<7>" LOC= "R17"; -# NET "btn<0>" LOC= "B18"; # Bank = 1 , Pin name = IP , Type = INPUT , Sch name = BTN0 -# NET "btn<1>" LOC= "D18"; # Bank = 1 , Pin name = IP/VREF_1 , Type = VREF , Sch name = BTN1 -# NET "btn<2>" LOC= "E18"; # Bank = 1 , Pin name = IP , Type = INPUT , Sch name = BTN2 -# NET "btn<3>" LOC= "H13"; # Bank = 1 , Pin name = IP , Type = INPUT , Sch name = BTN3 +NET "btn<0>" LOC= "B18"; # Bank = 1 , Pin name = IP , Type = INPUT , Sch name = BTN0 +NET "btn<1>" LOC= "D18"; # Bank = 1 , Pin name = IP/VREF_1 , Type = VREF , Sch name = BTN1 +NET "btn<2>" LOC= "E18"; # Bank = 1 , Pin name = IP , Type = INPUT , Sch name = BTN2 +NET "btn<3>" LOC= "H13"; # Bank = 1 , Pin name = IP , Type = INPUT , Sch name = BTN3 # Pin assignment for Leds # Connected to Nexys 2 diff --git a/fpga/examples/pong/pong.vhd b/fpga/examples/pong/pong.vhd index e41641e..dbe0db6 100644 --- a/fpga/examples/pong/pong.vhd +++ b/fpga/examples/pong/pong.vhd @@ -7,7 +7,7 @@ entity pong is port ( clk : in std_logic; --- btn : in std_logic_vector(3 downto 0); + btn : in std_logic_vector(3 downto 0); Led : out std_logic_vector(7 downto 0); -- usb : in std_logic; -- sw : in std_logic_vector(7 downto 0); @@ -30,14 +30,18 @@ architecture pong of pong is component draw is generic ( size_x : positive := 400; - size_y : positive := 400 + size_y : positive := 400; + palet_width : positive := 5; + palet_height : positive := 20 ); port ( - update : in std_logic; - x_pos : in integer range 0 to 639; - y_pos : in integer range 0 to 479; +-- update : in std_logic; + x_pixel : in integer range 0 to 639; + y_pixel : in integer range 0 to 479; ball_x : in integer range 0 to size_x - 1; ball_y : in integer range 0 to size_y - 1; + palet_l : in integer range 0 to size_y - 1; + palet_r : in integer range 0 to size_y - 1; color : out std_logic_vector (7 downto 0)); end component; @@ -82,21 +86,29 @@ architecture pong of pong is component game is generic ( size_x : positive := 400; - size_y : positive := 400); + size_y : positive := 400; + palet_width : positive := 5; + palet_height : positive := 20); port ( clk : in std_logic; - scan_code : in std_logic_vector ( 7 downto 0 ); - up_key : in std_logic; - extended_key : in std_logic; - key_int : in std_logic; + key_up_l : in std_logic; + key_down_l : in std_logic; + key_up_r : in std_logic; + key_down_r : in std_logic; ball_x : out integer range 0 to size_x - 1; ball_y : out integer range 0 to size_y - 1; - keys : out std_logic_vector ( 3 downto 0 ) + palet_l : out integer range 0 to size_y - 1; + palet_r : out integer range 0 to size_y - 1; + score_l : out integer range 0 to 255; + score_r : out integer range 0 to 255 +-- keys : out std_logic_vector ( 3 downto 0 ) ); end component; constant size_x : integer := 400; constant size_y : integer := 400; + constant palet_width : positive := 5; + constant palet_height : positive := 20; signal vga_color : std_logic_vector ( 7 downto 0 ); signal internal_vsync : std_logic; @@ -114,6 +126,11 @@ architecture pong of pong is signal key_extended : std_logic; signal key_int : std_logic; + signal key_up_l : std_logic; + signal key_down_l : std_logic; + signal key_up_r : std_logic; + signal key_down_r : std_logic; + signal slow_clk : std_logic; signal value_7seg : std_logic_vector ( 15 downto 0 ); signal point_7seg : std_logic_vector ( 3 downto 0 ); @@ -121,42 +138,70 @@ architecture pong of pong is -- game data signal ball_x : integer range 0 to size_x - 1; signal ball_y : integer range 0 to size_y - 1; + + signal palet_l : integer range 0 to size_y - 1; + signal palet_r : integer range 0 to size_y - 1; + + signal score_l : integer range 0 to 255 := 0; + signal score_r : integer range 0 to 255 := 0; + signal score_l_vector : std_logic_vector ( 7 downto 0 ); + signal score_r_vector : std_logic_vector ( 7 downto 0 ); + begin vsync <= internal_vsync; - vga_out <= vga_color; - + vga_out <= vga_color when active_output = '1' else "00000000"; + + score_l_vector <= (conv_std_logic_vector(score_l,8)); + score_r_vector <= (conv_std_logic_vector(score_r,8)); + value_7seg <= (score_l_vector(3 downto 0)) & (score_l_vector(7 downto 4)) + & (score_r_vector(3 downto 0)) & (score_r_vector(7 downto 4)); + key_up_l <= btn(0); + key_down_l <= btn(1); + key_up_r <= btn(2); + key_down_r <= btn(3); + draw_1 : draw generic map ( size_x, - size_y + size_y, + palet_width, + palet_height ) port map - ( internal_vsync, + ( -- internal_vsync, vga_x, vga_y, ball_x, ball_y, + palet_l, + palet_r, vga_color ); game_1 : game generic map ( size_x, - size_y) + size_y, + palet_width, + palet_height) port map ( clk, - scan_code, - key_up, - key_extended, - key_int, + key_up_l, + key_down_l, + key_up_r, + key_down_r, ball_x, ball_y, - led ( 3 downto 0 ) + palet_l, + palet_r, + score_l, + score_r +-- led ( 3 downto 0 ) ); - led ( 7 downto 4 ) <= "0000"; + led ( 7 downto 0 ) <= "00000000"; vga_1 : vga port map ( clk, @@ -195,7 +240,6 @@ begin an ); - process (clk) variable count : integer range 0 to 65535 := 0; variable tmp_std : std_logic_vector ( 15 downto 0 ); hooks/post-receive -- krobot-resources |