UIBytes.st
changeset 3433 a94725308432
parent 3410 93393f1c1022
child 3434 d04ff3256ebb
equal deleted inserted replaced
3432:1228d4ba9518 3433:a94725308432
    14 	instanceVariableNames:''
    14 	instanceVariableNames:''
    15 	classVariableNames:'IsBigEndian'
    15 	classVariableNames:'IsBigEndian'
    16 	poolDictionaries:''
    16 	poolDictionaries:''
    17 	category:'Collections-Abstract'
    17 	category:'Collections-Abstract'
    18 !
    18 !
       
    19 
       
    20 !UninterpretedBytes primitiveDefinitions!
       
    21 %{
       
    22 /*
       
    23  * Notice: I am abstract, and my subclasses may be anything.
       
    24  * Therefore, the code must always handle the fallback case
       
    25  * where the receiver is neither an ExternalBytes nor a ByteArray.
       
    26  * (which are, however, the most common)
       
    27  *
       
    28  * macro to fetch my byte address and size-in-bytes;
       
    29  * convenient for inline-C code.
       
    30  * (yes, C is bad ...)
       
    31  */
       
    32 #define __fetchBytePointerAndSize__(o, pPtr, pSize) \
       
    33     {\
       
    34       if (__isNonNilObject(o)) { \
       
    35         if (__qClass(o) == ByteArray) { \
       
    36 	  *(pPtr) = (char *)__ByteArrayInstPtr(o)->ba_element; \
       
    37 	  *(pSize) = __byteArraySize(o); \
       
    38 	} else if (__qClass(o) == ExternalBytes) { \
       
    39 	  OBJ __sz__ = __externalBytesSize(o); \
       
    40 	  if (__isSmallInteger(__sz__)) { \
       
    41 	    *(pSize) = __intVal(__sz__); \
       
    42 	    *(pPtr) = (char *)(__externalBytesAddress(o)); \
       
    43 	  } else { \
       
    44 	    *(pPtr) = (char *)0; \
       
    45 	  } \
       
    46 	} else { \
       
    47 	    *(pPtr) = (char *)0; \
       
    48 	} \
       
    49       } else { \
       
    50 	*(pPtr) = (char *)0; \
       
    51       } \
       
    52     }
       
    53 
       
    54 %}
       
    55 ! !
    19 
    56 
    20 !UninterpretedBytes class methodsFor:'documentation'!
    57 !UninterpretedBytes class methodsFor:'documentation'!
    21 
    58 
    22 copyright
    59 copyright
    23 "
    60 "
    42     and 
    79     and 
    43 	ExternalBytes (which store the bytes in the malloc-heap).
    80 	ExternalBytes (which store the bytes in the malloc-heap).
    44 
    81 
    45     UninterpretedBytes itself is abstract, so no instances of it can be created.
    82     UninterpretedBytes itself is abstract, so no instances of it can be created.
    46 
    83 
       
    84     [See also:]
       
    85         ByteArray String ExternalBytes
       
    86 
    47     [author:]
    87     [author:]
    48         Claus Gittinger
    88         Claus Gittinger
    49 
    89 
    50     [See also:]
    90     [Notice:]
    51         ByteArray String ExternalBytes
    91 	Notice the confusion due to multiple methods with the same
    52 
    92         functionality (i.e. 'xxxx:MSB:' vs. 'xxxx:bigEndian:').
    53     [author:]
    93         The reason is that at the time this class was written,
    54         Claus Gittinger
    94         ST80 sid not offer protocol to specify the byteOrder, and
       
    95         ST/X provided methods ending in 'MSB:' for this.
       
    96         In the meanwhile, VW added protocol ending in 'bigEndian:',
       
    97 	which has been added here for compatibility.
       
    98 	(certainly a point, where an ansi-standard will help)
    55 "
    99 "
    56 ! !
   100 ! !
    57 
   101 
    58 !UninterpretedBytes class methodsFor:'initialization'!
   102 !UninterpretedBytes class methodsFor:'initialization'!
    59 
   103 
   106 
   150 
   107 %{  /* NOCONTEXT */
   151 %{  /* NOCONTEXT */
   108 
   152 
   109     /*
   153     /*
   110      * I dont like ifdefs - you always forget some ...
   154      * I dont like ifdefs - you always forget some ...
   111      * therefore we look into a structure at run-time
   155      * therefore we look into a structure at run-time.
       
   156      * (also, there are CPUs around [mips], where the byteorder
       
   157      *  is programmable, and which come in different flavours)
       
   158      *
       
   159      * NOTICE: 
       
   160      *    both the JIT and stc may inline this to a 
       
   161      *    constant for systems where this is known.
   112      */
   162      */
   113     union {
   163     union {
   114 	unsigned int   u_l;
   164 	unsigned int   u_l;
   115 	char           u_c[sizeof(int)];
   165 	char           u_c[sizeof(int)];
   116     } u;
   166     } u;
   117 
   167 
   118     u.u_l = 0x87654321;
   168     u.u_l = 0x87654321;
   119     if (u.u_c[0] == 0x21) RETURN (false);
   169     if (u.u_c[0] == 0x21) RETURN (false);
   120     RETURN (true);
   170     RETURN (true);
   121 %}
   171 %}
   122     "UninterpretedBytes isBigEndian"
   172     "
       
   173      UninterpretedBytes isBigEndian
       
   174     "
   123 !
   175 !
   124 
   176 
   125 isBuiltInClass
   177 isBuiltInClass
   126     "return true if this class is known by the run-time-system.
   178     "return true if this class is known by the run-time-system.
   127      Here, true is returned, since UninterpretedBytes is the superclass of
   179      Here, true is returned, since UninterpretedBytes is the superclass of
   151     ^ self subclassResponsibility
   203     ^ self subclassResponsibility
   152 !
   204 !
   153 
   205 
   154 doubleAt:index
   206 doubleAt:index
   155     "return the 8-bytes starting at index as a Float.
   207     "return the 8-bytes starting at index as a Float.
       
   208      The index is a smalltalk index (i.e. 1-based).
   156      Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
   209      Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
   157      Notice also, that the bytes are expected to be in this machines
   210      Notice also, that the bytes are expected to be in this machines
   158      float representation - if the bytearray originated from another
   211      float representation - if the bytearray originated from another
   159      machine, some conversion is usually needed."
   212      machine, some conversion is usually needed."
   160 
   213 
   161     |newFloat|
   214     |newFloat|
   162 
   215 
       
   216 %{
       
   217     /*
       
   218      * handle the most common cases fast ...
       
   219      */
       
   220     if (__isSmallInteger(index)) {
       
   221 	char *cp;
       
   222 	int sz;
       
   223 	
       
   224 	__fetchBytePointerAndSize__(self, &cp, &sz);
       
   225         if (cp) {
       
   226 	    unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
       
   227 
       
   228 	    if ((idx+7) < sz) {
       
   229 		cp += idx;
       
   230 		/*
       
   231 		 * aligned
       
   232 		 */
       
   233 		if (((INT)cp & 7) == 0) {
       
   234 		    double dVal = ((double *)cp)[0];
       
   235 		    RETURN (__MKFLOAT(dVal));
       
   236 		}
       
   237 	    }
       
   238 	}
       
   239     }
       
   240 %}.
       
   241 
   163     newFloat := Float basicNew.
   242     newFloat := Float basicNew.
   164     1 to:8 do:[:destIndex|
   243     1 to:8 do:[:destIndex|
   165 	newFloat basicAt:destIndex put:(self at:index - 1 + destIndex)
   244 	newFloat basicAt:destIndex put:(self at:index - 1 + destIndex)
   166     ].
   245     ].
   167     ^ newFloat.
   246     ^ newFloat.
       
   247 
       
   248     "
       
   249      |b|
       
   250 
       
   251      b := ByteArray new:20.
       
   252      b doubleAt:1 put:(Float pi).
       
   253      Transcript showCR:b.
       
   254      Transcript showCR:(b doubleAt:1)
       
   255     "
   168 !
   256 !
   169 
   257 
   170 doubleAt:index put:aFloat
   258 doubleAt:index put:aFloat
   171     "store the value of the argument, aFloat into the receiver
   259     "store the value of the argument, aFloat into the receiver
   172      starting at index.
   260      starting at index.
       
   261      The index is a smalltalk index (i.e. 1-based).
   173      Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
   262      Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
   174      Notice also, that the bytes are expected to be in this machines
   263      Notice also, that the bytes are expected to be in this machines
   175      float representation - if the bytearray originated from another
   264      float representation - if the bytearray originated from another
   176      machine, some conversion is usually needed."
   265      machine, some conversion is usually needed."
   177 
   266 
   178     |flt|
   267     |flt|
   179 
   268 
   180     flt := aFloat asFloat.
   269     flt := aFloat asFloat.
       
   270 %{
       
   271     /*
       
   272      * handle the most common cases fast ...
       
   273      */
       
   274     if (__isSmallInteger(index) && __isFloat(flt)) {
       
   275         char *cp;
       
   276         int sz;
       
   277 
       
   278         __fetchBytePointerAndSize__(self, &cp, &sz);
       
   279         if (cp) {
       
   280             unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
       
   281 
       
   282             if ((idx+7) < sz) {
       
   283                 cp += idx;
       
   284                 /*
       
   285                  * aligned
       
   286                  */
       
   287                 if (((INT)cp & 7) == 0) {
       
   288                     ((double *)cp)[0] = __floatVal(flt);
       
   289                     RETURN (aFloat);
       
   290                 }
       
   291             }
       
   292         }
       
   293     }
       
   294 %}.
       
   295 
   181     1 to:8 do:[:srcIndex|
   296     1 to:8 do:[:srcIndex|
   182         self at:index - 1 + srcIndex put:(flt basicAt:srcIndex)
   297         self at:index - 1 + srcIndex put:(flt basicAt:srcIndex)
   183     ].
   298     ].
   184     ^ aFloat
   299     ^ aFloat
   185 !
   300 !
   186 
   301 
   187 doubleWordAt:index
   302 doubleWordAt:index
   188     "return the 4-bytes starting at index as an (unsigned) Integer.
   303     "return the 4-bytes starting at index as an (unsigned) Integer.
       
   304      The index is a smalltalk index (i.e. 1-based).
   189      The value is retrieved in the machines natural byte order.
   305      The value is retrieved in the machines natural byte order.
   190      Subclasses may redefine this for better performance."
   306      Subclasses may redefine this for better performance."
   191 
   307 
   192     ^ self doubleWordAt:index MSB:IsBigEndian
   308     ^ self doubleWordAt:index MSB:IsBigEndian
   193 
   309 
   201     "Modified: / 5.3.1998 / 14:57:35 / stefan"
   317     "Modified: / 5.3.1998 / 14:57:35 / stefan"
   202 !
   318 !
   203 
   319 
   204 doubleWordAt:index MSB:msb
   320 doubleWordAt:index MSB:msb
   205     "return the 4-bytes starting at index as an (unsigned) Integer.
   321     "return the 4-bytes starting at index as an (unsigned) Integer.
       
   322      The index is a smalltalk index (i.e. 1-based).
   206      The value is retrieved MSB-first, if the msb-arg is true;
   323      The value is retrieved MSB-first, if the msb-arg is true;
   207      LSB-first otherwise.
   324      LSB-first otherwise.
   208      Subclasses may redefine this for better performance."
   325      Subclasses may redefine this for better performance."
   209 
   326 
   210     |val 
   327     |val 
   211      ival "{ Class: SmallInteger }"
   328      ival "{ XXClass: SmallInteger }"
   212      i    "{ Class: SmallInteger }"
   329      i    "{ Class: SmallInteger }"
   213      b1   "{ Class: SmallInteger }"
   330      b1   "{ Class: SmallInteger }"
   214      b2   "{ Class: SmallInteger }"
   331      b2   "{ Class: SmallInteger }"
   215      b3   "{ Class: SmallInteger }"
   332      b3   "{ Class: SmallInteger }"
   216      b4   "{ Class: SmallInteger }"|
   333      b4   "{ Class: SmallInteger }"|
   223 
   340 
   224     msb ifTrue:[
   341     msb ifTrue:[
   225         ival := b1.
   342         ival := b1.
   226         ival := (ival bitShift:8) + b2.
   343         ival := (ival bitShift:8) + b2.
   227         ival := (ival bitShift:8) + b3.
   344         ival := (ival bitShift:8) + b3.
   228         val := (ival * 256) + b4.
   345         val := (ival bitShift:8) + b4.
   229     ] ifFalse:[
   346     ] ifFalse:[
   230         ival := b4.
   347         ival := b4.
   231         ival := (ival bitShift:8) + b3.
   348         ival := (ival bitShift:8) + b3.
   232         ival := (ival bitShift:8) + b2.
   349         ival := (ival bitShift:8) + b2.
   233         val := (ival * 256) + b1.
   350         val := (ival bitShift:8) + b1.
   234     ].
   351     ].
   235     ^ val
   352     ^ val
   236 
   353 
   237     "
   354     "
   238      |b|
   355      |b|
   245     "Modified: / 21.1.1998 / 17:42:30 / cg"
   362     "Modified: / 21.1.1998 / 17:42:30 / cg"
   246 !
   363 !
   247 
   364 
   248 doubleWordAt:index put:value
   365 doubleWordAt:index put:value
   249     "set the 4-bytes starting at index from the (unsigned) Integer value.
   366     "set the 4-bytes starting at index from the (unsigned) Integer value.
       
   367      The index is a smalltalk index (i.e. 1-based).
   250      The value should be in the range 0 to 16rFFFFFFFF
   368      The value should be in the range 0 to 16rFFFFFFFF
   251      (for negative values, the stored value is not defined).
   369      (for negative values, the stored value is not defined).
   252      The value is stored in the machines natural byte order.
   370      The value is stored in the machines natural byte order.
   253      Subclasses may redefine this for better performance."
   371      Subclasses may redefine this for better performance."
   254 
   372 
   264     "Modified: / 5.3.1998 / 14:57:48 / stefan"
   382     "Modified: / 5.3.1998 / 14:57:48 / stefan"
   265 !
   383 !
   266 
   384 
   267 doubleWordAt:index put:aNumber MSB:msb
   385 doubleWordAt:index put:aNumber MSB:msb
   268     "set the 4-bytes starting at index from the (unsigned) Integer value.
   386     "set the 4-bytes starting at index from the (unsigned) Integer value.
       
   387      The index is a smalltalk index (i.e. 1-based).
   269      The value must be in the range 0 to 16rFFFFFFFF.
   388      The value must be in the range 0 to 16rFFFFFFFF.
   270      The value is stored MSB-first if msb is true; LSB-first otherwise.
   389      The value is stored MSB-first if msb is true; LSB-first otherwise.
   271      Subclasses may redefine this for better performance."
   390      Subclasses may redefine this for better performance."
   272 
   391 
   273     |i "{ Class: SmallInteger }" |
   392     |i "{ Class: SmallInteger }" |
   352     "Created: / 21.1.1998 / 17:44:19 / cg"
   471     "Created: / 21.1.1998 / 17:44:19 / cg"
   353 !
   472 !
   354 
   473 
   355 floatAt:index
   474 floatAt:index
   356     "return the 4-bytes starting at index as a Float.
   475     "return the 4-bytes starting at index as a Float.
       
   476      The index is a smalltalk index (i.e. 1-based).
   357      Notice, that (currently) ST/X Floats are what Doubles are in ST-80;
   477      Notice, that (currently) ST/X Floats are what Doubles are in ST-80;
   358      therefore this method reads a 4-byte float from the byteArray and returns
   478      therefore this method reads a 4-byte float from the byteArray and returns
   359      a float object which keeps an 8-byte double internally.
   479      a float object which keeps an 8-byte double internally.
   360      Notice also, that the bytes are expected to be in this machines
   480      Notice also, that the bytes are expected to be in this machines
   361      float representation and order - if the bytearray originated from another
   481      float representation and order - if the bytearray originated from another
   371 !
   491 !
   372 
   492 
   373 floatAt:index put:aFloat
   493 floatAt:index put:aFloat
   374     "store the 4 bytes of value of the argument, aFloat into the receiver
   494     "store the 4 bytes of value of the argument, aFloat into the receiver
   375      starting at index.
   495      starting at index.
       
   496      The index is a smalltalk index (i.e. 1-based).
   376      Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
   497      Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
   377      Notice also, that the bytes are expected to be in this machines
   498      Notice also, that the bytes are expected to be in this machines
   378      float representation - if the bytearray originated from another
   499      float representation - if the bytearray originated from another
   379      machine, some conversion is usually needed."
   500      machine, some conversion is usually needed."
   380 
   501 
   387     ^ aFloat
   508     ^ aFloat
   388 !
   509 !
   389 
   510 
   390 ieeeDoubleAt:index
   511 ieeeDoubleAt:index
   391     "retrieve the 8 bytes starting at index as a float.
   512     "retrieve the 8 bytes starting at index as a float.
       
   513      The index is a smalltalk index (i.e. 1-based).
   392      The 8 bytes are assumed to be in IEEE floating point single precision
   514      The 8 bytes are assumed to be in IEEE floating point single precision
   393      number format."
   515      number format."
   394 
   516 
   395     "
   517     "
   396      currently, we assume that the machines native number format is already
   518      currently, we assume that the machines native number format is already
   397      IEEE format - we need some more code here whenever ST/X is ported
   519      IEEE format - we need some more code here whenever ST/X is ported
   398      to an IBM 370 or old VAX etc.
   520      to an IBM 370 or old VAX etc.
   399      To date, all supported systems use IEEE float numbers, so there should be
   521      To date, all supported systems use IEEE float numbers, so there should be
   400      no problem.
   522      no problem.
   401     "
   523     "
       
   524     self isIEEEFormat ifFalse:[self error:'unsupported operation'].
       
   525 
   402     ^ self doubleAt:index
   526     ^ self doubleAt:index
   403 
   527 
   404     "Created: / 5.3.1998 / 10:50:03 / stefan"
   528     "Created: / 5.3.1998 / 10:50:03 / stefan"
   405 !
   529 !
   406 
   530 
   407 ieeeDoubleAt:index put:aFloat
   531 ieeeDoubleAt:index put:aFloat
   408     "store the value of the argument, aFloat into the receiver
   532     "store the value of the argument, aFloat into the receiver
       
   533      The index is a smalltalk index (i.e. 1-based).
   409      starting at index. Storage is in IEEE floating point double precision format.
   534      starting at index. Storage is in IEEE floating point double precision format.
   410      (i.e. 8 bytes are stored)."
   535      (i.e. 8 bytes are stored)."
   411 
   536 
   412     "
   537     "
   413      currently, we assume that the machines native number format is already
   538      currently, we assume that the machines native number format is already
   414      IEEE format - we need some more code here whenever ST/X is ported
   539      IEEE format - we need some more code here whenever ST/X is ported
   415      to an IBM 370 or old VAX etc.
   540      to an IBM 370 or old VAX etc.
   416      To date, all supported systems use IEEE float numbers, so there should be
   541      To date, all supported systems use IEEE float numbers, so there should be
   417      no problem.
   542      no problem.
   418     "
   543     "
       
   544     self isIEEEFormat ifFalse:[self error:'unsupported operation'].
       
   545 
   419     ^ self doubleAt:index put:aFloat
   546     ^ self doubleAt:index put:aFloat
   420 
   547 
   421     "Created: / 5.3.1998 / 10:50:26 / stefan"
   548     "Created: / 5.3.1998 / 10:50:26 / stefan"
   422 !
   549 !
   423 
   550 
   424 ieeeFloatAt:index
   551 ieeeFloatAt:index
   425     "retrieve the 4 bytes starting at index as a float.
   552     "retrieve the 4 bytes starting at index as a float.
       
   553      The index is a smalltalk index (i.e. 1-based).
   426      The 4 bytes are assumed to be in IEEE floating point single precision
   554      The 4 bytes are assumed to be in IEEE floating point single precision
   427      number format."
   555      number format."
   428 
   556 
   429     "
   557     "
   430      currently, we assume that the machines native number format is already
   558      currently, we assume that the machines native number format is already
   431      IEEE format - we need some more code here whenever ST/X is ported
   559      IEEE format - we need some more code here whenever ST/X is ported
   432      to an IBM 370 or old VAX etc.
   560      to an IBM 370 or old VAX etc.
   433      To date, all supported systems use IEEE float numbers, so there should be
   561      To date, all supported systems use IEEE float numbers, so there should be
   434      no problem.
   562      no problem.
   435     "
   563     "
       
   564     self isIEEEFormat ifFalse:[self error:'unsupported operation'].
       
   565 
   436     ^ self floatAt:index
   566     ^ self floatAt:index
   437 
   567 
   438     "Created: / 5.3.1998 / 10:50:45 / stefan"
   568     "Created: / 5.3.1998 / 10:50:45 / stefan"
   439 !
   569 !
   440 
   570 
   441 ieeeFloatAt:index put:aFloat
   571 ieeeFloatAt:index put:aFloat
   442     "store the value of the argument, aFloat into the receiver
   572     "store the value of the argument, aFloat into the receiver
   443      starting at index. Storage is in IEEE floating point single precision format.
   573      starting at index, which is a smalltalk index (i.e. 1-based). 
       
   574      Storage is in IEEE floating point single precision format.
   444      (i.e. 4 bytes are stored). Since ST/X floats are really doubles, the low-
   575      (i.e. 4 bytes are stored). Since ST/X floats are really doubles, the low-
   445      order 4 bytes of the precision is lost."
   576      order 4 bytes of the precision is lost."
   446 
   577 
   447     "
   578     "
   448      currently, we assume that the machines native number format is already
   579      currently, we assume that the machines native number format is already
   449      IEEE format - we need some more code here whenever ST/X is ported
   580      IEEE format - we need some more code here whenever ST/X is ported
   450      to an IBM 370 or old VAX etc.
   581      to an IBM 370 or old VAX etc.
   451      To date, all supported systems use IEEE float numbers, so there should be
   582      To date, all supported systems use IEEE float numbers, so there should be
   452      no problem.
   583      no problem.
   453     "
   584     "
       
   585     self isIEEEFormat ifFalse:[self error:'unsupported operation'].
       
   586 
   454     ^ self floatAt:index put:aFloat
   587     ^ self floatAt:index put:aFloat
   455 
   588 
   456     "Created: / 5.3.1998 / 10:51:11 / stefan"
   589     "Created: / 5.3.1998 / 10:51:11 / stefan"
   457 !
   590 !
   458 
   591 
   459 longAt:index
   592 longAt:index
   460     "return the 4-bytes starting at index as a signed Integer.
   593     "return the 4-bytes starting at index as a signed Integer.
       
   594      The index is a smalltalk index (i.e. 1-based).
   461      The value is retrieved in the machines natural byte order.
   595      The value is retrieved in the machines natural byte order.
   462      This may be worth a primitive."
   596      This may be worth a primitive."
   463 
   597 
   464     |w|
   598     |w|
   465 
   599 
   480     "Modified: / 5.3.1998 / 12:06:28 / stefan"
   614     "Modified: / 5.3.1998 / 12:06:28 / stefan"
   481 !
   615 !
   482 
   616 
   483 longAt:index bigEndian:msb
   617 longAt:index bigEndian:msb
   484     "return the 4-bytes starting at index as a signed Integer.
   618     "return the 4-bytes starting at index as a signed Integer.
       
   619      The index is a smalltalk index (i.e. 1-based).
   485      Depending on msb, the value is retrieved MSB-first or LSB-first.
   620      Depending on msb, the value is retrieved MSB-first or LSB-first.
   486      This may be worth a primitive."
   621      This may be worth a primitive."
   487 
   622 
   488     |w|
   623     |w|
   489 
   624 
   504     "Created: / 5.3.1998 / 14:02:03 / stefan"
   639     "Created: / 5.3.1998 / 14:02:03 / stefan"
   505 !
   640 !
   506 
   641 
   507 longAt:index put:value
   642 longAt:index put:value
   508     "set the 4-bytes starting at index from the signed Integer value.
   643     "set the 4-bytes starting at index from the signed Integer value.
       
   644      The index is a smalltalk index (i.e. 1-based).
   509      The value is stored in the machines natural byte order.
   645      The value is stored in the machines natural byte order.
   510      This may be worth a primitive.
   646      This may be worth a primitive.
   511 
   647 
   512      This is the ST80 version of #signedDoubleWordAt:put:"
   648      This is the ST80 version of #signedDoubleWordAt:put:"
   513 
   649 
   532     "Created: / 5.3.1998 / 10:57:18 / stefan"
   668     "Created: / 5.3.1998 / 10:57:18 / stefan"
   533 !
   669 !
   534 
   670 
   535 longLongAt:index
   671 longLongAt:index
   536     "return the 4-bytes starting at index as a signed Integer.
   672     "return the 4-bytes starting at index as a signed Integer.
       
   673      The index is a smalltalk index (i.e. 1-based).
   537      The value is retrieved in the machines natural byte order.
   674      The value is retrieved in the machines natural byte order.
   538      This may be worth a primitive."
   675      This may be worth a primitive."
   539 
   676 
   540     |w|
   677     |w|
   541 
   678 
   557     "Modified: / 5.3.1998 / 14:58:32 / stefan"
   694     "Modified: / 5.3.1998 / 14:58:32 / stefan"
   558 !
   695 !
   559 
   696 
   560 longLongAt:index bigEndian:msb
   697 longLongAt:index bigEndian:msb
   561     "return the 4-bytes starting at index as a signed Integer.
   698     "return the 4-bytes starting at index as a signed Integer.
       
   699      The index is a smalltalk index (i.e. 1-based).
   562      The value is retrieved in the machines natural byte order.
   700      The value is retrieved in the machines natural byte order.
   563      This may be worth a primitive."
   701      This may be worth a primitive."
   564 
   702 
   565     |w|
   703     |w|
   566 
   704 
   582     "Created: / 5.3.1998 / 14:40:54 / stefan"
   720     "Created: / 5.3.1998 / 14:40:54 / stefan"
   583 !
   721 !
   584 
   722 
   585 longLongAt:byteIndex put:anInteger
   723 longLongAt:byteIndex put:anInteger
   586     "store a signed longLong (64bit) integer.
   724     "store a signed longLong (64bit) integer.
       
   725      The index is a smalltalk index (i.e. 1-based).
   587      Same as #signedQuadWordAt:put: - for ST80 compatibility."
   726      Same as #signedQuadWordAt:put: - for ST80 compatibility."
   588 
   727 
   589     ^ self signedQuadWordAt:byteIndex put:anInteger
   728     ^ self signedQuadWordAt:byteIndex put:anInteger
   590 
   729 
   591     "Modified: / 3.4.1998 / 13:33:14 / cg"
   730     "Modified: / 3.4.1998 / 13:33:14 / cg"
   592     "Created: / 3.4.1998 / 13:34:22 / cg"
   731     "Created: / 3.4.1998 / 13:34:22 / cg"
   593 !
   732 !
   594 
   733 
   595 quadWordAt:index MSB:msb
   734 quadWordAt:index MSB:msb
   596     "return the 8-bytes starting at index as an (unsigned) Integer.
   735     "return the 8-bytes starting at index as an (unsigned) Integer.
       
   736      The index is a smalltalk index (i.e. 1-based).
   597      Depending on msb, the value is retrieved MSB or LSB-first."
   737      Depending on msb, the value is retrieved MSB or LSB-first."
   598 
   738 
   599     |l 
   739     |l 
   600      bIdx  "{ Class: SmallInteger }"
   740      bIdx  "{ Class: SmallInteger }"
   601      delta "{ Class: SmallInteger }"|
   741      delta "{ Class: SmallInteger }"|
   624     "Modified: 5.11.1996 / 14:06:21 / cg"
   764     "Modified: 5.11.1996 / 14:06:21 / cg"
   625 !
   765 !
   626 
   766 
   627 quadWordAt:index put:anInteger MSB:msb
   767 quadWordAt:index put:anInteger MSB:msb
   628     "set the 8-bytes starting at index from the (unsigned) Integer value.
   768     "set the 8-bytes starting at index from the (unsigned) Integer value.
       
   769      The index is a smalltalk index (i.e. 1-based).
   629      The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
   770      The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
   630      Depending on msb, the value is stored MSB-first or LSB-first."
   771      Depending on msb, the value is stored MSB-first or LSB-first."
   631 
   772 
   632     |bIdx  "{ Class: SmallInteger }"
   773     |bIdx  "{ Class: SmallInteger }"
   633      delta "{ Class: SmallInteger }"|
   774      delta "{ Class: SmallInteger }"|
   657     "
   798     "
   658 !
   799 !
   659 
   800 
   660 shortAt:index
   801 shortAt:index
   661     "return the 2-bytes starting at index as a signed Integer.
   802     "return the 2-bytes starting at index as a signed Integer.
       
   803      The index is a smalltalk index (i.e. 1-based).
   662      The value is retrieved in the machines natural byte order.
   804      The value is retrieved in the machines natural byte order.
   663      This may be worth a primitive.
   805      This may be worth a primitive.
   664      This is the ST80 equivalent of #signedWordAt:"
   806      This is the ST80 equivalent of #signedWordAt:"
   665 
   807 
   666     ^ (self unsignedShortAt:index) signExtendedShortValue
   808     ^ (self unsignedShortAt:index) signExtendedShortValue
   677     "Modified: / 5.3.1998 / 23:39:38 / stefan"
   819     "Modified: / 5.3.1998 / 23:39:38 / stefan"
   678 !
   820 !
   679 
   821 
   680 shortAt:index bigEndian:msb
   822 shortAt:index bigEndian:msb
   681     "return the 2-bytes starting at index as a signed Integer.
   823     "return the 2-bytes starting at index as a signed Integer.
       
   824      The index is a smalltalk index (i.e. 1-based).
   682      The value is retrieved MSB-first, if the msb-arg is true;
   825      The value is retrieved MSB-first, if the msb-arg is true;
   683      LSB-first otherwise.
   826      LSB-first otherwise.
   684      This is the ST80 equivalent of #signedWordAt:"
   827      This is the ST80 equivalent of #signedWordAt:"
   685 
   828 
   686     ^ (self unsignedShortAt:index bigEndian:msb) signExtendedShortValue
   829     ^ (self unsignedShortAt:index bigEndian:msb) signExtendedShortValue
   696     "Created: / 5.3.1998 / 23:41:21 / stefan"
   839     "Created: / 5.3.1998 / 23:41:21 / stefan"
   697 !
   840 !
   698 
   841 
   699 shortAt:index put:value
   842 shortAt:index put:value
   700     "set the 2-bytes starting at index from the signed Integer value.
   843     "set the 2-bytes starting at index from the signed Integer value.
       
   844      The index is a smalltalk index (i.e. 1-based).
   701      The stored value must be in the range -32768 .. +32676.
   845      The stored value must be in the range -32768 .. +32676.
   702      The value is stored in the machines natural byteorder.
   846      The value is stored in the machines natural byteorder.
   703      This may be worth a primitive.
   847      This may be worth a primitive.
   704      This is the ST80 equivalent of #signedWordAt:put:"
   848      This is the ST80 equivalent of #signedWordAt:put:"
   705 
   849 
   727     "Created: / 5.3.1998 / 11:02:05 / stefan"
   871     "Created: / 5.3.1998 / 11:02:05 / stefan"
   728 !
   872 !
   729 
   873 
   730 signedByteAt:index
   874 signedByteAt:index
   731     "return the byte at index as a signed 8 bit value.
   875     "return the byte at index as a signed 8 bit value.
       
   876      The index is a smalltalk index (i.e. 1-based).
   732      This may be worth a primitive."
   877      This may be worth a primitive."
   733 
   878 
   734     ^ (self at:index) signExtendedByteValue
   879     ^ (self at:index) signExtendedByteValue
   735 
   880 
   736     "
   881     "
   744     "Modified: 1.7.1996 / 21:13:53 / cg"
   889     "Modified: 1.7.1996 / 21:13:53 / cg"
   745 !
   890 !
   746 
   891 
   747 signedByteAt:index put:aSignedByteValue
   892 signedByteAt:index put:aSignedByteValue
   748     "return the byte at index as a signed 8 bit value.
   893     "return the byte at index as a signed 8 bit value.
       
   894      The index is a smalltalk index (i.e. 1-based).
   749      Return the signedByteValue argument.
   895      Return the signedByteValue argument.
   750      This may be worth a primitive."
   896      This may be worth a primitive."
   751 
   897 
   752     |b "{ Class: SmallInteger }"|
   898     |b "{ Class: SmallInteger }"|
   753 
   899 
   769     "Modified: 1.7.1996 / 21:12:37 / cg"
   915     "Modified: 1.7.1996 / 21:12:37 / cg"
   770 !
   916 !
   771 
   917 
   772 signedDoubleWordAt:index
   918 signedDoubleWordAt:index
   773     "return the 4-bytes starting at index as a signed Integer.
   919     "return the 4-bytes starting at index as a signed Integer.
       
   920      The index is a smalltalk index (i.e. 1-based).
   774      The value is retrieved in the machines natural byte order.
   921      The value is retrieved in the machines natural byte order.
   775      This may be worth a primitive."
   922      This may be worth a primitive."
   776 
   923 
   777     |w|
   924     |w|
   778 
   925 
   792     "Modified: 1.7.1996 / 21:11:28 / cg"
   939     "Modified: 1.7.1996 / 21:11:28 / cg"
   793 !
   940 !
   794 
   941 
   795 signedDoubleWordAt:index MSB:msb
   942 signedDoubleWordAt:index MSB:msb
   796     "return the 4-bytes starting at index as a signed Integer.
   943     "return the 4-bytes starting at index as a signed Integer.
       
   944      The index is a smalltalk index (i.e. 1-based).
   797      Depending on msb, the value is retrieved MSB-first or LSB-first.
   945      Depending on msb, the value is retrieved MSB-first or LSB-first.
   798      This may be worth a primitive."
   946      This may be worth a primitive."
   799 
   947 
   800     |w|
   948     |w|
   801 
   949 
   815     "Modified: 1.7.1996 / 21:11:33 / cg"
   963     "Modified: 1.7.1996 / 21:11:33 / cg"
   816 !
   964 !
   817 
   965 
   818 signedDoubleWordAt:index put:value
   966 signedDoubleWordAt:index put:value
   819     "set the 4-bytes starting at index from the signed Integer value.
   967     "set the 4-bytes starting at index from the signed Integer value.
       
   968      The index is a smalltalk index (i.e. 1-based).
   820      The value is stored in the machines natural byte order.
   969      The value is stored in the machines natural byte order.
   821      This may be worth a primitive."
   970      This may be worth a primitive."
   822 
   971 
   823     |v|
   972     |v|
   824 
   973 
   840     "Modified: 1.7.1996 / 21:11:39 / cg"
   989     "Modified: 1.7.1996 / 21:11:39 / cg"
   841 !
   990 !
   842 
   991 
   843 signedDoubleWordAt:index put:value MSB:msb
   992 signedDoubleWordAt:index put:value MSB:msb
   844     "set the 4-bytes starting at index from the signed Integer value.
   993     "set the 4-bytes starting at index from the signed Integer value.
       
   994      The index is a smalltalk index (i.e. 1-based).
   845      Depending on msb, the value is stored MSB-first or LSB-first.
   995      Depending on msb, the value is stored MSB-first or LSB-first.
   846      This may be worth a primitive."
   996      This may be worth a primitive."
   847 
   997 
   848     |v|
   998     |v|
   849 
   999 
   865     "Modified: 1.7.1996 / 21:11:46 / cg"
  1015     "Modified: 1.7.1996 / 21:11:46 / cg"
   866 !
  1016 !
   867 
  1017 
   868 signedWordAt:index
  1018 signedWordAt:index
   869     "return the 2-bytes starting at index as a signed Integer.
  1019     "return the 2-bytes starting at index as a signed Integer.
       
  1020      The index is a smalltalk index (i.e. 1-based).
   870      The value is retrieved in the machines natural byte order.
  1021      The value is retrieved in the machines natural byte order.
   871      This may be worth a primitive."
  1022      This may be worth a primitive."
   872 
  1023 
   873     ^ (self wordAt:index) signExtendedShortValue
  1024     ^ (self wordAt:index) signExtendedShortValue
   874 
  1025 
   882     "Modified: 1.7.1996 / 21:14:38 / cg"
  1033     "Modified: 1.7.1996 / 21:14:38 / cg"
   883 !
  1034 !
   884 
  1035 
   885 signedWordAt:index MSB:msb
  1036 signedWordAt:index MSB:msb
   886     "return the 2-bytes starting at index as a signed Integer.
  1037     "return the 2-bytes starting at index as a signed Integer.
       
  1038      The index is a smalltalk index (i.e. 1-based).
   887      The value is retrieved MSB-first if the msb-arg is true,
  1039      The value is retrieved MSB-first if the msb-arg is true,
   888      LSB-first otherwise.
  1040      LSB-first otherwise.
   889      This may be worth a primitive."
  1041      This may be worth a primitive."
   890 
  1042 
   891     ^ (self wordAt:index MSB:msb) signExtendedShortValue
  1043     ^ (self wordAt:index MSB:msb) signExtendedShortValue
   901     "Modified: 1.7.1996 / 21:15:57 / cg"
  1053     "Modified: 1.7.1996 / 21:15:57 / cg"
   902 !
  1054 !
   903 
  1055 
   904 signedWordAt:index put:value
  1056 signedWordAt:index put:value
   905     "set the 2-bytes starting at index from the signed Integer value.
  1057     "set the 2-bytes starting at index from the signed Integer value.
       
  1058      The index is a smalltalk index (i.e. 1-based).
   906      The stored value must be in the range -32768 .. +32676.
  1059      The stored value must be in the range -32768 .. +32676.
   907      The value is stored in the machines natural byteorder.
  1060      The value is stored in the machines natural byteorder.
   908      This may be worth a primitive.
  1061      This may be worth a primitive.
   909      This is the ST80 equivalent of #signedWordAt:put:"
  1062      This is the ST80 equivalent of #signedWordAt:put:"
   910 
  1063 
   932     "Modified: / 5.3.1998 / 11:01:30 / stefan"
  1085     "Modified: / 5.3.1998 / 11:01:30 / stefan"
   933 !
  1086 !
   934 
  1087 
   935 signedWordAt:index put:value MSB:msb
  1088 signedWordAt:index put:value MSB:msb
   936     "set the 2-bytes starting at index from the signed Integer value.
  1089     "set the 2-bytes starting at index from the signed Integer value.
       
  1090      The index is a smalltalk index (i.e. 1-based).
   937      The stored value must be in the range -32768 .. +32676.
  1091      The stored value must be in the range -32768 .. +32676.
   938      The value is stored MSB-first, if the msb-arg is true;
  1092      The value is stored MSB-first, if the msb-arg is true;
   939      LSB-first otherwise.
  1093      LSB-first otherwise.
   940      This may be worth a primitive."
  1094      This may be worth a primitive."
   941 
  1095 
   959 
  1113 
   960     "Modified: 1.7.1996 / 21:12:13 / cg"
  1114     "Modified: 1.7.1996 / 21:12:13 / cg"
   961 !
  1115 !
   962 
  1116 
   963 stringAt:index
  1117 stringAt:index
   964     "return a string starting at index up to the 0-byte"
  1118     "return a string starting at index up to the 0-byte.
       
  1119      The index is a smalltalk index (i.e. 1-based)."
   965 
  1120 
   966     |stream i "{ Class: SmallInteger }" c|
  1121     |stream i "{ Class: SmallInteger }" c|
   967 
  1122 
   968     stream := WriteStream on:''.
  1123     stream := WriteStream on:''.
   969     i := index.
  1124     i := index.
   976     "Created: / 21.1.1998 / 17:44:50 / cg"
  1131     "Created: / 21.1.1998 / 17:44:50 / cg"
   977 !
  1132 !
   978 
  1133 
   979 stringAt:index put:aString
  1134 stringAt:index put:aString
   980     "copy aString to the externalBytes, starting at index up to
  1135     "copy aString to the externalBytes, starting at index up to
   981      (and including) the 0-byte"
  1136      (and including) the 0-byte.
       
  1137      The index is a smalltalk index (i.e. 1-based)."
   982 
  1138 
   983     |i "{ Class: SmallInteger }"|
  1139     |i "{ Class: SmallInteger }"|
   984 
  1140 
   985     i := index.
  1141     i := index.
   986     aString do:[:aChar |
  1142     aString do:[:aChar |
  1002 
  1158 
  1003     "Created: / 21.1.1998 / 17:45:02 / cg"
  1159     "Created: / 21.1.1998 / 17:45:02 / cg"
  1004 !
  1160 !
  1005 
  1161 
  1006 stringAt:index size:maxSize
  1162 stringAt:index size:maxSize
  1007     "return a string starting at index up to maxSize, or a 0-byte"
  1163     "return a string starting at index up to maxSize, or a 0-byte.
       
  1164      The index is a smalltalk index (i.e. 1-based)."
  1008 
  1165 
  1009     |stream c i "{ Class: SmallInteger }"|
  1166     |stream c i "{ Class: SmallInteger }"|
  1010 
  1167 
  1011     stream := WriteStream on:(String new:maxSize).
  1168     stream := WriteStream on:(String new:maxSize).
  1012     i := index.
  1169     i := index.
  1020     "Modified: / 21.1.1998 / 17:45:23 / cg"
  1177     "Modified: / 21.1.1998 / 17:45:23 / cg"
  1021 !
  1178 !
  1022 
  1179 
  1023 unsignedLongAt:index
  1180 unsignedLongAt:index
  1024     "return the 4-bytes starting at index as an (unsigned) Integer.
  1181     "return the 4-bytes starting at index as an (unsigned) Integer.
       
  1182      The index is a smalltalk index (i.e. 1-based).
  1025      The value is retrieved in the machines natural byte order.
  1183      The value is retrieved in the machines natural byte order.
  1026      Subclasses may redefine this for better performance."
  1184      Subclasses may redefine this for better performance."
  1027 
  1185 
  1028     ^ self unsignedLongAt:index bigEndian:IsBigEndian
  1186     ^ self unsignedLongAt:index bigEndian:IsBigEndian
  1029 
  1187 
  1038     "Modified: / 5.3.1998 / 14:58:48 / stefan"
  1196     "Modified: / 5.3.1998 / 14:58:48 / stefan"
  1039 !
  1197 !
  1040 
  1198 
  1041 unsignedLongAt:index bigEndian:msb
  1199 unsignedLongAt:index bigEndian:msb
  1042     "return the 4-bytes starting at index as an (unsigned) Integer.
  1200     "return the 4-bytes starting at index as an (unsigned) Integer.
       
  1201      The index is a smalltalk index (i.e. 1-based).
  1043      The value is retrieved MSB-first, if the msb-arg is true;
  1202      The value is retrieved MSB-first, if the msb-arg is true;
  1044      LSB-first otherwise.
  1203      LSB-first otherwise.
  1045      Subclasses may redefine this for better performance."
  1204      Subclasses may redefine this for better performance."
  1046 
  1205 
  1047     |val 
  1206     |val 
  1083     "Created: / 5.3.1998 / 11:46:05 / stefan"
  1242     "Created: / 5.3.1998 / 11:46:05 / stefan"
  1084 !
  1243 !
  1085 
  1244 
  1086 unsignedLongAt:index put:value
  1245 unsignedLongAt:index put:value
  1087     "set the 4-bytes starting at index from the (unsigned) Integer value.
  1246     "set the 4-bytes starting at index from the (unsigned) Integer value.
       
  1247      The index is a smalltalk index (i.e. 1-based).
  1088      The value should be in the range 0 to 16rFFFFFFFF
  1248      The value should be in the range 0 to 16rFFFFFFFF
  1089      (for negative values, the stored value is not defined).
  1249      (for negative values, the stored value is not defined).
  1090      The value is stored in the machines natural byte order.
  1250      The value is stored in the machines natural byte order.
  1091      Subclasses may redefine this for better performance."
  1251      Subclasses may redefine this for better performance."
  1092 
  1252 
  1103     "Modified: / 5.3.1998 / 14:58:59 / stefan"
  1263     "Modified: / 5.3.1998 / 14:58:59 / stefan"
  1104 !
  1264 !
  1105 
  1265 
  1106 unsignedLongAt:index put:aNumber bigEndian:msb
  1266 unsignedLongAt:index put:aNumber bigEndian:msb
  1107     "set the 4-bytes starting at index from the (unsigned) Integer value.
  1267     "set the 4-bytes starting at index from the (unsigned) Integer value.
       
  1268      The index is a smalltalk index (i.e. 1-based).
  1108      The value must be in the range 0 to 16rFFFFFFFF.
  1269      The value must be in the range 0 to 16rFFFFFFFF.
  1109      The value is stored MSB-first if msb is true; LSB-first otherwise.
  1270      The value is stored MSB-first if msb is true; LSB-first otherwise.
  1110      Subclasses may redefine this for better performance."
  1271      Subclasses may redefine this for better performance."
  1111 
  1272 
  1112     |i "{ Class: SmallInteger }" |
  1273     |i "{ Class: SmallInteger }" |
  1141     "Modified: / 5.3.1998 / 11:47:30 / stefan"
  1302     "Modified: / 5.3.1998 / 11:47:30 / stefan"
  1142 !
  1303 !
  1143 
  1304 
  1144 unsignedLongLongAt:index bigEndian:msb
  1305 unsignedLongLongAt:index bigEndian:msb
  1145     "return the 8-bytes starting at index as an (unsigned) Integer.
  1306     "return the 8-bytes starting at index as an (unsigned) Integer.
       
  1307      The index is a smalltalk index (i.e. 1-based).
  1146      Depending on msb, the value is retrieved MSB or LSB-first."
  1308      Depending on msb, the value is retrieved MSB or LSB-first."
  1147 
  1309 
  1148     |l 
  1310     |l 
  1149      bIdx  "{ Class: SmallInteger }"
  1311      bIdx  "{ Class: SmallInteger }"
  1150      delta "{ Class: SmallInteger }"|
  1312      delta "{ Class: SmallInteger }"|
  1174     "Modified: / 5.3.1998 / 14:04:44 / stefan"
  1336     "Modified: / 5.3.1998 / 14:04:44 / stefan"
  1175 !
  1337 !
  1176 
  1338 
  1177 unsignedLongLongAt:index put:anInteger
  1339 unsignedLongLongAt:index put:anInteger
  1178     "set the 8-bytes starting at index from the (unsigned) Integer value.
  1340     "set the 8-bytes starting at index from the (unsigned) Integer value.
       
  1341      The index is a smalltalk index (i.e. 1-based).
  1179      The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
  1342      The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
  1180      The value is stored in natural byte order."
  1343      The value is stored in natural byte order."
  1181 
  1344 
  1182     ^ self unsignedLongLongAt:index put:anInteger bigEndian:IsBigEndian
  1345     ^ self unsignedLongLongAt:index put:anInteger bigEndian:IsBigEndian
  1183 
  1346 
  1185     "Modified: / 5.3.1998 / 15:02:32 / stefan"
  1348     "Modified: / 5.3.1998 / 15:02:32 / stefan"
  1186 !
  1349 !
  1187 
  1350 
  1188 unsignedLongLongAt:index put:anInteger bigEndian:msb
  1351 unsignedLongLongAt:index put:anInteger bigEndian:msb
  1189     "set the 8-bytes starting at index from the (unsigned) Integer value.
  1352     "set the 8-bytes starting at index from the (unsigned) Integer value.
       
  1353      The index is a smalltalk index (i.e. 1-based).
  1190      The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
  1354      The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
  1191      Depending on msb, the value is stored MSB-first or LSB-first."
  1355      Depending on msb, the value is stored MSB-first or LSB-first."
  1192 
  1356 
  1193     |bIdx  "{ Class: SmallInteger }"
  1357     |bIdx  "{ Class: SmallInteger }"
  1194      delta "{ Class: SmallInteger }"|
  1358      delta "{ Class: SmallInteger }"|
  1220     "Created: / 5.3.1998 / 14:06:02 / stefan"
  1384     "Created: / 5.3.1998 / 14:06:02 / stefan"
  1221 !
  1385 !
  1222 
  1386 
  1223 unsignedShortAt:index
  1387 unsignedShortAt:index
  1224     "return the 2-bytes starting at index as an (unsigned) Integer.
  1388     "return the 2-bytes starting at index as an (unsigned) Integer.
       
  1389      The index is a smalltalk index (i.e. 1-based).
  1225      The value is retrieved in the machines natural byte order
  1390      The value is retrieved in the machines natural byte order
  1226      Subclasses may redefine this for better performance.
  1391      Subclasses may redefine this for better performance.
  1227      This is the ST80 equivalent of #wordAt:"
  1392      This is the ST80 equivalent of #wordAt:"
  1228 
  1393 
  1229 
  1394 
  1233     "Modified: / 5.3.1998 / 14:59:25 / stefan"
  1398     "Modified: / 5.3.1998 / 14:59:25 / stefan"
  1234 !
  1399 !
  1235 
  1400 
  1236 unsignedShortAt:index bigEndian:msb
  1401 unsignedShortAt:index bigEndian:msb
  1237     "return the 2-bytes starting at index as an (unsigned) Integer.
  1402     "return the 2-bytes starting at index as an (unsigned) Integer.
       
  1403      The index is a smalltalk index (i.e. 1-based).
  1238      The value is retrieved MSB-first (high 8 bits at lower index) if msb is true;
  1404      The value is retrieved MSB-first (high 8 bits at lower index) if msb is true;
  1239      LSB-first (i.e. low 8-bits at lower byte index) if its false)"
  1405      LSB-first (i.e. low 8-bits at lower byte index) if its false)"
  1240 
  1406 
  1241     |b1 "{ Class: SmallInteger }" 
  1407     |b1 "{ Class: SmallInteger }" 
  1242      b2 "{ Class: SmallInteger }"|
  1408      b2 "{ Class: SmallInteger }"|
  1252     "Created: / 5.3.1998 / 11:49:29 / stefan"
  1418     "Created: / 5.3.1998 / 11:49:29 / stefan"
  1253 !
  1419 !
  1254 
  1420 
  1255 unsignedShortAt:index put:value
  1421 unsignedShortAt:index put:value
  1256     "set the 2-bytes starting at index from the (unsigned) Integer value.
  1422     "set the 2-bytes starting at index from the (unsigned) Integer value.
       
  1423      The index is a smalltalk index (i.e. 1-based).
  1257      The stored value must be in the range 0 .. 16rFFFF. 
  1424      The stored value must be in the range 0 .. 16rFFFF. 
  1258      The value is stored in the machines natural byteorder."
  1425      The value is stored in the machines natural byteorder."
  1259 
  1426 
  1260     ^ self unsignedShortAt:index put:value bigEndian:IsBigEndian
  1427     ^ self unsignedShortAt:index put:value bigEndian:IsBigEndian
  1261 
  1428 
  1271     "Modified: / 5.3.1998 / 14:59:38 / stefan"
  1438     "Modified: / 5.3.1998 / 14:59:38 / stefan"
  1272 !
  1439 !
  1273 
  1440 
  1274 unsignedShortAt:index put:value bigEndian:msb
  1441 unsignedShortAt:index put:value bigEndian:msb
  1275     "set the 2-bytes starting at index from the (unsigned) Integer value.
  1442     "set the 2-bytes starting at index from the (unsigned) Integer value.
       
  1443      The index is a smalltalk index (i.e. 1-based).
  1276      The stored value must be in the range 0 .. 16rFFFF. 
  1444      The stored value must be in the range 0 .. 16rFFFF. 
  1277      The value is stored LSB-first (i.e. the low 8bits are stored at the
  1445      The value is stored LSB-first (i.e. the low 8bits are stored at the
  1278      lower index) if msb is false, MSB-first otherwise"
  1446      lower index) if msb is false, MSB-first otherwise"
  1279 
  1447 
  1280     |b1 b2
  1448     |b1 b2
  1309     "Modified: / 5.3.1998 / 11:52:28 / stefan"
  1477     "Modified: / 5.3.1998 / 11:52:28 / stefan"
  1310 !
  1478 !
  1311 
  1479 
  1312 wordAt:index
  1480 wordAt:index
  1313     "return the 2-bytes starting at index as an (unsigned) Integer.
  1481     "return the 2-bytes starting at index as an (unsigned) Integer.
       
  1482      The index is a smalltalk index (i.e. 1-based).
  1314      The value is retrieved in the machines natural byte order
  1483      The value is retrieved in the machines natural byte order
  1315      Subclasses may redefine this for better performance."
  1484      Subclasses may redefine this for better performance."
  1316 
  1485 
  1317     ^ self wordAt:index MSB:IsBigEndian
  1486     ^ self wordAt:index MSB:IsBigEndian
  1318 
  1487 
  1319     "Modified: / 5.3.1998 / 14:59:51 / stefan"
  1488     "Modified: / 5.3.1998 / 14:59:51 / stefan"
  1320 !
  1489 !
  1321 
  1490 
  1322 wordAt:index MSB:msb
  1491 wordAt:index MSB:msb
  1323     "return the 2-bytes starting at index as an (unsigned) Integer.
  1492     "return the 2-bytes starting at index as an (unsigned) Integer.
       
  1493      The index is a smalltalk index (i.e. 1-based).
  1324      The value is retrieved MSB (high 8 bits at lower index) if msb is true;
  1494      The value is retrieved MSB (high 8 bits at lower index) if msb is true;
  1325      LSB-first (i.e. low 8-bits at lower byte index) if its false.
  1495      LSB-first (i.e. low 8-bits at lower byte index) if its false.
  1326      Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
  1496      Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
  1327 
  1497 
  1328     |b1 "{ Class: SmallInteger }" 
  1498     |b1 "{ Class: SmallInteger }" 
  1338     "Modified: / 21.1.1998 / 17:46:07 / cg"
  1508     "Modified: / 21.1.1998 / 17:46:07 / cg"
  1339 !
  1509 !
  1340 
  1510 
  1341 wordAt:index put:value
  1511 wordAt:index put:value
  1342     "set the 2-bytes starting at index from the (unsigned) Integer value.
  1512     "set the 2-bytes starting at index from the (unsigned) Integer value.
       
  1513      The index is a smalltalk index (i.e. 1-based).
  1343      The stored value must be in the range 0 .. 16rFFFF. 
  1514      The stored value must be in the range 0 .. 16rFFFF. 
  1344      The value is stored in the machines natural byteorder.
  1515      The value is stored in the machines natural byteorder.
  1345      Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
  1516      Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
  1346 
  1517 
  1347     ^ self wordAt:index put:value MSB:IsBigEndian
  1518     ^ self wordAt:index put:value MSB:IsBigEndian
  1357     "Modified: / 5.3.1998 / 15:00:03 / stefan"
  1528     "Modified: / 5.3.1998 / 15:00:03 / stefan"
  1358 !
  1529 !
  1359 
  1530 
  1360 wordAt:index put:value MSB:msb
  1531 wordAt:index put:value MSB:msb
  1361     "set the 2-bytes starting at index from the (unsigned) Integer value.
  1532     "set the 2-bytes starting at index from the (unsigned) Integer value.
       
  1533      The index is a smalltalk index (i.e. 1-based).
  1362      The stored value must be in the range 0 .. 16rFFFF. 
  1534      The stored value must be in the range 0 .. 16rFFFF. 
  1363      The value is stored LSB-first (i.e. the low 8bits are stored at the
  1535      The value is stored LSB-first (i.e. the low 8bits are stored at the
  1364      lower index) if msb is false, MSB-first otherwise.
  1536      lower index) if msb is false, MSB-first otherwise.
  1365      Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
  1537      Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
  1366 
  1538 
  1444     "Created: / 21.1.1998 / 17:48:38 / cg"
  1616     "Created: / 21.1.1998 / 17:48:38 / cg"
  1445 !
  1617 !
  1446 
  1618 
  1447 zeroByteStringAt:index maximumSize:count
  1619 zeroByteStringAt:index maximumSize:count
  1448     "extract a zeroByte-delimited string, given initial index and
  1620     "extract a zeroByte-delimited string, given initial index and
  1449      maximum number of characters (bytes)"
  1621      maximum number of characters (bytes).
       
  1622      The index is a smalltalk index (i.e. 1-based)."
  1450 
  1623 
  1451     |bytes idx|
  1624     |bytes idx|
  1452 
  1625 
  1453     bytes := self copyFrom:index to:(index + count - 1).
  1626     bytes := self copyFrom:index to:(index + count - 1).
  1454     idx := bytes indexOf:0.
  1627     idx := bytes indexOf:0.
  1459 ! !
  1632 ! !
  1460 
  1633 
  1461 !UninterpretedBytes methodsFor:'misc'!
  1634 !UninterpretedBytes methodsFor:'misc'!
  1462 
  1635 
  1463 swapLongAt:byteIndex 
  1636 swapLongAt:byteIndex 
  1464     "swap the byteOrder of a long."
  1637     "swap the byteOrder of a long.
       
  1638      The index is a smalltalk index (i.e. 1-based)."
  1465 
  1639 
  1466     |t|
  1640     |t|
  1467 
  1641 
  1468     t := self byteAt:byteIndex.
  1642     t := self byteAt:byteIndex.
  1469     self byteAt:byteIndex put:(self byteAt:(byteIndex + 3)).
  1643     self byteAt:byteIndex put:(self byteAt:(byteIndex + 3)).
  1487 ! !
  1661 ! !
  1488 
  1662 
  1489 !UninterpretedBytes class methodsFor:'documentation'!
  1663 !UninterpretedBytes class methodsFor:'documentation'!
  1490 
  1664 
  1491 version
  1665 version
  1492     ^ '$Header: /cvs/stx/stx/libbasic/Attic/UIBytes.st,v 1.23 1998-04-25 21:33:11 cg Exp $'
  1666     ^ '$Header: /cvs/stx/stx/libbasic/Attic/UIBytes.st,v 1.24 1998-05-08 13:26:50 cg Exp $'
  1493 ! !
  1667 ! !
  1494 UninterpretedBytes initialize!
  1668 UninterpretedBytes initialize!