Skip to content

Commit

Permalink
Merge pull request #1333 from KrahJohlito/bdmt3
Browse files Browse the repository at this point in the history
Bdm update
  • Loading branch information
uyjulian authored Oct 7, 2024
2 parents 8c50a07 + ce99811 commit cbb8590
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
3 changes: 3 additions & 0 deletions include/opl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "include/hddsupport.h"
#include "include/supportbase.h"
#include "include/bdmsupport.h"

// Last Played Auto Start
#include <time.h>
Expand Down Expand Up @@ -207,8 +208,10 @@ extern unsigned char gDefaultTextColor[3];
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];

Expand Down
24 changes: 17 additions & 7 deletions src/bdmsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,15 @@ void bdmLaunchGame(item_list_t *itemList, int id, config_set_t *configSet)
u32 layer1_start, layer1_offset;
unsigned short int layer1_part;

bdm_device_data_t *pDeviceData = (bdm_device_data_t *)itemList->priv;
bdm_device_data_t *pDeviceData = NULL;

if (gAutoLaunchBDMGame == NULL)
if (gAutoLaunchBDMGame == NULL) {
pDeviceData = (bdm_device_data_t *)itemList->priv;
game = &pDeviceData->bdmGames[id];
else
} else {
pDeviceData = gAutoLaunchDeviceData;
game = gAutoLaunchBDMGame;
}

char vmc_name[32], vmc_path[256], have_error = 0;
int vmc_id, size_mcemu_irx = 0;
Expand Down Expand Up @@ -489,24 +492,31 @@ void bdmLaunchGame(item_list_t *itemList, int id, config_set_t *configSet)
if (configGetStrCopy(configSet, CONFIG_ITEM_ALTSTARTUP, filename, sizeof(filename)) == 0)
strcpy(filename, game->startup);

// deinit will free per device data.. copy driver name before free to compare for launch
char bdmCurrentDriver[32];
snprintf(bdmCurrentDriver, sizeof(bdmCurrentDriver), "%s", pDeviceData->bdmDriver);
settings->bdDeviceId = pDeviceData->massDeviceIndex;

if (gAutoLaunchBDMGame == NULL)
deinit(NO_EXCEPTION, itemList->mode); // CAREFUL: deinit will call bdmCleanUp, so bdmGames/game will be freed
else {
miniDeinit(configSet);

free(gAutoLaunchBDMGame);
gAutoLaunchBDMGame = NULL;

free(gAutoLaunchDeviceData);
gAutoLaunchDeviceData = NULL;
}

LOG("bdm pre sysLaunchLoaderElf\n");
settings->bdDeviceId = pDeviceData->massDeviceIndex;
if (!strcmp(pDeviceData->bdmDriver, "usb")) {
if (!strcmp(bdmCurrentDriver, "usb")) {
settings->common.fakemodule_flags |= FAKE_MODULE_FLAG_USBD;
sysLaunchLoaderElf(filename, "BDM_USB_MODE", irx_size, irx, size_mcemu_irx, bdm_mcemu_irx, EnablePS2Logo, compatmask);
} else if (!strcmp(pDeviceData->bdmDriver, "sd") && strlen(pDeviceData->bdmDriver) == 2) {
} else if (!strcmp(bdmCurrentDriver, "sd") && strlen(bdmCurrentDriver) == 2) {
settings->common.fakemodule_flags |= 0 /* TODO! fake ilinkman ? */;
sysLaunchLoaderElf(filename, "BDM_ILK_MODE", irx_size, irx, size_mcemu_irx, bdm_mcemu_irx, EnablePS2Logo, compatmask);
} else if (!strcmp(pDeviceData->bdmDriver, "sdc") && strlen(pDeviceData->bdmDriver) == 3) {
} else if (!strcmp(bdmCurrentDriver, "sdc") && strlen(bdmCurrentDriver) == 3) {
settings->common.fakemodule_flags |= 0;
sysLaunchLoaderElf(filename, "BDM_M4S_MODE", irx_size, irx, size_mcemu_irx, bdm_mcemu_irx, EnablePS2Logo, compatmask);
}
Expand Down
34 changes: 22 additions & 12 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ 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];
Expand Down Expand Up @@ -430,13 +431,8 @@ static void initAllSupport(int force_reinit)
static void deinitAllSupport(int exception, int modeSelected)
{
for (int i = 0; i < MODE_COUNT; i++) {
if (list_support[i].support != NULL) {
// If the selected mode is one of the mass devices then skip deinit for all mass device objects.
if (modeSelected >= BDM_MODE && modeSelected <= BDM_MODE4 && i <= BDM_MODE4)
continue;

if (list_support[i].support != NULL)
moduleCleanup(&list_support[i], exception, modeSelected);
}
}
}

Expand Down Expand Up @@ -1655,13 +1651,12 @@ void setDefaultColors(void)

static void setDefaults(void)
{
clearIOModuleT(&list_support[BDM_MODE]);
clearIOModuleT(&list_support[ETH_MODE]);
clearIOModuleT(&list_support[HDD_MODE]);
clearIOModuleT(&list_support[APP_MODE]);
for (int i = 0; i < MODE_COUNT; i++)
clearIOModuleT(&list_support[i]);

gAutoLaunchGame = NULL;
gAutoLaunchBDMGame = NULL;
gAutoLaunchDeviceData = NULL;
gOPLPart[0] = '\0';
gHDDPrefix = "pfs0:";
gBaseMCDir = "mc?:OPL";
Expand Down Expand Up @@ -1939,10 +1934,25 @@ static void autoLaunchBDMGame(char *argv[])
gAutoLaunchBDMGame->format = format;
gAutoLaunchBDMGame->parts = 1; // ul not supported.

if (gBDMPrefix[0] != '\0')
gAutoLaunchDeviceData = malloc(sizeof(bdm_device_data_t));
memset(gAutoLaunchDeviceData, 0, sizeof(bdm_device_data_t));

snprintf(path, sizeof(path), "mass0:");
int dir = fileXioDopen(path);
if (dir >= 0) {
fileXioIoctl2(dir, USBMASS_IOCTL_GET_DRIVERNAME, NULL, 0, &gAutoLaunchDeviceData->bdmDriver, sizeof(gAutoLaunchDeviceData->bdmDriver) - 1);
fileXioIoctl2(dir, USBMASS_IOCTL_GET_DEVICE_NUMBER, NULL, 0, &gAutoLaunchDeviceData->massDeviceIndex, sizeof(gAutoLaunchDeviceData->massDeviceIndex));

fileXioDclose(dir);
}

if (gBDMPrefix[0] != '\0') {
snprintf(path, sizeof(path), "mass0:%s/CFG/%s.cfg", gBDMPrefix, gAutoLaunchBDMGame->startup);
else
snprintf(gAutoLaunchDeviceData->bdmPrefix, sizeof(gAutoLaunchDeviceData->bdmPrefix), "mass0:%s/", gBDMPrefix);
} else {
snprintf(path, sizeof(path), "mass0:CFG/%s.cfg", gAutoLaunchBDMGame->startup);
snprintf(gAutoLaunchDeviceData->bdmPrefix, sizeof(gAutoLaunchDeviceData->bdmPrefix), "mass0:");
}

configSet = configAlloc(0, NULL, path);
configRead(configSet);
Expand Down
4 changes: 2 additions & 2 deletions src/themes.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,8 @@ static void drawMenuText(struct menu_list *menu, struct submenu_list *item, conf
static void drawBDMIndex(struct menu_list *menu, struct submenu_list *item, config_set_t *config, struct theme_element *elem)
{
item_list_t *itemList = menu->item->userdata;
// Only render for bdm modes
if (itemList->mode >= ETH_MODE)
// Only render for bdm modes and if current mode is visible
if (itemList->mode >= ETH_MODE || menu->item->visible == 0)
return;

// Only render if multiple mass devices are connected
Expand Down

0 comments on commit cbb8590

Please sign in to comment.