Category : Modula II Source Code
Archive   : CRC-M2.ZIP
Filename : CRC.MOD

 
Output of file : CRC.MOD contained in archive : CRC-M2.ZIP
MODULE CRC;

IMPORT SYSTEM, FIO, Lib, Str;
IMPORT CRCalc;

CONST
ReadOnly = 0; (* file attributes *)
Hidden = 1;
System = 2;
Volume = 3;
Directory = 4;
Archive = 5;

cr = CHR(13);
lf = CHR(10);

BufSize = (512 * 2) * 10;
MaxPath = 79;

TYPE PathName = ARRAY [0..MaxPath] OF CHAR;

PROCEDURE WrChar(ch: CHAR);
VAR r: SYSTEM.Registers;
BEGIN
r.AH := 02H; (* Character Output *)
r.DL := SHORTCARD(ch);
Lib.Dos(r)
END WrChar;

PROCEDURE WrStr(s: ARRAY OF CHAR);
VAR i: CARDINAL;
BEGIN
i := 0;
WHILE s[i] # 0C DO
WrChar(s[i]);
INC(i)
END
END WrStr;

PROCEDURE ReadFirstEntry(filename: ARRAY OF CHAR;
attr: FIO.FileAttr;
VAR D: FIO.DirEntry): BOOLEAN;
VAR r: SYSTEM.Registers;
BEGIN
WITH r DO
AH := 1AH; (* Set Disk Transfer Address (DTA) *)
DS := SYSTEM.Seg(D); (* Address of DTA *)
DX := SYSTEM.Ofs(D);
Lib.Dos(r);

AH := 4EH; (* Find First Matching File (FIND FIRST) *)
CL := SHORTCARD(attr);
DS := SYSTEM.Seg(filename);
DX := SYSTEM.Ofs(filename);
Lib.Dos(r);
IF SYSTEM.CarryFlag IN Flags THEN
WrStr(filename);
WrStr(": Cannot open");
WrChar(cr);
WrChar(lf);
RETURN FALSE
ELSE RETURN TRUE
END
END
END ReadFirstEntry;

PROCEDURE ReadNextEntry(VAR D: FIO.DirEntry): BOOLEAN;
VAR r: SYSTEM.Registers;
BEGIN
WITH r DO
AH := 1AH; (* Set Disk Transfer Address (DTA) *)
DS := SYSTEM.Seg(D); (* Address of DTA *)
DX := SYSTEM.Ofs(D);
Lib.Dos(r);

AH := 4FH; (* Find Next Matching File (FIND NEXT) *)
Lib.Dos(r);
IF SYSTEM.CarryFlag IN Flags THEN
RETURN FALSE
ELSE RETURN TRUE
END
END
END ReadNextEntry;

PROCEDURE Open(filename: ARRAY OF CHAR): FIO.File;
VAR r: SYSTEM.Registers;
BEGIN
WITH r DO
AH := 3DH; (* Open a File *)
AL := 00H; (* Read-only access *)
DS := SYSTEM.Seg(filename);
DX := SYSTEM.Ofs(filename);
Lib.Dos(r);
RETURN AX
END
END Open;

PROCEDURE Close(F: FIO.File);
VAR r: SYSTEM.Registers;
BEGIN
WITH r DO
AH := 3EH; (* Close a File Handle *)
BX := F;
Lib.Dos(r)
END
END Close;

PROCEDURE RdBin(F: FIO.File;
VAR buf: ARRAY OF BYTE;
Count: CARDINAL) : CARDINAL;
VAR r: SYSTEM.Registers;
BEGIN
WITH r DO
AH := 3FH; (* Read from File or Device, Using Handle *)
BX := F; (* File handle *)
CX := Count; (* Number of bytes to read *)
DS := SYSTEM.Seg(buf); (* Address of buffer *)
DX := SYSTEM.Ofs(buf);
Lib.Dos(r);
IF SYSTEM.CarryFlag IN Flags THEN
AX := 0
END;
RETURN AX
END
END RdBin;

PROCEDURE GetPath(VAR s: ARRAY OF CHAR);
CONST StopChars = Str.CHARSET{':', '\'};
VAR i: INTEGER;
BEGIN
i := Str.Length(s)-1;
WHILE i >= 0 DO
IF s[i] IN StopChars THEN RETURN END;
s[i] := 0C;
DEC(i)
END
END GetPath;

PROCEDURE WriteHex(v: CARDINAL);
CONST HexArray = "0123456789ABCDEF";
BEGIN
WrChar( HexArray[ v DIV 1000H MOD 10H ] );
WrChar( HexArray[ v DIV 100H MOD 10H ] );
WrChar( HexArray[ v DIV 10H MOD 10H ] );
WrChar( HexArray[ v MOD 10H ] )
END WriteHex;

PROCEDURE Process(path, name: ARRAY OF CHAR);
VAR F: FIO.File;
bytesRead, crc16: CARDINAL;
buf: ARRAY [0..BufSize-1] OF CHAR;
BEGIN
Str.Append(path, name);
WrStr(path);
WrStr(": ");
F := Open(path);
crc16 := 0;

REPEAT
bytesRead := RdBin(F, buf, BufSize);
CRCalc.crcme(buf, bytesRead, crc16)
UNTIL bytesRead # BufSize;

Close(F);
WrStr("CRC=");
WriteHex(crc16);
WrChar(cr);
WrChar(lf)
END Process;

CONST Attr = {Hidden, System};

VAR numParams: CARDINAL;
str: PathName;
i: CARDINAL;
D: FIO.DirEntry;

BEGIN
numParams := Lib.ParamCount();
FOR i := 1 TO numParams DO
Lib.ParamStr(str, i);
IF ReadFirstEntry(str, FIO.FileAttr(Attr), D) THEN
GetPath(str);
REPEAT
Process(str, D.Name)
UNTIL ~ReadNextEntry(D)
END
END
END CRC.


  3 Responses to “Category : Modula II Source Code
Archive   : CRC-M2.ZIP
Filename : CRC.MOD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/