/******************************************************************************* Copyright by Telesoft Europe AB 1990, 1991. Copyright by Telelogic Malmoe AB 1991, 1992, 1993, 1994. Copyright by Telelogic AB 1994 - 1998. This Program is owned by Telelogic and is protected by national copyright laws and international copyright treaties. Telelogic grants you the right to use this Program on one computer or in one local computer network at any one time. Under this License you may only modify the source code for the purpose of adapting it to your environment. You must reproduce and include any copyright and trademark notices on all copies of the source code. You may not use, copy, merge, modify or transfer the Program except as provided in this License. Telelogic does not warrant that the Program will meet your requirements or that the operation of the Program will be uninterrupted and error free. You are solely responsible that the selection of the Program and the modification of the source code will achieve your intended results and that the results are actually obtained. *******************************************************************************/ NEWTYPE byte /*#NAME 'byte' */ OPERATORS BAND /*#NAME 'BITWISE_AND_BYTES' */ : byte, byte -> byte; BOR /*#NAME 'BITWISE_OR_BYTES' */ : byte, byte -> byte; BXOR /*#NAME 'BITWISE_XOR_BYTES' */ : byte, byte -> byte; BNOT /*#NAME 'UNARY_NOT_BYTES' */ : byte -> byte; BSHL /*#NAME 'BITWISE_SHL_BYTES' */ : byte, Integer -> byte; /* BSHL truncates the result to the least significant byte*/ BSHR /*#NAME 'BITWISE_SHR_BYTES' */ : byte, Integer -> byte; BPLUS /*#NAME 'ADD_BYTES' */ : byte, byte -> byte; /* BPLUS truncates the result to the least significant byte*/ BSUB /*#NAME 'SUB_BYTES' */ : byte, byte -> byte; BMUL /*#NAME 'MUL_BYTES' */ : byte, byte -> byte; /* BMUL truncates the result to the least significant byte */ BDIV /*#NAME 'DIV_BYTES' */ : byte, byte -> byte; BMOD /*#NAME 'MOD_BYTES' */ : byte, byte -> byte; BHEX /*#NAME 'BHEX' */ : Charstring -> byte; /* BHEX transforms a CHARSTRING ( '00' - 'ff') into a byte. The string may be prefixed with an optional '0x'. */ I2B /*#NAME 'I2B ' */ : Integer -> byte; /* I2B transforms a INTEGER ( 00 - 255 ) into a byte */ B2I /*#NAME 'B2I ' */ : byte -> Integer; /* B2I transforms a BYTE ( 0x00 - 0xFF ) into an integer */ /*#ADT ( T A(S) E(S) R(H) W(H) D(H) HP) #TYPE typedef unsigned char byte; #ifdef XREADANDWRITEF static char yCTemp_Byte[20]; #endif #HEADING #define yDef_byte(V) *(V) = 0 #define BITWISE_AND_BYTES(ex1, ex2) ((ex1) & (ex2)) #define BITWISE_OR_BYTES(ex1, ex2) ((ex1) | (ex2)) #define BITWISE_XOR_BYTES(ex1, ex2) ((ex1) ^ (ex2)) #define UNARY_NOT_BYTES(ex1) (byte)(~(ex1)) #define BITWISE_SHL_BYTES(ex1, int1) (byte)( ((ex1) << (int1)) & 0xFF ) #define BITWISE_SHR_BYTES(ex1, int1) ((ex1) >> (int1)) #define ADD_BYTES(ex1, ex2) (byte)( ((ex1) + (ex2)) & 0xFF ) #define SUB_BYTES(ex1, ex2) ((ex1) - (ex2)) #define MUL_BYTES(ex1, ex2) (byte)( ((ex1) * (ex2)) & 0xFF ) #ifndef XEINTDIV #define DIV_BYTES(ex1, ex2) ((ex1) / (ex2)) #else extern byte DIV_BYTES XPP(( byte ex1, byte ex2)); #endif #ifndef XEINTDIV #define MOD_BYTES(ex1, ex2) ((ex1) % (ex2)) #else extern byte MOD_BYTES XPP(( byte ex1, byte ex2)); #endif #define BHEX( lit1 ) hxstr2byte( lit1 ) #define I2B( ex1 ) (byte)( ex1 ) #define B2I( ex1 ) (SDL_Integer)( ex1 ) extern byte hxstr2byte XPP(( char *S )); #ifdef XREADANDWRITEF extern int yRead_byte XPP(( void *Result )); extern char *yWri_byte XPP(( void *C )); #endif #BODY #ifdef XEINTDIV #ifndef XNOPROTO extern byte DIV_BYTES(byte ex1, byte ex2) #else extern byte DIV_BYTES(ex1, ex2) byte ex1, ex2; #endif { if ( ex2 == 0 ) { xSDLOpError("Division in sort byte", "Byte division with 0"); return 0; } else return ex1 / ex2; } #ifndef XNOPROTO extern byte MOD_BYTES(byte ex1, byte ex2) #else extern byte MOD_BYTES(ex1, ex2) byte ex1, ex2; #endif { if ( ex2 == 0 ) { xSDLOpError("Modulus operator in sort byte", "Right operand is 0"); return 0; } else return ex1 % ex2; } #endif COMMENT( ASCII-character to hexadecimal bit pattern conversion. \ Result is in the range 0x00 to 0x0F ) #ifndef XNOPROTO extern byte a2hex( char c ) #else extern byte a2hex( c ) char c; #endif { c &= 0x7F; if ( c < '0' ) return 0; if ( c <= '9' ) return ( c - 0x30 ); if ( c < 'A' ) return 0; if ( c <= 'F' ) return ( c - 0x37 ); if ( c < 'a' ) return 0; if ( c <= 'f' ) return ( c - 0x57 ); return 0; } COMMENT( Convert the last 2 characters in a string of hexadecimal \ ASCII-characters ( '0' - 'f' or 'F' ) to a byte ) #ifndef XNOPROTO extern byte hxstr2byte( char *S ) #else extern byte hxstr2byte( S ) char *S; #endif { byte result = 0x00; while ( *S ){ result = ( result << 4 ) | a2hex( *S++ ); } return result; } #ifdef XREADANDWRITEF #ifndef XNOPROTO extern int yRead_byte( void *Result ) #else extern int yRead_byte( Result ) void *Result; #endif { unsigned temp; xxToken Token; Token = xPromptQuestionMark(" (byte) : ", " (byte) : ", yCTemp_Byte); if (Token == xxId && sscanf(yCTemp_Byte, "%X", &temp) >= 1) { *(byte *)Result = (byte)temp; return 1; } xPrintString("Illegal byte value\n"); return 0; } #ifndef XNOPROTO extern char *yWri_byte( void * C) #else extern char *yWri_byte( C ) void * C; #endif { sprintf(yCTemp_Byte, "%0.2X", *(byte *)C); return yCTemp_Byte; } #endif */ ENDNEWTYPE byte;