(* D64DUMP.PAS -- simple disk image viewer
** Copyright (c) 1995,1996 Jochen Metzinger
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2, or (at your option)
** any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*)

PROGRAM D64dump;

USES global, errors, d64, dump;

VAR
 tr: INTEGER;
 sk: BYTE;
 sector: BLOCK;

PROCEDURE usage;
BEGIN
 WriteLn('D64DUMP  Version 0.3  View disk images');
 WriteLn('Copyright (c) 1995,1996 Jochen Metzinger ');
 WriteLn;
 WriteLn(short_usage);
 WriteLn;
 WriteLn('  image       disk image');
 HALT(1);
END; (* usage *)

PROCEDURE Init;
 VAR i, j: WORD; par: STRING;
  in_name: STRING;
BEGIN
 short_usage := 'D64DUMP [/?] image';
 in_name := '';
 IF ParamCount = 0 THEN
  usage;
 FOR i := 1 TO ParamCount DO BEGIN
  par := ParamStr(i);
  IF (par[1] = '/') OR (par[1] = '-') THEN
   BEGIN
    IF Length(par) = 1 THEN
     FATAL('unknown option '+par);
    FOR j := 2 TO Length(par) DO
     CASE UpCase(par[j]) OF
      '?', 'H': usage;
      ELSE FATAL('unknown option '+par);
     END; (* case *)
   END
  ELSE IF in_name = '' THEN
   in_name := AddExt(par, '.D64')
 END; (* for *)
 IF in_name = '' THEN usage;
 d64_open(in_name);
 err_stop;
 Write(in_name,' [15');
 IF d64_double_sided THEN Write('7') ELSE Write('4');
 Write('1 mode]');
 IF d64_read_only THEN Write(' RO');
 WriteLn;
 short_usage := '';
END; (* init *)

BEGIN
 Init;
 sector[0] := 18;
 sector[1] :=  0;
 REPEAT
  Write(' TR SK :');
  Read(tr);
  IF tr < 0 THEN
   BEGIN (* exit *)
    d64_close;
    EXIT;
   END
  ELSE IF tr = 0 THEN
   BEGIN (* next *)
    ReadLn;
    tr := sector[0];
    sk := sector[1];
   END
  ELSE
   ReadLn(sk);
  d64_read(tr,sk,sector);
  IF is_err
   THEN err_recover
   ELSE DumpVar(sector,256,0)
 UNTIL FALSE;
END. (* D64dump *)
