4 * Copyright (C) 1993-1999 by Jochen Wiedmann and Marcin Orlowski
5 * Copyright (C) 2002-2015 FlexCat Open Source Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 unsigned short (*SwapWord
)(unsigned short r
) = NULL
;
28 uint32 (*SwapLong
)(uint32 r
) = NULL
;
30 unsigned short SwapWord21(unsigned short r
)
32 return (unsigned short)(((r
& 0xff00) >> 8) | ((r
& 0x00ff) << 8));
35 unsigned short SwapWord12(unsigned short r
)
40 uint32
SwapLong4321(uint32 r
)
42 return (((r
& 0xff000000) >> 24) | ((r
& 0x00ff0000) >> 8) | ((r
& 0x0000ff00) << 8) | ((r
& 0x000000ff) << 24));
44 uint32
SwapLong1234(uint32 r
)
56 strncpy((char *)&w
, "\1\2", 2);
57 strncpy((char *)&d
, "\1\2\3\4", 4);
60 SwapWord
= SwapWord21
;
62 SwapWord
= SwapWord12
;
67 SwapLong
= SwapLong4321
;
68 else if(d
== 0x01020304)
69 SwapLong
= SwapLong1234
;