deanthecoder / ZXSpeculator

Cross-platform ZX Spectrum emulator written in C#
https://github.com/deanthecoder/ZXSpeculator
MIT License
81 stars 8 forks source link
avalonia avalonia-ui avaloniaui emulation retro spectrum z80 zx-spectrum zx-spectrum-emulator zxspectrum

Twitter URL

ZX Speculator

ZX Speculator is a cross-platform ZX Spectrum 48K emulator written in C#. Main UI

Features

Download

Development and Testing

Developed on a Mac environment, ZX Speculator is also tested on Windows and passes all the ZEXDOC tests and FUSE emulator tests. Jetpac published by Ultimate Play the Game

Getting Started

Loading Files

Common ZX Spectrum image files (.z80, .sna, etc) can be opened from the File->Open menu.

Loading .tap Files

  1. Type Load "" in BASIC.
  2. The File->Open dialog will automatically open, allowing a .tap file to be specified.
  3. Enjoy the loading experience.

Keyboard

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

Joystick

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

Building From Source

Prerequisites

Setup

The project is provided as C# source code:

  1. Clone the repository from GitHub.
  2. Open the solution (Speculator.sln) in your preferred IDE.
  3. Build and run the application.

Videos

There's a YouTube playlist showing some classic games played in the emulator.

Experiments - Raytracer

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.

Experiments - Conway's Game Of Life

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!

Experiments - Retro Fire

C compiled into Z80 machine code (here). Too slow to call 'real time', but not bad for the Speccy.

Experiments - The Matrix

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.

Experiments - 10PRINT

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!

Experiments - Sandy Situation

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.

Experiments - Twister

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.

Experiments - Breakout

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

Experiments - One Small Step

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.

Contribution and Improvements

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

Credits

Flux Capacitor icon licensed by CC BY 4.0.

Useful Resources