shared_page.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/common_funcs.h"
  6. #include "core/core.h"
  7. #include "core/mem_map.h"
  8. #include "core/hle/config_mem.h"
  9. #include "core/hle/shared_page.h"
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////
  11. namespace SharedPage {
  12. // see http://3dbrew.org/wiki/Configuration_Memory#Shared_Memory_Page_For_ARM11_Processes
  13. #pragma pack(1)
  14. struct DateTime {
  15. u64 date_time; // 0x0
  16. u64 update_tick; // 0x8
  17. INSERT_PADDING_BYTES(0x20 - 0x10); // 0x10
  18. };
  19. struct SharedPageDef {
  20. // most of these names are taken from the 3dbrew page linked above.
  21. u32 date_time_selector; // 0x0
  22. u8 running_hw; // 0x4
  23. u8 mcu_hw_info; // 0x5: don't know what the acronyms mean
  24. INSERT_PADDING_BYTES(0x20 - 0x6); // 0x6
  25. DateTime date_time_0; // 0x20
  26. DateTime date_time_1; // 0x40
  27. u8 wifi_macaddr[6]; // 0x60
  28. u8 wifi_unknown1; // 0x66: 3dbrew says these are "Likely wifi hardware related"
  29. u8 wifi_unknown2; // 0x67
  30. INSERT_PADDING_BYTES(0x80 - 0x68); // 0x68
  31. float sliderstate_3d; // 0x80
  32. u8 ledstate_3d; // 0x84
  33. INSERT_PADDING_BYTES(0xA0 - 0x85); // 0x85
  34. u64 menu_title_id; // 0xA0
  35. u64 active_menu_title_id; // 0xA8
  36. INSERT_PADDING_BYTES(0x1000 - 0xB0); // 0xB0
  37. };
  38. #pragma pack()
  39. static_assert(sizeof(DateTime) == 0x20, "Datetime size is wrong");
  40. static_assert(sizeof(SharedPageDef) == Memory::SHARED_PAGE_SIZE, "Shared page structure size is wrong");
  41. static SharedPageDef shared_page;
  42. template <typename T>
  43. inline void Read(T &var, const u32 addr) {
  44. u32 offset = addr - Memory::SHARED_PAGE_VADDR;
  45. var = *(reinterpret_cast<T*>(((uintptr_t)&shared_page) + offset));
  46. }
  47. // Explicitly instantiate template functions because we aren't defining this in the header:
  48. template void Read<u64>(u64 &var, const u32 addr);
  49. template void Read<u32>(u32 &var, const u32 addr);
  50. template void Read<u16>(u16 &var, const u32 addr);
  51. template void Read<u8>(u8 &var, const u32 addr);
  52. void Set3DSlider(float amount) {
  53. shared_page.sliderstate_3d = amount;
  54. shared_page.ledstate_3d = (amount == 0.0f); // off when non-zero
  55. }
  56. void Init() {
  57. shared_page.running_hw = 0x1; // product
  58. Set3DSlider(0.0f);
  59. }
  60. } // namespace