Revert "hosversion: Suggestion for tristate properly handle error scenarios"

This reverts commit af67b4adb1.
This commit is contained in:
plutooo 2019-02-17 17:39:43 +01:00
parent 6892ab4d13
commit 371b164e79
5 changed files with 28 additions and 57 deletions

View File

@ -19,31 +19,24 @@
/// Extracts the micro number from a HOS version value.
#define HOSVER_MICRO(_version) ( (_version) & 0xFF)
void hosversionSetup(void);
/// Returns the current HOS version. Normally, this matches the version returned by \ref setsysGetFirmwareVersion or, if set:sys is not available, the version detected by \ref detectKernelVersion.
u32 hosversionGet(void);
/// Sets or overrides the current HOS version. This function is normally called automatically by libnx on startup.
void hosversionSet(u32 version);
typedef enum {
CompareResult_False,
CompareResult_True,
CompareResult_Unknown
} CompareResult;
CompareResult cmpresNot(CompareResult in) {
// Does a not-operation. True maps to False, False maps to True. Unknown maps to Unknown.
switch (in) {
case CompareResult_False:
return CompareResult_True;
case CompareResult_True:
return CompareResult_False;
default:
return CompareResult_Unknown;
}
}
/// Returns true if the current HOS version is equal to or above the specified major/minor/micro version.
CompareResult hosversionAtLeast(u8 major, u8 minor, u8 micro);
static inline bool hosversionAtLeast(u8 major, u8 minor, u8 micro) {
return hosversionGet() >= MAKEHOSVERSION(major,minor,micro);
}
/// Returns true if the current HOS version is earlier than the specified major/minor/micro version.
static inline CompareResult hosversionBefore(u8 major, u8 minor, u8 micro) {
return cmpresNot(hosversionAtLeast(major, minor, micro));
static inline bool hosversionBefore(u8 major, u8 minor, u8 micro) {
return !hosversionAtLeast(major, minor, micro);
}
/// Returns true if the current HOS version is between the two specified major versions, i.e. [major1, major2).
static inline bool hosversionBetween(u8 major1, u8 major2) {
u32 ver = hosversionGet();
return ver >= MAKEHOSVERSION(major1,0,0) && ver < MAKEHOSVERSION(major2,0,0);
}

View File

@ -51,7 +51,6 @@ static void _swkbdConfigClear(SwkbdConfig* c) {
}
static void _swkbdInitVersion(u32* version) {
/*
u32 hosver = hosversionGet();
if (hosver >= MAKEHOSVERSION(5,0,0))
*version = 0x50009;
@ -61,7 +60,7 @@ static void _swkbdInitVersion(u32* version) {
*version = 0x30007;
else if (hosver >= MAKEHOSVERSION(2,0,0))
*version = 0x10006;
else*/
else
*version=0x5;//1.0.0+ version
}

View File

@ -1,33 +1,13 @@
#include "runtime/hosversion.h"
#include "kernel/detect.h"
static u32 g_hosVersionKernelLowerBound;
static bool g_hasKernelLowerBound;
static u32 g_hosVersion;
static u32 g_hosVersionExact;
static bool g_hasExact;
void hosversionSetup(void) {
g_hosVersionKernelLowerBound = MAKEHOSVERSION(detectKernelVersion(), 0, 0);
g_hasKernelLowerBound = true;
}
void hosversionSet(u32 version) {
g_hosVersionExact = version;
g_hasExact = true;
}
CompareResult hosversionAtLeast(u8 major, u8 minor, u8 micro)
u32 hosversionGet(void)
{
if (g_hasExact) {
return (MAKEHOSVERSION(major, minor, micro) <= g_hosVersionExact) ? CompareResult_True : CompareResult_False;
}
if (g_hasKernelLowerBound) {
if (MAKEHOSVERSION(major, minor, micro) <= g_hosVersionKernelLowerBound)
return CompareResult_True;
}
return CompareResult_Unknown;
return __atomic_load_n(&g_hosVersion, __ATOMIC_SEQ_CST);
}
void hosversionSet(u32 version)
{
__atomic_store_n(&g_hosVersion, version, __ATOMIC_SEQ_CST);
}

View File

@ -168,7 +168,7 @@ void __attribute__((weak)) __libnx_init(void* ctx, Handle main_thread, void* sav
// Libnx initialization goes here.
envSetup(ctx, main_thread, saved_lr);
hosversionSetup();
hosversionSet(MAKEHOSVERSION(detectKernelVersion(), 0, 0));
newlibSetup();
virtmemSetup();
__libnx_initheap();

View File

@ -56,13 +56,12 @@ Result audrenInitialize(const AudioRendererConfig* config)
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
// Choose revision (i.e. if splitters are used then at least revision 2 must be used)
/*
u32 hosver = hosversionGet();
if (hosver >= MAKEHOSVERSION(6,1,0))
/*if (hosver >= MAKEHOSVERSION(6,1,0))
g_audrenRevision = AUDREN_REVISION_6;
else if (hosver >= MAKEHOSVERSION(6,0,0))
g_audrenRevision = AUDREN_REVISION_5;
else if (hosver >= MAKEHOSVERSION(4,0,0))
else*/ if (hosver >= MAKEHOSVERSION(4,0,0))
g_audrenRevision = AUDREN_REVISION_4;
else if (hosver >= MAKEHOSVERSION(3,0,0))
g_audrenRevision = AUDREN_REVISION_3;
@ -70,7 +69,7 @@ Result audrenInitialize(const AudioRendererConfig* config)
g_audrenRevision = AUDREN_REVISION_2;
else
g_audrenRevision = AUDREN_REVISION_1;
*/
// Prepare parameter structure
AudioRendererParameter param = {0};
param.sample_rate = config->output_rate == AudioRendererOutputRate_32kHz ? 32000 : 48000;