-- FIFODriver.sak
-- last edited by Suzuki: 20-Nov-81 12:47:25 

DIRECTORY
	FIFO,
	Connector,
	Scheduler,
	SimIO,
	WF;

FIFODriver: MONITOR  
	IMPORTS 
		Connector, FIFO, Scheduler, SimIO, WF = {

Reader: DEVICE = {
	IN DataAv: BOOLEAN, DataOut: CARDINAL
	OUT ReadReq: BOOLEAN
	GUARDIAN {}
	STATE
	CONTROL {
	  WF.WF0["  Reader started.*n"];
	  THROUGH [0..50) DO
		Scheduler.Delay[10];
		UNTIL DataAv=TRUE DO 
			Scheduler.StandardDelay[] ENDLOOP;
		ReadReq ← TRUE;
		WF.WF1["%u  ", DataOut];
		Scheduler.Delay[5];
		ReadReq ← FALSE;
	  ENDLOOP;
	  WF.WF0["  Reader terminated.*n"];
	  Scheduler.ProcessEnd[]}
	};

Writer: DEVICE = {
	IN SpaceAv: BOOLEAN
	OUT WriteReq: BOOLEAN, DataIn: CARDINAL
	GUARDIAN {}
	STATE i: CARDINAL
	CONTROL {
	  WF.WF0[" Writer started.*n"];
	  FOR i IN [0..50) DO
		Scheduler.Delay[10];
		UNTIL SpaceAv=TRUE DO 
			Scheduler.StandardDelay[] ENDLOOP;
		DataIn ← i;
		WriteReq ← TRUE;
		WF.WF1["%u-  ", i];
		Scheduler.Delay[5];
		WriteReq ← FALSE;
	  ENDLOOP;
	  WF.WF0[" Writer terminated.*n"];
	  Scheduler.ProcessEnd[]}
	};

Start: DEVICE = {
	IN
	OUT Init, ReadReq, WriteReq: BOOLEAN
	GUARDIAN {}
	STATE
	CONTROL {
	  ReadReq ← FALSE;
	  WriteReq ← FALSE;
	  Scheduler.Delay[10];
	  Init ← TRUE;
	  Scheduler.Delay[5];
	  Init ← FALSE;
	  Scheduler.ProcessEnd[]}
	};

SimIO.Start["FIFO.jam"];
CIRCUIT {
  COMPONENTS fifo: FIFO.FIFOFunc[size: 100], reader: Reader, writer: Writer, start: Start
  NODES init, write, read, in, space, data, out: NODE
  REPRESENTATION
  CONNECTIONS
    fifo[Init: init, WriteRequest: write, ReadRequest: read,
		DIn: in, SpaceAv: space, DataAv: data, DOut: out],
    reader[DataAv: data, DataOut: out, ReadReq: read],
    writer[SpaceAv: space, WriteReq: write, DataIn: in],
    start[Init: init, ReadReq: read, WriteReq: write]};
SimIO.Stop[];
}.