author | Claus Gittinger <cg@exept.de> |
Tue, 26 Feb 2002 14:02:26 +0100 | |
changeset 6421 | 58dca33cf0fc |
parent 4782 | 04a2ea1ad3a5 |
child 6492 | 61c212c8b3fb |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
300 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
13 |
ArrayedCollection subclass:#UninterpretedBytes |
1266 | 14 |
instanceVariableNames:'' |
3323 | 15 |
classVariableNames:'IsBigEndian' |
1266 | 16 |
poolDictionaries:'' |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
17 |
category:'Collections-Abstract' |
1 | 18 |
! |
19 |
||
3433 | 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)) { \ |
|
4308 | 35 |
if (__qClass(o) == ByteArray) { \ |
36 |
*(pPtr) = (unsigned char *)__ByteArrayInstPtr(o)->ba_element; \ |
|
3433 | 37 |
*(pSize) = __byteArraySize(o); \ |
38 |
} else if (__qClass(o) == ExternalBytes) { \ |
|
39 |
OBJ __sz__ = __externalBytesSize(o); \ |
|
40 |
if (__isSmallInteger(__sz__)) { \ |
|
41 |
*(pSize) = __intVal(__sz__); \ |
|
4308 | 42 |
*(pPtr) = (unsigned char *)(__externalBytesAddress(o)); \ |
3433 | 43 |
} else { \ |
4308 | 44 |
*(pPtr) = (unsigned char *)0; \ |
3433 | 45 |
} \ |
46 |
} else { \ |
|
4308 | 47 |
*(pPtr) = (unsigned char *)0; \ |
3433 | 48 |
} \ |
49 |
} else { \ |
|
4308 | 50 |
*(pPtr) = (unsigned char *)0; \ |
3433 | 51 |
} \ |
52 |
} |
|
53 |
||
54 |
%} |
|
55 |
! ! |
|
56 |
||
68 | 57 |
!UninterpretedBytes class methodsFor:'documentation'! |
1 | 58 |
|
88 | 59 |
copyright |
60 |
" |
|
61 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
300 | 62 |
All Rights Reserved |
88 | 63 |
|
64 |
This software is furnished under a license and may be used |
|
65 |
only in accordance with the terms of that license and with the |
|
66 |
inclusion of the above copyright notice. This software may not |
|
67 |
be provided or otherwise made available to, or used by, any |
|
68 |
other person. No title to or ownership of the software is |
|
69 |
hereby transferred. |
|
70 |
" |
|
71 |
! |
|
72 |
||
68 | 73 |
documentation |
74 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
75 |
UninterpretedBytes provides the common protocol for byte-storage |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
76 |
containers; concrete subclasses are |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
77 |
ByteArray (which store the bytes within the |
4308 | 78 |
Smalltalk object memory) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
79 |
and |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
80 |
ExternalBytes (which store the bytes in the malloc-heap). |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
81 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
82 |
UninterpretedBytes itself is abstract, so no instances of it can be created. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
83 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
84 |
[See also:] |
4308 | 85 |
ByteArray String ExternalBytes |
1294 | 86 |
|
87 |
[author:] |
|
4308 | 88 |
Claus Gittinger |
3433 | 89 |
|
90 |
[Notice:] |
|
91 |
Notice the confusion due to multiple methods with the same |
|
4308 | 92 |
functionality (i.e. 'xxxx:MSB:' vs. 'xxxx:bigEndian:'). |
93 |
The reason is that at the time this class was written, |
|
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:', |
|
3433 | 97 |
which has been added here for compatibility. |
98 |
(certainly a point, where an ansi-standard will help) |
|
68 | 99 |
" |
100 |
! ! |
|
1 | 101 |
|
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
102 |
!UninterpretedBytes class methodsFor:'instance creation'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
103 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
104 |
from:aCollection |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
105 |
^ ByteArray from:aCollection |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
106 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
107 |
"Created: / 3.4.1998 / 13:29:50 / cg" |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
108 |
"Modified: / 3.4.1998 / 13:30:12 / cg" |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
109 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
110 |
|
1 | 111 |
!UninterpretedBytes class methodsFor:'queries'! |
112 |
||
113 |
isBigEndian |
|
77 | 114 |
"return true, if words/shorts store the most-significant |
115 |
byte first (MSB), false if least-sign.-first (LSB). |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
116 |
I.e. false for vax, intel; true for m68k, sun. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
117 |
|
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
118 |
Notice: UninterpretedBytes isBigEndian |
4308 | 119 |
this is inlined both by stc and the jit compiler" |
1 | 120 |
|
121 |
%{ /* NOCONTEXT */ |
|
122 |
||
4275 | 123 |
#if defined(__MSBFIRST) || defined(sparc) |
3936 | 124 |
RETURN (true); |
125 |
#else |
|
4275 | 126 |
# if defined(__LSBFIRST) || defined(i386) || defined(alpha) |
127 |
RETURN (false); |
|
128 |
# else |
|
1 | 129 |
/* |
130 |
* I dont like ifdefs - you always forget some ... |
|
3433 | 131 |
* therefore we look into a structure at run-time. |
132 |
* (also, there are CPUs around [mips], where the byteorder |
|
133 |
* is programmable, and which come in different flavours) |
|
134 |
* |
|
135 |
* NOTICE: |
|
136 |
* both the JIT and stc may inline this to a |
|
137 |
* constant for systems where this is known. |
|
1 | 138 |
*/ |
139 |
union { |
|
4308 | 140 |
unsigned int u_l; |
141 |
char u_c[sizeof(int)]; |
|
1 | 142 |
} u; |
143 |
||
144 |
u.u_l = 0x87654321; |
|
77 | 145 |
if (u.u_c[0] == 0x21) RETURN (false); |
146 |
RETURN (true); |
|
4275 | 147 |
# endif |
3936 | 148 |
#endif |
1 | 149 |
%} |
3433 | 150 |
" |
151 |
UninterpretedBytes isBigEndian |
|
152 |
" |
|
3209 | 153 |
! |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
154 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
155 |
isBuiltInClass |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
156 |
"return true if this class is known by the run-time-system. |
3323 | 157 |
Here, true is returned, since UninterpretedBytes is the superclass of |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
158 |
some builtIn classes (ByteArray & ExternalBytes)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
159 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
160 |
^ self == UninterpretedBytes |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
161 |
|
3323 | 162 |
"Modified: / 23.4.1996 / 15:56:25 / cg" |
163 |
"Modified: / 5.3.1998 / 14:56:22 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
164 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
165 |
|
3459 | 166 |
!UninterpretedBytes methodsFor:'accessing-bytes'! |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
167 |
|
4422 | 168 |
bcdByteAt:index |
169 |
"return the bcd-value for a byte at index." |
|
170 |
||
4425 | 171 |
^ (self byteAt:index) decodeFromBCD |
4422 | 172 |
|
173 |
" |
|
174 |
#[ 16r55 ] bcdByteAt:1 |
|
175 |
#[ 16r99] bcdByteAt:1 |
|
176 |
#[ 16rAA] bcdByteAt:1 |
|
177 |
" |
|
178 |
! |
|
179 |
||
180 |
bcdByteAt:index put:aNumber |
|
181 |
"set the byte at index as bcd-value." |
|
182 |
||
183 |
(aNumber between:0 and:99) ifFalse:[ |
|
4530
793b116fef3e
error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents:
4515
diff
changeset
|
184 |
self error:'invalid value for BCD encoding' |
4422 | 185 |
]. |
4425 | 186 |
^ self byteAt:index put:aNumber encodeAsBCD |
4422 | 187 |
|
188 |
" |
|
4425 | 189 |
(((ByteArray new:1) bcdByteAt:1 put:55; yourself) at:1) hexPrintString |
190 |
(((ByteArray new:1) bcdByteAt:1 put:99; yourself) at:1) hexPrintString |
|
191 |
(((ByteArray new:1) bcdByteAt:1 put:100; yourself) at:1) hexPrintString |
|
192 |
(((ByteArray new:1) bcdByteAt:1 put:-1; yourself) at:1) hexPrintString |
|
4422 | 193 |
" |
194 |
! |
|
195 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
196 |
byteAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
197 |
"return the byte at index. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
198 |
For ByteArray, this is the same as basicAt:; |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
199 |
however, for strings or symbols, this returns a numeric byteValue |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
200 |
instead of a character." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
201 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
202 |
^ self subclassResponsibility |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
203 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
204 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
205 |
byteAt:index put:value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
206 |
"set the byte at index. For ByteArray, this is the same as basicAt:put:. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
207 |
However, for Strings, this expects a byteValue to be stored." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
208 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
209 |
^ self subclassResponsibility |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
210 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
211 |
|
3459 | 212 |
signedByteAt:index |
213 |
"return the byte at index as a signed 8 bit value. |
|
214 |
The index is a smalltalk index (i.e. 1-based). |
|
215 |
This may be worth a primitive." |
|
216 |
||
217 |
^ (self at:index) signExtendedByteValue |
|
218 |
||
219 |
" |
|
220 |
|b| |
|
221 |
b := ByteArray new:2. |
|
222 |
b at:1 put:16rFF. |
|
223 |
b at:2 put:16r7F. |
|
224 |
b signedByteAt:1 |
|
225 |
" |
|
226 |
||
227 |
"Modified: 1.7.1996 / 21:13:53 / cg" |
|
228 |
! |
|
229 |
||
230 |
signedByteAt:index put:aSignedByteValue |
|
231 |
"return the byte at index as a signed 8 bit value. |
|
232 |
The index is a smalltalk index (i.e. 1-based). |
|
233 |
Return the signedByteValue argument. |
|
234 |
This may be worth a primitive." |
|
235 |
||
236 |
|b "{ Class: SmallInteger }"| |
|
237 |
||
238 |
aSignedByteValue >= 0 ifTrue:[ |
|
239 |
b := aSignedByteValue |
|
240 |
] ifFalse:[ |
|
241 |
b := 16r100 + aSignedByteValue |
|
242 |
]. |
|
243 |
self at:index put:b. |
|
244 |
^ aSignedByteValue |
|
245 |
||
246 |
" |
|
247 |
|b| |
|
248 |
b := ByteArray new:2. |
|
249 |
b signedByteAt:1 put:-1. |
|
250 |
b at:1 |
|
251 |
" |
|
252 |
||
253 |
"Modified: 1.7.1996 / 21:12:37 / cg" |
|
254 |
! ! |
|
255 |
||
256 |
!UninterpretedBytes methodsFor:'accessing-floats & doubles'! |
|
257 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
258 |
doubleAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
259 |
"return the 8-bytes starting at index as a Float. |
3433 | 260 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
261 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
262 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
263 |
float representation - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
264 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
265 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
266 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
267 |
|
3433 | 268 |
%{ |
269 |
/* |
|
270 |
* handle the most common cases fast ... |
|
271 |
*/ |
|
272 |
if (__isSmallInteger(index)) { |
|
4308 | 273 |
unsigned char *cp; |
3433 | 274 |
int sz; |
4308 | 275 |
|
3433 | 276 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
4308 | 277 |
if (cp) { |
3433 | 278 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
279 |
||
3434 | 280 |
if ((idx+(sizeof(double)-1)) < sz) { |
3433 | 281 |
cp += idx; |
282 |
/* |
|
283 |
* aligned |
|
284 |
*/ |
|
3434 | 285 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
3433 | 286 |
double dVal = ((double *)cp)[0]; |
3434 | 287 |
OBJ f; |
288 |
||
289 |
__qMKFLOAT(f, dVal); |
|
4308 | 290 |
RETURN (f); |
3433 | 291 |
} |
292 |
} |
|
293 |
} |
|
294 |
} |
|
295 |
%}. |
|
296 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
297 |
newFloat := Float basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
298 |
1 to:8 do:[:destIndex| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
299 |
newFloat basicAt:destIndex put:(self at:index - 1 + destIndex) |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
300 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
301 |
^ newFloat. |
3433 | 302 |
|
303 |
" |
|
304 |
|b| |
|
305 |
||
306 |
b := ByteArray new:20. |
|
307 |
b doubleAt:1 put:(Float pi). |
|
308 |
Transcript showCR:b. |
|
309 |
Transcript showCR:(b doubleAt:1) |
|
310 |
" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
311 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
312 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
313 |
doubleAt:index MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
314 |
"return the 8-bytes starting at index as a Float. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
315 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
316 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
317 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
318 |
float representation - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
319 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
320 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
321 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
322 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
323 |
msb == UninterpretedBytes isBigEndian ifTrue:[ |
4308 | 324 |
^ self doubleAt:index. |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
325 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
326 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
327 |
newFloat := Float basicNew. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
328 |
1 to:8 do:[:destIndex| |
4308 | 329 |
newFloat basicAt:(9-destIndex) put:(self at:index - 1 + destIndex) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
330 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
331 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
332 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
333 |
"Created: / 15.5.1998 / 17:21:45 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
334 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
335 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
336 |
doubleAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
337 |
"store the value of the argument, aFloat into the receiver |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
338 |
starting at index. |
3433 | 339 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
340 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
341 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
342 |
float representation - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
343 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
344 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
345 |
|flt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
346 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
347 |
flt := aFloat asFloat. |
3433 | 348 |
%{ |
349 |
/* |
|
350 |
* handle the most common cases fast ... |
|
351 |
*/ |
|
352 |
if (__isSmallInteger(index) && __isFloat(flt)) { |
|
4308 | 353 |
unsigned char *cp; |
354 |
int sz; |
|
3433 | 355 |
|
4308 | 356 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
357 |
if (cp) { |
|
358 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3433 | 359 |
|
4308 | 360 |
if ((idx+(sizeof(double)-1)) < sz) { |
361 |
cp += idx; |
|
362 |
/* |
|
363 |
* aligned |
|
364 |
*/ |
|
365 |
if (((INT)cp & (sizeof(double)-1)) == 0) { |
|
366 |
((double *)cp)[0] = __floatVal(flt); |
|
367 |
RETURN (aFloat); |
|
368 |
} |
|
369 |
} |
|
370 |
} |
|
3433 | 371 |
} |
372 |
%}. |
|
373 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
374 |
1 to:8 do:[:srcIndex| |
4308 | 375 |
self at:index - 1 + srcIndex put:(flt basicAt:srcIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
376 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
377 |
^ aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
378 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
379 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
380 |
doubleAt:index put:aFloat MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
381 |
"store the value of the argument, aFloat into the receiver |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
382 |
starting at index. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
383 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
384 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
385 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
386 |
float representation - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
387 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
388 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
389 |
|flt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
390 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
391 |
msb == UninterpretedBytes isBigEndian ifTrue:[ |
4308 | 392 |
^ self doubleAt:index put:aFloat. |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
393 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
394 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
395 |
flt := aFloat asFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
396 |
1 to:8 do:[:srcIndex| |
4308 | 397 |
self at:index - 1 + srcIndex put:(flt basicAt:(9-srcIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
398 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
399 |
^ aFloat |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
400 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
401 |
"Created: / 15.5.1998 / 17:22:27 / cg" |
3447 | 402 |
"Modified: / 15.5.1998 / 17:26:29 / cg" |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
403 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
404 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
405 |
floatAt:index |
3434 | 406 |
"return the 4-bytes starting at index as a ShortFloat. |
3433 | 407 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
408 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80; |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
409 |
therefore this method reads a 4-byte float from the byteArray and returns |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
410 |
a float object which keeps an 8-byte double internally. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
411 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
412 |
float representation and order - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
413 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
414 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
415 |
|newFloat| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
416 |
|
3434 | 417 |
%{ |
418 |
/* |
|
419 |
* handle the most common cases fast ... |
|
420 |
*/ |
|
421 |
if (__isSmallInteger(index)) { |
|
4308 | 422 |
unsigned char *cp; |
423 |
int sz; |
|
3434 | 424 |
|
4308 | 425 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
426 |
if (cp) { |
|
427 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 428 |
|
4308 | 429 |
if ((idx+(sizeof(float)-1)) < sz) { |
430 |
cp += idx; |
|
431 |
/* |
|
432 |
* aligned |
|
433 |
*/ |
|
434 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
435 |
float fVal = ((float *)cp)[0]; |
|
3434 | 436 |
OBJ f; |
437 |
||
438 |
__qMKSFLOAT(f, fVal); |
|
4308 | 439 |
RETURN (f); |
440 |
} |
|
441 |
} |
|
442 |
} |
|
3434 | 443 |
} |
444 |
%}. |
|
445 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
446 |
newFloat := ShortFloat basicNew. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
447 |
1 to:4 do:[:destIndex| |
4308 | 448 |
newFloat basicAt:destIndex put:(self at:index - 1 + destIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
449 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
450 |
^ newFloat. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
451 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
452 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
453 |
floatAt:index MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
454 |
"return the 4-bytes starting at index as a ShortFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
455 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
456 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80; |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
457 |
therefore this method reads a 4-byte float from the byteArray and returns |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
458 |
a float object which keeps an 8-byte double internally. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
459 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
460 |
float representation and order - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
461 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
462 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
463 |
|newFloat| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
464 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
465 |
msb == UninterpretedBytes isBigEndian ifTrue:[ |
4308 | 466 |
^ self floatAt:index |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
467 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
468 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
469 |
newFloat := ShortFloat basicNew. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
470 |
1 to:4 do:[:destIndex| |
4308 | 471 |
newFloat basicAt:(5-destIndex) put:(self at:index - 1 + destIndex) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
472 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
473 |
^ newFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
474 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
475 |
"Modified: / 15.5.1998 / 17:20:19 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
476 |
"Created: / 15.5.1998 / 17:20:35 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
477 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
478 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
479 |
floatAt:index put:aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
480 |
"store the 4 bytes of value of the argument, aFloat into the receiver |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
481 |
starting at index. |
3433 | 482 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
483 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
484 |
Notice also, that the bytes are expected to be in this machines |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
485 |
float representation - if the bytearray originated from another |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
486 |
machine, some conversion is usually needed." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
487 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
488 |
|sflt| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
489 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
490 |
sflt := aFloat asShortFloat. |
3434 | 491 |
%{ |
492 |
/* |
|
493 |
* handle the most common cases fast ... |
|
494 |
*/ |
|
495 |
if (__isSmallInteger(index) && __isShortFloat(sflt)) { |
|
4308 | 496 |
unsigned char *cp; |
497 |
int sz; |
|
3434 | 498 |
|
4308 | 499 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
500 |
if (cp) { |
|
501 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 502 |
|
4308 | 503 |
if ((idx+(sizeof(float)-1)) < sz) { |
504 |
cp += idx; |
|
505 |
/* |
|
506 |
* aligned |
|
507 |
*/ |
|
508 |
if (((INT)cp & (sizeof(float)-1)) == 0) { |
|
509 |
((float *)cp)[0] = __shortFloatVal(sflt); |
|
3434 | 510 |
|
4308 | 511 |
RETURN (aFloat); |
512 |
} |
|
513 |
} |
|
514 |
} |
|
3434 | 515 |
} |
516 |
%}. |
|
517 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
518 |
1 to:4 do:[:srcIndex| |
4308 | 519 |
self at:index - 1 + srcIndex put:(sflt basicAt:srcIndex) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
520 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
521 |
^ aFloat |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
522 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
523 |
|
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
524 |
floatAt:index put:aFloat MSB:msb |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
525 |
"store the 4 bytes of value of the argument, aFloat into the receiver |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
526 |
starting at index. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
527 |
The index is a smalltalk index (i.e. 1-based). |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
528 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
529 |
Notice also, that the bytes are expected to be in this machines |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
530 |
float representation - if the bytearray originated from another |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
531 |
machine, some conversion is usually needed." |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
532 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
533 |
|sflt| |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
534 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
535 |
msb == UninterpretedBytes isBigEndian ifTrue:[ |
4308 | 536 |
^ self floatAt:index put:aFloat |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
537 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
538 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
539 |
sflt := aFloat asShortFloat. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
540 |
1 to:4 do:[:srcIndex| |
4308 | 541 |
self at:index - 1 + srcIndex put:(sflt basicAt:(5-srcIndex)) |
3446
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
542 |
]. |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
543 |
^ aFloat |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
544 |
|
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
545 |
"Created: / 15.5.1998 / 17:20:41 / cg" |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
546 |
! |
1a8c314b5d7d
added #floatAt:MSB: , #floatAt:put:MSB: , #doubleAt:MSB: and #doubleAt:put:MSB:
Claus Gittinger <cg@exept.de>
parents:
3444
diff
changeset
|
547 |
|
3323 | 548 |
ieeeDoubleAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
549 |
"retrieve the 8 bytes starting at index as a float. |
3433 | 550 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 551 |
The 8 bytes are assumed to be in IEEE floating point single precision |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
552 |
number format." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
553 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
554 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
555 |
currently, we assume that the machines native number format is already |
3323 | 556 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
557 |
to an IBM 370 or old VAX etc. |
3323 | 558 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
559 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
560 |
" |
3433 | 561 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
562 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
563 |
^ self doubleAt:index |
3323 | 564 |
|
565 |
"Created: / 5.3.1998 / 10:50:03 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
566 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
567 |
|
3323 | 568 |
ieeeDoubleAt:index put:aFloat |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
569 |
"store the value of the argument, aFloat into the receiver |
3433 | 570 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 571 |
starting at index. Storage is in IEEE floating point double precision format. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
572 |
(i.e. 8 bytes are stored)." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
573 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
574 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
575 |
currently, we assume that the machines native number format is already |
3323 | 576 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
577 |
to an IBM 370 or old VAX etc. |
3323 | 578 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
579 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
580 |
" |
3433 | 581 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
582 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
583 |
^ self doubleAt:index put:aFloat |
3323 | 584 |
|
585 |
"Created: / 5.3.1998 / 10:50:26 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
586 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
587 |
|
3323 | 588 |
ieeeFloatAt:index |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
589 |
"retrieve the 4 bytes starting at index as a float. |
3433 | 590 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 591 |
The 4 bytes are assumed to be in IEEE floating point single precision |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
592 |
number format." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
593 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
594 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
595 |
currently, we assume that the machines native number format is already |
3323 | 596 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
597 |
to an IBM 370 or old VAX etc. |
3323 | 598 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
599 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
600 |
" |
3433 | 601 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
602 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
603 |
^ self floatAt:index |
3323 | 604 |
|
605 |
"Created: / 5.3.1998 / 10:50:45 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
606 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
607 |
|
3323 | 608 |
ieeeFloatAt:index put:aFloat |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
609 |
"store the value of the argument, aFloat into the receiver |
3433 | 610 |
starting at index, which is a smalltalk index (i.e. 1-based). |
611 |
Storage is in IEEE floating point single precision format. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
612 |
(i.e. 4 bytes are stored). Since ST/X floats are really doubles, the low- |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
613 |
order 4 bytes of the precision is lost." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
614 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
615 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
616 |
currently, we assume that the machines native number format is already |
3323 | 617 |
IEEE format - we need some more code here whenever ST/X is ported |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
618 |
to an IBM 370 or old VAX etc. |
3323 | 619 |
To date, all supported systems use IEEE float numbers, so there should be |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
620 |
no problem. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
621 |
" |
3433 | 622 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
623 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
624 |
^ self floatAt:index put:aFloat |
3323 | 625 |
|
626 |
"Created: / 5.3.1998 / 10:51:11 / stefan" |
|
3459 | 627 |
! ! |
628 |
||
629 |
!UninterpretedBytes methodsFor:'accessing-longlongs'! |
|
630 |
||
631 |
longLongAt:index |
|
632 |
"return the 8-bytes starting at index as a signed Integer. |
|
633 |
The index is a smalltalk index (i.e. 1-based). |
|
634 |
The value is retrieved in the machines natural byte order. |
|
635 |
This may be worth a primitive." |
|
636 |
||
637 |
|w| |
|
638 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
639 |
w := self unsignedLongLongAt:index bigEndian:(UninterpretedBytes isBigEndian). |
3459 | 640 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
4308 | 641 |
^ w - (16r10000000000000000) |
3459 | 642 |
]. |
643 |
^ w |
|
644 |
||
645 |
" |
|
646 |
|b| |
|
647 |
b := ByteArray new:4. |
|
648 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
649 |
(b longLongAt:1) |
|
650 |
" |
|
651 |
||
652 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
653 |
"Created: / 5.3.1998 / 14:40:05 / stefan" |
|
654 |
"Modified: / 5.3.1998 / 14:58:32 / stefan" |
|
655 |
! |
|
656 |
||
657 |
longLongAt:index bigEndian:msb |
|
658 |
"return the 8-bytes starting at index as a signed Integer. |
|
659 |
The index is a smalltalk index (i.e. 1-based). |
|
660 |
The value is retrieved in the given byte order. |
|
661 |
This may be worth a primitive." |
|
662 |
||
663 |
|w| |
|
664 |
||
665 |
w := self unsignedLongLongAt:index bigEndian:msb. |
|
666 |
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[ |
|
4308 | 667 |
^ w - (16r10000000000000000) |
3459 | 668 |
]. |
669 |
^ w |
|
670 |
||
671 |
" |
|
672 |
|b| |
|
673 |
b := ByteArray new:4. |
|
674 |
b unsignedLongLongAt:1 put:16rFFFFFFFFFFFFFFFF. |
|
675 |
(b longLongAt:1 msb:true) |
|
676 |
" |
|
677 |
||
678 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
679 |
"Created: / 5.3.1998 / 14:40:54 / stefan" |
|
680 |
"Modified: / 9.5.1998 / 01:10:59 / cg" |
|
681 |
! |
|
682 |
||
683 |
longLongAt:byteIndex put:anInteger |
|
684 |
"store a signed longLong (64bit) integer. |
|
685 |
The index is a smalltalk index (i.e. 1-based). |
|
686 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
687 |
||
688 |
^ self signedQuadWordAt:byteIndex put:anInteger |
|
689 |
||
690 |
"Modified: / 3.4.1998 / 13:33:14 / cg" |
|
691 |
"Created: / 3.4.1998 / 13:34:22 / cg" |
|
692 |
! |
|
693 |
||
694 |
longLongAt:byteIndex put:anInteger bigEndian:msb |
|
695 |
"store a signed longLong (64bit) integer. |
|
696 |
The index is a smalltalk index (i.e. 1-based). |
|
697 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
698 |
||
699 |
|v| |
|
700 |
||
701 |
v := anInteger. |
|
702 |
anInteger < 0 ifTrue:[ |
|
4308 | 703 |
v := v + 16r10000000000000000 |
3459 | 704 |
]. |
705 |
^ self unsignedLongLongAt:byteIndex put:v bigEndian:msb |
|
706 |
||
707 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
708 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
709 |
! |
|
710 |
||
711 |
quadWordAt:index MSB:msb |
|
712 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
713 |
The index is a smalltalk index (i.e. 1-based). |
|
714 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
715 |
||
716 |
|l |
|
717 |
bIdx "{ Class: SmallInteger }" |
|
718 |
delta "{ Class: SmallInteger }"| |
|
719 |
||
720 |
l := LargeInteger basicNew numberOfDigits:8. |
|
721 |
msb ifTrue:[ |
|
4308 | 722 |
bIdx := index + 7. |
723 |
delta := -1 |
|
3459 | 724 |
] ifFalse:[ |
4308 | 725 |
bIdx := index. |
726 |
delta := 1 |
|
3459 | 727 |
]. |
728 |
1 to:8 do:[:i | |
|
4308 | 729 |
l digitAt:i put:(self basicAt:bIdx). |
730 |
bIdx := bIdx + delta |
|
3459 | 731 |
]. |
732 |
^ l compressed |
|
733 |
||
734 |
" |
|
735 |
|b| |
|
736 |
||
737 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
738 |
(b quadWordAt:1 MSB:false) printStringRadix:16 |
|
739 |
" |
|
740 |
||
741 |
"Modified: 5.11.1996 / 14:06:21 / cg" |
|
742 |
! |
|
743 |
||
744 |
quadWordAt:index put:anInteger MSB:msb |
|
745 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
746 |
The index is a smalltalk index (i.e. 1-based). |
|
747 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
748 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
749 |
||
750 |
|bIdx "{ Class: SmallInteger }" |
|
751 |
delta "{ Class: SmallInteger }"| |
|
752 |
||
753 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFFFFFFFFFF]) ifTrue:[ |
|
754 |
^ self elementBoundsError |
|
755 |
]. |
|
756 |
||
757 |
msb ifTrue:[ |
|
758 |
bIdx := index + 7. |
|
759 |
delta := -1 |
|
760 |
] ifFalse:[ |
|
761 |
bIdx := index. |
|
762 |
delta := 1 |
|
763 |
]. |
|
764 |
1 to:8 do:[:i | |
|
765 |
self basicAt:bIdx put:(anInteger digitAt:i). |
|
766 |
bIdx := bIdx + delta. |
|
767 |
]. |
|
768 |
^ anInteger |
|
769 |
||
770 |
" |
|
771 |
|b| |
|
772 |
b := ByteArray new:8. |
|
773 |
b quadWordAtIndex:1 put:16r0807060504030201 MSB:false. |
|
774 |
b inspect |
|
775 |
" |
|
776 |
! |
|
777 |
||
778 |
unsignedLongLongAt:index bigEndian:msb |
|
779 |
"return the 8-bytes starting at index as an (unsigned) Integer. |
|
780 |
The index is a smalltalk index (i.e. 1-based). |
|
781 |
Depending on msb, the value is retrieved MSB or LSB-first." |
|
782 |
||
783 |
|l |
|
784 |
bIdx "{ Class: SmallInteger }" |
|
785 |
delta "{ Class: SmallInteger }"| |
|
786 |
||
787 |
l := LargeInteger basicNew numberOfDigits:8. |
|
788 |
msb ifTrue:[ |
|
4308 | 789 |
bIdx := index + 7. |
790 |
delta := -1 |
|
3459 | 791 |
] ifFalse:[ |
4308 | 792 |
bIdx := index. |
793 |
delta := 1 |
|
3459 | 794 |
]. |
795 |
1 to:8 do:[:i | |
|
4308 | 796 |
l digitAt:i put:(self basicAt:bIdx). |
797 |
bIdx := bIdx + delta |
|
3459 | 798 |
]. |
799 |
^ l compressed |
|
800 |
||
801 |
" |
|
802 |
|b| |
|
803 |
||
804 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8). |
|
805 |
(b unsignedLongLongAt:1 bigEndian:false) printStringRadix:16 |
|
806 |
" |
|
807 |
||
808 |
"Modified: / 5.11.1996 / 14:06:21 / cg" |
|
809 |
"Modified: / 5.3.1998 / 14:04:44 / stefan" |
|
810 |
! |
|
811 |
||
812 |
unsignedLongLongAt:index put:anInteger |
|
813 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
814 |
The index is a smalltalk index (i.e. 1-based). |
|
815 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
816 |
The value is stored in natural byte order." |
|
817 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
818 |
^ self unsignedLongLongAt:index put:anInteger bigEndian:(UninterpretedBytes isBigEndian) |
3459 | 819 |
|
820 |
"Created: / 5.3.1998 / 14:44:00 / stefan" |
|
821 |
"Modified: / 5.3.1998 / 15:02:32 / stefan" |
|
822 |
! |
|
823 |
||
824 |
unsignedLongLongAt:index put:anInteger bigEndian:msb |
|
825 |
"set the 8-bytes starting at index from the (unsigned) Integer value. |
|
826 |
The index is a smalltalk index (i.e. 1-based). |
|
827 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF. |
|
828 |
Depending on msb, the value is stored MSB-first or LSB-first." |
|
829 |
||
830 |
|bIdx "{ Class: SmallInteger }" |
|
831 |
delta "{ Class: SmallInteger }"| |
|
832 |
||
833 |
((anInteger < 0) or:[anInteger > 16rFFFFFFFFFFFFFFFF]) ifTrue:[ |
|
4308 | 834 |
^ self elementBoundsError |
3459 | 835 |
]. |
836 |
||
837 |
msb ifTrue:[ |
|
4308 | 838 |
bIdx := index + 7. |
839 |
delta := -1 |
|
3459 | 840 |
] ifFalse:[ |
4308 | 841 |
bIdx := index. |
842 |
delta := 1 |
|
3459 | 843 |
]. |
844 |
1 to:8 do:[:i | |
|
4308 | 845 |
self basicAt:bIdx put:(anInteger digitAt:i). |
846 |
bIdx := bIdx + delta. |
|
3459 | 847 |
]. |
848 |
^ anInteger |
|
849 |
||
850 |
" |
|
851 |
|b| |
|
852 |
b := ByteArray new:8. |
|
853 |
b unsignedLongLongAt:1 put:16r0807060504030201 bigEndian:false. |
|
854 |
b inspect |
|
855 |
" |
|
856 |
||
857 |
"Created: / 5.3.1998 / 14:06:02 / stefan" |
|
858 |
! ! |
|
859 |
||
860 |
!UninterpretedBytes methodsFor:'accessing-longs'! |
|
861 |
||
862 |
doubleWordAt:index |
|
863 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
864 |
The index is a smalltalk index (i.e. 1-based). |
|
4515 | 865 |
The value is retrieved in the machines natural byte order." |
3459 | 866 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
867 |
^ self doubleWordAt:index MSB:(UninterpretedBytes isBigEndian) |
3459 | 868 |
|
869 |
" |
|
870 |
|b| |
|
871 |
||
872 |
b := ByteArray withAll:#(1 2 3 4). |
|
873 |
(b doubleWordAt:1) printStringRadix:16 |
|
874 |
" |
|
875 |
||
876 |
"Modified: / 5.3.1998 / 14:57:35 / stefan" |
|
877 |
! |
|
878 |
||
879 |
doubleWordAt:index MSB:msb |
|
880 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
881 |
The index is a smalltalk index (i.e. 1-based). |
|
882 |
The value is retrieved MSB-first, if the msb-arg is true; |
|
4515 | 883 |
LSB-first otherwise." |
3459 | 884 |
|
885 |
|val |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
886 |
ival "{ Class: SmallInteger }" |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
887 |
t "{ Class: SmallInteger }" |
3459 | 888 |
i "{ Class: SmallInteger }" |
889 |
b1 "{ Class: SmallInteger }" |
|
890 |
b2 "{ Class: SmallInteger }" |
|
891 |
b3 "{ Class: SmallInteger }" |
|
892 |
b4 "{ Class: SmallInteger }"| |
|
893 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
894 |
%{ |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
895 |
/* |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
896 |
* handle the most common cases fast ... |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
897 |
*/ |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
898 |
if (__isSmallInteger(index)) { |
4515 | 899 |
unsigned char *cp; |
900 |
int sz; |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
901 |
|
4515 | 902 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
903 |
if (cp) { |
|
904 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
905 |
unsigned int iVal; |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
906 |
|
4515 | 907 |
if ((idx+(sizeof(int)-1)) < sz) { |
908 |
cp += idx; |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
909 |
|
4515 | 910 |
if (msb == true) { |
4275 | 911 |
#if defined(__MSBFIRST) || defined(sparc) |
4515 | 912 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
913 |
/* |
|
914 |
* aligned |
|
915 |
*/ |
|
916 |
iVal = ((unsigned int *)cp)[0]; |
|
917 |
} else |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
918 |
#endif |
4515 | 919 |
{ |
920 |
iVal = cp[0]; |
|
921 |
iVal = (iVal << 8) | cp[1]; |
|
922 |
iVal = (iVal << 8) | cp[2]; |
|
923 |
iVal = (iVal << 8) | cp[3]; |
|
924 |
} |
|
925 |
} else { |
|
4308 | 926 |
#if defined(i386) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST)) |
4515 | 927 |
/* |
928 |
* aligned or not - we dont care |
|
929 |
* (i386 can fetch unaligned) |
|
930 |
*/ |
|
931 |
iVal = ((unsigned int *)cp)[0]; |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
932 |
#else |
4308 | 933 |
# if defined(__LSBFIRST) || defined(i386) |
4515 | 934 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
935 |
/* |
|
936 |
* aligned |
|
937 |
*/ |
|
938 |
iVal = ((unsigned int *)cp)[0]; |
|
939 |
} else |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
940 |
# endif |
4515 | 941 |
{ |
942 |
iVal = cp[3]; |
|
943 |
iVal = (iVal << 8) | cp[2]; |
|
944 |
iVal = (iVal << 8) | cp[1]; |
|
945 |
iVal = (iVal << 8) | cp[0]; |
|
946 |
} |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
947 |
#endif |
4515 | 948 |
} |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
949 |
#ifdef alpha64 |
4515 | 950 |
RETURN (__MKSMALLINT(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
951 |
#else |
4515 | 952 |
RETURN (__MKUINT(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
953 |
#endif |
4515 | 954 |
} |
955 |
} |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
956 |
} |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
957 |
%}. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
958 |
|
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
959 |
"/ fallBack code - non ByteArray-like receiver |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
960 |
"/ or funny index |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
961 |
|
3459 | 962 |
i := index. |
963 |
b1 := self at:i. |
|
964 |
b2 := self at:(i+1). |
|
965 |
b3 := self at:(i+2). |
|
966 |
b4 := self at:(i+3). |
|
967 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
968 |
msb ifFalse:[ |
4515 | 969 |
t := b4. b4 := b1. b1 := t. |
970 |
t := b3. b3 := b2. b2 := t. |
|
3459 | 971 |
]. |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
972 |
ival := b1. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
973 |
ival := (ival bitShift:8) + b2. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
974 |
ival := (ival bitShift:8) + b3. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
975 |
val := (ival bitShift:8) + b4. |
3459 | 976 |
^ val |
977 |
||
978 |
" |
|
979 |
|b| |
|
980 |
||
981 |
b := ByteArray withAll:#(1 2 3 4). |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
982 |
(b doubleWordAt:1 MSB:true) printStringRadix:16. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
983 |
(b doubleWordAt:1 MSB:false) printStringRadix:16 |
3459 | 984 |
" |
985 |
||
986 |
! |
|
987 |
||
988 |
doubleWordAt:index put:value |
|
989 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
990 |
The index is a smalltalk index (i.e. 1-based). |
|
991 |
The value should be in the range 0 to 16rFFFFFFFF |
|
992 |
(for negative values, the stored value is not defined). |
|
4515 | 993 |
The value is stored in the machines natural byte order." |
3459 | 994 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
995 |
^ self doubleWordAt:index put:value MSB:(UninterpretedBytes isBigEndian) |
3459 | 996 |
|
997 |
" |
|
998 |
|b| |
|
999 |
b := ByteArray new:4. |
|
1000 |
b doubleWordAt:1 put:16r04030201. |
|
1001 |
b inspect |
|
1002 |
" |
|
1003 |
||
1004 |
"Modified: / 5.3.1998 / 14:57:48 / stefan" |
|
1005 |
! |
|
1006 |
||
1007 |
doubleWordAt:index put:aNumber MSB:msb |
|
1008 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
1009 |
The index is a smalltalk index (i.e. 1-based). |
|
1010 |
The value must be in the range 0 to 16rFFFFFFFF. |
|
4515 | 1011 |
The value is stored MSB-first if msb is true; LSB-first otherwise." |
3459 | 1012 |
|
1013 |
|i "{ Class: SmallInteger }" | |
|
1014 |
||
1015 |
((aNumber < 0) or:[aNumber > 16rFFFFFFFF]) ifTrue:[ |
|
4515 | 1016 |
^ self elementBoundsError |
3459 | 1017 |
]. |
1018 |
||
1019 |
i := index. |
|
1020 |
msb ifTrue:[ |
|
4515 | 1021 |
self at:i put:(aNumber digitAt:4). |
1022 |
self at:(i+1) put:(aNumber digitAt:3). |
|
1023 |
self at:(i+2) put:(aNumber digitAt:2). |
|
1024 |
self at:(i+3) put:(aNumber digitAt:1). |
|
3459 | 1025 |
] ifFalse:[ |
4515 | 1026 |
self at:i put:(aNumber digitAt:1). |
1027 |
self at:(i+1) put:(aNumber digitAt:2). |
|
1028 |
self at:(i+2) put:(aNumber digitAt:3). |
|
1029 |
self at:(i+3) put:(aNumber digitAt:4). |
|
3459 | 1030 |
]. |
1031 |
^ aNumber |
|
1032 |
||
1033 |
" |
|
1034 |
|b| |
|
1035 |
b := ByteArray new:8. |
|
1036 |
b doubleWordAt:1 put:16r04030201 MSB:true. |
|
1037 |
b doubleWordAt:5 put:16r04030201 MSB:false. |
|
1038 |
b inspect |
|
1039 |
" |
|
1040 |
||
1041 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
1042 |
"Modified: / 5.3.1998 / 11:42:17 / stefan" |
|
1043 |
! |
|
1044 |
||
1045 |
doubleWordAtDoubleWordIndex:index |
|
1046 |
"return the unsigned long at index, anInteger. |
|
1047 |
Fetching in the machines natural byte order. |
|
1048 |
Indices are 1-based and scaled as appropriate to allow |
|
1049 |
accessing the memory as an array of doubleWord entries. |
|
1050 |
(i.e. indices are 1, 2, ...)" |
|
1051 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1052 |
^ self doubleWordAtDoubleWordIndex:index MSB:(UninterpretedBytes isBigEndian) |
3459 | 1053 |
|
1054 |
"Created: / 21.1.1998 / 17:43:53 / cg" |
|
1055 |
"Modified: / 5.3.1998 / 14:58:06 / stefan" |
|
1056 |
! |
|
1057 |
||
1058 |
doubleWordAtDoubleWordIndex:index MSB:msb |
|
1059 |
"return the unsigned long at index, anInteger. |
|
1060 |
Fetching is MSB if msb is true, LSB otherwise. |
|
1061 |
Indices are 1-based and scaled as appropriate to allow |
|
1062 |
accessing the memory as an array of doubleWord entries. |
|
1063 |
(i.e. indices are 1, 2, ...)" |
|
1064 |
||
1065 |
^ self doubleWordAt:(index - 1 * 4 + 1) MSB:msb |
|
1066 |
||
1067 |
"Created: / 21.1.1998 / 17:44:07 / cg" |
|
1068 |
! |
|
1069 |
||
1070 |
doubleWordAtDoubleWordIndex:index put:value |
|
1071 |
"set the long at index, anInteger. |
|
1072 |
Storing in the machines natural byte order. |
|
1073 |
Indices are 1-based and scaled as appropriate to allow |
|
1074 |
accessing the memory as an array of doubleWord entries. |
|
1075 |
(i.e. indices are 1, 2, ...)" |
|
1076 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1077 |
^ self doubleWordAtDoubleWordIndex:index put:value MSB:(UninterpretedBytes isBigEndian) |
3459 | 1078 |
|
1079 |
"Created: / 21.1.1998 / 17:44:13 / cg" |
|
1080 |
"Modified: / 5.3.1998 / 14:58:19 / stefan" |
|
1081 |
! |
|
1082 |
||
1083 |
doubleWordAtDoubleWordIndex:index put:value MSB:msb |
|
1084 |
"set the long at index, anInteger. |
|
1085 |
Storing is MSB if msb is true, LSB otherwise. |
|
1086 |
Indices are 1-based and scaled as appropriate to allow |
|
1087 |
accessing the memory as an array of doubleWord entries. |
|
1088 |
(i.e. indices are 1, 2, ...)" |
|
1089 |
||
1090 |
^ self doubleWordAt:(index - 1 * 4 + 1) put:value MSB:msb |
|
1091 |
||
1092 |
"Created: / 21.1.1998 / 17:44:19 / cg" |
|
3323 | 1093 |
! |
1094 |
||
1095 |
longAt:index |
|
1096 |
"return the 4-bytes starting at index as a signed Integer. |
|
3433 | 1097 |
The index is a smalltalk index (i.e. 1-based). |
4308 | 1098 |
The value is retrieved in the machines natural byte order, |
1099 |
therefore, this should only be used for byte-data which is |
|
1100 |
only used inside this machine. |
|
1101 |
To setup data packets which are to be sent to other machines, |
|
1102 |
or stored into a file, always use longAt:MSB: and specify |
|
1103 |
a definite byteOrder." |
|
3323 | 1104 |
|
1105 |
|w| |
|
1106 |
||
3434 | 1107 |
%{ |
1108 |
/* |
|
1109 |
* handle the most common cases fast ... |
|
1110 |
*/ |
|
1111 |
if (__isSmallInteger(index)) { |
|
4308 | 1112 |
unsigned char *cp; |
1113 |
int sz; |
|
3434 | 1114 |
|
4308 | 1115 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
1116 |
if (cp) { |
|
1117 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 1118 |
|
4308 | 1119 |
if ((idx+(sizeof(int)-1)) < sz) { |
1120 |
cp += idx; |
|
1121 |
#if defined(i386) |
|
1122 |
/* |
|
1123 |
* aligned or not, we dont care (i386 can do both) |
|
1124 |
*/ |
|
1125 |
{ |
|
1126 |
int iVal = ((int *)cp)[0]; |
|
3434 | 1127 |
|
4308 | 1128 |
RETURN (__MKINT(iVal)); |
1129 |
} |
|
1130 |
#else |
|
1131 |
/* |
|
1132 |
* aligned |
|
1133 |
*/ |
|
1134 |
if (((INT)cp & (sizeof(int)-1)) == 0) { |
|
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1135 |
int iVal = ((int *)cp)[0]; |
4308 | 1136 |
|
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1137 |
# ifdef alpha64 |
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1138 |
RETURN (__MKSMALLINT(iVal)); |
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1139 |
# else |
4308 | 1140 |
RETURN (__MKINT(iVal)); |
4312
63eb0ccfd909
no need to call MKINT / MKUINT for 4-byte ints on alpha64
Claus Gittinger <cg@exept.de>
parents:
4308
diff
changeset
|
1141 |
# endif |
4308 | 1142 |
} |
1143 |
#endif |
|
1144 |
} |
|
1145 |
} |
|
3434 | 1146 |
} |
1147 |
%}. |
|
1148 |
||
3323 | 1149 |
w := self unsignedLongAt:index. |
1150 |
(w > (16r7FFFFFFF)) ifTrue:[ |
|
4308 | 1151 |
^ w - (16r100000000) |
3323 | 1152 |
]. |
1153 |
^ w |
|
1154 |
||
1155 |
" |
|
1156 |
|b| |
|
1157 |
b := ByteArray new:4. |
|
1158 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
1159 |
(b longAt:1) |
|
1160 |
" |
|
1161 |
||
1162 |
"Modified: / 1.7.1996 / 21:11:28 / cg" |
|
1163 |
"Modified: / 5.3.1998 / 12:06:28 / stefan" |
|
1164 |
! |
|
1165 |
||
1166 |
longAt:index bigEndian:msb |
|
1167 |
"return the 4-bytes starting at index as a signed Integer. |
|
3433 | 1168 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1169 |
Depending on msb, the value is retrieved MSB-first or LSB-first. |
1170 |
This may be worth a primitive." |
|
1171 |
||
1172 |
|w| |
|
1173 |
||
1174 |
w := self unsignedLongAt:index bigEndian:msb. |
|
1175 |
(w > (16r7FFFFFFF)) ifTrue:[ |
|
4308 | 1176 |
^ w - (16r100000000) |
3323 | 1177 |
]. |
1178 |
^ w |
|
1179 |
||
1180 |
" |
|
1181 |
|b| |
|
1182 |
b := ByteArray new:4. |
|
1183 |
b unsignedLongAt:1 put:16rFFFFFFFF. |
|
1184 |
(b longAt:1) |
|
1185 |
" |
|
1186 |
||
1187 |
"Modified: / 1.7.1996 / 21:11:33 / cg" |
|
1188 |
"Created: / 5.3.1998 / 14:02:03 / stefan" |
|
1189 |
! |
|
1190 |
||
1191 |
longAt:index put:value |
|
1192 |
"set the 4-bytes starting at index from the signed Integer value. |
|
3433 | 1193 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1194 |
The value is stored in the machines natural byte order. |
1195 |
This may be worth a primitive. |
|
1196 |
||
1197 |
This is the ST80 version of #signedDoubleWordAt:put:" |
|
1198 |
||
1199 |
|v| |
|
1200 |
||
3434 | 1201 |
%{ |
1202 |
/* |
|
1203 |
* handle the most common cases fast ... |
|
1204 |
*/ |
|
1205 |
if (__isSmallInteger(index)) { |
|
4308 | 1206 |
unsigned char *cp; |
1207 |
int sz; |
|
3434 | 1208 |
|
4308 | 1209 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
1210 |
if (cp) { |
|
1211 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
3434 | 1212 |
|
4308 | 1213 |
if ((idx+(sizeof(int)-1)) < sz) { |
1214 |
cp += idx; |
|
1215 |
/* |
|
1216 |
* aligned |
|
1217 |
*/ |
|
1218 |
if (((INT)cp & (sizeof(int)-1)) == 0) { |
|
3434 | 1219 |
int __v; |
1220 |
||
4308 | 1221 |
if (__isSmallInteger(value)) { |
1222 |
((int *)cp)[0] = __intVal(value); |
|
1223 |
RETURN (value); |
|
3434 | 1224 |
} |
1225 |
if (__v = __signedLongIntVal(value)) { |
|
1226 |
((int *)cp)[0] = __v; |
|
1227 |
RETURN (value); |
|
1228 |
} |
|
4308 | 1229 |
} |
1230 |
} |
|
1231 |
} |
|
3434 | 1232 |
} |
1233 |
%}. |
|
1234 |
||
3323 | 1235 |
value >= 0 ifTrue:[ |
4308 | 1236 |
v := value |
3323 | 1237 |
] ifFalse:[ |
4308 | 1238 |
v := value + 16r100000000 |
3323 | 1239 |
]. |
1240 |
self unsignedLongAt:index put:v. |
|
1241 |
^ value |
|
1242 |
||
1243 |
" |
|
1244 |
|b| |
|
1245 |
b := ByteArray new:4. |
|
1246 |
b longAt:1 put:-1. |
|
1247 |
(b unsignedLongAt:1) printStringRadix:16 |
|
1248 |
" |
|
1249 |
||
1250 |
"Modified: / 1.7.1996 / 21:11:39 / cg" |
|
1251 |
"Created: / 5.3.1998 / 10:57:18 / stefan" |
|
1252 |
! |
|
1253 |
||
3444 | 1254 |
longAt:byteIndex put:anInteger bigEndian:msb |
1255 |
"store a signed long (32bit) integer. |
|
1256 |
The index is a smalltalk index (i.e. 1-based). |
|
1257 |
Same as #signedQuadWordAt:put: - for ST80 compatibility." |
|
1258 |
||
1259 |
|v| |
|
1260 |
||
1261 |
v := anInteger. |
|
1262 |
anInteger < 0 ifTrue:[ |
|
4308 | 1263 |
v := v + 16r100000000 |
3444 | 1264 |
]. |
1265 |
^ self unsignedLongAt:byteIndex put:v bigEndian:msb |
|
1266 |
||
1267 |
"Created: / 9.5.1998 / 01:10:24 / cg" |
|
1268 |
"Modified: / 9.5.1998 / 01:13:34 / cg" |
|
1269 |
! |
|
1270 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1271 |
signedDoubleWordAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1272 |
"return the 4-bytes starting at index as a signed Integer. |
3433 | 1273 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1274 |
The value is retrieved in the machines natural byte order. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1275 |
This may be worth a primitive." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1276 |
|
4515 | 1277 |
^ self signedDoubleWordAt:index MSB:(UninterpretedBytes isBigEndian) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1278 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1279 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1280 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1281 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1282 |
b doubleWordAt:1 put:16rFFFFFFFF. |
4515 | 1283 |
(b signedDoubleWordAt:1) |
1284 |
" |
|
1285 |
" |
|
1286 |
|b| |
|
1287 |
b := ByteArray new:4. |
|
1288 |
b signedDoubleWordAt:1 put:-1. |
|
1289 |
(b doubleWordAt:1) |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1290 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1291 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1292 |
"Modified: 1.7.1996 / 21:11:28 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1293 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1294 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1295 |
signedDoubleWordAt:index MSB:msb |
4515 | 1296 |
"return the 4-bytes starting at index as a (signed) Integer. |
3433 | 1297 |
The index is a smalltalk index (i.e. 1-based). |
4515 | 1298 |
The value is retrieved MSB-first, if the msb-arg is true; |
1299 |
LSB-first otherwise." |
|
1300 |
||
1301 |
|val |
|
1302 |
ival "{ Class: SmallInteger }" |
|
1303 |
t "{ Class: SmallInteger }" |
|
1304 |
i "{ Class: SmallInteger }" |
|
1305 |
b1 "{ Class: SmallInteger }" |
|
1306 |
b2 "{ Class: SmallInteger }" |
|
1307 |
b3 "{ Class: SmallInteger }" |
|
1308 |
b4 "{ Class: SmallInteger }"| |
|
1309 |
||
1310 |
%{ |
|
1311 |
/* |
|
1312 |
* handle the most common cases fast ... |
|
1313 |
*/ |
|
1314 |
if (__isSmallInteger(index)) { |
|
1315 |
unsigned char *cp; |
|
1316 |
int sz; |
|
1317 |
||
1318 |
__fetchBytePointerAndSize__(self, &cp, &sz); |
|
1319 |
if (cp) { |
|
1320 |
unsigned INT idx = ((unsigned INT)__intVal(index)) - 1; |
|
1321 |
int iVal; |
|
1322 |
||
1323 |
if ((idx+(sizeof(int)-1)) < sz) { |
|
1324 |
cp += idx; |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1325 |
|
4515 | 1326 |
if (msb == true) { |
1327 |
#if defined(__MSBFIRST) || defined(sparc) |
|
1328 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
|
1329 |
/* |
|
1330 |
* aligned |
|
1331 |
*/ |
|
1332 |
iVal = ((int *)cp)[0]; |
|
1333 |
} else |
|
1334 |
#endif |
|
1335 |
{ |
|
1336 |
iVal = cp[0]; |
|
1337 |
iVal = (iVal << 8) | cp[1]; |
|
1338 |
iVal = (iVal << 8) | cp[2]; |
|
1339 |
iVal = (iVal << 8) | cp[3]; |
|
1340 |
} |
|
1341 |
} else { |
|
1342 |
#if defined(i386) || (defined(UNALIGNED_FETCH_OK) && defined(__LSBFIRST)) |
|
1343 |
/* |
|
1344 |
* aligned or not - we dont care |
|
1345 |
* (i386 can fetch unaligned) |
|
1346 |
*/ |
|
1347 |
iVal = ((int *)cp)[0]; |
|
1348 |
#else |
|
1349 |
# if defined(__LSBFIRST) || defined(i386) |
|
1350 |
if (((INT)cp & (sizeof(int)-1))== 0) { |
|
1351 |
/* |
|
1352 |
* aligned |
|
1353 |
*/ |
|
1354 |
iVal = ((int *)cp)[0]; |
|
1355 |
} else |
|
1356 |
# endif |
|
1357 |
{ |
|
1358 |
iVal = cp[3]; |
|
1359 |
iVal = (iVal << 8) | cp[2]; |
|
1360 |
iVal = (iVal << 8) | cp[1]; |
|
1361 |
iVal = (iVal << 8) | cp[0]; |
|
1362 |
} |
|
1363 |
#endif |
|
1364 |
} |
|
1365 |
#ifdef alpha64 |
|
1366 |
RETURN (__MKSMALLINT(iVal)); |
|
1367 |
#else |
|
1368 |
RETURN (__MKINT(iVal)); |
|
1369 |
#endif |
|
1370 |
} |
|
1371 |
} |
|
1372 |
} |
|
1373 |
%}. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1374 |
|
4515 | 1375 |
"/ fallBack code - non ByteArray-like receiver |
1376 |
"/ or funny index |
|
1377 |
||
1378 |
i := index. |
|
1379 |
b1 := self at:i. |
|
1380 |
b2 := self at:(i+1). |
|
1381 |
b3 := self at:(i+2). |
|
1382 |
b4 := self at:(i+3). |
|
1383 |
||
1384 |
msb ifFalse:[ |
|
1385 |
t := b4. b4 := b1. b1 := t. |
|
1386 |
t := b3. b3 := b2. b2 := t. |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1387 |
]. |
4515 | 1388 |
ival := b1. |
1389 |
ival := (ival bitShift:8) + b2. |
|
1390 |
ival := (ival bitShift:8) + b3. |
|
1391 |
val := (ival bitShift:8) + b4. |
|
1392 |
||
1393 |
(val > (16r7FFFFFFF)) ifTrue:[ |
|
1394 |
^ val - (16r100000000) |
|
1395 |
]. |
|
1396 |
^ val |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1397 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1398 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1399 |
|b| |
4515 | 1400 |
|
1401 |
b := ByteArray withAll:#(1 2 3 4). |
|
1402 |
(b signedDoubleWordAt:1 MSB:true) printStringRadix:16. |
|
1403 |
(b signedDoubleWordAt:1 MSB:false) printStringRadix:16 |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1404 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1405 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1406 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1407 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1408 |
signedDoubleWordAt:index put:value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1409 |
"set the 4-bytes starting at index from the signed Integer value. |
3433 | 1410 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1411 |
The value is stored in the machines natural byte order. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1412 |
This may be worth a primitive." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1413 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1414 |
|v| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1415 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1416 |
value >= 0 ifTrue:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1417 |
v := value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1418 |
] ifFalse:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1419 |
v := value + 16r100000000 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1420 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1421 |
self doubleWordAt:index put:v. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1422 |
^ value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1423 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1424 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1425 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1426 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1427 |
b signedDoubleWordAt:1 put:-1. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1428 |
(b doubleWordAt:1) printStringRadix:16 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1429 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1430 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1431 |
"Modified: 1.7.1996 / 21:11:39 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1432 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1433 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1434 |
signedDoubleWordAt:index put:value MSB:msb |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1435 |
"set the 4-bytes starting at index from the signed Integer value. |
3433 | 1436 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1437 |
Depending on msb, the value is stored MSB-first or LSB-first. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1438 |
This may be worth a primitive." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1439 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1440 |
|v| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1441 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1442 |
value >= 0 ifTrue:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1443 |
v := value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1444 |
] ifFalse:[ |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1445 |
v := value + 16r100000000 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1446 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1447 |
self doubleWordAt:index put:v MSB:msb. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1448 |
^ value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1449 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1450 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1451 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1452 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1453 |
b signedDoubleWordAt:1 put:-1. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1454 |
(b doubleWordAt:1) printStringRadix:16 |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1455 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1456 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1457 |
"Modified: 1.7.1996 / 21:11:46 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1458 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1459 |
|
3323 | 1460 |
unsignedLongAt:index |
1461 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
3433 | 1462 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1463 |
The value is retrieved in the machines natural byte order. |
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1464 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1465 |
Same as doubleWordAt: for protocol completeness" |
3323 | 1466 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1467 |
^ self doubleWordAt:index |
3323 | 1468 |
|
1469 |
" |
|
1470 |
|b| |
|
1471 |
||
1472 |
b := ByteArray withAll:#(1 2 3 4). |
|
1473 |
(b unsignedLongAt:1) printStringRadix:16 |
|
1474 |
" |
|
1475 |
||
1476 |
"Created: / 5.3.1998 / 11:56:53 / stefan" |
|
1477 |
"Modified: / 5.3.1998 / 14:58:48 / stefan" |
|
1478 |
! |
|
1479 |
||
1480 |
unsignedLongAt:index bigEndian:msb |
|
1481 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
|
3433 | 1482 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1483 |
The value is retrieved MSB-first, if the msb-arg is true; |
1484 |
LSB-first otherwise. |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1485 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1486 |
Same as doubleWordAt:MSB: for protocol completeness" |
3323 | 1487 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1488 |
^ self doubleWordAt:index MSB:msb |
3323 | 1489 |
|
1490 |
" |
|
1491 |
|b| |
|
1492 |
||
1493 |
b := ByteArray withAll:#(1 2 3 4). |
|
1494 |
(b unsignedLongAt:1 bigEndian:true) printStringRadix:16. |
|
1495 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1496 |
" |
|
1497 |
||
1498 |
"Modified: / 21.1.1998 / 17:42:30 / cg" |
|
1499 |
"Created: / 5.3.1998 / 11:46:05 / stefan" |
|
1500 |
! |
|
1501 |
||
1502 |
unsignedLongAt:index put:value |
|
1503 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 1504 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1505 |
The value should be in the range 0 to 16rFFFFFFFF |
1506 |
(for negative values, the stored value is not defined). |
|
1507 |
The value is stored in the machines natural byte order. |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1508 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1509 |
Same as doubleWordAt:put: for protocol completeness" |
3323 | 1510 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1511 |
^ self doubleWordAt:index put:value |
3323 | 1512 |
|
1513 |
" |
|
1514 |
|b| |
|
1515 |
b := ByteArray new:4. |
|
1516 |
b unsignedLongAt:1 put:16r04030201. |
|
1517 |
b inspect |
|
1518 |
" |
|
1519 |
||
1520 |
"Created: / 5.3.1998 / 11:57:44 / stefan" |
|
1521 |
"Modified: / 5.3.1998 / 14:58:59 / stefan" |
|
1522 |
! |
|
1523 |
||
1524 |
unsignedLongAt:index put:aNumber bigEndian:msb |
|
1525 |
"set the 4-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 1526 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1527 |
The value must be in the range 0 to 16rFFFFFFFF. |
1528 |
The value is stored MSB-first if msb is true; LSB-first otherwise. |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1529 |
Subclasses may redefine this for better performance. |
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1530 |
Same as doubleWordAt:put:MSB: for protocol completeness" |
3323 | 1531 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1532 |
^ self doubleWordAt:index put:aNumber MSB:msb |
3323 | 1533 |
|
1534 |
" |
|
1535 |
|b| |
|
1536 |
b := ByteArray new:8. |
|
1537 |
b unsignedLongAt:1 put:16r04030201 bigEndian:true. |
|
1538 |
(b unsignedLongAt:1 bigEndian:false) printStringRadix:16 |
|
1539 |
" |
|
1540 |
||
1541 |
"Modified: / 21.1.1998 / 17:43:34 / cg" |
|
1542 |
"Created: / 5.3.1998 / 11:43:53 / stefan" |
|
1543 |
"Modified: / 5.3.1998 / 11:47:30 / stefan" |
|
3459 | 1544 |
! ! |
1545 |
||
1546 |
!UninterpretedBytes methodsFor:'accessing-shorts'! |
|
1547 |
||
1548 |
shortAt:index |
|
1549 |
"return the 2-bytes starting at index as a signed Integer. |
|
1550 |
The index is a smalltalk index (i.e. 1-based). |
|
1551 |
The value is retrieved in the machines natural byte order. |
|
1552 |
This may be worth a primitive. |
|
1553 |
This is the ST80 equivalent of #signedWordAt:" |
|
1554 |
||
1555 |
^ (self unsignedShortAt:index) signExtendedShortValue |
|
1556 |
||
1557 |
" |
|
1558 |
|b| |
|
1559 |
b := ByteArray new:2. |
|
1560 |
b unsignedShortAt:1 put:16rFFFF. |
|
1561 |
b shortAt:1 |
|
1562 |
" |
|
1563 |
||
1564 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
|
1565 |
"Created: / 5.3.1998 / 10:59:57 / stefan" |
|
1566 |
"Modified: / 5.3.1998 / 23:39:38 / stefan" |
|
3323 | 1567 |
! |
1568 |
||
3459 | 1569 |
shortAt:index bigEndian:msb |
1570 |
"return the 2-bytes starting at index as a signed Integer. |
|
3433 | 1571 |
The index is a smalltalk index (i.e. 1-based). |
3459 | 1572 |
The value is retrieved MSB-first, if the msb-arg is true; |
1573 |
LSB-first otherwise. |
|
1574 |
This is the ST80 equivalent of #signedWordAt:" |
|
1575 |
||
1576 |
^ (self unsignedShortAt:index bigEndian:msb) signExtendedShortValue |
|
1577 |
||
1578 |
" |
|
1579 |
|b| |
|
1580 |
b := ByteArray new:2. |
|
1581 |
b unsignedShortAt:1 put:16rFFFF. |
|
1582 |
b shortAt:1 |
|
1583 |
" |
|
3323 | 1584 |
|
3459 | 1585 |
"Modified: / 1.7.1996 / 21:14:38 / cg" |
1586 |
"Created: / 5.3.1998 / 23:41:21 / stefan" |
|
1587 |
! |
|
1588 |
||
1589 |
shortAt:index put:value |
|
1590 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1591 |
The index is a smalltalk index (i.e. 1-based). |
|
1592 |
The stored value must be in the range -32768 .. +32676. |
|
1593 |
The value is stored in the machines natural byteorder. |
|
1594 |
This may be worth a primitive. |
|
1595 |
This is the ST80 equivalent of #signedWordAt:put:" |
|
1596 |
||
3323 | 1597 |
|
3459 | 1598 |
|v| |
1599 |
||
1600 |
value >= 0 ifTrue:[ |
|
4308 | 1601 |
v := value |
3323 | 1602 |
] ifFalse:[ |
4308 | 1603 |
v := 16r10000 + value |
3323 | 1604 |
]. |
3459 | 1605 |
self unsignedShortAt:index put:v. |
1606 |
^ value |
|
1607 |
||
1608 |
" |
|
1609 |
|b| |
|
1610 |
b := ByteArray new:6. |
|
1611 |
b shortAt:1 put:-1. |
|
1612 |
b shortAt:3 put:-2. |
|
1613 |
b shortAt:5 put:0. |
|
1614 |
b inspect |
|
1615 |
" |
|
1616 |
||
1617 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
|
1618 |
"Created: / 5.3.1998 / 11:02:05 / stefan" |
|
1619 |
! |
|
1620 |
||
1621 |
signedWordAt:index |
|
1622 |
"return the 2-bytes starting at index as a signed Integer. |
|
1623 |
The index is a smalltalk index (i.e. 1-based). |
|
1624 |
The value is retrieved in the machines natural byte order. |
|
1625 |
This may be worth a primitive." |
|
1626 |
||
1627 |
^ (self wordAt:index) signExtendedShortValue |
|
3323 | 1628 |
|
1629 |
" |
|
1630 |
|b| |
|
3459 | 1631 |
b := ByteArray new:2. |
1632 |
b wordAt:1 put:16rFFFF. |
|
1633 |
b signedWordAt:1 |
|
3323 | 1634 |
" |
1635 |
||
3459 | 1636 |
"Modified: 1.7.1996 / 21:14:38 / cg" |
3323 | 1637 |
! |
1638 |
||
3459 | 1639 |
signedWordAt:index MSB:msb |
1640 |
"return the 2-bytes starting at index as a signed Integer. |
|
3433 | 1641 |
The index is a smalltalk index (i.e. 1-based). |
3459 | 1642 |
The value is retrieved MSB-first if the msb-arg is true, |
1643 |
LSB-first otherwise. |
|
1644 |
This may be worth a primitive." |
|
3323 | 1645 |
|
3459 | 1646 |
^ (self wordAt:index MSB:msb) signExtendedShortValue |
3323 | 1647 |
|
1648 |
" |
|
1649 |
|b| |
|
3459 | 1650 |
b := ByteArray new:2. |
1651 |
b wordAt:1 put:16r0080. |
|
1652 |
b signedWordAt:1 MSB:true. |
|
1653 |
b signedWordAt:1 MSB:false. |
|
1654 |
" |
|
1655 |
||
1656 |
"Modified: 1.7.1996 / 21:15:57 / cg" |
|
1657 |
! |
|
1658 |
||
1659 |
signedWordAt:index put:value |
|
1660 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1661 |
The index is a smalltalk index (i.e. 1-based). |
|
1662 |
The stored value must be in the range -32768 .. +32676. |
|
1663 |
The value is stored in the machines natural byteorder. |
|
1664 |
This may be worth a primitive. |
|
1665 |
This is the ST80 equivalent of #signedWordAt:put:" |
|
1666 |
||
1667 |
||
1668 |
|v| |
|
1669 |
||
1670 |
value >= 0 ifTrue:[ |
|
4308 | 1671 |
v := value |
3459 | 1672 |
] ifFalse:[ |
4308 | 1673 |
v := 16r10000 + value |
3459 | 1674 |
]. |
1675 |
self unsignedShortAt:index put:v. |
|
1676 |
^ value |
|
1677 |
||
1678 |
" |
|
1679 |
|b| |
|
1680 |
b := ByteArray new:6. |
|
1681 |
b shortAt:1 put:-1. |
|
1682 |
b shortAt:3 put:-2. |
|
1683 |
b shortAt:5 put:0. |
|
3323 | 1684 |
b inspect |
1685 |
" |
|
1686 |
||
3459 | 1687 |
"Modified: / 1.7.1996 / 21:12:07 / cg" |
1688 |
"Modified: / 5.3.1998 / 11:01:30 / stefan" |
|
1689 |
! |
|
1690 |
||
1691 |
signedWordAt:index put:value MSB:msb |
|
1692 |
"set the 2-bytes starting at index from the signed Integer value. |
|
1693 |
The index is a smalltalk index (i.e. 1-based). |
|
1694 |
The stored value must be in the range -32768 .. +32676. |
|
1695 |
The value is stored MSB-first, if the msb-arg is true; |
|
1696 |
LSB-first otherwise. |
|
1697 |
This may be worth a primitive." |
|
1698 |
||
1699 |
|v| |
|
1700 |
||
1701 |
value >= 0 ifTrue:[ |
|
1702 |
v := value |
|
1703 |
] ifFalse:[ |
|
1704 |
v := 16r10000 + value |
|
1705 |
]. |
|
1706 |
self wordAt:index put:v MSB:msb. |
|
1707 |
^ value |
|
1708 |
||
1709 |
" |
|
1710 |
|b| |
|
1711 |
b := ByteArray new:4. |
|
1712 |
b signedWordAt:1 put:-1. |
|
1713 |
b signedWordAt:3 put:-2. |
|
1714 |
b inspect |
|
1715 |
" |
|
1716 |
||
1717 |
"Modified: 1.7.1996 / 21:12:13 / cg" |
|
3323 | 1718 |
! |
1719 |
||
1720 |
unsignedShortAt:index |
|
1721 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
3433 | 1722 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1723 |
The value is retrieved in the machines natural byte order |
1724 |
Subclasses may redefine this for better performance. |
|
1725 |
This is the ST80 equivalent of #wordAt:" |
|
1726 |
||
1727 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1728 |
^ self unsignedShortAt:index bigEndian:(UninterpretedBytes isBigEndian) |
3323 | 1729 |
|
1730 |
"Created: / 5.3.1998 / 11:38:25 / stefan" |
|
1731 |
"Modified: / 5.3.1998 / 14:59:25 / stefan" |
|
1732 |
! |
|
1733 |
||
1734 |
unsignedShortAt:index bigEndian:msb |
|
1735 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
|
3433 | 1736 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1737 |
The value is retrieved MSB-first (high 8 bits at lower index) if msb is true; |
1738 |
LSB-first (i.e. low 8-bits at lower byte index) if its false)" |
|
1739 |
||
1740 |
|b1 "{ Class: SmallInteger }" |
|
1741 |
b2 "{ Class: SmallInteger }"| |
|
1742 |
||
1743 |
b1 := self at:index. |
|
1744 |
b2 := self at:(index + 1). |
|
1745 |
msb ifTrue:[ |
|
4308 | 1746 |
^ (b1 bitShift:8) + b2 |
3323 | 1747 |
]. |
1748 |
^ (b2 bitShift:8) + b1 |
|
1749 |
||
1750 |
"Modified: / 21.1.1998 / 17:46:07 / cg" |
|
1751 |
"Created: / 5.3.1998 / 11:49:29 / stefan" |
|
1752 |
! |
|
1753 |
||
1754 |
unsignedShortAt:index put:value |
|
1755 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 1756 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1757 |
The stored value must be in the range 0 .. 16rFFFF. |
1758 |
The value is stored in the machines natural byteorder." |
|
1759 |
||
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1760 |
^ self unsignedShortAt:index put:value bigEndian:(UninterpretedBytes isBigEndian) |
3323 | 1761 |
|
1762 |
" |
|
1763 |
|b| |
|
1764 |
b := ByteArray new:4. |
|
1765 |
b unsignedShortAt:1 put:16r0102. |
|
1766 |
b unsignedShortAt:3 put:16r0304. |
|
1767 |
b inspect |
|
1768 |
" |
|
1769 |
||
1770 |
"Created: / 5.3.1998 / 11:54:52 / stefan" |
|
1771 |
"Modified: / 5.3.1998 / 14:59:38 / stefan" |
|
1772 |
! |
|
1773 |
||
1774 |
unsignedShortAt:index put:value bigEndian:msb |
|
1775 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
|
3433 | 1776 |
The index is a smalltalk index (i.e. 1-based). |
3323 | 1777 |
The stored value must be in the range 0 .. 16rFFFF. |
1778 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
|
1779 |
lower index) if msb is false, MSB-first otherwise" |
|
1780 |
||
1781 |
|b1 b2 |
|
1782 |
iVal "{ Class: SmallInteger }"| |
|
1783 |
||
1784 |
iVal := value. |
|
1785 |
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[ |
|
4308 | 1786 |
^ self elementBoundsError |
3323 | 1787 |
]. |
1788 |
msb ifTrue:[ |
|
4308 | 1789 |
b1 := ((iVal bitShift:-8) bitAnd:16rFF). |
1790 |
b2 := (iVal bitAnd:16rFF). |
|
3323 | 1791 |
] ifFalse:[ |
4308 | 1792 |
b1 := (iVal bitAnd:16rFF). |
1793 |
b2 := ((iVal bitShift:-8) bitAnd:16rFF). |
|
3323 | 1794 |
]. |
1795 |
self at:index put:b1. |
|
1796 |
self at:index+1 put:b2. |
|
1797 |
^ value |
|
1798 |
||
1799 |
" |
|
1800 |
|b| |
|
1801 |
b := ByteArray new:8. |
|
1802 |
b unsignedShortAt:1 put:16r0102 bigEndian:false. |
|
1803 |
b unsignedShortAt:3 put:16r0304 bigEndian:false. |
|
1804 |
b unsignedShortAt:5 put:16r0102 bigEndian:true. |
|
1805 |
b unsignedShortAt:7 put:16r0304 bigEndian:true. |
|
1806 |
b inspect |
|
1807 |
" |
|
1808 |
||
1809 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
|
1810 |
"Modified: / 5.3.1998 / 11:52:28 / stefan" |
|
1811 |
! |
|
1812 |
||
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1813 |
wordAt:index |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1814 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 1815 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1816 |
The value is retrieved in the machines natural byte order |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1817 |
Subclasses may redefine this for better performance." |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1818 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1819 |
^ self wordAt:index MSB:(UninterpretedBytes isBigEndian) |
3323 | 1820 |
|
1821 |
"Modified: / 5.3.1998 / 14:59:51 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1822 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1823 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1824 |
wordAt:index MSB:msb |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1825 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
3433 | 1826 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1827 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1828 |
LSB-first (i.e. low 8-bits at lower byte index) if its false. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1829 |
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1830 |
|
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1831 |
|b1 "{ Class: SmallInteger }" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1832 |
b2 "{ Class: SmallInteger }"| |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1833 |
|
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1834 |
b1 := self at:index. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1835 |
b2 := self at:(index + 1). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1836 |
msb ifTrue:[ |
4308 | 1837 |
^ (b1 bitShift:8) + b2 |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1838 |
]. |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1839 |
^ (b2 bitShift:8) + b1 |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1840 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1841 |
"Modified: / 21.1.1998 / 17:46:07 / cg" |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1842 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1843 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1844 |
wordAt:index put:value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1845 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 1846 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1847 |
The stored value must be in the range 0 .. 16rFFFF. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1848 |
The value is stored in the machines natural byteorder. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1849 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1850 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1851 |
^ self wordAt:index put:value MSB:(UninterpretedBytes isBigEndian) |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1852 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1853 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1854 |
|b| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1855 |
b := ByteArray new:4. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1856 |
b wordAt:1 put:16r0102. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1857 |
b wordAt:3 put:16r0304. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1858 |
b inspect |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1859 |
" |
3323 | 1860 |
|
1861 |
"Modified: / 5.3.1998 / 15:00:03 / stefan" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1862 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1863 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1864 |
wordAt:index put:value MSB:msb |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1865 |
"set the 2-bytes starting at index from the (unsigned) Integer value. |
3433 | 1866 |
The index is a smalltalk index (i.e. 1-based). |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1867 |
The stored value must be in the range 0 .. 16rFFFF. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1868 |
The value is stored LSB-first (i.e. the low 8bits are stored at the |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1869 |
lower index) if msb is false, MSB-first otherwise. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1870 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1871 |
|
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1872 |
|b1 b2 |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1873 |
iVal "{ Class: SmallInteger }"| |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1874 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1875 |
iVal := value. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1876 |
((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[ |
4308 | 1877 |
^ self elementBoundsError |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1878 |
]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1879 |
msb ifTrue:[ |
4308 | 1880 |
b1 := ((iVal bitShift:-8) bitAnd:16rFF). |
1881 |
b2 := (iVal bitAnd:16rFF). |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1882 |
] ifFalse:[ |
4308 | 1883 |
b1 := (iVal bitAnd:16rFF). |
1884 |
b2 := ((iVal bitShift:-8) bitAnd:16rFF). |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1885 |
]. |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1886 |
self at:index put:b1. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1887 |
self at:index+1 put:b2. |
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1888 |
^ value |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1889 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1890 |
" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1891 |
b := ByteArray new:8. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1892 |
b wordAt:1 put:16r0102 MSB:false. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1893 |
b wordAt:3 put:16r0304 MSB:false. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1894 |
b wordAt:5 put:16r0102 MSB:true. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1895 |
b wordAt:7 put:16r0304 MSB:true. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1896 |
b inspect |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
1897 |
" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1898 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1899 |
"Modified: / 21.1.1998 / 17:48:15 / cg" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1900 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1901 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1902 |
wordAtWordIndex:index |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1903 |
"return the unsigned short at index, anInteger. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1904 |
Fetching in the machines natural byte order. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1905 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1906 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1907 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1908 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1909 |
^ self wordAtWordIndex:index MSB:(UninterpretedBytes isBigEndian) |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1910 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1911 |
"Created: / 21.1.1998 / 17:48:26 / cg" |
3323 | 1912 |
"Modified: / 5.3.1998 / 15:00:16 / stefan" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1913 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1914 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1915 |
wordAtWordIndex:index MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1916 |
"return the unsigned short at index, anInteger. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1917 |
Fetching is MSB if msb is true, LSB otherwise. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1918 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1919 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1920 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1921 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1922 |
^ self wordAt:(index - 1 * 2 + 1) MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1923 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1924 |
"Created: / 21.1.1998 / 17:48:30 / cg" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1925 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1926 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1927 |
wordAtWordIndex:index put:value |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1928 |
"set the short at index, anInteger. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1929 |
Storing in the machines natural byte order. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1930 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1931 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1932 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1933 |
|
4019
c9284ca27a4a
tuned some doubleWordAt methods;
Claus Gittinger <cg@exept.de>
parents:
3936
diff
changeset
|
1934 |
^ self wordAtWordIndex:index put:value MSB:(UninterpretedBytes isBigEndian) |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1935 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1936 |
"Created: / 21.1.1998 / 17:48:34 / cg" |
3323 | 1937 |
"Modified: / 5.3.1998 / 15:00:27 / stefan" |
3212
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1938 |
! |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1939 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1940 |
wordAtWordIndex:index put:value MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1941 |
"set the short at index, anInteger. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1942 |
Storing is MSB if msb is true, LSB otherwise. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1943 |
Indices are 1-based and scaled as appropriate to allow |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1944 |
accessing the memory as an array of word entries. |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1945 |
(i.e. indices are 1, 2, ...)" |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1946 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1947 |
^ self wordAt:(index - 1 * 2 + 1) put:value MSB:msb |
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1948 |
|
b8cc18f8691b
moved some of ExtBytes protocol to here.
Claus Gittinger <cg@exept.de>
parents:
3209
diff
changeset
|
1949 |
"Created: / 21.1.1998 / 17:48:38 / cg" |
3459 | 1950 |
! ! |
1951 |
||
1952 |
!UninterpretedBytes methodsFor:'accessing-strings'! |
|
1953 |
||
1954 |
stringAt:index |
|
1955 |
"return a string starting at index up to the 0-byte. |
|
1956 |
The index is a smalltalk index (i.e. 1-based)." |
|
1957 |
||
1958 |
|stream i "{ Class: SmallInteger }" c| |
|
1959 |
||
1960 |
stream := WriteStream on:''. |
|
1961 |
i := index. |
|
1962 |
[(c := self basicAt:i) ~~ 0] whileTrue:[ |
|
4308 | 1963 |
stream nextPut:(Character value:c). |
1964 |
i := i + 1. |
|
3459 | 1965 |
]. |
1966 |
^ stream contents |
|
1967 |
||
1968 |
"Created: / 21.1.1998 / 17:44:50 / cg" |
|
1969 |
! |
|
1970 |
||
1971 |
stringAt:index put:aString |
|
1972 |
"copy aString to the externalBytes, starting at index up to |
|
1973 |
(and including) the 0-byte. |
|
1974 |
The index is a smalltalk index (i.e. 1-based)." |
|
1975 |
||
1976 |
|i "{ Class: SmallInteger }"| |
|
1977 |
||
1978 |
i := index. |
|
1979 |
aString do:[:aChar | |
|
4308 | 1980 |
self basicAt:i put:aChar asciiValue. |
1981 |
i := i + 1. |
|
3459 | 1982 |
]. |
1983 |
self basicAt:i put:0. |
|
1984 |
^ aString |
|
1985 |
||
1986 |
" |
|
1987 |
|bytes| |
|
1988 |
||
1989 |
bytes := ExternalBytes new:10. |
|
1990 |
bytes stringAt:1 put:'hello'. |
|
1991 |
1 to:bytes size do:[:i | |
|
4308 | 1992 |
Transcript showCR:(bytes at:i) |
3459 | 1993 |
] |
1994 |
" |
|
1995 |
||
1996 |
"Created: / 21.1.1998 / 17:45:02 / cg" |
|
1997 |
! |
|
1998 |
||
1999 |
stringAt:index size:maxSize |
|
2000 |
"return a string starting at index up to maxSize, or a 0-byte. |
|
2001 |
The index is a smalltalk index (i.e. 1-based)." |
|
2002 |
||
2003 |
|stream c i "{ Class: SmallInteger }"| |
|
2004 |
||
2005 |
stream := WriteStream on:(String new:maxSize). |
|
2006 |
i := index. |
|
2007 |
[(i <= maxSize) |
|
2008 |
and:[(c := self basicAt:i) ~~ 0]] whileTrue:[ |
|
4308 | 2009 |
stream nextPut:(Character value:c). |
2010 |
i := i + 1. |
|
3459 | 2011 |
]. |
2012 |
^ stream contents |
|
2013 |
||
2014 |
"Modified: / 21.1.1998 / 17:45:23 / cg" |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2015 |
! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2016 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2017 |
zeroByteStringAt:index maximumSize:count |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2018 |
"extract a zeroByte-delimited string, given initial index and |
3433 | 2019 |
maximum number of characters (bytes). |
2020 |
The index is a smalltalk index (i.e. 1-based)." |
|
3207
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2021 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2022 |
|bytes idx| |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2023 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2024 |
bytes := self copyFrom:index to:(index + count - 1). |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2025 |
idx := bytes indexOf:0. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2026 |
idx ~~ 0 ifTrue:[ bytes := bytes copyTo:idx-1 ]. |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2027 |
^ bytes asString |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2028 |
|
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2029 |
"Created: 9.9.1996 / 15:28:34 / cg" |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2030 |
! ! |
a6e3c98e2a8e
merged common protocol of ByteArray and ExternalBytes into this class.
Claus Gittinger <cg@exept.de>
parents:
1294
diff
changeset
|
2031 |
|
4782 | 2032 |
!UninterpretedBytes methodsFor:'filling & replacing'! |
2033 |
||
2034 |
replaceBytesFrom:start to:stop with:sourceBytes startingAt:sourceIndex |
|
2035 |
|srcIdx| |
|
2036 |
||
2037 |
srcIdx := sourceIndex. |
|
2038 |
start to:stop do:[:dstIdx | |
|
2039 |
self at:dstIdx put:(sourceBytes at:srcIdx). |
|
2040 |
srcIdx := srcIdx + 1 |
|
2041 |
]. |
|
2042 |
! ! |
|
2043 |
||
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2044 |
!UninterpretedBytes methodsFor:'misc'! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2045 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2046 |
swapLongAt:byteIndex |
3433 | 2047 |
"swap the byteOrder of a long. |
2048 |
The index is a smalltalk index (i.e. 1-based)." |
|
3363
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2049 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2050 |
|t| |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2051 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2052 |
t := self byteAt:byteIndex. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2053 |
self byteAt:byteIndex put:(self byteAt:(byteIndex + 3)). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2054 |
self byteAt:(byteIndex + 3) put:t. |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2055 |
t := self byteAt:(byteIndex + 1). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2056 |
self byteAt:(byteIndex + 1) put:(self byteAt:(byteIndex + 2)). |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2057 |
self byteAt:(byteIndex + 2) put:t |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2058 |
|
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2059 |
"Created: / 3.4.1998 / 13:37:01 / cg" |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2060 |
! ! |
3bb61f364fe3
added #from: and #swapLongAt: for ST80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3323
diff
changeset
|
2061 |
|
3323 | 2062 |
!UninterpretedBytes methodsFor:'queries'! |
2063 |
||
2064 |
sizeInBytes |
|
2065 |
"return the number of 8-bit bytes in the receiver. |
|
2066 |
This is needed since subclasse may redefine #size (TwoByteString)" |
|
2067 |
||
2068 |
^ super size |
|
2069 |
||
2070 |
"Created: / 5.3.1998 / 10:41:13 / stefan" |
|
2071 |
! ! |
|
2072 |
||
695 | 2073 |
!UninterpretedBytes class methodsFor:'documentation'! |
2074 |
||
2075 |
version |
|
4782 | 2076 |
^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.40 1999-09-21 00:23:30 cg Exp $' |
695 | 2077 |
! ! |