common.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_funcs.h"
  6. #include "common/common_types.h"
  7. #include "common/swap.h"
  8. #include "core/hle/result.h"
  9. namespace AudioCore {
  10. namespace Audren {
  11. constexpr ResultCode ERR_INVALID_PARAMETERS{ErrorModule::Audio, 41};
  12. }
  13. constexpr u32_le CURRENT_PROCESS_REVISION = Common::MakeMagic('R', 'E', 'V', '8');
  14. static constexpr u32 VersionFromRevision(u32_le rev) {
  15. // "REV7" -> 7
  16. return ((rev >> 24) & 0xff) - 0x30;
  17. }
  18. static constexpr bool IsRevisionSupported(u32 required, u32_le user_revision) {
  19. const auto base = VersionFromRevision(user_revision);
  20. return required <= base;
  21. }
  22. static constexpr bool IsValidRevision(u32_le revision) {
  23. const auto base = VersionFromRevision(revision);
  24. constexpr auto max_rev = VersionFromRevision(CURRENT_PROCESS_REVISION);
  25. return base <= max_rev;
  26. }
  27. static constexpr bool CanConsumeBuffer(std::size_t size, std::size_t offset, std::size_t required) {
  28. if (offset > size) {
  29. return false;
  30. }
  31. if (size < required) {
  32. return false;
  33. }
  34. if ((size - offset) < required) {
  35. return false;
  36. }
  37. return true;
  38. }
  39. } // namespace AudioCore