[Oberon] FPGA - Files.ReadBytes(), Files.WriteBytes()

Tomas Kral thomas.kral at email.cz
Fri Aug 24 14:01:49 CEST 2018


On Mon, 20 Aug 2018 19:39:39 +0200
Jörg <joerg.straube at iaeth.ch> wrote:

> IF r.bpos MOD 4 # 0 THEN
> 	i := 0; WHILE i < n DO ReadBytes(r, x[i]); INC(i) END (* copy
> single bytes *) ELSE 
> 	(* four times faster by using SYSTEM.COPY() *)
> END

This just a first try, using above to modify PO.V4 ReadBytes().

PROCEDURE ReadBytes*(VAR r: Rider; VAR x: ARRAY OF BYTE; n: INTEGER);
    VAR i, n0, n1, src, dst, m: INTEGER; buf: Buffer;
  BEGIN i := 0; n0 := n; dst := SYSTEM.ADR(x); (*this implementation is
to be improved*) WHILE (n > 0) & (r.bpos MOD 4 # 0) DO ReadByte(r,
x[i]); INC(i); DEC(n) END ; (*bytes to word boundary*) IF r.apos #
r.buf.apos THEN r.buf := GetBuf(r.file, r.apos) END ; n1 := n MOD 4;
(*bytes to copy*) n := n DIV 4; (*words to copy*)
    WHILE n > 0 DO (*words*)
      src := SYSTEM.ADR(r.buf.data) + r.bpos; m := r.bpos + n*4;
      IF m <= r.buf.lim THEN
        SYSTEM.COPY(src, dst, n); r.bpos := m; r.res := 0; (*EXIT*)
n := 0 ELSIF r.buf.lim = SS THEN
        m := (r.buf.lim - r.bpos) DIV 4;
        IF m > 0 THEN SYSTEM.COPY(src, dst, m); INC(dst, m*4); DEC(n,
m) END ; IF r.apos < r.file.aleng THEN
          INC(r.apos); r.bpos := 0; buf := Buf(r.file, r.apos);
          IF buf = NIL THEN
            IF r.buf.mod THEN WriteBuf(r.file, r.buf) END ;
            ReadBuf(r.file, r.buf, r.apos)
          ELSE r.buf := buf
          END
        ELSE r.res := n*4; r.eof := TRUE; (*EXIT*) n := 0
        END
      ELSE m := (r.buf.lim - r.bpos) DIV 4;
        IF m > 0 THEN SYSTEM.COPY(src, dst, m); r.bpos := r.buf.lim
END ; r.res := (n-m)*4; r.eof := TRUE; (*EXIT*) n := 0
      END
    END; (* n > 0 *)
    FOR i := n0-n1 TO n0 DO ReadByte(r, x[i]) END (*remaining bytes*)
  END ReadBytes;

-- 
Tomas Kral <thomas.kral at email.cz>


More information about the Oberon mailing list