ZX Spectrum on Altera DE1 – Source Code

Manic Miner in-game screenshotSorry it took so long, but I’ve finally cleaned up the source code ready for publishing, and here it is.  This contains a Quartus project file, so it should load and compile straight away.  I used Quartus 9.1 Web Edition, available from the Altera website.  There is also a pre-compiled .sof image which should work straight away if you have a DE1.

A full write-up will follow, but here is a quick summary:

The implementation is of a standard PAL 48K Spectrum.  IO is via the DE1’s existing interfaces, with the video hardware able to drive either a normal TV (via RGB SCART) or a PC monitor.  In the latter case the picture is double-scanned to obtain the required line scan rate.  A PS/2 keyboard can be connected although you will probably need a picture of a real Speccy to work out what all the keys do!  Some key combos like caps-lock and escape (BREAK) do actually work, though. Audio input and output are both available through the normal jacks, and programs can be loaded from tape or by using something like playtzx on a PC.  Loading images from SD card is planned but not yet implemented.

The design runs from a PLL-derived 28 MHz clock with clock-enables used to time-slice RAM access between the CPU and video hardware.  The CPU runs for one cycle in eight, resulting in the required 3.5 MHz cycle time.  Note that because of this time-slicing there is no RAM or IO contention, so this is slightly faster than a real Spectrum meaning that some games and turbo-loaders don’t yet work properly.  The CPU is a synchronous T80 core connected to the rest of the hardware through some address decoding and multiplexing logic.  The ROM image is contained on the FPGA, but the external SRAM is used for the Spectrum’s RAM, and the entire 48K is accessed over one time-sliced bus.  The address applied to the SRAM comes from either the CPU address bus or the video logic depending on whose turn it is.

On the IO side the ULA’s single IO port is implemented.  The PS/2 keyboard interface applies key up/down events to an 8×5 matrix representing a real Spectrum’s keyboard.  This matrix is addressed by the CPU and routed to the ULA IO port as in the real thing, so no changes to the ROM are needed.  Audio is fed both ways through the Wolfson codec which has its settings loaded on reset by a simple I2C loader block.  The register settings are hard-coded into this logic.  A bidirectional I2S<>parallel interface is used to interface the audio bus with the ULA register.  For recording (EAR in) the sign-bit from the capture side is used – some hysteresis would probably be beneficial here.  Note that the audio codec has its own 24 MHz clock and operates asynchronously with the rest of the design.

Four of the slide switches are used:

  • SW9 – /RESET – Down to reset, up to run
  • SW8 – PLL reset – Leave this down
  • SW7 – Slow mode – Allows CPU operation to be traced on the LEDs – Normally leave down
  • SW6 – PAL/VGA – Down for PAL (SCART) or up for VGA (PC monitor)

18 thoughts on “ZX Spectrum on Altera DE1 – Source Code

  1. aix


    First of all, great work!

    Your domain name suggests you’re in the UK. Do you know of a good place to buy a DE1 in this country?


  2. Mike Post author

    Hi aix. First of all, apologies for taking so long to approve your comment – for some reason it never sent me a notification email.

    I actually bought my DE1 about a year ago from Digikey. They will give you pricing in GBP and they take care of import duty, although you still have to pay the VAT and a small cash-on-delivery fee to the UPS driver. At the time it still worked out a little bit cheaper doing this than getting it from Farnell, which is probably an easier option if they still have it.

  3. Kpuchatek

    Another attempt to emulate ZX Spectrum. I hope more successful than other unfinished. What about AY emulation ?
    Is it possible to connect both keyboard & mouse to this board ? I can see only one PS/2 port.

  4. Dirk

    If you think its incomplete then finish it.
    Sources are available.
    With a small modification you can connect a PS2 Mouse to the DE1 board.

  5. Kpuchatek

    >>With a small modification you can connect a PS2 Mouse to the DE1 board.

    Any reference/links how to do that ?
    To finish I need start first 🙂
    DE1 board is best FPGA on market I think.
    I’m happy Mike released source for it. Thanks a lot !

  6. Jeff Braine

    Hi Mike, just wanted to thank you for making your project open-source, and to let you know that I’ve used it as a foundation for my own project, ZX Prism.

    My project is an FPGA based “Next Gen” Spectrum sporting more memory and more advanced (but still feasible to use from basic) screen modes.


    I intend my project to be open source as well, and of course will keep your copyright in all sections which are based on your code.


  7. Mike Post author

    Hi Jeff,

    I had a quick look at your project and it looks very interesting – I will be having a proper read later. I was intending to revisit the Speccy at some point soon to fix a few bugs, so I would be glad to receive patches for anything you fixed in the meantime. I am aware that there are some timing issues in the ULA, causing the 8 random pixels at the top-left in VGA mode, for example.

    The project is actually in a git repository here. Maybe it would be worth me copying it to github or similar so that you can have access to its development history?


  8. Peter

    Excellent project, I just got it working on my board a few minutes ago, it was kinda low on my screen though I think it was my LCD’s fault.
    I’ve been dying to have a spectrum again since I moved to Canada 10 years ago, I think this may be a winner! 🙂 Many thanks for you hard work. I hope you can find a way of loading games in via the SD card though.

  9. Mike Post author

    Hi. Glad you like it. The video timing is based on the real thing, but there is no real reason why you couldn’t tweak the sync timings to help get a better position on your screen.

    You can load from SD using the ZXMMC features, although I admit that this is a bit fiddly and it would be nice to have some hardware tape emulation similar to the disk emu in Minimig. Maybe I will add this somewhere down the line!


  10. lak

    Hi, great 48K spectrum project on the DE1.
    Any tips/plans to correct the 8 random pixels issue?
    (your 128K project is also fantastic by the way)

  11. Mark

    Mike, I just found your site and loaded your ZX Spectrum core on my DE1. Works great thank you for creating and sharing this.
    I also stumbled across a iOS app called Speccy Tape that makes loading tzx files a breeze. Seems like today is my lucky day.

    One question: Is the Minimig’s break out board compatible with your core for Joystick support?


  12. Mike Post author

    The speccy joysticks were all fairly trivial. e.g. the Sinclair one just emulated the cursor keys, and the Kempston was just a simple 5-bit input port (incompletely) address decoded at IN 31 iirc. There isn’t any Joystick logic in there as it stands, but adding it should take a matter of minutes.

  13. BrancoRP2000

    congrats for your Job.
    A bought recently an Altera DE 1 board but the .sof runs with a lot of problems. Some times it freezes in the black reset screen of the spectrum. Some times it stays reseting all the time.
    Do you know where is my mistake?

  14. Mike Post author

    Could be that your particular board has a different SRAM or Flash part with slightly different timing requirements. There are certainly some DE1 boards with different SDRAM chips.

    If you can identify the part number for the RAM and Flash I can compare it with my board when I get a minute.

Leave a Reply

Your email address will not be published. Required fields are marked *