Sunday, 17 July 2022

Remaking 3D Monster Maze for the Commodore PET

3D Monster Maze is of course the best game for the ZX81. I first played it on my first ZX81 back in 1982 and have loved it ever since. It is amazing what can be created with simple character block graphics.

I remember back in 2017, when I was drawing out the artwork for the PET replacement keyboard, it occurred to me that the PET character set included the same style graphics as the ZX81/TS1000.

Included on the PET are all the half and quarter block character on the ZX81*.

* spoiler: well, not quite all characters.

Around the same time, I came across Paul Farrow's reverse engineered source for the 3D Monster Maze. So, I got to thinking, I wonder if I could use that to make a PET version?

http://www.fruitcake.plus.com/Sinclair/ZX81/Disassemblies/MonsterMaze.htm

Now, first off, the ZX81 is 32x24 characters, and the code was a combination of Z80 assembly and ZX81 BASIC. How hard can it be to convert that to 40x25 characters in 6502 assembly? Well, maybe a bit too hard, so I wrote it in C instead to make my life a little easier.

I started with the first screen. Should be fairly simple, some block graphics and text. (The black and white pictures in this post show the ZX81 / TS1000 version, mainly screenshots from the Eighty One emulator. The black and green pictures are output from my new PET version from the Vice emulator)

Then I hit the first problem. It turns out that I didn't have all of the characters on the PET. The one highlighted in red was missing.

It's a character where the top half is 50% grey and the bottom is solid black. The ZX81 and the PET double the number of characters the have in ROM by inverted versions of each of those characters using additional hardware. So the one missing characters is actually two, one with bit 7 clear ($0A), and an inverted version which has bit 7 set ($8A).

It seems the PET has one where the bottom is 50% grey, but not the other way around. I found matches for all the other characters, but not that one. Ah well, it's only one character.

I just swapped that for a full 50% grey square, and moved his hand (it is a hand?) down a bit.

There, you would hardly notice it. I kept Malcolm Evans credit, and added my own. I also replaced the capital i and - characters in the Ringmaster with solid lines. If I hadn't told you about those changes, you probably wouldn't have noticed.

So far, so good. Is this going to work?

Guess what I found on the next screen? Yes, that one missing character is back again

I guess this is the Ringmaster's nose?

For the PET version, I just gave him a bigger nose.

Again, nothing you would notice. Looks like I am getting away with this. I wrote the text scrolling and screen update routines, and it was sort of coming together.

Then I moved onto the difficult bit. The main point of the game the 3D maze.

The wall in the far distance there, two black squares and one full 50% grey square isn't it?

No, it turns out the furthest wall is made up of six characters, and yes, it needs the one I don't have. In this case, the non-inverted version, 50% on the top, white on the bottom half.

At that point, I must have received a load of orders, or found something new to design. Either way, I put the code to one side with a plan to come back at some point.

...... insert some tumbleweeds here .....

Move forward to 2021, and in the lull between finishing packing all the Mini PET 40/80 kits and waiting for TFW8b to sort out the final packaging and flourishes, I thought it would be good to revisit it and see if I could finish the PET remake of 3D Monster Maze.

I decided the best option was to adjust the geometry. Rather than 6 squares making up the central square, I went for 1. You can see it best on the exit screen. This shows a pattern of random characters which start in the central six characters, and move outwards towards the edge.

For the new PET version, I went for a single central square, and that seemed to work quite well.

In the actual maze, the vanishing point looks fine.

However, I will take the opportunity to make a small improvement.

The PET has some diagonal half squares, and they work very nicely as maze walls.

I have left the ZX81 style crinkly walls as a hidden option.

On the ZX81 version, the score was always blank until you scored anything.

I decided to show the score from 0.

The ZX81 screen is 32 characters wide. The PET is 40. I have centred the screen and added 4 blank characters each side. I also updated my credit and rolled the date to 2021. Happy 40th Birthday 3DMM.

The ZX81 version works by drawing full walls on each side, then drawing in passage ways as required. You can sometimes see this when the screen is being drawn.

For the PET version, I use a double buffering technique, which helps to avoid this. I draw the screen to a 32x24 array, and then once everything is drawn, I copy the whole buffer to the PET screen. That makes it easier to offset it 4 characters from the left to centre things on the 40 column screen, and avoids tearing as much as possible.

Unfortunately that means it is not suitable for original 2001 PETs, as the screen updates will create "snow", caused by the video RAM being written at the same time as it is being drawn.

Something like the classic Space Invaders for the PET only moves one row of aliens at a time, and that fits in the gap between redraws. (the blue blocks show video RAM updates which fit in the gaps between the yellow sections where the screen is being drawn).

I did look at trying to do the screen copy in the VSync gaps, but it takes too long. There are 24 blocks, one for each line. The gap between them is the overhead of the loop and the call to memcpy. The two larger gaps are the PETs interrupt handler where it does it's keyboard scan etc.

Even if I disabled the PET interrupt handler, and wrote the whole copy routine in tight assembler, I'm not sure it would be enough. That the would reduce the gaps, but when it's actually running, I expect memcpy will be fairly well optimised, so the total is unlikely to be less that all of the blue blocks squashed together, and that is still too much to fit in the gap. If I split it into two or three updates, you will get tearing. I could rewrite the whole draw routine to only draw the bits of wall the need to change, but that's a lot of work and may not even be enough as there will always be times when the player turns to face a wall or Rex appears, so there will be snow on the 2001 whatever.

So it is fine on the 4032, and also any 2001N / 2032 / 3032 that have the requisite BASIC 4 and 32K RAM, just not the original 2001s with the chicklet keyboard and built in datasette.

The Mists of Time

One of the concepts I remember from 3D Monster Maze is the "Mists of Time".

What happens here is the ZX81 is switched to "FAST" mode. This is where it stops drawing the screen to it can run code all the time (instead of just in the gaps at the and bottom of the screen), and it does so for about 30 seconds whilst it is generating the random maze. This bit of the code is written in BASIC, and so is quite slow.

For the PET version, I wrote the whole thing in C. I was initially worried that the 1MHz 6502 might be slower than the 3.25MHz Z80, and I might have to hand turn some 6502 code to speed this bit up, but to my surprise it took less that half a second in C.

I updated the instructions to reflect that. To emulate the mists (i.e. the ZX81 not producing a picture so you old TV would show snow), I randomly cleared the screen a block at a time, and then revealed the maze a block at a time. That whole process takes several times longer than generating the maze!

The last thing to do was draw Rex.

From the first view to the second last frame of Rex animation, it's all black and white quarter squares, so translates 1:1 from the ZX81 version.

The last frame adds some details, and it is terrifying.

Even more so when you see just how many of the missing character Rex is drawn from.

A bit of artistic license here, moving his right arm up a bit to use whole squares, opening his mouth wider and adding a couple of extra teeth.

Either way. I expect the player is not going to be analysing the detail of the animation at this point.

Hopefully, you will find the exit, rather than Rex finding you. When you go through the exit, the ZX81 version takes you back to the Ringmaster and 30 seconds of the Mists of Time whilst it generates a new maze. Since that isn't required for the PET, I added an effect to have black characters create a tunnel effect for the exit which eventually fills the screen, and then the white square snow effect to the start of your new maze.

There are a few other extra bits I added, but I'll let you find those yourself.

There isn't any sound. I did try to add clumping footsteps for Rex. I also tried a Jaws type theme as Rex was approaching. In both cases, they sounded comically awful on the tiny piezo speaker on the PET, so I deleted the sound code never to be heard from again.

80 Column Mode

One extra I will tell you about what happens if you run this on an 80 column display PET (or Mini PET in 80 column mode).

The display is split, on the left is the same as the 40 column version. However, on the right there is a Pterodactyl's eye view of the maze. You can see it being initially generated, and then once it is complete, you can see yourself (the arrow showing the direction you are facing), Rex (R) and the Exit (X).

You can also follow Rex's progress as he leaves 'footprints' where he has been. The footprints are in the original code, the maze squares are changed once Rex has been there, although isn't used for anything. I wonder if there was a plan to draw these on the maze screen so you know that you are getting close to Rex?

You can also see that 'Rex Lies In Wait' actually means 'Rex is stuck'. The logic it uses is to move towards the player, along and down, even if that means walking down a dead end. As soon as you move past rex, he can follow you again.

There is also a small view of the maze ahead of the player, so you can see how that translates to the 3D view.

These were both added to help me during development, but I thought I would leave them in, they are useful as a trainer, and also to see how things work under the hood.

3D Monster Maze for PET and Mini PET is available on a cassette tape from The Future Was 8 bit. There is a video on the listing, but no matter what Rod says, there isn't any treasure in the maze. There never was any treasure in the maze. There never will be any treasure in the maze.

https://www.tfw8b.com/product/3d-monster-maze-pet-32k

Here it is on cassette with the two original releases of 3D Monster Maze (J.K.Greye software was split into two and 3D Monster Maze ended up with New Generation Software).

There is also a digital download available from itch.io.

https://tynemouth.itch.io/pet-3d-monster-maze

It needs a 32K PET with BASIC 4. Ideally a 40 column screen, or a Mini PET 40/80 so you can run it in 80 column trainer mode as well.

See also a port by George Beckett to the Jupiter Ace / Minstrel 4th

https://github.com/markgbeckett/jupiter_ace/tree/master/3d_monster_maze


Rex lies in wait........

Advertisements

This post was previously a Patreon exclusive post. If you want advance previews of posts like this and behind the scenes progress on new projects, you can follow along and support me on Patreon:

https://www.patreon.com/tynemouthsoftware

Sunday, 10 July 2022

One and a Half Million Views

My little blog has now clocked up 1,500,000 views over its 12 years. Not bad. Thank you for contributing to that view count.


I missed the 1 Million views (because 2020), so I thought I would celebrate 1.5 million instead.

You can see it is a general growth over time, with a couple of anomalies. One big spike (which I will cover later), and a big dip when I had to shut down for a while. It seems to be recovering, and will hopefully return to it's original trajectory.

It's interesting to look at the top posts.

I say top posts, I should say "most viewed" posts, because I don't think that all of these would feature in what I would consider the best posts. Maybe I should look at those for 2 million views.


1 - Minstrel ZX80 Clone (December 2016, 49.1K views)

http://blog.tynemouthsoftware.co.uk/2016/12/minstrel-zx80-clone.html

This is the large blip on the chart at the start of 2017. This was the very first post about the Minstrel. It wasn't very good, it was just "hey here is something I made". There were a couple of errors on the PCB and I just about got it working by the end of the post. That post got picked up by Hackday, and got an awful lot of views. I wasn't really ready for that, I didn't have a store or anything at that point. I was only selling the odd USB keyboard via email at that point. 

This is the post that started lots of things, the first Minstrel, selling PCBs, selling kits, the Tindie store etc.


2 - Raspberry Pi B+ ZX Spectrum USB Keyboard Case Mod (August 2014, 13.8K views)


This was one of the first "fit a Raspberry Pi and USB keyboard controller into a spare computer case" posts. I did lots of those. I took them all off line a while ago. That was 10 years ago when you could get a tatty broken Spectrum off ebay for a tenner, buy a new membrane and a new faceplate and turn it into something else.


3 - Asrock CIR Remote Demystified (April 2012, 12.2K views)

I never understood why this consistently gets loads of views. I was building a media PC and couldn't find the pinout for the connector, so I worked it out, wired it up to a cheap IR decoder and wrote it up.

I had been using the list at the start of this post, but it appears there is some discrepancy on view count on each of the individual pages, for example, this one shows 8.17K above, but the individual stats page shows 12.2K? 


I'll use the view count from the individual stats in the headings.


4 - ZX81 Internal 16K RAM (April 2012, 8.99K views)

http://blog.tynemouthsoftware.co.uk/2017/10/zx81-internal-16k-ram-reversible-version.html


Finally what I would consider a good post. This was a follow up to a previous post where I upgraded a ZX81 to have 16K internal RAM. To do that, I had to cut a few tracks under the RAM chip. This was an alternate technique that was reversible as it didn't require any tracks to be cut.


5 - Arduino Based ZX81 USB Keyboard (February 2012, 11.3K Views)


This was the first of the USB keyboard posts, back when I was using Arduino keyboard library hooked up to V-USB. That didn't last long, as I could never get it to behave how I would liked, so it wasn't long before I changed to microcontrollers with hardware USB and wrote new code. Like all the rest, this one is offline now.


6 - ZXBaremulator - Bare metal ZX Spectrum emulator for Raspberry Pi (June 2018, 6.75K Views)

http://blog.tynemouthsoftware.co.uk/2018/06/zxbaremulator-bare-metal-zx-spectrum-emulator-for-raspberry-pi.html


This was another USB keyboard conversion, this time with a new bare metal ZX Spectrum emulator for the Raspberry Pi. This was one of the posher ones, with USB hub, USB joystick and a DC-DC converter to power the Pi from 9V. I quite enjoyed making things like that. This one is still online, presumably as it was mainly a review of the emulator.


7 - How the ZX80 Works (October 2019, 4.31K Views)

http://blog.tynemouthsoftware.co.uk/2019/10/how-the-zx80-works.html


Quite a nice post on the inner workings of the ZX80, with the help of the Minstrel 2 ZX80 clone.


8 - Arduino 80x25 TV Video Output Library (September 2013, 8.65K Views)

This was one of a series of posts where I extended Grant Searle's Arduino based TV out terminal and added I2C support and some extra graphics modes etc. Must revisit that one day and see what I could do with it these days.


9 - Building a Harlequin ZX Spectrum Clone (November 2016, 10.6K views)

http://blog.tynemouthsoftware.co.uk/2016/11/building-harlequin-zx-spectrum-clone.html

In order to test the divMMC future, I built a Harlequin ZX Spectrum clone on a PCB I got in exchange for fixing someone elses Harlequin.


10 - ZX Spectrum Voltage Regulator Replacement (November 2014, 9.96K Views)

http://blog.tynemouthsoftware.co.uk/2014/11/zx-spectrum-voltage-regulator.html


One of several posts advocating the replacement of 7805 regulator + heatsink with Recom / Traco Power switching regulator replacements.


Notable Mentions

Since the table at the start does not seem to be right, here are a few more posts that I thought should have been on there, and are in the range.


Easy Atari 2600 VCS Composite Video Modifications (May 2018, 5.92K Views)

http://blog.tynemouthsoftware.co.uk/2018/05/easy-atari-2600-vcs-composite-video-mods.html


This was the post where I went through the method of identifying which parts needed to be removed and where to pick up the signals for a composite video modification on the Atari 2600 and related systems.


Designing the divMMC Future (January 2018, 5.91K Views)

http://blog.tynemouthsoftware.co.uk/2018/01/designing-divmmc-future.html


This was quite a detailed look into the process of refining the design of the divMMC future to make it work on any Spectrum that actually works in the first place.


Keep the blog going on to 2 million views

Thank you for reading these blog posts. Please let me know if you enjoy them. I post links on twitter each week

https://twitter.com/tynemouthsw

This blog continues to be updated weekly. There is often quite a lot of work in these post, and that is supported by my wonderful Patreon supporters. 

There is a mixture of new posts (like this one) and updated versions of posts that were previously Patreon exclusive posts.

Patreon continues to get updates on what is going on behind the scenes, new posts and development logs, and well as regular updates in my Patreon only Discord server.

If you enjoy these posts, please consider supporting me if you can, but I understand it is a difficult time for everyone at the moment. 


I don't normally mention it, but there is also a one off PayPal donation link in the list on the top right of the screen, here is the link if you would like to contribute that way.

http://paypal.me/tynemouthsoftware


Advertisements

I sell PCBs for the things I design in my SellMyRetro store, along with some built and tested items. I still have a few USB keyboard controllers left, and I am selling them off on there. There are also currently a couple of built Minstrel 2's, although the built ones don't usually last long before they get snapped up.

https://www.sellmyretro.com/store/tynemouth-software

Most of the kits have now sold out at The Future Was 8 bit, but the pre-built Mini PET 40/80D boards are still available, whilst stocks last. And obviously, they have lots of other nice things elsewhere on the store. We hope in future to have a new kit to put on there, just trying to pull all the bits together for that.

https://www.thefuturewas8bit.com/shop/tynemouth-products.html