Skip to content

oldbit-com/Spectron

Repository files navigation

Build and Test

Spectron ― ZX Spectrum 16/48/128 Emulator ☺

Here is Spectron, my personal ZX Spectrum emulator written in C# and Avalonia UI. It emulates the classic ZX Spectrum 16K, 48K, and 128K computers.

It is accurate and stable, capable of running most games and demos without issues, including support for loading protected tapes.

Spectron is a cross-platform emulator that runs on Windows, Linux, and macOS. Developed primarily on macOS, it is well-tested on that platform, while also showing solid performance on Windows. Further testing on Linux is ongoing.

This project is a hobby I have always wanted to pursue. It has been both a lot of fun and a rewarding challenge. While many other emulators exist, this is my own personal take.

The ZX Spectrum was my first computer, and I still have a deep affection for it. I plan to continue maintaining and evolving this project, as I use it personally to enjoy classic games and demos.

Main Window

Features

  • Emulation of classic machines: ZX Spectrum 16K, 48K, and 128K
  • Time Machine: Rewind and continue from any point in the past
  • State persistence: Emulator state is automatically saved and restored on restart
  • Wide format support: SNA, SZX, Z80, TAP, TZX, MDR, TRD, and SCL (including ZIP archives)
  • Support for POK trainer files
  • High accuracy: Precise timings, including memory and I/O contention
  • Floating bus support
  • Multicolor screen effects
  • ULA+ support
  • AY-3-8912 sound chip emulation
  • DivMMC emulation
  • Beta 128 Disk emulation
  • Microdrive emulation
  • Kempston mouse emulation
  • ZX Printer emulation
  • Integrated tape and disk viewers
  • Adjustable emulation speed
  • Keyboard-based joystick emulation: Kempston, Sinclair, Cursor, and Fuller
  • Audio and video recording
  • Support for alternative and custom ROMs
  • Built-in debugger
  • Favorites manager
  • Screen effects: Blur and CRT/Scanlines
  • And more to come...

Spectron relies on several custom libraries developed specifically for this project:

Library Description
Z80 Generic Z80 CPU emulator
Files Handles TZX, Z80, SNA and other file formats
Beep Basic audio player, cross-platform, native
Joypad Gamepad handler, cross-platform, native

The solution consists of several projects:

Project Description
Spectron Avalonia-based UI and main application logic
Spectron.Debugger Fully featured code debugger, including UI and controls
Spectron.Emulation Core emulation engine
Spectron.Basic Basic interpreter and related utilities
Spectron.Disassembly Z80 disassembler, used by the debugger
Spectron.Recorder Audio and video recording functionality

Quick demo

Spectron

Releases

There are some test releases that can be found in the project Releases if you don't want to build the project. These are self-contained and do not need .NET Framework to be installed separetely.

Running the emulator

Requires .NET 10 to build and run the emulator. Grab the latest code from the repository, build and run the emulator:

dotnet build -c Release
dotnet run --project ./src/Spectron

You can also run the emulator from the Releases page.

Command line options

Command lines allow overriding most of the default options and loading a specified file. Full list of available commands is here.

Testing and compatibility

  • Passes floatspy v0.33 (RAMSOFT) floating bus test in both 48k and 128k mode
  • Passes HALT2INT v3 (Mark Woodmass) test in both 48k and 128k mode
  • Passes EIHALT (Mark Woodmass) test in both 48k and 128k mode
  • Passes Super HALT Invaders (Mark Woodmass) test
  • Passes btime (Jan Bobrowski) test
  • Passes ptime (Patrik Rak) test

Test results can be found in the Results directory. Test programs can be found in the Tests directory.

CPU Emulation

I have developed a custom Z80 CPU emulator library for this project. The emulation is highly accurate and supports many undocumented instructions, as well as memory and I/O contention.

Session Persistence

When the emulator is closed, it automatically saves its current state, which is then restored upon restart. This behavior can be toggled in the settings.

Tape Loading

Tape loading is supported for TAP and TZX files (including ZIP archives). Three loading speeds are available:

  • Normal: Loads the tape at the original speed, including border and audio effects.
  • Accelerated: Loads the tape at the maximum possible emulator speed.
  • Instant: Loads the tape instantly into memory, bypassing the loading sequence. This mode works for files using standard ROM loaders.

Tape Saving

Tape saving is supported for TAP and TZX formats at two speeds:

  • Normal: Saves at the standard speed with border and audio effects.
  • Instant: Saves instantly by reading the current memory state.

Tape Browser

The Tape Browser allows you to inspect the contents of the currently loaded or saved tape. You can view blocks, their types, and basic information. Selecting a block allows you to load it using the standard LOAD "" command.

Snapshots

The emulator supports saving and loading snapshots in SNA, SZX, and Z80 formats. It also features a custom .spectron format, which is recommended as it captures most emulator settings.

Screen

Multicolor screen effects and border effects are fully supported. The border size can be adjusted in the settings. Additionally, screen effects like Blur and CRT/Scanlines can be applied to simulate an old TV feel.

Floating Bus

Floating bus emulation is supported for both 48K and 128K modes, which is required for a small number of specific games.

Alternative ROMs

Spectron allows you to select from various built-in alternative ROMs, such as TR-DOS and BBC Basic (which require 128K mode). Custom ROM files can also be loaded.

Audio

Standard beeper audio and AY-3-8912 sound (mono or stereo ABC/ACB modes) are supported. AY is enabled by default in 48K mode but can be disabled.

Audio playback is powered by Beep, a custom cross-platform audio library developed for this project.

Joystick and Gamepad

Emulation is supported for Kempston, Sinclair, Cursor, and Fuller joysticks. External gamepads and joysticks are also supported (tested with a variety of controllers). Buttons can be mapped to joystick or keyboard keys. The standard keyboard can also serve as a joystick, using the arrow keys for directions and Space for Fire.

Note

Controller compatibility may vary by platform. This is an experimental feature.

ULA+ Support

ULA+ mode is supported and can be enabled in the settings.

DivMMC

DivMMC emulation is supported and can be enabled in the settings. It is based on esxDOS 0.8.9 and requires a disk image containing the esxDOS system files. Sample disk images are available here.

Up to two SD card images are supported, and changes can be persisted to the images. RTC support is available via the RTC.SYS file, allowing DivMMC to use the current system date and time.

Microdrives

Microdrive emulation supports up to eight drives and can be enabled in the settings. MDR image files can be loaded and saved. Note that other Interface 1 features are not currently emulated.

Beta 128 (TR-DOS)

Beta 128 Disk Interface emulation supports up to four drives (TRD and SCL formats). It uses ROM version 5.03. To invoke TR-DOS, use RANDOMIZE USR 15616 from BASIC, or use the Pentagon 128 ROM for easier access.

Time Machine

The Time Machine feature allows you to rewind the emulation and resume from a previous point in time. The recording interval and history depth are adjustable in the settings.

Video and Audio Recording

Audio and video recording are supported. This is an experimental feature and performance may vary by platform. Changing emulator settings during recording may lead to unexpected results.

Audio

Audio is recorded in WAV format (PCM 16-bit, 44,100 Hz, mono or stereo). No external dependencies are required.

Video

Video recording requires FFmpeg. Videos are encoded as MP4 using the H.264 codec at 50 FPS. Rendering options like scaling and border size are adjustable.

Recording is processed in the background after it stops, leveraging FFmpeg to combine the captured frames and audio.

Debugger

The built-in debugger allows for inspection of CPU registers, memory, and disassembly. It supports code stepping and breakpoints. For more details, see the Debugger documentation.

Favorites Manager

The Favorites Manager helps organize your favorite games, demos, and files, accessible directly from the main menu. For more details, see the Favorites documentation.

Resources

About

Cross platform ZX Spectrum emulator written in C#. Accurately emulates classic ZX Spectrum computers: 16K, 48K and 128K models.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages