📄 mosprocess.java
字号:
import java.util.Iterator;
import java.util.LinkedList;
public class MosProcess implements Runnable {
private MosMM mm = null;
private MosCPU cpu = null;
private MosROM rom = null;
private MosVar var = null;
private MosPCB mp = null;
private MosJCB mj = null;
MosChannel1 chan1 = null;
MosChannel2 chan2 = null;
MosChannel3 chan3 = null;
LinkedList que_jcb_ready = null;
LinkedList que_jcb_start = null;
private LinkedList que_jcb_finish = null;
private LinkedList que_pcb_ready = null;
// private LinkedList<MosPCB> que_pcb_wait = null;
private MosDisk disk = null;
private byte[] intr = null;
MosP1 p1 = null;
MosP2 p2 = null;
MosP3 p3 = null;
byte[] pcb_cpu_r = null;
byte[] pcb_cpu_pc = null;
byte[] out_msg = null;
MosPage pcb_cpu_ptr = null;
char pcb_cpu_c = FinalVar.CPU_F;
int addr = 0;
int rtime = 0;
byte[] comm = {MosChar.G,MosChar.T,0,0};
byte[] prt_out = null;
byte[] temppc = null;
byte[] com = null;
private Thread t = null;
String s1 = "";
public MosProcess(MosMM mm, MosCPU cpu, MosROM rom, MosVar var, LinkedList que_jcb_finish,
LinkedList que_pcb_ready, MosDisk disk,MosChannel1 chan1,MosChannel2 chan2,
MosChannel3 chan3,LinkedList que_pcb_wait,LinkedList que_jcb_ready,
LinkedList que_jcb_start,MosP1 p1, MosP2 p2, MosP3 p3) {
this.mm = mm;
this.cpu = cpu;
this.rom = rom;
this.var = var;
this.chan1 = chan1;
this.chan2 = chan2;
this.chan3 = chan3;
this.que_jcb_finish = que_jcb_finish;
this.que_pcb_ready = que_pcb_ready;
// this.que_pcb_wait = que_pcb_wait;
this.que_jcb_ready = que_jcb_ready;
this.que_jcb_start = que_jcb_start;
this.disk = disk;
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
mm.mmMallocBuffer();
t = new Thread(this,"ProcessCall");
}
private int changeNum(byte a,byte b)
{
return (int)((a&15) * 10 + (b&15));
}
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 void savePresent(){
mp.setPcbCpuR(cpu.getR());
mp.setPcbCpuPc(cpu.getPC());
mp.setPcbCpuC(cpu.getC());
mp.setPcbCpuPtr(cpu.getPTR());
}
private void loadPresent() {
this.pcb_cpu_r = mp.getPcbCpuR();
this.pcb_cpu_pc = mp.getPcbCpuPc();
this.pcb_cpu_c = mp.getPcbCpuC();
this.pcb_cpu_ptr = mp.getPcbCpuPtr();
cpu.setR(pcb_cpu_r[0] ,pcb_cpu_r[1], pcb_cpu_r[2], pcb_cpu_r[3]);
cpu.setPC(pcb_cpu_pc[0], pcb_cpu_pc[1]);
cpu.setC(pcb_cpu_c);
cpu.setPTR(pcb_cpu_ptr);
}
public void processStart() {
t.start();
}
public void run() {
while(true) {
if(var.shutdown != 0) {
break;
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO: handle exception
}
if((var.st_nx_switch == 0)||(var.st_nx_switch == 1)) {
intr = cpu.getIntr();
if(intr[0] != (byte)0) {
intr[0] = 0;
}
if(intr[1] != (byte)0) {
if(intr[1] == 2) {
mp.setTempWl(rom.getWL());
mp.setPcbIoTimes();
intr[1] = 0;
var.getMain().var_si_label.setText("0");
}
if(intr[1] == 4) {
byte i;
byte[] h = null;
byte[] wl= null;
byte[] temp_jcb_name = null;
byte[] temp_pcb_run_time;
byte[] temp_pcb_io_times;
byte[] temp_jcb_in_time;
byte[] temp_jcb_out_time;
byte[] temp_turn_over = null;
byte[] temp_jcb_supposed_time = null;
byte[] temp_jcb_supposed_output = null;
byte[] block_table = null;
// get JCB;
mj = testJCB(mp.getPcbId());
// set cpu_out_time;
mj.setJcbOutTime(cpu.getTime());
// jcb_name/0;
temp_jcb_name = mj.getJcbName();
// jcb total run time/4;
temp_pcb_run_time = changeByte(mp.getPcbRunTime());
// jcb io times/8
temp_pcb_io_times = changeByte(mp.getPcbIoTimes());
// jcb input time/12;
temp_jcb_in_time = changeByte(mj.getJcbInTime());
// jcb output time/16;
temp_jcb_out_time = changeByte(mj.getJcbOutTime());
// turn job over time/20;
temp_turn_over = changeByte(mj.getJcbOutTime() - mj.getJcbInTime());
var.addTotalTime(mj.getJcbOutTime() - mj.getJcbInTime());
// supposed max time/24;
temp_jcb_supposed_time = mj.getJcbSupposedTime();
// supposed max line/28;
temp_jcb_supposed_output = mj.getJcbSupposedOutput();
var.incJobCount();
h = rom.getH();
wl = mp.getTempWl();
out_msg = new byte[32+h.length+wl.length];
for(i= 0;i < 4;i++) {
out_msg[i] = temp_jcb_name[i];
out_msg[12+i] = temp_jcb_in_time[i];
out_msg[16+i] = temp_jcb_out_time[i];
out_msg[4+i] = temp_pcb_run_time[i];
out_msg[8+i] = temp_pcb_io_times[i];
out_msg[20+i] = temp_turn_over[i];
out_msg[24+i] = temp_jcb_supposed_time[i];
out_msg[28+i] = temp_jcb_supposed_output[i];
}
for(i = 0;i < h.length;i++) {
out_msg[32+i] = h[i];
}
for(i = 0;i < wl.length;i++) {
out_msg[32+h.length+i] = wl[i];
}
// require output spooling;
block_table = disk.diskMalloc((byte)(out_msg.length/40+1),FinalVar.OUT_BUFFER_ADDR);
mj.setOutputTable(new MosBlock(block_table));
// start the 3th channel;
chan3.startChannel3(out_msg, block_table[0]);
que_jcb_finish.add(mj);
mm.mmFree(mp.getPcbCpuPtr().getPageTable());
var.getMain().proFree(mp.getPcbId());
var.getMain().jobnum_label.setText("" + String.valueOf(que_jcb_start.size()));
mp = null;
mp = test();
if(null != mp)
loadPresent();
intr[1] = 0;
var.var_si_label.setText("0");
}
}
if(intr[2] != (byte)0) {
intr[2] = 0;
var.var_ti_label.setText("0");
}
if(intr[3] != (byte)0) {
if(intr[3] == 1) {
p1.p1Read(var.input_field.getText());
var.input_field.setText("");
}
intr[3] = 0;
var.var_ioi_label.setText("0");
}
p1.p1Start();
p2.p2Start();
if(var.p1_switch == 0) {
var.input_btn.setEnabled(true);
}
if(null == mp) {
var.var_cpu_label.setText(" SuperWait ");
rom.romExecute(comm);
var.var_comm_label.setText("" + (char)comm[0] + (char)comm[1]+(char)comm[2]+(char)comm[3]);
var.incTime();
if(var.getTime()%5 == 0) {
cpu.incTime();
rtime = cpu.getRtime();
cpu.decRtime();
if(rtime == 0) {
cpu.setTI((byte)1);
}
mp = test();
if(null != mp)
loadPresent();
}
}
else {
var.var_cpu_label.setText(" " + mp.getTheName() + " ");
if(var.getTime()%5 == 0 && var.getTime() != 0) {
mp.setPcbRunTime();
cpu.incTime();
rtime = cpu.getRtime();
cpu.decRtime();
if(rtime%5 == 0) {
savePresent();
cpu.setTI((byte)1);
que_pcb_ready.add(mp);
mp = test();
if(null != mp) {
loadPresent();
continue;
}
}
}
temppc = cpu.getPC();
var.var_pc_label.setText("" + (char)temppc[0]+(char)temppc[1]);
addr = this.changeNum(temppc[0], temppc[1]);
var.var_ptr_label.setText("" + addr);
addr = pcb_cpu_ptr.changeAdd(addr);
com = mm.mmRead(addr, FinalVar.MM_READ_WORD);
var.var_comm_label.setText("" + (char)com[0] + (char)com[1]+(char)com[2]+(char)com[3]);
rom.romExecute(com);
var.getMain().proMsg(mp.getPcbId(),changeNum(temppc[0], temppc[1]));
var.incTime();
cpu.incPC();
var.var_next_label.setText("" + (addr + 1));
}
this.p3.p3Start();
if(var.st_nx_switch == 1) {
var.st_nx_switch = 2;
}
}
}
}
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;
}
private MosPCB test() {
Iterator iter = que_pcb_ready.iterator();
while(iter.hasNext()) {
MosPCB pcb = (MosPCB)iter.next();
pcb.setPcbState(FinalVar.PCB_RUN);
que_pcb_ready.remove(pcb);
return pcb;
}
return null;
}
private MosJCB testJCB(byte pcb_id) {
Iterator iter = que_jcb_start.iterator();
while(iter.hasNext()) {
MosJCB jcb = (MosJCB)iter.next();
if(jcb.getJcbPcId() == pcb_id) {
iter.remove();
return jcb;
}
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -