lcd.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "common/bit_field.h"
  7. #include "common/common_funcs.h"
  8. #include "common/common_types.h"
  9. #define LCD_REG_INDEX(field_name) (offsetof(LCD::Regs, field_name) / sizeof(u32))
  10. namespace LCD {
  11. struct Regs {
  12. union ColorFill {
  13. u32 raw;
  14. BitField<0, 8, u32> color_r;
  15. BitField<8, 8, u32> color_g;
  16. BitField<16, 8, u32> color_b;
  17. BitField<24, 1, u32> is_enabled;
  18. };
  19. INSERT_PADDING_WORDS(0x81);
  20. ColorFill color_fill_top;
  21. INSERT_PADDING_WORDS(0xE);
  22. u32 backlight_top;
  23. INSERT_PADDING_WORDS(0x1F0);
  24. ColorFill color_fill_bottom;
  25. INSERT_PADDING_WORDS(0xE);
  26. u32 backlight_bottom;
  27. INSERT_PADDING_WORDS(0x16F);
  28. static inline size_t NumIds() {
  29. return sizeof(Regs) / sizeof(u32);
  30. }
  31. u32& operator [] (int index) const {
  32. u32* content = (u32*)this;
  33. return content[index];
  34. }
  35. u32& operator [] (int index) {
  36. u32* content = (u32*)this;
  37. return content[index];
  38. }
  39. #undef ASSERT_MEMBER_SIZE
  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