Exemple #1
0
void iconTitleInit (void) {
	// initialize video mode
	videoSetMode(MODE_4_2D);

	// initialize VRAM banks
	vramSetPrimaryBanks(VRAM_A_MAIN_BG,
	                    VRAM_B_MAIN_SPRITE,
	                    VRAM_C_LCD,
	                    VRAM_D_LCD);

	// initialize bg2 as a rotation background and bg3 as a bmp background
	// http://mtheall.com/vram.html#T2=3&RNT2=96&MB2=3&TB2=0&S2=2&T3=6&MB3=1&S3=1
	bg2 = bgInit(2, BgType_Rotation, BgSize_R_512x512,   3, 0);
	bg3 = bgInit(3, BgType_Bmp16,    BgSize_B16_256x256, 1, 0);

	// initialize rotate, scale, and scroll
	bgSetRotateScale(bg3, 0, 1<<8, 1<<8);
	bgSetScroll(bg3, 0, 0);
	bgSetRotateScale(bg2, 0, 8*(1<<8)/6, 1<<8);
	bgSetScroll(bg2, -TITLE_POS_X, -TITLE_POS_Y);

	// clear bg2's map: 512x512 pixels is 64x64 tiles is 4KB
	dmaFillHalfWords(0, bgGetMapPtr(bg2), 4096);
	// load compressed font into bg2's tile data
	decompress(font6x8Tiles, bgGetGfxPtr(bg2), LZ77Vram);

	// load compressed bitmap into bg3
	decompress(hbmenu_bannerBitmap, bgGetGfxPtr(bg3), LZ77Vram);

	// load font palette
	dmaCopy(font6x8Pal, BG_PALETTE, font6x8PalLen);

	// apply the bg changes
	bgUpdate();

	// initialize OAM
	oamInit(&oamMain, SpriteMapping_1D_128, false);
	sprite = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_16Color);
	dmaFillHalfWords(0, sprite, sizeof(banner.icon));
	oamSet(&oamMain, 0, ICON_POS_X, ICON_POS_Y, 0, 0,
	       SpriteSize_32x32, SpriteColorFormat_16Color, sprite,
	       -1, 0, 0, 0, 0, 0);

	// oam can only be updated during vblank
	swiWaitForVBlank();
	oamUpdate(&oamMain);

	// everything's ready :)
	writeRow (0,"...initializing...");
	writeRow (1,"===>>> HBMenu+ <<<===");
	writeRow (2,"(this text should disappear...");
	writeRow (3,"...otherwise, trouble!)");
}
Exemple #2
0
void updateCenter(AppState & state) {
  Point bottomLeft = state.convertBufferToScreen(Point(0,0));
  Point topRight = state.convertBufferToScreen(Point(MY_BG_W,MY_BG_H));

  Point newCenter = state.convertScreenToImage(Point(SCREEN_WIDTH/2, SCREEN_HEIGHT/2));
  // printf("--------------\n");
  // printf("%d %d\n", bottomLeft.x, bottomLeft.y);
  // printf("%d %d\n", topRight.x, topRight.y);
  // printf("%d %d\n", newCenter.x, newCenter.y);

  if (bottomLeft.x > 0 || bottomLeft.y > 0 || topRight.x < SCREEN_WIDTH || topRight.y < SCREEN_HEIGHT) {
    //Point newCenter = state.convertScreenToImage(Point(SCREEN_WIDTH/2, SCREEN_HEIGHT/2));
      state.scroll_x = MY_BG_W/2-SCREEN_WIDTH/2;
      state.scroll_y = MY_BG_H/2-SCREEN_HEIGHT/2;
      state.center_x = newCenter.x;
      state.center_y = newCenter.y;

      // printf("%d %d\n", state.center_x, state.center_y);
      bgHide(3);
      fillDisplay(RGB15(0,0,0) | BIT(15), state.lastPage, state);
      drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state);
  }
  bgSetScroll(3, state.scroll_x, state.scroll_y);
  bgUpdate();
  bgShow(3);
}
Exemple #3
0
//---------------------------------------------------------------------------------
int main(void) {
	short scrX=0, scrY=0;
	unsigned short pad0, move;

    // Initialize SNES 
	consoleInit();

	// Copy tiles to VRAM
	bgInitTileSet(0, &LandTiles, &LandPalette, 1, (&LandTiles_end - &LandTiles), (&LandPalette_end - &LandPalette), BG_16COLORS, 0x0000);
	bgInitTileSet(2, &CloudTiles, &CloudPalette, 0, (&CloudTiles_end - &CloudTiles), (&CloudPalette_end - &CloudPalette),  BG_4COLORS, 0x1000);

	// Copy Map to VRAM
	bgInitMapSet(0, &Maps, (&Maps_end - &Maps),SC_32x32, 0x2000);
	bgInitMapSet(2, &Mapsc, (&Mapsc_end - &Mapsc),SC_32x32, 0x2400);

	// Now Put in 16 color mode and put cloud on top of screen
	setMode(BG_MODE1,BG3_MODE1_PRORITY_HIGH); bgSetDisable(1);  

	// Set BG3 SubScreen and 
	bgSetEnableSub(2);
	
	// enable Subscreen Color ADD/SUB and Color addition on BG1 and Backdrop color
	setColorEffect(CM_SUBBGOBJ_ENABLE, CM_MSCR_BACK | CM_MSCR_BG1);

	// Wait for nothing :P
	while(1) {
        // change scrolling 
	    scrX++; 
		bgSetScroll(2, scrX,0);

		WaitForVBlank();
	}
	return 0;
}
Exemple #4
0
void updateScroll(BG_INF* inf, int dx, int dy)
{
	scroll(inf->x, inf->y, dx, dy, inf);
	inf->x+= dx;
	inf->y+= dy;
	bgSetScroll (inf->bgId, inf->x, inf->y);
	bgUpdate();
}
void advRotating(void)
{
	videoSetMode(MODE_5_2D);
	vramSetBankA(VRAM_A_MAIN_BG);
	
	int bg = bgInit(3, BgType_ExRotation, BgSize_ER_256x256, 0,1);
	
	dmaCopy(TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
	dmaCopy(TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
	dmaCopy(Layer256x256Map, bgGetMapPtr(bg),  Layer256x256MapLen);
	
	bgMosaicEnable(bg);
	
	int keys = 0;
	int angle = 0;
	int center_x = 0;
	int center_y = 0;
	
	while(!(keys & KEY_B))
	{
		scanKeys();
		keys = keysHeld();
		
		if(keys & KEY_UP) center_y--;
		if(keys & KEY_DOWN) center_y++;
	
		if(keys & KEY_LEFT) center_x--;
		if(keys & KEY_RIGHT) center_x++;

		if(keys & KEY_L) angle-=40;
		if(keys & KEY_R) angle+=40;

		if(center_x > 256) center_x = 256;
		if(center_x < 0) center_x = 0;
		
		if(center_y > 192) center_y = 192;
		if(center_y < 0) center_y = 0;

		
		swiWaitForVBlank();
		
		bgSetRotate(bg, angle);
		bgSetScroll(bg, center_x, center_y);
		bgSetCenter(bg, center_x, center_y);
		bgUpdate();

		consoleClear();
		iprintf("Press B to exit.n");
		iprintf("Angle: %d \ncenter X: %d  center Y: %d", angleToDegrees(angle), center_x, center_y);
		
	}
}
Exemple #6
0
//---------------------------------------------------------------------------------
int main(void) {
	u16 scrX=0, scrY=0;
	u16 pad0, move;

    // Initialize SNES 
	consoleInit();
    
    // Initialize text console with our font
	consoleInitText(0, 1, &snesfont);

	// Copy tiles to VRAM
	bgInitTileSet(1, &patterns, &palette, 0, (&patterns_end - &patterns), 16*2, BG_16COLORS, 0x4000);

	// Copy Map to VRAM
	bgInitMapSet(1, &map, (&map_end - &map),SC_64x64, 0x1000);

	// Now Put in 16 color mode and disable last BG
	setMode(BG_MODE1,0);  bgSetDisable(2);
	
	// Wait for nothing :P
	while(1) {
        // no move currently
        move = 0;
        
		// Refresh pad values
		scanPads();
		
		// Get current #0 pad
		pad0 = padsCurrent(0);
		
		// Update scrolling with current pad
		switch (pad0) {
			case KEY_RIGHT	: scrX+=2; move = 1; break;
			case KEY_LEFT	: scrX-=2; move = 1; break;
			case KEY_DOWN	: scrY+=2; move = 1; break;
			case KEY_UP		: scrY-=2; move = 1; break;
		}
        if (move) bgSetScroll(1, scrX,scrY);
		
        // Just inform user
        consoleDrawText(0,0,"SCR X=%d Y=%d",scrX,scrY);

		WaitForVBlank();
	}
	return 0;
}
/*
	DS_ScrollBackground:

	Positions the screen as to center it over the emulated cursor.
*/
LOCALPROC DS_ScrollBackground(void)
{
	int ScrollX = 0;
	int ScrollY = 0;
	int Scale = 0;

	/*
		TODO:
		Lots of magic numbers here.
	*/
#if EnableMagnify
	if (WantMagnify) {
		ScrollX = ((int) CurMouseH) - (DS_ScreenWidth / 4);
		ScrollY = ((int) CurMouseV) - (DS_ScreenHeight / 4);
		Scale = 128;

		ScrollX = ScrollX > vMacScreenWidth - (DS_ScreenWidth / 2)
			? vMacScreenWidth - (DS_ScreenWidth / 2)
			: ScrollX;
		ScrollY = ScrollY > vMacScreenHeight - (DS_ScreenHeight / 2)
			? vMacScreenHeight - (DS_ScreenHeight / 2)
			: ScrollY;
	} else
#endif
	{
		ScrollX = ((int) CurMouseH) - (DS_ScreenWidth / 2);
		ScrollY = ((int) CurMouseV) - (DS_ScreenHeight / 2);
		Scale = 256;

		ScrollX = ScrollX > vMacScreenWidth - DS_ScreenWidth
			? vMacScreenWidth - DS_ScreenWidth
			: ScrollX;
		ScrollY = ScrollY > vMacScreenHeight - DS_ScreenHeight
			? vMacScreenHeight - DS_ScreenHeight
			: ScrollY;
	}

	ScrollX = ScrollX < 0 ? 0 : ScrollX;
	ScrollY = ScrollY < 0 ? 0 : ScrollY;

	if (Display_bg2_Main) {
		bgSetScale(Display_bg2_Main, Scale, Scale);
		bgSetScroll(Display_bg2_Main, ScrollX, ScrollY);
	}
}
Exemple #8
0
void Outro_Run() {
	Outro_ConfigureHardware();

	/* Enable background blending */
	REG_BLDCNT = BLEND_SRC_BG0 | BLEND_SRC_BG3 | BLEND_FADE_BLACK;
	REG_BLDCNT_SUB = BLEND_SRC_BG0 | BLEND_SRC_BG3 | BLEND_FADE_BLACK;

	/* Configure background engines */	
	int bg0_main = bgInit(0, BgType_Text4bpp, BgSize_T_256x256, 1, 0);
	int bg0_sub = bgInitSub(0, BgType_Text4bpp, BgSize_T_256x256, 1, 0);

	/* Set background 0 to display below background 1 */
	bgSetPriority(bg0_main, 1);
	bgSetPriority(bg0_sub, 1);

	Outro_LoadResources(bg0_main, bg0_sub);

	/* Set up distortion effects */
	Distorter *distorter_main = malloc(sizeof(Distorter));
	Distorter_Init(distorter_main, 0, DistorterEngineMain, -(20 << 8), 96, 4 << 8);

	Distorter *distorter_sub = malloc(sizeof(Distorter));
	Distorter_Init(distorter_sub, 3, DistorterEngineSub, -(16 << 8), 96, 4 << 8);

	/* Create a console for the main display and print the message to it */
	PrintConsole display_console_main;	
	TitleConsole_Init(&display_console_main, 3, true, 2, 1);

	consoleSelect(&display_console_main);
	iprintf("THE\nEND");

	/* Create a console for the sub display and print the message to it */
	PrintConsole display_console_sub;	
	TitleConsole_Init(&display_console_sub, 3, false, 2, 1);

	consoleSelect(&display_console_sub);
	iprintf("MORE\nSOON");

	/* Offset each console so they are vertically centered */
	bgSetScroll(display_console_main.bgId, 0, -16);
	bgSetScroll(display_console_sub.bgId, 0, -16);
	bgUpdate();

	/* Fade in */
	for (int blend_factor = 0xf; blend_factor >= 0x0; blend_factor--) {
		Outro_Draw(distorter_main, distorter_sub);

		REG_BLDY = blend_factor;
		REG_BLDY_SUB = blend_factor;
	}

	/* Main stage loop. Exit when a key is pressed */
	while (!(keysDown() & KEY_START)) {
		Outro_Draw(distorter_main, distorter_sub);

		scanKeys();
	}

	Distorter_Free(distorter_main);
	free(distorter_main);

	Distorter_Free(distorter_sub);
	free(distorter_sub);
}
Exemple #9
0
void setConsoleCooAbs(int x, int y)
{
	bgSetScroll(consoleId, x, y);
}
Exemple #10
0
static int NDS_CreateWindowFramebuffer(_THIS, SDL_Window *window,
									   Uint32 *format, void **pixels,
									   int *pitch)
{
	struct NDS_WindowData *wdata;
    int bpp;
    Uint32 Rmask, Gmask, Bmask, Amask;
	const SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
	const SDL_DisplayMode *mode = display->driverdata;
	const Uint32 fmt = mode->format;

	if (fmt != SDL_PIXELFORMAT_ABGR1555) {
		SDL_SetError("Unsupported pixel format (%x)", fmt);
		return -1;
	}

    if (!SDL_PixelFormatEnumToMasks
        (fmt, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
        SDL_SetError("Unknown texture format");
        return -1;
    }

	wdata = SDL_calloc(1, sizeof(struct NDS_WindowData));
	if (!wdata) {
		SDL_OutOfMemory();
		return -1;
	}

	if (bpp == 8) {
		wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH;
	} else {
		wdata->pixels_length = (SCREEN_HEIGHT+SCREEN_GAP+SCREEN_HEIGHT)*SCREEN_WIDTH*2;
	}
	wdata->pixels = SDL_calloc(1, wdata->pixels_length);
	if (!wdata->pixels) {
		SDL_free(wdata);
		SDL_SetError("Not enough memory");
        return -1;
    }

	if (bpp == 8) {
		wdata->main.bg_id = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
		wdata->sub.bg_id = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0);

		wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH;
		wdata->main.pixels = wdata->pixels;

		wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH;
		wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length;	/* or ...+SCREEN_GAP */
			
	} else {
		wdata->main.bg_id = bgInit(2, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
		wdata->sub.bg_id = bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);

		wdata->main.length = SCREEN_HEIGHT*SCREEN_WIDTH*2;
		wdata->main.pixels = wdata->pixels;

		wdata->sub.length = SCREEN_HEIGHT*SCREEN_WIDTH*2;
		wdata->sub.pixels = (u8 *)wdata->pixels + wdata->main.length;	/* or ...+SCREEN_GAP */
	}

	wdata->pitch = (window->w) * ((bpp+1) / 8);
	wdata->bpp = bpp;
	wdata->rotate = 0;
	wdata->scale.x = 0x100;
	wdata->scale.y = 0x100;
	wdata->scroll.x = 0;
	wdata->scroll.y = 0;

	wdata->main.vram_pixels = bgGetGfxPtr(wdata->main.bg_id);
	wdata->sub.vram_pixels = bgGetGfxPtr(wdata->sub.bg_id);

#if 0
	bgSetCenter(wdata->main.bg_id, 0, 0);
	bgSetRotateScale(wdata->main.bg_id, wdata->rotate, wdata->scale.x,
					 wdata->scale.y);
	bgSetScroll(wdata->main.bg_id, wdata->scroll.x, wdata->scroll.y);
#endif

#if 0
	bgSetCenter(wdata->sub.bg_id, 0, 0);
	bgSetRotateScale(wdata->sub.bg_id, wdata->rotate, wdata->scale.x,
					 wdata->scale.y);
	bgSetScroll(wdata->sub.bg_id, wdata->scroll.x, wdata->scroll.y);
#endif

	bgUpdate();

	*format = fmt;
	*pixels = wdata->pixels;
	*pitch = wdata->pitch;

	window->driverdata = wdata;

	return 0;
}
Exemple #11
0
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------

	const int tile_base = 0;
	const int map_base = 20;


	videoSetMode(0);	

	videoSetModeSub(MODE_5_2D);	
	vramSetBankC(VRAM_C_SUB_BG); 

	PrintConsole *console = consoleInit(0, 3, BgType_ExRotation, BgSize_ER_256x256, map_base, tile_base, false, false);

	ConsoleFont font;

	font.gfx = (u16*)fontTiles;
	font.pal = (u16*)fontPal;
	font.numChars = 95;
	font.numColors =  fontPalLen / 2;
	font.bpp = 8;
	font.asciiOffset = 32;
	font.convertSingleColor = false;
	
	consoleSetFont(console, &font);

	int bg3 = console->bgId;

	iprintf("Custom Font Demo\n");
	iprintf("   by Poffy\n");
	iprintf("modified by WinterMute and dovoto\n");
	iprintf("for libnds examples\n");

	
	unsigned int angle = 0;
    int scrollX = 0;
	int scrollY = 0;
	int scaleX = intToFixed(1,8);
	int scaleY = intToFixed(1,8);

	while(1) {
		scanKeys();
		u32 keys = keysHeld();

		if ( keys & KEY_L ) angle+=64; 
		if ( keys & KEY_R ) angle-=64;

		if ( keys & KEY_LEFT ) scrollX++;
		if ( keys & KEY_RIGHT ) scrollX--;
		if ( keys & KEY_UP ) scrollY++;
		if ( keys & KEY_DOWN ) scrollY--;

		if ( keys & KEY_A ) scaleX++;
		if ( keys & KEY_B ) scaleX--;

		if( keys & KEY_X ) scaleY++;
		if( keys & KEY_Y ) scaleY--;

		swiWaitForVBlank();


		bgSetRotateScale(bg3, angle, scaleX, scaleY);
		bgSetScroll(bg3, scrollX, scrollY);
		bgUpdate();
	}

}
static int
NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
    NDS_TextureData *txdat = NULL;
    int i;
    int bpp;
    Uint32 Rmask, Gmask, Bmask, Amask;

    if (!SDL_PixelFormatEnumToMasks
        (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
        SDL_SetError("Unknown texture format");
        return -1;
    }

    /* conditional statements on w/h to place it as bg/sprite
       depending on which one it fits. */
    if (texture->w <= 64 && texture->h <= 64) {
        int whichspr = -1;
        printf("NDS_CreateTexture: Tried to make a sprite.\n");
        txdat->type = NDSTX_SPR;
#if 0
        for (i = 0; i < SPRITE_COUNT; ++i) {
            if (data->oam_copy.spriteBuffer[i].attribute[0] & ATTR0_DISABLED) {
                whichspr = i;
                break;
            }
        }
        if (whichspr >= 0) {
            SpriteEntry *sprent = &(data->oam_copy.spriteBuffer[whichspr]);
            int maxside = texture->w > texture->h ? texture->w : texture->h;
            int pitch;

            texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
            txdat = (NDS_TextureData *) texture->driverdata;
            if (!txdat) {
                SDL_OutOfMemory();
                return -1;
            }

            sprent->objMode = OBJMODE_BITMAP;
            sprent->posX = 0;
            sprent->posY = 0;
            sprent->colMode = OBJCOLOR_16;      /* OBJCOLOR_256 for INDEX8 */

            /* the first 32 sprites get transformation matrices.
               first come, first served */
            if (whichspr < MATRIX_COUNT) {
                sprent->isRotoscale = 1;
                sprent->rsMatrixIdx = whichspr;
            }

            /* containing shape (square or 2:1 rectangles) */
            sprent->objShape = OBJSHAPE_SQUARE;
            if (texture->w / 2 >= texture->h) {
                sprent->objShape = OBJSHAPE_WIDE;
            } else if (texture->h / 2 >= texture->w) {
                sprent->objShape = OBJSHAPE_TALL;
            }

            /* size in pixels */
            /* FIXME: "pitch" is hardcoded for 2bytes per pixel. */
            sprent->objSize = OBJSIZE_64;
            pitch = 128;
            if (maxside <= 8) {
                sprent->objSize = OBJSIZE_8;
                pitch = 16;
            } else if (maxside <= 16) {
                sprent->objSize = OBJSIZE_16;
                pitch = 32;
            } else if (maxside <= 32) {
                sprent->objSize = OBJSIZE_32;
                pitch = 64;
            }

            /* FIXME: this is hard-coded and will obviously only work for one
               sprite-texture.  tells it to look at the beginning of SPRITE_GFX
               for its pixels. */
            sprent->tileIdx = 0;

            /* now for the texture data */
            txdat->type = NDSTX_SPR;
            txdat->hw_index = whichspr;
            txdat->dim.hdx = 0x100;
            txdat->dim.hdy = 0;
            txdat->dim.vdx = 0;
            txdat->dim.vdy = 0x100;
            txdat->dim.pitch = pitch;
            txdat->dim.bpp = bpp;
            txdat->vram_pixels =
                (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);
            /* FIXME: use tileIdx*boundary
               to point to proper location */
        } else {
            SDL_SetError("Out of NDS sprites.");
        }
#endif
    } else if (texture->w <= 256 && texture->h <= 256) {
        int whichbg = -1, base = 0;
        if (!data->bg_taken[2]) {
            whichbg = 2;
        } else if (!data->bg_taken[3]) {
            whichbg = 3;
            base = 4;
        }
        if (whichbg >= 0) {
            texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
            txdat = (NDS_TextureData *) texture->driverdata;
            if (!txdat) {
                SDL_OutOfMemory();
                return -1;
            }
// hard-coded for 256x256 for now...
// TODO: a series of if-elseif-else's to find the closest but larger size.
            if (!data->sub) {
                if (bpp == 8) {
                    txdat->hw_index =
                        bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
                } else {
                    txdat->hw_index =
                        bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0,
                               0);
                }
            } else {
                if (bpp == 8) {
                    txdat->hw_index =
                        bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0,
                                  0);
                } else {
                    txdat->hw_index =
                        bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256,
                                  0, 0);
                }
            }

/*   useful functions
        bgGetGfxPtr(bg3);            
		bgSetCenter(bg3, rcX, rcY);
		bgSetRotateScale(bg3, angle, scaleX, scaleY);
		bgSetScroll(bg3, scrollX, scrollY);
		bgUpdate(bg3);
*/
            txdat->type = NDSTX_BG;
            txdat->pitch = (texture->w) * (bpp / 8);
            txdat->bpp = bpp;
            txdat->rotate = 0;
            txdat->scale.x = 0x100;
            txdat->scale.y = 0x100;
            txdat->scroll.x = 0;
            txdat->scroll.y = 0;
            txdat->vram_pixels = (u16 *) bgGetGfxPtr(txdat->hw_index);

            bgSetCenter(txdat->hw_index, 0, 0);
            bgSetRotateScale(txdat->hw_index, txdat->rotate, txdat->scale.x,
                             txdat->scale.y);
            bgSetScroll(txdat->hw_index, txdat->scroll.x, txdat->scroll.y);
            bgUpdate(txdat->hw_index);

            data->bg_taken[whichbg] = 1;
            /*txdat->size = txdat->dim.pitch * texture->h; */
        } else {
            SDL_SetError("Out of NDS backgrounds.");
        }
    } else {
        SDL_SetError("Texture too big for NDS hardware.");
    }

    if (!texture->driverdata) {
        return -1;
    }

    return 0;
}