6

I am trying to check does any disk is present in drive A: (after my program installs i need to ensure that computer won't boot from installation diskette). I've tried using _access method (undefined reference...), FILE* and making directory inside diskette and remove it after checking. Unfortunately DOS displays ugly piece of text about putting disk in drive (Destroying my TUI and making user think that diskette in drive is important). So how to suppress this message, or safely check does disk is present in drive?

Kamila Szewczyk
  • 1,874
  • 1
  • 16
  • 33

2 Answers2

1

Possibly BIOS INT 13H 16H: Detect Media Change - it has a status:

80H = diskette drive not ready or not installed

Which may solve your problem - I lack the antique hardware and software to test it personally.

#include <dos.h>

unsigned int DetectMediaChange()
{
    union REGS regs;

    regs.h.ah = 0x16;            // Detect Media Change
    regs.h.dl = 0;               // Drive A
    int86( 0x13, &regs, &regs ); // BIOS Disk I/O INT 13h

    return regs.h.ah ;           // Status :  00H = diskette change line not active
                                 //           01H = invalid drive number
                                 //           06H = either change line is not supported or
                                 //                 disk change line is active (media was swapped)
                                 //           80H = diskette drive not ready or not installed
                                 // else= BIOS disk error code if CF is set to CY
}
Clifford
  • 88,407
  • 13
  • 85
  • 165
  • So if disk is not in drive will return 06h? – Kamila Szewczyk May 08 '17 at 15:14
  • 1
    @KrzysztofSzewczyk : I have added C code; but it is derived from antique code found on the Internet for other DOS/BIOS services; I have not tested it. Whether it works on a virtual machine depends entirely on the completeness of the virtualisation; since the BIOS is probably fundamental to may things working, one would imagine that it is complete and would therefore work. For you to try, not me to know. – Clifford May 08 '17 at 15:15
  • 1
    @KrzysztofSzewczyk : What makes you think that? I would imagine `0x80` as per the comment and the link referenced. But it depends what "not ready" means I guess - it is rather poorly documented. 0x06 occurs I believe when the "door" is operated (disk insert, possibly disk eject, but you would hope 0x80 would prevail in that event). I suggest you are in the best position to try this and care more than I do. Just suck it and see! – Clifford May 08 '17 at 15:18
  • Okay. I've inserted disk and it returned 6, took disk and returned 6. Broken. – Kamila Szewczyk May 08 '17 at 15:21
  • The "changed" status is only reset to zero on a valid disk access, so insert, access, eject. However you would get that result too if you ejected and immediately reinserted. Also "change line is not supported" is an allowed option and would generate that result - not "broken", just not implemented, or does not do what you need. I had hoped for a 0x80 on no media. – Clifford May 08 '17 at 15:25
  • That's okay then, but i need real-time information about diskette is inserted, "at the moment". – Kamila Szewczyk May 08 '17 at 15:26
  • If you can, simpler perhaps to prevent diskette media booting in the BIOS configuration. – Clifford May 08 '17 at 15:27
  • from my place it's impossible. I've heard about an interrupt that can disable it. I'll check out what exactly interrupt is it – Kamila Szewczyk May 08 '17 at 15:28
  • Sorry that was by best stab and software archaeology - I have nothing more for you at present. I doubt you can disable it from an S/W interrupt since it occurs on boot up - it needs a modification of the battery backed CMOS memory containing the BIOS configuration (and may not even be supported). – Clifford May 08 '17 at 15:30
  • I think `Int 2F/4A00` relates to swapping drive A/B on a single floppy machine. I am not sure how that will solve your problem. – Clifford May 08 '17 at 15:33
  • "Called by MS-DOS 5.0+ IO.SYS just before displaying the message "Insert diskette for drive X:" on single-floppy systems" and "FFFFh to skip "Insert diskette for drive X:" message" – Kamila Szewczyk May 08 '17 at 15:35
  • Yes but it still refers to "logical" not "physical" drives. See https://blogs.msdn.microsoft.com/oldnewthing/20090402-00/?p=18643 if it could not be done in Win95, I am pretty sure it was not a feature of MS-DOS either. – Clifford May 08 '17 at 15:36
1

Okay, I've figured it out:

char far * bufptr;
union REGS inregs, outregs;
struct SREGS segregs;
char buf [1024];
avaliable(){
    redo:
    segread(&segregs);
    bufptr = (char far *) buf;
    segregs.es = FP_SEG(bufptr);
    inregs.x.bx = FP_OFF(bufptr);
    inregs.h.ah = 2;
    inregs.h.al = 1;
    inregs.h.ch = 0;
    inregs.h.cl = 1;
    inregs.h.dh = 0;
    inregs.h.dl = 0;
    int86x(0x13, &inregs, &outregs, &segregs);
    return outregs.x.cflag;
}

Returns true if disk is in drive.

Kamila Szewczyk
  • 1,874
  • 1
  • 16
  • 33