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