hw.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2014 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/logging/log.h"
  6. #include "core/hw/hw.h"
  7. #include "core/hw/gpu.h"
  8. #include "core/hw/lcd.h"
  9. namespace HW {
  10. template <typename T>
  11. inline void Read(T &var, const u32 addr) {
  12. switch (addr & 0xFFFFF000) {
  13. case VADDR_GPU:
  14. case VADDR_GPU + 0x1000:
  15. case VADDR_GPU + 0x2000:
  16. case VADDR_GPU + 0x3000:
  17. case VADDR_GPU + 0x4000:
  18. case VADDR_GPU + 0x5000:
  19. case VADDR_GPU + 0x6000:
  20. case VADDR_GPU + 0x7000:
  21. case VADDR_GPU + 0x8000:
  22. case VADDR_GPU + 0x9000:
  23. case VADDR_GPU + 0xA000:
  24. case VADDR_GPU + 0xB000:
  25. case VADDR_GPU + 0xC000:
  26. case VADDR_GPU + 0xD000:
  27. case VADDR_GPU + 0xE000:
  28. case VADDR_GPU + 0xF000:
  29. GPU::Read(var, addr);
  30. break;
  31. case VADDR_LCD:
  32. LCD::Read(var, addr);
  33. break;
  34. default:
  35. LOG_ERROR(HW_Memory, "unknown Read%lu @ 0x%08X", sizeof(var) * 8, addr);
  36. }
  37. }
  38. template <typename T>
  39. inline void Write(u32 addr, const T data) {
  40. switch (addr & 0xFFFFF000) {
  41. case VADDR_GPU:
  42. case VADDR_GPU + 0x1000:
  43. case VADDR_GPU + 0x2000:
  44. case VADDR_GPU + 0x3000:
  45. case VADDR_GPU + 0x4000:
  46. case VADDR_GPU + 0x5000:
  47. case VADDR_GPU + 0x6000:
  48. case VADDR_GPU + 0x7000:
  49. case VADDR_GPU + 0x8000:
  50. case VADDR_GPU + 0x9000:
  51. case VADDR_GPU + 0xA000:
  52. case VADDR_GPU + 0xB000:
  53. case VADDR_GPU + 0xC000:
  54. case VADDR_GPU + 0xD000:
  55. case VADDR_GPU + 0xE000:
  56. case VADDR_GPU + 0xF000:
  57. GPU::Write(addr, data);
  58. break;
  59. case VADDR_LCD:
  60. LCD::Write(addr, data);
  61. break;
  62. default:
  63. LOG_ERROR(HW_Memory, "unknown Write%lu 0x%08X @ 0x%08X", sizeof(data) * 8, (u32)data, addr);
  64. }
  65. }
  66. // Explicitly instantiate template functions because we aren't defining this in the header:
  67. template void Read<u64>(u64 &var, const u32 addr);
  68. template void Read<u32>(u32 &var, const u32 addr);
  69. template void Read<u16>(u16 &var, const u32 addr);
  70. template void Read<u8>(u8 &var, const u32 addr);
  71. template void Write<u64>(u32 addr, const u64 data);
  72. template void Write<u32>(u32 addr, const u32 data);
  73. template void Write<u16>(u32 addr, const u16 data);
  74. template void Write<u8>(u32 addr, const u8 data);
  75. /// Update hardware
  76. void Update() {
  77. }
  78. /// Initialize hardware
  79. void Init() {
  80. GPU::Init();
  81. LCD::Init();
  82. LOG_DEBUG(HW, "initialized OK");
  83. }
  84. /// Shutdown hardware
  85. void Shutdown() {
  86. GPU::Shutdown();
  87. LCD::Shutdown();
  88. LOG_DEBUG(HW, "shutdown OK");
  89. }
  90. }