--- a/UninterpretedBytes.st Sat Mar 12 07:23:20 2016 +0000
+++ b/UninterpretedBytes.st Mon Mar 14 08:45:36 2016 +0000
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
@@ -469,13 +467,531 @@
"Modified: / 5.3.1998 / 14:56:22 / stefan"
! !
-
-!UninterpretedBytes methodsFor:'Compatibility-Squeak'!
-
-copyFromByteArray:aByteArray
- "copy as much as possible from aByteArray"
-
- self replaceBytesFrom:1 to:(self size min:aByteArray size) with:aByteArray startingAt:1
+!UninterpretedBytes methodsFor:'Compatibility'!
+
+doubleWordAt:index
+ "return the 4-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order."
+
+ ^ self unsignedInt32At:index MSB:IsBigEndian
+
+ "
+ |b|
+
+ b := ByteArray withAll:#(1 2 3 4).
+ (b doubleWordAt:1) printStringRadix:16
+ "
+
+ "Modified: / 5.3.1998 / 14:57:35 / stefan"
+!
+
+doubleWordAt:index MSB:msb
+ "return the 4-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved MSB-first, if the msb-arg is true;
+ LSB-first otherwise."
+
+ ^ self unsignedInt32At:index MSB:msb
+
+ "
+ |b|
+
+ b := ByteArray withAll:#(1 2 3 4).
+ (b doubleWordAt:1 MSB:true) printStringRadix:16.
+ (b doubleWordAt:1 MSB:false) printStringRadix:16
+ "
+!
+
+doubleWordAt:byteIndex put:anInteger
+ "set the 4-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value should be in the range 0 to 16rFFFFFFFF
+ (for negative values, the stored value is not defined).
+ The value is stored in the machines natural byte order."
+
+ ^ self unsignedInt32At:byteIndex put:anInteger MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b doubleWordAt:1 put:16r04030201.
+ b inspect
+ "
+
+ "Modified: / 5.3.1998 / 14:57:48 / stefan"
+!
+
+doubleWordAt:byteIndex put:anInteger MSB:msb
+ "set the 4-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value must be in the range 0 to 16rFFFFFFFF.
+ The value is stored MSB-first if msb is true; LSB-first otherwise."
+
+ ^ self unsignedInt32At:byteIndex put:anInteger MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:8.
+ b doubleWordAt:1 put:16r04030201 MSB:true.
+ b doubleWordAt:5 put:16r04030201 MSB:false.
+ b inspect
+ "
+
+ "Modified: / 21.1.1998 / 17:43:34 / cg"
+ "Modified: / 5.3.1998 / 11:42:17 / stefan"
+!
+
+doubleWordAtDoubleWordIndex:int32Index
+ "return the unsigned long (int32) at index, anInteger.
+ Fetching in the machine's natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAtDoubleWordIndex:int32Index MSB:IsBigEndian
+
+ "Created: / 21.1.1998 / 17:43:53 / cg"
+ "Modified: / 5.3.1998 / 14:58:06 / stefan"
+!
+
+doubleWordAtDoubleWordIndex:int32Index MSB:msb
+ "return the unsigned long (int32) at index, anInteger.
+ Fetching is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self unsignedInt32At:((int32Index - 1) * 4 + 1) MSB:msb
+
+ "Created: / 21.1.1998 / 17:44:07 / cg"
+!
+
+doubleWordAtDoubleWordIndex:int32Index put:anInteger
+ "set the long at index, anInteger.
+ Storing in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAtDoubleWordIndex:int32Index put:anInteger MSB:IsBigEndian
+
+ "Created: / 21.1.1998 / 17:44:13 / cg"
+ "Modified: / 5.3.1998 / 14:58:19 / stefan"
+!
+
+doubleWordAtDoubleWordIndex:int32Index put:anInteger MSB:msb
+ "set the long at index, anInteger.
+ Storing is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self unsignedInt32At:((int32Index - 1) * 4 + 1) put:anInteger MSB:msb
+
+ "Created: / 21.1.1998 / 17:44:19 / cg"
+!
+
+int16At:byteIndex
+ "return the 2-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order.
+ This may be worth a primitive."
+
+ ^ self signedInt16At:byteIndex
+
+ "
+ |b|
+ b := ByteArray new:2.
+ b wordAt:1 put:16rFFFF.
+ b signedWordAt:1
+ "
+
+ "Modified: 1.7.1996 / 21:14:38 / cg"
+!
+
+int16At:byteIndex MSB:msb
+ "return the 2-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order.
+ This may be worth a primitive."
+
+ ^ self signedInt16At:byteIndex MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:2.
+ b wordAt:1 put:16rFFFF.
+ b signedWordAt:1
+ "
+
+ "Modified: 1.7.1996 / 21:14:38 / cg"
+!
+
+int16At:index put:anInteger
+ "set the 2-bytes starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range -32768 .. +32676.
+ The value is stored in the machine's natural byteorder"
+
+ ^ self signedInt16At:index put:anInteger MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b shortAt:1 put:1 bigEndian:true.
+ b shortAt:3 put:1 bigEndian:false.
+ b inspect
+ "
+
+ "Modified: / 1.7.1996 / 21:12:07 / cg"
+ "Created: / 5.3.1998 / 11:02:05 / stefan"
+!
+
+int16At:index put:anInteger MSB:bigEndian
+ "set the 2-bytes starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range -32768 .. +32676.
+ The value is stored in the byteorder given by bigEndian.
+ This may be worth a primitive."
+
+
+ ^ self signedInt16At:index put:anInteger MSB:bigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b shortAt:1 put:1 bigEndian:true.
+ b shortAt:3 put:1 bigEndian:false.
+ b inspect
+ "
+
+ "Modified: / 1.7.1996 / 21:12:07 / cg"
+ "Created: / 5.3.1998 / 11:02:05 / stefan"
+!
+
+longAt:index
+ "return the 4-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order,
+ therefore, this should only be used for byte-data which is
+ only used inside this machine.
+ To setup data packets which are to be sent to other machines,
+ or stored into a file, always use longAt:MSB: and specify
+ a definite byteOrder."
+
+ ^ self signedInt32At:index
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b unsignedLongAt:1 put:16rFFFFFFFF.
+ (b longAt:1)
+ "
+
+ "Modified: / 1.7.1996 / 21:11:28 / cg"
+ "Modified: / 5.3.1998 / 12:06:28 / stefan"
+!
+
+longAt:index bigEndian:msb
+ "return the 4-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ Depending on msb, the value is retrieved MSB-first or LSB-first.
+ This may be worth a primitive."
+
+ ^ self signedInt32At:index MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b unsignedLongAt:1 put:16rFFFFFFFF.
+ (b longAt:1)
+ "
+
+ "Modified: / 1.7.1996 / 21:11:33 / cg"
+ "Created: / 5.3.1998 / 14:02:03 / stefan"
+!
+
+longAt:index put:value
+ "set the 4-bytes starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is stored in the machine's natural byte order."
+
+ ^ self signedInt32At:index put:value MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b longAt:1 put:-1.
+ (b unsignedLongAt:1) printStringRadix:16
+ "
+
+ "Modified: / 1.7.1996 / 21:11:39 / cg"
+ "Created: / 5.3.1998 / 10:57:18 / stefan"
+!
+
+longAt:byteIndex put:anInteger bigEndian:msb
+ "store a signed long (32bit) integer.
+ The index is a smalltalk index (i.e. 1-based)."
+
+ ^ self signedInt32At:byteIndex put:anInteger MSB:msb
+
+ "Created: / 9.5.1998 / 01:10:24 / cg"
+ "Modified: / 9.5.1998 / 01:13:34 / cg"
+!
+
+longLongAt:index
+ "return the 8-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machineÄs natural byte order.
+ This may be worth a primitive."
+
+ ^ self signedInt64At:index MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF.
+ (b longLongAt:1)
+ "
+
+ "Modified: / 1.7.1996 / 21:11:28 / cg"
+ "Created: / 5.3.1998 / 14:40:05 / stefan"
+ "Modified: / 5.3.1998 / 14:58:32 / stefan"
+!
+
+longLongAt:index bigEndian:msb
+ "return the 8-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the given byte order.
+ This may be worth a primitive."
+
+ ^ self signedInt64At:index MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF.
+ (b longLongAt:1 msb:true)
+ "
+
+ "Modified: / 5.3.1998 / 12:06:28 / stefan"
+ "Created: / 5.3.1998 / 14:40:54 / stefan"
+ "Modified: / 9.5.1998 / 01:10:59 / cg"
+!
+
+longLongAt:byteIndex put:anInteger
+ "store a signed longLong (64bit) integer.
+ The index is a smalltalk index (i.e. 1-based).
+ Same as #signedQuadWordAt:put: - for ST80 compatibility."
+
+ ^ self signedInt64At:byteIndex put:anInteger MSB:IsBigEndian
+!
+
+longLongAt:byteIndex put:anInteger bigEndian:msb
+ "store a signed longLong (64bit) integer.
+ The index is a smalltalk index (i.e. 1-based).
+ Same as #signedQuadWordAt:put: - for ST80 compatibility."
+
+ ^ self signedInt64At:byteIndex put:anInteger MSB:msb
+
+ "Created: / 9.5.1998 / 01:10:24 / cg"
+ "Modified: / 9.5.1998 / 01:13:34 / cg"
+!
+
+quadWordAt:index MSB:msb
+ "return the 8-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ Depending on msb, the value is retrieved MSB or LSB-first."
+
+ ^ self unsignedInt64At:index MSB:msb
+
+ "
+ |b|
+
+ b := ByteArray withAll:#(1 2 3 4 5 6 7 8).
+ (b quadWordAt:1 MSB:false) printStringRadix:16
+ "
+
+ "Modified: 5.11.1996 / 14:06:21 / cg"
+!
+
+quadWordAt:index put:anInteger MSB:msb
+ "set the 8-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
+ Depending on msb, the value is stored MSB-first or LSB-first."
+
+ ^ self unsignedInt64At:index put:anInteger MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:8.
+ b quadWordAtIndex:1 put:16r0807060504030201 MSB:false.
+ b inspect
+ "
+!
+
+shortAt:index
+ "return the 2-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order.
+ This may be worth a primitive.
+ This is the ST80 equivalent of #signedWordAt:"
+
+ ^ (self unsignedInt16At:index MSB:IsBigEndian) signExtendedShortValue
+
+ "
+ |b|
+ b := ByteArray new:2.
+ b unsignedShortAt:1 put:16rFFFF.
+ b shortAt:1
+ "
+
+ "Modified: / 1.7.1996 / 21:14:38 / cg"
+ "Created: / 5.3.1998 / 10:59:57 / stefan"
+ "Modified: / 5.3.1998 / 23:39:38 / stefan"
+!
+
+shortAt:index bigEndian:msb
+ "return the 2-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved MSB-first, if the msb-arg is true;
+ LSB-first otherwise.
+ This is the ST80 equivalent of #signedWordAt:"
+
+ ^ (self unsignedInt16At:index MSB:msb) signExtendedShortValue
+
+ "
+ |b|
+ b := ByteArray new:2.
+ b unsignedShortAt:1 put:16rFFFF.
+ b shortAt:1
+ "
+
+ "Modified: / 1.7.1996 / 21:14:38 / cg"
+ "Created: / 5.3.1998 / 23:41:21 / stefan"
+!
+
+shortAt:index put:value
+ "set the 2-bytes starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range -32768 .. +32676.
+ The value is stored in the machines natural byteorder.
+ This may be worth a primitive.
+ This is the ST80 equivalent of #signedWordAt:put:"
+
+ ^ self signedInt16At:index put:value MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:6.
+ b shortAt:1 put:-1.
+ b shortAt:3 put:-2.
+ b shortAt:5 put:0.
+ b inspect
+ "
+
+ "Modified: / 1.7.1996 / 21:12:07 / cg"
+ "Created: / 5.3.1998 / 11:02:05 / stefan"
+!
+
+shortAt:index put:value bigEndian:bigEndian
+ "set the 2-bytes starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range -32768 .. +32676.
+ The value is stored in the byteorder given by bigEndian.
+ This may be worth a primitive."
+
+ ^ self signedInt16At:index put:value MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b shortAt:1 put:1 bigEndian:true.
+ b shortAt:3 put:1 bigEndian:false.
+ b inspect
+ "
+
+ "Modified: / 1.7.1996 / 21:12:07 / cg"
+ "Created: / 5.3.1998 / 11:02:05 / stefan"
+!
+
+signedDoubleWordAt:index
+ "return the 4-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order.
+ This may be worth a primitive."
+
+ ^ self signedInt32At:index MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b doubleWordAt:1 put:16rFFFFFFFF.
+ (b signedDoubleWordAt:1)
+ "
+ "
+ |b|
+ b := ByteArray new:4.
+ b signedDoubleWordAt:1 put:-1.
+ (b doubleWordAt:1)
+ "
+
+ "Modified: 1.7.1996 / 21:11:28 / cg"
+!
+
+signedDoubleWordAt:index MSB:msb
+ "return the 4-bytes starting at index as a (signed) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved MSB-first, if the msb-arg is true;
+ LSB-first otherwise."
+
+ ^ self signedInt32At:index MSB:msb
+
+ "
+ |b|
+
+ b := ByteArray withAll:#(1 2 3 4).
+ (b signedDoubleWordAt:1 MSB:true) printStringRadix:16.
+ (b signedDoubleWordAt:1 MSB:false) printStringRadix:16
+ "
+!
+
+signedDoubleWordAt:index put:value
+ "set the 4-bytes starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is stored in the machines natural byte order.
+ This may be worth a primitive."
+
+ ^ self signedInt32At:index put:value MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b signedDoubleWordAt:1 put:-1.
+ (b doubleWordAt:1) printStringRadix:16
+ "
+
+ "Modified: 1.7.1996 / 21:11:39 / cg"
+!
+
+signedDoubleWordAt:index put:value MSB:msb
+ "set the 4-bytes starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ Depending on msb, the value is stored MSB-first or LSB-first.
+ This may be worth a primitive."
+
+ ^ self signedInt32At:index put:value MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b signedDoubleWordAt:1 put:-1.
+ (b doubleWordAt:1) printStringRadix:16
+ "
+
+ "Modified: 1.7.1996 / 21:11:46 / cg"
!
signedLongAt:index
@@ -511,6 +1027,412 @@
"
"Modified: 1.7.1996 / 21:14:38 / cg"
+!
+
+signedWordAt:index
+ "return the 2-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order.
+ This may be worth a primitive."
+
+ ^ (self unsignedInt16At:index MSB:IsBigEndian) signExtendedShortValue
+
+ "
+ |b|
+ b := ByteArray new:2.
+ b wordAt:1 put:16rFFFF.
+ b signedWordAt:1
+ "
+
+ "Modified: 1.7.1996 / 21:14:38 / cg"
+!
+
+signedWordAt:index MSB:msb
+ "return the 2-bytes starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved MSB-first if the msb-arg is true,
+ LSB-first otherwise.
+ This may be worth a primitive."
+
+ ^ (self unsignedInt16At:index MSB:msb) signExtendedShortValue
+
+ "
+ |b|
+ b := ByteArray new:2.
+ b wordAt:1 put:16r0080.
+ b signedWordAt:1 MSB:true.
+ b signedWordAt:1 MSB:false.
+ "
+
+ "Modified: 1.7.1996 / 21:15:57 / cg"
+!
+
+signedWordAt:byteIndex put:anInteger
+ "set the 2-bytes starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range -32768 .. +32676.
+ The value is stored in the machine's natural byteorder."
+
+ ^ self signedInt16At:byteIndex put:anInteger MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:6.
+ b shortAt:1 put:-1.
+ b shortAt:3 put:-2.
+ b shortAt:5 put:0.
+ b inspect
+ "
+
+ "Modified: / 1.7.1996 / 21:12:07 / cg"
+ "Modified: / 5.3.1998 / 11:01:30 / stefan"
+!
+
+signedWordAt:byteIndex put:anInteger MSB:msb
+ "set the 2-bytes starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range -32768 .. +32676.
+ The value is stored MSB-first, if the msb-arg is true;
+ LSB-first otherwise."
+
+ ^ self int16At:byteIndex put:anInteger MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b signedWordAt:1 put:-1.
+ b signedWordAt:3 put:-2.
+ b inspect
+ "
+
+ "Modified: 1.7.1996 / 21:12:13 / cg"
+!
+
+unsignedLongAt:index
+ "return the 4-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machine's natural byte order.
+ Subclasses may redefine this for better performance.
+ Same as doubleWordAt: for protocol completeness"
+
+ ^ self unsignedInt32At:index MSB:IsBigEndian
+
+ "
+ |b|
+
+ b := ByteArray withAll:#(1 2 3 4).
+ (b unsignedLongAt:1) printStringRadix:16
+ "
+
+ "Created: / 5.3.1998 / 11:56:53 / stefan"
+ "Modified: / 5.3.1998 / 14:58:48 / stefan"
+!
+
+unsignedLongAt:index bigEndian:msb
+ "return the 4-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved MSB-first, if the msb-arg is true;
+ LSB-first otherwise.
+ Subclasses may redefine this for better performance.
+ Same as doubleWordAt:MSB: for protocol completeness"
+
+ ^ self unsignedInt32At:index MSB:msb
+
+ "
+ |b|
+
+ b := ByteArray withAll:#(1 2 3 4).
+ (b unsignedLongAt:1 bigEndian:true) printStringRadix:16.
+ (b unsignedLongAt:1 bigEndian:false) printStringRadix:16
+ "
+
+ "Modified: / 21.1.1998 / 17:42:30 / cg"
+ "Created: / 5.3.1998 / 11:46:05 / stefan"
+!
+
+unsignedLongAt:index put:value
+ "set the 4-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value should be in the range 0 to 16rFFFFFFFF
+ (for negative values, the stored value is not defined).
+ The value is stored in the machines natural byte order.
+ Subclasses may redefine this for better performance.
+ Same as doubleWordAt:put: for protocol completeness"
+
+ ^ self unsignedInt32At:index put:value MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b unsignedLongAt:1 put:16r04030201.
+ b inspect
+ "
+
+ "Created: / 5.3.1998 / 11:57:44 / stefan"
+ "Modified: / 5.3.1998 / 14:58:59 / stefan"
+!
+
+unsignedLongAt:index put:aNumber bigEndian:msb
+ "set the 4-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value must be in the range 0 to 16rFFFFFFFF.
+ The value is stored MSB-first if msb is true; LSB-first otherwise.
+ Subclasses may redefine this for better performance.
+ Same as doubleWordAt:put:MSB: for protocol completeness"
+
+ ^ self unsignedInt32At:index put:aNumber MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:8.
+ b unsignedLongAt:1 put:16r04030201 bigEndian:true.
+ (b unsignedLongAt:1 bigEndian:false) printStringRadix:16
+ "
+
+ "Modified: / 21.1.1998 / 17:43:34 / cg"
+ "Created: / 5.3.1998 / 11:43:53 / stefan"
+ "Modified: / 5.3.1998 / 11:47:30 / stefan"
+!
+
+unsignedLongLongAt:index bigEndian:msb
+ "return the 8-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ Depending on msb, the value is retrieved MSB or LSB-first."
+
+ ^ self unsignedInt64At:index MSB:msb
+
+ "
+ |b|
+
+ b := ByteArray withAll:#(1 2 3 4 5 6 7 8).
+ (b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16
+ "
+
+ "Modified: / 5.11.1996 / 14:06:21 / cg"
+ "Modified: / 5.3.1998 / 14:04:44 / stefan"
+!
+
+unsignedLongLongAt:index put:anInteger
+ "set the 8-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
+ The value is stored in natural byte order."
+
+ ^ self unsignedInt64At:index put:anInteger MSB:IsBigEndian
+
+ "Created: / 5.3.1998 / 14:44:00 / stefan"
+ "Modified: / 5.3.1998 / 15:02:32 / stefan"
+!
+
+unsignedLongLongAt:index put:anInteger bigEndian:msb
+ "set the 8-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
+ Depending on msb, the value is stored MSB-first or LSB-first."
+
+ ^ self unsignedInt64At:index put:anInteger MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:8.
+ b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false.
+ b inspect
+ "
+
+ "Created: / 5.3.1998 / 14:06:02 / stefan"
+!
+
+unsignedShortAt:index
+ "return the 2-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order
+ Subclasses may redefine this for better performance.
+ This is the ST80 equivalent of #wordAt:"
+
+
+ ^ self unsignedInt16At:index MSB:IsBigEndian
+
+ "Created: / 5.3.1998 / 11:38:25 / stefan"
+ "Modified: / 5.3.1998 / 14:59:25 / stefan"
+!
+
+unsignedShortAt:index bigEndian:msb
+ "return the 2-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved MSB-first (high 8 bits at lower index) if msb is true;
+ LSB-first (i.e. low 8-bits at lower byte index) if its false)"
+
+ ^ self unsignedInt16At:index MSB:msb
+
+ "Modified: / 21.1.1998 / 17:46:07 / cg"
+ "Created: / 5.3.1998 / 11:49:29 / stefan"
+!
+
+unsignedShortAt:index put:value
+ "set the 2-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range 0 .. 16rFFFF.
+ The value is stored in the machines natural byteorder."
+
+ ^ self unsignedInt16At:index put:value
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b unsignedShortAt:1 put:16r0102.
+ b unsignedShortAt:3 put:16r0304.
+ b inspect
+ "
+
+ "Created: / 5.3.1998 / 11:54:52 / stefan"
+ "Modified: / 5.3.1998 / 14:59:38 / stefan"
+!
+
+unsignedShortAt:index put:value bigEndian:msb
+ "set the 2-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range 0 .. 16rFFFF.
+ The value is stored LSB-first (i.e. the low 8bits are stored at the
+ lower index) if msb is false, MSB-first otherwise"
+
+ ^ self unsignedInt16At:index put:value MSB:msb
+
+ "
+ |b|
+ b := ByteArray new:8.
+ b unsignedShortAt:1 put:16r0102 bigEndian:false.
+ b unsignedShortAt:3 put:16r0304 bigEndian:false.
+ b unsignedShortAt:5 put:16r0102 bigEndian:true.
+ b unsignedShortAt:7 put:16r0304 bigEndian:true.
+ b inspect
+ "
+
+ "Modified: / 21.1.1998 / 17:48:15 / cg"
+ "Modified: / 5.3.1998 / 11:52:28 / stefan"
+!
+
+wordAt:index
+ "return the 2-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order
+ Subclasses may redefine this for better performance."
+
+ ^ self unsignedInt16At:index MSB:IsBigEndian
+
+ "Modified: / 5.3.1998 / 14:59:51 / stefan"
+!
+
+wordAt:index MSB:msb
+ "return the 2-bytes starting at index as an (unsigned) Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved MSB (high 8 bits at lower index) if msb is true;
+ LSB-first (i.e. low 8-bits at lower byte index) if its false.
+ Notice:
+ the index is a byte index; thus, this allows for unaligned access to
+ words on any boundary.
+ Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
+
+ ^ self unsignedInt16At:index MSB:msb
+!
+
+wordAt:index put:value
+ "set the 2-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range 0 .. 16rFFFF.
+ The value is stored in the machines natural byteorder.
+ Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
+
+ ^ self unsignedInt16At:index put:value MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:4.
+ b wordAt:1 put:16r0102.
+ b wordAt:3 put:16r0304.
+ b inspect
+ "
+
+ "Modified: / 5.3.1998 / 15:00:03 / stefan"
+!
+
+wordAt:index put:value MSB:msb
+ "set the 2-bytes starting at index from the (unsigned) Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The stored value must be in the range 0 .. 16rFFFF.
+ The value is stored LSB-first (i.e. the low 8bits are stored at the
+ lower index) if msb is false, MSB-first otherwise.
+ Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
+
+ ^ self unsignedInt16At:index put:value MSB:msb
+
+ "
+ b := ByteArray new:8.
+ b wordAt:1 put:16r0102 MSB:false.
+ b wordAt:3 put:16r0304 MSB:false.
+ b wordAt:5 put:16r0102 MSB:true.
+ b wordAt:7 put:16r0304 MSB:true.
+ b inspect
+ "
+
+ "Modified: / 21.1.1998 / 17:48:15 / cg"
+!
+
+wordAtWordIndex:int16Index
+ "return the unsigned short (uint16) at index, anInteger.
+ Fetching in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self unsignedInt16At:int16Index MSB:IsBigEndian
+
+ "Created: / 21.1.1998 / 17:48:26 / cg"
+ "Modified: / 5.3.1998 / 15:00:16 / stefan"
+!
+
+wordAtWordIndex:int16Index MSB:msb
+ "return the unsigned short (uint16) at index, anInteger.
+ Fetching is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self unsignedInt16At:((int16Index - 1) * 2 + 1) MSB:msb
+
+ "Created: / 21.1.1998 / 17:48:30 / cg"
+!
+
+wordAtWordIndex:int16Index put:anInteger
+ "set the unsigned short (uint16) at index, anInteger.
+ Storing in the machine's natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self unsignedInt16At:int16Index put:anInteger MSB:IsBigEndian
+
+ "Created: / 21.1.1998 / 17:48:34 / cg"
+ "Modified: / 5.3.1998 / 15:00:27 / stefan"
+!
+
+wordAtWordIndex:int16Index put:anInteger MSB:msb
+ "set the short at index, anInteger.
+ Storing is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self unsignedInt16At:((int16Index - 1) * 2 + 1) put:anInteger MSB:msb
+
+ "Created: / 21.1.1998 / 17:48:38 / cg"
+! !
+
+!UninterpretedBytes methodsFor:'Compatibility-Squeak'!
+
+copyFromByteArray:aByteArray
+ "copy as much as possible from aByteArray"
+
+ self replaceBytesFrom:1 to:(self size min:aByteArray size) with:aByteArray startingAt:1
! !
!UninterpretedBytes methodsFor:'Compatibility-V''Age'!
@@ -552,6 +1474,119 @@
!UninterpretedBytes methodsFor:'accessing-arbitrary-long ints'!
+nativeIntAt:index
+ "return the 4- or 8-bytes (depending on the native integer/pointer size)
+ starting at index as a signed Integer.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is retrieved in the machines natural byte order,
+ therefore, this should only be used for byte-data which is
+ only used inside this machine."
+
+ |w|
+
+%{
+ /*
+ * handle the most common cases fast ...
+ */
+ if (__isSmallInteger(index)) {
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(INT)-1)) < sz) {
+ cp += idx;
+#if defined(__i386__)
+ /*
+ * aligned or not, we dont care (i386 can do both)
+ */
+ {
+ INT iVal = ((INT *)cp)[0];
+
+ RETURN (__MKINT(iVal));
+ }
+#else
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(INT)-1)) == 0) {
+ INT iVal = ((INT *)cp)[0];
+
+ RETURN (__MKINT(iVal));
+ }
+#endif
+ }
+ }
+ }
+%}.
+ ExternalAddress pointerSize == 8 ifTrue:[
+ ^ self signedInt64At:index
+ ].
+ ^ self signedInt32At:index
+
+ "
+ |b|
+ b := ByteArray new:8.
+ b nativeIntAt:1 put:SmallInteger maxVal.
+ b nativeIntAt:1
+ "
+!
+
+nativeIntAt:index put:value
+ "set the 4- or 8-bytes (depending on INT-/pointer size) starting at index from the signed Integer value.
+ The index is a smalltalk index (i.e. 1-based).
+ The value is stored in the machine's natural byte order."
+
+%{ /* NOCONTEXT */
+ /*
+ * handle the most common cases fast ...
+ */
+ if (__isSmallInteger(index)) {
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(INT)-1)) < sz) {
+ cp += idx;
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(INT)-1)) == 0) {
+ INT __v;
+
+ if (__isSmallInteger(value)) {
+ // how about a range check?
+ ((INT *)cp)[0] = (INT)(__intVal(value));
+ RETURN (value);
+ }
+ if ((__v = __signedLongIntVal(value)) != 0) {
+ // how about a range check?
+ ((INT *)cp)[0] = (INT)(__v);
+ RETURN (value);
+ }
+ }
+ }
+ }
+ }
+%}.
+ ExternalAddress pointerSize == 8 ifTrue:[
+ ^ self signedInt64At:index put:value MSB:IsBigEndian
+ ].
+ ^ self signedInt32At:index put:value MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:8.
+ b nativeIntAt:1 put:SmallInteger maxVal.
+ (b nativeIntAt:1)
+ "
+!
+
signedIntegerAt:index length:n bigEndian:bigEndian
"return the n-byte signed integer starting at index.
With n=1, this returns the single signed byte's value,
@@ -564,12 +1599,12 @@
bigEndian ifTrue:[
highByte := (self at:index).
index to:index+n-1 do:[:i |
- val := (val<<8) + (self at:i)
+ val := (val<<8) + (self byteAt:i)
]
] ifFalse:[
highByte := (self at:index+n-1).
index+n-1 to:index by:-1 do:[:i |
- val := (val<<8) + (self at:i)
+ val := (val<<8) + (self byteAt:i)
]
].
(highByte bitTest:16r80) ifTrue:[
@@ -618,13 +1653,13 @@
val := 0.
bigEndian ifTrue:[
- index to:index+n-1 do:[:i |
- val := (val<<8) + (self at:i)
- ]
+ index to:index+n-1 do:[:i |
+ val := (val<<8) + (self byteAt:i)
+ ]
] ifFalse:[
- index+n-1 to:index by:-1 do:[:i |
- val := (val<<8) + (self at:i)
- ]
+ index+n-1 to:index by:-1 do:[:i |
+ val := (val<<8) + (self byteAt:i)
+ ]
].
^ val
@@ -647,12 +1682,12 @@
val := newValue.
bigEndian ifTrue:[
index to:index+n-1 do:[:i |
- self at:i put:(val bitAnd:16rFF).
+ self byteAt:i put:(val bitAnd:16rFF).
val := val bitShift:-8.
]
] ifFalse:[
index+n-1 to:index by:-1 do:[:i |
- self at:i put:(val bitAnd:16rFF).
+ self byteAt:i put:(val bitAnd:16rFF).
val := val bitShift:-8.
]
].
@@ -675,9 +1710,9 @@
^ (self byteAt:index) decodeFromBCD
"
- #[ 16r55 ] bcdByteAt:1
- #[ 16r99] bcdByteAt:1
- #[ 16rAA] bcdByteAt:1
+ #[ 16r55 ] bcdByteAt:1
+ #[ 16r99 ] bcdByteAt:1
+ #[ 16rAA ] bcdByteAt:1
"
"Modified (comment): / 26-09-2011 / 11:57:33 / cg"
@@ -703,19 +1738,126 @@
"Modified (comment): / 26-09-2011 / 11:57:36 / cg"
!
-signedByteAt:index
- "return the byte at index as a signed 8 bit value in the range -128..+127.
- The index is a smalltalk index (i.e. 1-based).
- This may be worth a primitive."
-
- ^ (self at:index) signExtendedByteValue
+byteAt:byteIndex
+ "return the byte at byteIndex as an unsigned 8 bit value in the range 0..255.
+ The index is a smalltalk index (i.e. 1-based)."
+
+%{
+ if (__isSmallInteger(byteIndex)) {
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
+ char ch;
+
+ if (idx < sz) {
+ ch = cp[idx] & 0xFF;
+ RETURN (__mkSmallInteger( ch ));
+ }
+ }
+ }
+%}.
+
+ ^ self at:byteIndex
"
|b|
- b := ByteArray new:2.
+ b := ByteArray new:3.
b at:1 put:16rFF.
b at:2 put:16r7F.
- b signedByteAt:1
+ b at:3 put:16r80.
+ b byteAt:1.
+ b byteAt:2.
+ b byteAt:3.
+ "
+
+ "Modified: / 01-07-1996 / 21:13:53 / cg"
+ "Modified (comment): / 26-09-2011 / 11:57:14 / cg"
+!
+
+byteAt:byteIndex put:anInteger
+ "set the byte at byteIndex as an unsigned 8 bit value in the range 0..255.
+ The index is a smalltalk index (i.e. 1-based)."
+
+%{
+ if (__isSmallInteger(byteIndex) && __isSmallInteger(anInteger)) {
+ unsigned char *cp;
+ INT sz;
+ INT val = __intVal(anInteger);
+
+ if ( ((unsigned INT)val) <= 0xFF ) {
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
+
+ if (idx < sz) {
+ cp[idx] = val & 0xFF;
+ RETURN (anInteger);
+ }
+ }
+ }
+ }
+%}.
+
+ ^ self at:byteIndex put:anInteger
+
+ "
+ |b|
+ b := ByteArray new:3.
+ b byteAt:1 put:16rFF.
+ b byteAt:2 put:16r7F.
+ b byteAt:3 put:16r80.
+ b signedByteAt:1.
+ b signedByteAt:2.
+ b signedByteAt:3.
+ "
+!
+
+signedByteAt:byteIndex
+ "return the byte at byteIndex as a signed 8 bit value in the range -128..+127.
+ The index is a smalltalk index (i.e. 1-based).
+ This may be worth a primitive."
+
+%{
+ /*
+ * handle the most common cases fast ...
+ */
+ if (__isSmallInteger(byteIndex)) {
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
+ char ch;
+
+ if (idx < sz) {
+ cp += idx;
+ ch = cp[0];
+# ifndef HAS_SIGNED_CHAR
+ if ( (unsigned int)ch >= 0x80 ) {
+ ch = ch - 0x100;
+ }
+#endif
+ RETURN (__mkSmallInteger( ch ));
+ }
+ }
+ }
+%}.
+
+ ^ (self byteAt:byteIndex) signExtendedByteValue
+
+ "
+ |b|
+ b := ByteArray new:3.
+ b at:1 put:16rFF.
+ b at:2 put:16r7F.
+ b at:3 put:16r80.
+ b byteAt:1.
+ b byteAt:2.
+ b byteAt:3.
"
"Modified: / 01-07-1996 / 21:13:53 / cg"
@@ -731,11 +1873,11 @@
|b "{ Class: SmallInteger }"|
aSignedByteValue >= 0 ifTrue:[
- b := aSignedByteValue
+ b := aSignedByteValue
] ifFalse:[
- b := 16r100 + aSignedByteValue
+ b := 16r100 + aSignedByteValue
].
- self at:index put:b.
+ self byteAt:index put:b.
^ aSignedByteValue
"
@@ -766,33 +1908,33 @@
* handle the most common cases fast ...
*/
if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(double)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(double)-1)) == 0) {
- double dVal = ((double *)cp)[0];
- OBJ f;
-
- __qMKFLOAT(f, dVal);
- RETURN (f);
- }
- }
- }
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(double)-1)) < sz) {
+ cp += idx;
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(double)-1)) == 0) {
+ double dVal = ((double *)cp)[0];
+ OBJ f;
+
+ __qMKFLOAT(f, dVal);
+ RETURN (f);
+ }
+ }
+ }
}
%}.
newFloat := Float basicNew.
1 to:8 do:[:destIndex|
- newFloat basicAt:destIndex put:(self at:index - 1 + destIndex)
+ newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex))
].
^ newFloat.
@@ -817,12 +1959,12 @@
|newFloat|
msb == IsBigEndian ifTrue:[
- ^ self doubleAt:index.
+ ^ self doubleAt:index.
].
newFloat := Float basicNew.
1 to:8 do:[:destIndex|
- newFloat basicAt:(9-destIndex) put:(self at:index - 1 + destIndex)
+ newFloat basicAt:(9-destIndex) put:(self byteAt:(index - 1 + destIndex))
].
^ newFloat.
@@ -845,40 +1987,40 @@
* handle the most common cases fast ...
*/
if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(double)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(double)-1)) == 0) {
- if (__isFloat(aFloat)) {
- ((double *)cp)[0] = __floatVal(aFloat);
- RETURN (aFloat);
- }
- if (__isShortFloat(aFloat)) {
- ((double *)cp)[0] = (double)(__shortFloatVal(aFloat));
- RETURN (aFloat);
- }
- if (__isSmallInteger(aFloat)) {
- ((double *)cp)[0] = (double)(__intVal(aFloat));
- RETURN (aFloat);
- }
- }
- }
- }
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(double)-1)) < sz) {
+ cp += idx;
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(double)-1)) == 0) {
+ if (__isFloat(aFloat)) {
+ ((double *)cp)[0] = __floatVal(aFloat);
+ RETURN (aFloat);
+ }
+ if (__isShortFloat(aFloat)) {
+ ((double *)cp)[0] = (double)(__shortFloatVal(aFloat));
+ RETURN (aFloat);
+ }
+ if (__isSmallInteger(aFloat)) {
+ ((double *)cp)[0] = (double)(__intVal(aFloat));
+ RETURN (aFloat);
+ }
+ }
+ }
+ }
}
%}.
flt := aFloat asFloat.
1 to:8 do:[:srcIndex|
- self at:index - 1 + srcIndex put:(flt basicAt:srcIndex)
+ self byteAt:(index - 1 + srcIndex) put:(flt basicAt:srcIndex)
].
^ aFloat
!
@@ -895,12 +2037,12 @@
|flt|
msb == IsBigEndian ifTrue:[
- ^ self doubleAt:index put:aFloat.
+ ^ self doubleAt:index put:aFloat.
].
flt := aFloat asFloat.
1 to:8 do:[:srcIndex|
- self at:index - 1 + srcIndex put:(flt basicAt:(9-srcIndex))
+ self byteAt:(index - 1 + srcIndex) put:(flt basicAt:(9-srcIndex))
].
^ aFloat
@@ -925,33 +2067,33 @@
* handle the most common cases fast ...
*/
if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(float)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(float)-1)) == 0) {
- float fVal = ((float *)cp)[0];
- OBJ f;
-
- __qMKSFLOAT(f, fVal);
- RETURN (f);
- }
- }
- }
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(float)-1)) < sz) {
+ cp += idx;
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(float)-1)) == 0) {
+ float fVal = ((float *)cp)[0];
+ OBJ f;
+
+ __qMKSFLOAT(f, fVal);
+ RETURN (f);
+ }
+ }
+ }
}
%}.
newFloat := ShortFloat basicNew.
1 to:4 do:[:destIndex|
- newFloat basicAt:destIndex put:(self at:index - 1 + destIndex)
+ newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex))
].
^ newFloat.
!
@@ -969,12 +2111,12 @@
|newFloat|
msb == IsBigEndian ifTrue:[
- ^ self floatAt:index
+ ^ self floatAt:index
].
newFloat := ShortFloat basicNew.
1 to:4 do:[:destIndex|
- newFloat basicAt:(5-destIndex) put:(self at:index - 1 + destIndex)
+ newFloat basicAt:(5-destIndex) put:(self byteAt:(index - 1 + destIndex))
].
^ newFloat.
@@ -998,41 +2140,41 @@
* handle the most common cases fast ...
*/
if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(float)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(float)-1)) == 0) {
- if (__isShortFloat(aFloat)) {
- ((float *)cp)[0] = __shortFloatVal(aFloat);
- RETURN (self);
- }
- if (__isFloat(aFloat)) {
- ((float *)cp)[0] = (float)__floatVal(aFloat);
- RETURN (self);
- }
- if (__isSmallInteger(aFloat)) {
- ((float *)cp)[0] = (float)__intVal(aFloat);
- RETURN (self);
- }
- // bail out to smalltalk code
- }
- }
- }
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(float)-1)) < sz) {
+ cp += idx;
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(float)-1)) == 0) {
+ if (__isShortFloat(aFloat)) {
+ ((float *)cp)[0] = __shortFloatVal(aFloat);
+ RETURN (self);
+ }
+ if (__isFloat(aFloat)) {
+ ((float *)cp)[0] = (float)__floatVal(aFloat);
+ RETURN (self);
+ }
+ if (__isSmallInteger(aFloat)) {
+ ((float *)cp)[0] = (float)__intVal(aFloat);
+ RETURN (self);
+ }
+ // bail out to smalltalk code
+ }
+ }
+ }
}
%}.
sflt := aFloat asShortFloat.
1 to:4 do:[:srcIndex|
- self at:index - 1 + srcIndex put:(sflt basicAt:srcIndex)
+ self byteAt:index - 1 + srcIndex put:(sflt basicAt:srcIndex)
].
!
@@ -1048,13 +2190,13 @@
|sflt|
msb == IsBigEndian ifTrue:[
- self floatAt:index put:aFloat.
- ^ self.
+ self floatAt:index put:aFloat.
+ ^ self.
].
sflt := aFloat asShortFloat.
1 to:4 do:[:srcIndex|
- self at:index - 1 + srcIndex put:(sflt basicAt:(5-srcIndex))
+ self byteAt:(index - 1 + srcIndex) put:(sflt basicAt:(5-srcIndex))
].
"Created: / 15.5.1998 / 17:20:41 / cg"
@@ -1143,7 +2285,7 @@
!UninterpretedBytes methodsFor:'accessing-longlongs (64bit)'!
-longLongAt:index
+signedInt64At:index
"return the 8-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machines natural byte order.
@@ -1151,17 +2293,17 @@
|w|
- w := self unsignedLongLongAt:index bigEndian:IsBigEndian.
+ w := self unsignedInt64At:index bigEndian:IsBigEndian.
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[
- ^ w - (16r10000000000000000)
+ ^ w - (16r10000000000000000)
].
^ w
"
|b|
b := ByteArray new:4.
- b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF.
- (b longLongAt:1)
+ b unsignedInt64At:1 put:16rFFFFFFFFFFFFFFFF.
+ (b signedInt64At:1)
"
"Modified: / 1.7.1996 / 21:11:28 / cg"
@@ -1169,7 +2311,7 @@
"Modified: / 5.3.1998 / 14:58:32 / stefan"
!
-longLongAt:index bigEndian:msb
+signedInt64At:index MSB:msb
"return the 8-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the given byte order.
@@ -1177,9 +2319,9 @@
|w|
- w := self unsignedLongLongAt:index bigEndian:msb.
+ w := self unsignedInt64At:index MSB:msb.
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[
- ^ w - (16r10000000000000000)
+ ^ w - (16r10000000000000000)
].
^ w
@@ -1195,7 +2337,15 @@
"Modified: / 9.5.1998 / 01:10:59 / cg"
!
-longLongAt:byteIndex put:anInteger
+signedInt64At:byteIndex put:anInteger
+ "store a signed longLong (64bit) integer.
+ The index is a smalltalk index (i.e. 1-based).
+ Same as #signedQuadWordAt:put: - for ST80 compatibility."
+
+ ^ self signedInt64At:byteIndex put:anInteger MSB:IsBigEndian
+!
+
+signedInt64At:byteIndex put:anInteger MSB:msb
"store a signed longLong (64bit) integer.
The index is a smalltalk index (i.e. 1-based).
Same as #signedQuadWordAt:put: - for ST80 compatibility."
@@ -1204,30 +2354,35 @@
v := anInteger.
anInteger < 0 ifTrue:[
- v := v + 16r10000000000000000
+ v := v + 16r10000000000000000
].
- ^ self unsignedLongLongAt:byteIndex put:v
-!
-
-longLongAt:byteIndex put:anInteger bigEndian:msb
- "store a signed longLong (64bit) integer.
- The index is a smalltalk index (i.e. 1-based).
- Same as #signedQuadWordAt:put: - for ST80 compatibility."
-
- |v|
-
- v := anInteger.
- anInteger < 0 ifTrue:[
- v := v + 16r10000000000000000
- ].
- ^ self unsignedLongLongAt:byteIndex put:v bigEndian:msb
+ self unsignedInt64At:byteIndex put:v MSB:msb.
+ ^ anInteger
"Created: / 9.5.1998 / 01:10:24 / cg"
"Modified: / 9.5.1998 / 01:13:34 / cg"
!
-quadWordAt:index MSB:msb
- "return the 8-bytes starting at index as an (unsigned) Integer.
+unsignedInt64At:byteIndex
+ "return the 8-bytes starting at index in the machine's native
+ byteorder as an unsigned integer.
+ The index is a smalltalk index (i.e. 1-based)"
+
+ ^ self unsignedInt64At:byteIndex MSB:IsBigEndian
+
+ "
+ |b|
+
+ b := ByteArray withAll:#(1 2 3 4 5 6 7 8).
+ (b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16
+ "
+
+ "Modified: / 5.11.1996 / 14:06:21 / cg"
+ "Modified: / 5.3.1998 / 14:04:44 / stefan"
+!
+
+unsignedInt64At:byteIndex MSB:msb
+ "return the 8-bytes starting at index as an unsigned integer.
The index is a smalltalk index (i.e. 1-based).
Depending on msb, the value is retrieved MSB or LSB-first."
@@ -1237,82 +2392,15 @@
l := LargeInteger basicNew numberOfDigits:8.
msb ifTrue:[
- bIdx := index + 7.
- delta := -1
+ bIdx := byteIndex + 7.
+ delta := -1
] ifFalse:[
- bIdx := index.
- delta := 1
+ bIdx := byteIndex.
+ delta := 1
].
1 to:8 do:[:i |
- l digitAt:i put:(self basicAt:bIdx).
- bIdx := bIdx + delta
- ].
- ^ l compressed
-
- "
- |b|
-
- b := ByteArray withAll:#(1 2 3 4 5 6 7 8).
- (b quadWordAt:1 MSB:false) printStringRadix:16
- "
-
- "Modified: 5.11.1996 / 14:06:21 / cg"
-!
-
-quadWordAt:index put:anInteger MSB:msb
- "set the 8-bytes starting at index from the (unsigned) Integer value.
- The index is a smalltalk index (i.e. 1-based).
- The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
- Depending on msb, the value is stored MSB-first or LSB-first."
-
- |bIdx "{ Class: SmallInteger }"
- delta "{ Class: SmallInteger }"|
-
- ((anInteger < 0) or:[anInteger > 16rFFFFFFFFFFFFFFFF]) ifTrue:[
- ^ self elementBoundsError:anInteger
- ].
-
- msb ifTrue:[
- bIdx := index + 7.
- delta := -1
- ] ifFalse:[
- bIdx := index.
- delta := 1
- ].
- 1 to:8 do:[:i |
- self basicAt:bIdx put:(anInteger digitAt:i).
- bIdx := bIdx + delta.
- ].
- ^ anInteger
-
- "
- |b|
- b := ByteArray new:8.
- b quadWordAtIndex:1 put:16r0807060504030201 MSB:false.
- b inspect
- "
-!
-
-unsignedLongLongAt:index bigEndian:msb
- "return the 8-bytes starting at index as an (unsigned) Integer.
- The index is a smalltalk index (i.e. 1-based).
- Depending on msb, the value is retrieved MSB or LSB-first."
-
- |l
- bIdx "{ Class: SmallInteger }"
- delta "{ Class: SmallInteger }"|
-
- l := LargeInteger basicNew numberOfDigits:8.
- msb ifTrue:[
- bIdx := index + 7.
- delta := -1
- ] ifFalse:[
- bIdx := index.
- delta := 1
- ].
- 1 to:8 do:[:i |
- l digitAt:i put:(self basicAt:bIdx).
- bIdx := bIdx + delta
+ l digitAt:i put:(self byteAt:bIdx).
+ bIdx := bIdx + delta
].
^ l compressed
@@ -1327,19 +2415,26 @@
"Modified: / 5.3.1998 / 14:04:44 / stefan"
!
-unsignedLongLongAt:index put:anInteger
+unsignedInt64At:byteIndex put:anInteger
"set the 8-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
- The value is stored in natural byte order."
-
- ^ self unsignedLongLongAt:index put:anInteger bigEndian:IsBigEndian
-
- "Created: / 5.3.1998 / 14:44:00 / stefan"
- "Modified: / 5.3.1998 / 15:02:32 / stefan"
+ The value is stored in the machine's natural byteorder."
+
+ ^ self unsignedInt64At:byteIndex put:anInteger MSB:IsBigEndian
+
+ "
+ |b|
+ b := ByteArray new:10.
+ b unsignedInt64At:1 put:16r0807060504030201 MSB:false.
+ b unsignedInt64At:1 put:16r0807060504030201 MSB:true.
+ b inspect
+ "
+
+ "Created: / 5.3.1998 / 14:06:02 / stefan"
!
-unsignedLongLongAt:index put:anInteger bigEndian:msb
+unsignedInt64At:byteIndex put:anInteger MSB:msb
"set the 8-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
@@ -1349,19 +2444,19 @@
delta "{ Class: SmallInteger }"|
((anInteger < 0) or:[anInteger > 16rFFFFFFFFFFFFFFFF]) ifTrue:[
- ^ self elementBoundsError:anInteger
+ ^ self elementBoundsError:anInteger
].
msb ifTrue:[
- bIdx := index + 7.
- delta := -1
+ bIdx := byteIndex + 7.
+ delta := -1
] ifFalse:[
- bIdx := index.
- delta := 1
+ bIdx := byteIndex.
+ delta := 1
].
1 to:8 do:[:i |
- self basicAt:bIdx put:(anInteger digitAt:i).
- bIdx := bIdx + delta.
+ self byteAt:bIdx put:(anInteger digitAt:i).
+ bIdx := bIdx + delta.
].
^ anInteger
@@ -1377,527 +2472,6 @@
!UninterpretedBytes methodsFor:'accessing-longs (32bit)'!
-doubleWordAt:index
- "return the 4-bytes starting at index as an (unsigned) Integer.
- The index is a smalltalk index (i.e. 1-based).
- The value is retrieved in the machines natural byte order."
-
- ^ self doubleWordAt:index MSB:IsBigEndian
-
- "
- |b|
-
- b := ByteArray withAll:#(1 2 3 4).
- (b doubleWordAt:1) printStringRadix:16
- "
-
- "Modified: / 5.3.1998 / 14:57:35 / stefan"
-!
-
-doubleWordAt:index MSB:msb
- "return the 4-bytes starting at index as an (unsigned) Integer.
- The index is a smalltalk index (i.e. 1-based).
- The value is retrieved MSB-first, if the msb-arg is true;
- LSB-first otherwise."
-
- |val
- ival "{ Class: SmallInteger }"
- t "{ Class: SmallInteger }"
- i "{ Class: SmallInteger }"
- b1 "{ Class: SmallInteger }"
- b2 "{ Class: SmallInteger }"
- b3 "{ Class: SmallInteger }"
- b4 "{ Class: SmallInteger }"|
-
-%{
- /*
- * handle the most common cases fast ...
- */
- if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
- unsigned int iVal;
-
- if ((idx+(sizeof(int)-1)) < sz) {
- cp += idx;
-
- if (msb == true) {
-#if defined(__MSBFIRST__)
- if (((INT)cp & (sizeof(int)-1))== 0) {
- /*
- * aligned
- */
- iVal = ((unsigned int *)cp)[0];
- } else
-#endif
- {
- iVal = cp[0];
- iVal = (iVal << 8) | cp[1];
- iVal = (iVal << 8) | cp[2];
- iVal = (iVal << 8) | cp[3];
- }
- } else {
-#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__))
- /*
- * aligned or not - we dont care
- * (i386 can fetch unaligned)
- */
- iVal = ((unsigned int *)cp)[0];
-#else
-# if defined(__LSBFIRST__)
- if (((INT)cp & (sizeof(int)-1))== 0) {
- /*
- * aligned
- */
- iVal = ((unsigned int *)cp)[0];
- } else
-# endif
- {
- iVal = cp[3];
- iVal = (iVal << 8) | cp[2];
- iVal = (iVal << 8) | cp[1];
- iVal = (iVal << 8) | cp[0];
- }
-#endif
- }
-#if __POINTER_SIZE__ == 8
- RETURN (__mkSmallInteger(iVal));
-#else
- RETURN (__MKUINT(iVal));
-#endif
- }
- }
- }
-%}.
-
- "/ fallBack code - non ByteArray-like receiver
- "/ or funny index
-
- i := index.
- b1 := self byteAt:i.
- b2 := self byteAt:(i+1).
- b3 := self byteAt:(i+2).
- b4 := self byteAt:(i+3).
-
- msb ifFalse:[
- t := b4. b4 := b1. b1 := t.
- t := b3. b3 := b2. b2 := t.
- ].
- ival := b1.
- ival := (ival bitShift:8) + b2.
- ival := (ival bitShift:8) + b3.
- val := (ival bitShift:8) + b4.
- ^ val
-
- "
- |b|
-
- b := ByteArray withAll:#(1 2 3 4).
- (b doubleWordAt:1 MSB:true) printStringRadix:16.
- (b doubleWordAt:1 MSB:false) printStringRadix:16
- "
-!
-
-doubleWordAt:index put:value
- "set the 4-bytes starting at index from the (unsigned) Integer value.
- The index is a smalltalk index (i.e. 1-based).
- The value should be in the range 0 to 16rFFFFFFFF
- (for negative values, the stored value is not defined).
- The value is stored in the machines natural byte order."
-
- ^ self doubleWordAt:index put:value MSB:IsBigEndian
-
- "
- |b|
- b := ByteArray new:4.
- b doubleWordAt:1 put:16r04030201.
- b inspect
- "
-
- "Modified: / 5.3.1998 / 14:57:48 / stefan"
-!
-
-doubleWordAt:index put:aNumber MSB:msb
- "set the 4-bytes starting at index from the (unsigned) Integer value.
- The index is a smalltalk index (i.e. 1-based).
- The value must be in the range 0 to 16rFFFFFFFF.
- The value is stored MSB-first if msb is true; LSB-first otherwise."
-
- |i "{ Class: SmallInteger }" |
-
- ((aNumber < 0) or:[aNumber > 16rFFFFFFFF]) ifTrue:[
- ^ self elementBoundsError:aNumber
- ].
-
- i := index.
- msb ifTrue:[
- self byteAt:i put:(aNumber digitAt:4).
- self byteAt:(i+1) put:(aNumber digitAt:3).
- self byteAt:(i+2) put:(aNumber digitAt:2).
- self byteAt:(i+3) put:(aNumber digitAt:1).
- ] ifFalse:[
- self byteAt:i put:(aNumber digitAt:1).
- self byteAt:(i+1) put:(aNumber digitAt:2).
- self byteAt:(i+2) put:(aNumber digitAt:3).
- self byteAt:(i+3) put:(aNumber digitAt:4).
- ].
- ^ aNumber
-
- "
- |b|
- b := ByteArray new:8.
- b doubleWordAt:1 put:16r04030201 MSB:true.
- b doubleWordAt:5 put:16r04030201 MSB:false.
- b inspect
- "
-
- "Modified: / 21.1.1998 / 17:43:34 / cg"
- "Modified: / 5.3.1998 / 11:42:17 / stefan"
-!
-
-doubleWordAtDoubleWordIndex:index
- "return the unsigned long at index, anInteger.
- Fetching in the machines natural byte order.
- Indices are 1-based and scaled as appropriate to allow
- accessing the memory as an array of doubleWord entries.
- (i.e. indices are 1, 2, ...)"
-
- ^ self doubleWordAtDoubleWordIndex:index MSB:IsBigEndian
-
- "Created: / 21.1.1998 / 17:43:53 / cg"
- "Modified: / 5.3.1998 / 14:58:06 / stefan"
-!
-
-doubleWordAtDoubleWordIndex:index MSB:msb
- "return the unsigned long at index, anInteger.
- Fetching is MSB if msb is true, LSB otherwise.
- Indices are 1-based and scaled as appropriate to allow
- accessing the memory as an array of doubleWord entries.
- (i.e. indices are 1, 2, ...)"
-
- ^ self doubleWordAt:(index - 1 * 4 + 1) MSB:msb
-
- "Created: / 21.1.1998 / 17:44:07 / cg"
-!
-
-doubleWordAtDoubleWordIndex:index put:value
- "set the long at index, anInteger.
- Storing in the machines natural byte order.
- Indices are 1-based and scaled as appropriate to allow
- accessing the memory as an array of doubleWord entries.
- (i.e. indices are 1, 2, ...)"
-
- ^ self doubleWordAtDoubleWordIndex:index put:value MSB:IsBigEndian
-
- "Created: / 21.1.1998 / 17:44:13 / cg"
- "Modified: / 5.3.1998 / 14:58:19 / stefan"
-!
-
-doubleWordAtDoubleWordIndex:index put:value MSB:msb
- "set the long at index, anInteger.
- Storing is MSB if msb is true, LSB otherwise.
- Indices are 1-based and scaled as appropriate to allow
- accessing the memory as an array of doubleWord entries.
- (i.e. indices are 1, 2, ...)"
-
- ^ self doubleWordAt:(index - 1 * 4 + 1) put:value MSB:msb
-
- "Created: / 21.1.1998 / 17:44:19 / cg"
-!
-
-longAt:index
- "return the 4-bytes starting at index as a signed Integer.
- The index is a smalltalk index (i.e. 1-based).
- The value is retrieved in the machines natural byte order,
- therefore, this should only be used for byte-data which is
- only used inside this machine.
- To setup data packets which are to be sent to other machines,
- or stored into a file, always use longAt:MSB: and specify
- a definite byteOrder."
-
- |w|
-
-%{
- /*
- * handle the most common cases fast ...
- */
- if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(int)-1)) < sz) {
- cp += idx;
-#if defined(__i386__)
- /*
- * aligned or not, we dont care (i386 can do both)
- */
- {
- int iVal = ((int *)cp)[0];
-
- RETURN (__MKINT(iVal));
- }
-#else
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(int)-1)) == 0) {
- int iVal = ((int *)cp)[0];
-
-# if __POINTER_SIZE__ == 8
- RETURN (__mkSmallInteger(iVal));
-# else
- RETURN (__MKINT(iVal));
-# endif
- }
-#endif
- }
- }
- }
-%}.
-
- w := self unsignedLongAt:index.
- (w > (16r7FFFFFFF)) ifTrue:[
- ^ w - (16r100000000)
- ].
- ^ w
-
- "
- |b|
- b := ByteArray new:4.
- b unsignedLongAt:1 put:16rFFFFFFFF.
- (b longAt:1)
- "
-
- "Modified: / 1.7.1996 / 21:11:28 / cg"
- "Modified: / 5.3.1998 / 12:06:28 / stefan"
-!
-
-longAt:index bigEndian:msb
- "return the 4-bytes starting at index as a signed Integer.
- The index is a smalltalk index (i.e. 1-based).
- Depending on msb, the value is retrieved MSB-first or LSB-first.
- This may be worth a primitive."
-
- |w|
-
- w := self unsignedLongAt:index bigEndian:msb.
- (w > (16r7FFFFFFF)) ifTrue:[
- ^ w - (16r100000000)
- ].
- ^ w
-
- "
- |b|
- b := ByteArray new:4.
- b unsignedLongAt:1 put:16rFFFFFFFF.
- (b longAt:1)
- "
-
- "Modified: / 1.7.1996 / 21:11:33 / cg"
- "Created: / 5.3.1998 / 14:02:03 / stefan"
-!
-
-longAt:index put:value
- "set the 4-bytes starting at index from the signed Integer value.
- The index is a smalltalk index (i.e. 1-based).
- The value is stored in the machines natural byte order.
- This may be worth a primitive.
-
- This is the ST80 version of #signedDoubleWordAt:put:"
-
- |v|
-
-%{
- /*
- * handle the most common cases fast ...
- */
- if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(int)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(int)-1)) == 0) {
- INT __v;
-
- if (__isSmallInteger(value)) {
- // how about a range check?
- ((int *)cp)[0] = (int)(__intVal(value));
- RETURN (value);
- }
-# if __POINTER_SIZE__ == 4
- if ((__v = __signedLongIntVal(value)) != 0) {
- // how about a range check?
- ((int *)cp)[0] = (int)(__v);
- RETURN (value);
- }
-#endif
- }
- }
- }
- }
-%}.
-
- value >= 0 ifTrue:[
- v := value
- ] ifFalse:[
- v := value + 16r100000000
- ].
- self unsignedLongAt:index put:v.
- ^ value
-
- "
- |b|
- b := ByteArray new:4.
- b longAt:1 put:-1.
- (b unsignedLongAt:1) printStringRadix:16
- "
-
- "Modified: / 1.7.1996 / 21:11:39 / cg"
- "Created: / 5.3.1998 / 10:57:18 / stefan"
-!
-
-longAt:byteIndex put:anInteger bigEndian:msb
- "store a signed long (32bit) integer.
- The index is a smalltalk index (i.e. 1-based).
- Same as #signedQuadWordAt:put: - for ST80 compatibility."
-
- |v|
-
- v := anInteger.
- anInteger < 0 ifTrue:[
- v := v + 16r100000000
- ].
- ^ self unsignedLongAt:byteIndex put:v bigEndian:msb
-
- "Created: / 9.5.1998 / 01:10:24 / cg"
- "Modified: / 9.5.1998 / 01:13:34 / cg"
-!
-
-nativeIntAt:index
- "return the 4- or 8-bytes (depending on the native integer/pointer size) starting at index as a signed Integer.
- The index is a smalltalk index (i.e. 1-based).
- The value is retrieved in the machines natural byte order,
- therefore, this should only be used for byte-data which is
- only used inside this machine."
-
- |w|
-
-%{
- /*
- * handle the most common cases fast ...
- */
- if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(INT)-1)) < sz) {
- cp += idx;
-#if defined(__i386__)
- /*
- * aligned or not, we dont care (i386 can do both)
- */
- {
- INT iVal = ((INT *)cp)[0];
-
- RETURN (__MKINT(iVal));
- }
-#else
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(INT)-1)) == 0) {
- INT iVal = ((INT *)cp)[0];
-
- RETURN (__MKINT(iVal));
- }
-#endif
- }
- }
- }
-%}.
-
- ^ self primitiveFailed.
-
- "
- |b|
- b := ByteArray new:8.
- b nativeIntAt:1 put:SmallInteger maxVal.
- b nativeIntAt:1
- "
-!
-
-nativeIntAt:index put:value
- "set the 4- or 8-bytes (depending on INT-/pointer size) starting at index from the signed Integer value.
- The index is a smalltalk index (i.e. 1-based).
- The value is stored in the machines natural byte order."
-
- |v|
-
-%{
- /*
- * handle the most common cases fast ...
- */
- if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(INT)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(INT)-1)) == 0) {
- INT __v;
-
- if (__isSmallInteger(value)) {
- // how about a range check?
- ((INT *)cp)[0] = (INT)(__intVal(value));
- RETURN (value);
- }
- if ((__v = __signedLongIntVal(value)) != 0) {
- // how about a range check?
- ((INT *)cp)[0] = (INT)(__v);
- RETURN (value);
- }
- }
- }
- }
- }
-%}.
- ^ self primitiveFailed.
-
- "
- |b|
- b := ByteArray new:8.
- b nativeIntAt:1 put:SmallInteger maxVal.
- (b nativeIntAt:1)
- "
-!
-
pointerAt:index
"get a pointer starting at index as ExternalAddress.
The index is a smalltalk index (i.e. 1-based).
@@ -2076,60 +2650,107 @@
"
!
-signedDoubleWordAt:index
- "return the 4-bytes starting at index as a signed Integer.
+signedInt32At:byteIndex
+ "return the 4-bytes starting at byteIndex as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
- The value is retrieved in the machines natural byte order.
- This may be worth a primitive."
-
- ^ self signedDoubleWordAt:index MSB:IsBigEndian
+ The value is retrieved in the machine's natural byte order,
+ therefore, this should only be used for byte-data which is
+ only used inside this machine.
+ To setup data packets which are to be sent to other machines,
+ or stored into a file, always use longAt:MSB: and specify
+ a definite byteOrder."
+
+ |w|
+
+%{
+ /*
+ * handle the most common cases fast ...
+ */
+ if (__isSmallInteger(byteIndex)) {
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
+
+ if ((idx+(sizeof(int)-1)) < sz) {
+ cp += idx;
+#if defined(__i386__)
+ /*
+ * aligned or not, we dont care (i386 can do both)
+ */
+ {
+ int iVal = ((int *)cp)[0];
+
+ RETURN (__MKINT(iVal));
+ }
+#else
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(int)-1)) == 0) {
+ int iVal = ((int *)cp)[0];
+
+# if __POINTER_SIZE__ == 8
+ RETURN (__mkSmallInteger(iVal));
+# else
+ RETURN (__MKINT(iVal));
+# endif
+ }
+#endif
+ }
+ }
+ }
+%}.
+
+ w := self unsignedLongAt:byteIndex.
+ (w > (16r7FFFFFFF)) ifTrue:[
+ ^ w - (16r100000000)
+ ].
+ ^ w
"
|b|
b := ByteArray new:4.
- b doubleWordAt:1 put:16rFFFFFFFF.
- (b signedDoubleWordAt:1)
- "
+ b unsignedLongAt:1 put:16rFFFFFFFF.
+ (b longAt:1)
"
- |b|
- b := ByteArray new:4.
- b signedDoubleWordAt:1 put:-1.
- (b doubleWordAt:1)
- "
-
- "Modified: 1.7.1996 / 21:11:28 / cg"
+
+ "Modified: / 1.7.1996 / 21:11:28 / cg"
+ "Modified: / 5.3.1998 / 12:06:28 / stefan"
!
-signedDoubleWordAt:index MSB:msb
- "return the 4-bytes starting at index as a (signed) Integer.
- The index is a smalltalk index (i.e. 1-based).
+signedInt32At:byteIndex MSB:msb
+ "return the 4-bytes starting at byteIndex as a (signed) Integer.
+ The byteIndex is a smalltalk index (i.e. 1-based).
The value is retrieved MSB-first, if the msb-arg is true;
LSB-first otherwise."
|val
ival "{ Class: SmallInteger }"
- t "{ Class: SmallInteger }"
i "{ Class: SmallInteger }"
- b1 "{ Class: SmallInteger }"
- b2 "{ Class: SmallInteger }"
- b3 "{ Class: SmallInteger }"
- b4 "{ Class: SmallInteger }"|
+ bHH "{ Class: SmallInteger }"
+ bHL "{ Class: SmallInteger }"
+ bLH "{ Class: SmallInteger }"
+ bLL "{ Class: SmallInteger }"|
%{
/*
* handle the most common cases fast ...
*/
- if (__isSmallInteger(index)) {
+ if (__isSmallInteger(byteIndex)) {
unsigned char *cp;
INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
int iVal;
+ cp += idx;
+
if ((idx+(sizeof(int)-1)) < sz) {
- cp += idx;
if (msb == true) {
#if defined(__MSBFIRST__)
@@ -2149,7 +2770,7 @@
} else {
#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__))
/*
- * aligned or not - we dont care
+ * aligned or not - we don't care
* (i386 can fetch unaligned)
*/
iVal = ((int *)cp)[0];
@@ -2181,22 +2802,23 @@
%}.
"/ fallBack code - non ByteArray-like receiver
- "/ or funny index
-
- i := index.
- b1 := self byteAt:i.
- b2 := self byteAt:(i+1).
- b3 := self byteAt:(i+2).
- b4 := self byteAt:(i+3).
-
+ "/ or funny byteIndex
+
+ i := byteIndex.
msb ifFalse:[
- t := b4. b4 := b1. b1 := t.
- t := b3. b3 := b2. b2 := t.
+ bLL := self byteAt:i.
+ bLH := self byteAt:(i+1).
+ bHL := self byteAt:(i+2).
+ bHH := self byteAt:(i+3).
+ ] ifTrue:[
+ bHH := self byteAt:i.
+ bHL := self byteAt:(i+1).
+ bLH := self byteAt:(i+2).
+ bLL := self byteAt:(i+3).
].
- ival := b1.
- ival := (ival bitShift:8) + b2.
- ival := (ival bitShift:8) + b3.
- val := (ival bitShift:8) + b4.
+ ival := (bHH bitShift:8) + bHL.
+ ival := (ival bitShift:8) + bLH.
+ val := (ival bitShift:8) + bLL.
(val > (16r7FFFFFFF)) ifTrue:[
^ val - (16r100000000)
@@ -2207,261 +2829,319 @@
|b|
b := ByteArray withAll:#(1 2 3 4).
- (b signedDoubleWordAt:1 MSB:true) printStringRadix:16.
- (b signedDoubleWordAt:1 MSB:false) printStringRadix:16
+ (b signedInt32At:1 MSB:true) printStringRadix:16.
+ (b signedInt32At:1 MSB:false) printStringRadix:16
"
!
-signedDoubleWordAt:index put:value
- "set the 4-bytes starting at index from the signed Integer value.
+signedInt32At:byteIndex put:anInteger
+ "set the 4-bytes starting at index from the signed Integer anInteger.
The index is a smalltalk index (i.e. 1-based).
- The value is stored in the machines natural byte order.
- This may be worth a primitive."
-
- |v|
-
- value >= 0 ifTrue:[
- v := value
- ] ifFalse:[
- v := value + 16r100000000
- ].
- self doubleWordAt:index put:v.
- ^ value
+ The integer is stored in the machine's natural byte order."
+
+ ^ self signedInt32At:byteIndex put:anInteger MSB:IsBigEndian
"
|b|
b := ByteArray new:4.
- b signedDoubleWordAt:1 put:-1.
- (b doubleWordAt:1) printStringRadix:16
+ b longAt:1 put:-1.
+ (b unsignedLongAt:1) printStringRadix:16
"
- "Modified: 1.7.1996 / 21:11:39 / cg"
+ "Modified: / 1.7.1996 / 21:11:39 / cg"
+ "Created: / 5.3.1998 / 10:57:18 / stefan"
!
-signedDoubleWordAt:index put:value MSB:msb
- "set the 4-bytes starting at index from the signed Integer value.
- The index is a smalltalk index (i.e. 1-based).
- Depending on msb, the value is stored MSB-first or LSB-first.
- This may be worth a primitive."
+signedInt32At:byteIndex put:anInteger MSB:msb
+ "set the 4-bytes starting at byteIndex from the signed Integer value.
+ The byteIndex is a smalltalk index (i.e. 1-based).
+ The value is stored in the machines natural byte order.
+ This may be worth a primitive.
+
+ This is the ST80 version of #signedDoubleWordAt:put:"
|v|
- value >= 0 ifTrue:[
- v := value
+%{
+ /*
+ * handle the most common case fast ...
+ */
+ if (__isSmallInteger(byteIndex)) {
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
+
+ if ((idx+3) < sz) {
+ cp += idx;
+
+ if (__isSmallInteger(anInteger)) {
+ INT __v = __intVal(anInteger);
+
+# if __POINTER_SIZE__ == 8
+ if ((__v < -0x80000000L) || (__v > 0x7FFFFFFF)) {
+ goto badArg;
+ }
+# endif
+ if (((INT)cp & 3) == 0) {
+ /*
+ * aligned
+ */
+ if (
+# ifdef __LSBFIRST__
+ (msb == false)
+# else
+# ifdef __MSBFIRST__
+ (msb == true)
+# else
+ (0)
+# endif
+# endif
+ ) {
+ ((int *)cp)[0] = (int)__v;
+ RETURN (anInteger);
+ }
+ }
+ if (msb == false) {
+ cp[0] = __v & 0xFF;
+ cp[1] = (__v>>8) & 0xFF;
+ cp[2] = (__v>>16) & 0xFF;
+ cp[3] = (__v>>24) & 0xFF;
+ } else {
+ cp[0] = (__v>>24) & 0xFF;
+ cp[1] = (__v>>16) & 0xFF;
+ cp[2] = (__v>>8) & 0xFF;
+ cp[3] = __v & 0xFF;
+ }
+ RETURN (anInteger);
+ }
+ }
+ }
+ }
+ badArg: ;
+%}.
+
+ anInteger >= 0 ifTrue:[
+ v := anInteger
] ifFalse:[
- v := value + 16r100000000
+ v := anInteger + 16r100000000
].
- self doubleWordAt:index put:v MSB:msb.
- ^ value
+ self unsignedInt32At:byteIndex put:v MSB:msb.
+ ^ anInteger
"
|b|
b := ByteArray new:4.
- b signedDoubleWordAt:1 put:-1.
- (b doubleWordAt:1) printStringRadix:16
+ b longAt:1 put:-1.
+ (b unsignedLongAt:1) printStringRadix:16
"
- "Modified: 1.7.1996 / 21:11:46 / cg"
+ "Modified: / 1.7.1996 / 21:11:39 / cg"
+ "Created: / 5.3.1998 / 10:57:18 / stefan"
!
-unsignedLongAt:index
+unsignedInt32At:byteIndex
"return the 4-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
- The value is retrieved in the machine's natural byte order.
- Subclasses may redefine this for better performance.
- Same as doubleWordAt: for protocol completeness"
-
- ^ self doubleWordAt:index MSB:IsBigEndian
-
- "
- |b|
-
- b := ByteArray withAll:#(1 2 3 4).
- (b unsignedLongAt:1) printStringRadix:16
- "
-
- "Created: / 5.3.1998 / 11:56:53 / stefan"
- "Modified: / 5.3.1998 / 14:58:48 / stefan"
-!
-
-unsignedLongAt:index bigEndian:msb
- "return the 4-bytes starting at index as an (unsigned) Integer.
- The index is a smalltalk index (i.e. 1-based).
- The value is retrieved MSB-first, if the msb-arg is true;
- LSB-first otherwise.
- Subclasses may redefine this for better performance.
- Same as doubleWordAt:MSB: for protocol completeness"
-
- ^ self doubleWordAt:index MSB:msb
+ The value is retrieved in the machines natural byte order."
+
+ ^ self unsignedInt32At:byteIndex MSB:IsBigEndian
"
|b|
b := ByteArray withAll:#(1 2 3 4).
- (b unsignedLongAt:1 bigEndian:true) printStringRadix:16.
- (b unsignedLongAt:1 bigEndian:false) printStringRadix:16
+ (b unsignedInt32At:1) printStringRadix:16
"
- "Modified: / 21.1.1998 / 17:42:30 / cg"
- "Created: / 5.3.1998 / 11:46:05 / stefan"
+ "Modified: / 5.3.1998 / 14:57:35 / stefan"
!
-unsignedLongAt:index put:value
- "set the 4-bytes starting at index from the (unsigned) Integer value.
+unsignedInt32At:byteIndex MSB:msb
+ "return the 4-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
- The value should be in the range 0 to 16rFFFFFFFF
- (for negative values, the stored value is not defined).
- The value is stored in the machines natural byte order.
- Subclasses may redefine this for better performance.
- Same as doubleWordAt:put: for protocol completeness"
-
- ^ self doubleWordAt:index put:value
+ The value is retrieved MSB-first, if the msb-arg is true;
+ LSB-first otherwise."
+
+ |val
+ ival "{ Class: SmallInteger }"
+ i "{ Class: SmallInteger }"
+ bHH "{ Class: SmallInteger }"
+ bHL "{ Class: SmallInteger }"
+ bLH "{ Class: SmallInteger }"
+ bLL "{ Class: SmallInteger }"|
+
+%{
+ /*
+ * handle the most common cases fast ...
+ */
+ if (__isSmallInteger(byteIndex)) {
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
+ unsigned int iVal;
+
+ if ((idx+(sizeof(int)-1)) < sz) {
+ cp += idx;
+
+ if (msb == true) {
+#if defined(__MSBFIRST__)
+ if (((INT)cp & (sizeof(int)-1))== 0) {
+ /*
+ * aligned
+ */
+ iVal = ((unsigned int *)cp)[0];
+ } else
+#endif
+ {
+ iVal = cp[0];
+ iVal = (iVal << 8) | cp[1];
+ iVal = (iVal << 8) | cp[2];
+ iVal = (iVal << 8) | cp[3];
+ }
+ } else {
+#if defined(__i386__) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST__))
+ /*
+ * aligned or not - we dont care
+ * (i386 can fetch unaligned)
+ */
+ iVal = ((unsigned int *)cp)[0];
+#else
+# if defined(__LSBFIRST__)
+ if (((INT)cp & (sizeof(int)-1))== 0) {
+ /*
+ * aligned
+ */
+ iVal = ((unsigned int *)cp)[0];
+ } else
+# endif
+ {
+ iVal = cp[3];
+ iVal = (iVal << 8) | cp[2];
+ iVal = (iVal << 8) | cp[1];
+ iVal = (iVal << 8) | cp[0];
+ }
+#endif
+ }
+#if __POINTER_SIZE__ == 8
+ RETURN (__mkSmallInteger(iVal));
+#else
+ RETURN (__MKUINT(iVal));
+#endif
+ }
+ }
+ }
+%}.
+
+ "/ fallBack code - non ByteArray-like receiver
+ "/ or funny byteIndex
+
+ i := byteIndex.
+ msb ifFalse:[
+ bLL := self byteAt:i.
+ bLH := self byteAt:(i+1).
+ bHL := self byteAt:(i+2).
+ bHH := self byteAt:(i+3).
+ ] ifTrue:[
+ bHH := self byteAt:i.
+ bHL := self byteAt:(i+1).
+ bLH := self byteAt:(i+2).
+ bLL := self byteAt:(i+3).
+ ].
+ ival := (bHH bitShift:8) + bHL.
+ ival := (ival bitShift:8) + bLH.
+ val := (ival bitShift:8) + bLL.
+ ^ val
"
|b|
- b := ByteArray new:4.
- b unsignedLongAt:1 put:16r04030201.
- b inspect
+
+ b := ByteArray withAll:#(1 2 3 4).
+ (b unsignedInt32At:1 MSB:true) printStringRadix:16.
+ (b unsignedInt32At:1 MSB:false) printStringRadix:16
"
-
- "Created: / 5.3.1998 / 11:57:44 / stefan"
- "Modified: / 5.3.1998 / 14:58:59 / stefan"
!
-unsignedLongAt:index put:aNumber bigEndian:msb
- "set the 4-bytes starting at index from the (unsigned) Integer value.
+unsignedInt32At:byteIndex put:anInteger
+ "set the 4-bytes starting at index from the (unsigned) integer value.
The index is a smalltalk index (i.e. 1-based).
The value must be in the range 0 to 16rFFFFFFFF.
- The value is stored MSB-first if msb is true; LSB-first otherwise.
- Subclasses may redefine this for better performance.
- Same as doubleWordAt:put:MSB: for protocol completeness"
-
- ^ self doubleWordAt:index put:aNumber MSB:msb
+ The value is stored in the machine's native byte order"
+
+ ^ self unsignedInt32At:byteIndex put:anInteger MSB:IsBigEndian
"
|b|
b := ByteArray new:8.
- b unsignedLongAt:1 put:16r04030201 bigEndian:true.
- (b unsignedLongAt:1 bigEndian:false) printStringRadix:16
+ b doubleWordAt:1 put:16r04030201 MSB:true.
+ b doubleWordAt:5 put:16r04030201 MSB:false.
+ b inspect
"
"Modified: / 21.1.1998 / 17:43:34 / cg"
- "Created: / 5.3.1998 / 11:43:53 / stefan"
- "Modified: / 5.3.1998 / 11:47:30 / stefan"
-! !
-
-!UninterpretedBytes methodsFor:'accessing-shorts (16bit)'!
-
-shortAt:index
- "return the 2-bytes starting at index as a signed Integer.
+ "Modified: / 5.3.1998 / 11:42:17 / stefan"
+!
+
+unsignedInt32At:byteIndex put:anInteger MSB:msb
+ "set the 4-bytes starting at index from the (unsigned) integer value.
The index is a smalltalk index (i.e. 1-based).
- The value is retrieved in the machines natural byte order.
- This may be worth a primitive.
- This is the ST80 equivalent of #signedWordAt:"
-
- ^ (self unsignedShortAt:index) signExtendedShortValue
-
- "
- |b|
- b := ByteArray new:2.
- b unsignedShortAt:1 put:16rFFFF.
- b shortAt:1
- "
-
- "Modified: / 1.7.1996 / 21:14:38 / cg"
- "Created: / 5.3.1998 / 10:59:57 / stefan"
- "Modified: / 5.3.1998 / 23:39:38 / stefan"
-!
-
-shortAt:index bigEndian:msb
- "return the 2-bytes starting at index as a signed Integer.
- The index is a smalltalk index (i.e. 1-based).
- The value is retrieved MSB-first, if the msb-arg is true;
- LSB-first otherwise.
- This is the ST80 equivalent of #signedWordAt:"
-
- ^ (self unsignedShortAt:index bigEndian:msb) signExtendedShortValue
+ The value must be in the range 0 to 16rFFFFFFFF.
+ The value is stored MSB-first if msb is true; LSB-first otherwise."
+
+ |i "{ Class: SmallInteger }"
+ b1 "{ Class: SmallInteger }"
+ b2 "{ Class: SmallInteger }"
+ b3 "{ Class: SmallInteger }"
+ b4 "{ Class: SmallInteger }"|
+
+ ((anInteger < 0) or:[anInteger > 16rFFFFFFFF]) ifTrue:[
+ ^ self elementBoundsError:anInteger
+ ].
+
+ i := byteIndex.
+ msb ifTrue:[
+ b1 := (anInteger digitAt:4).
+ b2 := (anInteger digitAt:3).
+ b3 := (anInteger digitAt:2).
+ b4 := (anInteger digitAt:1).
+ ] ifFalse:[
+ b1 := (anInteger digitAt:1).
+ b2 := (anInteger digitAt:2).
+ b3 := (anInteger digitAt:3).
+ b4 := (anInteger digitAt:4).
+ ].
+ self byteAt:i put:b1.
+ self byteAt:(i+1) put:b2.
+ self byteAt:(i+2) put:b3.
+ self byteAt:(i+3) put:b3.
+ ^ anInteger
"
|b|
- b := ByteArray new:2.
- b unsignedShortAt:1 put:16rFFFF.
- b shortAt:1
- "
-
- "Modified: / 1.7.1996 / 21:14:38 / cg"
- "Created: / 5.3.1998 / 23:41:21 / stefan"
-!
-
-shortAt:index put:value
- "set the 2-bytes starting at index from the signed Integer value.
- The index is a smalltalk index (i.e. 1-based).
- The stored value must be in the range -32768 .. +32676.
- The value is stored in the machines natural byteorder.
- This may be worth a primitive.
- This is the ST80 equivalent of #signedWordAt:put:"
-
-
- |v|
-
- value >= 0 ifTrue:[
- v := value
- ] ifFalse:[
- v := 16r10000 + value
- ].
- self unsignedShortAt:index put:v bigEndian:IsBigEndian.
- ^ value
-
- "
- |b|
- b := ByteArray new:6.
- b shortAt:1 put:-1.
- b shortAt:3 put:-2.
- b shortAt:5 put:0.
+ b := ByteArray new:8.
+ b doubleWordAt:1 put:16r04030201 MSB:true.
+ b doubleWordAt:5 put:16r04030201 MSB:false.
b inspect
"
- "Modified: / 1.7.1996 / 21:12:07 / cg"
- "Created: / 5.3.1998 / 11:02:05 / stefan"
-!
-
-shortAt:index put:value bigEndian:bigEndian
- "set the 2-bytes starting at index from the signed Integer value.
- The index is a smalltalk index (i.e. 1-based).
- The stored value must be in the range -32768 .. +32676.
- The value is stored in the byteorder given by bigEndian.
- This may be worth a primitive."
-
-
- |v|
-
- value >= 0 ifTrue:[
- v := value
- ] ifFalse:[
- v := 16r10000 + value
- ].
- self unsignedShortAt:index put:v bigEndian:bigEndian.
- ^ value
-
- "
- |b|
- b := ByteArray new:4.
- b shortAt:1 put:1 bigEndian:true.
- b shortAt:3 put:1 bigEndian:false.
- b inspect
- "
-
- "Modified: / 1.7.1996 / 21:12:07 / cg"
- "Created: / 5.3.1998 / 11:02:05 / stefan"
-!
-
-signedWordAt:index
+ "Modified: / 21.1.1998 / 17:43:34 / cg"
+ "Modified: / 5.3.1998 / 11:42:17 / stefan"
+! !
+
+!UninterpretedBytes methodsFor:'accessing-shorts (16bit)'!
+
+signedInt16At:byteIndex
"return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
The value is retrieved in the machines natural byte order.
This may be worth a primitive."
- ^ (self wordAt:index) signExtendedShortValue
+ ^ (self unsignedInt16At:byteIndex) signExtendedShortValue
"
|b|
@@ -2473,59 +3153,44 @@
"Modified: 1.7.1996 / 21:14:38 / cg"
!
-signedWordAt:index MSB:msb
+signedInt16At:byteIndex MSB:msb
"return the 2-bytes starting at index as a signed Integer.
The index is a smalltalk index (i.e. 1-based).
- The value is retrieved MSB-first if the msb-arg is true,
- LSB-first otherwise.
+ The value is retrieved in the machines natural byte order.
This may be worth a primitive."
- ^ (self wordAt:index MSB:msb) signExtendedShortValue
+ ^ (self unsignedInt16At:byteIndex MSB:msb) signExtendedShortValue
"
|b|
b := ByteArray new:2.
- b wordAt:1 put:16r0080.
- b signedWordAt:1 MSB:true.
- b signedWordAt:1 MSB:false.
+ b wordAt:1 put:16rFFFF.
+ b signedWordAt:1
"
- "Modified: 1.7.1996 / 21:15:57 / cg"
+ "Modified: 1.7.1996 / 21:14:38 / cg"
!
-signedWordAt:index put:value
+signedInt16At:index put:anInteger
"set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
- The value is stored in the machines natural byteorder.
- This may be worth a primitive.
- This is the ST80 equivalent of #signedWordAt:put:"
-
-
- |v|
-
- value >= 0 ifTrue:[
- v := value
- ] ifFalse:[
- v := 16r10000 + value
- ].
- self unsignedShortAt:index put:v.
- ^ value
+ The value is stored in the machine's natural byte order."
+
+ ^ self signedInt16At:index put:anInteger MSB:IsBigEndian
"
|b|
- b := ByteArray new:6.
- b shortAt:1 put:-1.
- b shortAt:3 put:-2.
- b shortAt:5 put:0.
+ b := ByteArray new:4.
+ b signedInt16At:1 put:-2.
+ b signedInt16At:3 put:-3.
b inspect
"
- "Modified: / 1.7.1996 / 21:12:07 / cg"
- "Modified: / 5.3.1998 / 11:01:30 / stefan"
+ "Modified: 1.7.1996 / 21:12:13 / cg"
!
-signedWordAt:index put:value MSB:msb
+signedInt16At:index put:anInteger MSB:msb
"set the 2-bytes starting at index from the signed Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range -32768 .. +32676.
@@ -2535,13 +3200,13 @@
|v|
- value >= 0 ifTrue:[
- v := value
+ anInteger >= 0 ifTrue:[
+ v := anInteger
] ifFalse:[
- v := 16r10000 + value
+ v := 16r10000 + anInteger
].
- self wordAt:index put:v MSB:msb.
- ^ value
+ self unsignedInt16At:index put:v MSB:msb.
+ ^ anInteger
"
|b|
@@ -2554,25 +3219,23 @@
"Modified: 1.7.1996 / 21:12:13 / cg"
!
-unsignedShortAt:index
+unsignedInt16At:index
"return the 2-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
- The value is retrieved in the machines natural byte order
- Subclasses may redefine this for better performance.
- This is the ST80 equivalent of #wordAt:"
-
-
- ^ self unsignedShortAt:index bigEndian:IsBigEndian
-
- "Created: / 5.3.1998 / 11:38:25 / stefan"
- "Modified: / 5.3.1998 / 14:59:25 / stefan"
+ The value is retrieved in the machine's natural byte order
+ Subclasses may redefine this for better performance."
+
+ ^ self unsignedInt16At:index MSB:IsBigEndian
!
-unsignedShortAt:index bigEndian:msb
+unsignedInt16At:index MSB:msb
"return the 2-bytes starting at index as an (unsigned) Integer.
The index is a smalltalk index (i.e. 1-based).
- The value is retrieved MSB-first (high 8 bits at lower index) if msb is true;
- LSB-first (i.e. low 8-bits at lower byte index) if its false)"
+ The value is retrieved MSB (high 8 bits at lower index) if msb is true;
+ LSB-first (i.e. low 8-bits at lower byte index) if its false.
+ Notice:
+ the index is a byte index; thus, this allows for unaligned access to
+ words on any boundary."
|b1 "{ Class: SmallInteger }"
b2 "{ Class: SmallInteger }"|
@@ -2583,24 +3246,21 @@
^ (b1 bitShift:8) + b2
].
^ (b2 bitShift:8) + b1
-
- "Modified: / 21.1.1998 / 17:46:07 / cg"
- "Created: / 5.3.1998 / 11:49:29 / stefan"
!
-unsignedShortAt:index put:value
+unsignedInt16At:index put:anInteger
"set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
The value is stored in the machines natural byteorder."
- ^ self unsignedShortAt:index put:value bigEndian:IsBigEndian
+ ^ self unsignedInt16At:index put:anInteger MSB:IsBigEndian
"
|b|
b := ByteArray new:4.
- b unsignedShortAt:1 put:16r0102.
- b unsignedShortAt:3 put:16r0304.
+ b unsignedInt16At:1 put:16r0102.
+ b unsignedInt16At:3 put:16r0304.
b inspect
"
@@ -2608,7 +3268,7 @@
"Modified: / 5.3.1998 / 14:59:38 / stefan"
!
-unsignedShortAt:index put:value bigEndian:msb
+unsignedInt16At:index put:anInteger MSB:msb
"set the 2-bytes starting at index from the (unsigned) Integer value.
The index is a smalltalk index (i.e. 1-based).
The stored value must be in the range 0 .. 16rFFFF.
@@ -2618,7 +3278,7 @@
|b1 b2
iVal "{ Class: SmallInteger }"|
- iVal := value.
+ iVal := anInteger.
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[
^ self elementBoundsError:iVal
].
@@ -2631,7 +3291,7 @@
].
self byteAt:index put:b1.
self byteAt:index+1 put:b2.
- ^ value
+ ^ anInteger
"
|b|
@@ -2645,146 +3305,6 @@
"Modified: / 21.1.1998 / 17:48:15 / cg"
"Modified: / 5.3.1998 / 11:52:28 / stefan"
-!
-
-wordAt:index
- "return the 2-bytes starting at index as an (unsigned) Integer.
- The index is a smalltalk index (i.e. 1-based).
- The value is retrieved in the machines natural byte order
- Subclasses may redefine this for better performance."
-
- ^ self wordAt:index MSB:IsBigEndian
-
- "Modified: / 5.3.1998 / 14:59:51 / stefan"
-!
-
-wordAt:index MSB:msb
- "return the 2-bytes starting at index as an (unsigned) Integer.
- The index is a smalltalk index (i.e. 1-based).
- The value is retrieved MSB (high 8 bits at lower index) if msb is true;
- LSB-first (i.e. low 8-bits at lower byte index) if its false.
- Notice:
- the index is a byte index; thus, this allows for unaligned access to
- words on any boundary.
- Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
-
- |b1 "{ Class: SmallInteger }"
- b2 "{ Class: SmallInteger }"|
-
- b1 := self byteAt:index.
- b2 := self byteAt:(index + 1).
- msb ifTrue:[
- ^ (b1 bitShift:8) + b2
- ].
- ^ (b2 bitShift:8) + b1
-!
-
-wordAt:index put:value
- "set the 2-bytes starting at index from the (unsigned) Integer value.
- The index is a smalltalk index (i.e. 1-based).
- The stored value must be in the range 0 .. 16rFFFF.
- The value is stored in the machines natural byteorder.
- Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
-
- ^ self wordAt:index put:value MSB:IsBigEndian
-
- "
- |b|
- b := ByteArray new:4.
- b wordAt:1 put:16r0102.
- b wordAt:3 put:16r0304.
- b inspect
- "
-
- "Modified: / 5.3.1998 / 15:00:03 / stefan"
-!
-
-wordAt:index put:value MSB:msb
- "set the 2-bytes starting at index from the (unsigned) Integer value.
- The index is a smalltalk index (i.e. 1-based).
- The stored value must be in the range 0 .. 16rFFFF.
- The value is stored LSB-first (i.e. the low 8bits are stored at the
- lower index) if msb is false, MSB-first otherwise.
- Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
-
- |b1 b2
- iVal "{ Class: SmallInteger }"|
-
- iVal := value.
- ((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[
- ^ self elementBoundsError:iVal
- ].
- msb ifTrue:[
- b1 := ((iVal bitShift:-8) bitAnd:16rFF).
- b2 := (iVal bitAnd:16rFF).
- ] ifFalse:[
- b1 := (iVal bitAnd:16rFF).
- b2 := ((iVal bitShift:-8) bitAnd:16rFF).
- ].
- self byteAt:index put:b1.
- self byteAt:index+1 put:b2.
- ^ value
-
- "
- b := ByteArray new:8.
- b wordAt:1 put:16r0102 MSB:false.
- b wordAt:3 put:16r0304 MSB:false.
- b wordAt:5 put:16r0102 MSB:true.
- b wordAt:7 put:16r0304 MSB:true.
- b inspect
- "
-
- "Modified: / 21.1.1998 / 17:48:15 / cg"
-!
-
-wordAtWordIndex:index
- "return the unsigned short at index, anInteger.
- Fetching in the machines natural byte order.
- Indices are 1-based and scaled as appropriate to allow
- accessing the memory as an array of word entries.
- (i.e. indices are 1, 2, ...)"
-
- ^ self wordAtWordIndex:index MSB:IsBigEndian
-
- "Created: / 21.1.1998 / 17:48:26 / cg"
- "Modified: / 5.3.1998 / 15:00:16 / stefan"
-!
-
-wordAtWordIndex:index MSB:msb
- "return the unsigned short at index, anInteger.
- Fetching is MSB if msb is true, LSB otherwise.
- Indices are 1-based and scaled as appropriate to allow
- accessing the memory as an array of word entries.
- (i.e. indices are 1, 2, ...)"
-
- ^ self wordAt:(index - 1 * 2 + 1) MSB:msb
-
- "Created: / 21.1.1998 / 17:48:30 / cg"
-!
-
-wordAtWordIndex:index put:value
- "set the short at index, anInteger.
- Storing in the machines natural byte order.
- Indices are 1-based and scaled as appropriate to allow
- accessing the memory as an array of word entries.
- (i.e. indices are 1, 2, ...)"
-
- ^ self wordAtWordIndex:index put:value MSB:IsBigEndian
-
- "Created: / 21.1.1998 / 17:48:34 / cg"
- "Modified: / 5.3.1998 / 15:00:27 / stefan"
-!
-
-wordAtWordIndex:index put:value MSB:msb
- "set the short at index, anInteger.
- Storing is MSB if msb is true, LSB otherwise.
- Indices are 1-based and scaled as appropriate to allow
- accessing the memory as an array of word entries.
- (i.e. indices are 1, 2, ...)"
-
- ^ self wordAt:(index - 1 * 2 + 1) put:value MSB:msb
-
- "Created: / 21.1.1998 / 17:48:38 / cg"
! !
!UninterpretedBytes methodsFor:'accessing-strings'!