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