1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-14 06:26:57 +00:00
nxdumptool/source/utils.h

104 lines
2.5 KiB
C
Raw Normal View History

2020-04-16 01:06:41 +01:00
/*
* Copyright (c) 2020 DarkMatterCore
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2020-04-15 21:50:07 +01:00
#pragma once
#ifndef __UTILS_H__
#define __UTILS_H__
#include <switch.h>
#define APP_BASE_PATH "sdmc:/switch/nxdumptool/"
2020-04-15 21:50:07 +01:00
#define LOGFILE(fmt, ...) utilsWriteLogMessage(__func__, fmt, ##__VA_ARGS__)
2020-04-15 21:50:07 +01:00
#define MEMBER_SIZE(type, member) sizeof(((type*)NULL)->member)
2020-04-15 21:50:07 +01:00
#define MAX_ELEMENTS(x) ((sizeof((x))) / (sizeof((x)[0])))
2020-04-15 21:50:07 +01:00
2020-04-26 09:35:01 +01:00
#define ALIGN_DOWN(x, y) ((x) & ~((y) - 1))
#define ALIGN_UP(x, y) ((((y) - 1) + (x)) & ~((y) - 1))
2020-04-15 21:50:07 +01:00
#define BIS_SYSTEM_PARTITION_MOUNT_NAME "sys:"
2020-04-15 21:50:07 +01:00
2020-04-26 09:35:01 +01:00
#define NPDM_META_MAGIC 0x4D455441 /* "META" */
#define TITLE_PATCH_BITMASK (u64)0x800
#define TITLE_ADDON_BITMASK (u64)0xFFFFFFFFFFFF0000
2020-04-29 22:16:59 +01:00
NX_INLINE u64 titleGetPatchIdByApplicationId(u64 app_id)
{
return (app_id | TITLE_PATCH_BITMASK);
}
2020-04-29 22:16:59 +01:00
NX_INLINE u64 titleGetApplicationIdByPatchId(u64 patch_id)
{
return (patch_id & ~TITLE_PATCH_BITMASK);
}
2020-04-15 21:50:07 +01:00
typedef enum {
2020-04-16 11:13:11 +01:00
UtilsCustomFirmwareType_Unknown = 0,
UtilsCustomFirmwareType_Atmosphere = 1,
UtilsCustomFirmwareType_SXOS = 2,
UtilsCustomFirmwareType_ReiNX = 3
2020-04-15 21:50:07 +01:00
} UtilsCustomFirmwareType;
typedef struct {
u16 major : 6;
u16 minor : 6;
u16 micro : 4;
u16 bugfix;
} TitleVersion;
u64 utilsHidKeysAllDown(void);
u64 utilsHidKeysAllHeld(void);
void utilsWaitForButtonPress(void);
void utilsWriteLogMessage(const char *func_name, const char *fmt, ...);
void utilsOverclockSystem(bool restore);
bool utilsInitializeResources(void);
void utilsCloseResources(void);
2020-04-16 11:13:11 +01:00
u8 utilsGetCustomFirmwareType(void); ///< UtilsCustomFirmwareType.
void utilsGenerateHexStringFromData(char *dst, size_t dst_size, const void *src, size_t src_size);
2020-04-15 21:50:07 +01:00
FsStorage *utilsGetEmmcBisSystemPartitionStorage(void);
2020-04-15 21:50:07 +01:00
static inline void utilsSleep(u64 seconds)
2020-04-15 21:50:07 +01:00
{
if (seconds) svcSleepThread(seconds * (u64)1000000000);
2020-04-15 21:50:07 +01:00
}
#endif /* __UTILS_H__ */