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)
Leave a comment

10 Comments.

  1. –Mike– Been waiting for this, thank you!

  2. Mike,

    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?

    aix

  3. This seems very cool. Havn’t tried fPGA cards at alla before, but this tempts me to buy one.

  4. 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.

  5. 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.

  6. 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.

  7. >>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 !

  8. http://www.mikrocontroller.net/attachment/27279/DE2_Maus_2.jpg

    You need also a ps2 Y-Adapter for mouse and keyboard,too.

    Another source for mouse and joystick adapter:
    http://gamesource.groups.yahoo.com/group/minimigtg68/
    You have to join to this group to see the schematics.

  9. 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.

    http://zxprism.blogspot.com/

    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.

    Jeff

  10. 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?

    Mike

Leave a Reply


[ Ctrl + Enter ]