Beispiel #1
0
void maxfilt_centered_double_inplace( double *a, int len, int support )
{   static double **U = NULL;
    static size_t maxUbytes = 0;
    size_t maxU,maxR;
    unsigned int    iUf,iUb,iRf,iRb;
    static double *R = NULL;
    static size_t maxRbytes = 0;
    double *e;
    int off = support;
    int c = support/2+1;
    double this,last;
    assert(support > 2);

    U = request_storage_pow2items(U,&maxUbytes,sizeof(double*), 2*support , "maxfilt_centered_double_inplace");
    maxU = maxUbytes / sizeof(double*) - 1;
    iUf = maxU/2-1;
    iUb = maxU/2;
    R = request_storage_pow2items(R,&maxRbytes,sizeof(double), 2*(off-c), "maxfilt_centered_double_inplace");
    maxR = maxRbytes / sizeof(double) - 1;
    iRf=-1;
    iRb=0;

    //The middle (support entirely in interval)
    last = *a;
    for( e=a+1; e < a+len; e++ )
    {   this = *e;
        if( e-a >= c )
            pushf(R) = isempty(U) ? last : *peekf(U);
        if( e-a >= off  )
            e[-off] = popb(R);
        //progress("iRf:%5d\tiUf:%5d\tiUb:%5d\tsz:%5d\n",iRf,iUf,iUb,iUf-iUb+1);
        if( this > last )
        {   while( !isempty(U) )
            {   if( this <= *peekb(U) )
                {   if( e-off == peekf(U) )
                        popf_noassign(U);
                    break;
                }
                if( !isempty(U) )
                    popb_noassign(U);
            }
        } else
        {   pushb(U)  = e-1;
            if( (e-off) == peekf(U) )
                popf_noassign(U);
        }
        last = this;
    }
    //The end
    for( ; e <= a+len+c; e++ )
    {   pushf(R) = isempty(U) ? e[-1] : *peekf(U);
        e[-off] = popb(R);

        pushb(U)  = e-1;
        if( (e-off) == peekf(U) )
            popf_noassign(U);
    }
}
Beispiel #2
0
static int scan (void * arg, word segm, word ofs) {
        Context_Tag tag;
	ctxt_info_t *info;

        (void)arg;
	assert(segm);
	assert(ofs != (word)-1);

redo:
	if((tag = peekb(segm, ofs), ctxtIsInfoTag(tag))) {
		info = &CTXT_INFO_STRUCT(tag);
		if(peekb(segm, ofs + 1) == '=' && peekb(segm, ofs + 4) == 0) {
			/* status entry */
			info->c_sizemax = peekw(segm, ofs + 2) & ~0x8001;
		} else {		/* normal entry */
			char far *p = MK_FP(segm, ofs + 1);
			unsigned num;

			for(num = 0; isxdigit(*p); ++p) {
				num <<= 8;
				if(isdigit(*p))
					num |= *p & 0xf;
				else {
					assert(islower(*p));
					num |= *p - 'a' + 10;
				}
			}
			if(*p == '=') {
				info->c_sizecur += env_varlen(segm, ofs);
				if(num < info->c_nummin)
					info->c_nummin = num;
				if(num > info->c_nummax)
					info->c_nummax = num;
			} else {
				/* Invalid entry -> remove to make room for useful stuff */
				env_subVarOffset(segm, ofs);
				goto redo;
			}
		}
	} else if(tag > ' ') {			/* Alias */
		CTXT_INFO(CTXT_TAG_ALIAS, sizecur) += env_varlen(segm ,ofs);
	}

	return 0;		/* proceed */
}
Beispiel #3
0
int fstrlen(unsigned short int dseg, unsigned short int doff)
{
    unsigned short int i = 0;

    while (peekb(dseg, doff++))
        i++;

    return i;
}
Beispiel #4
0
word nxtMCB(word mcb)
{	DBG_ENTER("nxtMCB", Suppl_mcb)
	DBG_ARGUMENTS( ("MCB=%u", mcb) )
	assert(mcb);

	DBG_RETURN_BI( peekb(mcb, 0) == 'M'
		? MCB2SEG(mcb) + peekw(mcb, MCB_OFF_SIZE)
		: 0)
}
Beispiel #5
0
int _fMemiCmp(unsigned const dseg, unsigned dofs
 , unsigned const sseg, unsigned sofs, unsigned length)
{	int d;

	DBG_ENTER("_fMemiCmp", Suppl_farmem)

	if(!length)
		DBG_RETURN_I( 0)

	if((dseg | dofs) == 0)
		DBG_RETURN_I((sseg | sofs) != 0)
	if((sseg | sofs) == 0)
		DBG_RETURN_I(-1)

	while((d = toUpper(peekb(dseg, dofs++)) - toUpper(peekb(sseg, sofs++)))
	 == 0 && --length);

	DBG_RETURN_I( d)
}
Beispiel #6
0
unsigned _fstrchr(unsigned const seg, unsigned ofs, const unsigned value)
{	unsigned char v, i;

	v = value;
	do {
		if((i = peekb(seg, ofs)) == v)
			return ofs;
		if(!++ofs)
			break;
	} while(i);

	return 0;
}
Beispiel #7
0
word env_endOfVars(const word segm)
{	word offset;

	DBG_ENTER("env_endOfVars", Suppl_env)
	DBG_ARGUMENTS( ("env=%u", segm) )

	chkMem
	
	assert(segm != 0);

	offset = 0;					/* env starts always at location 0 */

	while(peekb(segm, offset))	/* there is a variable */
		offset += env_varlen(segm, offset);

	DBG_RETURN_U( offset)				/* This is the terminator byte */
}
Beispiel #8
0
static int renumber(void *arg, word segm, word ofs)
{	char buf[CTXT_ITEMNAME_LENGTH];

#define tag (Context_Tag)(int)arg

	assert(segm);
	assert(ofs != (word)-1);

	if(ctxtProbeItemTag(segm, ofs, arg)) {
		ctxtMkItemName(buf, tag, ++CTXT_INFO(tag, nummax));
		assert(peekb(segm , ofs + strlen(buf)) == '=');
		_fmemcpy(MK_FP(segm, ofs), TO_FP(buf), strlen(buf));
	}

#undef tag
	return 0;
}
Beispiel #9
0
int tty_write(struct inode *inode, struct file *file, char *data, int len)
{
    register struct tty *tty = determine_tty(inode->i_rdev);
    register char *pi;
#if 0
    int blocking = (file->f_flags & O_NONBLOCK) ? 0 : 1;
#endif
    __u16 tmp;

    pi = 0;
    while (((int)pi) < len) {
	tmp = peekb(current->t_regs.ds, (__u16) (data + ((int)pi)));
	tty_charout(tty, (unsigned char) tmp /* , blocking */ );
	++pi;
    }
    tty->ops->write(tty);
    return (int)pi;
}
Beispiel #10
0
unsigned ebdasize(void)
{
  unsigned ebdaseg = peek(0, EBDASEG);
  unsigned ramsize = ram_top;

  if (ramsize == peek(0, RAMSIZE))
    if (ramsize * 64 == ebdaseg && ramsize < 640 && peek(0, RAMSIZE) == ramsize)
    {
    unsigned ebdasz = peekb(ebdaseg, 0);

    /* sanity check: is there really no more than 63 KB?
     * must be at 640k (all other values never seen and are untested)
     */
    if (ebdasz <= 63 && ramsize + ebdasz == 640)
      return ebdasz * 1024U;
    }
  return 0;
}
Beispiel #11
0
int init_tty (void) /*{{{*/
{
   union REGS r;
   struct SREGS s;

   if (TTY_Initialized) return 0;
   bios_key_f = peekb(0x40,0x96) & 0x10; /* enhanced keyboard flag */

   /* Check for system type */
   delay_ptr = delay;
   r.x.ax = 0xC000;
   int86x (0x15, &r, &r, &s);
   if ((r.x.cflag == 0) && (r.h.al == 0))
     {
	unsigned char *table;

	table = MK_FP(s.es, r.x.bx);
	switch (table[2])
	  {
	   case 0xFF:		       /* pc */
	   case 0xFE:		       /* xt */
	   case 0xFB:		       /* xt */
	   case 0xFD:		       /* pc-jr */
	     break;

	   /* AT and higher */
	   default:
	     delay_ptr = my_delay;
	  }
     }

   set_ctrl_break(0);
   ctrlbrk(ctrl_break);
   init_int9_handler();

   TTY_Initialized = 1;

   if (Batch == 0)
     {
	if (X_Open_Mouse_Hook != NULL) (*X_Open_Mouse_Hook) ();
     }
   X_Set_Abort_Char_Hook = ibmpc_set_abort_char;
   return 0;
}
Beispiel #12
0
/* a bit naughty; take the TOS and do an indirection on it,
	directly accessing ev++ for the .w/b/l */
word do_indirection(void)
{
ulong ind;
long result;
char *p,s;
word err;
bool got;

	if (topitem==botitem)
		return ERRE_ITEMUNDERFLOW;
	must(coerce_type(--topitem,EXPR_LONG,&ind));	/* pops it */
	p=ev;
	got=FALSE;
	if (*p++=='.')
		{
		s=upper(*p++);
		if (s=='B')
			{
			result=peekb(ind);
			if (upper(*p)==s)
				{
				p++;
				result=(signed char)result;
				}
			ev=p; got=TRUE;
			}
		else if (s=='W')
			{
			if (checking)
				result=0;
			else
				{
				must(safe_peekw(ind,(uword*)&result));
				result>>=16;
				}
			if (upper(*p)==s)
				{
				p++;
				result=(word)result;
				}
			ev=p; got=TRUE;
			}
		else if (s=='L')
Beispiel #13
0
/*--------------------------------------------------------------------------
  INT 09h - Interrupcao de Teclado
 --------------------------------------------------------------------------*/
void interrupt int_09h()
{
  if ((inportb(0x60) == scan_tecla) &&            /* HOT KEY pressionada ? */
      ((peekb (0x40,0x17) & tecla_shift) != 0)) {
    auxb = inportb(0x61);
    outportb (0x61,auxb | 0x80);                  /* Sim, avisa o reconhe- */
    outportb (0x61,auxb);                         /* cimento da tecla para */
    outportb (0x20,0x20);                         /* o controlador         */
    if (video_on) {                               /* Chaveia Video         */
      video_on = 0;
      outportb (porta_video,desl_video);
    }
    else {
      video_on = 1;
      outportb (porta_video,liga_video);
    }
  }
  else (*velha_int_09h)();                        /* Chama int Original    */
}
Beispiel #14
0
int tty_read(struct inode *inode, struct file *file, char *data, int len)
{
#if 1
    register struct tty *tty = determine_tty(inode->i_rdev);
    register char *pi = 0;
    int j, k;
    int rawmode = (tty->termios.c_lflag & ICANON) ? 0 : 1;
    int blocking = (file->f_flags & O_NONBLOCK) ? 0 : 1;
    unsigned char ch;

    if (len != 0) {
	do {
	    if (tty->ops->read) {
		tty->ops->read(tty);
		blocking = 0;
	    }
	    j = chq_getch(&tty->inq, &ch, blocking);

	    if (j == -1) {
		if (!blocking)
		    break;
		return -EINTR;
	    }
	    if (!rawmode && (j == 04))	/* CTRL-D */
		break;
	    if (rawmode || (j != '\b')) {
		pokeb(current->t_regs.ds, (__u16) (data + ((int)pi)), ch);
		++pi;
		tty_echo(tty, ch);
	    } else if (((int)pi) > 0) {
		--pi;
		k = ((peekb(current->t_regs.ds, (__u16) (data + ((int)pi)))
		      == '\t') ? TAB_SPACES : 1);
		do {
		    tty_echo(tty, ch);
		} while (--k);
	    }
	} while (((int)pi) < len && (rawmode || j != '\n'));
    }
    return (int) pi;


#else
    register struct tty *tty = determine_tty(inode->i_rdev);
    int i = 0, j = 0, k, lch;
    int rawmode = (tty->termios.c_lflag & ICANON) ? 0 : 1;
    int blocking = (file->f_flags & O_NONBLOCK) ? 0 : 1;
    unsigned char ch;

    if (len == 0)
	return 0;

    do {
	if (tty->ops->read) {
	    tty->ops->read(tty);
	    blocking = 0;
	}
	j = chq_getch(&tty->inq, &ch, blocking);

	if (j == -1)
	    if (blocking)
		return -EINTR;
	    else
		break;
	if (!rawmode && (j == 04))	/* CTRL-D */
	    break;
	if (rawmode || (j != '\b')) {
	    pokeb(current->t_regs.ds, (__u16) (data + i++), ch);
	    tty_echo(tty, ch);
	} else if (i > 0) {
	    lch = ((peekb(current->t_regs.ds, (__u16) (data + --i)) == '\t')
			? TAB_SPACES : 1);
	    for (k = 0; k < lch; k++)
		tty_echo(tty, ch);
	}
    } while (i < len && (rawmode || j != '\n'));

    return i;
#endif
}
Beispiel #15
0
int main()
{
    char *filename[32];
    FILE*fp;
    char ch,flag;
    unsigned long n,m,k=0;
    clrscr();
    printf("Please input the object file:\n");
    gets(filename);
    printf(".......");
    if((fp=fopen(filename,"w+b"))==0)
    {
       printf("Cannot open the file %s\n",filename);
       exit(0);
    }
    for(m=0;m<40960;m+=4096)
    {
       for(n=0;n<65536;n++)
       {
          ch=peekb(m,n);
          if((ch<32&&ch!=13)||(ch>126&&ch<160))
          {
            flag=0;
            continue;
          }
          if(ch>160&&flag==0)
          {
             flag=ch;
             continue;
          }
          k++;
          if(ch<160)
          {
            fputc(ch,fp);
            if(ch==13)
            {
               fputc(10,fp);
               k=0;
            }
          }
          else
          {
             fputc(flag,fp);
             fputc(ch,fp);
             k++;
             flag=0;
          }
          if(k==MAXLINE-1)
          {
            fputc(13,fp);
            fputc(10,fp);
            k=0;
          }
       }
    }
    printf("\nRecover the text successfully!!\n");
    fclose(fp);
    printf("\nPlease input any key to quit...\n");
    getch();
    return 0;
}
Beispiel #16
0
static unsigned vpeekb(uint8_t* address) {
	return peekb(VGAGetFramebufferSegment(), address);
}
Beispiel #17
0
int initialize(void)
{
  //int rc;
  int comPath;                /* path to COMMAND.COM (for COMSPEC/reload) */
  char *newTTY;                 /* what to change TTY to */
  int showinfo;                 /* show initial info only if no command line options */

  int ec;           /* error code */
  unsigned offs;        /* offset into environment segment */

  int cmdlen;         /* length of command line */
  char *cmdline;        /* command line duplicated into heap */
  char *p, *h, *q;
#ifdef FEATURE_CALL_LOGGING
#ifndef INCLUDE_CMD_FDDEBUG
  FILE *f;
#endif
#endif

/* Set up the host environment of COMMAND.COM */

	/* Install the dummy handlers for Criter and ^Break */
	initCBreak();
	setvect(0x23, cbreak_handler);
	setvect(0x24, dummy_criter_handler);

  /* DOS shells patch the PPID to the own PID, how stupid this is, however,
    because then DOS won't terminate them, e.g. when a Critical Error
    occurs that is not detected by COMMAND.COM */

  oldPSP = OwnerPSP;
  atexit(exitfct);
  OwnerPSP = _psp;

	dbg_printmem();
#ifdef DEBUG
	{ void* p;
		if((p = malloc(5*1024)) == 0)
			dprintf(("[MEM: Out of memory allocating test block during INIT]"));
		else free(p);
	}
#endif

#ifdef FEATURE_KERNEL_SWAP_SHELL
	if(kswapInit()) {		/* re-invoked */
		if(kswapLoadStruc()) {
			/* OK, on success we need not really keep the shell trick
				(pretend we are our own parent), which might cause
				problems with beta-software-bugs ;-)
				In fact, KSSF will catch up our crashes and re-invoke
				FreeCOM, probably with the loss of any internal
				settings. */
			  OwnerPSP = oldPSP;
			return E_None;
		}
	}
#endif

  /* Some elder DOSs may not pass an initializied environment segment */
  if (env_glbSeg && !isMCB(SEG2MCB(env_glbSeg)))
    env_setGlbSeg(0);       /* Disable the environment */

/* Now parse the command line parameters passed to COMMAND.COM */
  /* Preparations */
  newTTY = 0;
  comPath = tracemode = 0;
  showinfo = 1;

  /* Because FreeCom should be executed in a DOS3+ compatible
    environment most of the time, it is assumed that its path
    can be determined from the environment.
    This has the advantage that the string area is accessable
    very early in the run.
    The name of the current file is string #0. */
  if((offs = env_string(0, 0)) != 0)    /* OK, environment filled */
    grabComFilename(0, (char far *)MK_FP(env_glbSeg, offs));
  /* After that argv[0] is no longer used and maybe zapped.
  	This also will help, as most programs altering the environment
  	segment externally don't expect a string area. */
  env_nullStrings(0);

  /* Aquire the command line, there are three possible sources:
    1) DOS command line @PSP:0x80 as pascal string,
    2) extended DOS command line environment variable CMDLINE,
      if peekb(PSP, 0x80) == 127,&
    3) MKS command line @ENV:2, if peekb(ENV, 0) == '~'
    	&& peekb(ENV, 1) == '='

    Currently implemented is version #1 only
  */
  cmdlen = peekb(_psp, 0x80);
  if(cmdlen < 0 || cmdlen > 126) {
    error_corrupt_command_line();
    cmdlen = 0;
  }
    /* duplicate the command line into the local address space */
  if((cmdline = malloc(cmdlen + 1)) == 0) {
    error_out_of_memory();  /* Cannot recover from this problem */
    return E_NoMem;
  }
  _fmemcpy((char far*)cmdline, MK_FP(_psp, 0x81), cmdlen);
  cmdline[cmdlen] = '\0';
#ifdef FEATURE_CALL_LOGGING
#ifndef INCLUDE_CMD_FDDEBUG
  if((f = fopen(logFilename, "at")) == 0) {
    fprintf(stderr, "Cannot open logfile: \"%s\"\n", logFilename);
  } else {

  putc('"', f);
  if(ComPath)   /* path to command.com already known */
    fputs(ComPath, f);
  putc('"', f);
  putc(':', f);

  fputs(cmdline, f);
  putc('\n', f);
  fclose(f);
  }
#else
	cmd_fddebug(logFilename);

	dbg_outc('"');
	dbg_outs(ComPath);
	dbg_outc('"');
	dbg_outc(':');
	dbg_outsn(cmdline);
#endif
#endif

  canexit = 1;
  p = cmdline;    /* start of the command line */
  do {
  ec = leadOptions(&p, opt_init, 0);
  if(ec == E_NoOption) {    /* /C or /K */
    assert(p && *p);
    if(!isoption(p)) {
      error_quoted_c_k();
      p = 0;
      break;
    }
    assert(p[1] && strchr("kKcC", p[1]));
    p += 2;   /* p := start of command line to execute */
    break;
  } else if(ec != E_None) {
        showhelp = 1;
    p = 0;
    break;
  }

  assert(p && !isoption(p) && !isspace(*p));
  if(!*p) {
    p = 0;
    break;      /* end of line reached */
  }
  q = unquote(p, h = skip_word(p));
  p = h;      /* Skip this word */
  if(!q) {
    error_out_of_memory();
    p = 0;
    break;
  }
  if(!comPath) {      /* 1st argument */
    grabComFilename(1, (char far*)q);
    comPath = 1;
    free(q);
  } else if(!newTTY) {  /* 2nd argument */
#ifdef INCLUDE_CMD_CTTY
    newTTY = q;
#else
      error_ctty_excluded();
    free(q);
#endif
      } else {
        error_too_many_parameters(q);
        showhelp = 1;
        free(q);
        break;
      }
   } while(1);

   /*
    * Now:
    * + autoexec: AUTOEXEC.BAT file to be executed if /P switch
    *   is enabled; if NULL, use default
    * + comPath: user-defined PATH to COMMAND.COM; if NULL, use
    *   the one from the environment
    * + newTTY: the name of the device to be CTTY'ed; if NULL,
    *   no change
    * + p: pointer to the command to be executed:
    *   *p == 'c' or 'C' --> spawn command, then terminate shell
    *   *p == 'k' or 'K' --> spawn command, then go interactive
    *   &p[1] --> command line, unless the first character is an
    *   argument character
    */

/* Now process the options */

#ifdef INCLUDE_CMD_CTTY
  if (newTTY) {      /* change TTY as early as possible so the caller gets
                          the messages into the correct channel */
    cmd_ctty(newTTY);
    free(newTTY);
  }
#endif

  if(!ComPath) {
    /* FreeCom is unable to find itself --> print error message */
    /* Emergency error */
#undef TEXT_MSG_FREECOM_NOT_FOUND
	puts(TEXT_MSG_FREECOM_NOT_FOUND);
    return E_Useage;
  }

  /* First of all, set up the environment */
    /* If a new valid size is specified, use that */
  env_resizeCtrl |= ENV_USEUMB | ENV_ALLOWMOVE;
  if(newEnvSize > 16 && newEnvSize < 32767)
    env_setsize(0, newEnvSize);

  /* Otherwise the path is placed into the environment */
    /* Set the COMSPEC variable. */
  if(chgEnv("COMSPEC", ComPath)) {		/* keep it silent */
    /* Failed to add this variable, the most likely problem should be that
      the environment is too small --> it is increased and the
      operation is redone */
    env_resize(0, strlen(ComPath) + 10);
    if(chgEnv("COMSPEC", ComPath))
    	chgEnv("COMSPEC",  NULL);	/* Cannot set -> zap an old one */
  }
  	inInit = 0;

	/* Install INT 24 Critical error handler */
	/* Needs the ComPath variable, eventually */
	if(!kswapContext) {
		/* Load the module/context into memory */
		if((kswapContext = modContext()) == 0) {
			error_loading_context();
			return E_NoMem;
		}
#ifdef FEATURE_KERNEL_SWAP_SHELL
		if(swapOnExec != ERROR)
			kswapRegister(kswapContext);
#endif
	}

	ctxtCreate();

	/* re-use the already loaded Module */
	setvect(0x24, (void interrupt(*)())
	 MK_FP(FP_SEG(kswapContext->cbreak_hdlr), kswapContext->ofs_criter));

  if(internalBufLen)
    error_l_notimplemented();
  if(inputBufLen)
    error_u_notimplemented();

  if(tracemode)
    showinfo = 0;

  if (showhelp)
    displayString(TEXT_CMDHELP_COMMAND);

  if ((showhelp || exitflag) && canexit)
    return E_None;

  /* Now the /P option can be processed */
	if(!canexit) {
		char *autoexec;

		autoexec = user_autoexec? user_autoexec: AUTO_EXEC;

		showinfo = 0;
		short_version();

		if(skipAUTOEXEC) {		/* /D option */
			showinfo = 0;
			displayString(TEXT_MSG_INIT_BYPASSING_AUTOEXEC, autoexec);
		} else {
			if(exist(autoexec)) {
#ifdef FEATURE_BOOT_KEYS
				struct REGPACK r;
				int key;

				r.r_ax = 0x3000;	/* Get DOS version & OEM ID */
				intr(0x21, &r);
				if(!tracemode	/* /Y --> F8 on CONFIG.SYS */
				 || ((r.r_bx & 0xff00) == 0xfd00	/* FreeDOS >= build 2025 */
				      && !(r.r_cx > 0x101 || (r.r_bx & 0xff) > 24))) {
					displayString(TEXT_MSG_INIT_BYPASS_AUTOEXEC, autoexec);
					key = cgetchar_timed(3);
					putchar('\n');
				} else key = 0;

				if(key == KEY_F8)
					tracemode = 1;

				if(key == KEY_F5)
					displayString(TEXT_MSG_INIT_BYPASSING_AUTOEXEC, autoexec);
				else
#endif
					process_input(1, autoexec);
			} else {
				if(user_autoexec)
					error_sfile_not_found(user_autoexec);
#ifdef INCLUDE_CMD_DATE
					cmd_date(0);
#endif
#ifdef INCLUDE_CMD_TIME
					cmd_time(0);
#endif
			}
		}

		free(user_autoexec);
	} else {
		assert(user_autoexec == 0);
	}

  /* Now the /C or /K option can be processed */
  if (p)
  {
    process_input(1, p);
    return spawnAndExit;
  }

  /* Don't place something here that must be executed after a /K or /C */

  if (showinfo)
  {
    short_version();
#ifndef DEBUG
    putchar('\n');
    showcmds(0);
    putchar('\n');
#endif
  }

  return E_None;
}
Beispiel #18
0
void interrupt handle_24 (unsigned bp, unsigned di, unsigned si,
			  unsigned ds, unsigned es, unsigned dx,
			  unsigned cx, unsigned bx, unsigned ax)
{

	int err,key,ret=-1;
	int r,c,start;
	
	err = di & 0x00FF;	/* Error message, from DOS. */

	/* Save section of screen that will be overwritten */
	for (r=8; r<17; r++) {
		start = (160 * r + 54);
		for (c=0; c<26; c++) {
			screen_buf[r-8][c*2] = peekb(scr, start++);
			screen_buf[r-8][c*2+1] = peekb(scr, start++);
		} 
	}

	/* Pop up error message */
	fastprintz( 8,27,0x07,"������������������������ķ");
	fastprintz( 9,27,0x07,"�Error!                  �");
	fastprintz(10,27,0x07,"�                        �");

	/* Common diagnosable problems */
	switch(err) {
		case 0x00:
	fastprintz(11,27,0x07,"�Disk is write protected.�"); break;
		case 0x02:
	fastprintz(11,27,0x07,"�Disk drive is not ready.�"); break;
		default:
	fastprintz(11,17,0x07,"�Disk error.             �"); break;
	}

	fastprintz(12,27,0x07,"�                        �");
	fastprintz(13,27,0x07,"� Try again              �");
	fastprintz(13,29,0x0f,"T");
	fastprintz(14,27,0x07,"� Exit this program      �");
	fastprintz(14,29,0x0f,"E");

	/* In DOS 3.00 and later, they can also fail the disk access */
	if (_osmajor > 2) {
	fastprintz(15,27,0x07,"� Cancel this operation  �");
	fastprintz(15,29,0x0f,"C");
	}
	else
	fastprintz(15,27,0x07,"�                        �");

	fastprintz(16,27,0x07,"������������������������Ľ");

	/* Call BIOS to get a single keystroke from the user */
	do {
		key=getbioskey();

		if (key & 0x00FF)
			key &= 0x00FF;

		switch(key) {
		case 't': case 'T': ret = 0x0001; break;
		case 'e': case 'E': ret = 0x0002; break;
		case 'c': case 'C': if (_osmajor > 2) ret = 0x0003; break;
		default: break;
		}

	} while (ret < 0);
	
	/* Restore that section of the screen */
	for (r=8; r<17; r++) {
		start = (160*r + 54);
		for (c=0; c<26; c++) {
			pokeb(scr, start++, screen_buf[r-8][c*2]);
			pokeb(scr, start++, screen_buf[r-8][c*2+1]);
		}
	}

	ax = ret;
/* And please don't tell me I didn't use any of those parameters. */
#pragma warn -par
}
Beispiel #19
0
int initialize(void)
{
  int comPath;                /* path to COMMAND.COM (for COMSPEC/reload) */
  char *newTTY;                 /* what to change TTY to */
  int showinfo;                 /* show initial info only if no command line options */
  int key;

  int ec;           /* error code */
  unsigned offs;        /* offset into environment segment */

  int cmdlen;         /* length of command line */
  char *cmdline;        /* command line duplicated into heap */
  char *p, *h, *q;
#ifdef FEATURE_CALL_LOGGING
  FILE *f;
#endif

/* Set up the host environment of COMMAND.COM */

  /* Install the ^Break handler (see chkCBreak() for more details) */
  extern void initCBreakCatcher(void);
  initCBreakCatcher();

  /* Install INT 24 Critical error handler */
  init_error_handler();

  /* DOS shells patch the PPID to the own PID, how stupid this is, however,
    because then DOS won't terminate them, e.g. when a Critical Error
    occurs that is not detected by COMMAND.COM */

  oldPSP = OwnerPSP;
  atexit(exitfct);
  OwnerPSP = _psp;

  /* Some elder DOSs may not pass an initialzied environment segment */
  if (env_glbSeg && !isMCB(SEG2MCB(env_glbSeg)))
    env_setGlbSeg(0);       /* Disable the environment */

/* Now parse the command line parameters passed to COMMAND.COM */
  /* Preparations */
  newTTY = NULL;
  comPath = tracemode = 0;
  showinfo = 1;

  /* Because FreeCom should be executed in a DOS3+ compatible
    environment most of the time, it is assumed that its path
    can be determined from the environment.
    This has the advantage that the string area is accessable
    very early in the run.
    The name of the current file is string #0. */
  if((offs = env_string(0, 0)) != 0)    /* OK, environment filled */
    grabComFilename(0, (char far *)MK_FP(env_glbSeg, offs));

  /* Aquire the command line, there are three possible sources:
    1) DOS command line @PSP:0x80 as pascal string,
    2) extended DOS command line environment variable CMDLINE,
      if peekb(PSP, 0x80) == 127,&
    3) MKS command line @ENV:2, if peekb(ENV, 0) == '~'

    Currently implemented is version #1 only
  */
  cmdlen = peekb(_psp, 0x80);
  if(cmdlen < 0 || cmdlen > 126) {
    error_corrupt_command_line();
    cmdlen = 0;
  }
    /* duplicate the command line into the local address space */
  if((cmdline = malloc(cmdlen + 1)) == NULL) {
    error_out_of_memory();  /* Cannot recover from this problem */
    return E_NoMem;
  }
  _fmemcpy((char far*)cmdline, MK_FP(_psp, 0x81), cmdlen);
  cmdline[cmdlen] = '\0';
#ifdef FEATURE_CALL_LOGGING
  if((f = fopen(logFilename, "at")) == NULL) {
    fprintf(stderr, "Cannot open logfile: \"%s\"\n", logFilename);
    exit(125);
  }

  putc('"', f);
  if(ComPath)   /* path to command.com already known */
    fputs(ComPath, f);
  putc('"', f);
  putc(':', f);

  fputs(cmdline, f);
  putc('\n', f);
  fclose(f);
#endif

  p = cmdline;    /* start of the command line */
  do {
  ec = leadOptions(&p, opt_init, NULL);
  if(ec == E_NoOption) {    /* /C or /K */
    assert(p && *p);
    if(!isoption(p)) {
      error_quoted_c_k();
      p = NULL;
      break;
    }
    assert(p[1] && strchr("kKcC", p[1]));
    p += 2;   /* p := start of command line to execute */
    break;
  } else if(ec != E_None) {
        showhelp = 1;
    p = NULL;
    break;
  }

  assert(p && !isoption(p) && !isspace(*p));
  if(!*p) {
    p = NULL;
    break;      /* end of line reached */
  }
  q = unquote(p, h = skip_word(p));
  p = h;      /* Skip this word */
  if(!q) {
    error_out_of_memory();
    p = NULL;
    break;
  }
  if(!comPath) {      /* 1st argument */
    grabComFilename(1, (char far*)q);
    comPath = 1;
    free(q);
  } else if(!newTTY) {  /* 2nd argument */
#ifdef INCLUDE_CMD_CTTY
    newTTY = q;
#else
      error_ctty_excluded();
    free(q);
#endif
      } else {
        error_too_many_parameters(q);
        showhelp = 1;
        free(q);
        break;
      }
   } while(1);

   /*
    * Now:
    * + autoexec: AUTOEXEC.BAT file to be executed if /P switch
    *   is enabled; if NULL, use default
    * + comPath: user-defined PATH to COMMAND.COM; if NULL, use
    *   the one from the environment
    * + newTTY: the name of the device to be CTTY'ed; if NULL,
    *   no change
    * + p: pointer to the command to be executed:
    *   *p == 'c' or 'C' --> spawn command, then terminate shell
    *   *p == 'k' or 'K' --> spawn command, then go interactive
    *   &p[1] --> command line, unless the first character is an
    *   argument character
    */

/* Now process the options */

#ifdef INCLUDE_CMD_CTTY
  if (newTTY) {                   /* change TTY as early as possible so the caller gets
                                   the messages into the correct channel */
    cmd_ctty(newTTY);
    free(newTTY);
  }
#endif

  if(!ComPath) {
    /* FreeCom is unable to find itself --> print error message */
    /* Emergency error */
    puts("You must specify the complete path to " COM_NAME);
    puts("as the first argument of COMMAND,");
    puts("for instance: C:\\FDOS");
    return E_Useage;
  }

  /* First of all, set up the environment */
  env_resizeCtrl |= ENV_USEUMB | ENV_ALLOWMOVE;
  if (envSize < 0)
    envSize = 32767;        /* Numeric overflow (number > 32767 specified) */
  else if (envSize < 256)
    envSize = 256;          /* Minimum size of 256. */
	if(envSize > env_resize(0, 0))	/* Test if to enlarge environment */
		env_setsize(0, envSize);
    /* Set the COMSPEC variable. */
#if 0
  if (chgEnv("COMSPEC", ComPath)) error_env_var("COMSPEC");
#else
  if (chgEnv("COMSPEC", ComPath)) {
    /* Failed to add this variable, the most likely problem should be that
      the environment is too small --> it is increased and the
      operation is redone */
    env_resize(0, strlen(ComPath) + 10);
    if (chgEnv("COMSPEC", ComPath))
    error_env_var("COMSPEC");
  }
#endif

  if(internalBufLen)
    error_l_notimplemented();
  if(inputBufLen)
    error_u_notimplemented();

  if(tracemode)
    showinfo = 0;

  if (showhelp)
    displayString(TEXT_CMDHELP_COMMAND);

  if ((showhelp || exitflag) && canexit)
    return E_None;

  /* Now the /P option can be processed */
  if (!canexit)
  {
    char *autoexec;

    autoexec = user_autoexec? user_autoexec: AUTO_EXEC;

    showinfo = 0;
    short_version();

    /* JP: changed so that if autoexec does not exist, then don't ask
       to trace or bypass.
     */
    if (exist(autoexec))
    {
      printf("\nPress F8 for trace mode, or F5 to bypass %s... ", autoexec);
      key = WaitForFkeys();
      putchar('\n');

      if (key == KEY_F8)
      {
        tracemode = 1;
      }

      if (key == KEY_F5)
      {
        printf("Bypassing %s\n", autoexec);
      }
      else
        process_input(1, autoexec);
    }
    else
    {
      if(user_autoexec)
        printf("%s not found.\n", autoexec);
#ifdef INCLUDE_CMD_DATE
      cmd_date(NULL);
#endif
#ifdef INCLUDE_CMD_TIME
      cmd_time(NULL);
#endif
    }

    free(user_autoexec);
  }
  else
  {
    assert(user_autoexec == NULL);
  }

  /* Now the /C or /K option can be processed */
  if (p)
  {
    process_input(1, p);
    return spawnAndExit;
  }

  /* Don't place something here that must be executed after a /K or /C */

  if (showinfo)
  {
    short_version();
    putchar('\n');
    showcmds(NULL);
    putchar('\n');
  }

  return E_None;
}
Beispiel #20
0
int
USL_HardError(word errval,int ax,int bp,int si)
{
#define IGNORE  0
#define RETRY   1
#define	ABORT   2
extern	void	ShutdownId(void);

static	char		buf[32];
static	WindowRec	wr;
		int			di;
		char		c,*s,*t;

	di = _DI;

	if (ax < 0)
		s = "DEVICE ERROR";
	else
	{
		if ((di & 0x00ff) == 0)
			s = "DRIVE ~ IS WRITE PROTECTED";
		else
			s = "ERROR ON DRIVE ~";
		for (t = buf;*s;s++,t++)	// Can't use sprintf()
			if ((*t = *s) == '~')
				*t = (ax & 0x00ff) + 'A';
		*t = '\0';
		s = buf;
	}

	c = peekb(0x40,0x49);	// Get the current screen mode
	if ((c < 4) || (c == 7))
		goto oh_kill_me;

	// DEBUG - handle screen cleanup

   fontnumber = 4;
	US_SaveWindow(&wr);
	US_CenterWindow(30,3);
	US_CPrint(s);
	US_CPrint("(R)ETRY or (A)BORT?");
	VW_UpdateScreen();
	IN_ClearKeysDown();

asm	sti	// Let the keyboard interrupts come through

	while (true)
	{
		switch (IN_WaitForASCII())
		{
		case key_Escape:
		case 'a':
		case 'A':
			goto oh_kill_me;
			break;
		case key_Return:
		case key_Space:
		case 'r':
		case 'R':
			US_ClearWindow();
			VW_UpdateScreen();
			US_RestoreWindow(&wr);
			return(RETRY);
			break;
		}
	}

oh_kill_me:
	abortprogram = s;
	ShutdownId();
	fprintf(stderr,"TERMINAL ERROR: %s\n",s);
	return(ABORT);

#undef	IGNORE
#undef	RETRY
#undef	ABORT
}
Beispiel #21
0
int
USL_HardError(word errval,int ax,int bp,int si)
{
#define IGNORE  0
#define RETRY   1
#define	ABORT   2
extern	void	ShutdownId(void);

static	char		buf[32];
static	WindowRec	wr;
		int			di;
		char		c,*s,*t;


	di = _DI;

	if (ax < 0)
		s = "Device Error";
	else
	{
		if ((di & 0x00ff) == 0)
			s = "Drive ~ is Write Protected";
		else
			s = "Error on Drive ~";
		for (t = buf;*s;s++,t++)	// Can't use sprintf()
			if ((*t = *s) == '~')
				*t = (ax & 0x00ff) + 'A';
		*t = '\0';
		s = buf;
	}

	c = peekb(0x40,0x49);	// Get the current screen mode
	if ((c < 4) || (c == 7))
		goto oh_kill_me;

	// DEBUG - handle screen cleanup

	US_SaveWindow(&wr);
	US_CenterWindow(30,3);
	US_CPrint(s);
	US_CPrint("(R)etry or (A)bort?");
	VW_UpdateScreen();
	IN_ClearKeysDown();

asm	sti	// Let the keyboard interrupts come through

	while (true)
	{
		switch (IN_WaitForASCII())
		{
		case key_Escape:
		case 'a':
		case 'A':
			goto oh_kill_me;
			break;
		case key_Return:
		case key_Space:
		case 'r':
		case 'R':
			US_ClearWindow();
			VW_UpdateScreen();
			US_RestoreWindow(&wr);
			return(RETRY);
			break;
		}
	}

oh_kill_me:
	abortprogram = s;
	ShutdownId();
	fprintf(stderr,"Terminal Error: %s\n",s);
	if (tedlevel)
		fprintf(stderr,"You launched from TED. I suggest that you reboot...\n");

	return(ABORT);
#undef	IGNORE
#undef	RETRY
#undef	ABORT
}