%%% Coroutine E %%% E1A PUSHJ $0,:LogE1 %%hide TRIP Cycle1,0 %%hide %% &E1A &TRIP &Cycle1,0 &Set NextInst to E1, goto Cycle.\cr E1 IS @ \ul{\sl E1. Wait for call.} (no action) E2A TRIP HoldC,0 Decelerate. E2 OR $0,callup,calldown \ul{\sl E2. Change of state.} OR $0,$0,callcar PUSHJ $1,:LogE2 %%hide BN state,1F ADD $1,floor,1 SR $2,$0,$1 BNZ $2,E3 There are calls on higher floors. NEG $1,64,floor If not, have passengers in the SL $2,callcar,$1 \qquad elevator called for lower floors? JMP 2F %%% 1H NEG $1,64,floor going down SL $2,$0,$1 BNZ $2,E3 There are calls on lower floors. ADD $1,floor,1 If not, have passengers in the SR $2,callcar,$1 \qquad elevator called for upper floors? %%% 2H NEG state,state Reverse direction of state SL $0,on,floor ANDN callup,callup,$0 ANDN calldown,calldown,$0 ANDN callcar,callcar,$0 CSZ state,$2,0 Set state to neutral if not called in the other direction. %%% E3 LDA C,Elev3 \ul{\sl E3. Open doors.} PUSHJ $0,:LogE3 %%hide LDO $0,C,LLink1 \lineref|NullLLink| BZ $0,1F If activity E9 is already scheduled, PUSHJ $0,DeleteW \qquad remove it from the Wait list. 1H SET dt,300 PUSHJ $0,Hold Schedule activity E9 after 300 units. LDA C,Elev2 SET dt,76 PUSHJ $0,Hold Schedule activity E5 after 76 units. SET bussy,on SET loading,on SET dt,20 E4A LDA C,Elev1 TRIP HoldC,0 E4 LDA $0,Elevator \ul{\sl E4. Open doors.} LDA C,Elevator $C\is \.{Elevator}$ 1H LDOU C,C,LLink2 $C\is C_{\.{LLink2}}$ CMP $1,C,$0 BZ $1,1F If $C=\.{Elevator}$, search is complete. LDB $1,C,Out CMP $1,$1,floor Compare $C_{\.{Out}}$ with \.{floor} BNZ $1,1B If not equal, continue searching; GETA $0,U6 \qquad otherwise prepare to send user to U6. JMP 2F %%% 1H 16ADDU $0,floor,Queue LDOU C,$0,RLink2 $C\is \.{Queue}[\.{floor}]_{\.{RLink2}}$ LDOU $1,C,RLink2 CMP $1,$1,C Is $C=C_{\.{RLink2}}$? BZ $1,1F If so, the queue is empty. PUSHJ $0,DeleteW If not, cancel action U4 for this user. GETA $0,U5 Prepare to replace U4 by U5. 2H STOU $0,C,NextInst Set NextInst of $C$. PUSHJ $0,Immed Put user at the front of the Wait List. SET dt,25 JMP E4A Wait 25 units and repeat E4. 1H SET loading,off SET waiting,on PUSHJ $1,:LogE4 %%hide TRIP Cycle,0 %%% E5 BZ loading,0F \ul{\sl E5. Close doors.} PUSHJ $0,:LogE5f %%hide TRIP HoldCI,40 If people are still getting in or out, JMP E5 wait 40 units and repeat E5. 0H SET waiting,off If not loading, stop waiting. PUSHJ $0,:LogE5 %%hide LDA C,Elev1 TRIP HoldCI,20 Wait 20 units, then go to E6. %%% E6 SL $0,on,floor \ul{\sl E6. Prepare to move.} ANDN callcar,callcar,$0 Reset callcar on this floor. ZSNN $1,state,$0 If not going down ANDN callup,callup,$1 \qquad reset callup on this floor. ZSNP $1,state,$0 If not going up ANDN calldown,calldown,$1 \qquad reset calldown on this floor. PUSHJ $0,Decision Perform Decision subroutine. E6B BZ state,E1A If state=neutral, go to E1 and wait. BZ bussy,0F PUSHJ $1,:LogE6 %%hide LDA C,Elev3 If bussy, PUSHJ $0,DeleteW \qquad cancel activity E9 STCO 0,C,LLink1 \qquad (see line |NullLLink|). 0H LDA C,Elev1 TRIP HoldCI,15 Wait 15 units of time. BN state,E8 If going down, go to E8 E7 PUSHJ $0,LogE7 %%hide ADD floor,floor,1 %%hide %% &E7 &ADD &floor,floor,1 &\ul{\sl E7. Go up a floor.}\cr TRIP HoldCI,51 Wait 51 units. SL $0,on,floor OR $1,callcar,callup AND $2,$1,$0 Is callcar or callup on? BNZ $2,1F CMP $2,floor,2 BZ $2,2F If not, is $\.{floor}=2$? AND $2,calldown,$0 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 SET dt,14 It is time to stop the elevator. JMP E2A Wait 14 units and go to E2\lineref|beforeex8| %%% %%\omit\hfil$\vcenter{\vskip -3.5pt\medskip\vdots\medskip}$&&&&(See exercise 8.)\cr %%off [[INCLUDE exercise8.mms]] %%on %%\noalign{\lastmmsline{|lastex8|}} %%% E9 STCO 0,C,LLink1 \ul{\sl E9. Set inaction indicator.} (See line |NullLLink|.) SET bussy,off PUSHJ $0,Decision TRIP Cycle,0 Return to simulation of other events. %%off