ZXSimulator for the Sinclair QL

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

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

So the movement key function is static...I set it up that way since constantly pressing them slowed things down. So you press left until you see the display at bottom center point left and then you let go and wait for the laser-site to move in that direction towards the darting pirate. When it gets close to the pirate you then press up or down to line them up in the laser-site and then just press F for fire (note that the default setting for up is the S key as you are pulling the controller back towards you to move up...and to go down you press the W key to move the controller forward). If you want to be in neutral then you just repeat the current control (i.e. if you are moving left you hit the left key, defaulted as A, a second time). You can watch the video a few posts above running in accelerated mode to get an idea of how to move the control.

Running on the ZXSimulator, which is a tad slower than the base ZX81, I use the space to fire and the cursor keys to move as that aligns with the QL joystick port and it works quite nicely. It is slow so you have to be patient until the laser-site lines up with the pirate and then you can fire away (it's during the firing that it gets a bit strategic and game-like since the pirate darts so if you think you have it lined up you may not). You'll also see your shields and ammo drop and that's where luck and strategy comes in because you hope you don't waste too many bullets and the pirate has shields of their own and requires between 2 to 6 hits to be destroyed. Whenever you hit the pirate you may lose shields and those generate the fewest. It's usually what kills me when I play. And if you take too long, the pirate just hyperspaces away and you don't get its cargo after wasting all those resources.

Note that if you are constantly changing direction or say constantly hitting the left key to move left you go in and out of that mode and waste all your fuel, which is limited, very quickly. You only have so much fuel and you need to destroy the pirate to replenish it. So likely that's why the game ended so fast for you.

I continue to look for ways to speed it up since its aim is to demo the ZXSimulator which runs slower than the ZX81. I may just have the stars sit still when the player is trying to home in on the pirate as that takes up a lot of time, or I can get rid of their independent movement and just have them react to the player movement to give some sense of orientation. It's not going to be a fast machine-coded shoot-em up game and in the end, the pirate hunting will be much more brief, where you maybe have to destroy 3 or 4 before orbiting a planet so you can start bartering for goods and replenish resources -- the main part of Elite. If you've not seen Elite, a lot of time is spent flying through space towards a planet with stars zooming by but getting to the planet can take minutes with little change. Sometimes pirates attack but on other occasions literally nothing happens, because....wait for it...you are in space and it tries to be a bit realistic in that sense. I didn't create the game but I think that was one of the charms of Elite.

I will configure the QL emulator to run maybe 3 times that of an unexpanded QL and then see how ZXSimulator runs the Elite demo as that may be closer to your double-speed ROM configuration. In the video I posted it's about 10 or so times faster and plays more like an arcade. The one advantage the ZXSimulator has is the QL keyboard and potential joystick as the ZX81 keyboard is not always that responsive to key input.

Thanks again for giving it a go and giving me incentive to improve it. I had so much fun writing the ZXSimulator and now I'm on pause with finishing it because I've had so much fun writing this demo in ZX81 BASIC.

bwinkel67
Posts: 74
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

Newest version of ZXSimulator. Not done yet but improves.

(Note that I include the executable to be run under a Sinclair QL, 3 demo basic programs including Elite.bas, and the C source code for the ZXSimulator compiled under Digital 'C' SE since it's an open source project)

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

Here's what's been added:
  • DIM statement added
  • CHR$ and CODE now use proper values (mostly, if unknown it will print ? and above 291 is reserved for QL)
  • STR$ and VAL implemented
  • NEW now wipes all variables and loops (and so does LOAD) and CLEAR was added to clear variables
  • speaking of LOAD, it now ignores '/r' so no need to convert to unix anymore
  • nesting of subroutines is now dynamic (variables still static in amount it can handle)
  • sped up by about 15%, last baseline was 98 seconds, slowed down to 104 seconds w/features...now at 86 seconds (compared to 57 for PAL ZX81)
  • string handling improved (concatenation now works and so does string equalities)
  • Elite.bas is now on the zip along with Banner.bas & Ball.bas. The game is complete in part 1. Next part will be planet hopping. Improved in speed.
Finally, a first, I got someone elses's program, Minesweeper.bas, to work on the ZXSimulator. Big step in development because I want it to be fully compatible.

Minesweeper.bas I found here:

http://www.zx81.de/english/soft_e.htm

If you open it up you'll see it starts like this:

Code: Select all

    0 REM  [3978 bytes]
    2 REM  [3969 bytes]     3 REM        %M%C%O%D%E%R\::%I%I         COPYRIGHT 1983   D C THRELFALL COMPILER AT 17300 PROG AT 20500
   10 REM  MINESWEEPER
Just delete line "0" and then ZXsimulator will read it in and run just fine. I think this was a dual (compiled and BASIC) version. There is this MCODE compiler for the ZX81 made in 1982 that does some sort of partial compilation. In any case, this is the whole BASIC program and it will load and run in ZXSimulator. It does some funky stuff with recursion/nesting so it needs all the memory space so you can't run it presently on an unexpanded QL but it's also very slow. So under QLAY with speed 1000 on the ZXSimulator it runs decently.

Give it a try. It's the first foreign program I've run on the ZXSImulator so it's pretty compatible already (even if it's still missing floating point).

bwinkel67
Posts: 74
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

So I optimized the Minesweeper game to run a bit faster on an unexpanded ZX81 or the ZXSimulator and give feedback of the setup process while you wait. You can look here to see what all I did.

https://qlforum.co.uk/viewtopic.php?f=3 ... =80#p33724


I got permission from the author to publish the modified Minesweeper game. The attached zip file contains these files:
  • minesZX.bas - this is the ZX81 BASIC that can run on ZXSimulator or any ZX81 (emulator or real) if converted into .p or tape file
  • minesZX.p - just the zxtext2p.exe converted file of the first (minesZX_bas) for one of the ZX81 emulators (I use EightyOne)
  • minesSB.bas - this is converted QL SuperBASIC version that runs a bit faster though interface is plain as it only uses characters
  • README.txt - repeats this above

It's a really fun game and very playable on the ZXSimulator on an unexpanded QL, or on a plain ZX81. If you really want to see it go, use an accelerated QL/ZX81. It does take a bit of time set up the board but I did add some output that tells you the progress (in addition to letting you choose key mapping - I use the arrow & space so I can use my joystick). Once the ZXSimulator version on an unexpanded QL starts play it becomes pretty playable (unless it clears out half the board because of a random clear path, then it'll take some time and sometimes it appears to be stuck but it is just getting out of a long nesting loop which takes time).
minesweeper.zip
(5.96 KiB) Downloaded 29 times

User avatar
1024MAK
Posts: 3031
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 »

bwinkel67 wrote:
Thu Apr 23, 2020 8:41 am
If you can find an accelerated ZX81 (do they exist?)
Yes! A member here, Andy Rea at one time produced a ULA replacement that enabled a ZX81 to run at twice the normal speed. Some ‘clones’ or compatibles can also run faster.

Mark

bwinkel67
Posts: 74
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

Just posted the latest ZXSimulator here:

https://qlforum.co.uk/viewtopic.php?f=3 ... 272#p34272

Most notable improvement is better file reading so it can load 16K programs into an unexpanded QL.

Also, I was able to salvage a game I wrote almost 40 years ago as a teenager that was in the process of being published (by Gladstone Electronics -- was that the right company) in early '83 but never made it as Timex pulled the plug in mid '83 I think. In any case, I remember waiting for their final response through the summer and then I got the word.

I'm adding it unchanged here. I got the audacity captured audio to load from PC into my spare TS1000. Unfortunately EightyOne did not want to load it. I then took 30 screen shots (it's almost 15K in size) and typed in in on Friday. Been playing with it and have gotten all the typos out. But I was so happy to have been able to reclaim it. Runs fine on the ZXSimulator as well, though I made one small mod and assign all instances of INKEY$ to a variable (K$) first, since the way that is implemented via a QL TRAP, it seems to miss some keystrokes and you can be sitting there pressing a key for longer than you want (esp on a faster machine that ZXSimulator is running on). For testing I use QLAY2, a QL emulator to run ZXSimulator, a ZX81 pseudo emulator, (it's like Inception all over again :-/).

The game has nice pacing I think. Let me know what you think...
battleship.p
(14.04 KiB) Downloaded 30 times
Last edited by bwinkel67 on Fri Jun 05, 2020 4:23 am, edited 1 time in total.

bwinkel67
Posts: 74
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

An upgraded version of Battleship (aka Battleship2020). This ones adds some features that make it a bit more playable. I had to rewrite some of the old code to give me the space for the new since it was already close 15K in size...just made it a bit space efficient.

battleship2020.p
(14.46 KiB) Downloaded 24 times

  • Computer play is slightly better, it no longer chooses spaces to the side or ends of already destroyed ships while searching or targeting.
    • i.e. if a carrier is destroyed then the 12 spaces around it will no longer be searched
    • still does useless moves as it doesn't account for what's left so it'll choose coordinate even if impossible to hold remaining ships
  • Can now choose keys for every action (i.e. completely joystick playable).
    • At the start screen you have to press "S" to start, any other key lets you set keys (so if you have a joystick, just press fire button).
    • For joystick, not only choose left/right/up/down but use down for vertical and right for horizontal...then use fire button for set.
    • Finally you are presented with choice "C" for coordinate, any other key (press fire button) uses joystick when playing game.
      • In other words, you can choose to type in coordinates like the old fashion way or pick coordinates by moving cursor there.
    • Defaults are set so once you start game you simply hit fire on joystick and it takes you to next screen.
      • i.e. if it asks if you want to start (Y/N) if you hit fire it will start you as it looks for "N" or assumes yes.
  • Adds a little animation so when you or computer picks a square you get a "blop" effect..
    • This really works well on an actual TS1000/ZX81 as the speed is perfect for it (create wave file in EightyOne from .p file)
    • In fact, this game really plays best on a normal TS1000/ZX81 as acceleration ruins pace and the "blop" animation.
  • Cursor movement sped up and fixed the bugginess
    • So I use and infinite for-loop for any loops that do cursor movement as it is faster
    • i.e. FOR I=0 TO 1 STEP 0 ... NEXT I
  • Added Battle mode
    • In configuration screen...when you choose, each player gets extra turn after sinking an opponent ships

This also plays really well in ZXSimulator. It's one of the few BASIC-only games I've gotten my hands on so far, that plays fast enough and is complex enough. Of course I wish I could find more. Minesweeper is great but oh-so slow and the other stuff I've found so far is a bit simple. Really, mostly machine-code programs give you the best game-play on a ZX81/TS1000. Likely why they thought hard about publishing Battleship back in the early 80's before the plug by Timex got pulled. Of course Battleship is a perfect game to write with limited computing power.

It brings up a thought about what to do with ZXSimulator once its initial goal has been met: if an unexpanded QL can run a ZX81 in realtime. It's kind of a tiny audience because you need to like the QL and then want to run ZX81 programs on it :-/ Though you can easily run QLAY2 and get ZXSimulator running pretty quickly (I automated this for my better-half since she likes Minsweeper, but only when it runs faster). ZXSimulator is actually a WYSIWYG ZX81 editor and runtime BASIC environment and writing some BASIC code in it is quicker and much less frustrating (no remembering which key to press to expand keywords) and you can see right away the graphics as you try them. So once I'm done with it I may port it to Windows, which should be pretty easy since it's mostly in C with a few graphics functions (block, window, etc...) tied to QDOS.

Any thoughts? What I like about the ZX81/TS1000 is that it feels a lot like a first generation Scratch environment (scratch.mit.edu) which I sometimes use in teaching programming to students to give a different perspective (usually more advanced students). By that I mean, it's simple with the block graphics to create something quickly and the BASIC is forgiving (so you don't get bogged down in details at the start). Scratch is similar, though a visual programming environment where you can create stuff quickly (albeit much fancier since it's fully graphics capable).

bwinkel67
Posts: 74
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

It's been a while since I've updated ZXSimulator. I basically turned all internal memory to dynamic (before variables were capped at 37 and loop nesting at 10). I also cleaned up the code and removed for-loops, replacing them with while-loops since the Digital 'C' SE compiler handles them better. You can find the latest here:

https://qlforum.co.uk/viewtopic.php?f=3 ... 120#p35378


I also modified another of Bodo Wenzel's games, Mench Aergere Dich Nicht, to better display its board on a ZX81/TS1000/ZXSimulator. The BASIC listing can be found here and needs to be converted to .p file or wave file. You can find it here:

https://qlforum.co.uk/viewtopic.php?f=3 ... 120#p35400


Also created a video if you want to see the ZXSimulator running next to the ZX81/TS1000. It gives some background on the QL, in case you have never used one, and then does some side-by-side runs. It's about a 26 minute video with first half+ giving some background and the 2nd half starting at about the 16:30 mark running the ZXSimulator and doing the comparison:

https://www.youtube.com/watch?v=kY0u0VfOa6w&t=28s

bwinkel67
Posts: 74
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

So you can now try out ZXSimulator online similar to the JtyOne Online ZX81 emulator.

Simply click on the link below and wait for it to start up and then press F2. Note that, like the movie Inception, we've got some nesting going on as we are running a ROM emulator (ZXSimulator) inside of a Sinclair QL emulator (QLAY) inside of a DOS emulator (DOSBox) within the JavaScript interpreter running in your browser. Whew, that's some nesting.

http://zxsimulator.epizy.com

You can run/play the provided ZX81 programs below or code up your own -- though it does not do keyword entries so you get to touch-type.
  • ball_bas - bouncing ball demo for ZXSimulator
  • bann_bas - banner demo for ZXSimulator (normally named banner_bas)
  • elit_bas - Elite game, playable but not complete (normally named elite_bas)
  • batt_bas - Battlship game (normally named battleship_bas)
  • mine_bas - Minesweeper game by Bodo Wenzel (normally named minesweeper_bas)
  • madn_bas - Mench Aergere Dich Nicht, famous German board game by Bodo Wenzel
  • drac_bas - Dragon fractal by Bodo Wenzel (normally named drachen_bas)

Post Reply