|
|
1.1 ! root 1: ! 2: #include "definitions" ! 3: ! 4: /* I/O ROUTINES TO CPU2 CONSOLE */ ! 5: ! 6: #define MAXC 1000 /* MAX 1000 chars per line */ ! 7: #define OUTADR 0x20000 /* Address of output buffer */ ! 8: #define INADR 0x20100 /* Address of input buffer */ ! 9: ! 10: long ocnt = 0; /* Next location in output buffer */ ! 11: long icnt = 0; /* Next location in input buffer */ ! 12: extern long savvec7; ! 13: ! 14: writec(c) /* VERSION to run on the simmulator */ ! 15: char c; ! 16: { ! 17: ! 18: /* asm("mfpr $MME,_savvec7"); ! 19: asm("movl *$0x418,_savvec7"); ! 20: savvec7 = savvec7 & 0x1; ! 21: asm("mtpr $0,$MME"); ! 22: */ ! 23: ! 24: putchar(c); ! 25: /* asm("mtpr _savvec7,$MME"); Restore MME */ ! 26: } ! 27: ! 28: readc(c) ! 29: char *c; ! 30: { char *cptr; ! 31: ! 32: /* asm("mfpr $MME,_savvec7"); */ ! 33: asm("movl *$0x414,_savvec7"); /* Cheat mfpr MME */ ! 34: savvec7 = savvec7 & 0x1; ! 35: asm("mtpr $0,$MME"); /* Disable MME */ ! 36: cptr = (char *)(INADR+ icnt++); ! 37: *c = *cptr; ! 38: asm("mtpr _savvec7,$MME"); /* Restore MME */ ! 39: } ! 40: ! 41: writes(s) ! 42: char *s; ! 43: { char *str; ! 44: int ix; ! 45: ! 46: str = s; ! 47: for(ix=0;;ix++) ! 48: { ! 49: if (str[ix]==NULL) break; ! 50: else writec(str[ix]); ! 51: } ! 52: } ! 53: ! 54: /* This function read a string of characters. ! 55: calling sequence : nochar = reads(s); ! 56: input argument : char *s; ! 57: return value : no. of char read; excluding NULL or CR. ! 58: */ ! 59: reads(s) ! 60: char *s; ! 61: { char *str; ! 62: int ix; ! 63: ! 64: str = s; ! 65: for(ix=0;ix<ALINE;ix++) ! 66: { ! 67: readc(str); ! 68: if ((*str==NULL)||(*str==CR)) ! 69: { *str = NULL; ! 70: break; ! 71: } ! 72: else str++; ! 73: } ! 74: icnt = 0; /* For simulator only */ ! 75: ! 76: return(ix); ! 77: } ! 78: /* This function read a string of HEX digit and ! 79: convert it to integer value. ! 80: calling sequence : stat = readh(ix); ! 81: input parameter : long *ix; ! 82: return value : (stat < 0) if error else (stat = 0); ! 83: */ ! 84: ! 85: /* ! 86: readh(ix) ! 87: long *ix; ! 88: { char line[ALINE], *getnum(), *del; ! 89: int nochar; ! 90: ! 91: if ( (nochar = reads(line)) > 8 ) return(-1); ! 92: if ( (del = getnum(line,ix,del,HEX)) < 0 ) return(-1); ! 93: else return(0); ! 94: } ! 95: ! 96: */ ! 97: ! 98: ! 99: ! 100: writeh(ix) /* 32 bits HEX */ ! 101: long ix; ! 102: { long iy, temp, mask; ! 103: int count; ! 104: char c; ! 105: ! 106: iy=1; count = 28; ! 107: mask = 0xf0000000; ! 108: while (mask) ! 109: { ! 110: c = ( (ix&mask) >> count )&0xf; ! 111: count -= 4; ! 112: mask = mask >> 4; ! 113: if (iy) ! 114: { mask = 0xf000000; ! 115: iy=0; ! 116: } ! 117: if ((c>=0)&&(c<=9)) c=c+'0'; ! 118: else c=c+'7'; ! 119: writec(c); ! 120: } ! 121: } ! 122: ! 123: /* This function read a string of DEC digit and ! 124: convert it to integer value. ! 125: calling sequence : stat = readd(ix); ! 126: input parameter : long *ix; ! 127: return value : (stat < 0) if error else (stat = 0); ! 128: */ ! 129: ! 130: /* ! 131: readd(ix) ! 132: long *ix; ! 133: { char line[ALINE], *getnum(), *del; ! 134: int nochar; ! 135: ! 136: if ( (nochar = reads(line)) > 11 ) return(-1); ! 137: if ( (del = getnum(line,ix,del,DEC)) < 0 ) return(-1); ! 138: else return(0); ! 139: } ! 140: */ ! 141: ! 142: ! 143: writed(ix) /* 32 bits DECIMAL */ ! 144: long ix; ! 145: { char c; ! 146: long div; ! 147: float divi; ! 148: int lead0; ! 149: ! 150: /* ! 151: if (ix<0) ! 152: { writes("********"); ! 153: return(0); } ! 154: lead0 = 1; ! 155: divi = 1000000000; ! 156: div = divi; ! 157: while (div) ! 158: { ! 159: c = (ix/div)+'0'; ! 160: ix = ix%div; ! 161: divi = divi/10; ! 162: div = divi; ! 163: if ((c=='0')&&(lead0)) c=SPACE; ! 164: else lead0 = 0; ! 165: writec(c); ! 166: } ! 167: */ ! 168: ! 169: } ! 170:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.