lcd.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstring>
  5. #include "common/common_types.h"
  6. #include "common/logging/log.h"
  7. #include "core/hw/hw.h"
  8. #include "core/hw/lcd.h"
  9. #include "core/tracer/recorder.h"
  10. #include "video_core/debug_utils/debug_utils.h"
  11. namespace LCD {
  12. Regs g_regs;
  13. template <typename T>
  14. inline void Read(T& var, const u32 raw_addr) {
  15. u32 addr = raw_addr - HW::VADDR_LCD;
  16. u32 index = addr / 4;
  17. // Reads other than u32 are untested, so I'd rather have them abort than silently fail
  18. if (index >= 0x400 || !std::is_same<T, u32>::value) {
  19. LOG_ERROR(HW_LCD, "unknown Read%lu @ 0x%08X", sizeof(var) * 8, addr);
  20. return;
  21. }
  22. var = g_regs[index];
  23. }
  24. template <typename T>
  25. inline void Write(u32 addr, const T data) {
  26. addr -= HW::VADDR_LCD;
  27. u32 index = addr / 4;
  28. // Writes other than u32 are untested, so I'd rather have them abort than silently fail
  29. if (index >= 0x400 || !std::is_same<T, u32>::value) {
  30. LOG_ERROR(HW_LCD, "unknown Write%lu 0x%08X @ 0x%08X", sizeof(data) * 8, (u32)data, addr);
  31. return;
  32. }
  33. g_regs[index] = static_cast<u32>(data);
  34. // Notify tracer about the register write
  35. // This is happening *after* handling the write to make sure we properly catch all memory reads.
  36. if (Pica::g_debug_context && Pica::g_debug_context->recorder) {
  37. // addr + GPU VBase - IO VBase + IO PBase
  38. Pica::g_debug_context->recorder->RegisterWritten<T>(
  39. addr + HW::VADDR_LCD - 0x1EC00000 + 0x10100000, data);
  40. }
  41. }
  42. // Explicitly instantiate template functions because we aren't defining this in the header:
  43. template void Read<u64>(u64& var, const u32 addr);
  44. template void Read<u32>(u32& var, const u32 addr);
  45. template void Read<u16>(u16& var, const u32 addr);
  46. template void Read<u8>(u8& var, const u32 addr);
  47. template void Write<u64>(u32 addr, const u64 data);
  48. template void Write<u32>(u32 addr, const u32 data);
  49. template void Write<u16>(u32 addr, const u16 data);
  50. template void Write<u8>(u32 addr, const u8 data);
  51. /// Initialize hardware
  52. void Init() {
  53. memset(&g_regs, 0, sizeof(g_regs));
  54. LOG_DEBUG(HW_LCD, "initialized OK");
  55. }
  56. /// Shutdown hardware
  57. void Shutdown() {
  58. LOG_DEBUG(HW_LCD, "shutdown OK");
  59. }
  60. } // namespace