From a76c15d018264edc46f1c40620b4f597923835c8 Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 30 Aug 2016 17:48:41 +0200 Subject: [PATCH 1/3] Introduce a strcat replacement --- source/draw.c | 10 +--------- source/fs.c | 9 +++++---- source/strings.c | 41 +++++++++++++++++++++++++++++++++++++++++ source/strings.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 source/strings.c create mode 100644 source/strings.h diff --git a/source/draw.c b/source/draw.c index a6a99f5..14b8b0e 100644 --- a/source/draw.c +++ b/source/draw.c @@ -26,20 +26,12 @@ */ #include "draw.h" +#include "strings.h" #include "screen.h" #include "utils.h" #include "fs.h" #include "font.h" -static inline int strlen(const char *string) -{ - char *stringEnd = (char *)string; - - while(*stringEnd) stringEnd++; - - return stringEnd - string; -} - bool loadSplash(void) { //Don't delay boot nor init the screens if no splash image is on the SD diff --git a/source/fs.c b/source/fs.c index f428bbe..67890de 100644 --- a/source/fs.c +++ b/source/fs.c @@ -22,6 +22,7 @@ #include "fs.h" #include "memory.h" +#include "strings.h" #include "cache.h" #include "screen.h" #include "fatfs/ff.h" @@ -127,8 +128,8 @@ void loadPayload(u32 pressed) memcpy(loaderAddress, loader, loader_size); - path[14] = '/'; - memcpy(&path[15], info.altname, 13); + concatenateStrings(path, "/"); + concatenateStrings(path, info.altname); loaderAddress[1] = fileRead((void *)0x24F00000, path); @@ -147,7 +148,7 @@ u32 firmRead(void *dest, u32 firmType) { "00000003", "20000003" }}; char path[48] = "1:/title/00040138/00000000/content"; - memcpy(&path[18], firmFolders[firmType][isN3DS ? 1 : 0], 8); + concatenateStrings(path, firmFolders[firmType][isN3DS ? 1 : 0]); DIR dir; FILINFO info; @@ -177,7 +178,7 @@ u32 firmRead(void *dest, u32 firmType) f_closedir(&dir); //Complete the string with the .app name - memcpy(&path[34], "/00000000.app", 14); + concatenateStrings(path, "/00000000.app"); //Last digit of the .app u32 i = 42; diff --git a/source/strings.c b/source/strings.c new file mode 100644 index 0000000..adaa712 --- /dev/null +++ b/source/strings.c @@ -0,0 +1,41 @@ +/* +* This file is part of Luma3DS +* Copyright (C) 2016 Aurora Wright, TuxSH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that 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 . +* +* Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified +* reasonable legal notices or author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +*/ + +#include "strings.h" +#include "memory.h" + +int strlen(const char *string) +{ + char *stringEnd = (char *)string; + + while(*stringEnd) stringEnd++; + + return stringEnd - string; +} + +void concatenateStrings(char *destination, const char *source) +{ + int i = strlen(source), + j = strlen(destination); + + memcpy(&destination[j], source, i + 1); +} \ No newline at end of file diff --git a/source/strings.h b/source/strings.h new file mode 100644 index 0000000..f6b035f --- /dev/null +++ b/source/strings.h @@ -0,0 +1,28 @@ +/* +* This file is part of Luma3DS +* Copyright (C) 2016 Aurora Wright, TuxSH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that 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 . +* +* Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified +* reasonable legal notices or author attributions in that material or in the Appropriate Legal +* Notices displayed by works containing it. +*/ + +#pragma once + +#include "types.h" + +int strlen(const char *string); +void concatenateStrings(char *destination, const char *source); \ No newline at end of file From a2003fba95bc78f20aa808e730e5f0ebda3e1b4c Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 30 Aug 2016 19:48:21 +0200 Subject: [PATCH 2/3] Add -O3 optimization for the string functions --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e964dd7..cf898ad 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ $(call rwildcard, $(dir_source), *.s *.c))) bundled = $(dir_build)/rebootpatch.h $(dir_build)/emunandpatch.h $(dir_build)/svcGetCFWInfopatch.h $(dir_build)/twl_k11modulespatch.h \ - $(dir_build)/injector.h $(dir_build)/loader.h + $(dir_build)/injector.h $(dir_build)/loader.h .PHONY: all all: launcher a9lh ninjhax @@ -112,7 +112,7 @@ $(dir_build)/loader.h: $(dir_loader)/Makefile @$(MAKE) -C $(dir_loader) @bin2c -o $@ -n loader $(@D)/loader.bin -$(dir_build)/memory.o: CFLAGS += -O3 +$(dir_build)/memory.o $(dir_build)/strings.o: CFLAGS += -O3 $(dir_build)/config.o: CFLAGS += -DCONFIG_TITLE="\"$(name) $(revision) configuration\"" $(dir_build)/patches.o: CFLAGS += -DREVISION=\"$(revision)\" -DCOMMIT_HASH="0x$(commit)" From 5406d648bca3bf66dece5b1554d35d3e40faef1c Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 30 Aug 2016 19:58:38 +0200 Subject: [PATCH 3/3] Fix derp --- source/fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/fs.c b/source/fs.c index 67890de..3eb247c 100644 --- a/source/fs.c +++ b/source/fs.c @@ -147,8 +147,9 @@ u32 firmRead(void *dest, u32 firmType) { "00000202", "20000202" }, { "00000003", "20000003" }}; - char path[48] = "1:/title/00040138/00000000/content"; + char path[48] = "1:/title/00040138/"; concatenateStrings(path, firmFolders[firmType][isN3DS ? 1 : 0]); + concatenateStrings(path, "/content"); DIR dir; FILINFO info;