ColorWorldImpl.mesa
Public interfaces to start and stop the color display and color cursor
Maureen Stone, July 21, 1982 11:57 am
Doug Wyatt, December 20, 1983 5:48 pm
DIRECTORY
Graphics USING [Context, NewContext],
Interminal USING [terminal, TurnOnColorCursor, TurnOffColorCursor],
ColorDevice USING [New],
ColorPackagePrivate USING [DeviceProc],
ColorMap USING [StandardMap, SetGamma],
ColorWorld USING [],
Terminal USING [CantDoIt, ColorMode, GetColorMode, LegalColorMode, SetColorBitmapState, TurnOnColorDisplay, Virtual],
TerminalExtras USING [AttachColorDisplay];
ColorWorldImpl: CEDAR PROGRAM
IMPORTS ColorDevice, ColorMap, Graphics, Interminal, Terminal, TerminalExtras
EXPORTS ColorWorld, ColorPackagePrivate = {
colorOn: BOOLEANFALSE;
terminal: PUBLIC Terminal.Virtual ← NIL;
valid values for bpp (bits per pixel) are:
Dolphins: 1, 2 or 4
Dorados: 1, 4, 8 and 24
Turn on color is expensive. It will take about 10 seconds worse case
If you call it more than once it will automatically do a TurnOffColor
HasMode: PUBLIC PROCEDURE[bpp: INT] RETURNS[BOOLEAN] = TRUSTED {
RETURN[(SELECT bpp FROM
1 => terminal.LegalColorMode[
[full: FALSE, bitsPerPixelChannelA: 1, bitsPerPixelChannelB: 0]],
2 => terminal.LegalColorMode[
[full: FALSE, bitsPerPixelChannelA: 2, bitsPerPixelChannelB: 0]],
4 => terminal.LegalColorMode[
[full: FALSE, bitsPerPixelChannelA: 4, bitsPerPixelChannelB: 0]],
8 => terminal.LegalColorMode[
[full: FALSE, bitsPerPixelChannelA: 8, bitsPerPixelChannelB: 0]],
24 => terminal.LegalColorMode[
[full: TRUE, bitsPerPixelChannelA: 0, bitsPerPixelChannelB: 0]],
ENDCASE => FALSE)];
};
TurnOnColor: PUBLIC PROC[bpp: INT, onLeft: BOOLEANTRUE] RETURNS[BOOLEAN] = {
mode: Terminal.ColorMode ← (IF bpp=24 THEN [TRUE,0,0] ELSE[FALSE,bpp,0]);
ok: BOOL ← terminal.LegalColorMode[mode];
IF ok THEN {
[] ← terminal.SetColorBitmapState[newState: allocated,
newMode: mode, newVisibility: all ! Terminal.CantDoIt => GOTO Fail];
ColorMap.SetGamma[2.2];
IF bpp # 24 THEN ColorMap.StandardMap[];
terminal.TurnOnColorDisplay[];
TRUSTED {Interminal.TurnOnColorCursor[bpp,onLeft]};
colorOn ← TRUE;
EXITS Fail => ok ← FALSE;
};
RETURN[ok];
};
TurnOffColor jumps the cursor back to the bi-level display and deallocates the
color framebuffer.
TurnOffColor: PUBLIC PROC = {
TRUSTED {Interminal.TurnOffColorCursor[]};
[] ← terminal.SetColorBitmapState[newState: none,
newMode: terminal.GetColorMode, newVisibility: all];
colorOn ← FALSE;
};
NewProc: ColorPackagePrivate.DeviceProc ← ColorDevice.New;
SetNewContextProc: PUBLIC PROC[new: ColorPackagePrivate.DeviceProc] = {NewProc ← new};
NewContext: PUBLIC PROC RETURNS[Graphics.Context] = {
IF ~colorOn THEN RETURN[NIL]
ELSE RETURN[Graphics.NewContext[NewProc[]]];
};
Initialize: PROC = {
terminal ← Interminal.terminal;
TerminalExtras.AttachColorDisplay[terminal];
};
Initialize[];
}.