Making a Better Maze Display for the ZX81 Computer

The teletype display wasn’t working for some. I took the logical next step and rewrote it.

Soon after sharing my Maze Generator for the ZX81, it was obvious that something didn’t quite click. I got a few comments about the maze didn’t work or that didn’t look right. It was clear the '70s style teletype display wouldn’t cut it. Fortunately, I could fix that.

# Reworking the display.

The rest of the program is pretty much the same, but the display is much more compact and, hopefully, clearer. I could have replaced the existing characters with solid spaces but I decided that wouldn’t look very good. Instead, I built out the maze using character graphics. The result turned out better than I expected.

Maze Generator v2, ZX81 Screenshot, 2024 by Steven ReidMaze Generator v2, ZX81 Screenshot, 2024 by Steven Reid

The new display allowed for a more clean appearance on the screen. In addition to it being more intuitive to the users, it fits better into the overall style of a ZX81. The previous version just felt like a rewrite of an old program—which it was. Although the maze generator algorithm is the same, the style fits better.

# Sharing a video.

In this era of video driven engagement, I thought it best to also capture the program running. Using ZXSP, I could capture a quick GIF to show how the program worked. In this case, I showed off the speed of the maze generator as well as the result.

Mazegen v2, Video, 2024 by Steven ReidMazegen v2, Video, 2024 by Steven Reid

The video isn’t very long and does a decent job of showing how it works. I doubt many people actually run the programs on my site. In this way, I can engage a larger audience by publishing it on other sites like Maze Generator Demo on YouTube.

What I didn’t expect was how popular that video would be. I somehow connected to the Zeitgeist of the moment—perhaps mazes interest people. To date, 9,450 people have watched the video over the last 108 days. Here are some more stats for reference:

Maze Generator Demo YouTube Statistics on May 26th, 2024Maze Generator Demo YouTube Statistics on May 26th, 2024

Sadly, I haven’t capitalized on this opportunity. My other videos haven't garnered nearly the same interest and I’ve not had the time to focus as much on my ZX81 hobby of late.

# Reworking the code.

Thinking through how I would code the new routine, I first needed to figure out what it would look like. My first ideas were to consolidate it down to one character. Although it would have worked, I felt it would be too small. Just replacing the charters, as noted before, felt too blocky. I needed a different plan.

As usual, while out on a run, I thought through the graphics and math of the problem. The solution I landed on was a rework of the code. The current display routine generated 3 characters across and 2 down for each cell. In the new version, I adjusted that to 2 characters across. This removed the elongation of the original routine, allowing the maze to look square.

Much of the code, then was just adjusting what was there. In fact, you’ll note in the assembly that I didn’t bother adjusting all the comments. No matter, the interesting part as the bottom right corner. Depending on the walls printed, I had to pick one of four characters. This is where the math played in.

To display the correct corner, I needed to know what walls had been removed or added. Fortunately, I already have that information in the cell. Even better, I can reuse that information to determine what character to display. To do that, I created a little array that I can use to pull the correct character.

        ld a,(hl)  ; pull wall information
  push hl ; save cell address
  ld hl,corner ; set hl to corner address
  ld d,0 ; convert a to 16bit
  ld e,a
  add hl,de ; add to corner address
  ld a,(hl) ; grab character
  pop hl ; restore wall location
  rst $10 ; and print the corner

The code isn’t difficult. The first thing I need to do is grab the wall information. I then grab the address for the corner and add the value to it. Lastly, I pull the character and display it. The corner array is a bit further down in the code and looks like this:

  db $81, $83, $85, $87

Though I rearranged this slightly in the assembly code, the essence of the algorithm remained the same. With determination, I set to work hacking up some code to generate the maze.

# So are we done yet?

I ended up really liking the results of this version. Although not a huge change, it works well and has that ZX81 vibe which I was looking for. Am I done, though? No. I’ve been slowly hacking at a couple of different ideas to use the routine for. I also haven’t been as happy with the random number routine and I’ve been playing with that as well.

I don’t have anything lined up yet for next month and work doesn’t look to get any slower, but hopefully I can find some time to put something together. Even better would be if I can do something with this maze generator. We’ll see.

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