//ds2_main.c
#include <libBAG.h>


TiledBG_t background;
void ds2_main(void){
	if(!BAG_Init(1))
		ds2_plug_exit();

	BAG_DBG_Init(NULL, DBG_HALT | DBG_LIB);


	BAG_DBG_Msg("Loading BG\n");
	//load tile graphics and tile map from /tilegfx/ folder on sd card
	BAG_TileBG_LoadBG("/tilegfx/zelda-tiles", "/tilegfx/zelda-map.tbag", &background);

	//make backround limited to a 8 x 8 tile bg at position 64,32 on screen
	BAG_TileBG_SetProperties(&background, 8, 8, 64, 32);


	BAG_DBG_Msg("Drawing BG\n");
	BAG_TileBG_DrawBG(down_screen_addr, &background, 0, 0);
	BAG_DBG_Msg("flipping screen\n");
	ds2_flipScreen(DOWN_SCREEN, 1);


	int scrollX = 0, scrollY = 0;
	while(1){

		scrollX += (Pad.Held.Right - Pad.Held.Left) << 2;
		scrollY += (Pad.Held.Down - Pad.Held.Up) << 2;

		if(Pad.key){
			ds2_clearScreen(DOWN_SCREEN, RGB15(0,0,0));
			BAG_TileBG_DrawBG(down_screen_addr, &background, scrollX, scrollY);
			ds2_flipScreen(DOWN_SCREEN, 1);
		}



		BAG_Update();
	}
}

