/*---------------------------------------------------------------------------*
  Project:  NITRO-System - build - demos - fnd - archive
  File:     main.c

  Copyright 2004,2005 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: main.c,v $
  Revision 1.6  01/21/2005 05:08:06  kitamurs
  Changed year

  Revision 1.5  11/05/2004 09:47:54  nishida
  Revised Project in the file header

  Revision 1.4  11/04/2004 09:39:25  nishida
  Fixed spelling error in the file header

  Revision 1.3  10/21/2004 05:28:48  nishida
  Added a comment about calling DC_FlushRange

  Revision 1.2  07/23/2004 05:43:56  nishida
  Added an example of specifying an index and reading data. Also added comments.

  Revision 1.1  05/26/2004 09:29:50  nishida
  Registered the initial version.

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

#include "sdk_init.h"
#include "nns_util.h"

// Index definition file for archive
#include "picture.naix"


static void	LoadPicture(void);

/* -------------------------------------------------------------------------
  Name:         NitroMain

  Description:  A sample program that reads BG data from an archive and
  				displays it on the screen.

  Arguments:    None.

  Returns:      None.
   ------------------------------------------------------------------------- */
void
NitroMain(void)
{
    InitSystem();
	InitMemory();
    InitVRAM();

    InitDisplay();
	LoadPicture();
	G2_SetBG0Offset(0,20);

    for(;;)
    {
		SVC_WaitVBlankIntr();
		ReadGamePad();
	}
}

/*---------------------------------------------------------------------------*
  Name:         LoadPicture

  Description:  Loads one archive, then transmits the data for each character,
  				color palette, and screen stored inside to the VRAM.

  				Removes the archive after transferring the data to VRAM.

  Arguments:    None.

  Returns:      None.
 *---------------------------------------------------------------------------*/
static void
LoadPicture(void)
{
	NNSFndArchive* archive;

	// Reads an archive into main memory and mounts it in the file system.
	// The call to DC_FlushRange() occurs within LoadArchive().
	// LoadArchive() is in nns_util.c
	if ((archive = LoadArchive("PCT", "/data/picture.narc")) != NULL)
	{
		// Specifies the path name and fetches data.
		void* chrData = NNS_FndGetArchiveFileByName("PCT:/picture/dog/dog256.chr");
		void* scnData = NNS_FndGetArchiveFileByName("PCT:/picture/dog/dog256.scn");

		// Specifies the index and fetches data.
		void* palData = NNS_FndGetArchiveFileByIndex(archive, NARC_picture_dog256_pal);

		// Load data into VRAM
		GX_LoadBG0Char(chrData, 0, 0x10000);
    	GX_LoadBG0Scr (scnData, 0, 0x00800);
		GX_LoadBGPltt (palData, 0, 0x00200);

		// The data in main memory is not needed after being loaded into VRAM, so
		// delete the archive.
		// RemoveArchive is in nns_util.c
		RemoveArchive(archive);
	}
}

