.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"
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)
#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;
}
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;
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;
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;
}
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) {
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))
}
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;
#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;
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;
}
} 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;
}
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;
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 */
/* 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
}
} 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)
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) */
#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);
}
// 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));