Crates.io | spectrusty |
lib.rs | spectrusty |
version | 0.4.0 |
source | src |
created_at | 2020-09-21 16:09:49.99463 |
updated_at | 2022-12-18 00:51:22.837311 |
description | SPECTRUSTY is a library for building highly customizable emulators of the ZX Spectrum computer series and clones. |
homepage | https://royaltm.github.io/spectrusty/ |
repository | https://github.com/royaltm/spectrusty |
max_upload_size | |
id | 291215 |
size | 427,273 |
There are plenty of ZX Spectrum emulators, a large portion of them are open-source, some very advanced, most are done just for fun. But except some examples of Z80 CPU emulators, each of the ones I've seen is a complete program, with code that is not easy to build upon or port to another system. Most that I found is written in C, a lot of them in Java, and even some in javascript.
The notable example is Free Unix Spectrum Emulator written in C with pleasantly readable code. The components of the emulator are nicely separated, with high cohesion but unfortunately, here and there sprinkled with a vast range of global variables. However, I can imagine that with sufficient patience and skill you can build successful projects upon such a foundation.
SPECTRUSTY was built from scratch, partly for fun, but also as a Rust abstraction testing facility. I needed some theme to dive deep into the Rust OO model for educational purposes, and have chosen ZX Spectrum because it's such a simple machine thoroughly reverse-engineered and documented. It was also the first computer that I've owned. From the start, the goal was not to build a complete emulator program, but rather a library, upon which you can relatively easy build emulators that suit your particular needs.
In this library, every component is a separate entity that doesn't know anything about the world and realizes its purpose via trait interfaces. Most of the structs are defined with generic parameters that can be substituted by the complementary components which complete or extend their base functionality.
To create your emulator with SPECTRUSTY first, you need to choose the components you need, then choose the way to glue them together, and then realize their functions via trait methods.
Because of the heavy use of polymorphism and static dispatching the separate code is being created due to monomorphisation for every set of spectrum chipset, device set, and the CPU. This may result in a rather large output code if you want all these sets to be available at run time. On the other hand, the produced code is quite efficient.
Because the best way to learn new things is by example, I invite you to see the tutorial.
Several examples of what can be built with SPECTRUSTY can be also found in the examples directory, provided as separate crates.
Because of ZX Spectrum's popularity, there is a lot of technical information available from various sources. On the other hand, the certainty of the information has been deluded because some of the resources are contradicting each other. Unfortunately, my access to the real hardware is very limited - I'm a proud owner of a single TC2048, that is still working today. If you'd find something that is being emulated incorrectly, please don't hesitate to submit an issue.
Below you'll find the featured facilities of the library and its roadmap.
The Zilog's Z80 CPU emulation is performed via a separate z80emu crate that can emulate NMOS
, CMOS
, and BM1
variants of the CPU.
The video and contention timings for the Sinclair/Amstrad machines are thoroughly tested and at least match those of the Fuse emulator. The SCLD implementation has no separate timings implemented yet, so for now it can borrow the timings from Sinclair models.
T4
, however the IO_IORQ
signal of Z80 is active between T1
and T4
and Fuse port read/write is timestamped at T1
. This is especially important for exact emulation of border effects.- .SNA format loader/saver
- .Z80 v1/2/3 format loader/saver
- .SLT
- .SZX
- .TAP format reader/writer, pulse encoder/decoder
- .TZX format reader/writer, pulse encoder/decoder
- .PZX format reader/writer, pulse encoder/decoder
- .RZX format reader/writer, recorder/player
- .MDR microdrive format reader/writer, filesystem browser
- .SCR format loader/saver
- .ZXP format loader/saver
- .AY player format parser
This version of spectrusty
requires Rustc version 1.59 or greater due to dependent crates usage of Rust 2021 Edition and other API stabilized in this version.
The SPECTRUSTY library is available under the terms of the GNU LGPL version 3 or later.
Examples, tests, and benchmarks are available under the terms of the GNU GPL version 3 or later.
ROM
files found in the resources directory are made available under different terms.