File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / d / io / Lib / bio.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:24:19 2019 UTC (7 years ago) by root
Branches: bsd, MAIN
CVS tags: v12b, v121, HEAD
Power 6/32 Unix version 1.2b


#define NULL	'\0'
#define CR	'\n'


/*	I/O ROUTINES TO CPU2 CONSOLE 	*/

writec(c)
char c;
{
	putchar(c);
}

writes(s)
char *s;
{
	putstr(s);
}

writeh(ix)	/* 32 bits HEX */
long ix;
{	register long count, mask, indx;
	char c, str[9];

	if (ix==0) { writec('0'); return; }
	indx = 0; count = 28;
	mask = 0xf0000000;
	str[8]='\0';
	while (mask)  {
		c = ( (ix&mask) >> count )&0xf;
		count -= 4;
		if (indx==0) mask = 0xf000000;
			else mask = mask >> 4;
		if ((c>=0)&&(c<=9)) c=c+'0';
			else c=c+'7';
		str[indx++] = c;
		}
	/* replace leading 0 with space */
	for (indx=0; indx<8; indx++) {
		if (str[indx]!='0') break;
			/* esle str[indx]=' '; */
		}
	writes(&str[indx]);
}

/* 	Function to write a 32_bit decimal to Console
*/
writed(ix)
long ix;
{	char c;
	register long div, lead0;

	if (ix==0) { writec('0'); return; }
	if (ix<0) { writec('-'); ix = (~ix)+1; }
	lead0 = 1;
	div = 1000000000;
	while (div) {
		c = (ix/div)+'0';
		ix = ix%div;		/* Mod */
		div /= 10;
		if ((c=='0')&&(lead0)) c=' ';
			else lead0 = 0;
		if (c != ' ') writec(c);
		}
}

/*	Function read 1 char from Console
*/
char readc()
{
	return(rdchar());
}

/*	This function read a string of characters.
	calling sequence : nochar = reads(s);
	input argument   : char *s;
	return value     : no. of char read; excluding NULL or CR.
*/
reads(s)
char *s;
{	register long ix;

	for(ix=0;;ix++) {
		*s = readc();
		if ((*s==NULL)||(*s==CR)) 
			{ *s = NULL; break; }
		     else s++;
		}
	return(ix);
}


unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.