You are on page 1of 6

{Contains APhase, BPhase & CPhase as used in the main program for the

simple array based Turbo Pascal Executive. This program uses the other

units to produce an executable simulation}

Uses ExecVars, GenLib, ExecUtil, Model, Crt;

Procedure Aphase;

{Time scan by examining the Details array of records. Checks all entities

for which Avail is false. For these, finds those with the smallest timecells

and puts the number of the entity into the CurrEntArray}

Var Entity, Minm : Integer;

Begin

NumCurrEnts := 0;

Minm := MaxInt;

For Entity := 1 to NumEnts do

With Details[Entity] do

If Not Avail then

Begin

If Timecell <= Minm then

Begin

If TimeCell < Minm then NumCurrEnts := 1

Else NumCurrEnts := NumCurrEnts + 1;

Minm := TimeCell;

CurrEntArray[NumCurrEnts] := Entity;

Writeln(TraceFile. End. Clock := Minm. If Minm = MaxInt then Error('Error in A phase. For Loop := 1 to NumCurrEnts do Begin CurrEnt := CurrEntArray[Loop]. 'Time now . Clock:5). End. Minm -ve'). Executed after A phase and before C phase} Var Loop : Integer. End.. PrevClock := Clock. If Minm < 0 then Error('Seems to be a mistake in A phase. For each entity number stored in CurrEntArray. Procedure Bphase. Begin If TraceOn then Begin Writeln(TraceFile). '. End. {Works through the CurrEntArray. With Details[CurrEnt] do Begin . ShowEntDetails. Minm still = MaxInt'). executes the B activity indicated for that entity.

Until Not CStarted. Bphase. . UpDateScreen. {Release CurrEnt} NextAct. {Do this B Activity} End. For Loop := 1 to NumCs do CArray[Loop]. Avail := True. While Clock <= RunDuration do Begin Aphase. Begin Repeat CStarted := False. Procedure Cphase. Cphase. End. End. End. {Try each C activity in turn} Var Loop : Integer. ********************** Main Program ************************************* Begin {Main program} Initialisation.

ScreenDelay.MaxEnt] of EntDetails. Finalisation.. End. This is a unit which may be separately compiled. if one due} Util : Integer. {Utilisation time} End. {Max No of C Activities} Type BAct = Procedure. hence the $F+ compiler directive at the head of the unit} Const MaxEnt = 30. CheckInterrupt. {Next B activity. . {TimeCell} NextAct : BAct. Observations = Array[1. CAct = Procedure.. As procedural types are used. {Don't try more than 30 entities} MaxC = 10. {Indicates whether occupied} TimeCell : Integer. {Entity name for listings} Avail : Boolean. the compilation must force far calls. {Contains the global variables required by the simple array based Turbo Pascal executive. EntDetails = Record {Holds entity information} Name : String. End.100] of Integer. Var Details : Array[1.

{Used in CPhase for repeat scans} End. {Number of C Activities} CurrEntArray : Array[1. {Of the ExecVars unit} Procedure Schedule(Entity : Integer.MaxEnt] of Integer. {Entities due now} CurrEnt : Integer.MaxC] of Procedure. End. Util := Util + Round(RTime). PrevClock : Integer. {Commits specified entity to Activity after RTime} Begin With Details[Entity] do Begin Nextact := Activity. . Avail := False. NumCurrEnts : Integer. CArray : Array[1.. {Entity involved in current B} CStarted : Boolean. {Used in APhase & BPhase} Clock. Activity : BAct. {Length of run} NumEnts : Integer. RTime : Real). TimeCell := Clock + Round(RTime). {Current simulation time} RunDuration : Integer.. {Number of entities} NumCs : Integer.