]> Chaos Git - corbenik/ctrulib.git/commitdiff
Minor cleanup in os.h/os.c + add osGet3DSliderState()
authorfincs <fincs.alt1@gmail.com>
Thu, 5 Nov 2015 11:33:43 +0000 (12:33 +0100)
committerfincs <fincs.alt1@gmail.com>
Thu, 5 Nov 2015 11:33:43 +0000 (12:33 +0100)
libctru/include/3ds/os.h
libctru/source/os.c

index edd596360d0b9ad8489ca34f212b98d91158abfd..db3db6d51e203e7fb5cfbb06b5d2891204c4c004 100644 (file)
@@ -47,7 +47,10 @@ const char* osStrError(u32 error);
  *
  * This can be used to compare system versions easily with @ref SYSTEM_VERSION.
  */
-u32 osGetFirmVersion(void);
+static inline u32 osGetFirmVersion(void)
+{
+       return (*(vu32*)0x1FF80060) & ~0xFF;
+}
 
 /**
  * @brief Gets the system's kernel version.
@@ -59,7 +62,10 @@ u32 osGetFirmVersion(void);
  * if(osGetKernelVersion() > SYSTEM_VERSION(2,46,0)) printf("You are running 9.0 or higher\n");
  * @endcode
  */
-u32 osGetKernelVersion(void);
+static inline u32 osGetKernelVersion(void)
+{
+       return (*(vu32*)0x1FF80000) & ~0xFF;
+}
 
 /**
  * @brief Gets the current time.
@@ -82,7 +88,19 @@ u64 osGetTime(void);
  *
  * These values correspond with the number of wifi bars displayed by Home Menu.
  */
-u8 osGetWifiStrength(void);
+static inline u8 osGetWifiStrength(void)
+{
+       return *(vu8*)0x1FF81066;
+}
+
+/**
+ * @brief Gets the state of the 3D slider.
+ * @return The state of the 3D slider (0.0~1.0)
+ */
+static inline float osGet3DSliderState(void)
+{
+       return *(volatile float*)0x1FF81080;
+}
 
 /**
  * @brief Configures the New 3DS speedup.
index 338546d8410f9fdd0f047f066be0988481faf8ef..029d9fc6c39e4d2ed90cf7af2b51d7a33a7090ce 100644 (file)
@@ -20,12 +20,9 @@ typedef struct {
        //...
 } datetime_t;
 
-static volatile u32* __datetime_selector =
-       (u32*) 0x1FF81000;
-static volatile datetime_t* __datetime0 =
-       (datetime_t*) 0x1FF81020;
-static volatile datetime_t* __datetime1 =
-       (datetime_t*) 0x1FF81040;
+#define __datetime_selector        (*(vu32*)0x1FF81000)
+#define __datetime0 (*(volatile datetime_t*)0x1FF81020)
+#define __datetime1 (*(volatile datetime_t*)0x1FF81040)
 
 __attribute__((weak)) bool __ctru_speedup = false;
 
@@ -54,16 +51,16 @@ u32 osConvertOldLINEARMemToNew(u32 vaddr) {
 //---------------------------------------------------------------------------------
 static datetime_t getSysTime(void) {
 //---------------------------------------------------------------------------------
-       u32 s1, s2 = *__datetime_selector & 1;
+       u32 s1, s2 = __datetime_selector & 1;
        datetime_t dt;
 
        do {
                s1 = s2;
                if(!s1)
-                       dt = *__datetime0;
+                       dt = __datetime0;
                else
-                       dt = *__datetime1;
-               s2 = *__datetime_selector & 1;
+                       dt = __datetime1;
+               s2 = __datetime_selector & 1;
        } while(s2 != s1);
 
        return dt;
@@ -97,7 +94,6 @@ int __libctru_gtod(struct _reent *ptr, struct timeval *tp, struct timezone *tz)
 
 }
 
-
 // Returns number of milliseconds since 1st Jan 1900 00:00.
 //---------------------------------------------------------------------------------
 u64 osGetTime(void) {
@@ -109,18 +105,6 @@ u64 osGetTime(void) {
        return dt.date_time + (u32)(u64_to_double(delta)/TICKS_PER_MSEC);
 }
 
-//---------------------------------------------------------------------------------
-u32 osGetFirmVersion(void) {
-//---------------------------------------------------------------------------------
-       return (*(u32*)0x1FF80060) & ~0xFF;
-}
-
-//---------------------------------------------------------------------------------
-u32 osGetKernelVersion(void) {
-//---------------------------------------------------------------------------------
-       return (*(u32*)0x1FF80000) & ~0xFF;
-}
-
 //---------------------------------------------------------------------------------
 const char* osStrError(u32 error) {
 //---------------------------------------------------------------------------------
@@ -152,12 +136,6 @@ const char* osStrError(u32 error) {
        }
 }
 
-//---------------------------------------------------------------------------------
-u8 osGetWifiStrength(void) {
-//---------------------------------------------------------------------------------
-       return *((u8*)0x1FF81066);
-}
-
 void __ctru_speedup_config(void)
 {
        if (ptmSysmInit()==0)