Re: Suppress Critical Error Message

new topic     » goto parent     » topic index » view thread      » older message » newer message

re: drive not ready.

I had a request to do the same error check with my editor before floppy disk
writes. It's been on the back burner, but I've got some files from the All
Basic Code packets that deal with the problem. The first file looks like an
easy port to Euphoria; the second is in assembly, but looks like it's just a
couple of BIOS calls as well, so it should be easy to port as well.

You may want to check for space on the disk as well, since that will also
generate an error. If you want, I can try digging that up as well.

Hope this helps.

 -- David Cuny

 -- TESTDISK.BAS BEGINS HERE
' Function FLOPPYDRIVEREADY checks if disk is in drive
' Function FLOPPYWRITEOK checks if disk is write protected

'$INCLUDE: 'QB.BI'

DECLARE FUNCTION FloppyDriveReady% (Drive$, ErrCode%)
DECLARE FUNCTION FloppyWriteOK% (Drive$)

DIM SHARED Register AS RegType, XRegister AS RegTypeX

A = FloppyDriveReady%("A", ErrCode%)

IF ErrCode% = -1 THEN PRINT "Disk in drive." ELSE PRINT "Drive not ready."

FUNCTION FloppyDriveReady% (Drive$, ErrCode%)
'returns True (-1) if the floppy drive specified in Drive$
'has a disk in it. If the function returns False (0), ErrCode%
'contains the DOS error code.
'by Douglas H. Lusher, April, 1993

Drive% = (ASC(Drive$) OR 32) - 97

'reset floppy drive
Register.ax = 0
Register.dx = Drive%
CALL INTERRUPT(&H13, Register, Register)

Register.ax = &H401
Register.cx = &H101
Register.dx = Drive%
CALL INTERRUPT(&H13, Register, Register)

'call the interrupt twice since if a disk has just been inserted,
'the first time gives a wrong answer
Register.ax = &H401
Register.cx = &H101
Register.dx = Drive%
CALL INTERRUPT(&H13, Register, Register)
FloppyDriveReady% = ((Register.flags AND 1) = 0)
ErrCode% = ((Register.ax AND &HFF00) \ &H100) AND &HFF

END FUNCTION

FUNCTION FloppyWriteOK% (Drive$)
'returns True (-1) if the disk in the specified floppy drive
'is not write protected
'by Douglas H. Lusher, April 1993

Drive% = (ASC(Drive$) OR 32) - 97

'reset floppy drive
XRegister.ax = 0
XRegister.dx = Drive%
CALL INTERRUPTX(&H13, XRegister, XRegister)
XRegister.ax = &H401
XRegister.cx = &H101
XRegister.dx = Drive%
CALL INTERRUPTX(&H13, XRegister, XRegister)

Buffer$ = SPACE$(512)
'read from the disk
XRegister.ax = &H201
XRegister.es = VARSEG(Buffer$)
XRegister.bx = SADD(Buffer$)
XRegister.cx = &H101
XRegister.dx = Drive%
CALL INTERRUPTX(&H13, XRegister, XRegister)

'try writing back to the disk
XRegister.ax = &H301
XRegister.es = VARSEG(Buffer$)
XRegister.bx = SADD(Buffer$)
XRegister.cx = &H101
XRegister.dx = Drive%
CALL INTERRUPTX(&H13, XRegister, XRegister)
FloppyWriteOK% = ((XRegister.flags AND 1) = 0)
ErrCode% = ((XRegister.ax AND &HFF00) \ &H100) AND &HFF

END FUNCTION


 -- TESTDISK.BAS ENDS HERE





 -- READY.BAS BEGINS HERE
' Drive Ready source for PowerBASIC 3.x
' by BRIAN MCLAUGHLIN

$LIB ALL OFF

DEFINT A-Z

DECLARE FUNCTION DriveReady( BYVAL Drive$ )

FOR X = ASC( "A" ) TO ASC( "F" )
  PRINT "Checking...";
  Ready = DriveReady( CHR$( X ))
  PRINT "drive "; CHR$( X );
  IF Ready THEN
    PRINT " ready."
  ELSE
    PRINT " NOT ready."
  END IF
NEXT

'===============================
FUNCTION DriveReady( BYVAL Drive$ ) PUBLIC AS INTEGER
'===============================
' This FUNCTION returns -1 (true) if the drive is ready, or 0 (false),
' if the drive is not ready, or the drive letter is an invalid drive.
' It will NOT recognize a CD-ROM drive as being ready.

  DIM DriveNum AS LOCAL INTEGER
  DIM DriveIsReady AS LOCAL INTEGER

  DriveNum = ( ASC( Drive$ ) OR 32 ) - 97
  DriveIsReady = -1 'assume drive will be ready

  ! push DS
  ! xor  AX, AX
  ! mov  DX, DriveNum     ; zero - based drive numbering used
  ! int  &H13             ; CALL BIOS TO RESET the drive controller
  ! mov  AX, &H401
  ! mov  CX, &H101
  ! mov  DX, DriveNum
  ! int  &H13
  ! mov  AX, &H401
  ! mov  CX, &H101
  ! mov  DX, DriveNum
  ! int  &H13
  ! jnc  DriveOK          ; carry set could be a fixed disk
  ! mov  AH, &H1C         ; so LET us look, USING DOS
  ! mov  DX, DriveNum
  ! inc  DX               ; one - based drive numbering used
  ! int  &H21
  ! cmp  DX, &HFF
  ! je   DriveOK
  ! mov  AX, [BX]
  ! cmp  AX, &HF8
  ! je   DriveOK
  ! mov  DriveIsReady, 0

DriveOK:

  ! pop DS

  DriveReady = DriveIsReady

END FUNCTION

 -- READY.BAS FILE ENDS HERE

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu