Category : Modula II Source Code
Archive   : FIOASM.ZIP
Filename : NFIO.MOD

 
Output of file : NFIO.MOD contained in archive : FIOASM.ZIP
(*$M CODE*)(*$D DATA*)
(*$S-,R-,I-*)
IMPLEMENTATION MODULE NFIO;

(* A module for JPI Topspeed Modula-2 *)
(* By Carl Neiburger
169 N. 25th St.
San Jose, Calif.

CompuServe No. 72336,2257

This module is designed to implement the same functions as
JPI's FIO, but using the assembly-language procedures in FioAsm.
In addition, it returns EOF as a function, by file, so you can tell
which file has reached the EOF marker.

Revised May 10, 1989, to correct EOF function to rely solely on
the settings of EOFstat. The earlier version also called FioAsm's
EOF function, which would report true when there were still characters
to be read in a file buffer.

Revised May 17, 1989, to make compatible with JPI Modula-2 version 1.16

*)

(*
NOTE!

THIS MODULE IS NOT COMPLETE!

You must copy some procedures from JPI's FIO.MOD to complete it.
I have deleted them to avoid violating JPI's copyright. The procedures
are listed below.

*)

FROM Str IMPORT CHARSET,Length,Compare,IntToStr,CardToStr,RealToStr,
StrToInt,StrToCard,StrToReal,Copy, Concat;
IMPORT AsmLib;

CONST
MaxHandle = MaxOpenFiles+3;

(*$V-*)

TYPE
FileInf = POINTER TO BufRec;

VAR
BufInf : ARRAY[0..MaxHandle] OF FileInf;
EOFstat: ARRAY[0..MaxHandle] OF BOOLEAN;

PROCEDURE SetEOFstat(F: File; B:BOOLEAN);
BEGIN
EOFstat[F] := B
END SetEOFstat;

PROCEDURE EOF(F: File): BOOLEAN;
BEGIN
RETURN EOFstat[F];
END EOF;

(* This is a good place to insert these procedures from JPI's
TopSpeed Modula-2:

WrChar, WrBool, WrShtInt, WrInt,
WrLngInt, WrShtCard, WrCard, WrLngCard,
WrShtHex, WrHex, WrLngHex, WrReal,
WrLngReal, WrStr, WrStrAdj, WrLn,
WrCharRep, RdBool, RdShtInt, RdInt,
RdLngInt, RdShtCard, RdCard, RdLngCard,
RdShtHex, RdHex, RdLngHex, RdReal,
RdLngReal, RdItem, RdChar,* RdStr*

* RdChar and RdStr must be modified as follows:


RdChar is the same as in JPI's FIO.MOD except that that the two lines reading

EOF := (c = CHR(26));

must be replaced by

SetEOFstat(F, c = CHR(26));


RdStr is the same as in FIO.MOD except that that the line reading

EOF := (i = 0);

must be replaced by

SetEOFstat(F, i = 0);

*)

PROCEDURE Flush(F: File);
VAR x : FileInf;
BEGIN
IF (F <= MaxHandle) THEN
x := BufInf[F];
IF (x # NIL) THEN
WITH x^ DO
IF RWPos > EOB THEN
OK := (RWPos = Write( F,Buffer,RWPos ))
AND (IOresult() = 0)
ELSIF RWPos < EOB THEN (* last was read, move DOS pointer back *)
FioAsm.SeekRel (F, LONGINT(RWPos) - LONGINT(EOB), OK);
END;
END;
RWPos := 0;
EOB := 0;
END;
END;
END;
END Flush;

PROCEDURE WrBin(F: File; Buf: ARRAY OF BYTE; Count: CARDINAL);
VAR i : CARDINAL;
BEGIN
OK := TRUE;
i := 0;
IF (F > MaxHandle) OR (BufInf[F] = NIL) THEN
OK := (Count = Write( F,Buf,Count ) )
AND (IOresult() = 0);
ELSE
WITH BufInf[F]^ DO
IF RWPos <= EOB THEN (* last was read *)
Flush(F);
END;
i := 0;
WHILE Count > i DO
WHILE (RWPos < BufSize) AND ( Count > i ) DO
Buffer[ RWPos ] := SHORTCARD(Buf[i]);
INC( i );
INC( RWPos );
END;
IF RWPos = BufSize THEN
OK := (BufSize =Write( F,Buffer,BufSize ))
AND (IOresult() = 0);
RWPos := 0;
END;
END;
END;
END;
END WrBin;

PROCEDURE RdBin(F: File; VAR Buf: ARRAY OF BYTE; Count: CARDINAL) : CARDINAL;
VAR i,h,j, m : CARDINAL;
BEGIN
i := 0;
OK := TRUE;
SetEOFstat(F, FALSE);
IF Count > 0 THEN
IF (F > MaxHandle) OR (BufInf[F] = NIL) THEN
i := Read( F,Buf,Count );
OK := (IOresult() =0);
ELSE
WITH BufInf[F]^ DO
IF RWPos > EOB THEN (* Last was write *) Flush( F ); END;
i := 0;
LOOP
IF Count <= i THEN EXIT; END;
IF RWPos >= EOB THEN
EOB := Read( F,Buffer,BufSize );
OK := (IOresult() =0);
RWPos := 0;
IF EOB=0 THEN EXIT; END;
END;
m := EOB-RWPos;
IF Count-i < m THEN m := Count-i END;
Lib.Move(ADR(Buffer[ RWPos ]), ADR(Buf[i]), m);
INC( i, m );
INC( RWPos, Count );
END;
END;
END;
IF (i = 0) THEN SetEOFstat(F, TRUE); END;
END;
RETURN i;
END RdBin;

(*
You must copy this procedure from JPI's FIO.MOD:
GetName
*)

PROCEDURE Truncate(F: File);
BEGIN
Flush( F );
OK := FioAsm.Truncate(F);
END Truncate;

PROCEDURE Open(Name: ARRAY OF CHAR) : File;
VAR
fn: PathStr;
BEGIN
GetName(Name,fn);
RETURN FioAsm.Open(fn, FioAsm.InputOutput)
END Open;

PROCEDURE Exists(Name: ARRAY OF CHAR) : BOOLEAN;
VAR d : DirEntry;
b : BOOLEAN ;
dta : ADDRESS;
BEGIN
dta := FioAsm.GetDTA();
b := ReadFirstEntry(Name,FileAttr{},d);
FioAsm.SetDTA(dta);
RETURN b;
END Exists;

PROCEDURE Seek (F: File; Pos: LONGCARD);
BEGIN
Flush( F );
FioAsm.Seek(F, Pos, OK)
END Seek;

PROCEDURE SeekEOF(F:File);
BEGIN
Flush( F );
FioAsm.SeekEOF(F, OK)
END SeekEOF;

PROCEDURE Append(Name: ARRAY OF CHAR) : File;
VAR F : CARDINAL;
BEGIN
F := Open( Name );
SeekEOF( F );
RETURN F;
END Append;

PROCEDURE Size(F: File) : LONGCARD;
VAR
p, q: LONGCARD;
BEGIN
Flush( F );
p := GetPos(F);
FioAsm.SeekEOF(F, OK);
q := GetPos(F);
FioAsm.Seek(F, p, OK);
RETURN q
END Size;

PROCEDURE GetDir(drive: SHORTCARD; VAR Name: ARRAY OF CHAR);
VAR
dr : ARRAY [0..2] OF CHAR;
BEGIN
FioAsm.GetDir(drive, Name);
IF drive = 0 THEN drive := FioAsm.GetDrive() END;
dr[0] := CHR(drive + 64);
dr[1] := ':';
dr[2] := '\';
Concat(Name,dr,Name)
END GetDir;

PROCEDURE ChDir (Name: ARRAY OF CHAR);
BEGIN
IF Name[1] = ':' THEN
OK := FioAsm.SetDrive(VAL(SHORTCARD,CAP(Name[0]))-VAL(SHORTCARD,'@'));
IF (NOT OK) OR (Name[2] = 0C) THEN RETURN END;
END;
OK := FioAsm.ChDir(Name)
END ChDir;

PROCEDURE MkDir (Name: ARRAY OF CHAR);
BEGIN
OK := FioAsm.MkDir(Name)
END MkDir;

PROCEDURE RmDir (Name: ARRAY OF CHAR);
BEGIN
OK := FioAsm.RmDir(Name)
END RmDir;

PROCEDURE Erase (Name: ARRAY OF CHAR);
BEGIN
OK := FioAsm.Erase(Name)
END Erase;

PROCEDURE GetPos (F: File) : LONGCARD;
BEGIN
RETURN FioAsm.GetPos(F, OK )
END GetPos;

PROCEDURE Close (F: File);
BEGIN
Flush ( F );
OK := FioAsm.Close(F);
END Close;

PROCEDURE Rename(Name,NewName : ARRAY OF CHAR);
BEGIN
OK := FioAsm.Rename(Name,NewName);
END Rename;

(*
You must copy these procedures from JPI's FIO.MOD:
InitBufInf
AssignBuffer
*)

BEGIN
AsmLib.Fill( ADR(EOFstat), SIZE(EOFstat), 0);
Eng := FALSE;
ChopOff := FALSE;
OK := TRUE;
Separators := CHARSET{CHR(9),CHR(10),CHR(13),CHR(26),' '};
InitBufInf;
END NFIO.



  3 Responses to “Category : Modula II Source Code
Archive   : FIOASM.ZIP
Filename : NFIO.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/