MAZIST v2.2
A maze generation programme for the Amstrad CPC
By Geoff Camp, 2020
Maze generation routine based on 'MAZE' as published in 'More Basic Computer Games', edited by David H Ahl,
published by Creative Computer Press. All other solving routines, grahics interface, sound, etc by myself.
History:
I originally wrote a maze generation programme (also called Mazist) on the Atari ST. It was also based on
David Ahl's routines but modified to be graphically based and mouse controlled. I used STOS - a beautiful
Basic language with easy music & sprite routines built in - to write that and it was released as shareware
under the Undersoft label.
Before I had the Atari I had an Amstrad 464, and later a 6128. Loved these machines and programmed quite a
bit in basic and taught myself some z80 machine code as well. Alas, once I went to 16bit I gave up using the
8bit CPC.
Today I have much free time and am revisiting my computer roots. I started this journey with a Raspberry Pi
running Retropi and discovered the wonderful world of retro gaming. Firstly playing the old Atari and Nintendo
games but then my world changed; I rediscovered the joys of those early 8 and 16 bit games. I tried to find
some old CPCs and STs but alas their cost and rarity in Austrlia is prohibitive and has made the search a futile
one so far. I now use a Raspberry Pi 'suitcase' setup with mouse/keyboard/joysticks to emulate my old CPCs and
STs when I'm on the move and have emulators set up on my PC Tower to programme and play games.
But playing games is not always stimulating enough.... so I decided to try my hand at programming again and chose
the CPC for this. I hadn't programmed anything in basic for many, many years but PDFs of the CPC manuals and
firmware calls helped immensely. I started off with Conway's game of life. It didn't take long to write the
programme in Basic and then came the steep learning curve - writing it in z80 machine code. I did release this
on an Amstrad Facebook page as an example of speed of basic vs compiled basic vs pure machine code. It was a
good learning exercise.
Many months passed and I pondered what to write next. I remembered Mazist I'd written on the Atari ST and thought
this would be a good start on the CPC. I knew where to find the basic maze generation code but the fun would be
converting it to a graphics interface, adding an on screen solve routine and some sort of user interface. After
many weeks of programming, testing, tweeking, testing, changing my mind, rewriting some code, testing, tweeking,
having a break, drinking too much coffee, rewriting some code and finally saying "That's enough!" I now present
MAZIST for the CPC......
MAZIST - A maze generation programme for Amstrad CPC 464/664/6128
Functions:
Produces a graphics based maze in a selectable size ranging from 10-79 horizontal nodes and 10-49 vertical nodes.
Each node is 2x2 squares and each square is 1x2 pixels so a 49x79 maze will fill a mode 0 screen.
The maze can be solved on screen by using the cursor keys to navigate to the exit. A mark can be left to assist
in identifying your progress around the maze.
The maze can be saved (and loaded of course) along with any progress in solving the maze.
A solution to the maze can be computed (Mouse solve) if you a really stuck.
Intro Screen:
Press [L] to load a previously saved maze - the disc has one saved maze on it already. The load is in
two parts - a screen shot of the maze it self loads first, then the array that describes the maze to the computer
is loaded.
Once loaded the 'Solve' routine is entered. Error checking is minimal.
Press [I] to get info and instructions for Mazist. Press [SPACE] at the end of each page to go to the next.
Press [SPACE] to enter the Maze Size routine.
Press [Q] to quit Mazist.
Maze Size:
Use the [CURSOR KEYS] to change the Horizontal and Vertical sizes for the maze.
Press [RETURN] when ready to generate the maze.
Maze Generation:
This page will display a counter for the number of nodes to compute. This is a recursive routine so the last
few lines of nodes can take a longer time to compute than the early ones. The counter does not count down every
node. I omitted this as the maximum sized maze would mean printing 3871 numbers. Time better spent calculating
nodes. A sound cuee will let you know the CPC is still working so be patient with big mazes.
Solve:
Use the [CURSOR KEYS] to navigate around the maze. Pressing [SHIFT] at the same time will mark a spot or line
so you can make and routes to try or not try or go back to. Once you have solved the maze you will be prompted
to press [SPACE] to continue either by the word SPACE at the bottom of the screen or by a flashing line at the
base of the screen if the maze is a large one.
Press [S] to save the maze. This is a two part process. Firstly a screen shot is saved. Note that a few bytes
of data are poked to the last line of the screen. This describes the position in the maze, its size, etc for
when the maze if reloaded. Any saved maze will overwrite any previous maze. Error checking is minimal.
Press[Q] to quit the maze and return to the Intro Screen.
Press [M] for a Mouse solve for the maze.
Mouse Solve:
The CPC will computer the solution to that maze. A growing red line at the bottom of the screen will indicate
progress and a sound cue will let you know that the CPC is still working. A small maze will be solved quite quickly.
Once the mouse solution is displayed you will be prompted to press [SPACE] to continue either by the word SPACE at
the bottom of the screen or by a flashing line at the base of the screen if the maze is a large one. The largest
maze will take a cup of coffee to mouse solve! Press [SPACE] when you've finished admiring the solution it return
to the Intro Screen.
The Future - Woohoo, now the present:
The above was writen when all the code was written in Locomative Basic. I wasn't happy with the performance and
firstly changed the routines to run on memory blocks instead of arrays. I was hoping this would allow a compiler
to be used to speed things up
a bit. Alas, I could't find a compiler that would handle the job unless I stripped the program right down so that
it became a shadow of its former self.
I did have some knowlege of z80 machine code (though the last time I used this knowlege was 30 odd years ago) so
I thought I'd try converting my basic code to machine code. The current version is the result of many a late night, many a cofee and
some interesting code bug searching hours. I have:
Converted maze generation routine to z80 M/Code
Converted Screen Printing routine to M/C
Converted Mouse Solve routine to M/C
Save and load routines now save/load blocks of memory so they are now faster and use less disc space
Performance is now phenominal - for instance, a 79x49 maze took 380 seconds to generate in basic but only 14 seconds
using M/Code routines. If you use an emulator in Turbo mode this is reduced to 4 seconds. Mouse solve routines also
run much. much faster.
Performance:
This table will give you some indication of maze generation times. I have used WinAPE to write Mazist and the Turbo
in the following table refers its turbo mode. The times are in seconds and are an average as times depend on the
amount of recursion that is needed towards the end on the maze generation process.
-----------------------------------------------------------------------------------------
| Maze Size | Basic | Basic-Turbo |M/Code Routines| M/Code-Turbo |
|---------------------------------------------------------------------------------------|
| 10x10 (100 nodes) | 6 - 4 | 3 - 1 | | |
| 20x20 (400 nodes) | 30 - 11 | 13 - 4 | | |
| 40x40 (1600 nodes) | 140 - 42 | 44 - 15 | 5 - 5 | 2 - 2 |
| 79x49 (3871 nodes) | 380 - 98 | 130 - 36 | 14 - 11 | 5 - 3 |
-----------------------------------------------------------------------------------------
Times are: to Generate - to Print
Contact:
Any comments, suggestions, offers of assistance, etc can be directed to me at goksteroo@gmail.com