Page 1 of 1

Check if BASIC is running

Posted: Fri Mar 08, 2019 4:35 pm
by Andrew
How can I check if BASIC is running ?

A function like this
100 DEFine FuNction isBasicRunning
110 RETurn NOT BASIC_B%(111)
120 END DEFine isBasicRunning

will return 1 (aka Basic is running) if either:
  1. a BASIC program is running
  2. a BASIC program was running but execution was interrupted with CTRL-SPACE (user can use CONTINUE to resume the execution)
  3. a BASIC program has run, but there was no STOP command in the program and no CLEAR or NEW command was issued after it ended
I am interested in finding a way that would return TRUE only if a BASIC program is actually running (item 1 from above - but not for items 2 and 3).
Is there any memory address / system variable / whatever that I could check ?

Re: Check if BASIC is running

Posted: Fri Mar 08, 2019 9:55 pm
by NormanDunbar
Ther's a list of Basic's own variables at http://qdosmsq.dunbar-it.co.uk/doku.php ... nal:sbvars which might be useful.

Number 2 you might get from bv_cont, possibly bv_line nd/or bv_stmt for option 1. Not sure about the last option though.

Good luck.

Cheers,
Norm.

Re: Check if BASIC is running

Posted: Fri Mar 08, 2019 10:20 pm
by Andrew
Thank you Norman !
I did not knew your site - but it is great ! Full of info I was looking for ! thank you !!

Re: Check if BASIC is running

Posted: Fri Mar 08, 2019 11:39 pm
by EmmBee
Current Line number executing ... BASIC_W%(104)

Continue Line number ... BASIC_W%(146)

Break - whether Ctrl-Space was pressed - BASIC_B%(143)

Best of luck with this. I got the above information from Jan Jones's QL SuperBASIC The Definitive Handbook
These will work with QDOS - but not necessarily with SMSQ/E

Re: Check if BASIC is running

Posted: Thu Mar 14, 2019 11:19 pm
by EmmBee
Here is a version I wrote ...

Code: Select all

DEFine FuNction isBasicRunning
  IF VER$ = "HBA"
    REMark SMSQ/E
    IF BASIC_B%(110) = 1 : RETurn 1 : ELSE RETurn 0
  ELSE
    REMark QDOS
    IF CHBASE(0,0) <> -1 : RETurn 2 : REMark no #0 cursor
    IF BASIC_W%(104) = BASIC_W%(146) : RETurn 0 : REMark STOP occurred
    IF BASIC_B%(143) = 0 : RETurn 0 : REMark break - Ctrl-Space pressed twice
    IF BASIC_B%(111)<> 0 : RETurn 0 : REMark single line command
    RETurn 3 : REMark Input to #0
  END IF
END DEFine isBasicRunning
It uses the DIY VolQ QBASE toolkit function CHBASE(). This makes the code easier to write.

Re: Check if BASIC is running

Posted: Fri Mar 15, 2019 10:30 pm
by Andrew
Thank you EmBee

IF CHBASE(0,0) <> -1 : RETurn 2 : REMark no #0 cursor
No matter what (program running or not running), on QEmulator I always get that CHBASE(0,0) = -1

Re: Check if BASIC is running

Posted: Sat Mar 16, 2019 12:10 pm
by EmmBee
I now don't think that the CHBASE(0,0) line is really necessary - it can be deleted.
It's all to do with finding out if it's stopped.
If it's not stopped, then it must be running.