MODULE RAMVolumes;
IMPORT SYSTEM, Files;
CONST
DirMark = LONGINT(9B1EA38DH);
TYPE
Volume* = OBJECT (Files.Volume)
VAR
data: POINTER TO ARRAY OF POINTER TO ARRAY OF CHAR;
PROCEDURE GetBlock*(adr: LONGINT; VAR blk: ARRAY OF CHAR);
VAR i: LONGINT;
BEGIN
IF (adr < 1) OR (adr > size) THEN SYSTEM.HALT(15) END;
ASSERT(LEN(blk) >= blockSize);
IF data[adr-1] # NIL THEN
SYSTEM.MOVE(SYSTEM.ADR(data[adr-1]^[0]), SYSTEM.ADR(blk[0]), blockSize)
ELSE
FOR i := 0 TO blockSize-1 DO blk[i] := 0X END
END
END GetBlock;
PROCEDURE PutBlock*(adr: LONGINT; VAR blk: ARRAY OF CHAR);
BEGIN
IF (adr < 1) OR (adr > size) THEN SYSTEM.HALT(15) END;
ASSERT(LEN(blk) >= blockSize);
IF data[adr-1] = NIL THEN NEW(data[adr-1], blockSize) END;
SYSTEM.MOVE(SYSTEM.ADR(blk[0]), SYSTEM.ADR(data[adr-1]^[0]), blockSize)
END PutBlock;
PROCEDURE Finalize*;
BEGIN
data := NIL;
Finalize^
END Finalize;
END Volume;
VAR
count: LONGINT;
PROCEDURE GetCount(): LONGINT;
BEGIN {EXCLUSIVE}
INC(count); RETURN count
END GetCount;
PROCEDURE New*(context : Files.Parameters);
VAR vol: Volume; size, vbs : LONGINT;
BEGIN
context.vol := NIL;
IF context.arg.GetInteger(size, FALSE) & context.arg.GetInteger(vbs, FALSE) & (size # 0) & (vbs > 0) THEN
NEW(vol); NEW(vol.data, size);
NEW(vol.data[0], vbs);
SYSTEM.PUT32(SYSTEM.ADR(vol.data[0]^[0]), DirMark);
vol.name := "RAM"; Files.AppendInt(GetCount(), vol.name);
vol.blockSize := vbs;
vol.Init({}, size, 0);
context.vol := vol;
ELSE
context.error.String("RAMVolumes: bad parameters"); context.error.Ln;
END;
END New;
BEGIN
count := -1
END RAMVolumes.