Skip to content

Commit

Permalink
Merge pull request #162 from emukidid/devicehandler_overhaul
Browse files Browse the repository at this point in the history
Devicehandler overhaul
  • Loading branch information
emukidid committed Jun 10, 2017
2 parents f626dcc + e372245 commit de67e04
Show file tree
Hide file tree
Showing 38 changed files with 1,419 additions and 1,380 deletions.
6 changes: 4 additions & 2 deletions cube/patches/base/dvdinterface.c
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();
}
}
}
35 changes: 1 addition & 34 deletions cube/swiss/include/main.h
Expand Up @@ -36,29 +36,6 @@ enum fileTypes
IS_SPECIAL
};

//Device Type
enum deviceTypes
{
DVD_DISC=0,
SD_CARD,
IDEEXI,
WKF,
WODE,
QOOB_FLASH,
USBGECKO,
MEMCARD,
SAMBA,
SYS
};

//Destination Device Type
enum destDeviceTypes
{
DEST_SD_CARD=0,
DEST_IDEEXI,
DEST_MEMCARD
};

//Where on the screen are we?
enum guiPos
{
Expand Down Expand Up @@ -91,7 +68,7 @@ enum dvdDiscTypes
MULTIDISC_DISC, //Multi Disc Gamecube Game
GAMECUBE_DISC, //Single Disc Gamecube Game
ISO9660_DISC, //ISO9660 Filesystem Disc
UNKNOWN_DISC //Unknown
UNKNOWN_DISC //Unknown
};

//DVD Drive Status (enum)
Expand All @@ -110,15 +87,6 @@ enum setupStream
ENABLE_BYDISK //Check from disc header whether to enable it
};

// Mediums we can have swiss search on boot
enum bootDevices
{
SD_SLOTA=0,
SD_SLOTB,
IDE_SLOTA,
IDE_SLOTB
};

#define DVD_MAGIC 0xC2339F3D

//Disc Types
Expand Down Expand Up @@ -164,7 +132,6 @@ extern u32 getCodeBaseSize();

extern char *dvdDiscTypeStr;
extern int dvdDiscTypeInt;
extern int curDevice; //SD_CARD or DVD_DISC
extern int drive_status;

extern int files; //number of files in a directory
Expand Down
6 changes: 4 additions & 2 deletions cube/swiss/include/swiss.h
Expand Up @@ -48,6 +48,8 @@ extern s32 sdgecko_setHS(s32 drv_no);

extern syssram* __SYS_LockSram();
extern u32 __SYS_UnlockSram(u32 write);
extern syssramex* __SYS_LockSramEx();
extern u32 __SYS_UnlockSramEx(u32 write);

extern char *getVideoString();
void print_gecko(const char* fmt, ...);
Expand All @@ -68,8 +70,7 @@ extern void drawFiles(file_handle** directory, int num_files);

extern void select_speed();
extern int select_slot();
extern void select_device(int skipPrompts);
extern void select_copy_device();
extern void select_device(int type);
extern void select_dest_dir(file_handle* directory, file_handle* selection);

typedef struct {
Expand All @@ -96,6 +97,7 @@ typedef struct {
char smbServerIp[128]; //80
int autoCheats;
int igrType;
u8 configDeviceId; // see deviceHandler.h
} SwissSettings __attribute__((aligned(32)));
extern SwissSettings swissSettings;

Expand Down
61 changes: 31 additions & 30 deletions cube/swiss/source/cheats/cheats.c
Expand Up @@ -194,38 +194,39 @@ int findCheats(bool silent) {
memset(trimmedGameId, 0, 8);
memcpy(trimmedGameId, (char*)&GCMDisk, 6);
file_handle *cheatsFile = memalign(32,sizeof(file_handle));
memcpy(cheatsFile, deviceHandler_initial, sizeof(file_handle));
sprintf(cheatsFile->name, "%s/cheats/%s.txt", deviceHandler_initial->name, trimmedGameId);
memcpy(cheatsFile, devices[DEVICE_CUR]->initial, sizeof(file_handle));
sprintf(cheatsFile->name, "%s/cheats/%s.txt", devices[DEVICE_CUR]->initial->name, trimmedGameId);
print_gecko("Looking for cheats file @ %s\r\n", cheatsFile->name);
cheatsFile->size = -1;

deviceHandler_temp_readFile = deviceHandler_readFile;
deviceHandler_temp_seekFile = deviceHandler_seekFile;

// Check SD in both slots if we're not already running from SD, or if we fail from SD
if((curDevice != SD_CARD && curDevice != IDEEXI && curDevice != WKF) || deviceHandler_temp_readFile(cheatsFile, &trimmedGameId, 8) != 8) {
if(deviceHandler_initial != &initial_SD0 && deviceHandler_initial != &initial_SD1) {
int slot = 0;
deviceHandler_temp_init = deviceHandler_FAT_init;
deviceHandler_temp_readFile = deviceHandler_FAT_readFile;
deviceHandler_temp_seekFile = deviceHandler_FAT_seekFile;
deviceHandler_temp_deinit = deviceHandler_FAT_deinit;
while(slot < 2) {
file_handle *slotFile = slot ? &initial_SD1:&initial_SD0;
// Try SD slots now
memcpy(cheatsFile, slotFile, sizeof(file_handle));
sprintf(cheatsFile->name, "%s/cheats/%s.txt", slotFile->name, trimmedGameId);
print_gecko("Looking for cheats file @ %s\r\n", cheatsFile->name);
cheatsFile->size = -1;
deviceHandler_temp_init(cheatsFile);
if(deviceHandler_temp_readFile(cheatsFile, &trimmedGameId, 8) == 8) {
break;
}
slot++;
}

devices[DEVICE_TEMP] = devices[DEVICE_CUR];

// Check SD in both slots if we're not already running from SD, or if we fail from current device
if(devices[DEVICE_TEMP]->readFile(cheatsFile, &trimmedGameId, 8) != 8) {
// Try SD slots now
devices[DEVICE_TEMP] = &__device_sd_a;
file_handle *slotFile = devices[DEVICE_TEMP]->initial;
memcpy(cheatsFile, slotFile, sizeof(file_handle));
sprintf(cheatsFile->name, "%s/cheats/%s.txt", slotFile->name, trimmedGameId);
print_gecko("Looking for cheats file @ %s\r\n", cheatsFile->name);
cheatsFile->size = -1;
devices[DEVICE_TEMP]->init(cheatsFile);
if(devices[DEVICE_TEMP]->readFile(cheatsFile, &trimmedGameId, 8) != 8) {
devices[DEVICE_TEMP] = NULL;
}
devices[DEVICE_TEMP] = &__device_sd_b;
slotFile = devices[DEVICE_TEMP]->initial;
memcpy(cheatsFile, slotFile, sizeof(file_handle));
sprintf(cheatsFile->name, "%s/cheats/%s.txt", slotFile->name, trimmedGameId);
print_gecko("Looking for cheats file @ %s\r\n", cheatsFile->name);
cheatsFile->size = -1;
devices[DEVICE_TEMP]->init(cheatsFile);
if(devices[DEVICE_TEMP]->readFile(cheatsFile, &trimmedGameId, 8) != 8) {
devices[DEVICE_TEMP] = NULL;
}

// Still fail?
if(deviceHandler_temp_readFile(cheatsFile, &trimmedGameId, 8) != 8) {
if(devices[DEVICE_TEMP] == NULL) {
if(!silent) {
while(PAD_ButtonsHeld(0) & PAD_BUTTON_Y);
DrawFrameStart();
Expand All @@ -241,8 +242,8 @@ int findCheats(bool silent) {
print_gecko("Cheats file found with size %i\r\n", cheatsFile->size);
char *cheats_buffer = memalign(32, cheatsFile->size);
if(cheats_buffer) {
deviceHandler_temp_seekFile(cheatsFile, 0, DEVICE_HANDLER_SEEK_SET);
deviceHandler_temp_readFile(cheatsFile, cheats_buffer, cheatsFile->size);
devices[DEVICE_TEMP]->seekFile(cheatsFile, 0, DEVICE_HANDLER_SEEK_SET);
devices[DEVICE_TEMP]->readFile(cheatsFile, cheats_buffer, cheatsFile->size);
parseCheats(cheats_buffer);
free(cheats_buffer);
free(cheatsFile);
Expand Down

0 comments on commit de67e04

Please sign in to comment.