shared_page.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/common_types.h"
  5. #include "common/log.h"
  6. #include "core/core.h"
  7. #include "core/mem_map.h"
  8. #include "core/hle/config_mem.h"
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////
  10. namespace SharedPage {
  11. // helper macro to properly align structure members.
  12. // Calling INSERT_PADDING_BYTES will add a new member variable with a name like "pad121",
  13. // depending on the current source line to make sure variable names are unique.
  14. #define INSERT_PADDING_BYTES_HELPER1(x, y) x ## y
  15. #define INSERT_PADDING_BYTES_HELPER2(x, y) INSERT_PADDING_BYTES_HELPER1(x, y)
  16. #define INSERT_PADDING_BYTES(num_words) u8 INSERT_PADDING_BYTES_HELPER2(pad, __LINE__)[(num_words)]
  17. // see http://3dbrew.org/wiki/Configuration_Memory#Shared_Memory_Page_For_ARM11_Processes
  18. #pragma pack(1)
  19. struct DateTime {
  20. u64 date_time; // 0x0
  21. u64 update_tick; // 0x8
  22. INSERT_PADDING_BYTES(0x20 - 0x10); // 0x10
  23. };
  24. struct SharedPageDef {
  25. // most of these names are taken from the 3dbrew page linked above.
  26. u32 date_time_selector; // 0x0
  27. u8 running_hw; // 0x4
  28. u8 mcu_hw_info; // 0x5: don't know what the acronyms mean
  29. INSERT_PADDING_BYTES(0x20 - 0x6); // 0x6
  30. DateTime date_time_0; // 0x20
  31. DateTime date_time_1; // 0x40
  32. u8 wifi_macaddr[6]; // 0x60
  33. u8 wifi_unknown1; // 0x66: 3dbrew says these are "Likely wifi hardware related"
  34. u8 wifi_unknown2; // 0x67
  35. INSERT_PADDING_BYTES(0x80 - 0x68); // 0x68
  36. float sliderstate_3d; // 0x80
  37. u8 ledstate_3d; // 0x84
  38. INSERT_PADDING_BYTES(0xA0 - 0x85); // 0x85
  39. u64 menu_title_id; // 0xA0
  40. u64 active_menu_title_id; // 0xA8
  41. INSERT_PADDING_BYTES(0x1000 - 0xB0); // 0xB0
  42. };
  43. #pragma pack()
  44. static_assert(sizeof(DateTime) == 0x20, "Datetime size is wrong");
  45. static_assert(sizeof(SharedPageDef) == Memory::SHARED_PAGE_SIZE, "Shared page structure size is wrong");
  46. static SharedPageDef shared_page;
  47. template <typename T>
  48. inline void Read(T &var, const u32 addr) {
  49. u32 offset = addr - Memory::SHARED_PAGE_VADDR;
  50. var = *(reinterpret_cast<T*>(((uintptr_t)&shared_page) + offset));
  51. }
  52. // Explicitly instantiate template functions because we aren't defining this in the header:
  53. template void Read<u64>(u64 &var, const u32 addr);
  54. template void Read<u32>(u32 &var, const u32 addr);
  55. template void Read<u16>(u16 &var, const u32 addr);
  56. template void Read<u8>(u8 &var, const u32 addr);
  57. void Set3DSlider(float amount) {
  58. shared_page.sliderstate_3d = amount;
  59. shared_page.ledstate_3d = (amount == 0.0f); // off when non-zero
  60. }
  61. void Init() {
  62. shared_page.running_hw = 0x1; // product
  63. Set3DSlider(0.0f);
  64. }
  65. } // namespace