Bringing it back to the basics. In the craze of the Pokemon GO popularity, I noticed this old team project video demo hit a thousand views on YouTube. It was a joint project to create a version of this popular game using behavioral Verilog code on an FPGA. I thought it might be interesting to dive into what this actually means.
Disclaimer: It has been several years since I’ve done any HDL or Verilog development, don’t treat this as an academic source
Verilog – a hardware description language
A hardware description language defines the placement and behavior of logic gates on an integrated chip to perform some function – such as, to create an arithmetic logic unit, or at a more macroscopic level, a CPU.
To understand this, it is important to understand how other programming languages function. If you write a program in C++ for example, you compile the code into assembly line-by-line instructions which essentially converts a line of code like ‘x = y+2’ into multiple CPU instructions like ‘READ Var < y; ADD Var < 2; STORE Var > x’ (pseudo assembly for communicative purposes). These are the most basic kinds of instructions or steps that the CPU of a machine can run. However, with a hardware description language you are not feeding instructions to pipe into a CPU. Instead you are essentially defining the instructions for how to arrange logic gates (made of transistors) on a chip.
In Verilog, you code using logic gates and connecting wires as building blocks. Using AND, OR, and XOR blocks you can create a module like a half bit or full bit adder. Multiple full bit adders sequenced together can create multi-bit adders. In this way, you can create sophisticated modules performing complex tasks using the elementary blocks of logic.
FPGA – Field Programmable Gate Array
If you are familiar with Arduinos, then an FPGA is similar in ways – but still a very different idea. On a small chip like Arduino’s or MSP430’s, you compile C code into an assembly language format that loads onto the chip. The CPU then runs this single program while powered. However with an FPGA, the code you feed and compile onto the device is not assembly code, but rather the formula to arrange all the configurable logic gates on the machine to then behave in the logical way defined in Verilog.
This allows us to test our real hardware designs before fabricating them to make an integrated chip (IC). Instead of an IC where logic gates and wires are soldered in place and cannot move, an FPGA uses high-voltage flashing to modify connections between all the logic gates to customize the function of the chip dynamically.
Pokemon FPGA – an interactive game
Now you know what an FPGA is and how hardware description languages work. Does making a fully functioning, interactive game with graphics, animations, and leveling mechanics sound crazy? It probably should.
Everything in this Pokemon videogame remake was written in Verilog and compiled onto the Spartan boards shown. That even includes the realtime network communication needed to send pixel-by-pixel data over the VGA cable to the monitor. It’s all done with logic gates and wires. In a later post, I’ll go into more detail on how my team actually accomplished this. To be continued.