Eject CD/Optical Drive in Assembly Language

流过昼夜 提交于 2020-01-11 10:22:31

问题


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,


回答1:


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




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/9380667/eject-cd-optical-drive-in-assembly-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!