Skip to content

Commit

Permalink
- Use disc read commands after fragment setup to test the waters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 12, 2023
1 parent c1fa79b commit 4763306
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cube/swiss/source/devices/deviceHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bool getFragments(int deviceSlot, file_handle *file, file_frag **fragList, u32 *
if(forceSize == 0) {
forceSize = file->size;
}
if(!file->status && file->ffsFp) {
if(file->ffsFp && file->status == STATUS_NOT_MAPPED) {
FATFS* fatfs = file->ffsFp->obj.fs;
// fatfs - Cluster link table map buffer
DWORD clmt[(MAX_FRAGS+1)*2];
Expand Down Expand Up @@ -168,7 +168,7 @@ bool getFragments(int deviceSlot, file_handle *file, file_frag **fragList, u32 *
forceSize -= size;
numFrags++;
}
file->status = 1;
file->status = STATUS_HAS_MAPPING;
}
else if(devices[deviceSlot] == &__device_fsp) {
frags = reallocarray(frags, numFrags + 2, sizeof(file_frag));
Expand Down
7 changes: 6 additions & 1 deletion cube/swiss/source/devices/deviceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
#include "wode/WodeInterface.h"
#include "bnr.h"

#define MAX_DEVICES 20
#define PATHNAME_MAX 1024

#define STATUS_NOT_MAPPED 0
#define STATUS_MAPPED 1
#define STATUS_HAS_MAPPING 2

typedef struct {
u32 offset;
u32 size;
Expand Down Expand Up @@ -208,6 +211,8 @@ extern bool deviceHandler_getDeviceAvailable(DEVICEHANDLER_INTERFACE *dev);
extern void deviceHandler_setDeviceAvailable(DEVICEHANDLER_INTERFACE *dev, bool availability);
extern void deviceHandler_setAllDevicesAvailable();

#define MAX_DEVICES 20

extern DEVICEHANDLER_INTERFACE* allDevices[MAX_DEVICES];
extern DEVICEHANDLER_INTERFACE* devices[MAX_DEVICE_SLOTS];

Expand Down
9 changes: 3 additions & 6 deletions cube/swiss/source/devices/dvd/deviceHandler-DVD.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#include "gcm.h"
#include "wkf.h"

#define OFFSET_NOTSET 0
#define OFFSET_SET 1

file_handle initial_DVD =
{ "dvd:/", // directory
0ULL, // fileBase (u64)
Expand Down Expand Up @@ -311,7 +308,7 @@ s32 deviceHandler_DVD_readDir(file_handle* ffile, file_handle** dir, u32 type){
(*dir)[num].size = (isGC?DISC_SIZE:WII_D9_SIZE)-tmpOffset;
(*dir)[num].fileAttrib = IS_FILE;
(*dir)[num].meta = 0;
(*dir)[num].status = OFFSET_NOTSET;
(*dir)[num].status = STATUS_NOT_MAPPED;
num++;
}
}
Expand Down Expand Up @@ -387,7 +384,7 @@ s32 deviceHandler_DVD_readFile(file_handle* file, void* buffer, u32 length){
if(file->size == 0) return 0; // Don't read garbage
u64 actualOffset = file->fileBase+file->offset;

if(file->status == OFFSET_SET) {
if(file->status == STATUS_MAPPED) {
actualOffset = file->offset;
}
int bytesread = DVD_Read(buffer,actualOffset,length);
Expand Down Expand Up @@ -418,7 +415,7 @@ s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2, Executabl
DrawDispose(msgBox);
}
dvd_set_offset(file->fileBase);
file->status = OFFSET_SET;
file->status = STATUS_MAPPED;
print_gecko("Streaming %s %08X\r\n",swissSettings.audioStreaming?"Enabled":"Disabled",dvd_get_error());
}
if(numToPatch < 0) {
Expand Down
37 changes: 24 additions & 13 deletions cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int gcloaderHwVersion;
char *gcloaderVersionStr;
static FATFS *gcloaderfs = NULL;

file_handle initial_GCLOADER =
file_handle initial_GCLoader =
{ "gcldr:/", // directory
0ULL, // fileBase (u64)
0, // offset
Expand All @@ -33,6 +33,15 @@ file_handle initial_GCLOADER =
0
};

s32 deviceHandler_GCLoader_readFile(file_handle* file, void* buffer, u32 length) {
if(file->status == STATUS_MAPPED) {
s32 bytes_read = DVD_ReadPrio((dvdcmdblk*)file->other, buffer, length, file->offset, 2);
if(bytes_read > 0) file->offset += bytes_read;
return bytes_read;
}
return deviceHandler_FAT_readFile(file, buffer, length);
}

static char *bootFile_names[] = {"boot.iso", "boot.iso.iso", "boot.gcm", "boot.gcm.gcm"};

static s32 setupFile(file_handle* file, file_handle* file2, ExecutableFile* filesToPatch, int numToPatch) {
Expand Down Expand Up @@ -87,6 +96,7 @@ static s32 setupFile(file_handle* file, file_handle* file2, ExecutableFile* file

free(disc2FragList);
free(disc1FragList);
file->status = STATUS_MAPPED;
return 1;

fail:
Expand All @@ -95,7 +105,7 @@ static s32 setupFile(file_handle* file, file_handle* file2, ExecutableFile* file
return 0;
}

s32 deviceHandler_GCLOADER_setupFile(file_handle* file, file_handle* file2, ExecutableFile* filesToPatch, int numToPatch) {
s32 deviceHandler_GCLoader_setupFile(file_handle* file, file_handle* file2, ExecutableFile* filesToPatch, int numToPatch) {
if(!setupFile(file, file2, filesToPatch, numToPatch)) {
goto fail;
}
Expand Down Expand Up @@ -238,10 +248,11 @@ s32 deviceHandler_GCLOADER_setupFile(file_handle* file, file_handle* file2, Exec
break;
}
}
file->status = STATUS_NOT_MAPPED;
return 0;
}

s32 deviceHandler_GCLOADER_init(file_handle* file){
s32 deviceHandler_GCLoader_init(file_handle* file){
if(gcloaderfs != NULL) {
f_unmount("gcldr:/");
free(gcloaderfs);
Expand All @@ -253,7 +264,7 @@ s32 deviceHandler_GCLOADER_init(file_handle* file){
return file->status == FR_OK ? 0 : EIO;
}

s32 deviceHandler_GCLOADER_deinit(file_handle* file) {
s32 deviceHandler_GCLoader_deinit(file_handle* file) {
deviceHandler_FAT_closeFile(file);
if(file) {
f_unmount(file->name);
Expand All @@ -264,7 +275,7 @@ s32 deviceHandler_GCLOADER_deinit(file_handle* file) {
return 0;
}

bool deviceHandler_GCLOADER_test() {
bool deviceHandler_GCLoader_test() {
free(gcloaderVersionStr);
gcloaderVersionStr = NULL;
gcloaderHwVersion = 0;
Expand Down Expand Up @@ -296,7 +307,7 @@ bool deviceHandler_GCLOADER_test() {
return false;
}

u32 deviceHandler_GCLOADER_emulated() {
u32 deviceHandler_GCLoader_emulated() {
if (devices[DEVICE_PATCHES]) {
if (devices[DEVICE_PATCHES] != devices[DEVICE_CUR]) {
if (swissSettings.emulateReadSpeed)
Expand Down Expand Up @@ -330,20 +341,20 @@ DEVICEHANDLER_INTERFACE __device_gcloader = {
FEAT_READ|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_HYPERVISOR|FEAT_AUDIO_STREAMING,
EMU_READ|EMU_READ_SPEED|EMU_MEMCARD,
LOC_DVD_CONNECTOR,
&initial_GCLOADER,
(_fn_test)&deviceHandler_GCLOADER_test,
&initial_GCLoader,
(_fn_test)&deviceHandler_GCLoader_test,
(_fn_info)&deviceHandler_FAT_info,
(_fn_init)&deviceHandler_GCLOADER_init,
(_fn_init)&deviceHandler_GCLoader_init,
(_fn_makeDir)&deviceHandler_FAT_makeDir,
(_fn_readDir)&deviceHandler_FAT_readDir,
(_fn_seekFile)&deviceHandler_FAT_seekFile,
(_fn_readFile)&deviceHandler_FAT_readFile,
(_fn_readFile)&deviceHandler_GCLoader_readFile,
(_fn_writeFile)deviceHandler_FAT_writeFile,
(_fn_closeFile)&deviceHandler_FAT_closeFile,
(_fn_deleteFile)deviceHandler_FAT_deleteFile,
(_fn_renameFile)&deviceHandler_FAT_renameFile,
(_fn_setupFile)&deviceHandler_GCLOADER_setupFile,
(_fn_deinit)&deviceHandler_GCLOADER_deinit,
(_fn_emulated)&deviceHandler_GCLOADER_emulated,
(_fn_setupFile)&deviceHandler_GCLoader_setupFile,
(_fn_deinit)&deviceHandler_GCLoader_deinit,
(_fn_emulated)&deviceHandler_GCLoader_emulated,
(_fn_status)&deviceHandler_FAT_status,
};
6 changes: 4 additions & 2 deletions cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,9 @@ void load_app(ExecutableFile *fileToPatch)
if(fileToPatch->tgcFstOffset != 0) {
// Read FST to top of Main Memory (round to 32 byte boundary)
u32 fstAddr = (topAddr-fileToPatch->tgcFstSize)&~31;
u32 fstSize = (fileToPatch->tgcFstSize+31)&~31;
devices[DEVICE_CUR]->seekFile(fileToPatch->file,fileToPatch->tgcFstOffset,DEVICE_HANDLER_SEEK_SET);
if(devices[DEVICE_CUR]->readFile(fileToPatch->file,(void*)fstAddr,fileToPatch->tgcFstSize) != fileToPatch->tgcFstSize) {
if(devices[DEVICE_CUR]->readFile(fileToPatch->file,(void*)fstAddr,fstSize) != fstSize) {
message = "Failed to read FST!";
goto fail_early;
}
Expand All @@ -877,8 +878,9 @@ void load_app(ExecutableFile *fileToPatch)
else {
// Read FST to top of Main Memory (round to 32 byte boundary)
u32 fstAddr = (topAddr-GCMDisk.MaxFSTSize)&~31;
u32 fstSize = (GCMDisk.FSTSize+31)&~31;
devices[DEVICE_CUR]->seekFile(&curFile,GCMDisk.FSTOffset,DEVICE_HANDLER_SEEK_SET);
if(devices[DEVICE_CUR]->readFile(&curFile,(void*)fstAddr,GCMDisk.FSTSize) != GCMDisk.FSTSize) {
if(devices[DEVICE_CUR]->readFile(&curFile,(void*)fstAddr,fstSize) != fstSize) {
message = "Failed to read FST!";
goto fail_early;
}
Expand Down

0 comments on commit 4763306

Please sign in to comment.