/*---------------------------------------------------------------------------* Project: Launch Disk Demo File: discnanddemo1.c Copyright 2007 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: discnanddemo1.c,v $ 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.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 /*---------------------------------------------------------------------------* * DVD definitions *---------------------------------------------------------------------------*/ static DVDFileInfo FileInfo; static volatile BOOL FileInfoIsInUse = FALSE; static DVDDiskID DiskID; #define GAMENAME "RABA" #define COMPANYNAME "ZZ" /*---------------------------------------------------------------------------* * Misc *---------------------------------------------------------------------------*/ #define MIN(x, y) ((x) < (y)? (x):(y)) /*---------------------------------------------------------------------------* * Data to pass from command issuing routines to status printing routine. *---------------------------------------------------------------------------*/ enum{ COMMAND_GET_ERROR_STATUS, COMMAND_CHANGE_DISK, COMMAND_PREPARE_DISK }; typedef struct { u32 command; s32 readLength; } CommandBlockData; static CommandBlockData Data; /*---------------------------------------------------------------------------* * Messages for errors *---------------------------------------------------------------------------*/ typedef struct { char* line[6]; } Message; // Error messages. XXX Caution: Subject to change. Message ErrorMessages[] = { {"Please insert the disc for xxx.", "", "", "", "", ""}, {"This disc is not for xxx.", "Please insert the disc for xxx.", "", "", "", ""}, {"The disc could not be read.", "", "Please read the NINTENDO REVOLUTION", "Instruction Booklet for more information", "", ""}, {"An error has occurred.", "", "Turn the power OFF and check", "the NINTENDO REVOLUTION", "Instruction Booklet for", "further instructions."}, {"Please insert the next disc.", "", "", "", "", ""}, }; enum{ MESSAGE_NO_DISK = 0, MESSAGE_WRONG_DISK, MESSAGE_RETRY_ERROR, MESSAGE_FATAL_ERROR, MESSAGE_CHANGE_DISK }; /*---------------------------------------------------------------------------* * Prototypes *---------------------------------------------------------------------------*/ static void InitWindows(void); static void __status_refresh(DEMOWinInfo *handle); static void Run_Demo(void); static void MNU_cancel(DEMOWinMenuInfo *menu, u32 item, u32 *result); static void MNU_launch_diskl(DEMOWinMenuInfo *menu, u32 item, u32 *result); static void MNU_launch_diskv(DEMOWinMenuInfo *menu, u32 item, u32 *result); static void MNU_get_disk_id(DEMOWinMenuInfo *menu, u32 item, u32 *result); static void MNU_prepare_disk(DEMOWinMenuInfo *menu, u32 item, u32 *result); /*---------------------------------------------------------------------------* * Main Control Menu Stuff! *---------------------------------------------------------------------------*/ DEMOWinMenuItem control_menu_items_nand[] = { { "ISSUE COMMAND", DEMOWIN_ITM_SEPARATOR, NULL, NULL }, { " OSLaunchDiskl", DEMOWIN_ITM_NONE, MNU_launch_diskl, NULL }, { " OSLaunchDiskv", DEMOWIN_ITM_NONE, MNU_launch_diskv, NULL }, { " DVDCancel", DEMOWIN_ITM_NONE, MNU_cancel, NULL }, { " DVDPrepareDisk", DEMOWIN_ITM_NONE, MNU_prepare_disk, NULL }, { " DVDGetCurrentDiskID", DEMOWIN_ITM_NONE, MNU_get_disk_id, NULL }, { "", DEMOWIN_ITM_TERMINATOR, NULL, NULL } }; DEMOWinMenuInfo control_menu = { "Launch Disk Demo", // title NULL, // window handle control_menu_items_nand, // 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 DEMOWinInfo *errmsg_win; // error message 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; // Intialize 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); // Initialize a window for showing error message errmsg_win = DEMOWinCreateWindow(120, 150, 520, 250, "Error message", 0, 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) { static u32 counter; s32 message; u32 i; CommandBlockData *data; // Clear status window (we only use the first two rows) DEMOWinClearRow(handle, 0); DEMOWinClearRow(handle, 1); // We use "user data" as the information of the command that was issued // last. data = DVDGetUserData((DVDCommandBlock*)&FileInfo); message = -1; // This part is for debugging purpose. Show the drive's status on status // window. switch(DVDGetDriveStatus()) { case DVD_STATE_END: FileInfoIsInUse = FALSE; DEMOWinPrintfXY(handle, 0, 1, "Command finished"); break; case DVD_STATE_FATAL_ERROR: DEMOWinPrintfXY(handle, 0, 1, "Fatal error occurred"); message = MESSAGE_FATAL_ERROR; break; case DVD_STATE_BUSY: break; case DVD_STATE_NO_DISK: DEMOWinPrintfXY(handle, 0, 1, "No disk"); message = MESSAGE_NO_DISK; break; case DVD_STATE_WRONG_DISK: DEMOWinPrintfXY(handle, 0, 1, "Wrong disk"); message = MESSAGE_WRONG_DISK; break; case DVD_STATE_RETRY: DEMOWinPrintfXY(handle, 0, 1, "Please retry"); message = MESSAGE_RETRY_ERROR; break; case DVD_STATE_MOTOR_STOPPED: DEMOWinPrintfXY(handle, 0, 1, "Ready to replace"); message = MESSAGE_CHANGE_DISK; break; } // If necessary, launch error message window to show the error message to // the user. if (message >= 0) { DEMOWinOpenWindow(errmsg_win); counter = (counter+1) % 60; for (i = 0; i < 6; i++) { if (counter < 45) { DEMOWinClearRow(errmsg_win, (u16)i); DEMOWinPrintfXY(errmsg_win, 0, (u16)i, ErrorMessages[message].line[i]); } else { DEMOWinClearRow(errmsg_win, (u16)i); } } } else { DEMOWinCloseWindow(errmsg_win); } 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() char* launchArgv[] = { "launchArgv", NULL }; /*---------------------------------------------------------------------------* Name: MNU_launch_diskl Description: Arguments: menu, item, result unused Returns: none *---------------------------------------------------------------------------*/ static void MNU_launch_diskl(DEMOWinMenuInfo *menu, u32 item, u32 *result) { #pragma unused(menu, item, result) // Black out screen VISetBlack(TRUE); VIFlush(); VIWaitForRetrace(); OSLaunchDiskl(&DiskID, 0xdeadbeef, "launchArgl", NULL); } /*---------------------------------------------------------------------------* Name: MNU_launch_diskv Description: Arguments: menu, item, result unused Returns: none *---------------------------------------------------------------------------*/ static void MNU_launch_diskv(DEMOWinMenuInfo *menu, u32 item, u32 *result) { #pragma unused(menu, item, result) // Black out screen VISetBlack(TRUE); VIFlush(); VIWaitForRetrace(); OSLaunchDiskv(&DiskID, 0xabadcafe, launchArgv); } /*---------------------------------------------------------------------------* Name: MNU_cancel Description: Issue DVDCancel. This function is called when DVDCancel is selected in the control window. Arguments: menu, item, result unused Returns: none *---------------------------------------------------------------------------*/ static void MNU_cancel(DEMOWinMenuInfo *menu, u32 item, u32 *result) { #pragma unused(menu, item, result) DVDCancelAsync((DVDCommandBlock*)&FileInfo, NULL); } /*---------------------------------------------------------------------------* Name: MNU_prepare_disk Description: Issue DVDPrepareDisk Arguments: menu Winmenuinfo for control window item, result unused Returns: none *---------------------------------------------------------------------------*/ static void MNU_prepare_disk(DEMOWinMenuInfo *menu, u32 item, u32 *result) { #pragma unused(menu, item, result) // Avoid using the same FileInfo/CommandBlock at the same time. if (FileInfoIsInUse) { return; } // Pass information to __status_refresh() Data.command = COMMAND_PREPARE_DISK; DVDSetUserData((DVDCommandBlock*)&FileInfo, (void*)&Data); FileInfoIsInUse = TRUE; DVDPrepareDiskAsync((DVDCommandBlock*)&FileInfo, &DiskID, NULL); } /*---------------------------------------------------------------------------* 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, "Launch disk 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 funcion 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 to 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() extern u32 OSGetLaunchCode(void); void main (s32 argc, char** argv) { // generate disk id for disk launch DVDGenerateDiskID(&DiskID, GAMENAME, COMPANYNAME, 0, 0); // disabled the default disc fatal screen DVDSetAutoFatalMessaging(FALSE); // clear user data DVDSetUserData((DVDCommandBlock*)&FileInfo, (void*)NULL); 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("OSGetAppType = %08X\n", OSGetAppType()); OSReport("OSGetResetCode = %08X\n", OSGetResetCode()); OSReport("OSGetLaunchCode = %08X\n", OSGetLaunchCode()); while(argc) { argc--; OSReport("argv[%d] = %s\n", argc, argv[argc]); } Run_Demo(); } // end main