📄 mos_io.cpp
字号:
// Mos_io.cpp: implementation of the CMos_io class.
// Author:biti_zx Released:March,2002.
// Copyright (c) By biti_zx 2002.
// All rights reserved.
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Mos.h"
#include "Mos_io.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMos_io m_io;
extern PCB m_pcb;
extern CVCS m_cpu;
extern CMos_stor m_stor;
CMos_io::CMos_io()
{
}
CMos_io::~CMos_io()
{
}
void CMos_io::ioreq(int chno)
{
CString str;
iorbtype* iorb = new iorbtype;
iorb->pcb = m_pcb.curr_pcb;
m_pcb.curr_pcb->iorbp = iorb;
mos_proc.sleep(chno);
m_cpu.CHST[chno-1] = BUSY;
m_UI.DealWithUI(_T("BUSY"),IDC_STATIC_KBS+chno-KB);
if(CHHEAD[chno-1] == NULL)
{
CHHEAD[chno-1] = CHTAIL[chno-1] = iorb;
iorb->link = NULL;
if(chno < 3)
m_cpu.CHCOUNT[chno-1] = 3;
else m_cpu.CHCOUNT[chno-1] = 1;
str.Format("%d",m_cpu.CHCOUNT[chno-1]);
m_UI.DealWithUI(str,IDC_STATIC_IOKB-chno+KB);
}
else{
CHTAIL[chno-1]->link = iorb;
CHTAIL[chno-1] = CHTAIL[chno-1]->link;
iorb->link = NULL;
}
}
void CMos_io::wdsk(int n,char *buffer,int rec1,int &rec2)//返回-1为已经写完
{
if(n>10||rec1>99||rec1<0||dsk==NULL) return;//错误情况
m_UI.FillList(rec1,buffer,IDC_LIST2);
fseek(dsk,rec1*sizeof(word)*10,SEEK_SET);//转到所要到的页
fwrite(buffer,sizeof(word),n,dsk);//写入信息
if(m_stor.DSKMTB[rec1].forwp==NULL)//写入的下一磁道
rec2=-1;
else
rec2=(m_stor.DSKMTB[rec1].forwp)->index;
m_cpu.io++;
ioreq(IORESTDSK);
}
void CMos_io::wdsk(int n,char *buffer,int rec1)
{
if(n>10||rec1>99||rec1<0||dsk==NULL) return;//错误情况
m_UI.FillList(rec1,buffer,IDC_LIST2);
fseek(dsk,rec1*sizeof(word)*10,SEEK_SET);//转到所要到的页
fwrite(buffer,sizeof(word),n,dsk);//写入信息
m_cpu.io++;
ioreq(IORESTDSK);
}
void CMos_io::wprtln(char *buffer)
{
if(print!=NULL)
{
fwrite(buffer,sizeof(char),strlen(buffer),print);
fwrite("\n",sizeof(char),1,print);
m_cpu.io++;
ioreq(IORESTPRT);
}
}
void CMos_io::rdsk(int n,char *buffer,int rec1,int &rec2)
{
if(n>10||rec1>99||rec1<0||dsk==NULL) return;
fseek(dsk,rec1*sizeof(word)*10,SEEK_SET);
fread(buffer,sizeof(word),n,dsk);
if(m_stor.DSKMTB[rec1].forwp==NULL)
rec2=-1;
else
rec2=(m_stor.DSKMTB[rec1].forwp)->index;
m_cpu.io++;
ioreq(IORESTDSK);
}
void CMos_io::rkbln(char *buffer)
{
if(kb!=NULL)
{
fgets(buffer,40,kb);
int length=strlen(buffer)-1;//备用
m_cpu.io++;
ioreq(IORESTKB);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -