📄 config.c
字号:
while (++pTmp != pLine) printf(" "); printf("^\n");}struct submcb { char type; unsigned short start; unsigned short size; char unused[3]; char name[8];};void FAR * KernelAllocPara(size_t nPara, char type, char *name, int mode){ seg base, start; struct submcb FAR *p; if (UmbState != 1) mode = 0; if (mode) { base = umb_base_seg; start = umb_start; } else { base = base_seg; start = LoL->first_mcb; } /* create the special DOS data MCB if it doesn't exist yet */ DebugPrintf(("kernelallocpara: %x %x %x %c %d\n", start, base, nPara, type, mode)); if (base == start) { mcb FAR *p = para2far(base); base++; mcb_init(base, p->m_size - 1, p->m_type); mumcb_init(FP_SEG(p), 0); p->m_name[1] = 'D'; } nPara++; mcb_init(base + nPara, para2far(base)->m_size - nPara, para2far(base)->m_type); para2far(start)->m_size += nPara; p = (struct submcb FAR *)para2far(base); p->type = type; p->start = FP_SEG(p)+1; p->size = nPara-1; if (name) fmemcpy(p->name, name, 8); base += nPara; if (mode) umb_base_seg = base; else base_seg = base; return MK_FP(FP_SEG(p)+1, 0);}void FAR * KernelAlloc(size_t nBytes, char type, int mode){ void FAR *p; size_t nPara = (nBytes + 15)/16; if (LoL->first_mcb == 0) { /* prealloc */ lpTop = MK_FP(FP_SEG(lpTop) - nPara, FP_OFF(lpTop)); p=AlignParagraph(lpTop); } else { p = KernelAllocPara(nPara, type, NULL, mode); } fmemset(p, 0, nBytes); return p;}#ifdef I86#if 0STATIC BYTE FAR * KernelAllocDma(WORD bytes, char type){ if ((base_seg & 0x0fff) + (bytes >> 4) > 0x1000) { KernelAllocPara((base_seg + 0x0fff) & 0xf000 - base_seg, type, NULL, 0); } return KernelAlloc(bytes, type);}#endifSTATIC void FAR * AlignParagraph(VOID FAR * lpPtr){ UWORD uSegVal; /* First, convert the segmented pointer to linear address */ uSegVal = FP_SEG(lpPtr); uSegVal += (FP_OFF(lpPtr) + 0xf) >> 4; if (FP_OFF(lpPtr) > 0xfff0) uSegVal += 0x1000; /* handle overflow */ /* and return an adddress adjusted to the nearest paragraph */ /* boundary. */ return MK_FP(uSegVal, 0);}#endifSTATIC int iswh(unsigned char c){ return (c == '\r' || c == '\n' || c == '\t' || c == ' ');}STATIC BYTE * skipwh(BYTE * s){ while (iswh(*s)) ++s; return s;}STATIC BYTE * scan(BYTE * s, BYTE * d){ askThisSingleCommand = FALSE; DontAskThisSingleCommand = FALSE; s = skipwh(s); MenuLine = 0; /* does the line start with "123?" */ if (isnum(*s)) { unsigned numbers = 0; for ( ; isnum(*s); s++) numbers |= 1 << (*s -'0'); if (*s == '?') { MenuLine = numbers; Menus |= numbers; s = skipwh(s+1); } } /* !dos=high,umb ?? */ if (*s == '!') { DontAskThisSingleCommand = TRUE; s = skipwh(s+1); } if (*s == ';') { /* semicolon is a synonym for rem */ *d++ = *s++; } else while (*s && !iswh(*s) && *s != '=') { if (*s == '?') askThisSingleCommand = TRUE; else *d++ = *s; s++; } *d = '\0'; return s;}STATIC BOOL isnum(char ch){ return (ch >= '0' && ch <= '9');}/* Yet another change for true portability (PJV) */STATIC char toupper(char c){ if (c >= 'a' && c <= 'z') c -= 'a' - 'A'; return c;}/* Convert string s to uppercase */STATIC VOID strupr(char *s){ while (*s) { *s = toupper(*s); s++; }}/* The following code is 8086 dependant */#if 1 /* ifdef KERNEL */STATIC VOID mcb_init_copy(UCOUNT seg, UWORD size, mcb *near_mcb){ near_mcb->m_size = size; fmemcpy(MK_FP(seg, 0), near_mcb, sizeof(mcb));}STATIC VOID mcb_init(UCOUNT seg, UWORD size, BYTE type){ static mcb near_mcb BSS_INIT({0}); near_mcb.m_type = type; mcb_init_copy(seg, size, &near_mcb);}STATIC VOID mumcb_init(UCOUNT seg, UWORD size){ static mcb near_mcb = { MCB_NORMAL, 8, 0, {0,0,0}, {"SC"} }; mcb_init_copy(seg, size, &near_mcb);}#endifchar *strcat(register char * d, register const char * s){ strcpy(d + strlen(d), s); return d;}/* compare two ASCII strings ignoring case */STATIC char strcaseequal(const char * d, const char * s){ char ch; while ((ch = toupper(*s++)) == toupper(*d++)) if (ch == '\0') return 1; return 0;}/* moved from BLOCKIO.C here. that saves some relocation problems */STATIC void config_init_buffers(int wantedbuffers){ struct buffer FAR *pbuffer; unsigned buffers = 0; /* fill HMA with buffers if BUFFERS count >=0 and DOS in HMA */ if (wantedbuffers < 0) wantedbuffers = -wantedbuffers; else if (HMAState == HMA_DONE) buffers = (0xfff0 - HMAFree) / sizeof(struct buffer); if (wantedbuffers < 6) /* min 6 buffers */ wantedbuffers = 6; if (wantedbuffers > 99) /* max 99 buffers */ { printf("BUFFERS=%u not supported, reducing to 99\n", wantedbuffers); wantedbuffers = 99; } if (wantedbuffers > buffers) /* more specified than available -> get em */ buffers = wantedbuffers; LoL->nbuffers = buffers; LoL->inforecptr = &LoL->firstbuf; { size_t bytes = sizeof(struct buffer) * buffers; pbuffer = HMAalloc(bytes); if (pbuffer == NULL) { pbuffer = KernelAlloc(bytes, 'B', 0); if (HMAState == HMA_DONE) firstAvailableBuf = MK_FP(0xffff, HMAFree); } else { LoL->bufloc = LOC_HMA; /* space in HMA beyond requested buffers available as user space */ firstAvailableBuf = pbuffer + wantedbuffers; } } LoL->deblock_buf = DiskTransferBuffer; LoL->firstbuf = pbuffer; DebugPrintf(("init_buffers (size %u) at", sizeof(struct buffer))); DebugPrintf((" (%p)", LoL->firstbuf)); buffers--; pbuffer->b_prev = FP_OFF(pbuffer + buffers); { int i = buffers; do { pbuffer->b_next = FP_OFF(pbuffer + 1); pbuffer++; pbuffer->b_prev = FP_OFF(pbuffer - 1); } while (--i); } pbuffer->b_next = FP_OFF(pbuffer - buffers); /* now, we can have quite some buffers in HMA -- up to 50 for KE38616. so we fill the HMA with buffers but not if the BUFFERS count is negative ;-) */ DebugPrintf((" done\n")); if (FP_SEG(pbuffer) == 0xffff) { buffers++; printf("Kernel: allocated %d Diskbuffers = %u Bytes in HMA\n", buffers, buffers * sizeof(struct buffer)); }}STATIC void config_init_fnodes(int f_nodes_cnt){ struct f_node FAR *p; size_t bytes; /* number of allocated files */ LoL->f_nodes_cnt = f_nodes_cnt; bytes = f_nodes_cnt * sizeof(struct f_node); p = HMAalloc(bytes); if (p == NULL) p = KernelAlloc(bytes, 'F', 0); LoL->f_nodes = p;}/* Undocumented feature: ANYDOS will report to MSDOS programs just the version number they expect. be careful with it!*/STATIC VOID SetAnyDos(BYTE * pLine){ UNREFERENCED_PARAMETER(pLine); ReturnAnyDosVersionExpected = TRUE;}STATIC VOID CfgIgnore(BYTE * pLine){ UNREFERENCED_PARAMETER(pLine);}/* 'MENU'ing stuff although it's worse then MSDOS's , its better then nothing */STATIC void ClearScreen(unsigned char attr);STATIC VOID CfgMenu(BYTE * pLine){ int nLen; BYTE *pNumber = pLine; printf("%s\n",pLine); if (MenuColor == -1) return; pLine = skipwh(pLine); /* skip drawing characters in cp437, which is what we'll have just after booting! */ while ((unsigned char)*pLine >= 0xb0 && (unsigned char)*pLine < 0xe0) pLine++; pLine = skipwh(pLine); /* skip more whitespaces... */ /* now I'm expecting a number here if this is a menu-choice line. */ if (isnum(pLine[0])) { struct MenuSelector *menu = &MenuStruct[pLine[0]-'0']; menu->x = (pLine-pNumber); /* xpos is at start of number */ menu->y = nMenuLine; /* copy menu text: */ nLen = findend(pLine); /* length is until cr/lf, null or three spaces */ /* max 40 chars including nullterminator (change struct at top of file if you want more...) */ if (nLen > MENULINEMAX-1) nLen = MENULINEMAX-1; memcpy(menu->Text, pLine, nLen); menu->Text[nLen] = 0; /* nullTerminate */ } nMenuLine++;}STATIC VOID CfgMenuEsc(BYTE * pLine){ BYTE * check; for (check = pLine; check[0]; check++) if (check[0] == '$') check[0] = 27; /* translate $ to ESC */ printf("%s\n",pLine);}STATIC VOID DoMenu(void){ iregs r; int key = -1; if (Menus == 0) return; InitKernelConfig.SkipConfigSeconds = -1; if (MenuColor == -1) Menus |= 1 << 0; /* '0' Menu always allowed */ nMenuLine+=2; /* use this to position "select menu" text (ypos): */ for (;;) { int i, j;RestartInput: if (MenuColor != -1) { SelectLine(MenuSelected); /* select current line. */ /* set new cursor position: */ r.a.b.h = 0x02; r.b.b.h = 0; r.d.b.l = 3; r.d.b.h = nMenuLine; init_call_intr(0x10, &r); /* set cursor pos */ } printf("Select from Menu ["); for (i = 0, j = 1; i <= 9; i++, j<<=1) if (Menus & j) printf("%c", '0' + i); printf("], or press [ENTER]"); if (MenuColor != -1) printf(" (Selection=%d) ", MenuSelected); if (MenuTimeout >= 0) printf("- %d \b", MenuTimeout); else printf(" \b\b\b\b\b"); if (MenuColor != -1) printf("\r\n\n "); else printf(" -"); printf(" Singlestepping (F8) is: %s \r", singleStep ? "ON " : "OFF"); key = GetBiosKey(MenuTimeout >= 0 ? 1 : -1); if (key == -1) /* timeout, take default */ { if (MenuTimeout > 0) { MenuTimeout--;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -