📄 mos_out.cpp
字号:
// Mos_out.cpp: implementation of the CMos_out class.
// Wrote by biti_zx. Released April,2002.
// Copyright (C) 2002 by biti_zx.
// All rights reserved.
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Mos.h"
#include "Mos_out.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern CMos_io m_io;
extern JCB m_jcb;
extern PCB m_pcb;
extern CVCS m_cpu;
extern CMos_stor m_stor;
CMos_out::CMos_out()
{
}
CMos_out::~CMos_out()
{
}
void CMos_out::jcb_free(jcbtype* &pj)
{
if(m_jcb.jcbfree_head==NULL)
m_jcb.jcbfree_head=m_jcb.jcbfree_tail=pj;
else{
m_jcb.jcbfree_tail->jnext = pj;
m_jcb.jcbfree_tail=m_jcb.jcbfree_tail->jnext;
m_jcb.jcbfree_tail->jnext=NULL;
}
m_jcb.free_jcb_count++;
CString str;
str.Format("%d",JCBMAX-m_jcb.free_jcb_count);
m_UI.DealWithUI(str,IDC_STATIC_JN);
}
void CMos_out::FreeDisk(jcbtype *pJ)
{//释放磁盘
maptype *p;
m_pcb.curr_pcb->step=0;
p=&m_stor.DSKMTB[pJ->rpadd];
m_stor.dsk_free(pJ->rplen/10,p);
for(int i=0;i<pJ->rplen/10;i++)
m_UI.UpdateList(IDC_LIST2);
if(pJ->rdadd!=-1)
{
p=&m_stor.DSKMTB[pJ->rdadd];
m_stor.dsk_free(pJ->rdlen/10,p);
for(i=0;i<pJ->rdlen/10;i++)
m_UI.UpdateList(IDC_LIST2);
}
if(pJ->wdadd!=-1)
{
p=&m_stor.DSKMTB[pJ->wdadd];
m_stor.dsk_free(pJ->wdlen/10,p);
for(i=0;i<pJ->wdlen/10;i++)
m_UI.UpdateList(IDC_LIST2);
}
}
void CMos_out::Deal_int(int n, char *to, char *from)
{
char tempB[5];
_itoa(n,tempB,10);
strcat(from,tempB);
m_UI.PrtMsg(from);
strcat(from,"\n");
strcat(to,from);
}
void CMos_out::FillBuffer(jcbtype* pJ,char *Buff)
{
char prtbuf[50];
strcpy(prtbuf,"Job run time: ");//Job run time
Deal_int(pJ->jcputime,Buff,prtbuf);
strcpy(prtbuf,"Job login time: ");//Job login time
Deal_int(pJ->logintime,Buff,prtbuf);
strcpy(prtbuf,"Job logout time: ");//Job logout time
pJ->logouttime=m_cpu.rtime;
Deal_int(pJ->logouttime,Buff,prtbuf);
strcpy(prtbuf,"Job turnover time: ");//Job turnover time
int turnovertime = pJ->logouttime-pJ->logintime;
Deal_int(turnovertime,Buff,prtbuf);
strcpy(prtbuf,"Job I/O times: ");//Job I/O times
Deal_int(pJ->jio,Buff,prtbuf);
m_cpu.turnovertimes += turnovertime;
m_cpu.totaljob++;
}
////////////////////////////////////////////////////////////////////////
//P3 delay_output()
////////////////////////////////////////////////////////////////////////
void CMos_out::delay_output()
{
static int out_rec;
static int out_line;
static jcbtype* curr_jcb;
static char buffer[41];//缓存
char prtbuf[50];
char WriteBuff[200];//写入打印机
int i;
for(i=0;i<200;i++)
WriteBuff[i] = '\0';
m_cpu.kerneltime++;
switch(m_pcb.curr_pcb->step)
{
//0//////////////////////////////////////////////////////////////////////
case 0: if(m_jcb.out_head==NULL)
{
m_proc.sleep(OUTNULL);//输出队列为空
return;
}
else{
if(m_jcb.out_head==m_jcb.out_tail)
{
curr_jcb=m_jcb.out_head;
m_jcb.out_head=m_jcb.out_tail=NULL;
}
else{
curr_jcb=m_jcb.out_head;
m_jcb.out_head=m_jcb.out_head->jnext;
}
m_pcb.curr_pcb->step=1;
strcpy(WriteBuff,"Job Name: ");
strcat(WriteBuff,curr_jcb->name);//输出表头
m_UI.PrtMsg(WriteBuff);//界面处理,写到屏幕上
m_io.wprtln(WriteBuff);//写到打印机文件
return;
}
//1//////////////////////////////////////////////////////////////////////////
case 1: if(curr_jcb->error==0)
{
m_pcb.curr_pcb->step=2;
out_rec=curr_jcb->wdadd;
out_line=curr_jcb->resultline;
m_UI.PrtMsg("The result is:");
m_io.wprtln("The result is:");
return;
}
else//作业有错
{
FreeDisk(curr_jcb);
switch(curr_jcb->error)
{
case ADDROVER:strcpy(WriteBuff,"Address Overflow!");
break;
case ILLINS:strcpy(WriteBuff,"Ilegall Instruction!");
break;
case OUTOVER:strcpy(WriteBuff,"Output Lines Over Expected!");
break;
case TIMEOVER:strcpy(WriteBuff,"Time Over Expected!");
break;
case READOUT:strcpy(WriteBuff,"Read Data Error!");
break;
case OVERFLOW:strcpy(WriteBuff,"Overflow When Calculating!");
break;
}//end of switch
m_UI.PrtMsg(WriteBuff);
strcat(WriteBuff,"\n");
strcpy(prtbuf,"Error address: ");
Deal_int(curr_jcb->eraddr,WriteBuff,prtbuf);//Error address
FillBuffer(curr_jcb,WriteBuff);
strcpy(prtbuf,"Meet error,job TERMINATE!");//Error
m_UI.PrtMsg(prtbuf);
strcat(WriteBuff,prtbuf);
strcat(WriteBuff,"\n");
m_io.wprtln(WriteBuff);//一次性写入
jcb_free(curr_jcb);//释放JCB资源
if(m_pcb.waitjcb_head!=NULL) m_proc.wakeup(JCBFULL);
if(m_pcb.dsk_head!=NULL) m_proc.wakeup(DSKFULL);
return;
}//end of else
//2/////////////////////////////////////////////////////////////////////
step2:case 2: m_pcb.curr_pcb->step=3;//从输出井取10字到缓存
for(i=0;i<=40;i++)
buffer[i]='\0';
out_line--;
m_io.rdsk(10,buffer,out_rec,out_rec);
if(out_line<0)//滤掉垃圾信息
for(i=0;i<=40;i++)
buffer[i]='\0';
return;
//3/////////////////////////////////////////////////////////////////////
case 3: m_pcb.curr_pcb->step=4;
m_UI.PrtMsg(buffer);
m_io.wprtln(buffer);//从缓存写到打印机文件
return;
//4/////////////////////////////////////////////////////////////////////
case 4: if(out_rec!=-1){//未取完输出井
m_pcb.curr_pcb->step=2;
goto step2;
}
else{
FreeDisk(curr_jcb);
FillBuffer(curr_jcb,WriteBuff);
strcat(WriteBuff,"Job finished normally.\n");//填缓冲区
m_UI.PrtMsg("Job finished normally.");
m_io.wprtln(WriteBuff);//一次性写入
jcb_free(curr_jcb);//释放JCB资源
if(m_pcb.waitjcb_head!=NULL) m_proc.wakeup(JCBFULL);
if(m_pcb.dsk_head!=NULL) m_proc.wakeup(DSKFULL);
return;
}//end of else
}//end of switch
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -