grub2: bring back build of aros-side grub2 tools
[AROS.git] / tools / flexcat / src / swapfuncs.c
blobee57733fb954b84e8b7560ed55c3472ca8314615
1 /*
2 * $Id$
4 * Copyright (C) 1993-1999 by Jochen Wiedmann and Marcin Orlowski
5 * Copyright (C) 2002-2010 by the 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.
23 #include "flexcat.h"
25 /// Swappers...
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)
37 return 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)
46 return r;
48 ///
49 /// SwapChoose
51 int SwapChoose(void)
53 unsigned short w;
54 uint32 d;
56 strncpy((char *)&w, "\1\2", 2);
57 strncpy((char *)&d, "\1\2\3\4", 4);
59 if(w == 0x0201)
60 SwapWord = SwapWord21;
61 else if(w == 0x0102)
62 SwapWord = SwapWord12;
63 else
64 return 0;
66 if(d == 0x04030201)
67 SwapLong = SwapLong4321;
68 else if(d == 0x01020304)
69 SwapLong = SwapLong1234;
70 else
71 return 0;
73 return 1;
75 ///