function_wrappers.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_types.h"
  6. #include "core/mem_map.h"
  7. #include "core/hle/hle.h"
  8. namespace HLE {
  9. #define PARAM(n) Core::g_app_core->GetReg(n)
  10. #define RETURN(n) Core::g_app_core->SetReg(0, n)
  11. ////////////////////////////////////////////////////////////////////////////////////////////////////
  12. // Function wrappers that return type s32
  13. template<s32 func(u32, u32, u32, u32)> void Wrap() {
  14. RETURN(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)));
  15. }
  16. template<s32 func(u32, u32, u32, u32, u32)> void Wrap() {
  17. RETURN(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)));
  18. }
  19. template<s32 func(u32*, u32, u32, u32, u32, u32)> void Wrap(){
  20. u32 param_1 = 0;
  21. u32 retval = func(&param_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
  22. Core::g_app_core->SetReg(1, param_1);
  23. RETURN(retval);
  24. }
  25. template<s32 func(s32*, u32*, s32, bool, s64)> void Wrap() {
  26. s32 param_1 = 0;
  27. s32 retval = func(&param_1, (Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2),
  28. (PARAM(3) != 0), (((s64)PARAM(4) << 32) | PARAM(0)));
  29. Core::g_app_core->SetReg(1, (u32)param_1);
  30. RETURN(retval);
  31. }
  32. // TODO(bunnei): Is this correct? Probably not - Last parameter looks wrong for ArbitrateAddress
  33. template<s32 func(u32, u32, u32, u32, s64)> void Wrap() {
  34. RETURN(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), (((s64)PARAM(5) << 32) | PARAM(4))));
  35. }
  36. template<s32 func(u32*)> void Wrap(){
  37. u32 param_1 = 0;
  38. u32 retval = func(&param_1);
  39. Core::g_app_core->SetReg(1, param_1);
  40. RETURN(retval);
  41. }
  42. template<s32 func(u32, s64)> void Wrap() {
  43. RETURN(func(PARAM(0), (((s64)PARAM(3) << 32) | PARAM(2))));
  44. }
  45. template<s32 func(void*, void*, u32)> void Wrap(){
  46. RETURN(func(Memory::GetPointer(PARAM(0)), Memory::GetPointer(PARAM(1)), PARAM(2)));
  47. }
  48. template<s32 func(s32*, u32)> void Wrap(){
  49. s32 param_1 = 0;
  50. u32 retval = func(&param_1, PARAM(1));
  51. Core::g_app_core->SetReg(1, param_1);
  52. RETURN(retval);
  53. }
  54. template<s32 func(u32, s32)> void Wrap() {
  55. RETURN(func(PARAM(0), (s32)PARAM(1)));
  56. }
  57. template<s32 func(u32*, u32)> void Wrap(){
  58. u32 param_1 = 0;
  59. u32 retval = func(&param_1, PARAM(1));
  60. Core::g_app_core->SetReg(1, param_1);
  61. RETURN(retval);
  62. }
  63. template<s32 func(u32)> void Wrap() {
  64. RETURN(func(PARAM(0)));
  65. }
  66. template<s32 func(void*)> void Wrap() {
  67. RETURN(func(Memory::GetPointer(PARAM(0))));
  68. }
  69. template<s32 func(s64*, u32, void*, s32)> void Wrap(){
  70. RETURN(func((s64*)Memory::GetPointer(PARAM(0)), PARAM(1), Memory::GetPointer(PARAM(2)),
  71. (s32)PARAM(3)));
  72. }
  73. template<s32 func(u32*, const char*)> void Wrap() {
  74. u32 param_1 = 0;
  75. u32 retval = func(&param_1, Memory::GetCharPointer(PARAM(1)));
  76. Core::g_app_core->SetReg(1, param_1);
  77. RETURN(retval);
  78. }
  79. ////////////////////////////////////////////////////////////////////////////////////////////////////
  80. // Function wrappers that return type u32
  81. template<u32 func()> void Wrap() {
  82. RETURN(func());
  83. }
  84. ////////////////////////////////////////////////////////////////////////////////////////////////////
  85. /// Function wrappers that return type void
  86. template<void func(s64)> void Wrap() {
  87. func(((s64)PARAM(1) << 32) | PARAM(0));
  88. }
  89. template<void func(const char*)> void Wrap() {
  90. func(Memory::GetCharPointer(PARAM(0)));
  91. }
  92. #undef PARAM
  93. #undef RETURN
  94. } // namespace HLE