This folder contains Verilator simulations to accompany the Project F blog post: FPGA Pong.
Verilator creates C++ simulations of Verilog designs, while SDL produces simple cross-platform graphics applications. By combining the two, you can simulate a hardware design on your PC: no dev board required! Verilator is fast, but it's still much slower than an FPGA. However, for this simple design, you can reach 60 FPS on a modern PC.
If you're new to graphics simulations check out the blog post on Verilog Simulation with Verilator and SDL.
If you have a dev board, see the main FPGA Pong README for build instructions.
Pong running as a Verilator simulation on macOS.
This simulation has been tested with:
- Verilator 4.038 (Ubuntu 22.04 amd64)
- Verilator 5.006 (macOS 13 arm64)
If this is the first time you've used Verilator and SDL, you need to install dependencies.
Make sure you're in the sim directory projf-explore/graphics/pong/sim
.
Build Pong:
make pong
Run the simulation executable from obj_dir
:
./obj_dir/pong
The keyboard controls are:
- Up Arrow - up
- Space Bar - start (fire)
- Down Arrow - down
You can quit the simulation by pressing the Q key.
You can edit the keyboard controls in main_pong.cpp
; search for update keyboard state
.
Note: this design uses simple_480p.sv and simple_score.sv from the main Pong folder.
To build the simulations, you need:
- C++ Toolchain
- Verilator
- SDL
The simulations should work on any modern platform, but I've confined my instructions to Linux and macOS. Windows installation depends on your choice of compiler, but the sims should work fine there too. For advice on SDL development on Windows, see Lazy Foo' - Setting up SDL on Windows.
For Debian and Ubuntu-based distros, you can use the following. Other distros will be similar.
Install a C++ toolchain via 'build-essential':
apt update
apt install build-essential
Install packages for Verilator and the dev version of SDL:
apt install verilator libsdl2-dev
That's it!
If you want to build the latest version of Verilator yourself, see Building Verilator for Linux.
Install the Homebrew package manager; this will also install Xcode Command Line Tools.
With Homebrew installed, you can run:
brew install verilator sdl2
And you're ready to go.