📄 cd1.asm
字号:
;=========================================================;
; 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]
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 cx
mov cx,0x0ffff
BusyDelay3a:
nop
nop
nop
nop
nop
nop
nop
nop
loop BusyDelay3a
pop cx
ret
;----------------------------------------------------;
; 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
;----------------------------------------------------;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -