用汇编语言弹出 CD/光驱

发布于 2025-01-07 08:00:32 字数 320 浏览 2 评论 0原文

这再简单不过了,但并没有改变。

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

该代码采用汇编语言,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 左右开始,

谢谢,

This couldn't have been simpler, but isn't budging.

I have a simple code that I'm using to see if the optical drive will eject

The code is in assembly language, intel nasm syntax.

[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

I could simply increase the drive number, but shouldn't this work correctly if the drive was 0? may be the drive start somewhere around 128 decimal

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

似狗非友 2025-01-14 08:00:32

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

但这需要做的事情比听起来要多得多。您必须检测 ATA 驱动器,将其过滤到 CD 驱动器,然后发送命令。

您需要查看 OSDev 的 ATA 文章 及其 ATAPI 文章

There does not appear to be any standardized BIOS interrupt to eject a CD from a drive. So, basically, you have a lot of work to do if you want this feature. You'll need to write an ATA driver and send out the raw commands to force the CD drive to eject.

This entails a lot more than it sounds though. You have to detect the ATA drives, filter them out to the CD drive, and then send the command.

You'll need to check out OSDev's ATA article and their ATAPI article

笑脸一如从前 2025-01-14 08:00:32

尝试使用函数 48h 获取驱动器参数。看看你会得到什么。可能是不同的驱动器号。或者,对于您的特定 BIOS 中的驱动器类型,此扩展功能可能不可用/不支持。

Try function 48h to get drive parameters. See what you get. Might well be a different drive number. Or, this extended function may not be available/supported for your drive types in your particular BIOS.

荒芜了季节 2025-01-14 08:00:32

您可以尝试重新上线时发布的代码:

.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 

或者更简单的 FASM 版本(这曾经是内置示例之一)。

; 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

You can try this code that was posted a 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 

Or the simpler FASM version (This used to be one of the built in examples ).

; 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文