Discussion:
Testing from a BASIC program the existence of a module
(too old to reply)
x***@gmail.com
2018-07-20 08:40:52 UTC
Permalink
As the title says, how can I test, from BASIC, the existence of a module ?

I'd like a real test for existence please, not a call and handling an error returned if the module is not present. Thanks in advance.
Vince M Hudd
2018-07-20 10:08:52 UTC
Permalink
Post by x***@gmail.com
As the title says, how can I test, from BASIC, the existence of a module ?
I'd like a real test for existence please, not a call and handling an error returned if the module is not present. Thanks in advance.
OS_Module 18 is probably the best you're going to get. According to the
documentation on the ROOL site, it does return an error pointer if the
module doesn't exist, but looks as though it should be simple to handle.

https://www.riscosopen.org/wiki/documentation/show/OS_Module%2018

This call was brought to my attention recently when I was discussing the
possibility of adding a module check to WaitUntil. In the end, though,
neither I nor the person I was discussing it with couldn't see any real
purpose for the addition.

(I'm not even entirely sure why I had the idea in the back of my mind -
possibly it was something requested an awfully long time ago!)
--
Vince M Hudd - Soft Rock Software - www.softrock.co.uk
RISCOSitory - www.riscository.com
John Williams (News)
2018-07-20 16:48:00 UTC
Permalink
Post by x***@gmail.com
As the title says, how can I test, from BASIC, the existence of a module ?
I'd like a real test for existence please, not a call and handling an
error returned if the module is not present. Thanks in advance.
Normally one would use the OS command RMEnsure in a Run file to check for
the presence of a module and this allows a command to be executed if it's
not present.

Normally this would be a command to RMLoad the module. But it could be
anything. It could be to raise an error, but it could be something else

You obviously have some reason for doing this from within a BASIC program,
whether multi or single-tasking.

I think if I had this problem I would call an Obeyfile from within the
BASIC and get it to set a system variable depending on the result.

When this OSCLI command returned to BASIC I would interrogate the system
variable using a routine such as this:

:
DEF FN_readsysvariable(sysvar$)
SYS"OS_ReadVarVal",sysvar$,block%,255,0,3 TO ,,val%
block%?val%=13
val$=$block%
=val$
:

Note that this requires a variable block% to have been dimensioned to size
255.

You then treat the returned string as a flag and do whatever you wish with
it.

This avoids the error scenario as you wish.

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Vince M Hudd
2018-07-20 17:58:01 UTC
Permalink
Post by John Williams (News)
[Check for the existence of a module from BASIC]
[...]
Post by John Williams (News)
I think if I had this problem I would call an Obeyfile from within the
BASIC and get it to set a system variable depending on the result.
[snip function to read a system variable]

As I said earlier, OS_Module 18. The docs I linked to said - and
probably still do for that matter! - that if the module is there, R0 is
preserved (18, the reason code), otherwise it contains an error pointer.

This is untested, and based purely on that, but if I read it right this
should work:

DEF FN_CheckForModule(ModuleName$)
LOCAL Result%
SYS "XOS_Module",18,ModuleName$ TO Result%
IF Result%=18 THEN =TRUE ELSE =FALSE
--
Vince M Hudd - Soft Rock Software - www.softrock.co.uk
RISCOSitory - www.riscository.com
John Williams (News)
2018-07-20 18:47:48 UTC
Permalink
Post by Vince M Hudd
This is untested, and based purely on that, but if I read it right this
OK - I'm conVinced!

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Steve Fryatt
2018-07-20 19:01:19 UTC
Permalink
On 20 Jul, "John Williams (News)" wrote in message
Post by John Williams (News)
I think if I had this problem I would call an Obeyfile from within the
BASIC and get it to set a system variable depending on the result.
When this OSCLI command returned to BASIC I would interrogate the system
Why an Obey file? Why not just

OSCLI("Set MyApp$MyModPresent 1")
OSCLI("RMEnsure MyModule Set MyApp$MyModPresent 0")

Although, as Vince says, using OS_Module 18 looks to be a much better
solution.
--
Steve Fryatt - Leeds, England

http://www.stevefryatt.org.uk/
l***@gmail.com
2018-07-21 15:53:03 UTC
Permalink
Post by Steve Fryatt
Why an Obey file? Why not just
OSCLI("Set MyApp$MyModPresent 1")
OSCLI("RMEnsure MyModule Set MyApp$MyModPresent 0")
Whenever I've had a need to check for the presence of a
module, it's always been the case that it's a fault if
it's not present, so the following has always been adequate:

*RMEnsure ModuleName 0.00 Error ModuleName not present

Otherwise,
SYS "XOS_Module",18,ModuleName$ TO ; Flags%
ModulePresent%=(Flags% AND 1)<>1

I'd prefer to test for the explicit case of an error being
returned, not for the case that R0<>18. I know it's as close
to impossible as makes no difference to have an error block
at address 18, but I would still prefer to test that an
*error* has been return, not for something that would also
be returned when an error is returned.

Unless the canonical Acorn documentation specifies something
else.

jgh
Vince M Hudd
2018-07-21 21:28:56 UTC
Permalink
On 21/07/18 16:53, ***@gmail.com wrote:

[snips]
Post by l***@gmail.com
Otherwise,
SYS "XOS_Module",18,ModuleName$ TO ; Flags%
ModulePresent%=(Flags% AND 1)<>1
I'd prefer to test for the explicit case of an error being
returned, not for the case that R0<>18.
Yes - but Xavier said:

"I'd like a real test for existence please, not a call and handling an
error returned if the module is not present."

Strictly speaking, doing it correctly as above or checking for R0<>18 is
still "handling an error returned" but I read that as not wanting to
check the flags for whatever reason.
--
Vince M Hudd - Soft Rock Software - www.softrock.co.uk
RISCOSitory - www.riscository.com
l***@gmail.com
2018-07-22 11:01:44 UTC
Permalink
Post by Vince M Hudd
Strictly speaking, doing it correctly as above or checking for R0<>18 is
still "handling an error returned" but I read that as not wanting to
check the flags for whatever reason.
Thinking a few thoughts, it is practically impossible for an
error block to be in the system zero page, and impossible for
it to be in the hardware vector space, and a lot of API calls
use <256 to test for non-address vs address, so I think I'd
be minded to use present=(R0<256), absent=(R0>255).

Loading...