-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathball.vhd
43 lines (31 loc) · 1.22 KB
/
ball.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.all;
USE IEEE.STD_LOGIC_ARITH.all;
USE IEEE.STD_LOGIC_UNSIGNED.all;
ENTITY ball IS
PORT
( clk : IN std_logic;
pixel_row, pixel_column : IN std_logic_vector(9 DOWNTO 0);
red, green, blue : OUT std_logic);
END ball;
architecture behavior of ball is
SIGNAL ball_on : std_logic;
SIGNAL size : std_logic_vector(9 DOWNTO 0);
SIGNAL ball_y_pos, ball_x_pos : std_logic_vector(9 DOWNTO 0);
BEGIN
size <= CONV_STD_LOGIC_VECTOR(15,10);
-- ball_x_pos and ball_y_pos show the (x,y) for the centre of ball
ball_x_pos <= CONV_STD_LOGIC_VECTOR(590,10);
ball_y_pos <= CONV_STD_LOGIC_VECTOR(59,10);
ball_on <= '1' when ( ('0' & ball_x_pos <= pixel_column + size)
and ('0' & pixel_column <= ball_x_pos + size) -- x_pos - size <= pixel_column <= x_pos + size
and ('0' & ball_y_pos <= pixel_row + size)
and ('0' & pixel_row <= ball_y_pos + size) ) else -- y_pos - size <= pixel_row <= y_pos + size
'0';
-- Colours for pixel data on video signal
-- Keeping background white and square in red
Red <= '1';
-- Turn off Green and Blue when displaying square
Green <= not ball_on;
Blue <= not ball_on;
END behavior;