How to Create an Infinite Maze on the ZX81

My take on a ZX81 version of the 10 PRINT one-liner maze generator from the C64.

I saw the Commodore 64 maze generator for years, but ignored it on my ZX81 for different reasons. For one, the characters needed didn’t exist on the ZX81 keyboard. The other was the lack of automatic scroll. Undeterred this month, I created my own version in Sinclair BASIC. I’m quite happy with the results, even if not quite the same.

# Not quite 10 PRINT.

I’d run across the 10 PRINT maze generator some time back. Using unique symbols from the Commodore 64, it forms an endless maze on the screen. To be fair, it works because the screen always has an opening below it, making it more of an infinite runner. But the concept is compact and easy to understand.

10 PRINT CHR$(205.5+RND(1)); : GOTO 10
– 10 PRINT for the Commodore 64 Computer

The ZX81 has a couple challenges that prevents it from emulating the one-liner. The first, and biggest issue, is that the ZX81 doesn’t support invite scroll. Go to far down on the screen and you get a screen full error. You can use CONT to continue if you like. But that doesn’t follow the spirt of the original program.

The other issue is that the original program is two lines of code. The C64 allows you to concatenate many lines by using the colon separator. I’ve wondered if there was a way around that, but haven’t found a way. Even if I did—as noted above, the characters used by the C64 aren’t available on the ZX81. I have lost my attempt to emulate the simplicity of 10 PRINT. That doesn’t mean I shouldn’t try.

# My infinite maze.

By not using a one-liner concept, there were more options to make something similar. I landed on using the two diagonal block characters (CHR$ 6 and 134). There are two ways to print the random characters. The first would be to use the CHR$ command along with some math. This takes advantage of the the second character being an inverse of the first. All you need to do is add 128 to it—or not.

PRINT CHR$ (6+128*INT (RND*2))

The other way is to use a string slice with the random number selecting an index of the string. This was my first thought and is the routine I used in the program itself. I think this version is more flexible in that it doesn’t assuming anything about the characters. Thus, you could swap them out with other characters to get different effects.

# Printing and scrolling.

That along didn’t yield the results I wanted as the characters are too compact. This prevents you from using the results as a maze. To compensate, I added single space to the line to give it a bit of breathing room. This works well, but has a side effect of lining up the next line exactly below it.

To make it more maze like, I added in a test to ensure every other line printed a leading space or a trailing one. Those tests created a nice pattern effect, like the C64 version but not exactly the same.

Infinite Maze, ZX81 Screenshot, 2023 by Steven ReidInfinite Maze, ZX81 Screenshot, 2023 by Steven Reid

To make a never-ending maze, I added the SCROLL command to the program. This moves the display up from the bottom. Using a FOR loop, I controlled the number of characters printed on the line. I then did a NOT on A to adjust the space location and printed the next line.

# Mostly done.

This worked well and generated the maze I was looking for. I like the omit look, even if it took more than a few extra lines of code to work. The screen is quick and creates a random and pretty picture. That said, we could optimize the code further.

Futzing with the routine I found you could drop the AT function by moving SCROLL up. This will use the next line at the bottom of the display. Since I still need the loop, though, It didn’t make a huge difference. It might be a tiny bit faster, but not enough to notice in testing.

Simplicity is the ultimate sophistication.
– Leonardo da Vinci

Leaving the program as is, feel free to try to improve it further. Besides minimizing the code, you might also be able to write a 1K version. I’m not sure you could fit a full screen in, but you could get close. There are also hardware and software ways to expand the ZX81 character set to get closer to the C64 version.

For such a simple program, there are many different ways to expand and foster the code. Give it a go and share your successes.

Comments on this article:

No comments so far.

Write a comment:

Type The Letters You See.
[captcha image][captcha image][captcha image][captcha image][captcha image][captcha image]
not case sensitive