Skip to content

Commit

Permalink
- Bug fixing
Browse files Browse the repository at this point in the history
-- Fix config device init
-- Only if DVD TC Interrupt is enabled, fake interrupt
-- Fix DVD based patches that go to SD Gecko
-- Fix stupid maskable overlap in deviceHandler.h
-- Fix device select
  • Loading branch information
emukidid committed Jun 10, 2017
1 parent 430e48a commit e372245
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 136 deletions.
6 changes: 4 additions & 2 deletions cube/patches/base/dvdinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ void DIUpdateRegisters() {
// Keep mask on SR but also set our TC INT to indicate operation complete
dvd[DI_SR] |= 0x10;
dvd[DI_CR] &= 2;
*(u32*)VAR_FAKE_IRQ_SET = 1;
trigger_dvd_interrupt();
if(dvd[DI_SR] & 0x8) { // TC Interrupt Enabled
*(u32*)VAR_FAKE_IRQ_SET = 4;
trigger_dvd_interrupt();
}
}
}
4 changes: 3 additions & 1 deletion cube/swiss/source/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ bool config_set_device() {
if(devices[DEVICE_CONFIG] == NULL) {
return false;
}

deviceHandler_setStatEnabled(0);
// If we're not using this device already, init it.
if(devices[DEVICE_CONFIG] != devices[DEVICE_CUR]) {
if(!devices[DEVICE_CONFIG]->init(devices[DEVICE_CONFIG]->initial)) {
deviceHandler_setStatEnabled(1);
return false;
}
}
deviceHandler_setStatEnabled(1);
return true;
}

Expand Down
27 changes: 14 additions & 13 deletions cube/swiss/source/devices/deviceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,23 @@ typedef s32 (* _fn_deinit)(file_handle*);
typedef device_info* (* _fn_deviceInfo)(void);

// Device features
#define FEAT_READ 0x100
#define FEAT_WRITE 0x200
#define FEAT_BOOT_GCM 0x4000
#define FEAT_BOOT_DEVICE 0x8000
#define FEAT_AUTOLOAD_DOL 0xC000
#define FEAT_FAT_FUNCS 0x10000
#define FEAT_REPLACES_DVD_FUNCS 0x20000
#define FEAT_READ 0x1
#define FEAT_WRITE 0x2
#define FEAT_BOOT_GCM 0x4
#define FEAT_BOOT_DEVICE 0x8
#define FEAT_AUTOLOAD_DOL 0x10
#define FEAT_FAT_FUNCS 0x20
#define FEAT_REPLACES_DVD_FUNCS 0x40
#define FEAT_CAN_READ_PATCHES 0x80

// Device locations
#define LOC_MEMCARD_SLOT_A 0x1
#define LOC_MEMCARD_SLOT_B 0x10
#define LOC_DVD_CONNECTOR 0x100
#define LOC_SERIAL_PORT_1 0x1000
#define LOC_SERIAL_PORT_2 0x2000
#define LOC_HSP 0x4000
#define LOC_SYSTEM 0x8000
#define LOC_MEMCARD_SLOT_B 0x2
#define LOC_DVD_CONNECTOR 0x4
#define LOC_SERIAL_PORT_1 0x8
#define LOC_SERIAL_PORT_2 0x10
#define LOC_HSP 0x20
#define LOC_SYSTEM 0x40

// Device unique Id (used to store last used config device in SRAM - configDeviceId)
#define DEVICE_ID_0 0x00
Expand Down
25 changes: 15 additions & 10 deletions cube/swiss/source/devices/dvd/deviceHandler-DVD.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2) {
print_gecko("Streaming %s %08X\r\n",streaming?"Enabled":"Disabled",dvd_get_error());
}
// Check if there are any fragments in our patch location for this game
if(savePatchDevice>=0) {
if(devices[DEVICE_PATCHES] != NULL) {
print_gecko("Save Patch device found\r\n");
// If there are 2 discs, we only allow 5 fragments per disc.
int maxFrags = (VAR_FRAG_SIZE/12), i = 0;
Expand All @@ -423,21 +423,25 @@ s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2) {
// Look for .patchX files, if we find some, open them and add them as fragments
file_handle patchFile;
int patches = 0;
char gameID[8];
memset(&gameID, 0, 8);
strncpy((char*)&gameID, (char*)&GCMDisk, 4);

for(i = 0; i < maxFrags; i++) {
u32 patchInfo[3];
u32 patchInfo[4];
patchInfo[0] = 0; patchInfo[1] = 0;
memset(&patchFile, 0, sizeof(file_handle));
sprintf(&patchFile.name[0], "%s:/swiss_patches/%i",(savePatchDevice ? "sdb":"sda"), i);

sprintf(&patchFile.name[0], "%sswiss_patches/%s/%i",devices[DEVICE_PATCHES]->initial->name,gameID, i);
print_gecko("Looking for file %s\r\n", &patchFile.name);
struct stat fstat;
if(stat(&patchFile.name[0],&fstat)) {
break;
}
patchFile.fp = fopen(&patchFile.name[0], "rb");
if(patchFile.fp) {
fseek(patchFile.fp, fstat.st_size-12, SEEK_SET);
fseek(patchFile.fp, fstat.st_size-16, SEEK_SET);

if((fread(&patchInfo, 1, 12, patchFile.fp) == 12) && (patchInfo[2] == SWISS_MAGIC)) {
if((fread(&patchInfo, 1, 16, patchFile.fp) == 16) && (patchInfo[2] == SWISS_MAGIC)) {
get_frag_list(&patchFile.name[0]);
print_gecko("Found patch file %i ofs 0x%08X len 0x%08X base 0x%08X\r\n",
i, patchInfo[0], patchInfo[1], frag_list->frag[0].sector);
Expand All @@ -461,12 +465,13 @@ s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2) {
// Copy the current speed
*(volatile unsigned int*)VAR_EXI_BUS_SPD = 192;
// Card Type
*(volatile unsigned int*)VAR_SD_TYPE = sdgecko_getAddressingType(savePatchDevice);
*(volatile unsigned int*)VAR_SD_TYPE = sdgecko_getAddressingType(((devices[DEVICE_PATCHES]->location == LOC_MEMCARD_SLOT_A) ? 0:1));
// Copy the actual freq
*(volatile unsigned int*)VAR_EXI_FREQ = EXI_SPEED16MHZ;
*(volatile unsigned int*)VAR_EXI_FREQ = EXI_SPEED16MHZ; // play it safe
// Device slot (0 or 1) // This represents 0xCC0068xx in number of u32's so, slot A = 0xCC006800, B = 0xCC006814
*(volatile unsigned int*)VAR_EXI_SLOT = savePatchDevice * 5;
*(volatile unsigned int*)VAR_EXI_SLOT = ((devices[DEVICE_PATCHES]->location == LOC_MEMCARD_SLOT_A) ? 0:1) * 5;
}

return 1;
}

Expand Down Expand Up @@ -502,7 +507,7 @@ DEVICEHANDLER_INTERFACE __device_dvd = {
"DVD",
"Supported File System(s): GCM, ISO 9660, Multi-Game",
{TEX_GCDVDSMALL, 80, 79},
FEAT_READ|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE,
FEAT_READ|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_CAN_READ_PATCHES,
LOC_DVD_CONNECTOR,
&initial_DVD,
(_fn_test)&deviceHandler_DVD_test,
Expand Down
16 changes: 8 additions & 8 deletions cube/swiss/source/devices/fat/deviceHandler-FAT.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ s32 deviceHandler_FAT_setupFile(file_handle* file, file_handle* file2) {

memset((void*)VAR_FRAG_LIST, 0, VAR_FRAG_SIZE);

// Look for .patchX files, if we find some, open them and add them as fragments
// Look for patch files, if we find some, open them and add them as fragments
file_handle patchFile;
int patches = 0;
for(i = 0; i < maxFrags; i++) {
Expand All @@ -236,7 +236,7 @@ s32 deviceHandler_FAT_setupFile(file_handle* file, file_handle* file2) {
memset(&gameID, 0, 8);
strncpy((char*)&gameID, (char*)&GCMDisk, 4);
memset(&patchFile, 0, sizeof(file_handle));
sprintf(&patchFile.name[0], "%s:/swiss_patches/%s/%i",(savePatchDevice ? "sdb":"sda"),&gameID[0], i);
sprintf(&patchFile.name[0], "%sswiss_patches/%s/%i", devices[DEVICE_CUR]->initial->name,&gameID[0], i);

struct stat fstat;
if(stat(&patchFile.name[0],&fstat)) {
Expand Down Expand Up @@ -323,9 +323,9 @@ s32 deviceHandler_FAT_setupFile(file_handle* file, file_handle* file2) {
// Copy the actual freq
*(volatile unsigned int*)VAR_EXI_FREQ = !swissSettings.exiSpeed ? EXI_SPEED16MHZ:EXI_SPEED32MHZ;
// Device slot (0 or 1) // This represents 0xCC0068xx in number of u32's so, slot A = 0xCC006800, B = 0xCC006814
*(volatile unsigned int*)VAR_EXI_SLOT = ((file->name[0] == 's') ? (file->name[2] == 'b') : (file->name[3] == 'b')) * 5;
*(volatile unsigned int*)VAR_EXI_SLOT = ((devices[DEVICE_CUR]->location == LOC_MEMCARD_SLOT_A)? 0:1) * 5;
// IDE-EXI only settings
if(!(file->name[0] == 's')) {
if((devices[DEVICE_CUR] == &__device_ide_a) || (devices[DEVICE_CUR] == &__device_ide_b)) {
// Is the HDD in use a 48 bit LBA supported HDD?
*(volatile unsigned int*)VAR_TMP1 = ataDriveInfo.lba48Support;
}
Expand Down Expand Up @@ -451,7 +451,7 @@ DEVICEHANDLER_INTERFACE __device_sd_a = {
"SD Gecko - Slot A",
"SD(HC/XC) Card - Supported File System(s): FAT16, FAT32",
{TEX_SDSMALL, 60, 80},
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_REPLACES_DVD_FUNCS,
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_CAN_READ_PATCHES|FEAT_REPLACES_DVD_FUNCS,
LOC_MEMCARD_SLOT_A,
&initial_SD_A,
(_fn_test)&deviceHandler_FAT_test_sd_a,
Expand All @@ -472,7 +472,7 @@ DEVICEHANDLER_INTERFACE __device_sd_b = {
"SD Gecko - Slot B",
"SD(HC/XC) Card - Supported File System(s): FAT16, FAT32",
{TEX_SDSMALL, 60, 80},
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_REPLACES_DVD_FUNCS,
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_CAN_READ_PATCHES|FEAT_REPLACES_DVD_FUNCS,
LOC_MEMCARD_SLOT_B,
&initial_SD_B,
(_fn_test)&deviceHandler_FAT_test_sd_b,
Expand All @@ -493,7 +493,7 @@ DEVICEHANDLER_INTERFACE __device_ide_a = {
"IDE-EXI - Slot A",
"IDE HDD - Supported File System(s): FAT16, FAT32",
{TEX_HDD, 80, 80},
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_REPLACES_DVD_FUNCS,
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_CAN_READ_PATCHES|FEAT_REPLACES_DVD_FUNCS,
LOC_MEMCARD_SLOT_A,
&initial_IDE_A,
(_fn_test)&deviceHandler_FAT_test_ide_a,
Expand All @@ -514,7 +514,7 @@ DEVICEHANDLER_INTERFACE __device_ide_b = {
"IDE-EXI - Slot B",
"IDE HDD - Supported File System(s): FAT16, FAT32",
{TEX_HDD, 80, 80},
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_REPLACES_DVD_FUNCS,
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_CAN_READ_PATCHES|FEAT_REPLACES_DVD_FUNCS,
LOC_MEMCARD_SLOT_B,
&initial_IDE_B,
(_fn_test)&deviceHandler_FAT_test_ide_b,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ DEVICEHANDLER_INTERFACE __device_wkf = {
"Wiikey / Wasp Fusion",
"Supported File System(s): FAT16, FAT32",
{TEX_WIIKEY, 102, 80},
FEAT_READ|FEAT_BOOT_GCM|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS/*|FEAT_BOOT_DEVICE*/, // TODO re-write init to be silent and re-enable this.
FEAT_READ|FEAT_BOOT_GCM|FEAT_AUTOLOAD_DOL|FEAT_FAT_FUNCS|FEAT_BOOT_DEVICE/*|FEAT_CAN_READ_PATCHES*/,
LOC_DVD_CONNECTOR,
&initial_WKF,
(_fn_test)&deviceHandler_WKF_test,
Expand Down
26 changes: 18 additions & 8 deletions cube/swiss/source/gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,21 @@ int parse_tgc(file_handle *file, ExecutableFile *filesToPatch, u32 tgc_base) {

int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, int multiDol) {
int i, num_patched = 0;

// If the current device isn't SD Gecko, init SD Gecko Slot A or B to write patches.

// If the current device isn't SD Gecko, init one slot to write patches.
// TODO expand this to support IDE-EXI and other writable devices (requires dvd patch re-write/modularity)
bool patchDeviceReady = false;
if(devices[DEVICE_CUR] != &__device_sd_a && devices[DEVICE_CUR] != &__device_sd_b) {
deviceHandler_setStatEnabled(0);
if(deviceHandler_test(&__device_sd_a)) {
devices[DEVICE_PATCHES] = &__device_sd_a;
}
else if(deviceHandler_test(&__device_sd_b)) {
devices[DEVICE_PATCHES] = &__device_sd_b;
}
deviceHandler_setStatEnabled(1);
}
else {
devices[DEVICE_PATCHES] = devices[DEVICE_CUR];
patchDeviceReady = true;
}

if(devices[DEVICE_PATCHES] == NULL) {
Expand All @@ -321,8 +322,8 @@ int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, i
memset(&patchDirName, 0, 256);
memset(&patchBaseDirName, 0, 256);
strncpy((char*)&gameID, (char*)&GCMDisk, 4);
sprintf(&patchDirName[0],"%s/swiss_patches/%s",devices[DEVICE_PATCHES]->initial->name, &gameID[0]);
sprintf(&patchBaseDirName[0],"%s/swiss_patches",devices[DEVICE_PATCHES]->initial->name);
sprintf(&patchDirName[0],"%sswiss_patches/%s",devices[DEVICE_PATCHES]->initial->name, &gameID[0]);
sprintf(&patchBaseDirName[0],"%sswiss_patches",devices[DEVICE_PATCHES]->initial->name);
print_gecko("Patch dir will be: %s if required\r\n", patchDirName);
*(u32*)VAR_EXECD_OFFSET = 0xFFFFFFFF;
// Go through all the possible files we think need patching..
Expand Down Expand Up @@ -353,8 +354,8 @@ int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, i
int sizeToRead = filesToPatch[i].size, ret = 0;
u8 *buffer = (u8*)memalign(32, sizeToRead);

devices[DEVICE_PATCHES]->seekFile(file,filesToPatch[i].offset, DEVICE_HANDLER_SEEK_SET);
ret = devices[DEVICE_PATCHES]->readFile(file,buffer,sizeToRead);
devices[DEVICE_CUR]->seekFile(file,filesToPatch[i].offset, DEVICE_HANDLER_SEEK_SET);
ret = devices[DEVICE_CUR]->readFile(file,buffer,sizeToRead);
print_gecko("Read from %08X Size %08X - Result: %08X\r\n", filesToPatch[i].offset, sizeToRead, ret);
if(ret != sizeToRead) {
DrawFrameStart();
Expand Down Expand Up @@ -407,6 +408,15 @@ int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, i
if(swissSettings.forceAnisotropy)
Patch_TexFilt(buffer, sizeToRead, filesToPatch[i].type);
if(patched) {
if(!patchDeviceReady) {
deviceHandler_setStatEnabled(0);
if(!devices[DEVICE_PATCHES]->init(devices[DEVICE_PATCHES]->initial)) {
deviceHandler_setStatEnabled(1);
return false;
}
deviceHandler_setStatEnabled(1);
patchDeviceReady = true;
}
// File handle for a patch we might need to write
FILE *patchFile = 0;
memset(patchFileName, 0, 256);
Expand Down
1 change: 0 additions & 1 deletion cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extern int SDHCCard;
extern int GC_SD_CHANNEL;

extern void animateBox(int x1,int y1, int x2, int y2, int color,char *msg);
int savePatchDevice = -1;

// Read
FuncPattern ReadDebug = {0xDC, 23, 18, 3, 2, 4, 0, 0, "Read (Debug)", 0};
Expand Down

0 comments on commit e372245

Please sign in to comment.