Procedure CheckDevice()

AmigaOS specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.

Hi,

here a little procedure which tests if a device is available in the systems
device list. Device means things like "DF0", "DH0", etc., but also devices
like "PIPE", "AUX" etc.

Parameter : name of the device to check for (e.g. "CON", "PAR" etc.).
Note: you don't have to add an ":" after the name
Returns : TRUE (-1) if the device is available, FALSE (0) if the device is
not present in the systems device list


Procedure.b CheckDevice(device$)
info.l=PeekL(PeekL(DosBase()+34)+24)*4 ; DosBase+34=root structure, root+24=info structure, *4 because it is a BCPL pointer
devinfo.l=PeekL(info+4)*4 ; pointer to deviceinfo structure
texte.l=PeekL(devinfo+40)*4 ; pointer to the name of the device
type.l=PeekL(devinfo+4) ; what type ? (0=device 1=directory 2=volume
While devinfo0 ; we search in all deviceinfo structures, 0= end of lists
IF type=0 ; type=device
text$=PeekS(texte+1) ; read out name of device (DF1 etc.), +1 because it is a BCPL string
IF text$=UCase(device$) ; is it the device we search for
ProcedureReturn -1 ; yes --> return TRUE
EndIf
EndIf
devinfo=PeekL(devinfo)*4 ; next device
texte=PeekL(devinfo+40)*4
type=PeekL(devinfo+4)
Wend
ProcedureReturn 0 ; not found --> return FALSE
EndProcedure

ok.b=CheckDevice("AWNPIPE")
if ok=-1
PrintN("Ok, AWNPIPE is available, we can use it!")
Else
PrintN("Hmm, AWNPIPE is not available, we use PIPE instead :)")
EndIf
End

Greetings ..
Roxxler
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Hello Roxxler !!

1 little thing:
>Returns:
>TRUE (-1) if the device is available,
>FALSE (0) if the device is not present

#FALSE is 0, right.

But #TRUE has ever been 1, not -1.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by plouf.

true is differend than 0
and dostrue(#DOSTRUE) in amigaos is -1
so its not so wrong :)
(i do by mistake write work i wond to write wrong :))
and #TRUE is 0 AFAIK in most languanges including blitz


Christos



Edited by - plouf on 21 February 2002 21:05:28
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.
Hello Roxxler !!

1 little thing:
>Returns:
>TRUE (-1) if the device is available,
>FALSE (0) if the device is not present

#FALSE is 0, right.

But #TRUE has ever been 1, not -1.

cya,
...Danilo

(registered PureBasic user)
It's not uncommon for #TRUE to be -1, for instance blitzbasic2 on amiga uses -1 as the value for TRUE, and logically -1 is a good value because bitwise all bits are set to 1 i.e. -1(byte)=11111111(binary)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.
Hello Roxxler !!

1 little thing:
>Returns:
>TRUE (-1) if the device is available,
>FALSE (0) if the device is not present

#FALSE is 0, right.

But #TRUE has ever been 1, not -1.

cya,
...Danilo

(registered PureBasic user)
It's not uncommon for #TRUE to be -1, for instance blitzbasic2 on amiga uses -1 as the value for TRUE, and logically -1 is a good value because bitwise all bits are set to 1 i.e. -1(byte)=11111111(binary)
Hi.

Yes, the reason for me to use -1 as TRUE are:
Long time ago, i started to learn something about AmigaDOS and the first
thing i've learned was the DOSTRUE, which was -1. So i used it of course in
AmigaBasic. Later GFA-Basic followed and there was also a system variable
called TRUE (also -1).
Next reason is something logical for me. If something went fine it returns
-1. If not it returns 0 or higher, which means that it returns in every case
something higher as -1. So -1 is ok, 0 means that something went wrong, 1 can
be a reason why it went wrong, 2 another reason and so on. If i use 1 for TRUE:
then 0 means failed, 1 is ok, 2 reason why it was 0, 2 maybe another reason
why it failed and so on. For me this is not clearly logical. Hope you understand
what i mean.

Greetings ..
Roxxler
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.
Hi.

Yes, the reason for me to use -1 as TRUE are:
Long time ago, i started to learn something about AmigaDOS and the first
thing i've learned was the DOSTRUE, which was -1. So i used it of course in
AmigaBasic. Later GFA-Basic followed and there was also a system variable
called TRUE (also -1).
Next reason is something logical for me. If something went fine it returns
-1. If not it returns 0 or higher, which means that it returns in every case
something higher as -1. So -1 is ok, 0 means that something went wrong, 1 can
be a reason why it went wrong, 2 another reason and so on. If i use 1 for TRUE:
then 0 means failed, 1 is ok, 2 reason why it was 0, 2 maybe another reason
why it failed and so on. For me this is not clearly logical. Hope you understand
what i mean.

Greetings ..
Roxxler
You lost me there :wink:
What i meant to say was that from a strictly Boolean algebra perspective there is only one correct value for #TRUE and that is -1, so with this in mind, -1 is logically a good value. Do you follow my logic :wink:
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Well, it was only a little hint about constants.

#TRUE should be the same in all PureBasic versions.
I checked it with PB/win, and there #TRUE is 1 and
#FALSE is 0.
This has nothing to do with #DOSTRUE or anything...

When somebody wants to write a multiplatform
application/game, all constants need to be the same.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.
You lost me there :wink:
What i meant to say was that from a strictly Boolean algebra perspective there is only one correct value for #TRUE and that is -1, so with this in mind, -1 is logically a good value. Do you follow my logic :wink:
:-) Yes, i can follow you, of course. I never saw it from this side :)

Roxxler
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.
Well, it was only a little hint about constants.

#TRUE should be the same in all PureBasic versions.
I checked it with PB/win, and there #TRUE is 1 and
#FALSE is 0.
This has nothing to do with #DOSTRUE or anything...

When somebody wants to write a multiplatform
application/game, all constants need to be the same.

cya,
...Danilo
(registered PureBasic user)
Hi,

if you see it from this side then it is right, of course. But
note that i never use TRUE as a constants. I don´t touch #TRUE.
The first thing i do in my programs is to define two variables
FALSE.b=0 and TRUE.b=-1 and work with this.
By the way: to write a multiplatform application / game all PureBasic
functions and comands should be the same on all machines; until now
the differences are to big. Not only regarding the GUI. For e.g. the
function FindString(String$, StringToSearch$, StartPosition). You can
use the function with a StartPosition of 0 with the PC version, no problem.
But on the Amiga it must start with 1. This is only one example and maybe
it is a bug on the amiga side.

Greetings ..
Roxxler
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by plouf.

the #TRUE is constand .. its the same
and then the correct way to check for true is 0
if variable 0 ; this is TRUE
this is the correct way in most languages
(i think blitz its that way) C and others

Christos
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

so you want to tell me that

If command() / variable = #TRUE
[...]
Endif

is incorrect in PureBasic, plouf ??

Please.... :wink:

cya,
...Danilo (incorrect coder)

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.
so you want to tell me that

If command() / variable = #TRUE
[...]
Endif

is incorrect in PureBasic, plouf ??

Please.... :wink:

cya,
...Danilo (incorrect coder)
Hehe, much ado about nothing!
It's not incorrect but you have to be aware that it is a constant. Basicly this means that you check against 1, this gives that the line below equals what you wrote earlier:
If [command()][variable]=1

You might want to try the following to check your theory(please notify me if you get the code inside the If statement to run;)

Code: Select all

if OpenWindow(0,0,0,100,100,0,"test")=#TRUE
...
EndIf
It is as plouf said, all values except zero is considered as TRUE in an If statement...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.
the #TRUE is constand .. its the same
and then the correct way to check for true is 0
if variable 0 ; this is TRUE
this is the correct way in most languages
(i think blitz its that way) C and others

Christos
Oh, many action around nearly nothing :) Or just around some definitions.
If a constant is the same like a variable why it isn´t called variable ?
It isn´t the same, it is just something like a placeholder, nothing more.

I think we all can live with it if we say TRUE is 0.

Greetings ..
Roxxler
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.
Oh, many action around nearly nothing :) Or just around some definitions.
If a constant is the same like a variable why it isn´t called variable ?
It isn´t the same, it is just something like a placeholder, nothing more.

I think we all can live with it if we say TRUE is 0.

Greetings ..
Roxxler
Yeah, you're right, let's just discontinue this thread, i think we've dragged this out long enough, all that needs to be said has been said.
Oh, by the way nice set of examples you've posted Roxxler you rule the PB Amiga corner :wink:
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.
Yeah, you're right, let's just discontinue this thread, i think we've dragged this out long enough, all that needs to be said has been said.
Oh, by the way nice set of examples you've posted Roxxler you rule the PB Amiga corner :wink:
Yeah, hope there are coming some another PB Amiga users too. Learning together
is much easier :))

Greetings ..
Roxxler
Post Reply