%%% Coroutine E %%% E1 SET dormant,on PUSHJ $0,:Log:E1 %%hide TRIP Pause,0,0 \ul{\sl E1. Wait for call.} (no action) SET dormant,off TRIP DelayI,20 Get ready. BZ state,E3 JMP E6 %%% E2 TRIP Send,Arrival,0 \ul{\sl E2. Change of state.} Tell supervisor. OR $0,callup,calldown OR $0,$0,callcar PUSHJ $1,:Log:E2 %%hide BN state,1F ADD $1,floor,1 If going up, SR $2,$0,$1 focus on upper floors. BNZ $2,E3 Jump if there are calls on higher floors. NEG $1,64,floor If not, have passengers in the SL $2,callcar,$1 elevator called for lower floors? JMP 2F %%% 1H NEG $1,64,floor If going down, SL $2,$0,$1 focus on lower floors. BNZ $2,E3 Jump if there are calls on lower floors. ADD $1,floor,1 If not, have passengers in the SR $2,callcar,$1 elevator called for upper floors? %%% 2H NEG state,state Then, reverse direction of state. ANDN callup,callup,floorBit Clear buttons on current floor. ANDN calldown,calldown,floorBit ANDN callcar,callcar,floorBit CSZ state,$2,0 Set state to neutral, if not called in the other direction. %%% E3 PUSHJ $0,:Log:E3 %%hide PUSHJ $0,Loading %%hide %% &E3 &PUSHJ &\$0,Loading &\ul{\sl E3. Open doors.} Start loading.\cr TRIP DelayI,20 Opening takes 20 units. %%% TRIP DelayI,56 Keep door open. TRIP DelayI,0 Give liftboy a chance to finish loading. %%% E5 BZ loading,0F \ul{\sl E5. Close doors.} PUSHJ $0,:Log:E5f %%hide TRIP DelayI,40 If people are still getting in or out, JMP E5 wait 40 units and repeat E5. 0H PUSHJ $0,:Log:E5 %%hide 0H SET waiting,off If not loading, stop waiting. SET closing,on TRIP DelayI,20 Closing takes 20 units. SET closing,off %%% E6 ANDN callcar,callcar,floorBit \ul{\sl E6. Prepare to move.} Reset callcar on this floor. ZSNN $1,state,floorBit If not going down ANDN callup,callup,$1 \qquad reset callup on this floor. ZSNP $1,state,floorBit If not going up ANDN calldown,calldown,$1 \qquad reset calldown on this floor. PUSHJ $0,Decision Perform Decision subroutine. E6B BZ state,E1 If \.{state} is neutral go to E1. PUSHJ $1,:Log:E6 %%hide TRIP DelayI,15 Build up some speed. BN state,E8 If going down, go to E8. %%% E7 PUSHJ $0,Log:E7 %%hide ADD floor,floor,1 %%hide %% &E7 &ADD &floor,floor,1 &\ul{\sl E7. Go up a floor.}\cr SL floorBit,floorBit,1 TRIP DelayI,51 Travel up takes 51 units. OR $1,callcar,callup AND $2,$1,floorBit Is callcar or callup on? BNZ $2,1F CMP $2,floor,2 BZ $2,2F If not, is $\.{floor}=2$? AND $2,calldown,floorBit If not is calldown on this floor on? BZ $2,E7 If not, repeat step E7. 2H OR $1,$1,calldown ADD $2,floor,1 SR $1,$1,$2 BNZ $1,E7 Are there calls for higher floors? 1H TRIP DelayI,14 Deceleration takes 14 units. JMP E2 It is time to stop the elevator.\lineref|beforeex8p| %%% %%\omit\hfil$\vcenter{\vskip -3.5pt\medskip\vdots\medskip}$&&&&(See exercise 8.)\cr %%off [[INCLUDE exercise8.mms]] %%on %%\noalign{\lastmmsline{|lastex8p|}} %%% %%off