⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mosrom.java

📁 本程序是在软件模拟的计算机系统上设计一个多道程序的操作系统MOS
💻 JAVA
字号:
class MosROM
{
	private int addr;
	private MosPage pagetable = null;
	private byte[] tempr = null;
	private int res;
	private MosCPU cpu = null;
	private MosMM mm = null;
	private byte[] tempwl = null;
	private byte[] temppc = null;
	private byte[] temph = null;
	private MosVar var = null;
	
	public MosROM(MosCPU cpu, MosMM mm, MosVar var)
	{
		this.cpu = cpu;
		this.mm = mm;
		this.var = var;
		addr = 0;
		res = 0;
	}
	
	private int changeNum(byte a,byte b)
	{
		return (int)((a&15) * 10 + (b&15));
	}
	
	private int changeNum(byte[] a)
	{
		int temp = (int)((a[1]&15) * 100 + (a[2]&15) * 10 + (a[3]&15));
		if(a[0] == MosChar.MINUS_SIGN)temp = temp * (-1);
		return temp;
	}
	
	private byte[] changeByte(int num)
	{
		byte[] temp = new byte[4];
		if(num < 0){temp[0] = MosChar.MINUS_SIGN;num = num * (-1);}
		else temp[0] = MosChar.PLUS_SIGN;
		temp[1] = (byte)((num/100) | 48);
		num = num % 100;
		temp[2] = (byte)((num/10) | 48);
		num = num % 10;
		temp[3] = (byte)(num | 48);
		return temp;
	}
	
	private int changeaddr(byte a,byte b)
	{
		addr = this.changeNum(a, b);
		pagetable = cpu.getPTR();
		addr = pagetable.changeAdd(addr);
		return addr;
	}
	
	byte[] getWL()
	{
		return tempwl;
	}
	
	byte[] getH()
	{
		return temph;
	}
	
	void romExecute(byte[] comm)
	{
		if(comm[0] == MosChar.S)
		{
			if(comm[1] == MosChar.R)
			{
				addr = this.changeaddr(comm[2], comm[3]);
				mm.mmWrite(cpu.getR(), addr);
			}
			else if(comm[1] == MosChar.U)
			{
				addr = this.changeaddr(comm[2], comm[3]);
				tempr = cpu.getR();
				res = this.changeNum(tempr);
				tempr = mm.mmRead(addr, FinalVar.MM_READ_WORD);
				res = res - this.changeNum(tempr);
				tempr = this.changeByte(res);
				cpu.setR(tempr[0], tempr[1], tempr[2], tempr[3]);
				tempr = null;
			}
			else if(comm[1] == MosChar.D){}
		}
		else if(comm[0] == MosChar.B)
		{
			if(comm[1] == MosChar.T)
			{
				if(cpu.getC() == 'T')cpu.setPC(comm[2],comm[3]);
			}
			else if(comm[1] == MosChar.N)
			{
				tempr = cpu.getR();
				res = this.changeNum(tempr);
				if(res < 0)cpu.setPC(comm[2],(byte)(comm[3] - 1));
				tempr = null;
			}
			else if(comm[1] == MosChar.U)
			{
				cpu.setPC(comm[2],(byte)(comm[3]-1));
			}
		}
		else if(comm[0] == MosChar.L)
		{
			if(comm[1] == MosChar.R)
			{
				addr = this.changeaddr(comm[2], comm[3]);
				tempr = mm.mmRead(addr, FinalVar.MM_READ_WORD);
				cpu.setR(tempr[0], tempr[1], tempr[2], tempr[3]);
				tempr = null;
			}
		}
		else if(comm[0] == MosChar.C)
		{
			if(comm[1] == MosChar.R)
			{
				addr = this.changeaddr(comm[2], comm[3]);
				byte[] tempm = mm.mmRead(addr, FinalVar.MM_READ_WORD);
				tempr = cpu.getR();
				res = 0;
				for(int i = 0;i < tempr.length;i++)
				{
					if(tempr[i] == tempm[i])++res;
					else break;
				}
				if(res == 4)cpu.setC('T');
				else cpu.setC('F');
				tempm = null;
				tempr = null;
			}
		}
		else if(comm[0] == MosChar.A)
		{
			if(comm[1] == MosChar.D)
			{
				addr = this.changeaddr(comm[2], comm[3]);
				tempr = cpu.getR();
				res = this.changeNum(tempr);
				tempr = mm.mmRead(addr, FinalVar.MM_READ_WORD);
				res = res + this.changeNum(tempr);
				tempr = this.changeByte(res);
				cpu.setR(tempr[0], tempr[1], tempr[2], tempr[3]);
				tempr = null;
			}
		}
		else if(comm[0] == MosChar.R)
		{
			if(comm[1] == MosChar.L)
			{
				var.getMain().var_si_label.setText("1");
				for(byte i = 0;i < 100;i++)
				{
					addr = cpu.getPTR().changeAdd(i);
					tempr = mm.mmRead(addr,  FinalVar.MM_READ_WORD);
					if(tempr[0] == MosChar.STAR) {++i;addr = cpu.getPTR().changeAdd(i);break;}
				}
				res = this.changeNum(comm[2], comm[3]);
				int times = res % 10;
				res = cpu.getPTR().changeAdd(res-times);
				for(int i =0;i <= times;i++)
				{
					tempr = mm.mmRead(addr, FinalVar.MM_READ_WORD);
					mm.mmWrite(tempr, res);
					addr = addr + 4;
					res = res + 4;
				}
				var.getMain().var_si_label.setText("0");
			}
		}
		else if(comm[0] == MosChar.W)
		{
			if(comm[1] == MosChar.L)
			{
				var.getMain().var_si_label.setText("2");
				res = this.changeNum(comm[2], comm[3]);
				int times = res % 10;
				addr = cpu.getPTR().changeAdd(res-times);
				this.tempwl=new byte[(times+1)*4];
				for(int i =0;i <= times;i++)
				{
					tempr = mm.mmRead(addr, FinalVar.MM_READ_WORD);
					for(int j = 0;j < 4;j++)
					{
						tempwl[i*4+j] = tempr[j];
					}
					addr = addr + 4;
				}
				cpu.setSI((byte)2);
				var.getMain().var_si_label.setText("0");
			}
		}
		else if(comm[0] == MosChar.G)
		{
			if(comm[1] == MosChar.T)
			{
				var.getMain().var_si_label.setText("3");
				res = cpu.getTime();
				tempr = this.changeByte(res);
				cpu.setR(tempr[0], tempr[1], tempr[2], tempr[3]);
				var.getMain().var_si_label.setText("0");
			}
		}
		else if(comm[0] == MosChar.H)
		{
			cpu.setSI((byte)4);
			temppc = cpu.getPC();
			addr = this.changeaddr(temppc[0], temppc[1]);
			int i = 0;
			addr = addr + 4;
			int add = addr;
			while(true)
			{
				tempr = mm.mmRead(add, FinalVar.MM_READ_WORD);
				if(tempr[0] != MosChar.MINUS_SIGN && tempr[0] != MosChar.PLUS_SIGN && tempr[0] != MosChar.AT)break;
				if(tempr[0] != MosChar.AT)++i;
				add = add + 4;
			}
			temph = new byte[i*4];
			i=0;
			for(int j = 0;;j++)
			{
				tempr = mm.mmRead(addr, FinalVar.MM_READ_WORD);
				if(tempr[0] != MosChar.MINUS_SIGN && tempr[0] != MosChar.PLUS_SIGN && tempr[0] != MosChar.AT)break;
				if(tempr[0] != MosChar.AT)
				{
					for(int k = 0;k < 4;k++)
					{
						temph[i*4+k] = tempr[k];
					}
					i++;
				}
				addr = addr + 4;
			}
		}
	}
	
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -