ZXSimulator for the Sinclair QL

Emulator and emulator development specific topics
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: Sat Apr 11, 2020 11:48 pm
dr beep wrote: Sat Apr 11, 2020 10:59 pm I am coding a new emulator and planning to built a converter that will run on a ZX Spectrum emulator, will load .P via BLOCK and SAVE as .TAP
Oh cool...would love to play with that eventually...
dr beep wrote: Sat Apr 11, 2020 10:59 pm Somewhere in the net is a converter that will convert .p to .tap but it might need DOSBOX
Great, I will look for that since I have other demo programs I've written and am currently writing a simple implementation of the game Elite to see how it runs on mine. Though I love the QL I've never really gotten into writing BASIC programs in it (I do C on it instead with a C compiler that I've had since the early 90's that can run from microdrives). But there is something about the ZX81 that I find fun writing BASIC programs -- funny since it is so much more lacking but maybe that makes it fun or the fact that the graphics is so limiting.
Found it
https://microhobby.speccy.cz/zx81/FILEEXE.htm
I recently saw a some games that blew me away (non-BASIC of course): Astroids, ZX80 Kong, Glooper, Gauntlet, and my two favorites City Patrol (w/parallax effect) and My Little Ghost (with pseudo-3D effect).
If you take a look at the new games section you will find a lot of games. Among them a lot of my games written in 1K and most also in hires.
bwinkel67
Posts: 147
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

I've been writing a ZX81 BASIC demo program on my ZXSimulator to show its compatibility and capability. It's a simplified version of Elite. It seems to run pretty even with the ZX81 on an unexpanded QL (they both run pretty slow but still playable). I've gotten the demo to do some game-play presently though not much else is tied in (i.e. no nearby planets, no trading, and fuel/energy/ammo/shields aren't being checked). It also has no idea of its immediate world so if you keep going up you don't come around to the other side and will never see ships and stars again...next fix.

Here is a video of Elite playing on ZXSimulator (accelerated, not unexpanded QL): https://vimeo.com/408952080

And here is a screen shot:

ZX-Elite.png

Here's the zipp'ed .p file to load into EightyOne (no need to unzip since I learned EightyOne can read zipp'ed ones).

elite.zip
(2.13 KiB) Downloaded 297 times

And the BASIC source code for the Elite.bas demo (that can be zxtext2p.exe'ed)

Code: Select all

10 REM ELITE
20 GOSUB 1000
40 GOSUB 2000
50 GOSUB 6000
400 REM PLAY
410 LET DY=0
420 LET DX=0
430 LET KEY=CODE INKEY$
440 IF KEY<>0 AND KEY<> FIRE THEN GOSUB 1300
450 IF KEY=FIRE THEN GOSUB 3000
460 IF KEY=LEFT THEN LET DX=DX+1
470 IF KEY=RIGHT THEN LET DX=DX-1
480 IF KEY=UP THEN LET DY=DY-1
490 IF KEY=DOWN THEN LET DY=DY+1
500 GOSUB 2000
510 GOSUB 4000
520 GOSUB 5000
530 GOTO 430
999 STOP
1000 REM DRAW DISPLAY
1010 FOR I=0 TO 31
1030 PRINT AT 15,I;"\.."
1040 NEXT I
1050 FOR I=16 TO 21
1060 PRINT AT I,7;"\ :"
1070 PRINT AT I,24;"\: "
1080 NEXT I
1090 PRINT AT 17,12;"\ .\..\.'\''\''\'.\..\. "
1100 PRINT AT 18,10;"\..\''\' ","   \ '\''\.."
1110 PRINT AT 19,9;"\.'","      \'."
1120 PRINT AT 20,8;"\ .\' ","      \ '\. "
1130 PRINT AT 21,8;"\ :  E L I T E   \: "
1140 PRINT AT 19,15;"\ :\:  "
1150 PRINT AT 17,0;"FUEL:"
1160 PRINT AT 18,0;"\##\##\##\##\##\##\##"
1170 PRINT AT 20,0;"ENERGY"
1180 PRINT AT 21,0;"\##\##\##\##\##\##\##"
1190 PRINT AT 17,25;"AMMO:"
1200 PRINT AT 18,25;"\##\##\##\##\##\##\##"
1210 PRINT AT 20,25;"SHIELD:"
1220 PRINT AT 21,25;"\##\##\##\##\##\##\##"
1230 RETURN
1300 REM CONTROLS
1310 PRINT AT 18,15;"  "
1320 PRINT AT 19,14;" \ :\:  "
1330 PRINT AT 20,15;"  "
1340 IF DX<>0 OR DY<>0 THEN LET KEY=0
1350 LET DY=0
1360 LET DX=0
1370 IF KEY=LEFT THEN PRINT AT 19,14;"\ :"
1380 IF KEY=RIGHT THEN PRINT AT 19,17;"\: "
1390 IF KEY=up THEN PRINT AT 18,15;"\ '\' "
1400 IF KEY=DOWN THEN PRINT AT 20,15;"\ .\. "
1410 RETURN
2000 REM LASER SIGHT
2010 PRINT AT 6,14;"\.'  \'."
2020 PRINT AT 7,14;"\'.  \.'"
2030 RETURN
3000 REM FIRE LASER
3010 FOR I=14 TO 7 STEP -1
3020 PRINT AT I,22-I;"\.'"
3030 PRINT AT I,9+I;"\'."
3040 NEXT I
3050 PAUSE 4
3060 FOR I=14 TO 7 STEP -1
3070 PRINT AT I,22-I;" "
3080 PRINT AT I,9+I;" "
3090 NEXT I
3100 IF EY<29 OR EY>30 THEN RETURN
3110 IF EX<30 OR EX>33 THEN RETURN
3120 LET EL=EL-1
3130 RETURN
4000 REM ENEMY SHIP
4010 IF SHIP=0 AND INT (RND*6)<>1 THEN RETURN
4020 IF SHIP=0 THEN GOTO 4240
4030 IF EY<13 OR EY>43 THEN GOTO 4060
4040 IF EX>=1 AND EX<65 THEN UNPLOT EX-1,EY
4050 IF EX>-2 AND EX<63 THEN UNPLOT EX+1,EY
4060 IF EX<0 OR EX>64 THEN GOTO 4090
4070 IF EY>13 AND EY<45 THEN UNPLOT EX,EY-1
4080 IF EY>11 AND EY<43 THEN UNPLOT EX,EY+1
4090 IF EL=0 THEN GOTO 4300
4100 LET DIR=INT (RND*8)+1
4110 IF DIR=1 AND EY<42 THEN LET EY=EY+1
4120 IF DIR=2 AND EX<62 THEN LET EX=EX+1
4130 IF DIR=3 AND EY>28 THEN LET EY=EY-1
4140 IF DIR=4 AND EX>1 THEN LET EX=EX-1
4150 LET EX=EX+DX
4160 LET EY=EY+DY
4170 IF EY<13 OR EY>43 THEN GOTO 4200
4180 IF EX>=1 AND EX<65 THEN PLOT EX-1,EY
4190 IF EX>-2 AND EX<63 THEN PLOT EX+1,EY
4200 IF EX<0 OR EX>63 THEN GOTO 4230
4210 IF EY>13 AND EY<45 THEN PLOT EX,EY-1
4220 IF EY>11 AND EY<43 THEN PLOT EX,EY+1
4230 RETURN
4240 LET SHIP=1
4250 LET EL=INT (RND*3)+2
4260 LET EX=INT (RND*62)+1
4270 LET EY=INT (RND*10)+33
4280 GOTO 4170
4300 REM SHIP EXPLODES
4310 LET SHIP=0
4320 FOR I=1 TO 2
4330 PLOT EX,EY
4340 PLOT EX-1,EY
4350 PLOT EX+1,EY
4360 PLOT EX,EY-1
4370 PLOT EX,EY+1
4380 UNPLOT EX,EY
4390 PLOT EX-2,EY-2
4400 PLOT EX+2,EY-2
4410 PLOT EX-2,EY+2
4420 PLOT EX+2,EY+2
4430 UNPLOT EX-1,EY
4440 UNPLOT EX+1,EY
4450 UNPLOT EX,EY-1
4460 UNPLOT EX,EY+1
4470 UNPLOT EX-2,EY-2
4480 UNPLOT EX+2,EY-2
4490 UNPLOT EX-2,EY+2
4500 UNPLOT EX+2,EY+2
4510 NEXT I
4520 RETURN
5000 REM STAR FIELD
5010 IF STARS=0 THEN GOTO 5120
5020 LET S$=" "
5030 GOSUB 5200
5040 IF INT (RND*10)=1 THEN LET SM=SM+1
5050 LET SX=SX+DX
5060 LET SY=SY-DY
5070 LET SM=SM-DY
5080 IF SY+SM>13 THEN GOTO 5130
5090 LET S$="."
5100 GOSUB 5200
5110 RETURN
5120 LET STARS=1
5130 LET SM=0
5140 LET SX=INT (RND*3)+5
5150 LET SY=INT(RND*2)+4
5160 GOTO 5090
5200 REM STAR
5210 IF SY+SM>=0 AND SY+SM<14 AND SX-SM>=0 AND SX-SM<32 THEN PRINT AT SY+SM,SX-SM;S$
5220 IF SY+SM*2-4>=0 AND SY+SM*2-4<14 AND SX+10>=0 AND SX+10<32 THEN PRINT AT SY+SM*2-4,SX+10;S$
5230 IF SY+SM-1>=0 AND SY+SM-1<14 AND SX+SM+20>=0 AND SX+SM+20<32 THEN PRINT AT SY+SM-1,SX+SM+20;S$
5240 RETURN
6000 REM SETTINGS
6010 LET SHIP=0
6020 LET STARS=0
6030 LET FIRE=CODE "F"
6040 LET LEFT=CODE "A"
6050 LET RIGHT=CODE "D"
6060 LET DOWN=CODE "W"
6070 LET UP=CODE "S"
6080 PRINT AT 0,0;"S:TART C:ONFIGURE?",,,"  DEFAULT: F,A,D,W,S"
6090 GOSUB 6500
6100 PRINT AT 0,0;"                  ",,,"                    "
6110 IF KEY=CODE "S" THEN RETURN
6120 PRINT AT 0,0;"PRESS KEY FOR ACTION:"
6130 PRINT AT 2,2;"FIRE?"
6140 GOSUB 6500
6150 LET FIRE=KEY
6160 PRINT AT 2,2;"LEFT?"
6170 GOSUB 6500
6180 LET LEFT=KEY
6190 PRINT AT 2,2;"RIGHT?"
6200 GOSUB 6500
6210 LET RIGHT=KEY
6220 PRINT AT 2,2;"UP?   "
6230 GOSUB 6500
6240 LET UP=KEY
6250 PRINT AT 2,2;"DOWN? "
6260 GOSUB 6500
6270 LET DOWN=KEY
6280 PRINT AT 0,0;"                     "
6290 PRINT AT 2,2;"      "
6300 RETURN
6500 REM GET KEY
6510 LET KEY=CODE INKEY$
6520 IF KEY<>0 THEN RETURN
6530 GOTO 6510
bwinkel67
Posts: 147
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

I slightly improved the main loop so it would run a bit faster on a non-accelerated computer. Kind of playable on a ZX81 or simulated on an unexpanded QL. You can see how if INKEY$ is 0 I go straight back to refreshing screen with stars, cross-hairs and enemy. Next will give opponent opportunity to shoot back and destroy me and impact ammo, shields, fuel and energy.

Code: Select all

10 REM ELITE
20 GOSUB 3000
30 GOSUB 3500
400 REM PLAY
410 LET DY=0
420 LET DX=1
430 GOSUB 1500
440 GOTO 460
450 GOSUB 2500
460 GOSUB 1000
470 GOSUB 1100
480 GOSUB 2000
490 LET KEY=CODE INKEY$
500 IF KEY=0 THEN GOTO 460
510 IF KEY=FIRE THEN GOTO 450 
520 GOTO 430
999 STOP
1000 REM LASER SIGHT
1010 PRINT AT 6,14;"\.'"
1020 PRINT AT 6,17;"\'."
1030 PRINT AT 7,14;"\'."
1040 PRINT AT 7,17;"\.'"
1050 RETURN
1100 REM STAR FIELD
1110 IF STARS=0 THEN GOTO 1220
1120 LET S$=" "
1130 GOSUB 1300
1140 IF INT (RND*10)=1 THEN LET SM=SM+1
1150 LET SX=SX+DX
1160 LET SY=SY-DY
1170 LET SM=SM-DY
1180 IF SY+SM>13 THEN GOTO 1230
1190 LET S$="."
1200 GOSUB 1300
1210 RETURN
1220 LET STARS=1
1230 LET SM=0
1240 LET SX=INT (RND*3)+5
1250 LET SY=INT(RND*2)+4
1260 GOTO 1190
1300 REM STAR
1310 IF SY+SM>=0 AND SY+SM<14 AND SX-SM>=0 AND SX-SM<32 THEN PRINT AT SY+SM,SX-SM;S$
1320 IF SY+SM*2-4>=0 AND SY+SM*2-4<14 AND SX+10>=0 AND SX+10<32 THEN PRINT AT SY+SM*2-4,SX+10;S$
1330 IF SY+SM-1>=0 AND SY+SM-1<14 AND SX+SM+20>=0 AND SX+SM+20<32 THEN PRINT AT SY+SM-1,SX+SM+20;S$
1340 RETURN
1500 REM CONTROLS
1510 PRINT AT 18,15;"  "
1520 PRINT AT 19,14;" \ :\:  "
1530 PRINT AT 20,15;"  "
1540 IF DX<>DY THEN LET KEY=0
1550 LET DY=0
1560 LET DX=0
1570 IF KEY=LEFT THEN GOTO 1620
1580 IF KEY=RIGHT THEN GOTO 1650
1590 IF KEY=up THEN GOTO 1680
1600 IF KEY=DOWN THEN GOTO 1710
1610 RETURN
1620 LET DX=DX+1
1630 PRINT AT 19,14;"\ :"
1640 RETURN
1650 LET DX=DX-1
1660 PRINT AT 19,17;"\: "
1670 RETURN
1680 LET DY=DY-1
1690 PRINT AT 18,15;"\ '\' "
1700 RETURN
1710 LET DY=DY+1
1720 PRINT AT 20,15;"\ .\. "
1730 RETURN
2000 REM ENEMY SHIP
2010 IF SHIP=0 AND INT (RND*6)<>1 THEN RETURN
2020 IF SHIP=0 THEN GOTO 2240
2030 IF EY<13 OR EY>43 THEN GOTO 2060
2040 IF EX>=1 AND EX<65 THEN UNPLOT EX-1,EY
2050 IF EX>-2 AND EX<63 THEN UNPLOT EX+1,EY
2060 IF EX<0 OR EX>64 THEN GOTO 2090
2070 IF EY>13 AND EY<45 THEN UNPLOT EX,EY-1
2080 IF EY>11 AND EY<43 THEN UNPLOT EX,EY+1
2090 IF EL=0 THEN GOTO 2700
2100 LET DIR=INT (RND*8)+1
2110 IF DIR=1 AND EY<42 THEN LET EY=EY+1
2120 IF DIR=2 AND EX<62 THEN LET EX=EX+1
2130 IF DIR=3 AND EY>28 THEN LET EY=EY-1
2140 IF DIR=4 AND EX>1 THEN LET EX=EX-1
2150 LET EX=EX+DX
2160 LET EY=EY+DY
2170 IF EY<13 OR EY>43 THEN GOTO 2200
2180 IF EX>=1 AND EX<65 THEN PLOT EX-1,EY
2190 IF EX>-2 AND EX<63 THEN PLOT EX+1,EY
2200 IF EX<0 OR EX>63 THEN GOTO 2230
2210 IF EY>13 AND EY<45 THEN PLOT EX,EY-1
2220 IF EY>11 AND EY<43 THEN PLOT EX,EY+1
2230 RETURN
2240 LET SHIP=1
2250 LET EL=INT (RND*3)+2
2260 LET EX=INT (RND*62)+1
2270 LET EY=INT (RND*10)+33
2280 GOTO 2170
2500 REM FIRE LASER
2510 FOR I=14 TO 7 STEP -1
2520 PRINT AT I,22-I;"\.'"
2530 PRINT AT I,9+I;"\'."
2540 NEXT I
2550 PAUSE 4
2560 FOR I=14 TO 7 STEP -1
2570 PRINT AT I,22-I;" "
2580 PRINT AT I,9+I;" "
2590 NEXT I
2600 IF EY<29 OR EY>30 THEN RETURN
2610 IF EX<30 OR EX>33 THEN RETURN
2620 LET EL=EL-1
2630 RETURN
2700 REM SHIP EXPLODES
2710 LET SHIP=0
2720 FOR I=1 TO 2
2730 PLOT EX,EY
2740 PLOT EX-1,EY
2750 PLOT EX+1,EY
2760 PLOT EX,EY-1
2770 PLOT EX,EY+1
2780 UNPLOT EX,EY
2790 PLOT EX-2,EY-2
2800 PLOT EX+2,EY-2
2810 PLOT EX-2,EY+2
2820 PLOT EX+2,EY+2
2830 UNPLOT EX-1,EY
2840 UNPLOT EX+1,EY
2850 UNPLOT EX,EY-1
2860 UNPLOT EX,EY+1
2870 UNPLOT EX-2,EY-2
2880 UNPLOT EX+2,EY-2
2890 UNPLOT EX-2,EY+2
2900 UNPLOT EX+2,EY+2
2910 NEXT I
2920 RETURN
3000 REM DRAW DISPLAY
3010 FOR I=0 TO 31
3030 PRINT AT 15,I;"\.."
3040 NEXT I
3050 FOR I=16 TO 21
3060 PRINT AT I,7;"\ :"
3070 PRINT AT I,24;"\: "
3080 NEXT I
3090 PRINT AT 17,12;"\ .\..\.'\''\''\'.\..\. "
3100 PRINT AT 18,10;"\..\''\' ","   \ '\''\.."
3110 PRINT AT 19,9;"\.'","      \'."
3120 PRINT AT 20,8;"\ .\' ","      \ '\. "
3130 PRINT AT 21,8;"\ :  E L I T E   \: "
3140 PRINT AT 19,15;"\ :\:  "
3150 PRINT AT 17,0;"FUEL:"
3160 PRINT AT 18,0;"\##\##\##\##\##\##\##"
3170 PRINT AT 20,0;"ENERGY"
3180 PRINT AT 21,0;"\##\##\##\##\##\##\##"
3190 PRINT AT 17,25;"AMMO:"
3200 PRINT AT 18,25;"\##\##\##\##\##\##\##"
3210 PRINT AT 20,25;"SHIELD:"
3220 PRINT AT 21,25;"\##\##\##\##\##\##\##"
3230 RETURN
3500 REM SETTINGS
3510 LET SHIP=0
3520 LET STARS=0
3530 LET FIRE=CODE "F"
3540 LET LEFT=CODE "A"
3550 LET RIGHT=CODE "D"
3560 LET DOWN=CODE "W"
3570 LET UP=CODE "S"
3580 PRINT AT 0,0;"S:TART C:ONFIGURE?",,,"  DEFAULT: F,A,D,W,S"
3590 GOSUB 3810
3600 PRINT AT 0,0;"                  ",,,"                    "
3610 IF KEY=CODE "S" THEN RETURN
3620 PRINT AT 0,0;"PRESS KEY FOR ACTION:"
3630 PRINT AT 2,2;"FIRE?"
3640 GOSUB 3810
3650 LET FIRE=KEY
3660 PRINT AT 2,2;"LEFT?"
3670 GOSUB 3810
3680 LET LEFT=KEY
3690 PRINT AT 2,2;"RIGHT?"
3700 GOSUB 3810
3710 LET RIGHT=KEY
3720 PRINT AT 2,2;"UP?   "
3730 GOSUB 3810
3740 LET UP=KEY
3750 PRINT AT 2,2;"DOWN? "
3760 GOSUB 3810
3770 LET DOWN=KEY
3780 PRINT AT 0,0;"                     "
3790 PRINT AT 2,2;"      "
3800 RETURN
3810 REM GET KEY
3820 LET KEY=CODE INKEY$
3830 IF KEY<>0 THEN RETURN
3840 GOTO 3820
User avatar
1024MAK
Posts: 5101
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: Sat Apr 11, 2020 11:20 pm BTW, were there speed differences between later Spectrum models -- are there faster unexpanded Speccy's out there? I assume there is no 60Hz mode like in the ZX81 since the Spectrum never made it to the US. I'll keep the EightyOne open and check since I will note retype the BANNER.BAS program as it was pretty painful using the old ZX81 keyboard mapping -- the one positive ZXSimulator attribute is that program entry is fast since you can just type the commands and not use key tokens.
The 128K models run at a very slightly different (faster) speed. However, the BASIC runs slightly slower depending on what you are doing (see here and here). Lots of technical details here. The only faster versions are compatibles ('clones'). Until recently that is. The new ZX Spectrum Next which was recently posted (mailed) out can run far faster.

There were 60Hz models designed for the American market. However, not many were sold in the USA. Timex Sinclair took over this market from Sinclair and eventually launched a computer based on the ZX Spectrum design, but not 100% compatible. This ran at 60Hz. See here for more details.

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 »

Here is the latest Elite game for the ZX81 as written on the ZXSimulator (as a test program to see how compatible it is). It works great on any accelerated machine but is also playable on a ZX81 and the ZXSimulator running on an unexpanded QL (the original goal for the ZXSimulator project). They both play about the same with the ZX81 ever so slightly faster.

On the slower machines it gets interesting when in cross-hairs as the pirate bounces in and out. It has been sped up a bit to have the pirate move left/right a bit quicker (after all, it's 64 pixels of space in that dimension and only 30 pixels from top to edge of display).

Game play is as follows. Note that it is pretty hard to win but there is an end goal when you fill your energy destroying all pirates.
  • You lose ammo whenever you fire
  • You may lose shields when firing at enemy: shields may hold or drain
  • Fuel gets used up when you maneuver so be cautious of movement
  • You gain energy when you destroy pirate...also grab ammo, fuel and regenerate shields (though minimally for shields - that's a weak point)
  • If you run out of fuel, ammo, or shields the game ends and you lose
  • If you destroy all the pirates you end the game (or at least part 1 of it)
  • Pirates may hyperspace away -- horrible if you invested a lot of ammo/fuel/shields hoping to gain their supplies when they are destroyed
This version of Elite only deals with pirates as there is no planet hopping or bartering at this point...should change eventually.

The .p file -- with zxtool.exe it reverts to BASIC with very little change: adding an extra space after REM (don't know why it needs 2 spaces after the REM) and converting "% " to "\::" (ZXSimulator allows for both ways to show a solid black block) but that's about it.

elite.zip
(2.81 KiB) Downloaded 328 times

Basic code -- about 6.5K though likely smaller on actual ZX81 when tokenized. With zxtext2p.exe it converts to above .p file. About as pretty as you can write BASIC in ZX81 considering no functions (only GOSUB's). I tried to avoid jumping (via GOTO) outside of code blocks unless I had a GOSUB followed by a RETURN (might as well just do a GOTO and use the subroutine's return as your own since a RETURN isn't tied to any specific code block).

Code: Select all

10 REM ELITE
20 GOSUB 3200
30 GOSUB 1200
400 REM PLAY
410 GOSUB 1500
420 GOTO 440
430 GOSUB 2400
440 GOSUB 1000
450 GOSUB 1100
460 GOSUB 2000
470 LET KEY=CODE INKEY$
480 IF KEY=0 THEN GOTO 440
490 IF KEY=FIRE THEN GOTO 430
500 GOTO 410
999 STOP
1000 REM LASER SIGHT
1010 PRINT AT 6,14;"\.'"
1020 PRINT AT 6,17;"\'."
1030 PRINT AT 7,14;"\'."
1040 PRINT AT 7,17;"\.'"
1050 RETURN
1100 REM STAR FIELD
1110 LET SD=INT (RND*6)=1
1120 IF SD=0 AND DX=DY THEN RETURN
1130 LET S$=" "
1140 GOSUB 1260
1150 IF STARS=0 OR SY+SM>13 THEN GOTO 1200
1160 LET SM=SM+SD
1170 LET SX=SX+DX
1180 LET SY=SY-DY
1190 GOTO 1250
1200 REM SHOW STARS
1210 LET STARS=1
1220 LET SM=0
1230 LET SX=INT (RND*3)+5
1240 LET SY=INT (RND*2)+4
1250 LET S$="."
1260 LET SXC=SX-SM
1270 LET SYC=SY+SM
1280 IF SYC>=0 AND SYC<14 AND SXC>=0 AND SXC<32 THEN PRINT AT SYC,SXC;S$
1290 LET SXC=SX+10
1300 LET SYC=SY+SM*2-4
1310 IF SYC>=0 AND SYC<14 AND SXC>=0 AND SXC<32 THEN PRINT AT SYC,SXC;S$
1320 LET SXC=SX+SM+20
1330 LET SYC=SY-SM
1340 IF SYC>=0 AND SYC<14 AND SXC>=0 AND SXC<32 THEN PRINT AT SYC,SXC;S$
1350 RETURN
1500 REM CONTROLS
1510 PRINT AT 18,15;"  "
1520 PRINT AT 19,14;" \ :\:  "
1530 PRINT AT 20,15;"  "
1540 IF KEY=LEFT THEN GOTO 1590
1550 IF KEY=RIGHT THEN GOTO 1640
1560 IF KEY=UP THEN GOTO 1690
1570 IF KEY=DOWN THEN GOTO 1740
1580 RETURN
1590 LET DX=DX<>1
1600 LET DY=0
1610 IF DX=0 THEN RETURN
1620 PRINT AT 19,14;"\ :"
1630 GOTO 1780
1640 LET DX=-(DX<>-1)
1650 LET DY=0
1660 IF DX=0 THEN RETURN
1670 PRINT AT 19,17;"\: "
1680 GOTO 1780
1690 LET DX=0
1700 LET DY=-(DY<>-1)
1710 IF DY=0 THEN RETURN
1720 PRINT AT 18,15;"\ '\' "
1730 GOTO 1780
1740 LET DX=0
1750 LET DY=DY<>1
1760 IF DY=0 THEN RETURN
1770 PRINT AT 20,15;"\ .\. "
1780 LET FUEL=FUEL-1
1790 GOSUB 2600
1800 IF FUEL=0 THEN GOTO 4010
1810 RETURN
2000 REM ENEMY SHIP
2010 LET TIME=TIME+1
2020 IF TIME<WAIT THEN RETURN
2030 IF TIME=WAIT THEN GOTO 2240
2040 IF EX<1 OR EX>62 OR EY<14 OR EY>42 THEN GOTO 2090
2050 UNPLOT EX-1,EY
2060 UNPLOT EX+1,EY
2070 UNPLOT EX,EY-1
2080 UNPLOT EX,EY+1
2090 IF EL=0 THEN GOTO 2850
2100 IF TIME=LEAVE THEN GOTO 2800
2110 LET DIR=INT (RND*8)+1
2120 IF DIR=1 AND EY<42 THEN LET EY=EY+1
2130 IF DIR=2 AND EX<62 THEN LET EX=EX+1
2140 IF DIR=3 AND EY>28 THEN LET EY=EY-1
2150 IF DIR=4 AND EX>1 THEN LET EX=EX-1
2160 LET EX=EX+DX*2
2170 LET EY=EY+DY
2180 IF EX<1 OR EX>62 OR EY<14 OR EY>42 THEN RETURN
2190 PLOT EX-1,EY
2200 PLOT EX+1,EY
2210 PLOT EX,EY-1
2220 PLOT EX,EY+1
2230 RETURN
2240 LET LEAVE=WAIT+INT (RND*25)+75
2250 LET EL=INT (RND*3)+2
2260 LET EX=INT (RND*62)+1
2270 LET EY=INT (RND*10)+33
2280 GOTO 2180
2400 REM FIRE LASER
2410 FOR I=14 TO 7 STEP -1
2420 PRINT AT I,22-I;"\.'"
2430 PRINT AT I,9+I;"\'."
2440 NEXT I
2450 PAUSE 4
2460 FOR I=14 TO 7 STEP -1
2470 PRINT AT I,22-I;" "
2480 PRINT AT I,9+I;" "
2490 NEXT I
2500 IF EY<29 OR EY>30 THEN GOTO 2560
2510 IF EX<30 OR EX>33 THEN GOTO 2560
2520 LET EL=EL-1
2530 LET SHIELD=SHIELD-INT (RND*3)
2540 IF SHIELD<14 THEN GOSUB 2700
2550 IF SHIELD<=0 THEN GOTO 4070
2560 LET AMMO=AMMO-1
2570 GOSUB 2650
2580 IF AMMO=0 THEN GOTO 4050
2590 RETURN
2600 REM FUEL
2610 LET BAR=INT (FUEL/3)
2620 PRINT AT 18,BAR;" "
2630 RETURN
2650 REM AMMO
2660 LET BAR=INT (AMMO/2)
2670 PRINT AT 18,25+BAR;" "
2680 RETURN
2700 REM SHIELD
2710 LET BAR=INT (SHIELD/2)
2720 PRINT AT 21,25+BAR;" "
2730 RETURN
2750 REM ENERGY
2760 LET BAR=INT ((ENERGY-1)/2)
2770 PRINT AT 21,BAR;"\##"
2780 IF ENERGY=14 THEN GOTO 4030
2800 REM INIT SHIP
2810 LET STARS=0
2820 LET TIME=0
2830 LET WAIT=INT (RND*5)+8
2840 RETURN
2850 REM SHIP EXPLODES
2860 FOR I=1 TO 2
2870 PLOT EX,EY
2880 PLOT EX-1,EY-1
2890 PLOT EX+1,EY-1
2900 PLOT EX-1,EY+1
2910 PLOT EX+1,EY+1
2920 UNPLOT EX,EY
2930 PLOT EX-2,EY-2
2940 PLOT EX+2,EY-2
2950 PLOT EX-2,EY+2
2960 PLOT EX+2,EY+2
2970 UNPLOT EX-1,EY-1
2980 UNPLOT EX+1,EY-1
2990 UNPLOT EX-1,EY+1
3000 UNPLOT EX+1,EY+1
3010 UNPLOT EX-2,EY-2
3020 UNPLOT EX+2,EY-2
3030 UNPLOT EX-2,EY+2
3040 UNPLOT EX+2,EY+2
3050 NEXT I
3060 LET I=INT (RND*2)+1
3070 LET BAR=FUEL+I*3
3080 LET FUEL=(BAR<22)*BAR+(BAR>21)*21
3090 PRINT AT 18,0;F$(1 TO INT (FUEL/3))
3100 LET BAR=AMMO+I*3
3110 LET AMMO=(BAR<15)*BAR+(BAR>14)*14
3120 PRINT AT 18,25;F$(1 TO INT (AMMO/2))
3130 LET BAR=SHIELD+I
3140 LET SHIELD=(BAR<15)*BAR+(BAR>14)*14
3150 PRINT AT 21,25;F$(1 TO INT (SHIELD/2))
3160 LET ENERGY=ENERGY+1
3170 GOTO 2750
3200 REM SETTINGS
3210 GOSUB 2800
3220 LET DX=0
3230 LET DY=0
3240 LET FUEL=21
3250 LET ENERGY=0
3260 LET AMMO=14
3270 LET SHIELD=14
3280 LET FIRE=CODE "F"
3290 LET LEFT=CODE "A"
3300 LET RIGHT=CODE "D"
3310 LET DOWN=CODE "W"
3320 LET UP=CODE "S"
3330 LET F$="\##\##\##\##\##\##\##"
3400 REM DRAW DISPLAY
3410 FOR I=0 TO 31
3420 PRINT AT 15,I;"\.."
3430 NEXT I
3440 FOR I=16 TO 21
3450 PRINT AT I,7;"\ :"
3460 PRINT AT I,24;"\: "
3470 NEXT I
3480 PRINT AT 17,12;"\ .\..\.'\''\''\'.\..\. "
3490 PRINT AT 18,10;"\..\''\' ","   \ '\''\.."
3500 PRINT AT 19,9;"\.'","      \'."
3510 PRINT AT 20,8;"\ .\' ","      \ '\. "
3520 PRINT AT 21,8;"\ :  E L I T E   \: "
3530 PRINT AT 19,15;"\ :\:  "
3540 PRINT AT 17,0;"FUEL:"
3550 PRINT AT 18,0;F$
3560 PRINT AT 20,0;"ENERGY:"
3570 PRINT AT 17,25;"AMMO:"
3580 PRINT AT 18,25;F$
3590 PRINT AT 20,25;"SHIELD:"
3600 PRINT AT 21,25;F$
3650 REM CONFIGURE
3660 PRINT AT 0,0;"S:TART C:ONFIGURE?",,,"  DEFAULT: F,A,D,W,S"
3670 GOSUB 3900
3680 PRINT AT 0,0;"                  ",,,"                    "
3690 IF KEY=CODE "S" THEN RETURN
3700 PRINT AT 0,0;"PRESS KEY FOR ACTION:"
3710 PRINT AT 2,2;"FIRE?"
3720 GOSUB 3900
3730 LET FIRE=KEY
3740 PRINT AT 2,2;"LEFT?"
3750 GOSUB 3900
3760 LET LEFT=KEY
3770 PRINT AT 2,2;"RIGHT?"
3780 GOSUB 3900
3790 LET RIGHT=KEY
3800 PRINT AT 2,2;"UP?   "
3810 GOSUB 3900
3820 LET UP=KEY
3830 PRINT AT 2,2;"DOWN? "
3840 GOSUB 3900
3850 LET DOWN=KEY
3860 PRINT AT 0,0;"                     "
3870 PRINT AT 2,2;"      "
3880 LET KEY=0
3890 RETURN
3900 REM GET KEY
3910 LET KEY=CODE INKEY$
3920 IF KEY<>0 THEN RETURN
3930 GOTO 3910
4000 REM GAME END
4010 LET S$="YOU RAN OUT OF FUEL"
4020 GOTO 4100
4030 LET S$="YOU GOT ALL OF THEM"
4040 GOTO 4100
4050 LET S$="YOU RAN OUT OF AMMO"
4060 GOTO 4100
4070 LET S$="YOUR SHIELDS FAILED"
4110 REM MESSAGE
4120 PRINT AT 6,14;"    "
4130 PRINT AT 7,14;"    "
4140 FOR I=1 TO 3
4150 PRINT AT 6,11;"%G%A%M%E% %O%V%E%R"
4160 PAUSE 20
4170 PRINT AT 6,11;"GAME OVER"
4180 PAUSE 20
4190 NEXT I
4200 PRINT AT 7,6;S$
4210 STOP

Obviously with zxtext2p.exe you can develop ZX81 programs in your favorite text editor and then convert it. ZXSimulator doesn't have all the perks of a graphical editor with mouse control but it handles entering code much better than a ZX81 emulator running the ROM; even the unaccelerated version (i.e. running on unexpanded QL). You type things in with line numbers (you type the entire commands and no hunting for the right key) and it adds the EDIT command to allow for editing line numbers (to delete you simply type the line number). No renumber function presently but I may write a separate program to do that (unless one already exists???).
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: ZXSimulator for the Sinclair QL

Post by Moggy »

Hmmm Just tried this in sz81 and eighty one and after pressing the fire button it stops with error report 2/2500.Tried goto 1 instead of run just in case I was wiping out some hidden variables also does it even when keys are reconfigured, will try on real zeddy and see what happens.
EDIT
Yup same on real zeddy.
bwinkel67
Posts: 147
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

Moggy wrote: Wed Apr 22, 2020 10:47 pm Hmmm Just tried this in sz81 and eighty one and after pressing the fire button it stops with error report 2/2500.Tried goto 1 instead of run just in case I was wiping out some hidden variables also does it even when keys are reconfigured, will try on real zeddy and see what happens.
EDIT
Yup same on real zeddy.
Yup, that's been fixed. You had to wait for the first pirate to show before firing otherwise no EX or EY defined (enemy x and y position - started calling them pirates since it sounds better). It's easier to see the issue on the ZXSimulator since it posts the line at the top letting you know BAD ARGUMENT. It doesn't put the arrow pointer to the spot where the error occurred in the line correctly so that's something I still need to fix. Still debating whether I should keep traditional syntax error messages or use the ZX81's codes. Do you find it simple to understand what 2/2500 is? Obviously 2500 refers to the line number.

I had actually fixed it earlier this evening when I encountered it and also inverted the screen since I realized it wouldn't impact game play so it looks a bit better. Probably Friday I will start adding the goods trading and planet hopping of Elite. So maybe after destroying a handful of pirates you end up at a planet and can start selling and buying goods.

I'll need to upgrade the ZXSimulator a tad since I'm maxed out at 31 variable names (I think Elite uses 29). At one point I'll make those dynamic but for now I'll just increase them to the next prime number (either 37 or 41) as it's an easy recompile...prime's are good for hash table lookup. I also want to add TAB and realized today that my string concatenation is broken since, if A$ contains "ABC" and I do PRINT A$+A$ it shows 0. Still haven't needed DIM'ed arrays but will need to add that too eventually along with floating point (the last thing I'll add).

Thanks for trying it...give this one a go. If you can find an accelerated ZX81 (do they exist?), even twice or four times, it plays a slight bit better though I do find it fun on a plain ZX81.

elite.zip
(2.87 KiB) Downloaded 303 times

elite.png
elite.png (8.03 KiB) Viewed 7186 times
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: ZXSimulator for the Sinclair QL

Post by Moggy »

Many thanks for quick reply. :D

Can't wait to try this as oddly enough my 81's are fitted with screen invert switches and double speed BASIC EPROM's.
bwinkel67
Posts: 147
Joined: Mon Mar 23, 2020 2:38 am

Re: ZXSimulator for the Sinclair QL

Post by bwinkel67 »

Moggy wrote: Thu Apr 23, 2020 1:54 pm Many thanks for quick reply. :D

Can't wait to try this as oddly enough my 81's are fitted with screen invert switches and double speed BASIC EPROM's.
Cool, let me know how it plays at twice the speed. BTW, I didn't really invert the screen, I just made the space part of the display black by using the appropriate inverted characters. If you invert your screen then you'll have an interesting display :-/

The good news is that I'm going to keep trying to speed up the game in BASIC since I want it to play reasonably fast on an unexpanded QL w/ZXSimulator.
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: ZXSimulator for the Sinclair QL

Post by Moggy »

Tried with double speed ROM and whilst the initial display set up is quite rapid the game play is very slow with the direction keys seeming to do very little. I tried very hard to home in on a pirate with no luck whatsoever and ended up with a game over message after a very short time.
Post Reply