-- MesaBandStreamImpl.mesa
-- Last changed by Ken Pier, March 14, 1982 6:48 PM
DIRECTORY
MesaBandStream,
PressBandsDefs USING [GetTfsBandsBuffer, ReadTfsPage],
Inline USING [COPY];
MesaBandStreamImpl: PROGRAM
IMPORTS Inline, PressBandsDefs
EXPORTS MesaBandStream = {
OPEN PB: PressBandsDefs, MesaBandStream;
wordsPerPage: CARDINAL = 256;
wordsPerTFSPage: CARDINAL = 1024;
InitBandFileBuffer: PUBLIC PROC[] = {
wordsLeft ← 0; bRef ← bStart ← PB.GetTfsBandsBuffer[];
bEnd ← bStart+bufferWords;
};
GetBand: PUBLIC PROC[to: POINTER, words: CARDINAL] RETURNS [CARDINAL] = {
wordsRead, nWords: CARDINAL ← 0;
DO
nWords ← MIN[wordsLeft, words];
Inline.COPY[from: bRef, nwords: nWords, to: to];
wordsRead ← wordsRead+nWords;
IF nWords=words THEN {--buffer had all the words
wordsLeft ← wordsLeft-words;
bRef ← bRef+words; EXIT;
};
--buffer empty and more to COPY.
bRef ← bStart; words ← words-wordsLeft; to ← to+wordsLeft;
PB.ReadTfsPage; wordsLeft ← wordsPerTFSPage;
ENDLOOP;
RETURN[wordsRead];
};--GetBand
SkipBand: PUBLIC PROC [words: CARDINAL] RETURNS [CARDINAL] = {
wordsRead, nWords: CARDINAL ← 0;
DO
nWords ← MIN[wordsLeft, words];
wordsRead ← wordsRead+nWords;
IF nWords=words THEN {--buffer had all the words
wordsLeft ← wordsLeft-words;
bRef ← bRef+words; EXIT;
};
--buffer empty and more to COPY.
bRef ← bStart; words ← words-wordsLeft;
PB.ReadTfsPage; wordsLeft ← wordsPerTFSPage;
ENDLOOP;
RETURN[wordsRead];
};--SkipBand
--global storage
wordsLeft: CARDINAL ← 0;--remaining valid words in Get buffer
bufferPages: CARDINAL ← 1;
bufferWords: CARDINAL ← bufferPages*wordsPerTFSPage;
bStart, bRef, bEnd: POINTER ← NIL;
}.
LOG
March 11, 1982, changed to SHORT POINTERS