Exploring Retro Computing with the ZX Spectrum Next

Alexey Medvecky
12 min readJun 9, 2024

--

In the ever-evolving landscape of technology, there is a unique charm in stepping back and immersing oneself in the world of retro computing. This nostalgic journey began with the iconic Commodore 64, a staple of early computing, renowned for its role in introducing an entire generation to video games and programming. My personal project, developing a Reverse Polish Notation (RPN) calculator for the Commodore 64, was not just about reliving the past but about rekindling the ingenuity and problem-solving approach of that era.

Reverse Polish Notation, a mathematical notation wherein every operator follows all of its operands, suits the processing style of the Commodore 64 remarkably well. Implementing this on the C64 involved delving into C programming language and Assembly. The challenge was not just in the coding itself but in operating within the 64 KB memory limit, which encouraged a level of creativity and efficiency nearly forgotten in today’s age of abundant computing resources.

A more detailed description of the RPN Calculator project can be found in my previous article.

Transition to ZX Spectrum Next

As fulfilling as it was to breathe new life into an old machine, my curiosity and passion for retro computing did not stop there. The next chapter in this vintage adventure was the ZX Spectrum, a British counterpart to the Commodore. The ZX Spectrum also boasts a rich history of influencing the software development and gaming industries. My interest in exploring different architectures and programming environments drove the transition to the ZX Spectrum.

However, this journey took an exciting turn with the introduction of the Spectrum Next, an enhanced version of the original ZX Spectrum. The Spectrum Next is not just a homage to its predecessor; it is a modern reimagining that maintains the soul of the original while boasting powerful new features such as a Z80 processor clocked at higher speeds, expanded memory, and new graphics modes.

Programming the Spectrum Next allowed for an interesting blend of old and new. While it was compatible with software written for the original ZX Spectrum, it also supported new functionalities that enabled me to push the boundaries of what could be achieved on retro hardware. My project transitioned into adapting the RPN calculator to this updated platform, which involved porting and optimising the code to take advantage of Next’s enhanced capabilities.

This part of the journey was about nostalgia and the lessons learned from history and how they can be applied in a modern context. The Spectrum Next provided a perfect bridge between the past and the present, allowing for a deeper appreciation of how far technology has come and how the foundations of these early computers still influence current technology trends.

Overview of the Spectrum Next

The Spectrum Next is an intriguing reimagining of the classic ZX Spectrum, designed to captivate both the enthusiasts of the original machine and modern programmers looking to explore retro computing with a twist. It stays true to its roots by maintaining the look and feel of the original ZX Spectrum but with significant enhancements that make it relevant in today’s technological landscape. At its heart, the Spectrum Next features a Z80 processor capable of running at speeds up to 28 MHz, a stark contrast to the original’s 3.5 MHz capability. It also includes up to 2 MB of RAM and supports VGA and HDMI output, offering much greater flexibility in display options than the original’s RF output.

The machine is not just an exercise in nostalgia; it is a fully functional computer that supports the development of new applications and games with enriched graphics and sound capabilities. Including hardware sprites, a tilemap mode, and a layering system make it particularly appealing for game development, bridging the gap between simple, classic gameplay and more complex graphical systems.

Expanding Capabilities with WiFi

One of the most notable modern enhancements in the Spectrum Next is the addition of WiFi connectivity, a feature unthinkable in the era of the original ZX Spectrum. This connectivity is a nod to modernity and a functional expansion that opens up many possibilities. With WiFi, users can easily download new software, participate in online coding communities, and even sync their projects across multiple devices without needing cumbersome physical media like cassettes or floppy disks.

The integration of WiFi also allows for the development of network-enabled applications and games. Programmers can create multiplayer experiences or utilities that fetch data from the internet, such as weather applications or RSS readers, directly on their Spectrum Next. This capability significantly expands the scope of what can be achieved with the machine, making it a powerful tool for education and experimentation in network computing.

Integrating WiFi into a retrocomputing platform like Spectrum Next enhances its utility and provides an educational bridge. It allows current generations to understand the fundamentals of computer networking and online communication within a more comprehensible and less complex framework than modern computers.

Introduction to z88dk C and Assembly Language on the ZX Spectrum Next

The ZX Spectrum Next revives the classic computing experience and provides fertile ground for low-level programming with assembly language. Using the z88dk development kit, a collection of tools and libraries designed to facilitate the development of applications for Z80-based machines like the ZX Spectrum, enthusiasts can dive into the nuts and bolts of computer programming.

In this part of our journey into retro computing, we’ll explore how to write and run a simple “Hello, World!” program on the ZX Spectrum Next using assembly language and z88dk. This foundational programming exercise is an excellent introduction to assembly programming, highlighting the direct manipulation of the machine’s memory and output functions.

Introduction to the Z80 Microprocessor

The Z80 microprocessor, designed by Zilog in 1976, has been a cornerstone in developing personal computers, particularly those from the late 70s and 80s, such as the ZX Spectrum series. Its architecture and capabilities have made it a preferred choice for consumer electronics and embedded systems. The Z80’s design builds upon the earlier Intel 8080, with an enhanced instruction set and interrupted handling capabilities, facilitating more efficient and powerful computing applications.

Technical Specifications and Features

  • Processor Speed: Originally, Z80 processors operated at clock speeds typically ranging from 2.5 MHz to 6 MHz. The Spectrum Next significantly boosts this, offering speeds up to 28 MHz for enhanced performance.
  • Instruction Set: The Z80 features an extended instruction set compared to its predecessors, including bit manipulation, block move, and search operations, which are not present in the Intel 8080.
  • Registers:
  • Accumulator and Flag Register: The 8-bit accumulator (A) is used for arithmetic and logic operations, with the results affecting the flags in the flag register for conditional operations.
  • General-Purpose Registers: Registers B, C, D, E, H, and L can be used individually as 8-bit registers or combined as BC, DE, and HL pairs for 16-bit operations.
  • Index Registers: IX and IY for effective address calculations, providing versatile addressing modes.
  • Stack Pointer (SP) and Program Counter (PC) are essential for stack management and program execution flow.
  • Interrupt Modes: The Z80 supports three interrupt modes (IM 0, IM 1, IM 2), allowing flexible response strategies to external events or internal conditions.

Architectural Advantages

The Z80’s architecture includes several features that were innovative for its time and continue to influence processor design:

  • Memory Management: The use of refresh registers (R) to maintain dynamic RAM during operation and simple yet effective interrupt handling mechanisms support robust system design.
  • Input/Output Operations: Separate input/output instructions (IN, OUT) and space allow direct control over peripherals, simplifying hardware design for devices like the ZX Spectrum.
  • Non-Maskable Interrupts (NMI): This feature provides a robust method for dealing with high-priority interrupts that must be immediately addressed, ensuring more reliable system behaviour.

Impact on Computing

The Z80’s flexibility and power made it a popular choice for early home computers and game consoles, laying the groundwork for software development and video game design during the early years of the computing revolution. Its design influenced many key concepts in computing, such as modular programming and event-driven programming, which are fundamental in modern software engineering.

Writing the Program

The “Hello, World!” program provided is a simple demonstration of using assembly language to output a string to the screen.

Here’s a breakdown of how the program works:

  • Defining the Entry Point: The program begins with GLOBAL _main, which defines its entry point. This is essential for the z88dk linker to know where to start execution.
  • Memory Section Declarations: The SECTION code_compiler and SECTION rodata_compiler commands organize code and read-only data separately, which helps manage memory usage more effectively.
  • Loading and Displaying the String:
  • ld bc, str_0: This instruction loads the address of the string into the BC register pair.
  • The my_loop label starts a loop where each string character is loaded into register A.
  • ld a, (bc): Loads the byte at the address contained in BC into A.
  • cp 0: Compares the value in A with 0 (the end-of-string marker).
  • jr z, end_program: Jumps to end_program if the zero flag is set (i.e., if A contains 0).
  • rst $10: RST (or ‘restart’) is the same as CALL, except it uses only one byte, and is faster. However, you can only use it with eight specific ROM addresses, one of which is 0x10, which we call here.
  • inc bc: Increments the BC register to point to the next character.
  • jr my_loop: Jumps back to the start of the loop until the end of the string is reached.
  • Ending the Program: end_program contains a ret instruction, which returns from the main function, effectively ending the program.
  • Defining the String: In the rodata_compiler section, str_0 is defined with DEFM “Hello, world!” followed by DEFB 13, 0, which adds a carriage return and a null terminator to the end of the string.

The result of the program running looks as follows:

From Assembly to C: A Strategic Shift

While assembly language offers deep control over system resources and performance, transitioning to C programming brings numerous advantages, such as increased code portability, easier debugging, and faster development times. On platforms like the ZX Spectrum Next, which retains a strong community of retro computing enthusiasts, leveraging C opens the doors to more complex and versatile application development.

Using conio.h for Text-Based User Interfaces

The conio.h library, short for “console input/output,” is a C header file commonly used in MS-DOS programs but has found utility in other systems, including the ZX Spectrum Next, for creating text-based user interfaces. It provides functions to control text output on the console or the terminal emulator (like VT100), making it possible to create visually appealing and interactive applications.

The VT100, introduced by Digital Equipment Corporation (DEC) in 1978, set the standard for terminal emulation, a protocol that continued to evolve into what is commonly referred to today as ANSI terminals. VT100 and its successors helped define many of the control sequences used in terminal emulation, influencing how computers communicate with terminals and how text-based interfaces are managed.

Let’s consider how a simple VT100/ANSI control sequence works in practice:

ESC[2J

This escape sequence clears the entire screen and moves the cursor to the top-left corner. It begins with the ESC character, followed by `[`, the numeric code `2`, and the letter `J`. This kind of command is invaluable for creating a clean state for new output on the screen, essential for things like refreshing a user interface or initializing a game screen.

Key Features of VT100/ANSI Terminals

  • Screen Management: ANSI terminals allow sophisticated screen management capabilities, including cursor movement, screen clearing, and scrolling regions. These features are crucial for developing text-based user interfaces that require dynamic content updates.
  • Text Formatting: Extensive options for text formatting are available, such as bold, underline, reverse video, and various text colours. These features enable developers to highlight important information and improve the readability of terminal output.
  • Escape Sequences: ANSI escape sequences, strings of characters starting with the ESC character (ASCII 27), and control terminal functions. Specific sequences handle moving the cursor, changing text properties, or clearing portions of the screen.
  • Keyboard and Mouse Input: ANSI terminals can also interpret input sequences from the keyboard and, in more advanced setups, from pointing devices like a mouse. This capability allows for interactive applications that respond in real-time to user actions.

Here’s a look at some of the functions used in the provided example:

  • bordercolor, textcolor, textbackground: These functions set the colors of the border, text, and background respectively. Colors are managed through simple identifiers like BLACK, GREEN, and WHITE.
  • clrscr: Clears the screen, a handy feature for initializing the display or refreshing the user interface.
  • gotoxy: Moves the cursor to a specified position on the screen, given by x and y coordinates. This function is crucial for placing text exactly where it’s needed.
  • puts: Writes a string to the console at the current cursor position.
  • cgetc: Waits for a character input, useful for pausing the program until the user presses a key.

Here is the result of the provided program and an example of using the .sync utility via WiFi:

Crafting “Hello World” on CP/M Using VT52/Generic Terminal Controls

Introduction to CP/M and VT52 Terminals

CP/M, short for Control Program for Microcomputers, was an early operating system that became widely known in the 1970s and 1980s for its use in business and personal computers. It provided a standardized software platform for early microcomputer hardware and inspired the design for subsequent systems like MS-DOS.

The VT52 is a terminal Digital Equipment Corporation (DEC) developed that predates the more widely known VT100. It was one of the first terminals to support cursor movement and other control functions through escape sequences, although it had a more limited set of capabilities than later ANSI terminals. The VT52 and similar generic terminals facilitated text-based output and simple graphical displays on early computer systems.

Implementing “Hello World” with VT52/Generic Console Commands

The provided C program showcases using basic VT52 terminal controls in a CP/M environment to position text on the screen and manage screen clearing. Here’s how each part of the program functions:

  • Function cls(): This function clears the screen using the VT52 escape sequence \x1BJ, which erases from the cursor’s current position to the end of the screen. It starts by positioning the cursor at the top-left using gotoyx(0, 0).
  • Function gotoyx(): It uses the escape sequence \x1BY followed by two characters that specify the cursor’s row and column positions. The `+ ‘ ‘` offset converts numerical values into printable ASCII characters, aligning with the VT52’s control code expectations.

Importance of VT52/Generic Terminal Capabilities

The simplicity of the VT52 and similar generic terminals made them crucial in the early development of computer software, particularly for environments like CP/M. They allowed developers to create more user-friendly and visually structured applications before the advent of graphical user interfaces. Controlling cursor movement and screen management through concise escape sequences enabled the development of text-based games, educational software, and business applications.

Here is an example of importing and running a Hello World application for CP/M:

Conclusion: Reflecting on the Journey Through Retro Computing

Exploring retro computing, from the Commodore 64 to the ZX Spectrum Next, encapsulates more than just a trip down memory lane—it represents a deep appreciation for the history and evolution of technology. This journey has allowed us to revisit the simplicity and innovation of the past and recognize how these early ideas continue to influence and shape modern computing.

Transitioning between different systems, from the Commodore 64 to the ZX Spectrum and finally to the Spectrum Next, provided valuable insights into the architectural and functional advancements in computing technology over the years. The introduction of modern features like WiFi connectivity and enhanced processing capabilities on the Spectrum Next demonstrates a seamless blend of nostalgia with contemporary technology, creating a platform that is both educational and functional.

Moreover, the use of programming languages from assembly to C has illustrated the evolution of software development practices. Starting with the detailed and hardware-close assembly language on the ZX Spectrum Next, and moving towards the higher-level abstractions offered by C, reflects broader trends in computing where the focus has increasingly shifted towards efficiency, portability, and accessibility.

The journey through retro computing is not merely about revisiting the technologies of the past but about learning from them. It teaches us the fundamentals of computing from the ground up, offering lessons in efficiency, creativity, and simplicity that are sometimes lost in modern, high-level programming environments. This understanding enriches our approach to contemporary software development, providing a solid foundation that combines the best of both worlds — the classic and the current.

In conclusion, the resurgence of interest in retro computing is more than nostalgia; it’s an homage to the industry's pioneers and an educational tool for today’s technologists. It serves as a reminder of how far technology has come and a testament to the enduring relevance of foundational computing principles. As we continue to advance into the future of technology, the lessons learned from these retro computing platforms will remain invaluable, guiding us through the next innovations and beyond.

--

--