Check if BASIC is running

Anything QL Software or Programming Related.
Post Reply
User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Check if BASIC is running

Post 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 ?


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Check if BASIC is running

Post 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.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: Check if BASIC is running

Post by Andrew »

Thank you Norman !
I did not knew your site - but it is great ! Full of info I was looking for ! thank you !!


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: Check if BASIC is running

Post 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


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: Check if BASIC is running

Post 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.


User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: Check if BASIC is running

Post 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


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: Check if BASIC is running

Post 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.


Post Reply