Esempio n. 1
0
File: genbin.c Progetto: 8l/FUZIX
void binheader(void)
{
#ifdef BINSYM
    if ((outfd = binfil) != 0x0 && binmbuf_set && binmax >= binmin)
    {
	writec(0x0);		/* binary header byte */
#ifdef LONG_BINHEADER
	writeoff(binmax - binmin);	/* program length */
	writeoff(binfbuf = binmin);	/* program start */
#else
	writew((unsigned) (binmax - binmin));	/* program length */
	writew((unsigned) (binfbuf = binmin));	/* program start */
#endif
    }
#else
    if ( ( outfd = symfil ) && binmbuf_set && binmax >= binmin)
    {
        int sft;
        writec('+'); writec(' ');
	for(sft=SIZEOF_OFFSET_T*8-4; sft >= 0; sft-=4)
           writec(hexdigit[(binmin>>sft) & 0xF]);
	writesn(" ----- $start");

        writec('+'); writec(' ');
	for(sft=SIZEOF_OFFSET_T*8-4; sft >= 0; sft-=4)
           writec(hexdigit[(binmax>>sft) & 0xF]);
	writesn(" ----- $end");

	binfbuf = binmin;	/* program start */
    }
Esempio n. 2
0
int
yorn(int special)
{
	char    c;
	int     i;

	i = 1;
	while ((c = readc()) != 'Y' && c != 'N') {
		if (special && c == special)
			return (2);
		if (i) {
			if (special) {
				writel("  (Y, N, or ");
				writec(special);
				writec(')');
			} else
				writel("  (Y or N)");
			i = 0;
		} else
			writec('\007');
	}
	if (c == 'Y')
		writel("  Yes.\n");
	else
		writel("  No.\n");
	if (tflag)
		buflush();
	return (c == 'Y');
}
Esempio n. 3
0
File: main.c Progetto: fdotli/libu
static int test_full_advance (int opts)
{
    int i;
    char c, prev, star = '*';
    enum { SZ = 3 };
    u_rb_t *rb = NULL;

    con_err_if (u_rb_create(SZ, opts, &rb));

    /* fill the rb */
    for (i = 0; i < SZ; i++)
        con_err_if (writec(rb, star));

    for (c = 32; c < 126; c++)
    {
        if (c < (SZ + 32))
            con_err_if (readc(rb, &star));
        else
        {
            prev = c - SZ; 
            con_err_if (readc(rb, &prev));
        }

        con_err_if (writec(rb, c));
    }

    return 0;
err:
    return 1;
}
Esempio n. 4
0
void
wrhit(int i)
{
	writel("Blot hit on ");
	wrint(i);
	writec('.');
	writec('\n');
}
Esempio n. 5
0
void
wrscore(void)
{
	writel("Score:  ");
	writel(color[1]);
	writec(' ');
	wrint(rscore);
	writel(", ");
	writel(color[0]);
	writec(' ');
	wrint(wscore);
}
Esempio n. 6
0
void
wrint(int n)
{
	int     i, j, t;

	for (i = 4; i > 0; i--) {
		t = 1;
		for (j = 0; j < i; j++)
			t *= 10;
		if (n > t - 1)
			writec((n / t) % 10 + '0');
	}
	writec(n % 10 + '0');
}
Esempio n. 7
0
void
proll(struct move *mm)
{
	if (mm->d0)
		mswap(mm);
	if (cturn == 1)
		writel("Red's roll:  ");
	else
		writel("White's roll:  ");
	writec(mm->D0 + '0');
	writec('\040');
	writec(mm->D1 + '0');
	if (tflag)
		cline();
}
Esempio n. 8
0
void writes(char *message)
{
	while(*message)
	{
		writec(*(message++));
	}
}
Esempio n. 9
0
static dsk_err_t writes(SQ_COMPRESS_DATA *self, unsigned short s)
{
	dsk_err_t e;

	e = writec(self, (unsigned char)(s & 0xFF));        if (e) return e;
	e = writec(self, (unsigned char)((s >> 8) & 0xFF)); if (e) return e;
	return DSK_ERR_OK;
}
Esempio n. 10
0
void leave(void)
{
    if (tflag)
	clear();
    else
	writec('\n');
    fixtty(&old);
    execlp("backgammon", "backgammon", "-n", args[1] ? args : 0, NULL);
    writel("Help! Backgammon program is missing\007!!\n");
    exit(1);
}
Esempio n. 11
0
void
moverr(int i)
{
	int j;

	if (tflag)
		curmove(20, 0);
	else
		writec('\n');
	writel("Error:  ");
	for (j = 0; j <= i; j++) {
		wrint(p[j]);
		writec('-');
		wrint(g[j]);
		if (j < i)
			writec(',');
	}
	writel("... ");
	movback(i);
}
Esempio n. 12
0
void writei(unsigned int i)
{
	while(i)
	{
		switch(i % 10)
		{
			case 0:
				writec('0');
				break;
			case 1:
				writec('1');
				break;
			case 2:
				writec('2');
				break;
			case 3:
				writec('3');
				break;
			case 4:
				writec('4');
				break;
			case 5:
				writec('5');
				break;
			case 6:
				writec('6');
				break;
			case 7:
				writec('7');
				break;
			case 8:
				writec('8');
				break;
			case 9:
				writec('9');
				break;
		}

		i /= 10;
	}
}
Esempio n. 13
0
bool 		writef(
	float 	f
){
	int part;

	part = (int)f;
	if(!writei(part)) return FALSE;
	if(!writec('.'))  return FALSE;
	f-=part;
	part = ((int)(f*PRECISION));
	if(!writei(part)) return FALSE;
	return TRUE;
}
Esempio n. 14
0
void
getout(int dummy __unused)
{
	/* go to bottom of screen */
	if (tflag) {
		curmove(23, 0);
		cline();
	} else
		writec('\n');

	/* fix terminal status */
	fixtty(&old);
	exit(0);
}
Esempio n. 15
0
File: level.c Progetto: igitur/ffe
static void
print_level_text(struct level *l,uint8_t *buffer)
{
    register uint8_t *text = buffer;

    if(!buffer) return;
    start_write();
    while(*text)
    {
        if(*text == '%' && text[1])
        {
            text++;
            switch(*text)
            {
                case 'g':
                    if(l) writes(l->group_name);
                    break;
                case 'm':
                    if(l) writes(l->element_name);
                    break;
                case '%':
                    writec('%');
                    break;
                default:
                    writec('%');
                    writec(*text);
                    break;
            }
        } else
        {
            writec(*text);
        }
        text++;
    }
    flush_write();
}
Esempio n. 16
0
static dsk_err_t compress(SQ_COMPRESS_DATA *self)
{
	char *s = self->sq_truename;
	dsk_err_t e;
	unsigned short dictbase;
	unsigned short dictlen;
	unsigned short dn;

	e = writes(self, MAGIC); if (e) return e;     /* Magic */
	e = writes(self, self->ck_sum);
				 if (e) return e;     /* Source file checksum */	
	do		/* Filename */
	{
		e = writec(self, *s); if (e) return e;
	} while ( *(s++) );	

	dictbase = self->huf_curnode + 1;
	/* Dictionary length = MAXNODE - dictbase */
	dictlen = MAXNODE - dictbase;
	e = writes(self, dictlen); if (e) return e;
	for (dn = dictbase; dn < MAXNODE; dn++)
	{
		short l = self->huf_node[dn].left;
		short r = self->huf_node[dn].right;

		if (l >= 0) l -= dictbase;
		if (r >= 0) r -= dictbase;

		e = writes(self, l);
		e = writes(self, r);
	}	
	/* Dictionary written. Start spitting bytes. */ 
	self->huf_nout = 0;
	self->huf_out  = 0;	
	rle_reset(self);
	e = rle_stream(self, huf_encode); if (e) return e;

	/* Write any pending bits */
	if (self->huf_nout)
	{
		if (fputc(self->huf_out, self->fp_out) == EOF) 
				return DSK_ERR_SYSERR;
	}
	fseek(self->fp_out, 2, SEEK_SET);
	
	return DSK_ERR_OK;
}
Esempio n. 17
0
void
roll(struct move *mm)
{
	char    c;
	int     row;
	int     col;

	row = col = 0;
	if (iroll) {
		if (tflag) {
			row = curr;
			col = curc;
			curmove(17, 0);
		} else
			writec('\n');
		writel("ROLL: ");
		c = readc();
		if (c != '\n') {
			while (c < '1' || c > '6')
				c = readc();
			mm->D0 = c - '0';
			writec(' ');
			writec(c);
			c = readc();
			while (c < '1' || c > '6')
				c = readc();
			mm->D1 = c - '0';
			writec(' ');
			writec(c);
			if (tflag) {
				curmove(17, 0);
				cline();
				curmove(row, col);
			} else
				writec('\n');
			return;
		}
		if (tflag) {
			curmove(17, 0);
			cline();
			curmove(row, col);
		} else
			writec('\n');
	}
	mm->D0 = rnum(6) + 1;
	mm->D1 = rnum(6) + 1;
	mm->d0 = 0;
}
Esempio n. 18
0
void
leave(void)
{
	int i;

	if (tflag)
		clear();
	else
		writec('\n');
	fixtty(old);
	args[0] = strdup("backgammon");
	args[acnt++] = strdup("-n");
	args[acnt] = 0;
	execv(EXEC, args);
	for (i = 0; i < acnt; i++)
		free(args[i]);
	writel("Help! Backgammon program is missing\007!!\n");
	exit(-1);
}
Esempio n. 19
0
File: main.c Progetto: fdotli/libu
static int test_advance (int opts)
{
    char c;
    enum { SZ = 3 };
    u_rb_t *rb = NULL;

    con_err_if (u_rb_create(SZ, opts, &rb));

    for (c = 0; c < 127; c++)
    {
        if (!isprint(c))
            continue;
        con_err_if (writec(rb, c));
        con_err_if (readc(rb, &c));
    }

    return 0;
err:
    return 1;
}
Esempio n. 20
0
int
quit(struct move *mm)
{

	if (tflag) {
		curmove(20, 0);
		clend();
	} else
		writec('\n');
	writel("Are you sure you want to quit?");
	if (yorn(0)) {
		if (rfl) {
			writel("Would you like to save this game?");
			if (yorn(0))
				save(mm, 0);
		}
		cturn = 0;
		return (1);
	}
	return (0);
}
Esempio n. 21
0
void
writel(const char *l)
{
#ifdef DEBUG
	const char   *s;

	if (trace == NULL)
		trace = fopen("bgtrace", "w");

	fprintf(trace, "writel: \"");
	for (s = l; *s; s++) {
		if (*s < ' ' || *s == '\177')
			fprintf(trace, "^%c", (*s) ^ 0100);
		else
			putc(*s, trace);
	}
	fprintf(trace, "\"\n");
	fflush(trace);
#endif

	while (*l)
		writec(*l++);
}
Esempio n. 22
0
File: main.c Progetto: fdotli/libu
static int write1 (u_rb_t *rb) { return writec(rb, '1'); }
Esempio n. 23
0
File: main.c Progetto: fdotli/libu
static int write2 (u_rb_t *rb) { return writec(rb, '2'); }
Esempio n. 24
0
File: main.c Progetto: fdotli/libu
static int write3 (u_rb_t *rb) { return writec(rb, '3'); }
Esempio n. 25
0
tutor ()  {
	register int	i, j;

	i = 0;
	begscr = 18;
	cturn = -1;
	home = 0;
	bar = 25;
	inptr = &in[0];
	inopp = &in[1];
	offptr = &off[0];
	offopp = &off[1];
	Colorptr = &color[0];
	colorptr = &color[2];
	colen = 5;
	wrboard();

	while (1)  {
		if (! brdeq(test[i].brd,board))  {
			if (tflag && curr == 23)
				curmove (18,0);
			writel (better);
			nexturn();
			movback (mvlim);
			if (tflag)  {
				refresh();
				clrest ();
			}
			if ((! tflag) || curr == 19)  {
				proll();
				writec ('\t');
			}
			else
				curmove (curr > 19? curr-2: curr+4,25);
			getmove();
			if (cturn == 0)
				leave();
			continue;
		}
		if (tflag)
			curmove (18,0);
		text (*test[i].com);
		if (! tflag)
			writec ('\n');
		if (i == maxmoves)
			break;
		D0 = test[i].roll1;
		D1 = test[i].roll2;
		d0 = 0;
		mvlim = 0;
		for (j = 0; j < 4; j++)  {
			if (test[i].mp[j] == test[i].mg[j])
				break;
			p[j] = test[i].mp[j];
			g[j] = test[i].mg[j];
			mvlim++;
		}
		if (mvlim)
			for (j = 0; j < mvlim; j++)
				if (makmove(j))
					writel ("AARGH!!!\n");
		if (tflag)
			refresh();
		nexturn();
		D0 = test[i].new1;
		D1 = test[i].new2;
		d0 = 0;
		i++;
		mvlim = movallow();
		if (mvlim)  {
			if (tflag)
				clrest();
			proll();
			writec('\t');
			getmove();
			if (tflag)
				refresh();
			if (cturn == 0)
				leave();
		}
	}
	leave();
}
Esempio n. 26
0
int
bosout(BOSIO *descriptor, int *buf)
{
  BOSIO *st;
  int error, ircn, nbytes, ii;

  st = descriptor;

  error = 0;

  nbytes = buf[0]*sizeof(int);

  if(st->access == 1)		/* sequential write */
  {
    st->outnum++;
    ircn = 0;

/* !!!!!!!!!!! remote files - as direct access !!!!! */
    if (st->client != 0) ircn = st->recnum + 1;

  }
  else if(st->access == 2)	/* direct write - determine record number */
  {
    ircn = st->outnum;
  }

  if(st->client != 0)
  {
    if(ircn != 0)
      ircn = (ircn-1)*nbytes + 1;
    if(st->client < 0)	/* network channel is dead, try to reconnect */
    {
      error = bosnres(descriptor,st->client,st->stream,1);
      if(error != 0) return(error);	/* reconnection failed */
    }
a:
    writec(&st->client,&st->stream,&ircn,&nbytes,buf,&error);
    if(error == -2)	/* network channel is dead, try to reconnect */
    {
      error = bosnres(descriptor,st->client,st->stream,1);
      if(error == 0) goto a;	/* reconnection successful */
      error = -1;
    }
  }
  else
  {
    error = cput(st->stream,ircn,buf[0],buf,st->medium);
  }
 
  if(st->access == 1)		/* sequential write */
  {
    if(error != 0) {
      DPR1("bosout : cput error = %i\n",error);
      return(error);
    }
    else
      st->recnum++;
  }
  else if(st->access == 2)	/* direct write - determine record number */
  {
    if(error != 0)
      return(error);
    else
      st->recnum = ircn;
  }
 
 
  return(error);
}
Esempio n. 27
0
void wrboard(void)
{
    int l;
    static const char bl[] = "|                       |   |                       |\n";
    static const char sv[] = "|                       |   |                       |    \n";

    fixtty(&noech);
    clear();

    if (tflag) {
	fboard();
	goto lastline;
    }
    writel("_____________________________________________________\n");
    writel(bl);
    strcpy(ln, bl);
    for (j = 1; j < 50; j += 4) {
	k = j / 4 + (j > 24 ? 12 : 13);
	ln[j + 1] = k % 10 + '0';
	ln[j] = k / 10 + '0';
	if (j == 21)
	    j += 4;
    }
    writel(ln);
    for (i = 0; i < 5; i++) {
	strcpy(ln, sv);
	for (j = 1; j < 50; j += 4) {
	    k = j / 4 + (j > 24 ? 12 : 13);
	    wrbsub();
	    if (j == 21)
		j += 4;
	}
	if (-board[25] > i)
	    ln[26] = 'w';
	if (-board[25] > i + 5)
	    ln[25] = 'w';
	if (-board[25] > i + 10)
	    ln[27] = 'w';
	l = 53;
	if (off[1] > i || (off[1] < 0 && off[1] + 15 > i)) {
	    ln[54] = 'r';
	    l = 55;
	}
	if (off[1] > i + 5 || (off[1] < 0 && off[1] + 15 > i + 5)) {
	    ln[55] = 'r';
	    l = 56;
	}
	if (off[1] > i + 10 || (off[1] < 0 && off[1] + 15 > i + 10)) {
	    ln[56] = 'r';
	    l = 57;
	}
	ln[l++] = '\n';
	ln[l] = '\0';
	writel(ln);
    }
    strcpy(ln, bl);
    ln[25] = 'B';
    ln[26] = 'A';
    ln[27] = 'R';
    writel(ln);
    strcpy(ln, sv);
    for (i = 4; i > -1; i--) {
	for (j = 1; j < 50; j += 4) {
	    k = ((j > 24 ? 53 : 49) - j) / 4;
	    wrbsub();
	    if (j == 21)
		j += 4;
	}
	if (board[0] > i)
	    ln[26] = 'r';
	if (board[0] > i + 5)
	    ln[25] = 'r';
	if (board[0] > i + 10)
	    ln[27] = 'r';
	l = 53;
	if (off[0] > i || (off[0] < 0 && off[0] + 15 > i)) {
	    ln[54] = 'w';
	    l = 55;
	}
	if (off[0] > i + 5 || (off[0] < 0 && off[0] + 15 > i + 5)) {
	    ln[55] = 'w';
	    l = 56;
	}
	if (off[0] > i + 10 || (off[0] < 0 && off[0] + 15 > i + 10)) {
	    ln[56] = 'w';
	    l = 57;
	}
	ln[l++] = '\n';
	ln[l] = '\0';
	writel(ln);
    }
    strcpy(ln, bl);
    for (j = 1; j < 50; j += 4) {
	k = ((j > 24 ? 53 : 49) - j) / 4;
	ln[j + 1] = k % 10 + '0';
	if (k > 9)
	    ln[j] = k / 10 + '0';
	if (j == 21)
	    j += 4;
    }
    writel(ln);
    writel("|_______________________|___|_______________________|\n");

  lastline:
    gwrite();
    if (tflag)
	curmove(18, 0);
    else {
	writec('\n');
	writec('\n');
    }
    fixtty(&bg_raw);
}
Esempio n. 28
0
/* zero if first move */
void
move(int okay)
{
    int i;			/* index */
    int l;			/* last man */

    l = 0;
    if (okay) {
        /* see if comp should double */
        if (gvalue < 64 && dlast != cturn && dblgood()) {
            writel(*Colorptr);
            dble();		/* double */
            /* return if declined */
            if (cturn != 1 && cturn != -1)
                return;
        }
        roll();
    }

    race = 0;
    for (i = 0; i < 26; i++) {
        if (board[i] < 0)
            l = i;
    }
    for (i = 0; i < l; i++) {
        if (board[i] > 0)
            break;
    }
    if (i == l)
        race = 1;

    /* print roll */
    if (tflag)
        curmove(cturn == -1 ? 18 : 19, 0);
    writel(*Colorptr);
    writel(" rolls ");
    writec(D0 + '0');
    writec(' ');
    writec(D1 + '0');
    /* make tty interruptable while thinking */
    if (tflag)
        cline();
    fixtty(noech);

    /* find out how many moves */
    mvlim = movallow();
    if (mvlim == 0) {
        writel(" but cannot use it.\n");
        nexturn();
        fixtty(raw);
        return;
    }

    /* initialize */
    for (i = 0; i < 4; i++)
        cp[i] = cg[i] = 0;

    /* strategize */
    trymove(0, 0);
    pickmove();

    /* print move */
    writel(" and moves ");
    for (i = 0; i < mvlim; i++) {
        if (i > 0)
            writec(',');
        wrint(p[i] = cp[i]);
        writec('-');
        wrint(g[i] = cg[i]);
        makmove(i);
    }
    writec('.');

    /* print blots hit */
    if (tflag)
        curmove(20, 0);
    else
        writec('\n');
    for (i = 0; i < mvlim; i++)
        if (h[i])
            wrhit(g[i]);
    /* get ready for next move */
    nexturn();
    if (!okay) {
        buflush();
        sleep(3);
    }
    fixtty(raw);		/* no more tty interrupt */
}
Esempio n. 29
0
int
text(const char *const *txt)
{
	const char *a;
	char b;
	const char *c;
	int i;

	fixtty(noech);
	while (*txt) {
		a = *(txt++);
		if (*a != '\0') {
			c = a;
			for (i = 0; *(c++) != '\0'; i--)
			    ; /* nothing */
			writel(a);
			writec('\n');
		} else {
			fixtty(raw);
			writel(prompt);
			for (;;) {
				if ((b = readc()) == '?') {
					if (tflag) {
						if (begscr) {
							curmove(18, 0);
							clend();
						} else
							clear();
					} else
						writec('\n');
					text(list);
					writel(prompt);
					continue;
				}
				i = 0;
				if (b == '\n')
					break;
				while (i < 11) {
					if (b == opts[i])
						break;
					i++;
				}
				if (i == 11)
					writec('\007');
				else
					break;
			}
			if (tflag) {
				if (begscr) {
					curmove(18, 0);
					clend();
				} else
					clear();
			} else
				writec('\n');
			if (i)
				return (i);
			fixtty(noech);
			if (tflag)
				curmove(curr, 0);
		}
	}
	fixtty(raw);
	return (0);
}
Esempio n. 30
0
getmove ()  {
	register int	i, c;

	c = 0;
	for (;;)  {
		i = checkmove(c);

		switch (i)  {
		case -1:
			if (movokay(mvlim))  {
				if (tflag)
					curmove (20,0);
				else
					writec ('\n');
				for (i = 0; i < mvlim; i++)
					if (h[i])
						wrhit(g[i]);
				nexturn();
				if (*offopp == 15)
					cturn *= -2;
				if (tflag && pnum)
					bflag = pnum;
				return;
			}

		case -4:
		case 0:
			if (tflag)
				refresh();
			if (i != 0 && i != -4)
				break;
			if (tflag)
				curmove (20,0);
			else
				writec ('\n');
			writel (*Colorptr);
			if (i == -4)
				writel (" must make ");
			else
				writel (" can only make ");
			writec (mvlim+'0');
			writel (" move");
			if (mvlim > 1)
				writec ('s');
			writec ('.');
			writec ('\n');
			break;

		case -3:
			if (quit())
				return;
		}

		if (! tflag)
			proll ();
		else  {
			curmove (cturn == -1? 18: 19,39);
			cline ();
			c = -1;
		}
	}
}