So, I've decided what I'm going to do for my Programmable Logic Project 14 entry. It's going to be a ball-rolling sort of game controlled by a couple of micro:bits. I'm hoping my kids will be able to help with the micro:bit side of things.
As the FPGA (a Spartan 7 on an Arty S7 board) will be generating the output VGA signal I started looking into how to generate FPGA. I found an excellent resource on VGA generation at timetoexplore. It describes all the timing required for a 640 x 480 VGA output from a VGA and even started going into generating graphics. I also discovered a different approach by Andy West here on E14. I really wanted to understand what I was doing rather than copy someone else's code so I took inspiration from both. The timing and generation on my version takes a lot from timetoexplore, but I liked the separation of the VGA signal generation from the rendering of element from Andy's solution.
Getting some video output
I also decide that I wanted to render the output on the fly rather than writing to an area of RAM to display from there. I felt that I'd learn more from doing it this way. Of course, I stumbled into a few FPGA pitfalls. At one point I managed to (I think) get the timing a little too close and half the screen was blanked and I got a smudgy green / purple mess. As a coder, that's not something you'd expect when only dealing with grey and blue.
Displaying something a little more game like
Once I'd got my timing issue sorted I decided to move on to having something a little more interesting than a square. This got me into the realm of uploaded an image file onto the FPGA. Once again timetoexplore was helpful. Still in my retro vibe and with a PacMan machine at work, I decided that a PacMan ghost would be cool. I ended up hand-entering image data in the form of a 14 x 14 grid of 2-bit binary data to form the image and a 4 colur palette to translate these to a 12-bit colour for display. If you look closely you can just about make out the figure in the image. Well, I can. Maybe I've been staring at it for too long.
// Pacman ghost 14x14, eyes looking left // 00 background // 01 white eye // 10 blue iris // 11 main colour // Hand typed by Fred from image here: https://www.pngkey.com/detail/u2e6e6e6a9u2e6q8_pacman-sprites-pixel-art-14x14-pac-man/ 00 00 00 00 00 11 11 11 11 00 00 00 00 00 00 00 00 11 11 11 11 11 11 11 11 00 00 00 00 00 11 11 11 11 11 11 11 11 11 11 00 00 00 11 01 01 11 11 11 11 01 01 11 11 11 00 00 01 01 01 01 11 11 01 01 01 01 11 11 00 00 10 10 01 01 11 11 10 10 01 01 11 11 00 11 10 10 01 01 11 11 10 10 01 01 11 11 11 11 11 01 01 11 11 11 11 01 01 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 00 11 11 11 00 00 11 11 11 00 11 11 11 00 00 00 11 11 00 00 11 11 00 00 00 11 // secondary image for moving "feet" 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 00 11 11 11 11 00 11 11 11 11 11 11 11 00 00 00 11 11 00 00 00 11 11 11
and the palette:
// Palette for pacman ghost // 4 12-bit colour values 0F0 // 00 = "green screen" background FFF // 01 = white eyes 48F // 10 = blue iris F00 // 11 = red body
These were loaded into distributed RAM (i.e. probably a load of LUTs) for simplicity. I may move them to Block RAM later. Once you've got the memory files as part of your Vivado project, they're simple imported like this. Note the readmemb for binary and readmemh for hex.
initial begin $display("Loading target and target palette."); $readmemb("pacman_ghost.mem", target_image); $readmemh("pacman_ghost_palette.mem", target_palette); end
I liked the way that the ghost's eyes always looked the way they were going in Pacman. Whilst Pacman had only 4 directions, I hoped my ghost was also going to move diagonally. I decided that just 2 images would be enough and that I could do this by flipping the whole ghost horizontally depending on the direction of travel. For some reason I'm struggling to animate his moving legs properly. This was the result so far:
Sorry for the poor hand-held video of the screen. One thing I noticed when doing this is that there's no easy way to record the output without buying some specialist hardware. The video is generated on the fly and never actually exists as a video file. Which I suppose is sort of the point!
What's next?
Next, I'm going to make the ghost move randomly and then start on the balls that need to be rolled towards him.
Top Comments