Procedure ExistDisk()

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 procedure which tests if a disk is inserted to a diskdrive.
For this the exec functions OpenDevice() and CloseDevice() are used.
Also used is the Dos function DoIO(). So the exec.library and dos.library
must be open. Also used is a InitMemoryBank(0) at program start, the
procedures uses Bank 0.

To avoid an upcoming "Please insert volume ...." if a drive is not available
just use the procedure ExistDiskDrive() i posted already before this procedure.

The parameter is just the number of the drive: 0 for df0:, 1 for df1: etc.
The procedure returns TRUE (-1) if a disk is present in the drive, FALSE (0)
if not.

Procedure.b ExistDisk(drivenumber.b)
iorequest.l=AllocateMemoryBank(0,80,#MEMF_FAST|#MEMF_CLEAR) ; some mem
res.l=OpenDevice_(@"trackdisk.device",drivenumber,iorequest,0) ; open trackdisk.device unit=drivenumber
If res=0
PokeW(iorequest+28,14) ;offset 28=command field, 14= Disk inserted ?
DoIO_(iorequest)
If PeekL(iorequest+32)>0 ;offet 32=command return field, >0 = Disk is not present
CloseDevice_(iorequest) ; close what we get from the system
ret.b=0
Else
CloseDevice_(iorequest)
ret.b=-1
EndIf
Else
ret.b=0
EndIf
FreeMemoryBank(0)
ProcedureReturn ret
EndProcedure

OpenExec.Library_(36)
OpenDosLibrary_(36)
InitMemoryBank(0)

ok.b=ExistDisk(0) ; test if a disk is present in DF0:
if ok=-1
PrintN("Disk is present!")
Else
PrintN("No Disk present!")
EndIf
End



Greetings ..
Roxxler