common_types.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * Copyright (C) 2005-2012 Gekko Emulator
  3. *
  4. * @file common_types.h
  5. * @author ShizZy <shizzy247@gmail.com>
  6. * @date 2012-02-11
  7. * @brief Common types used throughout the project
  8. *
  9. * @section LICENSE
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details at
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. * Official project repository can be found at:
  22. * http://code.google.com/p/gekko-gc-emu/
  23. */
  24. #pragma once
  25. #include <math.h>
  26. #include <xmmintrin.h> // data_types__m128.cpp
  27. #ifdef _WIN32
  28. #include <tchar.h>
  29. typedef unsigned __int8 u8; ///< 8-bit unsigned byte
  30. typedef unsigned __int16 u16; ///< 16-bit unsigned short
  31. typedef unsigned __int32 u32; ///< 32-bit unsigned word
  32. typedef unsigned __int64 u64; ///< 64-bit unsigned int
  33. typedef signed __int8 s8; ///< 8-bit signed byte
  34. typedef signed __int16 s16; ///< 16-bit signed short
  35. typedef signed __int32 s32; ///< 32-bit signed word
  36. typedef signed __int64 s64; ///< 64-bit signed int
  37. #else
  38. typedef unsigned char u8; ///< 8-bit unsigned byte
  39. typedef unsigned short u16; ///< 16-bit unsigned short
  40. typedef unsigned int u32; ///< 32-bit unsigned word
  41. typedef unsigned long long u64; ///< 64-bit unsigned int
  42. typedef signed char s8; ///< 8-bit signed byte
  43. typedef signed short s16; ///< 16-bit signed short
  44. typedef signed int s32; ///< 32-bit signed word
  45. typedef signed long long s64; ///< 64-bit signed int
  46. // For using windows lock code
  47. #define TCHAR char
  48. #define LONG int
  49. #endif // _WIN32
  50. typedef float f32; ///< 32-bit floating point
  51. typedef double f64; ///< 64-bit floating point
  52. #include "common/common.h"
  53. /// Union for fast 16-bit type casting
  54. union t16 {
  55. u8 _u8[2]; ///< 8-bit unsigned char(s)
  56. u16 _u16; ///< 16-bit unsigned shorts(s)
  57. };
  58. /// Union for fast 32-bit type casting
  59. union t32 {
  60. f32 _f32; ///< 32-bit floating point(s)
  61. u32 _u32; ///< 32-bit unsigned int(s)
  62. s32 _s32; ///< 32-bit signed int(s)
  63. u16 _u16[2]; ///< 16-bit unsigned shorts(s)
  64. u8 _u8[4]; ///< 8-bit unsigned char(s)
  65. };
  66. /// Union for fast 64-bit type casting
  67. union t64 {
  68. f64 _f64; ///< 64-bit floating point
  69. u64 _u64; ///< 64-bit unsigned long
  70. f32 _f32[2]; ///< 32-bit floating point(s)
  71. u32 _u32[2]; ///< 32-bit unsigned int(s)
  72. s32 _s32[2]; ///< 32-bit signed int(s)
  73. u16 _u16[4]; ///< 16-bit unsigned shorts(s)
  74. u8 _u8[8]; ///< 8-bit unsigned char(s)
  75. };
  76. /// Union for fast 128-bit type casting
  77. union t128 {
  78. struct
  79. {
  80. t64 ps0; ///< 64-bit paired single 0
  81. t64 ps1; ///< 64-bit paired single 1
  82. };
  83. __m128 a; ///< 128-bit floating point (__m128 maps to the XMM[0-7] registers)
  84. };
  85. namespace common {
  86. /// Rectangle data structure
  87. class Rect {
  88. public:
  89. Rect(int x0=0, int y0=0, int x1=0, int y1=0) {
  90. x0_ = x0;
  91. y0_ = y0;
  92. x1_ = x1;
  93. y1_ = y1;
  94. }
  95. ~Rect() { }
  96. int x0_; ///< Rect top left X-coordinate
  97. int y0_; ///< Rect top left Y-coordinate
  98. int x1_; ///< Rect bottom left X-coordinate
  99. int y1_; ///< Rect bottom right Y-coordinate
  100. inline u32 width() const { return abs(x1_ - x0_); }
  101. inline u32 height() const { return abs(y1_ - y0_); }
  102. inline bool operator == (const Rect& val) const {
  103. return (x0_ == val.x0_ && y0_ == val.y0_ && x1_ == val.x1_ && y1_ == val.y1_);
  104. }
  105. };
  106. }