home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / Port.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  2.1 KB  |  76 lines

  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
  5.  
  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.
  10. //
  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.
  15. //
  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.
  19.  
  20. #ifndef VBA_PORT_H
  21. #define VBA_PORT_H
  22.  
  23. // swaps a 16-bit value
  24. static inline u16 swap16(u16 v)
  25. {
  26.   return (v<<8)|(v>>8);
  27. }
  28.  
  29. // swaps a 32-bit value
  30. static inline u32 swap32(u32 v)
  31. {
  32.   return (v<<24)|((v<<8)&0xff0000)|((v>>8)&0xff00)|(v>>24);
  33. }
  34.  
  35. #ifdef WORDS_BIGENDIAN
  36. #if defined(__GNUC__) && defined(__ppc__)
  37.  
  38. #define READ16LE(base) \
  39.   ({ unsigned short lhbrxResult;       \
  40.      __asm__ ("lhbrx %0, 0, %1" : "=r" (lhbrxResult) : "r" (base) : "memory"); \
  41.       lhbrxResult; })
  42.  
  43. #define READ32LE(base) \
  44.   ({ unsigned long lwbrxResult; \
  45.      __asm__ ("lwbrx %0, 0, %1" : "=r" (lwbrxResult) : "r" (base) : "memory"); \
  46.       lwbrxResult; })
  47.  
  48. #define WRITE16LE(base, value) \
  49.   __asm__ ("sthbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
  50.   
  51. #define WRITE32LE(base, value) \
  52.   __asm__ ("stwbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")
  53.   
  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
  74.  
  75. #endif
  76.