void UsbKeepAlive() { if( isMounted[DEVICE_USB] ) { u32 time = SDL_GetTicks(); if( ( time - lastKeepAlive ) > KEEP_ALIVE ) { lastKeepAlive = time; keepAliveCount++; keepAliveCount %= 100; //if( !keepAliveFile ) //{ keepAliveFile = fopen( KEEP_ALIVE_FILE, "w" ); //} BOOL success = 0; if( keepAliveFile ) { fputc( keepAliveCount, keepAliveFile ); fflush( keepAliveFile ); fclose( keepAliveFile ); success = 1; } #ifdef WII_NETTRACE net_print_string( NULL, 0, "usb keepalive:%s, %d\n", KEEP_ALIVE_FILE, success ); #endif } } }
int net_print_init(const char *rhost, unsigned short port) { int sk = -1; int wd = 0x12345678; if ( _net_print_socket < 0 ) { if (rhost==NULL){ rhost = DEFAULT_NET_PRINT_HOST; } if (port <= 0 ){ port = DEFAULT_NET_PRINT_PORT; } sk = clientsocket( rhost, port); if ( sk >= 0 ) { _net_print_socket = sk; net_print_string( __FILE__, __LINE__, "net_print_init() successful, socket=%d, testing for hi-low-byte using int 0x12345678:\n", _net_print_socket); net_print_binary( 'X', &wd, sizeof(wd)); } } return _net_print_socket; }
/** * Write a log message. * * @param type Log message type. * @param msg Message to log. */ void WiiLogger::Write(LoggerType type, string msg) { std::ostringstream out; out << TypeToString(type) << " "; out << Utils::DateTime::GetCurrent() << ": "; out << msg << std::endl; string s = out.str(); net_print_string(NULL, 0, s.c_str()); }
/* * Determines and stores the base application path * * argc The count of main arguments * argv The array of argument values */ void wii_set_app_path( int argc, char *argv[] ) { snprintf( app_path, WII_MAX_PATH, "%s", WII_BASE_APP_DIR ); if( ( argc > 0 ) && ( argv[0] != NULL ) && ( strchr( argv[0], ':' ) != NULL ) ) // To support wiiload { #ifdef WII_NETTRACE net_print_string(__FILE__,__LINE__, "Found drive prefix" ); #endif char temp_path[WII_MAX_PATH]; snprintf( temp_path, WII_MAX_PATH, "%s", argv[0] ); char *loc; // Remove the file name loc = strrchr( temp_path, '/' ); if (loc != NULL) { *loc = '\0'; } snprintf( app_path, WII_MAX_PATH, "%s/", temp_path ); } else { #ifdef WII_NETTRACE net_print_string(__FILE__,__LINE__, "No drive prefix." ); #endif } if( strncmpi( "usb", app_path, 3 ) == 0 ) { wii_is_usb = TRUE; } }
u8* Mem2ManagerCalloc( int count, u32 size, const char* purpose ) { #ifdef WII_NETTRACE net_print_string( NULL, 0, "Mem2ManagerCalloc: %d 0x%x %s\n", count, size, purpose ); #endif u32 realSize = size * count; u8* result = Mem2ManagerAlloc( realSize, purpose ); //if( result != NULL ) //{ // memset( result, 0x0, realSize ); //} return result; }
void InitMem2Manager() { int size = (32*1024*1024)+(256*1024)+32; u32 level; _CPU_ISR_Disable(level); mem2_ptr = (u8*)((u32)SYS_GetArena2Hi()-size); SYS_SetArena2Hi(mem2_ptr); _CPU_ISR_Restore(level); mem2_size = size; Mem2ManagerReset(); #ifdef WII_NETTRACE net_print_string( NULL, 0, "InitMem2Manager: %d, %u\n", mem2_size, mem2_ptr ); #endif }
u8* Mem2ManagerAdjust( u8* mem, u32 size, const char* purpose ) { if( mem != last_head ) { MDFN_PrintError( "Unable to adjust '%s', not last allocation.", purpose ); return NULL; } else if( (((u32)last_head + size)-(u32)mem2_ptr) > mem2_size ) { MDFN_PrintError( "Unable to adjust '%s': %u bytes", purpose, size ); return NULL; } head = last_head + size; head = (u8*)(((u32)head+0x1f)&(~0x1f)); // Align to 32 bytes last_size = size; #ifdef WII_NETTRACE net_print_string( NULL, 0, "Mem2ManagerAdjust: %s = 0x%x, %0.2f\n", purpose, last_head, ((float)(size)/1048576.0) ); #endif return last_head; }
u8* Mem2ManagerAlloc( u32 size, const char* purpose ) { if( (((u32)head + size)-(u32)mem2_ptr) > mem2_size ) { MDFN_PrintError( "Unable to allocate '%s': %u bytes", purpose, size ); return NULL; } else { last_head = head; last_size = size; head += size; head = (u8*)(((u32)head+0x1f)&(~0x1f)); // Align to 32 bytes #ifdef WII_NETTRACE net_print_string( NULL, 0, "Mem2ManagerAlloc: %s = 0x%x, %0.2f\n", purpose, last_head, ((float)(size)/1048576.0) ); #endif memset( last_head, 0x0, size ); return last_head; } }
int net_print_binary( int format, const void* data, int len) { int col, k, ret; char line[80], *out; const unsigned char *in; const char* binary = (const char *)data; if ( _net_print_socket < 0 ) { return -1; } in = (unsigned char*)binary; for( k=0; k<len ; ) { out = line; switch( format ) { case 'x': for( col=0; col<8 && k<len && ((len-k)/2>0); col++, k+=2) { ret = sprintf( out, "%02X%02X ", *in, *(in+1)); if ( col==3) { strcat( out++, " "); } out += ret; in+=2; } break; case 'X': for( col=0; col<4 && k<len && ((len-k)/4>0); col++, k+=4) { ret = sprintf( out, "%02X%02X%02X%02X ", *in, *(in+1), *(in+2), *(in+3)); if ( col==1) { strcat( out++, " "); } out += ret; in+=4; } break; case 'c': for( col=0; col<16 && k<len; col++, k++) { if ( isprint( *in) && !isspace(*in)) { ret = sprintf( out, "%c ", *in); } else { ret = sprintf( out, "%02X ", *in); } if ( col==7) { strcat( out++, " "); } out += ret; in++; } break; default: for( col=0; col<16 && k<len; col++, k++) { ret = sprintf( out, "%02X ", *in); if ( col==7) { strcat( out++, " "); } out += ret; in++; } } if ( out != line ) { strcat( out, "\n"); net_print_string( NULL, 0, "%s", line); } else { break; } } /*** if ( out!=line) { strcat( out, "\n"); net_print_string( NULL, 0, "%s", line); } ***/ return len; }
void DatabaseManager::loadEntry( const char* hash ) { char buff[255]; // The buffer to use when reading the file FILE* dbFile; // The database file char dbHash[255]; // A hash found in the file we are reading from int readMode = 0; // The current read mode char* ptr; // Pointer into the current entry value #ifdef WII_NETTRACE net_print_string( NULL, 0, "%s\n", getDbFile() ); net_print_string( NULL, 0, "%s\n", getDbTmpFile() ); net_print_string( NULL, 0, "%s\n", getDbOldFile() ); #endif // Populate the entry with the defaults resetToDefaults(); dbEntry* entry = getEntry(); dbFile = fopen( getDbFile(), "r" ); if( dbFile != 0 ) { while( fgets( buff, sizeof(buff), dbFile ) != 0 ) { if( readMode == 2 ) { // We moved past the current record, exit. break; } if( readMode == 1 ) { // Read from the matching database entry ptr = strchr( buff, '=' ); if( ptr ) { *ptr++ = '\0'; Util_trim( buff ); Util_trim( ptr ); if( !strcmp( buff, "name" ) ) { Util_strlcpy( entry->name, ptr, sizeof(entry->name) ); } else { readEntryValue( entry, buff, ptr ); } } } // Search for the hash if( getHash( buff, dbHash ) && readMode < 2 ) { if( readMode || !strcmp( hash, dbHash ) ) { entry->loaded = 1; readMode++; } } } fclose( dbFile ); } }
/* * Reads the list of games into the specified menu * * menu The menu to read the games into */ static void wii_read_game_list( TREENODE *menu ) { const char* roms = wii_get_roms_dir(); wii_menu_clear_children( menu ); // Clear the children #ifdef WII_NETTRACE net_print_string( NULL, 0, "ReadGameList: %s\n", roms, strlen(roms) ); #endif BOOL success = FALSE; if( strlen( roms ) > 0 ) { DIR *romdir = opendir( roms ); #ifdef WII_NETTRACE net_print_string( NULL, 0, "OpenDir: %d\n", roms, romdir); #endif if( romdir != NULL) { wii_add_child( menu, wii_create_tree_node( NODETYPE_UPDIR, "[..]" ) ); struct dirent* entry = NULL; while( ( entry = readdir( romdir ) ) != NULL ) { if( ( strcmp( ".", entry->d_name ) && strcmp( "..", entry->d_name ) ) ) { TREENODE *child = wii_create_tree_node( ( entry->d_type == DT_DIR ? NODETYPE_DIR : NODETYPE_ROM ), entry->d_name ); wii_add_child( menu, child ); } } closedir( romdir ); // Sort the games list qsort( menu->children, menu->child_count, sizeof(*(menu->children)), game_name_compare ); success = TRUE; } else { char msg[256]; snprintf( msg, sizeof(msg), "%s: %s", gettextmsg("Error opening"), roms ); wii_set_status_message( msg ); } } if( !success ) { wii_set_roms_dir( "" ); wii_add_child( menu, wii_create_tree_node( NODETYPE_ROOT_DRIVE, "sd:" ) ); wii_add_child( menu, wii_create_tree_node( NODETYPE_ROOT_DRIVE, "usb:" ) ); wii_add_child( menu, wii_create_tree_node( NODETYPE_ROOT_DRIVE, "smb:" ) ); } games_read = TRUE; }