[About] [Installation & Use] [Download] [Documentation] [Contact & License]
[About]

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:

  • Write your own new 8-bit games with the same feeling as the original ZX but with all the computing power of your PC. Or remake old games! Some games out there already follow this philosophy, such as Beep's Escape (not using ZXEcosystem as far as I know, sigh!).
  • Re-write your old ZX Spectrum BASIC programs easily in a modern programming language (C++) and computer (your PC).
  • Provide your current desktop C++ programs with retro, easy-to use, and lovely graphical and sound interfaces (the ZX screen interface admits sizes different from the original one, i.e., larger screens). As an example, it has been used for writing the GUI of the Nutria-reboot emulator.
  • Write your own ZX Spectrum emulators.
  • Anything else your imagination can... well, imagine ;)

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.

[Installation & Use]

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:

  1. Download and install the headers and library files of SDL2 and SLD2-image for your system. Make sure that all of them can be found by any C++ program at compiling time through the angle-bracketed include #include <SDL2/SDL.h>.
  2. Make sure your machine has 3D acceleration (most machines have). In the case of building inside a virtual machine (e.g., VirtualBox), make sure to activate that kind of display acceleration in the settings. This is necessary for the SDL2 libraries to work properly for the ZXEcosystem.
  3. Download the files of the ZX Ecosystem for your system (see the Download section).
  4. Include in your C++ source program the zxecosystem.h header.
  5. Compile.
  6. Link your compiled program against the SDL2 and SLD2_image, and the ZX Ecosystem lib/objects.
  7. Enjoy!

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:

[Documentation]

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.

[Download]

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!

  • ZX Ecosystem v5.1.0 with GUI sublibrary v3.1.0. Added some new methods to some classes in ZXEcosystem; no changes in the GUI sub-library. Tested with both g++ 10.2.1 and VStudio Community 2022 (17.3.6) (32.3MB).
  • ZX Ecosystem v5.0.0 with GUI sublibrary v3.1.0. Changed the interface of different classes in ZXEcosystem for including new functionality, mainly new dithering loading of PNG files; several bug fixing. New methods for additional functionalities in the GUI sublibrary. Tested with both g++ 10.2.1 and VStudio Community 2022 (17.3.6) (32.2MB).
  • ZX Ecosystem v14.3.0 with GUI sublibrary v3.0.0. Added new methods to several classes to extend functionality in the main library; many changes and improvements in the GUI sublibrary to existing widgets, more natural interaction behaviour, a new ExplanationDialgo and non-editable TextEditor, and minor bugs fixed. Tested with both g++ 10.2.1 and VStudio Community 2022 (17.3.6) (28.3MB).
  • ZX Ecosystem v4.2.0 with GUI sublibrary v2.0.0. This contains important improvements in the GUI sublibrary: A new trace system that allows to dump into console exhaustive traces while drawing Widgets; changed the drawing system of Widget for a more consistent and safe one; added a new TextEditorWidget that provides basic text edition in a rectangle with automatic word wrapping; a new Form module to represent sets of widgets that are related within a container; a new way of showing menu dialogs suitable for context menus; DEEP containers with no tabs, i.e., whose selected child must be selected programmatically; etc. On the other hand, in the ZXEcosystem, we have now a ScaledTextPrinter subclass in Screen for printing scaled character bitmaps (both smaller and larger than regular ones); support for simple text clipboard read and write operations; and some other additions and minor bug fixes. Tested with both g++ 8.3.0.6 in Debian 10 and MS Visual Studio Community 2019 in Win10 (27.7MB).
  • ZX Ecosystem v4.1.0 with GUI sublibrary v1.0.0. This new version comes with many fixes and extensions. Among others: in the ZXEcosystem, printing chars defined directly by their bitmaps and filling char rectangles on the ZX screen; added PgDown and PgUp keys to the desktop; decolouring rectangles within the ZX screen; enhanced timing of sounds; new direct accesses to the ZX window in the desktop; enhanced display refreshes and accesses to the border of the ZX screen; extended documentation and miscellaneous functionality of classes; and a number of minor bug fixes. In the GUI sublibrary, better placing nd hiding of tooltip texts; flexible size ListWidgets; better behaviour of cursored lines in lists for widgets; new SwitchWidget; hiding/showing deploy button in CombBox; automatic ID generation for widget at creation; more powerful placing of dialogs; extended documentation and miscellaneous functionality on widget classes; and a number of minor bug fixes. Tested with both g++ 8.3.0.6 in Debian 10 and MS Visual Studio Community 2017 in Win10 (25.4MB).
  • ZX Ecosystem v4.0.0. This new version comes with important changes! Now the library works from C++17 up, a companion sub-library for making up GUIs is included (v0.0.1), a new, more consistent, powerful and clearer system of geometrical and colour classes substitutes the old ones, subscreens (subareas within existing Screen objects) can be defined, a more time balanced display refreshing method has been implemented, the desktop event system has been improved and robustified, and more informative coding of printing and colouring functions are available through the << operator; several minor bugs have been fixed along the way. Tested with both g++ 8.3.0.6 in Debian 10 and MS Visual Studio Community 2017 in Win10 (26.1MB).
  • ZX Ecosystem v3.1.0. Several bugs fixed and some additions for improving the functionality of the library for different purposes. In particular, more robust keyboard mappings, a new "decoloured" mode for showing the display (without disturbing the ZX functionality on the screen), and closer behaviour of some methods to the original ZX. Tested with both g++ 8.3.0.6 in Debian 10 and MS Visual Studio Community 2017 in Win10 (12.1MB).
  • ZX Ecosystem v3.0.0. Many changes in the structure of modules and files, and in particular in the Screen class API, for a more elegant and consistent programming; also, new functionality added for replicating the exact ZX Spectrum BASIC screen behaviour in addition to the flat model available in previous versions. Tested with both g++ 8.3.0.6 in Debian 10 and MS Visual Studio Community 2017 in Win10 (11.9MB).
  • ZX Ecosystem v2.0.0. Relevant improvements and changes in the API and the functionality; includes a Makefile for Linux (must be slightly adapted for Win). Tested with both g++ 8.3.0 in Debian 10 and MS Visual Studio Community 2017 in Win7/Win10 (12.4MB).
  • ZX Ecosystem v1.1.1. Some improvements in the speed of basic screen operations. Source code with GNUv3 license. Tested with both g++ 4.9.2 in Debian 8 and MS Visual Studio Community 2015 in Win7 (173.2KB).
  • ZX Ecosystem v1.1.0. Compiled library. Tested with both g++ 4.9.2 in Debian 8 and MS Visual Studio Community 2017 in Win10 (12.5MB).

    • NOTE: We have found some problems when executing programs linked to the currently last version of SDL2 libraries (2.0.8) in Win10 - Release. Therefore, debug versions of the ZX Ecosystem are recommended.

  • ZX Ecosystem v1.0.0. Compiled library. Tested with both g++ 4.9.2 in Debian 8 and MS Visual Studio Community 2015 in Win7 (8.7MB).

[Contact & License]

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.