Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
9
Добавлен:
01.05.2014
Размер:
1.94 Кб
Скачать
package memory.phithical_mem;

import java.util.Vector;

import memory.Page;

public class PhithicalMemory {

private static byte[] currentPageMem = null;
private static Vector<Page> allMemory = new Vector<Page>();
private static int avalibleIndex;
private static int cursor;

private PhithicalMemory(){};

public static void mallocXpages(int x){
if(allMemory.size()==0)
cursor=0;
for(int i=0;i<x;i++){
Page page = new Page();
allMemory.add(page);
}
}

public static byte[] getStateAvailFromPage(int i, boolean resume) {
byte[] result = new byte[8];
if(!resume)
avalibleIndex=0;
try{

currentPageMem = allMemory.elementAt(i).getPageMem();
// avalibleIndex=0;

for(int j=0;j<result.length;j++){
result[j]=currentPageMem[avalibleIndex];
avalibleIndex++;
}
}catch(ArrayIndexOutOfBoundsException e){
System.err.println("RISC Memory: Page you are asced for not avalible " +
"becorse it does not malloced.");
//e.printStackTrace();
return null;
}
return result;
}

public static byte[] rememberVar(byte[] var) {
byte[] res = new byte[3];
currentPageMem=allMemory.elementAt(0).getPageMem();
res[0]=0;
res[1]=(byte)cursor;
res[2]=var[1];
//System.out.println(var.length);
for(int i=0;i<var.length;i++){
//System.out.println(i);
currentPageMem[cursor]=var[i];
cursor++;
}
return res;
}

public static byte[] getVar(byte[] bs) {
currentPageMem=allMemory.elementAt(bs[0]).getPageMem();
int tmpCur=bs[1];
byte[] res = null;
if(currentPageMem[tmpCur]==1 || currentPageMem[tmpCur]==4)
res= new byte[4];
if(currentPageMem[tmpCur]==2 || currentPageMem[tmpCur]==5)
res = new byte[8];
if(currentPageMem[tmpCur]==3)
res=new byte[2];
tmpCur+=2;
for(int i=0; i<res.length;i++)
res[i]=currentPageMem[tmpCur+i];

return res;
}

}