dsp_dsp.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include "common/log.h"
  5. #include "core/hle/hle.h"
  6. #include "core/hle/kernel/event.h"
  7. #include "core/hle/service/dsp_dsp.h"
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////
  9. // Namespace DSP_DSP
  10. namespace DSP_DSP {
  11. static u32 read_pipe_count;
  12. static Handle semaphore_event;
  13. static Handle interrupt_event;
  14. /**
  15. * DSP_DSP::ConvertProcessAddressFromDspDram service function
  16. * Inputs:
  17. * 1 : Address
  18. * Outputs:
  19. * 1 : Result of function, 0 on success, otherwise error code
  20. * 2 : (inaddr << 1) + 0x1FF40000 (where 0x1FF00000 is the DSP RAM address)
  21. */
  22. void ConvertProcessAddressFromDspDram(Service::Interface* self) {
  23. u32* cmd_buff = Service::GetCommandBuffer();
  24. u32 addr = cmd_buff[1];
  25. cmd_buff[1] = 0; // No error
  26. cmd_buff[2] = (addr << 1) + (Memory::DSP_MEMORY_VADDR + 0x40000);
  27. LOG_WARNING(Service_DSP, "(STUBBED) called with address %u", addr);
  28. }
  29. /**
  30. * DSP_DSP::LoadComponent service function
  31. * Inputs:
  32. * 1 : Size
  33. * 2 : Unknown (observed only half word used)
  34. * 3 : Unknown (observed only half word used)
  35. * 4 : (size << 4) | 0xA
  36. * 5 : Buffer address
  37. * Outputs:
  38. * 1 : Result of function, 0 on success, otherwise error code
  39. * 2 : Component loaded, 0 on not loaded, 1 on loaded
  40. */
  41. void LoadComponent(Service::Interface* self) {
  42. u32* cmd_buff = Service::GetCommandBuffer();
  43. cmd_buff[1] = 0; // No error
  44. cmd_buff[2] = 1; // Pretend that we actually loaded the DSP firmware
  45. // TODO(bunnei): Implement real DSP firmware loading
  46. LOG_WARNING(Service_DSP, "(STUBBED) called");
  47. }
  48. /**
  49. * DSP_DSP::GetSemaphoreEventHandle service function
  50. * Outputs:
  51. * 1 : Result of function, 0 on success, otherwise error code
  52. * 3 : Semaphore event handle
  53. */
  54. void GetSemaphoreEventHandle(Service::Interface* self) {
  55. u32* cmd_buff = Service::GetCommandBuffer();
  56. cmd_buff[1] = 0; // No error
  57. cmd_buff[3] = semaphore_event; // Event handle
  58. LOG_WARNING(Service_DSP, "(STUBBED) called");
  59. }
  60. /**
  61. * DSP_DSP::RegisterInterruptEvents service function
  62. * Inputs:
  63. * 1 : Parameter 0 (purpose unknown)
  64. * 2 : Parameter 1 (purpose unknown)
  65. * 4 : Interrupt event handle
  66. * Outputs:
  67. * 1 : Result of function, 0 on success, otherwise error code
  68. */
  69. void RegisterInterruptEvents(Service::Interface* self) {
  70. u32* cmd_buff = Service::GetCommandBuffer();
  71. interrupt_event = static_cast<Handle>(cmd_buff[4]);
  72. cmd_buff[1] = 0; // No error
  73. LOG_WARNING(Service_DSP, "(STUBBED) called");
  74. }
  75. /**
  76. * DSP_DSP::WriteReg0x10 service function
  77. * Inputs:
  78. * 1 : Unknown (observed only half word used)
  79. * Outputs:
  80. * 1 : Result of function, 0 on success, otherwise error code
  81. */
  82. void WriteReg0x10(Service::Interface* self) {
  83. u32* cmd_buff = Service::GetCommandBuffer();
  84. Kernel::SignalEvent(interrupt_event);
  85. cmd_buff[1] = 0; // No error
  86. LOG_WARNING(Service_DSP, "(STUBBED) called");
  87. }
  88. /**
  89. * DSP_DSP::ReadPipeIfPossible service function
  90. * Inputs:
  91. * 1 : Unknown
  92. * 2 : Unknown
  93. * 3 : Size in bytes of read (observed only lower half word used)
  94. * 0x41 : Virtual address to read from DSP pipe to in memory
  95. * Outputs:
  96. * 1 : Result of function, 0 on success, otherwise error code
  97. * 2 : Number of bytes read from pipe
  98. */
  99. void ReadPipeIfPossible(Service::Interface* self) {
  100. u32* cmd_buff = Service::GetCommandBuffer();
  101. u32 size = cmd_buff[3] & 0xFFFF;// Lower 16 bits are size
  102. VAddr addr = cmd_buff[0x41];
  103. // Canned DSP responses that games expect. These were taken from HW by 3dmoo team.
  104. // TODO: Remove this hack :)
  105. static const std::array<u16, 16> canned_read_pipe = {
  106. 0x000F, 0xBFFF, 0x9E8E, 0x8680, 0xA78E, 0x9430, 0x8400, 0x8540,
  107. 0x948E, 0x8710, 0x8410, 0xA90E, 0xAA0E, 0xAACE, 0xAC4E, 0xAC58
  108. };
  109. u32 initial_size = read_pipe_count;
  110. for (unsigned offset = 0; offset < size; offset += sizeof(u16)) {
  111. if (read_pipe_count < canned_read_pipe.size()) {
  112. Memory::Write16(addr + offset, canned_read_pipe[read_pipe_count]);
  113. read_pipe_count++;
  114. } else {
  115. LOG_ERROR(Service_DSP, "canned read pipe log exceeded!");
  116. break;
  117. }
  118. }
  119. cmd_buff[1] = 0; // No error
  120. cmd_buff[2] = (read_pipe_count - initial_size) * sizeof(u16);
  121. LOG_WARNING(Service_DSP, "(STUBBED) called size=0x%08X, buffer=0x%08X", size, addr);
  122. }
  123. const Interface::FunctionInfo FunctionTable[] = {
  124. {0x00010040, nullptr, "RecvData"},
  125. {0x00020040, nullptr, "RecvDataIsReady"},
  126. {0x00030080, nullptr, "SendData"},
  127. {0x00040040, nullptr, "SendDataIsEmpty"},
  128. {0x00070040, WriteReg0x10, "WriteReg0x10"},
  129. {0x00080000, nullptr, "GetSemaphore"},
  130. {0x00090040, nullptr, "ClearSemaphore"},
  131. {0x000B0000, nullptr, "CheckSemaphoreRequest"},
  132. {0x000C0040, ConvertProcessAddressFromDspDram, "ConvertProcessAddressFromDspDram"},
  133. {0x000D0082, nullptr, "WriteProcessPipe"},
  134. {0x001000C0, ReadPipeIfPossible, "ReadPipeIfPossible"},
  135. {0x001100C2, LoadComponent, "LoadComponent"},
  136. {0x00120000, nullptr, "UnloadComponent"},
  137. {0x00130082, nullptr, "FlushDataCache"},
  138. {0x00140082, nullptr, "InvalidateDCache"},
  139. {0x00150082, RegisterInterruptEvents, "RegisterInterruptEvents"},
  140. {0x00160000, GetSemaphoreEventHandle, "GetSemaphoreEventHandle"},
  141. {0x00170040, nullptr, "SetSemaphoreMask"},
  142. {0x00180040, nullptr, "GetPhysicalAddress"},
  143. {0x00190040, nullptr, "GetVirtualAddress"},
  144. {0x001A0042, nullptr, "SetIirFilterI2S1_cmd1"},
  145. {0x001B0042, nullptr, "SetIirFilterI2S1_cmd2"},
  146. {0x001C0082, nullptr, "SetIirFilterEQ"},
  147. {0x001F0000, nullptr, "GetHeadphoneStatus"},
  148. {0x00210000, nullptr, "GetIsDspOccupied"},
  149. };
  150. ////////////////////////////////////////////////////////////////////////////////////////////////////
  151. // Interface class
  152. Interface::Interface() {
  153. semaphore_event = Kernel::CreateEvent(RESETTYPE_ONESHOT, "DSP_DSP::semaphore_event");
  154. interrupt_event = 0;
  155. read_pipe_count = 0;
  156. Register(FunctionTable, ARRAY_SIZE(FunctionTable));
  157. }
  158. Interface::~Interface() {
  159. }
  160. } // namespace