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

📄 ata_atapi1.inc

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



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

GetAtaPiDrive:
        mov   byte [Drive_num],0                        ; 0 the variable called " Drive_num ".
        mov   byte [command],0xec                       ; Put the hex number for IDENTIFY DRIVE in the var "command".
drive_id:
        mov   word [port],0x1f0                         ; Try port 1f0 .
        mov   byte [drive],0x00                         ; Try master drive 0 (bit 5 should be 0).

        call  AtaPi_Id_Drive                            ; Call proc,if no error we have a ata/atapi address.
              
        mov   word [port],0x1f0                         ; Try port 1f0 .
        mov   byte [drive],0x10                         ; Try slave drive 1 (bit 5 should be 1,so we put 0x10 bin 10000b) .

        call  AtaPi_Id_Drive                            ; Call proc,if no error we have a ata/atapi address.
              
        mov   word [port],0x170                         ; Try port 170 .
        mov   byte [drive],0x00                         ; Try master drive 0 (bit 5 should be 0).
               
        call  AtaPi_Id_Drive                            ; Call proc,if no error we have a ata/atapi address.
            
        mov   word [port],0x170                         ; Try port 170 .
        mov   byte [drive],0x10                         ; Try slave drive 1 (bit 5 should be 1,so we put 0x10 bin 10000b) .
               
        call  AtaPi_Id_Drive                            ; Call proc,if no error we have a ata/atapi address.
               
        cmp  byte[command],0xA1                         ; Have we been here before, yes then lets go!
        je   Lets_go                       
                                     
        mov  byte[command],0xA1                         ; Put the hex number for ATAPI IDENTIFY DRIVE in the var "command".
        jmp  drive_id
             
Lets_go:
               
        ret


 ;----------------------------------------------------;
 ; AtaPi_Id_Drive                                     ;
 ;----------------------------------------------------;

AtaPi_Id_Drive:
         
        mov   dx,0x7
        add   dx,word [port]
        mov   cx,0xffff

StatusReg1:                                  
        in    al,dx
        and   al,0x80    
        jz    WriteCommand1         
        loop  StatusReg1
                
        jmp   DeviceBusy             
WriteCommand1:                               
        mov   dx,0x6         
        add   dx,word [port]
        mov   al,byte [drive]       
        or    al,0xef
        out   dx,al
        mov   cx,0xffff
        mov   dx,0x7
        add   dx,word [port] 
        
StatusReg2:                                  
        in    al,dx
        test  al,0x80           
        jz    Drdy_check                 
        loop  StatusReg2 

        jmp   DeviceBusy
Drdy_check:  
        test  al,0x40
        jnz   WriteCommand2
        cmp   byte[command],0xA1
        je    WriteCommand2 
                    
DeviceBusy:     

        ;stc
        ret
 ;----------------------------------------------------;
 ;  WriteCommand2                                     ;
 ;----------------------------------------------------;

WriteCommand2:                               
        mov   dx,0x7           
        add   dx,word [port]
        mov   al,byte [command]      
        out   dx,al
        mov   cx,0xffff
        mov   dx,0x7
        add   dx,word [port] 
       
StatusReg3: 
        in    al,dx 
        test  al,0x80
        jnz   DrqErrorCheck1         
        test  al,0x01
        jnz   error
        test  al,0x08 
        jnz   Read_data_reg_0    

        ;stc
        ret
 ;----------------------------------------------------;
 ; DrqErrorCheck                                      ;
 ;----------------------------------------------------;

DrqErrorCheck1:          
        push  cx
        mov   cx,0xFFFF
busy_delay123:
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        loop  busy_delay123

        pop   cx
        loop  StatusReg3

error:
       ; stc
        ret
 ;----------------------------------------------------;
 ; Read data reg              (& move it into buffer) ;
 ;----------------------------------------------------;

                  
Read_data_reg_0:                                                  
        mov   dx,0             
        add   dx,word [port]
        xor   ecx,ecx
        mov   cx,0x100
        mov   di,Temp_Buffer
                
Read_data_reg_1:
        in    ax,dx                                                        
        stosw
        loop  Read_data_reg_1             
 ;----------------------------------------------------;
 ; Label drive C                                      ;
 ;----------------------------------------------------;
        cmp   word[HdPort1],0
        jne   ItsAcd_1
        
        mov   dx,word [port]
        mov   word[HdPort1],dx

        mov   al,byte [drive]
        mov   byte[HdDrive1],al 
        jmp   Byby 
ItsAcd_1:
        cmp   word[CdPort1],0
        jne   Byby
        mov   dx,word [port]
        mov   word[CdPort1],dx

        mov   al,byte [drive]
        mov   byte[CdDrive1],al 
            
Byby:
       ; mov   al,[Drive_num] 
       ; mov   ah,0xe
	;int   0x10 
              
        clc
        ret


 ;----------------------------------------------------;
 ; Small Delay                                        ;
 ;----------------------------------------------------;

Small_Delay:
        push  ecx
        mov   ecx,0x0ffff
BusyDelay3a:                                  
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        loop  BusyDelay3a
        pop   ecx
        ret  
     
 ;----------------------------------------------------;
 ; Send Atapi Packet                                  ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          esi, points to 12 byte packet.            ;
 ;  Output:                                           ;
 ;          none                                      ;
 ;                                             (100%) ;
 ;....................................................;
Send_Atapi_Packet:
             
 c11:
  
              
                mov dx,0x177
                mov cx,0xffff
a11:
                in  al,dx
                and al,0x80
                jz   a1a
                loop a11
                jmp  a2
a1a:
                mov dx,0x176
                mov al,0x0
                or  al,0xef
                out dx,al
                mov cx,0xffff
                mov dx,0x177
a3:
                in al,dx
               and al,80h
                jz a4
                loop a3
a2:
                stc
                ret
a4:
                mov dx,0x177
                mov al,0xA0
                out dx, al
                mov cx,0xffff
                mov dx,0x177
a5:  
                in  al,dx
                test al,0x80
                jnz  a6
                test al,0x01
                jnz  error
                test al,0x08 ;
                jnz a7
a6:
                loop a5
                jmp  a2
a7:
                mov dx,0x170
                mov si,packet
                xor ecx,ecx
                mov cx,6
a8:
                lodsw
                out dx,ax
                loop a8

                mov cx,0xffff
                mov dx,0x177
a9:
                in al,dx
                test al,80h
                jnz  b3
                test al,01h
                jnz error3
;----------------------------------
 mov dx,0x177
in al,dx
;----------------------------------
                clc
                ret
b3:
                push ecx
                mov  ecx,0xffff
b1:
                nop
                nop
                nop
                nop
                nop
                nop
                nop
                nop
                loop  b1
       
                pop ecx
                loop a9
                jmp a2
error3:
                stc
               ; jmp c11
 ;----------------------------------
 mov dx,0x177
in al,dx
;----------------------------------
                ret

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

Play_cd:
        push  edi

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

        pop   edi

        ret   

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

Clear_atapi_packet:
        push  edi
        push  ecx
        push  eax
        mov   edi,packet
        mov   cx,12
        xor   al,al
                
        rep   stosb
               
        pop   eax
        pop   ecx
        pop   edi

        ret

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

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

        pop   edi

        ret   

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

Pause_cd:
        push  edi

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

        pop   edi

        ret   

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

Start_cd:
        push  edi

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

        pop   edi

        ret   


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

Eject_cd:
       ; push  edi

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

      ;  pop   edi

        ret   

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

Close_cd:
        push  edi

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

        pop   edi

        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 0x1b                     
		db 0x1                    
		db 0x0                     
		db 0x0                     
                db 0x2                    
		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 + -