Пример #1
0
void lattr_hole(struct lattr_db *db, ptrdiff_t pos)
{
	if (pos > db->hole)
		mmove(db->buffer + db->hole, db->buffer + db->ehole, (pos - db->hole) * SIZEOF(HIGHLIGHT_STATE));
	else if (pos < db->hole)
		mmove(db->buffer + db->ehole - (db->hole - pos), db->buffer + pos, (db->hole - pos) * SIZEOF(HIGHLIGHT_STATE));
	db->ehole = pos + db->ehole - db->hole;
	db->hole = pos;
}
Пример #2
0
Файл: Mgcd.c Проект: 8l/csolve
FN minvert(MINT *a, MINT *b, MINT *c)
{	MINT x, y, z, w, Anew, Aold;
	int i = 0;
	static MINT one;
	static int oneinit = 1;

	if (oneinit) {
		oneinit = 0;
		MSET(1,&one);
	}
	MINIT(&x);
	MINIT(&y);
	MINIT(&z);
	MINIT(&w);
	MINIT(&Aold);
	MSET (1,&Anew);

	mcopy(b, &x);
	mcopy(a, &y);
	/*
	 * Loop invariant:
	 *
	 * y = -1^i * Anew * a  mod b
	 */
	while(mtest(&y) != 0)
	{	mdiv(&x, &y, &w, &z);
		mcopy(&Anew, &x);
		mmult(&w, &Anew, &Anew);
		madd(&Anew, &Aold, &Anew);
		mmove(&x, &Aold);
		mmove(&y, &x);
		mmove(&z, &y);
		i++;
	}
	if (mcmp(&one,&x)) {
		mcopy(&one,c);
	} else {
		mmove(&Aold, c);
		if( (i&01) == 0) msub(b, c, c);
	}

	MFREE(&x);
	MFREE(&y);
	MFREE(&z);
	MFREE(&w);
	MFREE(&Aold);
	MFREE(&Anew);
}
Пример #3
0
/*
Move scared monsters randomly away from the player position.
*/
static void move_scared(int i, int j)
{
	int xl, yl, tmp;

	/* check for a half-speed monster, and check if not to move.  Could be
	done in the monster list build.
	*/
	switch(mitem[i][j])
	{
	case TROGLODYTE:  case HOBGOBLIN:  case METAMORPH:  case XVART:
	case INVISIBLESTALKER:  case ICELIZARD: if ((gtime & 1) == 1) return;
	};

	if ((xl = i+rnd(3)-2) < 0)
		xl=0;
	if (xl >= MAXX)
		xl=MAXX-1;
	if ((yl = j+rnd(3)-2) < 0)
		yl=0;
	if (yl >= MAXY)
		yl=MAXY-1;

	if ((tmp=item[xl][yl]) != OWALL)
		if (mitem[xl][yl] == 0)
			if ((mitem[i][j] != VAMPIRE) || (tmp != OMIRROR))
				if (tmp != OCLOSEDDOOR)
					mmove(i,j,xl,yl);
}
Пример #4
0
void mmul1(double a[], double b[], int la, int lb, int m)
{
	int i, j, ka, kc, l;
	double *p, *q, *r, w, *work;

	if(m <= 0 || la < m || lb < m)
	{
		fprintf(stderr, "Error : Illegal parameter  in mmul1()\n");
		return;
	}
	work = (double *)malloc(m * m * sizeof(double));
	if(work == NULL)
	{
		fprintf(stderr, "Error : Out of memory  in mmul1()\n");
		return;
	}
	for(i = 0, ka = 0, r = work; i < m; i++, ka += la)
	{
		for(l = 0; l < m; l++)
		{
			w = 0.;
			for(j = 0, p = a + ka, q = b + l; j < m; j++)
			{
				w += *p++ * *q;
				q += lb;
			}
			*r++ = w;
		}
	}
	mmove(work, a, m, la, m, m);
	free((char *)work);
	return;
}
Пример #5
0
/*
Move monsters that are moving intelligently, using the proximity
ripple.  Attempt to move to a position in the proximity ripple
that is closer to the player.

Parameters: the X,Y position of the monster to be moved.
*/
static void move_smart(int i, int j)
{
	int x, y, z ;

	/* check for a half-speed monster, and check if not to move.  Could be
	done in the monster list build.
	*/
	switch(mitem[i][j])
	{
	case TROGLODYTE:  case HOBGOBLIN:  case METAMORPH:  case XVART:
	case INVISIBLESTALKER:  case ICELIZARD: if ((gtime & 1) == 1) return;
	};

	/* find an adjoining location in the proximity ripple that is
	closer to the player (has a lower value) than the monster's
	current position.
	*/
	if (mitem[i][j] != VAMPIRE)
		for (z=1; z<9; z++) /* go around in a circle */
		{
			x = i + diroffx[z] ;
			y = j + diroffy[z] ;
			if ( screen[x][y] < screen[i][j] )
				if ( !mitem[x][y] )
				{
					mmove(i,j,w1x[0]=x,w1y[0]=y);
					return;
				}
		}
	else
		/* prevent vampires from moving onto mirrors
		*/
		for (z=1; z<9; z++) /* go around in a circle */
		{
			x = i + diroffx[z] ;
			y = j + diroffy[z] ;
			if (( screen[x][y] < screen[i][j] ) &&
				( item[x][y] != OMIRROR ))
				if ( !mitem[x][y] )
				{
					mmove(i,j,w1x[0]=x,w1y[0]=y);
					return;
				}
		}

}
Пример #6
0
// --- 
tMsgHandler* pr_call _mh_add( tMHArray* mha, tHANDLE* handler, tDWORD flags, tDWORD msg_cls, tIID o_iid, tPID o_pid, tIID ctx_iid, tPID ctx_pid, tERROR* error ) {
  
	tMsgHandler* h;
	
	_check_handle_for_msg_recv( handler );

	h = _mh_find_handler( mha, 0, handler, msg_cls, o_iid, o_pid );

  if ( h ) {
    *error = errOBJECT_ALREADY_EXISTS;
    return 0;
  }

  if ( !mha->mcount ) { 
    if ( PR_SUCC(*error=PrAlloc((tPTR*)&mha->parr,8*sizeof(tMsgHandler))) )
      h = mha->parr;
    else
      return 0;
  }
  else if ( !(mha->mcount % 8) ) { 
    tMsgHandler* tmpa;
    if ( PR_FAIL(*error=PrAlloc((tPTR*)&h,(mha->mcount+8)*sizeof(tMsgHandler))) )
      return 0;
    mmove( h+1, mha->parr, mha->mcount*sizeof(tMsgHandler) );
    tmpa = mha->parr;
    mha->parr = h;
    PrFree( tmpa );
  }
  else {
    h = mha->parr;
    mmove( h+1, h, mha->mcount*sizeof(tMsgHandler) );
  }

  mha->mcount++;
  h->handler = handler;
  h->msg_cls = msg_cls;
  h->flags   = flags;
  h->obj_iid = o_iid;
  h->obj_pid = o_pid;
  h->ctx_iid = ctx_iid;
  h->ctx_pid = ctx_pid;
  *error = errOK;
  return h;
}
Пример #7
0
void lattr_check(struct lattr_db *db, ptrdiff_t amnt)
{
	if (amnt > db->ehole - db->hole) {
		/* Not enough space */
		/* Amount of additional space needed */
		amnt = amnt - (db->ehole - db->hole) + 16;
		db->buffer = (HIGHLIGHT_STATE *)joe_realloc(db->buffer, (db->end + amnt) * SIZEOF(HIGHLIGHT_STATE));
		mmove(db->buffer + db->ehole + amnt, db->buffer + db->ehole, (db->end - db->ehole) * SIZEOF(HIGHLIGHT_STATE));
		db->ehole += amnt;
		db->end += amnt;
	}
}
Пример #8
0
Файл: Mgcd.c Проект: 8l/csolve
void mgcd(MINT *a, MINT *b, MINT *c)
{	MINT x,y,z,w;

	MCOPY(a,&x);
	MCOPY(b,&y);
	MINIT(&z);
	MINIT(&w);

	while( mtest(&y) != 0)
	{	mdiv(&x,&y,&w,&z);
		mmove(&y,&x);
		mmove(&z,&y);
#if (! INTR)
		(*PollPtr)();
#endif
	}
	mmove(&x,c);
	MFREE(&y);
	MFREE(&z);
	MFREE(&w);
	return;
}
Пример #9
0
void cputc(Console cons, int c) {
  {
    while(!(inb(0x3f8+5) & 0x60));
    outb(0x3f8,c);
  }
  if (c == '\n') {
    cons->pos += 80 - cons->pos % 80;
  } else {
    cons->buf[cons->pos++] = c | (cons->color << 8);
  }
  if ((cons->pos / 80) >= 24) {
    mmove(cons->buf, cons->buf + 80, sizeof(cons->buf[0]) * 23 * 80);
    cons->pos -= 80;
    miset(cons->buf + cons->pos, (cons->color << 24 | cons->color << 8),
          sizeof(cons->buf[0]) * (24 * 80 - cons->pos));
  }
  movecursor(cons);
}
Пример #10
0
void acpiinit(Acpi a, Console c) {
  {
    /// See 5.2.5.1 and 5.2.5.3 of ACPI specification, which describes
    /// where the root system description pointer can be located.
    u8 *p = (u8 *)0x000e0000;
    u8 *end = (u8 *)0x000fffff;
    while (p < end) {
      u64 sig = *(u64*) p;
      if (sig == 0x2052545020445352) {
        cprint(c, "acpi: found rsdp at "), cprintint(c, (u64)p, 16, 0), cnl(c);
        u8 sum = 0;
        for (int i = 0; i < 20; ++i) {
          sum += p[i];
        }
        if (sum) {
          p += 16;
          continue;
        }
        char oem[7];
        mmove(oem, p+9, 6);
        oem[6] = '\0';
        cprint(c, "acpi: OEM is "), cprint(c, oem), cnl(c);
        u8 revision = p[15];
        if (revision == 0) {
          cprint(c, "acpi: version 1\n");
          u32 rsdtaddress = *(u32 *)(p + 16);
          acpiparsersdt(a, (AcpiHeader *)rsdtaddress);
        } else if (revision == 2) {
          cprint(c, "acpi: version 2\n");
          u32 rsdtaddress = *(u32 *)(p + 16);
          u64 xsdtaddress = *(u64 *)(p + 24);
          if (xsdtaddress) {
            acpiparsexsdt(a, (AcpiHeader *)xsdtaddress);
          } else {
            acpiparsersdt(a, (AcpiHeader *)rsdtaddress);
          }
        } else {
        }
        break;
      }
      p += 16;
    }
  }
}
Пример #11
0
int main()
{
	char x,b;
	int a,o;
	system("cls");
	printf("What type of Calendar you want to see...!!!\n\n");
	printf("Press 'Y' for Yearly or Press 'M' for Monthly\n\n");
	printf("For Instructions press 'I'\n\n");
	printf("To exit press 'E'\n\n");
	x=getch();
	if(x=='M'||x=='m')
	{
		printf("\t\t::MONTHLY::");
		printf("\n\nEnter a year : ");
		scanf("%d",&a);
		printf("\nEnter the number corresponding to a month: ");
		scanf("%d",&o);
		system("cls");
		choice(a,o);
		gotoxy(0,0);
		mmove(a,o);
	}
	else if(x=='Y'||x=='y')
	{
		printf("\t\t::YEARLY::");
		printf("\n\nEnter a year after 1800 : ");
		scanf("%d",&a);
		system("cls");
		for(o=1;o<=12;o++)
		choice(a,o);
		gotoxy(0,0);
		ymove(a);
	}
	else if(x=='i'||x=='I')
		instr();
	else if(x=='e'||x=='E')
		exit(1);
	else
		printf("Wrong Input...!!!");
	printf("\n\n");
	return 0;
}
Пример #12
0
// ---
tBOOL pr_call _mh_remove_by_ind( tMHArray* mha, tDWORD ind ) {
  if ( ind < mha->mcount ) {
    tDWORD c = --(mha->mcount);
    tDWORD t = c - ind;

    if ( t )
      mmove( mha->parr+ind, mha->parr+ind+1, t * sizeof(tMsgHandler) );

    if ( !c ) {
      tMsgHandler* tmp = mha->parr;
      mha->parr = 0;
      PrFree( tmp );
    }
    else if ( !(c % 8) )
			PrRealloc( (tPTR*)&mha->parr, mha->parr, c * sizeof(tMsgHandler) );
    return cTRUE;
  }
  else
    return cFALSE;
}
Пример #13
0
// ---
tBOOL pr_call _mh_c_remove( tMHCacheArray* mhc, tMsgHandler* mh ) {
  tUINT i, c;
  for( i=0, c=mhc->count; i<c; i++ ) {
    if ( mhc->parr[i].handler == mh ) {
      tDWORD tail;
      c = --mhc->count;
      tail = c - i;
      if ( tail )
        mmove( mhc->parr + i, mhc->parr + i + 1, tail * sizeof(tMsgHandler*) );
      if ( !c ) {
        PrFree( mhc->parr );
        mhc->parr = 0;
      }
      else if ( !(c % 16) )
        PrRealloc( (tPTR*)&mhc->parr, mhc->parr, c * sizeof(tMsgHandler*) );
      return cTRUE;
    }
  }
  return cFALSE;
}
Пример #14
0
Файл: Msqrt.c Проект: 8l/csolve
msqrt(MINT *a, MINT *b, MINT *r)
{	MINT x,y,z;
	register alen,j;

	MINIT(&x); MINIT(&y); MINIT(&z);
	alen = a->len;

	if (alen<0) mpfatal("msqrt: neg arg");
	if (alen==0) {
		mset(0,b);
		mset(0,r);
		return(0);
	}

	if(alen & 01) x.len = (1+alen)/2;
	else x.len = 1 + alen/2;
	valloc(x.val,x.len);
	for (j=x.len; (--j)>=0;) x.val[j]=0;
	if (alen & 01) x.val[x.len-1]=0400;
	else x.val[x.len-1]=1;

	for (;;) {
		mdiv(a,&x,&y,&z);
		madd(&x,&y,&y);
		mshiftr(&y,1);
		if (mcmp(&x,&y) <= 0) break;
		mmove(&y,&x);
	}
	mcopy(&x,&y);
	mmult(&x,&x,&x);
	msub(a,&x,r);
	MFREE(&x);
	MMOVEFREE(&y,b);
	MFREE(&z);
	return(r->len);
}
Пример #15
0
void undodel(UNDO *undo, long where, B *b)
{
	UNDOREC *rec;
	long size = b->eof->byte;

	if (inredo) {
		brm(b);
		return;
	}
	if (!inundo)
		if (undo->ptr && undo->ptr != &undo->recs)
			undoover(undo);

	yankdel(where, b);

	/* Store in undo buffer */
	rec = undo->recs.link.prev;
	if (rec != &undo->recs && rec->min && rec->del && where == rec->where) {
		if (rec->len + size >= SMALL) {
			if (rec->len < SMALL) {
				rec->big = bmk(NULL);
				binsm(rec->big->bof, rec->small, (int) rec->len);
				boffline(rec->big);
				joe_free(rec->small);
			}
			bonline(rec->big);
			binsb(rec->big->eof, b);
			boffline(rec->big);
		} else {
			rec->small = (unsigned char *) joe_realloc(rec->small, rec->len + size);
			brmem(b->bof, rec->small + rec->len, (int) size);
			brm(b);
		}
		rec->len += size;
	} else if (rec != &undo->recs && rec->min && rec->del && where + size == rec->where) {
		if (rec->len + size >= SMALL) {
			if (rec->len < SMALL) {
				rec->big = bmk(NULL);
				binsm(rec->big->bof, rec->small, (int) rec->len);
				boffline(rec->big);
				joe_free(rec->small);
			}
			bonline(rec->big);
			binsb(rec->big->bof, b);
			boffline(rec->big);
		} else {
			rec->small = (unsigned char *) joe_realloc(rec->small, rec->len + size);
			mmove(rec->small + size, rec->small, (int) rec->len);
			brmem(b->bof, rec->small, (int) size);
			brm(b);
		}
		rec->len += size;
		rec->where = where;
	} else {
		rec = alrec();
		if (size < SMALL) {
			rec->small = (unsigned char *) joe_malloc(size);
			brmem(b->bof, rec->small, (int) b->eof->byte);
			brm(b);
		} else {
			rec->big = b;
			boffline(b);
		}
		if (!undo->first)
			undo->first = rec;
		undo->last = rec;
		rec->where = where;
		rec->min = 1;
		rec->unit = NULL;
		rec->len = size;
		rec->del = 1;
		rec->changed = undo->b->changed;
		enqueb(UNDOREC, link, &undo->recs, rec);
	}
}
Пример #16
0
/*
For monsters that are not moving in an intelligent fashion.  Move
in a direct fashion toward the player's current position.

Parameters: the X,Y position of the monster to move.
*/
static void move_dumb(int i, int j)
{
	int xl, yl, xh, yh ;
	int k, m, tmp, tmpd, tmpx, tmpy ;

	/* check for a half-speed monster, and check if not to move.  Could be
	done in the monster list build.
	*/
	switch(mitem[i][j])
	{
	case TROGLODYTE:  case HOBGOBLIN:  case METAMORPH:  case XVART:
	case INVISIBLESTALKER:  case ICELIZARD: if ((gtime & 1) == 1) return;
	};

	/* dumb monsters move here */
	/* set up range of spots to check.  instead of checking all points
	around the monster, only check those closest to the player.  For
	example, if the player is up and right of the monster, check only
	the three spots up and right of the monster.
	*/
	xl=i-1;  yl=j-1;  xh=i+2;  yh=j+2;
	if (i<playerx) xl++; else if (i>playerx) --xh;
	if (j<playery) yl++; else if (j>playery) --yh;

	if (xl < 0) xl = 0;
	if (yl < 0) yl = 0;
	if (xh > MAXX) xh = MAXX; /* MAXX OK; loop check below is <, not <= */
	if (yh > MAXY) yh = MAXY; /* MAXY OK; loop check below is <, not <= */

	/* check all spots in the range.  find the one that is closest to
	the player.  if the monster is already next to the player, exit
	the check immediately.
	*/
	tmpd = 10000 ;
	tmpx = i ;  tmpy = j ;
	for ( k = xl ; k < xh ; k++ )
		for ( m = yl ; m < yh ; m++ )
			if ( k == playerx && m == playery )
			{
				tmpd = 1 ;
				tmpx = k ;
				tmpy = m ;
				break;       /* exitloop */
			}
			else if ((item[k][m] != OWALL) &&
				(item[k][m] != OCLOSEDDOOR) &&
				((mitem[k][m] == 0 ) || (( k == i ) && ( m == j ))) &&
				((mitem[i][j] != VAMPIRE) || (item[k][m] != OMIRROR)))
			{
				tmp = (playerx-k)*(playerx-k)+(playery-m)*(playery-m);
				if (tmp < tmpd)
				{
					tmpd = tmp;
					tmpx = k;
					tmpy = m;
				}  /* end if */
			}  /* end if */

			/* we have finished checking the spaces around the monster.  if
			any can be moved on and are closer to the player than the
			current location, move the monster.
			*/
			if ((tmpd < 10000) && ((tmpx != i) || (tmpy != j)))
			{
				mmove( i, j, tmpx, tmpy );
				w1x[0] = tmpx ;              /* for last monster hit */
				w1y[0] = tmpy ;
			}
			else
			{
				w1x[0] = i ;              /* for last monster hit */
				w1y[0] = j ;
			}
}  /* end move_dumb() */
Пример #17
0
int main(int argc, char* argv[])
{
    initscr();
    scrollok(stdscr, TRUE);
    wprintw(stdscr, "Welcome to Scripted ver. %d.%d for the Brave Quest engine.\nCopyright 2012 Mad Science Inc.\nPlease do not redistrubute.\n",scriptedvernum,scriptedvernum2);
    stufffilename();
    if(loadscript(filename) == 1)
    {
        wprintw(stdscr, "File not Found. Would you like to make a new file?\n");
        if(bie() == 'y')
        {
            cleanfilebuff();
            if(savescript(filename) == 1)
            {
                wprintw(stdscr, "Your disk sucks.\n");
                bi();
                return 1;
            }
        }
        else
        {
            wprintw(stdscr, "Goodbye.\n");
            endwin();
            return 1;
        }
    }
    currlinenum = linenum;
    menu();
    wprintw(stdscr, "Press escape to go to the save menu\n");
    for(;;)
    {
        wprintw(stdscr, "q= give, w= take, e= say, r= flag, t= move, y= battle, u= check flag, i= check item, o= party add, p= party remove, [ = check character\n");
        wprintw(stdscr, "a= warp, s= check experience, d= give experience, f= make experience, g= exec script, h= screen effect, j= user input, k= goline, l= make health\n");
        wprintw(stdscr, "b= check stat, n= make stat, m= blank, ,= show line, .= change line.\n");
        input[0] = bie();
        if(input[0] == 27)
            menu();
        if(input[0] == 'q')
            give();
        if(input[0] == 'w')
            take();
        if(input[0] == 'e')
            say();
        if(input[0] == 'r')
            flag();
        if(input[0] == 't')
            mmove();
        if(input[0] == 'y')
            battle();
        if(input[0] == 'u')
            checkflag();
        if(input[0] == 'i')
            checkitem();
        if(input[0] == 'o')
            partyadd();
        if(input[0] == 'p')
            partyrm();
        if(input[0] == '[')
            checkparty();
        if(input[0] == 'a')
            warp();
        if(input[0] == 's')
            checkexp();
        if(input[0] == 'd')
            giveexp();
        if(input[0] == 'f')
            makeexp();
        if(input[0] == 'g')
            execscript();
        if(input[0] == 'h')
            screeneffect();
        if(input[0] == 'j')
            userinput();
        if(input[0] == 'k')
            goline();
        if(input[0] == 'l')
            makehealth();
        if(input[0] == 'z')
            teachspell();
        if(input[0] == 'x')
            unlearnspell();
        if(input[0] == 'b')
            checkstat();
        if(input[0] == 'n')
            makestat();
        if(input[0] == 'm')
            blank();
        if(input[0] == ',')
            showline();
        if(input[0] == '.')
            changeline();
        if(currlinenum > linenum)
            linenum = currlinenum;
    }
    return 0;
};
Пример #18
0
static void yankdel(long where, B *b)
{
	UNDOREC *rec;
	long size = b->eof->byte;

	/* Store in yank buffer */
	rec = yanked.link.prev;
	if (!inyank) {
		if (rec != &yanked && where == rec->where && justkilled) {
			if (rec->len + size >= SMALL) {
				if (rec->len < SMALL) {
					rec->big = bmk(NULL);
					binsm(rec->big->bof, rec->small, (int) rec->len);
					boffline(rec->big);
					joe_free(rec->small);
				}
				bonline(rec->big);
				binsb(rec->big->eof, bcpy(b->bof, b->eof));
				boffline(rec->big);
			} else {
				rec->small = (unsigned char *) joe_realloc(rec->small, rec->len + size);
				brmem(b->bof, rec->small + rec->len, (int) size);
			}
			rec->len += size;
		} else if (rec != &yanked && where + size == rec->where && justkilled) {
			if (rec->len + size >= SMALL) {
				if (rec->len < SMALL) {
					rec->big = bmk(NULL);
					binsm(rec->big->bof, rec->small, (int) rec->len);
					boffline(rec->big);
					joe_free(rec->small);
				}
				bonline(rec->big);
				binsb(rec->big->bof, bcpy(b->bof, b->eof));
				boffline(rec->big);
			} else {
				rec->small = (unsigned char *) joe_realloc(rec->small, rec->len + size);
				mmove(rec->small + size, rec->small, (int) rec->len);
				brmem(b->bof, rec->small, (int) size);
			}
			rec->len += size;
			rec->where = where;
		} else {
			if (++nyanked == MAX_YANK) {
				frrec(deque_f(UNDOREC, link, yanked.link.next));
				--nyanked;
			}
			rec = alrec();
			if (size < SMALL && size > 0) {
				rec->small = (unsigned char *) joe_malloc(size);
				brmem(b->bof, rec->small, (int) b->eof->byte);
			} else {
				rec->big = bcpy(b->bof, b->eof);
				boffline(rec->big);
			}
			rec->where = where;
			rec->len = size;
			rec->del = 1;
			enqueb(UNDOREC, link, &yanked, rec);
		}
	}
}