/*---------------------------------------------------------------------------* Project: Revolution Install Demo File: discnanddemo2.c Copyright (C) 2008 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: discnanddemo2.c,v $ Revision 1.2.2.2 2009/10/21 02:36:42 miyamoto_satoshi Modified file name. Revision 1.2.2.1 2009/10/16 02:17:09 iwai_yuma Removed and added . Revision 1.2 2009/10/05 05:52:47 iwai_yuma Initial check-in to HEAD. Revision 1.1.2.2 2008/11/18 09:15:50 ooizumi Fixed typo. Revision 1.1.2.1 2008/11/18 09:02:40 ooizumi Initial check-in. $NoKeywords: $ *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------* * This demo illustrates how to handle errors. See __refresh_status() for * the actual error handling code! *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include /*---------------------------------------------------------------------------* * Installer definitions *---------------------------------------------------------------------------*/ typedef struct Channel { char* fileName; // channel application's file name to install u16* titleName; // channel application's title name to draw on screen OSTitleId titleId; // title id of channel application u32 fsBlocks; // FS block number u32 inodes; // inode number } Channel; static u16* TitleName; static Channel* InstallChannelList; static u16* TitleNameJp = L"ディスク派生チャンネルデモ2"; static Channel InstallChannelListJp[] = { { "discnanddemo1.wad", L"ディスク派生チャンネルデモ1", 0x0001000452414241, 35, 10 }, { NULL, NULL, 0, 0, 0 } }; static u16* TitleNameEn = L"Disc Spinoff Channel Demo 2"; static Channel InstallChannelListEn[] = { { "discnanddemo1.wad", L"Disc Spinoff Channel Demo 1", 0x0001000452414241, 35, 10 }, { NULL, NULL, 0, 0, 0 } }; static OSInstallInfo InstallChannelInfo[16]; static u32 InstallChannelNum; static u32 InstallFsBlocks; static u32 InstallInodes; /*---------------------------------------------------------------------------* * Prototypes *---------------------------------------------------------------------------*/ static void InitWindows(void); static void __status_refresh(DEMOWinInfo *handle); static void Run_Demo(void); static void MNU_check_install(DEMOWinMenuInfo *menu, u32 item, u32 *result); static void MNU_launch_installer(DEMOWinMenuInfo *menu, u32 item, u32 *result); static void MNU_get_disk_id(DEMOWinMenuInfo *menu, u32 item, u32 *result); /*---------------------------------------------------------------------------* * Main Control Menu Stuff! *---------------------------------------------------------------------------*/ DEMOWinMenuItem control_menu_items_dvd[] = { { "ISSUE COMMAND", DEMOWIN_ITM_SEPARATOR, NULL, NULL }, { " OSCheckInstall", DEMOWIN_ITM_NONE, MNU_check_install, NULL }, { " OSLaunchInstaller", DEMOWIN_ITM_NONE, MNU_launch_installer, NULL }, { " DVDGetCurrentDiskID", DEMOWIN_ITM_NONE, MNU_get_disk_id, NULL }, { "", DEMOWIN_ITM_TERMINATOR, NULL, NULL } }; DEMOWinMenuInfo control_menu = { "Channel Install Demo", // title NULL, // window handle control_menu_items_dvd, // List of menu items 50, // max num of items to display at a time DEMOWIN_MNU_NONE, // attribute flags? // user callbacks for misc menu operations NULL, NULL, NULL, NULL, // private menu info members; do not touch 0, 0, 0, 0, 0 }; DEMOWinMenuInfo *control_menu_ptr; /*---------------------------------------------------------------------------* * Debug and Status window stuff! *---------------------------------------------------------------------------*/ DEMOWinInfo *debug_win; // debug window DEMOWinInfo *status_win; // status window /*---------------------------------------------------------------------------* Name: InitWindows Description: Initialize windows Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ static void InitWindows(void) { DEMOWinInfo *p; control_menu_ptr = DEMOWinCreateMenuWindow(&control_menu, 20, 20); p = control_menu_ptr->handle; // Initialize a window for showing status of DVD commands // By passing "__status_refresh" as the last argument, the window system // calls "__status_refresh" once every frame. We use this function to // handle errors in this demo. status_win = DEMOWinCreateWindow((u16)(p->x2+5), p->y1, 620, (u16)(p->y1+100), "Status", 0, __status_refresh); // Initialize a window for debug output debug_win = DEMOWinCreateWindow((u16)(p->x2+5), (u16)(p->y1+105), 620, 434, "Debug", 1024, NULL); // Open status and debug windows. We don't open error message window until // we hit an error. DEMOWinOpenWindow(debug_win); DEMOWinOpenWindow(status_win); } /*---------------------------------------------------------------------------* Name: __status_refresh Description: This is the error handling part. This function is called once every frame. Arguments: handle: Window handle for the status window Returns: None. *---------------------------------------------------------------------------*/ static void __status_refresh(DEMOWinInfo *handle) { #pragma unused(handle) if (OSGetResetSwitchState()) { OSReport("reset is pressed\n"); while (OSGetResetSwitchState()) ; OSReport("reset is released\n"); // Black out screen VISetBlack(TRUE); VIFlush(); VIWaitForRetrace(); OSRestart(3); } } // end __status_refresh() /*---------------------------------------------------------------------------* Name: MNU_check_install Description: Arguments: menu, item, result: unused Returns: None. *---------------------------------------------------------------------------*/ static void MNU_check_install(DEMOWinMenuInfo *menu, u32 item, u32 *result) { #pragma unused(menu, item, result) u32 answer; if(!InstallChannelNum) { DEMOWinLogPrintf(debug_win, "Already installed.\n"); } else { answer = 0xffffffff; OSCheckInstall(InstallChannelNum, InstallFsBlocks, InstallInodes, &answer); DEMOWinLogPrintf(debug_win, "========Requirements========\n"); DEMOWinLogPrintf(debug_win, " Channel space ... %4d %s\n", InstallChannelNum, (answer & OSINSTALL_CHECK_SYS_INSCHAN) ? "NG" : "OK"); DEMOWinLogPrintf(debug_win, " FS blocks ....... %4d %s\n", InstallFsBlocks, (answer & OSINSTALL_CHECK_SYS_INSSPACE) ? "NG" : "OK"); DEMOWinLogPrintf(debug_win, " Inodes .......... %4d %s\n", InstallInodes, (answer & OSINSTALL_CHECK_SYS_INSINODE) ? "NG" : "OK"); } } /*---------------------------------------------------------------------------* Name: MNU_launch_installer Description: Arguments: menu, item, result: unused Returns: None. *---------------------------------------------------------------------------*/ static void MNU_launch_installer(DEMOWinMenuInfo *menu, u32 item, u32 *result) { #pragma unused(menu, item, result) if(!InstallChannelNum) { DEMOWinLogPrintf(debug_win, "Already installed.\n"); } else { // Black out screen VISetBlack(TRUE); VIFlush(); VIWaitForRetrace(); OSLaunchInstaller(0xdeadbeef, TitleName, InstallChannelInfo); } } /*---------------------------------------------------------------------------* Name: MNU_get_disk_id Description: Show disk id Arguments: menu: Winmenuinfo for control window item, result: unused Returns: None. *---------------------------------------------------------------------------*/ static void MNU_get_disk_id(DEMOWinMenuInfo *menu, u32 item, u32 *result) { #pragma unused(menu, item, result) DVDDiskID* id; id = DVDGetCurrentDiskID(); DEMOWinLogPrintf(debug_win, "====Current disk ID====\n"); DEMOWinLogPrintf(debug_win, " Game Name ... %-4.4s\n", id->gameName); DEMOWinLogPrintf(debug_win, " Company ..... %-2.2s\n", id->company); DEMOWinLogPrintf(debug_win, " Disk # ...... %x\n", id->diskNumber); DEMOWinLogPrintf(debug_win, " Game ver .... %x\n", id->gameVersion); } /*---------------------------------------------------------------------------* Name: Run_Demo Description: Main loop of the demo. Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ static void Run_Demo(void) { DEMOWinPadInfo pad; DEMOWinLogPrintf(debug_win, "-------------------------------\n"); DEMOWinLogPrintf(debug_win, "DVD error handling sample\n"); DEMOWinLogPrintf(debug_win, "-------------------------------\n"); DEMOWinLogPrintf(debug_win, "- Stick Up/Down to move cursor\n"); DEMOWinLogPrintf(debug_win, "- Button A to select an item\n"); DEMOWinLogPrintf(debug_win, "- Button B to exit a menu\n"); DEMOWinLogPrintf(debug_win, "While you are executing a command, open cover, make no disk,\n"); DEMOWinLogPrintf(debug_win, "put other disks to see how to handle errors\n"); while(1) { // Launch control window. This function returns when B is pressed. DEMOWinMenu(control_menu_ptr); DEMOWinLogPrintf(debug_win, "-------------------------------------------\n"); DEMOWinLogPrintf(debug_win, "\nUse Stick Up/Down to scroll debug buffer.\n"); DEMOWinLogPrintf(debug_win, "\nHit Start to resume the demo.\n"); DEMOBeforeRender(); DEMOWinRefresh(); DEMODoneRender(); DEMOWinPadRead(&pad); // Let the user scroll the debug window. Press start button to // go to the top of the outer loop and open the control window again. while(1) { DEMOWinPadRead(&pad); if (pad.pads[0].stickY < -50) { DEMOWinScrollWindow(debug_win, DEMOWIN_SCROLL_DOWN); if (pad.pads[0].triggerLeft > 150) { DEMOWinScrollWindow(debug_win, DEMOWIN_SCROLL_DOWN); DEMOWinScrollWindow(debug_win, DEMOWIN_SCROLL_DOWN); } } else if (pad.pads[0].stickY > 50) { DEMOWinScrollWindow(debug_win, DEMOWIN_SCROLL_UP); if (pad.pads[0].triggerLeft > 150) { DEMOWinScrollWindow(debug_win, DEMOWIN_SCROLL_UP); DEMOWinScrollWindow(debug_win, DEMOWIN_SCROLL_UP); } } else if (pad.changed_button[0] & PAD_BUTTON_START) { DEMOWinScrollWindow(debug_win, DEMOWIN_SCROLL_HOME); // get out of the inner loop break; } DEMOBeforeRender(); DEMOWinRefresh(); DEMODoneRender(); } // debug buffer scroll loop } // forever loop } // end Init_Player_Windows() void main (s32 argc, char** argv) { Channel* channelPtr; OSInstallInfo* channelInfoPtr; OSReport("to check installed titles:\n"); // select language if(SCGetLanguage() == SC_LANG_JAPANESE) { TitleName = TitleNameJp; InstallChannelList = InstallChannelListJp; } else { TitleName = TitleNameEn; InstallChannelList = InstallChannelListEn; } channelPtr = InstallChannelList; channelInfoPtr = InstallChannelInfo; InstallChannelNum = 0; InstallFsBlocks = 0; InstallInodes = 0; while(channelPtr->fileName) { if(OSIsTitleInstalled(channelPtr->titleId)) { OSReport(" title %016llx is already installed.\n", channelPtr->titleId); } else { channelInfoPtr->fileName = channelPtr->fileName; channelInfoPtr->titleName = channelPtr->titleName; InstallChannelNum++; InstallFsBlocks += channelPtr->fsBlocks; InstallInodes += channelPtr->inodes; OSReport(" added %016llx to install.\n", channelPtr->titleId); channelInfoPtr++; } channelPtr++; } channelInfoPtr->fileName = NULL; // set NULL to terminate // disabled the default disc fatal screen DVDSetAutoFatalMessaging(FALSE); DEMOInit(NULL); OSReport("Disk number is %x\n", DVDGetCurrentDiskID()->diskNumber); AIInit(NULL); OSReport("AIInit done\n"); DEMOWinInit(); OSReport("DEMOWinInit done\n"); InitWindows(); OSReport("InitWindows done\n"); OSReport("OSGetResetCode = %08X\n", OSGetResetCode()); // check reset code switch(OSGetResetCode()) { case 0: // boot from system menu { OSReport("boot from system menu\n"); break; } case OS_RESETCODE_RESTART|3: // restart { OSReport("restart\n"); break; } // boot from installer case OS_RESETCODE_INSTALLER: { OSReport("return from installer.\n"); OSReport("OSGetReturnCode = %08X %s\n", OSGetReturnCode(), OSGetReturnCode() ? "NG" : "OK"); OSReport("OSGetLaunchCode = %08X %s\n", OSGetLaunchCode(), (OSGetLaunchCode() == 0xdeadbeef) ? "OK" : "NG"); break; } case OS_RESETCODE_LAUNCH: // launch { OSReport("launch from nand app\n"); break; } default: { OSHalt("invalid state"); break; } } while(argc) { argc--; OSReport("argv[%d] = %s\n", argc, argv[argc]); } Run_Demo(); } // end main