From 9334294ca1f4b575a14cf52b457d2d792bb1928c Mon Sep 17 00:00:00 2001 From: Wolf3s Date: Tue, 31 Dec 2024 12:40:09 -0300 Subject: [PATCH 1/6] [Refactor]: Add submenu.c for refactor the menu system. --- Makefile | 2 +- include/gui.h | 2 +- include/{menusys.h => menu.h} | 33 ------ include/opl.h | 3 +- include/submenu.h | 42 ++++++++ include/themes.h | 2 +- src/gui.c | 2 +- src/{menusys.c => menu.c} | 176 +------------------------------- src/opl.c | 2 +- src/submenu.c | 185 ++++++++++++++++++++++++++++++++++ 10 files changed, 235 insertions(+), 214 deletions(-) rename include/{menusys.h => menu.h} (70%) create mode 100644 include/submenu.h rename src/{menusys.c => menu.c} (89%) create mode 100644 src/submenu.c diff --git a/Makefile b/Makefile index 3581889d9..8ecfb1d0c 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ ifneq ($(GIT_TAG),latest) endif endif -FRONTEND_OBJS = pad.o xparam.o fntsys.o renderman.o menusys.o OSDHistory.o system.o lang.o lang_internal.o config.o hdd.o dialogs.o \ +FRONTEND_OBJS = pad.o xparam.o fntsys.o renderman.o submenu.o menu.o OSDHistory.o system.o lang.o lang_internal.o config.o hdd.o dialogs.o \ dia.o ioman.o texcache.o themes.o supportbase.o bdmsupport.o ethsupport.o hddsupport.o zso.o lz4.o \ appsupport.o gui.o guigame.o textures.o opl.o atlas.o nbns.o httpclient.o gsm.o cheatman.o sound.o ps2cnf.o diff --git a/include/gui.h b/include/gui.h index 44c697409..a834d17f5 100644 --- a/include/gui.h +++ b/include/gui.h @@ -5,7 +5,7 @@ #include "include/opl.h" #include "include/texcache.h" #include "include/dialogs.h" -#include "include/menusys.h" +#include "include/menu.h" typedef enum { // Informs gui that init is over and main gui can be rendered diff --git a/include/menusys.h b/include/menu.h similarity index 70% rename from include/menusys.h rename to include/menu.h index 0cbf9bf9f..5452705e9 100644 --- a/include/menusys.h +++ b/include/menu.h @@ -4,32 +4,6 @@ #include "include/config.h" #include "include/dia.h" -/// a single submenu item -typedef struct submenu_item -{ - /// Icon used for rendering of this item - int icon_id; - - /// item description - char *text; - - /// item description in localized form (used if value is not negative) - int text_id; - - /// item id (MUST BE VALID, we assert it is != -1 to optimize rendering) - int id; - - int *cache_id; - int *cache_uid; -} submenu_item_t; - -typedef struct submenu_list -{ - struct submenu_item item; - - struct submenu_list *prev, *next; -} submenu_list_t; - typedef struct menu_hint_item { int icon_id; @@ -89,13 +63,6 @@ void menuInitAppMenu(void); void menuAppendItem(menu_item_t *item); -void submenuRebuildCache(submenu_list_t *submenu); -submenu_list_t *submenuAppendItem(submenu_list_t **submenu, int icon_id, char *text, int id, int text_id); -void submenuRemoveItem(submenu_list_t **submenu, int id); -void submenuDestroy(submenu_list_t **submenu); -void submenuSort(submenu_list_t **submenu); - -char *submenuItemGetText(submenu_item_t *it); char *menuItemGetText(menu_item_t *it); config_set_t *menuLoadConfig(); config_set_t *gameMenuLoadConfig(struct UIItem *ui); diff --git a/include/opl.h b/include/opl.h index 0d56a6b94..453ab180e 100644 --- a/include/opl.h +++ b/include/opl.h @@ -221,7 +221,8 @@ void setDefaultColors(void); #define MENU_ITEM_HEIGHT 19 -#include "include/menusys.h" +#include "include/submenu.h" +#include "include/menu.h" typedef struct { diff --git a/include/submenu.h b/include/submenu.h new file mode 100644 index 000000000..1ba0a1dd3 --- /dev/null +++ b/include/submenu.h @@ -0,0 +1,42 @@ +#ifndef __SUBMENU_H +#define __SUBMENU_H + +/// a single submenu item +typedef struct submenu_item +{ + /// Icon used for rendering of this item + int icon_id; + + /// item description + char *text; + + /// item description in localized form (used if value is not negative) + int text_id; + + /// item id (MUST BE VALID, we assert it is != -1 to optimize rendering) + int id; + + int *cache_id; + int *cache_uid; +} submenu_item_t; + +typedef struct submenu_list +{ + struct submenu_item item; + + struct submenu_list *prev, *next; +} submenu_list_t; + +void submenuRebuildCache(submenu_list_t *submenu); +submenu_list_t *submenuAppendItem(submenu_list_t **submenu, int icon_id, char *text, int id, int text_id); +void submenuRemoveItem(submenu_list_t **submenu, int id); +void submenuDestroy(submenu_list_t **submenu); +void submenuSort(submenu_list_t **submenu); + +char *submenuItemGetText(submenu_item_t *it); + +void submenuDestroyItem(submenu_list_t *submenu); + +submenu_list_t *submenuAllocItem(int icon_id, char *text, int id, int text_id); + +#endif \ No newline at end of file diff --git a/include/themes.h b/include/themes.h index b0cd3c91c..64ceb0f25 100644 --- a/include/themes.h +++ b/include/themes.h @@ -3,7 +3,7 @@ #include "include/textures.h" #include "include/texcache.h" -#include "include/menusys.h" +#include "include/menu.h" #define THM_MAX_FILES 64 #define THM_MAX_FONTS 16 diff --git a/src/gui.c b/src/gui.c index 3dc1bd225..1f5874b37 100644 --- a/src/gui.c +++ b/src/gui.c @@ -7,7 +7,7 @@ #include "include/opl.h" #include "include/gui.h" #include "include/renderman.h" -#include "include/menusys.h" +#include "include/menu.h" #include "include/fntsys.h" #include "include/ioman.h" #include "include/lang.h" diff --git a/src/menusys.c b/src/menu.c similarity index 89% rename from src/menusys.c rename to src/menu.c index 972f332ea..506a35b5b 100644 --- a/src/menusys.c +++ b/src/menu.c @@ -5,7 +5,7 @@ */ #include "include/opl.h" -#include "include/menusys.h" +#include "include/menu.h" #include "include/iosupport.h" #include "include/renderman.h" #include "include/fntsys.h" @@ -386,112 +386,6 @@ static void refreshMenuPosition(void) selected_item = cur; } -void submenuRebuildCache(submenu_list_t *submenu) -{ - while (submenu) { - if (submenu->item.cache_id) - free(submenu->item.cache_id); - if (submenu->item.cache_uid) - free(submenu->item.cache_uid); - - int size = gTheme->gameCacheCount * sizeof(int); - submenu->item.cache_id = malloc(size); - memset(submenu->item.cache_id, -1, size); - submenu->item.cache_uid = malloc(size); - memset(submenu->item.cache_uid, -1, size); - - submenu = submenu->next; - } -} - -static submenu_list_t *submenuAllocItem(int icon_id, char *text, int id, int text_id) -{ - submenu_list_t *it = (submenu_list_t *)malloc(sizeof(submenu_list_t)); - - it->prev = NULL; - it->next = NULL; - it->item.icon_id = icon_id; - it->item.text = text; - it->item.text_id = text_id; - it->item.id = id; - it->item.cache_id = NULL; - it->item.cache_uid = NULL; - submenuRebuildCache(it); - - return it; -} - -submenu_list_t *submenuAppendItem(submenu_list_t **submenu, int icon_id, char *text, int id, int text_id) -{ - if (*submenu == NULL) { - *submenu = submenuAllocItem(icon_id, text, id, text_id); - return *submenu; - } - - submenu_list_t *cur = *submenu; - - // traverse till the end - while (cur->next) - cur = cur->next; - - // create new item - submenu_list_t *newitem = submenuAllocItem(icon_id, text, id, text_id); - - // link - cur->next = newitem; - newitem->prev = cur; - - return newitem; -} - -static void submenuDestroyItem(submenu_list_t *submenu) -{ - free(submenu->item.cache_id); - free(submenu->item.cache_uid); - - free(submenu); -} - -void submenuRemoveItem(submenu_list_t **submenu, int id) -{ - submenu_list_t *cur = *submenu; - submenu_list_t *prev = NULL; - - while (cur) { - if (cur->item.id == id) { - submenu_list_t *next = cur->next; - - if (prev) - prev->next = cur->next; - - if (*submenu == cur) - *submenu = next; - - submenuDestroyItem(cur); - - cur = next; - } else { - prev = cur; - cur = cur->next; - } - } -} - -void submenuDestroy(submenu_list_t **submenu) -{ - // destroy sub menu - submenu_list_t *cur = *submenu; - - while (cur) { - submenu_list_t *td = cur; - cur = cur->next; - - submenuDestroyItem(td); - } - - *submenu = NULL; -} - void menuAddHint(menu_item_t *menu, int text_id, int icon_id) { // allocate a new hint item @@ -531,74 +425,6 @@ char *menuItemGetText(menu_item_t *it) return it->text; } -char *submenuItemGetText(submenu_item_t *it) -{ - if (it->text_id >= 0) - return _l(it->text_id); - else - return it->text; -} - -static void swap(submenu_list_t *a, submenu_list_t *b) -{ - submenu_list_t *pa, *nb; - pa = a->prev; - nb = b->next; - - a->next = nb; - b->prev = pa; - b->next = a; - a->prev = b; - - if (pa) - pa->next = b; - - if (nb) - nb->prev = a; -} - -// Sorts the given submenu by comparing the on-screen titles -void submenuSort(submenu_list_t **submenu) -{ - // a simple bubblesort - // *submenu = mergeSort(*submenu); - submenu_list_t *head; - int sorted = 0; - - if ((submenu == NULL) || (*submenu == NULL) || ((*submenu)->next == NULL)) - return; - - head = *submenu; - - while (!sorted) { - sorted = 1; - - submenu_list_t *tip = head; - - while (tip->next) { - submenu_list_t *nxt = tip->next; - - char *txt1 = submenuItemGetText(&tip->item); - char *txt2 = submenuItemGetText(&nxt->item); - - int cmp = strcasecmp(txt1, txt2); - - if (cmp > 0) { - swap(tip, nxt); - - if (tip == head) - head = nxt; - - sorted = 0; - } else { - tip = tip->next; - } - } - } - - *submenu = head; -} - static void menuNextH() { struct menu_list *next = selected_item->next; diff --git a/src/opl.c b/src/opl.c index 4b138bb17..6bb36495f 100644 --- a/src/opl.c +++ b/src/opl.c @@ -16,7 +16,7 @@ #include "include/texcache.h" #include "include/dia.h" #include "include/dialogs.h" -#include "include/menusys.h" +#include "include/menu.h" #include "include/system.h" #include "include/debug.h" #include "include/config.h" diff --git a/src/submenu.c b/src/submenu.c new file mode 100644 index 000000000..e630d47de --- /dev/null +++ b/src/submenu.c @@ -0,0 +1,185 @@ +/* + Copyright 2009, Ifcaro & volca + Copyright 2024-2025, André Guilherme + Licenced under Academic Free License version 3.0 + Review OpenUsbLd README & LICENSE files for further details. +*/ + +#include "include/opl.h" +#include "include/submenu.h" +#include "include/lang.h" +#include "include/themes.h" + +static void swap(submenu_list_t *a, submenu_list_t *b) +{ + submenu_list_t *pa, *nb; + pa = a->prev; + nb = b->next; + + a->next = nb; + b->prev = pa; + b->next = a; + a->prev = b; + + if (pa) + pa->next = b; + + if (nb) + nb->prev = a; +} + +void submenuRebuildCache(submenu_list_t *submenu) +{ + while (submenu) { + if (submenu->item.cache_id) + free(submenu->item.cache_id); + if (submenu->item.cache_uid) + free(submenu->item.cache_uid); + + int size = gTheme->gameCacheCount * sizeof(int); + submenu->item.cache_id = malloc(size); + memset(submenu->item.cache_id, -1, size); + submenu->item.cache_uid = malloc(size); + memset(submenu->item.cache_uid, -1, size); + + submenu = submenu->next; + } +} + +submenu_list_t *submenuAllocItem(int icon_id, char *text, int id, int text_id) +{ + submenu_list_t *it = (submenu_list_t *)malloc(sizeof(submenu_list_t)); + + it->prev = NULL; + it->next = NULL; + it->item.icon_id = icon_id; + it->item.text = text; + it->item.text_id = text_id; + it->item.id = id; + it->item.cache_id = NULL; + it->item.cache_uid = NULL; + submenuRebuildCache(it); + + return it; +} + +submenu_list_t *submenuAppendItem(submenu_list_t **submenu, int icon_id, char *text, int id, int text_id) +{ + if (*submenu == NULL) { + *submenu = submenuAllocItem(icon_id, text, id, text_id); + return *submenu; + } + + submenu_list_t *cur = *submenu; + + // traverse till the end + while (cur->next) + cur = cur->next; + + // create new item + submenu_list_t *newitem = submenuAllocItem(icon_id, text, id, text_id); + + // link + cur->next = newitem; + newitem->prev = cur; + + return newitem; +} + +void submenuDestroyItem(submenu_list_t *submenu) +{ + free(submenu->item.cache_id); + free(submenu->item.cache_uid); + + free(submenu); +} + +void submenuRemoveItem(submenu_list_t **submenu, int id) +{ + submenu_list_t *cur = *submenu; + submenu_list_t *prev = NULL; + + while (cur) { + if (cur->item.id == id) { + submenu_list_t *next = cur->next; + + if (prev) + prev->next = cur->next; + + if (*submenu == cur) + *submenu = next; + + submenuDestroyItem(cur); + + cur = next; + } else { + prev = cur; + cur = cur->next; + } + } +} + +void submenuDestroy(submenu_list_t **submenu) +{ + // destroy sub menu + submenu_list_t *cur = *submenu; + + while (cur) { + submenu_list_t *td = cur; + cur = cur->next; + + submenuDestroyItem(td); + } + + *submenu = NULL; +} + +char *submenuItemGetText(submenu_item_t *it) +{ + if (it->text_id >= 0) + return _l(it->text_id); + else + return it->text; +} + +// Sorts the given submenu by comparing the on-screen titles +void submenuSort(submenu_list_t **submenu) +{ + // a simple bubblesort + // *submenu = mergeSort(*submenu); + submenu_list_t *head; + int sorted = 0; + + if ((submenu == NULL) || (*submenu == NULL) || ((*submenu)->next == NULL)) + return; + + head = *submenu; + + while (!sorted) { + sorted = 1; + + submenu_list_t *tip = head; + + while (tip->next) { + submenu_list_t *nxt = tip->next; + + char *txt1 = submenuItemGetText(&tip->item); + char *txt2 = submenuItemGetText(&nxt->item); + + int cmp = strcasecmp(txt1, txt2); + + if (cmp > 0) { + swap(tip, nxt); + + if (tip == head) + head = nxt; + + sorted = 0; + } else { + tip = tip->next; + } + } + } + + *submenu = head; +} \ No newline at end of file From f3792c7ee6ff5c48f6245deb3d917777c087e043 Mon Sep 17 00:00:00 2001 From: Wolf3s Date: Tue, 31 Dec 2024 15:15:02 -0300 Subject: [PATCH 2/6] =?UTF-8?q?Remove=20redudant=20dependencies=20on=20opl?= =?UTF-8?q?=C2=B4s=20frontend.=20Remove=20hack=20code=20inside=20of=20soun?= =?UTF-8?q?d.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/appsupport.h | 2 -- include/bdmsupport.h | 4 ---- include/cheatman.h | 9 --------- include/dia.h | 2 -- include/ethsupport.h | 3 --- include/gui.h | 6 ------ include/hdd.h | 2 ++ include/hddsupport.h | 2 -- include/menu.h | 1 - include/opl.h | 28 ++-------------------------- include/system.h | 2 -- include/texcache.h | 2 -- src/OSDHistory.c | 11 ++--------- src/appsupport.c | 4 ---- src/atlas.c | 2 -- src/bdmsupport.c | 3 +-- src/cheatman.c | 3 ++- src/config.c | 1 - src/dia.c | 2 +- src/dialogs.c | 5 +---- src/ethsupport.c | 7 +++++-- src/gui.c | 4 +--- src/guigame.c | 3 +-- src/hdd.c | 2 ++ src/hddsupport.c | 4 ++-- src/ioman.c | 5 ----- src/menu.c | 3 +-- src/opl.c | 19 +++++++------------ src/renderman.c | 2 -- src/sound.c | 9 +++------ src/submenu.c | 1 - src/supportbase.c | 4 ---- src/system.c | 11 +++++++---- src/texcache.c | 1 - src/themes.c | 1 - src/util.c | 5 ----- src/xparam.c | 1 + 37 files changed, 41 insertions(+), 135 deletions(-) diff --git a/include/appsupport.h b/include/appsupport.h index 4fca27c9a..66a6074eb 100644 --- a/include/appsupport.h +++ b/include/appsupport.h @@ -1,8 +1,6 @@ #ifndef __APP_SUPPORT_H #define __APP_SUPPORT_H -#include "include/iosupport.h" - #define APP_MODE_UPDATE_DELAY 240 #define APP_TITLE_MAX 128 diff --git a/include/bdmsupport.h b/include/bdmsupport.h index 5c85b1384..c4ac9489a 100644 --- a/include/bdmsupport.h +++ b/include/bdmsupport.h @@ -1,12 +1,8 @@ #ifndef __BDM_SUPPORT_H #define __BDM_SUPPORT_H -#include "include/iosupport.h" - #define BDM_MODE_UPDATE_DELAY MENU_UPD_DELAY_GENREFRESH -#include "include/mcemu.h" - typedef struct { int active; /* Activation flag */ diff --git a/include/cheatman.h b/include/cheatman.h index 7d828e4f3..0ae082756 100644 --- a/include/cheatman.h +++ b/include/cheatman.h @@ -25,15 +25,6 @@ #ifndef _CHEATMAN_H_ #define _CHEATMAN_H_ -#include "opl.h" -#include -#include -#include -#include -#include -#include -#include - #define CHEAT_VERSION "0.5.3.7" #define MAX_HOOKS 5 diff --git a/include/dia.h b/include/dia.h index 3466ad077..bd9d00926 100644 --- a/include/dia.h +++ b/include/dia.h @@ -1,8 +1,6 @@ #ifndef __DIA_H #define __DIA_H -#include "include/opl.h" - // UI dialog item definition typedef enum { // terminates the definition of dialog. Mandatory diff --git a/include/ethsupport.h b/include/ethsupport.h index 470ba59db..64a5b1378 100644 --- a/include/ethsupport.h +++ b/include/ethsupport.h @@ -1,11 +1,8 @@ #ifndef __ETH_SUPPORT_H #define __ETH_SUPPORT_H -#include "include/iosupport.h" - #define ETH_MODE_UPDATE_DELAY 300 -#include "include/mcemu.h" typedef struct { int active; /* Activation flag */ diff --git a/include/gui.h b/include/gui.h index a834d17f5..483daffc6 100644 --- a/include/gui.h +++ b/include/gui.h @@ -1,12 +1,6 @@ #ifndef __GUI_H #define __GUI_H -#include "include/iosupport.h" -#include "include/opl.h" -#include "include/texcache.h" -#include "include/dialogs.h" -#include "include/menu.h" - typedef enum { // Informs gui that init is over and main gui can be rendered GUI_INIT_DONE = 1, diff --git a/include/hdd.h b/include/hdd.h index ef571e931..8704ca7a0 100644 --- a/include/hdd.h +++ b/include/hdd.h @@ -1,6 +1,8 @@ #ifndef __HDD_H #define __HDD_H +#include + typedef struct { u32 start; // Sector address diff --git a/include/hddsupport.h b/include/hddsupport.h index ddbd94963..ef36032a2 100644 --- a/include/hddsupport.h +++ b/include/hddsupport.h @@ -1,7 +1,6 @@ #ifndef __HDD_SUPPORT_H #define __HDD_SUPPORT_H -#include "include/iosupport.h" #include "include/hdd.h" #define HDD_MODE_UPDATE_DELAY MENU_UPD_DELAY_NOUPDATE @@ -38,7 +37,6 @@ typedef struct u32 length; } apa_subs; -#include "include/mcemu.h" typedef struct { int active; /* Activation flag */ diff --git a/include/menu.h b/include/menu.h index 5452705e9..3561d1bb8 100644 --- a/include/menu.h +++ b/include/menu.h @@ -1,7 +1,6 @@ #ifndef __MENUSYS_H #define __MENUSYS_H -#include "include/config.h" #include "include/dia.h" typedef struct menu_hint_item diff --git a/include/opl.h b/include/opl.h index 453ab180e..d480a5d7d 100644 --- a/include/opl.h +++ b/include/opl.h @@ -1,15 +1,9 @@ #ifndef __OPL_H #define __OPL_H -#include #include #include -#include -#include "opl-hdd-ioctl.h" -#include -#include #include -#include #include #include #include @@ -17,33 +11,15 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include "config.h" +#include "include/iosupport.h" +#include "include/mcemu.h" #include "include/hddsupport.h" #include "include/supportbase.h" #include "include/bdmsupport.h" - -// Last Played Auto Start -#include - // Master password for disabling the parental lock. #define OPL_PARENTAL_LOCK_MASTER_PASS "989765" diff --git a/include/system.h b/include/system.h index 2d9f8f1e8..491390322 100644 --- a/include/system.h +++ b/include/system.h @@ -1,8 +1,6 @@ #ifndef __SYSTEM_H #define __SYSTEM_H -#include "include/mcemu.h" - #define SYS_LOAD_MC_MODULES 0x01 #define SYS_LOAD_USB_MODULES 0x02 #define SYS_LOAD_ISOFS_MODULE 0x04 diff --git a/include/texcache.h b/include/texcache.h index 722d9a008..e978794ff 100644 --- a/include/texcache.h +++ b/include/texcache.h @@ -1,8 +1,6 @@ #ifndef __TEX_CACHE_H #define __TEX_CACHE_H -#include "include/iosupport.h" - /// A single cache entry... typedef struct { diff --git a/src/OSDHistory.c b/src/OSDHistory.c index d4bec4118..cbd4cd593 100644 --- a/src/OSDHistory.c +++ b/src/OSDHistory.c @@ -7,17 +7,10 @@ However, OPL does not need any of that, so it can be made simpler. */ -#include -#include + #include -#include -#include -#include -#include -#include -#include #include -#include +#include "include/opl.h" #include "include/util.h" #include "include/OSDHistory.h" diff --git a/src/appsupport.c b/src/appsupport.c index 443a7bf5f..25acbb5aa 100644 --- a/src/appsupport.c +++ b/src/appsupport.c @@ -7,10 +7,6 @@ #include "include/ioman.h" #include "include/util.h" -#include "include/bdmsupport.h" -#include "include/ethsupport.h" -#include "include/hddsupport.h" - #include static int appForceUpdate = 1; diff --git a/src/atlas.c b/src/atlas.c index 880c29e72..5a35d7cbb 100644 --- a/src/atlas.c +++ b/src/atlas.c @@ -4,8 +4,6 @@ Review OpenUsbLd README & LICENSE files for further details. */ -#include -#include #include "include/opl.h" #include "include/atlas.h" #include "include/renderman.h" diff --git a/src/bdmsupport.c b/src/bdmsupport.c index 5d06b9f7e..5e5be0bff 100644 --- a/src/bdmsupport.c +++ b/src/bdmsupport.c @@ -1,8 +1,6 @@ #include "include/opl.h" #include "include/lang.h" #include "include/gui.h" -#include "include/supportbase.h" -#include "include/bdmsupport.h" #include "include/util.h" #include "include/themes.h" #include "include/textures.h" @@ -14,6 +12,7 @@ #include "modules/iopcore/common/cdvd_config.h" #include +#include "opl-hdd-ioctl.h" #include #define NEWLIB_PORT_AWARE diff --git a/src/cheatman.c b/src/cheatman.c index 5fb538b10..cbe3a760e 100644 --- a/src/cheatman.c +++ b/src/cheatman.c @@ -22,9 +22,10 @@ * $Id$ */ -#include +#include "include/opl.h" #include "include/cheatman.h" #include "include/ioman.h" +#include static int gEnableCheat; // Enables PS2RD Cheat Engine - 0 for Off, 1 for On static int gCheatMode; // Cheat Mode - 0 Enable all cheats, 1 Cheats selected by user diff --git a/src/config.c b/src/config.c index c9ac92d73..8844ba0ed 100644 --- a/src/config.c +++ b/src/config.c @@ -8,7 +8,6 @@ #include "include/util.h" #include "include/ioman.h" #include "include/sound.h" -#include // FIXME: We should not need this function. // Use newlib's 'stat' to get GMT time. diff --git a/src/dia.c b/src/dia.c index 36cc84440..2936201dd 100644 --- a/src/dia.c +++ b/src/dia.c @@ -5,7 +5,7 @@ */ #include "include/opl.h" -#include "include/dia.h" +#include "include/dialogs.h" #include "include/gui.h" #include "include/lang.h" #include "include/pad.h" diff --git a/src/dialogs.c b/src/dialogs.c index ccb946611..344469ccc 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -1,12 +1,9 @@ -#include "include/dialogs.h" #include "include/opl.h" -#include "include/dia.h" +#include "include/dialogs.h" #include "include/lang.h" #include "include/gui.h" #include "include/guigame.h" -#include - // Network Config Menu struct UIItem diaNetConfig[] = { {UI_LABEL, 0, 1, 1, -1, 0, 0, {.label = {NULL, _STR_NETCONFIG}}}, diff --git a/src/ethsupport.c b/src/ethsupport.c index f0462fa42..26fd9da1d 100644 --- a/src/ethsupport.c +++ b/src/ethsupport.c @@ -1,8 +1,7 @@ #include "include/opl.h" +#include "include/mcemu.h" #include "include/lang.h" #include "include/gui.h" -#include "include/supportbase.h" -#include "include/ethsupport.h" #include "include/util.h" #include "include/renderman.h" #include "include/themes.h" @@ -12,9 +11,13 @@ #include "include/extern_irx.h" #include "include/cheatman.h" #include "modules/iopcore/common/cdvd_config.h" +#include "include/ethsupport.h" #define NEWLIB_PORT_AWARE #include // fileXioDevctl(ethBase, SMB_***) +#include +#include +#include #include "include/nbns.h" #include "httpclient.h" diff --git a/src/gui.c b/src/gui.c index 1f5874b37..eea4488e7 100644 --- a/src/gui.c +++ b/src/gui.c @@ -5,9 +5,9 @@ */ #include "include/opl.h" +#include "include/dialogs.h" #include "include/gui.h" #include "include/renderman.h" -#include "include/menu.h" #include "include/fntsys.h" #include "include/ioman.h" #include "include/lang.h" @@ -23,8 +23,6 @@ #include "include/sound.h" #include "include/guigame.h" -#include -#include #include // Last Played Auto Start diff --git a/src/guigame.c b/src/guigame.c index 8fa079a48..18ab6904a 100644 --- a/src/guigame.c +++ b/src/guigame.c @@ -4,12 +4,11 @@ */ #include "include/opl.h" +#include "include/dialogs.h" #include "include/gui.h" #include "include/ioman.h" #include "include/lang.h" #include "include/pad.h" -#include "include/config.h" -#include "include/ethsupport.h" #include "include/compatupd.h" #include "include/cheatman.h" #include "include/system.h" diff --git a/src/hdd.c b/src/hdd.c index 9f050b731..2b6130eaa 100644 --- a/src/hdd.c +++ b/src/hdd.c @@ -1,3 +1,4 @@ + #include "include/opl.h" #include "include/hdd.h" #include "include/ioman.h" @@ -5,6 +6,7 @@ #define NEWLIB_PORT_AWARE #include +#include "opl-hdd-ioctl.h" typedef struct // size = 1024 { diff --git a/src/hddsupport.c b/src/hddsupport.c index 7e58fdf96..5a771c50a 100644 --- a/src/hddsupport.c +++ b/src/hddsupport.c @@ -1,9 +1,7 @@ -#include "sys/fcntl.h" #include "include/opl.h" #include "include/lang.h" #include "include/gui.h" #include "include/supportbase.h" -#include "include/hddsupport.h" #include "include/util.h" #include "include/themes.h" #include "include/textures.h" @@ -18,6 +16,8 @@ #include // FIO_MT_RDWR #include +#include +#include "opl-hdd-ioctl.h" #define OPL_HDD_MODE_PS2LOGO_OFFSET 0x17F8 diff --git a/src/ioman.c b/src/ioman.c index 0945672d2..c9e4c1ffe 100644 --- a/src/ioman.c +++ b/src/ioman.c @@ -1,10 +1,5 @@ #include "include/opl.h" #include "include/ioman.h" -#include -#include -#include -#include -#include #ifdef __EESIO_DEBUG #include #endif diff --git a/src/menu.c b/src/menu.c index 506a35b5b..47db6b27c 100644 --- a/src/menu.c +++ b/src/menu.c @@ -5,8 +5,7 @@ */ #include "include/opl.h" -#include "include/menu.h" -#include "include/iosupport.h" +#include "include/dia.h" #include "include/renderman.h" #include "include/fntsys.h" #include "include/lang.h" diff --git a/src/opl.c b/src/opl.c index 6bb36495f..ca6f2a233 100644 --- a/src/opl.c +++ b/src/opl.c @@ -11,24 +11,15 @@ #include "include/renderman.h" #include "include/lang.h" #include "include/themes.h" -#include "include/textures.h" #include "include/pad.h" -#include "include/texcache.h" -#include "include/dia.h" #include "include/dialogs.h" -#include "include/menu.h" #include "include/system.h" -#include "include/debug.h" #include "include/config.h" #include "include/util.h" #include "include/compatupd.h" #include "include/extern_irx.h" #include "httpclient.h" - -#include "include/supportbase.h" -#include "include/bdmsupport.h" #include "include/ethsupport.h" -#include "include/hddsupport.h" #include "include/appsupport.h" #include "include/cheatman.h" @@ -41,14 +32,19 @@ #include // iox_stat_t int configGetStat(config_set_t *configSet, iox_stat_t *stat); -#include #ifdef PADEMU #include #include #endif +#include +#include +#include +#include + #ifdef __EESIO_DEBUG #include "SIOCookie.h" +#include "include/debug.h" #define LOG_INIT() ee_sio_start(38400, 0, 0, 0, 0, 1) #define LOG_ENABLE() \ do { \ @@ -1316,7 +1312,6 @@ static void compatUpdate(item_list_t *support, unsigned char mode, config_set_t clock.day = itob(stat.mtime[4]); clock.month = itob(stat.mtime[5]); clock.year = itob((stat.mtime[6] | ((unsigned short int)stat.mtime[7] << 8)) - 2000); - configConvertToGmtTime(&clock); mtime[0] = btoi(clock.year); // Year mtime[1] = btoi(clock.month) - 1; // Month @@ -1498,7 +1493,7 @@ static int loadLwnbdSvr(void) }; struct lwnbd_config config; - // deint audio lib while nbd server is running + // deinit audio lib and background music while nbd server is running audioEnd(); // block all io ops, wait for the ones still running to finish diff --git a/src/renderman.c b/src/renderman.c index 4d90251fc..f1e3a01de 100644 --- a/src/renderman.c +++ b/src/renderman.c @@ -4,8 +4,6 @@ Review OpenUsbLd README & LICENSE files for further details. */ -#include -#include #include "include/opl.h" #include "include/renderman.h" diff --git a/src/sound.c b/src/sound.c index cefb674ef..368ee0ede 100644 --- a/src/sound.c +++ b/src/sound.c @@ -3,20 +3,17 @@ Licenced under Academic Free License version 3.0 Review OpenPS2Loader README & LICENSE files for further details. */ - #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" #include +#pragma GCC diagnostic pop #include "include/sound.h" #include "include/opl.h" #include "include/ioman.h" #include "include/themes.h" -// Silence unused variable warnings from vorbisfile.h -static ov_callbacks OV_CALLBACKS_NOCLOSE __attribute__((unused)); -static ov_callbacks OV_CALLBACKS_STREAMONLY __attribute__((unused)); -static ov_callbacks OV_CALLBACKS_STREAMONLY_NOCLOSE __attribute__((unused)); - /*-- Theme Sound Effects ---------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------*/ diff --git a/src/submenu.c b/src/submenu.c index e630d47de..a39610be4 100644 --- a/src/submenu.c +++ b/src/submenu.c @@ -6,7 +6,6 @@ */ #include "include/opl.h" -#include "include/submenu.h" #include "include/lang.h" #include "include/themes.h" diff --git a/src/supportbase.c b/src/supportbase.c index 8e03f767b..fe4a882dc 100644 --- a/src/supportbase.c +++ b/src/supportbase.c @@ -1,14 +1,10 @@ #include "include/opl.h" -#include "include/lang.h" #include "include/util.h" -#include "include/iosupport.h" #include "include/system.h" -#include "include/supportbase.h" #include "include/ioman.h" #include "modules/iopcore/common/cdvd_config.h" #include "include/cheatman.h" #include "include/pggsm.h" -#include "include/cheatman.h" #include "include/ps2cnf.h" #include "include/gui.h" diff --git a/src/system.c b/src/system.c index 4a95c5b69..1a727ce22 100644 --- a/src/system.c +++ b/src/system.c @@ -11,19 +11,16 @@ #include "include/opl.h" #include "include/gui.h" #include "include/ethsupport.h" -#include "include/hddsupport.h" #include "include/util.h" #include "include/pad.h" +#include "include/mcemu.h" #include "include/system.h" #include "include/ioman.h" #include "include/ioprp.h" -#include "include/bdmsupport.h" #include "include/OSDHistory.h" #include "include/renderman.h" #include "include/extern_irx.h" #include "../ee_core/include/modules.h" -#include "../ee_core/include/coreconfig.h" -#include #include "include/pggsm.h" #include "include/cheatman.h" #include "include/xparam.h" @@ -35,6 +32,12 @@ #define NEWLIB_PORT_AWARE #include // fileXioInit, fileXioExit, fileXioDevctl +#include +#include +#include +#include +#include + typedef struct { diff --git a/src/texcache.c b/src/texcache.c index 2648b2846..2fa32db46 100644 --- a/src/texcache.c +++ b/src/texcache.c @@ -3,7 +3,6 @@ #include "include/textures.h" #include "include/ioman.h" #include "include/gui.h" -#include "include/util.h" #include "include/renderman.h" typedef struct diff --git a/src/themes.c b/src/themes.c index 338dcb1c7..4b55c2c60 100644 --- a/src/themes.c +++ b/src/themes.c @@ -3,7 +3,6 @@ #include "include/util.h" #include "include/gui.h" #include "include/renderman.h" -#include "include/textures.h" #include "include/ioman.h" #include "include/fntsys.h" #include "include/lang.h" diff --git a/src/util.c b/src/util.c index 1a2d51edf..607b3d262 100644 --- a/src/util.c +++ b/src/util.c @@ -8,12 +8,7 @@ #include "include/util.h" #include "include/ioman.h" #include "include/system.h" -#include -#include -#include -#include #include - #include "include/hdd.h" #include "../modules/isofs/zso.h" diff --git a/src/xparam.c b/src/xparam.c index a6524d538..ef2870fc6 100644 --- a/src/xparam.c +++ b/src/xparam.c @@ -8,6 +8,7 @@ #include "include/opl.h" #include "include/xparam.h" +#include char params_DCACHE_OFF[] = {'0', 'x', '1', '0', 0, '0', 0}; char params_CPU_DELAY[] = {'0', 'x', '6', 0, '0', 'x', '7', '8', '0', 0}; From 9d4e28683a6cab08ca57d3b8ab39f01d2a8e4b51 Mon Sep 17 00:00:00 2001 From: Wolf3s Date: Wed, 1 Jan 2025 17:52:10 -0300 Subject: [PATCH 3/6] Move all bin2c frontend embeded to imports.h. --- include/imports.h | 175 ++++++++++++++++++++++++++++++++++++++++++++++ src/bdmsupport.c | 2 +- src/debug.c | 2 +- src/ethsupport.c | 2 +- src/fntsys.c | 4 +- src/hddsupport.c | 2 +- src/opl.c | 4 +- src/sound.c | 28 +------- src/system.c | 2 +- src/themes.c | 6 +- src/util.c | 10 +-- 11 files changed, 191 insertions(+), 46 deletions(-) create mode 100644 include/imports.h diff --git a/include/imports.h b/include/imports.h new file mode 100644 index 000000000..520ba8721 --- /dev/null +++ b/include/imports.h @@ -0,0 +1,175 @@ +#ifndef IMPORTS_H +#define IMPORTS_H + +#define IMPORT_BIN2C(_n) \ + extern void *_n[]; \ + extern int size_##_n +// Try to keep this list alphabetical + +/* Irx modules */ + +IMPORT_BIN2C(apemodpatch_irx); + +IMPORT_BIN2C(audsrv_irx); + +IMPORT_BIN2C(bdm_irx); + +IMPORT_BIN2C(bdm_ata_cdvdman_irx); + +IMPORT_BIN2C(bdm_cdvdman_irx); + +IMPORT_BIN2C(bdm_mcemu_irx); + +IMPORT_BIN2C(bdmevent_irx); + +IMPORT_BIN2C(bdmfs_fatfs_irx); + +IMPORT_BIN2C(bt_pademu_irx); + +IMPORT_BIN2C(cdvdfsv_irx); + +IMPORT_BIN2C(cleareffects_irx); + +IMPORT_BIN2C(deci2_img); + +IMPORT_BIN2C(drvtif_irx); + +IMPORT_BIN2C(drvtif_ingame_irx); + +IMPORT_BIN2C(ds34bt_irx); + +IMPORT_BIN2C(ds34usb_irx); + +IMPORT_BIN2C(filexio_irx); + +IMPORT_BIN2C(genvmc_irx); + +IMPORT_BIN2C(hdd_cdvdman_irx); + +IMPORT_BIN2C(hdd_hdpro_cdvdman_irx); + +IMPORT_BIN2C(lwnbdsvr_irx); + +IMPORT_BIN2C(hdd_mcemu_irx); + +IMPORT_BIN2C(hdpro_atad_irx); + +IMPORT_BIN2C(httpclient_irx); + +IMPORT_BIN2C(IEEE1394_bd_irx); + +IMPORT_BIN2C(iLinkman_irx); + +IMPORT_BIN2C(imgdrv_irx); + +IMPORT_BIN2C(ingame_smstcpip_irx); + +IMPORT_BIN2C(iomanx_irx); + +IMPORT_BIN2C(ioptrap_irx); + +IMPORT_BIN2C(isofs_irx); + +IMPORT_BIN2C(iremsndpatch_irx); + +IMPORT_BIN2C(libsd_irx); + +IMPORT_BIN2C(mcman_irx); + +IMPORT_BIN2C(mcserv_irx); + +IMPORT_BIN2C(nbns_irx); + +IMPORT_BIN2C(netman_irx); + +IMPORT_BIN2C(f2techioppatch_irx); + +IMPORT_BIN2C(padman_irx); + +IMPORT_BIN2C(poweroff_irx); + +IMPORT_BIN2C(ppctty_irx); + +IMPORT_BIN2C(ps2atad_irx); + +IMPORT_BIN2C(ps2dev9_irx); + +IMPORT_BIN2C(ps2fs_irx); + +IMPORT_BIN2C(ps2hdd_irx); + +IMPORT_BIN2C(ps2ips_irx); + +IMPORT_BIN2C(ps2ip_irx); + +IMPORT_BIN2C(ps2link_irx); + +IMPORT_BIN2C(resetspu_irx); + +IMPORT_BIN2C(sio2man_irx); + +IMPORT_BIN2C(mx4sio_bd_irx); + +IMPORT_BIN2C(smap_irx); + +IMPORT_BIN2C(smap_ingame_irx); + +IMPORT_BIN2C(smb_mcemu_irx); + +IMPORT_BIN2C(smb_cdvdman_irx); + +IMPORT_BIN2C(smbinit_irx); + +IMPORT_BIN2C(smbman_irx); + +IMPORT_BIN2C(smsutils_irx); + +IMPORT_BIN2C(tifinet_irx); + +IMPORT_BIN2C(tifinet_ingame_irx); + +IMPORT_BIN2C(udptty_irx); + +IMPORT_BIN2C(udptty_ingame_irx); + +IMPORT_BIN2C(udnl_irx); + +IMPORT_BIN2C(usbd_irx); + +IMPORT_BIN2C(usbmass_bd_irx); + +IMPORT_BIN2C(usb_pademu_irx); + +IMPORT_BIN2C(xhdd_irx); + +/*-- Theme Sound Effects ---------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------------------------------*/ +IMPORT_BIN2C(boot_adp); + +IMPORT_BIN2C(bd_connect_adp); + +IMPORT_BIN2C(bd_disconnect_adp); + +IMPORT_BIN2C(cancel_adp); + +IMPORT_BIN2C(confirm_adp); + +IMPORT_BIN2C(cursor_adp); + +IMPORT_BIN2C(message_adp); + +IMPORT_BIN2C(transition_adp); + +/* icon images */ + +IMPORT_BIN2C(icon_sys); + +IMPORT_BIN2C(icon_icn); + +/* OPL Config */ +IMPORT_BIN2C(conf_theme_OPL_cfg); + +/* Raw Font */ +IMPORT_BIN2C(poeveticanew_raw); + +#endif diff --git a/src/bdmsupport.c b/src/bdmsupport.c index 5e5be0bff..047e7e4ea 100644 --- a/src/bdmsupport.c +++ b/src/bdmsupport.c @@ -6,7 +6,7 @@ #include "include/textures.h" #include "include/ioman.h" #include "include/system.h" -#include "include/extern_irx.h" +#include "include/imports.h" #include "include/cheatman.h" #include "include/sound.h" #include "modules/iopcore/common/cdvd_config.h" diff --git a/src/debug.c b/src/debug.c index 0456db54c..1f5e856ba 100644 --- a/src/debug.c +++ b/src/debug.c @@ -8,7 +8,7 @@ #include "include/ethsupport.h" #include "include/system.h" #include "include/ioman.h" -#include "include/extern_irx.h" +#include "include/imports.h" static u8 modulesLoaded = 0; diff --git a/src/ethsupport.c b/src/ethsupport.c index 26fd9da1d..383d094d7 100644 --- a/src/ethsupport.c +++ b/src/ethsupport.c @@ -8,7 +8,7 @@ #include "include/textures.h" #include "include/ioman.h" #include "include/system.h" -#include "include/extern_irx.h" +#include "include/imports.h" #include "include/cheatman.h" #include "modules/iopcore/common/cdvd_config.h" #include "include/ethsupport.h" diff --git a/src/fntsys.c b/src/fntsys.c index 35f50f10d..f0ddd558f 100644 --- a/src/fntsys.c +++ b/src/fntsys.c @@ -11,15 +11,13 @@ #include "include/utf8.h" #include "include/util.h" #include "include/atlas.h" +#include "include/imports.h" #include #include #include FT_FREETYPE_H -extern void *poeveticanew_raw; -extern int size_poeveticanew_raw; - /// Maximal count of atlases per font #define ATLAS_MAX 4 /// Atlas width in pixels diff --git a/src/hddsupport.c b/src/hddsupport.c index 5a771c50a..4c9a10ea2 100644 --- a/src/hddsupport.c +++ b/src/hddsupport.c @@ -7,7 +7,7 @@ #include "include/textures.h" #include "include/ioman.h" #include "include/system.h" -#include "include/extern_irx.h" +#include "include/imports.h" #include "include/cheatman.h" #include "modules/iopcore/common/cdvd_config.h" diff --git a/src/opl.c b/src/opl.c index ca6f2a233..af36eb92b 100644 --- a/src/opl.c +++ b/src/opl.c @@ -17,7 +17,7 @@ #include "include/config.h" #include "include/util.h" #include "include/compatupd.h" -#include "include/extern_irx.h" +#include "include/imports.h" #include "httpclient.h" #include "include/ethsupport.h" #include "include/appsupport.h" @@ -1493,7 +1493,7 @@ static int loadLwnbdSvr(void) }; struct lwnbd_config config; - // deinit audio lib and background music while nbd server is running + // deint audio lib while nbd server is running audioEnd(); // block all io ops, wait for the ones still running to finish diff --git a/src/sound.c b/src/sound.c index 368ee0ede..01628b7ac 100644 --- a/src/sound.c +++ b/src/sound.c @@ -9,38 +9,12 @@ #include #pragma GCC diagnostic pop +#include "include/imports.h" #include "include/sound.h" #include "include/opl.h" #include "include/ioman.h" #include "include/themes.h" -/*-- Theme Sound Effects ---------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------*/ - -extern unsigned char boot_adp[]; -extern unsigned int size_boot_adp; - -extern unsigned char cancel_adp[]; -extern unsigned int size_cancel_adp; - -extern unsigned char confirm_adp[]; -extern unsigned int size_confirm_adp; - -extern unsigned char cursor_adp[]; -extern unsigned int size_cursor_adp; - -extern unsigned char message_adp[]; -extern unsigned int size_message_adp; - -extern unsigned char transition_adp[]; -extern unsigned int size_transition_adp; - -extern unsigned char bd_connect_adp[]; -extern unsigned int size_bd_connect_adp; - -extern unsigned char bd_disconnect_adp[]; -extern unsigned int size_bd_disconnect_adp; - struct sfxEffect { const char *name; diff --git a/src/system.c b/src/system.c index 1a727ce22..fb945e7b7 100644 --- a/src/system.c +++ b/src/system.c @@ -19,7 +19,7 @@ #include "include/ioprp.h" #include "include/OSDHistory.h" #include "include/renderman.h" -#include "include/extern_irx.h" +#include "include/imports.h" #include "../ee_core/include/modules.h" #include "include/pggsm.h" #include "include/cheatman.h" diff --git a/src/themes.c b/src/themes.c index 4b55c2c60..07494da06 100644 --- a/src/themes.c +++ b/src/themes.c @@ -8,14 +8,12 @@ #include "include/lang.h" #include "include/pad.h" #include "include/sound.h" +#include "include/imports.h" #define MENU_POS_V 50 #define HINT_HEIGHT 32 #define DECORATOR_SIZE 20 -extern const char conf_theme_OPL_cfg; -extern u16 size_conf_theme_OPL_cfg; - theme_t *gTheme; static int screenWidth; @@ -1272,7 +1270,7 @@ static void thmLoad(const char *themePath) if (!themePath) { // No theme specified. Prepare and load the default theme. themeConfig = configAlloc(0, NULL, NULL); - configReadBuffer(themeConfig, &conf_theme_OPL_cfg, size_conf_theme_OPL_cfg); + configReadBuffer(themeConfig, (const char *)&conf_theme_OPL_cfg, size_conf_theme_OPL_cfg); } else { snprintf(path, sizeof(path), "%sconf_theme.cfg", themePath); themeConfig = configAlloc(0, NULL, path); diff --git a/src/util.c b/src/util.c index 607b3d262..f23a5f271 100644 --- a/src/util.c +++ b/src/util.c @@ -8,7 +8,12 @@ #include "include/util.h" #include "include/ioman.h" #include "include/system.h" +#include +#include +#include +#include #include +#include "include/imports.h" #include "include/hdd.h" #include "../modules/isofs/zso.h" @@ -16,11 +21,6 @@ extern int probed_fd; extern u32 probed_lba; -extern void *icon_sys; -extern int size_icon_sys; -extern void *icon_icn; -extern int size_icon_icn; - static int mcID = -1; void guiWarning(const char *text, int count); From 0d619d2e232e632d474697a4cb22e67a57f59c40 Mon Sep 17 00:00:00 2001 From: Wolf3s Date: Wed, 1 Jan 2025 17:56:20 -0300 Subject: [PATCH 4/6] [Refactor]: Cleanup the sound system and fix game launching when bgm is activated. --- include/sound.h | 5 ++--- src/appsupport.c | 3 +++ src/bdmsupport.c | 2 ++ src/config.c | 4 ++-- src/ethsupport.c | 3 +++ src/hddsupport.c | 3 +++ src/lang.c | 6 +++--- src/opl.c | 8 +++++--- src/sound.c | 27 +++++++++++++-------------- 9 files changed, 36 insertions(+), 25 deletions(-) diff --git a/include/sound.h b/include/sound.h index db18b486f..fb7f2cb13 100644 --- a/include/sound.h +++ b/include/sound.h @@ -24,8 +24,7 @@ void sfxPlay(int id); void bgmStart(void); void bgmStop(void); +void bgmEnd(); int isBgmPlaying(void); -void bgmMute(void); -void bgmUnMute(void); - +int bgmIsMuted(int muted); #endif diff --git a/src/appsupport.c b/src/appsupport.c index 25acbb5aa..c454feca6 100644 --- a/src/appsupport.c +++ b/src/appsupport.c @@ -6,6 +6,7 @@ #include "include/system.h" #include "include/ioman.h" #include "include/util.h" +#include "include/sound.h" #include @@ -357,6 +358,8 @@ static void appLaunchItem(item_list_t *itemList, int id, config_set_t *configSet char filename[256]; const char *argv1; + bgmEnd(); + // Retrieve configuration set by appGetConfig() configGetStrCopy(configSet, CONFIG_ITEM_STARTUP, filename, sizeof(filename)); diff --git a/src/bdmsupport.c b/src/bdmsupport.c index 047e7e4ea..9633100ad 100644 --- a/src/bdmsupport.c +++ b/src/bdmsupport.c @@ -326,6 +326,8 @@ void bdmLaunchGame(item_list_t *itemList, int id, config_set_t *configSet) bdm_device_data_t *pDeviceData = NULL; + bgmEnd(); + if (gAutoLaunchBDMGame == NULL) { pDeviceData = (bdm_device_data_t *)itemList->priv; game = &pDeviceData->bdmGames[id]; diff --git a/src/config.c b/src/config.c index 8844ba0ed..b38b40411 100644 --- a/src/config.c +++ b/src/config.c @@ -544,7 +544,7 @@ int configWrite(config_set_t *configSet) if (fileBuffer) { char line[512]; - bgmMute(); + bgmIsMuted(1); struct config_value_t *cur = configSet->head; while (cur) { if ((cur->key[0] != '\0') && (cur->key[0] != '#')) { @@ -558,7 +558,7 @@ int configWrite(config_set_t *configSet) closeFileBuffer(fileBuffer); configSet->modified = 0; - bgmUnMute(); + bgmIsMuted(0); return 1; } return 0; diff --git a/src/ethsupport.c b/src/ethsupport.c index 383d094d7..02dfb7bda 100644 --- a/src/ethsupport.c +++ b/src/ethsupport.c @@ -12,6 +12,7 @@ #include "include/cheatman.h" #include "modules/iopcore/common/cdvd_config.h" #include "include/ethsupport.h" +#include "include/sound.h" #define NEWLIB_PORT_AWARE #include // fileXioDevctl(ethBase, SMB_***) @@ -584,6 +585,8 @@ static void ethLaunchGame(item_list_t *itemList, int id, config_set_t *configSet u32 layer1_start, layer1_offset; unsigned short int layer1_part; + bgmEnd(); + if (!gPCShareName[0]) { memcpy(gPCShareName, game->name, sizeof(gPCShareName)); ethULSizePrev = -2; diff --git a/src/hddsupport.c b/src/hddsupport.c index 4c9a10ea2..828031785 100644 --- a/src/hddsupport.c +++ b/src/hddsupport.c @@ -10,6 +10,7 @@ #include "include/imports.h" #include "include/cheatman.h" #include "modules/iopcore/common/cdvd_config.h" +#include "include/sound.h" #define NEWLIB_PORT_AWARE #include // fileXioFormat, fileXioMount, fileXioUmount, fileXioDevctl @@ -426,6 +427,8 @@ void hddLaunchGame(item_list_t *itemList, int id, config_set_t *configSet) hdl_game_info_t *game; struct cdvdman_settings_hdd *settings; + bgmEnd(); + if (gAutoLaunchGame == NULL) game = &hddGames.games[id]; else diff --git a/src/lang.c b/src/lang.c index 24d386d96..22ca90b01 100644 --- a/src/lang.c +++ b/src/lang.c @@ -193,13 +193,13 @@ int lngSetGuiValue(int langID) { if (langID != -1) { if (guiLangID != langID) { - bgmMute(); + bgmIsMuted(1); if (langID != 0) { language_t *currLang = &languages[langID - 1]; if (lngLoadFromFile(currLang->filePath, currLang->name)) { guiLangID = langID; thmSetGuiValue(thmGetGuiValue(), 1); - bgmUnMute(); + bgmIsMuted(0); return 1; } } @@ -208,7 +208,7 @@ int lngSetGuiValue(int langID) // lang switched back to internalEnglish, reload default font fntLoadDefault(NULL); thmSetGuiValue(thmGetGuiValue(), 1); - bgmUnMute(); + bgmIsMuted(0); } } return 0; diff --git a/src/opl.c b/src/opl.c index af36eb92b..78bb592ff 100644 --- a/src/opl.c +++ b/src/opl.c @@ -1155,7 +1155,7 @@ void applyConfig(int themeID, int langID, int skipDeviceRefresh) int changed = rmSetMode(0); if (changed) { - bgmMute(); + bgmIsMuted(1); // reinit the graphics... thmReloadScreenExtents(); guiReloadScreenExtents(); @@ -1186,7 +1186,7 @@ void applyConfig(int themeID, int langID, int skipDeviceRefresh) } } - bgmUnMute(); + bgmIsMuted(0); #ifdef __DEBUG debugApplyConfig(); @@ -1493,8 +1493,9 @@ static int loadLwnbdSvr(void) }; struct lwnbd_config config; - // deint audio lib while nbd server is running + // deinit audio lib and background music while nbd server is running audioEnd(); + bgmEnd(); // block all io ops, wait for the ones still running to finish ioBlockOps(1); @@ -1627,6 +1628,7 @@ void deinit(int exception, int modeSelected) deinitAllSupport(exception, modeSelected); audioEnd(); + bgmEnd(); ioEnd(); guiEnd(); menuEnd(); diff --git a/src/sound.c b/src/sound.c index 01628b7ac..31feb88f2 100644 --- a/src/sound.c +++ b/src/sound.c @@ -1,5 +1,5 @@ /* - Copyright 2022, Thanks to SP193 + Copyright 2022-2025, Thanks to SP193 and KrahJohilto Licenced under Academic Free License version 3.0 Review OpenPS2Loader README & LICENSE files for further details. */ @@ -223,7 +223,8 @@ extern void *_gp; static int bgmThreadID, bgmIoThreadID; static int outSema, inSema; -static unsigned char terminateFlag, bgmIsPlaying; +static unsigned char terminateFlag; +static int bgmIsPlaying; static unsigned char rdPtr, wrPtr; static char bgmBuffer[BGM_RING_BUFFER_COUNT][BGM_RING_BUFFER_SIZE]; static volatile unsigned char bgmThreadRunning, bgmIoThreadRunning; @@ -477,22 +478,23 @@ void bgmStop(void) int isBgmPlaying(void) { - int ret = (int)bgmIsPlaying; - - return ret; + return bgmIsPlaying ? 1 : 0; } // HACK: BGM stutters while perfroming certain tasks, mute during these operations and unmute once completed. -void bgmMute(void) +int bgmIsMuted(int muted) { - if (audio_initialized) - audsrv_set_volume(0); + return audio_initialized ? audsrv_set_volume(muted ? 0 : gBGMVolume) : -1; } -void bgmUnMute(void) +void bgmEnd(void) { - if (audio_initialized) - audsrv_set_volume(gBGMVolume); + if (audio_initialized) { + if (gEnableBGM && isBgmPlaying()) { + gEnableBGM = 0; + bgmStop(); + } + } } /*-- General Audio ------------------------------------------------------------------------------------------------------ @@ -517,9 +519,6 @@ void audioEnd(void) return; } - if (gEnableBGM && isBgmPlaying()) - bgmStop(); - audsrv_quit(); audio_initialized = 0; } From f1570a2cbd43be47ba0d16f8923c82dee6fe96d0 Mon Sep 17 00:00:00 2001 From: Wolf3s Date: Sun, 5 Jan 2025 10:21:38 -0300 Subject: [PATCH 5/6] Fix gcc warnings and modularize audio system. --- Makefile | 2 +- include/audio.h | 8 ++++ include/cheatman.h | 2 +- include/sound.h | 4 -- src/audio.c | 40 ++++++++++++++++++++ src/cheatman.c | 2 +- src/gui.c | 3 +- src/opl.c | 1 + src/sound.c | 93 +++++++++++++--------------------------------- src/submenu.c | 2 +- src/supportbase.c | 3 +- 11 files changed, 83 insertions(+), 77 deletions(-) create mode 100644 include/audio.h create mode 100644 src/audio.c diff --git a/Makefile b/Makefile index 8ecfb1d0c..3a359b88d 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ ifneq ($(GIT_TAG),latest) endif endif -FRONTEND_OBJS = pad.o xparam.o fntsys.o renderman.o submenu.o menu.o OSDHistory.o system.o lang.o lang_internal.o config.o hdd.o dialogs.o \ +FRONTEND_OBJS = audio.o pad.o xparam.o fntsys.o renderman.o submenu.o menu.o OSDHistory.o system.o lang.o lang_internal.o config.o hdd.o dialogs.o \ dia.o ioman.o texcache.o themes.o supportbase.o bdmsupport.o ethsupport.o hddsupport.o zso.o lz4.o \ appsupport.o gui.o guigame.o textures.o opl.o atlas.o nbns.o httpclient.o gsm.o cheatman.o sound.o ps2cnf.o diff --git a/include/audio.h b/include/audio.h new file mode 100644 index 000000000..6ae700325 --- /dev/null +++ b/include/audio.h @@ -0,0 +1,8 @@ +#ifndef __AUDIO_H +#define __AUDIO_H + +void audioInit(void); +void audioEnd(void); +void audioSetVolume(int sfx); + +#endif \ No newline at end of file diff --git a/include/cheatman.h b/include/cheatman.h index 0ae082756..864249a2b 100644 --- a/include/cheatman.h +++ b/include/cheatman.h @@ -62,7 +62,7 @@ extern cheat_entry_t gCheats[MAX_CODES]; void InitCheatsConfig(config_set_t *configSet); int GetCheatsEnabled(void); -const u32 *GetCheatsList(void); +u32 *GetCheatsList(void); int load_cheats(const char *cheatfile); void set_cheats_list(void); diff --git a/include/sound.h b/include/sound.h index fb7f2cb13..798445116 100644 --- a/include/sound.h +++ b/include/sound.h @@ -14,10 +14,6 @@ enum SFX { SFX_COUNT }; -void audioInit(void); -void audioEnd(void); -void audioSetVolume(void); - int sfxInit(int bootSnd); int sfxGetSoundDuration(int id); void sfxPlay(int id); diff --git a/src/audio.c b/src/audio.c new file mode 100644 index 000000000..fb3160a13 --- /dev/null +++ b/src/audio.c @@ -0,0 +1,40 @@ +/* + Copyright 2022-2025, Thanks to SP193 and KrahJohilto + Copyright 2025 André Guilherme(Wofl3s) + Licenced under Academic Free License version 3.0 + Review OpenPS2Loader README & LICENSE files for further details. + */ + +#include + +#include "include/audio.h" +#include "include/opl.h" +#include "include/ioman.h" + +/*-- General Audio ------------------------------------------------------------------------------------------------------ +-----------------------------------------------------------------------------------------------------------------------------*/ + +void audioInit(void) +{ + if (audsrv_init() != 0) { + LOG("AUDIO: Failed to initialize audsrv\n"); + LOG("AUDIO: Audsrv returned error string: %s\n", audsrv_get_error_string()); + return; + } +} + +void audioEnd(void) +{ + audsrv_quit(); +} + +void audioSetVolume(int sfx) +{ + int i; + + for (i = 1; i < sfx; i++) + audsrv_adpcm_set_volume(i, gSFXVolume); + + audsrv_adpcm_set_volume(0, gBootSndVolume); + audsrv_set_volume(gBGMVolume); +} diff --git a/src/cheatman.c b/src/cheatman.c index cbe3a760e..808c8118c 100644 --- a/src/cheatman.c +++ b/src/cheatman.c @@ -59,7 +59,7 @@ int GetCheatsEnabled(void) return gEnableCheat; } -const u32 *GetCheatsList(void) +u32 *GetCheatsList(void) { return gCheatList; } diff --git a/src/gui.c b/src/gui.c index eea4488e7..2b7361e1a 100644 --- a/src/gui.c +++ b/src/gui.c @@ -20,6 +20,7 @@ #include "include/compatupd.h" #include "include/pggsm.h" #include "include/cheatman.h" +#include "include/audio.h" #include "include/sound.h" #include "include/guigame.h" @@ -882,7 +883,7 @@ static void guiSetAudioSettingsState(void) diaGetInt(diaAudioConfig, CFG_BOOT_SND_VOLUME, &gBootSndVolume); diaGetInt(diaAudioConfig, CFG_BGM_VOLUME, &gBGMVolume); diaGetString(diaAudioConfig, CFG_DEFAULT_BGM_PATH, gDefaultBGMPath, sizeof(gDefaultBGMPath)); - audioSetVolume(); + audioSetVolume(SFX_COUNT); if (gEnableBGM && !isBgmPlaying()) bgmStart(); diff --git a/src/opl.c b/src/opl.c index 78bb592ff..926be5b3d 100644 --- a/src/opl.c +++ b/src/opl.c @@ -23,6 +23,7 @@ #include "include/appsupport.h" #include "include/cheatman.h" +#include "include/audio.h" #include "include/sound.h" #include "include/xparam.h" diff --git a/src/sound.c b/src/sound.c index 31feb88f2..24cdf2eea 100644 --- a/src/sound.c +++ b/src/sound.c @@ -10,6 +10,7 @@ #pragma GCC diagnostic pop #include "include/imports.h" +#include "include/audio.h" #include "include/sound.h" #include "include/opl.h" #include "include/ioman.h" @@ -38,6 +39,29 @@ static struct sfxEffect sfx_files[SFX_COUNT] = { static struct audsrv_adpcm_t sfx[SFX_COUNT]; static int audio_initialized = 0; +/*-- Theme Background Music ------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------------------------------*/ + +#define BGM_RING_BUFFER_COUNT 16 +#define BGM_RING_BUFFER_SIZE 4096 +#define BGM_THREAD_BASE_PRIO 0x40 +#define BGM_THREAD_STACK_SIZE 0x1000 + +extern void *_gp; + +static int bgmThreadID, bgmIoThreadID; +static int outSema, inSema; +static unsigned char terminateFlag; +static int bgmIsPlaying; +static unsigned char rdPtr, wrPtr; +static char bgmBuffer[BGM_RING_BUFFER_COUNT][BGM_RING_BUFFER_SIZE]; +static volatile unsigned char bgmThreadRunning, bgmIoThreadRunning; + +static u8 bgmThreadStack[BGM_THREAD_STACK_SIZE] __attribute__((aligned(16))); +static u8 bgmIoThreadStack[BGM_THREAD_STACK_SIZE] __attribute__((aligned(16))); + +static OggVorbis_File *vorbisFile; + // Returns 0 if the specified file was read. The sfxEffect structure will not be updated unless the file is successfully read. static int sfxRead(const char *full_path, struct sfxEffect *sfx) { @@ -148,7 +172,7 @@ int sfxInit(int bootSnd) audsrv_adpcm_init(); sfxInitDefaults(); - audioSetVolume(); + audioSetVolume(SFX_COUNT); // Check default theme is not current theme int themeID = thmGetGuiValue(); @@ -211,29 +235,6 @@ void sfxPlay(int id) } } -/*-- Theme Background Music ------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------*/ - -#define BGM_RING_BUFFER_COUNT 16 -#define BGM_RING_BUFFER_SIZE 4096 -#define BGM_THREAD_BASE_PRIO 0x40 -#define BGM_THREAD_STACK_SIZE 0x1000 - -extern void *_gp; - -static int bgmThreadID, bgmIoThreadID; -static int outSema, inSema; -static unsigned char terminateFlag; -static int bgmIsPlaying; -static unsigned char rdPtr, wrPtr; -static char bgmBuffer[BGM_RING_BUFFER_COUNT][BGM_RING_BUFFER_SIZE]; -static volatile unsigned char bgmThreadRunning, bgmIoThreadRunning; - -static u8 bgmThreadStack[BGM_THREAD_STACK_SIZE] __attribute__((aligned(16))); -static u8 bgmIoThreadStack[BGM_THREAD_STACK_SIZE] __attribute__((aligned(16))); - -static OggVorbis_File *vorbisFile; - static void bgmThread(void *arg) { bgmThreadRunning = 1; @@ -495,46 +496,4 @@ void bgmEnd(void) bgmStop(); } } -} - -/*-- General Audio ------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------*/ - -void audioInit(void) -{ - if (!audio_initialized) { - if (audsrv_init() != 0) { - LOG("AUDIO: Failed to initialize audsrv\n"); - LOG("AUDIO: Audsrv returned error string: %s\n", audsrv_get_error_string()); - return; - } - audio_initialized = 1; - } -} - -void audioEnd(void) -{ - if (!audio_initialized) { - LOG("AUDIO: %s: ERROR: not initialized!\n", __FUNCTION__); - return; - } - - audsrv_quit(); - audio_initialized = 0; -} - -void audioSetVolume(void) -{ - int i; - - if (!audio_initialized) { - LOG("AUDIO: %s: ERROR: not initialized!\n", __FUNCTION__); - return; - } - - for (i = 1; i < SFX_COUNT; i++) - audsrv_adpcm_set_volume(i, gSFXVolume); - - audsrv_adpcm_set_volume(0, gBootSndVolume); - audsrv_set_volume(gBGMVolume); -} +} \ No newline at end of file diff --git a/src/submenu.c b/src/submenu.c index a39610be4..0edd63990 100644 --- a/src/submenu.c +++ b/src/submenu.c @@ -1,6 +1,6 @@ /* Copyright 2009, Ifcaro & volca - Copyright 2024-2025, André Guilherme + Copyright 2024-2025, André Guilherme(Wolf3s) Licenced under Academic Free License version 3.0 Review OpenUsbLd README & LICENSE files for further details. */ diff --git a/src/supportbase.c b/src/supportbase.c index fe4a882dc..a31ad6f8f 100644 --- a/src/supportbase.c +++ b/src/supportbase.c @@ -330,8 +330,9 @@ static int scanForISO(char *path, char type, struct game_list_t **glist) if (MountFD < 0 || GetStartupExecName("iso:/SYSTEM.CNF;1", startup, GAME_STARTUP_MAX - 1) != 0) { fileXioUmount("iso:"); - free(next); *glist = next->next; + free(next); + next = NULL; continue; } From e3420cfedaf92bbec3dfeaa66f82dc0f8ee4fa3b Mon Sep 17 00:00:00 2001 From: Wolf3s Date: Tue, 7 Jan 2025 12:57:09 -0300 Subject: [PATCH 6/6] Big cleanup(Part 1). --- .clang-format-ignore | 2 +- include/appsupport.h | 24 --- include/audio.h | 3 +- include/bdmsupport.h | 22 +- include/config.h | 6 +- include/ethsupport.h | 8 +- include/hdd.h | 96 +++------ include/hddsupport.h | 41 ---- include/iosupport.h | 2 - include/opl.h | 28 +-- include/supportbase.h | 37 ++++ include/themes.h | 1 + include/util.h | 26 --- src/appsupport.c | 285 +++++++++++++++++++++++-- src/audio.c | 45 +++- src/bdmsupport.c | 28 ++- src/config.c | 106 ++++++++-- src/dia.c | 3 + src/dialogs.c | 3 + src/ethsupport.c | 36 ++-- src/fntsys.c | 3 +- src/gui.c | 8 +- src/hdd.c | 75 ++++++- src/hddsupport.c | 7 + src/lang.c | 10 +- src/menu.c | 3 + src/opl.c | 331 +++-------------------------- src/sound.c | 10 +- src/submenu.c | 1 + src/supportbase.c | 481 +++++++++++++++++++++++++++++++++++++++++- src/system.c | 6 +- src/texcache.c | 2 + src/themes.c | 4 +- src/util.c | 481 +----------------------------------------- 34 files changed, 1151 insertions(+), 1073 deletions(-) diff --git a/.clang-format-ignore b/.clang-format-ignore index ac3296aac..e04f186f7 100644 --- a/.clang-format-ignore +++ b/.clang-format-ignore @@ -1,4 +1,4 @@ ./modules/isofs/lz4.c ./modules/isofs/lz4.h ./modules/network/lwNBD -./thirdparty/clang-format-lint-action +./thirdparty/clang-format-lint-action \ No newline at end of file diff --git a/include/appsupport.h b/include/appsupport.h index 66a6074eb..0f04e6a34 100644 --- a/include/appsupport.h +++ b/include/appsupport.h @@ -1,30 +1,6 @@ #ifndef __APP_SUPPORT_H #define __APP_SUPPORT_H -#define APP_MODE_UPDATE_DELAY 240 - -#define APP_TITLE_MAX 128 -#define APP_PATH_MAX 128 -#define APP_BOOT_MAX 64 -#define APP_ARGV1_MAX 128 - -#define APP_CONFIG_TITLE "title" -#define APP_CONFIG_BOOT "boot" -#define APP_CONFIG_ARGV1 "argv1" - -#define APP_TITLE_CONFIG_FILE "title.cfg" - -typedef struct -{ - char title[APP_TITLE_MAX + 1]; - char path[APP_PATH_MAX + 1]; - char boot[APP_BOOT_MAX + 1]; - char argv1[APP_ARGV1_MAX + 1]; - u8 legacy; -} app_info_t; - -void appInit(); item_list_t *appGetObject(int initOnly); -void appPostUpdateCallback(int mode); #endif diff --git a/include/audio.h b/include/audio.h index 6ae700325..a983b7ff4 100644 --- a/include/audio.h +++ b/include/audio.h @@ -3,6 +3,7 @@ void audioInit(void); void audioEnd(void); -void audioSetVolume(int sfx); +void audioSetVolume(); +void audioSetSfxVolume(int sfx); #endif \ No newline at end of file diff --git a/include/bdmsupport.h b/include/bdmsupport.h index c4ac9489a..265b18437 100644 --- a/include/bdmsupport.h +++ b/include/bdmsupport.h @@ -1,24 +1,6 @@ #ifndef __BDM_SUPPORT_H #define __BDM_SUPPORT_H -#define BDM_MODE_UPDATE_DELAY MENU_UPD_DELAY_GENREFRESH - -typedef struct -{ - int active; /* Activation flag */ - u64 start_sector; /* Start sector of vmc file */ - int flags; /* Card flag */ - vmc_spec_t specs; /* Card specifications */ -} bdm_vmc_infos_t; - -#define MAX_BDM_DEVICES 5 - -#define BDM_TYPE_UNKNOWN -1 -#define BDM_TYPE_USB 0 -#define BDM_TYPE_ILINK 1 -#define BDM_TYPE_SDC 2 -#define BDM_TYPE_ATA 3 - typedef struct { int massDeviceIndex; // Underlying device index backing the mass fs partition, ex: usb0 = 0, usb1 = 1, etc. @@ -38,10 +20,10 @@ typedef struct unsigned char ForceRefresh; } bdm_device_data_t; -void bdmInit(); +extern bdm_device_data_t *gAutoLaunchDeviceData; + int bdmFindPartition(char *target, const char *name, int write); void bdmLoadModules(void); -void bdmLaunchGame(item_list_t *itemList, int id, config_set_t *configSet); void bdmInitSemaphore(); void bdmEnumerateDevices(); diff --git a/include/config.h b/include/config.h index 3cf4be790..e733a206c 100644 --- a/include/config.h +++ b/include/config.h @@ -166,7 +166,6 @@ int configSetColor(config_set_t *configSet, const char *key, unsigned char *colo int configGetColor(config_set_t *configSet, const char *key, unsigned char *color); int configRemoveKey(config_set_t *configSet, const char *key); void configMerge(config_set_t *dest, const config_set_t *source); - void configGetDiscIDBinary(config_set_t *configSet, void *dst); int configRead(config_set_t *configSet); @@ -183,4 +182,9 @@ void configRemoveVMC(config_set_t *configSet, int slot); char *configGetDir(void); void configPrepareNotifications(char *prefix); +int configCheckBDM(int types); +int configCheckHDD(int types); + +int configCheckMC(int types); + #endif diff --git a/include/ethsupport.h b/include/ethsupport.h index 64a5b1378..d1781342e 100644 --- a/include/ethsupport.h +++ b/include/ethsupport.h @@ -12,13 +12,11 @@ typedef struct vmc_spec_t specs; /* Card specifications */ } smb_vmc_infos_t; -void ethInit(item_list_t *itemList); // Full initialization (Start ETH + SMB and apply configuration). GUI must be already initialized, used by GUI to start SMB mode. -void ethDeinitModules(void); // Module-only deinitialization, without the GUI's knowledge (for specific reasons, otherwise unused). -int ethLoadInitModules(void); // Initializes Ethernet and applies configuration. -void ethDisplayErrorStatus(void); // Displays the current error status (if any). GUI must be already initialized. +void ethDeinitModules(void); // Module-only deinitialization, without the GUI's knowledge (for specific reasons, otherwise unused). +int ethLoadInitModules(void); // Initializes Ethernet and applies configuration. +void ethDisplayErrorStatus(void); // Displays the current error status (if any). GUI must be already initialized. int ethGetNetConfig(u8 *ip_address, u8 *netmask, u8 *gateway); int ethApplyConfig(void); -int ethGetDHCPStatus(void); item_list_t *ethGetObject(int initOnly); #endif diff --git a/include/hdd.h b/include/hdd.h index 8704ca7a0..6df1a23c4 100644 --- a/include/hdd.h +++ b/include/hdd.h @@ -3,6 +3,11 @@ #include +#define HDL_GAME_NAME_MAX 64 + +// APA Partition +#define APA_IOCTL2_GETHEADER 0x6836 + typedef struct { u32 start; // Sector address @@ -11,49 +16,24 @@ typedef struct typedef struct { - u8 unused; - u8 sec; - u8 min; - u8 hour; - u8 day; - u8 month; - u16 year; -} ps2time_t; + char partition_name[APA_IDMAX + 1]; + char name[HDL_GAME_NAME_MAX + 1]; + char startup[8 + 1 + 3 + 1]; + u8 hdl_compat_flags; + u8 ops2l_compat_flags; + u8 dma_type; + u8 dma_mode; + u8 disctype; + u32 layer_break; + u32 start_sector; + u32 total_size_in_kb; +} hdl_game_info_t; typedef struct { - u32 checksum; - u32 magic; // APA_MAGIC - u32 next; - u32 prev; - char id[APA_IDMAX]; - char rpwd[APA_PASSMAX]; - char fpwd[APA_PASSMAX]; - u32 start; - u32 length; - u16 type; - u16 flags; - u32 nsub; - ps2time_t created; - u32 main; - u32 number; - u32 modver; - u32 pading1[7]; - char pading2[128]; - struct - { - char magic[32]; - u32 version; - u32 nsector; - ps2time_t created; - u32 osdStart; - u32 osdSize; - char pading3[200]; - } mbr; - apa_sub_t subs[APA_MAXSUB]; -} apa_header_t; - -#define PFS_INODE_MAX_BLOCKS 114 + u32 count; + hdl_game_info_t *games; +} hdl_games_list_t; typedef struct { @@ -62,29 +42,7 @@ typedef struct u16 count; } pfs_blockinfo_t; -typedef struct -{ - u32 checksum; - u32 magic; - pfs_blockinfo_t inode_block; - pfs_blockinfo_t next_segment; - pfs_blockinfo_t last_segment; - pfs_blockinfo_t unused; - pfs_blockinfo_t data[PFS_INODE_MAX_BLOCKS]; - u16 mode; - u16 attr; - u16 uid; - u16 gid; - ps2time_t atime; - ps2time_t ctime; - ps2time_t mtime; - u64 size; - u32 number_blocks; - u32 number_data; - u32 number_segdesg; - u32 subpart; - u32 reserved[4]; -} pfs_inode_t; +extern hdl_game_info_t *gAutoLaunchGame; int hddReadSectors(u32 lba, u32 nsectors, void *buf); @@ -94,4 +52,16 @@ int hddGetPartitionInfo(const char *name, apa_sub_t *parts); // Array should be max entries. int hddGetFileBlockInfo(const char *name, const apa_sub_t *subs, pfs_blockinfo_t *blocks, int max); +int hddCheck(void); +u32 hddGetTotalSectors(void); +int hddIs48bit(void); +int hddSetTransferMode(int type, int mode); +void hddSetIdleTimeout(int timeout); +void hddSetIdleImmediate(void); +int hddGetHDLGamelist(hdl_games_list_t *game_list); +void hddFreeHDLGamelist(hdl_games_list_t *game_list); +int hddSetHDLGameInfo(hdl_game_info_t *ginfo); +int hddDeleteHDLGame(hdl_game_info_t *ginfo); + + #endif diff --git a/include/hddsupport.h b/include/hddsupport.h index ef36032a2..698015f78 100644 --- a/include/hddsupport.h +++ b/include/hddsupport.h @@ -1,36 +1,6 @@ #ifndef __HDD_SUPPORT_H #define __HDD_SUPPORT_H -#include "include/hdd.h" - -#define HDD_MODE_UPDATE_DELAY MENU_UPD_DELAY_NOUPDATE - -#define HDL_GAME_NAME_MAX 64 - -// APA Partition -#define APA_IOCTL2_GETHEADER 0x6836 - -typedef struct -{ - char partition_name[APA_IDMAX + 1]; - char name[HDL_GAME_NAME_MAX + 1]; - char startup[8 + 1 + 3 + 1]; - u8 hdl_compat_flags; - u8 ops2l_compat_flags; - u8 dma_type; - u8 dma_mode; - u8 disctype; - u32 layer_break; - u32 start_sector; - u32 total_size_in_kb; -} hdl_game_info_t; - -typedef struct -{ - u32 count; - hdl_game_info_t *games; -} hdl_games_list_t; - typedef struct { u32 start; @@ -46,17 +16,6 @@ typedef struct vmc_spec_t specs; /* Card specifications */ } hdd_vmc_infos_t; -int hddCheck(void); -u32 hddGetTotalSectors(void); -int hddIs48bit(void); -int hddSetTransferMode(int type, int mode); -void hddSetIdleTimeout(int timeout); -void hddSetIdleImmediate(void); -int hddGetHDLGamelist(hdl_games_list_t *game_list); -void hddFreeHDLGamelist(hdl_games_list_t *game_list); -int hddSetHDLGameInfo(hdl_game_info_t *ginfo); -int hddDeleteHDLGame(hdl_game_info_t *ginfo); - void hddInit(); item_list_t *hddGetObject(int initOnly); void hddLoadModules(void); diff --git a/include/iosupport.h b/include/iosupport.h index e8c905a73..b480934ff 100644 --- a/include/iosupport.h +++ b/include/iosupport.h @@ -1,8 +1,6 @@ #ifndef __IOSUPPORT_H #define __IOSUPPORT_H -#include "include/config.h" - #define IO_MODE_SELECTED_NONE -1 #define IO_MODE_SELECTED_ALL MODE_COUNT diff --git a/include/opl.h b/include/opl.h index d480a5d7d..0f636ce20 100644 --- a/include/opl.h +++ b/include/opl.h @@ -3,23 +3,21 @@ #include #include -#include #include #include #include #include #include #include -#include #include #include #include +#include "include/config.h" #include "include/iosupport.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/mcemu.h" -#include "include/hddsupport.h" -#include "include/supportbase.h" -#include "include/bdmsupport.h" // Master password for disabling the parental lock. #define OPL_PARENTAL_LOCK_MASTER_PASS "989765" @@ -38,13 +36,6 @@ #define OPL_VMODE_CHANGE_CONFIRMATION_TIMEOUT_MS 10000 -int oplPath2Mode(const char *path); -int oplGetAppImage(const char *device, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm); -int oplScanApps(int (*callback)(const char *path, config_set_t *appConfig, void *arg), void *arg); -int oplShouldAppsUpdate(void); -config_set_t *oplGetLegacyAppsConfig(void); -config_set_t *oplGetLegacyAppsInfo(char *name); - void setErrorMessage(int strId); void setErrorMessageWithCode(int strId, int error); int loadConfig(int types); @@ -185,9 +176,6 @@ extern unsigned char gDefaultSelTextColor[3]; extern unsigned char gDefaultUITextColor[3]; // Launching games with args -extern hdl_game_info_t *gAutoLaunchGame; -extern base_game_info_t *gAutoLaunchBDMGame; -extern bdm_device_data_t *gAutoLaunchDeviceData; extern char *gHDDPrefix; extern char gOPLPart[128]; @@ -197,9 +185,6 @@ void setDefaultColors(void); #define MENU_ITEM_HEIGHT 19 -#include "include/submenu.h" -#include "include/menu.h" - typedef struct { item_list_t *support; @@ -211,11 +196,4 @@ typedef struct submenu_list_t *subMenu; } opl_io_module_t; -/* -BLURT output char blurttext[128]; -#define BLURT \ - snprintf(blurttext, sizeof(blurttext), "%s\\%s(%d)", __FILE__, __func__, __LINE__); \ - delay(10); -#define BLURT snprintf(blurttext, sizeof(blurttext), "%s(%d)", blurttext, __LINE__); -*/ #endif diff --git a/include/supportbase.h b/include/supportbase.h index 95a57ae02..59dea01ab 100644 --- a/include/supportbase.h +++ b/include/supportbase.h @@ -37,14 +37,35 @@ typedef struct u8 unknown2[10]; // Always zero } USBExtreme_game_entry_t; +typedef struct +{ + int fd; + int mode; + char *buffer; + unsigned int size; + unsigned int available; + char *lastPtr; + short allocResult; +} file_buffer_t; + +extern base_game_info_t *gAutoLaunchBDMGame; + int isValidIsoName(char *name, int *pNameLen); +int sbGetmcID(void); +void sbCheckMCFolder(void); + int sbIsSameSize(const char *prefix, int prevSize); +int sbGetFileSize(int fd); int sbCreateSemaphore(void); int sbReadList(base_game_info_t **list, const char *prefix, int *fsize, int *gamecount); +int sbListDir(char *path, const char *separator, int maxElem, int (*readEntry)(int index, const char *path, const char *separator, const char *name, unsigned char d_type)); int sbPrepare(base_game_info_t *game, config_set_t *configSet, int size_cdvdman, void **cdvdman_irx, int *patchindex); void sbUnprepare(void *pCommon); void sbRebuildULCfg(base_game_info_t **list, const char *prefix, int gamecount, int excludeID); +int sbCheckFile(char *path, int mode); void sbCreatePath(const base_game_info_t *game, char *path, const char *prefix, const char *sep, int part); +int sbOpenFile(char *path, int mode); +void *sbReadFile(char *path, int align, int *size); void sbDelete(base_game_info_t **list, const char *prefix, const char *sep, int gamecount, int id); void sbRename(base_game_info_t **list, const char *prefix, const char *sep, int gamecount, int id, char *newname); config_set_t *sbPopulateConfig(base_game_info_t *game, const char *prefix, const char *sep); @@ -57,4 +78,20 @@ int sbProbeISO9660_64(const char *path, base_game_info_t *game, u32 layer1_offse int sbLoadCheats(const char *path, const char *file); +/* File buffer IO functions */ + +/* size will be the maximum line size possible */ +file_buffer_t *sbOpenFileBuffer(char *fpath, int mode, short allocResult, unsigned int size); + +/* size will be the maximum line size possible */ +file_buffer_t *sbOpenFileBufferBuffer(short allocResult, const void *buffer, unsigned int size); + +int sbReadFileBuffer(file_buffer_t *fileBuffer, char **outBuf); + +void sbWriteFileBuffer(file_buffer_t *fileBuffer, char *inBuf, int size); + +void sbCloseFileBuffer(file_buffer_t *fileBuffer); + +int sbDeleteFolder(const char *folder); + #endif diff --git a/include/themes.h b/include/themes.h index 64ceb0f25..2aa5bd9af 100644 --- a/include/themes.h +++ b/include/themes.h @@ -3,6 +3,7 @@ #include "include/textures.h" #include "include/texcache.h" +#include "include/submenu.h" #include "include/menu.h" #define THM_MAX_FILES 64 diff --git a/include/util.h b/include/util.h index 5daad02c4..c8056217d 100644 --- a/include/util.h +++ b/include/util.h @@ -1,31 +1,6 @@ #ifndef __UTIL_H #define __UTIL_H -int getmcID(void); -int getFileSize(int fd); -void checkMCFolder(void); -int openFile(char *path, int mode); -void *readFile(char *path, int align, int *size); -int listDir(char *path, const char *separator, int maxElem, - int (*readEntry)(int index, const char *path, const char *separator, const char *name, unsigned char d_type)); - -typedef struct -{ - int fd; - int mode; - char *buffer; - unsigned int size; - unsigned int available; - char *lastPtr; - short allocResult; -} file_buffer_t; - -file_buffer_t *openFileBufferBuffer(short allocResult, const void *buffer, unsigned int size); -file_buffer_t *openFileBuffer(char *fpath, int mode, short allocResult, unsigned int size); -int readFileBuffer(file_buffer_t *readContext, char **outBuf); -void writeFileBuffer(file_buffer_t *fileBuffer, char *inBuf, int size); -void closeFileBuffer(file_buffer_t *fileBuffer); - int max(int a, int b); int min(int a, int b); int fromHex(char digit); @@ -44,7 +19,6 @@ enum CONSOLE_REGIONS { int InitConsoleRegionData(void); const char *GetSystemDataPath(void); char GetSystemFolderLetter(void); -int sysDeleteFolder(const char *folder); int CheckPS2Logo(int fd, u32 lba); diff --git a/src/appsupport.c b/src/appsupport.c index c454feca6..b1c635edc 100644 --- a/src/appsupport.c +++ b/src/appsupport.c @@ -1,20 +1,38 @@ #include "include/opl.h" #include "include/lang.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/gui.h" #include "include/appsupport.h" #include "include/themes.h" #include "include/system.h" #include "include/ioman.h" -#include "include/util.h" +#include "include/supportbase.h" #include "include/sound.h" #include -static int appForceUpdate = 1; -static int appItemCount = 0; +#define APP_MODE_UPDATE_DELAY 240 -static config_set_t *configApps; -static app_info_t *appsList; +#define APP_TITLE_MAX 128 +#define APP_PATH_MAX 128 +#define APP_BOOT_MAX 64 +#define APP_ARGV1_MAX 128 + +#define APP_CONFIG_TITLE "title" +#define APP_CONFIG_BOOT "boot" +#define APP_CONFIG_ARGV1 "argv1" + +#define APP_TITLE_CONFIG_FILE "title.cfg" + +typedef struct +{ + char title[APP_TITLE_MAX + 1]; + char path[APP_PATH_MAX + 1]; + char boot[APP_BOOT_MAX + 1]; + char argv1[APP_ARGV1_MAX + 1]; + u8 legacy; +} app_info_t; struct app_info_linked { @@ -22,11 +40,28 @@ struct app_info_linked app_info_t app; }; +static int appForceUpdate = 1; +static int appItemCount = 0; + +static int shouldAppsUpdate; + +static config_set_t *configApps; +static app_info_t *appsList; + // forward declaration static item_list_t appItemList; static void appFreeList(void); +static void appInit(); + +static int appPath2Mode(const char *path); +static int appGetConfigImage(const char *device, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm); +static int appScan(int (*callback)(const char *path, config_set_t *appConfig, void *arg), void *arg); +static int appShouldUpdate(void); +static config_set_t *appGetLegacyConfig(void); +static config_set_t *appGetLegacyConfigInfo(char *name); + static struct config_value_t *appGetConfigValue(int id) { struct config_value_t *cur = configApps->head; @@ -62,7 +97,7 @@ static float appGetELFSize(char *path) return 0.0f; } - size = getFileSize(fd); + size = sbGetFileSize(fd); close(fd); // Return size in MiB @@ -94,12 +129,12 @@ static char *appGetBoot(char *device, int max, char *path) return path; } -void appInit(item_list_t *itemList) +static void appInit(item_list_t *itemList) { LOG("APPSUPPORT Init\n"); appForceUpdate = 1; configGetInt(configGetByType(CONFIG_OPL), "app_frames_delay", &appItemList.delay); - configApps = oplGetLegacyAppsConfig(); + configApps = appGetLegacyConfig(); appsList = NULL; appItemList.enabled = 1; } @@ -120,11 +155,11 @@ static int appNeedsUpdate(item_list_t *itemList) appForceUpdate = 0; update = 1; } - if (oplShouldAppsUpdate()) + if (appShouldUpdate()) update = 1; if (update) - configApps = oplGetLegacyAppsConfig(); + configApps = appGetLegacyConfig(); return update; } @@ -247,7 +282,7 @@ static int appUpdateItemList(item_list_t *itemList) appItemCount += addAppsLegacyList(&appsLinkedList); // Scan devices for apps. - appItemCount += oplScanApps(&appScanCallback, &appsLinkedList); + appItemCount += appScan(&appScanCallback, &appsLinkedList); // Generate apps list if (appItemCount > 0) { @@ -317,7 +352,7 @@ static void appDeleteItem(item_list_t *itemList, int id) configApps->modified = 1; configWrite(configApps); } else { - sysDeleteFolder(appsList[id].path); + sbDeleteFolder(appsList[id].path); } appForceUpdate = 1; @@ -397,7 +432,7 @@ static void appLaunchItem(item_list_t *itemList, int id, config_set_t *configSet strcpy(partition, ""); // To keep the necessary device accessible, we will assume the mode that owns the device which contains the file to boot. - mode = oplPath2Mode(filename); + mode = appPath2Mode(filename); if (mode < 0) mode = APP_MODE; // Legacy apps mode on memory card (mc?:/*) @@ -422,7 +457,7 @@ static config_set_t *appGetConfig(item_list_t *itemList, int id) if (appsList[id].legacy) { struct config_value_t *cur = appGetConfigValue(id); - config = oplGetLegacyAppsInfo(appGetELFName(cur->val)); + config = appGetLegacyConfigInfo(appGetELFName(cur->val)); configRead(config); configSetStr(config, CONFIG_ITEM_NAME, appGetELFName(cur->val)); @@ -461,9 +496,9 @@ static int appGetImage(item_list_t *itemList, char *folder, int isRelative, char startup = appGetBoot(device, sizeof(device), value); if (!strcmp(folder, "ART")) - return oplGetAppImage(device, folder, isRelative, startup, suffix, resultTex, psm); + return appGetConfigImage(device, folder, isRelative, startup, suffix, resultTex, psm); else - return oplGetAppImage(device, folder, isRelative, value, suffix, resultTex, psm); + return appGetConfigImage(device, folder, isRelative, value, suffix, resultTex, psm); } static int appGetTextId(item_list_t *itemList) @@ -496,7 +531,223 @@ static void appShutdown(item_list_t *itemList) } } +extern opl_io_module_t list_support[MODE_COUNT]; /* TODO: Modularize apps support. */ + +// For resolving the mode, given an app's path +static int appPath2Mode(const char *path) +{ + char appsPath[APP_PATH_MAX]; + const char *blkdevnameend; + int i, blkdevnamelen; + item_list_t *listSupport; + + for (i = 0; i < MODE_COUNT; i++) { + opl_io_module_t *mod = &list_support[i]; + listSupport = mod->support; + if ((listSupport != NULL) && (listSupport->itemGetPrefix != NULL)) { + char *prefix = listSupport->itemGetPrefix(listSupport); + snprintf(appsPath, sizeof(appsPath), "%sAPPS", prefix); + + blkdevnameend = strchr(appsPath, ':'); + if (blkdevnameend != NULL) { + blkdevnamelen = (int)(blkdevnameend - appsPath); + + if (strncmp(path, appsPath, blkdevnamelen) == 0) + return listSupport->mode; + } + } + } + + return -1; +} + +static int appGetConfigImage(const char *device, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm) +{ + int i, remaining, elfbootmode; + char priority; + item_list_t *listSupport; + elfbootmode = -1; + if (device != NULL) { + elfbootmode = appPath2Mode(device); + if (elfbootmode >= 0) { + opl_io_module_t *mod = &list_support[elfbootmode]; + listSupport = mod->support; + + if ((listSupport != NULL) && (listSupport->enabled)) { + if (listSupport->itemGetImage(listSupport, folder, isRelative, value, suffix, resultTex, psm) >= 0) + return 0; + } + } + } + + // We search on ever devices from fatest to slowest. + for (remaining = MODE_COUNT, priority = 0; remaining > 0 && priority < 4; priority++) { + for (i = 0; i < MODE_COUNT; i++) { + opl_io_module_t *mod = &list_support[i]; + listSupport = mod->support; + + if (i == elfbootmode) + continue; + + if ((listSupport != NULL) && (listSupport->enabled) && (listSupport->appsPriority == priority)) { + if (listSupport->itemGetImage(listSupport, folder, isRelative, value, suffix, resultTex, psm) >= 0) + return 0; + remaining--; + } + } + } + + return -1; +} + +static int scanApps(int (*callback)(const char *path, config_set_t *appConfig, void *arg), void *arg, char *appsPath, int exception) +{ + struct dirent *pdirent; + DIR *pdir; + int count, ret; + config_set_t *appConfig; + char dir[APP_PATH_MAX]; + char path[APP_PATH_MAX]; + + count = 0; + if ((pdir = opendir(appsPath)) != NULL) { + while ((pdirent = readdir(pdir)) != NULL) { + if (exception && strchr(pdirent->d_name, '_') == NULL) + continue; + + if (strcmp(pdirent->d_name, ".") == 0 || strcmp(pdirent->d_name, "..") == 0) + continue; + + snprintf(dir, sizeof(dir), "%s/%s", appsPath, pdirent->d_name); + if (pdirent->d_type != DT_DIR) + continue; + + snprintf(path, sizeof(path), "%s/%s", dir, APP_TITLE_CONFIG_FILE); + appConfig = configAlloc(0, NULL, path); + if (appConfig != NULL) { + configRead(appConfig); + + ret = callback(dir, appConfig, arg); + configFree(appConfig); + + if (ret == 0) + count++; + else if (ret < 0) { // Stopped because of unrecoverable error. + break; + } + } + } + + closedir(pdir); + } else + LOG("APPS failed to open dir %s\n", appsPath); + + return count; +} + +static int appScan(int (*callback)(const char *path, config_set_t *appConfig, void *arg), void *arg) +{ + int i, count; + item_list_t *listSupport; + char appsPath[APP_PATH_MAX]; + count = 0; + for (i = 0; i < MODE_COUNT; i++) { + opl_io_module_t *mod = &list_support[i]; + listSupport = mod->support; + if ((listSupport != NULL) && (listSupport->enabled) && (listSupport->itemGetPrefix != NULL)) { + char *prefix = listSupport->itemGetPrefix(listSupport); + snprintf(appsPath, sizeof(appsPath), "%sAPPS", prefix); + count += scanApps(callback, arg, appsPath, 0); + } + } + + for (i = 0; i < 2; i++) { + snprintf(appsPath, sizeof(appsPath), "mc%d:", i); + count += scanApps(callback, arg, appsPath, 1); + } + + return count; +} + +static int appShouldUpdate(void) +{ + int result; + + result = shouldAppsUpdate; + shouldAppsUpdate = 0; + + return result; +} + +static config_set_t *appGetLegacyConfig(void) +{ + int i, fd; + item_list_t *listSupport; + config_set_t *appConfig; + char appsPath[128]; + + snprintf(appsPath, sizeof(appsPath), "mc?:OPL/conf_apps.cfg"); + fd = sbOpenFile(appsPath, O_RDONLY); + if (fd >= 0) { + appConfig = configAlloc(CONFIG_APPS, NULL, appsPath); + close(fd); + return appConfig; + } + + for (i = MODE_COUNT - 1; i >= 0; i--) { + opl_io_module_t *mod = &list_support[i]; + listSupport = mod->support; + if ((listSupport != NULL) && (listSupport->enabled) && (listSupport->itemGetPrefix != NULL)) { + char *prefix = listSupport->itemGetPrefix(listSupport); + snprintf(appsPath, sizeof(appsPath), "%sconf_apps.cfg", prefix); + + fd = sbOpenFile(appsPath, O_RDONLY); + if (fd >= 0) { + appConfig = configAlloc(CONFIG_APPS, NULL, appsPath); + close(fd); + return appConfig; + } + } + } + + /* Apps config not found on any device, go with last tested device. + Does not matter if the config file could be loaded or not */ + appConfig = configAlloc(CONFIG_APPS, NULL, appsPath); + + return appConfig; +} + +static config_set_t *appGetLegacyConfigInfo(char *name) +{ + int i, fd; + item_list_t *listSupport; + config_set_t *appConfig; + char appsPath[128]; + + for (i = MODE_COUNT - 1; i >= 0; i--) { + opl_io_module_t *mod = &list_support[i]; + listSupport = mod->support; + if ((listSupport != NULL) && (listSupport->enabled) && (listSupport->itemGetPrefix != NULL)) { + char *prefix = listSupport->itemGetPrefix(listSupport); + snprintf(appsPath, sizeof(appsPath), "%sCFG%s%s.cfg", prefix, i == ETH_MODE ? "\\" : "/", name); + + fd = sbOpenFile(appsPath, O_RDONLY); + if (fd >= 0) { + appConfig = configAlloc(0, NULL, appsPath); + close(fd); + return appConfig; + } + } + } + + /* Apps config not found on any device, go with last tested device. + Does not matter if the config file could be loaded or not */ + appConfig = configAlloc(0, NULL, appsPath); + + return appConfig; +} + static item_list_t appItemList = { APP_MODE, -1, 0, MODE_FLAG_NO_COMPAT | MODE_FLAG_NO_UPDATE, MENU_MIN_INACTIVE_FRAMES, APP_MODE_UPDATE_DELAY, NULL, NULL, &appGetTextId, NULL, &appInit, &appNeedsUpdate, &appUpdateItemList, &appGetItemCount, NULL, &appGetItemName, &appGetItemNameLength, &appGetItemStartup, &appDeleteItem, &appRenameItem, &appLaunchItem, - &appGetConfig, &appGetImage, &appCleanUp, &appShutdown, NULL, &appGetIconId}; + &appGetConfig, &appGetImage, &appCleanUp, &appShutdown, NULL, &appGetIconId}; \ No newline at end of file diff --git a/src/audio.c b/src/audio.c index fb3160a13..63ed017c7 100644 --- a/src/audio.c +++ b/src/audio.c @@ -7,34 +7,59 @@ #include -#include "include/audio.h" #include "include/opl.h" +#include "include/audio.h" #include "include/ioman.h" +extern int audio_initialized; /*-- General Audio ------------------------------------------------------------------------------------------------------ -----------------------------------------------------------------------------------------------------------------------------*/ void audioInit(void) { - if (audsrv_init() != 0) { - LOG("AUDIO: Failed to initialize audsrv\n"); - LOG("AUDIO: Audsrv returned error string: %s\n", audsrv_get_error_string()); - return; + if (!audio_initialized) { + if (audsrv_init() != 0) { + LOG("AUDIO: Failed to initialize audsrv\n"); + LOG("AUDIO: Audsrv returned error string: %s\n", audsrv_get_error_string()); + return; + } else { + audsrv_adpcm_init(); + } + audio_initialized = 1; } } void audioEnd(void) { + if (!audio_initialized) { + LOG("AUDIO: %s: ERROR: not initialized!\n", __FUNCTION__); + return; + } + audsrv_quit(); + audio_initialized = 0; } -void audioSetVolume(int sfx) +void audioSetVolume() { - int i; - - for (i = 1; i < sfx; i++) - audsrv_adpcm_set_volume(i, gSFXVolume); + if (!audio_initialized) { + LOG("AUDIO: %s: ERROR: not initialized!\n", __FUNCTION__); + return; + } audsrv_adpcm_set_volume(0, gBootSndVolume); audsrv_set_volume(gBGMVolume); } + +void audioSetSfxVolume(int sfx) +{ + int i; + + if (!audio_initialized) { + LOG("AUDIO: %s: ERROR: not initialized!\n", __FUNCTION__); + return; + } + + for (i = 1; i < sfx; i++) + audsrv_adpcm_set_volume(i, gSFXVolume); +} \ No newline at end of file diff --git a/src/bdmsupport.c b/src/bdmsupport.c index 9633100ad..745f7592b 100644 --- a/src/bdmsupport.c +++ b/src/bdmsupport.c @@ -1,5 +1,11 @@ #include "include/opl.h" +#include "include/hdd.h" +#include "include/hddsupport.h" +#include "include/supportbase.h" +#include "include/bdmsupport.h" #include "include/lang.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/gui.h" #include "include/util.h" #include "include/themes.h" @@ -18,15 +24,35 @@ #define NEWLIB_PORT_AWARE #include // fileXioIoctl, fileXioDevctl +#define MAX_BDM_DEVICES 5 + +#define BDM_TYPE_UNKNOWN -1 +#define BDM_TYPE_USB 0 +#define BDM_TYPE_ILINK 1 +#define BDM_TYPE_SDC 2 +#define BDM_TYPE_ATA 3 + +#define BDM_MODE_UPDATE_DELAY MENU_UPD_DELAY_GENREFRESH + +typedef struct +{ + int active; /* Activation flag */ + u64 start_sector; /* Start sector of vmc file */ + int flags; /* Card flag */ + vmc_spec_t specs; /* Card specifications */ +} bdm_vmc_infos_t; + static int iLinkModLoaded = 0; static int mx4sioModLoaded = 0; static int hddModLoaded = 0; static s32 bdmLoadModuleLock; -int bdmDeviceModeStarted; +static int bdmDeviceModeStarted; static item_list_t bdmDeviceList[MAX_BDM_DEVICES]; static int bdmDeviceListInitialized = 0; +bdm_device_data_t *gAutoLaunchDeviceData; + void bdmInitDevicesData(); int bdmUpdateDeviceData(item_list_t *itemList); diff --git a/src/config.c b/src/config.c index b38b40411..2082f92a6 100644 --- a/src/config.c +++ b/src/config.c @@ -5,9 +5,16 @@ */ #include "include/opl.h" +#include "include/submenu.h" +#include "include/menu.h" +#include "include/supportbase.h" #include "include/util.h" +#include "include/hdd.h" +#include "include/hddsupport.h" +#include "include/bdmsupport.h" #include "include/ioman.h" #include "include/sound.h" +#include "include/system.h" // FIXME: We should not need this function. // Use newlib's 'stat' to get GMT time. @@ -26,6 +33,8 @@ static const char *configFilenames[CONFIG_INDEX_COUNT] = { "conf_game.cfg", }; +static u8 isLoaded = 0; + static int strToColor(const char *string, unsigned char *color) { int cnt = 0, n = 0; @@ -164,7 +173,7 @@ static char cfgDevice[8]; char *configGetDir(void) { if (!strncmp(cfgDevice, "mc", 2)) { - cfgDevice[2] = getmcID(); + cfgDevice[2] = sbGetmcID(); } char *path = cfgDevice; @@ -410,10 +419,10 @@ static int configReadLegacyIP(void) config_set_t *configSet; char temp[16]; - int fd = openFile(legacyNetConfigPath, O_RDONLY); + int fd = sbOpenFile(legacyNetConfigPath, O_RDONLY); if (fd >= 0) { char ipconfig[256]; - int size = getFileSize(fd); + int size = sbGetFileSize(fd); read(fd, &ipconfig, size); close(fd); @@ -472,7 +481,7 @@ static int configReadFileBuffer(file_buffer_t *fileBuffer, config_set_t *configS char prefix[CONFIG_KEY_NAME_LEN]; memset(prefix, 0, sizeof(prefix)); - while (readFileBuffer(fileBuffer, &line)) { + while (sbReadFileBuffer(fileBuffer, &line)) { lineno++; char key[CONFIG_KEY_NAME_LEN], val[CONFIG_KEY_VALUE_LEN]; @@ -509,7 +518,7 @@ static int configReadFileBuffer(file_buffer_t *fileBuffer, config_set_t *configS int configReadBuffer(config_set_t *configSet, const void *buffer, int size) { int ret; - file_buffer_t *fileBuffer = openFileBufferBuffer(0, buffer, size); + file_buffer_t *fileBuffer = sbOpenFileBufferBuffer(0, buffer, size); if (!fileBuffer) { configSet->modified = 0; return 0; @@ -517,14 +526,14 @@ int configReadBuffer(config_set_t *configSet, const void *buffer, int size) ret = configReadFileBuffer(fileBuffer, configSet); - closeFileBuffer(fileBuffer); + sbCloseFileBuffer(fileBuffer); return ret; } int configRead(config_set_t *configSet) { int ret; - file_buffer_t *fileBuffer = openFileBuffer(configSet->filename, O_RDONLY, 0, 4096); + file_buffer_t *fileBuffer = sbOpenFileBuffer(configSet->filename, O_RDONLY, 0, 4096); if (!fileBuffer) { LOG("CONFIG No file %s.\n", configSet->filename); configSet->modified = 0; @@ -533,30 +542,30 @@ int configRead(config_set_t *configSet) ret = configReadFileBuffer(fileBuffer, configSet); - closeFileBuffer(fileBuffer); + sbCloseFileBuffer(fileBuffer); return ret; } int configWrite(config_set_t *configSet) { if (configSet->modified) { - file_buffer_t *fileBuffer = openFileBuffer(configSet->filename, O_WRONLY | O_CREAT | O_TRUNC, 0, 4096); + file_buffer_t *fileBuffer = sbOpenFileBuffer(configSet->filename, O_WRONLY | O_CREAT | O_TRUNC, 0, 4096); if (fileBuffer) { + bgmIsMuted(1); char line[512]; - bgmIsMuted(1); struct config_value_t *cur = configSet->head; while (cur) { if ((cur->key[0] != '\0') && (cur->key[0] != '#')) { snprintf(line, sizeof(line), "%s=%s\r\n", cur->key, cur->val); // add windows CR+LF (0x0D 0x0A) - writeFileBuffer(fileBuffer, line, strlen(line)); + sbWriteFileBuffer(fileBuffer, line, strlen(line)); } // and advance cur = cur->next; } - closeFileBuffer(fileBuffer); + sbCloseFileBuffer(fileBuffer); configSet->modified = 0; bgmIsMuted(0); return 1; @@ -645,3 +654,76 @@ void configRemoveVMC(config_set_t *configSet, int slot) snprintf(gkey, sizeof(gkey), "%s_%d", CONFIG_ITEM_VMC, slot); configRemoveKey(configSet, gkey); } + +int configCheckBDM(int types) +{ + char path[64]; + int value; + + // check USB + if (bdmFindPartition(path, "conf_opl.cfg", 0)) { + if (!isLoaded) { + configEnd(); + configInit(path); + value = configReadMulti(types); + config_set_t *configOPL = configGetByType(CONFIG_OPL); + configSetInt(configOPL, CONFIG_OPL_BDM_MODE, START_MODE_AUTO); + return value; + } else { + configSetMove(path); + return configWriteMulti(types); + } + } + + return -ENOENT; +} + +int configCheckHDD(int types) +{ + int value; + char path[64]; + + hddLoadModules(); + if (!isLoaded) { + hddLoadSupportModules(); + + snprintf(path, sizeof(path), "%sconf_opl.cfg", gHDDPrefix); + value = open(path, O_RDONLY); + if (value >= 0) { + close(value); + configEnd(); + configInit(gHDDPrefix); + value = configReadMulti(types); + config_set_t *configOPL = configGetByType(CONFIG_OPL); + configSetInt(configOPL, CONFIG_OPL_HDD_MODE, START_MODE_AUTO); + return value; + } + } else { + // Check that the formatted & usable HDD is connected. + if (hddCheck() == 0) { + configSetMove(gHDDPrefix); + return configWriteMulti(types); + } + } + + return -ENOENT; +} + +int configCheckMC(int types) +{ + if (!isLoaded) { + // At this point, the user has no loadable config files on any supported device, so try to find a device to save on. + // We don't want to get users into alternate mode for their very first launch of OPL (i.e no config file at all, but still want to save on MC) + // Check for a memory card inserted. + if (sysCheckMC() >= 0) { + configPrepareNotifications(gBaseMCDir); + showCfgPopup = 0; + return 0; + } + } else { + configSetMove(NULL); + return configWriteMulti(types); + } + + return -ENOENT; +} \ No newline at end of file diff --git a/src/dia.c b/src/dia.c index 2936201dd..27e688c45 100644 --- a/src/dia.c +++ b/src/dia.c @@ -5,7 +5,10 @@ */ #include "include/opl.h" +#include "include/dia.h" #include "include/dialogs.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/gui.h" #include "include/lang.h" #include "include/pad.h" diff --git a/src/dialogs.c b/src/dialogs.c index 344469ccc..d7c2d312a 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -1,6 +1,9 @@ #include "include/opl.h" +#include "include/dia.h" #include "include/dialogs.h" #include "include/lang.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/gui.h" #include "include/guigame.h" diff --git a/src/ethsupport.c b/src/ethsupport.c index 02dfb7bda..2cd29271d 100644 --- a/src/ethsupport.c +++ b/src/ethsupport.c @@ -1,6 +1,9 @@ #include "include/opl.h" +#include "include/supportbase.h" #include "include/mcemu.h" #include "include/lang.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/gui.h" #include "include/util.h" #include "include/renderman.h" @@ -162,6 +165,22 @@ static int ethSMBDisconnect(void) return 0; } +int ethGetDHCPStatus(void) +{ + t_ip_info ip_info; + int result; + + if ((result = ps2ip_getconfig("sm0", &ip_info)) >= 0) { + if (ip_info.dhcp_enabled) { + result = (ip_info.dhcp_status == DHCP_STATE_BOUND || (ip_info.dhcp_status == DHCP_STATE_OFF)); + } else + result = -1; + } + + return result; +} + + static void EthStatusCheckCb(s32 alarm_id, u16 time, void *common) { iSignalSema(*(int *)common); @@ -924,19 +943,4 @@ static int ethApplyIPConfig(void) } return result; -} - -int ethGetDHCPStatus(void) -{ - t_ip_info ip_info; - int result; - - if ((result = ps2ip_getconfig("sm0", &ip_info)) >= 0) { - if (ip_info.dhcp_enabled) { - result = (ip_info.dhcp_status == DHCP_STATE_BOUND || (ip_info.dhcp_status == DHCP_STATE_OFF)); - } else - result = -1; - } - - return result; -} +} \ No newline at end of file diff --git a/src/fntsys.c b/src/fntsys.c index f0ddd558f..ec0059a82 100644 --- a/src/fntsys.c +++ b/src/fntsys.c @@ -9,6 +9,7 @@ #include "include/renderman.h" #include "include/ioman.h" #include "include/utf8.h" +#include "include/supportbase.h" #include "include/util.h" #include "include/atlas.h" #include "include/imports.h" @@ -236,7 +237,7 @@ static int fntLoadSlot(font_t *font, char *path, int fontSize) fntInitSlot(font); if (path) { - buffer = readFile(path, -1, &bufferSize); + buffer = sbReadFile(path, -1, &bufferSize); if (!buffer) { LOG("FNTSYS Font file loading failed: %s\n", path); return FNT_ERROR; diff --git a/src/gui.c b/src/gui.c index 2b7361e1a..1dd57a810 100644 --- a/src/gui.c +++ b/src/gui.c @@ -5,6 +5,9 @@ */ #include "include/opl.h" +#include "include/submenu.h" +#include "include/menu.h" +#include "include/dia.h" #include "include/dialogs.h" #include "include/gui.h" #include "include/renderman.h" @@ -34,6 +37,7 @@ static int gCompletedOps; static int gTerminate; static int gInitComplete; + static gui_callback_t gFrameHook; static s32 gSemaId; @@ -713,6 +717,7 @@ void guiShowUIConfig(void) applyConfig(themeID, langID, 1); sfxInit(0); + audioInit(); if (gEnableBGM && !isBgmPlaying()) bgmStart(); @@ -883,7 +888,8 @@ static void guiSetAudioSettingsState(void) diaGetInt(diaAudioConfig, CFG_BOOT_SND_VOLUME, &gBootSndVolume); diaGetInt(diaAudioConfig, CFG_BGM_VOLUME, &gBGMVolume); diaGetString(diaAudioConfig, CFG_DEFAULT_BGM_PATH, gDefaultBGMPath, sizeof(gDefaultBGMPath)); - audioSetVolume(SFX_COUNT); + + audioSetVolume(); if (gEnableBGM && !isBgmPlaying()) bgmStart(); diff --git a/src/hdd.c b/src/hdd.c index 2b6130eaa..46bc22297 100644 --- a/src/hdd.c +++ b/src/hdd.c @@ -2,12 +2,58 @@ #include "include/opl.h" #include "include/hdd.h" #include "include/ioman.h" -#include "include/hddsupport.h" #define NEWLIB_PORT_AWARE #include +#include #include "opl-hdd-ioctl.h" +hdl_game_info_t *gAutoLaunchGame; + +typedef struct +{ + u8 unused; + u8 sec; + u8 min; + u8 hour; + u8 day; + u8 month; + u16 year; +} ps2time_t; + +typedef struct +{ + u32 checksum; + u32 magic; // APA_MAGIC + u32 next; + u32 prev; + char id[APA_IDMAX]; + char rpwd[APA_PASSMAX]; + char fpwd[APA_PASSMAX]; + u32 start; + u32 length; + u16 type; + u16 flags; + u32 nsub; + ps2time_t created; + u32 main; + u32 number; + u32 modver; + u32 pading1[7]; + char pading2[128]; + struct + { + char magic[32]; + u32 version; + u32 nsector; + ps2time_t created; + u32 osdStart; + u32 osdSize; + char pading3[200]; + } mbr; + apa_sub_t subs[APA_MAXSUB]; +} apa_header_t; + typedef struct // size = 1024 { u32 checksum; // HDL uses 0xdeadfeed magic here @@ -29,6 +75,33 @@ typedef struct // size = 1024 } part_specs[65]; } hdl_apa_header; +#define PFS_INODE_MAX_BLOCKS 114 + +typedef struct +{ + u32 checksum; + u32 magic; + pfs_blockinfo_t inode_block; + pfs_blockinfo_t next_segment; + pfs_blockinfo_t last_segment; + pfs_blockinfo_t unused; + pfs_blockinfo_t data[PFS_INODE_MAX_BLOCKS]; + u16 mode; + u16 attr; + u16 uid; + u16 gid; + ps2time_t atime; + ps2time_t ctime; + ps2time_t mtime; + u64 size; + u32 number_blocks; + u32 number_data; + u32 number_segdesg; + u32 subpart; + u32 reserved[4]; +} pfs_inode_t; + + #define HDL_GAME_DATA_OFFSET 0x100000 // Sector 0x800 in the extended attribute area. #define HDL_FS_MAGIC 0x1337 diff --git a/src/hddsupport.c b/src/hddsupport.c index 828031785..66ecdeeff 100644 --- a/src/hddsupport.c +++ b/src/hddsupport.c @@ -1,5 +1,8 @@ #include "include/opl.h" + #include "include/lang.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/gui.h" #include "include/supportbase.h" #include "include/util.h" @@ -20,7 +23,11 @@ #include #include "opl-hdd-ioctl.h" +#include "include/hdd.h" +#include "include/hddsupport.h" + #define OPL_HDD_MODE_PS2LOGO_OFFSET 0x17F8 +#define HDD_MODE_UPDATE_DELAY MENU_UPD_DELAY_NOUPDATE #include "../modules/isofs/zso.h" diff --git a/src/lang.c b/src/lang.c index 22ca90b01..a14079ece 100644 --- a/src/lang.c +++ b/src/lang.c @@ -1,6 +1,6 @@ #include "include/opl.h" #include "include/lang.h" -#include "include/util.h" +#include "include/supportbase.h" #include "include/fntsys.h" #include "include/ioman.h" #include "include/themes.h" @@ -56,17 +56,17 @@ static int lngLoadFromFile(char *path, char *name) { char dir[128]; - file_buffer_t *fileBuffer = openFileBuffer(path, O_RDONLY, 1, 1024); + file_buffer_t *fileBuffer = sbOpenFileBuffer(path, O_RDONLY, 1, 1024); if (fileBuffer) { // file exists, try to read it and load the custom lang char **curL = lang_strs; char **newL = (char **)calloc(LANG_STR_COUNT, sizeof(char *)); int strId = 0; - while (strId < LANG_STR_COUNT && readFileBuffer(fileBuffer, &newL[strId])) { + while (strId < LANG_STR_COUNT && sbReadFileBuffer(fileBuffer, &newL[strId])) { strId++; } - closeFileBuffer(fileBuffer); + sbCloseFileBuffer(fileBuffer); LOG("LANG Loaded %d entries\n", strId); @@ -154,7 +154,7 @@ int lngAddLanguages(char *path, const char *separator, int mode) { int result; - result = listDir(path, separator, MAX_LANGUAGE_FILES - nLanguages, &lngReadEntry); + result = sbListDir(path, separator, MAX_LANGUAGE_FILES - nLanguages, &lngReadEntry); nLanguages += result; lngRebuildLangNames(); diff --git a/src/menu.c b/src/menu.c index 47db6b27c..1f625594f 100644 --- a/src/menu.c +++ b/src/menu.c @@ -6,6 +6,9 @@ #include "include/opl.h" #include "include/dia.h" +#include "include/submenu.h" +#include "include/menu.h" +#include "include/supportbase.h" #include "include/renderman.h" #include "include/fntsys.h" #include "include/lang.h" diff --git a/src/opl.c b/src/opl.c index 926be5b3d..ee68516b9 100644 --- a/src/opl.c +++ b/src/opl.c @@ -6,12 +6,15 @@ #include "include/opl.h" #include "include/ioman.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/gui.h" #include "include/guigame.h" #include "include/renderman.h" #include "include/lang.h" #include "include/themes.h" #include "include/pad.h" +#include "include/dia.h" #include "include/dialogs.h" #include "include/system.h" #include "include/config.h" @@ -19,9 +22,13 @@ #include "include/compatupd.h" #include "include/imports.h" #include "httpclient.h" +#include "include/supportbase.h" #include "include/ethsupport.h" #include "include/appsupport.h" - +#include "include/bdmsupport.h" +#include "include/hdd.h" +#include "include/hddsupport.h" +#include "include/supportbase.h" #include "include/cheatman.h" #include "include/audio.h" #include "include/sound.h" @@ -107,7 +114,7 @@ static unsigned int frameCounter; static char errorMessage[256]; -static opl_io_module_t list_support[MODE_COUNT]; +opl_io_module_t list_support[MODE_COUNT]; // Global data char *gBaseMCDir; @@ -183,9 +190,6 @@ unsigned char gDefaultBgColor[3]; unsigned char gDefaultTextColor[3]; unsigned char gDefaultSelTextColor[3]; unsigned char gDefaultUITextColor[3]; -hdl_game_info_t *gAutoLaunchGame; -base_game_info_t *gAutoLaunchBDMGame; -bdm_device_data_t *gAutoLaunchDeviceData; char gOPLPart[128]; char *gHDDPrefix; char gExportName[32]; @@ -434,216 +438,6 @@ static void deinitAllSupport(int exception, int modeSelected) } } -// For resolving the mode, given an app's path -int oplPath2Mode(const char *path) -{ - char appsPath[64]; - const char *blkdevnameend; - int i, blkdevnamelen; - item_list_t *listSupport; - - for (i = 0; i < MODE_COUNT; i++) { - listSupport = list_support[i].support; - if ((listSupport != NULL) && (listSupport->itemGetPrefix != NULL)) { - char *prefix = listSupport->itemGetPrefix(listSupport); - snprintf(appsPath, sizeof(appsPath), "%sAPPS", prefix); - - blkdevnameend = strchr(appsPath, ':'); - if (blkdevnameend != NULL) { - blkdevnamelen = (int)(blkdevnameend - appsPath); - - if (strncmp(path, appsPath, blkdevnamelen) == 0) - return listSupport->mode; - } - } - } - - return -1; -} - -int oplGetAppImage(const char *device, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm) -{ - int i, remaining, elfbootmode; - char priority; - item_list_t *listSupport; - - elfbootmode = -1; - if (device != NULL) { - elfbootmode = oplPath2Mode(device); - if (elfbootmode >= 0) { - listSupport = list_support[elfbootmode].support; - - if ((listSupport != NULL) && (listSupport->enabled)) { - if (listSupport->itemGetImage(listSupport, folder, isRelative, value, suffix, resultTex, psm) >= 0) - return 0; - } - } - } - - // We search on ever devices from fatest to slowest. - for (remaining = MODE_COUNT, priority = 0; remaining > 0 && priority < 4; priority++) { - for (i = 0; i < MODE_COUNT; i++) { - listSupport = list_support[i].support; - - if (i == elfbootmode) - continue; - - if ((listSupport != NULL) && (listSupport->enabled) && (listSupport->appsPriority == priority)) { - if (listSupport->itemGetImage(listSupport, folder, isRelative, value, suffix, resultTex, psm) >= 0) - return 0; - remaining--; - } - } - } - - return -1; -} - -static int scanApps(int (*callback)(const char *path, config_set_t *appConfig, void *arg), void *arg, char *appsPath, int exception) -{ - struct dirent *pdirent; - DIR *pdir; - int count, ret; - config_set_t *appConfig; - char dir[128]; - char path[128]; - - count = 0; - if ((pdir = opendir(appsPath)) != NULL) { - while ((pdirent = readdir(pdir)) != NULL) { - if (exception && strchr(pdirent->d_name, '_') == NULL) - continue; - - if (strcmp(pdirent->d_name, ".") == 0 || strcmp(pdirent->d_name, "..") == 0) - continue; - - snprintf(dir, sizeof(dir), "%s/%s", appsPath, pdirent->d_name); - if (pdirent->d_type != DT_DIR) - continue; - - snprintf(path, sizeof(path), "%s/%s", dir, APP_TITLE_CONFIG_FILE); - appConfig = configAlloc(0, NULL, path); - if (appConfig != NULL) { - configRead(appConfig); - - ret = callback(dir, appConfig, arg); - configFree(appConfig); - - if (ret == 0) - count++; - else if (ret < 0) { // Stopped because of unrecoverable error. - break; - } - } - } - - closedir(pdir); - } else - LOG("APPS failed to open dir %s\n", appsPath); - - return count; -} - -int oplScanApps(int (*callback)(const char *path, config_set_t *appConfig, void *arg), void *arg) -{ - int i, count; - item_list_t *listSupport; - char appsPath[64]; - - count = 0; - for (i = 0; i < MODE_COUNT; i++) { - listSupport = list_support[i].support; - if ((listSupport != NULL) && (listSupport->enabled) && (listSupport->itemGetPrefix != NULL)) { - char *prefix = listSupport->itemGetPrefix(listSupport); - snprintf(appsPath, sizeof(appsPath), "%sAPPS", prefix); - count += scanApps(callback, arg, appsPath, 0); - } - } - - for (i = 0; i < 2; i++) { - snprintf(appsPath, sizeof(appsPath), "mc%d:", i); - count += scanApps(callback, arg, appsPath, 1); - } - - return count; -} - -int oplShouldAppsUpdate(void) -{ - int result; - - result = (int)shouldAppsUpdate; - shouldAppsUpdate = 0; - - return result; -} - -config_set_t *oplGetLegacyAppsConfig(void) -{ - int i, fd; - item_list_t *listSupport; - config_set_t *appConfig; - char appsPath[128]; - - snprintf(appsPath, sizeof(appsPath), "mc?:OPL/conf_apps.cfg"); - fd = openFile(appsPath, O_RDONLY); - if (fd >= 0) { - appConfig = configAlloc(CONFIG_APPS, NULL, appsPath); - close(fd); - return appConfig; - } - - for (i = MODE_COUNT - 1; i >= 0; i--) { - listSupport = list_support[i].support; - if ((listSupport != NULL) && (listSupport->enabled) && (listSupport->itemGetPrefix != NULL)) { - char *prefix = listSupport->itemGetPrefix(listSupport); - snprintf(appsPath, sizeof(appsPath), "%sconf_apps.cfg", prefix); - - fd = openFile(appsPath, O_RDONLY); - if (fd >= 0) { - appConfig = configAlloc(CONFIG_APPS, NULL, appsPath); - close(fd); - return appConfig; - } - } - } - - /* Apps config not found on any device, go with last tested device. - Does not matter if the config file could be loaded or not */ - appConfig = configAlloc(CONFIG_APPS, NULL, appsPath); - - return appConfig; -} - -config_set_t *oplGetLegacyAppsInfo(char *name) -{ - int i, fd; - item_list_t *listSupport; - config_set_t *appConfig; - char appsPath[128]; - - for (i = MODE_COUNT - 1; i >= 0; i--) { - listSupport = list_support[i].support; - if ((listSupport != NULL) && (listSupport->enabled) && (listSupport->itemGetPrefix != NULL)) { - char *prefix = listSupport->itemGetPrefix(listSupport); - snprintf(appsPath, sizeof(appsPath), "%sCFG%s%s.cfg", prefix, i == ETH_MODE ? "\\" : "/", name); - - fd = openFile(appsPath, O_RDONLY); - if (fd >= 0) { - appConfig = configAlloc(0, NULL, appsPath); - close(fd); - return appConfig; - } - } - } - - /* Apps config not found on any device, go with last tested device. - Does not matter if the config file could be loaded or not */ - appConfig = configAlloc(0, NULL, appsPath); - - return appConfig; -} - // ---------------------------------------------------------- // ----------------------- Updaters ------------------------- // ---------------------------------------------------------- @@ -771,47 +565,6 @@ void setErrorMessage(int strId) static int lscstatus = CONFIG_ALL; static int lscret = 0; -static int checkLoadConfigBDM(int types) -{ - char path[64]; - int value; - - // check USB - if (bdmFindPartition(path, "conf_opl.cfg", 0)) { - configEnd(); - configInit(path); - value = configReadMulti(types); - config_set_t *configOPL = configGetByType(CONFIG_OPL); - configSetInt(configOPL, CONFIG_OPL_BDM_MODE, START_MODE_AUTO); - return value; - } - - return 0; -} - -static int checkLoadConfigHDD(int types) -{ - int value; - char path[64]; - - hddLoadModules(); - hddLoadSupportModules(); - - snprintf(path, sizeof(path), "%sconf_opl.cfg", gHDDPrefix); - value = open(path, O_RDONLY); - if (value >= 0) { - close(value); - configEnd(); - configInit(gHDDPrefix); - value = configReadMulti(types); - config_set_t *configOPL = configGetByType(CONFIG_OPL); - configSetInt(configOPL, CONFIG_OPL_HDD_MODE, START_MODE_AUTO); - return value; - } - - return 0; -} - // When this function is called, the current device for loading/saving config is the memory card. static int tryAlternateDevice(int types) { @@ -823,29 +576,26 @@ static int tryAlternateDevice(int types) // First, try the device that OPL booted from. if (!strncmp(pwd, "mass", 4) && (pwd[4] == ':' || pwd[5] == ':')) { - if ((value = checkLoadConfigBDM(types)) != 0) + if ((value = configCheckBDM(types)) != 0) return value; } else if (!strncmp(pwd, "hdd", 3) && (pwd[3] == ':' || pwd[4] == ':')) { - if ((value = checkLoadConfigHDD(types)) != 0) + if ((value = configCheckHDD(types)) != 0) return value; } // Config was not found on the boot device. Check all supported devices. // Check USB device - if ((value = checkLoadConfigBDM(types)) != 0) + if ((value = configCheckBDM(types)) != 0) return value; // Check HDD - if ((value = checkLoadConfigHDD(types)) != 0) + if ((value = configCheckHDD(types)) != 0) return value; // At this point, the user has no loadable config files on any supported device, so try to find a device to save on. // We don't want to get users into alternate mode for their very first launch of OPL (i.e no config file at all, but still want to save on MC) // Check for a memory card inserted. - if (sysCheckMC() >= 0) { - configPrepareNotifications(gBaseMCDir); - showCfgPopup = 0; - return 0; - } + configCheckMC(types); + // No memory cards? Try a USB device... dir = opendir("mass0:"); if (dir != NULL) { @@ -989,37 +739,6 @@ static void _loadConfig() showCfgPopup = 1; } -static int trySaveConfigBDM(int types) -{ - char path[64]; - - // check USB - if (bdmFindPartition(path, "conf_opl.cfg", 1)) { - configSetMove(path); - return configWriteMulti(types); - } - - return -ENOENT; -} - -static int trySaveConfigHDD(int types) -{ - hddLoadModules(); - // Check that the formatted & usable HDD is connected. - if (hddCheck() == 0) { - configSetMove(gHDDPrefix); - return configWriteMulti(types); - } - - return -ENOENT; -} - -static int trySaveConfigMC(int types) -{ - configSetMove(NULL); - return configWriteMulti(types); -} - static int trySaveAlternateDevice(int types) { char pwd[8]; @@ -1029,24 +748,24 @@ static int trySaveAlternateDevice(int types) // First, try the device that OPL booted from. if (!strncmp(pwd, "mass", 4) && (pwd[4] == ':' || pwd[5] == ':')) { - if ((value = trySaveConfigBDM(types)) > 0) + if ((value = configCheckBDM(types)) > 0) return value; } else if (!strncmp(pwd, "hdd", 3) && (pwd[3] == ':' || pwd[4] == ':')) { - if ((value = trySaveConfigHDD(types)) > 0) + if ((value = configCheckHDD(types)) > 0) return value; } // Config was not saved to the boot device. Try all supported devices. // Try memory cards if (sysCheckMC() >= 0) { - if ((value = trySaveConfigMC(types)) > 0) + if ((value = configCheckMC(types)) > 0) return value; } // Try a USB device - if ((value = trySaveConfigBDM(types)) > 0) + if ((value = configCheckBDM(types)) > 0) return value; // Try the HDD - if ((value = trySaveConfigHDD(types)) > 0) + if ((value = configCheckHDD(types)) > 0) return value; // We tried everything, but... @@ -1135,7 +854,7 @@ static void _saveConfig() char *path = configGetDir(); if (!strncmp(path, "mc", 2)) { - checkMCFolder(); + sbCheckMCFolder(); configPrepareNotifications(gBaseMCDir); } @@ -1860,9 +1579,9 @@ static void miniInit(int mode) if (CONFIG_ALL & CONFIG_OPL) { if (!(ret & CONFIG_OPL)) { if (mode == BDM_MODE) - ret = checkLoadConfigBDM(CONFIG_ALL); + ret = configCheckBDM(CONFIG_ALL); else if (mode == HDD_MODE) - ret = checkLoadConfigHDD(CONFIG_ALL); + ret = configCheckHDD(CONFIG_ALL); } if (ret & CONFIG_OPL) { @@ -1914,6 +1633,8 @@ static void autoLaunchHDDGame(char *argv[]) hddLaunchGame(NULL, -1, configSet); } +static item_list_t *itemLaunchBDM; + static void autoLaunchBDMGame(char *argv[]) { char path[256]; @@ -1974,7 +1695,7 @@ static void autoLaunchBDMGame(char *argv[]) configSet = configAlloc(0, NULL, path); configRead(configSet); - bdmLaunchGame(NULL, -1, configSet); + itemLaunchBDM->itemLaunch(NULL, -1, configSet); } // --------------------- Main -------------------- diff --git a/src/sound.c b/src/sound.c index 24cdf2eea..7171bbbc8 100644 --- a/src/sound.c +++ b/src/sound.c @@ -37,7 +37,7 @@ static struct sfxEffect sfx_files[SFX_COUNT] = { }; static struct audsrv_adpcm_t sfx[SFX_COUNT]; -static int audio_initialized = 0; +int audio_initialized = 0; /*-- Theme Background Music ------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------*/ @@ -165,14 +165,8 @@ int sfxInit(int bootSnd) int thmSfxEnabled = 0; int i = 1; - if (!audio_initialized) { - LOG("SFX: %s: ERROR: not initialized!\n", __FUNCTION__); - return -1; - } - - audsrv_adpcm_init(); sfxInitDefaults(); - audioSetVolume(SFX_COUNT); + audioSetSfxVolume(SFX_COUNT); // Check default theme is not current theme int themeID = thmGetGuiValue(); diff --git a/src/submenu.c b/src/submenu.c index 0edd63990..edf47f674 100644 --- a/src/submenu.c +++ b/src/submenu.c @@ -6,6 +6,7 @@ */ #include "include/opl.h" +#include "submenu.h" #include "include/lang.h" #include "include/themes.h" diff --git a/src/supportbase.c b/src/supportbase.c index a31ad6f8f..9e5e3d2c4 100644 --- a/src/supportbase.c +++ b/src/supportbase.c @@ -1,4 +1,6 @@ #include "include/opl.h" +#include "include/hdd.h" +#include "include/supportbase.h" #include "include/util.h" #include "include/system.h" #include "include/ioman.h" @@ -6,7 +8,11 @@ #include "include/cheatman.h" #include "include/pggsm.h" #include "include/ps2cnf.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/gui.h" +#include "include/imports.h" + #define NEWLIB_PORT_AWARE #include // fileXioMount("iso:", ***), fileXioUmount("iso:") @@ -15,6 +21,8 @@ #include "../modules/isofs/zso.h" +base_game_info_t *gAutoLaunchBDMGame; + /// internal linked list used to populate the list from directory listing struct game_list_t { @@ -28,21 +36,129 @@ struct game_cache_list base_game_info_t *games; }; +static int mcID = -1; + +static int checkMC() +{ + int mc0_is_ps2card, mc1_is_ps2card; + int mc0_has_folder, mc1_has_folder; + + if (mcID == -1) { + mc0_is_ps2card = 0; + DIR *mc0_root_dir = opendir("mc0:/"); + if (mc0_root_dir != NULL) { + closedir(mc0_root_dir); + mc0_is_ps2card = 1; + } + + mc1_is_ps2card = 0; + DIR *mc1_root_dir = opendir("mc1:/"); + if (mc1_root_dir != NULL) { + closedir(mc1_root_dir); + mc1_is_ps2card = 1; + } + + mc0_has_folder = 0; + DIR *mc0_opl_dir = opendir("mc0:OPL/"); + if (mc0_opl_dir != NULL) { + closedir(mc0_opl_dir); + mc0_has_folder = 1; + } + + mc1_has_folder = 0; + DIR *mc1_opl_dir = opendir("mc1:OPL/"); + if (mc1_opl_dir != NULL) { + closedir(mc1_opl_dir); + mc1_has_folder = 1; + } + + if (mc0_has_folder) { + mcID = '0'; + return mcID; + } + + if (mc1_has_folder) { + mcID = '1'; + return mcID; + } + + if (mc0_is_ps2card) { + mcID = '0'; + return mcID; + } + + if (mc1_is_ps2card) { + mcID = '1'; + return mcID; + } + } + return mcID; +} + +int sbGetmcID(void) +{ + return mcID; +} + +void sbCheckMCFolder(void) +{ + char path[32]; + int fd; + + if (checkMC() < 0) { + return; + } + + snprintf(path, sizeof(path), "mc%d:OPL/", mcID & 1); + mkdir(path, 0777); + + snprintf(path, sizeof(path), "mc%d:OPL/opl.icn", mcID & 1); + fd = open(path, O_RDONLY); + if (fd < 0) { + fd = sbOpenFile(path, O_WRONLY | O_CREAT | O_TRUNC); + if (fd >= 0) { + write(fd, &icon_icn, size_icon_icn); + close(fd); + } + } else { + close(fd); + } + + snprintf(path, sizeof(path), "mc%d:OPL/icon.sys", mcID & 1); + fd = open(path, O_RDONLY); + if (fd < 0) { + fd = sbOpenFile(path, O_WRONLY | O_CREAT | O_TRUNC); + if (fd >= 0) { + write(fd, icon_sys, size_icon_sys); + close(fd); + } + } else { + close(fd); + } +} + int sbIsSameSize(const char *prefix, int prevSize) { int size = -1; char path[256]; snprintf(path, sizeof(path), "%sul.cfg", prefix); - int fd = openFile(path, O_RDONLY); + int fd = sbOpenFile(path, O_RDONLY); if (fd >= 0) { - size = getFileSize(fd); + size = sbGetFileSize(fd); close(fd); } return size == prevSize; } +int sbGetFileSize(int fd) +{ + int size = lseek(fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + return size; +} + int sbCreateSemaphore(void) { ee_sema_t sema; @@ -391,13 +507,13 @@ int sbReadList(base_game_info_t **list, const char *prefix, int *fsize, int *gam // count and process games in ul.cfg snprintf(path, sizeof(path), "%sul.cfg", prefix); - fd = openFile(path, O_RDONLY); + fd = sbOpenFile(path, O_RDONLY); if (fd >= 0) { USBExtreme_game_entry_t GameEntry; if (count < 0) count = 0; - size = getFileSize(fd); + size = sbGetFileSize(fd); *fsize = size; count += size / sizeof(USBExtreme_game_entry_t); @@ -466,6 +582,27 @@ int sbReadList(base_game_info_t **list, const char *prefix, int *fsize, int *gam return count; } +int sbListDir(char *path, const char *separator, int maxElem, + int (*readEntry)(int index, const char *path, const char *separator, const char *name, unsigned char d_type)) +{ + int index = 0; + char filename[128]; + + if (sbCheckFile(path, O_RDONLY)) { + DIR *dir = opendir(path); + struct dirent *dirent; + if (dir != NULL) { + while (index < maxElem && (dirent = readdir(dir)) != NULL) { + snprintf(filename, 128, "%s/%s", path, dirent->d_name); + index = readEntry(index, path, separator, dirent->d_name, dirent->d_type); + } + + closedir(dir); + } + } + return index; +} + extern int probed_fd; extern u32 probed_lba; extern u8 IOBuffer[2048]; @@ -714,6 +851,80 @@ void sbCreatePath(const base_game_info_t *game, char *path, const char *prefix, sbCreatePath_name(game, path, prefix, sep, part, game->name); } +int sbCheckFile(char *path, int mode) +{ + // check if it is mc + if (strncmp(path, "mc", 2) == 0) { + + // if user didn't explicitly asked for a MC (using '?' char) + if (path[2] == 0x3F) { + + // Use default detected card + if (checkMC() >= 0) + path[2] = mcID; + else + return 0; + } + + // in create mode, we check that the directory exist, or create it + if (mode & O_CREAT) { + char dirPath[256]; + char *pos = strrchr(path, '/'); + if (pos) { + memcpy(dirPath, path, (pos - path)); + dirPath[(pos - path)] = '\0'; + DIR *dir = opendir(dirPath); + if (dir == NULL) { + int res = mkdir(dirPath, 0777); + if (res != 0) + return 0; + } else + closedir(dir); + } + } + } + return 1; +} + +int sbOpenFile(char *path, int mode) +{ + if (sbCheckFile(path, mode)) + return open(path, mode, 0666); + else + return -1; +} + +void *sbReadFile(char *path, int align, int *size) +{ + void *buffer = NULL; + + int fd = sbOpenFile(path, O_RDONLY); + if (fd >= 0) { + unsigned int realSize = sbGetFileSize(fd); + + if ((*size > 0) && (*size != realSize)) { + LOG("UTIL Invalid filesize, expected: %d, got: %d\n", *size, realSize); + close(fd); + return NULL; + } + + if (align > 0) + buffer = memalign(64, realSize); // The allocation is aligned to aid the DMA transfers + else + buffer = malloc(realSize); + + if (!buffer) { + LOG("UTIL ReadFile: Failed allocation of %d bytes", realSize); + *size = 0; + } else { + read(fd, buffer, realSize); + close(fd); + *size = realSize; + } + } + return buffer; +} + void sbDelete(base_game_info_t **list, const char *prefix, const char *sep, int gamecount, int id) { int part; @@ -830,3 +1041,265 @@ int sbLoadCheats(const char *path, const char *file) return cheatMode; } + +/* size will be the maximum line size possible */ +file_buffer_t *sbOpenFileBuffer(char *fpath, int mode, short allocResult, unsigned int size) +{ + file_buffer_t *fileBuffer = NULL; + unsigned char bom[3]; + + int fd = sbOpenFile(fpath, mode); + if (fd >= 0) { + fileBuffer = (file_buffer_t *)malloc(sizeof(file_buffer_t)); + fileBuffer->size = size; + fileBuffer->available = 0; + fileBuffer->buffer = (char *)malloc(size * sizeof(char)); + if (mode == O_RDONLY) { + fileBuffer->lastPtr = NULL; + + // Check for and skip the UTF-8 BOM sequence. + if ((read(fd, bom, sizeof(bom)) != 3) || + (bom[0] != 0xEF || bom[1] != 0xBB || bom[2] != 0xBF)) { + // Not BOM, so rewind. + lseek(fd, 0, SEEK_SET); + } + } else + fileBuffer->lastPtr = fileBuffer->buffer; + fileBuffer->allocResult = allocResult; + fileBuffer->fd = fd; + fileBuffer->mode = mode; + } + + return fileBuffer; +} + +/* size will be the maximum line size possible */ +file_buffer_t *sbOpenFileBufferBuffer(short allocResult, const void *buffer, unsigned int size) +{ + file_buffer_t *fileBuffer = NULL; + + fileBuffer = (file_buffer_t *)malloc(sizeof(file_buffer_t)); + fileBuffer->size = size; + fileBuffer->available = size; + fileBuffer->buffer = (char *)malloc((size + 1) * sizeof(char)); + fileBuffer->lastPtr = fileBuffer->buffer; // O_RDONLY, but with the data in the buffer. + fileBuffer->allocResult = allocResult; + fileBuffer->fd = -1; + fileBuffer->mode = O_RDONLY; + + memcpy(fileBuffer->buffer, buffer, size); + fileBuffer->buffer[size] = '\0'; + + return fileBuffer; +} + +int sbReadFileBuffer(file_buffer_t *fileBuffer, char **outBuf) +{ + int lineSize = 0, readSize, length; + char *posLF = NULL; + + while (1) { + // if lastPtr is set, then we continue the read from this point as reference + if (fileBuffer->lastPtr) { + // Calculate the remaining chars to the right of lastPtr + lineSize = fileBuffer->available - (fileBuffer->lastPtr - fileBuffer->buffer); + /* LOG("##### Continue read, position: %X (total: %d) line size (\\0 not inc.): %d end: %x\n", + fileBuffer->lastPtr - fileBuffer->buffer, fileBuffer->available, lineSize, fileBuffer->lastPtr[lineSize]); */ + posLF = strchr(fileBuffer->lastPtr, '\n'); + } + + if (!posLF) { // We can come here either when the buffer is empty, or if the remaining chars don't have a LF + + // if available, we shift the remaining chars to the left ... + if (lineSize) { + // LOG("##### LF not found, Shift %d characters from end to beginning\n", lineSize); + memmove(fileBuffer->buffer, fileBuffer->lastPtr, lineSize); + } + + // ... and complete the buffer if we're not at EOF + if (fileBuffer->fd >= 0) { + + // Load as many characters necessary to fill the buffer + length = fileBuffer->size - lineSize - 1; + // LOG("##### Asking for %d characters to complete buffer\n", length); + readSize = read(fileBuffer->fd, fileBuffer->buffer + lineSize, length); + fileBuffer->buffer[lineSize + readSize] = '\0'; + + // Search again (from the lastly added chars only), the result will be "analyzed" in next if + posLF = strchr(fileBuffer->buffer + lineSize, '\n'); + + // Now update read context info + lineSize = lineSize + readSize; + // LOG("##### %d characters really read, line size now (\\0 not inc.): %d\n", read, lineSize); + + // If buffer not full it means we are at EOF + if (fileBuffer->size != lineSize + 1) { + // LOG("##### Reached EOF\n"); + close(fileBuffer->fd); + fileBuffer->fd = -1; + } + } + + fileBuffer->lastPtr = fileBuffer->buffer; + fileBuffer->available = lineSize; + } + + if (posLF) + lineSize = posLF - fileBuffer->lastPtr; + + // Check the previous char (on Windows there are CR/LF instead of single linux LF) + if (lineSize) + if (*(fileBuffer->lastPtr + lineSize - 1) == '\r') + lineSize--; + + fileBuffer->lastPtr[lineSize] = '\0'; + *outBuf = fileBuffer->lastPtr; + + // LOG("##### Result line is \"%s\" size: %d avail: %d pos: %d\n", fileBuffer->lastPtr, lineSize, fileBuffer->available, fileBuffer->lastPtr - fileBuffer->buffer); + + // If we are at EOF and no more chars available to scan, then we are finished + if (!lineSize && !fileBuffer->available && fileBuffer->fd == -1) + return 0; + + if (fileBuffer->lastPtr[0] == '#') { // '#' for comment lines + if (posLF) + fileBuffer->lastPtr = posLF + 1; + else + fileBuffer->lastPtr = NULL; + continue; + } + + if (lineSize && fileBuffer->allocResult) { + *outBuf = (char *)malloc((lineSize + 1) * sizeof(char)); + memcpy(*outBuf, fileBuffer->lastPtr, lineSize + 1); + } + + // Either move the pointer to next chars, or set it to null to force a whole buffer read (if possible) + if (posLF) + fileBuffer->lastPtr = posLF + 1; + else { + fileBuffer->lastPtr = NULL; + } + + return 1; + } +} + +void sbWriteFileBuffer(file_buffer_t *fileBuffer, char *inBuf, int size) +{ + LOG("writeFileBuffer avail: %d size: %d\n", fileBuffer->available, size); + if (fileBuffer->available && fileBuffer->available + size > fileBuffer->size) { + LOG("writeFileBuffer flushing: %d\n", fileBuffer->available); + write(fileBuffer->fd, fileBuffer->buffer, fileBuffer->available); + fileBuffer->lastPtr = fileBuffer->buffer; + fileBuffer->available = 0; + } + + if (size > fileBuffer->size) { + LOG("writeFileBuffer direct write: %d\n", size); + write(fileBuffer->fd, inBuf, size); + } else { + memcpy(fileBuffer->lastPtr, inBuf, size); + fileBuffer->lastPtr += size; + fileBuffer->available += size; + + LOG("writeFileBuffer lastPrt: %d\n", (fileBuffer->lastPtr - fileBuffer->buffer)); + } +} + +void sbCloseFileBuffer(file_buffer_t *fileBuffer) +{ + if (fileBuffer->fd >= 0) { + if (fileBuffer->mode != O_RDONLY && fileBuffer->available) { + // LOG("writeFileBuffer final write: %d\n", fileBuffer->available); + write(fileBuffer->fd, fileBuffer->buffer, fileBuffer->available); + } + close(fileBuffer->fd); + } + free(fileBuffer->buffer); + free(fileBuffer); +} + +struct DirentToDelete +{ + struct DirentToDelete *next; + char *filename; +}; + +int sbDeleteFolder(const char *folder) +{ + int result; + char *path; + struct dirent *dirent; + DIR *dir; + struct DirentToDelete *head, *start; + + result = 0; + start = head = NULL; + if ((dir = opendir(folder)) != NULL) { + /* Generate a list of files in the directory. */ + while ((dirent = readdir(dir)) != NULL) { + if ((strcmp(dirent->d_name, ".") == 0) || ((strcmp(dirent->d_name, "..") == 0))) + continue; + + path = malloc(strlen(folder) + strlen(dirent->d_name) + 2); + sprintf(path, "%s/%s", folder, dirent->d_name); + + if (dirent->d_type == DT_DIR) { + /* Recursive, delete all subfolders */ + result = sbDeleteFolder(path); + free(path); + } else { + free(path); + if (start == NULL) { + head = malloc(sizeof(struct DirentToDelete)); + if (head == NULL) + break; + start = head; + } else { + if ((head->next = malloc(sizeof(struct DirentToDelete))) == NULL) + break; + + head = head->next; + } + + head->next = NULL; + + if ((head->filename = malloc(strlen(dirent->d_name) + 1)) != NULL) + strcpy(head->filename, dirent->d_name); + else + break; + } + } + + closedir(dir); + } else + result = 0; + + if (result >= 0) { + /* Delete the files. */ + for (head = start; head != NULL; head = start) { + if (head->filename != NULL) { + if ((path = malloc(strlen(folder) + strlen(head->filename) + 2)) != NULL) { + sprintf(path, "%s/%s", folder, head->filename); + result = unlink(path); + if (result < 0) + LOG("sysDeleteFolder: failed to remove %s: %d\n", path, result); + + free(path); + } + free(head->filename); + } + + start = head->next; + free(head); + } + + if (result >= 0) { + result = rmdir(folder); + LOG("sysDeleteFolder: failed to rmdir %s: %d\n", folder, result); + } + } + + return result; +} \ No newline at end of file diff --git a/src/system.c b/src/system.c index fb945e7b7..2332b29b2 100644 --- a/src/system.c +++ b/src/system.c @@ -9,7 +9,11 @@ #endif #include "include/opl.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/gui.h" +#include "include/supportbase.h" +#include "include/bdmsupport.h" #include "include/ethsupport.h" #include "include/util.h" #include "include/pad.h" @@ -37,7 +41,7 @@ #include #include #include - +#include typedef struct { diff --git a/src/texcache.c b/src/texcache.c index 2fa32db46..fe3ea7da8 100644 --- a/src/texcache.c +++ b/src/texcache.c @@ -1,6 +1,8 @@ #include "include/opl.h" #include "include/texcache.h" #include "include/textures.h" +#include "include/submenu.h" +#include "include/menu.h" #include "include/ioman.h" #include "include/gui.h" #include "include/renderman.h" diff --git a/src/themes.c b/src/themes.c index 07494da06..425b694af 100644 --- a/src/themes.c +++ b/src/themes.c @@ -1,6 +1,6 @@ #include "include/opl.h" #include "include/themes.h" -#include "include/util.h" +#include "include/supportbase.h" #include "include/gui.h" #include "include/renderman.h" #include "include/ioman.h" @@ -1406,7 +1406,7 @@ int thmAddElements(char *path, const char *separator, int forceRefresh) { int result, i; - result = listDir(path, separator, THM_MAX_FILES - nThemes, &thmReadEntry); + result = sbListDir(path, separator, THM_MAX_FILES - nThemes, &thmReadEntry); nThemes += result; thmRebuildGuiNames(); diff --git a/src/util.c b/src/util.c index f23a5f271..471bcbb8d 100644 --- a/src/util.c +++ b/src/util.c @@ -8,12 +8,7 @@ #include "include/util.h" #include "include/ioman.h" #include "include/system.h" -#include -#include -#include -#include #include -#include "include/imports.h" #include "include/hdd.h" #include "../modules/isofs/zso.h" @@ -21,388 +16,10 @@ extern int probed_fd; extern u32 probed_lba; -static int mcID = -1; void guiWarning(const char *text, int count); -int getmcID(void) -{ - return mcID; -} - -int getFileSize(int fd) -{ - int size = lseek(fd, 0, SEEK_END); - lseek(fd, 0, SEEK_SET); - return size; -} - -static int checkMC() -{ - int mc0_is_ps2card, mc1_is_ps2card; - int mc0_has_folder, mc1_has_folder; - - if (mcID == -1) { - mc0_is_ps2card = 0; - DIR *mc0_root_dir = opendir("mc0:/"); - if (mc0_root_dir != NULL) { - closedir(mc0_root_dir); - mc0_is_ps2card = 1; - } - - mc1_is_ps2card = 0; - DIR *mc1_root_dir = opendir("mc1:/"); - if (mc1_root_dir != NULL) { - closedir(mc1_root_dir); - mc1_is_ps2card = 1; - } - - mc0_has_folder = 0; - DIR *mc0_opl_dir = opendir("mc0:OPL/"); - if (mc0_opl_dir != NULL) { - closedir(mc0_opl_dir); - mc0_has_folder = 1; - } - - mc1_has_folder = 0; - DIR *mc1_opl_dir = opendir("mc1:OPL/"); - if (mc1_opl_dir != NULL) { - closedir(mc1_opl_dir); - mc1_has_folder = 1; - } - - if (mc0_has_folder) { - mcID = '0'; - return mcID; - } - - if (mc1_has_folder) { - mcID = '1'; - return mcID; - } - - if (mc0_is_ps2card) { - mcID = '0'; - return mcID; - } - - if (mc1_is_ps2card) { - mcID = '1'; - return mcID; - } - } - return mcID; -} - -void checkMCFolder(void) -{ - char path[32]; - int fd; - - if (checkMC() < 0) { - return; - } - - snprintf(path, sizeof(path), "mc%d:OPL/", mcID & 1); - mkdir(path, 0777); - - snprintf(path, sizeof(path), "mc%d:OPL/opl.icn", mcID & 1); - fd = open(path, O_RDONLY); - if (fd < 0) { - fd = openFile(path, O_WRONLY | O_CREAT | O_TRUNC); - if (fd >= 0) { - write(fd, &icon_icn, size_icon_icn); - close(fd); - } - } else { - close(fd); - } - - snprintf(path, sizeof(path), "mc%d:OPL/icon.sys", mcID & 1); - fd = open(path, O_RDONLY); - if (fd < 0) { - fd = openFile(path, O_WRONLY | O_CREAT | O_TRUNC); - if (fd >= 0) { - write(fd, &icon_sys, size_icon_sys); - close(fd); - } - } else { - close(fd); - } -} - -static int checkFile(char *path, int mode) -{ - // check if it is mc - if (strncmp(path, "mc", 2) == 0) { - - // if user didn't explicitly asked for a MC (using '?' char) - if (path[2] == 0x3F) { - - // Use default detected card - if (checkMC() >= 0) - path[2] = mcID; - else - return 0; - } - - // in create mode, we check that the directory exist, or create it - if (mode & O_CREAT) { - char dirPath[256]; - char *pos = strrchr(path, '/'); - if (pos) { - memcpy(dirPath, path, (pos - path)); - dirPath[(pos - path)] = '\0'; - DIR *dir = opendir(dirPath); - if (dir == NULL) { - int res = mkdir(dirPath, 0777); - if (res != 0) - return 0; - } else - closedir(dir); - } - } - } - return 1; -} - -int openFile(char *path, int mode) -{ - if (checkFile(path, mode)) - return open(path, mode, 0666); - else - return -1; -} - -void *readFile(char *path, int align, int *size) -{ - void *buffer = NULL; - - int fd = openFile(path, O_RDONLY); - if (fd >= 0) { - unsigned int realSize = getFileSize(fd); - - if ((*size > 0) && (*size != realSize)) { - LOG("UTIL Invalid filesize, expected: %d, got: %d\n", *size, realSize); - close(fd); - return NULL; - } - - if (align > 0) - buffer = memalign(64, realSize); // The allocation is aligned to aid the DMA transfers - else - buffer = malloc(realSize); - - if (!buffer) { - LOG("UTIL ReadFile: Failed allocation of %d bytes", realSize); - *size = 0; - } else { - read(fd, buffer, realSize); - close(fd); - *size = realSize; - } - } - return buffer; -} - -int listDir(char *path, const char *separator, int maxElem, - int (*readEntry)(int index, const char *path, const char *separator, const char *name, unsigned char d_type)) -{ - int index = 0; - char filename[128]; - - if (checkFile(path, O_RDONLY)) { - DIR *dir = opendir(path); - struct dirent *dirent; - if (dir != NULL) { - while (index < maxElem && (dirent = readdir(dir)) != NULL) { - snprintf(filename, 128, "%s/%s", path, dirent->d_name); - index = readEntry(index, path, separator, dirent->d_name, dirent->d_type); - } - - closedir(dir); - } - } - return index; -} - -/* size will be the maximum line size possible */ -file_buffer_t *openFileBuffer(char *fpath, int mode, short allocResult, unsigned int size) -{ - file_buffer_t *fileBuffer = NULL; - unsigned char bom[3]; - - int fd = openFile(fpath, mode); - if (fd >= 0) { - fileBuffer = (file_buffer_t *)malloc(sizeof(file_buffer_t)); - fileBuffer->size = size; - fileBuffer->available = 0; - fileBuffer->buffer = (char *)malloc(size * sizeof(char)); - if (mode == O_RDONLY) { - fileBuffer->lastPtr = NULL; - // Check for and skip the UTF-8 BOM sequence. - if ((read(fd, bom, sizeof(bom)) != 3) || - (bom[0] != 0xEF || bom[1] != 0xBB || bom[2] != 0xBF)) { - // Not BOM, so rewind. - lseek(fd, 0, SEEK_SET); - } - } else - fileBuffer->lastPtr = fileBuffer->buffer; - fileBuffer->allocResult = allocResult; - fileBuffer->fd = fd; - fileBuffer->mode = mode; - } - - return fileBuffer; -} - -/* size will be the maximum line size possible */ -file_buffer_t *openFileBufferBuffer(short allocResult, const void *buffer, unsigned int size) -{ - file_buffer_t *fileBuffer = NULL; - - fileBuffer = (file_buffer_t *)malloc(sizeof(file_buffer_t)); - fileBuffer->size = size; - fileBuffer->available = size; - fileBuffer->buffer = (char *)malloc((size + 1) * sizeof(char)); - fileBuffer->lastPtr = fileBuffer->buffer; // O_RDONLY, but with the data in the buffer. - fileBuffer->allocResult = allocResult; - fileBuffer->fd = -1; - fileBuffer->mode = O_RDONLY; - - memcpy(fileBuffer->buffer, buffer, size); - fileBuffer->buffer[size] = '\0'; - - return fileBuffer; -} - -int readFileBuffer(file_buffer_t *fileBuffer, char **outBuf) -{ - int lineSize = 0, readSize, length; - char *posLF = NULL; - - while (1) { - // if lastPtr is set, then we continue the read from this point as reference - if (fileBuffer->lastPtr) { - // Calculate the remaining chars to the right of lastPtr - lineSize = fileBuffer->available - (fileBuffer->lastPtr - fileBuffer->buffer); - /* LOG("##### Continue read, position: %X (total: %d) line size (\\0 not inc.): %d end: %x\n", - fileBuffer->lastPtr - fileBuffer->buffer, fileBuffer->available, lineSize, fileBuffer->lastPtr[lineSize]); */ - posLF = strchr(fileBuffer->lastPtr, '\n'); - } - - if (!posLF) { // We can come here either when the buffer is empty, or if the remaining chars don't have a LF - - // if available, we shift the remaining chars to the left ... - if (lineSize) { - // LOG("##### LF not found, Shift %d characters from end to beginning\n", lineSize); - memmove(fileBuffer->buffer, fileBuffer->lastPtr, lineSize); - } - - // ... and complete the buffer if we're not at EOF - if (fileBuffer->fd >= 0) { - - // Load as many characters necessary to fill the buffer - length = fileBuffer->size - lineSize - 1; - // LOG("##### Asking for %d characters to complete buffer\n", length); - readSize = read(fileBuffer->fd, fileBuffer->buffer + lineSize, length); - fileBuffer->buffer[lineSize + readSize] = '\0'; - - // Search again (from the lastly added chars only), the result will be "analyzed" in next if - posLF = strchr(fileBuffer->buffer + lineSize, '\n'); - - // Now update read context info - lineSize = lineSize + readSize; - // LOG("##### %d characters really read, line size now (\\0 not inc.): %d\n", read, lineSize); - - // If buffer not full it means we are at EOF - if (fileBuffer->size != lineSize + 1) { - // LOG("##### Reached EOF\n"); - close(fileBuffer->fd); - fileBuffer->fd = -1; - } - } - - fileBuffer->lastPtr = fileBuffer->buffer; - fileBuffer->available = lineSize; - } - - if (posLF) - lineSize = posLF - fileBuffer->lastPtr; - - // Check the previous char (on Windows there are CR/LF instead of single linux LF) - if (lineSize) - if (*(fileBuffer->lastPtr + lineSize - 1) == '\r') - lineSize--; - - fileBuffer->lastPtr[lineSize] = '\0'; - *outBuf = fileBuffer->lastPtr; - - // LOG("##### Result line is \"%s\" size: %d avail: %d pos: %d\n", fileBuffer->lastPtr, lineSize, fileBuffer->available, fileBuffer->lastPtr - fileBuffer->buffer); - - // If we are at EOF and no more chars available to scan, then we are finished - if (!lineSize && !fileBuffer->available && fileBuffer->fd == -1) - return 0; - - if (fileBuffer->lastPtr[0] == '#') { // '#' for comment lines - if (posLF) - fileBuffer->lastPtr = posLF + 1; - else - fileBuffer->lastPtr = NULL; - continue; - } - - if (lineSize && fileBuffer->allocResult) { - *outBuf = (char *)malloc((lineSize + 1) * sizeof(char)); - memcpy(*outBuf, fileBuffer->lastPtr, lineSize + 1); - } - - // Either move the pointer to next chars, or set it to null to force a whole buffer read (if possible) - if (posLF) - fileBuffer->lastPtr = posLF + 1; - else { - fileBuffer->lastPtr = NULL; - } - - return 1; - } -} - -void writeFileBuffer(file_buffer_t *fileBuffer, char *inBuf, int size) -{ - // LOG("writeFileBuffer avail: %d size: %d\n", fileBuffer->available, size); - if (fileBuffer->available && fileBuffer->available + size > fileBuffer->size) { - // LOG("writeFileBuffer flushing: %d\n", fileBuffer->available); - write(fileBuffer->fd, fileBuffer->buffer, fileBuffer->available); - fileBuffer->lastPtr = fileBuffer->buffer; - fileBuffer->available = 0; - } - - if (size > fileBuffer->size) { - // LOG("writeFileBuffer direct write: %d\n", size); - write(fileBuffer->fd, inBuf, size); - } else { - memcpy(fileBuffer->lastPtr, inBuf, size); - fileBuffer->lastPtr += size; - fileBuffer->available += size; - - // LOG("writeFileBuffer lastPrt: %d\n", (fileBuffer->lastPtr - fileBuffer->buffer)); - } -} - -void closeFileBuffer(file_buffer_t *fileBuffer) -{ - if (fileBuffer->fd >= 0) { - if (fileBuffer->mode != O_RDONLY && fileBuffer->available) { - // LOG("writeFileBuffer final write: %d\n", fileBuffer->available); - write(fileBuffer->fd, fileBuffer->buffer, fileBuffer->available); - } - close(fileBuffer->fd); - } - free(fileBuffer->buffer); - free(fileBuffer); -} // a simple maximum of two int max(int a, int b) @@ -494,19 +111,6 @@ int GetSystemRegion(void) return ConsoleRegion; } -void logfile(char *text) -{ - int fd = open("mass:/opl_log.txt", O_APPEND | O_CREAT | O_WRONLY); - write(fd, text, strlen(text)); - close(fd); -} - -void logbuffer(char *path, void *buf, size_t size) -{ - int fd = open(path, O_CREAT | O_TRUNC | O_WRONLY); - write(fd, buf, size); - close(fd); -} int CheckPS2Logo(int fd, u32 lba) { @@ -573,89 +177,6 @@ int CheckPS2Logo(int fd, u32 lba) return ValidPS2Logo; } -struct DirentToDelete -{ - struct DirentToDelete *next; - char *filename; -}; - -int sysDeleteFolder(const char *folder) -{ - int result; - char *path; - struct dirent *dirent; - DIR *dir; - struct DirentToDelete *head, *start; - - result = 0; - start = head = NULL; - if ((dir = opendir(folder)) != NULL) { - /* Generate a list of files in the directory. */ - while ((dirent = readdir(dir)) != NULL) { - if ((strcmp(dirent->d_name, ".") == 0) || ((strcmp(dirent->d_name, "..") == 0))) - continue; - - path = malloc(strlen(folder) + strlen(dirent->d_name) + 2); - sprintf(path, "%s/%s", folder, dirent->d_name); - - if (dirent->d_type == DT_DIR) { - /* Recursive, delete all subfolders */ - result = sysDeleteFolder(path); - free(path); - } else { - free(path); - if (start == NULL) { - head = malloc(sizeof(struct DirentToDelete)); - if (head == NULL) - break; - start = head; - } else { - if ((head->next = malloc(sizeof(struct DirentToDelete))) == NULL) - break; - - head = head->next; - } - - head->next = NULL; - - if ((head->filename = malloc(strlen(dirent->d_name) + 1)) != NULL) - strcpy(head->filename, dirent->d_name); - else - break; - } - } - - closedir(dir); - } else - result = 0; - - if (result >= 0) { - /* Delete the files. */ - for (head = start; head != NULL; head = start) { - if (head->filename != NULL) { - if ((path = malloc(strlen(folder) + strlen(head->filename) + 2)) != NULL) { - sprintf(path, "%s/%s", folder, head->filename); - result = unlink(path); - if (result < 0) - LOG("sysDeleteFolder: failed to remove %s: %d\n", path, result); - - free(path); - } - free(head->filename); - } - - start = head->next; - free(head); - } - - if (result >= 0) { - result = rmdir(folder); - LOG("sysDeleteFolder: failed to rmdir %s: %d\n", folder, result); - } - } - - return result; -} /*----------------------------------------------------------------------------------------*/ /* NOP delay. */ @@ -669,4 +190,4 @@ void delay(int count) while (ret--) asm("nop\nnop\nnop\nnop"); } -} +} \ No newline at end of file