⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cd1.asm

📁 TestOS - 带简单GUI的DOS扩展OS// 源代码// ASM// 英文
💻 ASM
📖 第 1 页 / 共 2 页
字号:
 ; Write Command                                      ;
 ;----------------------------------------------------; 

WriteCommand2_1:                               
        mov   dx,0x7                                    ; Write Command = 7          
        add   dx,word [port]                            ; Add base
        mov   al,byte [command]                         ; Add the 8 bit code to al
        out   dx,al                                     ; Write al to port (register)
        mov   cx,0xffff                                 ; Mov cx, number of loops
        mov   dx,0x7                                    ; Read status = 7
        add   dx,word [port]                            ; Add the base
StatusReg3_1:                                 
        in    al,dx                                     ; Mov data from port to al
        test  al,0x80                                   ; Does bit 7 = 0 (busy bit)
        jnz   DrqErrorCheck1_1                          ; Jump to "DrqErrorCheck1_1" if bit7 is 1
        test  al,0x01                                   ; Does bit 0 = 0 (error bit)
        jnz   error_1                                   ; Jump to "error_1" if bit0 is 1      
        test  al,0x08                                   ; Does bit3 = 0 (DRQ bit)
        jnz   WriteCommandPacket1_1                     ; Jump to label if bit3 is 1,we can transfer data to port:-) 
DrqErrorCheck1_1:                              
        loop  StatusReg3_1                              ; Loop label
        jmp   DeviceBusy_1                              ; Time out:-(
 ;----------------------------------------------------;
 ; Write Command Packet                               ;
 ;----------------------------------------------------; 

WriteCommandPacket1_1:                         
        mov   dx,0x0                                    ; Read date/write = 0              
        add   dx,word [port]                            ; Add the base
        mov   si,packet                                 ; Point esi to how 12 byte packet
        xor   cx,cx                                     ; 0 cx  
        mov   cx,6                                      ; Mov number of words to mov into cx
WritePacket1_1:                                
        lodsw                                           ; Mov a word from packet to ax, inc esi 2
        out   dx,ax                                     ; Write ax to port (register)
        loop  WritePacket1_1                            ; Loop label

        mov   cx,0xffff                                 ; Mov cx, number of loops
        mov   dx,0x7                                    ; Read status = 7 
        add   dx,word [port]                            ; Add the base
StatusReg4_1:                                 
        in    al,dx                                     ; Mov data from port to al
        test  al,0x80                                   ; Does bit 7 = 0 (busy bit)
        jnz   DrqErrorCheck2_1                          ; Jump to "DrqErrorCheck2_1" if bit7 is 1
        test  al,0x1                                    ; Does bit 0 = 0 (error bit)
        jnz   error_1                                   ; Jump to "error_1" if bit0 is 1
                
        clc                                             ; Clear the carry flag
        ret

 ;----------------------------------------------------;
 ; Drq Error Check                                    ;
 ;----------------------------------------------------; 

DrqErrorCheck2_1:                             
        push  cx                                        ; Save old cx
        mov   cx,0xffff                                 ; Put 65535 in new cx
BusyDelay_1:                                            ; Label
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        nop                                             ; Do a null operation(xchg ax,ax)
        loop  BusyDelay_1                               ; Loop label
       
        pop   cx                                        ; Get old cx
        loop  StatusReg4_1                              ; Loop label
        jmp   DeviceBusy_1                              ; Time out
error_1:
        stc                                             ; Set the carry flag to 1
                                            
        ret



 ;----------------------------------------------------;
 ; Play cd                                            ;
 ;----------------------------------------------------;

Play_cd:
        push  di

        call  Clear_atapi_packet
        mov   di,packet
        mov   byte[es:di+8],0xff
        mov   byte[es:di+7],0xff
        mov   byte[es:di+5],0xff
        mov   byte[es:di+4],0xff
        mov   byte[es:di+3],0xff
        mov   byte[es:di+2],0xff
        mov   byte[es:di+0],0x45
        call  Send_Atapi_Packet

        pop   di

        ret   

 ;----------------------------------------------------;
 ; Clear atapi packet                                 ;
 ;----------------------------------------------------;

Clear_atapi_packet:
        push  di
        push  cx
        push  ax
        mov   di,packet
        mov   cx,12
        xor   al,al
                
        rep   stosb
               
        pop   ax
        pop   cx
        pop   di

        ret

 ;----------------------------------------------------;
 ; Stop cd                                            ;
 ;----------------------------------------------------;
Stop_cd:
        push  di

        call  Clear_atapi_packet
        mov   di,packet
        mov   byte[es:di+4],0x0
        mov   byte[es:di+1],0x1
        mov   byte[es:di+0],0x1b
                
        call  Send_Atapi_Packet

        pop   di

        ret   

 ;----------------------------------------------------;
 ; Pause cd                                           ;
 ;----------------------------------------------------;

Pause_cd:
        push  di

        call  Clear_atapi_packet
        mov   di,packet
                
        mov   byte[es:di+8],0x0               
        mov   byte[es:di+0],0x4b
                
        call  Send_Atapi_Packet

        pop   di

        ret   

 ;----------------------------------------------------;
 ; Start cd                                           ;
 ;----------------------------------------------------;

Start_cd:
        push  di

        call  Clear_atapi_packet
        mov   di,packet
        mov   byte[es:di+4],0x1
        mov   byte[es:di+1],0x1
        mov   byte[es:di+0],0x1b
                
        call  Send_Atapi_Packet

        pop   di

        ret   


 ;----------------------------------------------------;
 ; Eject cd                                           ;
 ;----------------------------------------------------;

Eject_cd:
        push  di

        call  Clear_atapi_packet
        mov   di,packet
        mov   byte[es:di+4],0x2
        mov   byte[es:di+1],0x1
        mov   byte[es:di+0],0x1b
                
        call  Send_Atapi_Packet

        pop   di

        ret   

 ;----------------------------------------------------;
 ; Close cd                                           ;
 ;----------------------------------------------------;

Close_cd:
        push  di

        call  Clear_atapi_packet
        mov   di,packet
        mov   byte[es:di+4],0x3
        mov   byte[es:di+1],0x1
        mov   byte[es:di+0],0x1b
                
        call  Send_Atapi_Packet

        pop   di

        ret 
  

 ;--------------------------------------------------------------------------------------------;
 ;                                           Data                                             ;
 ;--------------------------------------------------------------------------------------------;

include 'Atapi_info.inc'

command:         db 0
port:            dw 0
drive:           db 0
AtapiError       db 0
;ATAPIorNot      db 0  
Drive_num:       db 0

HdDrive1:        db 0
HdPort1:         dw 0

CdDrive1:        db 0
CdPort1:         dw 0


packet:
		db 0x0                     
		db 0x0                    
		db 0x0                     
		db 0x0                     
                db 0x0                    
		db 0x0                     
		db 0x0
		db 0x0                     
		db 0x0                    
		db 0x0
		db 0x0
		db 0x0

Temp_Buffer rw  256
              

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -