Cyclone IV


Grant Searle has a website that allows emulation of various old computers on a modern FPGA chip. This page builds on Gran't superb work using a newer FPGA chip that has more pins and more internal memory.

It is well worth reading Grant's pages in their entirety before embarking on this project. We are going to use much of Grant's code, but instead of using a Cyclone II board, we are going to use a newer Cyclone IV board, eg this board. These can be found on ebay by searching for Cyclone IV or the part number EP4CE6E22C8N. We chose this particular board as it was the least expensive (2015) and had both a JTAG (quick/temporary) and AS (slow/permanent) programming sockets. You will also need a "USB Blaster" to program the board - this converts USB to a 10 pin header.

This is a joint project by James Moxham (hardware) and Max Scane (software), and more details can be found over on the N8VEM forum.


The minimal build uses these parts and has a VGA display, Keyboard, SD card and onboard 3V switching regulator. It is run from an external 5V regulated supply. Additional components include up to to three serial ports and wifi, a second ram chip,  and the board also has provision for an onboard 5V switching regulator.

As per Grant's website, this minimal build is simple enough that it can be built without a PCB.

Files are transferred to the board via a clever program Max has written that enables both CP/M and FAT partitions to exist on the same SD card. A utility program can transfer files between the partitions. 

To solder up the board, I like to start with the shortest components first, like resistors. Once these are in, solder in the SD card. It is important to solder the SD socket before soldering in the socket for the fpga board. There are various SD sockets around - the one I used has two pins in the centre that join to one of the pads. One of these pins is ground and the other is card detect. Some sockets don't have the card detect. See the photo for a zoomed in version.

There are several options re the socket for the FPGA board - cutting up 40x2 headers, or using two single row headers. I cut up some 40x2 ones, and there is a gap in the middle, so I pulled the little gold plated socket out of those two pins. 

The FPGA board has two pins at the top corner for 5V and Gnd - on some versions the pins are facing up rather than down, and it may be necessary to unsolder these two pins and resolder them facing down. There is a reset pin which ends up underneath the board. A useful trick is to put the socket into the fpga board, then put all this into the board you are soldering up, and then solder the pins. Then it all aligns properly when inserting and removing the fpga board.

I added a couple of leds for 5V and 3V indication, but these are not strictly necessary for a minimal build. 

The switching regulator is a LM2574 DIP part. The parts specify a 330uH 1A inductor but at most it is likely to be 200mA, so the resistance should be maximum a few ohms. It will be roughly the size shown on the board - smaller ones may have too high a resistance. The parts came for multiple sources - VGA socket and ram chip from future electronics, the SD socket from sparkfun, the 40x2 sockets from ebay, the inductor from ebay, the 5V wall wart from ebay, the PS2 DIN socket from futurlec and all the other sundry components from futurlec as well. 


The schematic is here and the full Eagle files are here.  Parts here. The design uses switching regulators as a previous design build with linear ones ran too hot, and then needed large heatsinks. There is provision for three Max3232 RS232 chips on the board. There is also provision for an ESP8266 wifi module. There is also room for a second ram chip, giving 1 megabyte,  which we are planning to use for a ram disk, or for operating system additions, or for more MP/M users. The layout of the ram chip wiring looks a bit ad-hoc - this is so the traces end up on the board as short as possible.


As with Grant's design, software is put together as modules. Take a CPU emulation, and join it to UARTs and a clock  and a display driver. To start, head to altera and create an account. Then head to the download center and get the free version of Quartus. (Grant's board used an older version, but the latest version works fine with Cyclone IV boards). The download takes a few hours, and you may need to get the add-on for cyclone IV as well. The download can be a bit tricky - you can download a file for 2 hours and then find it is the 64bit instead of the 32bit version. Also when you run the file, it can take up to 4 minutes before windows comes back with a "do you want this program to install?". I'm still working out the best solution - one that worked was to get a 5gb .tar file instead of the 1.4gb .exe  as everything was included in that huge file.


Building VHDL code is described in more detail in Grant's website. It probably is not necessary to understand VHDL in order to build this computer, but in general terms, VHDL modules come with input and output pins, and are then connected together. Max and I have taken Grant's design and added a memory management unit. This allows any 4k block of memory to be mapped to any arbitrary location. We also have an interrupt controller, and there is some PLL code as the onboard xtal on the cyclone IV board runs at half the speed of Grant's board, and so we need to double that frequency in code. There are also optional extras, like using hardware multipliers on the Cyclone IV chip - these extra features all ended up too big for the Cyclone II, but there is plenty of spare room on the Cyclone IV.

August 7, 2015 version of VHDL files here

September 24, 2015 package here.  Includes Monitor and Rawrite and CPM2

One issue with the default version of Quartus is that it only produces a .sof file, ie the quick temporary file. To enable the .pof file, which is needed for a permanent load,  Assignments/Device/Device and Pin Options.../Configuration and check Use Configuration Device.

Using Quartus

There is a lot to learn in Quartus. In general, there is the VHDL code, with a 'main' program and then lots of sub programs. Then there is a section where you tell the software which lines connect to which physical pins on the chip. Then you compile the code and it creates two files - .sof, for jtag, and .pof, for AS. Then you download these to the chip. It is possible to distribute pre-compiled .pof files and download these and then not have to worry too much about the internal structure of the computer. 

To use Quartus, unzip the package in a folder (myfolder or whatever) - there should be three folders in this one - Components, ROMS and something like CycloneIV. Put the folder containing these three folders in the directory c:\altera\15.0 directory. Either open quartus, or navigate to the folder CycloneIV and double click on the file CycloneIV.qpf  This should open up the project. Click on the green triangle to compile - this takes about 4 minutes.

Plug in the usb blaster cable.

Near the right side of the toolbar is a button "programmer" (hover to find this). Click this button. If the usb blaster has already been plugged in, click on Hardware setup, and in Available Hardware Items, it should be listed. Double click the usb blaster, then click close. Now in the text box next to Hardware setup, the usb blaster should be listed.  Start with Mode/JTAG. Plug the 10 pin header into the jtag socket.

Now go to Add File... and browse to Output Files. There should be a .sof file listed - double click this. It should appear with a checksum and usercode, and next to this is a checkbox Program/Configure. If this is checked, then the Start button is enabled, and so click the start button and download.

For a permanent download, you need to set up Quartus to create .pof files. One issue with the default version of Quartus is that it only produces a .sof file, ie the quick temporary file. To enable the .pof file, which is needed for a permanent load,  Assignments/Device/Device and Pin Options.../Configuration and check Use Configuration Device.

Now go through the programmer again, but this time, change the Mode to Active Serial Programming. Add file..., select the .pof file, click the check box, click start, wait about 30s.

The SD card

Grant's computer has a ROM emulation which exists in VHDL. Rather than change this, we elected to leave it exactly as it is in the Cyclone II computer, and create a new monitor program that exists on the SD card. Max has written some clever software to do this. He has been using 2Gb SD cards, and has also written some different code to work with 1Gb cards. This involves creating an SD card with multiple partitions.

Max has written more detailed instructions, and to summarise:

1) Download a program called rawrite http://www.netbsd.org/~martin/rawrite32/  (included in the Sept 2015 package above)

2) Run this program. For the file to send, select fpga-boot.bin (for 2Gb) and send it to the SD card. It should auto select the SD card - don't send it to the computer's C drive, it may delete Windows!

3) Remove the SD card and reinsert it - Windows should ask to format this drive, so format as Fat16.

3a) If this doesn't work, or windows comes back with an error formatting, then low level reformat the sd card and start again. There is a low level formatting program in the September 2015 package. Be *very* careful to select the SD card, NOT your PC's hard drive!!

4) Copy cpm2-img.bin to the SD card (will copy to the fat partition)

5) Put the SD card in the multicomp, and reset (button on the underside of the board).

6) Space, then X, then capital Y. Instead of loading CP/M, this actually loads Max's debug monitor. If keyboard is in caps lock, change to smalls.

7) dir hsa0  (zero, not capital o)

8) image hsa0:cpm2-img.bin hsa2

9) Reset. Space, X, Y, then b hsa2

10) This boots into CP/M. There are some essential files, including a nifty one called FATDSK that copies files from the fat16 partition to the CP/M partition. Take out the card, put it in the PC and collect up some useful CP/M software, eg wordstar, programming languages. Copy them onto the card, put it back in the multicomp, then Reset, space, X, Y, b hsa2. Then fatdsk hsa0, then dir inside fatdsk, then something like

export myfile.com

and repeat for as many files as needed. Then type exit to get out of FATDSK and back to CP/M



Addit: October 14th, 2015, updated cpm2 image file here