common_types.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <cmath>
  26. #include <cstdint>
  27. #include <cstdlib>
  28. #ifdef _MSC_VER
  29. #ifndef __func__
  30. #define __func__ __FUNCTION__
  31. #endif
  32. #endif
  33. typedef std::uint8_t u8; ///< 8-bit unsigned byte
  34. typedef std::uint16_t u16; ///< 16-bit unsigned short
  35. typedef std::uint32_t u32; ///< 32-bit unsigned word
  36. typedef std::uint64_t u64; ///< 64-bit unsigned int
  37. typedef std::int8_t s8; ///< 8-bit signed byte
  38. typedef std::int16_t s16; ///< 16-bit signed short
  39. typedef std::int32_t s32; ///< 32-bit signed word
  40. typedef std::int64_t s64; ///< 64-bit signed int
  41. typedef float f32; ///< 32-bit floating point
  42. typedef double f64; ///< 64-bit floating point
  43. // TODO: It would be nice to eventually replace these with strong types that prevent accidental
  44. // conversion between each other.
  45. typedef u32 VAddr; ///< Represents a pointer in the userspace virtual address space.
  46. typedef u32 PAddr; ///< Represents a pointer in the ARM11 physical address space.
  47. /// Union for fast 16-bit type casting
  48. union t16 {
  49. u8 _u8[2]; ///< 8-bit unsigned char(s)
  50. u16 _u16; ///< 16-bit unsigned shorts(s)
  51. };
  52. /// Union for fast 32-bit type casting
  53. union t32 {
  54. f32 _f32; ///< 32-bit floating point(s)
  55. u32 _u32; ///< 32-bit unsigned int(s)
  56. s32 _s32; ///< 32-bit signed int(s)
  57. u16 _u16[2]; ///< 16-bit unsigned shorts(s)
  58. u8 _u8[4]; ///< 8-bit unsigned char(s)
  59. };
  60. /// Union for fast 64-bit type casting
  61. union t64 {
  62. f64 _f64; ///< 64-bit floating point
  63. u64 _u64; ///< 64-bit unsigned long
  64. f32 _f32[2]; ///< 32-bit floating point(s)
  65. u32 _u32[2]; ///< 32-bit unsigned int(s)
  66. s32 _s32[2]; ///< 32-bit signed int(s)
  67. u16 _u16[4]; ///< 16-bit unsigned shorts(s)
  68. u8 _u8[8]; ///< 8-bit unsigned char(s)
  69. };
  70. // An inheritable class to disallow the copy constructor and operator= functions
  71. class NonCopyable {
  72. protected:
  73. NonCopyable() = default;
  74. ~NonCopyable() = default;
  75. NonCopyable(NonCopyable&) = delete;
  76. NonCopyable& operator=(NonCopyable&) = delete;
  77. };
  78. namespace Common {
  79. /// Rectangle data structure
  80. class Rect {
  81. public:
  82. Rect(int x0=0, int y0=0, int x1=0, int y1=0) {
  83. x0_ = x0;
  84. y0_ = y0;
  85. x1_ = x1;
  86. y1_ = y1;
  87. }
  88. ~Rect() { }
  89. int x0_; ///< Rect top left X-coordinate
  90. int y0_; ///< Rect top left Y-coordinate
  91. int x1_; ///< Rect bottom left X-coordinate
  92. int y1_; ///< Rect bottom right Y-coordinate
  93. inline u32 width() const { return std::abs(x1_ - x0_); }
  94. inline u32 height() const { return std::abs(y1_ - y0_); }
  95. inline bool operator == (const Rect& val) const {
  96. return (x0_ == val.x0_ && y0_ == val.y0_ && x1_ == val.x1_ && y1_ == val.y1_);
  97. }
  98. };
  99. }