diff --git a/arm11/source/hw/codec.h b/arm11/source/hw/codec.h index f1d75f6..923b313 100755 --- a/arm11/source/hw/codec.h +++ b/arm11/source/hw/codec.h @@ -23,7 +23,7 @@ typedef struct { s16 cpad_x, cpad_y; - s16 ts_x, ts_y; + u16 ts_x, ts_y; } CODEC_Input; void CODEC_Init(void); diff --git a/arm11/source/hw/hid.c b/arm11/source/hw/hid.c index dd2140d..ce535df 100755 --- a/arm11/source/hw/hid.c +++ b/arm11/source/hw/hid.c @@ -30,24 +30,16 @@ static u32 HID_ConvertCPAD(s16 cpad_x, s16 cpad_y) { u32 ret = 0; - switch(int_sign(cpad_x)) { - default: - break; - case 1: - ret |= BUTTON_RIGHT; - break; - case -1: - ret |= BUTTON_LEFT; + if (cpad_x > 0) { + ret |= BUTTON_RIGHT; + } else if (cpad_x < 0) { + ret |= BUTTON_LEFT; } - switch(int_sign(cpad_y)) { - default: - break; - case 1: - ret |= BUTTON_UP; - break; - case -1: - ret |= BUTTON_DOWN; + if (cpad_y > 0) { + ret |= BUTTON_UP; + } else if (cpad_y < 0) { + ret |= BUTTON_DOWN; } return ret; diff --git a/arm11/source/hw/mcu.c b/arm11/source/hw/mcu.c index e20c500..af57dab 100755 --- a/arm11/source/hw/mcu.c +++ b/arm11/source/hw/mcu.c @@ -67,7 +67,7 @@ typedef struct { } PACKED_STRUCT MCU_NotificationLED; 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) { @@ -189,6 +189,8 @@ void MCU_Init(void) { u32 clrpend, mask = 0; + shell_state = SHELL_OPEN; + /* set register mask and clear any pending registers */ MCU_WriteRegBuf(REG_INT_EN, (const u8*)&mask, sizeof(mask)); MCU_ReadRegBuf(REG_INT_MASK, (u8*)&clrpend, sizeof(clrpend)); diff --git a/arm11/source/main.c b/arm11/source/main.c index c4dac2f..db23ada 100644 --- a/arm11/source/main.c +++ b/arm11/source/main.c @@ -39,8 +39,8 @@ static const u8 brightness_lvls[] = { 0x4D, 0x56, 0x60, 0x6B, 0x79, 0x8C, 0xA7, 0xD2 }; -static int prev_bright_lvl = -1; -static bool auto_brightness = true; +static int prev_bright_lvl; +static bool auto_brightness; #endif static SystemSHMEM __attribute__((section(".shared"))) SharedMemoryState; @@ -180,11 +180,11 @@ void __attribute__((noreturn)) MainLoop(void) { #ifdef FIXED_BRIGHTNESS LCD_SetBrightness(FIXED_BRIGHTNESS); + #else + prev_bright_lvl = -1; + auto_brightness = true; #endif - // clear up the shared memory section - memset(&SharedMemoryState, 0, sizeof(SharedMemoryState)); - // configure interrupts 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); diff --git a/arm9/source/crypto/crc16.c b/arm9/source/crypto/crc16.c index 888414c..3b1ac74 100644 --- a/arm9/source/crypto/crc16.c +++ b/arm9/source/crypto/crc16.c @@ -7,7 +7,7 @@ // see: https://github.com/TASVideos/desmume/blob/master/desmume/src/bios.cpp#L1070tions u16 crc16_quick(const void* src, u32 len) { - const u16 tabval[] = { CRC16_TABVAL }; + static const u16 tabval[] = { CRC16_TABVAL }; u16* data = (u16*) src; u16 crc = 0xFFFF; diff --git a/arm9/source/crypto/keydb.c b/arm9/source/crypto/keydb.c index d654b8e..d55f7b4 100644 --- a/arm9/source/crypto/keydb.c +++ b/arm9/source/crypto/keydb.c @@ -232,7 +232,7 @@ u32 CheckRecommendedKeyDb(const char* path) { // SHA-256 of the recommended aeskeydb.bin file // 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, 0x2B, 0x24, 0x00, 0x15, 0xBE, 0x9B, 0xFC, 0xDE, 0x7F, 0xED, 0x95, 0x1D, 0xD5, 0xAB, 0x2D, 0xCB }; diff --git a/arm9/source/filesys/filetype.c b/arm9/source/filesys/filetype.c index 5db4daa..f88b197 100644 --- a/arm9/source/filesys/filetype.c +++ b/arm9/source/filesys/filetype.c @@ -11,13 +11,13 @@ #include "ui.h" // only for font file detection u64 IdentifyFileType(const char* path) { - const u8 romfs_magic[] = { ROMFS_MAGIC }; - const u8 diff_magic[] = { DIFF_MAGIC }; - const u8 disa_magic[] = { DISA_MAGIC }; - const u8 tickdb_magic[] = { TICKDB_MAGIC }; - const u8 smdh_magic[] = { SMDH_MAGIC }; - const u8 threedsx_magic[] = { THREEDSX_EXT_MAGIC }; - const u8 png_magic[] = { PNG_MAGIC }; + static const u8 romfs_magic[] = { ROMFS_MAGIC }; + static const u8 diff_magic[] = { DIFF_MAGIC }; + static const u8 disa_magic[] = { DISA_MAGIC }; + static const u8 tickdb_magic[] = { TICKDB_MAGIC }; + static const u8 smdh_magic[] = { SMDH_MAGIC }; + static const u8 threedsx_magic[] = { THREEDSX_EXT_MAGIC }; + static const u8 png_magic[] = { PNG_MAGIC }; if (!path) return 0; // safety u8 ALIGN(32) header[0x2C0]; // minimum required size diff --git a/arm9/source/filesys/fsperm.c b/arm9/source/filesys/fsperm.c index 9a9af05..2a68bea 100644 --- a/arm9/source/filesys/fsperm.c +++ b/arm9/source/filesys/fsperm.c @@ -46,7 +46,7 @@ bool CheckWritePermissions(const char* path) { // check drive type, get permission type 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; if (drvtype & (DRV_CTRNAND|DRV_VIRTUAL)) { // check for paths const char* path_lvl3[] = { PATH_SYS_LVL3 }; @@ -65,7 +65,7 @@ bool CheckWritePermissions(const char* path) { perm = perms[lvl]; snprintf(area_name, 16, "SysNAND (lvl%lu)", lvl); } 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; if (drvtype & DRV_VIRTUAL) { // check for paths const char* path_lvl1[] = { PATH_EMU_LVL1 }; @@ -124,7 +124,7 @@ bool CheckWritePermissions(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++) { const char* path_cmp = path_chk[i]; u32 p = 0; diff --git a/arm9/source/filesys/sddata.c b/arm9/source/filesys/sddata.c index 0bdef29..efaa6f6 100644 --- a/arm9/source/filesys/sddata.c +++ b/arm9/source/filesys/sddata.c @@ -15,10 +15,10 @@ typedef struct { static FilCryptInfo filcrypt[NUM_FILCRYPTINFO] = { 0 }; -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_drv[NUM_ALIAS_DRV]; // 1 char ASCII drive number of the alias drive / 0x00 if unused +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 num = -1; diff --git a/arm9/source/game/cia.c b/arm9/source/game/cia.c index 62b3b02..e421089 100644 --- a/arm9/source/game/cia.c +++ b/arm9/source/game/cia.c @@ -50,11 +50,11 @@ u32 FixCiaHeaderForTmd(CiaHeader* header, TitleMetaData* tmd) { } 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, 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, 0x18, 0x83, 0xAF, 0xE0, 0xF4, 0xE5, 0x62, 0xBA, 0x69, 0xEE, 0x72, 0x2A, 0xC2, 0x4E, 0x95, 0xB3 }; diff --git a/arm9/source/game/disadiff.c b/arm9/source/game/disadiff.c index a31b6a0..f3814f5 100644 --- a/arm9/source/game/disadiff.c +++ b/arm9/source/game/disadiff.c @@ -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) { - const u8 disa_magic[] = { DISA_MAGIC }; - const u8 diff_magic[] = { DIFF_MAGIC }; - const u8 ivfc_magic[] = { IVFC_MAGIC }; - const u8 dpfs_magic[] = { DPFS_MAGIC }; - const u8 difi_magic[] = { DIFI_MAGIC }; + static const u8 disa_magic[] = { DISA_MAGIC }; + static const u8 diff_magic[] = { DIFF_MAGIC }; + static const u8 ivfc_magic[] = { IVFC_MAGIC }; + static const u8 dpfs_magic[] = { DPFS_MAGIC }; + static const u8 difi_magic[] = { DIFI_MAGIC }; // reset reader info memset(info, 0x00, sizeof(DisaDiffRWInfo)); diff --git a/arm9/source/game/gba.c b/arm9/source/game/gba.c index 5a86969..f967f9e 100644 --- a/arm9/source/game/gba.c +++ b/arm9/source/game/gba.c @@ -7,7 +7,7 @@ 0x84, 0x9D, 0xA0, 0xD5, 0x6F, 0x5A, 0x34, 0xC4, 0x81, 0x06, 0x0C, 0x9F, 0xF2, 0xFA, 0xD8, 0x18 u32 ValidateAgbSaveHeader(AgbSaveHeader* header) { - u8 magic[] = { AGBSAVE_MAGIC }; + static u8 magic[] = { AGBSAVE_MAGIC }; // basic checks if ((memcmp(header->magic, magic, sizeof(magic)) != 0) || @@ -28,7 +28,7 @@ u32 ValidateAgbSaveHeader(AgbSaveHeader* header) { // http://problemkaputt.de/gbatek.htm#gbacartridgeheader 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))); // check fixed value diff --git a/arm9/source/game/ncsd.c b/arm9/source/game/ncsd.c index 6bedfd2..3fb5213 100644 --- a/arm9/source/game/ncsd.c +++ b/arm9/source/game/ncsd.c @@ -2,7 +2,7 @@ #include "ncch.h" u32 ValidateNcsdHeader(NcsdHeader* header) { - u8 zeroes[16] = { 0 }; + static const u8 zeroes[16] = { 0 }; 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 return 1; diff --git a/arm9/source/game/romfs.c b/arm9/source/game/romfs.c index 3ae41f9..4273e22 100644 --- a/arm9/source/game/romfs.c +++ b/arm9/source/game/romfs.c @@ -19,7 +19,7 @@ u64 GetRomFsLvOffset(RomFsIvfcHeader* ivfc, u32 lvl) { // validate IVFC header by checking offsets and hash sizes u32 ValidateRomFsHeader(RomFsIvfcHeader* ivfc, u32 max_size) { - u8 magic[] = { ROMFS_MAGIC }; + static const u8 magic[] = { ROMFS_MAGIC }; // check magic number if (memcmp(magic, ivfc->magic, sizeof(magic)) != 0) diff --git a/arm9/source/game/smdh.c b/arm9/source/game/smdh.c index 2720131..2a8c053 100644 --- a/arm9/source/game/smdh.c +++ b/arm9/source/game/smdh.c @@ -9,7 +9,7 @@ 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) { - const u32 lut[8*8] = { SMDH_LUT }; + static const u32 lut[8*8] = { SMDH_LUT }; u16* pix565 = (u16*) smdh_icon; for (u32 y = 0; y < h; y += 8) { for (u32 x = 0; x < w; x += 8) { diff --git a/arm9/source/game/ticket.c b/arm9/source/game/ticket.c index f8ab0ec..bc617e4 100644 --- a/arm9/source/game/ticket.c +++ b/arm9/source/game/ticket.c @@ -6,7 +6,7 @@ #include "ff.h" 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) || ((strncmp((char*) ticket->issuer, TICKET_ISSUER, 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) { - const u8 sig_type[4] = { TICKET_SIG_TYPE }; // RSA_2048 SHA256 - const u8 ticket_cnt_index[] = { // whatever this is + static const u8 sig_type[4] = { TICKET_SIG_TYPE }; // RSA_2048 SHA256 + 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, 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 @@ -72,11 +72,11 @@ u32 GetTicketSize(const Ticket* ticket) { } 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, 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, 0xC6, 0x4B, 0xD4, 0x8F, 0xDF, 0x13, 0x21, 0x3D, 0xFC, 0x72, 0xFC, 0x8D, 0x9F, 0xDD, 0x01, 0x0E }; diff --git a/arm9/source/game/tmd.c b/arm9/source/game/tmd.c index 2eef622..d98f4fa 100644 --- a/arm9/source/game/tmd.c +++ b/arm9/source/game/tmd.c @@ -6,7 +6,7 @@ #include "ff.h" 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) || ((strncmp((char*) tmd->issuer, TMD_ISSUER, 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) { - const u8 sig_type[4] = { TMD_SIG_TYPE }; + static const u8 sig_type[4] = { TMD_SIG_TYPE }; // safety check: number of contents if (n_contents > TMD_MAX_CONTENTS) return 1; // potential incompatibility here (!) // 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) { - 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, 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, 0xC2, 0xE9, 0xCA, 0x93, 0x94, 0xF4, 0x29, 0xA0, 0x38, 0x54, 0x75, 0xFF, 0xAB, 0x6E, 0x8E, 0x71 }; diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index ccce5d2..3ab341f 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -417,10 +417,10 @@ void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) { } u32 SdFormatMenu(const char* slabel) { - 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 u32 cluster_size_table[5] = { 0x0, 0x0, 0x4000, 0x8000, 0x10000 }; + 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..." }; - 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); 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; @@ -467,13 +467,13 @@ u32 SdFormatMenu(const char* slabel) { u32 emunand_offset = 1; u32 n_emunands = 1; 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:"); if (user_select > 3) return 0; emunand_offset = (user_select == 3) ? 0 : 1; if (user_select == 1) n_emunands = 4; } 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:"); if (user_select > 2) return 0; 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 memcpy(BOT_SCREEN, bottom_cpy, SCREEN_SIZE_BOT); } 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:", (unsigned int) offset); if (user_select == 1) { // -> goto offset @@ -2329,7 +2329,7 @@ u32 GodMode(int entrypoint) { } else { // one level up u32 user_select = 1; 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]; TruncateString(pathstr, curr_entry->path, 32, 8); 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)) { ShowPrompt(false, "Not allowed in gamecart drive"); } 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]; u32 flags = 0; u32 user_select; @@ -2542,7 +2542,7 @@ u32 GodMode(int entrypoint) { } } } 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."); if (type) { const char* typestr = (type == 1) ? "folder" : (type == 2) ? "file" : NULL; diff --git a/arm9/source/nand/nand.c b/arm9/source/nand/nand.c index 99c6634..8748a57 100644 --- a/arm9/source/nand/nand.c +++ b/arm9/source/nand/nand.c @@ -386,7 +386,7 @@ u32 ValidateSecretSector(u8* sector) // see: https://github.com/d0k3/GodMode9/blob/master/source/game/ncsd.c#L4 u32 ValidateNandNcsdHeader(NandNcsdHeader* header) { - u8 zeroes[16] = { 0 }; + static const u8 zeroes[16] = { 0 }; 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 return 1; diff --git a/arm9/source/utils/ctrtransfer.c b/arm9/source/utils/ctrtransfer.c index 9f4c6e3..8ee054e 100644 --- a/arm9/source/utils/ctrtransfer.c +++ b/arm9/source/utils/ctrtransfer.c @@ -97,7 +97,7 @@ u32 TransferCtrNandImage(const char* path_img, const char* drv) { } // 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_from[32]; char path_dbs[32]; diff --git a/arm9/source/utils/nandcmac.c b/arm9/source/utils/nandcmac.c index 346f28b..2c9433f 100644 --- a/arm9/source/utils/nandcmac.c +++ b/arm9/source/utils/nandcmac.c @@ -68,7 +68,7 @@ u32 SetupSlot0x30(char drv) { } u32 LocateAgbSaveSdBottomSlot(const char* path, AgbSaveHeader* agbsave) { - const u32 save_sizes[] = { + static const u32 save_sizes[] = { GBASAVE_EEPROM_512, GBASAVE_EEPROM_8K, 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) return 1; - const u32 cmac_keyslot[] = { CMAC_KEYSLOT }; + static const u32 cmac_keyslot[] = { CMAC_KEYSLOT }; u8 hashdata[0x200] __attribute__((aligned(4))); u32 keyslot = cmac_keyslot[cmac_type]; u32 hashsize = 0; diff --git a/arm9/source/utils/nandutil.c b/arm9/source/utils/nandutil.c index 7a7b0c9..ed28070 100644 --- a/arm9/source/utils/nandutil.c +++ b/arm9/source/utils/nandutil.c @@ -607,7 +607,7 @@ u32 SafeInstallFirm(const char* path, u32 slots) { } 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))); char pathstr[32 + 1]; // truncated path string diff --git a/arm9/source/utils/scripting.c b/arm9/source/utils/scripting.c index 423db9b..8c30fcc 100644 --- a/arm9/source/utils/scripting.c +++ b/arm9/source/utils/scripting.c @@ -139,7 +139,7 @@ typedef struct { char content[_VAR_CNT_LEN]; } Gm9ScriptVar; -Gm9ScriptCmd cmd_list[] = { +static const Gm9ScriptCmd cmd_list[] = { { CMD_ID_NONE , "#" , 0, 0 }, // dummy entry { 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 @@ -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) { - Gm9ScriptCmd* cmd_entry = NULL; + const Gm9ScriptCmd* cmd_entry = NULL; for (u32 i = 0; i < (sizeof(cmd_list)/sizeof(Gm9ScriptCmd)); i++) { if (strncmp(cmd_list[i].cmd, cmd, len) == 0) { diff --git a/arm9/source/virtual/vgame.c b/arm9/source/virtual/vgame.c index 544e9a5..798e99e 100644 --- a/arm9/source/virtual/vgame.c +++ b/arm9/source/virtual/vgame.c @@ -672,7 +672,7 @@ bool BuildVGameFirmDir(void) { } bool BuildVGameTadDir(void) { - const char* name_type[] = { NAME_TAD_TYPES }; + static const char* name_type[] = { NAME_TAD_TYPES }; VirtualFile* templates = templates_tad; u32 content_offset = 0; u32 n = 0; diff --git a/arm9/source/virtual/vmem.c b/arm9/source/virtual/vmem.c index c3935cb..b257c6f 100644 --- a/arm9/source/virtual/vmem.c +++ b/arm9/source/virtual/vmem.c @@ -21,11 +21,11 @@ #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 -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, 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, 0x9C, 0xBE, 0xDC, 0x32, 0xF9, 0x03, 0xAE, 0xBE, 0x90, 0x61, 0x44, 0xDE, 0xA7, 0xA0, 0x75, 0x12 }; diff --git a/common/common.h b/common/common.h index b0e456b..66fd697 100755 --- a/common/common.h +++ b/common/common.h @@ -29,9 +29,6 @@ #define abs(x) \ (((x) >= 0) ? (x) : -(x)) -#define int_sign(x) \ - (((x) > 0) - ((x) < 0)) - #define clamp(x, min, max) \ ((x) < (max) ? ((x) > (min) ? (x) : (min)) : (max))