From 163147fa720cae821da65177164d52e1ed8a28f4 Mon Sep 17 00:00:00 2001 From: emu_kidid Date: Tue, 23 May 2017 21:40:52 +0930 Subject: [PATCH 1/8] - DeviceHandler overhaul to better identify devices and allow for easier assignment of devices to specific functions (config loading unimplemented for the time being) --- cube/swiss/include/main.h | 35 +- cube/swiss/include/swiss.h | 3 +- cube/swiss/source/cheats/cheats.c | 61 +- cube/swiss/source/config/config.c | 4 +- cube/swiss/source/devices/deviceHandler.c | 84 +- cube/swiss/source/devices/deviceHandler.h | 153 ++-- .../source/devices/dvd/deviceHandler-DVD.c | 42 +- .../source/devices/dvd/deviceHandler-DVD.h | 11 +- .../source/devices/fat/deviceHandler-FAT.c | 126 ++- .../source/devices/fat/deviceHandler-FAT.h | 19 +- cube/swiss/source/devices/filemeta.c | 20 +- .../devices/memcard/deviceHandler-CARD.c | 65 +- .../devices/memcard/deviceHandler-CARD.h | 15 +- .../source/devices/qoob/deviceHandler-Qoob.c | 38 +- .../source/devices/qoob/deviceHandler-Qoob.h | 11 +- .../source/devices/smb/deviceHandler-SMB.c | 36 +- .../source/devices/smb/deviceHandler-SMB.h | 11 +- .../source/devices/system/deviceHandler-SYS.c | 44 +- .../source/devices/system/deviceHandler-SYS.h | 13 +- .../devices/usbgecko/deviceHandler-usbgecko.c | 42 +- .../devices/usbgecko/deviceHandler-usbgecko.h | 13 +- .../wiikeyfusion/deviceHandler-wiikeyfusion.c | 43 +- .../wiikeyfusion/deviceHandler-wiikeyfusion.h | 11 +- .../source/devices/wode/deviceHandler-WODE.c | 38 +- .../source/devices/wode/deviceHandler-WODE.h | 10 +- cube/swiss/source/gcm.c | 82 +- cube/swiss/source/gui/FrameBufferMagic.c | 6 +- cube/swiss/source/gui/info.c | 4 +- cube/swiss/source/gui/settings.c | 4 +- cube/swiss/source/main.c | 247 ++---- cube/swiss/source/mp3.c | 4 +- cube/swiss/source/patcher.c | 10 +- cube/swiss/source/swiss.c | 831 ++++++------------ 33 files changed, 987 insertions(+), 1149 deletions(-) diff --git a/cube/swiss/include/main.h b/cube/swiss/include/main.h index 1fe6436a..c6f66906 100644 --- a/cube/swiss/include/main.h +++ b/cube/swiss/include/main.h @@ -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 { @@ -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) @@ -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 @@ -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 diff --git a/cube/swiss/include/swiss.h b/cube/swiss/include/swiss.h index 23d3ed25..8ed07426 100644 --- a/cube/swiss/include/swiss.h +++ b/cube/swiss/include/swiss.h @@ -68,8 +68,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 { diff --git a/cube/swiss/source/cheats/cheats.c b/cube/swiss/source/cheats/cheats.c index d71a1e4a..2f1e0b97 100644 --- a/cube/swiss/source/cheats/cheats.c +++ b/cube/swiss/source/cheats/cheats.c @@ -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(); @@ -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); diff --git a/cube/swiss/source/config/config.c b/cube/swiss/source/config/config.c index cd4c1a0e..cb8e2e3a 100644 --- a/cube/swiss/source/config/config.c +++ b/cube/swiss/source/config/config.c @@ -54,7 +54,7 @@ void strnscpy(char *s1, char *s2, int num) { Returns 1 on successful file open, 0 otherwise */ int config_init() { - sprintf(txtbuffer, "%sswiss.ini", deviceHandler_initial->name); + sprintf(txtbuffer, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); FILE *fp = fopen(txtbuffer, "rb"); if (fp) { fseek(fp, 0, SEEK_END); @@ -92,7 +92,7 @@ int config_create() { } int config_update_file() { - sprintf(txtbuffer, "%sswiss.ini", deviceHandler_initial->name); + sprintf(txtbuffer, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); FILE *fp = fopen( txtbuffer, "wb" ); if(fp) { // Write out header every time diff --git a/cube/swiss/source/devices/deviceHandler.c b/cube/swiss/source/devices/deviceHandler.c index eeee3f72..7bf1a57b 100644 --- a/cube/swiss/source/devices/deviceHandler.c +++ b/cube/swiss/source/devices/deviceHandler.c @@ -17,49 +17,59 @@ #define NULL 0 #endif -file_handle* deviceHandler_initial = NULL; -device_info* (*deviceHandler_info)(void) = NULL; +DEVICEHANDLER_INTERFACE* allDevices[MAX_DEVICES]; // All devices registered in Swiss +DEVICEHANDLER_INTERFACE* devices[MAX_DEVICES]; // Currently used devices -static int device_availability[MAX_DEVICES]; + +// Device stat global disable status static int statEnabled = 1; void deviceHandler_setStatEnabled(int enable) {statEnabled = enable;} int deviceHandler_getStatEnabled() {return statEnabled;} -int deviceHandler_getDeviceAvailable(int dev) { return device_availability[dev]; } -void deviceHandler_setDeviceAvailable(int dev, int a) { device_availability[dev] = a; } -void deviceHandler_setAllDevicesAvailable() {memset(&device_availability[0], 1, MAX_DEVICES);} -int (*deviceHandler_init)(file_handle*) = NULL; -int (*deviceHandler_readDir)(file_handle*, file_handle**, unsigned int) = NULL; -int (*deviceHandler_readFile)(file_handle*, void*, unsigned int) = NULL; -int (*deviceHandler_writeFile)(file_handle*, void*, unsigned int) = NULL; -int (*deviceHandler_deleteFile)(file_handle*) = NULL; -int (*deviceHandler_seekFile)(file_handle*, unsigned int, unsigned int) = NULL; -int (*deviceHandler_setupFile)(file_handle*, file_handle*) = NULL; -int (*deviceHandler_closeFile)(file_handle*) = NULL; -int (*deviceHandler_deinit)() = NULL; -// Destination Device -file_handle* deviceHandler_dest_initial = NULL; +// Device availability +typedef struct { + DEVICEHANDLER_INTERFACE* device; + bool available; +} _device_availability; +static _device_availability device_availability[MAX_DEVICES]; + +bool deviceHandler_getDeviceAvailable(DEVICEHANDLER_INTERFACE *dev) { + int i; + for(i = 0; i < MAX_DEVICES; i++) { + if(device_availability[i].device == dev) { + return device_availability[i].available; + } + } + return false; +} + +void deviceHandler_setDeviceAvailable(DEVICEHANDLER_INTERFACE *dev, bool availability) { + int i, empty_slot = -1; + for(i = 0; i < MAX_DEVICES; i++) { + if(device_availability[i].device == dev) { + device_availability[i].available = availability; + return; + } + if(device_availability[i].device == NULL && empty_slot < 0) { + empty_slot = i; + } + } + device_availability[empty_slot].device = dev; + device_availability[empty_slot].available = availability; +} -int (*deviceHandler_dest_init)(file_handle*) = NULL; -int (*deviceHandler_dest_readDir)(file_handle*, file_handle**, unsigned int) = NULL; -int (*deviceHandler_dest_readFile)(file_handle*, void*, unsigned int) = NULL; -int (*deviceHandler_dest_writeFile)(file_handle*, void*, unsigned int) = NULL; -int (*deviceHandler_dest_deleteFile)(file_handle*) = NULL; -int (*deviceHandler_dest_seekFile)(file_handle*, unsigned int, unsigned int) = NULL; -int (*deviceHandler_dest_setupFile)(file_handle*, file_handle*) = NULL; -int (*deviceHandler_dest_closeFile)(file_handle*) = NULL; -int (*deviceHandler_dest_deinit)() = NULL; +void deviceHandler_setAllDevicesAvailable() { + int i; + for(i = 0; i < MAX_DEVICES; i++) { + if(allDevices[i] != NULL) { + device_availability[i].device = allDevices[i]; + device_availability[i].available = true; + } + } +} -// Temporary Device -file_handle* deviceHandler_temp_initial = NULL; +int deviceHandler_test(DEVICEHANDLER_INTERFACE *device) { + return device->init(device->initial); +} -int (*deviceHandler_temp_init)(file_handle*) = NULL; -int (*deviceHandler_temp_readDir)(file_handle*, file_handle**, unsigned int) = NULL; -int (*deviceHandler_temp_readFile)(file_handle*, void*, unsigned int) = NULL; -int (*deviceHandler_temp_writeFile)(file_handle*, void*, unsigned int) = NULL; -int (*deviceHandler_temp_deleteFile)(file_handle*) = NULL; -int (*deviceHandler_temp_seekFile)(file_handle*, unsigned int, unsigned int) = NULL; -int (*deviceHandler_temp_setupFile)(file_handle*, file_handle*) = NULL; -int (*deviceHandler_temp_closeFile)(file_handle*) = NULL; -int (*deviceHandler_temp_deinit)() = NULL; diff --git a/cube/swiss/source/devices/deviceHandler.h b/cube/swiss/source/devices/deviceHandler.h index 40878e36..11545ec1 100644 --- a/cube/swiss/source/devices/deviceHandler.h +++ b/cube/swiss/source/devices/deviceHandler.h @@ -7,6 +7,8 @@ #define DEVICE_HANDLER_H #include +#include +#include #include #include "wode/WodeInterface.h" @@ -38,9 +40,78 @@ typedef struct { u32 totalSpaceInKB; // 4TB Max } device_info; +typedef struct { + int textureId; + u32 width; + u32 height; +} textureImage; + #define DEVICE_HANDLER_SEEK_SET 0 #define DEVICE_HANDLER_SEEK_CUR 1 +// Device struct +typedef s32 (* _fn_info)(void); +typedef bool (* _fn_test)(void); +typedef s32 (* _fn_init)(file_handle*); +typedef s32 (* _fn_readDir)(file_handle*, file_handle**, u32); +typedef s32 (* _fn_readFile)(file_handle*, void*, u32); +typedef s32 (* _fn_writeFile)(file_handle*, void*, u32); +typedef s32 (* _fn_deleteFile)(file_handle*); +typedef s32 (* _fn_seekFile)(file_handle*, u32, u32); +typedef s32 (* _fn_setupFile)(file_handle*, file_handle*); +typedef s32 (* _fn_closeFile)(file_handle*); +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 + +// 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 + +struct DEVICEHANDLER_STRUCT { + const char* deviceName; + const char* deviceDescription; + textureImage deviceTexture; + u32 features; + u32 location; + file_handle* initial; + _fn_test test; + _fn_info info; + _fn_init init; + _fn_readDir readDir; + _fn_readFile readFile; + _fn_writeFile writeFile; + _fn_deleteFile deleteFile; + _fn_seekFile seekFile; + _fn_setupFile setupFile; + _fn_closeFile closeFile; + _fn_deinit deinit; +} ; + +typedef struct DEVICEHANDLER_STRUCT DEVICEHANDLER_INTERFACE; + +enum DEVICE_SLOTS { + DEVICE_CUR, + DEVICE_DEST, + DEVICE_TEMP, + DEVICE_CONFIG, + DEVICE_PATCHES, + MAX_DEVICE_SLOTS +}; + #include "devices/dvd/deviceHandler-DVD.h" #include "devices/fat/deviceHandler-FAT.h" #include "devices/qoob/deviceHandler-Qoob.h" @@ -51,88 +122,16 @@ typedef struct { #include "devices/usbgecko/deviceHandler-usbgecko.h" #include "devices/system/deviceHandler-SYS.h" -extern file_handle* deviceHandler_initial; -extern device_info* (*deviceHandler_info)(void); extern void deviceHandler_setStatEnabled(int enable); extern int deviceHandler_getStatEnabled(); -extern int deviceHandler_getDeviceAvailable(int dev); -extern void deviceHandler_setDeviceAvailable(int dev, int a); +extern bool deviceHandler_getDeviceAvailable(DEVICEHANDLER_INTERFACE *dev); +extern void deviceHandler_setDeviceAvailable(DEVICEHANDLER_INTERFACE *dev, bool availability); extern void deviceHandler_setAllDevicesAvailable(); -/* Initialize the device */ -extern int (*deviceHandler_init)(file_handle*); - -/* read directory into array, return number of files found or error */ -extern int (*deviceHandler_readDir)(file_handle*, file_handle**, unsigned int); - -/* readFile returns the status of the read and reads if it can - arguments: handle*, buffer, length */ -extern int (*deviceHandler_readFile)(file_handle*, void*, unsigned int); - -/* writeFile returns the status of the write and writes if it can - arguments: handle*, buffer, length */ -extern int (*deviceHandler_writeFile)(file_handle*, void*, unsigned int); - -/* deleteFile returns the status of the delete - 0 for success, else error code */ -extern int (*deviceHandler_deleteFile)(file_handle*); - -/* seekFile returns the status of the seek and seeks if it can - arguments: file*, offset, seek type */ -extern int (*deviceHandler_seekFile)(file_handle*, unsigned int, unsigned int); - -/* sets the offset and other device specific stuff */ -extern int (*deviceHandler_setupFile)(file_handle*, file_handle*); - -/* closeFile cleans up file-specific data after access */ -int (*deviceHandler_closeFile)(file_handle*); - -/* Shutdown the device */ -extern int (*deviceHandler_deinit)(); - -// Destination Device -extern file_handle* deviceHandler_dest_initial; - -/* Initialize the device */ -extern int (*deviceHandler_dest_init)(file_handle*); - -/* read directory into array, return number of files found or error */ -extern int (*deviceHandler_dest_readDir)(file_handle*, file_handle**, unsigned int); - -/* readFile returns the status of the read and reads if it can - arguments: handle*, buffer, length */ -extern int (*deviceHandler_dest_readFile)(file_handle*, void*, unsigned int); - -/* writeFile returns the status of the write and writes if it can - arguments: handle*, buffer, length */ -extern int (*deviceHandler_dest_writeFile)(file_handle*, void*, unsigned int); - -/* deleteFile returns the status of the delete - 0 for success, else error code */ -extern int (*deviceHandler_dest_deleteFile)(file_handle*); - -/* seekFile returns the status of the seek and seeks if it can - arguments: file*, offset, seek type */ -extern int (*deviceHandler_dest_seekFile)(file_handle*, unsigned int, unsigned int); - -/* sets the offset and other device specific stuff */ -extern int (*deviceHandler_dest_setupFile)(file_handle*, file_handle*); - -/* closeFile cleans up file-specific data after access */ -int (*deviceHandler_dest_closeFile)(file_handle*); - -/* Shutdown the device */ -extern int (*deviceHandler_dest_deinit)(); +extern DEVICEHANDLER_INTERFACE* allDevices[MAX_DEVICES]; +extern DEVICEHANDLER_INTERFACE* devices[MAX_DEVICES]; -// Temporary device -extern file_handle* deviceHandler_temp_initial; -extern int (*deviceHandler_temp_init)(file_handle*); -extern int (*deviceHandler_temp_readDir)(file_handle*, file_handle**, unsigned int); -extern int (*deviceHandler_temp_readFile)(file_handle*, void*, unsigned int); -extern int (*deviceHandler_temp_writeFile)(file_handle*, void*, unsigned int); -extern int (*deviceHandler_temp_deleteFile)(file_handle*); -extern int (*deviceHandler_temp_seekFile)(file_handle*, unsigned int, unsigned int); -extern int (*deviceHandler_temp_setupFile)(file_handle*, file_handle*); -int (*deviceHandler_temp_closeFile)(file_handle*); -extern int (*deviceHandler_temp_deinit)(); +extern int deviceHandler_test(DEVICEHANDLER_INTERFACE *device); extern void print_frag_list(int hasDisc2); diff --git a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c index 0bb7096f..f4308a3a 100644 --- a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c +++ b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c @@ -254,7 +254,7 @@ device_info* deviceHandler_DVD_info() { return &initial_DVD_info; } -int deviceHandler_DVD_readDir(file_handle* ffile, file_handle** dir, unsigned int type){ +s32 deviceHandler_DVD_readDir(file_handle* ffile, file_handle** dir, u32 type){ unsigned int i = 0, isGC = is_gamecube(); unsigned int *tmpTable = NULL; @@ -361,13 +361,13 @@ int deviceHandler_DVD_readDir(file_handle* ffile, file_handle** dir, unsigned in return num_entries; } -int deviceHandler_DVD_seekFile(file_handle* file, unsigned int where, unsigned int type){ +s32 deviceHandler_DVD_seekFile(file_handle* file, u32 where, u32 type){ if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; return file->offset; } -int deviceHandler_DVD_readFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_DVD_readFile(file_handle* file, void* buffer, u32 length){ //print_gecko("read: status:%08X dst:%08X ofs:%08X base:%08X len:%08X\r\n" // ,file->status,(u32)buffer,file->offset,(u32)((file->fileBase) & 0xFFFFFFFF),length); u64 actualOffset = file->fileBase+file->offset; @@ -382,12 +382,12 @@ int deviceHandler_DVD_readFile(file_handle* file, void* buffer, unsigned int len return bytesread; } -int deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2) { +s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2) { // Multi-Game disc audio streaming setup if((dvdDiscTypeInt == COBRA_MULTIGAME_DISC)||(dvdDiscTypeInt == GCOSD5_MULTIGAME_DISC)||(dvdDiscTypeInt == GCOSD9_MULTIGAME_DISC)) { - deviceHandler_seekFile(file, 0, DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(file,(unsigned char*)0x80000000,32); + devices[DEVICE_CUR]->seekFile(file, 0, DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(file,(unsigned char*)0x80000000,32); char streaming = *(char*)0x80000008; if(streaming && !isXenoGC) { DrawFrameStart(); @@ -471,7 +471,7 @@ int deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2) { return 1; } -int deviceHandler_DVD_init(file_handle* file){ +s32 deviceHandler_DVD_init(file_handle* file){ file->status = initialize_disc(ENABLE_BYDISK); if(file->status == DRV_ERROR){ DrawFrameStart(); @@ -484,12 +484,36 @@ int deviceHandler_DVD_init(file_handle* file){ return file->status; } -int deviceHandler_DVD_deinit(file_handle* file) { +s32 deviceHandler_DVD_deinit(file_handle* file) { dvd_motor_off(); + dvdDiscTypeStr = NotInitStr; return 0; } -int deviceHandler_DVD_closeFile(file_handle* file){ +s32 deviceHandler_DVD_closeFile(file_handle* file){ return 0; } +bool deviceHandler_DVD_test() { + return swissSettings.hasDVDDrive != 0; +} + +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, + LOC_DVD_CONNECTOR, + &initial_DVD, + (_fn_test)&deviceHandler_DVD_test, + (_fn_info)&deviceHandler_DVD_info, + (_fn_init)&deviceHandler_DVD_init, + (_fn_readDir)&deviceHandler_DVD_readDir, + (_fn_readFile)&deviceHandler_DVD_readFile, + (_fn_writeFile)NULL, + (_fn_deleteFile)NULL, + (_fn_seekFile)&deviceHandler_DVD_seekFile, + (_fn_setupFile)&deviceHandler_DVD_setupFile, + (_fn_closeFile)&deviceHandler_DVD_closeFile, + (_fn_deinit)&deviceHandler_DVD_deinit +}; diff --git a/cube/swiss/source/devices/dvd/deviceHandler-DVD.h b/cube/swiss/source/devices/dvd/deviceHandler-DVD.h index a6c48f84..8380a552 100644 --- a/cube/swiss/source/devices/dvd/deviceHandler-DVD.h +++ b/cube/swiss/source/devices/dvd/deviceHandler-DVD.h @@ -9,16 +9,7 @@ #include "../deviceHandler.h" -extern file_handle initial_DVD; - -int deviceHandler_DVD_readDir(file_handle*, file_handle**, unsigned int); -int deviceHandler_DVD_readFile(file_handle*, void*, unsigned int); -int deviceHandler_DVD_seekFile(file_handle*, unsigned int, unsigned int); -int deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2); -int deviceHandler_DVD_init(file_handle* file); -int deviceHandler_DVD_deinit(file_handle* file); -int deviceHandler_DVD_closeFile(file_handle* file); -device_info *deviceHandler_DVD_info(); +extern DEVICEHANDLER_INTERFACE __device_dvd; int gettype_disc(); int initialize_disc(u32 streaming); diff --git a/cube/swiss/source/devices/fat/deviceHandler-FAT.c b/cube/swiss/source/devices/fat/deviceHandler-FAT.c index 1bc86c2a..c164b4f9 100644 --- a/cube/swiss/source/devices/fat/deviceHandler-FAT.c +++ b/cube/swiss/source/devices/fat/deviceHandler-FAT.c @@ -27,7 +27,7 @@ const DISC_INTERFACE* ideexia = &__io_ataa; const DISC_INTERFACE* ideexib = &__io_atab; extern void sdgecko_initIODefault(); -file_handle initial_SD0 = +file_handle initial_SD_A = { "sda:/", // directory 0ULL, // fileBase (u64) 0, // offset @@ -37,7 +37,7 @@ file_handle initial_SD0 = 0 }; -file_handle initial_SD1 = +file_handle initial_SD_B = { "sdb:/", // directory 0ULL, // fileBase (u64) 0, // offset @@ -47,7 +47,7 @@ file_handle initial_SD1 = 0 }; -file_handle initial_IDE0 = +file_handle initial_IDE_A = { "idea:/", // directory 0ULL, // fileBase (u64) 0, // offset @@ -57,7 +57,7 @@ file_handle initial_IDE0 = 0 }; -file_handle initial_IDE1 = +file_handle initial_IDE_B = { "ideb:/", // directory 0ULL, // fileBase (u64) 0, // offset @@ -96,7 +96,7 @@ void readDeviceInfo(file_handle* file) { } } -int deviceHandler_FAT_readDir(file_handle* ffile, file_handle** dir, unsigned int type){ +s32 deviceHandler_FAT_readDir(file_handle* ffile, file_handle** dir, u32 type){ DIR* dp = opendir( ffile->name ); if(!dp) return -1; @@ -150,13 +150,13 @@ int deviceHandler_FAT_readDir(file_handle* ffile, file_handle** dir, unsigned in return num_entries; } -int deviceHandler_FAT_seekFile(file_handle* file, unsigned int where, unsigned int type){ +s32 deviceHandler_FAT_seekFile(file_handle* file, u32 where, u32 type){ if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; return file->offset; } -int deviceHandler_FAT_readFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_FAT_readFile(file_handle* file, void* buffer, u32 length){ if(!file->fp) { file->fp = fopen( file->name, "r+" ); if(file->size == -1) { @@ -174,7 +174,7 @@ int deviceHandler_FAT_readFile(file_handle* file, void* buffer, unsigned int len return bytes_read; } -int deviceHandler_FAT_writeFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_FAT_writeFile(file_handle* file, void* buffer, u32 length){ if(!file->fp) { // Append file->fp = fopen( file->name, "r+" ); @@ -213,7 +213,7 @@ void print_frag_list(int hasDisc2) { print_gecko("== Fragments End ==\r\n"); } -int deviceHandler_FAT_setupFile(file_handle* file, file_handle* file2) { +s32 deviceHandler_FAT_setupFile(file_handle* file, file_handle* file2) { // Check if file2 exists if(file2) { get_frag_list(file2->name); @@ -243,8 +243,8 @@ int deviceHandler_FAT_setupFile(file_handle* file, file_handle* file2) { if(stat(&patchFile.name[0],&fstat)) { break; } - deviceHandler_seekFile(&patchFile,fstat.st_size-16,DEVICE_HANDLER_SEEK_SET); - if((deviceHandler_readFile(&patchFile, &patchInfo, 16) == 16) && (patchInfo[2] == SWISS_MAGIC)) { + devices[DEVICE_CUR]->seekFile(&patchFile,fstat.st_size-16,DEVICE_HANDLER_SEEK_SET); + if((devices[DEVICE_CUR]->readFile(&patchFile, &patchInfo, 16) == 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 (%i pieces)\r\n", i, patchInfo[0], patchInfo[1], frag_list->frag[0].sector,frag_list->num ); @@ -349,7 +349,7 @@ int EXI_ResetSD(int drv) { return 1; } -int deviceHandler_FAT_init(file_handle* file) { +s32 deviceHandler_FAT_init(file_handle* file) { int isSDCard = file->name[0] == 's'; int slot = isSDCard ? (file->name[2] == 'b') : (file->name[3] == 'b'); int ret = 0; @@ -398,7 +398,7 @@ char *getDeviceMountPath(char *str) { return path; } -int deviceHandler_FAT_deinit(file_handle* file) { +s32 deviceHandler_FAT_deinit(file_handle* file) { initial_FAT_info.freeSpaceInKB = 0; initial_FAT_info.totalSpaceInKB = 0; if(file && file->fp) { @@ -414,7 +414,7 @@ int deviceHandler_FAT_deinit(file_handle* file) { return 0; } -int deviceHandler_FAT_deleteFile(file_handle* file) { +s32 deviceHandler_FAT_deleteFile(file_handle* file) { if(file->fp) { fclose(file->fp); file->fp = 0; @@ -422,7 +422,7 @@ int deviceHandler_FAT_deleteFile(file_handle* file) { return (remove(file->name) == -1) ? -1:0; } -int deviceHandler_FAT_closeFile(file_handle* file) { +s32 deviceHandler_FAT_closeFile(file_handle* file) { int ret = 0; if(file->fp) { ret = fclose(file->fp); @@ -431,3 +431,99 @@ int deviceHandler_FAT_closeFile(file_handle* file) { return ret; } +bool deviceHandler_FAT_test_sd_a(int slot, bool isSdCard, char *mountPath) { + carda->shutdown(); + carda->startup(); + return carda->isInserted(); +} +bool deviceHandler_FAT_test_sd_b(int slot, bool isSdCard, char *mountPath) { + cardb->shutdown(); + cardb->startup(); + return cardb->isInserted(); +} +bool deviceHandler_FAT_test_ide_a(int slot, bool isSdCard, char *mountPath) { + return ide_exi_inserted(0); +} +bool deviceHandler_FAT_test_ide_b(int slot, bool isSdCard, char *mountPath) { + return ide_exi_inserted(1); +} + +DEVICEHANDLER_INTERFACE __device_sd_a = { + "SD Card via SD Adapter - Slot A", + "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, + LOC_MEMCARD_SLOT_A, + &initial_SD_A, + (_fn_test)&deviceHandler_FAT_test_sd_a, + (_fn_info)&deviceHandler_FAT_info, + (_fn_init)&deviceHandler_FAT_init, + (_fn_readDir)&deviceHandler_FAT_readDir, + (_fn_readFile)&deviceHandler_FAT_readFile, + (_fn_writeFile)&deviceHandler_FAT_writeFile, + (_fn_deleteFile)&deviceHandler_FAT_deleteFile, + (_fn_seekFile)&deviceHandler_FAT_seekFile, + (_fn_setupFile)&deviceHandler_FAT_setupFile, + (_fn_closeFile)&deviceHandler_FAT_closeFile, + (_fn_deinit)&deviceHandler_FAT_deinit +}; + +DEVICEHANDLER_INTERFACE __device_sd_b = { + "SD Card via SD Adapter - Slot B", + "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, + LOC_MEMCARD_SLOT_B, + &initial_SD_B, + (_fn_test)&deviceHandler_FAT_test_sd_b, + (_fn_info)&deviceHandler_FAT_info, + (_fn_init)&deviceHandler_FAT_init, + (_fn_readDir)&deviceHandler_FAT_readDir, + (_fn_readFile)&deviceHandler_FAT_readFile, + (_fn_writeFile)&deviceHandler_FAT_writeFile, + (_fn_deleteFile)&deviceHandler_FAT_deleteFile, + (_fn_seekFile)&deviceHandler_FAT_seekFile, + (_fn_setupFile)&deviceHandler_FAT_setupFile, + (_fn_closeFile)&deviceHandler_FAT_closeFile, + (_fn_deinit)&deviceHandler_FAT_deinit +}; + +DEVICEHANDLER_INTERFACE __device_ide_a = { + "IDE HDD via IDE-EXI - Slot A", + "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, + LOC_MEMCARD_SLOT_A, + &initial_IDE_A, + (_fn_test)&deviceHandler_FAT_test_ide_a, + (_fn_info)&deviceHandler_FAT_info, + (_fn_init)&deviceHandler_FAT_init, + (_fn_readDir)&deviceHandler_FAT_readDir, + (_fn_readFile)&deviceHandler_FAT_readFile, + (_fn_writeFile)&deviceHandler_FAT_writeFile, + (_fn_deleteFile)&deviceHandler_FAT_deleteFile, + (_fn_seekFile)&deviceHandler_FAT_seekFile, + (_fn_setupFile)&deviceHandler_FAT_setupFile, + (_fn_closeFile)&deviceHandler_FAT_closeFile, + (_fn_deinit)&deviceHandler_FAT_deinit +}; + +DEVICEHANDLER_INTERFACE __device_ide_b = { + "IDE HDD via IDE-EXI - Slot B", + "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, + LOC_MEMCARD_SLOT_B, + &initial_IDE_B, + (_fn_test)&deviceHandler_FAT_test_ide_b, + (_fn_info)&deviceHandler_FAT_info, + (_fn_init)&deviceHandler_FAT_init, + (_fn_readDir)&deviceHandler_FAT_readDir, + (_fn_readFile)&deviceHandler_FAT_readFile, + (_fn_writeFile)&deviceHandler_FAT_writeFile, + (_fn_deleteFile)&deviceHandler_FAT_deleteFile, + (_fn_seekFile)&deviceHandler_FAT_seekFile, + (_fn_setupFile)&deviceHandler_FAT_setupFile, + (_fn_closeFile)&deviceHandler_FAT_closeFile, + (_fn_deinit)&deviceHandler_FAT_deinit +}; diff --git a/cube/swiss/source/devices/fat/deviceHandler-FAT.h b/cube/swiss/source/devices/fat/deviceHandler-FAT.h index e8a4260e..26c3ac65 100644 --- a/cube/swiss/source/devices/fat/deviceHandler-FAT.h +++ b/cube/swiss/source/devices/fat/deviceHandler-FAT.h @@ -9,21 +9,10 @@ #include "../deviceHandler.h" -extern file_handle initial_SD0; -extern file_handle initial_SD1; -extern file_handle initial_IDE0; -extern file_handle initial_IDE1; -extern device_info* deviceHandler_FAT_info(); - -int deviceHandler_FAT_readDir(file_handle*, file_handle**, unsigned int); -int deviceHandler_FAT_readFile(file_handle*, void*, unsigned int); -int deviceHandler_FAT_writeFile(file_handle*, void*, unsigned int); -int deviceHandler_FAT_seekFile(file_handle*, unsigned int, unsigned int); -int deviceHandler_FAT_setupFile(file_handle* file, file_handle* file2); -int deviceHandler_FAT_init(file_handle* file); -int deviceHandler_FAT_deinit(file_handle* file); -int deviceHandler_FAT_deleteFile(file_handle* file); -int deviceHandler_FAT_closeFile(file_handle* file); +extern DEVICEHANDLER_INTERFACE __device_sd_a; +extern DEVICEHANDLER_INTERFACE __device_sd_b; +extern DEVICEHANDLER_INTERFACE __device_ide_a; +extern DEVICEHANDLER_INTERFACE __device_ide_b; #endif diff --git a/cube/swiss/source/devices/filemeta.c b/cube/swiss/source/devices/filemeta.c index b76f21c9..323f3930 100644 --- a/cube/swiss/source/devices/filemeta.c +++ b/cube/swiss/source/devices/filemeta.c @@ -87,7 +87,7 @@ void populate_meta(file_handle *f) { if(endsWith(f->name,".iso") || endsWith(f->name,".gcm") || endsWith(f->name,".ISO") || endsWith(f->name,".GCM")) { - if(curDevice == WODE) { + if(devices[DEVICE_CUR] == &__device_wode) { f->meta = (file_meta*)meta_alloc(sizeof(file_meta)); memset(f->meta, 0, sizeof(file_meta)); // Assign GCM region texture @@ -106,8 +106,8 @@ void populate_meta(file_handle *f) { f->meta = (file_meta*)meta_alloc(sizeof(file_meta)); memset(f->meta, 0, sizeof(file_meta)); DiskHeader *header = memalign(32, sizeof(DiskHeader)); - deviceHandler_seekFile(f, 0, DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(f, header, sizeof(DiskHeader)); + devices[DEVICE_CUR]->seekFile(f, 0, DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(f, header, sizeof(DiskHeader)); if(header->DVDMagicWord == DVD_MAGIC) { //print_gecko("FILE identifed as valid GCM\r\n"); @@ -119,23 +119,23 @@ void populate_meta(file_handle *f) { } else { - deviceHandler_seekFile(f,bannerOffset+0x20,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(f,f->meta->banner,BannerSize)!=BannerSize) { + devices[DEVICE_CUR]->seekFile(f,bannerOffset+0x20,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(f,f->meta->banner,BannerSize)!=BannerSize) { memcpy(f->meta->banner,blankbanner+0x20,BannerSize); } //print_gecko("Read banner from %08X+0x20\r\n", bannerOffset); char bnrType[8]; // If this is a BNR2 banner, show the proper description for the language the console is set to - deviceHandler_seekFile(f,bannerOffset,DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(f,&bnrType[0],4); + devices[DEVICE_CUR]->seekFile(f,bannerOffset,DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(f,&bnrType[0],4); if(!strncmp(bnrType, "BNR2", 4)) { - deviceHandler_seekFile(f,bannerOffset+(0x18e0+(swissSettings.sramLanguage*0x0140)),DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->seekFile(f,bannerOffset+(0x18e0+(swissSettings.sramLanguage*0x0140)),DEVICE_HANDLER_SEEK_SET); } else { - deviceHandler_seekFile(f,bannerOffset+0x18e0,DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->seekFile(f,bannerOffset+0x18e0,DEVICE_HANDLER_SEEK_SET); } - deviceHandler_readFile(f,&f->meta->description[0],0x80); + devices[DEVICE_CUR]->readFile(f,&f->meta->description[0],0x80); //print_gecko("Meta Description: [%s]\r\n",&f->meta->description[0]); } DCFlushRange(f->meta->banner,BannerSize); diff --git a/cube/swiss/source/devices/memcard/deviceHandler-CARD.c b/cube/swiss/source/devices/memcard/deviceHandler-CARD.c index 6aa4409f..b9cb65c1 100644 --- a/cube/swiss/source/devices/memcard/deviceHandler-CARD.c +++ b/cube/swiss/source/devices/memcard/deviceHandler-CARD.c @@ -99,7 +99,7 @@ device_info* deviceHandler_CARD_info() { return &initial_CARD_info; } -int deviceHandler_CARD_readDir(file_handle* ffile, file_handle** dir, unsigned int type){ +s32 deviceHandler_CARD_readDir(file_handle* ffile, file_handle** dir, u32 type){ int num_entries = 1, ret = 0, i = 0, slot = (!strncmp((const char*)initial_CARDB.name, ffile->name, 7)); card_dir *memcard_dir = NULL; @@ -144,7 +144,7 @@ int deviceHandler_CARD_readDir(file_handle* ffile, file_handle** dir, unsigned i return num_entries; } -int deviceHandler_CARD_seekFile(file_handle* file, unsigned int where, unsigned int type){ +s32 deviceHandler_CARD_seekFile(file_handle* file, u32 where, u32 type){ if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; return file->offset; @@ -186,7 +186,7 @@ int CARD_ReadUnaligned(card_file *cardfile, void *buffer, unsigned int length, u } -int deviceHandler_CARD_readFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_CARD_readFile(file_handle* file, void* buffer, u32 length){ card_file cardfile; void *dst = buffer; card_dir* cd = (card_dir*)&file->other; @@ -279,7 +279,7 @@ int deviceHandler_CARD_readFile(file_handle* file, void* buffer, unsigned int le } // This function should always be called for the FULL length cause CARD is lame like that. -int deviceHandler_CARD_writeFile(file_handle* file, void* data, unsigned int length) { +s32 deviceHandler_CARD_writeFile(file_handle* file, void* data, u32 length) { if(gciInfo == NULL) { // Swiss ID for this CARD_SetGameAndCompany(); @@ -396,11 +396,11 @@ void setGCIInfo(void *buffer) { } } -int deviceHandler_CARD_setupFile(file_handle* file, file_handle* file2) { +s32 deviceHandler_CARD_setupFile(file_handle* file, file_handle* file2) { return 1; } -int deviceHandler_CARD_init(file_handle* file){ +s32 deviceHandler_CARD_init(file_handle* file){ int slot = (!strncmp((const char*)initial_CARDB.name, file->name, 7)); file->status = initialize_card(slot); s32 memSize = 0, sectSize = 0; @@ -415,7 +415,7 @@ int deviceHandler_CARD_init(file_handle* file){ return file->status == CARD_ERROR_READY ? 1 : 0; } -int deviceHandler_CARD_deinit(file_handle* file) { +s32 deviceHandler_CARD_deinit(file_handle* file) { if(file) { int slot = (!strncmp((const char*)initial_CARDB.name, file->name, 7)); card_init[slot] = 0; @@ -424,7 +424,7 @@ int deviceHandler_CARD_deinit(file_handle* file) { return 0; } -int deviceHandler_CARD_deleteFile(file_handle* file) { +s32 deviceHandler_CARD_deleteFile(file_handle* file) { int slot = (!strncmp((const char*)initial_CARDB.name, file->name, 7)); char *filename = getRelativeName(file->name); card_dir* cd = (card_dir*)&file->other; @@ -444,7 +444,54 @@ int deviceHandler_CARD_deleteFile(file_handle* file) { return ret; } -int deviceHandler_CARD_closeFile(file_handle* file) { +s32 deviceHandler_CARD_closeFile(file_handle* file) { return 0; } +bool deviceHandler_CARD_test_a() { + return (initialize_card(0)==CARD_ERROR_READY); +} + +bool deviceHandler_CARD_test_b() { + return (initialize_card(1)==CARD_ERROR_READY); +} + +DEVICEHANDLER_INTERFACE __device_card_a = { + "Memory Card - Slot A", + "Backup & Restore save games", + {TEX_MEMCARD, 107, 80}, + FEAT_READ|FEAT_WRITE|FEAT_BOOT_DEVICE, + LOC_MEMCARD_SLOT_A, + &initial_CARDA, + (_fn_test)&deviceHandler_CARD_test_a, + (_fn_info)&deviceHandler_CARD_info, + (_fn_init)&deviceHandler_CARD_init, + (_fn_readDir)&deviceHandler_CARD_readDir, + (_fn_readFile)&deviceHandler_CARD_readFile, + (_fn_writeFile)&deviceHandler_CARD_writeFile, + (_fn_deleteFile)&deviceHandler_CARD_deleteFile, + (_fn_seekFile)&deviceHandler_CARD_seekFile, + (_fn_setupFile)&deviceHandler_CARD_setupFile, + (_fn_closeFile)&deviceHandler_CARD_closeFile, + (_fn_deinit)&deviceHandler_CARD_deinit +}; + +DEVICEHANDLER_INTERFACE __device_card_b = { + "Memory Card - Slot B", + "Backup & Restore save games", + {TEX_MEMCARD, 107, 80}, + FEAT_READ|FEAT_WRITE|FEAT_BOOT_DEVICE, + LOC_MEMCARD_SLOT_B, + &initial_CARDB, + (_fn_test)&deviceHandler_CARD_test_b, + (_fn_info)&deviceHandler_CARD_info, + (_fn_init)&deviceHandler_CARD_init, + (_fn_readDir)&deviceHandler_CARD_readDir, + (_fn_readFile)&deviceHandler_CARD_readFile, + (_fn_writeFile)&deviceHandler_CARD_writeFile, + (_fn_deleteFile)&deviceHandler_CARD_deleteFile, + (_fn_seekFile)&deviceHandler_CARD_seekFile, + (_fn_setupFile)&deviceHandler_CARD_setupFile, + (_fn_closeFile)&deviceHandler_CARD_closeFile, + (_fn_deinit)&deviceHandler_CARD_deinit +}; diff --git a/cube/swiss/source/devices/memcard/deviceHandler-CARD.h b/cube/swiss/source/devices/memcard/deviceHandler-CARD.h index 6a00e4c6..d6ef76b8 100644 --- a/cube/swiss/source/devices/memcard/deviceHandler-CARD.h +++ b/cube/swiss/source/devices/memcard/deviceHandler-CARD.h @@ -28,19 +28,8 @@ typedef struct { u32 comment_addr; } __attribute__((__packed__)) GCI; -extern file_handle initial_CARDA; -extern file_handle initial_CARDB; -extern device_info* deviceHandler_CARD_info(); - -int deviceHandler_CARD_readDir(file_handle*, file_handle**, unsigned int); -int deviceHandler_CARD_readFile(file_handle*, void*, unsigned int); -int deviceHandler_CARD_writeFile(file_handle*, void*, unsigned int); -int deviceHandler_CARD_seekFile(file_handle*, unsigned int, unsigned int); -int deviceHandler_CARD_setupFile(file_handle* file, file_handle* file2); -int deviceHandler_CARD_init(file_handle* file); -int deviceHandler_CARD_deinit(file_handle* file); -int deviceHandler_CARD_deleteFile(file_handle* file); -int deviceHandler_CARD_closeFile(file_handle* file); +extern DEVICEHANDLER_INTERFACE __device_card_a; +extern DEVICEHANDLER_INTERFACE __device_card_b; int initialize_card(int slot); void setCopyGCIMode(bool _isCopyGCIMode); diff --git a/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c b/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c index c48c8a21..8d712940 100644 --- a/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c +++ b/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c @@ -39,7 +39,7 @@ device_info* deviceHandler_Qoob_info() { return &initial_Qoob_info; } -int deviceHandler_Qoob_readDir(file_handle* ffile, file_handle** dir, unsigned int type){ +s32 deviceHandler_Qoob_readDir(file_handle* ffile, file_handle** dir, u32 type){ // Set everything up to read int num_entries = 1, i = 1, block = 0; @@ -81,23 +81,23 @@ int deviceHandler_Qoob_readDir(file_handle* ffile, file_handle** dir, unsigned i return num_entries; } -int deviceHandler_Qoob_seekFile(file_handle* file, unsigned int where, unsigned int type){ +s32 deviceHandler_Qoob_seekFile(file_handle* file, u32 where, u32 type){ if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; return file->offset; } -int deviceHandler_Qoob_readFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_Qoob_readFile(file_handle* file, void* buffer, u32 length){ __SYS_ReadROM(buffer,length,file->fileBase+file->offset); return length; } -int deviceHandler_Qoob_setupFile(file_handle* file, file_handle* file2) { +s32 deviceHandler_Qoob_setupFile(file_handle* file, file_handle* file2) { return 1; } -int deviceHandler_Qoob_init(file_handle* file){ +s32 deviceHandler_Qoob_init(file_handle* file){ DrawFrameStart(); DrawMessageBox(D_INFO,"Reading Qoob"); @@ -106,11 +106,35 @@ int deviceHandler_Qoob_init(file_handle* file){ return 1; } -int deviceHandler_Qoob_deinit(file_handle* file) { +s32 deviceHandler_Qoob_deinit(file_handle* file) { + ipl_set_config(6); return 0; } -int deviceHandler_Qoob_closeFile(file_handle* file) { +s32 deviceHandler_Qoob_closeFile(file_handle* file) { return 0; } +bool deviceHandler_Qoob_test() { + return true; // TODO proper detection +} + +DEVICEHANDLER_INTERFACE __device_qoob = { + "Qoob Pro", + "Qoob Pro Flash File System", + {TEX_QOOB, 70, 80}, + FEAT_READ, + LOC_SYSTEM, + &initial_Qoob, + (_fn_test)&deviceHandler_Qoob_test, + (_fn_info)&deviceHandler_Qoob_info, + (_fn_init)&deviceHandler_Qoob_init, + (_fn_readDir)&deviceHandler_Qoob_readDir, + (_fn_readFile)&deviceHandler_Qoob_readFile, + (_fn_writeFile)NULL, + (_fn_deleteFile)NULL, + (_fn_seekFile)&deviceHandler_Qoob_seekFile, + (_fn_setupFile)NULL, + (_fn_closeFile)&deviceHandler_Qoob_closeFile, + (_fn_deinit)&deviceHandler_Qoob_deinit +}; diff --git a/cube/swiss/source/devices/qoob/deviceHandler-Qoob.h b/cube/swiss/source/devices/qoob/deviceHandler-Qoob.h index e5774dc0..9c862574 100644 --- a/cube/swiss/source/devices/qoob/deviceHandler-Qoob.h +++ b/cube/swiss/source/devices/qoob/deviceHandler-Qoob.h @@ -9,16 +9,7 @@ #include "../deviceHandler.h" -extern file_handle initial_Qoob; -extern device_info* deviceHandler_Qoob_info(); - -int deviceHandler_Qoob_readDir(file_handle*, file_handle**, unsigned int); -int deviceHandler_Qoob_readFile(file_handle*, void*, unsigned int); -int deviceHandler_Qoob_seekFile(file_handle*, unsigned int, unsigned int); -int deviceHandler_Qoob_setupFile(file_handle* file, file_handle* file2); -int deviceHandler_Qoob_init(file_handle* file); -int deviceHandler_Qoob_deinit(file_handle* file); -int deviceHandler_Qoob_closeFile(file_handle* file); +extern DEVICEHANDLER_INTERFACE __device_qoob; #endif diff --git a/cube/swiss/source/devices/smb/deviceHandler-SMB.c b/cube/swiss/source/devices/smb/deviceHandler-SMB.c index 3a910f38..373bdf06 100644 --- a/cube/swiss/source/devices/smb/deviceHandler-SMB.c +++ b/cube/swiss/source/devices/smb/deviceHandler-SMB.c @@ -36,6 +36,7 @@ #include "deviceHandler.h" #include "deviceHandler-FAT.h" #include "deviceHandler-SMB.h" +#include "exi.h" /* SMB Globals */ extern int net_initialized; @@ -91,7 +92,7 @@ void init_samba() { } } -int deviceHandler_SMB_readDir(file_handle* ffile, file_handle** dir, unsigned int type){ +s32 deviceHandler_SMB_readDir(file_handle* ffile, file_handle** dir, u32 type){ // We need at least a share name and ip addr in the settings filled out if(!strlen(&swissSettings.smbShare[0]) || !strlen(&swissSettings.smbServerIp[0])) { @@ -166,13 +167,13 @@ int deviceHandler_SMB_readDir(file_handle* ffile, file_handle** dir, unsigned in return num_entries; } -int deviceHandler_SMB_seekFile(file_handle* file, unsigned int where, unsigned int type){ +s32 deviceHandler_SMB_seekFile(file_handle* file, u32 where, u32 type){ if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; return file->offset; } -int deviceHandler_SMB_readFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_SMB_readFile(file_handle* file, void* buffer, u32 length){ if(!file->fp) { file->fp = fopen( file->name, "rb" ); } @@ -184,13 +185,13 @@ int deviceHandler_SMB_readFile(file_handle* file, void* buffer, unsigned int len return bytes_read; } -int deviceHandler_SMB_init(file_handle* file){ +s32 deviceHandler_SMB_init(file_handle* file){ return 0; } extern char *getDeviceMountPath(char *str); -int deviceHandler_SMB_deinit(file_handle* file) { +s32 deviceHandler_SMB_deinit(file_handle* file) { if(smb_initialized) { smbClose("smb"); smb_initialized = 0; @@ -210,7 +211,30 @@ int deviceHandler_SMB_deinit(file_handle* file) { return 0; } -int deviceHandler_SMB_closeFile(file_handle* file) { +s32 deviceHandler_SMB_closeFile(file_handle* file) { return 0; } +bool deviceHandler_SMB_test() { + return exi_bba_exists(); +} + +DEVICEHANDLER_INTERFACE __device_smb = { + "Samba via BBA", + "Must be pre-configured via swiss.ini", + {TEX_SAMBA, 160, 85}, + FEAT_READ, + LOC_SERIAL_PORT_1, + &initial_SMB, + (_fn_test)&deviceHandler_SMB_test, + (_fn_info)&deviceHandler_SMB_info, + (_fn_init)&deviceHandler_SMB_init, + (_fn_readDir)&deviceHandler_SMB_readDir, + (_fn_readFile)&deviceHandler_SMB_readFile, + (_fn_writeFile)NULL, + (_fn_deleteFile)NULL, + (_fn_seekFile)&deviceHandler_SMB_seekFile, + (_fn_setupFile)NULL, + (_fn_closeFile)&deviceHandler_SMB_closeFile, + (_fn_deinit)&deviceHandler_SMB_deinit +}; diff --git a/cube/swiss/source/devices/smb/deviceHandler-SMB.h b/cube/swiss/source/devices/smb/deviceHandler-SMB.h index a94013a9..101a5dc1 100644 --- a/cube/swiss/source/devices/smb/deviceHandler-SMB.h +++ b/cube/swiss/source/devices/smb/deviceHandler-SMB.h @@ -31,16 +31,7 @@ #define SMB_SMBCFGERR -111 #define SMB_SMBERR -112 -extern file_handle initial_SMB; - -extern device_info* deviceHandler_SMB_info(); - -int deviceHandler_SMB_readDir(file_handle*, file_handle**, unsigned int type); -int deviceHandler_SMB_readFile(file_handle*, void*, unsigned int); -int deviceHandler_SMB_seekFile(file_handle*, unsigned int, unsigned int); -int deviceHandler_SMB_init(file_handle* file); -int deviceHandler_SMB_deinit(file_handle* file); -int deviceHandler_SMB_closeFile(file_handle* file); +extern DEVICEHANDLER_INTERFACE __device_smb; #endif diff --git a/cube/swiss/source/devices/system/deviceHandler-SYS.c b/cube/swiss/source/devices/system/deviceHandler-SYS.c index 721ce654..a39fa43d 100644 --- a/cube/swiss/source/devices/system/deviceHandler-SYS.c +++ b/cube/swiss/source/devices/system/deviceHandler-SYS.c @@ -226,8 +226,8 @@ int read_rom_dvd_rom(unsigned int offset, void* buffer, unsigned int length) { return length; } -int deviceHandler_SYS_init(file_handle* file) { - int i; +s32 deviceHandler_SYS_init(file_handle* file) { + s32 i; for(i = 0; i < NUM_ROMS; i++) { initial_SYS_info.totalSpaceInKB += rom_sizes[i]; @@ -238,7 +238,7 @@ int deviceHandler_SYS_init(file_handle* file) { return 1; } -int deviceHandler_SYS_readDir(file_handle* ffile, file_handle** dir, unsigned int type) { +s32 deviceHandler_SYS_readDir(file_handle* ffile, file_handle** dir, u32 type) { int num_entries = 1, i; *dir = malloc(num_entries * sizeof(file_handle)); memset(&(*dir)[0], 0, sizeof(file_handle)); @@ -258,34 +258,58 @@ int deviceHandler_SYS_readDir(file_handle* ffile, file_handle** dir, unsigned in return num_entries; } -int deviceHandler_SYS_readFile(file_handle* file, void* buffer, unsigned int length) { +s32 deviceHandler_SYS_readFile(file_handle* file, void* buffer, u32 length) { int ret = read_rom[file->fileBase](file->offset, buffer, length); file->offset += ret; return ret; } -int deviceHandler_SYS_writeFile(file_handle* file, void* buffer, unsigned int length) { +s32 deviceHandler_SYS_writeFile(file_handle* file, void* buffer, u32 length) { return 1; } -int deviceHandler_SYS_deleteFile(file_handle* file) { +s32 deviceHandler_SYS_deleteFile(file_handle* file) { return 1; } -int deviceHandler_SYS_seekFile(file_handle* file, unsigned int where, unsigned int type) { +s32 deviceHandler_SYS_seekFile(file_handle* file, u32 where, u32 type) { if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; return file->offset; } -int deviceHandler_SYS_setupFile(file_handle* file, file_handle* file2) { +s32 deviceHandler_SYS_setupFile(file_handle* file, file_handle* file2) { return 1; } -int deviceHandler_SYS_closeFile(file_handle* file) { +s32 deviceHandler_SYS_closeFile(file_handle* file) { return 0; } -int deviceHandler_SYS_deinit() { +s32 deviceHandler_SYS_deinit() { return 0; } + +bool deviceHandler_SYS_test() { + return true; +} + +DEVICEHANDLER_INTERFACE __device_sys = { + "System", + "Backup IPL, DSP, DVD, SRAM", + {TEX_SYSTEM, 160, 85}, + FEAT_READ, + LOC_SYSTEM, + &initial_SYS, + (_fn_test)&deviceHandler_SYS_test, + (_fn_info)&deviceHandler_SYS_info, + (_fn_init)&deviceHandler_SYS_init, + (_fn_readDir)&deviceHandler_SYS_readDir, + (_fn_readFile)&deviceHandler_SYS_readFile, + (_fn_writeFile)NULL, + (_fn_deleteFile)NULL, + (_fn_seekFile)&deviceHandler_SYS_seekFile, + (_fn_setupFile)&deviceHandler_SYS_setupFile, + (_fn_closeFile)&deviceHandler_SYS_closeFile, + (_fn_deinit)&deviceHandler_SYS_deinit +}; diff --git a/cube/swiss/source/devices/system/deviceHandler-SYS.h b/cube/swiss/source/devices/system/deviceHandler-SYS.h index ec2a454c..4550994e 100644 --- a/cube/swiss/source/devices/system/deviceHandler-SYS.h +++ b/cube/swiss/source/devices/system/deviceHandler-SYS.h @@ -8,17 +8,6 @@ #include "../deviceHandler.h" -extern file_handle initial_SYS; -extern device_info* deviceHandler_SYS_info(); - -int deviceHandler_SYS_init(file_handle* file); -int deviceHandler_SYS_readDir(file_handle* ffile, file_handle** dir, unsigned int type); -int deviceHandler_SYS_readFile(file_handle* file, void* buffer, unsigned int length); -int deviceHandler_SYS_writeFile(file_handle* file, void* buffer, unsigned int length); -int deviceHandler_SYS_deleteFile(file_handle* file); -int deviceHandler_SYS_seekFile(file_handle* file, unsigned int where, unsigned int type); -int deviceHandler_SYS_setupFile(file_handle* file, file_handle* file2); -int deviceHandler_SYS_closeFile(file_handle* file); -int deviceHandler_SYS_deinit(); +extern DEVICEHANDLER_INTERFACE __device_sys; #endif diff --git a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c index 4e10981d..d7735478 100644 --- a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c +++ b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c @@ -38,7 +38,7 @@ device_info* deviceHandler_USBGecko_info() { return &initial_USBGecko_info; } -int deviceHandler_USBGecko_readDir(file_handle* ffile, file_handle** dir, unsigned int type){ +s32 deviceHandler_USBGecko_readDir(file_handle* ffile, file_handle** dir, u32 type){ // Set everything up to read int num_entries = 0, i = 0; @@ -73,13 +73,13 @@ int deviceHandler_USBGecko_readDir(file_handle* ffile, file_handle** dir, unsign return num_entries; } -int deviceHandler_USBGecko_seekFile(file_handle* file, unsigned int where, unsigned int type){ +s32 deviceHandler_USBGecko_seekFile(file_handle* file, s32 where, s32 type){ if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; return file->offset; } -int deviceHandler_USBGecko_readFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_USBGecko_readFile(file_handle* file, void* buffer, u32 length){ int reallength = length; if(file->offset + length > file->size) { reallength = file->size - file->offset; @@ -93,14 +93,14 @@ int deviceHandler_USBGecko_readFile(file_handle* file, void* buffer, unsigned in return bytes_read; } -int deviceHandler_USBGecko_writeFile(file_handle* file, void* buffer, unsigned int length) { +s32 deviceHandler_USBGecko_writeFile(file_handle* file, void* buffer, u32 length) { int bytes_written = usbgecko_write_file(buffer, length, file->offset, file->name); if(bytes_written > 0) file->offset += bytes_written; return bytes_written; } -int deviceHandler_USBGecko_setupFile(file_handle* file, file_handle* file2) { +s32 deviceHandler_USBGecko_setupFile(file_handle* file, file_handle* file2) { u32 *fragList = (u32*)VAR_FRAG_LIST; memset((void*)VAR_FRAG_LIST, 0, VAR_FRAG_SIZE); fragList[1] = file->size; @@ -110,7 +110,7 @@ int deviceHandler_USBGecko_setupFile(file_handle* file, file_handle* file2) { return 1; } -int deviceHandler_USBGecko_init(file_handle* file) { +s32 deviceHandler_USBGecko_init(file_handle* file) { DrawFrameStart(); DrawMessageBox(D_INFO,"Looking for USBGecko in Slot B"); DrawFrameFinish(); @@ -147,14 +147,38 @@ int deviceHandler_USBGecko_init(file_handle* file) { } } -int deviceHandler_USBGecko_deinit(file_handle* file) { +s32 deviceHandler_USBGecko_deinit(file_handle* file) { return 0; } -int deviceHandler_USBGecko_deleteFile(file_handle* file) { +s32 deviceHandler_USBGecko_deleteFile(file_handle* file) { return -1; } -int deviceHandler_USBGecko_closeFile(file_handle* file) { +s32 deviceHandler_USBGecko_closeFile(file_handle* file) { return 0; } + +bool deviceHandler_USBGecko_test() { + return usb_isgeckoalive(1); +} + +DEVICEHANDLER_INTERFACE __device_usbgecko = { + "USB Gecko - Slot B only", + "Requires PC application to be up", + {TEX_USBGECKO, 129, 80}, + FEAT_READ|FEAT_BOOT_GCM|FEAT_REPLACES_DVD_FUNCS, + LOC_MEMCARD_SLOT_B, + &initial_USBGecko, + (_fn_test)&deviceHandler_USBGecko_test, + (_fn_info)&deviceHandler_USBGecko_info, + (_fn_init)&deviceHandler_USBGecko_init, + (_fn_readDir)&deviceHandler_USBGecko_readDir, + (_fn_readFile)&deviceHandler_USBGecko_readFile, + (_fn_writeFile)NULL, + (_fn_deleteFile)NULL, + (_fn_seekFile)&deviceHandler_USBGecko_seekFile, + (_fn_setupFile)&deviceHandler_USBGecko_setupFile, + (_fn_closeFile)&deviceHandler_USBGecko_closeFile, + (_fn_deinit)&deviceHandler_USBGecko_deinit +}; diff --git a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.h b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.h index 7caad7a4..63a391c8 100644 --- a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.h +++ b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.h @@ -9,18 +9,7 @@ #include "../deviceHandler.h" -extern file_handle initial_USBGecko; -extern device_info* deviceHandler_USBGecko_info(); - -int deviceHandler_USBGecko_readDir(file_handle*, file_handle**, unsigned int); -int deviceHandler_USBGecko_readFile(file_handle*, void*, unsigned int); -int deviceHandler_USBGecko_writeFile(file_handle*, void*, unsigned int); -int deviceHandler_USBGecko_seekFile(file_handle*, unsigned int, unsigned int); -int deviceHandler_USBGecko_setupFile(file_handle* file, file_handle* file2); -int deviceHandler_USBGecko_init(file_handle* file); -int deviceHandler_USBGecko_deinit(file_handle* file); -int deviceHandler_USBGecko_deleteFile(file_handle* file); -int deviceHandler_USBGecko_closeFile(file_handle* file); +extern DEVICEHANDLER_INTERFACE __device_usbgecko; #endif diff --git a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c index 4b1749d3..543c17f2 100644 --- a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c +++ b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c @@ -45,7 +45,7 @@ device_info* deviceHandler_WKF_info() { return &initial_WKF_info; } -int deviceHandler_WKF_readDir(file_handle* ffile, file_handle** dir, unsigned int type){ +s32 deviceHandler_WKF_readDir(file_handle* ffile, file_handle** dir, u32 type){ DIR* dp = opendir( ffile->name ); if(!dp) return -1; @@ -96,14 +96,14 @@ int deviceHandler_WKF_readDir(file_handle* ffile, file_handle** dir, unsigned in } -int deviceHandler_WKF_seekFile(file_handle* file, unsigned int where, unsigned int type){ +s32 deviceHandler_WKF_seekFile(file_handle* file, u32 where, u32 type){ if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; return file->offset; } -int deviceHandler_WKF_readFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_WKF_readFile(file_handle* file, void* buffer, u32 length){ if(!file->fp) { file->fp = fopen( file->name, "rb" ); if(file->size == -1) { @@ -121,12 +121,12 @@ int deviceHandler_WKF_readFile(file_handle* file, void* buffer, unsigned int len } -int deviceHandler_WKF_writeFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_WKF_writeFile(file_handle* file, void* buffer, u32 length){ return -1; } -int deviceHandler_WKF_setupFile(file_handle* file, file_handle* file2) { +s32 deviceHandler_WKF_setupFile(file_handle* file, file_handle* file2) { // Check if file2 exists if(file2) { get_frag_list(file2->name); @@ -192,7 +192,7 @@ int deviceHandler_WKF_setupFile(file_handle* file, file_handle* file2) { return 1; } -int deviceHandler_WKF_init(file_handle* file){ +s32 deviceHandler_WKF_init(file_handle* file){ struct statvfs buf; DrawFrameStart(); @@ -216,21 +216,44 @@ int deviceHandler_WKF_init(file_handle* file){ } extern char *getDeviceMountPath(char *str); -int deviceHandler_WKF_deinit(file_handle* file) { +s32 deviceHandler_WKF_deinit(file_handle* file) { if(file && file->fp) { fclose(file->fp); file->fp = 0; } - if(deviceHandler_initial) + if(file) fatUnmount(getDeviceMountPath(file->name)); return 0; } -int deviceHandler_WKF_deleteFile(file_handle* file) { +s32 deviceHandler_WKF_deleteFile(file_handle* file) { return -1; } -int deviceHandler_WKF_closeFile(file_handle* file) { +s32 deviceHandler_WKF_closeFile(file_handle* file) { return 0; } +bool deviceHandler_WKF_test() { + return swissSettings.hasDVDDrive && (__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF); +} + +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. + LOC_DVD_CONNECTOR, + &initial_WKF, + (_fn_test)&deviceHandler_WKF_test, + (_fn_info)&deviceHandler_WKF_info, + (_fn_init)&deviceHandler_WKF_init, + (_fn_readDir)&deviceHandler_WKF_readDir, + (_fn_readFile)&deviceHandler_WKF_readFile, + (_fn_writeFile)NULL, + (_fn_deleteFile)NULL, + (_fn_seekFile)&deviceHandler_WKF_seekFile, + (_fn_setupFile)&deviceHandler_WKF_setupFile, + (_fn_closeFile)&deviceHandler_WKF_closeFile, + (_fn_deinit)&deviceHandler_WKF_deinit +}; diff --git a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.h b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.h index 7443c97c..48d7d968 100644 --- a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.h +++ b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.h @@ -9,17 +9,8 @@ #include "../deviceHandler.h" -extern file_handle initial_WKF; extern int wkfFragSetupReq; -extern device_info* deviceHandler_WKF_info(); - -int deviceHandler_WKF_readDir(file_handle*, file_handle**, unsigned int); -int deviceHandler_WKF_readFile(file_handle*, void*, unsigned int); -int deviceHandler_WKF_seekFile(file_handle*, unsigned int, unsigned int); -int deviceHandler_WKF_setupFile(file_handle* file, file_handle* file2); -int deviceHandler_WKF_init(file_handle* file); -int deviceHandler_WKF_deinit(file_handle* file); -int deviceHandler_WKF_closeFile(file_handle* file); +extern DEVICEHANDLER_INTERFACE __device_wkf; #endif diff --git a/cube/swiss/source/devices/wode/deviceHandler-WODE.c b/cube/swiss/source/devices/wode/deviceHandler-WODE.c index c0e962a3..56de9c4a 100644 --- a/cube/swiss/source/devices/wode/deviceHandler-WODE.c +++ b/cube/swiss/source/devices/wode/deviceHandler-WODE.c @@ -49,7 +49,7 @@ device_info* deviceHandler_WODE_info() { return &initial_WODE_info; } -int deviceHandler_WODE_readDir(file_handle* ffile, file_handle** dir, unsigned int type){ +s32 deviceHandler_WODE_readDir(file_handle* ffile, file_handle** dir, u32 type){ if(!wodeInited) return 0; DrawFrameStart(); @@ -87,13 +87,13 @@ int deviceHandler_WODE_readDir(file_handle* ffile, file_handle** dir, unsigned i return num_entries; } -int deviceHandler_WODE_seekFile(file_handle* file, unsigned int where, unsigned int type){ +s32 deviceHandler_WODE_seekFile(file_handle* file, unsigned int where, u32 type){ if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; return file->offset; } -int deviceHandler_WODE_readFile(file_handle* file, void* buffer, unsigned int length){ +s32 deviceHandler_WODE_readFile(file_handle* file, void* buffer, u32 length){ int bytesread = DVD_Read(buffer,file->offset,length); if(bytesread > 0) { file->offset += bytesread; @@ -101,7 +101,7 @@ int deviceHandler_WODE_readFile(file_handle* file, void* buffer, unsigned int le return bytesread; } -int deviceHandler_WODE_setupFile(file_handle* file, file_handle* file2) { +s32 deviceHandler_WODE_setupFile(file_handle* file, file_handle* file2) { ISOInfo_t* isoInfo = (ISOInfo_t*)&file->other; SetISO(isoInfo->iso_partition,isoInfo->iso_number); sleep(2); @@ -110,13 +110,13 @@ int deviceHandler_WODE_setupFile(file_handle* file, file_handle* file2) { return 1; } -int deviceHandler_WODE_init(file_handle* file){ +s32 deviceHandler_WODE_init(file_handle* file){ wodeInited = startupWode() == 0 ? 1:0; initial_WODE_info.totalSpaceInKB = 0; return wodeInited; } -int deviceHandler_WODE_deinit(file_handle* file) { +s32 deviceHandler_WODE_deinit(file_handle* file) { return 0; } @@ -124,6 +124,30 @@ char wodeRegionToChar(int region) { return wode_regions[region]; } -int deviceHandler_WODE_closeFile(file_handle* file) { +s32 deviceHandler_WODE_closeFile(file_handle* file) { return 0; } + +bool deviceHandler_WODE_test() { + return true; +} + +DEVICEHANDLER_INTERFACE __device_wode = { + "WODE Jukebox", + "Supported File System(s): FAT32, NTFS, EXT2/3, HPFS", + {TEX_WODEIMG, 146, 72}, + FEAT_READ|FEAT_BOOT_GCM/*|FEAT_BOOT_DEVICE*/, // TODO re-write init to be silent and re-enable this.; + LOC_DVD_CONNECTOR, + &initial_WODE, + (_fn_test)&deviceHandler_WODE_test, + (_fn_info)&deviceHandler_WODE_info, + (_fn_init)&deviceHandler_WODE_init, + (_fn_readDir)&deviceHandler_WODE_readDir, + (_fn_readFile)&deviceHandler_WODE_readFile, + (_fn_writeFile)NULL, + (_fn_deleteFile)NULL, + (_fn_seekFile)&deviceHandler_WODE_seekFile, + (_fn_setupFile)&deviceHandler_WODE_setupFile, + (_fn_closeFile)&deviceHandler_WODE_closeFile, + (_fn_deinit)&deviceHandler_WODE_deinit +}; diff --git a/cube/swiss/source/devices/wode/deviceHandler-WODE.h b/cube/swiss/source/devices/wode/deviceHandler-WODE.h index 0aa1fd71..71b1e58f 100644 --- a/cube/swiss/source/devices/wode/deviceHandler-WODE.h +++ b/cube/swiss/source/devices/wode/deviceHandler-WODE.h @@ -9,15 +9,7 @@ #include "../deviceHandler.h" -extern file_handle initial_WODE; -extern device_info* deviceHandler_WODE_info(); -int deviceHandler_WODE_readDir(file_handle*, file_handle**, unsigned int); -int deviceHandler_WODE_readFile(file_handle*, void*, unsigned int); -int deviceHandler_WODE_seekFile(file_handle*, unsigned int, unsigned int); -int deviceHandler_WODE_setupFile(file_handle* file, file_handle* file2); -int deviceHandler_WODE_init(file_handle* file); -int deviceHandler_WODE_deinit(file_handle* file); -int deviceHandler_WODE_closeFile(file_handle* file); +extern DEVICEHANDLER_INTERFACE __device_wode; #endif diff --git a/cube/swiss/source/gcm.c b/cube/swiss/source/gcm.c index ce3acb8a..95d191b2 100644 --- a/cube/swiss/source/gcm.c +++ b/cube/swiss/source/gcm.c @@ -31,14 +31,14 @@ unsigned int getBannerOffset(file_handle *file) { char filename[256]; // lets just quickly check if this is a valid GCM (contains magic) - deviceHandler_seekFile(file,0x1C,DEVICE_HANDLER_SEEK_SET); - if((deviceHandler_readFile(file,(unsigned char*)buffer,sizeof(int))!=sizeof(int)) || (buffer[0]!=0xC2339F3D)) { + devices[DEVICE_CUR]->seekFile(file,0x1C,DEVICE_HANDLER_SEEK_SET); + if((devices[DEVICE_CUR]->readFile(file,(unsigned char*)buffer,sizeof(int))!=sizeof(int)) || (buffer[0]!=0xC2339F3D)) { return 0; } // get FST offset and size - deviceHandler_seekFile(file,0x424,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(file,(unsigned char*)buffer,sizeof(int)*2)!=sizeof(int)*2) { + devices[DEVICE_CUR]->seekFile(file,0x424,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(file,(unsigned char*)buffer,sizeof(int)*2)!=sizeof(int)*2) { return 0; } @@ -56,8 +56,8 @@ unsigned int getBannerOffset(file_handle *file) { } // read the FST - deviceHandler_seekFile(file,fst_offset,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(file,FST,fst_size)!=fst_size) { + devices[DEVICE_CUR]->seekFile(file,fst_offset,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(file,FST,fst_size)!=fst_size) { free(FST); return 0; } @@ -98,8 +98,8 @@ int parse_gcm(file_handle *file, ExecutableFile *filesToPatch) { // Grab disc header memset(&header,0,sizeof(DiskHeader)); - deviceHandler_seekFile(file,0,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(file,&header,sizeof(DiskHeader)) != sizeof(DiskHeader)) { + devices[DEVICE_CUR]->seekFile(file,0,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(file,&header,sizeof(DiskHeader)) != sizeof(DiskHeader)) { return -1; } @@ -108,8 +108,8 @@ int parse_gcm(file_handle *file, ExecutableFile *filesToPatch) { if(!FST) { return -1; } - deviceHandler_seekFile(file,header.FSTOffset,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(file,FST,header.FSTSize) != header.FSTSize) { + devices[DEVICE_CUR]->seekFile(file,header.FSTOffset,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(file,FST,header.FSTSize) != header.FSTSize) { free(FST); return -1; } @@ -175,8 +175,8 @@ int parse_gcm(file_handle *file, ExecutableFile *filesToPatch) { DOLHEADER dolhdr; u32 main_dol_size = 0; // Calc size - deviceHandler_seekFile(file,GCMDisk.DOLOffset,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(file,&dolhdr,DOLHDRLENGTH) != DOLHDRLENGTH) { + devices[DEVICE_CUR]->seekFile(file,GCMDisk.DOLOffset,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(file,&dolhdr,DOLHDRLENGTH) != DOLHDRLENGTH) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Failed to read Main DOL Header"); DrawFrameFinish(); @@ -199,8 +199,8 @@ int parse_gcm(file_handle *file, ExecutableFile *filesToPatch) { // Patch the apploader too! // Calc Apploader trailer size u32 appldr_info[2]; - deviceHandler_seekFile(file,0x2454,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(file,&appldr_info,8) != 8) { + devices[DEVICE_CUR]->seekFile(file,0x2454,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(file,&appldr_info,8) != 8) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Failed to read Apploader info"); DrawFrameFinish(); @@ -221,12 +221,12 @@ int parse_tgc(file_handle *file, ExecutableFile *filesToPatch, u32 tgc_base) { u32 fileAreaStart, fakeAmount, offset, size, numFiles = 0; // add this embedded GCM's main DOL - deviceHandler_seekFile(file,tgc_base+0x1C,DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(file,&offset,4); - deviceHandler_readFile(file,&size,4); - deviceHandler_readFile(file, &fileAreaStart, 4); - deviceHandler_seekFile(file,tgc_base+0x34,DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(file, &fakeAmount, 4); + devices[DEVICE_CUR]->seekFile(file,tgc_base+0x1C,DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(file,&offset,4); + devices[DEVICE_CUR]->readFile(file,&size,4); + devices[DEVICE_CUR]->readFile(file, &fileAreaStart, 4); + devices[DEVICE_CUR]->seekFile(file,tgc_base+0x34,DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(file, &fakeAmount, 4); filesToPatch[numFiles].offset = offset+tgc_base; filesToPatch[numFiles].size = size; filesToPatch[numFiles].type = PATCH_DOL; @@ -235,13 +235,13 @@ int parse_tgc(file_handle *file, ExecutableFile *filesToPatch, u32 tgc_base) { // Grab FST Offset & Size u32 fstOfsAndSize[2]; - deviceHandler_seekFile(file,tgc_base+0x10,DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(file,&fstOfsAndSize,2*sizeof(u32)); + devices[DEVICE_CUR]->seekFile(file,tgc_base+0x10,DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(file,&fstOfsAndSize,2*sizeof(u32)); // Alloc and read FST FST=(char*)memalign(32,fstOfsAndSize[1]); - deviceHandler_seekFile(file,tgc_base+fstOfsAndSize[0],DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(file,FST,fstOfsAndSize[1]); + devices[DEVICE_CUR]->seekFile(file,tgc_base+fstOfsAndSize[0],DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(file,FST,fstOfsAndSize[1]); u32 entries=*(unsigned int*)&FST[8]; u32 string_table_offset=FST_ENTRY_SIZE*entries; @@ -291,23 +291,21 @@ int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, i int i, num_patched = 0; // If the current device isn't SD Gecko, init SD Gecko Slot A or B to write patches. - if(deviceHandler_initial != &initial_SD0 && deviceHandler_initial != &initial_SD1) { + if(devices[DEVICE_CUR] != &__device_sd_a && devices[DEVICE_CUR] != &__device_sd_b) { deviceHandler_setStatEnabled(0); - if(deviceHandler_FAT_init(&initial_SD0)) { - savePatchDevice = 0; + if(deviceHandler_test(&__device_sd_a)) { + devices[DEVICE_PATCHES] = &__device_sd_a; } - else if(deviceHandler_FAT_init(&initial_SD1)) { - savePatchDevice = 1; + else if(deviceHandler_test(&__device_sd_b)) { + devices[DEVICE_PATCHES] = &__device_sd_b; } deviceHandler_setStatEnabled(1); } - // Already using SD Gecko - if(deviceHandler_initial == &initial_SD0) - savePatchDevice = 0; - else if(deviceHandler_initial == &initial_SD1) - savePatchDevice = 1; + else { + devices[DEVICE_PATCHES] = devices[DEVICE_CUR]; + } - if(savePatchDevice == -1) { + if(devices[DEVICE_PATCHES] == NULL) { DrawFrameStart(); DrawMessageBox(D_FAIL, "No writable device present\nA SD Gecko must be inserted in\n order to utilise patches for this game."); DrawFrameFinish(); @@ -323,8 +321,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",(savePatchDevice ? "sdb":"sda"), &gameID[0]); - sprintf(&patchBaseDirName[0],"%s:/swiss_patches",(savePatchDevice ? "sdb":"sda")); + 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); 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.. @@ -355,8 +353,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); - deviceHandler_seekFile(file,filesToPatch[i].offset, DEVICE_HANDLER_SEEK_SET); - ret = deviceHandler_readFile(file,buffer,sizeToRead); + devices[DEVICE_PATCHES]->seekFile(file,filesToPatch[i].offset, DEVICE_HANDLER_SEEK_SET); + ret = devices[DEVICE_PATCHES]->readFile(file,buffer,sizeToRead); print_gecko("Read from %08X Size %08X - Result: %08X\r\n", filesToPatch[i].offset, sizeToRead, ret); if(ret != sizeToRead) { DrawFrameStart(); @@ -366,7 +364,7 @@ int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, i return 0; } - if(curDevice != DVD_DISC) { + if(devices[DEVICE_CUR] != &__device_dvd) { ret = Patch_DVDLowLevelRead(buffer, sizeToRead, filesToPatch[i].type); if(READ_PATCHED_ALL != ret) { DrawFrameStart(); @@ -379,7 +377,7 @@ int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, i } // Patch specific game hacks - if(curDevice != DVD_DISC) { + if(devices[DEVICE_CUR] != &__device_dvd) { patched += Patch_GameSpecific(buffer, sizeToRead, &gameID[0], filesToPatch[i].type); } @@ -396,7 +394,7 @@ int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, i Patch_CheatsHook(buffer, sizeToRead, filesToPatch[i].type); } - if(curDevice == DVD_DISC && is_gamecube()) { + if(devices[DEVICE_CUR] == &__device_dvd && is_gamecube()) { patched += Patch_DVDLowLevelReadForDVD(buffer, sizeToRead, filesToPatch[i].type); patched += Patch_DVDReset(buffer, sizeToRead); } diff --git a/cube/swiss/source/gui/FrameBufferMagic.c b/cube/swiss/source/gui/FrameBufferMagic.c index 3aea384e..ef98f034 100644 --- a/cube/swiss/source/gui/FrameBufferMagic.c +++ b/cube/swiss/source/gui/FrameBufferMagic.c @@ -501,14 +501,14 @@ void DrawFileBrowserButton(int x1, int y1, int x2, int y2, char *message, file_h // Print specific stats if(file->fileAttrib==IS_FILE) { - if(curDevice == WODE) { + if(devices[DEVICE_CUR] == &__device_wode) { ISOInfo_t* isoInfo = (ISOInfo_t*)&file->other; sprintf(txtbuffer,"Partition: %i, ISO: %i", isoInfo->iso_partition,isoInfo->iso_number); } - else if(curDevice == MEMCARD) { + else if(devices[DEVICE_CUR] == &__device_card_a || devices[DEVICE_CUR] == &__device_card_b) { sprintf(txtbuffer,"%.2fKB (%ld blocks)", (float)file->size/1024, file->size/8192); } - else if(curDevice == QOOB_FLASH) { + else if(devices[DEVICE_CUR] == &__device_qoob) { sprintf(txtbuffer,"%.2fKB (%ld blocks)", (float)file->size/1024, file->size/0x10000); } else { diff --git a/cube/swiss/source/gui/info.c b/cube/swiss/source/gui/info.c index 16426c8c..72b0326a 100644 --- a/cube/swiss/source/gui/info.c +++ b/cube/swiss/source/gui/info.c @@ -117,7 +117,7 @@ void info_draw_page(int page_num) { sprintf(topStr,"USB Gecko: Not Present"); } WriteFont(30, 170, topStr); - if (!deviceHandler_initial) { + /*if (!deviceHandler_initial) { sprintf(topStr, "Current Device: No Device Selected"); } else if(deviceHandler_initial == &initial_SD0 || deviceHandler_initial == &initial_SD1) { @@ -149,7 +149,7 @@ void info_draw_page(int page_num) { else if(deviceHandler_initial == &initial_SYS) { sprintf(topStr, "Current Device: System"); } - WriteFont(30, 200, topStr); + WriteFont(30, 200, topStr); TODO*/ } else if(page_num == 2) { WriteFont(30, 65, "Credits (3/3):"); diff --git a/cube/swiss/source/gui/settings.c b/cube/swiss/source/gui/settings.c index a1289d23..c0096198 100644 --- a/cube/swiss/source/gui/settings.c +++ b/cube/swiss/source/gui/settings.c @@ -299,7 +299,7 @@ int show_settings(file_handle *file, ConfigEntry *config) { } else { // Save the Swiss system settings since we're called from the main menu - if((curDevice == SD_CARD)||(curDevice == IDEEXI)) { + /*TODO if((curDevice == SD_CARD)||(curDevice == IDEEXI)) { DrawFrameStart(); DrawMessageBox(D_INFO,"Saving Config ..."); DrawFrameFinish(); @@ -314,7 +314,7 @@ int show_settings(file_handle *file, ConfigEntry *config) { DrawMessageBox(D_INFO,"Config Failed to Save!"); DrawFrameFinish(); } - } + }*/ } return 1; } diff --git a/cube/swiss/source/main.c b/cube/swiss/source/main.c index 84f26d46..f68d4963 100644 --- a/cube/swiss/source/main.c +++ b/cube/swiss/source/main.c @@ -23,9 +23,9 @@ #include "info.h" #include "swiss.h" #include "bba.h" -#include "exi.h" #include "dvd.h" #include "wkf.h" +#include "exi.h" #include "httpd.h" #include "config.h" #include "gui/FrameBufferMagic.h" @@ -213,7 +213,8 @@ void* Initialise (void) } void load_auto_dol() { - sprintf(txtbuffer, "%sboot.dol", deviceHandler_initial->name); + sprintf(txtbuffer, "%sboot.dol", devices[DEVICE_CUR]->initial->name); + // TODO use devicehandler stuff here so we can support more devices FILE *fp = fopen(txtbuffer, "rb"); if (fp) { fseek(fp, 0, SEEK_END); @@ -235,17 +236,7 @@ void load_auto_dol() { void load_config() { // Try to open up the config .ini in case it hasn't been opened already (SD, IDE-EXI only) - if(!config_init()) { - if(curDevice == SD_CARD || curDevice == IDEEXI) { - if(!config_create()) { - DrawFrameStart(); - DrawMessageBox(D_INFO,"Failed to create configuration file!"); - DrawFrameFinish(); - sleep(1); - } - } - } - else { + if(config_init()) { DrawFrameStart(); sprintf(txtbuffer,"Loaded %i entries from the config file",config_get_count()); DrawMessageBox(D_INFO,txtbuffer); @@ -263,7 +254,7 @@ int comp(const void *a1, const void *b1) if(a && !b) return -1; if(!a && !b) return 0; - if((curDevice == DVD_DISC) && ((dvdDiscTypeInt == GAMECUBE_DISC) || (dvdDiscTypeInt == MULTIDISC_DISC))) + if((devices[DEVICE_CUR] == &__device_dvd) && ((dvdDiscTypeInt == GAMECUBE_DISC) || (dvdDiscTypeInt == MULTIDISC_DISC))) { if(a->size == DISC_SIZE && a->fileBase == 0) return -1; @@ -313,64 +304,43 @@ void main_loop() // We don't care if a subsequent device is "default" if(needsDeviceChange) { free_files(); - if(deviceHandler_deinit) { - deviceHandler_deinit(deviceHandler_initial); + if(devices[DEVICE_CUR]) { + devices[DEVICE_CUR]->deinit(devices[DEVICE_CUR]->initial); } - curDevice = -1; + devices[DEVICE_CUR] = NULL; needsDeviceChange = 0; - deviceHandler_initial = NULL; needsRefresh = 1; curMenuLocation = ON_FILLIST; - select_device(0); + select_device(DEVICE_CUR); + if(devices[DEVICE_CUR] != NULL) { + memcpy(&curFile, devices[DEVICE_CUR]->initial, sizeof(file_handle)); + } curMenuLocation = ON_OPTIONS; } pause_netinit_thread(); - if(deviceHandler_initial) { + if(devices[DEVICE_CUR] != NULL) { // If the user selected a device, make sure it's ready before we browse the filesystem - deviceHandler_deinit( deviceHandler_initial ); + devices[DEVICE_CUR]->deinit(devices[DEVICE_CUR]->initial); sdgecko_setSpeed(EXI_SPEED32MHZ); - if(!deviceHandler_init( deviceHandler_initial )) { - if(((deviceHandler_initial->name[0] == 's')&&(deviceHandler_initial->name[1] == 'd'))||(deviceHandler_initial->name[0] == 'i')) { - print_gecko("SD/IDE-EXI Device Failed to initialize @ 32MHz!\r\nTrying again once @ 16MHz...\r\n"); - sdgecko_setSpeed(EXI_SPEED16MHZ); - if(!deviceHandler_init(deviceHandler_initial)) { - // Try the alternate slot for SDGecko or IDE-EXI - if(deviceHandler_initial->name[0] == 's') - deviceHandler_initial = (deviceHandler_initial == &initial_SD0) ? - &initial_SD1:&initial_SD0; - else - deviceHandler_initial = (deviceHandler_initial == &initial_IDE0) ? - &initial_IDE1:&initial_IDE0; - memcpy(&curFile, deviceHandler_initial, sizeof(file_handle)); - } - print_gecko("Trying alternate slot @ 32MHz...\r\n"); - sdgecko_setSpeed(EXI_SPEED32MHZ); - if(!deviceHandler_init( deviceHandler_initial )) { - print_gecko("Alternate slot failed once @ 16MHz... \r\n"); - sdgecko_setSpeed(EXI_SPEED16MHZ); - if(!deviceHandler_init( deviceHandler_initial )) { - print_gecko("Both slots failed twice\r\n"); - needsDeviceChange = 1; - return; - } - } - } - } - if(curDevice==SD_CARD || curDevice==WKF || curDevice==IDEEXI) { - load_config(); + if(!devices[DEVICE_CUR]->init( devices[DEVICE_CUR]->initial )) { + needsDeviceChange = 1; + return; } + // TODO load config from current device or if it's not there, try from devices[DEVICE_CONFIG] + //load_config(); + } else { curMenuLocation=ON_OPTIONS; } // If a previously undetected device has been successfully init'd, mark it as available from now on - if(!deviceHandler_getDeviceAvailable(curDevice)) { - deviceHandler_setDeviceAvailable(curDevice, 1); + if(!deviceHandler_getDeviceAvailable(devices[DEVICE_CUR])) { + deviceHandler_setDeviceAvailable(devices[DEVICE_CUR], true); } resume_netinit_thread(); while(1) { - if(deviceHandler_initial && needsRefresh) { + if(devices[DEVICE_CUR] != NULL && needsRefresh) { curMenuLocation=ON_OPTIONS; free_files(); curSelection=0; files=0; curMenuSelection=0; @@ -378,12 +348,12 @@ void main_loop() if(allFiles){ free(allFiles); allFiles = NULL; } print_gecko("Reading directory: %s\r\n",curFile.name); pause_netinit_thread(); - files = deviceHandler_readDir(&curFile, &allFiles, -1); + files = devices[DEVICE_CUR]->readDir(&curFile, &allFiles, -1); resume_netinit_thread(); memcpy(&curDir, &curFile, sizeof(file_handle)); sortFiles(allFiles, files); print_gecko("Found %i entries\r\n",files); - if(files<1) { deviceHandler_deinit(deviceHandler_initial); needsDeviceChange=1; break;} + if(files<1) { devices[DEVICE_CUR]->deinit(devices[DEVICE_CUR]->initial); needsDeviceChange=1; break;} needsRefresh = 0; curMenuLocation=ON_FILLIST; } @@ -395,7 +365,7 @@ void main_loop() if(btns & PAD_BUTTON_LEFT){ curMenuSelection = (--curMenuSelection < 0) ? (MENU_MAX-1) : curMenuSelection;} else if(btns & PAD_BUTTON_RIGHT){curMenuSelection = (curMenuSelection + 1) % MENU_MAX; } } - if(deviceHandler_initial && ((btns & PAD_BUTTON_B)||(curMenuLocation==ON_FILLIST))) { + if(devices[DEVICE_CUR] != NULL && ((btns & PAD_BUTTON_B)||(curMenuLocation==ON_FILLIST))) { while(PAD_ButtonsHeld(0) & PAD_BUTTON_B){ VIDEO_WaitVSync (); } curMenuLocation=ON_FILLIST; renderFileBrowser(&allFiles, files); @@ -413,10 +383,10 @@ void main_loop() show_info(); break; case 3: - if(deviceHandler_initial) { - memcpy(&curFile, deviceHandler_initial, sizeof(file_handle)); - if(curDevice == WKF) { - wkfReinit(); deviceHandler_deinit(deviceHandler_initial); + if(devices[DEVICE_CUR] != NULL) { + memcpy(&curFile, devices[DEVICE_CUR]->initial, sizeof(file_handle)); + if(devices[DEVICE_CUR] == &__device_wkf) { + wkfReinit(); devices[DEVICE_CUR]->deinit(devices[DEVICE_CUR]->initial); } } needsRefresh=1; @@ -444,6 +414,30 @@ int main () { // Setup defaults (if no config is found) memset(&swissSettings, 0 , sizeof(SwissSettings)); + + // Register all devices supported (order matters for boot devices) + int i = 0; + allDevices[i++] = &__device_wkf; + allDevices[i++] = &__device_wode; + allDevices[i++] = &__device_sd_a; + allDevices[i++] = &__device_sd_b; + allDevices[i++] = &__device_card_a; + allDevices[i++] = &__device_card_b; + allDevices[i++] = &__device_dvd; + allDevices[i++] = &__device_ide_a; + allDevices[i++] = &__device_ide_b; + allDevices[i++] = &__device_qoob; + allDevices[i++] = &__device_smb; + allDevices[i++] = &__device_sys; + allDevices[i++] = &__device_usbgecko; + allDevices[i++] = NULL; + + // Set current devices + devices[DEVICE_CUR] = NULL; + devices[DEVICE_DEST] = NULL; + devices[DEVICE_TEMP] = NULL; + devices[DEVICE_CONFIG] = NULL; + devices[DEVICE_PATCHES] = NULL; void *fb; fb = Initialise(); @@ -463,7 +457,6 @@ int main () needsDeviceChange = 1; needsRefresh = 1; - //debugging stuff if(swissSettings.debugUSB) { if(usb_isgeckoalive(1)) { @@ -475,86 +468,37 @@ int main () print_gecko("GIT Revision: %s\r\n", GITVERSION); } - curDevice = -1; // Are we working with a Wiikey Fusion? if(__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF) { print_gecko("Detected Wiikey Fusion with SPI Flash ID: %08X\r\n",__wkfSpiReadId()); - curDevice = WKF; + devices[DEVICE_CUR] = &__device_wkf; } else { deviceHandler_setStatEnabled(0); - // Try to init SD cards here and load config - deviceHandler_initial = &initial_SD0; - deviceHandler_init = deviceHandler_FAT_init; - deviceHandler_deinit = deviceHandler_FAT_deinit; - if(deviceHandler_init(deviceHandler_initial)) { - print_gecko("Detected SDGecko in Slot A\r\n"); - load_auto_dol(); - curDevice = SD_CARD; - } - else { - deviceHandler_initial = &initial_SD1; - if(deviceHandler_init(deviceHandler_initial)) { - print_gecko("Detected SDGecko in Slot B\r\n"); - load_auto_dol(); - curDevice = SD_CARD; - } - } - deviceHandler_setStatEnabled(1); - // If there's still no device, try memory card - if(curDevice < 0) { - deviceHandler_initial = &initial_CARDA; - deviceHandler_init = deviceHandler_CARD_init; - deviceHandler_deinit = deviceHandler_CARD_deinit; - if(deviceHandler_init(deviceHandler_initial)) { - print_gecko("Detected Memory Card in Slot A\r\n"); - curDevice = MEMCARD; - } - else { - deviceHandler_initial = &initial_CARDB; - if(deviceHandler_init(deviceHandler_initial)) { - print_gecko("Detected Memory Card in Slot B\r\n"); - curDevice = MEMCARD; + // Go through all devices with FEAT_BOOT_DEVICE feature and set it as current if one is available + for(i = 0; i < MAX_DEVICES; i++) { + if(allDevices[i] != NULL && (allDevices[i]->features & FEAT_BOOT_DEVICE)) { + print_gecko("Testing device %s\r\n", allDevices[i]->deviceName); + if(allDevices[i]->test()) { + devices[DEVICE_CUR] = allDevices[i]; + break; } } } - } - - // If no device has been selected yet to browse .. - if(curDevice < 0) { - print_gecko("No default boot device detected, trying DVD!\r\n"); - // Do we have a DVD drive with a ready medium we can perhaps browse then? - u8 driveReallyExists[8]; - drive_version(&driveReallyExists[0]); - if(*(u32*)&driveReallyExists[0]) { - dvd_read_id(); - if(!dvd_get_error()) { - print_gecko("DVD Medium is up, using it as default device\r\n"); - curDevice = DVD_DISC; - - // If we have a GameCube (single image) bootable disc, show the banner screen here - dvdDiscTypeInt = gettype_disc(); - if(dvdDiscTypeInt == GAMECUBE_DISC) { - select_device(1); - // Setup curFile and load it - memset(&curFile, 0, sizeof(file_handle)); - strcpy(&curFile.name[0], "game.gcm"); - curFile.size = DISC_SIZE; - curFile.fileAttrib = IS_FILE; - populate_meta(&curFile); - load_file(); - curDevice = -1; - deviceHandler_initial = NULL; - } + if(devices[DEVICE_CUR] != NULL) { + print_gecko("Detected %s\r\n", devices[DEVICE_CUR]->deviceName); + if(devices[DEVICE_CUR]->features & FEAT_AUTOLOAD_DOL) { + load_auto_dol(); } + memcpy(&curFile, devices[DEVICE_CUR]->initial, sizeof(file_handle)); + needsDeviceChange = 0; + // TODO: re-add if dvd && gcm type disc, show banner/boot screen } + deviceHandler_setStatEnabled(1); } - // Default device detected, use it - if(curDevice >= 0) { - needsDeviceChange = 0; - select_device(1); // to setup deviceHandler_ ptrs - load_config(); - } + + // TODO: load config + // Scan here since some devices would already be initialised (faster) populateDeviceAvailability(); @@ -624,38 +568,15 @@ void populateDeviceAvailability() { deviceHandler_setAllDevicesAvailable(); return; } - const DISC_INTERFACE* carda = &__io_gcsda; - const DISC_INTERFACE* cardb = &__io_gcsdb; - // DVD - deviceHandler_setDeviceAvailable(DVD_DISC, swissSettings.hasDVDDrive); - // SD Gecko - DrawFrameStart(); - DrawMessageBox(D_INFO, "Detecting devices [SD] ...\nThis can be skipped by holding B next time"); - DrawFrameFinish(); - deviceHandler_setDeviceAvailable(SD_CARD, carda->isInserted() || cardb->isInserted()); - // IDE-EXI - DrawFrameStart(); - DrawMessageBox(D_INFO, "Detecting devices [IDE-EXI] ...\nThis can be skipped by holding B next time"); - DrawFrameFinish(); - deviceHandler_setDeviceAvailable(IDEEXI, ide_exi_inserted(0) || ide_exi_inserted(1)); - // Qoob - deviceHandler_setDeviceAvailable(QOOB_FLASH, 0); // Hidden by default, add auto detect at some point - // WODE - deviceHandler_setDeviceAvailable(WODE, 0); // Hidden by default, add auto detect at some point - // Memory card - DrawFrameStart(); - DrawMessageBox(D_INFO, "Detecting devices [Memory Card] ...\nThis can be skipped by holding B next time"); - DrawFrameFinish(); - deviceHandler_setDeviceAvailable(MEMCARD, (initialize_card(0)==CARD_ERROR_READY) || (initialize_card(1)==CARD_ERROR_READY)); - // WKF/WASP - DrawFrameStart(); - DrawMessageBox(D_INFO, "Detecting devices [WKF/WASP] ...\nThis can be skipped by holding B next time"); - DrawFrameFinish(); - deviceHandler_setDeviceAvailable(WKF, swissSettings.hasDVDDrive && (__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF)); - // USB Gecko - deviceHandler_setDeviceAvailable(USBGECKO, usb_isgeckoalive(1)); - // BBA/SAMBA - deviceHandler_setDeviceAvailable(SAMBA, exi_bba_exists()); - // System, always there - deviceHandler_setDeviceAvailable(SYS, 1); + int i; + for(i = 0; i < MAX_DEVICES; i++) { + if(allDevices[i] != NULL) { + print_gecko("Checking device availability for device %s\r\n", allDevices[i]->deviceName); + deviceHandler_setDeviceAvailable(allDevices[i], allDevices[i]->test()); + } + if(PAD_ButtonsHeld(0) & PAD_BUTTON_B) { + deviceHandler_setAllDevicesAvailable(); + break; + } + } } diff --git a/cube/swiss/source/mp3.c b/cube/swiss/source/mp3.c index b9ad688b..b4671319 100644 --- a/cube/swiss/source/mp3.c +++ b/cube/swiss/source/mp3.c @@ -13,8 +13,8 @@ static int volume = 255; s32 mp3Reader(void *cbdata, void *dst, s32 size) { file_handle *file = cbdata; - deviceHandler_seekFile(file,file->offset,DEVICE_HANDLER_SEEK_SET); - int ret = deviceHandler_readFile(file,dst,size); + devices[DEVICE_CUR]->seekFile(file,file->offset,DEVICE_HANDLER_SEEK_SET); + int ret = devices[DEVICE_CUR]->readFile(file,dst,size); return ret; } diff --git a/cube/swiss/source/patcher.c b/cube/swiss/source/patcher.c index 1ca02737..3fcf9366 100644 --- a/cube/swiss/source/patcher.c +++ b/cube/swiss/source/patcher.c @@ -71,29 +71,29 @@ int install_code() } // IDE-EXI - if(deviceHandler_initial == &initial_IDE0 || deviceHandler_initial == &initial_IDE1) { + if(devices[DEVICE_CUR] == &__device_ide_a || devices[DEVICE_CUR] == &__device_ide_b) { patch = (!_ideexi_version)?&ideexi_v1_bin[0]:&ideexi_v2_bin[0]; patchSize = (!_ideexi_version)?ideexi_v1_bin_size:ideexi_v2_bin_size; print_gecko("Installing Patch for IDE-EXI\r\n"); } // SD Gecko - else if(deviceHandler_initial == &initial_SD0 || deviceHandler_initial == &initial_SD1) { + else if(devices[DEVICE_CUR] == &__device_sd_a || devices[DEVICE_CUR] == &__device_sd_b) { patch = &sd_bin[0]; patchSize = sd_bin_size; print_gecko("Installing Patch for SD Gecko\r\n"); } // DVD 2 disc code - else if(deviceHandler_initial == &initial_DVD) { + else if(devices[DEVICE_CUR] == &__device_dvd) { patch = &dvd_bin[0]; patchSize = dvd_bin_size; location = (void*)LO_RESERVE_DVD; print_gecko("Installing Patch for DVD\r\n"); } // USB Gecko - else if(deviceHandler_initial == &initial_USBGecko) { + else if(devices[DEVICE_CUR] == &__device_usbgecko) { patch = &usbgecko_bin[0]; patchSize = usbgecko_bin_size; print_gecko("Installing Patch for USB Gecko\r\n"); } // Wiikey Fusion - else if(deviceHandler_initial == &initial_WKF) { + else if(devices[DEVICE_CUR] == &__device_wkf) { location = (void*)LO_RESERVE_DVD; patch = &wkf_bin[0]; patchSize = wkf_bin_size; print_gecko("Installing Patch for WKF\r\n"); diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index 5808956e..9e17b3c5 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -52,8 +52,6 @@ char txtbuffer[2048]; //temporary text buffer file_handle curFile; //filedescriptor for current file file_handle curDir; //filedescriptor for current directory int SDHCCard = 0; //0 == SDHC, 1 == normal SD -int curDevice = 0; //SD_CARD or DVD_DISC or IDEEXI or WODE -int curCopyDevice = 0; //SD_CARD or DVD_DISC or IDEEXI or WODE char *videoStr = NULL; int current_view_start = 0; int current_view_end = 0; @@ -285,21 +283,24 @@ char *stripInvalidChars(char *str) { } void drawCurrentDevice() { - if(deviceHandler_initial == NULL) + if(devices[DEVICE_CUR] == NULL) return; - device_info* info = deviceHandler_info(); - int slot = -1; - + device_info* info = (device_info*)devices[DEVICE_CUR]->info(); + DrawTransparentBox(30, 100, 135, 180); // Device icon + slot box DrawImage(info->textureId, 50, 95, 64, 64, 0, 0.0f, 1.0f, 0.0f, 1.0f, 0); - if(deviceHandler_initial == &initial_SD0 || deviceHandler_initial == &initial_SD1) - slot = (deviceHandler_initial->name[2] == 'b'); - else if(deviceHandler_initial == &initial_IDE0 || deviceHandler_initial == &initial_IDE1) - slot = (deviceHandler_initial->name[3] == 'b'); - else if(deviceHandler_initial == &initial_CARDA || deviceHandler_initial == &initial_CARDB) - slot = (int)deviceHandler_initial->fileBase; - if(slot != -1) - WriteFontStyled(50, 160, slot?"SLOT B":"SLOT A", 0.65f, false, defaultColor); + if(devices[DEVICE_CUR]->location == LOC_MEMCARD_SLOT_A) + WriteFontStyled(50, 160, "Slot A", 0.65f, false, defaultColor); + if(devices[DEVICE_CUR]->location == LOC_MEMCARD_SLOT_B) + WriteFontStyled(50, 160, "Slot B", 0.65f, false, defaultColor); + if(devices[DEVICE_CUR]->location == LOC_DVD_CONNECTOR) + WriteFontStyled(50, 160, "DVD Device", 0.65f, false, defaultColor); + if(devices[DEVICE_CUR]->location == LOC_SERIAL_PORT_1) + WriteFontStyled(50, 160, "Serial Port 1", 0.65f, false, defaultColor); + if(devices[DEVICE_CUR]->location == LOC_SERIAL_PORT_2) + WriteFontStyled(50, 160, "Serial Port 2", 0.65f, false, defaultColor); + if(devices[DEVICE_CUR]->location == LOC_SYSTEM) + WriteFontStyled(50, 160, "System", 0.65f, false, defaultColor); DrawTransparentBox(30, 200, 135, 305); // Device size/extra info box WriteFontStyled(30, 200, "Total:", 0.6f, false, defaultColor); @@ -429,7 +430,7 @@ void select_dest_dir(file_handle* directory, file_handle* selection) while(1){ // Read the directory if(refresh) { - num_files = deviceHandler_dest_readDir(&curDir, &directories, IS_DIR); + num_files = devices[DEVICE_DEST]->readDir(&curDir, &directories, IS_DIR); sortFiles(directories, num_files); refresh = idx = 0; } @@ -493,8 +494,8 @@ unsigned int load_app(int multiDol) memcpy((void*)0x80000020,GC_DefaultConfig,0xE0); // Read the game header to 0x80000000 & apploader header - deviceHandler_seekFile(&curFile,0,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(&curFile,(unsigned char*)0x80000000,32) != 32) { + devices[DEVICE_CUR]->seekFile(&curFile,0,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(&curFile,(unsigned char*)0x80000000,32) != 32) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Game Header Failed to read"); DrawFrameFinish(); @@ -515,7 +516,7 @@ unsigned int load_app(int multiDol) } // Don't needlessly apply audio streaming if the game doesn't want it - if(!GCMDisk.AudioStreaming || curDevice == WKF || curDevice == DVD_DISC) { + if(!GCMDisk.AudioStreaming || devices[DEVICE_CUR] == &__device_wkf || devices[DEVICE_CUR] == &__device_dvd) { swissSettings.muteAudioStreaming = 1; } if(!strncmp((const char*)0x80000000, "PZL", 3)) @@ -532,8 +533,8 @@ unsigned int load_app(int multiDol) // Read FST to top of Main Memory (round to 32 byte boundary) u32 fstSizeAligned = GCMDisk.MaxFSTSize + (32-(GCMDisk.MaxFSTSize%32)); - deviceHandler_seekFile(&curFile,GCMDisk.FSTOffset,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(&curFile,(void*)(top_of_main_ram-fstSizeAligned),GCMDisk.MaxFSTSize) != GCMDisk.MaxFSTSize) { + devices[DEVICE_CUR]->seekFile(&curFile,GCMDisk.FSTOffset,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(&curFile,(void*)(top_of_main_ram-fstSizeAligned),GCMDisk.MaxFSTSize) != GCMDisk.MaxFSTSize) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Failed to read fst.bin"); DrawFrameFinish(); @@ -541,8 +542,8 @@ unsigned int load_app(int multiDol) } // Read bi2.bin (Disk Header Information) to just under the FST - deviceHandler_seekFile(&curFile,0x440,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(&curFile,(void*)(top_of_main_ram-fstSizeAligned-0x2000),0x2000) != 0x2000) { + devices[DEVICE_CUR]->seekFile(&curFile,0x440,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(&curFile,(void*)(top_of_main_ram-fstSizeAligned-0x2000),0x2000) != 0x2000) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Failed to read bi2.bin"); DrawFrameFinish(); @@ -563,8 +564,8 @@ unsigned int load_app(int multiDol) print_gecko("Main DOL Lives at %08X\r\n", GCMDisk.DOLOffset); // Read the Main DOL header - deviceHandler_seekFile(&curFile,GCMDisk.DOLOffset,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(&curFile,&dolhdr,DOLHDRLENGTH) != DOLHDRLENGTH) { + devices[DEVICE_CUR]->seekFile(&curFile,GCMDisk.DOLOffset,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(&curFile,&dolhdr,DOLHDRLENGTH) != DOLHDRLENGTH) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Failed to read Main DOL Header"); DrawFrameFinish(); @@ -585,8 +586,8 @@ unsigned int load_app(int multiDol) // Read the entire Main DOL main_dol_buffer = (u8*)memalign(32,main_dol_size+DOLHDRLENGTH); print_gecko("Main DOL buffer %08X\r\n", (u32)main_dol_buffer); - deviceHandler_seekFile(&curFile,GCMDisk.DOLOffset,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(&curFile,(void*)main_dol_buffer,main_dol_size+DOLHDRLENGTH) != main_dol_size+DOLHDRLENGTH) { + devices[DEVICE_CUR]->seekFile(&curFile,GCMDisk.DOLOffset,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(&curFile,(void*)main_dol_buffer,main_dol_size+DOLHDRLENGTH) != main_dol_size+DOLHDRLENGTH) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Failed to read Main DOL"); DrawFrameFinish(); @@ -594,9 +595,7 @@ unsigned int load_app(int multiDol) } // Patch to read from SD/HDD/USBGecko/WKF (if frag req or audio streaming) - if((curDevice == SD_CARD) - ||(curDevice == IDEEXI) - ||(curDevice == USBGECKO)) { + if(devices[DEVICE_CUR]->features & FEAT_REPLACES_DVD_FUNCS) { u32 ret = Patch_DVDLowLevelRead(main_dol_buffer, main_dol_size+DOLHDRLENGTH, PATCH_DOL); if(READ_PATCHED_ALL != ret) { DrawFrameStart(); @@ -607,7 +606,7 @@ unsigned int load_app(int multiDol) } // Only set up the WKF fragmentation patch if we have to. - if(curDevice == WKF && wkfFragSetupReq) { + if(devices[DEVICE_CUR] == &__device_wkf && wkfFragSetupReq) { u32 ret = Patch_DVDLowLevelReadForWKF(main_dol_buffer, main_dol_size+DOLHDRLENGTH, PATCH_DOL); if(1 != ret) { DrawFrameStart(); @@ -622,11 +621,11 @@ unsigned int load_app(int multiDol) Patch_GameSpecific(main_dol_buffer, main_dol_size+DOLHDRLENGTH, gameID, PATCH_DOL); // 2 Disc support with no modchip - if((curDevice == DVD_DISC) && (is_gamecube()) && (drive_status == DEBUG_MODE)) { + if((devices[DEVICE_CUR] == &__device_dvd) && (is_gamecube()) && (drive_status == DEBUG_MODE)) { Patch_DVDReset(main_dol_buffer, main_dol_size+DOLHDRLENGTH); } // Support patches for multi-dol discs that need to read patched data from SD - if(multiDol && curDevice == DVD_DISC && is_gamecube()) { + if(multiDol && devices[DEVICE_CUR] == &__device_dvd && is_gamecube()) { Patch_DVDLowLevelReadForDVD(main_dol_buffer, main_dol_size+DOLHDRLENGTH, PATCH_DOL); } @@ -672,8 +671,8 @@ unsigned int load_app(int multiDol) } // Don't spin down the drive when running something from it... - if(curDevice != DVD_DISC) { - deviceHandler_deinit(&curFile); + if(devices[DEVICE_CUR] == &__device_dvd) { + devices[DEVICE_CUR]->deinit(&curFile); } DrawFrameStart(); @@ -687,13 +686,13 @@ unsigned int load_app(int multiDol) ICInvalidateRange((void*)0x80000000, 0x3100); // Try a device speed test using the actual in-game read code - if((curDevice == SD_CARD)||(curDevice == IDEEXI)||(curDevice == USBGECKO)) { + if(devices[DEVICE_CUR]->features & FEAT_REPLACES_DVD_FUNCS) { print_gecko("Attempting speed test\r\n"); char *buffer = memalign(32,1024*1024); typedef u32 (*_calc_speed) (void* dst, u32 len, u32 *speed); _calc_speed calculate_speed = (_calc_speed) (void*)(CALC_SPEED); u32 speed = 0; - if(curDevice == IDEEXI) { + if(devices[DEVICE_CUR] == &__device_ide_a || devices[DEVICE_CUR] == &__device_ide_b) { calculate_speed(buffer, 1024*1024, &speed); //Once more for HDD seek speed = 0; } @@ -728,7 +727,7 @@ unsigned int load_app(int multiDol) } // Set WKF base offset if not using the frag or audio streaming patch - if(curDevice == WKF /*&& !wkfFragSetupReq && swissSettings.muteAudioStreaming*/) { + if(devices[DEVICE_CUR] == &__device_wkf /*&& !wkfFragSetupReq && swissSettings.muteAudioStreaming*/) { wkfWriteOffset(*(volatile unsigned int*)VAR_DISC_1_LBA); } print_gecko("libogc shutdown and boot game!\r\n"); @@ -758,9 +757,9 @@ void boot_dol() DrawProgressBar((int)((float)((float)i/(float)curFile.size)*100), txtbuffer); DrawFrameFinish(); - deviceHandler_seekFile(&curFile,i,DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->seekFile(&curFile,i,DEVICE_HANDLER_SEEK_SET); int size = i+131072 > curFile.size ? curFile.size-i : 131072; - if(deviceHandler_readFile(&curFile,ptr,size)!=size) { + if(devices[DEVICE_CUR]->readFile(&curFile,ptr,size)!=size) { DrawFrameStart(); DrawMessageBox(D_FAIL,"Failed to read DOL. Press A."); DrawFrameFinish(); @@ -783,8 +782,8 @@ void boot_dol() file_handle *argFile = &allFiles[i]; char *cli_buffer = memalign(32, argFile->size); if(cli_buffer) { - deviceHandler_seekFile(argFile, 0, DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(argFile, cli_buffer, argFile->size); + devices[DEVICE_CUR]->seekFile(argFile, 0, DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(argFile, cli_buffer, argFile->size); // CLI support if(endsWith(allFiles[i].name,".cli")) { @@ -824,7 +823,7 @@ void boot_dol() } } - if(deviceHandler_deinit && deviceHandler_initial) deviceHandler_deinit( deviceHandler_initial ); + if(devices[DEVICE_CUR] != NULL) devices[DEVICE_CUR]->deinit( devices[DEVICE_CUR]->initial ); // Boot DOLtoARAM(dol_buffer, argc, argc == 0 ? NULL : argv); } @@ -843,7 +842,7 @@ void manage_file() { WriteFontStyled(640/2, 160, "Manage File:", 1.0f, true, defaultColor); float scale = GetTextScaleToFitInWidth(getRelativeName(curFile.name), vmode->fbWidth-10-10); WriteFontStyled(640/2, 200, getRelativeName(curFile.name), scale, true, defaultColor); - if(deviceHandler_deleteFile) { + if(devices[DEVICE_CUR]->features & FEAT_WRITE) { WriteFontStyled(640/2, 230, "(A) Load (X) Copy (Y) Move (Z) Delete", 1.0f, true, defaultColor); } else { @@ -860,12 +859,12 @@ void manage_file() { while(PAD_ButtonsHeld(0) & PAD_BUTTON_X){ VIDEO_WaitVSync (); } break; } - if(deviceHandler_deleteFile && (buttons & PAD_BUTTON_Y)) { + if((devices[DEVICE_CUR]->features & FEAT_WRITE) && (buttons & PAD_BUTTON_Y)) { option = MOVE_OPTION; while(PAD_ButtonsHeld(0) & PAD_BUTTON_Y){ VIDEO_WaitVSync (); } break; } - if(deviceHandler_deleteFile && (buttons & PAD_TRIGGER_Z)) { + if((devices[DEVICE_CUR]->features & FEAT_WRITE) && (buttons & PAD_TRIGGER_Z)) { option = DELETE_OPTION; while(PAD_ButtonsHeld(0) & PAD_TRIGGER_Z){ VIDEO_WaitVSync (); } break; @@ -881,7 +880,7 @@ void manage_file() { // If delete, delete it + refresh the device if(option == DELETE_OPTION) { - if(!deviceHandler_deleteFile(&curFile)) { + if(!devices[DEVICE_CUR]->deleteFile(&curFile)) { //go up a folder int len = strlen(&curFile.name[0]); while(len && curFile.name[len-1]!='/') { @@ -904,38 +903,27 @@ void manage_file() { else if((option == COPY_OPTION) || (option == MOVE_OPTION)) { u32 ret = 0; // Show a list of destination devices (the same device is also a possibility) - select_copy_device(); - // If the devices are not the same, init the second, fail on non-existing device/etc - if(deviceHandler_initial != deviceHandler_dest_initial) { - deviceHandler_dest_deinit( deviceHandler_dest_initial ); - if(!deviceHandler_dest_init( deviceHandler_dest_initial )) { - // Try the alternate slot for SDGecko or IDE-EXI - if(deviceHandler_dest_initial->name[0] == 's') - deviceHandler_dest_initial = (deviceHandler_dest_initial == &initial_SD0) ? - &initial_SD1:&initial_SD0; - else - deviceHandler_dest_initial = (deviceHandler_dest_initial == &initial_IDE0) ? - &initial_IDE1:&initial_IDE0; - - print_gecko("Trying alternate slot...\r\n"); - if(!deviceHandler_dest_init( deviceHandler_dest_initial )) { - DrawFrameStart(); - sprintf(txtbuffer, "Failed to init destination device! (%ld)",ret); - DrawMessageBox(D_FAIL,txtbuffer); - DrawFrameFinish(); - wait_press_A(); - return; - } + select_device(DEVICE_DEST); + // If the devices are not the same, init the destination, fail on non-existing device/etc + if(devices[DEVICE_CUR] != devices[DEVICE_DEST]) { + devices[DEVICE_DEST]->deinit( devices[DEVICE_DEST]->initial ); + if(!devices[DEVICE_DEST]->init( devices[DEVICE_DEST]->initial )) { + DrawFrameStart(); + sprintf(txtbuffer, "Failed to init destination device! (%ld)",ret); + DrawMessageBox(D_FAIL,txtbuffer); + DrawFrameFinish(); + wait_press_A(); + return; } } // Traverse this destination device and let the user select a directory to dump the file in file_handle *destFile = memalign(32,sizeof(file_handle)); // Show a directory only browser and get the destination file location - select_dest_dir(deviceHandler_dest_initial, destFile); + select_dest_dir(devices[DEVICE_DEST]->initial, destFile); - u32 isDestCard = deviceHandler_dest_writeFile == deviceHandler_CARD_writeFile; - u32 isSrcCard = deviceHandler_readFile == deviceHandler_CARD_readFile; + u32 isDestCard = devices[DEVICE_DEST] == &__device_card_a || devices[DEVICE_DEST] == &__device_card_b; + u32 isSrcCard = devices[DEVICE_CUR] == &__device_card_a || devices[DEVICE_CUR] == &__device_card_b; sprintf(destFile->name, "%s/%s",destFile->name,getRelativeName(&curFile.name[0])); destFile->fp = 0; @@ -951,7 +939,7 @@ void manage_file() { // If the destination file already exists, ask the user what to do u8 nothing[1]; - if(deviceHandler_dest_readFile(destFile, nothing, 1) >= 0) { + if(devices[DEVICE_DEST]->readFile(destFile, nothing, 1) >= 0) { DrawFrameStart(); DrawEmptyBox(10,150, vmode->fbWidth-10, 350, COLOR_BLACK); WriteFontStyled(640/2, 160, "File exists:", 1.0f, true, defaultColor); @@ -973,7 +961,7 @@ void manage_file() { return; } else { - deviceHandler_dest_deleteFile(destFile); + devices[DEVICE_DEST]->deleteFile(destFile); } while(PAD_ButtonsHeld(0) & PAD_TRIGGER_Z){ VIDEO_WaitVSync (); } @@ -991,7 +979,7 @@ void manage_file() { name_backup[cursor] = destFile->name[cursor]; } - deviceHandler_dest_closeFile(destFile); + devices[DEVICE_DEST]->closeFile(destFile); if(extension_start >= 0) { destFile->name[extension_start] = 0; @@ -1019,8 +1007,8 @@ void manage_file() { strcpy(destFile->name + cursor, name_backup + extension_start); } - while(deviceHandler_dest_readFile(destFile, nothing, 1) >= 0) { - deviceHandler_dest_closeFile(destFile); + while(devices[DEVICE_DEST]->readFile(destFile, nothing, 1) >= 0) { + devices[DEVICE_DEST]->closeFile(destFile); copy_num++; if(copy_num > 99) { DrawFrameStart(); @@ -1045,12 +1033,12 @@ void manage_file() { } // Seek back to 0 after all these reads - deviceHandler_dest_seekFile(destFile, 0, DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_DEST]->seekFile(destFile, 0, DEVICE_HANDLER_SEEK_SET); // Same (fat based) device and user wants to move the file, just rename ;) - if(deviceHandler_initial == deviceHandler_dest_initial + if(devices[DEVICE_CUR] == devices[DEVICE_DEST] && option == MOVE_OPTION - && (deviceHandler_initial->name[0] =='s' || deviceHandler_initial->name[0] =='i')) { + && (devices[DEVICE_CUR]->features & FEAT_FAT_FUNCS)) { ret = rename(&curFile.name[0], &destFile->name[0]); //go up a folder int len = strlen(&curFile.name[0]); @@ -1074,15 +1062,15 @@ void manage_file() { if(isDestCard && (endsWith(destFile->name,".gci"))) { // Read the header char *gciHeader = memalign(32, sizeof(GCI)); - deviceHandler_seekFile(&curFile, 0, DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(&curFile, gciHeader, sizeof(GCI)); - deviceHandler_seekFile(&curFile, 0, DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->seekFile(&curFile, 0, DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(&curFile, gciHeader, sizeof(GCI)); + devices[DEVICE_CUR]->seekFile(&curFile, 0, DEVICE_HANDLER_SEEK_SET); setGCIInfo(gciHeader); free(gciHeader); } // Read from one file and write to the new directory - u32 isCard = deviceHandler_readFile == deviceHandler_CARD_readFile; + u32 isCard = devices[DEVICE_CUR] == &__device_card_a || devices[DEVICE_CUR] == &__device_card_b; u32 curOffset = 0, cancelled = 0, chunkSize = (isCard||isDestCard) ? curFile.size : (256*1024); char *readBuffer = (char*)memalign(32,chunkSize); @@ -1097,10 +1085,10 @@ void manage_file() { DrawProgressBar((int)((float)((float)curOffset/(float)curFile.size)*100), txtbuffer); DrawFrameFinish(); u32 amountToCopy = curOffset + chunkSize > curFile.size ? curFile.size - curOffset : chunkSize; - ret = deviceHandler_readFile(&curFile, readBuffer, amountToCopy); + ret = devices[DEVICE_CUR]->readFile(&curFile, readBuffer, amountToCopy); if(ret != amountToCopy) { // Retry the read. - deviceHandler_seekFile(&curFile, curFile.offset-ret, DEVICE_HANDLER_SEEK_SET); - ret = deviceHandler_readFile(&curFile, readBuffer, amountToCopy); + devices[DEVICE_CUR]->seekFile(&curFile, curFile.offset-ret, DEVICE_HANDLER_SEEK_SET); + ret = devices[DEVICE_CUR]->readFile(&curFile, readBuffer, amountToCopy); if(ret != amountToCopy) { free(readBuffer); DrawFrameStart(); @@ -1113,7 +1101,7 @@ void manage_file() { return; } } - ret = deviceHandler_dest_writeFile(destFile, readBuffer, amountToCopy); + ret = devices[DEVICE_DEST]->writeFile(destFile, readBuffer, amountToCopy); if(ret != amountToCopy) { free(readBuffer); DrawFrameStart(); @@ -1130,7 +1118,7 @@ void manage_file() { // Handle empty files as a special case if(curFile.size == 0) { - ret = deviceHandler_dest_writeFile(destFile, readBuffer, 0); + ret = devices[DEVICE_DEST]->writeFile(destFile, readBuffer, 0); if(ret != 0) { free(readBuffer); DrawFrameStart(); @@ -1144,7 +1132,7 @@ void manage_file() { } } free(readBuffer); - if(deviceHandler_dest_initial->name[0] == 'i' || deviceHandler_dest_initial->name[0] == 's') { + if(devices[DEVICE_DEST]->features & FEAT_FAT_FUNCS) { fclose(destFile->fp); } setGCIInfo(NULL); @@ -1154,7 +1142,7 @@ void manage_file() { if(!cancelled) { // If cut, delete from source device if(option == MOVE_OPTION) { - deviceHandler_deleteFile(&curFile); + devices[DEVICE_CUR]->deleteFile(&curFile); needsRefresh=1; DrawMessageBox(D_INFO,"Move Complete!"); } @@ -1178,95 +1166,21 @@ void manage_file() { } } -/* Execute/Load/Parse the currently selected file */ -void load_file() -{ - char *fileName = &curFile.name[0]; - - // If it's not a DVD Disc, or it's a DVD disc with some file structure, browse by file type - if((curDevice != DVD_DISC) || (curDevice == DVD_DISC && dvdDiscTypeInt==ISO9660_DISC)) { - //if it's a DOL, boot it - if(strlen(fileName)>4) { - if(endsWith(fileName,".dol")) { - boot_dol(); - // if it was invalid (overlaps sections, too large, etc..) it'll return - DrawFrameStart(); - DrawMessageBox(D_WARN, "Invalid DOL"); - DrawFrameFinish(); - sleep(2); - return; - } - if(endsWith(fileName,".mp3")) { - mp3_player(allFiles, files, &curFile); - return; - } - if(endsWith(fileName,".fzn")) { - if(curFile.size != 0x1D0000) { - DrawFrameStart(); - DrawMessageBox(D_WARN, "File Size must be 0x1D0000 bytes!"); - DrawFrameFinish(); - sleep(2); - return; - } - DrawFrameStart(); - DrawMessageBox(D_INFO, "Reading Flash File ..."); - DrawFrameFinish(); - u8 *flash = (u8*)memalign(32,0x1D0000); - deviceHandler_seekFile(&curFile,0,DEVICE_HANDLER_SEEK_SET); - deviceHandler_readFile(&curFile,flash,0x1D0000); - // Try to read a .fw file too. - file_handle fwFile; - memset(&fwFile, 0, sizeof(file_handle)); - sprintf(&fwFile.name[0],"%s.fw", &curFile.name[0]); - u8 *firmware = (u8*)memalign(32, 0x3000); - DrawFrameStart(); - if(curDevice == DVD_DISC || deviceHandler_readFile(&fwFile,firmware,0x3000) != 0x3000) { - free(firmware); firmware = NULL; - DrawMessageBox(D_WARN, "Didn't find a firmware file, flashing menu only."); - } - else { - DrawMessageBox(D_INFO, "Found firmware file, this will be flashed too."); - } - DrawFrameFinish(); - sleep(1); - wkfWriteFlash(flash, firmware); - DrawFrameStart(); - DrawMessageBox(D_INFO, "Flashing Complete !!"); - DrawFrameFinish(); - sleep(2); - return; - } - if(!(endsWith(fileName,".iso") || endsWith(fileName,".gcm"))) { - DrawFrameStart(); - DrawMessageBox(D_WARN, "Unknown File Type\nEnable file management to manage this file."); - DrawFrameFinish(); - sleep(1); - return; - } - if((endsWith(fileName,".iso") || endsWith(fileName,".gcm")) && (curDevice == SAMBA)) { - DrawFrameStart(); - DrawMessageBox(D_WARN, "Not Supported"); - DrawFrameFinish(); - sleep(1); - return; - } - - } - } +void load_game() { DrawFrameStart(); DrawMessageBox(D_INFO, "Reading ..."); DrawFrameFinish(); - if((curDevice==WODE)) { + if(devices[DEVICE_CUR] == &__device_wode) { DrawFrameStart(); DrawMessageBox(D_INFO, "Setup base offset please Wait .."); DrawFrameFinish(); - deviceHandler_setupFile(&curFile, 0); + devices[DEVICE_CUR]->setupFile(&curFile, 0); } // boot the GCM/ISO file, gamecube disc or multigame selected entry - deviceHandler_seekFile(&curFile,0,DEVICE_HANDLER_SEEK_SET); - if(deviceHandler_readFile(&curFile,&GCMDisk,sizeof(DiskHeader)) != sizeof(DiskHeader)) { + devices[DEVICE_CUR]->seekFile(&curFile,0,DEVICE_HANDLER_SEEK_SET); + if(devices[DEVICE_CUR]->readFile(&curFile,&GCMDisk,sizeof(DiskHeader)) != sizeof(DiskHeader)) { DrawFrameStart(); DrawMessageBox(D_WARN, "Invalid or Corrupt File!"); DrawFrameFinish(); @@ -1301,15 +1215,15 @@ void load_file() int multiDol = 0; // Report to the user the patch status of this GCM/ISO file - if((curDevice == SD_CARD) || (curDevice == IDEEXI) || (curDevice == DVD_DISC)) { + if(devices[DEVICE_CUR]->features & FEAT_REPLACES_DVD_FUNCS) { multiDol = check_game(); } - if(curDevice!=WODE) { + if(devices[DEVICE_CUR] != &__device_wode) { file_handle *secondDisc = NULL; // If we're booting from SD card or IDE hdd - if((curDevice == SD_CARD) || (curDevice == IDEEXI) || (curDevice == WKF)) { + if(devices[DEVICE_CUR]->features & FEAT_REPLACES_DVD_FUNCS) { // look to see if it's a two disc game // set things up properly to allow disc swapping // the files must be setup as so: game-disc1.xxx game-disc2.xxx @@ -1330,7 +1244,7 @@ void load_file() } // Call the special setup for each device (e.g. SD will set the sector(s)) - if(!deviceHandler_setupFile(&curFile, secondDisc)) { + if(!devices[DEVICE_CUR]->setupFile(&curFile, secondDisc)) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Failed to setup the file (too fragmented?)"); DrawFrameFinish(); @@ -1349,6 +1263,85 @@ void load_file() load_app(multiDol); } +/* Execute/Load/Parse the currently selected file */ +void load_file() +{ + char *fileName = &curFile.name[0]; + + // If it's not a DVD Disc, or it's a DVD disc with some file structure, browse by file type + if((devices[DEVICE_CUR] != &__device_dvd) + || (devices[DEVICE_CUR] == &__device_dvd && dvdDiscTypeInt==ISO9660_DISC)) { + //if it's a DOL, boot it + if(strlen(fileName)>4) { + if(endsWith(fileName,".dol")) { + boot_dol(); + // if it was invalid (overlaps sections, too large, etc..) it'll return + DrawFrameStart(); + DrawMessageBox(D_WARN, "Invalid DOL"); + DrawFrameFinish(); + sleep(2); + return; + } + if(endsWith(fileName,".mp3")) { + mp3_player(allFiles, files, &curFile); + return; + } + if(endsWith(fileName,".fzn")) { + if(curFile.size != 0x1D0000) { + DrawFrameStart(); + DrawMessageBox(D_WARN, "File Size must be 0x1D0000 bytes!"); + DrawFrameFinish(); + sleep(2); + return; + } + DrawFrameStart(); + DrawMessageBox(D_INFO, "Reading Flash File ..."); + DrawFrameFinish(); + u8 *flash = (u8*)memalign(32,0x1D0000); + devices[DEVICE_CUR]->seekFile(&curFile,0,DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(&curFile,flash,0x1D0000); + // Try to read a .fw file too. + file_handle fwFile; + memset(&fwFile, 0, sizeof(file_handle)); + sprintf(&fwFile.name[0],"%s.fw", &curFile.name[0]); + u8 *firmware = (u8*)memalign(32, 0x3000); + DrawFrameStart(); + if(devices[DEVICE_CUR] == &__device_dvd || devices[DEVICE_CUR]->readFile(&fwFile,firmware,0x3000) != 0x3000) { + free(firmware); firmware = NULL; + DrawMessageBox(D_WARN, "Didn't find a firmware file, flashing menu only."); + } + else { + DrawMessageBox(D_INFO, "Found firmware file, this will be flashed too."); + } + DrawFrameFinish(); + sleep(1); + wkfWriteFlash(flash, firmware); + DrawFrameStart(); + DrawMessageBox(D_INFO, "Flashing Complete !!"); + DrawFrameFinish(); + sleep(2); + return; + } + if(endsWith(fileName,".iso") || endsWith(fileName,".gcm")) { + if(devices[DEVICE_CUR]->features & FEAT_BOOT_GCM) + load_game(); + else { + DrawFrameStart(); + DrawMessageBox(D_WARN, "This device does not support booting of images."); + DrawFrameFinish(); + sleep(2); + } + return; + } + DrawFrameStart(); + DrawMessageBox(D_WARN, "Unknown File Type\nEnable file management to manage this file."); + DrawFrameFinish(); + sleep(1); + return; + } + } +} + int check_game() { int multiDol = 0; @@ -1369,7 +1362,7 @@ int check_game() void save_config(ConfigEntry *config) { // Save settings to current device - if(curDevice == SD_CARD || curDevice == IDEEXI) { + /*if(curDevice == SD_CARD || curDevice == IDEEXI) { DrawFrameStart(); DrawMessageBox(D_INFO,"Saving Config ..."); DrawFrameFinish(); @@ -1383,7 +1376,7 @@ void save_config(ConfigEntry *config) { DrawMessageBox(D_INFO,"Config Failed to Save!"); DrawFrameFinish(); } - } + }*/ } void draw_game_info() { @@ -1394,10 +1387,27 @@ void draw_game_info() { float scale = GetTextScaleToFitInWidth(txtbuffer,(vmode->fbWidth-78)-75); WriteFontStyled(640/2, 130, txtbuffer, scale, true, defaultColor); - if((curDevice==SD_CARD)||(curDevice == IDEEXI) ||(curDevice == WKF) ||(curDevice == DVD_DISC)) { + if(devices[DEVICE_CUR] == &__device_qoob) { + sprintf(txtbuffer,"Size: %.2fKb (%ld blocks)", (float)curFile.size/1024, curFile.size/0x10000); + WriteFontStyled(640/2, 160, txtbuffer, 0.8f, true, defaultColor); + sprintf(txtbuffer,"Position on Flash: %08lX",(u32)(curFile.fileBase&0xFFFFFFFF)); + WriteFontStyled(640/2, 180, txtbuffer, 0.8f, true, defaultColor); + } + else if(devices[DEVICE_CUR] == &__device_wode) { + ISOInfo_t* isoInfo = (ISOInfo_t*)&curFile.other; + sprintf(txtbuffer,"Partition: %i, ISO: %i", isoInfo->iso_partition,isoInfo->iso_number); + WriteFontStyled(640/2, 160, txtbuffer, 0.8f, true, defaultColor); + } + else if(devices[DEVICE_CUR] == &__device_card_a || devices[DEVICE_CUR] == &__device_card_b) { + sprintf(txtbuffer,"Size: %.2fKb (%ld blocks)", (float)curFile.size/1024, curFile.size/8192); + WriteFontStyled(640/2, 160, txtbuffer, 0.8f, true, defaultColor); + sprintf(txtbuffer,"Position on Card: %08lX",curFile.offset); + WriteFontStyled(640/2, 180, txtbuffer, 0.8f, true, defaultColor); + } + else { sprintf(txtbuffer,"Size: %.2fMB", (float)curFile.size/1024/1024); WriteFontStyled(640/2, 160, txtbuffer, 0.8f, true, defaultColor); - if((curDevice==SD_CARD)||(curDevice == IDEEXI) ||(curDevice == WKF)) { + if(devices[DEVICE_CUR]->features & FEAT_FAT_FUNCS) { get_frag_list(curFile.name); if(frag_list->num > 1) sprintf(txtbuffer,"File is in %ld fragments.", frag_list->num); @@ -1422,23 +1432,6 @@ void draw_game_info() { } } } - else if(curDevice == QOOB_FLASH) { - sprintf(txtbuffer,"Size: %.2fKb (%ld blocks)", (float)curFile.size/1024, curFile.size/0x10000); - WriteFontStyled(640/2, 160, txtbuffer, 0.8f, true, defaultColor); - sprintf(txtbuffer,"Position on Flash: %08lX",(u32)(curFile.fileBase&0xFFFFFFFF)); - WriteFontStyled(640/2, 180, txtbuffer, 0.8f, true, defaultColor); - } - else if(curDevice == WODE) { - ISOInfo_t* isoInfo = (ISOInfo_t*)&curFile.other; - sprintf(txtbuffer,"Partition: %i, ISO: %i", isoInfo->iso_partition,isoInfo->iso_number); - WriteFontStyled(640/2, 160, txtbuffer, 0.8f, true, defaultColor); - } - else if(curDevice == MEMCARD) { - sprintf(txtbuffer,"Size: %.2fKb (%ld blocks)", (float)curFile.size/1024, curFile.size/8192); - WriteFontStyled(640/2, 160, txtbuffer, 0.8f, true, defaultColor); - sprintf(txtbuffer,"Position on Card: %08lX",curFile.offset); - WriteFontStyled(640/2, 180, txtbuffer, 0.8f, true, defaultColor); - } if(GCMDisk.DVDMagicWord == DVD_MAGIC) { sprintf(txtbuffer,"GameID: [%s] Audio Streaming [%s]", (const char*)&GCMDisk ,(GCMDisk.AudioStreaming==1) ? "YES":"NO"); WriteFontStyled(640/2, 200, txtbuffer, 0.8f, true, defaultColor); @@ -1492,121 +1485,7 @@ int info_game() return ret; } - -void select_copy_device() -{ - int inAdvanced = 0; - int inAdvancedPos = 0; - int slot = 1; - while(1) { - doBackdrop(); - DrawEmptyBox(20,190, vmode->fbWidth-20, 355, COLOR_BLACK); - WriteFontStyled(640/2, 195, "Destination device selection", 1.0f, true, defaultColor); - if(inAdvanced) { - // Draw slot / speed selection if advanced menu is showing. - DrawEmptyBox(vmode->fbWidth-170, 370, vmode->fbWidth-20, 405, COLOR_BLACK); - WriteFontStyled(vmode->fbWidth-165, 370, slot ? "Slot: B":"Slot: A", 0.65f, false, !inAdvancedPos ? defaultColor:deSelectedColor); - WriteFontStyled(vmode->fbWidth-165, 385, swissSettings.exiSpeed ? "Speed: Fast":"Speed: Compatible", 0.65f, false, inAdvancedPos ? defaultColor:deSelectedColor); - } - WriteFontStyled(vmode->fbWidth-120, 345, "(X) Advanced", 0.65f, false, inAdvanced ? defaultColor:deSelectedColor); - if(curCopyDevice==DEST_SD_CARD) { - DrawImage(TEX_SDSMALL, 640/2, 230, 60, 80, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "SD Card via SD Gecko", 0.85f, true, defaultColor); - } - else if(curCopyDevice==DEST_IDEEXI) { - DrawImage(TEX_HDD, 640/2, 230, 80, 80, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "IDE HDD via IDE-EXI", 0.85f, true, defaultColor); - } - else if(curCopyDevice==DEST_MEMCARD) { - DrawImage(TEX_MEMCARD, 640/2, 230, 107, 80, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "Memory Card", 0.85f, true, defaultColor); - } - if(curCopyDevice != 2) { - WriteFont(520, 270, "->"); - } - if(curCopyDevice != 0) { - WriteFont(100, 270, "<-"); - } - DrawFrameFinish(); - while (!(PAD_ButtonsHeld(0) & PAD_BUTTON_RIGHT)&& !(PAD_ButtonsHeld(0) & PAD_BUTTON_LEFT) - && !(PAD_ButtonsHeld(0) & PAD_BUTTON_B)&& !(PAD_ButtonsHeld(0) & PAD_BUTTON_A) - && !(PAD_ButtonsHeld(0) & PAD_BUTTON_X)&& !(PAD_ButtonsHeld(0) & PAD_BUTTON_UP)&& !(PAD_ButtonsHeld(0) & PAD_BUTTON_DOWN) ) - { VIDEO_WaitVSync (); } - u16 btns = PAD_ButtonsHeld(0); - if(btns & PAD_BUTTON_X) - inAdvanced ^= 1; - if(inAdvanced) { - if((btns & PAD_BUTTON_DOWN) || (btns & PAD_BUTTON_UP)) { - inAdvancedPos = inAdvancedPos + ((btns & PAD_BUTTON_DOWN) ? 1:-1); - if(inAdvancedPos > 1) inAdvancedPos = 0; - if(inAdvancedPos < 0) inAdvancedPos = 1; - } - if((btns & PAD_BUTTON_RIGHT) || (btns & PAD_BUTTON_LEFT)) { - if(!inAdvancedPos) { - slot ^= 1; - } - else { - swissSettings.exiSpeed^=1; - } - } - } - else { - if((btns & PAD_BUTTON_RIGHT) && curCopyDevice < 2) - curCopyDevice++; - if((btns & PAD_BUTTON_LEFT) && curCopyDevice > 0) - curCopyDevice--; - if((btns & PAD_BUTTON_A) || (btns & PAD_BUTTON_B)) - break; - } - if(btns & PAD_BUTTON_A) { - if(!inAdvanced) - break; - else - inAdvanced = 0; - } - if(btns & PAD_BUTTON_B) break; - while (!(!(PAD_ButtonsHeld(0) & PAD_BUTTON_RIGHT) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_LEFT) - && !(PAD_ButtonsHeld(0) & PAD_BUTTON_B) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_A) - && !(PAD_ButtonsHeld(0) & PAD_BUTTON_X) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_UP) && !(PAD_ButtonsHeld(0) & PAD_BUTTON_DOWN) )) - { VIDEO_WaitVSync (); } - } - while ((PAD_ButtonsHeld(0) & PAD_BUTTON_A)){ VIDEO_WaitVSync (); } - // Deinit any existing deviceHandler state - if((deviceHandler_dest_deinit && deviceHandler_dest_initial) && (deviceHandler_dest_initial != deviceHandler_initial)) deviceHandler_dest_deinit( deviceHandler_dest_initial ); - // Change all the deviceHandler pointers based on the current device - switch(curCopyDevice) { - case DEST_SD_CARD: - case DEST_IDEEXI: - if(curCopyDevice==DEST_IDEEXI) - deviceHandler_dest_initial = !slot ? &initial_IDE0 : &initial_IDE1; - else - deviceHandler_dest_initial = !slot ? &initial_SD0 : &initial_SD1; - deviceHandler_dest_readDir = deviceHandler_FAT_readDir; - deviceHandler_dest_readFile = deviceHandler_FAT_readFile; - deviceHandler_dest_writeFile= deviceHandler_FAT_writeFile; - deviceHandler_dest_deleteFile= deviceHandler_FAT_deleteFile; - deviceHandler_dest_seekFile = deviceHandler_FAT_seekFile; - deviceHandler_dest_setupFile= deviceHandler_FAT_setupFile; - deviceHandler_dest_init = deviceHandler_FAT_init; - deviceHandler_dest_deinit = deviceHandler_FAT_deinit; - deviceHandler_dest_closeFile= deviceHandler_FAT_closeFile; - break; - case DEST_MEMCARD: - deviceHandler_dest_initial = !slot ? &initial_CARDA : &initial_CARDB; - deviceHandler_dest_readDir = deviceHandler_CARD_readDir; - deviceHandler_dest_readFile = deviceHandler_CARD_readFile; - deviceHandler_dest_writeFile= deviceHandler_CARD_writeFile; - deviceHandler_dest_deleteFile= deviceHandler_CARD_deleteFile; - deviceHandler_dest_seekFile = deviceHandler_CARD_seekFile; - deviceHandler_dest_setupFile= deviceHandler_CARD_setupFile; - deviceHandler_dest_init = deviceHandler_CARD_init; - deviceHandler_dest_deinit = deviceHandler_CARD_deinit; - deviceHandler_dest_closeFile= deviceHandler_CARD_closeFile; - break; - } -} - -void select_device(int skipPrompts) +void select_device(int type) { if(is_httpd_in_use()) { doBackdrop(); @@ -1616,269 +1495,111 @@ void select_device(int skipPrompts) return; } - int slot = 1; - if(curDevice < 0) { - curDevice = SD_CARD; - // Go to the first device after SD Gecko if it's not avail - if(!deviceHandler_getDeviceAvailable(curDevice)) { - int i; - for(i=curDevice+1;i<9;i++) { - if(deviceHandler_getDeviceAvailable(i)) { + int curDevice = 0; + int inAdvanced = 0, showAllDevices = 0; + + while(1) { + // Go to the first device available + if(!deviceHandler_getDeviceAvailable(allDevices[curDevice])) { + int i = 0; + while(allDevices[i] != NULL) { + if(deviceHandler_getDeviceAvailable(allDevices[i])) { curDevice = i; break; } + i++; } } - dvdDiscTypeStr = NotInitStr; - int inAdvanced = 0, showAllDevices = 0, inAdvancedPos = 0; - while(1) { - doBackdrop(); - DrawEmptyBox(20,190, vmode->fbWidth-20, 410, COLOR_BLACK); - WriteFontStyled(640/2, 195, "Device Selection", 1.0f, true, defaultColor); + + doBackdrop(); + DrawEmptyBox(20,190, vmode->fbWidth-20, 410, COLOR_BLACK); + WriteFontStyled(640/2, 195, "Device Selection", 1.0f, true, defaultColor); // TODO change based on type + + textureImage *deviceImage = &allDevices[curDevice]->deviceTexture; + DrawImage(deviceImage->textureId, 640/2, 230, deviceImage->width, deviceImage->height, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); + WriteFontStyled(640/2, 330, allDevices[curDevice]->deviceName, 0.85f, true, defaultColor); + WriteFontStyled(640/2, 350, allDevices[curDevice]->deviceDescription, 0.65f, true, defaultColor); + + // Memory card port devices, allow for speed selection + if(allDevices[curDevice]->location & (LOC_MEMCARD_SLOT_A | LOC_MEMCARD_SLOT_B)) { + WriteFontStyled(vmode->fbWidth-190, 400, "(X) EXI Options", 0.65f, false, inAdvanced ? defaultColor:deSelectedColor); if(inAdvanced) { - // Draw slot / speed selection if advanced menu is showing. - WriteFontStyled(vmode->fbWidth-160, 370, slot ? "Slot: B":"Slot: A", 0.65f, false, !inAdvancedPos ? defaultColor:deSelectedColor); - WriteFontStyled(vmode->fbWidth-160, 385, swissSettings.exiSpeed ? "Speed: Fast":"Speed: Compatible", 0.65f, false, inAdvancedPos ? defaultColor:deSelectedColor); + // Draw speed selection if advanced menu is showing. + WriteFontStyled(vmode->fbWidth-160, 385, swissSettings.exiSpeed ? "Speed: Fast":"Speed: Compatible", 0.65f, false, defaultColor); } - if(curDevice==DVD_DISC) { - DrawImage(TEX_GCDVDSMALL, 640/2, 230, 80, 79, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "DVD", 0.85f, true, defaultColor); - WriteFontStyled(640/2, 350, "Supported File System(s): GCM, ISO 9660, Multi-Game", 0.65f, true, defaultColor); - } - else if(curDevice==SD_CARD) { - DrawImage(TEX_SDSMALL, 640/2, 230, 60, 80, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "SD Card via SD Gecko", 0.85f, true, defaultColor); - WriteFontStyled(640/2, 350, "Supported File System(s): FAT16, FAT32", 0.65f, true, defaultColor); - WriteFontStyled(vmode->fbWidth-190, 400, "(X) Advanced Options", 0.65f, false, inAdvanced ? defaultColor:deSelectedColor); - } - else if(curDevice==IDEEXI) { - DrawImage(TEX_HDD, 640/2, 230, 80, 80, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "IDE HDD via IDE-EXI", 0.85f, true, defaultColor); - WriteFontStyled(640/2, 350, "Supported File System(s): FAT16, FAT32", 0.65f, true, defaultColor); - WriteFontStyled(vmode->fbWidth-190, 400, "(X) Advanced Options", 0.65f, false, inAdvanced ? defaultColor:deSelectedColor); - } - else if(curDevice==QOOB_FLASH) { - DrawImage(TEX_QOOB, 640/2, 230, 70, 80, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "Qoob PRO", 0.85f, true, defaultColor); - WriteFontStyled(640/2, 350, "Supported File System(s): QOOB Flash", 0.65f, true, defaultColor); - } - else if(curDevice==WODE) { - DrawImage(TEX_WODEIMG, 640/2, 230, 146, 72, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "WODE Jukebox", 0.85f, true, defaultColor); - WriteFontStyled(640/2, 350, "Supported File System(s): FAT32, NTFS, EXT2/3, HPFS", 0.65f, true, defaultColor); - } - else if(curDevice==MEMCARD) { - DrawImage(TEX_MEMCARD, 640/2, 230, 107, 80, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "Memory Card", 0.85f, true, defaultColor); - WriteFontStyled(vmode->fbWidth-190, 400, "(X) Advanced Options", 0.65f, false, inAdvanced ? defaultColor:deSelectedColor); - } - else if(curDevice==WKF) { - DrawImage(TEX_WIIKEY, 640/2, 230, 102, 80, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "Wiikey / Wasp Fusion", 0.85f, true, defaultColor); - WriteFontStyled(640/2, 350, "Supported File System(s): FAT16, FAT32", 0.65f, true, defaultColor); - } - else if(curDevice==USBGECKO) { - DrawImage(TEX_USBGECKO, 640/2, 230, 129, 80, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "USB Gecko (req. PC app)", 0.85f, true, defaultColor); - WriteFontStyled(640/2, 350, "Slot B only", 0.65f, true, defaultColor); - } - else if(curDevice==SAMBA) { - DrawImage(TEX_SAMBA, 640/2, 230, 160, 85, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "Samba via BBA", 0.85f, true, defaultColor); - } - else if(curDevice==SYS) { - DrawImage(TEX_SYSTEM, 640/2, 230, 160, 85, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, "System", 0.85f, true, defaultColor); + } + WriteFont(520, 270, "->"); + WriteFont(100, 270, "<-"); + + WriteFontStyled(20, 400, "(Z) Show all devices", 0.65f, false, showAllDevices ? defaultColor:deSelectedColor); + DrawFrameFinish(); + while (!(PAD_ButtonsHeld(0) & + (PAD_BUTTON_RIGHT|PAD_BUTTON_LEFT|PAD_BUTTON_B|PAD_BUTTON_A + |PAD_BUTTON_X|PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_TRIGGER_Z) )) + { VIDEO_WaitVSync (); } + u16 btns = PAD_ButtonsHeld(0); + if((btns & PAD_BUTTON_X) && (allDevices[curDevice]->location & (LOC_MEMCARD_SLOT_A | LOC_MEMCARD_SLOT_B))) + inAdvanced ^= 1; + if(btns & PAD_TRIGGER_Z) + showAllDevices ^= 1; + if(inAdvanced) { + if((btns & PAD_BUTTON_RIGHT) || (btns & PAD_BUTTON_LEFT)) { + swissSettings.exiSpeed^=1; } - WriteFont(520, 270, "->"); - WriteFont(100, 270, "<-"); - WriteFontStyled(20, 400, "(Z) Show all devices", 0.65f, false, showAllDevices ? defaultColor:deSelectedColor); - DrawFrameFinish(); - while (!(PAD_ButtonsHeld(0) & - (PAD_BUTTON_RIGHT|PAD_BUTTON_LEFT|PAD_BUTTON_B|PAD_BUTTON_A - |PAD_BUTTON_X|PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_TRIGGER_Z) )) - { VIDEO_WaitVSync (); } - u16 btns = PAD_ButtonsHeld(0); - if(btns & PAD_BUTTON_X && ((curDevice == SD_CARD) || (curDevice == IDEEXI) ||(curDevice == MEMCARD))) - inAdvanced ^= 1; - if(btns & PAD_TRIGGER_Z) - showAllDevices ^= 1; - if(inAdvanced) { - if((btns & PAD_BUTTON_DOWN) || (btns & PAD_BUTTON_UP)) { - inAdvancedPos = inAdvancedPos + ((btns & PAD_BUTTON_DOWN) ? 1:-1); - if(inAdvancedPos > 1) inAdvancedPos = 0; - if(inAdvancedPos < 0) inAdvancedPos = 1; + } + else { + if(btns & PAD_BUTTON_RIGHT) { + if(allDevices[curDevice+1] == NULL) + curDevice = 0; + else + curDevice++; + // Go to the next available device + while(!showAllDevices && !deviceHandler_getDeviceAvailable(allDevices[curDevice])) { + if(allDevices[curDevice] == NULL) + curDevice = 0; + else + curDevice ++; } - if((btns & PAD_BUTTON_RIGHT) || (btns & PAD_BUTTON_LEFT)) { - if(!inAdvancedPos) { - slot ^= 1; - } - else { - swissSettings.exiSpeed^=1; - } + } + if(btns & PAD_BUTTON_LEFT) { + curDevice = curDevice > 0 ? curDevice-1 : 0; + // Go to the next available device + while(!showAllDevices && (allDevices[curDevice] == NULL || !deviceHandler_getDeviceAvailable(allDevices[curDevice]))) { + if(curDevice == 0) + curDevice = MAX_DEVICES; + else + curDevice --; } } - else { - if(btns & PAD_BUTTON_RIGHT) { - curDevice = curDevice < 9 ? curDevice+1 : 0; - while(!showAllDevices && !deviceHandler_getDeviceAvailable(curDevice)) { - if(curDevice == 9) - curDevice = 0; - else - curDevice ++; + } + if(btns & PAD_BUTTON_A) { + if(!inAdvanced) { + if(type == DEVICE_CUR) + break; + else { + if(!(allDevices[curDevice]->features & FEAT_WRITE)) { + // TODO don't break cause read only device } - } - if(btns & PAD_BUTTON_LEFT) { - curDevice = curDevice > 0 ? curDevice-1 : 9; - while(!showAllDevices && !deviceHandler_getDeviceAvailable(curDevice)) { - if(curDevice == 0) - curDevice = 9; - else - curDevice --; + else { + break; } } } - if(btns & PAD_BUTTON_A) { - if(!inAdvanced) - break; - else - inAdvanced = 0; - } - if(btns & PAD_BUTTON_B) { - return; - } - while ((PAD_ButtonsHeld(0) & - (PAD_BUTTON_RIGHT|PAD_BUTTON_LEFT|PAD_BUTTON_B|PAD_BUTTON_A - |PAD_BUTTON_X|PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_TRIGGER_Z) )) - { VIDEO_WaitVSync (); } + else + inAdvanced = 0; } - while ((PAD_ButtonsHeld(0) & PAD_BUTTON_A)){ VIDEO_WaitVSync (); } - // Deinit any existing deviceHandler state - if(deviceHandler_deinit && deviceHandler_initial) deviceHandler_deinit( deviceHandler_initial ); + if(btns & PAD_BUTTON_B) { + return; + } + while ((PAD_ButtonsHeld(0) & + (PAD_BUTTON_RIGHT|PAD_BUTTON_LEFT|PAD_BUTTON_B|PAD_BUTTON_A + |PAD_BUTTON_X|PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_TRIGGER_Z) )) + { VIDEO_WaitVSync (); } } + while ((PAD_ButtonsHeld(0) & PAD_BUTTON_A)){ VIDEO_WaitVSync (); } + // Deinit any existing device + if(devices[type] != NULL) devices[type]->deinit( devices[type]->initial ); - // Change all the deviceHandler pointers based on the current device - switch(curDevice) { - case SD_CARD: - case IDEEXI: - if(skipPrompts) { - slot = (deviceHandler_initial->name[2] == 'b'); - } - if(curDevice==IDEEXI) - deviceHandler_initial = !slot ? &initial_IDE0 : &initial_IDE1; - else - deviceHandler_initial = !slot ? &initial_SD0 : &initial_SD1; - deviceHandler_readDir = deviceHandler_FAT_readDir; - deviceHandler_readFile = deviceHandler_FAT_readFile; - deviceHandler_writeFile= deviceHandler_FAT_writeFile; - deviceHandler_deleteFile= deviceHandler_FAT_deleteFile; - deviceHandler_seekFile = deviceHandler_FAT_seekFile; - deviceHandler_setupFile= deviceHandler_FAT_setupFile; - deviceHandler_init = deviceHandler_FAT_init; - deviceHandler_deinit = deviceHandler_FAT_deinit; - deviceHandler_closeFile= deviceHandler_FAT_closeFile; - deviceHandler_info = deviceHandler_FAT_info; - break; - case DVD_DISC: - deviceHandler_initial = &initial_DVD; - deviceHandler_readDir = deviceHandler_DVD_readDir; - deviceHandler_readFile = deviceHandler_DVD_readFile; - deviceHandler_seekFile = deviceHandler_DVD_seekFile; - deviceHandler_setupFile= deviceHandler_DVD_setupFile; - deviceHandler_init = deviceHandler_DVD_init; - deviceHandler_deinit = deviceHandler_DVD_deinit; - deviceHandler_closeFile= deviceHandler_DVD_closeFile; - deviceHandler_info = deviceHandler_DVD_info; - deviceHandler_deleteFile = NULL; - break; - case QOOB_FLASH: - deviceHandler_initial = &initial_Qoob; - deviceHandler_readDir = deviceHandler_Qoob_readDir; - deviceHandler_readFile = deviceHandler_Qoob_readFile; - deviceHandler_seekFile = deviceHandler_Qoob_seekFile; - deviceHandler_setupFile= deviceHandler_Qoob_setupFile; - deviceHandler_init = deviceHandler_Qoob_init; - deviceHandler_deinit = deviceHandler_Qoob_deinit; - deviceHandler_closeFile= deviceHandler_Qoob_closeFile; - deviceHandler_info = deviceHandler_Qoob_info; - deviceHandler_deleteFile = NULL; - break; - case WODE: - deviceHandler_initial = &initial_WODE; - deviceHandler_readDir = deviceHandler_WODE_readDir; - deviceHandler_readFile = deviceHandler_WODE_readFile; - deviceHandler_seekFile = deviceHandler_WODE_seekFile; - deviceHandler_setupFile= deviceHandler_WODE_setupFile; - deviceHandler_init = deviceHandler_WODE_init; - deviceHandler_deinit = deviceHandler_WODE_deinit; - deviceHandler_closeFile= deviceHandler_WODE_closeFile; - deviceHandler_info = deviceHandler_WODE_info; - deviceHandler_deleteFile = NULL; - break; - case MEMCARD: - if(skipPrompts) { - slot = (deviceHandler_initial->name[4] == 'b'); - } - deviceHandler_initial = !slot ? &initial_CARDA : &initial_CARDB; - deviceHandler_readDir = deviceHandler_CARD_readDir; - deviceHandler_readFile = deviceHandler_CARD_readFile; - deviceHandler_writeFile= deviceHandler_CARD_writeFile; - deviceHandler_deleteFile= deviceHandler_CARD_deleteFile; - deviceHandler_seekFile = deviceHandler_CARD_seekFile; - deviceHandler_setupFile= deviceHandler_CARD_setupFile; - deviceHandler_init = deviceHandler_CARD_init; - deviceHandler_deinit = deviceHandler_CARD_deinit; - deviceHandler_closeFile= deviceHandler_CARD_closeFile; - deviceHandler_info = deviceHandler_CARD_info; - break; - case WKF: - deviceHandler_initial = &initial_WKF; - deviceHandler_readDir = deviceHandler_WKF_readDir; - deviceHandler_readFile = deviceHandler_WKF_readFile; - deviceHandler_seekFile = deviceHandler_WKF_seekFile; - deviceHandler_setupFile= deviceHandler_WKF_setupFile; - deviceHandler_init = deviceHandler_WKF_init; - deviceHandler_deinit = deviceHandler_WKF_deinit; - deviceHandler_closeFile= deviceHandler_WKF_closeFile; - deviceHandler_info = deviceHandler_WKF_info; - deviceHandler_deleteFile = NULL; - break; - case USBGECKO: - deviceHandler_initial = &initial_USBGecko; - deviceHandler_readDir = deviceHandler_USBGecko_readDir; - deviceHandler_readFile = deviceHandler_USBGecko_readFile; - deviceHandler_writeFile = deviceHandler_USBGecko_writeFile; - deviceHandler_seekFile = deviceHandler_USBGecko_seekFile; - deviceHandler_setupFile= deviceHandler_USBGecko_setupFile; - deviceHandler_init = deviceHandler_USBGecko_init; - deviceHandler_deinit = deviceHandler_USBGecko_deinit; - deviceHandler_closeFile= deviceHandler_USBGecko_closeFile; - deviceHandler_info = deviceHandler_USBGecko_info; - deviceHandler_deleteFile = NULL; - break; - case SAMBA: - deviceHandler_initial = &initial_SMB; - deviceHandler_readDir = deviceHandler_SMB_readDir; - deviceHandler_readFile = deviceHandler_SMB_readFile; - deviceHandler_seekFile = deviceHandler_SMB_seekFile; - deviceHandler_init = deviceHandler_SMB_init; - deviceHandler_deinit = deviceHandler_SMB_deinit; - deviceHandler_closeFile= deviceHandler_SMB_closeFile; - deviceHandler_info = deviceHandler_SMB_info; - deviceHandler_deleteFile = NULL; - break; - case SYS: - deviceHandler_initial = &initial_SYS; - deviceHandler_readDir = deviceHandler_SYS_readDir; - deviceHandler_readFile = deviceHandler_SYS_readFile; - deviceHandler_seekFile = deviceHandler_SYS_seekFile; - deviceHandler_init = deviceHandler_SYS_init; - deviceHandler_deinit = deviceHandler_SYS_deinit; - deviceHandler_closeFile= deviceHandler_SYS_closeFile; - deviceHandler_info = deviceHandler_SYS_info; - deviceHandler_deleteFile = NULL; - break; - } - memcpy(&curFile, deviceHandler_initial, sizeof(file_handle)); + devices[type] = allDevices[curDevice]; } From 85d466d92948c23b1acbf58d34802cd34bedae4e Mon Sep 17 00:00:00 2001 From: emu_kidid Date: Tue, 23 May 2017 21:45:42 +0930 Subject: [PATCH 2/8] - Remove unnecessary wkf exclusive detection --- cube/swiss/source/main.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/cube/swiss/source/main.c b/cube/swiss/source/main.c index f68d4963..40040f3f 100644 --- a/cube/swiss/source/main.c +++ b/cube/swiss/source/main.c @@ -468,33 +468,24 @@ int main () print_gecko("GIT Revision: %s\r\n", GITVERSION); } - // Are we working with a Wiikey Fusion? - if(__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF) { - print_gecko("Detected Wiikey Fusion with SPI Flash ID: %08X\r\n",__wkfSpiReadId()); - devices[DEVICE_CUR] = &__device_wkf; - } - else { - deviceHandler_setStatEnabled(0); - // Go through all devices with FEAT_BOOT_DEVICE feature and set it as current if one is available - for(i = 0; i < MAX_DEVICES; i++) { - if(allDevices[i] != NULL && (allDevices[i]->features & FEAT_BOOT_DEVICE)) { - print_gecko("Testing device %s\r\n", allDevices[i]->deviceName); - if(allDevices[i]->test()) { - devices[DEVICE_CUR] = allDevices[i]; - break; - } + // Go through all devices with FEAT_BOOT_DEVICE feature and set it as current if one is available + for(i = 0; i < MAX_DEVICES; i++) { + if(allDevices[i] != NULL && (allDevices[i]->features & FEAT_BOOT_DEVICE)) { + print_gecko("Testing device %s\r\n", allDevices[i]->deviceName); + if(allDevices[i]->test()) { + devices[DEVICE_CUR] = allDevices[i]; + break; } } - if(devices[DEVICE_CUR] != NULL) { - print_gecko("Detected %s\r\n", devices[DEVICE_CUR]->deviceName); - if(devices[DEVICE_CUR]->features & FEAT_AUTOLOAD_DOL) { - load_auto_dol(); - } - memcpy(&curFile, devices[DEVICE_CUR]->initial, sizeof(file_handle)); - needsDeviceChange = 0; - // TODO: re-add if dvd && gcm type disc, show banner/boot screen + } + if(devices[DEVICE_CUR] != NULL) { + print_gecko("Detected %s\r\n", devices[DEVICE_CUR]->deviceName); + if(devices[DEVICE_CUR]->features & FEAT_AUTOLOAD_DOL) { + load_auto_dol(); } - deviceHandler_setStatEnabled(1); + memcpy(&curFile, devices[DEVICE_CUR]->initial, sizeof(file_handle)); + needsDeviceChange = 0; + // TODO: re-add if dvd && gcm type disc, show banner/boot screen } // TODO: load config From 3761d795fe974c77de3de9b39e3fb766db82b88a Mon Sep 17 00:00:00 2001 From: emu_kidid Date: Tue, 30 May 2017 21:57:06 +0930 Subject: [PATCH 3/8] - Fix show all devices navigation issue - Support saving config to any writeable device (setting to choose a config device doesn't exist yet) --- cube/swiss/source/config/config.c | 160 ++++++++++-------- .../source/devices/fat/deviceHandler-FAT.c | 2 +- .../devices/memcard/deviceHandler-CARD.c | 41 ++++- cube/swiss/source/gui/settings.c | 26 ++- cube/swiss/source/main.c | 15 +- cube/swiss/source/swiss.c | 28 ++- 6 files changed, 169 insertions(+), 103 deletions(-) diff --git a/cube/swiss/source/config/config.c b/cube/swiss/source/config/config.c index cb8e2e3a..433c0079 100644 --- a/cube/swiss/source/config/config.c +++ b/cube/swiss/source/config/config.c @@ -44,91 +44,109 @@ static ConfigEntry configEntries[2048]; // That's a lot of Games! static int configEntriesCount = 0; static SwissSettings configSwissSettings; + void strnscpy(char *s1, char *s2, int num) { strncpy(s1, s2, num); s1[num] = 0; } -/** - Initialises the configuration file - Returns 1 on successful file open, 0 otherwise -*/ -int config_init() { - sprintf(txtbuffer, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); - FILE *fp = fopen(txtbuffer, "rb"); - if (fp) { - fseek(fp, 0, SEEK_END); - int size = ftell(fp); - fseek(fp, 0, SEEK_SET); - if (size > 0) { - configEntriesCount = 0; - char *configData = (char*) memalign(32, size); - if (configData) { - fread(configData, 1, size, fp); - config_parse(configData); - free(configData); - } - } - else { - return 0; +/** Crappy dynamic string appender */ +#define APPEND_BLOCKSIZE 256 +typedef struct { + char *mem; + u32 memlen; +} appended_string; + +appended_string *string_append(appended_string *appstr, char* str) { + + if(appstr == NULL) { + appstr = calloc(1, sizeof(appended_string)); + appstr->memlen = (str != NULL) ? strlen(str) : APPEND_BLOCKSIZE; + appstr->memlen += APPEND_BLOCKSIZE-(appstr->memlen % APPEND_BLOCKSIZE); // 64b sized blocks + appstr->mem = calloc(1, appstr->memlen); + if(appstr->mem != NULL && str != NULL) { + strcpy(appstr->mem, str); } - fclose(fp); - return 1; } else { - return 0; + if(str != NULL) { + u32 oldlen = strlen(appstr->mem); + u32 newlenreq = strlen(str) + strlen(appstr->mem); + if(newlenreq >= appstr->memlen) { + newlenreq += APPEND_BLOCKSIZE-(newlenreq%APPEND_BLOCKSIZE); + appstr->mem = realloc(appstr->mem, newlenreq); + appstr->memlen = newlenreq; + memset(appstr->mem + oldlen, 0, newlenreq-oldlen); + } + strcpy(appstr->mem + oldlen, str); + } } - - return 1; + return appstr; } -/** - Creates a configuration file on the root of the device "swiss.ini" - Returns 1 on successful creation, 0 otherwise +/** + Initialises the configuration file + Returns 1 on successful file open, 0 otherwise */ -int config_create() { - return config_update_file(); +int config_init() { + if(devices[DEVICE_CONFIG] == NULL) { + return 0; + } + file_handle *configFile = (file_handle*)calloc(1, sizeof(file_handle)); + sprintf(configFile->name, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); + + if(devices[DEVICE_CONFIG]->readFile(configFile, txtbuffer, 1) == 1) { + devices[DEVICE_CONFIG]->seekFile(configFile, 0, DEVICE_HANDLER_SEEK_SET); + char *configData = (char*) memalign(32, configFile->size); + configEntriesCount = 0; + if (configData) { + memset(configData, 0, configFile->size); + devices[DEVICE_CONFIG]->readFile(configFile, configData, configFile->size); + devices[DEVICE_CONFIG]->closeFile(configFile); + config_parse(configData); + free(configData); + return 1; + } + } + return 0; } int config_update_file() { - sprintf(txtbuffer, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); - FILE *fp = fopen( txtbuffer, "wb" ); - if(fp) { + + if(devices[DEVICE_CONFIG] != NULL) { // Write out header every time char *str = "# Swiss Configuration File!\r\n# Anything written in here will be lost!\r\n\r\n#!!Swiss Settings Start!!\r\n"; - fwrite(str, 1, strlen(str), fp); - + appended_string *configString = string_append(NULL, str); // Write out Swiss settings sprintf(txtbuffer, "SD/IDE Speed=%s\r\n",(configSwissSettings.exiSpeed ? "32MHz":"16MHz")); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Swiss Video Mode=%s\r\n",(uiVModeStr[configSwissSettings.uiVMode])); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Enable Debug=%s\r\n",(configSwissSettings.debugUSB ? "Yes":"No")); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Hide Unknown file types=%s\r\n",(configSwissSettings.hideUnknownFileTypes ? "Yes":"No")); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Stop DVD Motor on startup=%s\r\n",(configSwissSettings.stopMotor ? "Yes":"No")); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Enable WiiRD debug=%s\r\n",(configSwissSettings.wiirdDebug ? "Yes":"No")); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Enable File Management=%s\r\n",(configSwissSettings.enableFileManagement ? "Yes":"No")); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "SMBUserName=%s\r\n",configSwissSettings.smbUser); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "SMBPassword=%s\r\n",configSwissSettings.smbPassword); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "SMBShareName=%s\r\n",configSwissSettings.smbShare); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "SMBHostIP=%s\r\n",configSwissSettings.smbServerIp); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "AutoCheats=%s\r\n", (configSwissSettings.autoCheats ? "Yes":"No")); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "IGRType=%s\r\n", (igrTypeStr[swissSettings.igrType])); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "#!!Swiss Settings End!!\r\n\r\n"); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); - + string_append(configString, txtbuffer); // Write out Game Configs int i; @@ -136,42 +154,52 @@ int config_update_file() { char buffer[256]; strnscpy(buffer, &configEntries[i].game_id[0], 4); sprintf(txtbuffer, "ID=%s\r\n",buffer); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); strnscpy(buffer, &configEntries[i].game_name[0], 32); sprintf(txtbuffer, "Name=%s\r\n",buffer); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); strnscpy(buffer, &configEntries[i].comment[0], 128); sprintf(txtbuffer, "Comment=%s\r\n",buffer); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); strnscpy(buffer, &configEntries[i].status[0], 32); sprintf(txtbuffer, "Status=%s\r\n",buffer); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Force Video Mode=%s\r\n",gameVModeStr[configEntries[i].gameVMode]); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Soft Progressive=%s\r\n",softProgressiveStr[configEntries[i].softProgressive]); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Mute Audio Streaming=%s\r\n",(configEntries[i].muteAudioStreaming ? "Yes":"No")); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Force Widescreen=%s\r\n",forceWidescreenStr[configEntries[i].forceWidescreen]); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); sprintf(txtbuffer, "Force Anisotropy=%s\r\n",(configEntries[i].forceAnisotropy ? "Yes":"No")); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); - + string_append(configString, txtbuffer); + sprintf(txtbuffer, "Force Encoding=%s\r\n\r\n\r\n",forceEncodingStr[configEntries[i].forceEncoding]); - fwrite(txtbuffer, 1, strlen(txtbuffer), fp); + string_append(configString, txtbuffer); + } + + file_handle *configFile = (file_handle*)calloc(1, sizeof(file_handle)); + sprintf(configFile->name, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); + + u32 len = strlen(configString->mem); + if(devices[DEVICE_CONFIG]->writeFile(configFile, configString->mem, len) == len) { + devices[DEVICE_CONFIG]->closeFile(configFile); + return 1; + } + else { + return 0; } - fclose(fp); - return 1; } - return 0; + return 1; } void config_parse(char *configData) { diff --git a/cube/swiss/source/devices/fat/deviceHandler-FAT.c b/cube/swiss/source/devices/fat/deviceHandler-FAT.c index c164b4f9..b25ea722 100644 --- a/cube/swiss/source/devices/fat/deviceHandler-FAT.c +++ b/cube/swiss/source/devices/fat/deviceHandler-FAT.c @@ -159,7 +159,7 @@ s32 deviceHandler_FAT_seekFile(file_handle* file, u32 where, u32 type){ s32 deviceHandler_FAT_readFile(file_handle* file, void* buffer, u32 length){ if(!file->fp) { file->fp = fopen( file->name, "r+" ); - if(file->size == -1) { + if(file->size == 0) { struct stat fstat; stat(file->name,&fstat); file->size = fstat.st_size; diff --git a/cube/swiss/source/devices/memcard/deviceHandler-CARD.c b/cube/swiss/source/devices/memcard/deviceHandler-CARD.c index b9cb65c1..33fb2b2a 100644 --- a/cube/swiss/source/devices/memcard/deviceHandler-CARD.c +++ b/cube/swiss/source/devices/memcard/deviceHandler-CARD.c @@ -75,6 +75,7 @@ char *cardError(int error_code) { int initialize_card(int slot) { + EXI_Detach(slot); int slot_error = CARD_ERROR_READY, i = 0; if(!card_init[slot]) { @@ -144,6 +145,29 @@ s32 deviceHandler_CARD_readDir(file_handle* ffile, file_handle** dir, u32 type){ return num_entries; } +// Finds a file based on file->name and populates file->size if found. +bool findFile(file_handle* file) { + unsigned int slot = (!strncmp((const char*)initial_CARDB.name, file->name, 7)), ret = 0; + char *filename = getRelativeName(file->name); + bool found = false; + CARD_SetGameAndCompany(); + + card_dir* memcard_dir = (card_dir*)memalign(32,sizeof(card_dir)); + memset(memcard_dir, 0, sizeof(card_dir)); + + ret = CARD_FindFirst (slot, memcard_dir, true); + while (CARD_ERROR_NOFILE != ret && !found) { + if(!strcasecmp((const char*)filename, (char*)memcard_dir->filename)) { + file->size = memcard_dir->filelen; + memcpy( file->other, memcard_dir, sizeof(card_dir)); + found = true; + } + ret = CARD_FindNext (memcard_dir); + } + free(memcard_dir); + return found; +} + s32 deviceHandler_CARD_seekFile(file_handle* file, u32 where, u32 type){ if(type == DEVICE_HANDLER_SEEK_SET) file->offset = where; else if(type == DEVICE_HANDLER_SEEK_CUR) file->offset += where; @@ -192,11 +216,21 @@ s32 deviceHandler_CARD_readFile(file_handle* file, void* buffer, u32 length){ card_dir* cd = (card_dir*)&file->other; char *filename = getRelativeName(file->name); unsigned int slot = (!strncmp((const char*)initial_CARDB.name, file->name, 7)), ret = 0; + + if(cd->company[0] == '\0' && cd->gamecode[0] == '\0') { + // Find the file we don't know about and populate this file_handle if we find it. + if(!findFile(file)) { + return CARD_ERROR_NOFILE; + } + CARD_SetCompany((const char*)cd->company); + CARD_SetGamecode((const char*)cd->gamecode); + } + else { + CARD_SetCompany((const char*)cd->company); + CARD_SetGamecode((const char*)cd->gamecode); + } int swissFile = !strncmp((const char*)cd->gamecode, "SWIS", 4) && !strncmp((const char*)cd->company, "S0", 2); - - CARD_SetCompany((const char*)cd->company); - CARD_SetGamecode((const char*)cd->gamecode); // Open the file based on the slot & file name ret = CARD_Open(slot,filename, &cardfile); @@ -272,6 +306,7 @@ s32 deviceHandler_CARD_readFile(file_handle* file, void* buffer, u32 length){ if(swissFile && length != 0) { amountRead+= length; } + DCFlushRange(dst, amountRead); CARD_Close(&cardfile); free(read_buffer); diff --git a/cube/swiss/source/gui/settings.c b/cube/swiss/source/gui/settings.c index c0096198..98b6291b 100644 --- a/cube/swiss/source/gui/settings.c +++ b/cube/swiss/source/gui/settings.c @@ -299,22 +299,20 @@ int show_settings(file_handle *file, ConfigEntry *config) { } else { // Save the Swiss system settings since we're called from the main menu - /*TODO if((curDevice == SD_CARD)||(curDevice == IDEEXI)) { + DrawFrameStart(); + DrawMessageBox(D_INFO,"Saving Config ..."); + DrawFrameFinish(); + config_copy_swiss_settings(&swissSettings); + if(config_update_file()) { DrawFrameStart(); - DrawMessageBox(D_INFO,"Saving Config ..."); + DrawMessageBox(D_INFO,"Config Saved Successfully!"); DrawFrameFinish(); - config_copy_swiss_settings(&swissSettings); - if(config_update_file()) { - DrawFrameStart(); - DrawMessageBox(D_INFO,"Config Saved Successfully!"); - DrawFrameFinish(); - } - else { - DrawFrameStart(); - DrawMessageBox(D_INFO,"Config Failed to Save!"); - DrawFrameFinish(); - } - }*/ + } + else { + DrawFrameStart(); + DrawMessageBox(D_INFO,"Config Failed to Save!"); + DrawFrameFinish(); + } } return 1; } diff --git a/cube/swiss/source/main.c b/cube/swiss/source/main.c index 40040f3f..5c5c03be 100644 --- a/cube/swiss/source/main.c +++ b/cube/swiss/source/main.c @@ -235,7 +235,7 @@ void load_auto_dol() { void load_config() { - // Try to open up the config .ini in case it hasn't been opened already (SD, IDE-EXI only) + // Try to open up the config .ini in case it hasn't been opened already if(config_init()) { DrawFrameStart(); sprintf(txtbuffer,"Loaded %i entries from the config file",config_get_count()); @@ -326,8 +326,8 @@ void main_loop() needsDeviceChange = 1; return; } - // TODO load config from current device or if it's not there, try from devices[DEVICE_CONFIG] - //load_config(); + // load config from current device or if it's not there, try from devices[DEVICE_CONFIG] + load_config(); } else { @@ -486,9 +486,16 @@ int main () memcpy(&curFile, devices[DEVICE_CUR]->initial, sizeof(file_handle)); needsDeviceChange = 0; // TODO: re-add if dvd && gcm type disc, show banner/boot screen + // If this device can write, set it as the config device for now + if(devices[DEVICE_CUR]->features & FEAT_WRITE) { + devices[DEVICE_CONFIG] = devices[DEVICE_CUR]; + } } - // TODO: load config + // load config if we got a device + if(devices[DEVICE_CONFIG] != NULL) { + load_config(); + } // Scan here since some devices would already be initialised (faster) populateDeviceAvailability(); diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index 9e17b3c5..1cce7140 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -1361,22 +1361,20 @@ int check_game() } void save_config(ConfigEntry *config) { - // Save settings to current device - /*if(curDevice == SD_CARD || curDevice == IDEEXI) { + // Save settings to current config device + DrawFrameStart(); + DrawMessageBox(D_INFO,"Saving Config ..."); + DrawFrameFinish(); + if(config_update(config)) { DrawFrameStart(); - DrawMessageBox(D_INFO,"Saving Config ..."); + DrawMessageBox(D_INFO,"Config Saved Successfully!"); DrawFrameFinish(); - if(config_update(config)) { - DrawFrameStart(); - DrawMessageBox(D_INFO,"Config Saved Successfully!"); - DrawFrameFinish(); - } - else { - DrawFrameStart(); - DrawMessageBox(D_INFO,"Config Failed to Save!"); - DrawFrameFinish(); - } - }*/ + } + else { + DrawFrameStart(); + DrawMessageBox(D_INFO,"Config Failed to Save!"); + DrawFrameFinish(); + } } void draw_game_info() { @@ -1500,7 +1498,7 @@ void select_device(int type) while(1) { // Go to the first device available - if(!deviceHandler_getDeviceAvailable(allDevices[curDevice])) { + if(!showAllDevices && !deviceHandler_getDeviceAvailable(allDevices[curDevice])) { int i = 0; while(allDevices[i] != NULL) { if(deviceHandler_getDeviceAvailable(allDevices[i])) { From 84e4c20d18afa934325467196dec6dce1521af6f Mon Sep 17 00:00:00 2001 From: emu_kidid Date: Sat, 3 Jun 2017 00:04:42 +0930 Subject: [PATCH 4/8] - More config device stuff, give each device a unique id and store the configDevice id in sram --- cube/swiss/include/swiss.h | 3 + cube/swiss/source/config/config.c | 176 ++++++++++-------- cube/swiss/source/devices/deviceHandler.c | 8 + cube/swiss/source/devices/deviceHandler.h | 19 ++ .../source/devices/dvd/deviceHandler-DVD.c | 1 + .../source/devices/fat/deviceHandler-FAT.c | 20 +- .../devices/memcard/deviceHandler-CARD.c | 2 + .../source/devices/qoob/deviceHandler-Qoob.c | 1 + .../source/devices/smb/deviceHandler-SMB.c | 1 + .../source/devices/system/deviceHandler-SYS.c | 1 + .../devices/usbgecko/deviceHandler-usbgecko.c | 1 + .../wiikeyfusion/deviceHandler-wiikeyfusion.c | 1 + .../source/devices/wode/deviceHandler-WODE.c | 1 + cube/swiss/source/gui/settings.c | 92 +++++++-- cube/swiss/source/main.c | 19 +- 15 files changed, 239 insertions(+), 107 deletions(-) diff --git a/cube/swiss/include/swiss.h b/cube/swiss/include/swiss.h index 8ed07426..83b04c83 100644 --- a/cube/swiss/include/swiss.h +++ b/cube/swiss/include/swiss.h @@ -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, ...); @@ -95,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; diff --git a/cube/swiss/source/config/config.c b/cube/swiss/source/config/config.c index 433c0079..a22a0fdc 100644 --- a/cube/swiss/source/config/config.c +++ b/cube/swiss/source/config/config.c @@ -84,18 +84,41 @@ appended_string *string_append(appended_string *appstr, char* str) { return appstr; } +// Tries to init the current config device +bool config_set_device() { + // Set the current config device to whatever the current configDeviceId is + DEVICEHANDLER_INTERFACE *configDevice = getDeviceByUniqueId(swissSettings.configDeviceId); + devices[DEVICE_CONFIG] = NULL; + if(configDevice != NULL) { + if((configDevice->features & FEAT_WRITE) && deviceHandler_getDeviceAvailable(configDevice)) { + devices[DEVICE_CONFIG] = configDevice; + } + } + + // Not available or not a writable device? That's too bad. + if(devices[DEVICE_CONFIG] == NULL) { + return false; + } + + // 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)) { + return false; + } + } + return true; +} /** Initialises the configuration file Returns 1 on successful file open, 0 otherwise */ int config_init() { - if(devices[DEVICE_CONFIG] == NULL) { - return 0; - } + if(!config_set_device()) return 0; file_handle *configFile = (file_handle*)calloc(1, sizeof(file_handle)); sprintf(configFile->name, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); + // Read config if(devices[DEVICE_CONFIG]->readFile(configFile, txtbuffer, 1) == 1) { devices[DEVICE_CONFIG]->seekFile(configFile, 0, DEVICE_HANDLER_SEEK_SET); char *configData = (char*) memalign(32, configFile->size); @@ -104,6 +127,9 @@ int config_init() { memset(configData, 0, configFile->size); devices[DEVICE_CONFIG]->readFile(configFile, configData, configFile->size); devices[DEVICE_CONFIG]->closeFile(configFile); + if(devices[DEVICE_CONFIG] != devices[DEVICE_CUR]) { + devices[DEVICE_CONFIG]->deinit(devices[DEVICE_CONFIG]->initial); + } config_parse(configData); free(configData); return 1; @@ -113,92 +139,96 @@ int config_init() { } int config_update_file() { + if(!config_set_device()) return 0; - if(devices[DEVICE_CONFIG] != NULL) { - // Write out header every time - char *str = "# Swiss Configuration File!\r\n# Anything written in here will be lost!\r\n\r\n#!!Swiss Settings Start!!\r\n"; - appended_string *configString = string_append(NULL, str); - // Write out Swiss settings - sprintf(txtbuffer, "SD/IDE Speed=%s\r\n",(configSwissSettings.exiSpeed ? "32MHz":"16MHz")); - string_append(configString, txtbuffer); - sprintf(txtbuffer, "Swiss Video Mode=%s\r\n",(uiVModeStr[configSwissSettings.uiVMode])); - string_append(configString, txtbuffer); - sprintf(txtbuffer, "Enable Debug=%s\r\n",(configSwissSettings.debugUSB ? "Yes":"No")); - string_append(configString, txtbuffer); - sprintf(txtbuffer, "Hide Unknown file types=%s\r\n",(configSwissSettings.hideUnknownFileTypes ? "Yes":"No")); - string_append(configString, txtbuffer); - sprintf(txtbuffer, "Stop DVD Motor on startup=%s\r\n",(configSwissSettings.stopMotor ? "Yes":"No")); + // Write out header every time + char *str = "# Swiss Configuration File!\r\n# Anything written in here will be lost!\r\n\r\n#!!Swiss Settings Start!!\r\n"; + appended_string *configString = string_append(NULL, str); + // Write out Swiss settings + sprintf(txtbuffer, "SD/IDE Speed=%s\r\n",(configSwissSettings.exiSpeed ? "32MHz":"16MHz")); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "Swiss Video Mode=%s\r\n",(uiVModeStr[configSwissSettings.uiVMode])); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "Enable Debug=%s\r\n",(configSwissSettings.debugUSB ? "Yes":"No")); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "Hide Unknown file types=%s\r\n",(configSwissSettings.hideUnknownFileTypes ? "Yes":"No")); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "Stop DVD Motor on startup=%s\r\n",(configSwissSettings.stopMotor ? "Yes":"No")); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "Enable WiiRD debug=%s\r\n",(configSwissSettings.wiirdDebug ? "Yes":"No")); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "Enable File Management=%s\r\n",(configSwissSettings.enableFileManagement ? "Yes":"No")); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "SMBUserName=%s\r\n",configSwissSettings.smbUser); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "SMBPassword=%s\r\n",configSwissSettings.smbPassword); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "SMBShareName=%s\r\n",configSwissSettings.smbShare); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "SMBHostIP=%s\r\n",configSwissSettings.smbServerIp); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "AutoCheats=%s\r\n", (configSwissSettings.autoCheats ? "Yes":"No")); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "IGRType=%s\r\n", (igrTypeStr[swissSettings.igrType])); + string_append(configString, txtbuffer); + sprintf(txtbuffer, "#!!Swiss Settings End!!\r\n\r\n"); + string_append(configString, txtbuffer); + + // Write out Game Configs + int i; + for(i = 0; i < configEntriesCount; i++) { + char buffer[256]; + strnscpy(buffer, &configEntries[i].game_id[0], 4); + sprintf(txtbuffer, "ID=%s\r\n",buffer); string_append(configString, txtbuffer); - sprintf(txtbuffer, "Enable WiiRD debug=%s\r\n",(configSwissSettings.wiirdDebug ? "Yes":"No")); + + strnscpy(buffer, &configEntries[i].game_name[0], 32); + sprintf(txtbuffer, "Name=%s\r\n",buffer); string_append(configString, txtbuffer); - sprintf(txtbuffer, "Enable File Management=%s\r\n",(configSwissSettings.enableFileManagement ? "Yes":"No")); + + strnscpy(buffer, &configEntries[i].comment[0], 128); + sprintf(txtbuffer, "Comment=%s\r\n",buffer); string_append(configString, txtbuffer); - sprintf(txtbuffer, "SMBUserName=%s\r\n",configSwissSettings.smbUser); + + strnscpy(buffer, &configEntries[i].status[0], 32); + sprintf(txtbuffer, "Status=%s\r\n",buffer); string_append(configString, txtbuffer); - sprintf(txtbuffer, "SMBPassword=%s\r\n",configSwissSettings.smbPassword); + + sprintf(txtbuffer, "Force Video Mode=%s\r\n",gameVModeStr[configEntries[i].gameVMode]); string_append(configString, txtbuffer); - sprintf(txtbuffer, "SMBShareName=%s\r\n",configSwissSettings.smbShare); + + sprintf(txtbuffer, "Soft Progressive=%s\r\n",softProgressiveStr[configEntries[i].softProgressive]); string_append(configString, txtbuffer); - sprintf(txtbuffer, "SMBHostIP=%s\r\n",configSwissSettings.smbServerIp); + + sprintf(txtbuffer, "Mute Audio Streaming=%s\r\n",(configEntries[i].muteAudioStreaming ? "Yes":"No")); string_append(configString, txtbuffer); - sprintf(txtbuffer, "AutoCheats=%s\r\n", (configSwissSettings.autoCheats ? "Yes":"No")); + + sprintf(txtbuffer, "Force Widescreen=%s\r\n",forceWidescreenStr[configEntries[i].forceWidescreen]); string_append(configString, txtbuffer); - sprintf(txtbuffer, "IGRType=%s\r\n", (igrTypeStr[swissSettings.igrType])); + + sprintf(txtbuffer, "Force Anisotropy=%s\r\n",(configEntries[i].forceAnisotropy ? "Yes":"No")); string_append(configString, txtbuffer); - sprintf(txtbuffer, "#!!Swiss Settings End!!\r\n\r\n"); + + sprintf(txtbuffer, "Force Encoding=%s\r\n\r\n\r\n",forceEncodingStr[configEntries[i].forceEncoding]); string_append(configString, txtbuffer); - - // Write out Game Configs - int i; - for(i = 0; i < configEntriesCount; i++) { - char buffer[256]; - strnscpy(buffer, &configEntries[i].game_id[0], 4); - sprintf(txtbuffer, "ID=%s\r\n",buffer); - string_append(configString, txtbuffer); - - strnscpy(buffer, &configEntries[i].game_name[0], 32); - sprintf(txtbuffer, "Name=%s\r\n",buffer); - string_append(configString, txtbuffer); - - strnscpy(buffer, &configEntries[i].comment[0], 128); - sprintf(txtbuffer, "Comment=%s\r\n",buffer); - string_append(configString, txtbuffer); - - strnscpy(buffer, &configEntries[i].status[0], 32); - sprintf(txtbuffer, "Status=%s\r\n",buffer); - string_append(configString, txtbuffer); - - sprintf(txtbuffer, "Force Video Mode=%s\r\n",gameVModeStr[configEntries[i].gameVMode]); - string_append(configString, txtbuffer); - - sprintf(txtbuffer, "Soft Progressive=%s\r\n",softProgressiveStr[configEntries[i].softProgressive]); - string_append(configString, txtbuffer); - - sprintf(txtbuffer, "Mute Audio Streaming=%s\r\n",(configEntries[i].muteAudioStreaming ? "Yes":"No")); - string_append(configString, txtbuffer); - - sprintf(txtbuffer, "Force Widescreen=%s\r\n",forceWidescreenStr[configEntries[i].forceWidescreen]); - string_append(configString, txtbuffer); - - sprintf(txtbuffer, "Force Anisotropy=%s\r\n",(configEntries[i].forceAnisotropy ? "Yes":"No")); - string_append(configString, txtbuffer); + } - sprintf(txtbuffer, "Force Encoding=%s\r\n\r\n\r\n",forceEncodingStr[configEntries[i].forceEncoding]); - string_append(configString, txtbuffer); - } + file_handle *configFile = (file_handle*)calloc(1, sizeof(file_handle)); + sprintf(configFile->name, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); - file_handle *configFile = (file_handle*)calloc(1, sizeof(file_handle)); - sprintf(configFile->name, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); + u32 len = strlen(configString->mem); - u32 len = strlen(configString->mem); - if(devices[DEVICE_CONFIG]->writeFile(configFile, configString->mem, len) == len) { - devices[DEVICE_CONFIG]->closeFile(configFile); - return 1; - } - else { - return 0; + if(devices[DEVICE_CONFIG]->writeFile(configFile, configString->mem, len) == len) { + devices[DEVICE_CONFIG]->closeFile(configFile); + if(devices[DEVICE_CONFIG] != devices[DEVICE_CUR]) { + devices[DEVICE_CONFIG]->deinit(devices[DEVICE_CONFIG]->initial); } + return 1; + } + else { + return 0; } + return 1; } diff --git a/cube/swiss/source/devices/deviceHandler.c b/cube/swiss/source/devices/deviceHandler.c index 7bf1a57b..af0056cc 100644 --- a/cube/swiss/source/devices/deviceHandler.c +++ b/cube/swiss/source/devices/deviceHandler.c @@ -73,3 +73,11 @@ int deviceHandler_test(DEVICEHANDLER_INTERFACE *device) { return device->init(device->initial); } +DEVICEHANDLER_INTERFACE* getDeviceByUniqueId(u8 id) { + for(int i = 0; i < MAX_DEVICES; i++) { + if(allDevices[i] != NULL && allDevices[i]->deviceUniqueId == id) { + return allDevices[i]; + } + } + return NULL; +} diff --git a/cube/swiss/source/devices/deviceHandler.h b/cube/swiss/source/devices/deviceHandler.h index 11545ec1..9db50199 100644 --- a/cube/swiss/source/devices/deviceHandler.h +++ b/cube/swiss/source/devices/deviceHandler.h @@ -81,7 +81,25 @@ typedef device_info* (* _fn_deviceInfo)(void); #define LOC_HSP 0x4000 #define LOC_SYSTEM 0x8000 +// Device unique Id (used to store last used config device in SRAM - configDeviceId) +#define DEVICE_ID_0 0x00 +#define DEVICE_ID_1 0x01 +#define DEVICE_ID_2 0x02 +#define DEVICE_ID_3 0x03 +#define DEVICE_ID_4 0x04 +#define DEVICE_ID_5 0x05 +#define DEVICE_ID_6 0x06 +#define DEVICE_ID_7 0x07 +#define DEVICE_ID_8 0x08 +#define DEVICE_ID_9 0x09 +#define DEVICE_ID_A 0x0A +#define DEVICE_ID_B 0x0B +#define DEVICE_ID_C 0x0C +#define DEVICE_ID_MAX DEVICE_ID_C +#define DEVICE_ID_UNK (DEVICE_ID_MAX + 1) + struct DEVICEHANDLER_STRUCT { + u8 deviceUniqueId; const char* deviceName; const char* deviceDescription; textureImage deviceTexture; @@ -132,6 +150,7 @@ extern DEVICEHANDLER_INTERFACE* allDevices[MAX_DEVICES]; extern DEVICEHANDLER_INTERFACE* devices[MAX_DEVICES]; extern int deviceHandler_test(DEVICEHANDLER_INTERFACE *device); +extern DEVICEHANDLER_INTERFACE* getDeviceByUniqueId(u8 id); extern void print_frag_list(int hasDisc2); diff --git a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c index f4308a3a..57d5330e 100644 --- a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c +++ b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c @@ -499,6 +499,7 @@ bool deviceHandler_DVD_test() { } DEVICEHANDLER_INTERFACE __device_dvd = { + DEVICE_ID_0, "DVD", "Supported File System(s): GCM, ISO 9660, Multi-Game", {TEX_GCDVDSMALL, 80, 79}, diff --git a/cube/swiss/source/devices/fat/deviceHandler-FAT.c b/cube/swiss/source/devices/fat/deviceHandler-FAT.c index b25ea722..d76ce993 100644 --- a/cube/swiss/source/devices/fat/deviceHandler-FAT.c +++ b/cube/swiss/source/devices/fat/deviceHandler-FAT.c @@ -449,8 +449,9 @@ bool deviceHandler_FAT_test_ide_b(int slot, bool isSdCard, char *mountPath) { } DEVICEHANDLER_INTERFACE __device_sd_a = { - "SD Card via SD Adapter - Slot A", - "Supported File System(s): FAT16, FAT32", + DEVICE_ID_1, + "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, LOC_MEMCARD_SLOT_A, @@ -469,8 +470,9 @@ DEVICEHANDLER_INTERFACE __device_sd_a = { }; DEVICEHANDLER_INTERFACE __device_sd_b = { - "SD Card via SD Adapter - Slot B", - "Supported File System(s): FAT16, FAT32", + DEVICE_ID_2, + "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, LOC_MEMCARD_SLOT_B, @@ -489,8 +491,9 @@ DEVICEHANDLER_INTERFACE __device_sd_b = { }; DEVICEHANDLER_INTERFACE __device_ide_a = { - "IDE HDD via IDE-EXI - Slot A", - "Supported File System(s): FAT16, FAT32", + DEVICE_ID_3, + "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, LOC_MEMCARD_SLOT_A, @@ -509,8 +512,9 @@ DEVICEHANDLER_INTERFACE __device_ide_a = { }; DEVICEHANDLER_INTERFACE __device_ide_b = { - "IDE HDD via IDE-EXI - Slot B", - "Supported File System(s): FAT16, FAT32", + DEVICE_ID_4, + "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, LOC_MEMCARD_SLOT_B, diff --git a/cube/swiss/source/devices/memcard/deviceHandler-CARD.c b/cube/swiss/source/devices/memcard/deviceHandler-CARD.c index 33fb2b2a..41a5a32c 100644 --- a/cube/swiss/source/devices/memcard/deviceHandler-CARD.c +++ b/cube/swiss/source/devices/memcard/deviceHandler-CARD.c @@ -492,6 +492,7 @@ bool deviceHandler_CARD_test_b() { } DEVICEHANDLER_INTERFACE __device_card_a = { + DEVICE_ID_5, "Memory Card - Slot A", "Backup & Restore save games", {TEX_MEMCARD, 107, 80}, @@ -512,6 +513,7 @@ DEVICEHANDLER_INTERFACE __device_card_a = { }; DEVICEHANDLER_INTERFACE __device_card_b = { + DEVICE_ID_6, "Memory Card - Slot B", "Backup & Restore save games", {TEX_MEMCARD, 107, 80}, diff --git a/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c b/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c index 8d712940..8c3ed3d1 100644 --- a/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c +++ b/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c @@ -120,6 +120,7 @@ bool deviceHandler_Qoob_test() { } DEVICEHANDLER_INTERFACE __device_qoob = { + DEVICE_ID_7, "Qoob Pro", "Qoob Pro Flash File System", {TEX_QOOB, 70, 80}, diff --git a/cube/swiss/source/devices/smb/deviceHandler-SMB.c b/cube/swiss/source/devices/smb/deviceHandler-SMB.c index 373bdf06..bd9f21ca 100644 --- a/cube/swiss/source/devices/smb/deviceHandler-SMB.c +++ b/cube/swiss/source/devices/smb/deviceHandler-SMB.c @@ -220,6 +220,7 @@ bool deviceHandler_SMB_test() { } DEVICEHANDLER_INTERFACE __device_smb = { + DEVICE_ID_8, "Samba via BBA", "Must be pre-configured via swiss.ini", {TEX_SAMBA, 160, 85}, diff --git a/cube/swiss/source/devices/system/deviceHandler-SYS.c b/cube/swiss/source/devices/system/deviceHandler-SYS.c index a39fa43d..164cbbf2 100644 --- a/cube/swiss/source/devices/system/deviceHandler-SYS.c +++ b/cube/swiss/source/devices/system/deviceHandler-SYS.c @@ -295,6 +295,7 @@ bool deviceHandler_SYS_test() { } DEVICEHANDLER_INTERFACE __device_sys = { + DEVICE_ID_9, "System", "Backup IPL, DSP, DVD, SRAM", {TEX_SYSTEM, 160, 85}, diff --git a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c index d7735478..7420c027 100644 --- a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c +++ b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c @@ -164,6 +164,7 @@ bool deviceHandler_USBGecko_test() { } DEVICEHANDLER_INTERFACE __device_usbgecko = { + DEVICE_ID_A, "USB Gecko - Slot B only", "Requires PC application to be up", {TEX_USBGECKO, 129, 80}, diff --git a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c index 543c17f2..c748cde1 100644 --- a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c +++ b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c @@ -239,6 +239,7 @@ bool deviceHandler_WKF_test() { } DEVICEHANDLER_INTERFACE __device_wkf = { + DEVICE_ID_B, "Wiikey / Wasp Fusion", "Supported File System(s): FAT16, FAT32", {TEX_WIIKEY, 102, 80}, diff --git a/cube/swiss/source/devices/wode/deviceHandler-WODE.c b/cube/swiss/source/devices/wode/deviceHandler-WODE.c index 56de9c4a..85240127 100644 --- a/cube/swiss/source/devices/wode/deviceHandler-WODE.c +++ b/cube/swiss/source/devices/wode/deviceHandler-WODE.c @@ -133,6 +133,7 @@ bool deviceHandler_WODE_test() { } DEVICEHANDLER_INTERFACE __device_wode = { + DEVICE_ID_C, "WODE Jukebox", "Supported File System(s): FAT32, NTFS, EXT2/3, HPFS", {TEX_WODEIMG, 146, 72}, diff --git a/cube/swiss/source/gui/settings.c b/cube/swiss/source/gui/settings.c index 98b6291b..64934ddc 100644 --- a/cube/swiss/source/gui/settings.c +++ b/cube/swiss/source/gui/settings.c @@ -22,15 +22,27 @@ char *forceWidescreenStr[] = {"No", "Persp", "Yes"}; char *forceEncodingStr[] = {"Auto", "ANSI", "SJIS"}; char *igrTypeStr[] = {"Disabled", "Reboot", "boot.bin", "USB Flash"}; syssram* sram; +syssramex* sramex; // Number of settings (including Back, Next, Save, Exit buttons) per page -int settings_count_pp[3] = {7, 9, 8}; +int settings_count_pp[3] = {8, 9, 8}; void refreshSRAM() { sram = __SYS_LockSram(); swissSettings.sramStereo = sram->flags & 4; swissSettings.sramLanguage = sram->lang; __SYS_UnlockSram(0); + sramex = __SYS_LockSramEx(); + swissSettings.configDeviceId = sramex->__padding0; + if(swissSettings.configDeviceId > DEVICE_ID_MAX || !(allDevices[swissSettings.configDeviceId]->features & FEAT_WRITE)) { + swissSettings.configDeviceId = DEVICE_ID_UNK; + } + __SYS_UnlockSramEx(0); +} + +char* getConfigDeviceName() { + DEVICEHANDLER_INTERFACE *configDevice = getDeviceByUniqueId(swissSettings.configDeviceId); + return configDevice != NULL ? (configDevice->deviceName) : "None"; } void settings_draw_page(int page_num, int option, file_handle *file) { @@ -42,31 +54,40 @@ void settings_draw_page(int page_num, int option, file_handle *file) { // IPL/Game Language [English/German/French/Spanish/Italian/Dutch] // IPL/Game Audio [Mono/Stereo] // SD/IDE Speed [16/32 MHz] - // Swiss Video Mode [576i (PAL 50Hz), 480i (NTSC 60Hz), 480p (NTSC 60Hz)] - // Stop DVD Motor on startup [Yes/No] + // Swiss Video Mode [576i (PAL 50Hz), 480i (NTSC 60Hz), 480p (NTSC 60Hz), etc] + // In Game Reset [Yes/No] + // Configuration Device [Writable device name] /** Advanced Settings (Page 2/) */ // Enable USB Gecko Debug via Slot B [Yes/No] - // Force No DVD Drive Mode [Yes/No] - // Hide Unknown file types [Yes/No] // TO BE IMPLEMENTED + // Hide Unknown file types [Yes/No] // TODO Implement + // Stop DVD Motor on startup [Yes/No] + // Enable WiiRD debugging in Games [Yes/No] + // Enable File Management [Yes/No] + // Auto-load all cheats [Yes/No] /** Current Game Settings - only if a valid GCM file is highlighted (Page 3/) */ - // Force Video Mode [576i (PAL 50Hz), 480i (NTSC 60Hz), 480p (NTSC 60Hz), Auto] - // Mute Audio Streaming [Yes/No] - // Try to mute audio stutter [Yes/No] + // Force Video Mode [576i (PAL 50Hz), 480i (NTSC 60Hz), 480p (NTSC 60Hz), Auto, etc] + // If Progressive, Soften [No/Yes/Soften] + // Force Widescreen [Yes/No/Persp] + // Force Anistropy [Yes/No] + // Disable Audio Streaming [Yes/No] + // Force Encoding [Auto/SJIS] if(!page_num) { WriteFont(30, 65, "Global Settings (1/3):"); WriteFontStyled(30, 120, "IPL/Game Language:", 1.0f, false, defaultColor); - DrawSelectableButton(400, 120, -1, 150, getSramLang(swissSettings.sramLanguage), option == 0 ? B_SELECTED:B_NOSELECT,-1); + DrawSelectableButton(320, 120, -1, 150, getSramLang(swissSettings.sramLanguage), option == 0 ? B_SELECTED:B_NOSELECT,-1); WriteFontStyled(30, 160, "IPL/Game Audio:", 1.0f, false, defaultColor); - DrawSelectableButton(400, 160, -1, 190, swissSettings.sramStereo ? "Stereo":"Mono", option == 1 ? B_SELECTED:B_NOSELECT,-1); + DrawSelectableButton(320, 160, -1, 190, swissSettings.sramStereo ? "Stereo":"Mono", option == 1 ? B_SELECTED:B_NOSELECT,-1); WriteFontStyled(30, 200, "SD/IDE Speed:", 1.0f, false, defaultColor); - DrawSelectableButton(400, 200, -1, 230, swissSettings.exiSpeed ? "32 MHz":"16 MHz", option == 2 ? B_SELECTED:B_NOSELECT,-1); + DrawSelectableButton(320, 200, -1, 230, swissSettings.exiSpeed ? "32 MHz":"16 MHz", option == 2 ? B_SELECTED:B_NOSELECT,-1); WriteFontStyled(30, 240, "Swiss Video Mode:", 1.0f, false, defaultColor); - DrawSelectableButton(400, 240, -1, 270, uiVModeStr[swissSettings.uiVMode], option == 3 ? B_SELECTED:B_NOSELECT,-1); + DrawSelectableButton(320, 240, -1, 270, uiVModeStr[swissSettings.uiVMode], option == 3 ? B_SELECTED:B_NOSELECT,-1); WriteFontStyled(30, 280, "In-Game-Reset:", 1.0f, false, defaultColor); - DrawSelectableButton(400, 280, -1, 310, igrTypeStr[swissSettings.igrType], option == 4 ? B_SELECTED:B_NOSELECT,-1); + DrawSelectableButton(320, 280, -1, 310, igrTypeStr[swissSettings.igrType], option == 4 ? B_SELECTED:B_NOSELECT,-1); + WriteFontStyled(30, 320, "Config Device:", 1.0f, false, defaultColor); + DrawSelectableButton(320, 320, -1, 350, getConfigDeviceName(), option == 5 ? B_SELECTED:B_NOSELECT,-1); } else if(page_num == 1) { WriteFont(30, 65, "Advanced Settings (2/3):"); @@ -141,6 +162,48 @@ void settings_toggle(int page, int option, int direction, file_handle *file) { if(swissSettings.igrType < 0) swissSettings.igrType = 3; break; + case 5: + { + int curDevicePos = -1; + + // Set it to the first writable device available + if(swissSettings.configDeviceId == DEVICE_ID_UNK) { + for(int i = 0; i < MAX_DEVICES; i++) { + if(allDevices[i] != NULL && (allDevices[i]->features & FEAT_WRITE)) { + swissSettings.configDeviceId = allDevices[i]->deviceUniqueId; + return; + } + } + } + + // get position in allDevices for current save device + for(int i = 0; i < MAX_DEVICES; i++) { + if(allDevices[i] != NULL && allDevices[i]->deviceUniqueId == swissSettings.configDeviceId) { + curDevicePos = i; + break; + } + } + + if(curDevicePos >= 0) { + if(direction > 0) { + curDevicePos = allDevices[curDevicePos+1] == NULL ? 0 : curDevicePos+1; + } + else { + curDevicePos = curDevicePos > 0 ? curDevicePos-1 : 0; + } + // Go to next writable device + while(!(allDevices[curDevicePos] != NULL && allDevices[curDevicePos]->features & FEAT_WRITE)) { + if((curDevicePos == 0 && direction < 0) || allDevices[curDevicePos] == NULL) + curDevicePos = direction > 0 ? 0 : MAX_DEVICES; + else + curDevicePos += direction; + } + if(allDevices[curDevicePos] != NULL) { + swissSettings.configDeviceId = allDevices[curDevicePos]->deviceUniqueId; + } + } + } + break; } } else if(page == 1) { @@ -287,6 +350,9 @@ int show_settings(file_handle *file, ConfigEntry *config) { sram->flags = swissSettings.sramStereo ? (sram->flags|0x04):(sram->flags&~0x04); sram->flags = (swissSettings.sramVideo&0x03)|(sram->flags&~0x03); __SYS_UnlockSram(1); + sramex = __SYS_LockSramEx(); + sramex->__padding0 = swissSettings.configDeviceId; + __SYS_UnlockSramEx(1); while(!__SYS_SyncSram()); // Update our .ini if(config != NULL) { diff --git a/cube/swiss/source/main.c b/cube/swiss/source/main.c index 5c5c03be..ff7360ba 100644 --- a/cube/swiss/source/main.c +++ b/cube/swiss/source/main.c @@ -324,8 +324,10 @@ void main_loop() sdgecko_setSpeed(EXI_SPEED32MHZ); if(!devices[DEVICE_CUR]->init( devices[DEVICE_CUR]->initial )) { needsDeviceChange = 1; + deviceHandler_setDeviceAvailable(devices[DEVICE_CUR], false); return; } + deviceHandler_setDeviceAvailable(devices[DEVICE_CUR], true); // load config from current device or if it's not there, try from devices[DEVICE_CONFIG] load_config(); @@ -333,10 +335,6 @@ void main_loop() else { curMenuLocation=ON_OPTIONS; } - // If a previously undetected device has been successfully init'd, mark it as available from now on - if(!deviceHandler_getDeviceAvailable(devices[DEVICE_CUR])) { - deviceHandler_setDeviceAvailable(devices[DEVICE_CUR], true); - } resume_netinit_thread(); while(1) { @@ -487,19 +485,14 @@ int main () needsDeviceChange = 0; // TODO: re-add if dvd && gcm type disc, show banner/boot screen // If this device can write, set it as the config device for now - if(devices[DEVICE_CUR]->features & FEAT_WRITE) { - devices[DEVICE_CONFIG] = devices[DEVICE_CUR]; - } - } - - // load config if we got a device - if(devices[DEVICE_CONFIG] != NULL) { - load_config(); } // Scan here since some devices would already be initialised (faster) populateDeviceAvailability(); - + + // load config if we got a device + load_config(); + // Start up the BBA if it exists init_network_thread(); init_httpd_thread(); From 905f8f3c78a8887fe4888e51f7acdc764365005d Mon Sep 17 00:00:00 2001 From: emu_kidid Date: Tue, 6 Jun 2017 19:54:22 +0930 Subject: [PATCH 5/8] Implement Wode detect, fix current device image display --- cube/swiss/source/devices/deviceHandler.h | 1 - .../source/devices/dvd/deviceHandler-DVD.c | 1 - .../source/devices/fat/deviceHandler-FAT.c | 2 - .../devices/memcard/deviceHandler-CARD.c | 1 - .../source/devices/qoob/deviceHandler-Qoob.c | 1 - .../source/devices/smb/deviceHandler-SMB.c | 1 - .../source/devices/system/deviceHandler-SYS.c | 1 - .../devices/usbgecko/deviceHandler-usbgecko.c | 1 - .../wiikeyfusion/deviceHandler-wiikeyfusion.c | 1 - .../source/devices/wode/deviceHandler-WODE.c | 6 +-- cube/swiss/source/main.c | 7 +-- cube/swiss/source/swiss.c | 50 +++++++++++-------- 12 files changed, 34 insertions(+), 39 deletions(-) diff --git a/cube/swiss/source/devices/deviceHandler.h b/cube/swiss/source/devices/deviceHandler.h index 9db50199..f6e4d723 100644 --- a/cube/swiss/source/devices/deviceHandler.h +++ b/cube/swiss/source/devices/deviceHandler.h @@ -35,7 +35,6 @@ typedef struct { } file_handle; typedef struct { - int textureId; u32 freeSpaceInKB; // 4TB Max u32 totalSpaceInKB; // 4TB Max } device_info; diff --git a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c index 57d5330e..d4470182 100644 --- a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c +++ b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c @@ -35,7 +35,6 @@ file_handle initial_DVD = }; device_info initial_DVD_info = { - TEX_GCDVDSMALL, 1425760, 1425760 }; diff --git a/cube/swiss/source/devices/fat/deviceHandler-FAT.c b/cube/swiss/source/devices/fat/deviceHandler-FAT.c index d76ce993..4664cf19 100644 --- a/cube/swiss/source/devices/fat/deviceHandler-FAT.c +++ b/cube/swiss/source/devices/fat/deviceHandler-FAT.c @@ -68,7 +68,6 @@ file_handle initial_IDE_B = }; device_info initial_FAT_info = { - 0, 0, 0 }; @@ -382,7 +381,6 @@ s32 deviceHandler_FAT_init(file_handle* file) { } if(ret) readDeviceInfo(file); - initial_FAT_info.textureId = isSDCard ? TEX_SDSMALL:TEX_HDD; return ret; } diff --git a/cube/swiss/source/devices/memcard/deviceHandler-CARD.c b/cube/swiss/source/devices/memcard/deviceHandler-CARD.c index 41a5a32c..bca9822e 100644 --- a/cube/swiss/source/devices/memcard/deviceHandler-CARD.c +++ b/cube/swiss/source/devices/memcard/deviceHandler-CARD.c @@ -36,7 +36,6 @@ file_handle initial_CARDB = }; device_info initial_CARD_info = { - TEX_MEMCARD, 0, 0 }; diff --git a/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c b/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c index 8c3ed3d1..8d900528 100644 --- a/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c +++ b/cube/swiss/source/devices/qoob/deviceHandler-Qoob.c @@ -30,7 +30,6 @@ file_handle initial_Qoob = }; device_info initial_Qoob_info = { - TEX_QOOB, 0, 2048 }; diff --git a/cube/swiss/source/devices/smb/deviceHandler-SMB.c b/cube/swiss/source/devices/smb/deviceHandler-SMB.c index bd9f21ca..6832b77a 100644 --- a/cube/swiss/source/devices/smb/deviceHandler-SMB.c +++ b/cube/swiss/source/devices/smb/deviceHandler-SMB.c @@ -53,7 +53,6 @@ file_handle initial_SMB = }; device_info initial_SMB_info = { - TEX_SAMBA, 0, 0 }; diff --git a/cube/swiss/source/devices/system/deviceHandler-SYS.c b/cube/swiss/source/devices/system/deviceHandler-SYS.c index 164cbbf2..a59b0eae 100644 --- a/cube/swiss/source/devices/system/deviceHandler-SYS.c +++ b/cube/swiss/source/devices/system/deviceHandler-SYS.c @@ -71,7 +71,6 @@ file_handle initial_SYS = device_info initial_SYS_info = { - TEX_SYSTEM, 0, 0 }; diff --git a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c index 7420c027..0c257790 100644 --- a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c +++ b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c @@ -27,7 +27,6 @@ file_handle initial_USBGecko = }; device_info initial_USBGecko_info = { - TEX_USBGECKO, 0, 0 }; diff --git a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c index c748cde1..ae73598c 100644 --- a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c +++ b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c @@ -36,7 +36,6 @@ file_handle initial_WKF = device_info initial_WKF_info = { - TEX_WIIKEY, 0, 0 }; diff --git a/cube/swiss/source/devices/wode/deviceHandler-WODE.c b/cube/swiss/source/devices/wode/deviceHandler-WODE.c index 85240127..daa8b0b4 100644 --- a/cube/swiss/source/devices/wode/deviceHandler-WODE.c +++ b/cube/swiss/source/devices/wode/deviceHandler-WODE.c @@ -13,6 +13,7 @@ #include "gui/FrameBufferMagic.h" #include "gui/IPLFontWrite.h" #include "main.h" +#include "swiss.h" #include "dvd.h" #include "WodeInterface.h" @@ -29,7 +30,6 @@ file_handle initial_WODE = DRV_ERROR }; device_info initial_WODE_info = { - TEX_WODEIMG, 0, 0 }; @@ -129,7 +129,7 @@ s32 deviceHandler_WODE_closeFile(file_handle* file) { } bool deviceHandler_WODE_test() { - return true; + return swissSettings.hasDVDDrive && (*(u32*)&driveVersion[0] == 0x20080714); } DEVICEHANDLER_INTERFACE __device_wode = { @@ -137,7 +137,7 @@ DEVICEHANDLER_INTERFACE __device_wode = { "WODE Jukebox", "Supported File System(s): FAT32, NTFS, EXT2/3, HPFS", {TEX_WODEIMG, 146, 72}, - FEAT_READ|FEAT_BOOT_GCM/*|FEAT_BOOT_DEVICE*/, // TODO re-write init to be silent and re-enable this.; + FEAT_READ|FEAT_BOOT_GCM|FEAT_BOOT_DEVICE, LOC_DVD_CONNECTOR, &initial_WODE, (_fn_test)&deviceHandler_WODE_test, diff --git a/cube/swiss/source/main.c b/cube/swiss/source/main.c index ff7360ba..72382844 100644 --- a/cube/swiss/source/main.c +++ b/cube/swiss/source/main.c @@ -327,10 +327,7 @@ void main_loop() deviceHandler_setDeviceAvailable(devices[DEVICE_CUR], false); return; } - deviceHandler_setDeviceAvailable(devices[DEVICE_CUR], true); - // load config from current device or if it's not there, try from devices[DEVICE_CONFIG] - load_config(); - + deviceHandler_setDeviceAvailable(devices[DEVICE_CUR], true); } else { curMenuLocation=ON_OPTIONS; @@ -490,7 +487,7 @@ int main () // Scan here since some devices would already be initialised (faster) populateDeviceAvailability(); - // load config if we got a device + // load config load_config(); // Start up the BBA if it exists diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index 1cce7140..8e58fe36 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -287,41 +287,49 @@ void drawCurrentDevice() { return; device_info* info = (device_info*)devices[DEVICE_CUR]->info(); - DrawTransparentBox(30, 100, 135, 180); // Device icon + slot box - DrawImage(info->textureId, 50, 95, 64, 64, 0, 0.0f, 1.0f, 0.0f, 1.0f, 0); + DrawTransparentBox(30, 100, 135, 200); // Device icon + slot box + // Draw the device image + float scale = 80.0f / (float)MAX(devices[DEVICE_CUR]->deviceTexture.width, devices[DEVICE_CUR]->deviceTexture.height); + int scaledWidth = devices[DEVICE_CUR]->deviceTexture.width*scale; + int scaledHeight = devices[DEVICE_CUR]->deviceTexture.height*scale; + DrawImage(devices[DEVICE_CUR]->deviceTexture.textureId + , 30 + ((135-30) / 2) - (scaledWidth/2), 95 + ((200-100) /2) - (scaledHeight/2) // center x,y + , scaledWidth, scaledHeight, // scaled image + 0, 0.0f, 1.0f, 0.0f, 1.0f, 0); if(devices[DEVICE_CUR]->location == LOC_MEMCARD_SLOT_A) - WriteFontStyled(50, 160, "Slot A", 0.65f, false, defaultColor); - if(devices[DEVICE_CUR]->location == LOC_MEMCARD_SLOT_B) - WriteFontStyled(50, 160, "Slot B", 0.65f, false, defaultColor); - if(devices[DEVICE_CUR]->location == LOC_DVD_CONNECTOR) - WriteFontStyled(50, 160, "DVD Device", 0.65f, false, defaultColor); - if(devices[DEVICE_CUR]->location == LOC_SERIAL_PORT_1) - WriteFontStyled(50, 160, "Serial Port 1", 0.65f, false, defaultColor); - if(devices[DEVICE_CUR]->location == LOC_SERIAL_PORT_2) - WriteFontStyled(50, 160, "Serial Port 2", 0.65f, false, defaultColor); - if(devices[DEVICE_CUR]->location == LOC_SYSTEM) - WriteFontStyled(50, 160, "System", 0.65f, false, defaultColor); - - DrawTransparentBox(30, 200, 135, 305); // Device size/extra info box - WriteFontStyled(30, 200, "Total:", 0.6f, false, defaultColor); + sprintf(txtbuffer, "%s", "Slot A"); + else if(devices[DEVICE_CUR]->location == LOC_MEMCARD_SLOT_B) + sprintf(txtbuffer, "%s", "Slot B"); + else if(devices[DEVICE_CUR]->location == LOC_DVD_CONNECTOR) + sprintf(txtbuffer, "%s", "DVD Device"); + else if(devices[DEVICE_CUR]->location == LOC_SERIAL_PORT_1) + sprintf(txtbuffer, "%s", "Serial Port 1"); + else if(devices[DEVICE_CUR]->location == LOC_SERIAL_PORT_2) + sprintf(txtbuffer, "%s", "Serial Port 2"); + else if(devices[DEVICE_CUR]->location == LOC_SYSTEM) + sprintf(txtbuffer, "%s", "System"); + + WriteFontStyled(30 + ((135-30) / 2), 190, txtbuffer, 0.65f, true, defaultColor); + DrawTransparentBox(30, 220, 135, 325); // Device size/extra info box + WriteFontStyled(30, 220, "Total:", 0.6f, false, defaultColor); if(info->totalSpaceInKB < 1024) // < 1 MB sprintf(txtbuffer,"%ldKB", info->totalSpaceInKB); if(info->totalSpaceInKB < 1024*1024) // < 1 GB sprintf(txtbuffer,"%.2fMB", (float)info->totalSpaceInKB/1024); else sprintf(txtbuffer,"%.2fGB", (float)info->totalSpaceInKB/(1024*1024)); - WriteFontStyled(60, 215, txtbuffer, 0.6f, false, defaultColor); + WriteFontStyled(60, 235, txtbuffer, 0.6f, false, defaultColor); - WriteFontStyled(30, 235, "Free:", 0.6f, false, defaultColor); + WriteFontStyled(30, 255, "Free:", 0.6f, false, defaultColor); if(info->freeSpaceInKB < 1024) // < 1 MB sprintf(txtbuffer,"%ldKB", info->freeSpaceInKB); if(info->freeSpaceInKB < 1024*1024) // < 1 GB sprintf(txtbuffer,"%.2fMB", (float)info->freeSpaceInKB/1024); else sprintf(txtbuffer,"%.2fGB", (float)info->freeSpaceInKB/(1024*1024)); - WriteFontStyled(60, 250, txtbuffer, 0.6f, false, defaultColor); + WriteFontStyled(60, 270, txtbuffer, 0.6f, false, defaultColor); - WriteFontStyled(30, 270, "Used:", 0.6f, false, defaultColor); + WriteFontStyled(30, 290, "Used:", 0.6f, false, defaultColor); u32 usedSpaceInKB = (info->totalSpaceInKB)-(info->freeSpaceInKB); if(usedSpaceInKB < 1024) // < 1 MB sprintf(txtbuffer,"%ldKB", usedSpaceInKB); @@ -329,7 +337,7 @@ void drawCurrentDevice() { sprintf(txtbuffer,"%.2fMB", (float)usedSpaceInKB/1024); else sprintf(txtbuffer,"%.2fGB", (float)usedSpaceInKB/(1024*1024)); - WriteFontStyled(60, 285, txtbuffer, 0.6f, false, defaultColor); + WriteFontStyled(60, 305, txtbuffer, 0.6f, false, defaultColor); } // Draws all the files in the current dir. From 2adb9d0c3ec02a43510780ee03b538f37c19e1e7 Mon Sep 17 00:00:00 2001 From: emu_kidid Date: Tue, 6 Jun 2017 23:15:14 +0930 Subject: [PATCH 6/8] - Fix USBGecko PC server --- cube/swiss/source/devices/deviceHandler.h | 6 +++--- .../devices/usbgecko/deviceHandler-usbgecko.c | 18 +++++++++--------- cube/swiss/source/devices/usbgecko/usbgecko.c | 14 +++++++------- cube/swiss/source/devices/usbgecko/usbgecko.h | 10 +++++----- cube/swiss/source/gui/settings.c | 2 +- cube/swiss/source/swiss.c | 15 ++++++++------- pc/usbgecko/Makefile | 4 ++-- pc/usbgecko/main.c | 14 ++++++++------ 8 files changed, 43 insertions(+), 40 deletions(-) diff --git a/cube/swiss/source/devices/deviceHandler.h b/cube/swiss/source/devices/deviceHandler.h index f6e4d723..78139fc9 100644 --- a/cube/swiss/source/devices/deviceHandler.h +++ b/cube/swiss/source/devices/deviceHandler.h @@ -27,12 +27,12 @@ typedef struct { uint64_t fileBase; // Raw sector on device u32 offset; // Offset in the file u32 size; // size of the file - int fileAttrib; // IS_FILE or IS_DIR - int status; // is the device ok + s32 fileAttrib; // IS_FILE or IS_DIR + s32 status; // is the device ok FILE *fp; // file pointer file_meta *meta; u8 other[128]; // Store anything else we want here -} file_handle; +} file_handle; // Note: If the contents of this change, recompile pc/usbgecko/main.c typedef struct { u32 freeSpaceInKB; // 4TB Max diff --git a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c index 0c257790..0ef86fea 100644 --- a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c +++ b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c @@ -40,7 +40,7 @@ device_info* deviceHandler_USBGecko_info() { s32 deviceHandler_USBGecko_readDir(file_handle* ffile, file_handle** dir, u32 type){ // Set everything up to read - int num_entries = 0, i = 0; + s32 num_entries = 0, i = 0; file_handle *entry = NULL; if(strlen(ffile->name)!=1) { i = num_entries = 1; @@ -54,7 +54,7 @@ s32 deviceHandler_USBGecko_readDir(file_handle* ffile, file_handle** dir, u32 ty DrawMessageBox(D_INFO,"Read directory!"); DrawFrameFinish(); // Read each entry of the directory - int res = usbgecko_open_dir(&ffile->name[0]); + s32 res = usbgecko_open_dir(&ffile->name[0]); if(!res) return -1; while( (entry = usbgecko_get_entry()) != NULL ){ // Make sure we have room for this one @@ -79,21 +79,21 @@ s32 deviceHandler_USBGecko_seekFile(file_handle* file, s32 where, s32 type){ } s32 deviceHandler_USBGecko_readFile(file_handle* file, void* buffer, u32 length){ - int reallength = length; + s32 reallength = length; if(file->offset + length > file->size) { reallength = file->size - file->offset; } if(reallength < 0) { return 0; } - int bytes_read = usbgecko_read_file(buffer, reallength, file->offset, file->name); + s32 bytes_read = usbgecko_read_file(buffer, reallength, file->offset, file->name); if(bytes_read > 0) file->offset += bytes_read; return bytes_read; } s32 deviceHandler_USBGecko_writeFile(file_handle* file, void* buffer, u32 length) { - int bytes_written = usbgecko_write_file(buffer, length, file->offset, file->name); + s32 bytes_written = usbgecko_write_file(buffer, length, file->offset, file->name); if(bytes_written > 0) file->offset += bytes_written; return bytes_written; @@ -103,9 +103,9 @@ s32 deviceHandler_USBGecko_setupFile(file_handle* file, file_handle* file2) { u32 *fragList = (u32*)VAR_FRAG_LIST; memset((void*)VAR_FRAG_LIST, 0, VAR_FRAG_SIZE); fragList[1] = file->size; - *(volatile unsigned int*)VAR_DISC_1_LBA = 0; - *(volatile unsigned int*)VAR_DISC_2_LBA = 0; - *(volatile unsigned int*)VAR_CUR_DISC_LBA = 0; + *(volatile u32*)VAR_DISC_1_LBA = 0; + *(volatile u32*)VAR_DISC_2_LBA = 0; + *(volatile u32*)VAR_CUR_DISC_LBA = 0; return 1; } @@ -114,7 +114,7 @@ s32 deviceHandler_USBGecko_init(file_handle* file) { DrawMessageBox(D_INFO,"Looking for USBGecko in Slot B"); DrawFrameFinish(); if(usb_isgeckoalive(1)) { - int retries = 1000; + s32 retries = 1000; DrawFrameStart(); DrawMessageBox(D_INFO,"Waiting for PC ..."); diff --git a/cube/swiss/source/devices/usbgecko/usbgecko.c b/cube/swiss/source/devices/usbgecko/usbgecko.c index f9b54229..48583470 100644 --- a/cube/swiss/source/devices/usbgecko/usbgecko.c +++ b/cube/swiss/source/devices/usbgecko/usbgecko.c @@ -34,8 +34,8 @@ file_handle filehndl; char served_file[1024]; // The file we're currently being served by the PC typedef struct { - unsigned int offset; // Offset in the file - unsigned int size; // size to read + u32 offset; // Offset in the file + u32 size; // size to read } usb_data_req; static inline u32 bswap32(u32 val) { @@ -51,7 +51,7 @@ u8 *get_buffer() { } // Returns 1 if the PC side is ready, 0 otherwise -int usbgecko_pc_ready() { +s32 usbgecko_pc_ready() { // Ask PC, are you ready? usb_sendbuffer_safe(1, &ASK_READY, 1); @@ -63,7 +63,7 @@ int usbgecko_pc_ready() { return 0; } -void usbgecko_lock_file(int lock) { +void usbgecko_lock_file(s32 lock) { if(!lock) { // Send a zero byte read to end locked mode usb_data_req req; @@ -101,7 +101,7 @@ void usbgecko_served_file(char *filename) { } // Read from the remote file, returns amount read -int usbgecko_read_file(void *buffer, u32 length, u32 offset, char* filename) { +s32 usbgecko_read_file(void *buffer, u32 length, u32 offset, char* filename) { if(!length) return 0; usbgecko_served_file(filename); @@ -114,12 +114,12 @@ int usbgecko_read_file(void *buffer, u32 length, u32 offset, char* filename) { } // Write to the remote file, returns amount written -int usbgecko_write_file(void *buffer, u32 length, u32 offset, char* filename) { +s32 usbgecko_write_file(void *buffer, u32 length, u32 offset, char* filename) { return 0; } // Opens a directory on the PC end -int usbgecko_open_dir(char *filename) { +s32 usbgecko_open_dir(char *filename) { usbgecko_lock_file(0); // Tell PC, I'm ready to send a path name usb_sendbuffer_safe(1, &ASK_OPENPATH, 1); diff --git a/cube/swiss/source/devices/usbgecko/usbgecko.h b/cube/swiss/source/devices/usbgecko/usbgecko.h index 31b94e38..a57da696 100644 --- a/cube/swiss/source/devices/usbgecko/usbgecko.h +++ b/cube/swiss/source/devices/usbgecko/usbgecko.h @@ -17,21 +17,21 @@ res; }) // Returns 1 if the PC side is ready, 0 otherwise -int usbgecko_pc_ready(); +s32 usbgecko_pc_ready(); // Read from the remote file, returns amount read -int usbgecko_read_file(void *buffer, u32 length, u32 offset, char* filename); +s32 usbgecko_read_file(void *buffer, u32 length, u32 offset, char* filename); // Write to the remote file, returns amount written -int usbgecko_write_file(void *buffer, u32 length, u32 offset, char* filename); +s32 usbgecko_write_file(void *buffer, u32 length, u32 offset, char* filename); // Opens a directory on the PC end -int usbgecko_open_dir(char *filename); +s32 usbgecko_open_dir(char *filename); // Returns the next file in the directory opened with usbgecko_open_dir, NULL on end. file_handle* usbgecko_get_entry(); -void usbgecko_lock_file(int lock); +void usbgecko_lock_file(s32 lock); #endif diff --git a/cube/swiss/source/gui/settings.c b/cube/swiss/source/gui/settings.c index 64934ddc..3cf9d76d 100644 --- a/cube/swiss/source/gui/settings.c +++ b/cube/swiss/source/gui/settings.c @@ -42,7 +42,7 @@ void refreshSRAM() { char* getConfigDeviceName() { DEVICEHANDLER_INTERFACE *configDevice = getDeviceByUniqueId(swissSettings.configDeviceId); - return configDevice != NULL ? (configDevice->deviceName) : "None"; + return configDevice != NULL ? (char*)(configDevice->deviceName) : "None"; } void settings_draw_page(int page_num, int option, file_handle *file) { diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index 8e58fe36..d191cbcd 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -309,7 +309,7 @@ void drawCurrentDevice() { else if(devices[DEVICE_CUR]->location == LOC_SYSTEM) sprintf(txtbuffer, "%s", "System"); - WriteFontStyled(30 + ((135-30) / 2), 190, txtbuffer, 0.65f, true, defaultColor); + WriteFontStyled(30 + ((135-30) / 2), 195, txtbuffer, 0.65f, true, defaultColor); DrawTransparentBox(30, 220, 135, 325); // Device size/extra info box WriteFontStyled(30, 220, "Total:", 0.6f, false, defaultColor); if(info->totalSpaceInKB < 1024) // < 1 MB @@ -1444,7 +1444,7 @@ void draw_game_info() { WriteFontStyled(640/2, 220, (GCMDisk.DiscID ? "Disc 2":""), 0.8f, true, defaultColor); } - WriteFontStyled(640/2, 370, "Settings (X) - Cheats (Y) - Exit (B) - Continue (A)", 0.75f, true, defaultColor); + WriteFontStyled(640/2, 370, "Settings (X) - Cheats (Y) - Exit (B) - Boot (A)", 0.75f, true, defaultColor); DrawFrameFinish(); } @@ -1481,8 +1481,9 @@ int info_game() // Look for a cheats file based on the GameID if(PAD_ButtonsHeld(0) & PAD_BUTTON_Y) { int num_cheats = findCheats(false); - if(num_cheats == 0) return 0; - DrawCheatsSelector(getRelativeName(allFiles[curSelection].name)); + if(num_cheats != 0) { + DrawCheatsSelector(getRelativeName(allFiles[curSelection].name)); + } } while(PAD_ButtonsHeld(0) & PAD_BUTTON_A){ VIDEO_WaitVSync (); } } @@ -1519,12 +1520,12 @@ void select_device(int type) doBackdrop(); DrawEmptyBox(20,190, vmode->fbWidth-20, 410, COLOR_BLACK); - WriteFontStyled(640/2, 195, "Device Selection", 1.0f, true, defaultColor); // TODO change based on type + WriteFontStyled(640/2, 195, type == DEVICE_DEST ? "Destination Device" : "Device Selection", 1.0f, true, defaultColor); textureImage *deviceImage = &allDevices[curDevice]->deviceTexture; DrawImage(deviceImage->textureId, 640/2, 230, deviceImage->width, deviceImage->height, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1); - WriteFontStyled(640/2, 330, allDevices[curDevice]->deviceName, 0.85f, true, defaultColor); - WriteFontStyled(640/2, 350, allDevices[curDevice]->deviceDescription, 0.65f, true, defaultColor); + WriteFontStyled(640/2, 330, (char*)allDevices[curDevice]->deviceName, 0.85f, true, defaultColor); + WriteFontStyled(640/2, 350, (char*)allDevices[curDevice]->deviceDescription, 0.65f, true, defaultColor); // Memory card port devices, allow for speed selection if(allDevices[curDevice]->location & (LOC_MEMCARD_SLOT_A | LOC_MEMCARD_SLOT_B)) { diff --git a/pc/usbgecko/Makefile b/pc/usbgecko/Makefile index b151a3ce..eef88bbb 100644 --- a/pc/usbgecko/Makefile +++ b/pc/usbgecko/Makefile @@ -1,6 +1,6 @@ ifeq ($(OS),Windows_NT) -CC = -WIN-CC= mingw32-gcc +CC = i686-w64-mingw32-gcc +WIN-CC= i686-w64-mingw32-gcc else CC = gcc WIN-CC= i586-mingw32msvc-gcc diff --git a/pc/usbgecko/main.c b/pc/usbgecko/main.c index 9e39f053..2ca0d9fe 100644 --- a/pc/usbgecko/main.c +++ b/pc/usbgecko/main.c @@ -41,16 +41,18 @@ typedef struct { char name[1024]; // File or Folder, absolute path goes here uint64_t fileBase; // Raw sector on device - unsigned int offset; // Offset in the file - unsigned int size; // size of the file - int fileAttrib; // IS_FILE or IS_DIR - int status; // is the device ok + uint32_t offset; // Offset in the file + uint32_t size; // size of the file + int32_t fileAttrib; // IS_FILE or IS_DIR + int32_t status; // is the device ok FILE *fp; // file pointer + int32_t metaptr; // not used in usbgecko server side + uint8_t other[128]; // not used in usbgecko server side } file_handle; typedef struct { - unsigned int offset; // Offset in the file - unsigned int size; // size to read + uint32_t offset; // Offset in the file + uint32_t size; // size to read } usb_data_req; FILE *served_file_fp; From 430e48a13a87d2555d135e13be20134a9a7333ae Mon Sep 17 00:00:00 2001 From: emu_kidid Date: Wed, 7 Jun 2017 18:55:19 +0930 Subject: [PATCH 7/8] Fix config device check, init default device so config can be loaded from it. --- cube/swiss/source/config/config.c | 3 ++- cube/swiss/source/gui/settings.c | 3 ++- cube/swiss/source/main.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cube/swiss/source/config/config.c b/cube/swiss/source/config/config.c index a22a0fdc..d2e07649 100644 --- a/cube/swiss/source/config/config.c +++ b/cube/swiss/source/config/config.c @@ -124,6 +124,7 @@ int config_init() { char *configData = (char*) memalign(32, configFile->size); configEntriesCount = 0; if (configData) { + print_gecko("Config Size %i\r\n", configFile->size); memset(configData, 0, configFile->size); devices[DEVICE_CONFIG]->readFile(configFile, configData, configFile->size); devices[DEVICE_CONFIG]->closeFile(configFile); @@ -217,7 +218,7 @@ int config_update_file() { sprintf(configFile->name, "%sswiss.ini", devices[DEVICE_CONFIG]->initial->name); u32 len = strlen(configString->mem); - + // TODO ask overwrite? if(devices[DEVICE_CONFIG]->writeFile(configFile, configString->mem, len) == len) { devices[DEVICE_CONFIG]->closeFile(configFile); if(devices[DEVICE_CONFIG] != devices[DEVICE_CUR]) { diff --git a/cube/swiss/source/gui/settings.c b/cube/swiss/source/gui/settings.c index 3cf9d76d..790eff19 100644 --- a/cube/swiss/source/gui/settings.c +++ b/cube/swiss/source/gui/settings.c @@ -34,7 +34,7 @@ void refreshSRAM() { __SYS_UnlockSram(0); sramex = __SYS_LockSramEx(); swissSettings.configDeviceId = sramex->__padding0; - if(swissSettings.configDeviceId > DEVICE_ID_MAX || !(allDevices[swissSettings.configDeviceId]->features & FEAT_WRITE)) { + if(swissSettings.configDeviceId > DEVICE_ID_MAX || !(getDeviceByUniqueId(swissSettings.configDeviceId)->features & FEAT_WRITE)) { swissSettings.configDeviceId = DEVICE_ID_UNK; } __SYS_UnlockSramEx(0); @@ -350,6 +350,7 @@ int show_settings(file_handle *file, ConfigEntry *config) { sram->flags = swissSettings.sramStereo ? (sram->flags|0x04):(sram->flags&~0x04); sram->flags = (swissSettings.sramVideo&0x03)|(sram->flags&~0x03); __SYS_UnlockSram(1); + while(!__SYS_SyncSram()); sramex = __SYS_LockSramEx(); sramex->__padding0 = swissSettings.configDeviceId; __SYS_UnlockSramEx(1); diff --git a/cube/swiss/source/main.c b/cube/swiss/source/main.c index 72382844..57a9d67b 100644 --- a/cube/swiss/source/main.c +++ b/cube/swiss/source/main.c @@ -475,6 +475,7 @@ int main () } if(devices[DEVICE_CUR] != NULL) { print_gecko("Detected %s\r\n", devices[DEVICE_CUR]->deviceName); + devices[DEVICE_CUR]->init(devices[DEVICE_CUR]->initial); if(devices[DEVICE_CUR]->features & FEAT_AUTOLOAD_DOL) { load_auto_dol(); } From e37224587a4093e56149d64bb966339a157283d1 Mon Sep 17 00:00:00 2001 From: emu_kidid Date: Sat, 10 Jun 2017 20:03:26 +0930 Subject: [PATCH 8/8] - Bug fixing -- 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 --- cube/patches/base/dvdinterface.c | 6 +- cube/swiss/source/config/config.c | 4 +- cube/swiss/source/devices/deviceHandler.h | 27 +-- .../source/devices/dvd/deviceHandler-DVD.c | 25 ++- .../source/devices/fat/deviceHandler-FAT.c | 16 +- .../wiikeyfusion/deviceHandler-wiikeyfusion.c | 2 +- cube/swiss/source/gcm.c | 26 ++- cube/swiss/source/patcher.c | 1 - cube/swiss/source/swiss.c | 176 +++++++++--------- 9 files changed, 147 insertions(+), 136 deletions(-) diff --git a/cube/patches/base/dvdinterface.c b/cube/patches/base/dvdinterface.c index 8355a31a..b031010d 100644 --- a/cube/patches/base/dvdinterface.c +++ b/cube/patches/base/dvdinterface.c @@ -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(); + } } } diff --git a/cube/swiss/source/config/config.c b/cube/swiss/source/config/config.c index d2e07649..2f497959 100644 --- a/cube/swiss/source/config/config.c +++ b/cube/swiss/source/config/config.c @@ -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; } diff --git a/cube/swiss/source/devices/deviceHandler.h b/cube/swiss/source/devices/deviceHandler.h index 78139fc9..85ca7cd5 100644 --- a/cube/swiss/source/devices/deviceHandler.h +++ b/cube/swiss/source/devices/deviceHandler.h @@ -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 diff --git a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c index d4470182..c88f0e0b 100644 --- a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c +++ b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c @@ -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; @@ -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); @@ -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; } @@ -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, diff --git a/cube/swiss/source/devices/fat/deviceHandler-FAT.c b/cube/swiss/source/devices/fat/deviceHandler-FAT.c index 4664cf19..c9719628 100644 --- a/cube/swiss/source/devices/fat/deviceHandler-FAT.c +++ b/cube/swiss/source/devices/fat/deviceHandler-FAT.c @@ -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++) { @@ -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)) { @@ -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; } @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c index ae73598c..76356c7d 100644 --- a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c +++ b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c @@ -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, diff --git a/cube/swiss/source/gcm.c b/cube/swiss/source/gcm.c index 95d191b2..3eb7cb6d 100644 --- a/cube/swiss/source/gcm.c +++ b/cube/swiss/source/gcm.c @@ -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) { @@ -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.. @@ -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(); @@ -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); diff --git a/cube/swiss/source/patcher.c b/cube/swiss/source/patcher.c index 3fcf9366..fb09ab49 100644 --- a/cube/swiss/source/patcher.c +++ b/cube/swiss/source/patcher.c @@ -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}; diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index d191cbcd..2efc725a 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -679,7 +679,7 @@ unsigned int load_app(int multiDol) } // Don't spin down the drive when running something from it... - if(devices[DEVICE_CUR] == &__device_dvd) { + if(devices[DEVICE_CUR] != &__device_dvd) { devices[DEVICE_CUR]->deinit(&curFile); } @@ -912,6 +912,8 @@ void manage_file() { u32 ret = 0; // Show a list of destination devices (the same device is also a possibility) select_device(DEVICE_DEST); + if(devices[DEVICE_DEST] == NULL) return; + // If the devices are not the same, init the destination, fail on non-existing device/etc if(devices[DEVICE_CUR] != devices[DEVICE_DEST]) { devices[DEVICE_DEST]->deinit( devices[DEVICE_DEST]->initial ); @@ -1223,7 +1225,7 @@ void load_game() { int multiDol = 0; // Report to the user the patch status of this GCM/ISO file - if(devices[DEVICE_CUR]->features & FEAT_REPLACES_DVD_FUNCS) { + if(devices[DEVICE_CUR]->features & FEAT_CAN_READ_PATCHES) { multiDol = check_game(); } @@ -1276,78 +1278,75 @@ void load_file() { char *fileName = &curFile.name[0]; - // If it's not a DVD Disc, or it's a DVD disc with some file structure, browse by file type - if((devices[DEVICE_CUR] != &__device_dvd) - || (devices[DEVICE_CUR] == &__device_dvd && dvdDiscTypeInt==ISO9660_DISC)) { - //if it's a DOL, boot it - if(strlen(fileName)>4) { - if(endsWith(fileName,".dol")) { - boot_dol(); - // if it was invalid (overlaps sections, too large, etc..) it'll return + //if it's a DOL, boot it + if(strlen(fileName)>4) { + if(endsWith(fileName,".dol")) { + boot_dol(); + // if it was invalid (overlaps sections, too large, etc..) it'll return + DrawFrameStart(); + DrawMessageBox(D_WARN, "Invalid DOL"); + DrawFrameFinish(); + sleep(2); + return; + } + if(endsWith(fileName,".mp3")) { + mp3_player(allFiles, files, &curFile); + return; + } + if(endsWith(fileName,".fzn")) { + if(curFile.size != 0x1D0000) { DrawFrameStart(); - DrawMessageBox(D_WARN, "Invalid DOL"); + DrawMessageBox(D_WARN, "File Size must be 0x1D0000 bytes!"); DrawFrameFinish(); sleep(2); return; } - if(endsWith(fileName,".mp3")) { - mp3_player(allFiles, files, &curFile); - return; + DrawFrameStart(); + DrawMessageBox(D_INFO, "Reading Flash File ..."); + DrawFrameFinish(); + u8 *flash = (u8*)memalign(32,0x1D0000); + devices[DEVICE_CUR]->seekFile(&curFile,0,DEVICE_HANDLER_SEEK_SET); + devices[DEVICE_CUR]->readFile(&curFile,flash,0x1D0000); + // Try to read a .fw file too. + file_handle fwFile; + memset(&fwFile, 0, sizeof(file_handle)); + sprintf(&fwFile.name[0],"%s.fw", &curFile.name[0]); + u8 *firmware = (u8*)memalign(32, 0x3000); + DrawFrameStart(); + if(devices[DEVICE_CUR] == &__device_dvd || devices[DEVICE_CUR]->readFile(&fwFile,firmware,0x3000) != 0x3000) { + free(firmware); firmware = NULL; + DrawMessageBox(D_WARN, "Didn't find a firmware file, flashing menu only."); } - if(endsWith(fileName,".fzn")) { - if(curFile.size != 0x1D0000) { - DrawFrameStart(); - DrawMessageBox(D_WARN, "File Size must be 0x1D0000 bytes!"); - DrawFrameFinish(); - sleep(2); - return; - } - DrawFrameStart(); - DrawMessageBox(D_INFO, "Reading Flash File ..."); - DrawFrameFinish(); - u8 *flash = (u8*)memalign(32,0x1D0000); - devices[DEVICE_CUR]->seekFile(&curFile,0,DEVICE_HANDLER_SEEK_SET); - devices[DEVICE_CUR]->readFile(&curFile,flash,0x1D0000); - // Try to read a .fw file too. - file_handle fwFile; - memset(&fwFile, 0, sizeof(file_handle)); - sprintf(&fwFile.name[0],"%s.fw", &curFile.name[0]); - u8 *firmware = (u8*)memalign(32, 0x3000); - DrawFrameStart(); - if(devices[DEVICE_CUR] == &__device_dvd || devices[DEVICE_CUR]->readFile(&fwFile,firmware,0x3000) != 0x3000) { - free(firmware); firmware = NULL; - DrawMessageBox(D_WARN, "Didn't find a firmware file, flashing menu only."); - } - else { - DrawMessageBox(D_INFO, "Found firmware file, this will be flashed too."); - } - DrawFrameFinish(); - sleep(1); - wkfWriteFlash(flash, firmware); + else { + DrawMessageBox(D_INFO, "Found firmware file, this will be flashed too."); + } + DrawFrameFinish(); + sleep(1); + wkfWriteFlash(flash, firmware); + DrawFrameStart(); + DrawMessageBox(D_INFO, "Flashing Complete !!"); + DrawFrameFinish(); + sleep(2); + return; + } + if(endsWith(fileName,".iso") || endsWith(fileName,".gcm")) { + if(devices[DEVICE_CUR]->features & FEAT_BOOT_GCM) + load_game(); + else { DrawFrameStart(); - DrawMessageBox(D_INFO, "Flashing Complete !!"); + DrawMessageBox(D_WARN, "This device does not support booting of images."); DrawFrameFinish(); sleep(2); - return; - } - if(endsWith(fileName,".iso") || endsWith(fileName,".gcm")) { - if(devices[DEVICE_CUR]->features & FEAT_BOOT_GCM) - load_game(); - else { - DrawFrameStart(); - DrawMessageBox(D_WARN, "This device does not support booting of images."); - DrawFrameFinish(); - sleep(2); - } - return; } - DrawFrameStart(); - DrawMessageBox(D_WARN, "Unknown File Type\nEnable file management to manage this file."); - DrawFrameFinish(); - sleep(1); - return; + return; } + DrawFrameStart(); + DrawMessageBox(D_WARN, "Unknown File Type\nEnable file management to manage this file."); + DrawFrameFinish(); + sleep(1); + return; } + } int check_game() @@ -1494,6 +1493,8 @@ int info_game() void select_device(int type) { + u32 requiredFeatures = (type == DEVICE_DEST) ? FEAT_WRITE:FEAT_READ; + if(is_httpd_in_use()) { doBackdrop(); DrawMessageBox(D_INFO,"Can't load device while HTTP is processing!"); @@ -1504,18 +1505,23 @@ void select_device(int type) int curDevice = 0; int inAdvanced = 0, showAllDevices = 0; - + int direction = 1; + while(1) { - // Go to the first device available - if(!showAllDevices && !deviceHandler_getDeviceAvailable(allDevices[curDevice])) { - int i = 0; - while(allDevices[i] != NULL) { - if(deviceHandler_getDeviceAvailable(allDevices[i])) { - curDevice = i; - break; - } - i++; + // Go to the first device available if we're not showing all devices + int i = curDevice; + i+= direction; + + if(i < 0) i = MAX_DEVICES; + else if (i > MAX_DEVICES) i = 0; + while(1) { + if(allDevices[i] != NULL && (deviceHandler_getDeviceAvailable(allDevices[i])||showAllDevices) && (allDevices[i]->features & requiredFeatures)) { + curDevice = i; + break; } + i+=direction; + if(i < 0) i = MAX_DEVICES; + else if (i > MAX_DEVICES) i = 0; } doBackdrop(); @@ -1547,8 +1553,10 @@ void select_device(int type) u16 btns = PAD_ButtonsHeld(0); if((btns & PAD_BUTTON_X) && (allDevices[curDevice]->location & (LOC_MEMCARD_SLOT_A | LOC_MEMCARD_SLOT_B))) inAdvanced ^= 1; - if(btns & PAD_TRIGGER_Z) + if(btns & PAD_TRIGGER_Z) { showAllDevices ^= 1; + direction = 0; + } if(inAdvanced) { if((btns & PAD_BUTTON_RIGHT) || (btns & PAD_BUTTON_LEFT)) { swissSettings.exiSpeed^=1; @@ -1556,27 +1564,10 @@ void select_device(int type) } else { if(btns & PAD_BUTTON_RIGHT) { - if(allDevices[curDevice+1] == NULL) - curDevice = 0; - else - curDevice++; - // Go to the next available device - while(!showAllDevices && !deviceHandler_getDeviceAvailable(allDevices[curDevice])) { - if(allDevices[curDevice] == NULL) - curDevice = 0; - else - curDevice ++; - } + direction = 1; } if(btns & PAD_BUTTON_LEFT) { - curDevice = curDevice > 0 ? curDevice-1 : 0; - // Go to the next available device - while(!showAllDevices && (allDevices[curDevice] == NULL || !deviceHandler_getDeviceAvailable(allDevices[curDevice]))) { - if(curDevice == 0) - curDevice = MAX_DEVICES; - else - curDevice --; - } + direction = -1; } } if(btns & PAD_BUTTON_A) { @@ -1596,6 +1587,7 @@ void select_device(int type) inAdvanced = 0; } if(btns & PAD_BUTTON_B) { + devices[type] = NULL; return; } while ((PAD_ButtonsHeld(0) &