This is the home page of the ZX Ecosystem: a library that provides your modern C++ programs with the look and feel of an authentic ZX Spectrum! The library includes support for the main user interfaces of the original ZX: the screen, the keyboard and the sound, replicating really closely their behaviors under the ZX operating system, and it also has built-in support for the mouse, if you have one; it even has support for creating ZX-like GUIs!
The uses of this library can be very diverse:
This library has been built upon the experience obtained through other works that I have done around the ZX Spectrum, such as the GIMP plug-in for generating ZX-like images and the Nutria ZX Spectrum emulator. In particular, if you wish to program the PC with the ZX Spectrum behaviour in the original Sinclair BASIC instead of C++, you can use the ZXBasicus utility.
Since version 4.0.0, the ZX Ecosystem library is written in C++17 (in C++11 for previous versions), thus it is intended for modern C++ programming. For installing it, just follow these steps:
#include <SDL2/SDL.h>
.zxecosystem.h
header.The structure of your programs may be diverse, since, as you will see in the documentation, there are several ways of executing code with the ZX interfaces, mainly due to the way screen refresh is done. A common fashion is the one of the next example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | // g++ -std=c++17 -I ./include -c fractal_example.cpp -o fractal_example.o // g++ -o fractal_example fractal_example.o -L ./lib/ -l zxecosystem // -l SDL2 -l SDL2_image -l rt -l pthread #include <iostream> #include <chrono> #include <random> #include "zxecosystem/zxecosystem.h" using namespace zxeco; int main(void) { DesktopInterface & desktop = DesktopSDL2::theDesktop(); auto & myzx = ZXEco::theZXEco(&desktop); myzx.activate("ZXEco #1",32,32,2,2); // border width: 32px, scale: x2 myzx.refreshCode([](ZXEco & zxe) { auto & disp = zxe.screen(); std::cout << "---> fractal test." << std::endl; disp.setBorder(BLACK); disp.colors().setPaper(BLACK); disp.cls(); std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> dis(0.0, 1.0); float x = 128.0 * dis(gen), y = 128.0 * dis(gen); int last{6},vertex; PixelCoord xc,yc; // --- original fractal program by @8bitfractals in Sinclair BASIC auto t0 = std::chrono::steady_clock::now(); for (unsigned i = 1; i <= 20000; ++i) { vertex = last; while (vertex == last) vertex = static_cast<int>(4 * dis(gen)); x /= 2.0; y /= 2.0; if ((vertex == 0) || (vertex == 1)) x += 64.0; if ((vertex == 1) || (vertex == 2)) y += 64.0; disp.colors().setInk(static_cast<ColorBaseType>(6 - last)); xc = static_cast<PixelCoord>(64 + x); yc = static_cast<PixelCoord>(24 + y); disp.plot({xc,yc}); last = vertex - 1; if (last == -1) last = 3; } auto d = std::chrono::steady_clock::now() - t0; std::cout << " The fractal took " << std::chrono::duration_cast< std::chrono::microseconds>(d).count() << " microseconds. " << std::endl; std::this_thread::sleep_for(std::chrono::seconds(5)); }); // refresh the display periodically every 20 millis (default behaviour) return(0); } |
In that program, first we get the singleton object responsible for accessing the desktop of our system, then get the ZXEco object for that desktop, then activate the ZXEco, and finally call user code under some refresh mode. In this case (periodic refresh mode), the code will be executed in a thread different from the main one. The result is as shown in the figure:
The ZX Ecosystem library also includes a testing suite (test.cpp
) that performs a thorough test of every functionality of the library, as seen in the videos below. Be prepared for colors and sounds!
Since v4.0.0, the ZX Ecosystem library includes a GUI sub-library that is able to create windows and dialogs with the traditional ZX look and quite a complete widget toolkit:
The ZX Ecosystem library is not too small or naïve. Detailed documentation on its classes and functionalities can be found here. Better start with the ZXEco
class and then follow the thread of the other classes and definitions as it uses them.
These are the links to download the ZX Ecosystem Library in all its modalities (open-source, compiled for Linux or for Windows). Do not forget to read the README.txt!
The ZX Ecosystem library has been developed by me (Juan-Antonio Fernández-Madrigal) in Aug-Nov 2016 (v1.0.0), Oct 2018 (v1.1.0), Dec 2018 (v1.1.1), Oct 2019 (v2.0.0), Dec 2019 (v3.0.0), Jun 2020 (v3.1.0), Nov 2020 (v4.0.0), May 2021 (v4.1.0), Aug 2021 (v4.2.0). It was originally an exercise for deepening into C++11, SDL2, and Doxygen (and into the ZX Spectrum too!).
The intended use of the library is to be free only for non-commercial use, but the open-source license does not prevent to use it for commercial products as long as the same license is forwarded. I will appreciate that you mention this web page in your programs ;) If you are interested in other uses of the library, or in some variation of it, contact me at "software" (remove quotes), jafma.net.