📄 mos_jsw.cpp
字号:
// Mos_jsw.cpp: implementation of the CMos_jsw class.
// Code by biti_zx. Released April,2002.
// Copyright (C) 2002 by biti_zx.
// All rights reserved.
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Mos.h"
#include "Mos_jsw.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern CMos_stor m_stor;
extern PCB m_pcb;
extern JCB m_jcb;
extern CMos_io m_io;
extern CVCS m_cpu;
CMos_jsw::CMos_jsw()
{
}
CMos_jsw::~CMos_jsw()
{
}
pcbtype* CMos_jsw::pcb_allocation()
{
pcbtype* pP;
if(m_pcb.pcb_free_head==NULL)
return NULL;//失败
pP = m_pcb.pcb_free_head;
m_pcb.pcb_free_head = m_pcb.pcb_free_head->next;
pP->next = NULL;
if(m_pcb.pcb_free_head==NULL)
m_pcb.pcb_free_tail = NULL;
m_pcb.free_pcb_count--;
CString str;
str.Format("%d",PCBMAX-m_pcb.free_pcb_count);
m_UI.DealWithUI(str,IDC_STATIC_PN);
return pP;
}
void CMos_jsw::Fillmemory(int page, char *buff)
{
char temp[8];
for(int i=0;i<=6;i++)
temp[i] = ' ';
temp[7] = '\0';
for(i=0;i<10;i++)
{
temp[0]=m_cpu.memory[page*10+i].op1=buff[i*4];//高位
temp[2]=m_cpu.memory[page*10+i].op2=buff[i*4+1];
temp[4]=m_cpu.memory[page*10+i].op3=buff[i*4+2];
temp[6]=m_cpu.memory[page*10+i].op4=buff[i*4+3];//低位
m_UI.FillList(page*10+i,temp,IDC_LIST1);
}
}
////////////////////////////////////////////////////////////////////////
//P2 jsw()
////////////////////////////////////////////////////////////////////////
void CMos_jsw::jsw()
{
static char diskBuf[41];
static int currmp;//分配的内存页
static int dskrec;//读磁道
static pcbtype* alloc_pcb;//指向分配的PCB
static maptype* outwell;//指向分配的输出井
static memtype* alloc_mem;//指向分配的memory
static jcbtype* curr_jcb;
char temp[8];
for(int i=0;i<=6;i++)
temp[i] = ' ';
temp[7]='\0';
m_cpu.kerneltime++;
switch(m_pcb.curr_pcb->step)
{
//0//////////////////////////////////////////////////////////////////////
step0:case 0: if(m_jcb.jcb_head==NULL)
{
m_proc.sleep(JCBNULL);
return;
}
else{
curr_jcb=m_jcb.jcb_head;
curr_jcb->logintime=m_cpu.rtime;
if(m_jcb.jcb_head->jnext!=NULL)
m_jcb.jcb_head=m_jcb.jcb_head->jnext;
else m_jcb.jcb_head=m_jcb.jcb_tail=NULL;
m_pcb.curr_pcb->step=1;
}
//1///////////////////////////////////////////////////////////////////////////
case 1: if(m_stor.mem_allocation(curr_jcb->rplen/10+1,alloc_mem))
{//成功分配根据作业长度申请的内存,接着在分配的第一页创建页表
currmp=alloc_mem->index;
for(i=0;m_stor.MEMTB[currmp].forwp!=NULL;i++)//填页表
{
currmp=m_stor.MEMTB[currmp].forwp->index;
temp[0]=m_cpu.memory[alloc_mem->index*10+i].op1=currmp/10+0x30;
temp[2]=m_cpu.memory[alloc_mem->index*10+i].op2=currmp%10+0x30;
m_UI.FillList(alloc_mem->index*10+i,temp,IDC_LIST1);
}
m_pcb.curr_pcb->step=2;
currmp=alloc_mem->forwp->index;
dskrec=curr_jcb->rpadd;
m_io.rdsk(10,diskBuf,dskrec,dskrec);
Fillmemory(currmp,diskBuf);
return;
}
else {
m_proc.sleep(MEMFULL);
return;
}
//2///////////////////////////////////////////////////////////////////////////
case 2: if(dskrec==-1)
{
m_pcb.curr_pcb->step=3;
}
else{
m_pcb.curr_pcb->step=2;
currmp=m_stor.MEMTB[currmp].forwp->index;
m_io.rdsk(10,diskBuf,dskrec,dskrec);//读磁盘下一块
Fillmemory(currmp,diskBuf);
return;
}
//3///////////////////////////////////////////////////////////////////////////
case 3: if((alloc_pcb=pcb_allocation())!=NULL)
{//为该作业创建新进程
m_proc.creat(alloc_pcb,curr_jcb);
alloc_pcb->regptr[0]='0';
alloc_pcb->regptr[1]=curr_jcb->rplen/10+0x30-1;
alloc_pcb->regptr[2]=alloc_mem->index/10+0x30;
alloc_pcb->regptr[3]=alloc_mem->index%10+0x30;
m_pcb.curr_pcb->step=4;
}
else{
m_proc.sleep(PCBFULL);
return;
}
//4//////////////////////////////////////////////////////////////////////
case 4: if(m_stor.dsk_allocation(curr_jcb->wdlen/10,outwell))
{//申请输出井成功
m_pcb.curr_pcb->step=0;
curr_jcb->wdadd=outwell->index;
alloc_pcb->outp=curr_jcb->wdadd;
alloc_pcb->olimit=curr_jcb->wdlen/10;
alloc_pcb->inp=curr_jcb->rdadd;
alloc_pcb->ilimit=curr_jcb->rdlen/10;
goto step0;
}
else{
m_proc.sleep(DSKFULL);
return;
}
}//end of switch
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -