I recently embarked on a new hobby in addition to programming and photography, which is why this blog has been lacking new content for quite some time.

I have an interest in producing my own single board computer in the mould of the old 8-bit home computers to allows users to learn to program and experiment using BASIC and without the cost and distractions that come with an internet connected PC.

My current avenue of investigation has led me to the fascinating world of Field Programmable Gate Arrays (FPGA’s) which is a way of developing new chips and hardware using a form of configurable silicon. Normally producing a chip (ASIC) would typically cost millions of dollars, but FPGA’s are reaching the point where they are powerful enough to produce quite major systems and at a reasonable price.

The circuits within FPGA’s can be designed using schematic capture software, like you would traditionally use for simple circuits. However, most chip designs are developed using special high level hardware description languages (HDL’s) such as Verilog or VHDL (the former is popular in the States, and the later is popular in Europe). These languages let you describe the hardware that special compilers turn into circuits which are then programmed into the FPGA (the process is called synthesis).

I purchased the Terasic DE2-115 FPGA development board from parallax.com (who supply their Propeller processor as an open source core that can be programmed into the FPGA), which comes with a very powerful Altera Cyclone IV FPGA and most of the peripherals a typical system would require:

I’ve always had an interest in home computers since my family purchased a TRS-80 in 1980. FPGA’s are being widely used to emulate these home computers in hardware, since they are able to fully recreate any hardware from the 8/16 bit era.

The first thing I wanted to do once I had the board was to look at what emulators may have been developed already that I could try out. Unfortunately the DE2-115 is quite an expensive board and the only emulators I could find had been developed for the previous DE1 or DE2-70 boards which have different on-board support components. I decided the best way for me to learn how to develop hardware in Verilog or VHDL was to get stuck in converting these emulators to work on my board.

I came across a Spectrum Emulator for the DE1 board, developed by Mike Stirling which had also been ported to the DE2-70. More information on this emulator which applies equally to the port can be found on Mikes website here:

http://www.mike-stirling.com/retro-fpga/zx-spectrum-on-an-fpga/

I’ve been working on getting this ported to the DE2-115 for the past few weeks and finally have a fully working port. The Emulator supports all the following features:

* Spectrum 48k, 128k or +2A emulation

* ZXMMC+ compatible interface (SD loading and paged flash and RAM support)

* ResiDOS support - Supports loading TZX and SNA files directly from SD

* TV and VGA mode (see Mike’s article for more info)

* Regular and AY-3-8912 sound emulation

* Load tapes (or audio streams) via Line In connection

The following switches are used on the DE2-115

* SW0 - ZXMMC+ boot - Down (default) RAM / Up Flash

* SW1 - ZXMMC+ ROM - Down (default) ROM / Up Flash

* SW7 - Video mode - Down (default) TV / Up VGA

* SW9 - System Reset - Down (default) off / Up On (needs to be up to work)

The emulator needs the various ROMS of the different Spectrums programmed into the DE2’s onboard Flash in order to work. Mike’s article describes where they should be placed, but the ControlPanel app for the DE2 makes this very confusing because the offsets are specified in 16 bit words, even though the Flash memory is only 8 bits wide. For convenience I have compiled a single ROM file which you can just program into address 0 of the Flash using the DE2 Control Panel application and everything will then just work. I have placed the ROM file in the ROM subdirectory of the main project source, which is located here (if anyone objects to this, then I will need to remove them):

https://dl.dropboxusercontent.com/u/7799729/geek/spectrum_release_20110901_DE2-115-Stripped.zip

Here is a a quick video I put together of me loading and playing Manic Miner on the Terasic board. This was loaded using PLAYTZX with the Line Out of my Mac connected to the Line In of the Terasic board (complete with flashing borders):

To get the ResiDOS ROM working, I recommend you download and play the TZX file into your DE2-115. Once it has been installed it will always be there on future boots as it installs itself into FLASH. Do the following to install ResiDOS:

* Download the ResiDOS TZX from the link below for the ZXMMC+

* Download PlayTZX for your OS

* Connect the Line Out of your PC to the Line In of the DE2

* Boot the Emulator with SW0 and SW1 up (ZXMMC+ Flash mode)

* Press Z to start 48k mode

* Press SHIFT-J (load) then CTRL-P twice (double quote) and press ENTER

* Run PlayTZX residos.tzx to start the tape loading on your PC

* Once it completes press ENTER twice on the DE2 to complete the installation

ResiDOS Link: http://www.worldofspectrum.org/residos/index.html

Once installed, on future boots if you start with SW0 and SW1 both up and then press R it will take you straight into the ResiDOS shell. Unfortunately ResiDOS only seems to work in 48K mode so you will have fun trying to find the right Spectrum keys. I recommend you get a picture of the Spectrum keyboard for reference. Some useful keys to remember include:

* SHIFT-J - LOAD

* SHIFT-R - RUN

* CTRL-P - “ (double quote)

* CTRL-M - . (full stop)

* CTRL-5 - % (percent used for ResiDOS commands)

Some useful ResiDOS commands include:

* %dir - Directory the SD card in the DE2

* %snapload "filename.sna” - Load file from SNA or Z80 snapshot

* load %“filename” - load file from SD (e.g. BAS files)

Also, you can install the optional TAPEIO package which lets you load TZX and TAP files directly from the SD card. This is a little tricky so I recommend the following steps to install it:

* Download the PKGINST.BAS from the plugins page and place it on your SD card

* Boot into ResiDOS

* Type LOAD %“PKGINST.BAS” to load it from SD

* Press enter through the prompts, until you get to load it from tape

* Use PlayTZX tapeio.tzx again to load tapeio.tzx from your PC

* Once loaded finish the install by pressing ENTER through each prompt

At the end you can use the following command to load any .TZX or .TAP file:

* %tapein “filename.tap” or “filename.tzx”

A couple of gotcha’s exist with the emulator. First, not all PS2 keyboards will work with it; I have found some modern PS2 keyboards send code 0xAA to the PC and won’t work until the BIOS responds. Because the keyboard code is unidirectional, these keyboards will not work. Also, not all VGA monitors support the low frequency used by the emulator.

I hope you find the above guide useful and look forward to any comments you have on the emulator. Massive thanks to Mike Stirling for doing all the hard work in making the DE1 version.