-- CGScreenImpl.mesa
-- Last changed by Doug Wyatt, August 23, 1982 4:15 pm

DIRECTORY
CGScreen USING [],
BitBlt USING [BBTableSpace, BBptr, AlignedBBTable, BITBLT],
UserTerminal USING [GetBitBltTable, GetState, SetState, screenHeight, State];

CGScreenImpl: CEDAR PROGRAM
IMPORTS BitBlt, UserTerminal
EXPORTS CGScreen = {

screenbase: LONG POINTERNIL;
screenraster,screenheight: CARDINAL ← 0;

screenx,screeny: CARDINAL = 0; -- In Pilot, we own the whole screen

Bits: PUBLIC PROC RETURNS[base: LONG POINTER, raster,height: CARDINAL] = {
RETURN[screenbase,screenraster,screenheight];
};

Origin: PUBLIC PROC RETURNS[x,y: CARDINAL] = {
RETURN[x: screenx, y: screeny]
};

MouseToWorld: PUBLIC PROC[mx,my: INTEGER] RETURNS[wx,wy: INTEGER] = {
RETURN[wx: mx-screenx, wy: (screenheight+screeny)-my];
};

InitScreen: PROC = TRUSTED {
bbs: BitBlt.BBTableSpace;
bb: BitBlt.BBptr ← BitBlt.AlignedBBTable[@bbs];
bpl,lines: CARDINAL;
h: CARDINAL = 4;
gray: ARRAY[0..h) OF CARDINAL ← [42104B,42104B,10421B,10421B];
oldState: UserTerminal.State ← UserTerminal.GetState[];
IF oldState=disconnected THEN [] ← UserTerminal.SetState[off]; -- allocate bitmap if necessary
bb^ ← UserTerminal.GetBitBltTable[];
bpl ← bb.dstBpl; lines ← UserTerminal.screenHeight;
IF (bpl MOD 16)#0 THEN ERROR; IF bb.dst.bit#0 THEN ERROR;
screenbase ← bb.dst.word; screenraster ← bpl/16; screenheight ← lines;
IF oldState#on THEN {
bb.src ← [word: @gray, bit: 0];
bb.srcDesc.gray ← [yOffset: 0, widthMinusOne: 0, heightMinusOne: h-1];
bb.width ← bpl; bb.height ← lines;
bb.flags ← [disjoint: TRUE, gray: TRUE];
BitBlt.BITBLT[bb]; -- make the screen gray
[] ← UserTerminal.SetState[on]; -- display it
};
};

InitScreen[];

}.