/*---------------------------------------------------------------------------* Project: WiiConnect24 API demos File: MsgViewerUpdate.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: MsgViewerUpdate.c,v $ Revision 1.4 2008/05/01 08:50:26 hirose_kazuki Added "Close library" mode. Revision 1.3 2008/04/28 11:20:23 hirose_kazuki Updated framework. Revision 1.2 2007/02/02 02:20:46 torigoe_nobutaka Added handling of messages without subject or body text. Revision 1.1 2006/09/27 08:58:21 torigoe_nobutaka Renamed from update.c Moved from nwc24demo/src. Revision 1.2 2006/09/27 07:31:45 torigoe_nobutaka Improved performance. Revision 1.1 2006/08/28 08:51:50 torigoe_nobutaka Initial check in. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include "MsgViewerUpdate.h" #include "MsgViewer.h" /*---------------------------------------------------------------------------* Local functions *---------------------------------------------------------------------------*/ static BOOL GetMsgData ( MsgData* msgData, NWC24MsgBoxId mBoxId, u32 msgId ); static void ReceiveMessage ( void ); static void PostMessage ( void ); static void CreateMessage ( NWC24MsgBoxId mBoxId ); static void UpdateMenu ( u32 input ); static void UpdateRecvBox ( u32 input ); static void UpdateSendBox ( u32 input ); static void UpdateMsgContent ( u32 input ); static void UpdateDeleteMsg ( u32 input ); static void UpdateBeforeRecvMsg ( u32 input ); static void UpdateBeforePostMsg ( u32 input ); static void UpdateDoneRecvMsg ( u32 input ); static void UpdateDonePostMsg ( u32 input ); static void UpdateLibClosed ( u32 input ); static void UpdateWaitOpen ( u32 input ); static void UpdateErrorMsg ( u32 input ); /*---------------------------------------------------------------------------* Name : Render Description : Updates scenes not being rendered. Arguments : input - Input data from controller buttons (KPAD & PAD) Returns : None. *---------------------------------------------------------------------------*/ void Update( u32 input ) { switch ( g_state ) { case MB_STATE_MENU: UpdateMenu( input ); break; case MB_STATE_RECV_BOX: UpdateRecvBox( input ); break; case MB_STATE_SEND_BOX: UpdateSendBox( input ); break; case MB_STATE_MSG_CONTENT: UpdateMsgContent( input ); break; case MB_STATE_DELETE_MSG: UpdateDeleteMsg( input ); break; case MB_STATE_BEFORE_RECV_MSG: UpdateBeforeRecvMsg( input ); break; case MB_STATE_BEFORE_POST_MSG: UpdateBeforePostMsg( input ); break; case MB_STATE_DONE_RECV_MSG: UpdateDoneRecvMsg( input ); break; case MB_STATE_DONE_POST_MSG: UpdateDonePostMsg( input ); break; case MB_STATE_LIB_CLOSED: UpdateLibClosed( input ); break; case MB_STATE_WAIT_OPEN: UpdateWaitOpen( input ); break; case MB_STATE_ERROR_CONT: UpdateErrorMsg( input ); break; case MB_STATE_ERROR_STOP: break; } return; } /*---------------------------------------------------------------------------* Name : GetMsgData Description : Gets data from the specified message. Arguments : msgData - Pointer to the MsgData-type structure that stores the message data. mBoxId - Message box type. msgId - Message ID. Returns : BOOL - TRUE if successful. *---------------------------------------------------------------------------*/ #define THROW_ERROR(func, err) \ { \ if ( err != NWC24_OK ) \ { \ OSReport("%s : error %d\n", func, err); \ goto errorHandling; \ } \ } static BOOL GetMsgData( MsgData* msgData, NWC24MsgBoxId mBoxId, u32 msgId ) { NWC24Err err; NWC24MsgObj msgObj; u32 subjectSize; char* subject; u32 textSize; char* text; NWC24Charset charset; NWC24Encoding encoding; MsgBoxType mbType = (mBoxId == NWC24_RECV_BOX) ? MB_TYPE_RECV : MB_TYPE_SEND; err = NWC24GetMsgObj( &msgObj, mBoxId, msgId ); if ( err == NWC24_ERR_HIDDEN ) { return FALSE; } THROW_ERROR( "NWC24InitMsgObj()", err ); /* Message type */ err = NWC24GetMsgType( &msgObj, &msgData->type ); THROW_ERROR( "NWC24GetMsgType()", err ); /* Number of recipients */ err = NWC24GetMsgNumTo( &msgObj, &msgData->numTo ); THROW_ERROR( "NWC24GetMsgNumTo()", err ); if ( MAX_NUM_TO < msgData->numTo ) { msgData->numTo = MAX_NUM_TO; } /* Subject Line */ err = NWC24GetMsgSubjectSize( &msgObj, &subjectSize ); THROW_ERROR( "NWC24GetMsgSubjectSize()", err ); if ( subjectSize < 1 ) { subjectSize = 1; } subject = MEMAllocFromAllocator( &DemoAllocator1, subjectSize ); err = NWC24ReadMsgSubject( &msgObj, subject, subjectSize ); if ( err != NWC24_OK ) { MEMFreeToAllocator( &DemoAllocator1, subject ); THROW_ERROR( "NWC24ReadMsgSubject()", err ); } if ( MAX_SUBJECT_SIZE < subjectSize ) { subjectSize = MAX_SUBJECT_SIZE; } (void)memcpy( msgData->subject, subject, subjectSize ); msgData->subject[subjectSize] = '\0'; MEMFreeToAllocator( &DemoAllocator1, subject ); /* Text */ err = NWC24GetMsgTextSize( &msgObj, &textSize ); THROW_ERROR( "NWC24GetMsgTextSize()", err ); if ( textSize < 1 ) { textSize = 1; } text = MEMAllocFromAllocator( &DemoAllocator1, textSize ); err = NWC24ReadMsgText( &msgObj, text, textSize, &charset, &encoding ); if ( err != NWC24_OK ) { MEMFreeToAllocator( &DemoAllocator1, text ); THROW_ERROR( "NWC24ReadMsgText()", err ); } if ( MAX_TEXT_SIZE < textSize ) { textSize = MAX_TEXT_SIZE; } (void)memcpy( msgData->text, text, textSize ); msgData->text[textSize] = '\0'; MEMFreeToAllocator( &DemoAllocator1, text ); /* Sender/recipient */ if ( msgData->type != NWC24_MSGTYPE_PUBLIC ) { NWC24UserId temp; u32 i; err = NWC24GetMsgFromId( &msgObj, &temp ); THROW_ERROR( "NWC24GetMsgFromId()", err ); (void)sprintf( msgData->from, "%016llu", temp ); for ( i = 0; i < msgData->numTo; ++i ) { err = NWC24ReadMsgToId( &msgObj, i, &temp ); THROW_ERROR( "NWC24ReadMsgToId()", err ); (void)sprintf( msgData->to[i], "%016llu", temp ); } } else { u32 i; err = NWC24ReadMsgFromAddr( &msgObj, msgData->from, MAX_ADDR_SIZE ); THROW_ERROR( "NWC24ReadMsgFromAddr()", err ); for ( i = 0; i < msgData->numTo; ++i ) { err = NWC24ReadMsgToAddr( &msgObj, i, msgData->to[i], MAX_ADDR_SIZE ); THROW_ERROR( "NWC24ReadMsgToAddr()", err ); } } return TRUE; errorHandling: msgData->subject[0] = '\0'; msgData->text[0] = '\0'; msgData->from[0] = '\0'; msgData->numTo = 0; return TRUE; } #undef THROW_ERROR /*---------------------------------------------------------------------------* Name : ReceiveMessage Description : Creates a Wii message and stores it in the Inbox. Arguments : None. Returns : None. *---------------------------------------------------------------------------*/ static void ReceiveMessage( void ) { CreateMessage( NWC24_RECV_BOX ); ReleaseMsgIdList( NWC24_RECV_BOX ); GetMsgIdList( NWC24_RECV_BOX ); ReleaseListedSubjects( NWC24_RECV_BOX ); GetListedSubjects( NWC24_RECV_BOX ); return; } /*---------------------------------------------------------------------------* Name : PostMessage Description : Creates a Wii message and stores it in the Outbox. Arguments : None. Returns : None. *---------------------------------------------------------------------------*/ static void PostMessage( void ) { NWC24Err err; err = NWC24Check(NWC24_USE_MESSAGES); if ( err != NWC24_OK ) { /* Cannot create a message to send */ g_errorCode = NWC24GetErrorCode(); g_state = MB_STATE_ERROR_CONT; return; } CreateMessage( NWC24_SEND_BOX ); ReleaseMsgIdList( NWC24_SEND_BOX ); GetMsgIdList( NWC24_SEND_BOX ); ReleaseListedSubjects( NWC24_SEND_BOX ); GetListedSubjects( NWC24_SEND_BOX ); return; } /*---------------------------------------------------------------------------* Name : CreateMessage Description : Creates a Wii message and stores it in the specified message box. Arguments : None. Returns : None. *---------------------------------------------------------------------------*/ static void CreateMessage( NWC24MsgBoxId mBoxId ) { NWC24Err err; NWC24MsgObj msgObj; const NWC24UserId UID_TO = 9999999999999999ULL; const char* STR_SUBJECT = "TEST MESSAGE"; const char* STR_BODY_TEXT = "Hello Wii Connect 24 World!!\x0d\x0a" "This is a test mail.\x0d\x0a" "Thank you.\x0d\x0a"; err = NWC24InitMsgObj( &msgObj, NWC24_MSGTYPE_WII ); CheckError( "NWC24InitMsgObj()", err ); if ( mBoxId == NWC24_SEND_BOX ) { err = NWC24SetMsgToId( &msgObj, UID_TO ); } else { // Set the local hardware as the recipient if the storage destination is the Inbox. NWC24UserId uidMy; err = NWC24GetMyUserId( &uidMy ); CheckError( "NWC24GetMyUserId()", err ); err = NWC24SetMsgToId( &msgObj, uidMy ); } CheckError( "NWC24SetMsgToId()", err ); err = NWC24SetMsgSubject( &msgObj, STR_SUBJECT, (u32)strlen( STR_SUBJECT ) ); CheckError( "NWC24SetMsgSubject()", err ); err = NWC24SetMsgText( &msgObj, (char*)STR_BODY_TEXT, (u32)strlen( STR_BODY_TEXT ), NWC24_US_ASCII, NWC24_ENC_7BIT ); CheckError( "NWC24SetMsgText()", err ); err = NWC24CommitMsg( &msgObj ); CheckError( "NWC24CommitMsg()", err ); return; } /*---------------------------------------------------------------------------* Name : UpdateMenu Description : This function is called each frame to perform updating other than rendering during menu selection. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateMenu ( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { switch ( g_selectedMenu ) { case MB_MENU_RECV_BOX: { if ( g_numMsgs[MB_TYPE_RECV] != 0 ) { g_state = MB_STATE_RECV_BOX; } break; } case MB_MENU_SEND_BOX: { if ( g_numMsgs[MB_TYPE_SEND] != 0 ) { g_state = MB_STATE_SEND_BOX; } break; } case MB_MENU_RECV_MSG: { g_state = MB_STATE_BEFORE_RECV_MSG; break; } case MB_MENU_POST_MSG: { g_state = MB_STATE_BEFORE_POST_MSG; break; } } } /* (up) button */ if ( input & (KPAD_BUTTON_UP|(PAD_BUTTON_UP<<16)) ) { if ( 0 < g_selectedMenu ) { --g_selectedMenu; g_lineTopOfBodyText = 0; } } /* (down) button */ if ( input & (KPAD_BUTTON_DOWN|(PAD_BUTTON_DOWN<<16)) ) { if (g_selectedMenu < NUM_MSG_BOX_MENUS - 1) { ++g_selectedMenu; g_lineTopOfBodyText = 0; } } /* (B) button */ if ( input & (KPAD_BUTTON_B|(PAD_BUTTON_B<<16)) ) { /* Close the library */ (void)CloseLib(); } return; } /*---------------------------------------------------------------------------* Name : UpdateRecvBox Description : This function is called each frame to perform updating other than rendering during inbox selection. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateRecvBox( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { if ( GetMsgData( &g_msgData, NWC24_RECV_BOX, g_idListBuf[MB_TYPE_RECV][g_idxSelectedId[MB_TYPE_RECV]] ) ) { g_state = MB_STATE_MSG_CONTENT; } else { g_state = MB_STATE_RECV_BOX; } } /* (B) button */ if ( input & (KPAD_BUTTON_B|(PAD_BUTTON_B<<16)) ) { g_state = MB_STATE_MENU; } /* (up) button */ if ( input & (KPAD_BUTTON_UP|(PAD_BUTTON_UP<<16)) ) { if ( 0 < g_idxSelectedId[MB_TYPE_RECV] ) { if ( g_idxSelectedId[MB_TYPE_RECV] == g_idxIdTopOfList[MB_TYPE_RECV] ) { u32 msgId; char* subjectBuf = NULL; --g_idxIdTopOfList[MB_TYPE_RECV]; g_idxSubjectBufStart[MB_TYPE_RECV] = (u32)((g_idxSubjectBufStart[MB_TYPE_RECV] + LIST_BOX_ROWS - 1) % LIST_BOX_ROWS); msgId = g_idListBuf[MB_TYPE_RECV][g_idxIdTopOfList[MB_TYPE_RECV]]; subjectBuf = g_subjectBuf[MB_TYPE_RECV][g_idxSubjectBufStart[MB_TYPE_RECV]]; if ( subjectBuf ) { MEMFreeToAllocator( &DemoAllocator1, subjectBuf ); subjectBuf = NULL; } subjectBuf = MEMAllocFromAllocator( &DemoAllocator1, LEN_SUBJECT_DISP ); (void)NETMemSet( subjectBuf, 0, LEN_SUBJECT_DISP ); (void)ReadSubject( subjectBuf, LEN_SUBJECT_DISP-1, NWC24_RECV_BOX, msgId ); g_subjectBuf[MB_TYPE_RECV][g_idxSubjectBufStart[MB_TYPE_RECV]] = subjectBuf; } --g_idxSelectedId[MB_TYPE_RECV]; g_lineTopOfBodyText = 0; } } /* (down) button */ if ( input & (KPAD_BUTTON_DOWN|(PAD_BUTTON_DOWN<<16)) ) { if ( g_idxSelectedId[MB_TYPE_RECV] < g_numMsgs[MB_TYPE_RECV] - 1 ) { u32 idxIdBottomOfList = g_idxIdTopOfList[MB_TYPE_RECV] + LIST_BOX_ROWS - 1; if ( g_idxSelectedId[MB_TYPE_RECV] == idxIdBottomOfList ) { u32 msgId; char* subjectBuf = NULL; u32 idxSubjectBufEnd; ++g_idxIdTopOfList[MB_TYPE_RECV]; ++idxIdBottomOfList; idxSubjectBufEnd = g_idxSubjectBufStart[MB_TYPE_RECV]; g_idxSubjectBufStart[MB_TYPE_RECV] = (u32)((g_idxSubjectBufStart[MB_TYPE_RECV] + 1) % LIST_BOX_ROWS); msgId = g_idListBuf[MB_TYPE_RECV][idxIdBottomOfList]; subjectBuf = g_subjectBuf[MB_TYPE_RECV][idxSubjectBufEnd]; if ( subjectBuf ) { MEMFreeToAllocator( &DemoAllocator1, subjectBuf ); subjectBuf = NULL; } subjectBuf = MEMAllocFromAllocator( &DemoAllocator1, LEN_SUBJECT_DISP ); (void)NETMemSet( subjectBuf, 0, LEN_SUBJECT_DISP ); (void)ReadSubject( subjectBuf, LEN_SUBJECT_DISP-1, NWC24_RECV_BOX, msgId ); g_subjectBuf[MB_TYPE_RECV][idxSubjectBufEnd] = subjectBuf; } ++g_idxSelectedId[MB_TYPE_RECV]; g_lineTopOfBodyText = 0; } } return; } /*---------------------------------------------------------------------------* Name : UpdateSendBox Description : This function is called each frame to perform updating other than rendering during outbox selection. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateSendBox( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { if ( GetMsgData( &g_msgData, NWC24_SEND_BOX, g_idListBuf[MB_TYPE_SEND][g_idxSelectedId[MB_TYPE_SEND]] ) ) { g_state = MB_STATE_MSG_CONTENT; } else { g_state = MB_STATE_SEND_BOX; } } /* (B) button */ if ( input & (KPAD_BUTTON_B|(PAD_BUTTON_B<<16)) ) { g_state = MB_STATE_MENU; } /* (up) button */ if ( input & (KPAD_BUTTON_UP|(PAD_BUTTON_UP<<16)) ) { if ( 0 < g_idxSelectedId[MB_TYPE_SEND] ) { if ( g_idxSelectedId[MB_TYPE_SEND] == g_idxIdTopOfList[MB_TYPE_SEND] ) { u32 msgId; char* subjectBuf = NULL; --g_idxIdTopOfList[MB_TYPE_SEND]; g_idxSubjectBufStart[MB_TYPE_SEND] = (u32)((g_idxSubjectBufStart[MB_TYPE_SEND] + LIST_BOX_ROWS - 1) % LIST_BOX_ROWS); msgId = g_idListBuf[MB_TYPE_SEND][g_idxIdTopOfList[MB_TYPE_SEND]]; subjectBuf = g_subjectBuf[MB_TYPE_SEND][g_idxSubjectBufStart[MB_TYPE_SEND]]; if ( subjectBuf ) { MEMFreeToAllocator( &DemoAllocator1, subjectBuf ); subjectBuf = NULL; } subjectBuf = MEMAllocFromAllocator( &DemoAllocator1, LEN_SUBJECT_DISP ); (void)NETMemSet( subjectBuf, 0, LEN_SUBJECT_DISP ); (void)ReadSubject( subjectBuf, LEN_SUBJECT_DISP-1, NWC24_SEND_BOX, msgId ); g_subjectBuf[MB_TYPE_SEND][g_idxSubjectBufStart[MB_TYPE_SEND]] = subjectBuf; } --g_idxSelectedId[MB_TYPE_SEND]; g_lineTopOfBodyText = 0; } } /* (down) button */ if ( input & (KPAD_BUTTON_DOWN|(PAD_BUTTON_DOWN<<16)) ) { if ( g_idxSelectedId[MB_TYPE_SEND] < g_numMsgs[MB_TYPE_SEND] - 1 ) { u32 idxIdBottomOfList = g_idxIdTopOfList[MB_TYPE_SEND] + LIST_BOX_ROWS - 1; if ( g_idxSelectedId[MB_TYPE_SEND] == idxIdBottomOfList ) { u32 msgId; char* subjectBuf = NULL; u32 idxSubjectBufEnd; ++g_idxIdTopOfList[MB_TYPE_SEND]; ++idxIdBottomOfList; idxSubjectBufEnd = g_idxSubjectBufStart[MB_TYPE_SEND]; g_idxSubjectBufStart[MB_TYPE_SEND] = (u32)((g_idxSubjectBufStart[MB_TYPE_SEND] + 1) % LIST_BOX_ROWS); msgId = g_idListBuf[MB_TYPE_SEND][idxIdBottomOfList]; subjectBuf = g_subjectBuf[MB_TYPE_SEND][idxSubjectBufEnd]; if ( subjectBuf ) { MEMFreeToAllocator( &DemoAllocator1, subjectBuf ); subjectBuf = NULL; } subjectBuf = MEMAllocFromAllocator( &DemoAllocator1, LEN_SUBJECT_DISP ); (void)NETMemSet( subjectBuf, 0, LEN_SUBJECT_DISP ); (void)ReadSubject( subjectBuf, LEN_SUBJECT_DISP-1, NWC24_SEND_BOX, msgId ); g_subjectBuf[MB_TYPE_SEND][idxSubjectBufEnd] = subjectBuf; } ++g_idxSelectedId[MB_TYPE_SEND]; g_lineTopOfBodyText = 0; } } return; } /*---------------------------------------------------------------------------* Name : UpdateMsgContent Description : This function is called each frame to perform updating other than rendering during message selection. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateMsgContent( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { g_state = MB_STATE_DELETE_MSG; } /* (B) button */ if ( input & (KPAD_BUTTON_B|(PAD_BUTTON_B<<16)) ) { g_state = (g_selectedMenu == MB_MENU_RECV_BOX) ? MB_STATE_RECV_BOX : MB_STATE_SEND_BOX; } /* (up) button */ if ( input & (KPAD_BUTTON_UP|(PAD_BUTTON_UP<<16)) ) { if ( 0 < g_lineTopOfBodyText ) { --g_lineTopOfBodyText; } } /* (down) button */ if ( input & (KPAD_BUTTON_DOWN|(PAD_BUTTON_DOWN<<16)) ) { if ( (s32)g_lineTopOfBodyText < (s32)(g_numLinesBodyText - TEXT_BOX_ROWS) ) { ++g_lineTopOfBodyText; } } return; } /*---------------------------------------------------------------------------* Name : UpdateDeleteMsg Description : This function is called each frame to perform updating other than rendering when delete message is selected. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateDeleteMsg( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { NWC24Err err; NWC24MsgBoxId mBoxId = (g_selectedMenu == MB_MENU_RECV_BOX) ? NWC24_RECV_BOX : NWC24_SEND_BOX; MsgBoxType mbType = (g_selectedMenu == MB_MENU_RECV_BOX) ? MB_TYPE_RECV : MB_TYPE_SEND; err = NWC24DeleteMsg( mBoxId, g_idListBuf[mbType][ g_idxSelectedId[mbType] ] ); if ( err == NWC24_ERR_PROTECTED ) { OSReport("Can't delete this message. (protected)\n"); g_state = MB_STATE_MSG_CONTENT; } else { CheckError( "NWC24DeleteMsg()", err ); } ReleaseMsgIdList( mBoxId ); GetMsgIdList( mBoxId ); if ( g_numMsgs[mbType] == 0 ) { g_idxSelectedId[mbType] = 0; g_state = MB_STATE_MENU; } else { if ( g_numMsgs[mbType] <= g_idxSelectedId[mbType] ) { g_idxSelectedId[mbType] = g_numMsgs[mbType] - 1; } if ( g_idxIdTopOfList[mbType] != 0 && g_numMsgs[mbType] - g_idxIdTopOfList[mbType] < LIST_BOX_ROWS ) { g_idxIdTopOfList[mbType] = g_numMsgs[mbType] - LIST_BOX_ROWS; } g_state = (g_selectedMenu == MB_MENU_RECV_BOX) ? MB_STATE_RECV_BOX : MB_STATE_SEND_BOX; } ReleaseListedSubjects( mBoxId ); GetListedSubjects( mBoxId ); } /* (B) button */ if ( input & (KPAD_BUTTON_B|(PAD_BUTTON_B<<16)) ) { g_state = MB_STATE_MSG_CONTENT; } return; } /*---------------------------------------------------------------------------* Name : UpdateBeforeRecvMsg Description : This function is called each frame to perform updating other than rendering when receive message is selected. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateBeforeRecvMsg( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { ReceiveMessage(); g_state = MB_STATE_DONE_RECV_MSG; } /* (B) button */ if ( input & (KPAD_BUTTON_B|(PAD_BUTTON_B<<16)) ) { g_state = MB_STATE_MENU; } return; } /*---------------------------------------------------------------------------* Name : UpdateBeforePostMsg Description : This function is called each frame to perform updating other than rendering when send message is selected. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateBeforePostMsg( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { PostMessage(); g_state = MB_STATE_DONE_POST_MSG; } /* (B) button */ if ( input & (KPAD_BUTTON_B|(PAD_BUTTON_B<<16)) ) { g_state = MB_STATE_MENU; } return; } /*---------------------------------------------------------------------------* Name : UpdateDoneRecvMsg Description : This function is called each frame to perform updating other than rendering after the message is received. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateDoneRecvMsg( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { g_state = MB_STATE_MENU; } return; } /*---------------------------------------------------------------------------* Name : UpdateDonePostMsg Description : This function is called each frame to perform updating other than rendering after the message is sent. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateDonePostMsg( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { g_state = MB_STATE_MENU; } return; } /*---------------------------------------------------------------------------* Name : UpdateLibClosed Description : This function is called each frame while closing the library to perform non-rendering updates. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateLibClosed( u32 input ) { /* (A) button */ if ( input & (KPAD_BUTTON_A|(PAD_BUTTON_A<<16)) ) { g_state = MB_STATE_WAIT_OPEN; } return; } /*---------------------------------------------------------------------------* Name : UpdateWaitOpen Description : This function is called each frame while waiting for the open state to perform non-rendering updates. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateWaitOpen( u32 input ) { static u32 waitCount = 0; (void)input; if ( waitCount == 0 ) { if ( OpenLib() ) { /* Get the state after being reopened */ ReleaseMsgIdList( NWC24_RECV_BOX ); ReleaseMsgIdList( NWC24_SEND_BOX ); ReleaseListedSubjects( NWC24_RECV_BOX ); ReleaseListedSubjects( NWC24_SEND_BOX ); GetMsgIdList( NWC24_RECV_BOX ); GetMsgIdList( NWC24_SEND_BOX ); GetListedSubjects( NWC24_RECV_BOX ); GetListedSubjects( NWC24_SEND_BOX ); g_state = MB_STATE_MENU; return; } } /* processing to retry once per second */ ++waitCount; waitCount %= 60; /* It is recommended to wait for approximately 10 to 20 seconds and then briefly display a message prompting the user to try again later. */ return; } /*---------------------------------------------------------------------------* Name : UpdateErrorMsg Description : This function is called each frame while displaying an error to perform non-rendering updates. Arguments : input - Input data from controller buttons (KPAD and PAD) Returns : None. *---------------------------------------------------------------------------*/ static void UpdateErrorMsg( u32 input ) { /* (B) button */ if ( input & (KPAD_BUTTON_B|(PAD_BUTTON_B<<16)) ) { g_state = MB_STATE_MENU; } return; } /*======== End of MsgViewerUpdate.c ========*/