home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
465.lha
/
Sparc2Amiga
/
Disk2File.mod
< prev
next >
Wrap
Text File
|
1991-01-09
|
6KB
|
217 lines
MODULE Disk2File;
FROM ASCII IMPORT nul, lf;
FROM Arts IMPORT Error, TermProcedure;
FROM SYSTEM IMPORT ADR, LONGSET, BYTE;
FROM Exec IMPORT IOStdReq, IOStdReqPtr, DoIO, MsgPort, MsgPortPtr,
OpenDevice, CloseDevice, IOFlagSet, read,
AllocMem, FreeMem, MemReqs, MemReqSet;
FROM ExecSupport IMPORT CreatePort, DeletePort, CreateExtIO, DeleteExtIO;
FROM TrackDisk IMPORT sector;
FROM Dos IMPORT Open, Close, Write, Output, FileHandlePtr, newFile;
FROM Arguments IMPORT NumArgs, GetArg;
FROM Conversions IMPORT ValToStr;
CONST Version = "Disk2File v2.0 (c) by jf (19.10.1990)";
Koepfe = 2;
maxSektoren = 11;
Tracks = 80;
trackLaenge = sector * maxSektoren;
TYPE tBuffer = ARRAY [0..trackLaenge-1] OF BYTE;
VAR DiskPort : MsgPortPtr;
DiskReq : IOStdReqPtr;
ChipMem,
error, Ok : BOOLEAN;
StdOut,
Datei : FileHandlePtr;
Drive, Len : LONGINT;
i, Sektoren,
TrackLaenge : LONGCARD;
l, n : INTEGER;
Attribut : MemReqSet;
Buffer : POINTER TO tBuffer;
Dummy,
trackDiskName,
FileName : ARRAY [0..40] OF CHAR;
PROCEDURE Fehler (error: INTEGER; Text: ARRAY OF CHAR);
BEGIN
(* wird von CleanUp erledigt
CASE error OF
| 0: FreeMem (Buffer, SIZE (tBuffer));
| 1: CloseDevice (DiskReq);
DeleteExtIO (DiskReq);
DeletePort (DiskPort);
FreeMem (Buffer, SIZE (tBuffer));
| 2: DeleteExtIO (DiskReq);
DeletePort (DiskPort);
FreeMem (Buffer, SIZE (tBuffer));
| 3: DeletePort (DiskPort);
FreeMem (Buffer, SIZE (tBuffer));
| 4:
| 5:
ELSE; END;
*)
Error (ADR ("Disk2File:"), ADR (Text));
END Fehler;
PROCEDURE CleanUp;
BEGIN
IF Buffer # NIL THEN
FreeMem (Buffer, SIZE (tBuffer)); END;
IF Datei # NIL THEN
Close (Datei); END;
IF DiskReq # NIL THEN
CloseDevice (DiskReq); END;
IF DiskReq # NIL THEN
DeleteExtIO (DiskReq); END;
IF DiskPort # NIL THEN
DeletePort (DiskPort); END;
END CleanUp;
PROCEDURE WriteLn;
VAR ch: CHAR;
l : LONGINT;
BEGIN
ch:= lf;
l:= Write (StdOut, ADR (ch), 1);
END WriteLn;
PROCEDURE WriteString (string: ARRAY OF CHAR);
VAR l, len: LONGINT;
BEGIN
l:= 0;
len:= HIGH (string);
WHILE (l < len) & (string [l] # nul) DO
INC (l); END;
IF (l = len) & (string [l] # nul) THEN
INC (l); END;
l:= Write (StdOut, ADR (string), l);
END WriteString;
PROCEDURE USAGE;
BEGIN
WriteString (Version);
WriteLn;
WriteString (" [Unit <0..3>] [Filename] [Device <0..1>]");
WriteLn;
WriteString (" default 0 DH2:T/Disk.tar 0");
WriteLn;
WriteString (" [Unit <0..3>] StdOut");
WriteLn;
WriteString (" Device 0 : messydisk.device 9 Sektoren");
WriteLn;
WriteString (" Device 1 : trackdisk.device 11 Sektoren");
WriteLn;
END USAGE;
PROCEDURE ReadTrack (Track: LONGCARD): BOOLEAN;
BEGIN
DiskReq^.command:= read;
DiskReq^.offset := Track * TrackLaenge;
DiskReq^.length := TrackLaenge;
DiskReq^.data:= Buffer;
DoIO (DiskReq);
IF DiskReq^.error = 0
THEN RETURN TRUE
ELSE RETURN FALSE; END;
END ReadTrack;
BEGIN
DiskPort:= NIL;
DiskReq := NIL;
Datei := NIL;
Buffer := NIL;
ChipMem := FALSE;
TermProcedure (ADR (CleanUp));
FileName:= "DH2:T/Disk.tar";
Drive := 0;
trackDiskName:= "messydisk.device";
Sektoren:= 9;
TrackLaenge:= sector * Sektoren;
StdOut:= Output ();
IF StdOut = NIL THEN
Fehler (0, "Kein StdOut!"); END;
n:= NumArgs ();
IF n >= 1 THEN
GetArg (1, Dummy, l);
IF l # 1 THEN
Fehler (4, "Falsches Laufwerk"); END;
CASE Dummy [0] OF
| "?" : USAGE;
RETURN;
| "0".."3": Drive:= LONGINT (Dummy [0]) - LONGINT ("0");
ELSE Fehler (4, "Falsches Laufwerk"); END; END;
IF n >= 2 THEN
GetArg (2, FileName, l); END;
IF n >= 3 THEN
GetArg (3, Dummy, l);
IF l # 1 THEN
Fehler (4, "Falsches Device"); END;
CASE Dummy [0] OF
| "0" : trackDiskName:= "messydisk.device";
Sektoren:= 9;
| "1" : trackDiskName:= "trackdisk.device";
Sektoren:= 11;
ChipMem := TRUE;
ELSE Fehler (4, "Falsches Device"); END; END;
TrackLaenge:= sector * Sektoren;
IF ChipMem
THEN Attribut:= MemReqSet {chip};
ELSE Attribut:= MemReqSet {public}; END;
Buffer:= AllocMem (SIZE (tBuffer), Attribut);
IF Buffer = NIL THEN
Fehler (4, "Zuwenig Speicherplatz!"); END;
DiskPort:= CreatePort (0, 0);
IF DiskPort = NIL THEN
Fehler (4, "Port läßt sich nicht öffnen!"); END;
DiskReq:= CreateExtIO (DiskPort, SIZE (IOStdReq));
IF DiskReq = NIL THEN
Fehler (3, "Request nicht zu erstellen!"); END;
OpenDevice (ADR (trackDiskName), Drive, DiskReq, LONGSET {} );
IF DiskReq^.error # 0 THEN
Fehler (2, "Device läßt sich nicht öffnen!"); END;
i:= 0;
IF n = 1
THEN Datei:= StdOut;
ELSE Datei:= Open (ADR (FileName), newFile);
IF Datei = NIL THEN
Fehler (1, "Datei nicht geöffnet !"); END; END;
REPEAT
Ok:= ReadTrack (i);
IF Ok THEN
Len:= Write (Datei, Buffer, TrackLaenge); END;
i:= i + 1;
UNTIL ~Ok;
IF n # 1 THEN
(* wird von CleanUp erledigt
Close (Datei);
*)
ValToStr (i-1, FALSE, Dummy, 10, -1, " ", error);
WriteString (Dummy);
WriteString (" Tracks übertragen");
WriteLn; END;
(* wird von CleanUp erledigt
FreeMem (Buffer, SIZE (tBuffer));
CloseDevice (DiskReq);
DeleteExtIO (DiskReq);
DeletePort (DiskPort);
*)
END Disk2File.mod