remove more unportable ASM, obsoleting C_CORE define
[rofl0r-VisualBoyAdvance.git] / src / Port.h
blob3716bf9c66e6cf53aeb8beeb94df7d915e0f4add
1 // -*- C++ -*-
2 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
3 // Copyright (C) 1999-2003 Forgotten
4 // Copyright (C) 2004 Forgotten and the VBA development team
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or(at your option)
9 // any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef VBA_PORT_H
21 #define VBA_PORT_H
23 // swaps a 16-bit value
24 static inline u16 swap16(u16 v)
26 return (v<<8)|(v>>8);
29 // swaps a 32-bit value
30 static inline u32 swap32(u32 v)
32 return (v<<24)|((v<<8)&0xff0000)|((v>>8)&0xff00)|(v>>24);
35 #ifdef WORDS_BIGENDIAN
36 #if defined(__GNUC__) && defined(__ppc__)
38 #define READ16LE(base) \
39 ({ unsigned short lhbrxResult; \
40 __asm__ ("lhbrx %0, 0, %1" : "=r" (lhbrxResult) : "r" (base) : "memory"); \
41 lhbrxResult; })
43 #define READ32LE(base) \
44 ({ unsigned long lwbrxResult; \
45 __asm__ ("lwbrx %0, 0, %1" : "=r" (lwbrxResult) : "r" (base) : "memory"); \
46 lwbrxResult; })
48 #define WRITE16LE(base, value) \
49 __asm__ ("sthbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
51 #define WRITE32LE(base, value) \
52 __asm__ ("stwbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
54 #else
55 #define READ16LE(x) \
56 swap16(*((u16 *)(x)))
57 #define READ32LE(x) \
58 swap32(*((u32 *)(x)))
59 #define WRITE16LE(x,v) \
60 *((u16 *)x) = swap16((v))
61 #define WRITE32LE(x,v) \
62 *((u32 *)x) = swap32((v))
63 #endif
64 #else
65 #define READ16LE(x) \
66 *((u16 *)x)
67 #define READ32LE(x) \
68 *((u32 *)x)
69 #define WRITE16LE(x,v) \
70 *((u16 *)x) = (v)
71 #define WRITE32LE(x,v) \
72 *((u32 *)x) = (v)
73 #endif
75 #endif