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)
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.
23 // swaps a 16-bit value
24 static inline u16
swap16(u16 v
)
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"); \
43 #define READ32LE(base) \
44 ({ unsigned long lwbrxResult; \
45 __asm__ ("lwbrx %0, 0, %1" : "=r" (lwbrxResult) : "r" (base) : "memory"); \
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")
59 #define WRITE16LE(x,v) \
60 *((u16 *)x) = swap16((v))
61 #define WRITE32LE(x,v) \
62 *((u32 *)x) = swap32((v))
69 #define WRITE16LE(x,v) \
71 #define WRITE32LE(x,v) \