assemblyx86pascalcd-romata

Can not read CD using ATAPI


Here is my code. It fills ATAPI_RAWDATA array with 65535 in decimal. No Error codes. Secondary Error Register Port filled with 0. It does not halt and there is no cpu_triple_fault. When I remove Secondary Master CD device the procedure halts normaly. These loops in code for detecting BSY bit or something else. I tried EJECT procedure in real hardware so there is not any problem on that code but ATAPIREADSECTOR procedure not going fine. Is there any problem on READCD Command or something else?

var
READCD:array[0..5] of word($00BE,$0000,$0000,$0000,$0001,$0000);
ATAPI_RAWdata:array[0..1023] of word;
procedure ATAPI_READSECTOR(LBA:Integer;Dev:Byte);
var
i:integer;
x:word;
begin
asm
mov dx,177h
@loop1:
in al,dx
and al,10000000b
jne @loop1
mov dx,177h
@loop2:
in al,dx
and al,01000000b
je @loop2
mov dx,176h
mov al,0A0h
out dx,al
mov dx,3F6h
mov al,00001010b
out dx,al
mov dx,177h
mov al,0a0h
out dx,al
mov cx,0FFFFh
@waitloop:
loopnz @waitloop
mov dx,177h
@loop3:
in al,dx
and al,10000000b
jne @loop3
mov dx,177h
@loop4:
in al,dx
and al,00001000b
je @loop4
end;
for i:=0 to 5 do begin //SEND COMMAND
x:=READCD[i];
outw($170,x);
inb($376);
end;
inb($376);
asm
mov dx,177h
@loop5:
in al,dx
and al,10000000b
jne @loop5
end;
for i:=0 to 1023 do begin //INPUT DATA from DATA REGISTER
atapi_rawdata[i]:=inw($170);
end;
end;

My EJECT procedure works fine:

var
EJECT_COM:array [0..5] of Word=($001B,$0000,$0002,$0000,$0000,$0000);
procedure EJECT_CD;
var
i:integer;
x:word;
begin
asm
mov dx,177h
@loop1:
in al,dx
and al,10000000b
jne @loop1
mov dx,177h
@loop2:
in al,dx
and al,01000000b
je @loop2
mov dx,176h
mov al,0A0h
out dx,al
mov dx,3F6h
mov al,00001010b
out dx,al
mov dx,177h
mov al,0a0h
out dx,al
mov cx,0FFFFh
@waitloop:
loopnz @waitloop
mov dx,177h
@loop3:
in al,dx
and al,10000000b
jne @loop3
mov dx,177h
@loop4:
in al,dx
and al,00001000b
je @loop4
end;
for i:=0 to 5 do begin
x:=EJECT_COM[i];
outw($170,x);
inb($376);
end;
inb($376);
asm
mov dx,177h
@loop5:
in al,dx
and al,10000000b
jne @loop5
end;
end;

Solution

  • SCSI command READ CD $BE not using that structure so use READ 12 $A8 SCSI COMMAND instead of READ CD $BE:

    READCD:array[0..5] of word($00A8,$0000,$0000,$0000,$0001,$0000);