lcd.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 constexpr size_t NumIds() {
  30. return sizeof(Regs) / sizeof(u32);
  31. }
  32. const u32& operator[](int index) const {
  33. const u32* content = reinterpret_cast<const u32*>(this);
  34. return content[index];
  35. }
  36. u32& operator[](int index) {
  37. u32* content = reinterpret_cast<u32*>(this);
  38. return content[index];
  39. }
  40. };
  41. static_assert(std::is_standard_layout<Regs>::value, "Structure does not use standard layout");
  42. // TODO: MSVC does not support using offsetof() on non-static data members even though this
  43. // is technically allowed since C++11. This macro should be enabled once MSVC adds
  44. // support for that.
  45. #ifndef _MSC_VER
  46. #define ASSERT_REG_POSITION(field_name, position) \
  47. static_assert(offsetof(Regs, field_name) == position * 4, \
  48. "Field " #field_name " has invalid position")
  49. ASSERT_REG_POSITION(color_fill_top, 0x81);
  50. ASSERT_REG_POSITION(backlight_top, 0x90);
  51. ASSERT_REG_POSITION(color_fill_bottom, 0x281);
  52. ASSERT_REG_POSITION(backlight_bottom, 0x290);
  53. #undef ASSERT_REG_POSITION
  54. #endif // !defined(_MSC_VER)
  55. extern Regs g_regs;
  56. template <typename T>
  57. void Read(T& var, const u32 addr);
  58. template <typename T>
  59. void Write(u32 addr, const T data);
  60. /// Initialize hardware
  61. void Init();
  62. /// Shutdown hardware
  63. void Shutdown();
  64. } // namespace