Design Your Own Computer
Welcome to this series where you will learn how to Design Your Own Computer on an FPGA!
Overview of series
In the first few episodes we'll be focussing on the VGA output, essentially building a (small) GPU. The reason is that this will give us excellent possibilities later on to view the internal state of the CPU.
Later we'll design and implement the 6502 processor. This is the same processor that was used in e.g. the Commodore 64 computer from the 1980's. There is an abundance of information on this processor on the Internet. In later episodes I'll provide more links.
In the end I would like to build a web server that can run on this computer.
Of course, the ultimate goal is to have fun building stuff!
The computer we're building will be running on an FPGA board, and inside the FPGA there will be:
- VGA interface (GPU)
- Memory (RAM and ROM)
- 6502 CPU
- Keyboard interface
- Ethernet interface
We will be designing and building these blocks roughly in the above order.
List of episodes:
- "Hello World". Here you will generate a checkerboard pattern on the VGA output.
- "Binary Digits". Here you will learn how to display a string of binary digits on VGA.
- "Adding memory to the system". Here we will add memory to the system, and display accesses on VGA.
- "Adding hexadecimal output to VGA". Here we will implement a complete font and show data in hexadecimal format.
- "Datapath". Here the skeleton of the CPU datapath will be developed. Instructions implemented: 1/151.
- "Load and Store". We will add instructions that load and store in memory. Instructions implemented: 4/151.
- "Control logic". The control logic will be greatly expanded. Instructions implemented: 4/151.
- "ALU". Here the Arithmetic and Logic Unit will be added to the CPU. Instructions implemented: 16/151.
- "Branching". We add conditional jumps to allow brancing. Instructions implemented: 31/151.
- "Assembler". Now we use an assembler to compile programs with. Instructions implemented: 31/151.
- "Zero Page". We build on the datapath to support the zero-page addressing mode. Instructions implemented: 39/151.
- "Stack Pointer". We add the stack pointer and can now support subroutine calls. Instructions implemented: 45/151.
- "More ALU". We expand the ALU and add several more instructions. Instructions implemented: 64/151.
- "Registers X and Y". We add the two remaining registers 'X' and 'Y'. Instructions implemented: 90/151.
- "Indexed addressing". We implement the indexed addressing modes. Instructions implemented: 132/151.
- "Indirect addressing". We finish (almost) the CPU by adding support for indirect addressing modes. Instructions implemented: 148/151.
- "Software Interrupts". We add the remaining three instructions. Instructions implemented: 151/151.
- "Hardware Interrupts". We finish the CPU by adding support for hardware interrupts.
- "C Runtime". We modify the toolchain to allow CPU to run C programs.
VGA part 2
- "Text display". We expand on the VGA module by adding a screen memory to contain the text to be displayed.
- "Reading from Display memory". We make it possible for the CPU to read from the character and colour memories.
- "Memory Mapped I/O". Now we allow the CPU to control e.g. background colour.
- "Interrupt Controller". Here we build an interrupt controller.
- "Keyboard". We are now ready to add the keyboard interface.
- "Sample Programs". We now demonstrate some sample programs for our new computer.
- "Ethernet PHY". Here we start communicating with the Ethernet PHY.
- "Rx DMA". Now we can receive Ethernet frames.
- "Tx DMA". Now we can send Ethernet frames.
- "Protocol Stack". Now we can reply to ping!
More to come soon...
To get started you need an FPGA board. There are many possibilities, e.g.
- Nexys 4 DDR (from Digilent). This is the one I am using (but somewhat of an overkill for this project).
- Basys 3 (from Digilent). Less expensive.
- Go board (from Nandland). Even less expensive.
Make sure that the FPGA board you buy has (at least) the following features:
- VGA connector
- USB input connector (for keyboard)
- Crystal oscillator
- Ethernet PHY (optional)
FPGA toolchain (software)
You need a tool chain for programming the FPGA. There are three major FPGA vendors:
- Intel (formerly Altera)
The Nexys 4 DDR board uses a Xilinx FPGA, and the toolchain is called Vivado. Use the Webpack edition, because it is free to use.
Recommended additional information
I recommend watching the video series Building an 8-bit breadboard computer! by Ben Eater. He goes into great depth explaining the concepts and elements in a computer. The design we're building will be somewhat more elaborate and have more features. This is largely due to the many possibilities of using FPGAs.
I also recommend watching (at least the first half of) the video series Computation Structures from MIT. These are university lectures explaining very clearly the concepts involved in digital design.
I will in this series assume you are at least a little familiar with logic gates and digital electronics.
I will also assume you are comfortable in at least one other programming language, e.g. C, C++, Java, or similar.
I'm currently working as a professional FPGA developer, but have previously been teaching the subjects mathematics, physics, and programming in High School. Before that I've worked for twelve years as a software developer.
As a child I used to program in assembler on the Commodore 64. This "heritage" is reflected in some of the design choices for the present project, e.g. choosing the 6502 processor.