From b593d0bbeb8b56f83c309f029e2658a0b1ce50c8 Mon Sep 17 00:00:00 2001 From: GrapheneCt <57592952+GrapheneCt@users.noreply.github.com> Date: Mon, 4 May 2020 02:50:51 +0200 Subject: [PATCH] Updated to v2.21 - Reduced newlib usage to the minimum - All settings are now saved in savedata0: --- CMakeLists.txt | 3 +-- source/config.c | 44 ++++++++++++++++--------------- source/dirbrowse.c | 45 +++++++++++++++++--------------- source/fs.c | 4 +-- source/main.c | 5 ++-- source/menus/menu_audioplayer.c | 44 ++++++++++++++++--------------- source/menus/menu_displayfiles.c | 4 +-- source/menus/menu_settings.c | 2 +- source/touch.c | 8 +++--- source/utils.c | 17 ++---------- 10 files changed, 85 insertions(+), 91 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 28e676d..12ffd15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ include("${DOLCESDK}/share/dolce.cmake" REQUIRED) set(VITA_APP_NAME "Eleven Music Player") set(VITA_TITLEID "ELEVENMPV") -set(VITA_VERSION "02.20") +set(VITA_VERSION "02.21") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall -Werror") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") @@ -66,7 +66,6 @@ add_executable(${PROJECT_NAME} source/dirbrowse.c source/fs.c source/main.c - source/status_bar.c source/textures.c source/touch.c source/utils.c diff --git a/source/config.c b/source/config.c index c32fbed..cea13aa 100644 --- a/source/config.c +++ b/source/config.c @@ -1,5 +1,5 @@ +#include #include -#include #include #include @@ -12,6 +12,8 @@ config_t config; static int config_version_holder = 0; +extern void* mspace; + const char *config_file = "config_ver = %d\n" "metadata_flac = %d\n" @@ -24,23 +26,23 @@ const char *config_file = int Config_Save(config_t config) { int ret = 0; - char *buf = malloc(128); - int len = snprintf(buf, 128, config_file, CONFIG_VERSION, config.meta_flac, config.meta_mp3, config.meta_opus, config.sort, + char *buf = sceClibMspaceMalloc(mspace, 128); + int len = sceClibSnprintf(buf, 128, config_file, CONFIG_VERSION, config.meta_flac, config.meta_mp3, config.meta_opus, config.sort, config.alc_mode, config.device); - if (R_FAILED(ret = FS_WriteFile("ux0:data/ElevenMPV/config.cfg", buf, len))) { - free(buf); + if (R_FAILED(ret = FS_WriteFile("savedata0:config.cfg", buf, len))) { + sceClibMspaceFree(mspace, buf); return ret; } - free(buf); + sceClibMspaceFree(mspace, buf); return 0; } int Config_Load(void) { int ret = 0; - if (!FS_FileExists("ux0:data/ElevenMPV/config.cfg")) { + if (!FS_FileExists("savedata0:config.cfg")) { // set these to the following by default: config.meta_flac = SCE_FALSE; config.meta_mp3 = SCE_TRUE; @@ -52,22 +54,22 @@ int Config_Load(void) { } SceOff size = 0; - FS_GetFileSize("ux0:data/ElevenMPV/config.cfg", &size); - char *buf = malloc(size + 1); + FS_GetFileSize("savedata0:config.cfg", &size); + char *buf = sceClibMspaceMalloc(mspace, size + 1); - if (R_FAILED(ret = FS_ReadFile("ux0:data/ElevenMPV/config.cfg", buf, size))) { - free(buf); + if (R_FAILED(ret = FS_ReadFile("savedata0:config.cfg", buf, size))) { + sceClibMspaceFree(mspace, buf); return ret; } buf[size] = '\0'; sscanf(buf, config_file, &config_version_holder, &config.meta_flac, &config.meta_mp3, &config.meta_opus, &config.sort, &config.alc_mode, &config.device); - free(buf); + sceClibMspaceFree(mspace, buf); // Delete config file if config file is updated. This will rarely happen. if (config_version_holder < CONFIG_VERSION) { - sceIoRemove("ux0:data/ElevenMPV/config.cfg"); + sceIoRemove("savedata0:config.cfg"); config.meta_flac = SCE_FALSE; config.meta_mp3 = SCE_TRUE; config.meta_opus = SCE_TRUE; @@ -88,20 +90,20 @@ int Config_GetLastDirectory(void) { "uma0:/" }; - if (!FS_FileExists("ux0:data/ElevenMPV/lastdir.txt")) { - snprintf(root_path, 8, "ux0:/"); - FS_WriteFile("ux0:data/ElevenMPV/lastdir.txt", root_path, strlen(root_path) + 1); + if (!FS_FileExists("savedata0:lastdir.txt")) { + sceClibSnprintf(root_path, 8, "ux0:/"); + FS_WriteFile("savedata0:lastdir.txt", root_path, strlen(root_path) + 1); strcpy(cwd, root_path); // Set Start Path to "sdmc:/" if lastDir.txt hasn't been created. } else { strcpy(root_path, root_paths[config.device]); SceOff size = 0; - FS_GetFileSize("ux0:data/ElevenMPV/lastdir.txt", &size); - char *buf = malloc(size + 1); + FS_GetFileSize("savedata0:lastdir.txt", &size); + char *buf = sceClibMspaceMalloc(mspace, size + 1); - if (R_FAILED(ret = FS_ReadFile("ux0:data/ElevenMPV/lastdir.txt", buf, size))) { - free(buf); + if (R_FAILED(ret = FS_ReadFile("savedata0:lastdir.txt", buf, size))) { + sceClibMspaceFree(mspace, buf); return ret; } @@ -114,7 +116,7 @@ int Config_GetLastDirectory(void) { else strcpy(cwd, root_path); - free(buf); + sceClibMspaceFree(mspace, buf); } return 0; diff --git a/source/dirbrowse.c b/source/dirbrowse.c index edc59e8..6e6e4fd 100644 --- a/source/dirbrowse.c +++ b/source/dirbrowse.c @@ -1,8 +1,8 @@ +#include #include #include #include #include -#include #include #include "common.h" @@ -15,19 +15,22 @@ File *files = NULL; +extern void* mspace; +void* sceClibMspaceCalloc(void* space, size_t num, size_t size); + static void Dirbrowse_RecursiveFree(File *node) { if (node == NULL) // End of list return; Dirbrowse_RecursiveFree(node->next); // Nest further - free(node); // Free memory + sceClibMspaceFree(mspace, node); // Free memory } static void Dirbrowse_SaveLastDirectory(void) { - char *buf = malloc(256); - int len = snprintf(buf, 256, "%s\n", cwd); - FS_WriteFile("ux0:data/elevenmpv/lastdir.txt", buf, len); - free(buf); + char *buf = sceClibMspaceMalloc(mspace, 256); + int len = sceClibSnprintf(buf, 256, "%s\n", cwd); + FS_WriteFile("savedata0:lastdir.txt", buf, len); + sceClibMspaceFree(mspace, buf); } static int cmpstringp(const void *p1, const void *p2) { @@ -62,7 +65,7 @@ int Dirbrowse_PopulateFiles(SceBool refresh) { if (R_SUCCEEDED(dir = sceIoDopen(cwd))) { int entryCount = 0; - SceIoDirent *entries = (SceIoDirent *)calloc(MAX_FILES, sizeof(SceIoDirent)); + SceIoDirent *entries = (SceIoDirent *)sceClibMspaceCalloc(mspace, MAX_FILES, sizeof(SceIoDirent)); while (sceIoDread(dir, &entries[entryCount]) > 0) entryCount++; @@ -72,17 +75,17 @@ int Dirbrowse_PopulateFiles(SceBool refresh) { for (int i = -1; i < entryCount; i++) { // Allocate Memory - File *item = (File *)malloc(sizeof(File)); - memset(item, 0, sizeof(File)); + File *item = (File *)sceClibMspaceMalloc(mspace, sizeof(File)); + sceClibMemset(item, 0, sizeof(File)); - if ((strcmp(cwd, root_path)) && (i == -1) && (!parent_dir_set)) { + if ((sceClibStrcmp(cwd, root_path)) && (i == -1) && (!parent_dir_set)) { strcpy(item->name, ".."); item->is_dir = SCE_TRUE; parent_dir_set = SCE_TRUE; file_count++; } else { - if ((i == -1) && (!(strcmp(cwd, root_path)))) + if ((i == -1) && (!(sceClibStrcmp(cwd, root_path)))) continue; item->is_dir = SCE_S_ISDIR(entries[i].d_stat.st_mode); @@ -108,7 +111,7 @@ int Dirbrowse_PopulateFiles(SceBool refresh) { } } - free(entries); + sceClibMspaceFree(mspace, entries); } else return dir; @@ -126,7 +129,7 @@ int Dirbrowse_PopulateFiles(SceBool refresh) { void Dirbrowse_DisplayFiles(void) { vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, cwd)) / 2) + 20, RGBA8(255, 255, 255, 255), 25, cwd); - if (!(!strcmp(cwd, root_path))) + if (!(!sceClibStrcmp(cwd, root_path))) vita2d_draw_texture(icon_back, 25, 54); int i = 0, printed = 0; @@ -142,14 +145,14 @@ void Dirbrowse_DisplayFiles(void) { if (file->is_dir) vita2d_draw_texture(icon_dir, 15, 117 + (72 * printed)); - else if ((!strncasecmp(file->ext, "flac", 4)) || (!strncasecmp(file->ext, "it", 4)) || (!strncasecmp(file->ext, "mod", 4)) - || (!strncasecmp(file->ext, "mp3", 4)) || (!strncasecmp(file->ext, "ogg", 4)) || (!strncasecmp(file->ext, "opus", 4)) - || (!strncasecmp(file->ext, "s3m", 4))|| (!strncasecmp(file->ext, "wav", 4)) || (!strncasecmp(file->ext, "xm", 4))) + else if ((!sceClibStrncasecmp(file->ext, "flac", 4)) || (!sceClibStrncasecmp(file->ext, "it", 4)) || (!sceClibStrncasecmp(file->ext, "mod", 4)) + || (!sceClibStrncasecmp(file->ext, "mp3", 4)) || (!sceClibStrncasecmp(file->ext, "ogg", 4)) || (!sceClibStrncasecmp(file->ext, "opus", 4)) + || (!sceClibStrncasecmp(file->ext, "s3m", 4))|| (!sceClibStrncasecmp(file->ext, "wav", 4)) || (!sceClibStrncasecmp(file->ext, "xm", 4))) vita2d_draw_texture(icon_audio, 15, 117 + (72 * printed)); else vita2d_draw_texture(icon_file, 15, 117 + (72 * printed)); - if (strncmp(file->name, "..", 2) == 0) + if (sceClibStrncmp(file->name, "..", 2) == 0) vita2d_font_draw_text(font, 102, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, "Parent folder"); else vita2d_font_draw_text(font, 102, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, file->name); @@ -188,9 +191,9 @@ void Dirbrowse_OpenFile(void) { Dirbrowse_PopulateFiles(SCE_TRUE); } } - else if ((!strncasecmp(file->ext, "flac", 4)) || (!strncasecmp(file->ext, "it", 4)) || (!strncasecmp(file->ext, "mod", 4)) - || (!strncasecmp(file->ext, "mp3", 4)) || (!strncasecmp(file->ext, "ogg", 4)) || (!strncasecmp(file->ext, "opus", 4)) - || (!strncasecmp(file->ext, "s3m", 4))|| (!strncasecmp(file->ext, "wav", 4)) || (!strncasecmp(file->ext, "xm", 4))) + else if ((!sceClibStrncasecmp(file->ext, "flac", 4)) || (!sceClibStrncasecmp(file->ext, "it", 4)) || (!sceClibStrncasecmp(file->ext, "mod", 4)) + || (!sceClibStrncasecmp(file->ext, "mp3", 4)) || (!sceClibStrncasecmp(file->ext, "ogg", 4)) || (!sceClibStrncasecmp(file->ext, "opus", 4)) + || (!sceClibStrncasecmp(file->ext, "s3m", 4))|| (!sceClibStrncasecmp(file->ext, "wav", 4)) || (!sceClibStrncasecmp(file->ext, "xm", 4))) Menu_PlayAudio(path); } @@ -202,7 +205,7 @@ int Dirbrowse_Navigate(SceBool parent) { return -1; // Special case ".." - if ((parent) || (!strncmp(file->name, "..", 2))) { + if ((parent) || (!sceClibStrncmp(file->name, "..", 2))) { char *slash = NULL; // Find last '/' in working directory diff --git a/source/fs.c b/source/fs.c index 76ac136..4adf9df 100644 --- a/source/fs.c +++ b/source/fs.c @@ -1,7 +1,7 @@ +#include #include #include #include -#include #include "common.h" #include "fs.h" @@ -29,7 +29,7 @@ SceBool FS_DirExists(const char *path) { } const char *FS_GetFileExt(const char *filename) { - const char *dot = strrchr(filename, '.'); + const char *dot = sceClibStrrchr(filename, '.'); if (!dot || dot == filename) return ""; diff --git a/source/main.c b/source/main.c index 18e640e..f9a3950 100644 --- a/source/main.c +++ b/source/main.c @@ -19,14 +19,14 @@ #define CLIB_HEAP_SIZE 1 * 1024 * 1024 -int _newlib_heap_size_user = 1 * 1024 * 1024; +int _newlib_heap_size_user = 128 * 1024; +void* mspace; int sceAppMgrAcquireBgmPortForMusicPlayer(void); int main(int argc, char *argv[]) { void* clibm_base; - void* mspace; SceUID clib_heap = sceKernelAllocMemBlock("ClibHeap", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, CLIB_HEAP_SIZE, NULL); sceKernelGetMemBlockBase(clib_heap, &clibm_base); mspace = sceClibMspaceCreate(clibm_base, CLIB_HEAP_SIZE); @@ -36,7 +36,6 @@ int main(int argc, char *argv[]) { font = vita2d_load_font_file("app0:Roboto-Regular.ttf"); Textures_Load(); - sceIoMkdir("ux0:data/ElevenMPV", 0777); Config_Load(); Config_GetLastDirectory(); diff --git a/source/menus/menu_audioplayer.c b/source/menus/menu_audioplayer.c index 87c1992..6e8d10d 100644 --- a/source/menus/menu_audioplayer.c +++ b/source/menus/menu_audioplayer.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -33,13 +32,16 @@ static int length_time_width = 0; char *position_time = NULL, *length_time = NULL, *filename = NULL; extern int isFG; +extern void* mspace; + +void* sceClibMspaceCalloc(void* space, size_t num, size_t size); static int Menu_GetMusicList(void) { SceUID dir = 0; if (R_SUCCEEDED(dir = sceIoDopen(cwd))) { int entryCount = 0, i = 0; - SceIoDirent *entries = (SceIoDirent *)calloc(MAX_FILES, sizeof(SceIoDirent)); + SceIoDirent *entries = (SceIoDirent *)sceClibMspaceCalloc(mspace, MAX_FILES, sizeof(SceIoDirent)); while (sceIoDread(dir, &entries[entryCount]) > 0) entryCount++; @@ -48,18 +50,18 @@ static int Menu_GetMusicList(void) { qsort(entries, entryCount, sizeof(SceIoDirent), Utils_Alphasort); for (i = 0; i < entryCount; i++) { - if ((!strncasecmp(FS_GetFileExt(entries[i].d_name), "flac", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "it", 4)) || - (!strncasecmp(FS_GetFileExt(entries[i].d_name), "mod", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "mp3", 4)) || - (!strncasecmp(FS_GetFileExt(entries[i].d_name), "ogg", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "opus", 4)) || - (!strncasecmp(FS_GetFileExt(entries[i].d_name), "s3m", 4)) || (!strncasecmp(FS_GetFileExt(entries[i].d_name), "wav", 4)) || - (!strncasecmp(FS_GetFileExt(entries[i].d_name), "xm", 4))) { + if ((!sceClibStrncasecmp(FS_GetFileExt(entries[i].d_name), "flac", 4)) || (!sceClibStrncasecmp(FS_GetFileExt(entries[i].d_name), "it", 4)) || + (!sceClibStrncasecmp(FS_GetFileExt(entries[i].d_name), "mod", 4)) || (!sceClibStrncasecmp(FS_GetFileExt(entries[i].d_name), "mp3", 4)) || + (!sceClibStrncasecmp(FS_GetFileExt(entries[i].d_name), "ogg", 4)) || (!sceClibStrncasecmp(FS_GetFileExt(entries[i].d_name), "opus", 4)) || + (!sceClibStrncasecmp(FS_GetFileExt(entries[i].d_name), "s3m", 4)) || (!sceClibStrncasecmp(FS_GetFileExt(entries[i].d_name), "wav", 4)) || + (!sceClibStrncasecmp(FS_GetFileExt(entries[i].d_name), "xm", 4))) { strcpy(playlist[count], cwd); strcpy(playlist[count] + strlen(playlist[count]), entries[i].d_name); count++; } } - free(entries); + sceClibMspaceFree(mspace, entries); } else { sceIoDclose(dir); @@ -71,7 +73,7 @@ static int Menu_GetMusicList(void) { static int Music_GetCurrentIndex(char *path) { for(int i = 0; i < count; ++i) { - if (!strcmp(playlist[i], path)) + if (!sceClibStrcmp(playlist[i], path)) return i; } @@ -85,9 +87,9 @@ static void Menu_ConvertSecondsToString(char *string, SceUInt64 seconds) { s = (seconds - (3600 * h) - (m * 60)); if (h > 0) - snprintf(string, 35, "%02d:%02d:%02d", h, m, s); + sceClibSnprintf(string, 35, "%02d:%02d:%02d", h, m, s); else - snprintf(string, 35, "%02d:%02d", m, s); + sceClibSnprintf(string, 35, "%02d:%02d", m, s); } static void Menu_InitMusic(char *path) { @@ -95,10 +97,10 @@ static void Menu_InitMusic(char *path) { if (sceAudioOutSetAlcMode(config.alc_mode) < 0) return; - filename = malloc(128); - snprintf(filename, 128, Utils_Basename(path)); - position_time = malloc(35); - length_time = malloc(35); + filename = sceClibMspaceMalloc(mspace, 128); + sceClibSnprintf(filename, 128, Utils_Basename(path)); + position_time = sceClibMspaceMalloc(mspace, 35); + length_time = sceClibMspaceMalloc(mspace, 35); length_time_width = 0; Menu_ConvertSecondsToString(length_time, Audio_GetLengthSeconds()); @@ -128,9 +130,9 @@ static void Music_HandleNext(SceBool forward, int state) { Audio_Stop(); - free(filename); - free(length_time); - free(position_time); + sceClibMspaceFree(mspace, filename); + sceClibMspaceFree(mspace, length_time); + sceClibMspaceFree(mspace, position_time); if ((metadata.has_meta) && (metadata.cover_image)) { vita2d_wait_rendering_done(); @@ -293,9 +295,9 @@ void Menu_PlayAudio(char *path) { break; } - free(filename); - free(length_time); - free(position_time); + sceClibMspaceFree(mspace, filename); + sceClibMspaceFree(mspace, length_time); + sceClibMspaceFree(mspace, position_time); if ((metadata.has_meta) && (metadata.cover_image)) { vita2d_wait_rendering_done(); diff --git a/source/menus/menu_displayfiles.c b/source/menus/menu_displayfiles.c index be819b3..3d34ef0 100644 --- a/source/menus/menu_displayfiles.c +++ b/source/menus/menu_displayfiles.c @@ -1,4 +1,4 @@ -#include +#include #include #include "common.h" @@ -29,7 +29,7 @@ static void Menu_HandleControls(void) { Dirbrowse_OpenFile(); } - if ((strcmp(cwd, root_path) != 0) && (pressed & SCE_CTRL_CANCEL)) { + if ((sceClibStrcmp(cwd, root_path) != 0) && (pressed & SCE_CTRL_CANCEL)) { Dirbrowse_Navigate(SCE_TRUE); Dirbrowse_PopulateFiles(SCE_TRUE); } diff --git a/source/menus/menu_settings.c b/source/menus/menu_settings.c index 11abb34..1f42876 100644 --- a/source/menus/menu_settings.c +++ b/source/menus/menu_settings.c @@ -77,7 +77,7 @@ static void Menu_DisplayDeviceSettings(void) { Config_Save(config); strcpy(root_path, menu_items[config.device]); strcpy(cwd, root_path); - sceIoRemove("ux0:data/ElevenMPV/lastdir.txt"); + sceIoRemove("savedata0:lastdir.txt"); Dirbrowse_PopulateFiles(SCE_TRUE); } } diff --git a/source/touch.c b/source/touch.c index db44c16..0ea5394 100644 --- a/source/touch.c +++ b/source/touch.c @@ -7,7 +7,7 @@ */ #include -#include +#include #include "touch.h" @@ -15,6 +15,8 @@ static SceTouchData touch; +extern void* mspace; + typedef struct { int posX; int posY; @@ -40,14 +42,14 @@ void Touch_Reset(void) { int Touch_Init(void) { sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, 1); - touchState = malloc(sizeof(touchStateData)); + touchState = sceClibMspaceMalloc(mspace, sizeof(touchStateData)); Touch_Reset(); return 1; } void Touch_Shutdown(void) { - free(touchState); + sceClibMspaceFree(mspace, touchState); } int Touch_GetX(void) { diff --git a/source/utils.c b/source/utils.c index 0c40146..32d2723 100644 --- a/source/utils.c +++ b/source/utils.c @@ -7,19 +7,7 @@ #include #include -#include "common.h" - -typedef struct SceAppMgrAppStatus { // size is 0x40 on FW 0.990 - SceUInt32 unk_0; // 0x0 - SceUInt32 launchMode; // 0x4 - SceUInt32 bgm_priority_or_status; // 0x8 - char appName[32]; // 0xC - SceUInt32 unk_2C; // 0x2C - SceUID appId; // 0x30 - Application ID - SceUID processId; // 0x34 - Process ID - SceUInt32 isForeground; // 0x38 - SceUInt32 status_related_2; // 0x3C -} SceAppMgrAppStatus; +#include "common.h" typedef struct SceAppMgrEvent { // size is 0x64 int event; /* Event ID */ @@ -28,7 +16,6 @@ typedef struct SceAppMgrEvent { // size is 0x64 } SceAppMgrEvent; int _sceAppMgrReceiveEvent(SceAppMgrEvent *appEvent); -int sceAppMgrQuitForNonSuspendableApp(void); int isFG = SCE_TRUE; @@ -153,7 +140,7 @@ int Utils_Alphasort(const void *p1, const void *p2) { } char *Utils_Basename(const char *filename) { - char *p = strrchr (filename, '/'); + char *p = sceClibStrrchr (filename, '/'); return p ? p + 1 : (char *) filename; }