🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #6438

Re: Floppy Drive Readiness

#6438
From: Andrew Gryc
Date: Thu, 19 Nov 1992 18:43
50 lines
2084 bytes
Below is code I wrote to determine if a disk is in Drive A (the code can
be easily modified to check for B: too, if you load DL from a stack param;
0=A:, 1=B:).
It is in C inline assembly (best of both worlds, as far as I'm concerned).  
I've used it without problem, but please note that I was coding this for 
a specific BIOS platform (i.e. read the note about ES:BX!).  Have fun...
 

o
 \/___________________________________________________________________________
 /\
o

int DiskInDriveA(void)
{
  _asm {
    mov cx,4        ; Allow once + 3 retries before we give up 
                    ; (motor may not be on initially, and BIOS will err)

TryAgain:
    push cx
    mov ah,4        ; Verify sector (uses ES:BX as ptr to verify buffer)
                    ; Don't care where es:bx points to (NOTE: apparently, this
                    ;   can be a problem for some early versions of BIOS, 
                    ;   to be safe, point to a sector-sized "junk" area) 
    mov al,1        ; 1 sector long
    xor cx,cx       ; cylinder 0, sector 0
    xor dx,dx       ; head 0, drive 0
    int 13h         ; Who cares if it verifies, just want to see if disk present
    cmp ah,80h
    jne DiskThere   ; 80h is disk timeout--anything else is a real disk

    mov ah,00h      ; Reset diskette A:
    int 13h
    pop cx
    loop TryAgain   ; Oops, errored on verify...

    xor ax,ax
    jmp short ExitDisk
DiskThere:
    pop cx           ; Grab the loop off the stack
    mov ax,1
ExitDisk:
  }
}

----------------------------------------------------------------------
Andrew J. Gryc   |  #include <stddisclaimer.h>
Hewlett-Packard  |
Corvallis, OR    |
Technical Details
Message-ID: <198880001@hpcvra.cv.hp.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hp-cv!hp-pcd!hpcvra!andyg
References: <951@hq.dla.mil>

Show Full Headers
Complete Article Headers
From: andyg@hpcvra.cv.hp.com (Andrew Gryc)
Date: Thu, 19 Nov 1992 18:43:41 GMT
Subject: Re: Floppy Drive Readiness
Message-ID: <198880001@hpcvra.cv.hp.com>
Organization: Hewlett-Packard Co., Corvallis, OR, USA
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hp-cv!hp-pcd!hpcvra!andyg
Newsgroups: comp.os.msdos.programmer
References: <951@hq.dla.mil>
Lines: 50