PDA

View Full Version : check CD-ROM status...?????



Sunny
02-25-2002, 06:19 AM
Heya all ppl!!

Anyone here know how to check the status of the CD-ROM? I mean, like if there is a cd inside or if it's ejected...???

Ok, thanks a lot

ihsir
02-25-2002, 09:18 AM
theres a biosdisk() in bios.h. i haven't used it just read about it so can't really help you right now.

that's if you want to use it while like in programming.


otherwise whats wrong with using the d: or your driveletter command??

Shiro
02-25-2002, 01:04 PM
Isn't it in the documentation of your driver? I think you need to send a command to the driver and interpret the result it sends back. Sending a command to the driver is in this case calling a driver function which retrieves the status of the CD-ROM device.

VirtualAce
02-25-2002, 05:52 PM
You can access the CD-ROM via the multiplex interrupt 2Fh.

For more information consult Ralf Brown's Interrupt Listing. You will also have to use DOS IOCTL via int 21h to issue IO commands to the drive for things such as opening the door and closing the door.

Sunny
02-28-2002, 01:13 AM
Thanks. I found out it's a LOT more complicated than i thought.
I found some interesting documentation at he.net. BUt it's still very hard to check the drive status.

The ideal would be to know if it's ejected, closed or if there's a CD inside and all that.

Thanks a lot everybody!!!!



Stefano

VirtualAce
03-05-2002, 03:58 AM
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.



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


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


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).


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


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.


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.

Sunny
03-05-2002, 10:34 PM
Thanks a lot. It sure does help.

Stef