/*---------------------------------------------------------------------------*
  Project:  NitroSDK - MB - demos - multiboot
  File:     common.c

  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: common.c,v $
  Revision 1.13  2004/10/05 06:47:54  sato_masaki
  Added setup menu. Made several other small revisions.

  Revision 1.12  2004/09/30 03:05:12  sato_masaki
  - Changed so that name of parent device is obtained from NVRAM.
  - Changed so that you cycle through channels when initializing.

  Revision 1.11  2004/09/14 23:56:23  yosizaki
  change MBGameregistry's member to Unicode.

  Revision 1.10  2004/09/14 02:54:07  miya
  Included sign

  Revision 1.9  2004/09/13 06:25:40  yosizaki
  change balldemo -> pol_toon

  Revision 1.8  2004/09/09 14:03:31  sato_masaki
  Revision due to mb library changes

  Revision 1.7  2004/09/08 00:23:27  sato_masaki
  Returned the number of registered MBGameRegistry to 2

  Revision 1.6  2004/08/25 04:28:20  sato_masaki
  Implemented the MB_CommStartSending function

  Revision 1.5  2004/08/23 07:27:27  yasu
  Workaround for pushing A button in IPL

  Revision 1.4  2004/08/19 14:47:18  yosiokat
  Will try to add a line break in the MBGameRegistry game contents description

  Revision 1.3  2004/08/19 02:43:19  yosizaki
  change type of MBUserInfo.

  Revision 1.2  2004/08/12 09:57:34  yosiokat
  Changed so that the icon data is designated by the file path

  Revision 1.1  2004/08/10 07:31:53  yosizaki
  (none)

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


#include <nitro.h>


#include "common.h"


/*
 * The common features used on this demo as a whole
 */


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

/* The program information array that this demo causes to download */
const MBGameRegistry mbGameList[GAME_PROG_MAX] = {
    {
	"/em.srl",					// The file path of the multiboot child device binary
	L"edgeDemo",				// The game name
	L"edgemarking demo\ntesttesttest",	// Description of the game contents
	"/data/icon.char",				// The file path of the icon character data
	"/data/icon.plt",				// The file path of the icon palette data
	0x12123434,					// GameGroupID(GGID)
	16,						// The maximum number of players
    },
    {
	"/pol_toon.srl",
	L"PolToon",
	L"toon rendering",
	"/data/icon.char",
	"/data/icon.plt",
	0x56567878,
	8,
    },
} ;


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

/* The work region allocated to the MB library */
u32	cwork[ MB_SYSTEM_BUF_SIZE / sizeof(u32) ];

/* The game sequence state of this demo */
u8 prog_state;


/******************************************************************************/
/* function */

/* Key trigger detection */
u16 ReadKeySetTrigger(u16 keyset)
{
    static u16 cont = 0xffff;    /* Steps for holding down the A button in IPL */
    u16 trigger  = (u16)(keyset & (keyset ^ cont));
    cont = keyset;
    return trigger;
}

/* rotation of val value in min - max range by offset amount */
BOOL RotateU8(u8 *val, u8 min, u8 max, s8 offset)
{
	int lVal = (int)*val - min;
	int div = max - min + 1;
	
	if ( div == 0 ) return FALSE;
	
	lVal = (lVal + offset + div)%div + min;
	
	*val = (u8)lVal;
	return TRUE;
}

