From 68f30102b3e72550f00ee9ddc6e2225e9ca60a53 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Mon, 23 May 2016 19:59:13 -0400 Subject: [PATCH] Reformat --- Makefile | 2 +- external/loader/source/patcher.c | 4 +- host/compile_header.c | 133 +++++++++++++++++-------------- source/fatfs/ff.c | 71 +++++++---------- source/fatfs/ff.h | 2 +- source/fatfs/sdmmc.c | 34 ++++---- 6 files changed, 121 insertions(+), 125 deletions(-) diff --git a/Makefile b/Makefile index 66e556c..f22430f 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ a9lh: $(dir_out)/arm9loaderhax.bin .PHONY: reformat reformat: - clang-format -i $(dir_source)/*.{c,h} $(dir_source)/*/*.{c,h} external/loader/source/*.{c,h} external/loader/source/*/*.{c,h} + clang-format -i $(dir_source)/*.{c,h} $(dir_source)/*/*.{c,h} external/loader/source/*.{c,h} external/loader/source/*/*.{c,h} host/*.c host/langemu.conf: echo "Generating langemu.conf - may take a bit" diff --git a/external/loader/source/patcher.c b/external/loader/source/patcher.c index c38e166..6000e49 100644 --- a/external/loader/source/patcher.c +++ b/external/loader/source/patcher.c @@ -367,8 +367,8 @@ patchCfgGetLanguage(u8* code, u32 size, u8 languageId, 0xE3A00000 | languageId; // mov r0, sp // => mov r0, =languageId *(u32*)instr = 0xE5CD0000; // bl - // CFGU_GetConfigInfoBlk2 => - // strb r0, [sp] + // CFGU_GetConfigInfoBlk2 => + // strb r0, [sp] *((u32*)instr + 1) = 0xE3B00000; // (1 or 2 instructions) => movs // r0, 0 (result code) diff --git a/host/compile_header.c b/host/compile_header.c index 8ec4454..f912dda 100644 --- a/host/compile_header.c +++ b/host/compile_header.c @@ -6,91 +6,100 @@ #include "../source/patch_format.h" -void read_file_u64(char* name, uint64_t* to) { - FILE* hdl = fopen(name, "rb"); - fscanf(hdl, "%llu", to); - fclose(hdl); +void +read_file_u64(char* name, uint64_t* to) +{ + FILE* hdl = fopen(name, "rb"); + fscanf(hdl, "%llu", to); + fclose(hdl); } - -void read_file_u32(char* name, uint32_t* to) { - FILE* hdl = fopen(name, "rb"); - fscanf(hdl, "%u", to); - fclose(hdl); +void +read_file_u32(char* name, uint32_t* to) +{ + FILE* hdl = fopen(name, "rb"); + fscanf(hdl, "%u", to); + fclose(hdl); } -void read_str(char* name, char* to, size_t len) { - FILE* hdl = fopen(name, "rb"); - int r = fread(to, 1, len-1, hdl); - fclose(hdl); - - for(int i=len-1; i >= 0; i--) { - if (to[i] == '\n') { - to[i] = 0; - break; - } - } +void +read_str(char* name, char* to, size_t len) +{ + FILE* hdl = fopen(name, "rb"); + int r = fread(to, 1, len - 1, hdl); + fclose(hdl); + + for (int i = len - 1; i >= 0; i--) { + if (to[i] == '\n') { + to[i] = 0; + break; + } + } } uint32_t size = 0; -uint8_t* read_file_mem(char* name) { - FILE* hdl = fopen(name, "rb"); +uint8_t* +read_file_mem(char* name) +{ + FILE* hdl = fopen(name, "rb"); - fseek(hdl, 0, SEEK_END); - size = ftell(hdl); - rewind(hdl); + fseek(hdl, 0, SEEK_END); + size = ftell(hdl); + rewind(hdl); - uint8_t* mem = malloc(size); - memset(mem, 0, size); + uint8_t* mem = malloc(size); + memset(mem, 0, size); - int r = fread(mem, 1, size, hdl); - fclose(hdl); + int r = fread(mem, 1, size, hdl); + fclose(hdl); - return mem; + return mem; } -int main(int c, char** v) { - struct system_patch patch; - int at = 0; +int +main(int c, char** v) +{ + struct system_patch patch; + int at = 0; - memset(&patch, 0, sizeof(patch)); + memset(&patch, 0, sizeof(patch)); - // Set magic. - patch.magic[0] = 'A'; - patch.magic[1] = 'I'; - patch.magic[2] = 'D'; - patch.magic[3] = 'A'; + // Set magic. + patch.magic[0] = 'A'; + patch.magic[1] = 'I'; + patch.magic[2] = 'D'; + patch.magic[3] = 'A'; - read_file_u32("meta/patch_version", & patch.patch_ver); - read_file_u32("meta/cfw_version", & patch.load_ver); + read_file_u32("meta/patch_version", &patch.patch_ver); + read_file_u32("meta/cfw_version", &patch.load_ver); - read_file_u64("meta/uuid", & patch.patch_id); - read_file_u64("meta/title", & patch.tid); + read_file_u64("meta/uuid", &patch.patch_id); + read_file_u64("meta/title", &patch.tid); - read_str("meta/name", patch.name, sizeof(patch.name)); - read_str("meta/desc", patch.desc, sizeof(patch.desc)); + read_str("meta/name", patch.name, sizeof(patch.name)); + read_str("meta/desc", patch.desc, sizeof(patch.desc)); - uint8_t* code = read_file_mem("out/patch.bin"); + uint8_t* code = read_file_mem("out/patch.bin"); - patch.patch_size = size; + patch.patch_size = size; - FILE* out = fopen("out/patch.vco", "wb"); - fwrite(&patch, 1, sizeof(patch), out); - fwrite(code, 1, patch.patch_size, out); - fclose(out); + FILE* out = fopen("out/patch.vco", "wb"); + fwrite(&patch, 1, sizeof(patch), out); + fwrite(code, 1, patch.patch_size, out); + fclose(out); - free(code); + free(code); - printf("Ver: %u\n" - "CFW: %u\n" - "UUID: %llu\n" - "TID: %llu\n" - "Name: %s\n" - "Desc: %s\n" - "Size: %u\n", - patch.patch_ver, patch.load_ver, patch.patch_id, - patch.tid, patch.name, patch.desc, patch.patch_size); + printf("Ver: %u\n" + "CFW: %u\n" + "UUID: %llu\n" + "TID: %llu\n" + "Name: %s\n" + "Desc: %s\n" + "Size: %u\n", + patch.patch_ver, patch.load_ver, patch.patch_id, patch.tid, + patch.name, patch.desc, patch.patch_size); - return 0; + return 0; } diff --git a/source/fatfs/ff.c b/source/fatfs/ff.c index ed60fee..80c112c 100644 --- a/source/fatfs/ff.c +++ b/source/fatfs/ff.c @@ -852,9 +852,8 @@ chk_lock( /* Check if the file can be accessed */ for (i = be = 0; i < _FS_LOCK; i++) { if (Files[i].fs) { /* Existing entry */ if (Files[i].fs == - dp - ->fs && /* Check if the object matched with an open - object */ + dp->fs && /* Check if the object matched with an open + object */ Files[i].clu == dp->sclust && Files[i].idx == dp->index) break; @@ -885,10 +884,9 @@ static int enq_lock(void) /* Check if an entry is available for a new object */ static UINT inc_lock(/* Increment object open counter and returns its index (0:Internal error) */ - DIR* - dp, /* Directory object pointing the file to register or increment - */ - int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */ + DIR* dp, /* Directory object pointing the file to register or increment + */ + int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */ ) { UINT i; @@ -1371,9 +1369,8 @@ dir_sdi(DIR* dp, /* Pointer to directory object */ if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */ if (clst < 2 || - clst >= - dp->fs->n_fatent) /* Reached to end of table or internal - error */ + clst >= dp->fs->n_fatent) /* Reached to end of table or internal + error */ return FR_INT_ERR; idx -= ic; } @@ -2076,9 +2073,8 @@ get_fileinfo( /* No return code */ break; } /* No LFN if it could not be converted */ if (_DF1S && - w >= - 0x100) /* Put 1st byte if it is a DBC (always false on - SBCS cfg) */ + w >= 0x100) /* Put 1st byte if it is a DBC (always false on + SBCS cfg) */ p[i++] = (TCHAR)(w >> 8); #endif if (i >= fno->lfsize - 1) { @@ -2203,9 +2199,8 @@ create_name(DIR* dp, /* Pointer to the directory object */ return FR_INVALID_NAME; #if !_LFN_UNICODE w &= 0xFF; - if (IsDBCS1( - w)) { /* Check if it is a DBC 1st byte (always false on SBCS - cfg) */ + if (IsDBCS1(w)) { /* Check if it is a DBC 1st byte (always false on SBCS + cfg) */ b = (BYTE)p[si++]; /* Get 2nd byte */ w = (w << 8) + b; /* Create a DBC */ if (!IsDBCS2(b)) @@ -2319,9 +2314,8 @@ create_name(DIR* dp, /* Pointer to the directory object */ } if (dp->fn[0] == DDEM) - dp - ->fn[0] = RDDEM; /* If the first character collides with deleted - mark, replace it with RDDEM */ + dp->fn[0] = RDDEM; /* If the first character collides with deleted + mark, replace it with RDDEM */ if (ni == 8) b <<= 2; @@ -2392,9 +2386,8 @@ create_name(DIR* dp, /* Pointer to the directory object */ #endif #endif } - if (IsDBCS1( - c)) { /* Check if it is a DBC 1st byte (always false on SBCS - cfg) */ + if (IsDBCS1(c)) { /* Check if it is a DBC 1st byte (always false on SBCS + cfg) */ d = (BYTE)p[si++]; /* Get 2nd byte */ if (!IsDBCS2(d) || i >= ni - 1) /* Reject invalid DBC */ return FR_INVALID_NAME; @@ -2536,9 +2529,8 @@ get_ldnumber(/* Returns logical drive number (-1:invalid drive) */ tp = *path; i = *tp++ - '0'; if (i < 10 && tp == tt) { /* Is there a numeric drive id? */ - if (i < - _VOLUMES) { /* If a drive id is found, get the value and - strip it */ + if (i < _VOLUMES) { /* If a drive id is found, get the value and + strip it */ vol = (int)i; *path = ++tt; } @@ -2559,10 +2551,9 @@ get_ldnumber(/* Returns logical drive number (-1:invalid drive) */ } while ( (c || tp != tt) && ++i < - _VOLUMES); /* Repeat for each id until pattern match */ - if (i < - _VOLUMES) { /* If a drive id is found, get the value and - strip it */ + _VOLUMES); /* Repeat for each id until pattern match */ + if (i < _VOLUMES) { /* If a drive id is found, get the value and + strip it */ vol = (int)i; *path = tt; } @@ -2587,9 +2578,8 @@ static BYTE check_fs(/* 0:FAT boor sector, 1:Valid boor sector but not FAT, 2:Not a boot sector, 3:Disk error */ FATFS* fs, /* File system object */ - DWORD - sect /* Sector# (lba) to check if it is an FAT boot record or not - */ + DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not + */ ) { fs->wflag = 0; @@ -3446,10 +3436,9 @@ f_getcwd(TCHAR* buff, /* Pointer to the directory path */ res = find_volume(&dj.fs, (const TCHAR**)&buff, 0); /* Get current volume */ if (res == FR_OK) { INIT_BUF(dj); - i = len; /* Bottom of buffer (directory stack base) */ - dj.sclust = - dj.fs->cdir; /* Start to follow upper directory from current - directory */ + i = len; /* Bottom of buffer (directory stack base) */ + dj.sclust = dj.fs->cdir; /* Start to follow upper directory from current + directory */ while ((ccl = dj.sclust) != 0) { /* Repeat while current directory is a sub-directory */ res = dir_sdi(&dj, 1); /* Get parent directory */ @@ -3612,9 +3601,8 @@ f_lseek(FIL* fp, /* Pointer to the file object */ /* Normal Seek */ { - if (ofs > - fp->fsize /* In read-only mode, clip offset with the file size - */ + if (ofs > fp->fsize /* In read-only mode, clip offset with the file size + */ #if !_FS_READONLY && !(fp->flag & FA_WRITE) #endif @@ -3661,9 +3649,8 @@ f_lseek(FIL* fp, /* Pointer to the file object */ } } else #endif - clst = - get_fat(fp->fs, clst); /* Follow cluster chain if - not in write mode */ + clst = get_fat(fp->fs, clst); /* Follow cluster chain if + not in write mode */ if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); if (clst <= 1 || clst >= fp->fs->n_fatent) diff --git a/source/fatfs/ff.h b/source/fatfs/ff.h index 31960b4..2fe5e6a 100644 --- a/source/fatfs/ff.h +++ b/source/fatfs/ff.h @@ -117,7 +117,7 @@ typedef struct DWORD fptr; /* File read/write pointer (Zeroed on file open) */ DWORD fsize; /* File size */ DWORD - sclust; /* File start cluster (0:no cluster chain, always 0 when fsize + sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */ DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */ DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */ diff --git a/source/fatfs/sdmmc.c b/source/fatfs/sdmmc.c index 79d5cbe..d249a57 100644 --- a/source/fatfs/sdmmc.c +++ b/source/fatfs/sdmmc.c @@ -394,37 +394,37 @@ InitSD() #ifdef DATA32_SUPPORT *(volatile uint16_t*)0x10006100 |= 0x402u; // SDDATACTL32 #else - *(volatile uint16_t*)0x10006100 |= 0x402u; // SDDATACTL32 + *(volatile uint16_t*)0x10006100 |= 0x402u; // SDDATACTL32 #endif *(volatile uint16_t*)0x100060D8 = (*(volatile uint16_t*)0x100060D8 & 0xFFDD) | 2; #ifdef DATA32_SUPPORT *(volatile uint16_t*)0x10006100 &= 0xFFFFu; // SDDATACTL32 *(volatile uint16_t*)0x100060D8 &= 0xFFDFu; // SDDATACTL - *(volatile uint16_t*)0x10006104 = 512; // SDBLKLEN32 + *(volatile uint16_t*)0x10006104 = 512; // SDBLKLEN32 #else *(volatile uint16_t*)0x10006100 &= 0xFFFDu; // SDDATACTL32 *(volatile uint16_t*)0x100060D8 &= 0xFFDDu; // SDDATACTL - *(volatile uint16_t*)0x10006104 = 0; // SDBLKLEN32 + *(volatile uint16_t*)0x10006104 = 0; // SDBLKLEN32 #endif - *(volatile uint16_t*)0x10006108 = 1; // SDBLKCOUNT32 - *(volatile uint16_t*)0x100060E0 &= 0xFFFEu; // SDRESET - *(volatile uint16_t*)0x100060E0 |= 1u; // SDRESET - *(volatile uint16_t*)0x10006020 |= TMIO_MASK_ALL; // SDIR_MASK0 + *(volatile uint16_t*)0x10006108 = 1; // SDBLKCOUNT32 + *(volatile uint16_t*)0x100060E0 &= 0xFFFEu; // SDRESET + *(volatile uint16_t*)0x100060E0 |= 1u; // SDRESET + *(volatile uint16_t*)0x10006020 |= TMIO_MASK_ALL; // SDIR_MASK0 *(volatile uint16_t*)0x10006022 |= TMIO_MASK_ALL >> 16; // SDIR_MASK1 - *(volatile uint16_t*)0x100060FC |= 0xDBu; // SDCTL_RESERVED7 - *(volatile uint16_t*)0x100060FE |= 0xDBu; // SDCTL_RESERVED8 - *(volatile uint16_t*)0x10006002 &= 0xFFFCu; // SDPORTSEL + *(volatile uint16_t*)0x100060FC |= 0xDBu; // SDCTL_RESERVED7 + *(volatile uint16_t*)0x100060FE |= 0xDBu; // SDCTL_RESERVED8 + *(volatile uint16_t*)0x10006002 &= 0xFFFCu; // SDPORTSEL #ifdef DATA32_SUPPORT *(volatile uint16_t*)0x10006024 = 0x20; *(volatile uint16_t*)0x10006028 = 0x40EE; #else - *(volatile uint16_t*)0x10006024 = 0x40; // Nintendo sets this to 0x20 - *(volatile uint16_t*)0x10006028 = 0x40EB; // Nintendo sets this to 0x40EE + *(volatile uint16_t*)0x10006024 = 0x40; // Nintendo sets this to 0x20 + *(volatile uint16_t*)0x10006028 = 0x40EB; // Nintendo sets this to 0x40EE #endif *(volatile uint16_t*)0x10006002 &= 0xFFFCu; ////SDPORTSEL - *(volatile uint16_t*)0x10006026 = 512; // SDBLKLEN - *(volatile uint16_t*)0x10006008 = 0; // SDSTOP + *(volatile uint16_t*)0x10006026 = 512; // SDBLKLEN + *(volatile uint16_t*)0x10006008 = 0; // SDSTOP inittarget(&handelSD); } @@ -574,11 +574,11 @@ SD_Init() // sdmmc_send_command(&handelSD,0x10769,0x00FF8000 | temp); // // DEBUGPRINT(topScreen, "sd error ", handelSD.error, 10, 20 + 17*8, - //RGB(40, 40, 40), RGB(208, 208, 208)); + // RGB(40, 40, 40), RGB(208, 208, 208)); // DEBUGPRINT(topScreen, "sd ret: ", handelSD.ret[0], 10, 20 + 18*8, - //RGB(40, 40, 40), RGB(208, 208, 208)); + // RGB(40, 40, 40), RGB(208, 208, 208)); // DEBUGPRINT(topScreen, "count: ", count++, 10, 20 + 19*8, RGB(40, 40, - //40), RGB(208, 208, 208)); + // 40), RGB(208, 208, 208)); //} // while(!(handelSD.ret[0] & 0x80000000)); -- 2.39.5