0470185317 (2008) fpga prototyping by vhdl examples xilinx spartan 3 version

Page 340

THE COMPLETE PONG GAME

309

text-on <= score-on & logo-on & rule-on & over-on; -- f o n t 240

ROM i n t e r f a c e

rom-addr <= char-addr & r o w - a d d r ; font-bit <= font-word(to-integer(unsigned(n0t end a r c h ;

bit-addr)));

The structure of each segment is similar. Because the messages are short, they are coded with the regular ROM template. Since no clock signal is used, a distributed RAM or combinational logic should be inferred. Generation of the two-digit score depends on the two 4-bit external signals, digO and d i g l . Note that the ASCII codes for the digits 0, 1, . . ., 9, are 3016, 3116, . . ., 3916. We can generate the char-addr signal simply by concatenating “Oil” in front of digO and d i g l . 13.4.2

Modified graphic subsystem

To accommodate the new top-level controller, the graphic circuit in Section 12.4.3 requires several modifications: 0 Add a g r a - s t i l l (for “still graphics”) control signal. When it is asserted, the vertical bar is placed in the middle and the ball is placed at the center of the screen without movement. 0 Add the h i t and miss status signals. The h i t signal is asserted for one clock cycle when the paddle hits the ball. The miss signal is asserted when the paddle misses the ball and the ball reaches the right border. Add a graph-on signal to indicate the on status of.the graph subsystem. The modified portion of the code is shown in Listing 13.7. Listing 13.7 Modified portion of a graph subsystem for the pong game

-- new b a l l p o s i t i o n 5

in

15

20

ball-x-next <= to_unsigned((MAX-X)/2,10) when g r a - s t i l l = ’ l ’ e l s e ball-x-reg + ball-vx-reg when r e f r - t i c k = ’ l ’ e l s e ball-x-reg ; ball-y-next <= to_unsigned((MAX-Y)/2,10) when g r a - s t i l l = ’ l ’ e l s e ball-y-reg + ball-vy-reg when r e f r - t i c k = ’ l ’ e l s e ball-y-reg ; -- new b a l l v e l o c i t y process(ball~vx~reg,ball~vy~reg,ball~y~t,ball~x~l,ball~x~r, ball-y-t,ball-y-b,bar-y-t,bar-y-b,gra-still) begin hit < = ’ O ’ ; miss < = ’ O ’ ; ball-vx-next <= b a l l - v x - r e g ; ball-vy-next <= b a l l - v y - r e g ; i f g r a - s t i l l = ’ l > then -- i n i t i a 1 v e 1 o c i t y ball-vx-next <= B A L L - V - N ; ball-vy-next < = BALL-V-P; e l s i f ball-y-t < 1 then __ r e a c h t o p


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.