ZX Speculator is a cross-platform ZX Spectrum 48K emulator written in C#.
- Cross Platfom: Built using Avalonia, ensuring compatibility across various platforms.
- File Format Support: Compatible with .z80, .bin, .scr, .tap, and .sna files.
- Archive Support: Load files directly from
.zip
archives. - Display: Optional CRT TV and 'Ambient Blur' effects.
- Joysticks: Kempston and Cursor joystick support.
- Sound: Utilizes OpenAL on Mac and Windows for sound emulation.
- Integrated Debugger: Includes a built-in debugger for examination of the Z80 CPU state, including:
- Instruction stepping.
- Breakpoints.
- Instruction history.
- Rollback: Die in your favourite game? Accidentally delete a line of code? Continuous recording allows you to 'roll back' to an earlier time. (
F1
will roll back 5 seconds.) - Theming: The Sinclair BASIC ROM can be customized to allow for:
- Classic ZX Spectrum input vs a per-character typing strategy. (Courtesy of the JGH Spectrum 48K ROM by J.G.Harston)
- Selectable colors schemes and fonts.
- Download from the Releases section.
- Mac users may need to run the following command to unblock the application:
xattr -d com.apple.quarantine /Applications/ZX\ Speculator.app
Developed on a Mac environment, ZX Speculator is also tested on Windows and passes all the ZEXDOC tests and FUSE emulator tests.
Common ZX Spectrum image files (.z80, .sna, etc) can be opened from the File->Open menu.
- Type
Load ""
in BASIC. - The File->Open dialog will automatically open, allowing a .tap file to be specified.
- Enjoy the loading experience.
Move the mouse pointer to the small keyboard icon at the top-right of the screen to see a representation of the ZX Spectrum keyboard. Many keys on a modern keyboard are automatically mapped to their ZX Spectrum equivalent. For example, backspace, quotes, math symbols etc.
The left shift key maps to CAPS SHIFT on the Spectrum, and the right shift key maps to SYMBOL SHIFT.
ESCape will reset the machine.
The emulator will mimic either a Kempston or Cursor joystick.
In both cases the keyboard arrow keys are used for direction control, and the backslash or backtick keys will 'fire'.
- .NET compatible IDE, such as JetBrains Rider or Visual Studio 2022.
- Basic knowledge of C# and emulation concepts.
The project is provided as C# source code:
- Clone the repository from GitHub.
- Open the solution (
Speculator.sln
) in your preferred IDE. - Build and run the application.
There's a YouTube playlist showing some classic games played in the emulator.
As my other hobby is writing GLSL shaders on ShaderToy (See here for my GLSL Shader Shrinker application), I thought it'd be interesting to try a 'cross over' project.
I've taken inspiration from the Human Shader project and recreated the algorithm using ZX Spectrum BASIC, using this emulator.
Here's the result:
Earlier version, with a basic dither:
First iteration: Solid blocks:
I've included a .sna
snapshot of the code here.
I realized I had never written a Conway's Game Of Life, so decided to make one using the emulator.
Performance in this BASIC version isn't great... (See here - Requires the JGH ROM)
...so I rewrote it in C, compiled into Z80 machine code (here). Muuuch faster!
C compiled into Z80 machine code (here). Too slow to call 'real time', but not bad for the Speccy.
C compiled into Z80 machine code (here). This one runs in real time, which surprised me.
I first populate the entire screen with characters (black on black), then build up a 768 element array of color values with a repeated sequence ranging from green to bright green, white to bright white.
This array is then used to set the colors on the screen, and a memmove
command is used to scroll the buffer by one byte. This keeps the framerate up as it's only the color attributes that change - Not the characters on the screen.
C compiled into Z80 machine code (here).
The screen is filled with forward and backslashes (Drawn with a small gap in my case), then I randomly fill areas of the screen. Quite relaxing to watch!
C compiled into Z80 machine code (here).
Iterating over a fixed number of grains, advancing each depending on what is below them. I did try a different approach of iterating through all cells in an x/y grid which worked well, but wasn't anywhere near as performant.
I'm making use of the z88dk's 'chunky' pixel blitting routines too.
Pushing my graphical skills on the ZX Spectrum, resulting in the creation of a classic 'twister' effect. The code is written in C and compiled into Z80 machine code (here) - Needed to keep the performance up.
The twister effect, a staple of early computer graphics and demoscene productions, seemed like the perfect challenge - I've always wanted to make one of these but never got round to it. Helped with details from 8bitshack. It takes a while to complete the precaching, but I like the result.
Two balls fighting for dominance! I saw an effect similar to this on Twitter and thought it was a great idea. A little more of a 'demo-style' with this one - I've added a DTC logo (which I'll developed more in the future).
The code is written in C and compiled into Z80 machine code (here).
This is based on a GLSL shader I wrote a while ago. I built a library of GLSL-like functions in C to recreate the original code, then ran it over many hours.
The final quality was achieved with a Floyd-Steinberg dithering algorithm. A random dither is much easier to implement, but the result was way too noisy.
The executable is here.
ZX Speculator is an ongoing project and contributions are welcome. Whether it's improving emulation accuracy, testing on different platforms, or enhancing existing features, your input is valuable (although I can't always promise a fast response, as this is a side project).
Flux Capacitor icon licensed by CC BY 4.0.
- The Undocumented Z80 Documented
- Z80 Undocumented Instructions (World Of Spectrum)
- ClrHome's Z80 Opcode Table
- ZX Spectrum Keyboard Cheat Sheet
- Z80 Instruction Exerciser (zexall, zexdoc)
- JSMoo Z80 tests
- JGH Spectrum 48K ROM by J.G.Harston.
- z88dk C to z80 compiler
Feel free to follow me on Twitter for more updates: @deanthecoder