Du bist hier: Snippet-Verzeichnis » DOS (8)
Sprache:

Reading CDs with DOS

Sprache: English
Programmiersprache: Pascal
Veröffentlicht von: cinek [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 989


Beschreibung

This Pascal source shows how toread out mode1-CDs with DOS.In most cases you have to changethe source to get it to work.

Code

1 uses ATAPI; 2 3 const IDEPORT_DATA=0; 4 HALT_ERROR=$FF; 5 ImageFileName='C:\TEMP\CDIMAGE.DAT'; 6 7 type PCDMode=^TCDMode; 8 TCDMode=record 9 Header:TModeParametersHeader; 10 PSPageCode:byte; {PS bit 7} 11 {PageCode bits 0-6} 12 PageLength:byte; {=$32} 13 TestFlagWriteType:byte; {TestFlag bit 4} 14 {Write type bits 0-3} 15 MSFPCopyTrackMode:byte; {MS (Multisession) bits 6-7} 16 {FP bit 5} 17 {Copy bit 4} 18 {Track mode bits 0-3} 19 DataBlockType:byte; {bits 0-3} 20 Reserved1:array[1..2] of byte; 21 HostApplicationCode:byte; {bits 0-5} 22 SessionFormat:byte; 23 Reserved2:byte; 24 PacketSize:longint; 25 AudioPauseLength:word; 26 MCVAL:byte; {bit 7} 27 MediaCatalogNumber:array[1..13] of byte; 28 ZeroMC:byte; 29 AFRAMEMC:byte; {=$00} 30 TCVAL:byte; {bit 7} 31 CountryCode:byte; 32 InternationalStandardRecordingCode:byte; 33 OwnerCode:array[1..3] of byte; 34 YearOfRecording:word; 35 SerialNumber:array[1..5] of byte; 36 ZeroTC:byte; 37 AFRAMETC:byte; 38 Reserved3:byte; 39 SubHeader:array[0..3] of byte; 40 41 end; 42 var Dev:PATAPIDevice; 43 TOC:PTOC; 44 Size,a,b,Error:word; 45 StartRead,ReadBlocks,WriteBlocks,StartWrite:longint; 46 Data:PWordArray; 47 imagef,f:file; 48 SubC:pointer; 49 begin 50 Dev:=New(PATAPIDevice,Init(DRV_MASTER,1,RESET_DRIVE)); 51 52 Dev^.TestUnitReady; 53 54 writeln('Reading TOC.'); 55 Dev^.ReadTOC(TOC,Size); 56 57 58 { if (TOC^.FirstTrack<>TOC^.LastTrack)or(TOC^.FirstTrack<>1)or 59 (Dev^.GetError>0) then 60 begin 61 writeln('Error occured while reading TOC.'); 62 writeln('CD is empty, damaged or recorded with multiple tracks.'); 63 FreeMem(TOC,Size); 64 Dispose(Dev,Done); 65 Halt(HALT_ERROR); 66 end;} 67 for a:=0 to 255 do if TOC^.Entry[a].TrackNr=1 then Break; 68 if a=255 then 69 begin 70 writeln('Error occured while analysing TOC.'); 71 writeln('CD is possibly damaged.'); 72 FreeMem(TOC,Size); 73 Dispose(Dev,Done); 74 Halt(HALT_ERROR); 75 end; 76 StartRead:=BigEndianLongint(TOC^.Entry[a].LBA); 77 for a:=0 to 255 do if TOC^.Entry[a].TrackNr=$AA then Break; 78 if a=255 then 79 begin 80 writeln('Error occured while analysing TOC.'); 81 writeln('CD is possibly damaged.'); 82 FreeMem(TOC,Size); 83 Dispose(Dev,Done); 84 Halt(HALT_ERROR); 85 end; 86 ReadBlocks:=BigEndianLongint(TOC^.Entry[a].LBA)-StartRead; 87 Freemem(TOC,Size); 88 WriteBlocks:=0; 89 Getmem(Data,16*MAX_CDDATABLOCK); 90 Assign(imagef,ImageFileName); 91 Rewrite(imagef,1); 92 writeln('TOC analysed.'); 93 writeln('Reading CD ...'); 94 95 96 while (ReadBlocks>0) do 97 begin 98 Size:=0; 99 for a:=0 to 15 do 100 begin 101 Error:=5; 102 repeat 103 Dev^.ReadCDInit(SECTYPE_MODE1,StartRead,1,RCDF_USERDATA,RCDSC_NOSUBCHDATA,MAX_CDDATABLOCK); 104 Dec(Error); 105 until (((Dev^.GetStatus and AST_CHECK)=0)or(Error=0)) 106 and(Dev^.GetByteCount=MAX_CDDATABLOCK); 107 if Error=0 then 108 begin 109 writeln('Error: ',StartRead); 110 end else 111 begin 112 Inc(WriteBlocks); 113 while (Dev^.GetInterruptReason and AIR_IO)=0 do; 114 while (Dev^.GetStatus and AST_BSY)>0 do; 115 116 for b:=0 to (Pred(MAX_CDDATABLOCK) shr 1) do 117 Data^[a*(MAX_CDDATABLOCK shr 1)+b]:=Portw[Dev^.ATAPIPort+IDEPORT_DATA]; 118 end; 119 Dec(ReadBlocks); 120 Inc(StartRead); 121 Inc(Size); 122 if (ReadBlocks=0) then Break; 123 end; 124 BlockWrite(imagef,Data^,Size*MAX_CDDATABLOCK); 125 write('Blocks left: ',ReadBlocks,' ',#13); 126 end; 127 writeln(#10,'Reading done.');; 128 Close(imagef); 129 Freemem(Data,16*MAX_CDDATABLOCK); 130 Dispose(Dev,Done); 131 end. 132

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS