以汇编语言弹出CD /光驱

时间:2012-02-21 15:56:40

标签: assembly x86 nasm

这可能不会更简单,但不会动摇。

我有一个简单的代码,我正在使用它来查看光驱是否会弹出

代码采用汇编语言,即intel nasm语法。

[BITS 16]
[ORG 0X07C00]
STI

Eject:

mov ah, 46h
mov al, 00h
mov dl, 00h
int 13h

endprogram:
times 510-($-$$) db 0
db 0x55
db 0xAA

我可以简单地增加驱动器号,但如果驱动器为0,这不应该正常工作吗?可能是驱动开始大约128十进制

谢谢,

3 个答案:

答案 0 :(得分:2)

似乎没有任何标准化的BIOS中断从驱动器中弹出CD。所以,基本上,如果你想要这个功能,你还有很多工作要做。您需要编写ATA驱动程序并发送原始命令以强制CD驱动器弹出。

这比听起来要多得多。您必须检测ATA驱动器,将它们过滤到CD驱动器,然后发送命令。

您需要查看OSDev的ATA article及其ATAPI article

答案 1 :(得分:0)

尝试48h功能以获取驱动器参数。看看你得到了什么。可能是一个不同的驱动器号码。或者,您的特定BIOS中的驱动器类型可能不支持此扩展功能。

答案 2 :(得分:0)

您可以尝试发布while back online

的代码
.386
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE

INCLUDE windows.inc

INCLUDE kernel32.inc
INCLUDE winmm.inc
INCLUDE masm32.inc

INCLUDE c:\masm32\macros\macros.asm

INCLUDELIB kernel32.lib
INCLUDELIB winmm.lib
INCLUDELIB masm32.lib

.DATA

   szDriveLetter BYTE "R:", 0

.DATA?

   szBuffer      BYTE 256 DUP(?)

.CODE

start:

 ; to close
   INVOKE lstrcat, ADDR szBuffer, SADD("open ")
   INVOKE lstrcat, ADDR szBuffer, ADDR szDriveLetter
   INVOKE lstrcat, ADDR szBuffer, SADD(" type cdaudio alias CDName")
   INVOKE mciSendString, ADDR szBuffer, NULL, 0, 0
   .IF eax != 0
       push eax
       INVOKE StdOut, SADD("Error",13,10)
       pop eax
       jmp done
   .ENDIF
   INVOKE mciSendString, SADD("set CDName door closed"), NULL, 0, 0
   .IF eax != 0
       push eax
       INVOKE StdOut, SADD("Error",13,10)
       pop eax
       jmp done
   .ENDIF    
   INVOKE mciSendString, SADD("close CDName"), NULL, 0, 0                          
   .IF eax != 0
       push eax
       INVOKE StdOut, SADD("Error",13,10)
       pop eax
       jmp done
   .ENDIF  

   mov eax, 0

 done:  

   INVOKE ExitProcess, eax

END start 

the simpler FASM version(这曾是内置示例之一)。

; Beer - example of tiny (one section) Win32 program

format PE GUI 4.0

include 'win32a.inc'

; no section defined - fasm will automatically create .flat section for both
; code and data, and set entry point at the beginning of this section

invoke MessageBoxA,0,_message,_caption,MB_ICONQUESTION+MB_YESNO
cmp eax,IDYES
jne exit

invoke mciSendString,_cmd_open,0,0,0
invoke mciSendString,_cmd_eject,0,0,0
invoke mciSendString,_cmd_close,0,0,0

exit:
invoke ExitProcess,0

_message db 'Do you need additional place for the beer?',0
_caption db 'Desktop configuration',0

_cmd_open db 'open cdaudio',0
_cmd_eject db 'set cdaudio door open',0
_cmd_close db 'close cdaudio',0

; import data in the same section

data import

library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL',\
winmm,'WINMM.DLL'

import kernel32,\
ExitProcess,'ExitProcess'

import user32,\
MessageBoxA,'MessageBoxA'

import winmm,\
mciSendString,'mciSendStringA'

end data