DIRECTORY Cucumber, IntTypes, IO, Process, Rope, Rosemary, RoseClocks, ViewRec; RoseClocksImpl: CEDAR MONITOR IMPORTS Cucumber, IO, IntTypes, Process, Rosemary, VR: ViewRec EXPORTS RoseClocks = BEGIN OPEN IntTypes, RoseClocks; ROPE: TYPE = Rope.ROPE; Cell: TYPE = Rosemary.Cell; ClockInitData: TYPE = REF ClockInitDataRec; ClockInitDataRec: PUBLIC TYPE = RECORD [ sense: Sense, style: Style ]; Init: PUBLIC PROC [sense: Sense _ ActiveHigh, style: Style _ TwoStep] RETURNS [id: ClockInitData] = {RETURN [NEW [ClockInitDataRec _ [sense, style]]]}; ClockGenIORef: TYPE = REF ClockGenIORec; ClockGenIORec: TYPE = MACHINE DEPENDENT RECORD [ fill1(0:0..14): [0..32767], phi1(0:15..15): BOOLEAN, fill2(1:0..14): [0..32767], phi2(1:15..15): BOOLEAN]; ClockState: TYPE = REF ClockStateRep; ClockStateRep: TYPE = RECORD [ init: ClockInitData, display: Display, rv: VR.RecordViewer, cell, root: Cell, notice: CONDITION, stopResponse: StopResponse _ Abort]; StopResponse: TYPE = {Resume, Abort}; Display: TYPE = REF DisplayRep; DisplayRep: TYPE = RECORD [ sofar: INTEGER, state: State, status: Status _ Normal, Cycle: PROC [cell: Cell, cycles: CARDINAL], Step: PROC [cell: Cell], Interrupt: PROC, Proceed, Abort: PROC [cell: Cell] ]; State: TYPE = [0..6); Status: TYPE = {Normal, Interrupted}; clockHandler: Cucumber.Handler _ NEW [Cucumber.HandlerRep _ [ PrepareWhole: PrepareClock, PartTransfer: TransferClock]]; displayHandler: Cucumber.Handler _ NEW [Cucumber.HandlerRep _ [ PartTransfer: TransferDisplay]]; PrepareClock: Cucumber.Bracket--PROC [whole: REF ANY, where: IO.STREAM, direction: Direction, data: REF ANY] RETURNS [leaveTheseToMe: SelectorList _ NIL]-- = {leaveTheseToMe _ LIST[$notice]}; TransferClock: Cucumber.PartTransferProc = UNCHECKED BEGIN cs: ClockState _ NARROW[whole]; SELECT part.first FROM $init, $rv, $cell, $root, $notice => NULL; $display => Cucumber.Transfer[what: cs.display, where: where, direction: direction]; ENDCASE => ERROR Cucumber.Error[IO.PutFR["Unexpected field %g in Clock State", IO.atom[NARROW[part.first]]]]; END; TransferDisplay: Cucumber.PartTransferProc = {}; CreateClockGenIO: Rosemary.IOCreator = BEGIN cell.realCellStuff.oldIO _ NEW [ClockGenIORec]; cell.realCellStuff.newIO _ NEW [ClockGenIORec]; END; InitializeClockGen: Rosemary.Initializer = BEGIN cgi: ClockInitData _ NARROW[initData]; newIO: ClockGenIORef _ NARROW[cell.realCellStuff.newIO]; oldIO: ClockGenIORef _ NARROW[cell.realCellStuff.oldIO]; [newIO.phi1, newIO.phi2] _ StateToBits[cgi.sense][Initial[cgi.style]]; IF leafily THEN TRUSTED BEGIN display: Display _ NEW [DisplayRep _ [ sofar: 0, state: Initial[cgi.style], Cycle: DoCycle, Step: DoStep, Interrupt: Interrupt, Proceed: Proceed, Abort: Abort ]]; cs: ClockState _ NEW [ClockStateRep _ [ init: cgi, display: display, cell: cell, root: RootCell[cell] ]]; cell.realCellStuff.state _ cs; Process.InitializeCondition[ condition: @cs.notice, ticks: Process.SecondsToTicks[5]]; cs.rv _ VR.ViewRef[ agg: display, specs: CONS[["state", Value[val: NIL, visible: TRUE, dontAssign: TRUE]], CONS[["sofar", Value[val: NIL, visible: TRUE, dontAssign: TRUE]], CONS[["status", Value[val: NIL, visible: TRUE, dontAssign: TRUE]], VR.BindAllOfATypeFromRefs[rec: display, handle: NEW [Cell _ cell]] ]]], viewerInit: [name: cell.LongCellName[], iconic: FALSE], createOptions: [exclusiveProcs: FALSE]]; END; END; RootCell: PROC [cell: Cell] RETURNS [root: Cell] = {FOR root _ cell, root.parent WHILE root.parent # NIL DO NULL ENDLOOP}; Initial: ARRAY Style OF State = [5, 0]; ClockGenEval: Rosemary.EvalProc = {}; Interrupt: PROC = {Rosemary.stop _ TRUE}; Proceed: ENTRY PROC [cell: Cell] = BEGIN cs: ClockState _ NARROW[cell.realCellStuff.state]; cs.stopResponse _ Resume; cs.display.status _ Normal; BROADCAST cs.notice; END; Abort: ENTRY PROC [cell: Cell] = BEGIN cs: ClockState _ NARROW[cell.realCellStuff.state]; cs.stopResponse _ Abort; cs.display.status _ Normal; BROADCAST cs.notice; END; GetStopResponse: ENTRY PROC [cell: Cell, msg: ROPE, data: REF ANY] RETURNS [sr: StopResponse] = BEGIN cs: ClockState _ NARROW[cell.realCellStuff.state]; Rosemary.NotifyGlobalEvent[$Stop]; cs.display.status _ Interrupted; cs.rv.DisplayMessage[msg]; WHILE cs.display.status = Interrupted DO WAIT cs.notice; ENDLOOP; Rosemary.stop _ FALSE; sr _ cs.stopResponse; Rosemary.NotifyGlobalEvent[$Start]; END; DoStep: PROC [cell: Cell] = BEGIN Rosemary.NotifyGlobalEvent[$Start]; Step[cell !UNWIND => Rosemary.NotifyGlobalEvent[$Stop]]; Rosemary.NotifyGlobalEvent[$Stop]; END; Step: PUBLIC PROC [cell: Cell] = BEGIN DoIt: Rosemary.ModifyProc = BEGIN cs: ClockState _ NARROW[cell.realCellStuff.state]; newIO: ClockGenIORef _ NARROW[cell.realCellStuff.newIO]; cs.display.state _ Transitions[cs.display.state]; [newIO.phi1, newIO.phi2] _ StateToBits[cs.init.sense][cs.display.state]; END; cell.AllowToModify[DoIt]; cell.RootStructure[].Run[ !Rosemary.Stop => CHECKED BEGIN SELECT GetStopResponse[cell, msg, data] FROM Resume => RESUME; Abort => ERROR ABORTED; ENDCASE => ERROR; END]; END; DoCycle: PROC [cell: Cell, cycles: CARDINAL] = BEGIN Rosemary.NotifyGlobalEvent[$Start]; Cycle[cell, cycles !UNWIND => Rosemary.NotifyGlobalEvent[$Stop]]; Rosemary.NotifyGlobalEvent[$Stop]; END; Cycle: PUBLIC PROC [cell: Cell, cycles: CARDINAL] = BEGIN cs: ClockState _ NARROW[cell.realCellStuff.state]; cs.display.sofar _ 0; DO IF cs.display.state = TestTime[cs.init.style] THEN BEGIN IF cycles < 1 THEN EXIT; cycles _ cycles - 1; cs.display.sofar _ cs.display.sofar + 1; END; Step[cell]; IF cs.display.state = EndTime[cs.init.style] THEN cs.root.NotifyCellEvent[$EndOfClockCycle !Rosemary.Stop => CHECKED BEGIN SELECT GetStopResponse[cell, msg, data] FROM Resume => RESUME; Abort => ERROR ABORTED; ENDCASE => ERROR; END]; ENDLOOP; END; TestTime: ARRAY Style OF State = [5, 0]; EndTime: ARRAY Style OF State = [5, 3]; Transitions: ARRAY State OF State = [1, 2, 3, 0, 5, 4]; StateToBits: ARRAY Sense OF ARRAY State OF RECORD [BOOL, BOOL] = [ [ [FALSE, FALSE], [TRUE, FALSE], [FALSE, FALSE], [FALSE, TRUE], [TRUE, FALSE], [FALSE, TRUE] ], [ [TRUE, TRUE], [FALSE, TRUE], [TRUE, TRUE], [TRUE, FALSE], [FALSE, TRUE], [TRUE, FALSE] ] ]; Setup: PROC = BEGIN clockGenPorts: Rosemary.Ports _ NEW [Rosemary.PortsRep[2]]; clockGenPorts[0] _ [firstWord: 0, wordCount: 1, name: "PhaseA", type: IntType[1], output: TRUE]; clockGenPorts[1] _ [firstWord: 1, wordCount: 1, name: "PhaseB", type: IntType[1], output: TRUE]; Rosemary.RegisterCellClass[ className: "ClockGen", expandProc: NIL, ioCreator: CreateClockGenIO, initializer: InitializeClockGen, evalProc: ClockGenEval, ports: clockGenPorts]; clockHandler.Register[CODE[ClockStateRep]]; displayHandler.Register[CODE[DisplayRep]]; END; Setup[]; END. zRoseClocksImpl.Mesa Last Edited by: Spreitzer, October 3, 1983 1:48 pm Last Edited by: Barth, June 9, 1983 11:09 am Κ k˜J™J™2J™,Icode˜šΟk ˜ Kšœœ/˜E—K˜šΠbxœœ˜Kšœ œœ ˜>Kšœ ˜—K˜Kšœœ˜ K˜Kšœœœ˜Kšœœ˜K˜Kšœœœ˜+šœœœœ˜(Kšœ ˜ K˜ K˜—K˜šΟnœœœ5œ˜cKšœœœ'˜3—K˜Kšœœœ˜(š œœœ œœ˜0Kšœ˜Kšœœ˜K˜Kšœœ˜—K˜Kšœ œœ˜%šœœœ˜K˜K˜Kšœœ˜K˜Kšœ œ˜Kšœ$˜$—K˜Kšœœ˜%K˜Kšœ œœ ˜šœ œœ˜Kšœœ˜Kšœ ˜ K˜KšŸœœœ˜+KšŸœœ˜KšŸ œœ˜KšŸœŸœœ˜$—K˜Kšœœ ˜K˜Kšœœ˜%K˜šœ!œ˜=Kšœ˜K˜—K˜šœ#œ˜?K˜ —K˜šŸ œΟc}œ˜Kšœœ ˜!—K˜šŸ œ ˜4Kš˜Kšœœ˜šœ ˜Kšœ%œ˜*K˜TKš œœœ-œœ˜m—Kšœ˜—K˜KšŸœ!˜0K˜šŸœ˜&Kš˜Kšœœ˜/Kšœœ˜/Kšœ˜—K˜šŸœ˜*Kš˜Kšœœ ˜&Kšœœ˜8Kšœœ˜8KšœF˜Fšœ ˜Kšœ˜ šœœ˜&K˜ K˜K˜K˜ K˜K˜K˜—šœœ˜'K˜ K˜K˜ K˜—Kšœ˜˜K˜K˜"—šœœ ˜K˜ š œœœ œœ˜HKšœœ œœ˜AKšœœ œœ˜BKšœ.œ˜G—Kšœ0œ˜7Kšœ œ˜(—Kšœ˜—Kšœ˜—K˜šŸœœœ˜2Kš œœœœœœœ˜G—K˜Kšœ œœ˜'K˜KšŸ œ˜%K˜KšŸ œœœ˜)K˜šŸœœœ˜"Kš˜Kšœœ˜2Kšœ˜Kšœ˜Kš œ ˜Kšœ˜—K˜šŸœœœ˜ Kš˜Kšœœ˜2Kšœ˜Kšœ˜Kš œ ˜Kšœ˜—K˜šŸœœœœœœœ˜_Kš˜Kšœœ˜2K˜"Kšœ ˜ Kšœ˜šœ!˜(Kšœ ˜Kšœ˜—Kšœœ˜Kšœ˜Kšœ#˜#Kšœ˜—K˜šŸœœ˜Kš˜Kšœ#˜#Kšœ œ'˜8K˜"Kšœ˜—K˜šŸœœœ˜ Kš˜šŸœ˜Kš˜Kšœœ˜2Kšœœ˜8Kšœ1˜1KšœH˜HKšœ˜—Kšœ˜˜šœ˜Kš˜šœ"˜,Kšœ œ˜Kšœ œœ˜Kšœœ˜—Kšœ˜——Kšœ˜—K˜šŸœœœ˜.Kš˜Kšœ#˜#Kšœœ'˜AK˜"Kšœ˜—K˜šŸœœœœ˜3Kš˜Kšœœ˜2K˜š˜šœ,˜2Kš˜Kšœ œœ˜K˜K˜(Kšœ˜—Kšœ ˜ šœ+œ)˜Zšœ˜Kš˜šœ"˜,Kšœ œ˜Kšœ œœ˜Kšœœ˜—Kšœ˜——Kšœ˜—Kšœ˜—K˜Kšœ œœ˜(K˜Kšœ œœ˜'K˜Kšœ œœ˜7K˜šœ œœœœœœœ˜@šœ˜šœ˜Kšœœœ˜Kšœœœ˜Kšœœœ˜Kšœœœ˜Kšœœœ˜Kšœœœ˜—˜Kšœœœ˜ Kšœœœ˜Kšœœœ˜ Kšœœœ˜Kšœœœ˜Kšœœœ˜———K˜šŸœœ˜ Kš˜Kšœ œ˜;K˜Kšœ[œ˜aKšœZœ˜`K˜˜K˜Kšœ œ˜K˜K˜ K˜K˜—K˜Kšœœ˜+Kšœœ˜*Kšœ˜—K˜K˜K˜Kšœ˜—…—X$=