better hints to reduce compiled size by a few kb

mostly just added static const to constant arrays/buffers
This commit is contained in:
Wolfvak 2020-07-23 13:46:42 -03:00
parent 698ad9d891
commit 929cc7fdcf
26 changed files with 72 additions and 81 deletions

View File

@ -23,7 +23,7 @@
typedef struct { typedef struct {
s16 cpad_x, cpad_y; s16 cpad_x, cpad_y;
s16 ts_x, ts_y; u16 ts_x, ts_y;
} CODEC_Input; } CODEC_Input;
void CODEC_Init(void); void CODEC_Init(void);

View File

@ -30,23 +30,15 @@ static u32 HID_ConvertCPAD(s16 cpad_x, s16 cpad_y)
{ {
u32 ret = 0; u32 ret = 0;
switch(int_sign(cpad_x)) { if (cpad_x > 0) {
default:
break;
case 1:
ret |= BUTTON_RIGHT; ret |= BUTTON_RIGHT;
break; } else if (cpad_x < 0) {
case -1:
ret |= BUTTON_LEFT; ret |= BUTTON_LEFT;
} }
switch(int_sign(cpad_y)) { if (cpad_y > 0) {
default:
break;
case 1:
ret |= BUTTON_UP; ret |= BUTTON_UP;
break; } else if (cpad_y < 0) {
case -1:
ret |= BUTTON_DOWN; ret |= BUTTON_DOWN;
} }

View File

@ -67,7 +67,7 @@ typedef struct {
} PACKED_STRUCT MCU_NotificationLED; } PACKED_STRUCT MCU_NotificationLED;
static u8 cached_volume_slider = 0; static u8 cached_volume_slider = 0;
static u32 spec_hid = 0, shell_state = SHELL_OPEN; static u32 spec_hid = 0, shell_state = 0;
static void MCU_UpdateVolumeSlider(void) static void MCU_UpdateVolumeSlider(void)
{ {
@ -189,6 +189,8 @@ void MCU_Init(void)
{ {
u32 clrpend, mask = 0; u32 clrpend, mask = 0;
shell_state = SHELL_OPEN;
/* set register mask and clear any pending registers */ /* set register mask and clear any pending registers */
MCU_WriteRegBuf(REG_INT_EN, (const u8*)&mask, sizeof(mask)); MCU_WriteRegBuf(REG_INT_EN, (const u8*)&mask, sizeof(mask));
MCU_ReadRegBuf(REG_INT_MASK, (u8*)&clrpend, sizeof(clrpend)); MCU_ReadRegBuf(REG_INT_MASK, (u8*)&clrpend, sizeof(clrpend));

View File

@ -39,8 +39,8 @@ static const u8 brightness_lvls[] = {
0x4D, 0x56, 0x60, 0x6B, 0x4D, 0x56, 0x60, 0x6B,
0x79, 0x8C, 0xA7, 0xD2 0x79, 0x8C, 0xA7, 0xD2
}; };
static int prev_bright_lvl = -1; static int prev_bright_lvl;
static bool auto_brightness = true; static bool auto_brightness;
#endif #endif
static SystemSHMEM __attribute__((section(".shared"))) SharedMemoryState; static SystemSHMEM __attribute__((section(".shared"))) SharedMemoryState;
@ -180,11 +180,11 @@ void __attribute__((noreturn)) MainLoop(void)
{ {
#ifdef FIXED_BRIGHTNESS #ifdef FIXED_BRIGHTNESS
LCD_SetBrightness(FIXED_BRIGHTNESS); LCD_SetBrightness(FIXED_BRIGHTNESS);
#else
prev_bright_lvl = -1;
auto_brightness = true;
#endif #endif
// clear up the shared memory section
memset(&SharedMemoryState, 0, sizeof(SharedMemoryState));
// configure interrupts // configure interrupts
gicSetInterruptConfig(PXI_RX_INTERRUPT, BIT(0), GIC_PRIO2, GIC_RISINGEDGE_1N, PXI_RX_Handler); gicSetInterruptConfig(PXI_RX_INTERRUPT, BIT(0), GIC_PRIO2, GIC_RISINGEDGE_1N, PXI_RX_Handler);
gicSetInterruptConfig(MCU_INTERRUPT, BIT(0), GIC_PRIO1, GIC_RISINGEDGE_1N, MCU_HandleInterrupts); gicSetInterruptConfig(MCU_INTERRUPT, BIT(0), GIC_PRIO1, GIC_RISINGEDGE_1N, MCU_HandleInterrupts);

View File

@ -7,7 +7,7 @@
// see: https://github.com/TASVideos/desmume/blob/master/desmume/src/bios.cpp#L1070tions // see: https://github.com/TASVideos/desmume/blob/master/desmume/src/bios.cpp#L1070tions
u16 crc16_quick(const void* src, u32 len) { u16 crc16_quick(const void* src, u32 len) {
const u16 tabval[] = { CRC16_TABVAL }; static const u16 tabval[] = { CRC16_TABVAL };
u16* data = (u16*) src; u16* data = (u16*) src;
u16 crc = 0xFFFF; u16 crc = 0xFFFF;

View File

@ -232,7 +232,7 @@ u32 CheckRecommendedKeyDb(const char* path)
{ {
// SHA-256 of the recommended aeskeydb.bin file // SHA-256 of the recommended aeskeydb.bin file
// equals MD5 A5B28945A7C051D7A0CD18AF0E580D1B // equals MD5 A5B28945A7C051D7A0CD18AF0E580D1B
const u8 recommended_sha[0x20] = { static const u8 recommended_sha[0x20] = {
0x40, 0x76, 0x54, 0x3D, 0xA3, 0xFF, 0x91, 0x1C, 0xE1, 0xCC, 0x4E, 0xC7, 0x2F, 0x92, 0xE4, 0xB7, 0x40, 0x76, 0x54, 0x3D, 0xA3, 0xFF, 0x91, 0x1C, 0xE1, 0xCC, 0x4E, 0xC7, 0x2F, 0x92, 0xE4, 0xB7,
0x2B, 0x24, 0x00, 0x15, 0xBE, 0x9B, 0xFC, 0xDE, 0x7F, 0xED, 0x95, 0x1D, 0xD5, 0xAB, 0x2D, 0xCB 0x2B, 0x24, 0x00, 0x15, 0xBE, 0x9B, 0xFC, 0xDE, 0x7F, 0xED, 0x95, 0x1D, 0xD5, 0xAB, 0x2D, 0xCB
}; };

View File

@ -11,13 +11,13 @@
#include "ui.h" // only for font file detection #include "ui.h" // only for font file detection
u64 IdentifyFileType(const char* path) { u64 IdentifyFileType(const char* path) {
const u8 romfs_magic[] = { ROMFS_MAGIC }; static const u8 romfs_magic[] = { ROMFS_MAGIC };
const u8 diff_magic[] = { DIFF_MAGIC }; static const u8 diff_magic[] = { DIFF_MAGIC };
const u8 disa_magic[] = { DISA_MAGIC }; static const u8 disa_magic[] = { DISA_MAGIC };
const u8 tickdb_magic[] = { TICKDB_MAGIC }; static const u8 tickdb_magic[] = { TICKDB_MAGIC };
const u8 smdh_magic[] = { SMDH_MAGIC }; static const u8 smdh_magic[] = { SMDH_MAGIC };
const u8 threedsx_magic[] = { THREEDSX_EXT_MAGIC }; static const u8 threedsx_magic[] = { THREEDSX_EXT_MAGIC };
const u8 png_magic[] = { PNG_MAGIC }; static const u8 png_magic[] = { PNG_MAGIC };
if (!path) return 0; // safety if (!path) return 0; // safety
u8 ALIGN(32) header[0x2C0]; // minimum required size u8 ALIGN(32) header[0x2C0]; // minimum required size

View File

@ -46,7 +46,7 @@ bool CheckWritePermissions(const char* path) {
// check drive type, get permission type // check drive type, get permission type
if (drvtype & DRV_SYSNAND) { if (drvtype & DRV_SYSNAND) {
u32 perms[] = { PERM_SYS_LVL0, PERM_SYS_LVL1, PERM_SYS_LVL2, PERM_SYS_LVL3 }; static const u32 perms[] = { PERM_SYS_LVL0, PERM_SYS_LVL1, PERM_SYS_LVL2, PERM_SYS_LVL3 };
u32 lvl = (drvtype & (DRV_TWLNAND|DRV_ALIAS|DRV_CTRNAND)) ? 1 : 0; u32 lvl = (drvtype & (DRV_TWLNAND|DRV_ALIAS|DRV_CTRNAND)) ? 1 : 0;
if (drvtype & (DRV_CTRNAND|DRV_VIRTUAL)) { // check for paths if (drvtype & (DRV_CTRNAND|DRV_VIRTUAL)) { // check for paths
const char* path_lvl3[] = { PATH_SYS_LVL3 }; const char* path_lvl3[] = { PATH_SYS_LVL3 };
@ -65,7 +65,7 @@ bool CheckWritePermissions(const char* path) {
perm = perms[lvl]; perm = perms[lvl];
snprintf(area_name, 16, "SysNAND (lvl%lu)", lvl); snprintf(area_name, 16, "SysNAND (lvl%lu)", lvl);
} else if (drvtype & DRV_EMUNAND) { } else if (drvtype & DRV_EMUNAND) {
u32 perms[] = { PERM_EMU_LVL0, PERM_EMU_LVL1 }; static const u32 perms[] = { PERM_EMU_LVL0, PERM_EMU_LVL1 };
u32 lvl = (drvtype & (DRV_ALIAS|DRV_CTRNAND)) ? 1 : 0; u32 lvl = (drvtype & (DRV_ALIAS|DRV_CTRNAND)) ? 1 : 0;
if (drvtype & DRV_VIRTUAL) { // check for paths if (drvtype & DRV_VIRTUAL) { // check for paths
const char* path_lvl1[] = { PATH_EMU_LVL1 }; const char* path_lvl1[] = { PATH_EMU_LVL1 };
@ -124,7 +124,7 @@ bool CheckWritePermissions(const char* path) {
} }
bool CheckDirWritePermissions(const char* path) { bool CheckDirWritePermissions(const char* path) {
const char* path_chk[] = { PATH_SYS_LVL3, PATH_SYS_LVL2, PATH_SYS_LVL1, PATH_EMU_LVL1 }; static const char* path_chk[] = { PATH_SYS_LVL3, PATH_SYS_LVL2, PATH_SYS_LVL1, PATH_EMU_LVL1 };
for (u32 i = 0; i < sizeof(path_chk) / sizeof(char*); i++) { for (u32 i = 0; i < sizeof(path_chk) / sizeof(char*); i++) {
const char* path_cmp = path_chk[i]; const char* path_cmp = path_chk[i];
u32 p = 0; u32 p = 0;

View File

@ -15,10 +15,10 @@ typedef struct {
static FilCryptInfo filcrypt[NUM_FILCRYPTINFO] = { 0 }; static FilCryptInfo filcrypt[NUM_FILCRYPTINFO] = { 0 };
char alias_drv[NUM_ALIAS_DRV]; // 1 char ASCII drive number of the alias drive / 0x00 if unused static char alias_drv[NUM_ALIAS_DRV]; // 1 char ASCII drive number of the alias drive / 0x00 if unused
char alias_path[NUM_ALIAS_DRV][128]; // full path to resolve the alias into static char alias_path[NUM_ALIAS_DRV][128]; // full path to resolve the alias into
u8 sd_keyy[NUM_ALIAS_DRV][16] __attribute__((aligned(4))); // key Y belonging to alias drive static u8 sd_keyy[NUM_ALIAS_DRV][16] __attribute__((aligned(4))); // key Y belonging to alias drive
int alias_num (const TCHAR* path) { int alias_num (const TCHAR* path) {
int num = -1; int num = -1;

View File

@ -50,11 +50,11 @@ u32 FixCiaHeaderForTmd(CiaHeader* header, TitleMetaData* tmd) {
} }
u32 BuildCiaCert(u8* ciacert) { u32 BuildCiaCert(u8* ciacert) {
const u8 cert_hash_expected[0x20] = { static const u8 cert_hash_expected[0x20] = {
0xC7, 0x2E, 0x1C, 0xA5, 0x61, 0xDC, 0x9B, 0xC8, 0x05, 0x58, 0x58, 0x9C, 0x63, 0x08, 0x1C, 0x8A, 0xC7, 0x2E, 0x1C, 0xA5, 0x61, 0xDC, 0x9B, 0xC8, 0x05, 0x58, 0x58, 0x9C, 0x63, 0x08, 0x1C, 0x8A,
0x10, 0x78, 0xDF, 0x42, 0x99, 0x80, 0x3A, 0x68, 0x58, 0xF0, 0x41, 0xF9, 0xCB, 0x10, 0xE6, 0x35 0x10, 0x78, 0xDF, 0x42, 0x99, 0x80, 0x3A, 0x68, 0x58, 0xF0, 0x41, 0xF9, 0xCB, 0x10, 0xE6, 0x35
}; };
const u8 cert_hash_expected_dev[0x20] = { static const u8 cert_hash_expected_dev[0x20] = {
0xFB, 0xD2, 0xC0, 0x47, 0x95, 0xB9, 0x4C, 0xC8, 0x0B, 0x64, 0x58, 0x96, 0xF6, 0x61, 0x0F, 0x52, 0xFB, 0xD2, 0xC0, 0x47, 0x95, 0xB9, 0x4C, 0xC8, 0x0B, 0x64, 0x58, 0x96, 0xF6, 0x61, 0x0F, 0x52,
0x18, 0x83, 0xAF, 0xE0, 0xF4, 0xE5, 0x62, 0xBA, 0x69, 0xEE, 0x72, 0x2A, 0xC2, 0x4E, 0x95, 0xB3 0x18, 0x83, 0xAF, 0xE0, 0xF4, 0xE5, 0x62, 0xBA, 0x69, 0xEE, 0x72, 0x2A, 0xC2, 0x4E, 0x95, 0xB3
}; };

View File

@ -159,11 +159,11 @@ inline static FRESULT DisaDiffQWrite(const TCHAR* path, const void* buf, UINT of
} }
u32 GetDisaDiffRWInfo(const char* path, DisaDiffRWInfo* info, bool partitionB) { u32 GetDisaDiffRWInfo(const char* path, DisaDiffRWInfo* info, bool partitionB) {
const u8 disa_magic[] = { DISA_MAGIC }; static const u8 disa_magic[] = { DISA_MAGIC };
const u8 diff_magic[] = { DIFF_MAGIC }; static const u8 diff_magic[] = { DIFF_MAGIC };
const u8 ivfc_magic[] = { IVFC_MAGIC }; static const u8 ivfc_magic[] = { IVFC_MAGIC };
const u8 dpfs_magic[] = { DPFS_MAGIC }; static const u8 dpfs_magic[] = { DPFS_MAGIC };
const u8 difi_magic[] = { DIFI_MAGIC }; static const u8 difi_magic[] = { DIFI_MAGIC };
// reset reader info // reset reader info
memset(info, 0x00, sizeof(DisaDiffRWInfo)); memset(info, 0x00, sizeof(DisaDiffRWInfo));

View File

@ -7,7 +7,7 @@
0x84, 0x9D, 0xA0, 0xD5, 0x6F, 0x5A, 0x34, 0xC4, 0x81, 0x06, 0x0C, 0x9F, 0xF2, 0xFA, 0xD8, 0x18 0x84, 0x9D, 0xA0, 0xD5, 0x6F, 0x5A, 0x34, 0xC4, 0x81, 0x06, 0x0C, 0x9F, 0xF2, 0xFA, 0xD8, 0x18
u32 ValidateAgbSaveHeader(AgbSaveHeader* header) { u32 ValidateAgbSaveHeader(AgbSaveHeader* header) {
u8 magic[] = { AGBSAVE_MAGIC }; static u8 magic[] = { AGBSAVE_MAGIC };
// basic checks // basic checks
if ((memcmp(header->magic, magic, sizeof(magic)) != 0) || if ((memcmp(header->magic, magic, sizeof(magic)) != 0) ||
@ -28,7 +28,7 @@ u32 ValidateAgbSaveHeader(AgbSaveHeader* header) {
// http://problemkaputt.de/gbatek.htm#gbacartridgeheader // http://problemkaputt.de/gbatek.htm#gbacartridgeheader
u32 ValidateAgbHeader(AgbHeader* agb) { u32 ValidateAgbHeader(AgbHeader* agb) {
const u8 logo_sha[0x20] = { AGBLOGO_SHA256 }; static const u8 logo_sha[0x20] = { AGBLOGO_SHA256 };
u8 logo[0x9C] __attribute__((aligned(4))); u8 logo[0x9C] __attribute__((aligned(4)));
// check fixed value // check fixed value

View File

@ -2,7 +2,7 @@
#include "ncch.h" #include "ncch.h"
u32 ValidateNcsdHeader(NcsdHeader* header) { u32 ValidateNcsdHeader(NcsdHeader* header) {
u8 zeroes[16] = { 0 }; static const u8 zeroes[16] = { 0 };
if ((memcmp(header->magic, "NCSD", 4) != 0) || // check magic number if ((memcmp(header->magic, "NCSD", 4) != 0) || // check magic number
(memcmp(header->partitions_fs_type, zeroes, 8) != 0) || !header->mediaId) // prevent detection of NAND images (memcmp(header->partitions_fs_type, zeroes, 8) != 0) || !header->mediaId) // prevent detection of NAND images
return 1; return 1;

View File

@ -19,7 +19,7 @@ u64 GetRomFsLvOffset(RomFsIvfcHeader* ivfc, u32 lvl) {
// validate IVFC header by checking offsets and hash sizes // validate IVFC header by checking offsets and hash sizes
u32 ValidateRomFsHeader(RomFsIvfcHeader* ivfc, u32 max_size) { u32 ValidateRomFsHeader(RomFsIvfcHeader* ivfc, u32 max_size) {
u8 magic[] = { ROMFS_MAGIC }; static const u8 magic[] = { ROMFS_MAGIC };
// check magic number // check magic number
if (memcmp(magic, ivfc->magic, sizeof(magic)) != 0) if (memcmp(magic, ivfc->magic, sizeof(magic)) != 0)

View File

@ -9,7 +9,7 @@
36, 37, 44, 45, 38, 39, 46, 47, 52, 53, 60, 61, 54, 55, 62, 63 36, 37, 44, 45, 38, 39, 46, 47, 52, 53, 60, 61, 54, 55, 62, 63
u32 ConvertSmdhIcon(u16* icon, const u16* smdh_icon, u32 w, u32 h) { u32 ConvertSmdhIcon(u16* icon, const u16* smdh_icon, u32 w, u32 h) {
const u32 lut[8*8] = { SMDH_LUT }; static const u32 lut[8*8] = { SMDH_LUT };
u16* pix565 = (u16*) smdh_icon; u16* pix565 = (u16*) smdh_icon;
for (u32 y = 0; y < h; y += 8) { for (u32 y = 0; y < h; y += 8) {
for (u32 x = 0; x < w; x += 8) { for (u32 x = 0; x < w; x += 8) {

View File

@ -6,7 +6,7 @@
#include "ff.h" #include "ff.h"
u32 ValidateTicket(Ticket* ticket) { u32 ValidateTicket(Ticket* ticket) {
const u8 magic[] = { TICKET_SIG_TYPE }; static const u8 magic[] = { TICKET_SIG_TYPE };
if ((memcmp(ticket->sig_type, magic, sizeof(magic)) != 0) || if ((memcmp(ticket->sig_type, magic, sizeof(magic)) != 0) ||
((strncmp((char*) ticket->issuer, TICKET_ISSUER, 0x40) != 0) && ((strncmp((char*) ticket->issuer, TICKET_ISSUER, 0x40) != 0) &&
(strncmp((char*) ticket->issuer, TICKET_ISSUER_DEV, 0x40) != 0)) || (strncmp((char*) ticket->issuer, TICKET_ISSUER_DEV, 0x40) != 0)) ||
@ -39,8 +39,8 @@ u32 ValidateTicketSignature(Ticket* ticket) {
} }
u32 BuildFakeTicket(Ticket* ticket, u8* title_id) { u32 BuildFakeTicket(Ticket* ticket, u8* title_id) {
const u8 sig_type[4] = { TICKET_SIG_TYPE }; // RSA_2048 SHA256 static const u8 sig_type[4] = { TICKET_SIG_TYPE }; // RSA_2048 SHA256
const u8 ticket_cnt_index[] = { // whatever this is static const u8 ticket_cnt_index[] = { // whatever this is
0x00, 0x01, 0x00, 0x14, 0x00, 0x00, 0x00, 0xAC, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00, 0x14, 0x00, 0x01, 0x00, 0x14, 0x00, 0x00, 0x00, 0xAC, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00, 0x14,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x84,
0x00, 0x00, 0x00, 0x84, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x84, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@ -72,11 +72,11 @@ u32 GetTicketSize(const Ticket* ticket) {
} }
u32 BuildTicketCert(u8* tickcert) { u32 BuildTicketCert(u8* tickcert) {
const u8 cert_hash_expected[0x20] = { static const u8 cert_hash_expected[0x20] = {
0xDC, 0x15, 0x3C, 0x2B, 0x8A, 0x0A, 0xC8, 0x74, 0xA9, 0xDC, 0x78, 0x61, 0x0E, 0x6A, 0x8F, 0xE3, 0xDC, 0x15, 0x3C, 0x2B, 0x8A, 0x0A, 0xC8, 0x74, 0xA9, 0xDC, 0x78, 0x61, 0x0E, 0x6A, 0x8F, 0xE3,
0xE6, 0xB1, 0x34, 0xD5, 0x52, 0x88, 0x73, 0xC9, 0x61, 0xFB, 0xC7, 0x95, 0xCB, 0x47, 0xE6, 0x97 0xE6, 0xB1, 0x34, 0xD5, 0x52, 0x88, 0x73, 0xC9, 0x61, 0xFB, 0xC7, 0x95, 0xCB, 0x47, 0xE6, 0x97
}; };
const u8 cert_hash_expected_dev[0x20] = { static const u8 cert_hash_expected_dev[0x20] = {
0x97, 0x2A, 0x32, 0xFF, 0x9D, 0x4B, 0xAA, 0x2F, 0x1A, 0x24, 0xCF, 0x21, 0x13, 0x87, 0xF5, 0x38, 0x97, 0x2A, 0x32, 0xFF, 0x9D, 0x4B, 0xAA, 0x2F, 0x1A, 0x24, 0xCF, 0x21, 0x13, 0x87, 0xF5, 0x38,
0xC6, 0x4B, 0xD4, 0x8F, 0xDF, 0x13, 0x21, 0x3D, 0xFC, 0x72, 0xFC, 0x8D, 0x9F, 0xDD, 0x01, 0x0E 0xC6, 0x4B, 0xD4, 0x8F, 0xDF, 0x13, 0x21, 0x3D, 0xFC, 0x72, 0xFC, 0x8D, 0x9F, 0xDD, 0x01, 0x0E
}; };

View File

@ -6,7 +6,7 @@
#include "ff.h" #include "ff.h"
u32 ValidateTmd(TitleMetaData* tmd) { u32 ValidateTmd(TitleMetaData* tmd) {
const u8 magic[] = { TMD_SIG_TYPE }; static const u8 magic[] = { TMD_SIG_TYPE };
if ((memcmp(tmd->sig_type, magic, sizeof(magic)) != 0) || if ((memcmp(tmd->sig_type, magic, sizeof(magic)) != 0) ||
((strncmp((char*) tmd->issuer, TMD_ISSUER, 0x40) != 0) && ((strncmp((char*) tmd->issuer, TMD_ISSUER, 0x40) != 0) &&
(strncmp((char*) tmd->issuer, TMD_ISSUER_DEV, 0x40) != 0))) (strncmp((char*) tmd->issuer, TMD_ISSUER_DEV, 0x40) != 0)))
@ -77,7 +77,7 @@ u32 FixTmdHashes(TitleMetaData* tmd) {
} }
u32 BuildFakeTmd(TitleMetaData* tmd, u8* title_id, u32 n_contents, u32 save_size, u32 twl_privsave_size) { u32 BuildFakeTmd(TitleMetaData* tmd, u8* title_id, u32 n_contents, u32 save_size, u32 twl_privsave_size) {
const u8 sig_type[4] = { TMD_SIG_TYPE }; static const u8 sig_type[4] = { TMD_SIG_TYPE };
// safety check: number of contents // safety check: number of contents
if (n_contents > TMD_MAX_CONTENTS) return 1; // potential incompatibility here (!) if (n_contents > TMD_MAX_CONTENTS) return 1; // potential incompatibility here (!)
// set TMD all zero for a clean start // set TMD all zero for a clean start
@ -102,11 +102,11 @@ u32 BuildFakeTmd(TitleMetaData* tmd, u8* title_id, u32 n_contents, u32 save_size
} }
u32 BuildTmdCert(u8* tmdcert) { u32 BuildTmdCert(u8* tmdcert) {
const u8 cert_hash_expected[0x20] = { static const u8 cert_hash_expected[0x20] = {
0x91, 0x5F, 0x77, 0x3A, 0x07, 0x82, 0xD4, 0x27, 0xC4, 0xCE, 0xF5, 0x49, 0x25, 0x33, 0xE8, 0xEC, 0x91, 0x5F, 0x77, 0x3A, 0x07, 0x82, 0xD4, 0x27, 0xC4, 0xCE, 0xF5, 0x49, 0x25, 0x33, 0xE8, 0xEC,
0xF6, 0xFE, 0xA1, 0xEB, 0x8C, 0xCF, 0x59, 0x6E, 0x69, 0xBA, 0x2A, 0x38, 0x8D, 0x73, 0x8A, 0xE1 0xF6, 0xFE, 0xA1, 0xEB, 0x8C, 0xCF, 0x59, 0x6E, 0x69, 0xBA, 0x2A, 0x38, 0x8D, 0x73, 0x8A, 0xE1
}; };
const u8 cert_hash_expected_dev[0x20] = { static const u8 cert_hash_expected_dev[0x20] = {
0x49, 0xC9, 0x41, 0x56, 0xCA, 0x86, 0xBD, 0x1F, 0x36, 0x51, 0x51, 0x6A, 0x4A, 0x9F, 0x54, 0xA1, 0x49, 0xC9, 0x41, 0x56, 0xCA, 0x86, 0xBD, 0x1F, 0x36, 0x51, 0x51, 0x6A, 0x4A, 0x9F, 0x54, 0xA1,
0xC2, 0xE9, 0xCA, 0x93, 0x94, 0xF4, 0x29, 0xA0, 0x38, 0x54, 0x75, 0xFF, 0xAB, 0x6E, 0x8E, 0x71 0xC2, 0xE9, 0xCA, 0x93, 0x94, 0xF4, 0x29, 0xA0, 0x38, 0x54, 0x75, 0xFF, 0xAB, 0x6E, 0x8E, 0x71
}; };

View File

@ -417,10 +417,10 @@ void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) {
} }
u32 SdFormatMenu(const char* slabel) { u32 SdFormatMenu(const char* slabel) {
const u32 cluster_size_table[5] = { 0x0, 0x0, 0x4000, 0x8000, 0x10000 }; static const u32 cluster_size_table[5] = { 0x0, 0x0, 0x4000, 0x8000, 0x10000 };
const char* option_emunand_size[7] = { "No EmuNAND", "RedNAND size (min)", "GW EmuNAND size (full)", static const char* option_emunand_size[7] = { "No EmuNAND", "RedNAND size (min)", "GW EmuNAND size (full)",
"MultiNAND size (2x)", "MultiNAND size (3x)", "MultiNAND size (4x)", "User input..." }; "MultiNAND size (2x)", "MultiNAND size (3x)", "MultiNAND size (4x)", "User input..." };
const char* option_cluster_size[4] = { "Auto", "16KB Clusters", "32KB Clusters", "64KB Clusters" }; static const char* option_cluster_size[4] = { "Auto", "16KB Clusters", "32KB Clusters", "64KB Clusters" };
u32 sysnand_min_size_sectors = GetNandMinSizeSectors(NAND_SYSNAND); u32 sysnand_min_size_sectors = GetNandMinSizeSectors(NAND_SYSNAND);
u64 sysnand_min_size_mb = ((sysnand_min_size_sectors * 0x200) + 0xFFFFF) / 0x100000; u64 sysnand_min_size_mb = ((sysnand_min_size_sectors * 0x200) + 0xFFFFF) / 0x100000;
u64 sysnand_multi_size_mb = (align(sysnand_min_size_sectors + 1, 0x2000) * 0x200) / 0x100000; u64 sysnand_multi_size_mb = (align(sysnand_min_size_sectors + 1, 0x2000) * 0x200) / 0x100000;
@ -467,13 +467,13 @@ u32 SdFormatMenu(const char* slabel) {
u32 emunand_offset = 1; u32 emunand_offset = 1;
u32 n_emunands = 1; u32 n_emunands = 1;
if (emunand_size_mb >= 2 * sysnand_size_mb) { if (emunand_size_mb >= 2 * sysnand_size_mb) {
const char* option_emunand_type[4] = { "RedNAND type (multi)", "RedNAND type (single)", "GW EmuNAND type", "Don't set up" }; static const char* option_emunand_type[4] = { "RedNAND type (multi)", "RedNAND type (single)", "GW EmuNAND type", "Don't set up" };
user_select = ShowSelectPrompt(4, option_emunand_type, "Choose EmuNAND type to set up:"); user_select = ShowSelectPrompt(4, option_emunand_type, "Choose EmuNAND type to set up:");
if (user_select > 3) return 0; if (user_select > 3) return 0;
emunand_offset = (user_select == 3) ? 0 : 1; emunand_offset = (user_select == 3) ? 0 : 1;
if (user_select == 1) n_emunands = 4; if (user_select == 1) n_emunands = 4;
} else if (emunand_size_mb >= sysnand_size_mb) { } else if (emunand_size_mb >= sysnand_size_mb) {
const char* option_emunand_type[3] = { "RedNAND type", "GW EmuNAND type", "Don't set up" }; static const char* option_emunand_type[3] = { "RedNAND type", "GW EmuNAND type", "Don't set up" };
user_select = ShowSelectPrompt(3, option_emunand_type, "Choose EmuNAND type to set up:"); user_select = ShowSelectPrompt(3, option_emunand_type, "Choose EmuNAND type to set up:");
if (user_select > 2) return 0; if (user_select > 2) return 0;
emunand_offset = (user_select == 2) ? 0 : 1; // 0 -> GW EmuNAND emunand_offset = (user_select == 2) ? 0 : 1; // 0 -> GW EmuNAND
@ -748,7 +748,7 @@ u32 FileHexViewer(const char* path) {
else if (dual_screen) ClearScreen(BOT_SCREEN, COLOR_STD_BG); else if (dual_screen) ClearScreen(BOT_SCREEN, COLOR_STD_BG);
else memcpy(BOT_SCREEN, bottom_cpy, SCREEN_SIZE_BOT); else memcpy(BOT_SCREEN, bottom_cpy, SCREEN_SIZE_BOT);
} else if (pad_state & BUTTON_X) { } else if (pad_state & BUTTON_X) {
const char* optionstr[3] = { "Go to offset", "Search for string", "Search for data" }; static const char* optionstr[3] = { "Go to offset", "Search for string", "Search for data" };
u32 user_select = ShowSelectPrompt(3, optionstr, "Current offset: %08X\nSelect action:", u32 user_select = ShowSelectPrompt(3, optionstr, "Current offset: %08X\nSelect action:",
(unsigned int) offset); (unsigned int) offset);
if (user_select == 1) { // -> goto offset if (user_select == 1) { // -> goto offset
@ -2329,7 +2329,7 @@ u32 GodMode(int entrypoint) {
} else { // one level up } else { // one level up
u32 user_select = 1; u32 user_select = 1;
if (curr_drvtype & DRV_SEARCH) { // special menu for search drive if (curr_drvtype & DRV_SEARCH) { // special menu for search drive
const char* optionstr[2] = { "Open this folder", "Open containing folder" }; static const char* optionstr[2] = { "Open this folder", "Open containing folder" };
char pathstr[32 + 1]; char pathstr[32 + 1];
TruncateString(pathstr, curr_entry->path, 32, 8); TruncateString(pathstr, curr_entry->path, 32, 8);
user_select = ShowSelectPrompt(2, optionstr, "%s", pathstr); user_select = ShowSelectPrompt(2, optionstr, "%s", pathstr);
@ -2490,7 +2490,7 @@ u32 GodMode(int entrypoint) {
} else if ((curr_drvtype & DRV_CART) && (pad_state & BUTTON_Y)) { } else if ((curr_drvtype & DRV_CART) && (pad_state & BUTTON_Y)) {
ShowPrompt(false, "Not allowed in gamecart drive"); ShowPrompt(false, "Not allowed in gamecart drive");
} else if (pad_state & BUTTON_Y) { // paste files } else if (pad_state & BUTTON_Y) { // paste files
const char* optionstr[2] = { "Copy path(s)", "Move path(s)" }; static const char* optionstr[2] = { "Copy path(s)", "Move path(s)" };
char promptstr[64]; char promptstr[64];
u32 flags = 0; u32 flags = 0;
u32 user_select; u32 user_select;
@ -2542,7 +2542,7 @@ u32 GodMode(int entrypoint) {
} }
} }
} else if (pad_state & BUTTON_Y) { // create an entry } else if (pad_state & BUTTON_Y) { // create an entry
const char* optionstr[] = { "Create a folder", "Create a dummy file" }; static const char* optionstr[] = { "Create a folder", "Create a dummy file" };
u32 type = ShowSelectPrompt(2, optionstr, "Create a new entry here?\nSelect type."); u32 type = ShowSelectPrompt(2, optionstr, "Create a new entry here?\nSelect type.");
if (type) { if (type) {
const char* typestr = (type == 1) ? "folder" : (type == 2) ? "file" : NULL; const char* typestr = (type == 1) ? "folder" : (type == 2) ? "file" : NULL;

View File

@ -386,7 +386,7 @@ u32 ValidateSecretSector(u8* sector)
// see: https://github.com/d0k3/GodMode9/blob/master/source/game/ncsd.c#L4 // see: https://github.com/d0k3/GodMode9/blob/master/source/game/ncsd.c#L4
u32 ValidateNandNcsdHeader(NandNcsdHeader* header) u32 ValidateNandNcsdHeader(NandNcsdHeader* header)
{ {
u8 zeroes[16] = { 0 }; static const u8 zeroes[16] = { 0 };
if ((memcmp(header->magic, "NCSD", 4) != 0) || // check magic number if ((memcmp(header->magic, "NCSD", 4) != 0) || // check magic number
(memcmp(header->partitions_fs_type, zeroes, 8) == 0) || header->mediaId) // prevent detection of cart NCSD images (memcmp(header->partitions_fs_type, zeroes, 8) == 0) || header->mediaId) // prevent detection of cart NCSD images
return 1; return 1;

View File

@ -97,7 +97,7 @@ u32 TransferCtrNandImage(const char* path_img, const char* drv) {
} }
// actual transfer - db files / titles // actual transfer - db files / titles
const char* dbnames[] = { "ticket.db", "certs.db", "title.db", "import.db", "tmp_t.db", "tmp_i.db" }; static const char* dbnames[] = { "ticket.db", "certs.db", "title.db", "import.db", "tmp_t.db", "tmp_i.db" };
char path_to[32]; char path_to[32];
char path_from[32]; char path_from[32];
char path_dbs[32]; char path_dbs[32];

View File

@ -68,7 +68,7 @@ u32 SetupSlot0x30(char drv) {
} }
u32 LocateAgbSaveSdBottomSlot(const char* path, AgbSaveHeader* agbsave) { u32 LocateAgbSaveSdBottomSlot(const char* path, AgbSaveHeader* agbsave) {
const u32 save_sizes[] = { static const u32 save_sizes[] = {
GBASAVE_EEPROM_512, GBASAVE_EEPROM_512,
GBASAVE_EEPROM_8K, GBASAVE_EEPROM_8K,
GBASAVE_SRAM_32K, GBASAVE_SRAM_32K,
@ -210,7 +210,7 @@ u32 CalculateFileCmac(const char* path, u8* cmac) {
else if ((cmac_type == CMAC_CMD_SD) || (cmac_type == CMAC_CMD_TWLN)) return 1; else if ((cmac_type == CMAC_CMD_SD) || (cmac_type == CMAC_CMD_TWLN)) return 1;
else if (!cmac_type) return 1; else if (!cmac_type) return 1;
const u32 cmac_keyslot[] = { CMAC_KEYSLOT }; static const u32 cmac_keyslot[] = { CMAC_KEYSLOT };
u8 hashdata[0x200] __attribute__((aligned(4))); u8 hashdata[0x200] __attribute__((aligned(4)));
u32 keyslot = cmac_keyslot[cmac_type]; u32 keyslot = cmac_keyslot[cmac_type];
u32 hashsize = 0; u32 hashsize = 0;

View File

@ -607,7 +607,7 @@ u32 SafeInstallFirm(const char* path, u32 slots) {
} }
u32 SafeInstallKeyDb(const char* path) { u32 SafeInstallKeyDb(const char* path) {
const u8 perfect_sha[] = { KEYDB_PERFECT_HASH }; static const u8 perfect_sha[] = { KEYDB_PERFECT_HASH };
u8 keydb[KEYDB_PERFECT_SIZE] __attribute__((aligned(4))); u8 keydb[KEYDB_PERFECT_SIZE] __attribute__((aligned(4)));
char pathstr[32 + 1]; // truncated path string char pathstr[32 + 1]; // truncated path string

View File

@ -139,7 +139,7 @@ typedef struct {
char content[_VAR_CNT_LEN]; char content[_VAR_CNT_LEN];
} Gm9ScriptVar; } Gm9ScriptVar;
Gm9ScriptCmd cmd_list[] = { static const Gm9ScriptCmd cmd_list[] = {
{ CMD_ID_NONE , "#" , 0, 0 }, // dummy entry { CMD_ID_NONE , "#" , 0, 0 }, // dummy entry
{ CMD_ID_NOT , _CMD_NOT , 0, 0 }, // inverts the output of the following command { CMD_ID_NOT , _CMD_NOT , 0, 0 }, // inverts the output of the following command
{ CMD_ID_IF , _CMD_IF , 1, 0 }, // control flow commands at the top of the list { CMD_ID_IF , _CMD_IF , 1, 0 }, // control flow commands at the top of the list
@ -532,7 +532,7 @@ bool expand_arg(char* argex, const char* arg, u32 len) {
} }
cmd_id get_cmd_id(char* cmd, u32 len, u32 flags, u32 argc, char* err_str) { cmd_id get_cmd_id(char* cmd, u32 len, u32 flags, u32 argc, char* err_str) {
Gm9ScriptCmd* cmd_entry = NULL; const Gm9ScriptCmd* cmd_entry = NULL;
for (u32 i = 0; i < (sizeof(cmd_list)/sizeof(Gm9ScriptCmd)); i++) { for (u32 i = 0; i < (sizeof(cmd_list)/sizeof(Gm9ScriptCmd)); i++) {
if (strncmp(cmd_list[i].cmd, cmd, len) == 0) { if (strncmp(cmd_list[i].cmd, cmd, len) == 0) {

View File

@ -672,7 +672,7 @@ bool BuildVGameFirmDir(void) {
} }
bool BuildVGameTadDir(void) { bool BuildVGameTadDir(void) {
const char* name_type[] = { NAME_TAD_TYPES }; static const char* name_type[] = { NAME_TAD_TYPES };
VirtualFile* templates = templates_tad; VirtualFile* templates = templates_tad;
u32 content_offset = 0; u32 content_offset = 0;
u32 n = 0; u32 n = 0;

View File

@ -21,11 +21,11 @@
#define HAS_OTP_KEY (HAS_BOOT9 || ((LoadKeyFromFile(NULL, 0x11, 'N', "OTP") == 0) && (LoadKeyFromFile(NULL , 0x11, 'I', "OTP") == 0))) #define HAS_OTP_KEY (HAS_BOOT9 || ((LoadKeyFromFile(NULL, 0x11, 'N', "OTP") == 0) && (LoadKeyFromFile(NULL , 0x11, 'I', "OTP") == 0)))
// see: https://www.youtube.com/watch?v=wogNzUypLuI // see: https://www.youtube.com/watch?v=wogNzUypLuI
u8 boot9_sha256[0x20] = { static const u8 boot9_sha256[0x20] = {
0x2F, 0x88, 0x74, 0x4F, 0xEE, 0xD7, 0x17, 0x85, 0x63, 0x86, 0x40, 0x0A, 0x44, 0xBB, 0xA4, 0xB9, 0x2F, 0x88, 0x74, 0x4F, 0xEE, 0xD7, 0x17, 0x85, 0x63, 0x86, 0x40, 0x0A, 0x44, 0xBB, 0xA4, 0xB9,
0xCA, 0x62, 0xE7, 0x6A, 0x32, 0xC7, 0x15, 0xD4, 0xF3, 0x09, 0xC3, 0x99, 0xBF, 0x28, 0x16, 0x6F 0xCA, 0x62, 0xE7, 0x6A, 0x32, 0xC7, 0x15, 0xD4, 0xF3, 0x09, 0xC3, 0x99, 0xBF, 0x28, 0x16, 0x6F
}; };
u8 boot11_sha256[0x20] = { static const u8 boot11_sha256[0x20] = {
0x74, 0xDA, 0xAC, 0xE1, 0xF8, 0x06, 0x7B, 0x66, 0xCC, 0x81, 0xFC, 0x30, 0x7A, 0x3F, 0xDB, 0x50, 0x74, 0xDA, 0xAC, 0xE1, 0xF8, 0x06, 0x7B, 0x66, 0xCC, 0x81, 0xFC, 0x30, 0x7A, 0x3F, 0xDB, 0x50,
0x9C, 0xBE, 0xDC, 0x32, 0xF9, 0x03, 0xAE, 0xBE, 0x90, 0x61, 0x44, 0xDE, 0xA7, 0xA0, 0x75, 0x12 0x9C, 0xBE, 0xDC, 0x32, 0xF9, 0x03, 0xAE, 0xBE, 0x90, 0x61, 0x44, 0xDE, 0xA7, 0xA0, 0x75, 0x12
}; };

View File

@ -29,9 +29,6 @@
#define abs(x) \ #define abs(x) \
(((x) >= 0) ? (x) : -(x)) (((x) >= 0) ? (x) : -(x))
#define int_sign(x) \
(((x) > 0) - ((x) < 0))
#define clamp(x, min, max) \ #define clamp(x, min, max) \
((x) < (max) ? ((x) > (min) ? (x) : (min)) : (max)) ((x) < (max) ? ((x) > (min) ? (x) : (min)) : (max))