/*---------------------------------------------------------------------------*
  Project:  NitroSDK - wireless_shared - demos - mbp
  File:     mbp.h


  Copyright 2003,2004 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: mbp.h,v $
  Revision 1.2  2004/11/24 06:15:12  yosizaki
  rename MB_StartParentEx/MB_EndEx

  Revision 1.1  2004/11/12 09:02:39  yosizaki
  (none)

  $NoKeywords: $
 *---------------------------------------------------------------------------*/

#ifndef NITROSDK_DEMO_WIRELESSSHARED_MBP_H_
#define NITROSDK_DEMO_WIRELESSSHARED_MBP_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <nitro/mb.h>


/******************************************************************************/
/* constant */

/*
 * Game group ID
 *
 * Now with MBGameRegistry structure, it is possible to set GGID for each file, 
 * and the specification with MB_Init() may lose its significance in the future.
 */

/*
 * Channel which the parent distributes
 *
 * The multiboot child goes around every possible channels, 
 * so any of the values allowed with WM library (in the current condition, 3, 8, and 13) is accepted.
 *
 * Make it variable to avoid the communication confusion in the user application. 
 * The timing of the channel change depends on the application, 
 * but for example, a possible method is to set the trigger by a user pressing "restart" 
 * when the response is bad.
 */

/* The maximum number of children that can be connected */
#define MBP_CHILD_MAX       (15)

/* DMA number to be allocated to MB library. */
#define MBP_DMA_NO          (2)

/*
 * Switch that uses MB_StartParentFromIdle() / MB_EndToIdle() in MB library.
 * It is possible to go through the multiboot process in IDLE state.
 */
#define	MPB_USING_MB_EX



/* MP parent state */
typedef struct
{
    u16 state;              // Parent state 
    u16 connectChildBmp;    // Flag for all children that are connected
    u16 requestChildBmp;    // Flag for children that are requesting entry
    u16 entryChildBmp;      // Flag for children that are waiting for data
    u16 downloadChildBmp;   // Flag for children that are downloading data
    u16 bootableChildBmp;   // Flag for children that has completed downloading
    u16 rebootChildBmp;     // Flag for children that sent boot
} MBPState;


/* Connected child state */
typedef struct
{
    MBUserInfo user;
    u8 macAddress[ 6 ];
    u16 playerNo;
} MBPChildInfo;


/* Value of this demo game sequence state  */
enum
{
    MBP_STATE_STOP,          // Stop state
    MBP_STATE_IDLE,          // Idle state (Init done)
    MBP_STATE_ENTRY,         // Child entry accepting
    MBP_STATE_DATASENDING,   // MP data transmitting
    MBP_STATE_REBOOTING,     // Child rebooting
    MBP_STATE_COMPLETE,      // Child reboot completed
    MBP_STATE_CANCEL,        // Multiboot cancellation processing
    MBP_STATE_ERROR,         // Error generated
    MBP_STATE_NUM
};

/* Type of the connection status bit map */
typedef enum
{
    MBP_BMPTYPE_CONNECT,      // Connected child information
    MBP_BMPTYPE_REQUEST,      // Information of the child requesting connection
    MBP_BMPTYPE_ENTRY,        // Information of the child waiting for downloading after the entry
    MBP_BMPTYPE_DOWNLOADING,  // Information on the child that is downloading
    MBP_BMPTYPE_BOOTABLE,     // Bootable child
    MBP_BMPTYPE_REBOOT,       // Reboot completed child
    MBP_BMPTYPE_NUM
} MBPBmpType;

/* Multiboot child status */
typedef enum
{
    MBP_CHILDSTATE_NONE,        // No connection
    MBP_CHILDSTATE_CONNECTING,  // Connecting
    MBP_CHILDSTATE_REQUEST,     // Requesting connection
    MBP_CHILDSTATE_ENTRY,       // Entering
    MBP_CHILDSTATE_DOWNLOADING, // Downloading
    MBP_CHILDSTATE_BOOTABLE,    // Boot waiting
    MBP_CHILDSTATE_REBOOT,      // Rebooting
    MBP_CHILDSTATE_NUM
} MBPChildState;


/******************************************************************************/
/* variable */

/* Initializing parent */
void MBP_Init( u32 ggid, u16 tgid );
void MBP_Start( const MBGameRegistry *gameInfo, u16 channel );

/* Parent main process in each frame */
const MBPState* MBP_Main( void );

void MBP_KickChild( u16 child_aid );
void MBP_AcceptChild( u16 child_aid );
void MBP_StartRebootAll( void );
void MBP_StartDownload( u16 child_aid );
void MBP_StartDownloadAll( void );
BOOL MBP_IsBootableAll( void );

void MBP_Cancel( void );

u16  MBP_GetState( void );
u16  MBP_GetChildBmp( MBPBmpType bmpType );
void MBP_GetConnectState( MBPState *state );
const u8* MBP_GetChildMacAddress( u16 aid );
MBPChildState MBP_GetChildState( u16 aid );
u16 MBP_GetPlayerNo( const u8* macAddress );
const MBPChildInfo* MBP_GetChildInfo( u16 child_aid );


#ifdef __cplusplus
}/* extern "C" */
#endif

#endif // NITROSDK_DEMO_WIRELESSSHARED_MBP_H_


