Annotation of researchv9/jtools/src/pads/host/protocol.c, revision 1.1.1.1

1.1       root        1: #include <pads.pri>
                      2: 
                      3: static void Proto(p) { PutRemote(p); }
                      4: 
                      5: static void CheckProto( p ) { if( GetRemote() != p ) ProtoErr(); }
                      6: 
                      7: static long ShiftIn( bytes )
                      8: register bytes;
                      9: {
                     10:        register long shifter = 0;
                     11: 
                     12:        CheckProto( bytes );
                     13:        while( bytes-- ) shifter = (shifter<<8) + (GetRemote()&0xFF);
                     14:        return shifter;
                     15: }
                     16: 
                     17: long  RcvLong()  { return (long)  ShiftIn( P_LONG  ); }
                     18: short RcvShort() { return (short) ShiftIn( P_SHORT ); }
                     19: unsigned char RcvUChar() { return (unsigned char) ShiftIn( P_UCHAR ); }
                     20: 
                     21: static void ShiftOut( bytes, shifter )
                     22: register bytes;
                     23: register long shifter;
                     24: {
                     25:        Proto( bytes );
                     26:        do { PutRemote( (char)(shifter>>( (--bytes)*8 )) ); } while( bytes );
                     27: }
                     28: 
                     29: void SendLong(x)  long  x; { ShiftOut( P_LONG,  (long) x ); }
                     30: void SendShort(x) short x; { ShiftOut( P_SHORT, (long) x ); }
                     31: void SendUChar(x) unsigned char x; { ShiftOut( P_UCHAR, (long) x ); }
                     32: 
                     33: char *RcvString( s0 )
                     34: char *s0;
                     35: {
                     36:        register char *s = s0;
                     37:        register unsigned char len;
                     38: 
                     39:        CheckProto( P_STRING );
                     40:        len = RcvUChar();
                     41:        if( !s0 ) s = s0 = new char [len+1];
                     42:        while( len-->0 ) *s++ = GetRemote();
                     43:        *s = '\0';
                     44:        return s0;
                     45: }
                     46: 
                     47: void SendString(s)
                     48: register char *s;
                     49: {
                     50:        int len;
                     51: 
                     52:        Proto( P_STRING );
                     53:        len =  strlen(s);
                     54:        if( len > 255 ) len = 255;
                     55:        SendUChar( len );
                     56:        while( len-- ) PutRemote(*s++); 
                     57: }

unix.superglobalmegacorp.com

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