/* 
 * FIFO.java  (First In First Out Victim Frame search.)
 *
 * Written by : Nitin  Motgi (nmotgi@cs.ucf.edu)
 *
 * Portions copyright(c) 2001 to School of Electrical Engineering and 
 * Computer Science, UCF, Orlando.                   
 *                                    
 * Use and distribution of this source code are strictly governed by 
 * terms and conditions set by the authors.
 * 
 * $Id : FIFO.java, v1.0.0 02/24/2001. $
 *            
 * Revision History:
 *
 * 1. Created basic structure           Nitin,        v1.0.0  03/12/2001.
 * 2. Added Documentation.              Nitin,        v1.0.1  03/12/2001.
 * 3. Final Documentation Check.        Nitin,        v1.4.3  03/26/2001.  
 * 4. Final Variable Name Check.        Nitin,        v1.4.4  03/26/2001.          
 * 5. Final Functionality Check.        Nitin,        v1.4.5  03/26/2001.          
*/

/* Import some of the libraries.*/
import java.lang.*;
import java.util.*;
import java.io.*;


   class FIFO extends PagingAlgorithm{
    String[][] szRequest;
    int nPageSize;
    int nNoOfRequest;
    int nCurrentFramePointer;

    public FIFO(String[][] szRequest,int nNoOfRequest,
	       int nNoOfFrames, int nPageSize,boolean bDebug){
     this.szRequest = szRequest;
     this.nNoOfRequest = nNoOfRequest;
     this.nPageSize = nPageSize;
     nCurrentFramePointer = 0;
     super.nNoOfFrames = nNoOfFrames;
     super.bDebug = bDebug;
     super.Create();
    }/* End of constructor.*/

    public void read(int nProgName, int nPageIndex,int nAddress){
     super.read(nProgName, nPageIndex, nAddress);
    }/* End of read.*/

    public void load(int nProgName, int nProgSize){
     super.load(nProgName, nProgSize, nPageSize);
    }/* End of read.*/

    public void write(int nProgName, int nPageIndex,int nAddress){
     super.write(nProgName, nPageIndex, nAddress);
    }/* End of read.*/

    public void unload(int nProgName){
     super.unload( nProgName);
    }/* End of read.*/

    public void Start(){
     System.out.println("Using FIFO ...");
     for(int nIndex=2; nIndex < nNoOfRequest; nIndex++){
     if(szRequest[nIndex][0].equals("load"))
       load(Integer.parseInt(szRequest[nIndex][1]),
	    Integer.parseInt(szRequest[nIndex][2]));
	    

     if(szRequest[nIndex][0].equals("read"))
	read(Integer.parseInt(szRequest[nIndex][1]),
	     (int)Integer.parseInt(szRequest[nIndex][2])/nPageSize,
	     Integer.parseInt(szRequest[nIndex][2]));

    if(szRequest[nIndex][0].equals("write"))
       write(Integer.parseInt(szRequest[nIndex][1]),
	     (int)Integer.parseInt(szRequest[nIndex][2])/nPageSize,
	     Integer.parseInt(szRequest[nIndex][2]));

    if(szRequest[nIndex][0].equals("unload"))
       unload(Integer.parseInt(szRequest[nIndex][1]));
		   
    }/* End for.*/
    System.out.println("Number of page faults for FIFO:"+super.nPageFault);
   }/* End of Start.*/

   public int getVictim(int nProgName){
    Frame newFrame = new Frame();
    nCurrentFramePointer%=super.nNoOfFrames;
    newFrame = (Frame)super.FrameList.elementAt(nCurrentFramePointer);
    return nCurrentFramePointer++;
   }/* End of getVictim.*/
}/* End of MFU.*/

				 

