# Vhdl VGA Problem

I'm doing a fpga project in vhdl for my studies.

I'm displaying a dog on the screen that I try to move. That works well for right, left and up but trying to make the dog go down, it moves in a strange way: it's like the dog "scrolls", it's hard to describe but its not the dog that moves its kind of a window that moves on a list of following dogs.

If i move the else Spot <= '0' part of the code , other directions (right and down) became invalid (same error) .

Here is the full code: https://dl.dropbox.com/u/67429007/Desktop.rar

Here is the bugging (I think) code part:

begin

if clk25'event and clk25='1' then
if Compteur_pixels >= origineX and compteur_pixels < origineX + tailleX
and compteur_lignes >= origineY and compteur_lignes < origineY + tailleY  then
Spot <= dog (ligne,Pixel); --dog and is an array of 0 and 1
Pixel := Pixel+1;

if pixel >= tailleX then
pixel := 0;
ligne := ligne + 1;

if ligne >= tailleY then
ligne := 0;

else Spot <= '0';

if direction = "00011100" then     -- right key pressed (A)
if originex < 700  then
originex := origineX + 1; --increment X origin of dog
end if;

elsif direction = "00011010" then -- left (w)
if originex > 83  then
originex := origineX - 1;
end if;

elsif direction = "00111010" then -- up
if originey > 46 then
originey := originey - 1;
end if;

elsif direction = "01000010" then  -- down
if originey < 450  then
originey := originey + 1;
end if;
end if;
end if;
end if;
end if;
end if ;

end process ;

• It looks as if you aren't erasing the old image of the dog when you move it to a new location. – user_1818839 Apr 1 '13 at 17:03
• it's not that because I display all the screen every time. – Comeon Apr 1 '13 at 17:38
• The algorithme is : <pre> For all pixel of the screen if we are in the position of displaying the picture display the corresponding pixel else display a black pixel if direction is up origin of picture -- ; etc. . . – Comeon Apr 1 '13 at 17:39
• but ... I think your else Spot <= '0'; is in the wrong place. – user_1818839 Apr 1 '13 at 17:43
• I saw that to and I changed it but in a wrong way, I'm trying to correct it now :) I tell you – Comeon Apr 1 '13 at 17:46

Thanks to a friend, I wait for the Vertical Synchronisation signal to be equal 0 to make my picture move. It solved the problem because the sprite origin now changes only when the screen is near to be redraw.

You have some white pixels ('1') on the edge or your dog array. If you just slide it like the algo does, then you will see the 'scrolling' bug you talk about. Make your array (i.e. sprite), have zeros on the edges if you want to move it one pixel at a time. Or you can just clear the screen and repaint on every cursor move.

• Can you upload a video to show what happens? Maybe a waveform too? – MIkeB Apr 1 '13 at 17:38
• Actually, Brian answered your question. Clear the area first them move the 'sprite'. – MIkeB Apr 1 '13 at 17:40
• In fact it's not doing like a paint brush, there is distinct dogs one over an other.. I take a video – Comeon Apr 1 '13 at 19:06
• You gave a Smart way of solve the problem anyway I like it. But It's not mine :/ <br> I would have prefer it was – Comeon Apr 1 '13 at 19:34
• Hre is the video youtu.be/npoi_ITIuNg – Comeon Apr 1 '13 at 19:38

My earlier comments were wrong, because the scrolling is within the sprite area, with the rest of the screen clear. I couldn't tell that from your description.

Now I can see that when you move the origin of a partially displayed dog on screen, you do not adjust the Pixel and Ligne positions within the dog. So, moving the sprite in one direction, you move it OUT of the scan range and start re-drawing it at (0,0) in dog cordinates when you reach the next line.

Moving in the other direction you ought to skip a line. What was (1,0) or (0,1) in dog coordinates should now be (2,0) or (0,2) but you don't make that adjustment. However if you did, you would have to miss the first line or column of pixels and draw an incomplete sprite.

A better answer is to only detect sprite movement and process the origin when your pixel counter is outside the frame entirely. Or at least, outside the sprite in the Y axis.

Also, make the boundary values (83, 46 etc) not magic numbers but dependent on the sprite size, e.g. VGA_height - Dog_height - margin;

• I see it seems to be the answer , i don't understand all the thing but I'll work on it :) Thanks Brian. – Comeon Apr 1 '13 at 21:23
• Yes that is what I was trying to do in fact, I only move the OriginX and the originY When the line counter of the sprite is equal to is maximum. – Comeon Apr 1 '13 at 21:43
• Actually, Even with the correction it does not work. In the code i change origin of dog only when the line counter is to '0' – Comeon Apr 1 '13 at 22:04
• dl.dropbox.com/u/67429007/Nouveau%20document%20texte.txt here iss the revision – Comeon Apr 1 '13 at 22:07