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

📄 ata_atapi32.inc

📁 TestOS - 带简单GUI的DOS扩展OS// 源代码// ASM// 英文
💻 INC
字号:
;=========================================================;
; Ata_Atapi32                                    11/12/03 ;
;---------------------------------------------------------;
; DOS EXTREME OS V0.01                                    ;
; by Craig Bamford.                                       ;
;                                                         ;
; ATA/ATAPI functions.                                    ;                          
;=========================================================;

 Atapi_Packet_Command  = 0xA0 ; *M

 ;----------------------------------------------------;
 ; GetAtaPiDrive      ; Gets the Ata/Atapi drive info ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          none.                                     ;
 ;  Output:                                           ;
 ;          Puts drive info in vals:                  ;
 ;                                             (100%) ;
 ;....................................................;


 ;----------------------------------------------------;
 ; Send Atapi Packet                                  ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          esi, points to 12 byte packet.            ;
 ;  Output:                                           ;
 ;          none                                      ;
 ;                                             (100%) ;
 ;....................................................;
Send_Atapi_Packet:
             
        mov   dx,0x7                                    ; Read Status = 7
        add   dx,word [port]                            ; Add the base
        mov   cx,0xffff                                 ; Mov cx, number of loops
StatusReg1_1:                                  
        in    al,dx                                     ; Mov data from port to al
        and   al,0x80                                   ; Check bit 7(busy bit) ,loop if not 0
        jz    WriteCommand1_1                           ; Jump to WriteCommand1_1 if al bit7 =0
        loop  StatusReg1_1                              ; If al bit 7 =1,loop StatusReg1_1
        jmp   DeviceBusy_1                              ; time out:-(
WriteCommand1_1:                               
        mov   dx,0x6                                    ; Write Drivehead register = 6        
        add   dx,word [port]                            ; Add to base
        mov   al,byte [drive]                           ; Bit 4 ,0 to select primary drive, 1 to select secondary drive
        or    al,0xef                                   ; What is bit 4 ?
        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
StatusReg2_1:                                  
        in    al,dx                                     ; Mov data from port to al
        and   al,0x80                                   ; Check bit 7(busy bit) ,loop if not 0
        jz    WriteCommand2_1                           ; Jump to WriteCommand2_1 if al bit7 =0
        loop  StatusReg2_1                              ; If al bit 7 =1,loop StatusReg2_1
DeviceBusy_1:                                           ; time out:-(
        stc                                             ; Set the carry flag to 1
        ret                                   

 ;----------------------------------------------------;
 ; 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   ecx,ecx                                     ; 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
;----------------------------------
mov   dx,0x7                                    ; Read status = 7 
        add   dx,word [port]   
in al,dx
;----------------------------------
                
        clc                                             ; Clear the carry flag
        ret

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

DrqErrorCheck2_1:                             
        push  ecx                                        ; Save old cx
        mov   ecx,0xf                                 ; 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   ecx                                        ; Get old cx
        loop  StatusReg4_1                              ; Loop label
        jmp   DeviceBusy_1                              ; Time out
error_1:
        stc  
;----------------------------------
mov   dx,0x7                                    ; Read status = 7 
        add   dx,word [port]   
in al,dx
;----------------------------------                                           ; Set the carry flag to 1
                                            
        ret

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

Play_cd:
        push  edi

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

        pop   edi

        ret   

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

Clear_atapi_packet:
        push  edi
        pushad
        mov  ax,linear_sel
	mov  es,ax
        cld
        cli
        
        mov   edi,packet
        xor   ecx,ecx
        mov   cx,12
        xor   al,al
                
        rep   stosb
        sti      
        popad
        pop   edi

        ret

 ;----------------------------------------------------;
 ; Stop cd                                            ;
 ;----------------------------------------------------;
Stop_cd:
        push  edi

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

        pop   edi

        ret   

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

Pause_cd:
        push  edi

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

        pop   edi

        ret   

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

Start_cd:
        push  edi

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

        pop   edi

        ret   


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

Eject_cd:
        push  edi
        pushad
       
        call  Clear_atapi_packet
        
        mov   byte[packet+4],0x2
        mov   byte[packet+1],0x1
        mov   byte[packet+0],0x1b
                
        call  Send_Atapi_Packet
        popad
        pop   edi

        ret   

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

Close_cd:
        push  edi
        pushad
        call  Clear_atapi_packet
       
       
        mov   byte[packet+0],0x1b 
        
        mov   byte[packet+1],0x1
       
        mov   byte[packet+4],0x3
                
        call  Send_Atapi_Packet
        popad
        pop   edi

        ret 
  

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




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


              

⌨️ 快捷键说明

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