First you have to check if MSCDEX is installed.
This is all in assembly, but it is not to hard to port to C or to do
it inline. Make sure to preserve DS, just in case I forgot to, in functions that alter it or C will crash.
I would personally write this in a separate assembly source file and then call out to it from C. If you need help on setting that up, let me know.
Code:
mov AX,0DADAh
push AX
mov AX,01100h
int 2Fh
pop BX
cmp BX,0ADADh
jne NOTFOUND
;if we get here MSCDEX is installed
To get the version of MSCDEX
Code:
mov AX,0150Ch
int 2Fh
;BH holds major version
;BL holds minor version
To do anything you have to know how many CD-ROMS are present
Code:
mov AX,01500h
xor BX,BX ;same as mov bx,0
int 2Fh
;BX holds number of CD-ROMS
;CL holds first drive's letter (0=A,1=B, etc.)
;Cannot be used with DOS 4.0 GRAPHICS.COM
Now you need to get the name of the CD-ROM device driver
You will need a buffer that is 5 times the number of drives present (in bytes).
Code:
mov AX,01501h
les BX,Array
int 2Fh
Now to get a file handle to the device
FileHandle can be retrieved via DOS function 3Dh
Code:
mov dx, SEG Array ;our file name is the device driver
push ds ;even for inline asm - DS must be pushed
mov ds,dx
mov dx,OFFSET Array
mov al,002h ;open file for read/write
mov ah,3Dh ;open file with handle
int 21h
jc error_encountered
mov FileHandle,ax
pop DS ;restore DS so C or asm can continue normally
;handle will be in AX
Now you can check the CD-ROM status
You will need a 5 byte block of memory.
Code:
mov bx,FileHandle
mov cx,MaxBytes
mov dx,SEG Buffer
push ds ;Save DS
mov ds,dx
mov dx,OFFSET buffer
mov ax,04402h
int 21h
jc error_encountered
mov BytesReceived,ax
pop DS ;Restore DS
bit 10 is set if audio is playing
bit 9 is set if Red Book and HSG addressing are supported
bit 8 is set if audio channel control is supported
bit 7 is set if prefetch requests are supported
bit 5 is set if interleaving is supported
bit 4 is set if audio/video playback supported
bit 3 is set if the CD-ROM is writable
bit 2 is set if raw and cooked read is supported
bit 1 is set if door is unlocked
bit 0 is set if door is open
Hope this helps.