ZXSimulator

Anything QL Software or Programming Related.
User avatar
bwinkel67
Gold Card
Posts: 405
Joined: Thu Oct 03, 2019 2:09 am

Re: ZXSimulator

Postby bwinkel67 » Mon Jun 01, 2020 5:27 am

pjw wrote:Read the file header into a buffer with trap #3, d0 = $47. You only need to load the first 14 bytes (16 for DDL2). If you use the SuperBASIC buffer then precede the trap #3 with a trap #4 to make it a6 relative. The file length is the first item in the buffer. It includes the 64 byte header length so youll need to subtract this for the net file length. Check out the Technical guide for the exact details.


Oh good. I will take a look at it. I actually cut file reading by almost in half (from 2 1/4 minutes to about 1 1/4 for a 13K file) by using fseek to more efficiently look for the end of file...

From this:

Code: Select all

   size = BLKLEN;
   while (fgetc(fp) != EOF) size++;
   fseek(fp, 0L, 0);


To this:

Code: Select all

   size = BLKLEN;
   while (fseek(fp, size, 0) == 0) size+=BLKLEN;
   fseek(fp, 0L, 0);


On a BBQL it seems to only add about 10% to the overall file read.

Here is the latest with that change:

zx.zip
(33.15 KiB) Downloaded 11 times


User avatar
bwinkel67
Gold Card
Posts: 405
Joined: Thu Oct 03, 2019 2:09 am

Re: ZXSimulator

Postby bwinkel67 » Mon Jun 08, 2020 9:30 pm

Latest version:

zx.zip
(33.67 KiB) Downloaded 9 times


This one speeds up GOTO and GOSUB as I no longer do a linear search. This speeds things up nicely for longer listings that jump around a lot. Minesweeper runs a minute or two faster for long clear-outs on a BBQL.

Code: Select all


   while ((ch=str[sp]) != EOP)
   {
      sp++;
      if (ch == EOL)
         if (linenum(&lnum) == NOERR)
         {
            if (num < lnum)
               return NOVAL;
            else if (num == lnum)
               return NOERR;
         }
   }


changed to a binary search:

Code: Select all

   while (beg < end)
   {
      sp = (beg + end) >> 1;   /* divide by 2 */

      getline (sp, &bp, &ep); sp=bp;

      if (linenum(&lnum) != NOERR)
         break;

      if (num == lnum)
         return NOERR;

      if (num < lnum)
         end = bp-1;
      else
      {
         beg = ep+1;
         sp = beg;
      }
   }


I also updated the Battleship game. It is now fully joystick playable (besides direction, use down for vertical and right for horizontal) and added a "battle" mode where, whenever you sink a ship, you get an extra turn. Makes the game more fun.


User avatar
bwinkel67
Gold Card
Posts: 405
Joined: Thu Oct 03, 2019 2:09 am

Re: ZXSimulator

Postby bwinkel67 » Fri Jun 12, 2020 2:51 am

Small memory issue fix. I wasn't always catching NULL returned pointer when loading in file which caused an intenral ZXSimulator "SYSTEM ERROR" that you couldn't recover from. If you get a "BAD HEAP QUERY" error, those you can recover from (note I changed that message form the former "MAX HEAP SPACE" since it is more descriptive).

zx.zip
(33.67 KiB) Downloaded 4 times


User avatar
bwinkel67
Gold Card
Posts: 405
Joined: Thu Oct 03, 2019 2:09 am

Re: ZXSimulator

Postby bwinkel67 » Fri Jun 12, 2020 9:19 am

For those QL'ers who love games, besides the two already included int the ZXSimulator distribution above: Elite_bas and Battleship_bas, here's an updated version of Minesweeper, which now shows mines faster when you accidentally hit one...in the past it took a long time. Note, this only runs on ZXSimulator (or ZX81/TS1000 equivalent) and is pretty playable on BBQL (aside from a bit of a wait for setup or large clear-outs).

BTW, I need to add a README file in my distribution but you load programs via the LOAD command with file name in quotes and break a running program via Ctl-S.

Example of loading: LOAD "MDV2_MINESWEEPER_BAS"

Code: Select all

10 REM  MINESWEEPER
20 REM  (C)1999 BODO WENZEL
30 REM  SPEED UP AND I/O BY MIKE JONAS
100 REM  START
110 GOSUB 500
120 PRINT AT 0,26;T
130 LET T=T+1
140 PRINT AT Y,X-1;"\::"
150 LET KEY=CODE INKEY$
160 PRINT AT Y,X-1;F$(F(21*(X-1)+Y)+1);
170 IF KEY=0 THEN GOTO 140
180 IF KEY=LEFT AND X>1 THEN LET X=X-1
190 IF KEY=RIGHT AND X<32 THEN LET X=X+1
200 IF KEY=DOWN AND Y<21 THEN LET Y=Y+1
210 IF KEY=UP AND Y>1 THEN LET Y=Y-1
220 IF KEY<>MODE THEN GOTO 120
230 PRINT AT Y,X-1;"%O"
240 LET KEY=CODE INKEY$
250 PRINT AT Y,X-1;F$(F(21*(X-1)+Y)+1);
260 IF KEY=0 THEN GOTO 230
270 IF KEY=UP OR KEY=DOWN THEN GOSUB 5000
280 IF KEY=LEFT OR KEY=RIGHT THEN GOSUB 6000
290 IF BM=1 THEN GOTO 7700
300 IF N<>0 THEN GOTO 120
310 FOR I=1 TO 32
320 FOR J=1 TO 21
330 LET E=21*(I-1)+J
340 LET K= F(E)
350 IF K>=10 AND K<=19 THEN GOTO 120
360 IF K>=30 THEN GOTO 120
370 NEXT J
380 NEXT I
400 REM  READY
410 LET K$="READY "
420 GOTO 7500
500 REM  SETUP KEYS AND DATA
510 DIM F(672)
520 CLS
530 PRINT AT 0,10;"%M%I%N%E%S%W%E%E%P%E%R"
540 PRINT AT 5,7;"MOVE W/CURSOR KEYS"
550 PRINT AT 7,7;"SPACE TO CHANGE MODE"
560 PRINT AT 9,7;"  MARK - LEFT/RIGHT"
570 PRINT AT 11,7;"  OPEN - UP/DOWN"
580 PRINT AT 13,7;"HIT %R%E%T%U%R%N TO START"
590 INPUT A
600 PRINT AT 21,7;"PLEASE WAIT...";
610 LET BM=0
620 GOSUB 1100
630 PRINT AT 0,0;N
640 LET F$=" 12345678%*\##\##\##\##\##\##\##\##\##\##%#%#%#%#%#%#%#%#%#%#%?%?%?%?%?%?%?%?%?%?%?"
650 LET LEFT=192
660 LET RIGHT=200
670 LET UP=208
680 LET DOWN=216
690 LET MODE=252
700 LET X=1
710 LET Y=1
720 LET T=0
730 RETURN
1100 REM  PREPARE FIELD,SET BOMBS
1110 DIM B(70)
1120 PRINT AT 13,7;"PCT BOMBS SET:     "
1130 FOR N=1 TO 70
1140 PRINT AT 13,22;INT (N*10/7);
1150 LET X=INT (RND*32)
1160 LET Y=INT (RND*21)
1170 LET E=21*(X)+Y+1
1180 IF F(E)=9 THEN GOTO 1150
1200 FOR I=X TO X+2
1210 FOR J=Y TO Y+2
1220 IF I<1 THEN GOTO 1270
1225 IF I>32 THEN GOTO 1270
1230 IF J<1 THEN GOTO 1260
1235 IF J>21 THEN GOTO 1260
1236 LET E=21*(I-1)+J
1240 IF F(E)=9 THEN GOTO 1260
1250 LET F(E)=F(E)+1
1260 NEXT J
1270 NEXT I
1280 LET E=21*X+Y+1
1290 LET B(N)=E
1300 LET F(E)=9
1310 NEXT N
1320 LET N=N-1
1400 PRINT AT 1,0;
1405 FOR X=1 TO 32
1410 FOR Y=1 TO 21
1415 LET E=21*(X-1)+Y
1420 LET F(E)=F(E)+10
1425 PRINT "\##";
1430 NEXT Y
1440 NEXT X
1990 RETURN
5000 REM  OPEN FIELD
5010 IF X<1 THEN RETURN
5015 IF X>32 THEN RETURN
5020 IF Y<1 THEN RETURN
5024 IF Y>21 THEN RETURN
5025 LET E=21*(X-1)+Y
5030 IF F(E)=19 THEN GOTO 7000
5040 IF F(E)<10 THEN RETURN
5045 IF F(E)>19 THEN RETURN
5050 LET F(E)=F(E)-10
5060 PRINT AT Y,X-1;F$(F(E)+1);
5070 IF F(E)<>0 THEN RETURN
5100 LET X=X-1
5110 LET Y=Y-1
5120 GOSUB 5000
5130 LET Y=Y+1
5140 GOSUB 5000
5150 LET Y=Y+1
5160 GOSUB 5000
5170 LET X=X+1
5180 GOSUB 5000
5190 LET Y=Y-1
5200 GOSUB 5000
5210 LET Y=Y-1
5220 GOSUB 5000
5230 LET X=X+1
5240 GOSUB 5000
5250 LET Y=Y+1
5260 GOSUB 5000
5270 LET Y=Y+1
5280 GOSUB 5000
5290 LET X=X-1
5300 LET Y=Y-1
5990 RETURN
6000 REM  MARK FIELD
6005 LET E=21*(X-1)+Y
6010 LET C=F(E)
6020 IF C<10 THEN RETURN
6030 IF C>=30 THEN GOTO 6100
6040 LET N=N+1
6050 IF C<20 THEN LET N=N-2
6060 LET F(E)=C+10
6070 PRINT AT 0,0;N;" "
6090 RETURN
6100 LET F(E)=C-20
6190 RETURN
7000 REM  HIT BOMB
7010 FOR N=1 TO 70
7020 LET E=B(N)
7030 LET X=INT ((E-1)/21)
7040 LET Y=E-(X*21)
7050 PRINT AT Y,X;"%*"
7060 NEXT N
7070 LET K$=" %B%O%O%M "
7080 PAUSE 50
7090 LET BM=1
7500 PRINT AT 10,11;"\:'\''\''\''\''\''\''\''\''\':"
7510 PRINT AT 11,11;"\:  ";K$;" \ :"
7520 PRINT AT 12,11;"\:.\..\..\..\..\..\..\..\..\.:"
7530 PAUSE 100
9000 CLS
9005 CLEAR
9010 PRINT AT 0,0;"  MINESWEEPER BY BODO WENZEL"
9015 PRINT "TRANSLATED AND MCODER BY PETER"
9020 PRINT "       HTTP://WWW.ZX81.DE"
9025 PRINT "ZXSIMULATOR KEY MAP: MIKE JONAS"
9030 PRINT
9040 PRINT "CHOOSE %RESTART OR %QUIT"
9050 INPUT I$
9060 IF LEN I$<>1 THEN GOTO 9050
9070 IF I$="R" THEN RUN
9080 STOP



Who is online

Users browsing this forum: No registered users and 2 guests