[Oberon] ORX.WriteFile
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Thu Oct 17 22:21:51 CEST 2019
> I used a different approach and isolated the additional code to a separate procedure ORG.WriteHexFile.
Which is practically identical to ORX.WriteFile.. there are only so many ways to do this..
PROCEDURE WriteFile*; (*write code section of M.rsc in PROM format with specified size (nof opcodes) to output file*)
VAR f, g: Files.File; Rf, Rg: Files.Rider;
code: ARRAY maxCode OF LONGINT;
i, size, outsize, start, nofimps, res: INTEGER;
name: ARRAY 32 OF CHAR;
S: Texts.Scanner;
BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S); res := -1;
IF S.class = Texts.Name THEN name := S.s; Texts.Scan(S);
IF S.class = Texts.Int THEN outsize := S.i; Texts.Scan(S);
IF S.class = Texts.Name THEN res := 0; Texts.WriteString(W, " WriteFile ");
Texts.WriteString(W, name); Texts.WriteInt(W, outsize, 5); Texts.Write(W, " "); Texts.WriteString(W, S.s);
IF outsize > 0 THEN f := Files.Old(name);
IF f # NIL THEN g := Files.New(S.s); Files.Set(Rf, f, 0);
ReadCode(Rf, code, size, start, nofimps, res);
IF res = 0 THEN
IF nofimps = 0 THEN
IF size <= outsize THEN Files.Set(Rg, g, 0); i := 0;
WHILE i < size DO WriteHex(Rg, code[i]); Files.Write(Rg, CR); INC(i) END ;
WHILE i < outsize DO WriteHex(Rg, 0); Files.Write(Rg, CR); INC(i) END ;
Files.Register(g); Texts.WriteString(W, " done")
ELSE Texts.WriteString(W, " insufficent size")
END
ELSE Texts.WriteString(W, " imports not allowed")
END
ELSIF res = 1 THEN Texts.WriteString(W, " input file format error")
ELSIF res = 2 THEN Texts.WriteString(W, " program too long")
END
ELSE Texts.WriteString(W, " input file not found")
END
ELSE Texts.WriteString(W, " outputsize must be positive")
END
END
END
END ;
IF res = -1 THEN Texts.WriteString(W, "Usage: ORX.WriteFile M.rsc outputsize M.mem") END ;
Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
END WriteFile;
from:
https://github.com/andreaspirklbauer/Oberon-building-tools/blob/master/Sources/OriginalOberon2013/ORX.Mod
More information about the Oberon
mailing list