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

📄 ata_atapi3.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
        sti
StatusReg1:                                  
        in    al,dx
         test   al,0x80 
    
        jz    WriteCommand1      ;jz   
        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]
        mov   cx,0x100
        mov   edi,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  cx
        mov   cx,0x0ffff
BusyDelay3a:                                  
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        loop  BusyDelay3a
        pop   cx
        
        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 + -