Skip to content

Commit

Permalink
- Network init is now optional via settings/not threaded and off by d…
Browse files Browse the repository at this point in the history
…efault
  • Loading branch information
emukidid committed Jul 31, 2017
1 parent 6474588 commit 87afd9e
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 66 deletions.
5 changes: 1 addition & 4 deletions cube/swiss/include/bba.h
Expand Up @@ -3,11 +3,8 @@

extern char bba_ip[16];
extern int net_initialized;
extern int netInitPending;
extern int bba_exists;

void resume_netinit_thread();
void pause_netinit_thread();
void init_network_thread();
void init_network();

#endif
1 change: 1 addition & 0 deletions cube/swiss/include/swiss.h
Expand Up @@ -102,6 +102,7 @@ typedef struct {
bool ftpUsePasv;
int autoCheats;
int igrType;
int initNetworkAtStart;
u8 configDeviceId; // see deviceHandler.h
} SwissSettings __attribute__((aligned(32)));
extern SwissSettings swissSettings;
Expand Down
53 changes: 5 additions & 48 deletions cube/swiss/source/bba.c
Expand Up @@ -8,49 +8,15 @@
/* Network Globals */
int net_initialized = 0;
int bba_exists = 0;
int netInitPending = 1;
char bba_ip[16];

// net init thread
static lwp_t initnetthread = LWP_THREAD_NULL;
static int netInitHalted = 0;
// Init the GC net interface (bba)
void init_network(void *args) {

void resume_netinit_thread() {
if(initnetthread != LWP_THREAD_NULL) {
netInitHalted = 0;
LWP_ResumeThread(initnetthread);
}
}

void pause_netinit_thread() {
if(initnetthread != LWP_THREAD_NULL) {
netInitHalted = 1;

if(!netInitPending) {
return;
}

// until it's completed for this iteration.
while(!LWP_ThreadIsSuspended(initnetthread)) {
usleep(1000);
}
}
}
int res = 0;


// Init the GC/Wii net interface (wifi/bba/etc)
static void* init_network(void *args) {
int res = 0, netsleep = 1*1000*1000;

while(netsleep > 0) {
if(netInitHalted) {
LWP_SuspendThread(initnetthread);
}
usleep(100);
netsleep -= 100;
}

if(!net_initialized) {
bba_exists = exi_bba_exists();
if(bba_exists && !net_initialized) {
res = if_config(bba_ip, NULL, NULL, true, 20);
if(res >= 0 && strcmp("255.255.255.255", bba_ip)) {
net_initialized = 1;
Expand All @@ -59,15 +25,6 @@ static void* init_network(void *args) {
memset(bba_ip, 0, sizeof(bba_ip));
net_initialized = 0;
}
netInitPending = 0;
}

return NULL;
}

void init_network_thread() {
bba_exists = exi_bba_exists();
if(bba_exists) {
LWP_CreateThread (&initnetthread, init_network, NULL, NULL, 0, 40);
}
}
6 changes: 6 additions & 0 deletions cube/swiss/source/config/config.c
Expand Up @@ -27,6 +27,7 @@
//SMBShareName=nas
//SMBHostIP=192.168.1.32
//AutoCheats=Yes
//InitNetwork=No
//IGRType=Disabled
//FTPUserName=user
//FTPPassword=password
Expand Down Expand Up @@ -177,6 +178,8 @@ int config_update_file() {
string_append(configString, txtbuffer);
sprintf(txtbuffer, "AutoCheats=%s\r\n", (configSwissSettings.autoCheats ? "Yes":"No"));
string_append(configString, txtbuffer);
sprintf(txtbuffer, "InitNetwork=%s\r\n", (configSwissSettings.initNetworkAtStart ? "Yes":"No"));
string_append(configString, txtbuffer);
sprintf(txtbuffer, "IGRType=%s\r\n", (igrTypeStr[swissSettings.igrType]));
string_append(configString, txtbuffer);
sprintf(txtbuffer, "FTPUserName=%s\r\n",configSwissSettings.ftpUserName);
Expand Down Expand Up @@ -396,6 +399,9 @@ void config_parse(char *configData) {
else if(!strcmp("AutoCheats", name)) {
configSwissSettings.autoCheats = !strcmp("Yes", value) ? 1:0;
}
else if(!strcmp("InitNetwork", name)) {
configSwissSettings.initNetworkAtStart = !strcmp("Yes", value) ? 1:0;
}
else if(!strcmp("IGRType", name)) {
if(!strcmp(igrTypeStr[0], value))
configSwissSettings.igrType = 0;
Expand Down
4 changes: 3 additions & 1 deletion cube/swiss/source/devices/smb/deviceHandler-SMB.c
Expand Up @@ -37,6 +37,7 @@
#include "deviceHandler-FAT.h"
#include "deviceHandler-SMB.h"
#include "exi.h"
#include "bba.h"

/* SMB Globals */
extern int net_initialized;
Expand Down Expand Up @@ -187,7 +188,8 @@ s32 deviceHandler_SMB_readFile(file_handle* file, void* buffer, u32 length){
return bytes_read;
}

s32 deviceHandler_SMB_init(file_handle* file){
s32 deviceHandler_SMB_init(file_handle* file) {
init_network();
return 1;
}

Expand Down
7 changes: 6 additions & 1 deletion cube/swiss/source/gui/settings.c
Expand Up @@ -25,7 +25,7 @@ syssram* sram;
syssramex* sramex;

// Number of settings (including Back, Next, Save, Exit buttons) per page
int settings_count_pp[3] = {8, 9, 8};
int settings_count_pp[3] = {8, 10, 8};

void refreshSRAM() {
sram = __SYS_LockSram();
Expand Down Expand Up @@ -65,6 +65,7 @@ void settings_draw_page(int page_num, int option, file_handle *file) {
// Enable WiiRD debugging in Games [Yes/No]
// Enable File Management [Yes/No]
// Auto-load all cheats [Yes/No]
// Init network at startup [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, etc]
Expand Down Expand Up @@ -103,6 +104,8 @@ void settings_draw_page(int page_num, int option, file_handle *file) {
DrawSelectableButton(500, 230, -1, 255, swissSettings.enableFileManagement ? "Yes":"No", option == 4 ? B_SELECTED:B_NOSELECT,-1);
WriteFontStyled(30, 260, "Auto-load all cheats:", 1.0f, false, defaultColor);
DrawSelectableButton(500, 260, -1, 285, swissSettings.autoCheats ? "Yes":"No", option == 5 ? B_SELECTED:B_NOSELECT,-1);
WriteFontStyled(30, 290, "Init network at startup:", 1.0f, false, defaultColor);
DrawSelectableButton(500, 290, -1, 315, swissSettings.initNetworkAtStart ? "Yes":"No", option == 6 ? B_SELECTED:B_NOSELECT,-1);
}
else if(page_num == 2) {
WriteFont(30, 65, "Current Game Settings (3/3):");
Expand Down Expand Up @@ -226,6 +229,8 @@ void settings_toggle(int page, int option, int direction, file_handle *file) {
case 5:
swissSettings.autoCheats ^=1;
break;
case 6:
swissSettings.initNetworkAtStart ^= 1;
}
}
else if(page == 2 && file != NULL) {
Expand Down
6 changes: 1 addition & 5 deletions cube/swiss/source/httpd.c
Expand Up @@ -41,11 +41,7 @@ const static char http_get_ipl[] = "GET /ipl.bin HTTP/1.1\r\n";
//---------------------------------------------------------------------------------
void *httpd (void *arg) {
//---------------------------------------------------------------------------------

print_gecko("httpd Waiting\r\n");
while(netInitPending) {
sleep(1);
}

if(!net_initialized) {
print_gecko("httpd thread exiting, no IP\r\n");
return NULL;
Expand Down
18 changes: 11 additions & 7 deletions cube/swiss/source/main.c
Expand Up @@ -294,9 +294,7 @@ void scan_files() {
// Read the directory/device TOC
if(allFiles){ free(allFiles); allFiles = NULL; }
print_gecko("Reading directory: %s\r\n",curFile.name);
pause_netinit_thread();
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);
Expand Down Expand Up @@ -357,8 +355,10 @@ void main_loop()
}
curMenuLocation = ON_OPTIONS;
}
pause_netinit_thread();
if(devices[DEVICE_CUR] != NULL) {
DrawFrameStart();
DrawMessageBox(D_INFO,"Setting up device");
DrawFrameFinish();
// If the user selected a device, make sure it's ready before we browse the filesystem
devices[DEVICE_CUR]->deinit(devices[DEVICE_CUR]->initial);
sdgecko_setSpeed(EXI_SPEED32MHZ);
Expand All @@ -373,7 +373,6 @@ void main_loop()
curMenuLocation=ON_OPTIONS;
}

resume_netinit_thread();
while(1) {
if(devices[DEVICE_CUR] != NULL && needsRefresh) {
curMenuLocation=ON_OPTIONS;
Expand Down Expand Up @@ -523,9 +522,14 @@ int main ()
// load config
load_config();

// Start up the BBA if it exists
init_network_thread();
init_httpd_thread();
if(swissSettings.initNetworkAtStart) {
// Start up the BBA if it exists
DrawFrameStart();
DrawMessageBox(D_INFO,"Initialising Network");
DrawFrameFinish();
init_network();
init_httpd_thread();
}

// DVD Motor off
if(swissSettings.stopMotor && swissSettings.hasDVDDrive) {
Expand Down

0 comments on commit 87afd9e

Please sign in to comment.