Download as pdf or txt
Download as pdf or txt
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;
End;

End;

If Minm = MaxInt then Error('Error in A phase, Minm still = MaxInt');

If Minm < 0 then Error('Seems to be a mistake in A phase, Minm -ve');

PrevClock := Clock;

Clock := Minm;

End;

Procedure Bphase;

{Works through the CurrEntArray. For each entity number stored in CurrEntArray,

executes the B activity indicated for that entity. Executed after A phase

and before C phase}

Var Loop : Integer;

Begin

If TraceOn then

Begin

Writeln(TraceFile);

Writeln(TraceFile, 'Time now .. ', Clock:5);

End;

ShowEntDetails;

For Loop := 1 to NumCurrEnts do

Begin

CurrEnt := CurrEntArray[Loop];

With Details[CurrEnt] do

Begin
Avail := True; {Release CurrEnt}

NextAct; {Do this B Activity}

End;

End;

End;

Procedure Cphase;

{Try each C activity in turn}

Var Loop : Integer;

Begin

Repeat

CStarted := False;

For Loop := 1 to NumCs do CArray[Loop];

Until Not CStarted;

End;

********************** Main Program *************************************

Begin {Main program}

Initialisation;

While Clock <= RunDuration do

Begin

Aphase;

Bphase;

Cphase;

UpDateScreen;
ScreenDelay;

CheckInterrupt;

End;

Finalisation;

End.

{Contains the global variables required by the simple array based Turbo

Pascal executive. This is a unit which may be separately compiled.

As procedural types are used, the compilation must force far calls, hence

the $F+ compiler directive at the head of the unit}

Const MaxEnt = 30; {Don't try more than 30 entities}

MaxC = 10; {Max No of C Activities}

Type BAct = Procedure;

CAct = Procedure;

Observations = Array[1..100] of Integer;

EntDetails = Record {Holds entity information}

Name : String; {Entity name for listings}

Avail : Boolean; {Indicates whether occupied}

TimeCell : Integer; {TimeCell}

NextAct : BAct; {Next B activity, if one due}

Util : Integer; {Utilisation time}

End;

Var Details : Array[1..MaxEnt] of EntDetails;


CArray : Array[1..MaxC] of Procedure;

NumCurrEnts : Integer; {Used in APhase & BPhase}

Clock, PrevClock : Integer; {Current simulation time}

RunDuration : Integer; {Length of run}

NumEnts : Integer; {Number of entities}

NumCs : Integer; {Number of C Activities}

CurrEntArray : Array[1..MaxEnt] of Integer; {Entities due now}

CurrEnt : Integer; {Entity involved in current B}

CStarted : Boolean; {Used in CPhase for repeat scans}

End. {Of the ExecVars unit}

Procedure Schedule(Entity : Integer;

Activity : BAct;

RTime : Real);

{Commits specified entity to Activity after RTime}

Begin

With Details[Entity] do

Begin

Nextact := Activity;

TimeCell := Clock + Round(RTime);

Avail := False;

Util := Util + Round(RTime);

End;

You might also like