ZXSimulator for the Sinclair QL

Emulator and emulator development specific topics
bwinkel67
Posts: 147
Joined: Mon Mar 23, 2020 2:38 am

ZXSimulator for the Sinclair QL

Post by bwinkel67 »

Hi folks,

My first post on this board. The ZX81 was my first ever computer when I got it in 1982 back in the US and is the computer that introduced me to coding both BASIC and machine code. I have very fond memories of it. At the end of the 80's I upgraded to a Sinclair QL and then in the mid 90's left that platform. I've recently gotten back into using the system and have spent time on the QL Forum.

The latest crisis has us all staying home more so I decided for a fun project I would resurrect an old BASIC interpreter I wrote in the early 90's that I prototype on the QL (as it was all I the only computer I owned back then) and eventually moved to the Mac platform and turned into a real product (this post is not about that so I will skip details but feel free to enquirer as it was a full-featured system that ran on the old 68K Macs). The BASIC was a cross between the ZX81 BASIC that I initially learned on and the QL's SuperBASIC.

Born about two weeks ago was the ZXSimulator, a ZX81 simulator for an unexpanded QL. That's the primary goal, getting it to run to as close to realtime as possible without extra memory and without extra processing power. I post about a new copy or so a week in a zip file that can be expanded in one of the QL emulators and then run. I also include the C source code (presently a single file since I haven't figured out how to use multiple files in the old C compiler I used back in the 90's -- it is doable as the original BASIC was written in 4 files).

It presently isn't complete but is pretty far along and mostly I had to pull code out as it had too many SuperBASIC features that the ZX81 didn't have. I also spend a lot of time on finding ways to efficiently show the ZX81 character set and graphics, and it follows the zxtools/zxtext2p format so my saved BASIC files can be saved and run on ZX81 emulators like the EightyOne (and I have done that). ZXSimulator doesn't use keywords to enter code, instead you type code as you would today and then it parses an runs the program. It makes code entry into the ZX81 a bit faster (and what many of us are used to today). Currently it still only does integer BASIC which is the next big improvement needed to convert it to floating point plus its error handling is something to be desired so that will be fixed.

Instead of cross posting everything, here is the link to he QL forum for anyone that has run a QL emulator (I have been using QLAY2) and wants to give it a go. I will eventually create a package (a subfolder) that is configured as win1_ and should autorun via a "boot" file when starting up QLAY2. Could there be a Windows port in the future? Not really the point of it but if someone wants a ZX81 simulator that bypasses the quirky nature of the ZX81 ROM and how it deals with code entry...sure, why not, maybe someone will pick that up.

https://qlforum.co.uk/viewtopic.php?f=3&t=3193&start=50

The point of all this is just to do it for the fun of doing it. There are already several high quality ZX/Speccy emulators for the QL but all need extra speed and memory. Ironically, after I started this project I found the Speccy simulator for the Commodore 64 (by Whitby) so that gives me more reason to move forward and once I have it complete I may try and convert it to a Speccy Simulator to run on an unexpanded QL which would really be cool. So a mid 80's Sinclair computer running another mid 80's Sinclair computer with no modern intervention...pretty cool and if a Commodore 64 can do it, so should a QL, right?
User avatar
1024MAK
Posts: 5102
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZXSimulator for the Sinclair QL

Post by 1024MAK »

Hello and welcome. You may wish to properly introduce yourself in the welcome area ;-)

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
bwinkel67
Posts: 147
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

Thank you. Yes, I should head there. I need to dig out my ZX81 from my closet. I do have a TS1000 handy but I have an old mod'ed ZX81 (in a homemade case an all with real keyboard) that I should resurrect.

With the current version of ZXSimulator I wrote some simple BASIC programs: ball_bas which is a spinning ball that bounces around the screen and banner_bas which just flashes a banner and inverts it and repeats. Both were written within ZXSimulator by just typing/editing them in. It's a bit easier and quicker as you don't have to hit specific keys but type normally. Then when you run it you get a syntax error if you made a mistake and fix it (i.e. not an emulator that you are used to).

The latest one has editing and listing working pretty well. It supports the zxtext2p.exe/zxtools.exe format and within the ZXSimulator you just type the % or \ key followed by the appropriate keys and the graphics will appear and be treated just like a normal ZX81 character and when saved it will appear as expected in ASCII mode to be convertible to a .p file. This makes program development a bit quicker and less frustrating if you are a touch typist. I've done the conversion for both basic files and they work in the EightyOne the same way.

If you are interested in running it and haven't used QLAY2, pm me and I'll forward you a zip file of a win1_ directory and give you instructions on how to set up QLAY2 to get it to automatically boot into the ZXSimulator so you run it for yourself. QLAY2 is the QL emulator for Windows (there are others but that's the one I've been using). Remember that currently still no floating point, that's the next big item followed by then just finishing up by adding missing functions like plot/unplot and all the math ones and making code and chr$ map to the ZX81 set (right now they map to ASCII).
RWAP
Posts: 1348
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

Re: ZXSimulator for the Sinclair QL

Post by RWAP »

Welcome to the forums - great to see a new ZX81 emulator for the QL - there is an existing one, but whilst the Spectrum emulators have had several versions and improvements, there has only ever been Xtricator (http://www.dilwyn.me.uk/zx81/index.html).
bwinkel67
Posts: 147
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

Yes, I've seen them all on the QL. I may upgrade the ZXSimulator to a full blown Speccy once I get it up and running and working for this first phase. I'll have to learn Speccy BASIC to see how many new things it adds. The Commodore 64 has one so I figure the QL ought to be able to support most of what the Spectrum has.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZXSimulator for the Sinclair QL

Post by dr beep »

RWAP wrote: Tue Mar 31, 2020 10:09 pm Welcome to the forums - great to see a new ZX81 emulator for the QL - there is an existing one, but whilst the Spectrum emulators have had several versions and improvements, there has only ever been Xtricator (http://www.dilwyn.me.uk/zx81/index.html).
And the developer died a few years ago so no updates from him anymore.
bwinkel67
Posts: 147
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

Oh that's very sad to hear. I've seen the Xtricator running and it looks like a very sophisticated and a polished piece of software. I was trying to run it on the Q68 but hadn't set up my directory environment properly. My ZXSimulator won't be as compatible as that since it won't emulate the Z80 and can't run machine code stuff...but it will run any BASIC program once I get it all implemented. I want it to be able to run pretty close to real-time on unexpanded QL whereas Xtricator required at least 300K, the pointer environment and TK2, and recommended hardware acceleration.

ZXSimulator is pretty far along, I just need to add floating point and some floating point functions. I think I got all the graphics down pretty well. Right now trying to write some demo programs (a simple form of Elite) and also trying to reclaim some old BASIC programs that I wrote in the early 80's on my ZX81 but getting the EightyOne emulator to read my audacity sampled cassette audio has been very frustrating (I've also used the java tool, tapeutils.jar, that lets you see the faults to no avail). I've compared what I captured to what I saved from EightyOne and they do not align with the latter being a very clean, non-analog looking audio recording whereas the real thing is all over the place. I even tried to manipulate the recording to make it look more like that output but to no avail. It sounds ok but just won't load.

Trying a more expensive cassette player to see if that helps. I captured both channels in mono but I'm not sure if that is the problem since the player is playing stereo when it was originally recorded in mono. Need to understand what a mono tape recording does. Audacity sees both channels but lets you combine them so the cassette player is seeing recordings on both left and right channels and they are not identical but neither is noise either.

In any case, my latest, greatest ZXSimulator is out and can be found here
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZXSimulator for the Sinclair QL

Post by dr beep »

bwinkel67 wrote: Mon Apr 06, 2020 12:13 am Oh that's very sad to hear. I've seen the Xtricator running and it looks like a very sophisticated and a polished piece of software. I was trying to run it on the Q68 but hadn't set up my directory environment properly. My ZXSimulator won't be as compatible as that since it won't emulate the Z80 and can't run machine code stuff...but it will run any BASIC program once I get it all implemented. I want it to be able to run pretty close to real-time on unexpanded QL whereas Xtricator required at least 300K, the pointer environment and TK2, and recommended hardware acceleration.
The 300K is due to the most efficient emulator. Each opcode has 256 bytes of space for optimal speed in defining an opcode.
Like the Z80 emulator. The quickest method is to jump to an address formed by the highbyte only.
So opcode #06 would jump to #0600 for the emulation.
bwinkel67
Posts: 147
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

So Z80 has 252 instructions and you are saying that using 2 bytes per for 252x256 which equals 64512 (or the full 256x256 for efficiency at a full 64K) so that each instruction is a memory address of the high byte (which means some memory is completely unused assuming not all opcodes need 256 bytes to implement). And then getting the ROM and memory and the pointer environment all integrated with the hardware graphics of the ZX81 makes it in all total about 300K. I can see that. So is that why the Speccy emulators need only 256K since they emulate the Z80 less efficiently? Not sure if using 64K for the opcodes couldn't be reduced through a good hash to keep it still pretty efficient though I suppose at the instruction level, any delay will slow it down.

I will have to do some timings of the Xtricator compared to the other emulators running on the QL. Is the Xtricator the only ZX81 emulator on the QL or does one of the Speccy ones also have an option to run in ZX81 mode? Once I'm done getting the fully blow ZXSimulator to work I may see if I can upgrade it to also implement Spectrum BASIC. I think I can get it done since the Commodore 64 had one back in the 80's made by Whitby.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZXSimulator for the Sinclair QL

Post by dr beep »

bwinkel67 wrote: Tue Apr 07, 2020 12:02 am So Z80 has 252 instructions and you are saying that using 2 bytes per for 252x256 which equals 64512 (or the full 256x256 for efficiency at a full 64K) so that each instruction is a memory address of the high byte (which means some memory is completely unused assuming not all opcodes need 256 bytes to implement). And then getting the ROM and memory and the pointer environment all integrated with the hardware graphics of the ZX81 makes it in all total about 300K. I can see that. So is that why the Speccy emulators need only 256K since they emulate the Z80 less efficiently? Not sure if using 64K for the opcodes couldn't be reduced through a good hash to keep it still pretty efficient though I suppose at the instruction level, any delay will slow it down.

I will have to do some timings of the Xtricator compared to the other emulators running on the QL. Is the Xtricator the only ZX81 emulator on the QL or does one of the Speccy ones also have an option to run in ZX81 mode? Once I'm done getting the fully blow ZXSimulator to work I may see if I can upgrade it to also implement Spectrum BASIC. I think I can get it done since the Commodore 64 had one back in the 80's made by Whitby.
The only reason to this was speed. This is the quickest way to determie an opcode and do the right emulation.
Z80, Gerton Lunters emulator did that too. PC were slow back then.

My ZX81 emulator uses another way since I didn’t have so much memory on a ZX Spectrum. This is slower but still is the quickest way on a ZX Spectrum. Same routine is used on Galaksija-emulator for the SAM Coupe.
Post Reply