⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.c

📁 GNU FreeDOS兼容MS DOS很好的东东.
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************//*                                                              *//*                          config.c                            *//*                            DOS-C                             *//*                                                              *//*                config.sys Processing Functions               *//*                                                              *//*                      Copyright (c) 1996                      *//*                      Pasquale J. Villani                     *//*                      All Rights Reserved                     *//*                                                              *//* This file is part of DOS-C.                                  *//*                                                              *//* DOS-C is free software; you can redistribute it and/or       *//* modify it under the terms of the GNU General Public License  *//* as published by the Free Software Foundation; either version *//* 2, or (at your option) any later version.                    *//*                                                              *//* DOS-C is distributed in the hope that it will be useful, but *//* WITHOUT ANY WARRANTY; without even the implied warranty of   *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See    *//* the GNU General Public License for more details.             *//*                                                              *//* You should have received a copy of the GNU General Public    *//* License along with DOS-C; see the file COPYING.  If not,     *//* write to the Free Software Foundation, Inc.,                 *//* 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.     *//****************************************************************/#include "portab.h"#include "init-mod.h"#include "dyndata.h"#ifdef VERSION_STRINGSstatic BYTE *RcsId =    "$Id: config.c,v 1.91 2005/09/08 23:48:25 perditionc Exp $";#endif#ifdef DEBUG#define DebugPrintf(x) printf x#else#define DebugPrintf(x)#endif#define para2far(seg) ((mcb FAR *)MK_FP((seg), 0))/**  Menu selection bar struct:  x pos, ypos, string*/#define MENULINEMAX 80#define MENULINESMAX 10struct MenuSelector{  int x;  int y;  BYTE bSelected;  BYTE Text[MENULINEMAX];};/** Structure below holds the menu-strings */STATIC struct MenuSelector MenuStruct[MENULINESMAX] BSS_INIT({0});int nMenuLine BSS_INIT(0);int MenuColor = -1;STATIC void WriteMenuLine(struct MenuSelector *menu){  iregs r;  unsigned char attr = (unsigned char)MenuColor;  char *pText = menu->Text;  if (pText[0] == 0)    return;  if(menu->bSelected)    attr = ((attr << 4) | (attr >> 4));  /* clear line */  r.a.x   = 0x0600;  r.b.b.h = attr;  r.c.b.l = r.d.b.l = menu->x;  r.c.b.h = r.d.b.h = menu->y;  r.d.b.l += strlen(pText) - 1;  init_call_intr(0x10, &r);  /* set cursor position: */  r.a.b.h = 0x02;  r.b.b.h = 0;  r.d.b.l = menu->x;  r.d.b.h = menu->y;  init_call_intr(0x10, &r);  printf("%s", pText);}/* Deselect the previously selected line */STATIC void DeselectLastLine(void){  struct MenuSelector *menu;  for (menu = MenuStruct; menu < &MenuStruct[MENULINESMAX]; menu++)  {    if (menu->bSelected)    {      /* deselect it: */      menu->bSelected = 0;      WriteMenuLine(menu);      break;    }  }}STATIC void SelectLine(int MenuSelected){  struct MenuSelector *menu;  DeselectLastLine(); /* clear previous selection */  menu = &MenuStruct[MenuSelected];  menu->bSelected = 1;  /* set selection flag for this one */  WriteMenuLine(menu);}UWORD umb_start BSS_INIT(0), UMB_top BSS_INIT(0);UWORD ram_top BSS_INIT(0); /* How much ram in Kbytes               */size_t ebda_size BSS_INIT(0);static UBYTE ErrorAlreadyPrinted[128] BSS_INIT({0});char master_env[128] BSS_INIT({0});static char *envp = master_env;struct config Config = {  0,  NUMBUFF,  NFILES,  0,  NFCBS,  0,  "command.com",  " /P /E:256\r\n",  NLAST,  0,  NSTACKS,  0,  STACKSIZE      /* COUNTRY= is initialized within DoConfig() */      , 0                       /* country ID */      , 0                       /* codepage */      , 0                       /* amount required memory */      , 0                       /* pointer to loaded data */      , 0                       /* strategy for command.com is low by default */      , 0                       /* default value for switches=/E:nnnn */};STATIC seg base_seg BSS_INIT(0);STATIC seg umb_base_seg BSS_INIT(0);BYTE FAR *lpTop BSS_INIT(0);STATIC unsigned nCfgLine BSS_INIT(0);COUNT UmbState BSS_INIT(0);STATIC BYTE szLine[256] BSS_INIT({0});STATIC BYTE szBuf[256] BSS_INIT({0});BYTE singleStep BSS_INIT(FALSE);        /* F8 processing */BYTE SkipAllConfig BSS_INIT(FALSE);     /* F5 processing */BYTE askThisSingleCommand BSS_INIT(FALSE);      /* ?device=  device?= */BYTE DontAskThisSingleCommand BSS_INIT(FALSE);  /* !files=            */COUNT MenuTimeout = -1;BYTE  MenuSelected BSS_INIT(0);UCOUNT MenuLine BSS_INIT(0);UCOUNT Menus BSS_INIT(0);STATIC VOID CfgMenuColor(BYTE * pLine);STATIC VOID Config_Buffers(BYTE * pLine);STATIC VOID sysScreenMode(BYTE * pLine);STATIC VOID sysVersion(BYTE * pLine);STATIC VOID CfgBreak(BYTE * pLine);STATIC VOID Device(BYTE * pLine);STATIC VOID DeviceHigh(BYTE * pLine);STATIC VOID Files(BYTE * pLine);STATIC VOID FilesHigh(BYTE * pLine);STATIC VOID Fcbs(BYTE * pLine);STATIC VOID CfgLastdrive(BYTE * pLine);STATIC VOID CfgLastdriveHigh(BYTE * pLine);STATIC BOOL LoadDevice(BYTE * pLine, char FAR *top, COUNT mode);STATIC VOID Dosmem(BYTE * pLine);STATIC VOID DosData(BYTE * pLine);STATIC VOID Country(BYTE * pLine);STATIC VOID InitPgm(BYTE * pLine);STATIC VOID InitPgmHigh(BYTE * pLine);STATIC VOID CmdInstall(BYTE * pLine);STATIC VOID CmdInstallHigh(BYTE * pLine);STATIC VOID CmdSet(BYTE * pLine);STATIC VOID CfgSwitchar(BYTE * pLine);STATIC VOID CfgSwitches(BYTE * pLine);STATIC VOID CfgFailure(BYTE * pLine);STATIC VOID CfgIgnore(BYTE * pLine);STATIC VOID CfgMenu(BYTE * pLine);STATIC VOID CfgMenuEsc(BYTE * pLine);STATIC VOID DoMenu(void);STATIC VOID CfgMenuDefault(BYTE * pLine);STATIC BYTE * skipwh(BYTE * s);STATIC BYTE * scan(BYTE * s, BYTE * d);STATIC BOOL isnum(char ch);#if 0STATIC COUNT tolower(COUNT c);#endifSTATIC char toupper(char c);STATIC VOID strupr(char *s);STATIC VOID mcb_init(UCOUNT seg, UWORD size, BYTE type);STATIC VOID mumcb_init(UCOUNT seg, UWORD size);STATIC VOID Stacks(BYTE * pLine);STATIC VOID StacksHigh(BYTE * pLine);STATIC VOID SetAnyDos(BYTE * pLine);STATIC VOID Numlock(BYTE * pLine);STATIC BYTE * GetNumArg(BYTE * pLine, COUNT * pnArg);BYTE *GetStringArg(BYTE * pLine, BYTE * pszString);STATIC int SkipLine(char *pLine);#if 0STATIC char * stristr(char *s1, char *s2);#endifSTATIC char strcaseequal(const char * d, const char * s);STATIC int LoadCountryInfoHardCoded(char *filename, COUNT ctryCode, COUNT codePage);STATIC void umb_init(void);void HMAconfig(int finalize);STATIC void config_init_buffers(int anzBuffers);     /* from BLOCKIO.C */STATIC void config_init_fnodes(int f_nodes_cnt);#ifdef I86STATIC VOID FAR * AlignParagraph(VOID FAR * lpPtr);#else#define AlignParagraph(x) ((VOID *)x)#endif#define EOF 0x1aSTATIC struct table * LookUp(struct table *p, BYTE * token);typedef void config_sys_func_t(BYTE * pLine);struct table {  BYTE *entry;  signed char pass;  config_sys_func_t *func;};STATIC struct table commands[] = {  /* first = switches! this one is special since it is asked for but     also checked before F5/F8 */  {"SWITCHES", 0, CfgSwitches},  /* rem is never executed by locking out pass                    */  {"REM", 0, CfgIgnore},  {";", 0,   CfgIgnore},  {"MENUCOLOR",0,CfgMenuColor},  {"MENUDEFAULT", 0, CfgMenuDefault},  {"MENU", 0, CfgMenu},         /* lines to print in pass 0 */  {"ECHO", 2, CfgMenu},         /* lines to print in pass 2 - install(high) */  {"EECHO", 2, CfgMenuEsc},     /* modified ECHO (ea) */  {"BREAK", 1, CfgBreak},  {"BUFFERS", 1, Config_Buffers},  {"COMMAND", 1, InitPgm},  {"COUNTRY", 1, Country},  {"DOS", 1, Dosmem},  {"DOSDATA", 1, DosData},  {"FCBS", 1, Fcbs},  {"FILES", 1, Files},  {"FILESHIGH", 1, FilesHigh},  {"LASTDRIVE", 1, CfgLastdrive},  {"LASTDRIVEHIGH", 1, CfgLastdriveHigh},  {"NUMLOCK", 1, Numlock},  {"SHELL", 1, InitPgm},  {"SHELLHIGH", 1, InitPgmHigh},  {"STACKS", 1, Stacks},  {"STACKSHIGH", 1, StacksHigh},  {"SWITCHAR", 1, CfgSwitchar},  {"SCREEN", 1, sysScreenMode},   /* JPP */  {"VERSION", 1, sysVersion},     /* JPP */  {"ANYDOS", 1, SetAnyDos},       /* tom */  {"DEVICE", 2, Device},  {"DEVICEHIGH", 2, DeviceHigh},  {"INSTALL", 2, CmdInstall},  {"INSTALLHIGH", 2, CmdInstallHigh},  {"SET", 2, CmdSet},    /* default action                                               */  {"", -1, CfgFailure}};/* RE function for menu. */int  findend(BYTE * s){  int nLen = 0;  /* 'marks' end if at least ten spaces, 0, or newline is found. */  while (*s && (*s != 0x0d || *s != 0x0a) )  {    BYTE *p= skipwh(s);    /* ah, more than 9 whitespaces ? We're done here (hrmph!) */    if(p - s >= 10)      break;    nLen++;    ++s;  }  return nLen;}BYTE *pLineStart BSS_INIT(0);BYTE HMAState BSS_INIT(0);#define HMA_NONE 0              /* do nothing */#define HMA_REQ 1               /* DOS = HIGH detected */#define HMA_DONE 2              /* Moved kernel to HMA */#define HMA_LOW 3               /* Definitely LOW *//* Do first time initialization.  Store last so that we can reset it    *//* later.                                                               */void PreConfig(void){  /* Initialize the base memory pointers                          */#ifdef DEBUG  {    printf("SDA located at 0x%p\n", internal_data);  }#endif  /* Begin by initializing our system buffers                     */#ifdef DEBUG/*  printf("Preliminary %d buffers allocated at 0x%p\n", Config.cfgBuffers, buffers);*/#endif  LoL->DPBp =      DynAlloc("DPBp", blk_dev.dh_name[0], sizeof(struct dpb));  /* Initialize the file table                                    */  config_init_fnodes(Config.cfgFiles);  LoL->sfthead = MK_FP(FP_SEG(LoL), 0xcc); /* &(LoL->firstsftt) */  /* LoL->FCBp = (sfttbl FAR *)&FcbSft; */  /* LoL->FCBp = (sfttbl FAR *)     KernelAlloc(sizeof(sftheader)     + Config.cfgFiles * sizeof(sft)); */  config_init_buffers(Config.cfgBuffers);  LoL->CDSp = KernelAlloc(sizeof(struct cds) * LoL->lastdrive, 'L', 0);#ifdef DEBUG  printf("Preliminary:\n f_node 0x%p\n", LoL->f_nodes);/*  printf(" FCB table 0x%p\n",LoL->FCBp);*/  printf(" sft table 0x%p\n", LoL->sfthead);  printf(" CDS table 0x%p\n", LoL->CDSp);  printf(" DPB table 0x%p\n", LoL->DPBp);#endif  /* Done.  Now initialize the MCB structure                      */  /* This next line is 8086 and 80x86 real mode specific          */#ifdef DEBUG  printf("Preliminary  allocation completed: top at %p\n", lpTop);#endif}/* Do second pass initialization: near allocation and MCBs              */void PreConfig2(void){  struct sfttbl FAR *sp;  /* initialize NEAR allocated things */  /* Initialize the base memory pointers from last time.          */  /*     if the kernel could be moved to HMA, everything behind the dynamic     near data is free.     otherwise, the kernel is moved down - behind the dynamic allocated data,     and allocation starts after the kernel.   */  base_seg = LoL->first_mcb = FP_SEG(AlignParagraph((BYTE FAR *) DynLast() + 0x0f));  if (Config.ebda2move)  {    ebda_size = ebdasize();    ram_top += ebda_size / 1024;    if (ebda_size > Config.ebda2move)      ebda_size = Config.ebda2move;  }  /* We expect ram_top as Kbytes, so convert to paragraphs */  mcb_init(base_seg, ram_top * 64 - LoL->first_mcb - 1, MCB_LAST);  sp = LoL->sfthead;  sp = sp->sftt_next = KernelAlloc(sizeof(sftheader) + 3 * sizeof(sft), 'F', 0);  sp->sftt_next = (sfttbl FAR *) - 1;  sp->sftt_count = 3;  if (ebda_size)  /* move the Extended BIOS Data Area from top of RAM here */    movebda(ebda_size, FP_SEG(KernelAlloc(ebda_size, 'I', 0)));  if (UmbState == 2)    umb_init();}/* Do third pass initialization.                                        *//* Also, run config.sys to load drivers.                                */void PostConfig(void){  sfttbl FAR *sp;  /* We could just have loaded FDXMS or HIMEM */  if (HMAState == HMA_REQ && MoveKernelToHMA())    HMAState = HMA_DONE;    if (Config.cfgDosDataUmb)  {    Config.cfgFilesHigh = TRUE;    Config.cfgLastdriveHigh = TRUE;    Config.cfgStacksHigh = TRUE;  }          /* compute lastdrive ... */  LoL->lastdrive = Config.cfgLastdrive;  if (LoL->lastdrive < LoL->nblkdev)    LoL->lastdrive = LoL->nblkdev;  DebugPrintf(("starting FAR allocations at %x\n", base_seg));  /* Initialize the file table                                    */  config_init_fnodes(Config.cfgFiles);  /* Begin by initializing our system buffers                     */  /* dma_scratch = (BYTE FAR *) KernelAllocDma(BUFFERSIZE); */#ifdef DEBUG  /* printf("DMA scratchpad allocated at 0x%p\n", dma_scratch); */#endif  config_init_buffers(Config.cfgBuffers);/* LoL->sfthead = (sfttbl FAR *)&basesft; */  /* LoL->FCBp = (sfttbl FAR *)&FcbSft; */  /* LoL->FCBp = KernelAlloc(sizeof(sftheader)     + Config.cfgFiles * sizeof(sft)); */  sp = LoL->sfthead->sftt_next;  sp = sp->sftt_next = (sfttbl FAR *)    KernelAlloc(sizeof(sftheader) + (Config.cfgFiles - 8) * sizeof(sft), 'F',                Config.cfgFilesHigh);  sp->sftt_next = (sfttbl FAR *) - 1;  sp->sftt_count = Config.cfgFiles - 8;  LoL->CDSp = KernelAlloc(sizeof(struct cds) * LoL->lastdrive, 'L', Config.cfgLastdriveHigh);#ifdef DEBUG  printf("Final: \n f_node 0x%p\n", LoL->f_nodes);/*  printf(" FCB table 0x%p\n",LoL->FCBp);*/  printf(" sft table 0x%p\n", LoL->sfthead->sftt_next);  printf(" CDS table 0x%p\n", LoL->CDSp);  printf(" DPB table 0x%p\n", LoL->DPBp);#endif  if (Config.cfgStacks)  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -