Procedure ExistDiskDrive()

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 to check if a diskdrive is present or not.
For that the procedure uses the exec/OpenDevice() function, so we
have to open the exec.library at program start. Also used is the
PureBasic function AllocateMemoryBank(0,....), so we need also
a InitMemory(min 0) at program start.


Procedure.b ExistDiskDrive(drivenumber.b) ; parameter is the number of the diskdrive (0-3)
iorequest.l=AllocateMemoryBank(0,80,#MEMF_FAST|#MEMF_CLEAR) ; we need some mem for the iorequest
res.l=OpenDevice_(@"trackdisk.device",drivenumber,iorequest,0) ; we open the device, for diskdrives it is the
; trackdisk.device, the unitnumber is also used
; and also the address of our iorequest
If res=0 ; 0 means that all went fine and the device is open
CloseDevice_(iorequest) ; close the opened device
ProcedureReturn -1 ; and we can return -1 (TRUE), the drive is present
Else
ProcedureReturn 0 ; >0 means that the drive is not present, we return a 0
EndIf
FreeMemoryBank(0) ; free our mem, we don't have to do this, PureBasic will do it at program end, but we do
EndProcedure

;example:
OpenExecLibrary_(36)
InitMemoryBank(0)
For z.b=0 To 3
ok.b=ExistDiskDrive(z)
If ok
Print("Diskdrive DF"):PrintNumber(z):PrintN(": is present!")
Else
Print("Diskdrive DF"):Printnumber(z):PrintN(": is not present!")
EndIf
Next z
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 plouf.

nice procedure :)

and you can check other devices as well not only trackdisk :)



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 Roxxler.
nice procedure :)

and you can check other devices as well not only trackdisk :)
Christos
Hi,

yes you can :) Just change the device and the drivenumber (which is the unitnumber). E.g. "scsi.device" drivenumber "0" will check if there is a
harddisk is present as Unit 0 at the internal IDE or SCSI adaptor.

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

Hi,

here again the procedure ExistDiskDrive(). I have changed it a little bit,
because the first one don't free MemoryBank 0 correct. Of course PureBasic
will close every Bank at program end, but i always use Bank 0 in my procedures
and if it is already used trouble is in sight.

Procedure.b ExistDiskDrive(drivenumber.b)
iorequest.l=AllocateMemoryBank(0,80,#MEMF_FAST|#MEMF_CLEAR)
res.l=OpenDevice_(@"trackdisk.device",drivenumber,iorequest,0)
If res=0
CloseDevice_(iorequest)
ret.b=-1
Else
ret.b=0
EndIf
FreeMemoryBank(0)
ProcedureReturn ret
EndProcedure


Greetings ..
Roxxler
Post Reply