Z80 Snake

Classic Snake Game for the Z80 Microprocessor

Dial 555-7635 to Launch
            ╔═══════════════════════════════════════════════════╗
            ║                                                   ║
            ║     +--------------------------------------+      ║
            ║     |                                      |      ║
            ║     |        OoooooO         *             |      ║
            ║     |              o                       |      ║
            ║     |              o                       |      ║
            ║     |              o                       |      ║
            ║     |                                      |      ║
            ║     +--------------------------------------+      ║
            ║                                                   ║
            ║           Z 8 0   S N A K E   G A M E             ║
            ╚═══════════════════════════════════════════════════╝

Introduction

Welcome to Z80 Snake---the classic arcade game, running in a browser-local Z80 WASM emulator through the Emulator.ca Systems modem path.

The snake game is one of computing's most enduring diversions. Its roots stretch back to the 1976 arcade game Blockade, but the concept truly entered the public consciousness through Nokia's mobile phones in the late 1990s. The premise is timeless: guide a growing snake around a field, consuming food to increase your score while avoiding walls and your own ever-lengthening tail. Simple to learn, devilishly difficult to master.

What makes this implementation remarkable is not the game itself, but the journey the code takes to reach your screen. The game is written in C---a high-level language by the standards of 8-bit computing---and compiled down to native Z80 machine code. That binary is then loaded into a faithful Z80 CPU emulator running inside your browser, complete with BIOS, UART, and interrupt-driven timer hardware. The Z80 executes each instruction one cycle at a time, driving the snake across your terminal at 60 frames per second through ANSI escape sequences.

You are, in effect, playing a C programme running on an emulated 1976-era microprocessor, communicating through a simulated serial port, over a virtual modem connection. The fact that it works at all is a small miracle. The fact that it plays smoothly is a testament to both the elegance of the Z80 architecture and the power of modern web technology.

This version (555-7635) runs the C-compiled binary with timer-driven gameplay. For the hand-crafted Z80 assembly variant, dial 555-9807. See the Snake (Z80 ASM) manual for details.

Technical Overview

Quick Start

Ready to slither? Here is everything you need:

  1. Dial 555-7635 from the EC-TTY main menu
  2. Wait for CONNECT 1200 and the Z80-C BIOS/program assets to load
  3. Press any key on the title screen to start
  4. Steer the snake with W A S D or the arrow keys
  5. Eat the food (*) to grow and score points
  6. Avoid the walls and your own tail
  7. Press Q at any time to quit
ATDT555-7635
CONNECT 1200

=== Z80 SNAKE ===
v2.0 in C
Controls: WASD or Arrow Keys
Q to Quit

Press any key to start...

+--------------------------------------+
|                                      |
|                                      |
|                  *                   |
|                                      |
|        Oooooooo                      |
|               o                      |
|               o                      |
|                                      |
|                                      |
+--------------------------------------+

Getting Connected

Dialling In

From the EC-TTY terminal, dial the Snake game line:

ATDT555-7635

Upon connection, you will see the Z80 emulator initialisation sequence. The system loads the BIOS, then the snake binary. Within a few moments, the game field appears and play begins.

Terminal Requirements

Z80 Snake requires a terminal capable of:

If using the EC-TTY terminal, all requirements are met by default.

Modem Profile

This backend is listed with the V.32bis modem profile, but the current browser modem path negotiates CONNECT 1200 for this line. The game itself is browser-local after the static /bios/z80-c/bios.bin, /programs/z80/snake.bin, and Z80 WASM assets load.

Gameplay

The Playing Field

The game takes place on a bordered rectangular field, 40 characters wide by 20 characters tall. The border is drawn in cyan and consists of:

The snake cannot pass through the border. Hitting any edge ends the game.

The Snake

Your snake is drawn in green:

Symbol Meaning
O Snake head
o Snake body segment

The snake starts at three segments long, positioned in the centre of the field, moving to the right.

Food

Food appears as a yellow * at a random position within the field. When the snake's head reaches the food:

Scoring

Your score is displayed above the playing field and updates in real time. Each food item consumed is worth 10 points. The maximum snake length is 200 segments, giving a theoretical maximum score of 1,970 points (197 food items after the initial 3 segments).

Game Over

The game ends when:

Upon game over, you will see:

=== GAME OVER ===

Final Score: 150

Play again? (Y/N)

Press Y to restart or N to quit and disconnect.

Controls

Z80 Snake supports two control schemes: WASD keys and arrow keys.

WASD Controls

Key Direction
W Up
A Left
S Down
D Right

Arrow Key Controls

Key Direction
Up Arrow Up
Left Arrow Left
Down Arrow Down
Right Arrow Right

Other Commands

Key Action
Q Quit the game

You cannot reverse direction directly. If the snake is moving right, pressing left will be ignored. You must turn up or down first, then left. This prevents you from instantly colliding with your own body.

Strategy Guide

Early Game

When the snake is short (3-10 segments), you have plenty of room to manoeuvre. Use this time to get comfortable with the controls and the speed of movement. The timer-driven gameplay means the snake moves at a constant pace regardless of your input---you cannot slow down by hesitating.

Mid Game

As the snake grows to 20-50 segments, corridors become tighter. Begin thinking one or two moves ahead. Avoid trapping yourself in corners. A good strategy is to sweep the field in long horizontal or vertical passes, creating predictable patterns that leave open space.

Late Game

Beyond 100 segments, the playing field becomes a maze of your own making. Every move matters. Plan your route to the food carefully---the shortest path is not always the safest. Sometimes it is better to take a longer route that leaves you an escape path.

General Tips

Technical Details

The Z80 CPU

The game runs on a faithful emulation of the Zilog Z80 microprocessor, an 8-bit CPU with a 16-bit address bus. The Z80 was the heart of countless home computers and arcade machines in the late 1970s and 1980s. For a complete reference on the Z80 architecture, dial 555-4355 to access the Z80 CPU Reference Manual.

BIOS v1.2

The SLP-Z80 BIOS v1.2 provides essential services to the running programme:

Service Code Function
GETC $01 Read a character from UART (blocking)
PUTC $02 Write a character to UART
PRINT $03 Print a null-terminated string
KBHIT $05 Check if input is available (non-blocking)
CLEAR $30 Clear the terminal screen

Services are invoked via RST 08h with the service code in register C.

Timer Interrupt

The BIOS v1.2 timer fires at 60 Hz (every 16,667 CPU cycles at 1 MHz). This drives the game loop, ensuring consistent snake movement speed regardless of how quickly or slowly the player provides input.

Memory Map

Address Range Contents
$0000-$1FFF BIOS ROM (8 KB)
$2000-$FEFF Programme RAM (snake.bin loaded here)
$FF00-$FFFF Stack area

Command Reference

Command Context Description
W / Up In-game Move snake up
A / Left In-game Move snake left
S / Down In-game Move snake down
D / Right In-game Move snake right
Q In-game Quit the game
Y Game over Play again
N Game over Disconnect

Quick Reference Card

╔══════════════════════════════════════════════════════════════════════╗
║  Z80 Snake - QUICK REFERENCE                    Emulator.ca Systems ║
╠══════════════════════════════════════════════════════════════════════╣
║                                                                      ║
║  DIAL: 555-7635 (C version)         ALT: 555-9807 (ASM version)    ║
║                                                                      ║
║  CONTROLS:        WASD or Arrow Keys                                ║
║    W / Up       = Move up            SYMBOLS:                       ║
║    A / Left     = Move left            O  = Snake head (green)      ║
║    S / Down     = Move down            o  = Snake body (green)      ║
║    D / Right    = Move right           *  = Food (yellow)           ║
║    Q            = Quit game                                         ║
║                                                                      ║
║  SCORING:         +10 points per food eaten                         ║
║  MAX LENGTH:      200 segments                                      ║
║  GAME OVER:       Hit a wall or your own tail                       ║
║                                                                      ║
║  CPU: Z80 @ 1 MHz | BIOS v1.2 | Timer: 60 Hz | Field: 40x20      ║
║                                                                      ║
╚══════════════════════════════════════════════════════════════════════╝

Troubleshooting

Problem: Snake moves erratically or skips positions

This can occur if the browser tab is throttled or the terminal falls behind the ANSI redraws. The current modem path reports CONNECT 1200; if the tab is backgrounded, bring it forward and reconnect.

Problem: Arrow keys do not work

Arrow keys send ANSI escape sequences (ESC [ A/B/C/D). If your terminal is not configured for VT100 emulation, these sequences may not be generated correctly. Use the WASD keys as an alternative, or check your terminal configuration.

Problem: Colours do not display

The game uses ANSI colour codes for the snake (green), food (yellow), and border (cyan). If your terminal does not support ANSI colours, the game will still be playable but the visual distinction between elements will be reduced. Ensure ANSI colour support is enabled in your terminal settings.

Problem: Game ends immediately after starting

The snake begins moving to the right upon game start. If input is sent during the loading phase, it may be interpreted as a direction change that causes an immediate collision. Wait for the game field to fully render before pressing any keys.

Problem: Display appears garbled after game over

Press N to cleanly disconnect. The game restores the cursor and clears the screen upon exit. If you disconnect by dropping carrier (hanging up the modem) instead, the terminal may retain the game's hidden cursor setting. Type the ANSI sequence ESC [ ? 25 h to restore the cursor, or simply reconnect to the BBS.

See Also


Z80 Snake -- C version with timer-driven gameplay

Emulator.ca Systems

Document Revision 1.0