XlEndianPrivate-PrincOps.mesa
Copyright Ó 1989, 1991 by Xerox Corporation. All rights reserved.
Christian Jacobi, February 1, 1989 2:52:14 pm PST
Christian Jacobi, March 7, 1991 4:14 pm PST
DIRECTORY Xl;
XlEndianPrivate--PrincOps--: CEDAR DEFINITIONS
SHARES Xl ~
BEGIN OPEN Xl;
Endian specific private types for Xl
Endian: TYPE = {lsbFirst, msbFirst};
Types consider byte order of host [here crazy dorado]
FourBytes: TYPE = MACHINE DEPENDENT RECORD [
lh, ll, hh, hl: BYTE
];
--byte order of host
TwoBytes: TYPE = MACHINE DEPENDENT RECORD [
hi, lo: BYTE
];
--byte order of host
Procs consider byte order used for X protocol [here big endian]
communicationByteOrder: Endian = msbFirst;
bitmapBitInByteOrder: Endian = msbFirst;
hhOff:  INT = 0;
hlOff:  INT = 1;
lHOff:  INT = 2;
llOff:  INT = 3;
highOff:  INT = 0;
lowOff:  INT = 1;
Byte0: PROC [n: CARD32] RETURNS [BYTE]
= INLINE { RETURN[LOOPHOLE[n, FourBytes].hh] };
Byte1: PROC [n: CARD32] RETURNS [BYTE]
= INLINE { RETURN[LOOPHOLE[n, FourBytes].hl] };
Byte2: PROC [n: CARD32] RETURNS [BYTE]
= INLINE { RETURN[LOOPHOLE[n, FourBytes].lh] };
Byte3: PROC [n: CARD32] RETURNS [BYTE]
= INLINE { RETURN[LOOPHOLE[n, FourBytes].ll] };
Byte0Of16: PROC [n: CARD16] RETURNS [BYTE]
= INLINE { RETURN[LOOPHOLE[n, TwoBytes].hi] };
Byte1Of16: PROC [n: CARD16] RETURNS [BYTE]
= INLINE { RETURN[LOOPHOLE[n, TwoBytes].lo] };
InlineGet8: PROC [c: Connection] RETURNS [BYTE] ~ INLINE {
byte: BYTE ~ ORD[c.getChar[c.recv]];
RETURN [byte]
};
InlineGet16: PROC [c: Connection] RETURNS [CARD16] ~ INLINE {
byte0: BYTE ~ ORD[c.getChar[c.recv]];
byte1: BYTE ~ ORD[c.getChar[c.recv]];
RETURN [byte0*256 + byte1]
};
InlineGet32: PROC [c: Connection] RETURNS [CARD32] ~ INLINE {
byte0: BYTE ~ ORD[c.getChar[c.recv]];
byte1: BYTE ~ ORD[c.getChar[c.recv]];
byte2: BYTE ~ ORD[c.getChar[c.recv]];
byte3: BYTE ~ ORD[c.getChar[c.recv]];
ln: FourBytes ~ [hh: byte0, hl: byte1, lh: byte2, ll: byte3];
RETURN [LOOPHOLE[ln]]
};
InlineGetText8: PROC [text: REF TEXT, startPos: NAT] RETURNS [BYTE] = INLINE {
RETURN [ORD[text[startPos]]]
};
InlineGetText16: PROC [text: REF TEXT, startPos: NAT] RETURNS [CARD16] = INLINE {
byte0: BYTE ~ ORD[text[startPos]];
byte1: BYTE ~ ORD[text[startPos+1]];
RETURN [byte0*256 + byte1]
};
InlineGetText32: PROC [text: REF TEXT, startPos: NAT] RETURNS [CARD32] = INLINE {
ln: FourBytes ~ [hh: ORD[text[startPos]], hl: ORD[text[startPos+1]], lh: ORD[text[startPos+2]], ll: ORD[text[startPos+3]]];
RETURN [LOOPHOLE[ln]]
};
InlineGetExtension8: PROC [e: ExtensionEvent, startPos: NAT] RETURNS [BYTE] = INLINE {
RETURN [e.bytes[startPos]]
};
InlineGetExtension16: PROC [e: ExtensionEvent, startPos: NAT] RETURNS [CARD16] = INLINE {
RETURN [e.bytes[startPos]*256 + e.bytes[startPos+1]]
};
InlineGetExtension32: PROC [e: ExtensionEvent, startPos: NAT] RETURNS [CARD32] = INLINE {
ln: FourBytes ~ [hh: e.bytes[startPos], hl: e.bytes[startPos+1], lh: e.bytes[startPos+2], ll: e.bytes[startPos+3]];
RETURN [LOOPHOLE[ln]]
};
InlinePut8: PROC [c: Connection, val: BYTE] ~ INLINE {
c.putChar[c.xmit, VAL[val]];
c.sent ¬ c.sent + 1
};
InlinePut16: PROC [c: Connection, val: CARD16] ~ INLINE {
c.putChar[c.xmit, VAL[Byte0Of16[val]]];
c.putChar[c.xmit, VAL[Byte1Of16[val]]];
c.sent ¬ c.sent + 2
};
InlinePut32: PROC [c: Connection, val: CARD32] ~ INLINE {
l: FourBytes ~ LOOPHOLE[val];
c.putChar[c.xmit, VAL[l.hh]];
c.putChar[c.xmit, VAL[l.hl]];
c.putChar[c.xmit, VAL[l.lh]];
c.putChar[c.xmit, VAL[l.ll]];
c.sent ¬ c.sent + 4
};
END.