Generating video output from a FPGA is one of the really cool things you can do.
Progressing beyond Blinky LEDs and Serial Outputs to drawing stuff on the screen can bring a project to life. And the Game of Life (GOL) would be nothing if we could not watch the cells living out their lives. So this blog is the first in a mini-series that covers getting the cells to come to life and drawing them on the screen.
If we cast our minds back to my co-blogger Adam Taylor's columns on VGA Basics and generating VGA Test Patterns, then we have all we need to get started! Taking Adam's design apart, we find that his video data generator uses the pixels' positions to draw things on the screen. These positions are represented by two counters called "h_count" and "v_count" that scan the whole visible area of the screen. This means that when these values are used to access a block of memory, like a frame buffer, we can output its content to the screen. So how is this going to work for us?
Let's start with a summary of the basic information. My GOL grid is going to cover 60x60 cells. Meanwhile, the screen resolution I am using is 800x600 pixels. Thus, my plan as shown below is to use the 600x600 area on the right-hand side of the screen to represent our GOL grid.
Dividing our 600x600 area by 60x60 cells gives us a nice cell size of 10x10 pixels. Later on, I will be using the red area on the left-hand side of the screen to present textual information, like the number of cells that are currently alive and the number of the current generation, but all of that is for the future.
My cells will either be alive or dead. We could use colors to represent these states; for example, blue = "dead" and green = "alive" ("It's alive! It's alive!"). However, I'm keeping to a 1970s/1980s "retro look," so Iíll be using boring black and white for now. The point of all this is that from a pixel point of view, our grid starts 200 pixels to the right. This means that the upper left-hand cell has coordinates that cover the area defined by the following X/Y coordinates: (200,0), (209,0), (200,9), and (209,9).
So that covers some of the basics with regard to "what" and "where," now we need to consider the "how" portion of the process. The main core of Adam's "video_data_gen" code uses a "CASE" statement to cover the "v_count" value (down the screen). For each row down the screen, Adam uses an "IF" statement to decide what gets drawn across the screen using the "h_count" value. I ripped this down to the raw basics as shown below:
Next page >