TTYPortHeadDLion.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Tim Diebert: February 3, 1987 10:01:53 am PST
Reconstructed from the Pilot 6.0 heads.
DIRECTORY
DeviceCleanup USING [Await, Item, Reason],
DLionInputOutput USING [IOPage],
TTYFace;
TTYPortHeadDLion: PROGRAM
IMPORTS DeviceCleanup, DLionInputOutput
EXPORTS TTYFace
~ BEGIN
TTY: LONG POINTER TO MACHINE DEPENDENT RECORD [
outData(0):  UNSPECIFIED, -- Char or Parameter Record
outControl(1): OutControl,
inData(2):  CHAR,
inControl(3): InCharStatus,
unused(4:0..7): [0..400B),
dataTerminalReady(4:8..8): BOOL,
unused1(4:9..12): [0..20B),
requestToSend(4:13..13): BOOLEAN,
rxRDY(4:14..14): BOOLEAN,
txRDY(4:15..15): BOOLEAN,
notifyMask(5): WORD] = DLionInputOutput.IOPage + 121B;
OutControl: TYPE = MACHINE DEPENDENT {
(0), -- outControl >= putChar means busy
putChar(100000B), -- setParameterCommand(100001B), -- getStatus(100002B),
on(100003B), off(100004B), setDSR(100401B), setCTS(101001B),
setCharLength(102001B), setParity(104001B), setStopBits(110001B),
setBaudRate(120001B), setAllParameters(137401B), (177777B)};
ParameterRecord: TYPE = MACHINE DEPENDENT RECORD [
onOff(0:0..3): MACHINE DEPENDENT {on(0), off(1), (17B)}, -- (Head flag)
baudRate(0:4..7): TTYFace.LineSpeed ← bps1200,
stopBits(0:8..9): TTYFace.StopBits ← two,
parity(0:10..11): ChipParity ← none,
charLength(0:12..13): TTYFace.CharacterLength ← lengthIs8bits,
clearToSend(0:14..14): BOOLEANFALSE,
dataSetReady(0:15..15): BOOLEANFALSE];
ChipParity: TYPE = MACHINE DEPENDENT {none(0), odd(1), even(3)};
ConvertParity: ARRAY TTYFace.Parity OF ChipParity = [none: none, odd: odd, even: even];
InCharStatus: TYPE = MACHINE DEPENDENT RECORD [
state(0:0..0):  MACHINE DEPENDENT{empty(0), charPresent(1)},
unused(0:1..7): [0..200B),
success(0:8..8): BOOLEAN,
breakDetected(0:9..9): BOOLEAN,
framingError(0:10..10): BOOLEAN,
dataLost(0:11..11): BOOLEAN,
parityError(0:12..12): BOOLEAN,
unused1(0:13..14): [0..4),
notReady(0:15..15): BOOLEAN];
state: ParameterRecord ← [onOff: off];
GetCommand: PUBLIC PROC [CARDINAL] RETURNS [data: CHARACTER, stat: TTYFace.TransferStatus] = BEGIN
ttyInStatus: InCharStatus = TTY.inControl;
IF ttyInStatus.state = empty THEN RETURN[NULL, notReady];
data ← TTY.inData; TTY.inControl.state ← empty;
stat ← SELECT TRUE FROM
ttyInStatus.success => success,
ttyInStatus.breakDetected => breakDetected,
ttyInStatus.framingError => asynchFramingError,
ttyInStatus.dataLost => dataLost,
ttyInStatus.parityError => parityError,
ttyInStatus.notReady => notReady,
ENDCASE => success;
END;
GetLineCount: PUBLIC PROC RETURNS [CARDINAL] = {RETURN[1]};
GetStatus: PUBLIC PROC [CARDINAL] RETURNS [TTYFace.DeviceStatus] = BEGIN
RETURN[[readyToPut: TTY.outControl < putChar,
readyToGet: TTY.inControl.state = charPresent,
dataTerminalReady: TTY.dataTerminalReady,
requestToSend: TTY.requestToSend]];
END;
PutCommand: PUBLIC PROC [lineNumber: CARDINAL, data: CHARACTER] RETURNS [TTYFace.TransferStatus] = BEGIN
IF TTY.outControl >= putChar THEN RETURN[notReady];
TTY.outData ← data; TTY.outControl ← putChar;
RETURN[success];
END;
SetParameter: PUBLIC PROC [lineNumber: CARDINAL, parameter: TTYFace.Parameter] = BEGIN
control: OutControl;
WITH parameter SELECT FROM
characterLength => {control ← setCharLength; state.charLength ← characterLength};
clearToSend => {control ← setCTS; state.clearToSend ← clearToSend};
dataSetReady => {control ← setDSR; state.dataSetReady ← dataSetReady};
lineSpeed => {control ← setBaudRate; state.baudRate ← lineSpeed};
parity => {control ← setParity; state.parity ← ConvertParity[parity]};
stopBits => {control ← setStopBits; state.stopBits ← stopBits};
ENDCASE => RETURN;
WHILE TTY.outControl >= putChar DO ENDLOOP;
TTY.outData ← state;
TTY.outControl ← control;
END;
-- should check to see if the out is busy???
On: PUBLIC PROC [lineNumber: CARDINAL, mask: UNSPECIFIED] = BEGIN
state ← [onOff: on];
TTY.notifyMask ← mask; TTY.inControl.state ← empty;
TTY.outControl ← on;
END;
Off: PUBLIC PROC [CARDINAL] = BEGIN
WHILE TTY.outControl >= putChar DO ENDLOOP;
TTY.notifyMask ← 0;
TTY.outControl ← off;
state ← [onOff: off];
END;
InitializeCleanup: PROC = BEGIN
item: DeviceCleanup.Item;
mask: WORD;
DO
reason: DeviceCleanup.Reason = DeviceCleanup.Await[@item];
IF state.onOff=on THEN SELECT reason FROM
turnOff, kill => BEGIN
WHILE TTY.outControl >= putChar DO ENDLOOP;
mask ← TTY.notifyMask;
TTY.notifyMask ← 0;
TTY.outControl ← off;
WHILE TTY.outControl >= putChar DO ENDLOOP;
END;
turnOn => BEGIN
TTY.notifyMask ← mask;
TTY.outControl ← on;
WHILE TTY.outControl >= putChar DO ENDLOOP;
TTY.outData ← state;
TTY.outControl ← setAllParameters;
END;
disconnect => NULL; -- turnOff was already called
ENDCASE;
ENDLOOP;
END;
Start Chain
Start: PUBLIC PROC = {RemainingHeads.Start[]};
Mainline code
InitializeCleanup[];
END.
-- TTYPortHeadDLion.mesa
-- Copyright (C) 1980, 1982 by Xerox Corporation. All rights reserved.
-- Last edited: 26-Sep-84 0:17:24 By: Grundler
-- This head supports only ONE LINE
-- Tim Diebert: November 16, 1985 12:11:20 pm PST

DIRECTORY
DeviceCleanup USING [Await, Item, Reason],
-- HeadStartChain,
DLionInputOutput USING [IOPage -- , ttyCommandOffset, ttyInCSBOffset, ttyOutCSBOffset -- ],
Process USING[MsecToTicks, Pause],
TTYFace;

TTYPortHeadDLion: PROGRAM
IMPORTS DeviceCleanup, DLionInputOutput, Process --, RemainingHeads: HeadStartChain
EXPORTS -- HeadStartChain, -- TTYFace =
BEGIN


TTYInCSB: LONG POINTER TO MACHINE DEPENDENT RECORD [
inControl(0): InCharStatus,
inData(1:0..7): CHARACTER,
dataTerminalReady(1:8..8): BOOLEAN,
unused1(1:9..12): [0..20B),
requestToSend(1:13..13): BOOLEAN,
rxRDY(1:14..14): BOOLEAN,
txRDY(1:15..15): BOOLEAN] = DLionInputOutput.IOPage + 053H;
-- DLionInputOutput.ttyInCSBOffset

TTYOutCSB: LONG POINTER TO MACHINE DEPENDENT RECORD [
parameter(0): ParameterRecord,
notifyMask(1): WORD] = DLionInputOutput.IOPage + 051H;
-- DLionInputOutput.ttyOutCSBOffset

TTYOutCommand: LONG POINTER TO MACHINE DEPENDENT RECORD [
command(0:0..7):  {(0), putChar(200B), abortPut(205B)},
outData(0:8..15):  CHARACTER] = DLionInputOutput.IOPage
-- DLionInputOutput.ttyCommandOffset

TTYSetParameterCommand: LONG POINTER TO MACHINE DEPENDENT RECORD [
command: {(0), --setParameterCommand(100400B),
setDSR(100401B), setCTS(100402B),
setCharLength(100404B), setParity(100410B), setStopBits(100420B),
setBaudRate(100440B), setAllParameters(100477B), (177777B)}] = DLionInputOutput.IOPage -- + DLionInputOutput.ttyCommandOffset -- ;

TTYCommand: LONG POINTER TO MACHINE DEPENDENT RECORD [
command: {(0), getStatus(101000B), on(101400B), off(102000B), --abortPut(102400B),-- breakOn(103000B), breakOff(103400B)}] = DLionInputOutput.IOPage -- + DLionInputOutput.ttyCommandOffset -- ;

ChipParity: TYPE = MACHINE DEPENDENT {none(0), odd(1), even(3)};
ConvertParity: ARRAY TTYFace.Parity OF ChipParity = [
none: none, odd: odd, even: even];

ParameterRecord: TYPE = MACHINE DEPENDENT RECORD [
onOff(0:0..3): MACHINE DEPENDENT {on(0), off(1), (17B)}, -- (Head flag)
baudRate(0:4..7): TTYFace.LineSpeed ← bps1200,
stopBits(0:8..9): TTYFace.StopBits ← two,
parity(0:10..11): ChipParity ← none,
charLength(0:12..13): TTYFace.CharacterLength ← lengthIs8bits,
clearToSend(0:14..14): BOOLEANFALSE,
dataSetReady(0:15..15): BOOLEANFALSE];

InCharStatus: TYPE = MACHINE DEPENDENT RECORD [
state(0:0..0): MACHINE DEPENDENT{empty(0), charPresent(1)},
unused(0:1..7): [0..200B),
success(0:8..8): BOOLEAN,
breakDetected(0:9..9): BOOLEAN,
framingError(0:10..10): BOOLEAN,
dataLost(0:11..11): BOOLEAN,
parityError(0:12..12): BOOLEAN,
unused1(0:13..14): [0..4),
notReady(0:15..15): BOOLEAN];

state: ParameterRecord ← [onOff: off];

GetCommand: PUBLIC PROC [CARDINAL]
RETURNS [data: CHARACTER, stat: TTYFace.TransferStatus] =
BEGIN
ttyInStatus: InCharStatus = TTYInCSB.inControl;
IF ttyInStatus.state = empty THEN RETURN[NULL, notReady];
data ← TTYInCSB.inData; TTYInCSB.inControl.state ← empty;
stat ← SELECT TRUE FROM
ttyInStatus.success => success,
ttyInStatus.breakDetected => breakDetected,
ttyInStatus.framingError => asynchFramingError,
ttyInStatus.dataLost => dataLost,
ttyInStatus.parityError => parityError,
ttyInStatus.notReady => notReady,
ENDCASE => success;
END;

GetLineCount: PUBLIC PROC RETURNS [CARDINAL] = {RETURN[1]};

GetStatus: PUBLIC PROC [CARDINAL] RETURNS [TTYFace.DeviceStatus] =
BEGIN
RETURN[[
readyToPut: TTYOutCommand.command < putChar,
readyToGet: TTYInCSB.inControl.state = charPresent,
dataTerminalReady: TTYInCSB.dataTerminalReady,
requestToSend: TTYInCSB.requestToSend]];
END;

PutCommand: PUBLIC PROC [lineNumber: CARDINAL, data: CHARACTER]
RETURNS [TTYFace.TransferStatus] =
BEGIN
IF TTYOutCommand.command >= putChar THEN RETURN[notReady];
TTYOutCommand.outData ← data; TTYOutCommand.command ← putChar;
RETURN[success];
END;

SendBreak: PUBLIC PROC [lineNumber: CARDINAL] =
BEGIN
WHILE TTYOutCommand.command >= putChar DO ENDLOOP; --Wait for IOP to finish current command
TTYCommand.command ← breakOn;
Process.Pause[Process.MsecToTicks[190]];
TTYCommand.command ← breakOff;
END;

SetParameter: PUBLIC PROC [lineNumber: CARDINAL, parameter: TTYFace.Parameter] =
BEGIN
WHILE TTYOutCommand.command >= putChar DO ENDLOOP; --Wait for IOP to finish current command
WITH parameter SELECT FROM
characterLength => {TTYOutCSB.parameter.charLength ← characterLength; TTYSetParameterCommand.command ← setCharLength};
clearToSend => {TTYOutCSB.parameter.clearToSend ← clearToSend; TTYSetParameterCommand.command ← setCTS};
dataSetReady => {TTYOutCSB.parameter.dataSetReady ← dataSetReady; TTYSetParameterCommand.command ← setDSR};
lineSpeed => {TTYOutCSB.parameter.baudRate ← lineSpeed;  TTYSetParameterCommand.command ← setBaudRate};
stopBits => {TTYOutCSB.parameter.stopBits ← stopBits;  TTYSetParameterCommand.command ← setStopBits; };
parity => {TTYOutCSB.parameter.parity ← ConvertParity[parity]; TTYSetParameterCommand.command ← setParity};
ENDCASE => RETURN;
state ← TTYOutCSB.parameter; -- save state for inload
END;

-- should check to see if the out is busy???
On: PUBLIC PROC [lineNumber: CARDINAL, mask: UNSPECIFIED] =
BEGIN
state ← [onOff: on];
TTYOutCSB.notifyMask ← mask; TTYInCSB.inControl.state ← empty;
TTYInCSB.dataTerminalReady ← FALSE;
TTYInCSB.requestToSend ← FALSE;
TTYCommand.command ← on;
-- set the defaults independent of what the IOP may think
WHILE TTYOutCommand.command >= putChar DO ENDLOOP; -- Wait for IOP to process command
TTYOutCSB.parameter ← state; TTYSetParameterCommand.command ← setAllParameters
END;

Off: PUBLIC PROC [CARDINAL] =
BEGIN
WHILE TTYOutCommand.command >= putChar DO ENDLOOP;
TTYOutCSB.notifyMask ← 0;
TTYCommand.command ← off;
state ← [onOff: off];
END;

InitializeCleanup: PROC =
BEGIN
item: DeviceCleanup.Item;
mask: WORD;
DO
reason: DeviceCleanup.Reason = DeviceCleanup.Await[@item];
IF state.onOff=on THEN SELECT reason FROM
turnOff, kill =>
BEGIN
THROUGH [0..LAST[CARDINAL]] WHILE TTYOutCommand.command >= putChar DO ENDLOOP;
IF TTYOutCommand.command >= putChar THEN {
  TTYOutCommand.command ← abortPut; -- the printer is stuck
WHILE TTYOutCommand.command >= putChar DO ENDLOOP;
  };
  mask ← TTYOutCSB.notifyMask; TTYOutCSB.notifyMask ← 0; TTYCommand.command ← off;
WHILE TTYOutCommand.command >= putChar DO ENDLOOP;
END;
turnOn =>
BEGIN
TTYOutCSB.notifyMask ← mask; TTYCommand.command ← on;
WHILE TTYOutCommand.command >= putChar DO ENDLOOP;
TTYOutCSB.parameter ← state; TTYSetParameterCommand.command ← setAllParameters;
END;
disconnect => NULL; -- turnOff was already called
ENDCASE;
ENDLOOP;
END;

-- Start Chain
-- Start: PUBLIC PROC = {RemainingHeads.Start[]};

-- Mainline code
InitializeCleanup[];

END....




LOG
Time: September 9, 1980 2:19 PM By: Ken Yamanaka Action: Created file
Time: September 11, 1980 10:30 PM By: Ken Yamanaka Action: Many Changes
Time: September 25, 1980 11:27 PM By: Forrest Action: maul Over
Time: October 16, 1980 11:42 AM By: Forrest Action: Add device cleanup (sigh)
Time: October 20, 1980 5:24 PM By: Forrest Action: redo setParameter and device cleanup
Time: 23-Jul-82 15:30:38 By: Jim Frandeen Action: New IOPage format
Time: 18-Aug-82 13:52:27 By: Jim Frandeen Action: Added SendBreak
Time: 16-Sep-82 10:11:34 By: Jim Frandeen Action: Save parameters for inload.
Time: 6-Oct-82 15:04:22 By: Jim Frandeen Action: Leave Break on for 190 msec. Initialize TTYInCSB in On command.
Time: 26-Sep-84 0:17:21 By: Grundler Action: Added copyright notice and rebuild for 11.1 release.