home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_05 / 2n05018a < prev    next >
Text File  |  1991-03-27  |  4KB  |  156 lines

  1.  
  2. program access_CD;
  3.  var
  4.   buf: Ptr            (* dummy area to read data into *)
  5.   IOErr: integer;     (* return from I/O functions *)
  6.   refnum: integer;
  7.   startTime: longint; (* timer variables, accurate to 1/60 second *)
  8.   endTime: longint;
  9.   count: longint;     (* number of bytes to read or write *)
  10.   picsize: longint;   (* number of bytes in an "image" *)
  11.   sndsize: longint;   (* number of bytes in a "sound" *)
  12.   wrdsize:longint;    (* number of bytes in "text" *)
  13.   i: integer;         (* ubiquitous counter variable *)
  14.   s: string;          (* get user input here *)
  15.  
  16.  procedure checkIO;   (* did I/O come out OK? *)
  17.  begin
  18.   if (IOErr <> 0) then
  19.    begin
  20.     writeln('IOErr = ', IOErr);
  21.     halt;
  22.    end;
  23.  end;
  24.  
  25.  procedure separate;  (* access CD as though data is separated *)
  26.   var
  27.    i: integer;
  28.  begin
  29.  
  30.   (* This first read will start CD spinning if it's quiescent *)
  31.   IOErr := SetFPos(refnum, fsFromStart, 0);
  32.   count := 1024;
  33.   IOErr := FSRead(refnum, count, buf);
  34.   checkIO;
  35.  
  36.   (* Start the timer *)
  37.   startTime := TickCount;
  38.   for i := 0 to 9 do
  39.    begin
  40.     IOErr := SetFPos(refnum, fsFromStart, picsize * i);
  41.     checkIO;
  42.  
  43.     count := picsize;
  44.     IOErr := FSRead(refnum, count, buf);
  45.     checkIO;
  46.  
  47.     (* reposition past the pictures, into the sound area *)
  48.     IOErr := SetFPos(refnum, fsFromStart, 10 * picsize + sndsize * i);
  49.     checkIO;
  50.  
  51.     count := sndsize;
  52.     IOErr := FSRead(refnum, count, buf);
  53.     checkIO;
  54.  
  55.     (* reposition past the sounds, into the text area *)
  56.     IOErr := SetFPos(refnum, fsFromStart, 10 * (picsize + sndsize)
  57.         + wrdsize * i);
  58.     checkIO;
  59.  
  60.     count := wrdsize;
  61.     IOErr := FSRead(refnum, count, buf);
  62.     checkio;
  63.    end;
  64.  
  65.   endTime := TickCount - startTime;
  66.   writeln('Separate data areas: ');
  67.   writeln('Total time=', endTime / 60 : 9 : 4);
  68.  end;
  69.  
  70.  procedure adjacent;  (* access CD as though data is adjacent *)
  71.   var
  72.    i: integer;
  73.  
  74.  begin
  75.   (* This first read will start CD spinning if it's quiescent *)
  76.   IOErr := SetFPos(refnum, fsFromStart, 0);
  77.   checkio;
  78.  
  79.   count := 1024;
  80.   IOErr := FSRead(refnum, count, buf);
  81.   checkio;
  82.  
  83.   startTime := TickCount;
  84.   for i := 0 to 9 do
  85.  
  86.    begin
  87.     (* position to the area where combined data begins *)
  88.  
  89.     IOErr := SetFPos(refnum, fsFromStart, 
  90.        (picsize + wrdsize + sndsize) * i);
  91.     checkIO;
  92.  
  93.  
  94.     count := picsize;
  95.     IOErr := FSRead(refnum, count, buf);
  96.     checkio;
  97.  
  98.     count := sndsize;
  99.     IOErr := FSRead(refnum, count, buf);
  100.     checkio;
  101.  
  102.     count := wrdsize;
  103.     IOErr := FSRead(refnum, count, buf);
  104.     checkio;
  105.  
  106.    end;
  107.   endTime := TickCount - startTime;
  108.   writeln('Adjacent areas:');
  109.   writeln('Total time=', endTime / 60 : 9 : 4);
  110.  end;
  111.  
  112. begin
  113.  
  114. (* The file named below was one that was big enough to not *)
  115. (* cause positioning errors *)
  116.  
  117.  ioerr := FSOpen('AVCM90AA:AIRC.NDX;1', 0, refnum);
  118.  if (ioerr <> 0) then
  119.   begin
  120.    IOErr := FSClose(refnum);
  121.    halt;
  122.   end;
  123.  
  124.  count := 200;
  125.  count := (count * 1024);  (* gives 200K without overflow *)
  126.  sndsize := count;
  127.  picsize := 65536;
  128.  wrdsize := 32768;
  129.  
  130. (* allocate area to read dummy data into *)
  131.  buf := NewPtr(count + picsize + wrdsize);
  132.  if (buf = nil) then
  133.   halt;
  134.  
  135.  ShowText;
  136.  
  137.  (* Give user a choice of which test to run first; *)
  138.  (* this way we can cancel out possible vagaries of *)
  139.  (* system caching [which was not enabled during this test] *)
  140.  write('Look at CD as separate areas first? (Y/N/Quit) ');
  141.  readln(s);
  142.  if (s = 'y') or (s = 'Y') then
  143.   begin
  144.    separate;
  145.    adjacent;
  146.   end
  147.  else if (s = 'n') or (s = 'N') then
  148.   begin
  149.    adjacent;
  150.    separate;
  151.   end;
  152.  IOErr := FSClose(refnum);
  153. end.
  154.  
  155.  
  156.