Skip to content

Commit

Permalink
- Add workaround for byteswapped file size.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 10, 2024
1 parent edcb2f7 commit b79bdb2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
10 changes: 6 additions & 4 deletions cube/swiss/source/devices/deviceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ typedef char* (* _fn_details)(file_handle*);
// Device quirks
#define QUIRK_NONE 0x0
#define QUIRK_EXI_SPEED 0x1
#define QUIRK_GCLOADER_NO_DISC_2 0x2
#define QUIRK_GCLOADER_NO_PARTIAL_READ 0x4
#define QUIRK_GCLOADER_WRITE_CONFLICT 0x8
#define QUIRK_NO_DEINIT 0x10
#define QUIRK_FDI_BYTESWAP_SIZE 0x2
#define QUIRK_FDI_EXCLUSIVE_OPEN 0x4
#define QUIRK_GCLOADER_NO_DISC_2 0x8
#define QUIRK_GCLOADER_NO_PARTIAL_READ 0x10
#define QUIRK_GCLOADER_WRITE_CONFLICT 0x20
#define QUIRK_NO_DEINIT 0x40

// Device emulated features
#define EMU_READ 0x80000000
Expand Down
17 changes: 15 additions & 2 deletions cube/swiss/source/devices/flippydrive/deviceHandler-flippydrive.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ s32 deviceHandler_Flippy_readFile(file_handle* file, void* buffer, u32 length) {
return bytes_read;
}
if(!file->fp) {
if(endsWith(file->name,".fdi") && (getDeviceFromPath(file->name)->quirks & QUIRK_FDI_EXCLUSIVE_OPEN)) {
return -1;
}
file->fp = memalign(32, sizeof(flippyfileinfo));
if((getDeviceFromPath(file->name) == &__device_flippyflash ?
flippy_flash_open(file->fp, getDevicePath(file->name), defaultFlags(file)) :
Expand All @@ -109,6 +112,11 @@ s32 deviceHandler_Flippy_readFile(file_handle* file, void* buffer, u32 length) {
return -1;
}
flippyfileinfo* info = file->fp;
if(endsWith(file->name,".fdi") && (getDeviceFromPath(file->name)->quirks & QUIRK_FDI_BYTESWAP_SIZE)) {
if(info->file.size != file->size) {
info->file.size = __builtin_bswap32(info->file.size >> 9 << 8) << 9;
}
}
file->size = info->file.size;
}
if(file->offset > file->size) {
Expand Down Expand Up @@ -323,10 +331,15 @@ bool deviceHandler_Flippy_test() {
}
case 0x20220426:
flippyversion *version = (flippyversion *)driveInfo.pad;
__device_flippy.quirks = QUIRK_NO_DEINIT;

if (FLIPPY_VERSION(version->major, version->minor, version->build) < FLIPPY_VERSION(1,3,1))
__device_flippy.extraExtensions = NULL;
if (FLIPPY_VERSION(version->major, version->minor, version->build) < FLIPPY_VERSION(1,3,3))
__device_flippy.quirks |= QUIRK_FDI_BYTESWAP_SIZE;

if (FLIPPY_VERSION(version->major, version->minor, version->build) < FLIPPY_VERSION(1,3,1)) {
__device_flippy.extraExtensions = NULL;
__device_flippy.quirks |= QUIRK_FDI_EXCLUSIVE_OPEN;
}
swissSettings.hasFlippyDrive = 1;
return true;
}
Expand Down

0 comments on commit b79bdb2

Please sign in to comment.