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