📄 config.c
字号:
if (*pTmp == '\r' || *pTmp == EOF)
break;
}
if (pTmp - szLine >= LINESIZE)
break;
if (*pTmp == EOF)
bEof = TRUE;
*pTmp = '\0';
pLineStart = pLine;
/* Skip leading white space and get verb. */
pLine = scan(pLine, szBuf);
/* Translate the verb to lower case ... */
for(pTmp = szBuf; *pTmp != '\0'; pTmp++)
*pTmp = tolower(*pTmp);
/* If the line was blank, skip it. Otherwise, look up */
/* the verb and execute the appropriate function. */
if(*szBuf != '\0')
{
pEntry = LookUp(commands, szBuf);
if(pEntry -> pass < 0 || pEntry -> pass == nPass)
{
if (!singleStep || !SkipLine(pLineStart))
{
skipwh(pLine);
if('=' != *pLine)
CfgFailure(pLine);
else (*(pEntry -> func))(++pLine);
}
}
}
skipLine: nCfgLine++;
pLine += strlen(pLine) + 1;
}
}
dos_close(nFileDesc);
}
struct table *LookUp(struct table *p, BYTE *token)
{
while(*(p -> entry) != '\0')
{
if(strcmp(p -> entry, token) == 0)
break;
else
++p;
}
return p;
}
BOOL SkipLine(char *pLine)
{
char kbdbuf[16];
keyboard *kp = (keyboard *)kbdbuf;
char *pKbd = &kp->kb_buf[0];
kp->kb_size = 12;
kp->kb_count = 0;
printf("%s [Y,N]?", pLine);
sti(kp);
pKbd = skipwh(pKbd);
if (*pKbd == 'n' || *pKbd == 'N')
return TRUE;
return FALSE;
}
BYTE *GetNumArg(BYTE *pLine, COUNT *pnArg)
{
/* look for NUMBER */
pLine = skipwh(pLine);
if(!isnum(pLine))
{
CfgFailure(pLine);
return (BYTE *)0;
}
return GetNumber(pLine, pnArg);
}
BYTE *GetStringArg(BYTE *pLine, BYTE *pszString)
{
/* look for STRING */
pLine = skipwh(pLine);
/* just return whatever string is there, including null */
return scan(pLine, pszString);
}
static VOID Buffers(BYTE *pLine)
{
COUNT nBuffers;
/* Get the argument */
if(GetNumArg(pLine, &nBuffers) == (BYTE *)0)
return;
/* Got the value, assign either default or new value */
Config.cfgBuffers = max(Config.cfgBuffers, nBuffers);
}
static VOID Files(BYTE *pLine)
{
COUNT nFiles;
/* Get the argument */
if(GetNumArg(pLine, &nFiles) == (BYTE *)0)
return;
/* Got the value, assign either default or new value */
Config.cfgFiles = max(Config.cfgFiles, nFiles);
}
static VOID Lastdrive(BYTE *pLine)
{
/* Format: LASTDRIVE = letter */
COUNT nFiles;
BYTE drv;
pLine = skipwh(pLine);
drv = *pLine & ~0x20;
if (drv < 'A' || drv > 'Z')
{
CfgFailure(pLine);
return;
}
drv -= 'A';
Config.cfgLastdrive = max(Config.cfgLastdrive, drv);
}
static VOID Switchar(BYTE *pLine)
{
/* Format: SWITCHAR = character */
GetStringArg(pLine, szBuf);
switchar = *szBuf;
}
static VOID Fcbs(BYTE *pLine)
{
/* Format: FCBS = totalFcbs [,protectedFcbs] */
if ((pLine = GetNumArg(pLine, &Config.cfgFcbs)) == 0)
return;
pLine = skipwh(pLine);
if (*pLine == ',')
GetNumArg(++pLine, &Config.cfgProtFcbs);
if (Config.cfgProtFcbs > Config.cfgFcbs)
Config.cfgProtFcbs = Config.cfgFcbs;
}
static VOID Country(BYTE *pLine)
{
/* Format: COUNTRY = countryCode, [codePage], filename */
UWORD ctryCode;
UWORD codePage;
if ((pLine = GetNumArg(pLine, &ctryCode)) == 0)
return;
pLine = skipwh(pLine);
if (*pLine == ',')
{
pLine = skipwh(pLine);
if (*pLine == ',')
{
codePage = 0;
++pLine;
} else {
if ((pLine = GetNumArg(pLine, &codePage)) == 0)
return;
}
pLine = skipwh(pLine);
if (*pLine == ',')
{
GetStringArg(++pLine, szBuf);
if (LoadCountryInfo(szBuf, ctryCode, codePage))
return;
}
}
CfgFailure(pLine);
}
static VOID Stacks(BYTE *pLine)
{
/* Format: STACKS = stacks [, stackSize] */
pLine = GetNumArg(pLine, &Config.cfgStacks);
if (*pLine == ',')
GetNumArg(++pLine, &Config.cfgStackSize);
if (Config.cfgStacks)
{
if (Config.cfgStackSize < 32) Config.cfgStackSize = 32;
if (Config.cfgStackSize > 512) Config.cfgStackSize = 512;
if (Config.cfgStacks > 64) Config.cfgStacks = 64;
}
}
static VOID InitPgm(BYTE *pLine)
{
/* Get the string argument that represents the new init pgm */
pLine = GetStringArg(pLine, Config.cfgInit);
/* Now take whatever tail is left and add it on as a single */
/* string. */
strcpy(Config.cfgInitTail, pLine);
/* and add a DOS new line just to be safe */
strcat(Config.cfgInitTail, "\r\n");
}
static VOID Break(BYTE *pLine)
{
/* Format: BREAK = (ON | OFF) */
BYTE *pTmp;
GetStringArg(pLine, szBuf);
break_ena = strcmp(szBuf, "OFF")? 1 : 0;
}
static VOID Device(BYTE *pLine)
{
VOID FAR *driver_ptr;
BYTE *pTmp;
exec_blk eb;
struct dhdr FAR *dhp;
struct dhdr FAR *next_dhp;
UWORD dev_seg = (((ULONG)FP_SEG(lpBase) << 4) + FP_OFF(lpBase) + 0xf) >> 4;
/* Get the device driver name */
GetStringArg(pLine, szBuf);
/* The driver is loaded at the top of allocated memory. */
/* The device driver is paragraph aligned. */
eb.load.reloc = eb.load.load_seg = dev_seg;
dhp = MK_FP(dev_seg, 0);
#ifdef DEBUG
printf("Loading device driver %s at segment %04x\n",
szBuf, dev_seg);
#endif
if (DosExec(3, &eb, szBuf) == SUCCESS)
{
while(FP_OFF(dhp) != 0xFFFF)
{
next_dhp = MK_FP(FP_SEG(dhp), FP_OFF(dhp -> dh_next));
dhp -> dh_next = nul_dev.dh_next;
link_dhdr(&nul_dev, dhp, pLine);
dhp = next_dhp;
}
} else CfgFailure(pLine);
}
static VOID CfgFailure(BYTE *pLine)
{
BYTE *pTmp = pLineStart;
printf("CONFIG.SYS error in line %d\n", nCfgLine);
printf(">>>%s\n", pTmp);
while(++pTmp != pLine)
printf(" ");
printf("^\n");
}
#ifndef KDB
static BYTE FAR *
KernelAlloc(WORD nBytes)
{
BYTE FAR *lpAllocated;
lpBase = AlignParagraph(lpBase);
lpAllocated = lpBase;
if (0x10000 - FP_OFF(lpBase) <= nBytes)
{
UWORD newOffs = (FP_OFF(lpBase) + nBytes) & 0xFFFF;
UWORD newSeg = FP_SEG(lpBase) + 0x1000;
lpBase = MK_FP(newSeg, newOffs);
} else lpBase += nBytes;
return lpAllocated;
}
#endif
#ifdef I86
static VOID FAR *AlignParagraph(VOID FAR *lpPtr)
{
ULONG lTemp;
UWORD uSegVal;
/* First, convert the segmented pointer to linear address */
lTemp = FP_SEG(lpPtr);
lTemp = (lTemp << 4) + FP_OFF(lpPtr);
/* Next, round up the linear address to a paragraph boundary. */
lTemp += 0x0f;
lTemp &= 0xfffffff0l;
/* Break it into segments. */
uSegVal = (UWORD)(lTemp >> 4);
/* and return an adddress adjusted to the nearest paragraph */
/* boundary. */
return MK_FP(uSegVal, 0);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -