Skip to content

Commit

Permalink
- Fix return to loader on GC Loader with data.iso present.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Jan 25, 2025
1 parent d6897bd commit d34d7f1
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 25 deletions.
42 changes: 40 additions & 2 deletions cube/patches/stub/asmfunc.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024, Extrems <[email protected]>
* Copyright (c) 2020-2025, Extrems <[email protected]>
*
* This file is part of Swiss.
*
Expand Down Expand Up @@ -65,13 +65,37 @@ xmit_spi:
srwi r3, r0, 24
blr

.globl dvd_reset
dvd_reset:
lis r3, 0x0C00
li r4, 0x3000 + 9*4
eciwx r0, r4, r3
rlwinm r0, r0, 0, 30, 28
ori r0, r0, 0b001
ecowx r0, r4, r3
mftb r5
1: mftb r6
sub r0, r6, r5
cmplwi r0, 486
blt 1b
eciwx r0, r4, r3
ori r0, r0, 0b101
ecowx r0, r4, r3
blr

.globl dvd_inquiry
dvd_inquiry:
lis r6, 0x1200
li r5, 0
1: li r5, 0
li r4, 32
b dvd_readdma

.globl dvd_read_id
dvd_read_id:
lis r6, 0xA800
ori r6, r6, 0x0040
b 1b

.globl dvd_read
dvd_read:
lis r6, 0xA800
Expand Down Expand Up @@ -115,6 +139,20 @@ dvd_readdma:
3: li r3, 0
blr

.globl dvd_stop_motor
dvd_stop_motor:
lis r3, 0x0C00
li r4, 0x6000 + 2*4
lis r0, 0xE300
ecowx r0, r4, r3
li r4, 0x6000 + 7*4
li r0, 0b001
ecowx r0, r4, r3
1: eciwx r0, r4, r3
andi. r0, r0, 0b001
bne 1b
blr

.globl flippy_reset
flippy_reset:
lis r3, 0x0C00
Expand Down
14 changes: 13 additions & 1 deletion cube/patches/stub/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2024, Extrems <[email protected]>
* Copyright (c) 2020-2025, Extrems <[email protected]>
*
* This file is part of Swiss.
*
Expand Down Expand Up @@ -51,8 +51,11 @@ static bool memeq(const void *a, const void *b, size_t size)
return true;
}

void dvd_reset(void);
uint32_t dvd_inquiry(DVDDriveInfo *info);
uint32_t dvd_read_id(DVDDiskID *id);
uint32_t dvd_read(void *address, uint32_t length, uint32_t offset);
void dvd_stop_motor(void);
void flippy_reset(void);

static void dvd_load(uint32_t offset)
Expand Down Expand Up @@ -89,6 +92,15 @@ void dvd_main(void)
if (!dvd_inquiry(&info)) return;

switch (info.releaseDate) {
case 0x20196C64:
{
dvd_stop_motor();
dvd_reset();
dly_us(1150 * 1000);
dvd_reset();
if (!dvd_read_id(NULL)) return;
break;
}
case 0x20220426:
flippy_reset();
case 0x20220420:
Expand Down
43 changes: 22 additions & 21 deletions cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,20 @@ s32 deviceHandler_GCLoader_readFile(file_handle* file, void* buffer, u32 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) {
bool gcloaderGetBootFile(file_handle* file) {
int i;
for(i = 0; i < sizeof(bootFile_names)/sizeof(char*); i++) {
memset(file, 0, sizeof(file_handle));
concat_path(file->name, initial_GCLoader.name, bootFile_names[i]);

if(!deviceHandler_FAT_statFile(file)) {
return true;
}
}
return false;
}

static s32 gcloaderSetupFile(file_handle* file, file_handle* file2, ExecutableFile* filesToPatch, int numToPatch) {
// GCLoader disc/file fragment setup
file_frag *disc1FragList = NULL, *disc2FragList = NULL;
u32 disc1Frags = 0, disc2Frags = 0;
Expand Down Expand Up @@ -113,7 +126,7 @@ s32 deviceHandler_GCLoader_setupFile(file_handle* file, file_handle* file2, Exec
file_frag *fragList = NULL;
u32 numFrags = 0;

if(!setupFile(file, file2, filesToPatch, numToPatch)) {
if(!gcloaderSetupFile(file, file2, filesToPatch, numToPatch)) {
return 0;
}
if(numToPatch < 0 || !devices[DEVICE_CUR]->emulated()) {
Expand Down Expand Up @@ -145,15 +158,9 @@ s32 deviceHandler_GCLoader_setupFile(file_handle* file, file_handle* file2, Exec
}
}

for(i = 0; i < sizeof(bootFile_names)/sizeof(char*); i++) {
file_handle bootFile;
memset(&bootFile, 0, sizeof(file_handle));
concat_path(bootFile.name, initial_GCLoader.name, bootFile_names[i]);

if(getFragments(DEVICE_CUR, &bootFile, &fragList, &numFrags, FRAGS_BOOT_GCM, 0, UINT32_MAX)) {
devices[DEVICE_CUR]->closeFile(&bootFile);
break;
}
if(gcloaderGetBootFile(&patchFile)) {
getFragments(DEVICE_CUR, &patchFile, &fragList, &numFrags, FRAGS_BOOT_GCM, 0, UINT32_MAX);
devices[DEVICE_CUR]->closeFile(&patchFile);
}

if(swissSettings.igrType == IGR_APPLOADER || endsWith(file->name,".tgc")) {
Expand Down Expand Up @@ -243,16 +250,10 @@ s32 deviceHandler_GCLoader_init(file_handle* file){

s32 deviceHandler_GCLoader_closeFile(file_handle* file) {
if(file && file->status == STATUS_MAPPED) {
int i;
for(i = 0; i < sizeof(bootFile_names)/sizeof(char*); i++) {
file_handle bootFile;
memset(&bootFile, 0, sizeof(file_handle));
concat_path(bootFile.name, initial_GCLoader.name, bootFile_names[i]);

if(setupFile(&bootFile, NULL, NULL, -1)) {
deviceHandler_FAT_closeFile(&bootFile);
break;
}
file_handle bootFile;
if(gcloaderGetBootFile(&bootFile)) {
gcloaderSetupFile(&bootFile, NULL, NULL, -1);
deviceHandler_FAT_closeFile(&bootFile);
}
file->status = STATUS_NOT_MAPPED;
}
Expand Down
2 changes: 2 additions & 0 deletions cube/swiss/source/devices/gcloader/deviceHandler-gcloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@

extern DEVICEHANDLER_INTERFACE __device_gcloader;

bool gcloaderGetBootFile(file_handle* file);

#endif

14 changes: 13 additions & 1 deletion cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,16 @@ void boot_dol(file_handle* file, int argc, char *argv[])
devices[DEVICE_CUR]->statFile(imageFile);
}

file_handle *bootFile = NULL;
if(devices[DEVICE_CUR] == &__device_gcloader) {
bootFile = calloc(1, sizeof(file_handle));

if(!gcloaderGetBootFile(bootFile)) {
free(bootFile);
bootFile = NULL;
}
}

// Build a command line to pass to the DOL
char *argz = getExternalPath(imageFile->fileType == IS_FILE ? imageFile->name : file->name);
size_t argz_len = strlen(argz) + 1;
Expand Down Expand Up @@ -1412,7 +1422,7 @@ void boot_dol(file_handle* file, int argc, char *argv[])

// Boot
if(devices[DEVICE_CUR]->location == LOC_DVD_CONNECTOR) {
devices[DEVICE_CUR]->setupFile(imageFile, NULL, NULL, -1);
devices[DEVICE_CUR]->setupFile(imageFile, bootFile, NULL, -1);
}

if(!memcmp(buffer, ELFMAG, SELFMAG)) {
Expand All @@ -1430,7 +1440,9 @@ void boot_dol(file_handle* file, int argc, char *argv[])
free(argz);
free(buffer);

devices[DEVICE_CUR]->closeFile(bootFile);
devices[DEVICE_CUR]->closeFile(imageFile);
free(bootFile);
free(imageFile);
}

Expand Down

0 comments on commit d34d7f1

Please sign in to comment.