About Z80

Z80

Description of the Zilog Z80 Microprocessor

1. Overview

The Zilog Z80 is an 8-bit microprocessor developed by Zilog and released in 1976. It was designed by Federico Faggin, who previously worked on the Intel 4004 and 8080 processors. The Z80 was highly successful, becoming one of the most popular CPUs in the 1980s, particularly in personal computers, embedded systems, and gaming consoles.

The Z80 was largely compatible with the Intel 8080, which was crucial for its adoption because it allowed existing 8080 software to be easily ported to the Z80. It also introduced several enhancements and new features that made it more powerful and easier to use.

2. Architecture

The Z80 has a complex yet efficient architecture for an 8-bit processor. Here’s an in-depth look at its architecture:

A. Registers

The Z80 includes a rich set of registers that make it more powerful than the 8080:

  • 8-bit General Purpose Registers:
    • A (Accumulator): Used for arithmetic and logic operations.
    • B, C, D, E, H, L: Six general-purpose 8-bit registers that can be paired (BC, DE, HL) to form 16-bit registers for various operations.
  • 16-bit Registers:
    • BC, DE, HL: Pairs of general-purpose registers that can be used as 16-bit registers.
    • SP (Stack Pointer): Points to the current top of the stack in memory.
    • PC (Program Counter): Holds the address of the next instruction to be executed.
  • Index Registers:
    • IX, IY: Special 16-bit index registers used for indirect addressing, particularly useful for accessing data structures and arrays.
  • Special Purpose Registers:
    • F (Flags Register): Stores the status flags (Zero, Carry, Sign, Parity/Overflow, Half Carry, and Subtract).
    • I (Interrupt Vector Register): Used in interrupt mode 2 to point to an interrupt vector table.
    • R (Refresh Register): Used for dynamic RAM refresh, as well as during instruction execution to refresh memory addresses.
  • Alternate Register Set:
    • The Z80 also includes an alternate set of registers (A’, F’, BC’, DE’, HL’) that can be swapped with the primary set using the EXX and EX AF,AF' instructions, enabling faster context switching.

B. Instruction Set

The Z80 has an extensive and versatile instruction set, including:

  • Arithmetic and Logic Instructions: ADD, SUB, AND, OR, XOR, CP, INC, DEC, etc.
  • Data Movement Instructions: LD (load), PUSH, POP, EX (exchange registers), etc.
  • Bit Manipulation: BIT (test), SET (set bit), RES (reset bit), RL (rotate left), RR (rotate right), etc.
  • Control Flow Instructions: JP (jump), JR (relative jump), CALL, RET, DJNZ (decrement and jump if not zero), etc.
  • Input/Output Instructions: IN, OUT, allowing direct communication with peripheral devices.
  • Block Transfer/Block Search Instructions: LDIR, CPIR, used for block memory transfers and searches.

The Z80 introduced new instructions not present in the 8080, such as those for bit manipulation and block memory transfers, which significantly improved its capabilities for system-level programming.

C. Interrupt Handling

The Z80 supports three interrupt modes:

  1. Mode 0: Directly executes an instruction supplied by an external device during an interrupt.
  2. Mode 1: Automatically jumps to a fixed location in memory (address 0x0038) when an interrupt occurs.
  3. Mode 2: Uses a vectorized interrupt system, where the interrupting device provides an 8-bit vector, which the Z80 combines with the I register to form the address of the interrupt service routine.

This flexibility in interrupt handling made the Z80 suitable for a wide range of real-time and embedded applications.

D. Addressing Modes

The Z80 supports several addressing modes:

  • Immediate Addressing: Operands are specified directly in the instruction.
  • Register Addressing: Operands are in the registers.
  • Direct Addressing: Memory addresses are provided directly in the instruction.
  • Indirect Addressing: Operands are accessed via memory locations pointed to by registers (e.g., (HL)).
  • Indexed Addressing: Uses index registers (IX or IY) with a displacement to access memory locations.

These addressing modes enable efficient and flexible programming, especially in applications involving data manipulation and control.

3. Key Features and Enhancements over the Intel 8080

  • Extended Instruction Set: The Z80’s instruction set is a superset of the 8080’s, with many additional instructions that simplify programming tasks.
  • Register File: The Z80’s expanded register set, including the alternate register set, improves performance in context-switching scenarios.
  • Interrupt Modes: The Z80’s flexible interrupt system, especially Mode 2, is more advanced than the 8080’s, allowing for complex interrupt-driven applications.
  • Bit Manipulation: New instructions for bit-level operations and block data transfers are powerful tools for system-level programming.
  • Memory Refresh: The Z80’s automatic memory refresh capability (using the R register) is crucial for systems using dynamic RAM.

4. Applications

The Z80 was used in a wide variety of systems, including:

  • Home Computers: The Z80 was the CPU in many popular home computers, such as the Sinclair ZX Spectrum, TRS-80, Amstrad CPC, and MSX.
  • Embedded Systems: The Z80’s versatility and simplicity made it a favorite in embedded systems, from industrial controllers to consumer electronics.
  • Gaming Consoles: The Z80 was used as the main CPU or as an audio processor in gaming consoles like the Sega Master System and the Game Boy.
  • CP/M Systems: Many early personal computers running the CP/M operating system used the Z80 due to its backward compatibility with the 8080 and its enhanced capabilities.

5. Development Tools and Emulation

  • Assemblers: Tools like Z80ASM, TASM, and NASM (with specific settings) are commonly used for assembling Z80 assembly code.
  • Emulators: There are numerous Z80 emulators available, such as ZEMU, EmuZ80, and SimH, which help developers test and debug their code before deploying it on actual hardware.
  • Development Boards: Modern retrocomputing enthusiasts can use development boards and kits featuring the Z80 to build and experiment with Z80-based systems.

6. Legacy and Influence

The Z80’s impact on computing is profound. Its architecture influenced the design of subsequent processors and remains in use in various forms today. The Z80’s instruction set is still studied by computer science students, and its legacy lives on in the retrocomputing community, where it is still used for hobbyist projects and educational purposes.

Use cases

The Zilog Z80 microprocessor has been used in a wide range of applications due to its versatility, ease of use, and powerful features for its time. Here’s a list of notable use cases for the Z80 processor:

1. Home Computers

The Z80 was a popular choice for many early home computers due to its affordability and robust feature set. Examples include:

  • Sinclair ZX Spectrum: One of the most famous Z80-based computers, widely popular in Europe during the 1980s for gaming and programming.
  • TRS-80: Sold by Radio Shack, it was one of the first mass-market home computers in the United States.
  • Amstrad CPC: A British series of home computers that were successful in Europe, known for their integrated design.
  • MSX: A standardized home computer architecture that was popular in Japan and other countries, which used the Z80 as its CPU.
  • Timex Sinclair 2068: A U.S.-based version of the Sinclair ZX Spectrum, with enhanced features.

2. Gaming Consoles

The Z80 was also widely used in early gaming consoles and arcade systems:

  • Sega Master System: A popular 8-bit gaming console that used the Z80 as its main CPU.
  • Sega Game Gear: A handheld gaming console that also featured a Z80 processor.
  • Sega Genesis/Mega Drive: The Z80 was used as a secondary processor to handle audio processing in this popular 16-bit console.
  • Nintendo Game Boy: The original Game Boy used a modified version of the Z80 for its CPU.
  • Arcade Machines: Many arcade systems in the 1980s, such as Pac-Man and Space Invaders machines, used the Z80 to drive their gameplay and audio.

3. Embedded Systems

The Z80’s simple design and reliable performance made it a favorite in embedded systems, which required a robust and straightforward CPU:

  • Industrial Control Systems: Used in factory automation, robotics, and control systems where reliability and predictability are key.
  • Telecommunications Equipment: Found in early telephone systems, modems, and network equipment for handling data processing tasks.
  • Medical Devices: Utilized in early medical instruments and monitoring devices due to its ability to manage real-time processing with simple control logic.
  • Printers: Many early dot-matrix and impact printers used the Z80 for controlling the printing mechanism and handling communication with computers.
  • Point of Sale (POS) Terminals: The Z80 was embedded in early cash registers and POS systems, managing transaction processing and peripherals.

4. CP/M Computers

The Z80 was widely used in computers running the CP/M operating system, a popular OS before the rise of MS-DOS:

  • Kaypro: A line of portable computers that ran CP/M and used the Z80 as its main CPU.
  • Osborne 1: The first commercially successful portable computer, also running CP/M with a Z80 processor.
  • Zenith Z-100: Another CP/M-based computer using the Z80, often used in business environments.

5. Calculators and Educational Tools

The Z80 was used in several advanced calculators and educational computing tools:

  • TI-83/84 Series Calculators: Texas Instruments used the Z80 in its popular graphing calculators, which are still widely used in schools.
  • Educational Kits: The Z80 was featured in many educational computer kits, such as the Heathkit H89, which allowed users to learn about microcomputing and assembly language programming.

6. Networking Equipment

In the early days of networking, the Z80 was used in various pieces of network equipment due to its capability to handle data transmission protocols:

  • Modems: Z80 CPUs were embedded in early modems for processing communication protocols.
  • Routers and Bridges: Simple network devices used the Z80 to manage packet forwarding and routing tables.

7. Robotics and Automation

The Z80’s ability to handle real-time tasks made it a solid choice for early robotics and automation systems:

  • Robotic Controllers: Used in early robotic arms and automated machinery for handling precise control tasks.
  • CNC Machines: Z80 processors were embedded in early computer numerical control (CNC) machines to control machining processes.

8. Test and Measurement Equipment

The Z80 was used in various types of test and measurement equipment:

  • Oscilloscopes: Early digital oscilloscopes used the Z80 to process signal data and manage user interfaces.
  • Multimeters: Used in digital multimeters for signal processing and measurement calculation.

9. Audio and Music Equipment

The Z80 was utilized in some audio and music production equipment, particularly in the early days of digital audio:

  • Synthesizers: Some early digital synthesizers and sound modules used the Z80 to handle audio processing tasks.
  • Drum Machines: Digital drum machines and sequencers used the Z80 for timing and pattern management.

10. Scientific Instruments

The Z80 found its way into various scientific instruments due to its processing power and reliability:

  • Data Loggers: Used in environmental monitoring and scientific data collection devices.
  • Laboratory Equipment: Embedded in devices like centrifuges and spectrometers for controlling experiments and processing data.

11. Retrocomputing and Hobby Projects

Even today, the Z80 is popular in the retrocomputing community and among hobbyists:

  • Homebrew Computers: Enthusiasts build custom Z80-based computers as a learning tool or for nostalgia.
  • Retro Gaming Projects: Hobbyists recreate classic gaming systems or build new games for Z80-based platforms.
  • Emulation Projects: The Z80 is often emulated in software for use in retro gaming and computing environments.

Conclusion

The Zilog Z80 microprocessor has been used in a vast array of applications, ranging from early home computers and gaming consoles to embedded systems and industrial automation. Its combination of power, flexibility, and ease of programming made it a go-to choice for many different types of devices, and its influence continues today in the fields of retrocomputing and embedded systems.

Operating Systems

The Zilog Z80, being a versatile and widely used microprocessor, has been the basis for several operating systems (OS) throughout its history. Some operating systems were designed specifically for the Z80, while others were ported from similar processors like the Intel 8080.

Here’s a list of operating systems that are native to or could be ported to the Z80:

1. CP/M (Control Program for Microcomputers)

  • Native/Ported: Native (designed for 8080, easily ported to Z80)
  • Description: CP/M is the most famous operating system for the Z80 and similar processors. It was the dominant OS for microcomputers in the late 1970s and early 1980s. CP/M supports a wide range of software, including word processors, compilers, and other utilities.
  • Features:
    • Command-line interface.
    • Supports multiple file systems.
    • Modular structure with support for different hardware configurations.

2. MP/M (Multi-Programming Monitor Control Program)

  • Native/Ported: Native (derived from CP/M)
  • Description: MP/M is a multi-user version of CP/M, designed to allow multiple users to share a single Z80-based system. It introduced features like task switching and user isolation.
  • Features:
    • Multi-user support.
    • Task scheduling and multitasking.
    • File system compatible with CP/M.

3. TRSDOS

  • Native/Ported: Ported (originally for TRS-80)
  • Description: TRSDOS is the operating system for the Tandy TRS-80 line of computers, which were based on the Z80. It’s similar in structure to CP/M but was specifically designed for the TRS-80 hardware.
  • Features:
    • File management and disk utilities.
    • BASIC interpreter integration.
    • Supports TRS-80 peripherals.

4. HDOS (Heath DOS)

  • Native/Ported: Native
  • Description: HDOS was developed for the Heathkit H89, a Z80-based computer. It’s similar to CP/M but with some different utilities and a distinct file system.
  • Features:
    • Text-based interface.
    • Support for Heathkit peripherals.
    • File system and disk management.

5. QDOS

  • Native/Ported: Native
  • Description: QDOS is a simple disk operating system for the ZX Spectrum, which uses a Z80 processor. It was not as fully featured as CP/M but provided basic file management and program loading capabilities.
  • Features:
    • Simple command-line interface.
    • Tape and disk support.
    • Used in early home computing environments.

6. NewDOS/80

  • Native/Ported: Native
  • Description: NewDOS/80 is an enhanced version of TRSDOS for the TRS-80 computers. It provided better compatibility and more features than the original TRSDOS.
  • Features:
    • Advanced disk management.
    • Support for a wider range of peripherals.
    • Enhanced user interface over TRSDOS.

7. ZRDOS

  • Native/Ported: Native
  • Description: ZRDOS is an improved disk operating system for Z80-based computers. It’s compatible with CP/M software but provides additional features such as better disk management and enhanced utilities.
  • Features:
    • Improved performance over CP/M.
    • Advanced file management utilities.
    • Compatibility with CP/M software.

8. ZCPR (Z80 Command Processor Replacement)

  • Native/Ported: Native (as an enhancement to CP/M)
  • Description: ZCPR is an enhanced command processor replacement for CP/M, offering a more powerful command-line interface and additional features.
  • Features:
    • Extended command-line capabilities.
    • Enhanced scripting and batch processing.
    • Better support for different environments.

9. Fuzix

  • Native/Ported: Ported (based on Unix-like systems)
  • Description: Fuzix is a modern Unix-like operating system for small machines, including the Z80. It’s a lightweight OS inspired by early Unix systems, designed to run on limited hardware like the Z80.
  • Features:
    • Multi-tasking.
    • Support for standard Unix utilities.
    • Simple file system.

10. UZI (Unix Z80 Implementation)

  • Native/Ported: Ported (Unix-like)
  • Description: UZI is a small, Unix-like operating system for the Z80, inspired by Version 7 Unix. It includes a simple shell, file system, and basic utilities.
  • Features:
    • Multi-tasking.
    • Unix-like file system.
    • Simple command-line interface.

11. MSX-DOS

  • Native/Ported: Native (for MSX computers)
  • Description: MSX-DOS was designed for the MSX home computer standard, which used the Z80. It was similar to CP/M but with enhancements to better support the MSX hardware.
  • Features:
    • Disk-based operating system.
    • Command-line interface similar to MS-DOS.
    • File management and basic utilities.

12. Contiki

  • Native/Ported: Ported (lightweight OS for 8-bit systems)
  • Description: Contiki is a small, lightweight operating system designed for 8-bit computers, including the Z80. It’s particularly known for including a simple TCP/IP stack, making it suitable for networked applications.
  • Features:
    • Multi-tasking.
    • Basic network support.
    • GUI on supported platforms.

13. ZELOS

  • Native/Ported: Native
  • Description: ZELOS (Z80 Executive Loader Operating System) is a small operating system designed specifically for Z80 systems. It’s known for being lightweight and easy to use.
  • Features:
    • Simple file system.
    • Basic command-line interface.
    • Small footprint.

14. SymbOS

  • Native/Ported: Native
  • Description: SymbOS is a multitasking operating system with a graphical user interface (GUI) for Z80-based systems like the Amstrad CPC and MSX. It’s one of the most advanced OSes available for Z80 computers.
  • Features:
    • Multitasking with a graphical interface.
    • Support for multiple file systems.
    • Network support and multimedia applications.

15. RDOS

  • Native/Ported: Native
  • Description: RDOS (Remote DOS) was used in some Z80-based embedded systems, offering basic real-time capabilities and support for remote operations.
  • Features:
    • Real-time capabilities.
    • Support for remote operations and peripherals.
    • Simple command-line interface.

16. ZOS (Z80 Operating System)

  • Native/Ported: Native
  • Description: ZOS is a small, simple operating system for Z80 computers, often used in embedded systems and educational contexts.
  • Features:
    • Basic file management.
    • Command-line interface.
    • Small and efficient, ideal for limited hardware.

Conclusion

The Zilog Z80 microprocessor has supported a wide range of operating systems, from CP/M and its derivatives to modern Unix-like systems like Fuzix and UZI. Many of these operating systems have been developed specifically for the Z80, taking advantage of its features and addressing the needs of both personal computers and embedded systems.

These operating systems provide a variety of capabilities, from simple command-line interfaces and single-tasking environments to more complex multitasking systems with graphical user interfaces. The Z80’s versatility and longevity have made it a staple in computing history, with its legacy continuing through the development of these diverse operating systems.

Linux ?

Running Linux on a Zilog Z80 microprocessor is not feasible due to the significant differences in architecture, processing power, and memory requirements. Here’s a detailed explanation of why Linux cannot be directly ported to or run on a Z80, along with alternative solutions for Unix-like environments on Z80 systems.

1. Why Linux Cannot Run on the Z80:

A. Architecture Differences:

  • Word Size: Linux is designed for 32-bit and 64-bit processors (such as x86, ARM, and PowerPC), while the Z80 is an 8-bit microprocessor. The Z80 can only handle 8-bit data at a time, which is far below the capabilities needed for Linux.
  • Address Space: The Z80 has a limited 16-bit address bus, meaning it can directly address only 64 KB of memory. In contrast, Linux requires a much larger address space to manage its processes, kernel, and user-space applications.
  • Complex Instruction Set: Linux requires a more complex instruction set to manage multitasking, memory management, and other advanced features. The Z80’s simpler instruction set is not sufficient to support these operations.
  • Lack of Memory Management Unit (MMU): Modern operating systems like Linux rely on an MMU to handle virtual memory, process isolation, and other critical tasks. The Z80 lacks an MMU, making it impossible to implement the necessary memory management features for Linux.

B. Resource Requirements:

  • Memory Requirements: A minimal Linux system requires at least several megabytes of RAM just to boot. The Z80’s maximum addressable memory is only 64 KB, which is insufficient to load even a basic Linux kernel.
  • Processing Power: The Z80 operates at clock speeds typically around 2 to 4 MHz, which is vastly slower than the processors Linux is designed to run on. The processing power of the Z80 is inadequate for running an operating system as complex as Linux.

2. Alternative Unix-like Environments for Z80:

While Linux cannot be run on a Z80, there are Unix-like operating systems and environments that have been specifically designed for or ported to the Z80. These systems offer some of the features of Unix, scaled down to work within the Z80’s constraints.

A. Fuzix

  • Description: Fuzix is a Unix-like operating system designed for small, 8-bit computers like the Z80. It’s heavily inspired by Unix Version 7 and includes basic multitasking, file management, and process control features.
  • Features:
    • Multi-tasking support.
    • Simple Unix-like file system.
    • Compatible with small and low-power 8-bit systems.
  • Limitations: While Fuzix brings many Unix-like features to the Z80, it is much more limited than Linux, given the hardware constraints.

B. UZI (Unix Z80 Implementation)

  • Description: UZI is a minimal Unix-like OS designed for the Z80, providing a command-line interface, basic file system, and process control similar to Unix. It’s a very lightweight implementation suitable for Z80-based systems.
  • Features:
    • Multi-tasking with a preemptive scheduler.
    • Unix-like shell and utilities.
    • Support for serial terminals.
  • Limitations: UZI is limited in scope and functionality, focusing on providing the bare essentials of a Unix-like environment on the Z80.

C. CP/M with Unix-like Tools

  • Description: CP/M (Control Program for Microcomputers) is not a Unix-like OS, but many Unix-like utilities (e.g., text editors, shell environments) have been ported to CP/M. These tools give CP/M a more Unix-like feel, even though it lacks many of the advanced features of Unix.
  • Features:
    • Basic command-line interface.
    • Availability of Unix-like utilities such as grep, sed, and awk.
    • File management and batch processing.
  • Limitations: CP/M itself is not Unix-like and lacks multi-tasking, memory management, and other key Unix features.

3. Summary:

While Linux is not suitable for the Z80 microprocessor due to its architectural and resource limitations, there are alternative Unix-like operating systems and environments that can run on Z80-based systems. These include Fuzix, UZI, and CP/M with Unix-like utilities, each providing a subset of Unix-like functionality that is feasible within the constraints of the Z80.

These alternatives offer a way to experience Unix-like operating systems on a Z80, although they are far less powerful and feature-rich compared to Linux. They are valuable for educational purposes, retrocomputing, and embedded systems where simplicity and low resource usage are key.

DOOM ?

Running DOOM, the classic first-person shooter, on a Zilog Z80 processor is not feasible due to the significant limitations of the Z80 compared to the hardware required to run DOOM. Here’s a detailed explanation:

1. Understanding DOOM’s Requirements:

A. Hardware Requirements:

  • Processor: DOOM was originally released in 1993 for PCs with Intel 80386 processors, which are 32-bit processors running at 20-33 MHz. The Zilog Z80, on the other hand, is an 8-bit processor running at typically 2-4 MHz.
  • Memory: DOOM requires at least 4 MB of RAM to run. The Z80 has a 16-bit address bus, which limits it to a maximum of 64 KB of directly addressable memory.
  • Graphics: DOOM requires a VGA-compatible graphics card, capable of rendering 320×200 pixels in 256 colors. The Z80 typically runs in systems with much simpler graphics capabilities, like monochrome or basic 4-color displays.
  • Sound: DOOM used sound cards like Sound Blaster for audio, which is far beyond the simple beeper or basic sound chips commonly used with Z80 systems.

B. Software Requirements:

  • Operating System: DOOM was designed to run on MS-DOS, which requires a more powerful CPU and more memory than a Z80-based system can provide.
  • Game Engine: The DOOM engine is a complex piece of software designed to take advantage of the 32-bit architecture of x86 CPUs. It involves floating-point math, memory management, and advanced graphics rendering techniques, none of which are feasible on an 8-bit Z80 processor.

2. Why DOOM Can’t Run on a Z80:

A. Processing Power:

  • The Z80 is an 8-bit processor with a much simpler architecture and significantly lower processing power than the 32-bit processors required for DOOM. It simply cannot handle the complex calculations needed for DOOM’s 3D graphics engine.

B. Memory Constraints:

  • The Z80’s maximum of 64 KB of addressable memory is far below the 4 MB required just to load and run DOOM, not to mention the additional memory needed for handling textures, sounds, and game logic.

C. Graphics and Audio Capabilities:

  • The graphics and audio systems typically connected to a Z80 processor are far too primitive to render DOOM’s detailed environments and play its sound effects.

3. What You Can Do on a Z80:

While running the original DOOM on a Z80 is not possible, here are some alternative approaches:

A. Text-Based Games:

  • Rogue: You could run text-based roguelike games such as Rogue on a Z80, which offer dungeon-crawling gameplay with ASCII graphics.
  • Adventure Games: Early text-based adventure games, like Zork, can run on a Z80 system, offering deep storytelling without the need for advanced graphics.

B. Simplified FPS Games:

  • Wireframe or Grid-Based FPS: You could develop or port a very simplified FPS game that uses wireframe graphics or grid-based movement, like early FPS games before DOOM. This would involve moving through simple mazes with basic rendering.
  • Maze Games: Games like Wolfenstein 3D, which is a predecessor to DOOM but simpler in design, might inspire a highly simplified version on the Z80, though even Wolfenstein 3D would be extremely difficult to replicate faithfully on such limited hardware.

C. 2D Action Games:

  • Platformers or Shoot ’em Ups: Classic 2D games such as Space Invaders, Pac-Man, or simple side-scrolling shooters can be successfully implemented on a Z80.

D. DOOM Ports on Minimal Hardware:

  • DOOM on Calculators: There are ports of DOOM for graphing calculators like the TI-83/84, which use a Z80 processor, but these are heavily optimized versions that involve significant reduction in graphics, gameplay, and features to fit within the constraints of the hardware. Even these versions require much more powerful hardware than a standard Z80 setup.

4. The “Can It Run DOOM?” Meme:

The idea of porting DOOM to unlikely hardware has become a meme in the tech community, leading to attempts to run DOOM on everything from ATMs to printers. However, most of these devices still have significantly more power and memory than a Z80, or they rely on external hardware to run DOOM.

Conclusion:

Running DOOM on a Zilog Z80 processor is not technically feasible due to the severe limitations in processing power, memory, graphics, and sound capabilities. However, for those interested in retrocomputing or game development on a Z80, there are plenty of other avenues to explore, including text-based games, simple 2D games, or highly simplified versions of early 3D games. If you’re interested in pushing the limits of what the Z80 can do, creating a minimalist FPS or a simple game inspired by DOOM could be a rewarding challenge, even if it doesn’t resemble the original DOOM in complexity or visual presentation.

Emulators

There are several good emulators for the Zilog Z80 that you can use for developing, testing, and debugging your bootloader or other software.

Here are some of the most popular and reliable Z80 emulators:

1. ZEMU

  • Description: ZEMU is a lightweight Z80 emulator that can run CP/M and other Z80 software. It’s particularly useful for testing Z80 assembly code and small systems.
  • Features:
    • Simple and easy to use.
    • Provides basic debugging features like breakpoints and memory inspection.
    • Supports loading binary files and running them directly.
  • Platform: Linux, Windows (via Cygwin), macOS
  • Website: ZEMU on GitHub

2. EmuZ80

  • Description: EmuZ80 is a Z80 emulator written in C, offering a good balance between simplicity and features. It’s great for running and debugging Z80 code in a controlled environment.
  • Features:
    • Supports various Z80 configurations and peripherals.
    • Debugging tools like step execution, breakpoints, and memory inspection.
  • Platform: Linux, Windows, macOS (can be compiled from source)
  • Website: EmuZ80 on SourceForge

3. SimH (SIMH)

  • Description: SimH is a highly versatile emulator that supports a wide range of classic computers, including those with Z80 processors. It’s often used for emulating older systems like the Altair 8800.
  • Features:
    • Extremely versatile with support for multiple architectures.
    • Advanced debugging and tracing capabilities.
    • Can simulate full systems with multiple peripherals.
  • Platform: Windows, Linux, macOS
  • Website: SimH Official Site

4. Z80-EMU

  • Description: Z80-EMU is a compact emulator focused on emulating the Z80 CPU. It’s designed for those who want to test Z80 assembly code and run small programs.
  • Features:
    • Lightweight and simple.
    • Provides basic debugging features.
    • Ideal for learning and small projects.
  • Platform: Linux, Windows
  • Website: Z80-EMU on GitHub

5. ZXSP

  • Description: ZXSP is a more specialized emulator aimed at ZX Spectrum enthusiasts, which also uses the Z80 CPU. It’s a great tool if you’re interested in developing or testing Z80 code in the context of a Spectrum-like environment.
  • Features:
    • Emulates the ZX Spectrum environment.
    • Integrated debugger for Z80 assembly.
    • Supports a wide range of Spectrum models.
  • Platform: macOS, with older versions available for Linux
  • Website: ZXSP Official Site

6. MESS (Multi Emulator Super System)

  • Description: MESS is part of the MAME project and supports emulating a wide range of systems, including Z80-based systems. It’s well-suited for those who want to emulate specific Z80-based hardware.
  • Features:
    • Supports a vast array of old systems and CPUs.
    • Excellent for detailed emulation of complete systems.
    • Extensive documentation and community support.
  • Platform: Windows, Linux, macOS
  • Website: MAME Official Site

7. ZX80 Emulator (for Classic ZX80 Systems)

  • Description: This emulator is specifically for the Sinclair ZX80, which uses a Zilog Z80. It is useful if you’re working with or developing software for ZX80 systems.
  • Features:
    • Accurate emulation of the ZX80 system.
    • Includes basic debugging tools.
  • Platform: Windows, Linux (with Wine or similar tools)
  • Website: ZX80 Emulator by Vavasour

Conclusion

The choice of emulator depends on your specific needs:

  • For general Z80 development and testing: ZEMU or EmuZ80 are great starting points due to their simplicity and ease of use.
  • For full system emulation: SimH or MESS provide robust options if you need to emulate entire Z80-based systems with peripherals.
  • For ZX Spectrum enthusiasts: ZXSP is a specialized tool that’s ideal for Spectrum-related development.

These emulators offer a range of features and platforms, allowing you to develop, test, and debug your Z80 code effectively.

Boot Code Test 1

The Z80 typically runs embedded systems or simple computers that often boot directly from ROM.

1. Understanding the Z80 Boot Process

When the Z80 microprocessor is reset or powered on, it starts executing instructions from the memory address 0x0000. This is typically where the system’s ROM is mapped, so the very first instructions of your boot code must reside at this address.

2. Writing the ROM Boot Code

Here is an example of a simple bootloader that would initialize the system and potentially jump to a more complex program or operating system stored elsewhere in memory:

; Z80 Assembly Language Bootloader Example

ORG 0x0000  ; Start the program at address 0x0000, where the Z80 begins execution

start:
    DI                 ; Disable interrupts during initialization
    LD SP, 0xFF00      ; Set up the stack pointer (example address)
    LD A, 0x00
    LD HL, 0x4000      ; Example: Clear RAM from 0x4000 to 0x7FFF
clear_loop:
    LD (HL), A
    INC HL
    LD A, H            ; Check if HL has reached 0x8000
    CP 0x80
    JR NZ, clear_loop

    ; Example hardware initialization
    ; This is where you would initialize I/O ports, peripherals, etc.

    ; Load and execute the main program
    LD HL, 0x0100      ; Suppose the main program starts at 0x0100
    JP (HL)            ; Jump to the main program

    HALT               ; Halt the CPU if execution returns here

; The rest of the ROM might contain the main program or additional initialization code

3. Explanation of the ROM Code

  • Disable Interrupts:
    • DI (Disable Interrupts) is used to prevent any interrupts from occurring while the system is initializing.
  • Stack Setup:
    • The stack pointer (SP) is set to a high address in RAM (0xFF00 in this example), which will not conflict with the boot code or other programs.
  • RAM Initialization:
    • The example clears a section of RAM (from 0x4000 to 0x7FFF). This step is often used to initialize memory to a known state.
  • Hardware Initialization:
    • This section would contain code to set up I/O ports, configure timers, or initialize other peripherals that are part of the system.
  • Jump to Main Program:
    • The bootloader finishes by jumping to the main program, which starts at a predefined memory address (0x0100 in this example).
  • Halt:
    • The HALT instruction stops the CPU if execution ever reaches this point.

4. Assembling and Writing the Code to ROM

  1. Assemble the Code:
    • Save the boot code in a file named z80_bootloader.asm.
    • Use an assembler like z80asm to compile it into a binary format:
    z80asm -b z80_bootloader.asm -o z80_bootloader.bin This will produce a binary file z80_bootloader.bin that you can burn onto a ROM.
  2. Write the Code to ROM:
    • Use a ROM programmer to write z80_bootloader.bin to a ROM chip.
    • The ROM should be mapped to start at address 0x0000 in your Z80 system.
  3. Install the ROM Chip:
    • Place the ROM chip into the appropriate socket on your Z80-based system.

5. System Startup

When the Z80 microprocessor starts up, it will begin executing the code stored in the ROM at address 0x0000. The bootloader initializes the system and then jumps to the main program or operating system.

6. Expanding the Bootloader

  • Loading from External Storage:
    • If your system has external storage (e.g., a disk or tape drive), you can expand the bootloader to read the operating system or application code from that storage into RAM.
  • Interrupt Handling:
    • After the initial setup, you might want to enable interrupts and set up interrupt handling routines.
  • Hardware Abstraction:
    • The bootloader can also include code to abstract hardware details, making it easier to develop portable software for the Z80 system.

7. Debugging and Testing

  • Emulator Testing:
    • Use a Z80 emulator to test your ROM code before burning it to a physical chip. Emulators can provide debugging tools like breakpoints and memory inspection.
  • Physical Testing:
    • Once the ROM is installed, power on the system and verify that the bootloader runs as expected, initializing hardware and loading the main program.

Conclusion

Creating a bootloader for a Zilog Z80 involves writing ROM code that initializes the system and starts executing your main application or operating system.

This bootloader runs immediately upon power-on or reset, handling basic tasks such as setting up the stack, clearing memory, and preparing the hardware.

The example provided is a starting point, and you can expand it to handle more complex tasks depending on your system’s requirements.

Boot Code Test 2 – FDD, KEYB & TTY

To create a Zilog Z80 bootloader that boots from a floppy disk and enables keyboard input and serial console output for a TTY display, we need to consider the following components:

  1. Floppy Disk Booting: The bootloader needs to read the boot sector from the floppy disk into memory.
  2. Keyboard Input: The bootloader will set up the Z80 to receive input from the keyboard.
  3. Serial Console Output: The bootloader will set up a serial port for output to a TTY display.

Here’s how we can structure the bootloader:

Z80 Bootloader Code

; Z80 Bootloader for Floppy with Keyboard and Serial Console TTY Display

ORG 0x0000  ; Start at address 0x0000, where the Z80 begins execution

start:
    DI                  ; Disable interrupts during initialization

    ; Set up stack
    LD SP, 0xFF00       ; Set stack pointer near the top of memory

    ; Initialize serial port (assume port 0x80 for serial I/O)
    LD A, 0x00          ; Assuming 0x00 initializes serial port correctly
    OUT (0x80), A       ; Initialize serial port for output

    ; Initialize floppy disk controller (FDC)
    CALL init_floppy

    ; Load boot sector from floppy (first 512 bytes) into memory at 0x0100
    CALL read_boot_sector

    ; Jump to the loaded code in memory at 0x0100
    JP 0x0100

halt:
    HALT                ; Halt the CPU

; Initialize Floppy Disk Controller
init_floppy:
    ; Initialization code for the floppy disk controller
    ; This typically involves sending specific commands to the FDC hardware
    ; For this example, we assume it's already initialized by hardware
    RET

; Read Boot Sector from Floppy into Memory
read_boot_sector:
    ; Assume the floppy disk controller is mapped to I/O ports 0x10 to 0x1F
    ; Disk parameters: track 0, sector 1, head 0
    LD A, 0x00          ; Track 0
    OUT (0x10), A       ; Send track number to FDC

    LD A, 0x01          ; Sector 1
    OUT (0x11), A       ; Send sector number to FDC

    LD A, 0x00          ; Head 0
    OUT (0x12), A       ; Send head number to FDC

    LD A, 0x01          ; Number of sectors to read
    OUT (0x13), A       ; Send sector count to FDC

    ; Assume the boot sector is loaded into memory at 0x0100
    LD HL, 0x0100       ; Destination address in memory
    LD B, 128           ; 128 bytes per sector (for the first 128 bytes)

    ; Read loop for 128-byte block
read_loop:
    IN A, (0x14)        ; Read a byte from FDC data port
    LD (HL), A          ; Store byte in memory
    INC HL              ; Increment memory address
    DJNZ read_loop      ; Repeat for the next byte

    ; Repeat for the remaining 384 bytes (if the FDC reads 512 bytes per sector)
    LD B, 128
    JR NZ, read_loop

    RET

; Keyboard Input Handler
read_key:
    ; Wait for keypress from keyboard (assuming keyboard input at port 0x20)
    IN A, (0x20)        ; Read from keyboard input port
    AND A               ; Check if a key is pressed
    JR Z, read_key      ; Loop until a key is pressed

    ; Process keypress
    OUT (0x80), A       ; Output the keypress to the serial port (TTY display)
    RET

; Serial Console Output
serial_out:
    ; Output character in register A to the serial port
    OUT (0x80), A       ; Output to serial port (assuming port 0x80)
    RET

times 510-($-$$) db 0  ; Pad the rest of the sector with zeros
dw 0xAA55              ; Boot signature

Explanation of the Code:

  1. Initialization:
    • The bootloader starts by disabling interrupts (DI) and setting up the stack pointer (SP) near the top of memory.
  2. Serial Port Initialization:
    • The serial port is initialized with an assumed port address 0x80. The initialization sequence is simplified for this example.
  3. Floppy Disk Initialization:
    • The init_floppy routine is a placeholder for any necessary initialization of the floppy disk controller (FDC).
  4. Reading the Boot Sector:
    • The read_boot_sector routine reads the first 512 bytes (one sector) from the floppy disk into memory starting at address 0x0100.
    • The floppy disk parameters (track, sector, head) are set using output ports, and data is read into memory using a loop that handles 128 bytes at a time.
  5. Keyboard Input:
    • The read_key routine reads a keypress from the keyboard, assumed to be connected to I/O port 0x20.
    • The keypress is then output to the serial port for display on a TTY terminal.
  6. Serial Console Output:
    • The serial_out routine sends the contents of register A to the serial port, which could be connected to a TTY display or other serial devices.
  7. Bootloader End:
    • The bootloader finishes with padding to ensure it is exactly 512 bytes, followed by the boot signature (0xAA55), which is required by many systems to identify a valid boot sector.

Booting the System:

  1. Floppy Disk Preparation:
    • The bootloader binary (bootloader.bin) should be written to the first sector of a floppy disk using a tool like dd: dd if=bootloader.bin of=/dev/fd0 bs=512 count=1
  2. Running the Bootloader:
    • Insert the floppy disk into the Z80-based system and power it on. The system should execute the bootloader, which initializes the serial port, reads the boot sector, and allows interaction via the keyboard.
  3. Serial and Keyboard Interaction:
    • The serial console will display characters typed on the keyboard, and any further boot process loaded from the floppy can interact with the user through this interface.

Considerations:

  • Hardware-Specific Initialization: The actual hardware specifics for the keyboard, serial port, and floppy disk controller might differ, requiring adjustments to the port addresses and initialization sequences.
  • Error Handling: This example assumes a simple and straightforward boot process. More robust error handling should be added for a production environment.
  • Peripheral Addressing: Ensure that the port addresses (e.g., 0x80 for serial, 0x10-0x1F for floppy, 0x20 for keyboard) match your system’s actual hardware configuration.

This code provides a starting point for developing a Z80 bootloader that boots from a floppy disk and allows interaction via a serial console and keyboard. You may need to tailor the code further based on your specific hardware environment.