/*---------------------------------------------------------------------------* Project: Revolution SDK DS-Wireless FileSystem demo File: download.c Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: download.c,v $ Revision 1.5 2007/10/26 08:06:56 seiki_masashi Support for REXDEMOGetAnyMixedPadTrigger. Revision 1.4 2007/08/01 09:36:29 kitase_hirotake Changed TAB to SPACE. Revision 1.3 2007/02/27 00:26:06 yosizaki Changed type of the playerbits (from int to u32) Revision 1.2 2007/02/21 08:08:41 okubata_ryoma Small fix Revision 1.1 2007/01/16 08:33:30 yosizaki Initial upload. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include "rexdemo/demokpad.h" #include "rexdemo/graphic.h" /*===========================================================================*/ /* Variables */ /* MPDL work structure */ static MPDLConfig mpdlConfig ATTRIBUTE_ALIGN(32) = { NULL, NULL, 2, // threadPriority 0x00000000, // ggid MP_TGID_AUTO, // tgid MP_CHANNEL_AUTO, // channel 0, // serverColor L"Wii", // serverName L"MPFS sample", // programTitle L"do MPDL¨MPFS", // programComment 3, // programMaxEntry NULL, // programImage }; /*===========================================================================*/ /* Functions */ // MPDL driver void ExecuteDownload(void* (*alloc)(u32), void (*free)(void*), const void *program); void ExecuteDownload(void* (*alloc)(u32), void (*free)(void*), const void *program) { enum { MODE_AUTODOWNLOAD, MODE_MAX }; static BOOL auto_download_mode = TRUE; int mode_cursor = 0; BOOL is_entry_closed = FALSE; u32 fixed_entry = 0; MPDLConfig * const config = &mpdlConfig; config->alloc = alloc; config->free = free; config->programImage = (void*)program; /* Initialize and startup MPDL */ if ( MPDLStartup( config ) != MP_RESULT_OK ) { OSHalt( "failed to startup MPDL!\n" ); } for (; ;) { int i; u32 entry; u32 booted; REXDEMOKPadRead(); /* Update sequence */ entry = MPDLGetEntryBitmap(); booted = MPDLGetBootedBitmap(); if (!is_entry_closed) { const u32 full_entry = (u32)(((1 << config->programMaxEntry) - 1) & ~1); /* Move cursor and select options */ if ((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_RIGHT | KPAD_BUTTON_LEFT | (PAD_BUTTON_RIGHT << 16) | (PAD_BUTTON_LEFT << 16))) != 0) { switch (mode_cursor) { case MODE_AUTODOWNLOAD: auto_download_mode = !auto_download_mode; break; default: break; } } if (((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_UP | (PAD_BUTTON_UP << 16))) != 0) && (--mode_cursor < 0)) { mode_cursor += MODE_MAX; } if (((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_DOWN | (PAD_BUTTON_DOWN << 16))) != 0) && (++mode_cursor >= MODE_MAX)) { mode_cursor -= MODE_MAX; } /* Close entry and start download */ if (((entry == full_entry) && auto_download_mode) || ((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_A | (PAD_BUTTON_A << 16))) != 0)) { is_entry_closed = TRUE; fixed_entry = MPDLStartDownload(); } } else if (entry == 0) { MPDLEnableFlag(TRUE, FALSE); if ((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_A | (PAD_BUTTON_A << 16))) != 0) { break; } } /* DrawFrame */ REXDEMOBeginRender(); { /* *INDENT-OFF* */ static const GXColor ds_ipl_color_table[16] = { { 0x63, 0x84, 0x9C, }, /* GRAY */ { 0xBD, 0x4A, 0x00, }, /* BROWN */ { 0xFF, 0x00, 0x18, }, /* RED */ { 0xFF, 0x8C, 0xFF, }, /* PINK */ { 0xFF, 0x94, 0x00, }, /* ORANGE */ { 0xF7, 0xE7, 0x00, }, /* YELLOW */ { 0xAD, 0xFF, 0x00, }, /* LIME_GREEN */ { 0x00, 0xFF, 0x00, }, /* GREEN */ { 0x00, 0xA5, 0x39, }, /* DARK_GREEN */ { 0x4A, 0xDE, 0x8C, }, /* SEA_GREEN */ { 0x31, 0xBD, 0xF7, }, /* TURQUOISE */ { 0x00, 0x5A, 0xF7, }, /* BLUE */ { 0x00, 0x00, 0x94, }, /* DARK_BLUE */ { 0x8C, 0x00, 0xD6, }, /* PURPLE */ { 0xD6, 0x00, 0xEF, }, /* VIOLET */ { 0xFF, 0x00, 0x94, }, /* MAGENTA */ }; /* *INDENT-ON* */ const s16 ox = 4, oy = 158; /* header */ REXDEMOSetTextColor(REXDEMO_COLOR_WHITE); REXDEMOPrintf(4, 8, 0, "MPDL simple sample"); REXDEMOSetTextColor(REXDEMO_COLOR_YELLOW); if (!is_entry_closed) { REXDEMOPrintf(4, 24, 0, "entry is opened."); REXDEMOPrintf(200, 24, 0, "(press A to start download)"); } else if (entry > 0) { REXDEMOPrintf(4, 24, 0, "entry is closed, now downloading..."); } else { REXDEMOPrintf(4, 24, 0, "download has been completed."); REXDEMOPrintf(320, 24, 0, "(press A to restart as FS server)"); } REXDEMOSetTextColor(REXDEMO_COLOR_WHITE); REXDEMOPrintf(30, 60, 0, "auto-download mode : ON OFF"); REXDEMOSetTextColor(REXDEMO_COLOR_YELLOW); REXDEMOPrintf(10, 60 + mode_cursor * 10, 0, ">"); REXDEMOPrintf(30, 60, 0, " %s %s", auto_download_mode ? "[ ]" : " ", auto_download_mode ? " " : "[ ]"); /* entries */ REXDEMOSetTextColor(REXDEMO_COLOR_WHITE); REXDEMOPrintf(ox, oy, 0, "AID STATUS MAC-ADDR NAME"); for (i = 1; i < 16; ++i) { const s16 sy = (s16)(oy + i * 15); MPDLPlayerInfo info[1]; BOOL valid_player = MPDLGetPlayerInfo(i, info); REXDEMOSetTextColor(valid_player ? ds_ipl_color_table[info->color] : REXDEMO_COLOR_GRAY); /* AID */ REXDEMOPrintf(ox + 5, sy, 0, "%2d", i); /* STATUS */ if (!is_entry_closed) { if (valid_player) { REXDEMOPrintf(ox + 40, sy, 0, "ready"); } else if (i < config->programMaxEntry) { REXDEMOPrintf(ox + 40, sy, 0, " none "); } } else { if (valid_player) { if ((booted & (1 << i)) != 0) { REXDEMOPrintf(ox + 40, sy, 0, "booted"); } else { REXDEMOPrintf(ox + 40, sy, 0, " %3d%% ", info->progress); } } else if ((fixed_entry & (1 << i)) != 0) { REXDEMOPrintf(ox + 40, sy, 0, "failed"); } } /* MAC-ADDR & NAME */ if (valid_player) { char name[MPDL_PLAYER_NAME_MAX + 1]; int n; for (n = 0; n < info->name_length; ++n) { u16 c = info->name[n]; name[n] = (char)(((c & 0xFF) == 0) ? (c >> 8) : '?'); } name[n] = '\0'; REXDEMOPrintf(ox + 110, sy, 0, "%02X%02X%02X:%02X%02X%02X %-10s", info->mac[0], info->mac[1], info->mac[2], info->mac[3], info->mac[4], info->mac[5], name); } } } REXDEMOWaitRetrace(); } (void)MPDLCleanup(); } /*===========================================================================*/