Skip to content

Implementation of "netwalk" game for the Amstrad CPC, using Z80 assembly language

Notifications You must be signed in to change notification settings

borilla/cpc-netwalk

Repository files navigation

cpc-netwalk

Overview

This repo is a record of my attempt to make a "netwalk" game for the Amstrad CPC, using Z80 assembly language

Note: There's a russian wikipedia page for netwalk but no english

Maze algorithm

The game is really based around maze generation. I've written many maze generators, in various languages, over the years but almost all based on Prim's algorithm

But, after reading Jamis Buck's page on maze algorithms, I found a beautiful (and simple) alternative to Prim's algorithm, which he calls the "Growing Tree algorithm"

This algorithm (which can actually be made to return exactly the same maze as Prim's) is naturally stack-based, so is easier to implement in Z80. This inspired me to finally combine my interests in mazes and in Z80 code, and make a Z80 netwalk game

Game size

The maximum game-grid size is 16 x 16 cells. Each grid-cell doesn't need to store too much data, so we can get away with using a single byte per cell, which means the entire grid can be stored in 16 x 16 x 1 = 256 bytes. This is a neat number for an 8-bit processor as we can index all cells very quickly by manipulating a single 8-bit register

In addition to the grid itself, we also set aside another 256-byte section of memory to use as a stack of cell indexes. This is needed for generating the grid. It will also be reused later when calculating connected cells while playing the game

Cell structure

Each cell is a single byte. The bits of this byte are used to represent different properties of the cell. My original intuition was to use the lowest four bits to represent exits to top, right, bottom and left respectively. Amazingly this coincided exactly with the subset of the Amstrad CPC character set between &90 and &9f used to represent maze-type shapes

Amstrad CPC maze characters

This made writing a quick BASIC program to help debugging the maze generator very simple

BASIC test prorgam

Cell bit pattern

The bit pattern for each grid-cell looks as follows, where bit 0 is the least-significant bit (LSB), bit 7 is most-significant bit (MSB):

Bit Usage
0 Top exit
1 Right exit
2 Bottom exit
3 Left exit
4 Tile rotation (low bit)
5 Tile rotation (high bit)
6 Connected to power supply
7 [unused]

Graphics

The game runs in four-colour mode 1. Tiles for the cells are 16x16 pixels and the screen is setup to be 256x256 pixels. If the grid-size is 16x16 cells this doesn't leave any room for anything apart from the game-grid (titles, banners, scores, timers, etc) so I may have to rethink either grid-size or screen layout but we'll carry on for now

Graphics are generated using Retro Game Asset Studio (RGAS)

There are 15 possible different combinations of exits for each cell and, for each of these, there are four rotation positions (to allow for relatively smooth rotation animation). In addition to these is another set of 15 "connected" cells (ie with a different colouring to represent being connected to the power supply)

In mode 1 each byte represents four pixels so each tile sprite takes 64 bytes. Total memory required for our tile sprites is 64 x 15 (exit combinations) x 5 (rotations plus connected) = 4800 bytes. In actual fact, it turns out to be much easier in terms of calculations if we allocate space for 16 exit combinations (ie include tiles representing cells that have no exits, even though they won't appear in the game) which turns out as 5120 bytes / 5KB. Rather than wasting this space, we can use these extra tiles to hold other sprites used elsewhere in the game, such as the power supply tile and reticule position indicator

Tile sprites

In addition to the tiles themselves, I had a stab at creating a chunky retro font. Surprisingly this took me less than one day for design and pixel wrangling. Each character is 7 x 11 pixels. There are 39 characters so this easily fits into less than 1KB (2 x 11 x 39 = 858 bytes)

Character set

Progress

This is how the game looks at the moment, running in the WinAPE emulator. The info bar at the top of the screen shows how many terminals are currently connected, the count of moves and rotations, and the time taken so far

Game screenshot

Here's a quick list of tasks in the approximate order I intend to do them. Not complete and probably going to change quite significantly as I gradually get stuff done...

  • Maze generation
  • Draw tile sprites
  • Render a single tile
  • Render whole game-grid
  • Show currently selected cell in rendered grid
  • Navigate around the grid using keyboard
  • Animate tile rotation
  • Add power supply tile
  • Calculate which cells are connected to power supply
  • Display connected tiles
  • Shuffle rotations before game
  • Recognise when game is complete (ie all terminals connected)
  • Allow different grid-sizes
  • Add timer/countdown
  • Game menus
  • Logo graphics
  • Sound effects
  • Music
  • Loading screen

About

Implementation of "netwalk" game for the Amstrad CPC, using Z80 assembly language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published