-- CGScreenImpl.mesa
-- Last changed by Doug Wyatt, August 23, 1982 4:15 pm
-- Last changed by Paul Rovner, December 14, 1983 3:31 pm

DIRECTORY
CGScreen USING [],
Interminal USING [terminal],
PrincOps USING [BBTableSpace, BBptr],
PrincOpsUtils USING [AlignedBBTable, BITBLT],
Terminal USING [BitmapState, GetBitBltTable, GetBWBitmapState, SetBWBitmapState,
Virtual, Select];

CGScreenImpl: CEDAR PROGRAM
IMPORTS PrincOpsUtils, Interminal, Terminal
EXPORTS CGScreen = {

terminal: Terminal.Virtual ← Interminal.terminal;

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: PrincOps.BBTableSpace;
bb: PrincOps.BBptr ← PrincOpsUtils.AlignedBBTable[@bbs];
bpl,lines: CARDINAL;
h: CARDINAL = 4;
gray: ARRAY[0..h) OF CARDINAL ← [42104B,42104B,10421B,10421B];
oldState: Terminal.BitmapState ← Terminal.GetBWBitmapState[terminal];
[] ← Terminal.SetBWBitmapState[terminal, allocated];
bb^ ← Terminal.GetBitBltTable[terminal];
bpl ← bb.dstBpl; lines ← terminal.bwHeight;
IF (bpl MOD 16)#0 OR bb.dst.bit#0 THEN ERROR;
screenbase ← bb.dst.word; screenraster ← bpl/16; screenheight ← lines;
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];
PrincOpsUtils.BITBLT[bb]; -- make the screen gray
[] ← Terminal.SetBWBitmapState[terminal, displayed];
Terminal.Select[terminal];
};

InitScreen[];

}.