-- file: MFScreenImpl.mesa
-- Pascal-to-Mesa translator output, translated at October 31, 1985 4:28:02 pm PST


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  MFTypes,
  MFProcArray,
  MFExternals,
  MFMath,
  MFEdges,
  MFScreen;

MFScreenImpl: PROGRAM IMPORTS PascalBasic, MFProcArray, MFExternals, MFMath, MFEdges EXPORTS MFScreen = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, MFTypes, MFProcArray, MFExternals, MFMath, MFEdges, MFScreen;
--:557----566:
--SCREEN←PIXEL:ARRAY[SCREEN←ROW,SCREEN←COL]OF PIXEL←COLOR;----:566----569:

ScreenStarted: PascalBoolean;

ScreenOk: PascalBoolean;
--:569----572:
WindowOpen: LONG POINTER TO ARRAY WindowNumber OF PascalBoolean ← PascalStaticZone.NEW[ARRAY WindowNumber OF PascalBoolean];

LeftCol: LONG POINTER TO ARRAY WindowNumber OF ScreenCol ← PascalStaticZone.NEW[ARRAY WindowNumber OF ScreenCol];

RightCol: LONG POINTER TO ARRAY WindowNumber OF ScreenCol ← PascalStaticZone.NEW[ARRAY WindowNumber OF ScreenCol];

TopRow: LONG POINTER TO ARRAY WindowNumber OF ScreenRow ← PascalStaticZone.NEW[ARRAY WindowNumber OF ScreenRow];

BotRow: LONG POINTER TO ARRAY WindowNumber OF ScreenRow ← PascalStaticZone.NEW[ARRAY WindowNumber OF ScreenRow];

MWindow: LONG POINTER TO ARRAY WindowNumber OF PascalInteger ← PascalStaticZone.NEW[ARRAY WindowNumber OF PascalInteger];

NWindow: LONG POINTER TO ARRAY WindowNumber OF PascalInteger ← PascalStaticZone.NEW[ARRAY WindowNumber OF PascalInteger];

WindowTime: LONG POINTER TO ARRAY WindowNumber OF PascalInteger ← PascalStaticZone.NEW[ARRAY WindowNumber OF PascalInteger];
--:572----579:
RowTransition: LONG POINTER TO TransSpec ← PascalStaticZone.NEW[TransSpec];
--:568----574:
 OpenAWindow: PROCEDURE[K: WindowNumber,R0,C0,R1,C1: Scaled,X,Y: Scaled]
 = 
BEGIN M, N:PascalInteger;--575:
IF R0<0  THEN R0←0  ELSE R0←RoundUnscaled[R0];R1←RoundUnscaled[R1];
IF R1>ScreenDepth  THEN R1←ScreenDepth;
IF R1<R0  THEN IF R0>ScreenDepth  THEN R0←R1  ELSE R1←R0;
IF C0<0  THEN C0←0  ELSE C0←RoundUnscaled[C0];C1←RoundUnscaled[C1];
IF C1>ScreenWidth  THEN C1←ScreenWidth;
IF C1<C0  THEN IF C0>ScreenWidth  THEN C0←C1  ELSE C1←C0--:575--;
WindowOpen↑[K]←TRUE;WindowTime↑[K]←WindowTime↑[K]+1;LeftCol↑[K]←C0;
RightCol↑[K]←C1;TopRow↑[K]←R0;BotRow↑[K]←R1;--576:
M←RoundUnscaled[X];N←RoundUnscaled[Y]-1;MWindow↑[K]←C0-M;
NWindow↑[K]←R0+N--:576--;
BEGIN IF  NOT ScreenStarted  THEN BEGIN ScreenOk←InitScreen[];
ScreenStarted←TRUE; END; END;
IF ScreenOk  THEN BEGIN BlankRectangle[C0,C1,R0,R1];UpdateScreen[]; END;
 END;--:574----577:-- DispEdges: PROCEDURE[K: WindowNumber] = 
BEGIN 
 P, Q:Halfword;AlreadyThere:PascalBoolean;R:PascalInteger;--580:--N:ScreenCol;
W, Ww:PascalInteger;B:PixelColor;M, Mm:PascalInteger;D:PascalInteger;MAdjustment:PascalInteger;
RightEdge:PascalInteger;MinCol:ScreenCol;--:580
 IF ScreenOk  THEN IF  INT[LeftCol↑[K]]<RightCol↑[K] THEN IF 
 INT[TopRow↑[K]]<BotRow↑[K] THEN BEGIN AlreadyThere←FALSE;
IF Mem[ INT[CurEdges]+3]↑.Hh.Rh=K  THEN IF Mem[ INT[CurEdges]+4]↑.Int=WindowTime↑[K]
 THEN AlreadyThere←TRUE;
IF  NOT AlreadyThere  THEN BlankRectangle[LeftCol↑[K],RightCol↑[K],
TopRow↑[K],BotRow↑[K]];--581:
MAdjustment←MWindow↑[K]-Mem[ INT[CurEdges]+3]↑.Hh.Lh;
RightEdge←8*(RightCol↑[K]-MAdjustment);MinCol←LeftCol↑[K]--:581--;
P←Mem[CurEdges]↑.Hh.Rh;R←NWindow↑[K]-( INT[Mem[ INT[CurEdges]+1]↑.Hh.Lh]-4096);
WHILE(P#CurEdges)AND (R>=TopRow↑[K])DO BEGIN IF R<BotRow↑[K] THEN--578:
BEGIN 
 {IF  INT[Mem[ INT[P]+1]↑.Hh.Lh]>1  THEN SortEdges[P] ELSE IF Mem[ INT[P]+1]↑.Hh.Lh=1
 THEN IF AlreadyThere  THEN  GOTO Label30;Mem[ INT[P]+1]↑.Hh.Lh←1;--582:--N←0;Ww←0;
M←-1;W←0;Q←Mem[ INT[P]+1]↑.Hh.Rh;RowTransition↑[0]←MinCol;
{WHILE TRUE DO BEGIN IF Q=50000  THEN D←RightEdge  ELSE D←Mem[Q]↑.Hh.Lh;
Mm←( PascalDIVPower2[D ,3])+MAdjustment;IF Mm#M  THEN BEGIN--583:
IF W<=0  THEN BEGIN IF Ww>0  THEN IF M>MinCol  THEN BEGIN IF N=0  THEN IF
AlreadyThere  THEN BEGIN B←0;N←N+1; END  ELSE B←1  ELSE N←N+1;
RowTransition↑[N]←M; END;
 END  ELSE IF Ww<=0  THEN IF M>MinCol  THEN BEGIN IF N=0  THEN B←1;N←N+1;
RowTransition↑[N]←M; END--:583--;M←Mm;W←Ww; END;
IF D>=RightEdge  THEN  GOTO Label40;Ww←Ww+( PascalMODPower2Mask[D ,7])-4;Q←Mem[Q]↑.Hh.Rh; END ENDLOOP ;
EXITS Label40 => NULL};--584:
IF AlreadyThere OR (Ww>0) THEN BEGIN IF N=0  THEN IF Ww>0  THEN B←1  ELSE B
←0;N←N+1;RowTransition↑[N]←RightCol↑[K];
 END  ELSE IF N=0  THEN  GOTO Label30--:584--;--:582--PaintRow[R,B,@RowTransition↑,N];EXITS Label30 => NULL}; END--:578--;P←Mem[P]↑.Hh.Rh;R←R-1; END ENDLOOP ;
UpdateScreen[];WindowTime↑[K]←WindowTime↑[K]+1;
Mem[ INT[CurEdges]+3]↑.Hh.Rh←K;Mem[ INT[CurEdges]+4]↑.Int←WindowTime↑[K]; END; END;

END.