Skip to content

Commit

Permalink
test multiple mass devices
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Jul 12, 2024
1 parent f3c8642 commit 933db45
Show file tree
Hide file tree
Showing 19 changed files with 706 additions and 326 deletions.
28 changes: 25 additions & 3 deletions include/bdmsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,35 @@ typedef struct

#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

typedef struct
{
int massDeviceIndex; // Underlying device index backing the mass fs partition, ex: usb0 = 0, usb1 = 1, ata master = 0, ata slave = 1, etc.
char bdmPrefix[40]; // Contains the full path to the folder where all the games are.
int bdmULSizePrev;
time_t bdmModifiedCDPrev;
time_t bdmModifiedDVDPrev;
int bdmGameCount;
base_game_info_t *bdmGames;
char bdmDriver[32];
int bdmDeviceType; // Type of BDM device, see BDM_TYPE_* above

int bdmDeviceTick; // Used alongside BdmGeneration to tell if device data needs to be refreshed
unsigned char ThemesLoaded;
unsigned char LanguagesLoaded;
unsigned char ForceRefresh;
} bdm_device_data_t;

void bdmInit();
item_list_t *bdmGetObject(int initOnly);
int bdmFindPartition(char *target, const char *name, int write);
void bdmLoadModules(void);
void bdmLaunchGame(int id, config_set_t *configSet);
void bdmSetPrefix(void);
void bdmLaunchGame(item_list_t *pItemList, int id, config_set_t *configSet);

void bdmInitSemaphore();
void bdmEnumerateDevices();

#endif
8 changes: 4 additions & 4 deletions include/ethsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ typedef struct
vmc_spec_t specs; /* Card specifications */
} smb_vmc_infos_t;

void ethInit(void); // 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 ethInit(item_list_t *pItemList); // 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.
int ethGetNetConfig(u8 *ip_address, u8 *netmask, u8 *gateway);
int ethApplyConfig(void);
int ethGetDHCPStatus(void);
Expand Down
2 changes: 1 addition & 1 deletion include/hddsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ int hddDeleteHDLGame(hdl_game_info_t *ginfo);
void hddInit();
item_list_t *hddGetObject(int initOnly);
void hddLoadModules(void);
void hddLaunchGame(int id, config_set_t *configSet);
void hddLaunchGame(item_list_t *pItemList, int id, config_set_t *configSet);

#endif
51 changes: 31 additions & 20 deletions include/iosupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

enum IO_MODES {
BDM_MODE = 0,
BDM_MODE1,
BDM_MODE2,
BDM_MODE3,
ETH_MODE,
HDD_MODE,
APP_MODE,
Expand Down Expand Up @@ -75,7 +78,9 @@ enum ERROR_CODE {
#define MENU_UPD_DELAY_NOUPDATE -1 // Auto refresh is disabled for the item. The refresh button may be used to manually refresh the item.
#define MENU_UPD_DELAY_GENREFRESH 0 // The item will be refreshed every MENU_GENERAL_UPDATE_DELAY frames, regardless of whether automatic refresh is enabled or not.

typedef struct
typedef struct _item_list_t item_list_t;

typedef struct _item_list_t
{
short int mode;

Expand All @@ -93,47 +98,53 @@ typedef struct
/// 0 = General refresh, which means that it will be refreshed every MENU_GENERAL_UPDATE_DELAY frames, regardless of whether automatic refresh is enabled or not.
int updateDelay;

// Per-device data
void *priv;

// opl_io_module_t instance that owns this item list.
void *owner;

/// item description in localised form (used if value is not negative)
int (*itemTextId)(void);
int (*itemTextId)(item_list_t *pItemList);

/// @return path to device prefix (set callback to NULL if not applicable).
char *(*itemGetPrefix)(void);
char *(*itemGetPrefix)(item_list_t *pItemList);

void (*itemInit)(void);
void (*itemInit)(item_list_t *pItemList);

/** @return 1 if update is needed, 0 otherwise */
int (*itemNeedsUpdate)(void);
int (*itemNeedsUpdate)(item_list_t *pItemList);

/** @return game count (0 on error) */
int (*itemUpdate)(void);
int (*itemUpdate)(item_list_t *pItemList);

int (*itemGetCount)(void);
int (*itemGetCount)(item_list_t *pItemList);

void *(*itemGet)(int id);
void *(*itemGet)(item_list_t *pItemList, int id);

char *(*itemGetName)(int id);
char *(*itemGetName)(item_list_t *pItemList, int id);

int (*itemGetNameLength)(int id);
int (*itemGetNameLength)(item_list_t *pItemList, int id);

char *(*itemGetStartup)(int id);
char *(*itemGetStartup)(item_list_t *pItemList, int id);

void (*itemDelete)(int id);
void (*itemDelete)(item_list_t *pItemList, int id);

void (*itemRename)(int id, char *newName);
void (*itemRename)(item_list_t *pItemList, int id, char *newName);

void (*itemLaunch)(int id, config_set_t *configSet);
void (*itemLaunch)(item_list_t *pItemList, int id, config_set_t *configSet);

config_set_t *(*itemGetConfig)(int id);
config_set_t *(*itemGetConfig)(item_list_t *pItemList, int id);

int (*itemGetImage)(char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm);
int (*itemGetImage)(item_list_t *pItemList, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm);

void (*itemCleanUp)(int exception);
void (*itemCleanUp)(item_list_t *pItemList, int exception);

void (*itemShutdown)(void);
void (*itemShutdown)(item_list_t *pItemList);

int (*itemCheckVMC)(char *name, int createSize);
int (*itemCheckVMC)(item_list_t *pItemList, char *name, int createSize);

int (*itemIconId)(void);
int (*itemIconId)(item_list_t *pItemList);
} item_list_t;

#endif
4 changes: 4 additions & 0 deletions include/menusys.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ typedef struct menu_item
/// item description in localised form (used if value is not negative)
int text_id;

// Indicates if the menu item should be drawn or not.
int visible;

void *userdata;

/// submenu, selection and page start (only used in static mode)
Expand Down Expand Up @@ -86,6 +89,7 @@ void menuInitGameMenu(void);
void menuInitAppMenu(void);

void menuAppendItem(menu_item_t *item);
void refreshMenuPosition();

void submenuRebuildCache(submenu_list_t *submenu);
submenu_list_t *submenuAppendItem(submenu_list_t **submenu, int icon_id, char *text, int id, int text_id);
Expand Down
17 changes: 16 additions & 1 deletion include/opl.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void setErrorMessage(int strId);
void setErrorMessageWithCode(int strId, int error);
int loadConfig(int types);
int saveConfig(int types, int showUI);
void applyConfig(int themeID, int langID);
void applyConfig(int themeID, int langID, int skipDeviceRefresh);
void menuDeferredUpdate(void *data);
void moduleUpdateMenu(int mode, int themeChanged, int langChanged);
void handleLwnbdSrv();
Expand Down Expand Up @@ -209,10 +209,25 @@ extern base_game_info_t *gAutoLaunchBDMGame;
extern char *gHDDPrefix;
extern char gOPLPart[128];

void initSupport(item_list_t *itemList, int mode, int force_reinit);

void setDefaultColors(void);

#define MENU_ITEM_HEIGHT 19

#include "include/menusys.h"

typedef struct
{
item_list_t *support;

/// menu item used with this list support
menu_item_t menuItem;

/// submenu list
submenu_list_t *subMenu;
} opl_io_module_t;

/*
BLURT output char blurttext[128];
#define BLURT \
Expand Down
15 changes: 10 additions & 5 deletions modules/iopcore/cdvdman/device-bdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ void bdm_connect_bd(struct block_device *bd)
{
DPRINTF("connecting device %s%dp%d\n", bd->name, bd->devNr, bd->parNr);

if (g_bd == NULL) {
if (g_bd == NULL && bd->devNr == cdvdman_settings.bdDeviceId) {
DPRINTF("attaching to %s%dp%d\n", bd->name, bd->devNr, bd->parNr);
g_bd = bd;
g_bd_sectors_per_sector = (2048 / bd->sectorSize);
// Free usage of block device
Expand All @@ -38,10 +39,14 @@ void bdm_disconnect_bd(struct block_device *bd)
{
DPRINTF("disconnecting device %s%dp%d\n", bd->name, bd->devNr, bd->parNr);

// Lock usage of block device
WaitSema(bdm_io_sema);
if (g_bd == bd)
g_bd = NULL;
if (bd->devNr == cdvdman_settings.bdDeviceId) {
DPRINTF("detatching from %s%dp%d\n", bd->name, bd->devNr, bd->parNr);

// Lock usage of block device
WaitSema(bdm_io_sema);
if (g_bd == bd)
g_bd = NULL;
}
}

//
Expand Down
3 changes: 3 additions & 0 deletions modules/iopcore/common/cdvd_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ struct cdvdman_settings_bdm
// 0 = ISO
struct cdvdman_fragfile fragfile[BDM_MAX_FILES];

// Device ID of the block device to bind to.
u32 bdDeviceId;

// Fragment table, containing the fragments of all files
bd_fragment_t frags[BDM_MAX_FRAGS];
} __attribute__((packed));
Expand Down
34 changes: 17 additions & 17 deletions src/appsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static char *appGetBoot(char *device, int max, char *path)
return path;
}

void appInit(void)
void appInit(item_list_t *pItemList)
{
LOG("APPSUPPORT Init\n");
appForceUpdate = 1;
Expand All @@ -114,7 +114,7 @@ item_list_t *appGetObject(int initOnly)
return &appItemList;
}

static int appNeedsUpdate(void)
static int appNeedsUpdate(item_list_t *pItemList)
{
int update;

Expand Down Expand Up @@ -238,7 +238,7 @@ static int appScanCallback(const char *path, config_set_t *appConfig, void *arg)
return -1;
}

static int appUpdateItemList(void)
static int appUpdateItemList(item_list_t *pItemList)
{
struct app_info_linked *appsLinkedList, *appNext;

Expand Down Expand Up @@ -284,24 +284,24 @@ static void appFreeList(void)
}
}

static int appGetItemCount(void)
static int appGetItemCount(item_list_t *pItemList)
{
return appItemCount;
}

static char *appGetItemName(int id)
static char *appGetItemName(item_list_t *pItemList, int id)
{
return appsList[id].title;
}

static int appGetItemNameLength(int id)
static int appGetItemNameLength(item_list_t *pItemList, int id)
{
return CONFIG_KEY_NAME_LEN;
}

/* appGetItemStartup() is called to get the startup path for display & for the art assets.
The path is used immediately, before a subsequent call to appGetItemStartup(). */
static char *appGetItemStartup(int id)
static char *appGetItemStartup(item_list_t *pItemList, int id)
{
if (appsList[id].legacy) {
struct config_value_t *cur = appGetConfigValue(id);
Expand All @@ -311,7 +311,7 @@ static char *appGetItemStartup(int id)
}
}

static void appDeleteItem(int id)
static void appDeleteItem(item_list_t *pItemList, int id)
{
if (appsList[id].legacy) {
struct config_value_t *cur = appGetConfigValue(id);
Expand All @@ -326,7 +326,7 @@ static void appDeleteItem(int id)
appForceUpdate = 1;
}

static void appRenameItem(int id, char *newName)
static void appRenameItem(item_list_t *pItemList, int id, char *newName)
{
char value[256];

Expand Down Expand Up @@ -355,7 +355,7 @@ static void appRenameItem(int id, char *newName)
appForceUpdate = 1;
}

static void appLaunchItem(int id, config_set_t *configSet)
static void appLaunchItem(item_list_t *pItemList, int id, config_set_t *configSet)
{
int fd;
const char *filename;
Expand Down Expand Up @@ -394,7 +394,7 @@ static void appLaunchItem(int id, config_set_t *configSet)
guiMsgBox(_l(_STR_ERR_FILE_INVALID), 0, NULL);
}

static config_set_t *appGetConfig(int id)
static config_set_t *appGetConfig(item_list_t *pItemList, int id)
{
config_set_t *config;
char tmp[8];
Expand Down Expand Up @@ -433,7 +433,7 @@ static config_set_t *appGetConfig(int id)
return config;
}

static int appGetImage(char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm)
static int appGetImage(item_list_t *pItemList, char *folder, int isRelative, char *value, char *suffix, GSTEXTURE *resultTex, short psm)
{
char device[8], *startup;

Expand All @@ -445,18 +445,18 @@ static int appGetImage(char *folder, int isRelative, char *value, char *suffix,
return oplGetAppImage(device, folder, isRelative, value, suffix, resultTex, psm);
}

static int appGetTextId(void)
static int appGetTextId(item_list_t *pItemList)
{
return _STR_APPS;
}

static int appGetIconId(void)
static int appGetIconId(item_list_t *pItemList)
{
return APP_ICON;
}

// This may be called, even if appInit() was not.
static void appCleanUp(int exception)
static void appCleanUp(item_list_t *pItemList, int exception)
{
if (appItemList.enabled) {
LOG("APPSUPPORT CleanUp\n");
Expand All @@ -466,7 +466,7 @@ static void appCleanUp(int exception)
}

// This may be called, even if appInit() was not.
static void appShutdown(void)
static void appShutdown(item_list_t *pItemList)
{
if (appItemList.enabled) {
LOG("APPSUPPORT Shutdown\n");
Expand All @@ -476,6 +476,6 @@ static void appShutdown(void)
}

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, &appGetTextId, NULL, &appInit, &appNeedsUpdate, &appUpdateItemList,
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};
Loading

0 comments on commit 933db45

Please sign in to comment.