home *** CD-ROM | disk | FTP | other *** search
- ' Program EX_0506.BAS
- ' Listing 11B - see documentation in TUTOR.SSS
-
- const ARRIVL = 1, STARTA = 2, ENDACT = 3, NEXTAC = 4
- const FINAL = 3
- const FALSE = 0, TRUE = not FALSE
-
- dim shared busy(1 to 3), block(1 to 3), defect(1 to 3)
-
- common shared ecode, statn, rewkn, debugf, serial
-
- declare sub waital ()
- declare sub prime ()
- declare sub deciph (i%)
- declare sub triggr (i)
- declare sub unblk (i%)
-
- rem $include: 'SSSB.H'
-
- prime
-
- f1$ = "####.###"
- f2$ = "####.##"
- f3$ = "###"
-
- do
- ecode = NEXTEV
- if ecode > 0 then
- select case ecode
-
- case ARRIVL
- if IDE > 0 then
- unblk IDE
- else
- CREATE EX(.5), 0
- SETA 1, RN(.25, .05)
- SETA 2, serial
- serial = serial + 1
- SCHED 0, NEXTAC, 0
- end if
-
- case NEXTAC
- deciph IDE
- if debugf then
- print using f1$; "At "; T; " #"; A(2);
- print using f2$; " for "; A(1);
- print "h. to station #";
- print using f3$; statn; " for "; rewkn;
- print " rework";
- end if
-
- if busy(statn) or block(statn) then
- QUEUE statn, 0
- if debugf then print " and waits"
- if NQ(statn) > 4 and statn > 1 then
- block(statn - 1) = TRUE
- end if
-
- else
- SCHED 0, STARTA, IDE
- if debugf then
- print " and processed"
- waital
- end if
- end if
-
- case STARTA
- deciph IDE
- if debugf then
- print using f1$; "At "; T; " #"; A(2);
- print " starts working at station #";
- print statn
- end if
- if rewkn = 0 then TALLY statn, 1
- busy(statn) = TRUE
- SCHED A(1), ENDACT, IDE
-
- case ENDACT
- deciph IDE
- TALLY statn, 0
- if debugf then
- print using f1$; "At "; T; " #"; A(2);
- print " ends work at "; statn; " and ";
- end if
- busy(statn) = FALSE
-
- if RA > defect(statn) then
- if statn = FINAL then
- DISPOS
- if debugf then print "discharged"
- else
- SETA 1, RN(.25, .05)
- SCHED 0, NEXTAC, statn
- if debugf then print "goes on"
- end if
-
- else
- SETA 1, A(1) / 2
- SCHED 0, NEXTAC, statn + 4 * (rewkn + 1) - 1
- if debugf then print "recycled"
- end if
- if debugf then
- print using f1$; "At"; T; " "; NQ(statn);
- print " are waiting at "; statn
- end if
- if NQ(statn) > 0 then triggr statn
-
- end select
- end if
- loop while ecode > 0
-
- title$ = " "
- SUMRY sadd(title$)
-
-
- sub deciph (i%)
- statn = 1 + (i% and 3)
- rewkn = i% \ 4
- end sub
-
- sub prime
- defect(1) = .3
- defect(2) = .2
- defect(3) = .1
- debugf = FALSE
- serial = 1
-
- INIQUE 3, 2, 3
- for i = 1 to 3
- busy(i) = FALSE
- block(i) = FALSE
- title$ = "Prod t #" + str$(i) + " "
- INISTA i, sadd(title$), 0, 0, 0, 0
- next i
- CREATE 0, 0
- SIMEND 6
- end sub
-
- sub triggr (i)
- REMVFQ i, 1
- SCHED 0, NEXTAC, IDE
- if i > 1 then CREATE 0, i - 1
- end sub
-
- sub unblk (i%)
- DISPOS
- if block(i%) then
- if NQ(i%) > 0 and (not busy(i%)) then triggr i
- block(i%) = FALSE
- end if
- end sub
-
- sub waital
- input "Press q to quit"; q$
- if left$(ucase$(q$), 1) = "Q" then stop
- end sub
-
-