No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MouseDisplay.vhd 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. ------------------------------------------------------------------------
  2. -- mouse_displayer.vhd
  3. ------------------------------------------------------------------------
  4. -- Author : Ulrich Zoltán
  5. -- Copyright 2006 Digilent, Inc.
  6. ------------------------------------------------------------------------
  7. -- Software version : Xilinx ISE 7.1.04i
  8. -- WebPack
  9. -- Device : 3s200ft256-4
  10. ------------------------------------------------------------------------
  11. -- This file contains the implementation of a mouse cursor.
  12. ------------------------------------------------------------------------
  13. -- Behavioral description
  14. ------------------------------------------------------------------------
  15. -- Mouse position is received from the mouse_controller, horizontal and
  16. -- vertical counters are received from vga_module and if the counters
  17. -- are inside the mouse cursor bounds, then the mouse is sent to the
  18. -- screen.
  19. -- The mouse display module can be also used as an overlay of the VGA
  20. -- signal, also blanking the VGA screen, if the red_in, green_in, blue_in
  21. -- and the blank_in signals are used.
  22. -- In this application the signals mentioned and their corresponding code
  23. -- lines are commented, therefore the mouse display module only generates
  24. -- the RGB signals to display the cursor, and the VGA controller decides
  25. -- whether or not to display the cursor.
  26. -- The mouse cursor is 16x16 pixels and uses 2 colors: white and black.
  27. -- For the color encoding 2 bits are used to be able to use transparency.
  28. -- The cursor is stored in a 256X2 bit distributed ram memory. If the current
  29. -- pixel of the mouse is "00" then output color is black, if "01" then is
  30. -- white and if "10" or "11" then the pixel is transparent and the input
  31. -- R, G and B signals are passed to the output.
  32. -- In this way, the mouse cursor will not be a 16x16 square, instead will
  33. -- have an arrow shape.
  34. -- The memory address is composed from the difference of the vga counters
  35. -- and mouse position: xdiff is the difference on 4 bits (because cursor
  36. -- is 16 pixels width) between the horizontal vga counter and the xpos
  37. -- of the mouse. ydiff is the difference on 4 bits (because cursor
  38. -- has 16 pixels in height) between the vertical vga counter and the
  39. -- ypos of the mouse. By concatenating ydiff and xidff (in this order)
  40. -- the memory address of the current pixel is obtained.
  41. -- A distributed memory implementation is forced by the attributes, to save
  42. -- BRAM resources.
  43. -- If the blank input from the vga_module is active, this means that current
  44. -- pixel is not inside visible screen and color outputs are set to black
  45. ------------------------------------------------------------------------
  46. -- Port definitions
  47. ------------------------------------------------------------------------
  48. -- pixel_clk - input pin, representing the pixel clock, used
  49. -- - by the vga_controller for the currently used
  50. -- - resolution, generated by a dcm. 25MHz for 640x480,
  51. -- - 40MHz for 800x600 and 108 MHz for 1280x1024.
  52. -- - This clock is used to read pixels from memory
  53. -- - and output data on color outputs.
  54. -- xpos - input pin, 10 bits, from mouse_controller
  55. -- - the x position of the mouse relative to the upper
  56. -- - left corner
  57. -- ypos - input pin, 10 bits, from mouse_controller
  58. -- - the y position of the mouse relative to the upper
  59. -- - left corner
  60. -- hcount - input pin, 11 bits, from vga_module
  61. -- - the horizontal counter from the vga_controller
  62. -- - tells the horizontal position of the current pixel
  63. -- - on the screen from left to right.
  64. -- vcount - input pin, 11 bits, from vga_module
  65. -- - the vertical counter from the vga_controller
  66. -- - tells the vertical position of the currentl pixel
  67. -- - on the screen from top to bottom.
  68. -- red_out - output pin, 4 bits, to vga hardware module.
  69. -- - red output channel
  70. -- green_out - output pin, 4 bits, to vga hardware module.
  71. -- - green output channel
  72. -- blue_out - output pin, 4 bits, to vga hardware module.
  73. -- - blue output channel
  74. ------------------- Signals used when the mouse display is in overlay mode
  75. -- blank - input pin, from vga_module
  76. -- - if active, current pixel is not in visible area,
  77. -- - and color outputs should be set on 0.
  78. -- red_in - input pin, 4 bits, from effects_layer
  79. -- - red channel input of the image to be displayed
  80. -- green_in - input pin, 4 bits, from effects_layer
  81. -- - green channel input of the image to be displayed
  82. -- blue_in - input pin, 4 bits, from effects_layer
  83. -- - blue channel input of the image to be displayed
  84. ------------------------------------------------------------------------
  85. library IEEE;
  86. use IEEE.STD_LOGIC_1164.ALL;
  87. use IEEE.STD_LOGIC_ARITH.ALL;
  88. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  89. -- simulation library
  90. --library UNISIM;
  91. --use UNISIM.VComponents.all;
  92. -- the mouse_displayer entity declaration
  93. -- read above for behavioral description and port definitions.
  94. entity MouseDisplay is
  95. port (
  96. pixel_clk: in std_logic;
  97. xpos : in std_logic_vector(11 downto 0);
  98. ypos : in std_logic_vector(11 downto 0);
  99. hcount : in std_logic_vector(11 downto 0);
  100. vcount : in std_logic_vector(11 downto 0);
  101. --blank : in std_logic; -- if VGA blank is used
  102. --red_in : in std_logic_vector(3 downto 0); -- if VGA signal pass-through is used
  103. --green_in : in std_logic_vector(3 downto 0);
  104. --blue_in : in std_logic_vector(3 downto 0);
  105. enable_mouse_display_out : out std_logic;
  106. red_out : out std_logic_vector(3 downto 0);
  107. green_out: out std_logic_vector(3 downto 0);
  108. blue_out : out std_logic_vector(3 downto 0)
  109. );
  110. -- force synthesizer to extract distributed ram for the
  111. -- displayrom signal, and not a block ram, to save BRAM resources.
  112. attribute rom_extract : string;
  113. attribute rom_extract of MouseDisplay: entity is "yes";
  114. attribute rom_style : string;
  115. attribute rom_style of MouseDisplay: entity is "distributed";
  116. end MouseDisplay;
  117. architecture Behavioral of MouseDisplay is
  118. ------------------------------------------------------------------------
  119. -- CONSTANTS
  120. ------------------------------------------------------------------------
  121. type displayrom is array(0 to 255) of std_logic_vector(1 downto 0);
  122. -- the memory that holds the cursor.
  123. -- 00 - black
  124. -- 01 - white
  125. -- 1x - transparent
  126. constant mouserom: displayrom := (
  127. "00","00","11","11","11","11","11","11","11","11","11","11","11","11","11","11",
  128. "00","01","00","11","11","11","11","11","11","11","11","11","11","11","11","11",
  129. "00","01","01","00","11","11","11","11","11","11","11","11","11","11","11","11",
  130. "00","01","01","01","00","11","11","11","11","11","11","11","11","11","11","11",
  131. "00","01","01","01","01","00","11","11","11","11","11","11","11","11","11","11",
  132. "00","01","01","01","01","01","00","11","11","11","11","11","11","11","11","11",
  133. "00","01","01","01","01","01","01","00","11","11","11","11","11","11","11","11",
  134. "00","01","01","01","01","01","01","01","00","11","11","11","11","11","11","11",
  135. "00","01","01","01","01","01","00","00","00","00","11","11","11","11","11","11",
  136. "00","01","01","01","01","01","00","11","11","11","11","11","11","11","11","11",
  137. "00","01","00","00","01","01","00","11","11","11","11","11","11","11","11","11",
  138. "00","00","11","11","00","01","01","00","11","11","11","11","11","11","11","11",
  139. "00","11","11","11","00","01","01","00","11","11","11","11","11","11","11","11",
  140. "11","11","11","11","11","00","01","01","00","11","11","11","11","11","11","11",
  141. "11","11","11","11","11","00","01","01","00","11","11","11","11","11","11","11",
  142. "11","11","11","11","11","11","00","00","11","11","11","11","11","11","11","11"
  143. );
  144. -- width and height of cursor.
  145. constant OFFSET: std_logic_vector(4 downto 0) := "10000"; -- 16
  146. ------------------------------------------------------------------------
  147. -- SIGNALS
  148. ------------------------------------------------------------------------
  149. -- pixel from the display memory, representing currently displayed
  150. -- pixel of the cursor, if the cursor is being display at this point
  151. signal mousepixel: std_logic_vector(1 downto 0) := (others => '0');
  152. -- when high, enables displaying of the cursor, and reading the
  153. -- cursor memory.
  154. signal enable_mouse_display: std_logic := '0';
  155. -- difference in range 0-15 between the vga counters and mouse position
  156. signal xdiff: std_logic_vector(3 downto 0) := (others => '0');
  157. signal ydiff: std_logic_vector(3 downto 0) := (others => '0');
  158. signal red_int : std_logic_vector(3 downto 0);
  159. signal green_int: std_logic_vector(3 downto 0);
  160. signal blue_int : std_logic_vector(3 downto 0);
  161. signal red_int1 : std_logic_vector(3 downto 0);
  162. signal green_int1: std_logic_vector(3 downto 0);
  163. signal blue_int1 : std_logic_vector(3 downto 0);
  164. begin
  165. -- compute xdiff
  166. x_diff: process(hcount, xpos)
  167. variable temp_diff: std_logic_vector(11 downto 0) := (others => '0');
  168. begin
  169. temp_diff := hcount - xpos;
  170. xdiff <= temp_diff(3 downto 0);
  171. end process x_diff;
  172. -- compute ydiff
  173. y_diff: process(vcount, xpos)
  174. variable temp_diff: std_logic_vector(11 downto 0) := (others => '0');
  175. begin
  176. temp_diff := vcount - ypos;
  177. ydiff <= temp_diff(3 downto 0);
  178. end process y_diff;
  179. -- read pixel from memory at address obtained by concatenation of
  180. -- ydiff and xdiff
  181. mousepixel <= mouserom(conv_integer(ydiff & xdiff))
  182. when rising_edge(pixel_clk);
  183. -- set enable_mouse_display high if vga counters inside cursor block
  184. enable_mouse: process(pixel_clk, hcount, vcount, xpos, ypos)
  185. begin
  186. if(rising_edge(pixel_clk)) then
  187. if(hcount >= xpos +X"001" and hcount < (xpos + OFFSET - X"001") and
  188. vcount >= ypos and vcount < (ypos + OFFSET)) and
  189. (mousepixel = "00" or mousepixel = "01")
  190. then
  191. enable_mouse_display <= '1';
  192. else
  193. enable_mouse_display <= '0';
  194. end if;
  195. end if;
  196. end process enable_mouse;
  197. enable_mouse_display_out <= enable_mouse_display;
  198. -- if cursor display is enabled, then, according to pixel
  199. -- value, set the output color channels.
  200. process(pixel_clk)
  201. begin
  202. if(rising_edge(pixel_clk)) then
  203. -- if in visible screen
  204. -- if(blank = '0') then
  205. -- in display is enabled
  206. if(enable_mouse_display = '1') then
  207. -- white pixel of cursor
  208. if(mousepixel = "01") then
  209. red_out <= (others => '1');
  210. green_out <= (others => '1');
  211. blue_out <= (others => '1');
  212. -- black pixel of cursor
  213. elsif(mousepixel = "00") then
  214. red_out <= (others => '0');
  215. green_out <= (others => '0');
  216. blue_out <= (others => '0');
  217. -- transparent pixel of cursor
  218. -- let input pass to output
  219. -- else
  220. -- red_out <= red_in;
  221. -- green_out <= green_in;
  222. -- blue_out <= blue_in;
  223. end if;
  224. -- cursor display is not enabled
  225. -- let input pass to output.
  226. -- else
  227. -- red_out <= red_in;
  228. -- green_out <= green_in;
  229. -- blue_out <= blue_in;
  230. end if;
  231. -- not in visible screen, black outputs.
  232. -- else
  233. -- red_out <= (others => '0');
  234. -- green_out <= (others => '0');
  235. -- blue_out <= (others => '0');
  236. -- end if;
  237. end if;
  238. end process;
  239. end Behavioral;