Dynamic program loading in SuperBASIC

Anything QL Software or Programming Related.
User avatar
badaman
Over Heated PSU
Posts: 149
Joined: Sun Jan 12, 2020 12:18 pm
Location: Spain
Contact:

Re: Dynamic program loading in SuperBASIC

Post by badaman »

I was looking for a name to refer to this method, and today, in the Spanish forum they proposed "shadow loading". If you can think of another possibility, I would like to know about it.


User avatar
badaman
Over Heated PSU
Posts: 149
Joined: Sun Jan 12, 2020 12:18 pm
Location: Spain
Contact:

Re: Dynamic program loading in SuperBASIC

Post by badaman »

RWAP wrote: Wed May 15, 2024 8:48 am As the QL does not know the number of lines in the listing until it is fully loaded using a similar mechanism could not be programmed too easily.

However, a ROM routine could be incorporated within the LOAD routine to calculate the % loaded based on the byte size of the program / bytes loaded.

The only other option would be to have a generic machine code procedure to display the loading, and you still add the extra lines to the program, but calling that specific procedure.

The main issue is that the progress loading lines have to be added by manually editing the saved program - so the easiest might be to develop a variant of the SAVE routine to insert them automatically (as that can work out the total number of lines and where to insert the progress loading lines).
If the load is shown based on the number of bytes loaded, it could also be used for EXEC.

I also think that the shadow loading could be associated with a switch type variable that would activate or deactivate it.


User avatar
bwinkel67
QL Wafer Drive
Posts: 1267
Joined: Thu Oct 03, 2019 2:09 am

Re: Dynamic program loading in SuperBASIC

Post by bwinkel67 »

Really cool. I knew you could put non-line numbered statements into BASIC since I've seen boot files that did that. But never thought of doing a status bar. Curious why it's not more common in long BASIC listings.

I added a twirling clock to minesweeper program and it works really well:

Code: Select all

10 REMark  MINESWEEPER
20 REMark  (C)1999 BODO WENZEL
30 REMark  SPEED UP AND I/O BY MIKE JONAS
40 REMark  CONVERTED FROM ZX81 TO QL BASIC BY MIKE JONAS
100 REMark  START, GET KEY, AND MOVE
110 GO SUB 3000
120 AT 0,26: PRINT T
130 LET T=T+1
140 AT Y,X-1: PRINT "_"
150 LET KEY=CODE (INKEY$)
AT #0,0,0:PRINT #0,"Loading ";
160 AT Y,X-1: PRINT F$(F(21*(X-1)+Y)+1);
170 IF KEY=0 THEN GO TO 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=CHECK THEN GO SUB 1000
230 IF KEY=MARK THEN GO SUB 2000
240 IF N<>0 THEN GO TO 120
250 GO SUB 4000
AT #0,0,8:PRINT #0,"|"
260 GO TO 120
1000 REMark  OPEN FIELD
1010 IF X<1 THEN RETurn 
1020 IF X>32 THEN RETurn 
1030 IF Y<1 THEN RETurn 
1040 IF Y>21 THEN RETurn 
1050 LET E=21*(X-1)+Y
1060 IF F(E)=19 THEN GO TO 5000
1070 IF F(E)<10 THEN RETurn 
1080 IF F(E)>19 THEN RETurn 
AT #0,0,8:PRINT #0,"/"
1090 LET F(E)=F(E)-10
1100 AT Y,X-1: PRINT F$(F(E)+1);
1110 IF F(E)<>0 THEN RETurn 
1120 LET X=X-1
1130 LET Y=Y-1
1140 GO SUB 1000
1150 LET Y=Y+1
1160 GO SUB 1000
1170 LET Y=Y+1
1180 GO SUB 1000
AT #0,0,8:PRINT #0,"-"
1190 LET X=X+1
1200 GO SUB 1000
1210 LET Y=Y-1
1220 GO SUB 1000
1230 LET Y=Y-1
1240 GO SUB 1000
1250 LET X=X+1
1260 GO SUB 1000
1270 LET Y=Y+1
1280 GO SUB 1000
1290 LET Y=Y+1
AT #0,0,8:PRINT #0,"\"
1300 GO SUB 1000
1310 LET X=X-1
1320 LET Y=Y-1
1330 RETurn 
2000 REMark  MARK FIELD
2010 LET E=21*(X-1)+Y
2020 LET C=F(E)
2030 IF C<10 THEN RETurn 
2040 IF C>=30 THEN GO TO 2100
2050 LET N=N+1
AT #0,0,8:PRINT #0,"|"
2060 IF C<20 THEN LET N=N-2
2070 LET F(E)=C+10
2080 AT 0,0: PRINT N;" "
2090 RETurn 
2100 LET F(E)=C-20
2110 RETurn 
3000 REMark  SETUP
3010 DIM F(672)
3020 MODE 8: WINDOW #1,388,222,62,0: PAPER #1,7: INK #1,0: CLS #1
3030 AT 0,10: PRINT "MINESWEEPER"
AT #0,0,8:PRINT #0,"/"
3040 AT 5,5: PRINT "5..8  CURSOR"
3050 AT 7,5: PRINT "O     OPEN"
3060 AT 9,5: PRINT "M     MARK"
3070 GO SUB 3500
3080 AT 21,5: PRINT "PLEASE WAIT...";
3090 LET F$=" 12345678*##########@@@@@@@@@@???????????"
3095 FOR I=11 TO 20: F$(I)=CHR$(255)
3100 REMark  PREPARE FIELD, SET BOMBS
3110 DIM B(70)
3120 AT 11,5: PRINT "PCT BOMBS SET:    "
AT #0,0,8:PRINT #0,"-"
3130 FOR N=1 TO 70
3140 AT 11,20: PRINT INT (N*10/7);
3150 LET X=INT (RND*32)
3160 LET Y=INT (RND*21)
3170 IF F(21*X+Y+1)=9 THEN GO TO 3150
3180 FOR I=X TO X+2
3190 FOR J=Y TO Y+2
3200 IF I<1 THEN GO TO 3280
3210 IF I>32 THEN GO TO 3280
3220 IF J<1 THEN GO TO 3270
AT #0,0,8:PRINT #0,"\"
3230 IF J>21 THEN GO TO 3270
3240 LET E=21*(I-1)+J
3250 IF F(E)=9 THEN GO TO 3270
3260 LET F(E)=F(E)+1
3270 NEXT J
3280 NEXT I
3290 LET E=21*X+Y+1
3300 LET B(N)=E
3310 LET F(E)=9
3320 NEXT N
AT #0,0,8:PRINT #0,"|"
3330 REMark  QL FOR LOOP DIFFERENT FROM ZX, SO IGNORE: LET N=N-1
3340 AT 1,0
3350 FOR Y=1 TO 21
3360 FOR X=1 TO 32
3370 LET E=21*(X-1)+Y
3380 LET F(E)=F(E)+10
3390 PRINT CHR$(255);
3400 NEXT X
3410 PRINT
3420 NEXT Y
AT #0,0,8:PRINT #0,"/"
3430 REMark  INITIALIZE
3440 LET X=1
3450 LET Y=1
3460 LET T=0
3470 AT 0,0: PRINT N
3480 RETurn 
3500 REMark  CONFIG: BY MIKE JONAS FOR ZXSIMULATOR
3510 LET LEFT=CODE ("5")
3520 LET RIGHT=CODE ("8")
3530 LET DOWN=CODE ("6")
AT #0,0,8:PRINT #0,"-"
3540 LET UP=CODE ("7")
3550 LET CHECK=CODE ("o")
3560 LET MARK=CODE ("m")
3570 AT 11,5: PRINT "S:TART C:HANGE"
3580 GO SUB 3800
3590 AT 11,5: PRINT "              "
3600 IF KEY=CODE ("s") THEN RETurn 
3610 AT 11,5: PRINT "KEY FOR:"
3620 AT 11,14: PRINT "LEFT?"
3630 GO SUB 3800
AT #0,0,8:PRINT #0,"\"
3640 LET LEFT=KEY
3650 AT 11,14: PRINT "RIGHT?"
3660 GO SUB 3800
3670 LET RIGHT=KEY
3680 AT 11,14: PRINT "DOWN? "
3690 GO SUB 3800
3700 LET DOWN=KEY
3710 AT 11,14: PRINT "UP?   "
3720 GO SUB 3800
3730 LET UP=KEY
3740 AT 11,14: PRINT "OPEN? "
AT #0,0,8:PRINT #0,"|"
3750 GO SUB 3800
3760 LET CHECK=KEY
3770 AT 11,5: PRINT "              "
3780 RETurn 
3800 REMark  GET KEY
3810 LET KEY=CODE (INKEY$)
3820 IF KEY<>0 THEN RETurn 
3830 GO TO 3810
4000 REMark  CHECK END
4010 FOR I=1 TO 32
AT #0,0,8:PRINT #0,"/"
4020 FOR J=1 TO 21
4030 LET E=21*(I-1)+J
4040 LET K= F(E)
4050 IF K>=10 AND K<=19 THEN RETurn 
4060 IF K>=30 THEN RETurn 
4070 NEXT J
4080 NEXT I
4100 REMark  WINNER
4120 LET K$="READY "
4130 GO TO 5500
AT #0,0,8:PRINT #0,"-"
5000 REMark  HIT BOMB
5010 FOR N=1 TO 70
5020 LET E=B(N)
5030 LET X=INT ((E-1)/21)
5040 LET Y=E-(X*21)
5050 AT Y,X: PRINT "*"
5060 NEXT N
5070 LET K$=" BOOM "
5080 PAUSE 50
5500 REMark  END MESSAGE
AT #0,0,8:PRINT #0,"\"
5510 AT 10,11: PRINT ":''''''''':"
5520 AT 11,11: PRINT ":  ";K$;" :"
5530 AT 12,11: PRINT ":.........:"
5540 PAUSE 100
9000 CLS
9010 CLEAR
9020 AT 0,0: PRINT "  MINESWEEPER BY BODO WENZEL"
9030 PRINT "TRANSLATED AND MCODER BY PETER"
9040 PRINT "       HTTP://WWW.ZX81.DE"
9050 PRINT "ZXSIMULATOR KEY MAP: MIKE JONAS"
AT #0,0,8:PRINT #0,"|"
9060 PRINT
9070 PRINT "CHOOSE R:ESTART OR Q:UIT"
9080 INPUT I$
9090 IF LEN (I$)<>1 THEN GO TO 9080
9100 IF I$="r" THEN RUN
9110 STOP
AT #0,0,0:PRINT #0,"Complete."


Derek_Stewart
Font of All Knowledge
Posts: 4109
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Dynamic program loading in SuperBASIC

Post by Derek_Stewart »

Hi,

I tried adding unumbered line with MRUN to a numbered programme.

BUt on QPC2, Q68, SMSQmulator, the sysem is going so fast the SBASIC is loaded and no counter can be seen, only a flash of the status loading bar.


Regards,

Derek
User avatar
badaman
Over Heated PSU
Posts: 149
Joined: Sun Jan 12, 2020 12:18 pm
Location: Spain
Contact:

Re: Dynamic program loading in SuperBASIC

Post by badaman »

bwinkel67 wrote: Wed May 15, 2024 12:18 pm I added a twirling clock to minesweeper program and it works really well:
Great!


User avatar
badaman
Over Heated PSU
Posts: 149
Joined: Sun Jan 12, 2020 12:18 pm
Location: Spain
Contact:

Re: Dynamic program loading in SuperBASIC

Post by badaman »

Derek_Stewart wrote: Wed May 15, 2024 1:38 pm Hi,

I tried adding unumbered line with MRUN to a numbered programme.

BUt on QPC2, Q68, SMSQmulator, the sysem is going so fast the SBASIC is loaded and no counter can be seen, only a flash of the status loading bar.
This gives a new meaning to the definition of "shadow loading" for cases like the one you mention on fast machines. #Humor


User avatar
dilwyn
Mr QL
Posts: 2826
Joined: Wed Dec 01, 2010 10:39 pm

Re: Dynamic program loading in SuperBASIC

Post by dilwyn »

I'll just add a little note of caution here as regards a warning in the Toolkit 2 manual of what can happen with un-numbered lines in a BASIC file on some QDOS ROMs, which is also mentioned in Simon Goodwin's ROM bugs articles in QL World.

"If you try to RUN a BASIC program from a DO file, then the file will be left open. Likewise, if you put direct commands in a file that is MERGEd, then the file will be left open."

(a DO file is a file of direct commands to be executed by Toolkit 2's DO command).

That may be why this technique has never really been implemented, that people were aware of potential issues like this with loading files with direct commands if someone were to MERGE the program. Simon's articles state that this MERGE issue is fixed in Minerva and to some extent by Toolkit 2.

In any event, it would be easy to check if LRUN / LOAD work OK just by loading from a disk and checking if the file remains open afterwards using something like the channels menu of QPAC2, or even by changing disks - the system will soon complain if you try to change disks with a file still open.


Derek_Stewart
Font of All Knowledge
Posts: 4109
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Dynamic program loading in SuperBASIC

Post by Derek_Stewart »

Hi,

How do the programme loader S*BASIC lines get added to the programme being loaded?

All the large programmes I load are loaded within a second of pressing Enter key.


Regards,

Derek
User avatar
bwinkel67
QL Wafer Drive
Posts: 1267
Joined: Thu Oct 03, 2019 2:09 am

Re: Dynamic program loading in SuperBASIC

Post by bwinkel67 »

dilwyn wrote: Thu May 16, 2024 7:18 pm I'll just add a little note of caution here as regards a warning in the Toolkit 2 manual of what can happen with un-numbered lines in a BASIC file on some QDOS ROMs, which is also mentioned in Simon Goodwin's ROM bugs articles in QL World.

"If you try to RUN a BASIC program from a DO file, then the file will be left open. Likewise, if you put direct commands in a file that is MERGEd, then the file will be left open."

(a DO file is a file of direct commands to be executed by Toolkit 2's DO command).
Thanks for that info. I will give it a try. It sounds like Toolkit 2 specifically added the DO command to avoid using LRUN or LOAD for unnumbered lines?!


User avatar
dilwyn
Mr QL
Posts: 2826
Joined: Wed Dec 01, 2010 10:39 pm

Re: Dynamic program loading in SuperBASIC

Post by dilwyn »

Not sure if it applies to LOAD/LRUN, it specifically mentions MERGE.


Post Reply