www.pudn.com > Mos.rar > Mos_main.cpp


// Mos_main.cpp: implementation of the Mos_main class. 
// Wrote by Wang Hao. Released April,2002. 
// Copyright (C) 2002 by Wang Hao. 
// All rights reserved. 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "mos.h" 
#include "Mos_main.h" 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
extern CVCS m_cpu; 
extern PCB  m_pcb; 
extern JCB  m_jcb; 
extern CMos_stor m_stor; 
extern CMos_io m_io; 
Mos_main::Mos_main() 
{ 
 
} 
 
Mos_main::~Mos_main() 
{ 
 
} 
 
void Mos_main::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 Mos_main::PrintSysMsg() 
{ 
	char Buff[250]; 
	char prtbuf[50]; 
	strcpy(prtbuf,"******System Messages******"); 
	m_UI.PrtMsg(prtbuf); 
	strcpy(Buff,prtbuf); 
	strcat(Buff,"\n"); 
 
	strcpy(prtbuf,"Total kernel time: "); 
	Deal_int(m_cpu.kerneltime,Buff,prtbuf); 
 
	strcpy(prtbuf,"Total user time: "); 
	Deal_int(m_cpu.usertime,Buff,prtbuf); 
 
	strcpy(prtbuf,"Total idle time: "); 
	Deal_int(m_cpu.idletime,Buff,prtbuf); 
 
	strcpy(prtbuf,"Cpu using rate: "); 
	char buff[4]; 
	_itoa((m_cpu.rtime-m_cpu.idletime)*100/m_cpu.rtime,buff,10); 
	strcat(prtbuf,buff); 
	strcat(prtbuf,"%"); 
	m_UI.PrtMsg(prtbuf); 
	strcat(prtbuf,"\n"); 
	strcat(Buff,prtbuf); 
 
	strcpy(prtbuf,"Total io times: "); 
	Deal_int(m_cpu.io,Buff,prtbuf); 
 
	strcpy(prtbuf,"Total jobs: "); 
	Deal_int(m_cpu.totaljob,Buff,prtbuf); 
 
	strcpy(prtbuf,"Average turnover time: "); 
	int average = m_cpu.turnovertimes/m_cpu.totaljob; 
	Deal_int(average,Buff,prtbuf); 
 
	strcpy(prtbuf,"System shutdown time: "); 
	Deal_int(m_cpu.rtime,Buff,prtbuf); 
 
	fwrite(Buff,sizeof(char),strlen(Buff),m_io.print); 
} 
 
bool Mos_main::term() 
{ 
	if(m_cpu.FatalError||(m_pcb.free_pcb_count == (PCBMAX-3)&& 
		m_pcb.kbend_head==m_pcb.PcbTab&& 
		m_pcb.jcbnull_head==(m_pcb.PcbTab+1)&& 
		m_pcb.waitout_head==(m_pcb.PcbTab+2))) 
	{ 
		PrintSysMsg(); 
		m_UI.DealWithUI(" ",IDC_STATIC_WJOB); 
		m_UI.DealWithUI(" ",IDC_STATIC_WRJ); 
		m_UI.DealWithUI(" ",IDC_STATIC_WOUT); 
		m_UI.DealWithUI("0",IDC_STATIC_PN); 
		return true; 
	} 
	else return false; 
} 
////////////////////////////////////////////////////////////////// 
//Mos_main::init() 
////////////////////////////////////////////////////////////////// 
void Mos_main::init() 
{ 
	m_cpu.C = '0'; 
	for(int i = 0;i<=2;i++) 
	{ 
		m_cpu.CHCOUNT[i] = 0; 
		m_cpu.CHST[i] = FREE; 
		m_UI.DealWithUI("0",IDC_STATIC_IOKB-i); 
		m_UI.DealWithUI("FREE",IDC_STATIC_KBS+i); 
	} 
	m_cpu.MODE = IDLE; 
	m_cpu.FatalError = false; 
	m_cpu.PI = 0; 
	m_cpu.TI = 0; 
	m_cpu.IOI = 0; 
	m_cpu.SI = 0; 
 
	m_cpu.PC[0] = m_cpu.PC[1] = '0'; 
	m_cpu.PTR.op1 = m_cpu.PTR.op2 = m_cpu.PTR.op3 = m_cpu.PTR.op4 = '0';  
	m_cpu.R[0] = m_cpu.R[1] = m_cpu.R[2] = m_cpu.R[3] =  '0'; 
	m_cpu.rtime = m_cpu.time = m_cpu.idletime = 0; 
	m_cpu.usertime =m_cpu.io = m_cpu.turnovertimes = m_cpu.totaljob = m_cpu.kerneltime = 0; 
 
	for(i=0;i<300;i++) 
		m_cpu.memory[i].op1=m_cpu.memory[i].op2=m_cpu.memory[i].op3=m_cpu.memory[i].op4='0'; 
////////以上初始化CPU寄存器、内存及相关数据//////////////////////// 
/* PCBMAX:8 
	P1[0 ] 
  	P2[1 ] 
	P3[2 ] 
user->[3 ] 
	  [4 ] 
	  [5 ] 
	  [6 ] 
	  [7 ] 
*/ 
	for(i=3;iP1",IDC_STATIC_RP); 
	m_UI.DealWithUI("->P2",IDC_STATIC_WRJ); 
	m_UI.DealWithUI("->P3",IDC_STATIC_WOUT); 
	m_UI.DealWithUI("3",IDC_STATIC_PN); 
////////////////////////以上创建三个系统进程/////////////////////// 
}