在DOS编程中如何控制光驱的弹出,关闭及其获取其状态
编号:QA004723
建立日期: 2003年10月13日 最后修改日期:2003年10月13日
所属类别:
Q
南祠:
操作系统: dos
编程工具: 汇编
问题: 请问在DOS(汇编)编程中如何控制光驱的弹出,关闭及其获取其状态?
A回答:
下面的程序是通过调用MSCDEX来实现光驱的弹出、关闭。有关MSCDEX的更多内容,可以参考http://www.he.net/~marcj/cdrom.html。
; CDROM AA Copyright (c) Jannes Faber 1995
;
; You can contact me at : faber@fys.ruu.nl
; My www-page : http://www.fys.ruu.nl/~faber
;
; Improved by: edward beroset
;
; This little program Opens & Closes your CD-ROM drive at the DOS-prompt.
;
; Syntax: CDROM O or CDROM C
;
; I tried to make this COM-file as small as possible, so don't expect all
; that pretty on-line hyperhelptext in full color.
; It just opens or closes your drawer, or, if something isn't right, it
; prints 'Err' on your screen. See the CDROM.TXT file for more info if things
; do go wrong !
;
; If anyone could tell me how to detect whether the drive is currently open
; or closed, i'd really appreciate it if you'd tell me ! I also would like
; to hear from you if you succeeded in making the COM-file significantly
; smaller than 73 bytes (not by changing the error-message into 'E' !).
.MODEL TINY
.CODE
DOS_TTY_WRITE equ 009h ; TTY style write of '$' term string
DOS_OPEN_HANDLE equ 03dh ; open file with handle
DOS_IOCTL equ 044h ; write to handle
DOS_TERMINATE equ 04ch ; terminate with error code
DOSINT macro function, subfunction
IFB
mov ah,(function AND 0ffh)
ELSE
mov ax,(function SHL 8) OR (subfunction AND 0ffh)
ENDIF
int 21h ; invoke DOS function
endm
Org 5Dh
Params LABEL BYTE
.STARTUP
mov al, [Params]
or al, 00100000b ; Convert to lowercase
cmp al, 'o'
je OpenDev
cmp al, 'c'
jne ErrorHandler
mov [ControlBlock],5 ; Close CD-rom
OpenDev:
; Open Device using handle:
mov dx, offset FileName
DOSINT DOS_OPEN_HANDLE, 021h
jc ErrorHandler
mov bx, ax ; file handle into bx
mov cx, 1 ; number of bytes to write
dec dx ; point to control block
DOSINT DOS_IOCTL, 3 ; issue IOCTL request
jnc Einde
ErrorHandler:
mov dx, offset ShowErr ; display error
DOSINT DOS_TTY_WRITE
Einde:
DOSINT DOS_TERMINATE ; exit program
ShowErr DB 'Err$'
ControlBlock DB 0 ; preload with open command
FileName DB 'MSCD000 ', 0
END
此问题由李海回答。
附加关键字:编程, 源程序, programming, source code, 其他语言, asm, vba, vbscript, DDK与硬件设备, hardware, ddk, vtoolsd, driver studio, winrt。
| |
|
|
| |
|
|