Skip to content

Commit

Permalink
- Support FlippyDrive disc drive passthrough.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Nov 4, 2024
1 parent 23d5a5c commit 1258ad2
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions cube/swiss/include/swiss.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern bool select_dest_dir(file_handle* initial, file_handle* selection);
typedef struct {
int debugUSB; // Debug prints over USBGecko
int hasDVDDrive; // 0 if none, 1 if something
int hasFlippyDrive;
int exiSpeed;
int uiVMode; // What mode to force Swiss into
int gameVMode; // What mode to force a Game into
Expand Down
2 changes: 1 addition & 1 deletion cube/swiss/source/devices/deviceHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool getFragments(int deviceSlot, file_handle *file, file_frag **fragList, u32 *
}
file->status = STATUS_HAS_MAPPING;
}
else if(devices[deviceSlot] == &__device_flippy) {
else if(devices[deviceSlot] == &__device_flippy || devices[deviceSlot] == &__device_flippyflash) {
frags = reallocarray(frags, numFrags + 2, sizeof(file_frag));
if(frags == NULL) {
return false;
Expand Down
5 changes: 5 additions & 0 deletions cube/swiss/source/devices/dvd/deviceHandler-DVD.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "gui/FrameBufferMagic.h"
#include "gui/IPLFontWrite.h"
#include "main.h"
#include "flippy.h"
#include "patcher.h"
#include "dvd.h"
#include "gcm.h"
Expand Down Expand Up @@ -523,6 +524,10 @@ s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2, Executabl
}

s32 deviceHandler_DVD_init(file_handle* file){
if(devices[DEVICE_CUR] == &__device_flippy || devices[DEVICE_CUR] == &__device_flippyflash) {
return EBUSY;
}
if(swissSettings.hasFlippyDrive) flippy_bypass(true);
if(!swissSettings.hasDVDDrive) return ENODEV;

file->status = initialize_disc(ENABLE_BYDISK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ file_handle initial_Flippy =
};

file_handle initial_FlippyFlash =
{ "flffs:/", // directory
{ "fdffs:/", // directory
0ULL, // fileBase (u64)
0, // offset
0, // size
Expand Down Expand Up @@ -246,6 +246,11 @@ s32 deviceHandler_Flippy_setupFile(file_handle* file, file_handle* file2, Execut
}

s32 deviceHandler_Flippy_init(file_handle* file) {
if(devices[DEVICE_CUR] && (devices[DEVICE_CUR]->location & LOC_DVD_CONNECTOR) &&
devices[DEVICE_CUR] != &__device_flippy &&
devices[DEVICE_CUR] != &__device_flippyflash) {
return EBUSY;
}
return flippy_init() == FLIPPY_RESULT_OK ? 0 : ENODEV;
}

Expand Down Expand Up @@ -303,6 +308,7 @@ bool deviceHandler_Flippy_test() {
if (DVD_Inquiry(&commandBlock, &driveInfo) < 0)
return false;
case 0x20220426:
swissSettings.hasFlippyDrive = 1;
return true;
}
}
Expand Down
34 changes: 33 additions & 1 deletion cube/swiss/source/devices/flippydrive/flippy.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
((dvdcmdbuf){(((0xB5) << 24) | (0x12))})
#define FLIPPY_CMD_RENAME \
((dvdcmdbuf){(((0xB5) << 24) | (0x13))})
#define FLIPPY_CMD_BYPASS_ENTRY \
((dvdcmdbuf){(((0xDC) << 24))})
#define FLIPPY_CMD_BYPASS_EXIT \
((dvdcmdbuf){(((0xDC) << 24)), (0xE3F72BAB), (0x72648977)})

typedef void (*flippycallback)(flippyfile *file);
typedef void (*dvdcallbacklow)(s32 result);
Expand Down Expand Up @@ -767,13 +771,41 @@ flippyresult flippy_rename(const char *old, const char *new)
return file->result;
}

flippyresult flippy_bypass(bool bypass)
{
dvdcmdblk block;

if (DVD_Inquiry(&block, &driveinfo) < 0)
return FLIPPY_RESULT_NOT_READY;

switch (driveinfo.rel_date) {
case 0x20220420:
case 0x20220426:
if (!bypass) return FLIPPY_RESULT_OK;
break;
default:
if (bypass) return FLIPPY_RESULT_OK;
break;
}

LWP_SemInit(&semaphore, 0, 1);
if (!DVD_ReadImmAsyncPrio(&block, bypass ? FLIPPY_CMD_BYPASS_ENTRY : FLIPPY_CMD_BYPASS_EXIT, NULL, 0, reset_callback, 3)) {
LWP_SemDestroy(semaphore);
return FLIPPY_RESULT_NOT_READY;
}

LWP_SemWait(semaphore);
LWP_SemDestroy(semaphore);
return FLIPPY_RESULT_OK;
}

flippyresult flippy_init(void)
{
static bool initialized;
dvdcmdblk block;
flippyversion *version = (flippyversion *)driveinfo.pad;

if (initialized) return FLIPPY_RESULT_OK;
if (initialized) return flippy_bypass(false);
DVD_Init();

if (DVD_Inquiry(&block, &driveinfo) < 0 || driveinfo.rel_date != 0x20220426)
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/source/devices/flippydrive/flippy.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ flippyresult flippy_flash_open(flippyfileinfo *info, const char *path, u32 flags
flippyresult flippy_flash_opendir(flippydirinfo *info, const char *path);
flippyresult flippy_flash_unlink(const char *path);
flippyresult flippy_rename(const char *old, const char *new);
flippyresult flippy_bypass(bool bypass);
flippyresult flippy_init(void);

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -2797,8 +2797,8 @@ void menu_loop()
if(devices[DEVICE_CUR] != NULL) {
devices[DEVICE_CUR]->deinit(devices[DEVICE_CUR]->initial);
}
DEVICEHANDLER_INTERFACE *device = getDeviceByLocation(LOC_DVD_CONNECTOR);
if(device == &__device_flippy) {
if(swissSettings.hasFlippyDrive) {
flippy_bypass(false);
flippy_reset();
}
DrawShutdown();
Expand Down
2 changes: 1 addition & 1 deletion cube/swiss/source/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ char *getExternalPath(char *path)
{ "ataa:/", "carda:" },
{ "atab:/", "cardb:" },
{ "atac:/", "fat:" },
{ "fdffs:/", "flash:" },
{ "fldrv:/", "dvd:" },
{ "flffs:/", "flash:" },
{ "gcldr:/", "dvd:" },
{ "sda:/", "carda:" },
{ "sdb:/", "cardb:" },
Expand Down

0 comments on commit 1258ad2

Please sign in to comment.