1 {
2      File:       CarbonCore/Endian.h
3 
4      Contains:   Endian swapping utilties
5                  The contents of this header file are deprecated.
6                  Use CFByteOrder API instead.
7 
8      Copyright:  � 1997-2011 by Apple Inc. All rights reserved.
9 }
10 {
11     Modified for use with Free Pascal
12     Version 308
13     Please report any bugs to <gpc@microbizz.nl>
14 }
15 
16 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
17 {$mode macpas}
18 {$modeswitch cblocks}
19 {$packenum 1}
20 {$macro on}
21 {$inline on}
22 {$calling mwpascal}
23 
24 unit Endian;
25 interface
26 {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
27 {$setc GAP_INTERFACES_VERSION := $0308}
28 
29 {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
30     {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
31 {$endc}
32 
33 {$ifc defined CPUPOWERPC and defined CPUI386}
34 	{$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
35 {$endc}
36 {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
37 	{$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
38 {$endc}
39 
40 {$ifc not defined __ppc__ and defined CPUPOWERPC32}
41 	{$setc __ppc__ := 1}
42 {$elsec}
43 	{$setc __ppc__ := 0}
44 {$endc}
45 {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
46 	{$setc __ppc64__ := 1}
47 {$elsec}
48 	{$setc __ppc64__ := 0}
49 {$endc}
50 {$ifc not defined __i386__ and defined CPUI386}
51 	{$setc __i386__ := 1}
52 {$elsec}
53 	{$setc __i386__ := 0}
54 {$endc}
55 {$ifc not defined __x86_64__ and defined CPUX86_64}
56 	{$setc __x86_64__ := 1}
57 {$elsec}
58 	{$setc __x86_64__ := 0}
59 {$endc}
60 {$ifc not defined __arm__ and defined CPUARM}
61 	{$setc __arm__ := 1}
62 {$elsec}
63 	{$setc __arm__ := 0}
64 {$endc}
65 {$ifc not defined __arm64__ and defined CPUAARCH64}
66   {$setc __arm64__ := 1}
67 {$elsec}
68   {$setc __arm64__ := 0}
69 {$endc}
70 
71 {$ifc defined cpu64}
72   {$setc __LP64__ := 1}
73 {$elsec}
74   {$setc __LP64__ := 0}
75 {$endc}
76 
77 
78 {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
79 	{$error Conflicting definitions for __ppc__ and __i386__}
80 {$endc}
81 
82 {$ifc defined __ppc__ and __ppc__}
83 	{$setc TARGET_CPU_PPC := TRUE}
84 	{$setc TARGET_CPU_PPC64 := FALSE}
85 	{$setc TARGET_CPU_X86 := FALSE}
86 	{$setc TARGET_CPU_X86_64 := FALSE}
87 	{$setc TARGET_CPU_ARM := FALSE}
88 	{$setc TARGET_CPU_ARM64 := FALSE}
89 	{$setc TARGET_OS_MAC := TRUE}
90 	{$setc TARGET_OS_IPHONE := FALSE}
91 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
92 	{$setc TARGET_OS_EMBEDDED := FALSE}
93 {$elifc defined __ppc64__ and __ppc64__}
94 	{$setc TARGET_CPU_PPC := FALSE}
95 	{$setc TARGET_CPU_PPC64 := TRUE}
96 	{$setc TARGET_CPU_X86 := FALSE}
97 	{$setc TARGET_CPU_X86_64 := FALSE}
98 	{$setc TARGET_CPU_ARM := FALSE}
99 	{$setc TARGET_CPU_ARM64 := FALSE}
100 	{$setc TARGET_OS_MAC := TRUE}
101 	{$setc TARGET_OS_IPHONE := FALSE}
102 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
103 	{$setc TARGET_OS_EMBEDDED := FALSE}
104 {$elifc defined __i386__ and __i386__}
105 	{$setc TARGET_CPU_PPC := FALSE}
106 	{$setc TARGET_CPU_PPC64 := FALSE}
107 	{$setc TARGET_CPU_X86 := TRUE}
108 	{$setc TARGET_CPU_X86_64 := FALSE}
109 	{$setc TARGET_CPU_ARM := FALSE}
110 	{$setc TARGET_CPU_ARM64 := FALSE}
111 {$ifc defined iphonesim}
112  	{$setc TARGET_OS_MAC := FALSE}
113 	{$setc TARGET_OS_IPHONE := TRUE}
114 	{$setc TARGET_IPHONE_SIMULATOR := TRUE}
115 {$elsec}
116 	{$setc TARGET_OS_MAC := TRUE}
117 	{$setc TARGET_OS_IPHONE := FALSE}
118 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
119 {$endc}
120 	{$setc TARGET_OS_EMBEDDED := FALSE}
121 {$elifc defined __x86_64__ and __x86_64__}
122 	{$setc TARGET_CPU_PPC := FALSE}
123 	{$setc TARGET_CPU_PPC64 := FALSE}
124 	{$setc TARGET_CPU_X86 := FALSE}
125 	{$setc TARGET_CPU_X86_64 := TRUE}
126 	{$setc TARGET_CPU_ARM := FALSE}
127 	{$setc TARGET_CPU_ARM64 := FALSE}
128 {$ifc defined iphonesim}
129  	{$setc TARGET_OS_MAC := FALSE}
130 	{$setc TARGET_OS_IPHONE := TRUE}
131 	{$setc TARGET_IPHONE_SIMULATOR := TRUE}
132 {$elsec}
133 	{$setc TARGET_OS_MAC := TRUE}
134 	{$setc TARGET_OS_IPHONE := FALSE}
135 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
136 {$endc}
137 	{$setc TARGET_OS_EMBEDDED := FALSE}
138 {$elifc defined __arm__ and __arm__}
139 	{$setc TARGET_CPU_PPC := FALSE}
140 	{$setc TARGET_CPU_PPC64 := FALSE}
141 	{$setc TARGET_CPU_X86 := FALSE}
142 	{$setc TARGET_CPU_X86_64 := FALSE}
143 	{$setc TARGET_CPU_ARM := TRUE}
144 	{$setc TARGET_CPU_ARM64 := FALSE}
145 	{$setc TARGET_OS_MAC := FALSE}
146 	{$setc TARGET_OS_IPHONE := TRUE}
147 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
148 	{$setc TARGET_OS_EMBEDDED := TRUE}
149 {$elifc defined __arm64__ and __arm64__}
150 	{$setc TARGET_CPU_PPC := FALSE}
151 	{$setc TARGET_CPU_PPC64 := FALSE}
152 	{$setc TARGET_CPU_X86 := FALSE}
153 	{$setc TARGET_CPU_X86_64 := FALSE}
154 	{$setc TARGET_CPU_ARM := FALSE}
155 	{$setc TARGET_CPU_ARM64 := TRUE}
156 {$ifc defined ios}
157 	{$setc TARGET_OS_MAC := FALSE}
158 	{$setc TARGET_OS_IPHONE := TRUE}
159 	{$setc TARGET_OS_EMBEDDED := TRUE}
160 {$elsec}
161 	{$setc TARGET_OS_MAC := TRUE}
162 	{$setc TARGET_OS_IPHONE := FALSE}
163 	{$setc TARGET_OS_EMBEDDED := FALSE}
164 {$endc}
165 	{$setc TARGET_IPHONE_SIMULATOR := FALSE}
166 {$elsec}
167 	{$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
168 {$endc}
169 
170 {$ifc defined __LP64__ and __LP64__ }
171   {$setc TARGET_CPU_64 := TRUE}
172 {$elsec}
173   {$setc TARGET_CPU_64 := FALSE}
174 {$endc}
175 
176 {$ifc defined FPC_BIG_ENDIAN}
177 	{$setc TARGET_RT_BIG_ENDIAN := TRUE}
178 	{$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
179 {$elifc defined FPC_LITTLE_ENDIAN}
180 	{$setc TARGET_RT_BIG_ENDIAN := FALSE}
181 	{$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
182 {$elsec}
183 	{$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
184 {$endc}
185 {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
186 {$setc CALL_NOT_IN_CARBON := FALSE}
187 {$setc OLDROUTINENAMES := FALSE}
188 {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
189 {$setc OPAQUE_UPP_TYPES := TRUE}
190 {$setc OTCARBONAPPLICATION := TRUE}
191 {$setc OTKERNEL := FALSE}
192 {$setc PM_USE_SESSION_APIS := TRUE}
193 {$setc TARGET_API_MAC_CARBON := TRUE}
194 {$setc TARGET_API_MAC_OS8 := FALSE}
195 {$setc TARGET_API_MAC_OSX := TRUE}
196 {$setc TARGET_CARBON := TRUE}
197 {$setc TARGET_CPU_68K := FALSE}
198 {$setc TARGET_CPU_MIPS := FALSE}
199 {$setc TARGET_CPU_SPARC := FALSE}
200 {$setc TARGET_OS_UNIX := FALSE}
201 {$setc TARGET_OS_WIN32 := FALSE}
202 {$setc TARGET_RT_MAC_68881 := FALSE}
203 {$setc TARGET_RT_MAC_CFM := FALSE}
204 {$setc TARGET_RT_MAC_MACHO := TRUE}
205 {$setc TYPED_FUNCTION_POINTERS := TRUE}
206 {$setc TYPE_BOOL := FALSE}
207 {$setc TYPE_EXTENDED := FALSE}
208 {$setc TYPE_LONGLONG := TRUE}
209 uses MacTypes;
210 {$endc} {not MACOSALLINCLUDE}
211 
212 
213 
214 {$ALIGN MAC68K}
215 
216 {
217     This file provides Endian Flipping routines for dealing with converting data
218     between Big-Endian and Little-Endian machines.  These routines are useful
219     when writing code to compile for both Big and Little Endian machines and
220     which must handle other endian number formats, such as reading or writing
221     to a file or network packet.
222 
223     These routines are named as follows:
224 
225         Endian<U><W>_<S>to<D>
226 
227     where
228         <U> is whether the integer is signed ('S') or unsigned ('U')
229         <W> is integer bit width: 16, 32, or 64
230         <S> is the source endian format: 'B' for big, 'L' for little, or 'N' for native
231         <D> is the destination endian format: 'B' for big, 'L' for little, or 'N' for native
232 
233     For example, to convert a Big Endian 32-bit unsigned integer to the current native format use:
234 
235         long i = EndianU32_BtoN(data);
236 
237     This file is set up so that the function macro to nothing when the target runtime already
238     is the desired format (e.g. on Big Endian machines, EndianU32_BtoN() macros away).
239 
240     If long long's are not supported, you cannot get 64-bit quantities as a single value.
241     The macros are not defined in that case.
242 
243     For gcc, the macros build on top of the inline byte swapping
244     routines from <libkern/OSByteOrder.h>, which may have better performance.
245 
246 
247                                 <<< W A R N I N G >>>
248 
249     It is very important not to put any autoincrements inside the macros.  This
250     will produce erroneous results because each time the address is accessed in the macro,
251     the increment occurs.
252 
253  }
254  // Macros might be better solutions
Endian16_Swapnull255 function Endian16_Swap( arg: UInt16 ): UInt16; inline;
Endian32_Swapnull256 function Endian32_Swap( arg: UInt32 ): UInt32; inline;
Endian64_Swap_Pascalnull257 function Endian64_Swap_Pascal( arg: UInt64 ): UInt64; inline;
EndianS16_Swapnull258 function EndianS16_Swap( arg: SInt16 ): SInt16; inline;
EndianS32_Swapnull259 function EndianS32_Swap( arg: SInt32 ): SInt32; inline;
EndianS64_Swapnull260 function EndianS64_Swap( arg: SInt64 ): SInt64; inline;
261 
262 
Endian64_Swapnull263 function Endian64_Swap( arg: UInt64 ): UInt64; inline;
264 //  Macro away no-op functions
265 
266 {$ifc TARGET_RT_BIG_ENDIAN}
267 
EndianS16_BtoNnull268 function EndianS16_BtoN( arg: SInt16 ): SInt16; inline;
EndianS16_NtoBnull269 function EndianS16_NtoB( arg: SInt16 ): SInt16; inline;
EndianU16_BtoNnull270 function EndianU16_BtoN( arg: UInt16 ): UInt16; inline;
EndianU16_NtoBnull271 function EndianU16_NtoB( arg: UInt16 ): UInt16; inline;
EndianS32_BtoNnull272 function EndianS32_BtoN( arg: SInt32 ): SInt32; inline;
EndianS32_NtoBnull273 function EndianS32_NtoB( arg: SInt32 ): SInt32; inline;
EndianU32_BtoNnull274 function EndianU32_BtoN( arg: UInt32 ): UInt32; inline;
EndianU32_NtoBnull275 function EndianU32_NtoB( arg: UInt32 ): UInt32; inline;
EndianS64_BtoNnull276 function EndianS64_BtoN( arg: SInt64 ): SInt64; inline;
EndianS64_NtoBnull277 function EndianS64_NtoB( arg: SInt64 ): SInt64; inline;
EndianU64_BtoNnull278 function EndianU64_BtoN( arg: UInt64 ): UInt64; inline;
EndianU64_NtoBnull279 function EndianU64_NtoB( arg: UInt64 ): UInt64; inline;
280 
281 {$elsec}
282 
EndianS16_LtoNnull283 function EndianS16_LtoN( arg: SInt16 ): SInt16; inline;
EndianS16_NtoLnull284 function EndianS16_NtoL( arg: SInt16 ): SInt16; inline;
EndianU16_LtoNnull285 function EndianU16_LtoN( arg: UInt16 ): UInt16; inline;
EndianU16_NtoLnull286 function EndianU16_NtoL( arg: UInt16 ): UInt16; inline;
EndianS32_LtoNnull287 function EndianS32_LtoN( arg: SInt32 ): SInt32; inline;
EndianS32_NtoLnull288 function EndianS32_NtoL( arg: SInt32 ): SInt32; inline;
EndianU32_LtoNnull289 function EndianU32_LtoN( arg: UInt32 ): UInt32; inline;
EndianU32_NtoLnull290 function EndianU32_NtoL( arg: UInt32 ): UInt32; inline;
EndianS64_LtoNnull291 function EndianS64_LtoN( arg: SInt64 ): SInt64; inline;
EndianS64_NtoLnull292 function EndianS64_NtoL( arg: SInt64 ): SInt64; inline;
EndianU64_LtoNnull293 function EndianU64_LtoN( arg: UInt64 ): UInt64; inline;
EndianU64_NtoLnull294 function EndianU64_NtoL( arg: UInt64 ): UInt64; inline;
295 
296 {$endc}
297 
298 //  Map native to actual
299 
300 {$ifc TARGET_RT_BIG_ENDIAN}
301 
EndianS16_LtoNnull302 function EndianS16_LtoN( arg: SInt16 ): SInt16; inline;
EndianS16_NtoLnull303 function EndianS16_NtoL( arg: SInt16 ): SInt16; inline;
EndianU16_LtoNnull304 function EndianU16_LtoN( arg: UInt16 ): UInt16; inline;
EndianU16_NtoLnull305 function EndianU16_NtoL( arg: UInt16 ): UInt16; inline;
EndianS32_LtoNnull306 function EndianS32_LtoN( arg: SInt32 ): SInt32; inline;
EndianS32_NtoLnull307 function EndianS32_NtoL( arg: SInt32 ): SInt32; inline;
EndianU32_LtoNnull308 function EndianU32_LtoN( arg: UInt32 ): UInt32; inline;
EndianU32_NtoLnull309 function EndianU32_NtoL( arg: UInt32 ): UInt32; inline;
EndianS64_LtoNnull310 function EndianS64_LtoN( arg: SInt64 ): SInt64; inline;
EndianS64_NtoLnull311 function EndianS64_NtoL( arg: SInt64 ): SInt64; inline;
EndianU64_LtoNnull312 function EndianU64_LtoN( arg: UInt64 ): UInt64; inline;
EndianU64_NtoLnull313 function EndianU64_NtoL( arg: UInt64 ): UInt64; inline;
314 
315 {$elsec}
316 
EndianS16_BtoNnull317 function EndianS16_BtoN( arg: SInt16 ): SInt16; inline;
EndianS16_NtoBnull318 function EndianS16_NtoB( arg: SInt16 ): SInt16; inline;
EndianU16_BtoNnull319 function EndianU16_BtoN( arg: UInt16 ): UInt16; inline;
EndianU16_NtoBnull320 function EndianU16_NtoB( arg: UInt16 ): UInt16; inline;
EndianS32_BtoNnull321 function EndianS32_BtoN( arg: SInt32 ): SInt32; inline;
EndianS32_NtoBnull322 function EndianS32_NtoB( arg: SInt32 ): SInt32; inline;
EndianU32_BtoNnull323 function EndianU32_BtoN( arg: UInt32 ): UInt32; inline;
EndianU32_NtoBnull324 function EndianU32_NtoB( arg: UInt32 ): UInt32; inline;
EndianS64_BtoNnull325 function EndianS64_BtoN( arg: SInt64 ): SInt64; inline;
EndianS64_NtoBnull326 function EndianS64_NtoB( arg: SInt64 ): SInt64; inline;
EndianU64_BtoNnull327 function EndianU64_BtoN( arg: UInt64 ): UInt64; inline;
EndianU64_NtoBnull328 function EndianU64_NtoB( arg: UInt64 ): UInt64; inline;
329 
330 {$endc}
331 
332 //     Implement *LtoB and *BtoL
333 
EndianS16_LtoBnull334 function EndianS16_LtoB( arg: SInt16 ): SInt16; inline;
EndianS16_BtoLnull335 function EndianS16_BtoL( arg: SInt16 ): SInt16; inline;
EndianU16_LtoBnull336 function EndianU16_LtoB( arg: UInt16 ): UInt16; inline;
EndianU16_BtoLnull337 function EndianU16_BtoL( arg: UInt16 ): UInt16; inline;
EndianS32_LtoBnull338 function EndianS32_LtoB( arg: SInt32 ): SInt32; inline;
EndianS32_BtoLnull339 function EndianS32_BtoL( arg: SInt32 ): SInt32; inline;
EndianU32_LtoBnull340 function EndianU32_LtoB( arg: UInt32 ): UInt32; inline;
EndianU32_BtoLnull341 function EndianU32_BtoL( arg: UInt32 ): UInt32; inline;
EndianS64_LtoBnull342 function EndianS64_LtoB( arg: SInt64 ): SInt64; inline;
EndianS64_BtoLnull343 function EndianS64_BtoL( arg: SInt64 ): SInt64; inline;
EndianU64_LtoBnull344 function EndianU64_LtoB( arg: UInt64 ): UInt64; inline;
EndianU64_BtoLnull345 function EndianU64_BtoL( arg: UInt64 ): UInt64; inline;
346 
347 {
348    These types are used for structures that contain data that is
349    always in BigEndian format.  This extra typing prevents little
350    endian code from directly changing the data, thus saving much
351    time in the debugger.
352 }
353 
354 {$ifc TARGET_RT_LITTLE_ENDIAN}
355 
356 type
357 	BigEndianUInt32 = record
358 		bigEndianValue: UInt32;
359 	end;
360 type
361 	BigEndianLong = record
362 		bigEndianValue: SIGNEDLONG;
363 	end;
364 type
365 	BigEndianUnsignedLong = record
366 		bigEndianValue: UNSIGNEDLONG;
367 	end;
368 type
369 	BigEndianShort = record
370 		bigEndianValue: SInt16;
371 	end;
372 type
373 	BigEndianUnsignedShort = record
374 		bigEndianValue: UInt16;
375 	end;
376 type
377 	BigEndianFixed = record
378 		bigEndianValue: Fixed;
379 	end;
380 type
381 	BigEndianUnsignedFixed = record
382 		bigEndianValue: UnsignedFixed;
383 	end;
384 type
385 	BigEndianOSType = record
386 		bigEndianValue: OSType;
387 	end;
388 
389 {$elsec}
390 
391 type
392 	BigEndianUInt32 = UInt32;
393 	BigEndianLong = SIGNEDLONG;
394 	BigEndianUnsignedLong = UNSIGNEDLONG;
395 	BigEndianShort = SInt16;
396 	BigEndianUnsignedShort = UInt16;
397 	BigEndianFixed = Fixed;
398 	BigEndianUnsignedFixed = UnsignedFixed;
399 	BigEndianOSType = OSType;
400 {$endc}  {TARGET_RT_LITTLE_ENDIAN}
401 
402 type
403 	BigEndianUInt32Ptr = ^BigEndianUInt32;
404 	BigEndianLongPtr = ^BigEndianLong;
405 	BigEndianUnsignedLongPtr = ^BigEndianUnsignedLong;
406 	BigEndianShortPtr = ^BigEndianShort;
407 	BigEndianUnsignedShortPtr = ^BigEndianUnsignedShort;
408 	BigEndianFixedPtr = ^BigEndianFixed;
409 	BigEndianUnsignedFixedPtr = ^BigEndianUnsignedFixed;
410 	BigEndianOSTypePtr = ^BigEndianOSType;
411 
412 {$ifc TARGET_API_MAC_OSX}
413 {
414         CoreEndian flipping API.
415 
416         This API is used to generically massage data buffers, in
417         place, from one endian architecture to another.  In effect,
418         the API supports registering a set of callbacks that can
419         effect this translation.
420 
421         The data types have specific meanings within their domain,
422         although some data types can be registered with the same
423         callback in several domains.  There is no wildcard domain.
424 
425         A set of pre-defined flippers are implemented by the Carbon
426         frameworks for most common resource manager and AppleEvent data
427         types.
428   }
429 const
430 	kCoreEndianResourceManagerDomain = FourCharCode('rsrc');
431 	kCoreEndianAppleEventManagerDomain = FourCharCode('aevt');
432 
433 
434 {
435  *  CoreEndianFlipProc
436  *
437  *  Discussion:
438  *    Callback use to flip endian-ness of typed data
439  *
440  *  Parameters:
441  *
442  *    dataDomain:
443  *      Domain of the data type
444  *
445  *    dataType:
446  *      Type of data being flipped
447  *
448  *    id:
449  *      resource id (if being flipped on behalf of the resource
450  *      manager, otherwise will be zero)
451  *
452  *    dataPtr:
453  *      Pointer to the data
454  *
455  *    dataSize:
456  *      Length of the data
457  *
458  *    currentlyNative:
459  *      Boolean indicating which direction to flip: false means flip
460  *      from disk big endian to native (from disk), true means flip
461  *      from native to disk big endian (to disk)
462  *
463  *    refcon:
464  *      An optional user reference supplied when the flipper is
465  *      installed
466  *
467  *  Result:
468  *    Error code indicating whether the data was flipped.  noErr would
469  *    indicate that the data was flipped as appropriate; any other
470  *    error will be propagated back to the caller.
471  }
472 type
dataDomainnull473 	CoreEndianFlipProc = function( dataDomain: OSType; dataType: OSType; id: SInt16; dataPtr: UnivPtr; dataSize: ByteCount; currentlyNative: Boolean; refcon: UnivPtr ): OSStatus;
474 {
475  * Install a flipper for this application
476  }
477 {
478  *  CoreEndianInstallFlipper()
479  *
480  *  Summary:
481  *    Installs a flipper proc for the given data type.  If the flipper
482  *    is already registered, this flipper will take replace it.
483  *
484  *  Mac OS X threading:
485  *    Thread safe since version 10.3
486  *
487  *  Parameters:
488  *
489  *    dataDomain:
490  *      Domain of the data type
491  *
492  *    dataType:
493  *      Type of data for which this flipper should be installed
494  *
495  *    proc:
496  *      Flipper callback to be called for data of this type
497  *
498  *    refcon:
499  *      Optional user reference for the flipper
500  *
501  *  Result:
502  *    Error code indicating whether or not the flipper could be
503  *    installed
504  *
505  *  Availability:
506  *    Mac OS X:         in version 10.3 and later in CoreServices.framework
507  *    CarbonLib:        not available
508  *    Non-Carbon CFM:   not available
509  }
CoreEndianInstallFlippernull510 function CoreEndianInstallFlipper( dataDomain: OSType; dataType: OSType; proc: CoreEndianFlipProc; refcon: UnivPtr { can be NULL } ): OSStatus; external name '_CoreEndianInstallFlipper';
511 (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3, __MAC_10_8, __IPHONE_NA, __IPHONE_NA) *)
512 
513 
514 {
515  *  CoreEndianGetFlipper()
516  *
517  *  Summary:
518  *    Gets an existing data flipper proc for the given data type
519  *
520  *  Mac OS X threading:
521  *    Thread safe since version 10.3
522  *
523  *  Parameters:
524  *
525  *    dataDomain:
526  *      Domain of the data type
527  *
528  *    dataType:
529  *      Type of the data for which this flipper should be installed
530  *
531  *    proc:
532  *      Pointer to a flipper callback
533  *
534  *    refcon:
535  *      Pointer to the callback refcon
536  *
537  *  Result:
538  *    noErr if the given flipper could be found; otherwise
539  *    handlerNotFoundErr will be returned.
540  *
541  *  Availability:
542  *    Mac OS X:         in version 10.3 and later in CoreServices.framework
543  *    CarbonLib:        not available
544  *    Non-Carbon CFM:   not available
545  }
CoreEndianGetFlippernull546 function CoreEndianGetFlipper( dataDomain: OSType; dataType: OSType; var proc: CoreEndianFlipProc; refcon: UnivPtrPtr ): OSStatus; external name '_CoreEndianGetFlipper';
547 (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3, __MAC_10_8, __IPHONE_NA, __IPHONE_NA) *)
548 
549 
550 {
551  *  CoreEndianFlipData()
552  *
553  *  Summary:
554  *    Calls the flipper for the given data type with the associated data
555  *
556  *  Mac OS X threading:
557  *    Thread safe since version 10.3
558  *
559  *  Parameters:
560  *
561  *    dataDomain:
562  *      Domain of the data type
563  *
564  *    dataType:
565  *      type of the data
566  *
567  *    id:
568  *      resource id (if not a resource, pass zero)
569  *
570  *    data:
571  *      a pointer to the data to be flipped (in place)
572  *
573  *    dataLen:
574  *      length of the data to flip
575  *
576  *    currentlyNative:
577  *      a boolean indicating the direction to flip (whether the data is
578  *      currently native endian or big-endian)
579  *
580  *  Result:
581  *    Error code indicating whether the data was flipped.  If
582  *    handlerNotFound is returned, then no flipping took place (which
583  *    is not necessarily an error condtion)
584  *
585  *  Availability:
586  *    Mac OS X:         in version 10.3 and later in CoreServices.framework
587  *    CarbonLib:        not available
588  *    Non-Carbon CFM:   not available
589  }
CoreEndianFlipDatanull590 function CoreEndianFlipData( dataDomain: OSType; dataType: OSType; id: SInt16; data: UnivPtr; dataLen: ByteCount; currentlyNative: Boolean ): OSStatus; external name '_CoreEndianFlipData';
591 (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3, __MAC_10_8, __IPHONE_NA, __IPHONE_NA) *)
592 
593 {$endc} {TARGET_API_MAC_OSX}
594 
595 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
596 implementation
597 
598 {$R-}
599 
Endian16_Swapnull600 function Endian16_Swap( arg: UInt16 ): UInt16; inline;
601 begin
602 	Endian16_Swap := (( arg shl 8) and $0FF00) or (( arg shr 8) and $00FF);
603 end;
604 
Endian32_Swapnull605 function Endian32_Swap( arg: UInt32 ): UInt32; inline;
606 begin
607     Endian32_Swap := ((arg and $FF) shl 24) or ((arg and $0FF00) shl 8) or ((arg shr 8) and $0FF00) or ((arg shr 24) and $FF);
608 end;
609 
Endian64_Swap_Pascalnull610 function Endian64_Swap_Pascal( arg: UInt64 ): UInt64; inline;
611 begin
612 	Endian64_Swap_Pascal := (Endian32_Swap( arg and $FFFFFFFF ) shl 32) or Endian32_Swap( (arg shr 32) and $FFFFFFFF );
613 end;
614 
Endian64_Swapnull615 function Endian64_Swap( arg: UInt64 ): UInt64; inline;
616 begin
617 	Endian64_Swap := Endian64_Swap_Pascal(arg);
618 end;
619 
EndianS16_Swapnull620 function EndianS16_Swap( arg: SInt16 ): SInt16; inline;
621 begin
622 	EndianS16_Swap := (( arg shl 8) and $0FF00) or (( arg shr 8) and $00FF);
623 end;
624 
EndianS32_Swapnull625 function EndianS32_Swap( arg: SInt32 ): SInt32; inline;
626 begin
627     EndianS32_Swap := ((arg and $FF) shl 24) or ((arg and $0FF00) shl 8) or ((arg shr 8) and $0FF00) or ((arg shr 24) and $FF);
628 end;
629 
EndianS64_Swapnull630 function EndianS64_Swap( arg: SInt64 ): SInt64; inline;
631 begin
632 	EndianS64_Swap := (SInt64( Endian32_Swap( arg and $FFFFFFFF ) ) shl 32) or Endian32_Swap( (arg shr 32) and $FFFFFFFF );
633 end;
634 
635 {$ifc TARGET_RT_BIG_ENDIAN}
EndianS16_BtoNnull636 function EndianS16_BtoN( arg: SInt16 ): SInt16; inline;
637 begin
638   EndianS16_BtoN := arg;
639 end;
640 
EndianS16_NtoBnull641 function EndianS16_NtoB( arg: SInt16 ): SInt16; inline;
642 begin
643   EndianS16_NtoB := arg;
644 end;
645 
EndianU16_BtoNnull646 function EndianU16_BtoN( arg: UInt16 ): UInt16; inline;
647 begin
648   EndianU16_BtoN := arg;
649 end;
650 
EndianU16_NtoBnull651 function EndianU16_NtoB( arg: UInt16 ): UInt16; inline;
652 begin
653   EndianU16_NtoB := arg;
654 end;
655 
EndianS32_BtoNnull656 function EndianS32_BtoN( arg: SInt32 ): SInt32; inline;
657 begin
658   EndianS32_BtoN := arg;
659 end;
660 
EndianS32_NtoBnull661 function EndianS32_NtoB( arg: SInt32 ): SInt32; inline;
662 begin
663   EndianS32_NtoB := arg;
664 end;
665 
EndianU32_BtoNnull666 function EndianU32_BtoN( arg: UInt32 ): UInt32; inline;
667 begin
668   EndianU32_BtoN := arg;
669 end;
670 
EndianU32_NtoBnull671 function EndianU32_NtoB( arg: UInt32 ): UInt32; inline;
672 begin
673   EndianU32_NtoB := arg;
674 end;
675 
EndianS64_BtoNnull676 function EndianS64_BtoN( arg: SInt64 ): SInt64; inline;
677 begin
678   EndianS64_BtoN := arg;
679 end;
680 
EndianS64_NtoBnull681 function EndianS64_NtoB( arg: SInt64 ): SInt64; inline;
682 begin
683   EndianS64_NtoB := arg;
684 end;
685 
EndianU64_BtoNnull686 function EndianU64_BtoN( arg: UInt64 ): UInt64; inline;
687 begin
688   EndianU64_BtoN := arg;
689 end;
690 
EndianU64_NtoBnull691 function EndianU64_NtoB( arg: UInt64 ): UInt64; inline;
692 begin
693   EndianU64_NtoB := arg;
694 end;
695 
EndianS16_LtoNnull696 function EndianS16_LtoN( arg: SInt16 ): SInt16; inline;
697 begin
698   EndianS16_LtoN := EndianS16_Swap(arg);
699 end;
700 
EndianS16_NtoLnull701 function EndianS16_NtoL( arg: SInt16 ): SInt16; inline;
702 begin
703   EndianS16_NtoL := EndianS16_Swap(arg);
704 end;
705 
EndianU16_LtoNnull706 function EndianU16_LtoN( arg: UInt16 ): UInt16; inline;
707 begin
708   EndianU16_LtoN := Endian16_Swap(arg);
709 end;
710 
EndianU16_NtoLnull711 function EndianU16_NtoL( arg: UInt16 ): UInt16; inline;
712 begin
713   EndianU16_NtoL := Endian16_Swap(arg);
714 end;
715 
EndianS32_LtoNnull716 function EndianS32_LtoN( arg: SInt32 ): SInt32; inline;
717 begin
718   EndianS32_LtoN := EndianS32_Swap(arg);
719 end;
720 
EndianS32_NtoLnull721 function EndianS32_NtoL( arg: SInt32 ): SInt32; inline;
722 begin
723   EndianS32_NtoL := EndianS32_Swap(arg);
724 end;
725 
EndianU32_LtoNnull726 function EndianU32_LtoN( arg: UInt32 ): UInt32; inline;
727 begin
728   EndianU32_LtoN := Endian32_Swap(arg);
729 end;
730 
EndianU32_NtoLnull731 function EndianU32_NtoL( arg: UInt32 ): UInt32; inline;
732 begin
733   EndianU32_NtoL := Endian32_Swap(arg);
734 end;
735 
736 
EndianS64_LtoNnull737 function EndianS64_LtoN( arg: SInt64 ): SInt64; inline;
738 begin
739   EndianS64_LtoN := EndianS64_Swap(arg);
740 end;
741 
EndianS64_NtoLnull742 function EndianS64_NtoL( arg: SInt64 ): SInt64; inline;
743 begin
744   EndianS64_NtoL := EndianS64_Swap(arg);
745 end;
746 
EndianU64_LtoNnull747 function EndianU64_LtoN( arg: UInt64 ): UInt64; inline;
748 begin
749   EndianU64_LtoN := Endian64_Swap(arg);
750 end;
751 
EndianU64_NtoLnull752 function EndianU64_NtoL( arg: UInt64 ): UInt64; inline;
753 begin
754   EndianU64_NtoL := Endian64_Swap(arg);
755 end;
756 
757 {$elsec}
EndianS16_BtoNnull758 function EndianS16_BtoN( arg: SInt16 ): SInt16; inline;
759 begin
760   EndianS16_BtoN := EndianS16_Swap(arg);
761 end;
762 
EndianS16_NtoBnull763 function EndianS16_NtoB( arg: SInt16 ): SInt16; inline;
764 begin
765   EndianS16_NtoB := EndianS16_Swap(arg);
766 end;
767 
EndianU16_BtoNnull768 function EndianU16_BtoN( arg: UInt16 ): UInt16; inline;
769 begin
770   EndianU16_BtoN := Endian16_Swap(arg);
771 end;
772 
EndianU16_NtoBnull773 function EndianU16_NtoB( arg: UInt16 ): UInt16; inline;
774 begin
775   EndianU16_NtoB := Endian16_Swap(arg);
776 end;
777 
EndianS32_BtoNnull778 function EndianS32_BtoN( arg: SInt32 ): SInt32; inline;
779 begin
780   EndianS32_BtoN := EndianS32_Swap(arg);
781 end;
782 
EndianS32_NtoBnull783 function EndianS32_NtoB( arg: SInt32 ): SInt32; inline;
784 begin
785   EndianS32_NtoB := EndianS32_Swap(arg);
786 end;
787 
EndianU32_BtoNnull788 function EndianU32_BtoN( arg: UInt32 ): UInt32; inline;
789 begin
790   EndianU32_BtoN := Endian32_Swap(arg);
791 end;
792 
EndianU32_NtoBnull793 function EndianU32_NtoB( arg: UInt32 ): UInt32; inline;
794 begin
795   EndianU32_NtoB := Endian32_Swap(arg);
796 end;
797 
798 
EndianS64_BtoNnull799 function EndianS64_BtoN( arg: SInt64 ): SInt64; inline;
800 begin
801   EndianS64_BtoN := EndianS64_Swap(arg);
802 end;
803 
EndianS64_NtoBnull804 function EndianS64_NtoB( arg: SInt64 ): SInt64; inline;
805 begin
806   EndianS64_NtoB := EndianS64_Swap(arg);
807 end;
808 
EndianU64_BtoNnull809 function EndianU64_BtoN( arg: UInt64 ): UInt64; inline;
810 begin
811   EndianU64_BtoN := Endian64_Swap(arg);
812 end;
813 
EndianU64_NtoBnull814 function EndianU64_NtoB( arg: UInt64 ): UInt64; inline;
815 begin
816   EndianU64_NtoB := Endian64_Swap(arg);
817 end;
818 
EndianS16_LtoNnull819 function EndianS16_LtoN( arg: SInt16 ): SInt16; inline;
820 begin
821   EndianS16_LtoN := arg;
822 end;
823 
EndianS16_NtoLnull824 function EndianS16_NtoL( arg: SInt16 ): SInt16; inline;
825 begin
826   EndianS16_NtoL := arg;
827 end;
828 
EndianU16_LtoNnull829 function EndianU16_LtoN( arg: UInt16 ): UInt16; inline;
830 begin
831   EndianU16_LtoN := arg;
832 end;
833 
EndianU16_NtoLnull834 function EndianU16_NtoL( arg: UInt16 ): UInt16; inline;
835 begin
836   EndianU16_NtoL := arg;
837 end;
838 
EndianS32_LtoNnull839 function EndianS32_LtoN( arg: SInt32 ): SInt32; inline;
840 begin
841   EndianS32_LtoN := arg;
842 end;
843 
EndianS32_NtoLnull844 function EndianS32_NtoL( arg: SInt32 ): SInt32; inline;
845 begin
846   EndianS32_NtoL := arg;
847 end;
848 
EndianU32_LtoNnull849 function EndianU32_LtoN( arg: UInt32 ): UInt32; inline;
850 begin
851   EndianU32_LtoN := arg;
852 end;
853 
EndianU32_NtoLnull854 function EndianU32_NtoL( arg: UInt32 ): UInt32; inline;
855 begin
856   EndianU32_NtoL := arg;
857 end;
858 
EndianS64_LtoNnull859 function EndianS64_LtoN( arg: SInt64 ): SInt64; inline;
860 begin
861   EndianS64_LtoN := arg;
862 end;
863 
EndianS64_NtoLnull864 function EndianS64_NtoL( arg: SInt64 ): SInt64; inline;
865 begin
866   EndianS64_NtoL := arg;
867 end;
868 
EndianU64_LtoNnull869 function EndianU64_LtoN( arg: UInt64 ): UInt64; inline;
870 begin
871   EndianU64_LtoN := arg;
872 end;
873 
EndianU64_NtoLnull874 function EndianU64_NtoL( arg: UInt64 ): UInt64; inline;
875 begin
876   EndianU64_NtoL := arg;
877 end;
878 
879 {$endc}
880 
EndianS16_LtoBnull881 function EndianS16_LtoB( arg: SInt16 ): SInt16; inline;
882 begin
883   EndianS16_LtoB:=EndianS16_Swap(arg);
884 end;
885 
EndianS16_BtoLnull886 function EndianS16_BtoL( arg: SInt16 ): SInt16; inline;
887 begin
888   EndianS16_BtoL:=EndianS16_Swap(arg);
889 end;
890 
EndianU16_LtoBnull891 function EndianU16_LtoB( arg: UInt16 ): UInt16; inline;
892 begin
893   EndianU16_LtoB:=Endian16_Swap(arg);
894 end;
895 
EndianU16_BtoLnull896 function EndianU16_BtoL( arg: UInt16 ): UInt16; inline;
897 begin
898   EndianU16_BtoL:=Endian16_Swap(arg);
899 end;
900 
EndianS32_LtoBnull901 function EndianS32_LtoB( arg: SInt32 ): SInt32; inline;
902 begin
903   EndianS32_LtoB:=EndianS32_Swap(arg);
904 end;
905 
EndianS32_BtoLnull906 function EndianS32_BtoL( arg: SInt32 ): SInt32; inline;
907 begin
908   EndianS32_BtoL:=EndianS32_Swap(arg);
909 end;
910 
EndianU32_LtoBnull911 function EndianU32_LtoB( arg: UInt32 ): UInt32; inline;
912 begin
913   EndianU32_LtoB:=Endian32_Swap(arg);
914 end;
915 
EndianU32_BtoLnull916 function EndianU32_BtoL( arg: UInt32 ): UInt32; inline;
917 begin
918   EndianU32_BtoL:=Endian32_Swap(arg);
919 end;
920 
EndianS64_LtoBnull921 function EndianS64_LtoB( arg: SInt64 ): SInt64; inline;
922 begin
923   EndianS64_LtoB:=EndianS64_Swap(arg);
924 end;
925 
EndianS64_BtoLnull926 function EndianS64_BtoL( arg: SInt64 ): SInt64; inline;
927 begin
928   EndianS64_BtoL:=EndianS64_Swap(arg);
929 end;
930 
EndianU64_LtoBnull931 function EndianU64_LtoB( arg: UInt64 ): UInt64; inline;
932 begin
933   EndianU64_LtoB:=Endian64_Swap_Pascal(arg);
934 end;
935 
EndianU64_BtoLnull936 function EndianU64_BtoL( arg: UInt64 ): UInt64; inline;
937 begin
938   EndianU64_BtoL:=Endian64_Swap_Pascal(arg);
939 end;
940 
941 
942 
943 end.
944 
945 {$endc} {not MACOSALLINCLUDE}
946