|
|
1.1 root 1: #include "definitions"
2:
3: /* I/O ROUTINES TO CPU2 CONSOLE */
4: writec(c)
5: char c;
6: {
7: putchar(c);
8: }
9: writes(s)
10: char *s;
11: {
12: putstr(s);
13: }
14: writeh(ix) /* 32 bits HEX */
15: long ix;
16: { register long count, mask, indx;
17: char c, str[9];
18:
19: if (ix==0) { writec('0'); return; }
20: indx = 0; count = 28;
21: mask = 0xf0000000;
22: str[8]='\0';
23: while (mask) {
24: c = ( (ix&mask) >> count )&0xf;
25: count -= 4;
26: if (indx==0) mask = 0xf000000;
27: else mask = mask >> 4;
28: if ((c>=0)&&(c<=9)) c=c+'0';
29: else c=c+'7';
30: str[indx++] = c;
31: }
32: indx = 0;
33: /* replace leading 0 with space */
34: /* for (indx=0; indx<8; indx++) {
35: if (str[indx]!='0') break;
36: else str[indx]=' ';
37: }
38: */
39: writes(&str[indx]);
40: }
41: /* Function to write a 32_bit decimal to Console
42: */
43: writed(ix)
44: long ix;
45: { char c;
46: register long div, lead0;
47:
48: if (ix==0) { writec('0'); return; }
49: if (ix<0) { writec('-'); ix = (~ix)+1; }
50: lead0 = 1;
51: div = 1000000000;
52: while (div) {
53: c = (ix/div)+'0';
54: ix = ix%div; /* Mod */
55: div /= 10;
56: if ((c=='0')&&(lead0)) c=' ';
57: else lead0 = 0;
58: if (c != ' ') writec(c);
59: }
60: }
61: /* Function read 1 char from Console
62: */
63: char readc()
64: { char c, rdchar();
65:
66: writec(c=rdchar());
67: return(c);
68: }
69: /* This function read a string of characters.
70: calling sequence : nochar = reads(s);
71: input argument : char *s;
72: return value : no. of char read; excluding NULL or CR.
73: */
74: reads(s)
75: char *s;
76: { register long ix;
77:
78: for(ix=0;;ix++) {
79: *s = readc();
80: if (*s == '015')
81: { *s = NULL; return(ix); }
82: else s++;
83: }
84: }
85: /* This function read a string of HEX digit and
86: convert it to integer value.
87: calling sequence : stat = readh(ix);
88: input parameter : long *ix;
89: return value : (stat < 0) if error else (stat = 0);
90: */
91: /*
92: readh(ix)
93: long *ix;
94: { char line[ALINE], *getnum(), *del;
95: int nochar;
96:
97: if ( (nochar = reads(line)) > 8 ) return(-1);
98: if ( (del = getnum(line,ix,del,HEX)) < 0 ) return(-1);
99: else return(0);
100: }
101: */
102: /* This function read a string of DEC digit and
103: convert it to integer value.
104: calling sequence : stat = readd(ix);
105: input parameter : long *ix;
106: return value : (stat < 0) if error else (stat = 0);
107: */
108: /*
109: readd(ix)
110: long *ix;
111: { char line[ALINE], *getnum(), *del;
112: int nochar;
113:
114: if ( (nochar = reads(line)) > 11 ) return(-1);
115: if ( (del = getnum(line,ix,del,DEC)) < 0 ) return(-1);
116: else return(0);
117: }
118: */
119:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.