Skip to content

Commit

Permalink
- Enable hypervisor for WODE. (untested)
Browse files Browse the repository at this point in the history
- Enable memory card emulation for WODE.
- Minor optimizations.
  • Loading branch information
Extrems committed Sep 25, 2021
1 parent 369b904 commit 088879e
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 91 deletions.
25 changes: 5 additions & 20 deletions cube/swiss/source/devices/dvd/deviceHandler-DVD.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,9 @@ s32 deviceHandler_DVD_readFile(file_handle* file, void* buffer, u32 length){
}

s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2, int numToPatch) {

if(file2) {
devices[DEVICE_CUR]->seekFile(file2, 0, DEVICE_HANDLER_SEEK_SET);
devices[DEVICE_CUR]->readFile(file2, VAR_DISC_2_ID, sizeof(VAR_DISC_2_ID));
}
devices[DEVICE_CUR]->seekFile(file, 0, DEVICE_HANDLER_SEEK_SET);
devices[DEVICE_CUR]->readFile(file, VAR_DISC_1_ID, sizeof(VAR_DISC_1_ID));

// Multi-Game disc audio streaming setup
if((dvdDiscTypeInt == COBRA_MULTIGAME_DISC)||(dvdDiscTypeInt == GCOSD5_MULTIGAME_DISC)||(dvdDiscTypeInt == GCOSD9_MULTIGAME_DISC)) {
dvddiskid *diskId = (dvddiskid*)VAR_DISC_1_ID;
if(diskId->streaming && !isXenoGC) {
if(swissSettings.audioStreaming && !isXenoGC) {
uiDrawObj_t *msgBox = DrawPublish(DrawProgressBar(true, 0, "One moment, setting up audio streaming."));
dvd_motor_off();
print_gecko("Set extension %08X\r\n",dvd_get_error());
Expand All @@ -408,14 +399,14 @@ s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2, int numTo
print_gecko("Set Status - done %08X\r\n",dvd_get_error());
dvd_read_id();
print_gecko("Read ID %08X\r\n",dvd_get_error());
dvd_set_streaming(diskId->streaming);
dvd_set_streaming(swissSettings.audioStreaming);
DrawDispose(msgBox);
}
dvd_set_offset(file->fileBase);
file->status = OFFSET_SET;
print_gecko("Streaming %s %08X\r\n",diskId->streaming?"Enabled":"Disabled",dvd_get_error());
print_gecko("Streaming %s %08X\r\n",swissSettings.audioStreaming?"Enabled":"Disabled",dvd_get_error());
}

// Check if there are any fragments in our patch location for this game
if(devices[DEVICE_PATCHES] != NULL) {
int i;
Expand Down Expand Up @@ -530,14 +521,8 @@ s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2, int numTo
*(vu8*)VAR_EXI_SLOT = (u8)(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2));
*(vu32**)VAR_EXI_REGS = ((vu32(*)[5])0xCC006800)[*(vu8*)VAR_EXI_SLOT];
}
else {
*(vu8*)VAR_SD_SHIFT = 32;
*(vu8*)VAR_EXI_FREQ = EXI_SPEED1MHZ;
*(vu8*)VAR_EXI_SLOT = EXI_CHANNEL_MAX;
*(vu32**)VAR_EXI_REGS = NULL;
}

*(vu8*)VAR_DRIVE_PATCHED = drive_status == DEBUG_MODE;
memcpy(VAR_DISC_1_ID, (char*)&GCMDisk, sizeof(VAR_DISC_1_ID));
return 1;
}

Expand Down
6 changes: 0 additions & 6 deletions cube/swiss/source/devices/fsp/deviceHandler-FSP.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,6 @@ s32 deviceHandler_FSP_setupFile(file_handle* file, file_handle* file2, int numTo
*(vu8*)VAR_EXI_SLOT = (u8)(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2));
*(vu32**)VAR_EXI_REGS = ((vu32(*)[5])0xCC006800)[*(vu8*)VAR_EXI_SLOT];
}
else {
*(vu8*)VAR_SD_SHIFT = 32;
*(vu8*)VAR_EXI_FREQ = EXI_SPEED1MHZ;
*(vu8*)VAR_EXI_SLOT = EXI_CHANNEL_MAX;
*(vu32**)VAR_EXI_REGS = NULL;
}

if(fragList) {
memset(&fragList[totFrags], 0, sizeof(*fragList));
Expand Down
15 changes: 1 addition & 14 deletions cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,13 @@ s32 deviceHandler_GCLOADER_writeFile(file_handle* file, void* buffer, u32 length


s32 deviceHandler_GCLOADER_setupFile(file_handle* file, file_handle* file2, int numToPatch) {

// GCLoader disc/file fragment setup
s32 maxDiscFrags = MAX_GCLOADER_FRAGS_PER_DISC;
u32 discFragList[maxDiscFrags][3];
s32 disc1Frags = 0, disc2Frags = 0;

// If there is a disc 2 and it's fragmented, make a note of the fragments and their sizes
if(file2) {
devices[DEVICE_CUR]->seekFile(file2, 0, DEVICE_HANDLER_SEEK_SET);
devices[DEVICE_CUR]->readFile(file2, VAR_DISC_2_ID, sizeof(VAR_DISC_2_ID));

if(!(disc2Frags = getFragments(file2, &discFragList[0], maxDiscFrags, 0, DISC_SIZE, DEVICE_CUR))) {
return 0;
}
Expand All @@ -83,9 +79,6 @@ s32 deviceHandler_GCLOADER_setupFile(file_handle* file, file_handle* file2, int
// write disc 2 frags
gcloaderWriteFrags(1, &discFragList[0], disc2Frags);

devices[DEVICE_CUR]->seekFile(file, 0, DEVICE_HANDLER_SEEK_SET);
devices[DEVICE_CUR]->readFile(file, VAR_DISC_1_ID, sizeof(VAR_DISC_1_ID));

// If disc 1 is fragmented, make a note of the fragments and their sizes
if(!(disc1Frags = getFragments(file, &discFragList[0], maxDiscFrags, 0, DISC_SIZE, DEVICE_CUR))) {
return 0;
Expand Down Expand Up @@ -222,13 +215,7 @@ s32 deviceHandler_GCLOADER_setupFile(file_handle* file, file_handle* file2, int
*(vu8*)VAR_EXI_SLOT = (u8)(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2));
*(vu32**)VAR_EXI_REGS = ((vu32(*)[5])0xCC006800)[*(vu8*)VAR_EXI_SLOT];
}
else {
*(vu8*)VAR_SD_SHIFT = 32;
*(vu8*)VAR_EXI_FREQ = EXI_SPEED1MHZ;
*(vu8*)VAR_EXI_SLOT = EXI_CHANNEL_MAX;
*(vu32**)VAR_EXI_REGS = NULL;
}

memcpy(VAR_DISC_1_ID, (char*)&GCMDisk, sizeof(VAR_DISC_1_ID));
return 1;
}

Expand Down
6 changes: 0 additions & 6 deletions cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ s32 deviceHandler_USBGecko_setupFile(file_handle* file, file_handle* file2, int
*(vu8*)VAR_EXI_SLOT = (u8)(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2));
*(vu32**)VAR_EXI_REGS = ((vu32(*)[5])0xCC006800)[*(vu8*)VAR_EXI_SLOT];
}
else {
*(vu8*)VAR_SD_SHIFT = 32;
*(vu8*)VAR_EXI_FREQ = EXI_SPEED1MHZ;
*(vu8*)VAR_EXI_SLOT = EXI_CHANNEL_MAX;
*(vu32**)VAR_EXI_REGS = NULL;
}

if(fragList) {
memset(&fragList[totFrags], 0, sizeof(*fragList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@ s32 deviceHandler_WKF_setupFile(file_handle* file, file_handle* file2, int numTo
*(vu8*)VAR_EXI_SLOT = (u8)(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2));
*(vu32**)VAR_EXI_REGS = ((vu32(*)[5])0xCC006800)[*(vu8*)VAR_EXI_SLOT];
}
else {
*(vu8*)VAR_SD_SHIFT = 32;
*(vu8*)VAR_EXI_FREQ = EXI_SPEED1MHZ;
*(vu8*)VAR_EXI_SLOT = EXI_CHANNEL_MAX;
*(vu32**)VAR_EXI_REGS = NULL;
}

// If disc 1 is fragmented, make a note of the fragments and their sizes
if(!(fragList = realloc(fragList, (totFrags + MAX_FRAGS + 1) * sizeof(*fragList)))) {
Expand Down
141 changes: 132 additions & 9 deletions cube/swiss/source/devices/wode/deviceHandler-WODE.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#include "deviceHandler.h"
#include "gui/FrameBufferMagic.h"
#include "gui/IPLFontWrite.h"
#include "main.h"
#include "swiss.h"
#include "main.h"
#include "patcher.h"
#include "dvd.h"
#include "WodeInterface.h"

Expand Down Expand Up @@ -118,11 +119,130 @@ s32 deviceHandler_WODE_readFile(file_handle* file, void* buffer, u32 length) {
}

s32 deviceHandler_WODE_setupFile(file_handle* file, file_handle* file2, int numToPatch) {
ISOInfo_t* isoInfo = (ISOInfo_t*)&file->other;
SetISO(isoInfo->iso_partition,isoInfo->iso_number);
sleep(2);
DVD_Reset(DVD_RESETHARD);
while(dvd_get_error()) {dvd_read_id();}
if(numToPatch < 0) {
ISOInfo_t* isoInfo = (ISOInfo_t*)&file->other;
SetISO(isoInfo->iso_partition,isoInfo->iso_number);
sleep(2);
DVD_Reset(DVD_RESETHARD);
while(dvd_get_error()) {dvd_read_id();}
return 1;
}

// Check if there are any fragments in our patch location for this game
if(devices[DEVICE_PATCHES] != NULL) {
int i;
u32 (*fragList)[3] = NULL;
s32 frags = 0, totFrags = 0;

print_gecko("Save Patch device found\r\n");

// Look for patch files, if we find some, open them and add them as fragments
file_handle patchFile;
for(i = 0; i < numToPatch; i++) {
memset(&patchFile, 0, sizeof(file_handle));
snprintf(&patchFile.name[0], PATHNAME_MAX, "%sswiss_patches/%.4s/%i", devices[DEVICE_PATCHES]->initial->name, (char*)&GCMDisk, i);

if(devices[DEVICE_PATCHES]->readFile(&patchFile, NULL, 0) == 0) {
u32 patchInfo[4];
memset(patchInfo, 0, 16);
devices[DEVICE_PATCHES]->seekFile(&patchFile, patchFile.size-16, DEVICE_HANDLER_SEEK_SET);
if((devices[DEVICE_PATCHES]->readFile(&patchFile, &patchInfo, 16) == 16) && (patchInfo[2] == SWISS_MAGIC)) {
if(!(fragList = realloc(fragList, (totFrags + MAX_FRAGS + 1) * sizeof(*fragList)))) {
return 0;
}
if(!(frags = getFragments(&patchFile, &fragList[totFrags], MAX_FRAGS, patchInfo[0], patchInfo[1], DEVICE_PATCHES))) {
free(fragList);
return 0;
}
totFrags+=frags;
devices[DEVICE_PATCHES]->closeFile(&patchFile);
}
else {
devices[DEVICE_PATCHES]->deleteFile(&patchFile);
free(fragList);
return 0;
}
}
else {
free(fragList);
return 0;
}
}

// Check for igr.dol
if(swissSettings.igrType == IGR_BOOTBIN) {
memset(&patchFile, 0, sizeof(file_handle));
snprintf(&patchFile.name[0], PATHNAME_MAX, "%sigr.dol", devices[DEVICE_PATCHES]->initial->name);

if(!(fragList = realloc(fragList, (totFrags + MAX_FRAGS + 1) * sizeof(*fragList)))) {
return 0;
}
if((frags = getFragments(&patchFile, &fragList[totFrags], MAX_FRAGS, FRAGS_IGR_DOL, 0, DEVICE_PATCHES))) {
totFrags+=frags;
devices[DEVICE_PATCHES]->closeFile(&patchFile);
}
}

if(swissSettings.emulateMemoryCard) {
if(devices[DEVICE_PATCHES] != &__device_sd_a) {
memset(&patchFile, 0, sizeof(file_handle));
snprintf(&patchFile.name[0], PATHNAME_MAX, "%sswiss_patches/MemoryCardA.%s.raw", devices[DEVICE_PATCHES]->initial->name, wodeRegionToString(GCMDisk.RegionCode));

if(devices[DEVICE_PATCHES]->readFile(&patchFile, NULL, 0) != 0) {
devices[DEVICE_PATCHES]->seekFile(&patchFile, 16*1024*1024, DEVICE_HANDLER_SEEK_SET);
devices[DEVICE_PATCHES]->writeFile(&patchFile, NULL, 0);
devices[DEVICE_PATCHES]->closeFile(&patchFile);
}

if(!(fragList = realloc(fragList, (totFrags + MAX_FRAGS + 1) * sizeof(*fragList)))) {
return 0;
}
if((frags = getFragments(&patchFile, &fragList[totFrags], MAX_FRAGS, FRAGS_CARD_A, 31.5*1024*1024, DEVICE_PATCHES))) {
*(vu8*)VAR_CARD_A_ID = (patchFile.size*8/1024/1024) & 0xFC;
totFrags+=frags;
devices[DEVICE_PATCHES]->closeFile(&patchFile);
}
}

if(devices[DEVICE_PATCHES] != &__device_sd_b) {
memset(&patchFile, 0, sizeof(file_handle));
snprintf(&patchFile.name[0], PATHNAME_MAX, "%sswiss_patches/MemoryCardB.%s.raw", devices[DEVICE_PATCHES]->initial->name, wodeRegionToString(GCMDisk.RegionCode));

if(devices[DEVICE_PATCHES]->readFile(&patchFile, NULL, 0) != 0) {
devices[DEVICE_PATCHES]->seekFile(&patchFile, 16*1024*1024, DEVICE_HANDLER_SEEK_SET);
devices[DEVICE_PATCHES]->writeFile(&patchFile, NULL, 0);
devices[DEVICE_PATCHES]->closeFile(&patchFile);
}

if(!(fragList = realloc(fragList, (totFrags + MAX_FRAGS + 1) * sizeof(*fragList)))) {
return 0;
}
if((frags = getFragments(&patchFile, &fragList[totFrags], MAX_FRAGS, FRAGS_CARD_B, 31.5*1024*1024, DEVICE_PATCHES))) {
*(vu8*)VAR_CARD_B_ID = (patchFile.size*8/1024/1024) & 0xFC;
totFrags+=frags;
devices[DEVICE_PATCHES]->closeFile(&patchFile);
}
}
}

if(fragList) {
memset(&fragList[totFrags], 0, sizeof(*fragList));
print_frag_list(fragList);

*(vu32**)VAR_FRAG_LIST = installPatch2(fragList, (totFrags + 1) * sizeof(*fragList));
free(fragList);
fragList = NULL;
}

// Card Type
*(vu8*)VAR_SD_SHIFT = (u8)(sdgecko_getAddressingType(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2)) ? 9:0);
// Copy the actual freq
*(vu8*)VAR_EXI_FREQ = (u8)(sdgecko_getSpeed(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2)));
// Device slot (0, 1 or 2)
*(vu8*)VAR_EXI_SLOT = (u8)(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2));
*(vu32**)VAR_EXI_REGS = ((vu32(*)[5])0xCC006800)[*(vu8*)VAR_EXI_SLOT];
}
memcpy(VAR_DISC_1_ID, (char*)&GCMDisk, sizeof(VAR_DISC_1_ID));
return 1;
}

Expand Down Expand Up @@ -153,7 +273,10 @@ bool deviceHandler_WODE_test() {
}

u32 deviceHandler_WODE_emulated() {
return EMU_NONE;
if (swissSettings.emulateMemoryCard)
return EMU_MEMCARD;
else
return EMU_NONE;
}

DEVICEHANDLER_INTERFACE __device_wode = {
Expand All @@ -162,8 +285,8 @@ DEVICEHANDLER_INTERFACE __device_wode = {
"WODE Jukebox",
"Supported File System(s): FAT32, NTFS, EXT2/3, HPFS",
{TEX_WODEIMG, 116, 40},
FEAT_READ|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE,
EMU_NONE,
FEAT_READ|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_HYPERVISOR,
EMU_MEMCARD,
LOC_DVD_CONNECTOR,
&initial_WODE,
(_fn_test)&deviceHandler_WODE_test,
Expand Down
2 changes: 1 addition & 1 deletion cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int install_code(int final)
print_gecko("Installing Patch for SD Card over EXI\r\n");
}
// DVD
else if(devices[DEVICE_CUR] == &__device_dvd) {
else if(devices[DEVICE_CUR] == &__device_dvd || devices[DEVICE_CUR] == &__device_wode) {
switch (devices[DEVICE_CUR]->emulated()) {
case EMU_NONE:
patch = dvd_bin;
Expand Down
59 changes: 30 additions & 29 deletions cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1709,9 +1709,11 @@ bool manage_file() {
}

void load_game() {
file_handle *disc2File = meta_find_disk2(&curFile);

if(devices[DEVICE_CUR] == &__device_wode) {
uiDrawObj_t *msgBox = DrawPublish(DrawProgressBar(true, 0, "Setup base offset please Wait .."));
devices[DEVICE_CUR]->setupFile(&curFile, NULL, 0);
devices[DEVICE_CUR]->setupFile(&curFile, disc2File, -1);
DrawDispose(msgBox);
}
uiDrawObj_t *msgBox = DrawPublish(DrawProgressBar(true, 0, "Reading ..."));
Expand Down Expand Up @@ -1791,15 +1793,12 @@ void load_game() {
config_unload_current();
return;
}
if(devices[DEVICE_CUR] != &__device_wode) {
file_handle *disc2File = meta_find_disk2(&curFile);
if(!devices[DEVICE_CUR]->setupFile(&curFile, disc2File, 0)) {
msgBox = DrawPublish(DrawMessageBox(D_FAIL, "Failed to setup the file (too fragmented?)"));
wait_press_A();
DrawDispose(msgBox);
config_unload_current();
return;
}
if(!devices[DEVICE_CUR]->setupFile(&curFile, disc2File, 0)) {
msgBox = DrawPublish(DrawMessageBox(D_FAIL, "Failed to setup the file (too fragmented?)"));
wait_press_A();
DrawDispose(msgBox);
config_unload_current();
return;
}
if(devices[DEVICE_CUR] != &__device_dvd) {
devices[DEVICE_CUR]->deinit(&curFile);
Expand Down Expand Up @@ -1839,25 +1838,27 @@ void load_game() {
numToPatch = check_game(filesToPatch);
}

if(devices[DEVICE_CUR] != &__device_wode) {
file_handle *disc2File = meta_find_disk2(&curFile);
*(vu8*)VAR_CURRENT_DISC = 0;
*(vu8*)VAR_SECOND_DISC = disc2File ? 1:0;
*(vu8*)VAR_DRIVE_PATCHED = 0;
*(vu8*)VAR_EMU_READ_SPEED = swissSettings.emulateReadSpeed;
*(vu8*)VAR_IGR_TYPE = swissSettings.igrType;
*(vu32**)VAR_FRAG_LIST = NULL;
*(vu8*)VAR_CARD_A_ID = 0x00;
*(vu8*)VAR_CARD_B_ID = 0x00;
// Call the special setup for each device (e.g. SD will set the sector(s))
if(!devices[DEVICE_CUR]->setupFile(&curFile, disc2File, numToPatch)) {
msgBox = DrawPublish(DrawMessageBox(D_FAIL, "Failed to setup the file (too fragmented?)"));
wait_press_A();
free(filesToPatch);
DrawDispose(msgBox);
config_unload_current();
return;
}
*(vu8*)VAR_CURRENT_DISC = 0;
*(vu8*)VAR_SECOND_DISC = disc2File ? 1:0;
*(vu8*)VAR_DRIVE_PATCHED = 0;
*(vu8*)VAR_EMU_READ_SPEED = swissSettings.emulateReadSpeed;
*(vu32**)VAR_EXI_REGS = NULL;
*(vu8*)VAR_EXI_SLOT = EXI_CHANNEL_0;
*(vu8*)VAR_EXI_FREQ = EXI_SPEED1MHZ;
*(vu8*)VAR_SD_SHIFT = 0;
*(vu8*)VAR_IGR_TYPE = swissSettings.igrType;
*(vu32**)VAR_FRAG_LIST = NULL;
*(vu8*)VAR_CARD_A_ID = 0x00;
*(vu8*)VAR_CARD_B_ID = 0x00;

// Call the special setup for each device (e.g. SD will set the sector(s))
if(!devices[DEVICE_CUR]->setupFile(&curFile, disc2File, numToPatch)) {
msgBox = DrawPublish(DrawMessageBox(D_FAIL, "Failed to setup the file (too fragmented?)"));
wait_press_A();
free(filesToPatch);
DrawDispose(msgBox);
config_unload_current();
return;
}

load_app(filesToPatch, numToPatch);
Expand Down

0 comments on commit 088879e

Please sign in to comment.