--NXUtil.mesa (Last edit by: Gobbel on: December 19, 1980 9:41 PM)
-- Last modified December 14, 1983 3:12 PM by Taft
DIRECTORY
BufferDefs USING [PupBuffer],
IODefs USING [CR, DEL, ReadChar, WriteChar, WriteLine, WriteString],
MMOps USING [BootDMT],
OsStaticDefs USING [OsStatics],
NXDefs USING [displayLines, SetIntoHost, SetIntoTime],
ProcessDefs USING [MsecToTicks, Pause, SecondsToTicks, SetTimeout, Yield],
PupDefs USING [
AppendPupAddress, GetFreePupBuffer, GetPupAddress, PupAddress, PupAddressLookup, PupNameTrouble, PupRouterBroadcastThis, PupSocket, PupSocketMake, ReturnFreePupBuffer, SecondsToTocks, SetPupContentsWords, UniqueLocalPupSocketID],
PupTypes USING [fillInPupAddress, miscSrvSoc, PupSocketID],
StringDefs USING [AppendChar, AppendString],
TimeDefs USING [
AppendDayTime, currentParameters, currentTime, CurrentDayTime, PackedTime, UnpackDT, UnpackedTime, WestEast];
NXUtil: MONITOR
IMPORTS IODefs, MMOps, NXDefs, ProcessDefs, PupDefs, StringDefs, TimeDefs
EXPORTS NXDefs =
BEGIN
UserAbort: PUBLIC SIGNAL = CODE; -- means we got a negative reply to "More?" question
lineCount: CARDINAL;
Line: PUBLIC PROCEDURE [str: STRING] =
{More[]; IODefs.WriteLine[str]};
LineReset: PUBLIC PROCEDURE [str: STRING] =
{lineCount ← 1; IODefs.WriteLine[str]};
NewLine: PUBLIC PROCEDURE =
{More[]; IODefs.WriteChar[IODefs.CR]};
More: PROCEDURE =
BEGIN
IF lineCount=NXDefs.displayLines-2 THEN
BEGIN
c: CHARACTER;
IODefs.WriteChar[IODefs.CR];
IODefs.WriteString["More? "L];
c ← IODefs.ReadChar[];
IF c=’N OR c=’n OR c=IODefs.DEL THEN
{IODefs.WriteChar[IODefs.CR]; SIGNAL UserAbort};
lineCount ← 1;
END;
lineCount ← lineCount+1;
END;
SetTime: PUBLIC PROC--ESS-- =
BEGIN OPEN BufferDefs, PupDefs, PupTypes, TimeDefs;
TimeReply: TYPE = RECORD [
time: PackedTime,
zone: RECORD [
direction: TimeDefs.WestEast,
unused1: [0..7B],
hours: [0..12],
unused2: [0..3B],
minutes: [0..59]],
dstBegin: CARDINAL,
dstEnd: CARDINAL];
timeP: POINTER TO TimeReply;
me: PupSocketID ← UniqueLocalPupSocketID[];
socket: PupSocket ← PupSocketMake[me, fillInPupAddress, SecondsToTocks[2]];
buffer: PupBuffer;
THROUGH [1..5] DO
buffer ← GetFreePupBuffer[];
buffer.source.socket ← me;
buffer.dest.socket ← miscSrvSoc;
buffer.pupType ← dateAltoRequest;
SetPupContentsWords[buffer, 0];
PupRouterBroadcastThis[buffer];
DO
buffer ← socket.get[];
IF buffer=NIL THEN EXIT;
timeP ← LOOPHOLE[@buffer.pupBody];
IF buffer.pupType=dateAltoIs THEN
BEGIN
TimeDefs.currentTime↑ ← LOOPHOLE[timeP.time];
TimeDefs.currentParameters.direction ← timeP.zone.direction;
TimeDefs.currentParameters.zone ← timeP.zone.hours;
TimeDefs.currentParameters.zoneminutes ← timeP.zone.minutes;
TimeDefs.currentParameters.beginDST ← timeP.dstBegin;
TimeDefs.currentParameters.endDST ← timeP.dstEnd;
END;
ReturnFreePupBuffer[buffer];
ProcessDefs.Yield[];
ENDLOOP;
ProcessDefs.Yield[];
ENDLOOP;
END;
userAction: BOOLEAN FALSE;
userActionOrFiveMinutes: CONDITION;
NoteUserAction: PUBLIC ENTRY PROC =
{userAction ← TRUE; BROADCAST userActionOrFiveMinutes};
WatchDog: PUBLIC ENTRY PROC--ESS-- =
BEGIN OPEN ProcessDefs;
userActionOrFiveMinutes: CONDITION;
DO
SetTimeout[@userActionOrFiveMinutes, 5*MsecToTicks[60000]]; -- 5 minutes
WAIT userActionOrFiveMinutes;
IF ~userAction THEN MMOps.BootDMT[];
userAction ← FALSE;
ENDLOOP;
END;
Timer: PUBLIC ENTRY PROC--ESS-- =
BEGIN OPEN NXDefs, ProcessDefs, StringDefs, TimeDefs;
dayNames: ARRAY [0..6] OF STRING =
["Monday"L, "Tuesday"L, "Wednesday"L, "Thursday"L, "Friday"L, "Saturday"L, "Sunday"L];
timeLength: CARDINAL = 35;
am: BOOLEAN;
i, fillLength: CARDINAL;
unpTime: UnpackedTime;
oneSecond: CONDITION;
tempStr: STRING ← [timeLength];
timeStr: STRING ← [timeLength];
SetTimeout[@oneSecond, MsecToTicks[1000]];
DO
timeStr.length ← tempStr.length ← 0;
unpTime ← UnpackDT[CurrentDayTime[]];
AppendString[tempStr, dayNames[unpTime.weekday]]; AppendChar[tempStr, ’ ];
am ← unpTime.hour<12; IF unpTime.hour>12 THEN unpTime.hour ← unpTime.hour-12;
AppendDayTime[tempStr, unpTime];
AppendString[tempStr, IF am THEN " am"L ELSE " pm"L];
fillLength ← timeLength-tempStr.length;
FOR i IN [0..fillLength/2) DO AppendChar[timeStr, ’-] ENDLOOP;
AppendChar[timeStr, ’ ]; AppendString[timeStr, tempStr]; AppendChar[timeStr, ’ ];
FOR i IN [timeStr.length..timeLength) DO AppendChar[timeStr, ’-] ENDLOOP;
SetIntoTime[timeStr];
WAIT oneSecond;
ENDLOOP;
END;
Host: PUBLIC PROC--ESS-- =
BEGIN OPEN NXDefs, OsStaticDefs, PupDefs, PupTypes, StringDefs;
processorNames: ARRAY [0..5] OF STRING
[" AltoI"L, " AltoI"L, " AltoII"L, " AltoIIX"L, " Dolphin"L, " Dorado"L];
hostLength: CARDINAL = 45;
me: PupAddress;
myName: STRING ← [20];
hostString: STRING ← [hostLength];
tempString: STRING ← [hostLength+5];
FOR tries: CARDINAL IN [0..10) DO
me ← fillInPupAddress;
GetPupAddress[@me, "ME"L ! PupNameTrouble => {
ProcessDefs.Pause[ProcessDefs.SecondsToTicks[1]]; RETRY}];
IF me.net#0 THEN EXIT;
ProcessDefs.Pause[ProcessDefs.SecondsToTicks[1]];
ENDLOOP;
PupAddressLookup[myName, me
! PupNameTrouble =>
{myName ← "NoName"L; CONTINUE}];
hostString.length ← tempString.length ← 0;
AppendString[tempString, processorNames[OsStatics.AltoVersion.engineeringnumber]];
AppendString[tempString, " ["L];
AppendString[tempString, myName];
AppendString[tempString, "] "L];
AppendPupAddress[tempString, me];
tempString[tempString.length-1] ← ’ ;
THROUGH [0..(hostLength-tempString.length)/2) DO AppendChar[hostString, ’-] ENDLOOP;
AppendString[hostString, tempString];
THROUGH [hostString.length..hostLength) DO AppendChar[hostString, ’-] ENDLOOP;
SetIntoHost[hostString];
END;
END...