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

📄 moscpu.java

📁 本程序是在软件模拟的计算机系统上设计一个多道程序的操作系统MOS
💻 JAVA
字号:
class MosCPU
{
	//以下保存CPU中的各种寄存器
	private byte[] cpu_r = null;
	private char cpu_c;
	private byte[] cpu_pc = null;
	private int cpu_time;
	private int cpu_rtime;
	private byte cpu_mode;
	private MosPage cpu_ptr = null;
	private byte[] cpu_intr = null;
	private MosVar var = null;
	
	//构造方法
	public MosCPU(MosVar var)
	{
		this.cpu_r = new byte[4];
		this.cpu_c = 0;
		this.cpu_pc = new byte[2];
		this.cpu_time = 0;
		this.cpu_rtime = 1;
		this.cpu_mode = 0;
		this.cpu_intr = new byte[4];
		this.var =var;
	}
	
	//获取条件寄存器C方法,返回一个字符
	char getC()
	{
		return cpu_c;
	}
	
	//设置条件寄存器C方法,参数为一个字符
	void setC(char cpu_c)
	{
		this.cpu_c = cpu_c;
		var.getMain().var_c_label.setText(Character.toString(this.cpu_c));
	}
	
	//获取CPU工作模式方法,返回一个字节
	byte getMode()
	{
		return cpu_mode;
	}
	
	//设置CPU工作模式方法,参数为一个字符
	void setMode(byte cpu_mode)
	{
		this.cpu_mode = cpu_mode;
	}
	
	//获取指令寄存器PC方法,返回一个长度为2的字节数组
	byte[] getPC()
	{
		return cpu_pc;
	}
	
	//设置指令寄存器PC方法,参数为2个字节,分别对应指令寄存器PC的第一和第二个字节
	void setPC(byte a,byte b)
	{
		this.cpu_pc[0] = a;
		this.cpu_pc[1] = b;
		var.getMain().var_pc_label.setText(chgStr(this.cpu_pc));
	}
	
	//设置指令寄存器PC方法,把指令寄存器PC的值加1
	void incPC()
	{
		if(this.cpu_pc[1] == 57){this.cpu_pc[1] = 48;++this.cpu_pc[0];}
		else ++this.cpu_pc[1];
		var.getMain().var_pc_label.setText(chgStr(this.cpu_pc));
	}
	
	//获取页表寄存器方法,返回一个页表
	MosPage getPTR()
	{
		return cpu_ptr;
	}
	
	//设置页表寄存器方法,参数为一个页表
	void setPTR(MosPage cpu_ptr)
	{
		this.cpu_ptr = cpu_ptr;
	}
	
	//获取寄存器R方法,返回一个长度为4的字节数组
	byte[] getR()
	{
		return cpu_r;
	}
	
	//设置寄存器R方法,参数为4个字节,和寄存器R的每个字节一一对应
	void setR(byte a,byte b,byte c,byte d)
	{
		this.cpu_r[0] = a;
		this.cpu_r[1] = b;
		this.cpu_r[2] = c;
		this.cpu_r[3] = d;
		var.getMain().var_r_label.setText(chgStr(this.cpu_r));
	}
	
	//获取中断寄存器方法,返回一个长度为4的字节数组
	byte[] getIntr()
	{
		return cpu_intr;
	}
	
	//设置中断寄存器PI方法,参数为一个字节
	void setPI(byte pi)
	{
		this.cpu_intr[0] = pi;
		var.getMain().var_pi_label.setText(String.valueOf(pi));
	}
	
	//设置中断寄存器SI方法,参数为一个字节
	void setSI(byte si)
	{
		this.cpu_intr[1] = si;
		var.getMain().var_si_label.setText(String.valueOf(si));
	}
	
	//设置中断寄存器TI方法,参数为一个字节
	void setTI(byte ti)
	{
		this.cpu_intr[2] = ti;
		var.getMain().var_ti_label.setText(String.valueOf(ti));
	}
	
	//设置中断寄存器IOI方法,参数为一个字节
	void setIOI(byte ioi)
	{
		this.cpu_intr[3] = ioi;
		var.getMain().var_ioi_label.setText(String.valueOf(ioi));
	}
	
	//获取相对时间方法,返回一个整型
	int getRtime()
	{
		return cpu_rtime;
	}
	
	//设置相对时间方法,把相对时间减1,如果相对时间为0就把它置5
	void decRtime()
	{
		if(this.cpu_rtime == 0)this.cpu_rtime = 1;
		else --this.cpu_rtime;
		var.getMain().var_rtime_label.setText(String.valueOf(this.cpu_rtime));
	}
	
	//获取绝对时间方法,返回一个整型
	int getTime()
	{
		return cpu_time;
	}
	
	//设置绝对时间方法,把绝对时间加1
	void incTime()
	{
		++this.cpu_time;
		var.getMain().var_time_label.setText(String.valueOf(this.cpu_time));
	}
	
	private String chgStr(byte[] a)
	{
		String str = null;
		int i;
		for(i = 0;i < a.length;i++)
		{
			if(a[i] == 0)break;
		}
		try
		{
			str = new String(a,0,i,"ISO8859-1");
		}
		catch(Exception e){}
		return str;
	}
}

⌨️ 快捷键说明

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