Z-machine in BASIC

Hello folks,

Does anyone have any experience with implementing the Z-machine in BASIC?

I’m playing about with writing one (initially for v3) for the obscure Colour Maximite (http://geoffg.net/maximite.html) - this is an odd little machine which is really a 32-bit microcontroller that has been convinced it is an 8-bit microcomputer. Because of how it works the only development language available for it is BASIC unless you actually want to reprogram the flash on the microcontroller itself.

It’s only got ~80K RAM to play with, but it does have an SD card that I can use to page the Z-machine’s static memory from. That sounds like it might just be enough, but BASIC is not the most memory efficient language so I’m wondering whether the task is even possible, can anyone offer any insight?

Note that even if I succeed I doubt there are half a dozen potential users, so this is really just for my own entertainment / a technical challenge.

Best regards,

Tom

2 Likes

With 80K of RAM it seems likely to me that you’d be able to write an interpreter that can play at least some Z-Machine games, even if it can’t handle those that use the full 64K RAM. So I’d say go for it, get an initial version working, and then you can see what the overheads are. If it leaves you with 60K for the interpreter’s RAM, then with some work you might be able to optimise your code enough to allow for the full 64K; if only 40K is left then you probably can’t without changing to another language.

1 Like

Even if there’s only 40K of free RAM, using the SD card as a swap file might be practical for games that need the full 64K. Infocom’s virtual memory system was ROM-only, but there’s no reason a modern one backed by flash would have to be.

2 Likes

Probably not helpful, and you most likely know about it and have already decided against it, but if it was my project I would install RetroBSD first.

1 Like

Thanks for the positive responses, I’ll press on and see what I can achieve.

Regarding the RetroBSD option, I was only peripherally aware of it but it doesn’t change my plans. I (a) want something that doesn’t require replacing the Maximite firmware and (b) want to revise my BASIC for if/when it is time to teach my kids.

Tom

1 Like

Tom,

This looks like a very interesting project. I thought of doing something similar with a Pyboard using python obviously. As I experimented, the limitations with the Pyboard were too much for me to overcome.

I enjoy working with the Raspberry Pi platform. There are several BASIC interpreters available for the RPi. Just about any language is available. The RPi hardware resources are large enough that there would be few limitations. Also, the RPi is inexpensive and readily available.

As you develop your project for the Maximite, I would be interested is trying to port it to the RPi if it is open source and available. I may also purchase a Maximite from CircuitGizmo to experiment with.

Thanks,
Jeff

That’s depending on how advanced the Basic is. Many Basics don’t have support for bit shift operations, and a Z-machine interpreter will be harder to write without them.

It seems like a quite fast Basic. Reuse code in functions / procedures / gosubs a lot to keep code size down.

Also note: You don’t have to be able to support all Z-machine games for this to be worthwile. If you can support say 30 KB of dynamic memory, that’s enough to play pretty much all Infocom games and most Inform 6 games.

As for how useful this terp will be: Do it for the fun and for the learning experience. If you write code that’s somewhat easy to read and understand, others may port your code to other platforms as well. To support this, I would probably write the program with lots of comments and long variable names and write a program which minifies the code to create the version actually used when playing games.

Sounds like good fun. Good luck!

1 Like

I can’t comment on how advanced the BASIC is, but it doesn’t have the shift ops so I would have to implement those. Fortunately my understanding is that it is 100s of times faster than old 8-bit BASICs.

Thanks for the info regarding the ~30K dynamic memory. My understanding of the spec is that it would be something like that, but the earlier post suggesting I would need 64K of z-machine storage in RAM had me worried.

I was coming to the same conclusion regarding the need to have a long-hand version of the code and a tool to shrink it for actual execution.

I will make the code public if I get anywhere, although I can’t imagine why someone would want to port a BASIC implementation to another platform when there are several implementations in more suitable languages.

Tom

Let me know if you want a speaking partner. I know a bit about Z-code and a bit about Basic.

Thanks Fredrik, I may take you up on that offer.

I made good progress writing code to read and dump various structures from the Z-machine input immediately after I made the original post, but since then my day job and young family have meant I haven’t even had time to switch the Maximite on :frowning:

Added to that I aquired a reconditioned BBC Master on tueday :smiley: so I have a new distraction.

Tom

1 Like