📄 ata_atapi38.inc
字号:
;=========================================================;
; Ata_Atapi32 11/12/03 ;
;---------------------------------------------------------;
; DOS EXTREME OS V0.01 ;
; by Craig Bamford. ;
; ;
; ATA/ATAPI functions. ;
;=========================================================;
Atapi_Packet_Command = 0xA0 ; *M
;----------------------------------------------------;
; Send Atapi Packet ;
;----------------------------------------------------;
; ;
; Input: ;
; esi, points to 12 byte command packet. ;
; Output: ;
; none ;
; (100%) ;
;....................................................;
Send_Atapi_Packet:
pushad ; Save some 32bit regs
xor al,al ; Move al,0
mov dx,1 ; Move DX 1(FEATURE REG = 1)
add dx,word [port] ; Add the base
out dx,al ; Move data from al to port
mov al,1 ; Move 1 into al (SECTORCOUNT = 1)
mov dx,2 ; Move DX 2 (SECTCOUNT REG =2)
add dx,word [port] ; Add the base
out dx,al ; Move data from al to port
mov al,1 ; Move al 1 (START SECTOR = 1)
mov dx,3 ; Move DX 3 (SECOR REG =3)
add dx,word [port] ; Add the base
out dx,al ; Move data from al to port
xor al,al ; Move al,0
mov dx,4 ; Move DX 4 (CYLINDER-LO = 4)
add dx,word [port] ; Add the base
mov al,04 ; Move AL 04 (for lo-byte of number of tomove)
out dx,al ; Move data from al to port
xor al,al ; Move al,0
mov al,8 ; Move AL 8 (for hi-byte of number of tomove)
mov dx,5 ; Move DX 5 (CYLINDER-HI = 5)
add dx,word [port] ; Add the base
out dx,al ; Move data from al to port
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
jmp WriteCommand2_1
DeviceBusy_1: ; time out:-(
stc ; Set the carry flag to 1
popad
ret
;----------------------------------------------------;
; Write Command ;
;----------------------------------------------------;
WriteCommand2_1:
call Small_Delay1 ; May not be needed ?
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: ; Come on, get amove on:-(
loop StatusReg3_1 ; Loop label
jmp DeviceBusy_1 ; Time out:-(
;----------------------------------------------------;
; Write Command Packet ;
;----------------------------------------------------;
WriteCommandPacket1_1:
xor dx,dx
mov dx,0x00 ; Read date/write = 0
add dx,word [port] ; Add the base
mov esi,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
call Small_Delay1 ; May not be needed ?
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_11 ; Jump to "DrqErrorCheck2_1" if bit7 is 1(BSY BIT)
test al,0x1 ; Does bit 0 = 0 (error bit)
jnz error_1 ; Jump to "error_1" if bit0 is 1
test al, 08h ; DRQ bit
jnz Send_Packet_ok ; Jump if no error (please)
DrqErrorCheck2_11:
loop StatusReg4_1
stc ; Set the carry flag to 1
popad ; Get some old regs off stack
ret
Send_Packet_ok: ; Thank you!;-).
clc ; Clear the carry flag
popad ; Get some old regs off stack
ret
;----------------------------------------------------;
; Drq Error Check ;
;----------------------------------------------------;
DrqErrorCheck2_1:
push ecx ; Save old ecx
mov ecx,0xffff ; Put 65535 in new ecx
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 ecx
loop StatusReg4_1 ; Loop label
jmp DeviceBusy_1 ; Time out
error_1:
popad
stc ; Set the carry flag to 1
ret
;----------------------------------------------------;
; Read write toc ;
;----------------------------------------------------;
; ;
; Input: ;
; edi, points to 804 byte buffer. ;
; Output: ;
; toc info ;
; (100%) ;
;....................................................;
Read_write_toc:
pushad ; Save some 32bit regs
push es ; Save es
mov ax,sys_data ; Move how data base,into ax
mov es,ax ; move ax into es
mov edi,TOC_Data_Buffer ; Point edi to how data buffer.
loc_Read_Data_reg_1b:
mov dx, 0 ; Read date/write = 0
add dx, word[port] ; Add the base
in ax,dx ; Mov data from port to ax
mov word[TOC_Data_Buffer],ax ; move ax,into data buffer.
xchg ah,al ; put whats in al in ah & what was in ah into al.
mov cx,ax ; move ax into cx
shr cx,1 ; 1/2 the number in cx
inc edi
inc edi ; inc edi by 2
loc_Read_Data_reg_1c:
in ax,dx ; Move data (word) from port to ax
stosw ; Move a word from ax into data buffer,inc edi by 2.
loop loc_Read_Data_reg_1c ; Loop untill cx = 0
mov dx,0x7 ; Read status = 7
add dx,word [port] ; Add the base
mov cx,0xffff ; Mov cx, number of loops
do_some_loops:
in al,dx ; Mov data from port to al
test al,0x80 ; Check bit 7(busy bit) ,loop if not 0
jnz do_some_loops_loops ; Jump to do_some_loops_loops if al bit7 =1
test al,0x1 ; Does bit 0 = 0 (error bit)
jnz error_readtoc ; Jump to "error_1" if bit0 is 1
clc ; Clear the carry flag
jmp read_toc_ok ; Goto ok exit lable
do_some_loops_loops: ; Lable
loop do_some_loops ; Loop if cx, not 0
error_readtoc:
stc ; Set the carry flag to 1
read_toc_ok:
pop es ; Get old es off stack
popad ; Get some old regs off stack
ret
;----------------------------------------------------;
; get the reg hex ;
;----------------------------------------------------;
get_the_reg_hex:
mov esi,TOC_Data_Buffer
add esi,4
add esi,2
add esi,8
xor ecx,ecx
mov cx,1
please:
lodsw
call write_hex32
loop please
ret
;----------------------------------------------------;
; Wait unit ready ;
;----------------------------------------------------;
Wait_unit_ready:
call Clear_atapi_packet
mov byte[packet+0],0x0
call Send_Atapi_Packet
Clear_status:
xor ecx,ecx
mov cx,0xffff
mov dx,0x7
add dx,word[port]
loc_read_status_reg_4w:
in al,dx
test al,0x80 ; BSY bit
jnz pass_drq_err_check_2w
test al,0x40
jz pass_drq_err_check_2w
test al,0x01
jnz loc_ata_ide_io_error_w
clc
jmp lets_go_by
pass_drq_err_check_2w:
loop loc_read_status_reg_4w
loc_ata_ide_io_error_w:
stc
lets_go_by:
ret
;----------------------------------------------------;
; Play cd ;
;----------------------------------------------------;
Play_cd:
call Small_Delay1
call Wait_unit_ready
call Small_Delay1
call Wait_unit_ready
jc Unit_not_ready_play
call Clear_atapi_packet
mov ax,10*60*75
mov byte[packet+8],al
mov byte[packet+7],ah
mov byte[packet+0],0x45
call Send_Atapi_Packet
mov esi, stringood
call print_string
ret
Unit_not_ready_play:
mov esi, stringbad
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -