lcd.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include <type_traits>
  7. #include "common/bit_field.h"
  8. #include "common/common_funcs.h"
  9. #include "common/common_types.h"
  10. #define LCD_REG_INDEX(field_name) (offsetof(LCD::Regs, field_name) / sizeof(u32))
  11. namespace LCD {
  12. struct Regs {
  13. union ColorFill {
  14. u32 raw;
  15. BitField<0, 8, u32> color_r;
  16. BitField<8, 8, u32> color_g;
  17. BitField<16, 8, u32> color_b;
  18. BitField<24, 1, u32> is_enabled;
  19. };
  20. INSERT_PADDING_WORDS(0x81);
  21. ColorFill color_fill_top;
  22. INSERT_PADDING_WORDS(0xE);
  23. u32 backlight_top;
  24. INSERT_PADDING_WORDS(0x1F0);
  25. ColorFill color_fill_bottom;
  26. INSERT_PADDING_WORDS(0xE);
  27. u32 backlight_bottom;
  28. INSERT_PADDING_WORDS(0x16F);
  29. static inline size_t NumIds() {
  30. return sizeof(Regs) / sizeof(u32);
  31. }
  32. u32& operator [] (int index) const {
  33. u32* content = (u32*)this;
  34. return content[index];
  35. }
  36. u32& operator [] (int index) {
  37. u32* content = (u32*)this;
  38. return content[index];
  39. }
  40. #undef ASSERT_MEMBER_SIZE
  41. };
  42. static_assert(std::is_standard_layout<Regs>::value, "Structure does not use standard layout");
  43. // TODO: MSVC does not support using offsetof() on non-static data members even though this
  44. // is technically allowed since C++11. This macro should be enabled once MSVC adds
  45. // support for that.
  46. #ifndef _MSC_VER
  47. #define ASSERT_REG_POSITION(field_name, position) \
  48. static_assert(offsetof(Regs, field_name) == position * 4, \
  49. "Field "#field_name" has invalid position")
  50. ASSERT_REG_POSITION(color_fill_top, 0x81);
  51. ASSERT_REG_POSITION(backlight_top, 0x90);
  52. ASSERT_REG_POSITION(color_fill_bottom, 0x281);
  53. ASSERT_REG_POSITION(backlight_bottom, 0x290);
  54. #undef ASSERT_REG_POSITION
  55. #endif // !defined(_MSC_VER)
  56. extern Regs g_regs;
  57. template <typename T>
  58. void Read(T &var, const u32 addr);
  59. template <typename T>
  60. void Write(u32 addr, const T data);
  61. /// Initialize hardware
  62. void Init();
  63. /// Shutdown hardware
  64. void Shutdown();
  65. } // namespace