示例#1
0
void PA_16bitSwapBuffer(u8 screen){
	pa16bitbuffer[screen] = !pa16bitbuffer[screen];
	PA_DrawBg[screen] =  (u16*)(0x06000000 + (0x200000 *  screen) + (192-pa16bitbuffer[screen]*192) * 512);
	PA_DrawBg32[screen] = (u32*)PA_DrawBg[screen];
	_REG16(REG_BGCNT(screen, 3)) &= ~(BG_BMP_BASE(7));
	_REG16(REG_BGCNT(screen, 3)) |= BG_BMP_BASE(pa16bitbuffer[screen]*6);
}
示例#2
0
文件: screen.c 项目: LemonBoy/PrexDS
void screen_init(void)
{
	DISPSTAT = (1 << 3);
	/* Initialize the screens */
	POWCNT1 = 0x820E;
	/* Setup the screens */
	DISPLAY_CR = 0x10005 | (1 << 11);
	SUB_DISPLAY_CR = 0x10005 | (1 << 11);
	/* Setup the vram banks */
	VRAM_A_CR = 0x80 | 1;
	VRAM_C_CR = 0x80 | 4;
	/* Setup the backgrounds */
	background_main.control[3] = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_WRAP_ON;
	background_sub.control[3] = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_WRAP_ON;
	/* Setup the matrices for both screens */
	background_main.bg3_rotation.xdy = 0;
	background_main.bg3_rotation.xdx = 1 << 8;
	background_main.bg3_rotation.ydx = 0;
	background_main.bg3_rotation.ydy = 1 << 8;
	background_main.bg3_rotation.cx = 0;
	background_main.bg3_rotation.cy = 0;		
 
	background_sub.bg3_rotation.xdy = 0;
	background_sub.bg3_rotation.xdx = 1 << 8;
	background_sub.bg3_rotation.ydx = 0;
	background_sub.bg3_rotation.ydy = 1 << 8;	
	background_sub.bg3_rotation.cx = 0;
	background_sub.bg3_rotation.cy = 0;
}
示例#3
0
文件: render.cpp 项目: jsykes/starkas
void Render::InitBackgrounds()
{
    /*  Set up affine background 3 on main as a 16-bit color background. */
    REG_BG3CNT = BG_BMP16_256x256 |
                 BG_BMP_BASE(0) | // The starting place in memory
                 BG_PRIORITY(3); // A low priority

    /*  Set the affine transformation matrix for the main screen background 3
     *  to be the identity matrix.
     */
    REG_BG3PA = 1 << 8;
    REG_BG3PB = 0;
    REG_BG3PC = 0;
    REG_BG3PD = 1 << 8;

    /*  Place main screen background 3 at the origin (upper left of the
     *  screen).
     */
    REG_BG3X = 0;
    REG_BG3Y = 0;

    /*  Set up affine background 2 on main as a 16-bit color background. */
    REG_BG2CNT = BG_BMP16_256x256 |
                 BG_BMP_BASE(8) | // The starting place in memory
                 BG_PRIORITY(2);  // A higher priority

    /*  Set the affine transformation matrix for the main screen background 3
     *  to be the identity matrix.
     */
    REG_BG2PA = 1 << 8;
    REG_BG2PB = 0;
    REG_BG2PC = 0;
    REG_BG2PD = 1 << 8;

    /*  Place main screen background 2 in an interesting place. */
    REG_BG2X = -(SCREEN_WIDTH / 2 - 32) << 8;
    REG_BG2Y = -32 << 8;

    /*  Set up affine background 3 on the sub screen as a 16-bit color
     *  background.
     */
    REG_BG3CNT_SUB = BG_BMP16_256x256 |
                     BG_BMP_BASE(9) | // The starting place in memory
                     BG_PRIORITY(3); // A low priority

    /*  Set the affine transformation matrix for the sub screen background 3
     *  to be the identity matrix.
     */
    REG_BG3PA_SUB = 1 << 8;
    REG_BG3PB_SUB = 0;
    REG_BG3PC_SUB = 0;
    REG_BG3PD_SUB = 1 << 8;

    /*
     *  Place main screen background 3 at the origin (upper left of the screen)
     */
    REG_BG3X_SUB = 0;
    REG_BG3Y_SUB = 0;
}
示例#4
0
/* Fondo sistema konfiguratzeko prozedura */
void hasieratuFondoak() {
    /*  Pantaila nagusiko 3 fondoaren afinitatea ezarri 16 biteko koloretarako. */
    REG_BG3CNT = BG_BMP16_256x256 |
                 BG_BMP_BASE(0) | // Memoriako hasierako helbidea
                 BG_PRIORITY(3); // Lehentasun baxua

    /*  Pantaila nagusiko 3 fondoaren transformazio matrizeari identitate matrizea esleitu. */
    REG_BG3PA = 1 << 8;
    REG_BG3PB = 0;
    REG_BG3PC = 0;
    REG_BG3PD = 1 << 8;

/*******************************************************************************************/
    /*  Pantaila nagusiko 3 fondoaren egoera definitu. */
    /*  Grafikoa beste posizio batean jarri nahi izanez gero hau aldatu beharko da. */
    REG_BG3X = 0;
    REG_BG3Y = 0;
/*******************************************************************************************/

    /*  Pantaila nagusiko 3 fondoaren afinitatea ezarri 16 biteko koloretarako. */
    REG_BG2CNT = BG_BMP16_128x128 |
                 BG_BMP_BASE(8) | // Memoriako hasierako helbidea
                 BG_PRIORITY(2);  // Lehentasun baxua

    /*  Pantaila nagusiko 3 fondoaren transformazio matrizeari identitate matrizea esleitu. */
    REG_BG2PA = 1 << 8;
    REG_BG2PB = 0;
    REG_BG2PC = 0;
    REG_BG2PD = 1 << 8;

/*******************************************************************************************/
    /*  Pantaila nagusiko 3 fondoaren egoera definitu. */
    /*  Grafikoa beste posizio batean jarri nahi izanez gero hau aldatu beharko da. */
    REG_BG2X = -(SCREEN_WIDTH / 2 - 32) << 8;
    REG_BG2Y = -32 << 8;
/*******************************************************************************************/

    /*  Bigarren mailako pantailako 3 fondoaren afinitatea ezarri 16 biteko koloretarako. */
    REG_BG3CNT_SUB = BG_BMP16_256x256 |
                     BG_BMP_BASE(0) | // Memoriako hasierako helbidea
                     BG_PRIORITY(3); // Lehentasun baxua

    /*  Bigarren mailako pantailako 3 fondoaren transformazio matrizeari identitate matrizea esleitu. */
    REG_BG3PA_SUB = 1 << 8;
    REG_BG3PB_SUB = 0;
    REG_BG3PC_SUB = 0;
    REG_BG3PD_SUB = 1 << 8;

/*******************************************************************************************/
    /*  Bigarren mailako pantailako 3 fondoaren egoera definitu. */
    /*  Grafikoa beste posizio batean jarri nahi izanez gero hau aldatu beharko da. */
    REG_BG3X_SUB = 0;
    REG_BG3Y_SUB = 0;
/*******************************************************************************************/
}
示例#5
0
文件: boot9.cpp 项目: suloku/fas1
void gbaFrame(void)
{
  u16* frame=NULL;
  cBMP15 frameBMP=createBMP15FromFile("/GBA/gbaframe.bmp");
  if(frameBMP.valid()&&frameBMP.width()==SCREEN_WIDTH&&frameBMP.height()==SCREEN_HEIGHT)
  {
    frame=(u16*)malloc(SCREEN_WIDTH*SCREEN_HEIGHT*2);
    memcpy(frame,frameBMP.buffer(),SCREEN_WIDTH*SCREEN_HEIGHT*2); //tricky thing
  }

  videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG_0x06200000, VRAM_D_LCD);

  // for the main screen
  BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_WRAP_OFF;
  BG3_XDX = 1 << 8; //scale x
  BG3_XDY = 0; //rotation x
  BG3_YDX = 0; //rotation y
  BG3_YDY = 1 << 8; //scale y
  BG3_CX = 0; //translation x
  BG3_CY = 0; //translation y

  if(frame)
  {
    dmaCopy(frame,(void*)BG_BMP_RAM(0),SCREEN_WIDTH*SCREEN_HEIGHT*2);
    dmaCopy(frame,(void*)BG_BMP_RAM(8),SCREEN_WIDTH*SCREEN_HEIGHT*2);
    free(frame);
  }
  else
  {
    memset((void*)BG_BMP_RAM(0),0,0x18000);
    memset((void*)BG_BMP_RAM(8),0,0x18000);
  }
}
示例#6
0
void CGbaLoader::LoadBorder(void)
{
  videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
  vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG_0x06200000, VRAM_D_LCD);

  // for the main screen
  REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_WRAP_OFF;
  REG_BG3PA = 1 << 8; //scale x
  REG_BG3PB = 0; //rotation x
  REG_BG3PC = 0; //rotation y
  REG_BG3PD = 1 << 8; //scale y
  REG_BG3X = 0; //translation x
  REG_BG3Y = 0; //translation y

  memset((void*)BG_BMP_RAM(0),0,0x18000);
  memset((void*)BG_BMP_RAM(8),0,0x18000);

  cBMP15 frameBMP=createBMP15FromFile(SFN_GBAFRAME);
  if(frameBMP.valid()&&frameBMP.width()==SCREEN_WIDTH&&frameBMP.height()==SCREEN_HEIGHT)
  {
    DC_FlushRange(frameBMP.buffer(),SCREEN_WIDTH*SCREEN_HEIGHT*2);
    dmaCopy(frameBMP.buffer(),(void*)BG_BMP_RAM(0),SCREEN_WIDTH*SCREEN_HEIGHT*2);
    dmaCopy(frameBMP.buffer(),(void*)BG_BMP_RAM(8),SCREEN_WIDTH*SCREEN_HEIGHT*2);
  }
}
示例#7
0
void init_pda()
{

  // set the sub background up for text display (we could just print to one
  // of the main display text backgrounds just as easily
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG2_ACTIVE);
  SUB_BG2_CR = BG_BMP8_256x256 | BG_WRAP_ON | BG_BMP_BASE(4);
  SUB_BG3_CR = BG_BMP8_256x256 | BG_WRAP_ON;

  SUB_BG3_XDX = 1 << 8;
  SUB_BG3_XDY = 0;
  SUB_BG3_YDX = 0;
  SUB_BG3_YDY = 1 << 8;

  SUB_BG2_XDX = 1 << 8;
  SUB_BG2_XDY = 0;
  SUB_BG2_YDX = 0;
  SUB_BG2_YDY = 1 << 8;
  

  SUB_BG3_CX = 0;
  SUB_BG3_CY = 0; //32 << 8;

  SUB_BG2_CX = 0;//2000;
  SUB_BG2_CY = 0;//2000; //32 << 8;

  for(int i = 0; i < 256; ++i)
    BG_PALETTE_SUB[i] = ((u16*)subscreen_pal_bin)[i];

  for(int i = 0; i < 256*192/2; ++i)
    ((u16*)BG_BMP_RAM_SUB(4))[i] = ((u16*)map_img_bin)[i];

  for(int i = 0; i < 256*256/2; ++i)
    ((u16*)BG_BMP_RAM_SUB(0))[i] = ((u16*)realmap_img_bin)[i];
}
示例#8
0
void init_doorminigame()
{
  videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG2_ACTIVE);  

  vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_SPRITE, //VRAM_B_MAIN_BG_0x6020000,
                   VRAM_C_SUB_BG, VRAM_D_MAIN_BG_0x6020000);

  SUB_BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(4);
  SUB_BG3_CR = BG_BMP8_256x256;

  SUB_BG3_XDX = 1 << 8;
  SUB_BG3_XDY = 0;
  SUB_BG3_YDX = 0;
  SUB_BG3_YDY = 1 << 8;

  SUB_BG2_XDX = 1 << 8;
  SUB_BG2_XDY = 0;
  SUB_BG2_YDX = 0;
  SUB_BG2_YDY = 1 << 8;

  SUB_BG3_CX = 0;
  SUB_BG3_CY = 0; //32 << 8;

  SUB_BG2_CX = 0;//2000;
  SUB_BG2_CY = 0;//2000; //32 << 8;

  for(int i = 0; i < 256; ++i)
    BG_PALETTE_SUB[i] = ((u16*)doorbg_pal_bin)[i];

  for(int i = 0; i < 256*256/2; ++i)
    ((u16*)BG_BMP_RAM_SUB(0))[i] = ((u16*)doorbg_img_bin)[i];

  for(int i = 0; i < 256*256/2; ++i)
    ((u16*)BG_BMP_RAM_SUB(4))[i] = ((u16*)doorfg_img_bin)[i];
}
示例#9
0
Graphics::Graphics(void) {
	//irqInit(); 
	//irqSet(IRQ_VBLANK, 0); 
	setColor(RGB15(20,31,10) | (1<<15));
			 
	videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
	//videoSetModeSub(MODE_2_2D | DISPLAY_BG3_ACTIVE);
			
	vramSetBankA(VRAM_A_MAIN_BG);
	vramSetBankB(VRAM_B_MAIN_BG);
	//vramSetBankC(VRAM_C_SUB_BG);
			
			
	REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0);
	REG_BG3PA  = 1 << 8;
	REG_BG3PB  = 0;
	REG_BG3PC  = 0;
	REG_BG3PD  = 1 << 8;
	videoRam   = BG_BMP_RAM(0);
			
			
	//REG_BG3CNT_SUB = BG_BMP16_256x256 | BG_BMP_BASE(0);
	//REG_BG3PA_SUB = 1<< 8;
	//REG_BG3PB_SUB = 0;
	//REG_BG3PC_SUB = 0;
	//REG_BG3PD_SUB = 1 << 8;
	//memClone   = BG_BMP_RAM_SUB(2);
}
示例#10
0
void PA_Init16bitDblBuffer(u8 screen, u8 bg_priority){

	PA_Default16bitInit(screen, bg_priority);

	DMA_Copy(Blank, (0x06000000 + (0x200000 *  screen)), 256*384, DMA_16NOW);
	PA_DrawBg[screen] =  (u16*)(0x06000000 + (0x200000 *  screen) + 192 * 512);
	PA_DrawBg32[screen] = (u32*)PA_DrawBg[screen];
		
	pa16bitbuffer[screen] = 0; // First buffer...
	charsetstart[screen] = 0; // On se réserve la moitié de la mémoire...

	_REG16(REG_BGCNT(screen, 3)) = bg_priority | BG_BMP16_256x256 | BG_BMP_BASE(0);
	PA_SetDrawSize(screen, 1);
	vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,VRAM_B_MAIN_BG_0x06020000,VRAM_C_SUB_BG,VRAM_D_SUB_SPRITE);
}
示例#11
0
void PA_Init16bitBg(u8 screen, u8 bg_priority){

	PA_Default16bitInit(screen, bg_priority);

	PA_DrawBg[screen] =  (u16*)(0x06000000 + (0x200000 *  screen) + 128 * 256);
	PA_DrawBg32[screen] = (u32*)PA_DrawBg[screen];
	DMA_Copy(Blank, (void*)PA_DrawBg[screen], 256*192, DMA_16NOW);
		
	//this is just used so we can write red color bits to one frame and green to the 
	//other
	
	charsetstart[screen] = 2; // On se réserve la moitié de la mémoire...
	charblocks[screen][16] = 1; // Block la mémoire

	_REG16(REG_BGCNT(screen, 3)) = bg_priority | BG_BMP16_256x256 | BG_BMP_BASE(2);

	PA_SetDrawSize(screen, 1);
}
示例#12
0
文件: dual3D.c 项目: Almamu/portalDS
void initD3D()
{
	int x,y,i;
	
	videoSetMode(MODE_3_3D);
	videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_2D_BMP_256);
    vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_SUB_BG,VRAM_D_SUB_SPRITE);
	vramSetBankH(VRAM_H_LCD);
	vramSetBankI(VRAM_I_LCD);
	
	REG_BG0CNT = BG_PRIORITY(1);
	
	REG_BG2CNT_SUB = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(1);
        REG_BG2PA_SUB = 1 << 8;
        REG_BG2PB_SUB = 0;
        REG_BG2PC_SUB = 0;
        REG_BG2PD_SUB = 1 << 8;
		
        REG_BG2X_SUB = 0;
        REG_BG2Y_SUB = 0;
	
	initSprites();
	
	d3dSpriteRotations[0].hdx=256;
	d3dSpriteRotations[0].hdy=0;
	d3dSpriteRotations[0].vdx=0;
	d3dSpriteRotations[0].vdy=256;
	
	i=0;
	
	for (y = 0; y < 3; y++)
	{
		for (x = 0; x < 4; x++) {
			d3dSprites[i].attribute[0] = ATTR0_BMP | ATTR0_SQUARE | (64 * y);
			d3dSprites[i].attribute[1] = ATTR1_SIZE_64 | (64 * x);
			d3dSprites[i].attribute[2] = ATTR2_ALPHA(1) | (8 * 32 * y) | (8 * x);
			i++;
		}
	}
	
	updateOAM();
	d3dScreen=true;
}
示例#13
0
文件: arm9_main.c 项目: 0xtob/dsmi
int main(void)
{
	
	lcdMainOnBottom();

	// Set modes
	videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
	videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG2_ACTIVE);
	
	// Set banks
	vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000,
		VRAM_C_SUB_BG_0x06200000 , VRAM_D_LCD);
	
	// Gfx on main
	REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(0);
	REG_BG3PA = 1 << 8;
	REG_BG3PB = 0;
	REG_BG3PC = 0;
	REG_BG3PD = 1 << 8;
	
	// Text bg on sub
	REG_BG0CNT_SUB = BG_MAP_BASE(4) | BG_TILE_BASE(0) | BG_PRIORITY(0);
	BG_PALETTE_SUB[255] = RGB15(31,15,0);
	consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false, true);
	
	// Gfx on sub
	REG_BG2CNT_SUB = BG_BMP16_256x256 | BG_MAP_BASE(2) | BG_PRIORITY(1);
	REG_BG2PA_SUB = 1 << 8;
	REG_BG2PB_SUB = 0;
	REG_BG2PC_SUB = 0;
	REG_BG2PD_SUB = 1 << 8;
	
	u16 i;
	for(i=0; i<256*192; ++i)
		sub_vram[i] = dsmi_logo_ds[i];
	drawKaos();
	drawSlider1();
	drawSlider2();
	drawSlider3();
	
	iprintf("\x1b[12;12HOSC Demo\n");
	
	iprintf("\x1b[15;0H\x1b[KConnecting\n");
	int res = dsmi_connect();
	
	if(res == 1) {
		iprintf("\x1b[15;0H\x1b[KOK\n");
	} else {
		iprintf("\x1b[15;0H\x1b[KOh no, could not connect!\n");
		while(1);
	}
	
	
	while(1)
	{
		int ret, i;
		char data[32];
		size_t size = sizeof(data);
	       	char type;

		VblankHandler();
		while( dsmi_osc_read() ){
			iprintf("\x1b[17;0H\x1b[K%s\n", dsmi_osc_getaddr());
			while( ret = dsmi_osc_getnextarg( data, &size, &type)){
				if( ret == -1) break; //buffer too small error
				switch(type){
					case 'i':
					case 'f':
					  iprintf("%c : 0x%x%x%x%x\n", type, data[0], data[1], data[2], data[3]);
					  break;
					case 's':
					  iprintf("%c : %s\n", type, data);
					  break;
					default:
					  break;
				}
			}
		}
		swiWaitForVBlank();
	}
	
}
示例#14
0
void gamescreen()
{
  // set the mode for 2 text layers and two extended background layers
  videoSetMode(MODE_5_2D |
               //DISPLAY_BG1_ACTIVE |
               DISPLAY_BG3_ACTIVE |
               DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT
               );

  // set the first bank as background memory and the third as sub background memory
  // B and D are not used (if you want a bitmap greater than 256x256 you will need more
  // memory so another vram bank must be used and mapped consecutivly
  vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_SPRITE, //VRAM_B_MAIN_BG_0x6020000,
                   VRAM_C_SUB_BG, VRAM_D_MAIN_BG_0x6020000);
  
  // set up our bitmap background
  BG3_CR     = BG_BMP8_512x256 | BG_WRAP_ON| BG_BMP_BASE(0);
  //BG2_CR     = BG_BMP8_256x256 | BG_BMP_BASE(8);
  
  BG1_CR = BG_32x32 | BG_TILE_BASE(0) | BG_MAP_BASE(8) | BG_256_COLOR;


  // these are rotation backgrounds so you must set the rotation attributes:
  // these are fixed point numbers with the low 8 bits the fractional part
  // this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
  BG3_XDX = 1 << 8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1 << 8;

  BG2_XDX = 1 << 8;
  BG2_XDY = 0;
  BG2_YDX = 0;
  BG2_YDY = 1 << 8;


  //our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2
  BG3_CX = 0;
  BG3_CY = 0;

  BG2_CX = 0;
  BG2_CY = 0;

  for(int i = 0; i < 512*256; i++)
    BG_GFX[i] = ((u16*)topscreen_img_bin)[i];

  for(int i = 0; i < 256; ++i)
    BG_PALETTE[i] = ((u16*)topscreen_pal_bin)[i];
  //for(int i = 0; i < 256; ++i)
  //BG_PALETTE[i] = ((u16*)numbers_pal_bin)[i];

        
  x = 0;
  y = 0;
  px = 128-32;
  py = 103;
  oldx = x;
  oldy = y;
  drag = false;
  touch_down = touchReadXY();

  initSprites();
  
  for(int i=0;i<256*256;i++)
    {
      SPRITE_GFX[i] = i % 256 | ((i % 256) << 8);
    }

  //for(int i = 0; i < 8*8*256/2; ++i)
  //    ((u16*)BG_TILE_RAM(0))[i] = ((u16*)numbers_img_bin)[i];

  //for(int i = 0; i < 32*32; ++i)
  //((u16*)BG_MAP_RAM(8))[i] = i%256;

  /*    for(int y=0;y<64; ++y)
        for(int x=0;x<32; ++x)
        {
        SPRITE_GFX[y*64+x] = ((u16*)sprite_img_bin)[y*32+x];
        }*/

  const u8* frames[16];
  frames[0]  = walk_frame00_img_bin;
  frames[1]  = walk_frame01_img_bin;
  frames[2]  = walk_frame02_img_bin;
  frames[3]  = walk_frame03_img_bin;
  frames[4]  = walk_frame04_img_bin;
  frames[5]  = walk_frame05_img_bin;
  frames[6]  = walk_frame06_img_bin;
  frames[7]  = walk_frame07_img_bin;
  frames[8]  = walk_frame08_img_bin;
  frames[9]  = walk_frame09_img_bin;
  frames[10] = walk_frame10_img_bin;
  frames[11] = walk_frame11_img_bin;
  frames[12] = walk_frame12_img_bin;
  frames[13] = walk_frame13_img_bin;
  frames[14] = walk_frame14_img_bin;
  frames[15] = walk_frame15_img_bin;

  const u8* pal_frames[16];
  pal_frames[0]  = walk_frame00_pal_bin;
  pal_frames[1]  = walk_frame01_pal_bin;
  pal_frames[2]  = walk_frame02_pal_bin;
  pal_frames[3]  = walk_frame03_pal_bin;
  pal_frames[4]  = walk_frame04_pal_bin;
  pal_frames[5]  = walk_frame05_pal_bin;
  pal_frames[6]  = walk_frame06_pal_bin;
  pal_frames[7]  = walk_frame07_pal_bin;
  pal_frames[8]  = walk_frame08_pal_bin;
  pal_frames[9]  = walk_frame09_pal_bin;
  pal_frames[10] = walk_frame10_pal_bin;
  pal_frames[11] = walk_frame11_pal_bin;
  pal_frames[12] = walk_frame12_pal_bin;
  pal_frames[13] = walk_frame13_pal_bin;
  pal_frames[14] = walk_frame14_pal_bin;
  pal_frames[15] = walk_frame15_pal_bin;

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i] = ((u16*)sprite_img_bin)[i];

  for(int i=0;i<32*32/2; ++i)
    SPRITE_GFX[i+64*32] = ((u16*)use_icon_img_bin)[i];

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i+ (64*32) + (32*16)] = ((u16*)smalldoor_img_bin)[i];

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i] = ((u16*)walk_frame00_img_bin)[i];

  for(int i = 0; i < 256; ++i)
    SPRITE_PALETTE[i] = ((u16*)walk_frame00_pal_bin)[i];


  sprites[0].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_BMP | px;
  sprites[0].attribute[1] = ATTR1_SIZE_64 | py  | ATTR1_FLIP_Y;
  sprites[0].attribute[2] = ATTR2_ALPHA(3);

  sprites[1].attribute[0] = ATTR0_SQUARE | ATTR0_COLOR_256 | (192-32-8) | ATTR0_DISABLED;
  sprites[1].attribute[1] = ATTR1_SIZE_32 | (256-32-8);
  sprites[1].attribute[2] = 64*2;//64*64;//64*32;

  sprites[2].attribute[0] = ATTR0_SQUARE | ATTR0_COLOR_256 | 90-6;
  sprites[2].attribute[1] = ATTR1_SIZE_64 | 200+16+2;
  sprites[2].attribute[2] = 64*2+32;

  int frame_index = 0;
  int sx = 0;
  //int sy = 0;
  bool left = true;;

  if (subscreen_mode == PDA)
    init_pda();
  else
    init_doorminigame();

  while(1) 
    {
      swiWaitForVBlank();

      frame_index += 1;
      frame_index = frame_index % 80;

      //SPRITE_GFX[i] = ((u16*)numbers_img_bin)[i];


      // read the button states
      scanKeys();
      touch = touchReadXY();

      pressed = keysDown();	// buttons pressed this loop
      held = keysHeld();		// buttons currently held
      
      if (subscreen_mode != DIALOG)
        {
          sprites[0].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_COLOR_256 | mod(103,512);
          sprites[0].attribute[1] = ATTR1_SIZE_64 | mod(128-32,512) | (left ? 0: ATTR1_FLIP_X);
          sprites[0].attribute[2] = ATTR2_ALPHA(3);

          sprites[2].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_COLOR_256 | mod(90-6, 512);
          sprites[2].attribute[1] = ATTR1_SIZE_64 | mod((200+16+2 - px + 128-32 + door_pos/4),512);
          sprites[2].attribute[2] = ATTR2_ALPHA(1) | 64*2+32;
        }
      else
        {
          sprites[0].attribute[0] |=  ATTR0_DISABLED;
          sprites[1].attribute[0] |=  ATTR0_DISABLED;
          sprites[2].attribute[0] |=  ATTR0_DISABLED;
        }

      if ((held & KEY_L) && (held & KEY_R))
        swiSoftReset();

      if ((pressed & KEY_LEFT) || (pressed & KEY_RIGHT))
        {
          frame_index = 0;
        }

      if (held & KEY_LEFT)
        {
          left = true;
          px -= 1;
          sprites[0].attribute[1] = sprites[0].attribute[1] & ~ATTR1_FLIP_X;

          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[frame_index/5])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[frame_index/5])[i];
        }
      else if (held & KEY_RIGHT)
        {
          left = false;
          px += 1;
          sprites[0].attribute[1] = sprites[0].attribute[1] | ATTR1_FLIP_X;

          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[frame_index/5])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[frame_index/5])[i];
        }
      else
        {
          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[0])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[0])[i];
        }

      if (held & KEY_DOWN)
        py += 1;
      else if (held & KEY_UP)
        py -= 1;


      if ((px + 128) > 328-16 && 
          (px + 128) < (328+35+16))
        {
          sprites[1].attribute[0] &=  ~ATTR0_DISABLED;
          //if (pressed & KEY_X)
          //            {
          if (subscreen_mode == PDA)
            {
              init_doorminigame();
              subscreen_mode = DOOR_MINIGAME;
            }
          else if (subscreen_mode == DOOR_MINIGAME)
            {
              init_pda();
              subscreen_mode = PDA;
            }
          //}
        }
      else if ((px + 128) > 133-16 &&
               (px + 128) < 133-16+32)
        {
          init_dialog();
          subscreen_mode = DIALOG;
        }
      else
        {
          sprites[1].attribute[0] |= ATTR0_DISABLED;
          if (subscreen_mode == DOOR_MINIGAME)
            {
              init_pda();
              subscreen_mode = PDA;
            }
        }


      sx = px;
      //sx += 1;
      
      if ((held & KEY_TOUCH)  && drag)
        {
          x = oldx + (touch_down.px - touch.px);
          y = oldy + (touch_down.py - touch.py);
        }

      if (!(held & KEY_TOUCH))
        drag = false;
      
      if (subscreen_mode != DIALOG)
        {
          BG3_CX  = x*500 + sx<<8 ;
          BG3_CY  = y*500 + (32<<8);
        }
      //2_CX  = -x;
      //2_CY  = -y;
      
      update_subscreen();

      updateOAM();
    }
}