Getting started with libnds

Post Reply
Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Getting started with libnds

Post by Derrik » Wed May 07, 2014 6:39 pm

Thanks, I'll see how it goes using straight up libnds then!

I'm having a little trouble setting up GFX the DS. Ideally I'd like to have all of my VRAM banks set up in a similar way to how PAlib used to, so I would like to have extended palettes for sprites and backgrounds and be able to load 4 layers of backgrounds on each screen.

I have ball.bin and pal.bin (converted with grit) in my data folder and am using this code:

Code: Select all

#include <nds.h>

#include "ball_bin.h"
#include "pal_bin.h"

int main(int argc, char **argv) {
	videoSetMode(MODE_5_2D);
	videoSetModeSub(MODE_5_2D);
	vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
	vramSetBankB(VRAM_B_MAIN_SPRITE);
	vramSetBankC(VRAM_C_SUB_BG_0x06200000);
	vramSetBankD(VRAM_D_SUB_SPRITE);
	vramSetBankF(VRAM_F_SPRITE_EXT_PALETTE);
	vramSetBankI(VRAM_I_SUB_SPRITE_EXT_PALETTE);
	
	oamInit(&oamMain, SpriteMapping_1D_128, true);
	oamInit(&oamSub, SpriteMapping_1D_128, true);
	
	u16 *ball = NULL;
	ball = oamAllocateGfx(&oamSub, SpriteSize_32x32, SpriteColorFormat_256Color);
	dmaCopy(ball_bin, ball, 1024);
	
	vramSetBankF(VRAM_F_LCD);
	vramSetBankF(VRAM_I_LCD);
	dmaCopy(pal_bin, VRAM_F_EXT_SPR_PALETTE[0], 512);
	dmaCopy(pal_bin, VRAM_I_EXT_SPR_PALETTE[0], 512);
	vramSetBankF(VRAM_F_SPRITE_EXT_PALETTE);
	vramSetBankI(VRAM_I_SUB_SPRITE_EXT_PALETTE);
	
	oamSet(&oamSub, 0, 0, 0, 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color, ball, -1, false, false, false, false, false);
	
	while(1) {
		scanKeys();
		swiWaitForVBlank();
		
		oamUpdate(&oamMain);
		oamUpdate(&oamSub);
	}
	
	return 0;
}
The screen displays nothing, so I assume that either I have set up the VRAM banks incorrectly or that I have not correctly unlocked the extended sprite palette before attempting to dmaCopy to the palette.

Many thanks.

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Getting started with libnds

Post by Derrik » Wed May 07, 2014 7:02 pm

OK; changing oamSub to oamMain in both oamAllocateGfx and oamSet lets me draw the sprite on the top screen!

So now I know it is a problem with VRAM bank setup which is not letting me draw sprites on the bottom screen.

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Getting started with libnds

Post by Derrik » Thu May 08, 2014 5:02 pm

Not sure why, but it's working on the bottom screen now too.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Getting started with libnds

Post by elhobbs » Thu May 08, 2014 5:43 pm

sounds like you may have already solved your issues but mtheall created a page to help visual vram layout - http://mtheall.com/banks.html

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Getting started with libnds

Post by Derrik » Thu May 08, 2014 8:42 pm

Hi, thanks for the link.

As I mentioned before, I'd like 4 layers of backgrounds on both screens. So I am currently using this hacked together VRAM layout:

http://mtheall.com/vram.html#T0=1&NT0=5 ... TB3=6&S3=0

I have kept it under 128KB so that I can use the same setup for both screens.

Is this the correct way to go about loading backgrounds in this setup?

Code: Select all

topLayers[layer] = bgInit(layer, BgType_Text8bpp, BgSize_B8_256x256, layer + 28, layer * 2);
Because I can load backgrounds on layer 0 and 1, but not 2 or 3.

WinterMute
Site Admin
Posts: 1845
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Getting started with libnds

Post by WinterMute » Sat May 10, 2014 1:37 pm

Derrik wrote:Thanks, I'll see how it goes using straight up libnds then!

I'm having a little trouble setting up GFX the DS. Ideally I'd like to have all of my VRAM banks set up in a similar way to how PAlib used to, so I would like to have extended palettes for sprites and backgrounds and be able to load 4 layers of backgrounds on each screen.
That isn't necessarily a good idea.

Are the palettes on your sprites and backgrounds sufficiently different to warrant blowing 48K of VRAM just for the color data alone? Do you really need 256 color tiles given that they take up twice as much space as 16 color tiles? Bear in mind that 16 color backgrounds can still have 240 colors.

At this point it might be better for you to describe what you're trying to do in terms of the graphical content. i.e. is this a scrolling game? How big are the maps? What are you displaying on each layer?

If you're inclined to more real time discussion then the IRC channel can be a good place for these questions.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Getting started with libnds

Post by Derrik » Sun May 11, 2014 2:54 pm

Thanks for sticking with me.

I've uploaded a BG loading template:

http://filetrip.net/dl?acx8azBO5O

It can load backgrounds on all 4 layers of the top screen (which I have setup as oamMain) however I can only load backgrounds on layers 0 - 2 of the bottom screen (oamSub), if I try to load one on layer 3 of oamSub the previous layers get corrupted and it displays mostly garbage on the screen.

Setting up the VRAM banks to be as efficient and specific to my project as possible isn't really a viable solution for me since ideally I'd like to be able to have users be able to make their own backgrounds which would be loaded from FAT eventually.

sverx
Posts: 94
Joined: Wed Aug 12, 2009 2:56 pm
Location: github.com/sverx
Contact:

Re: Getting started with libnds

Post by sverx » Wed May 14, 2014 12:48 pm

If it's ok for you to have the same extended palettes for backgrounds 0 and 2 and for backgrounds 1 and 3, then you could use VRAM_BANK_F or VRAM_BANK_G, which are only 16KB and you won't waste anything.
To achieve this, you should set BG0 to use the extended palettes for BG2 using BG_PALETTE_SLOT2 and set BG1 to use the extended palettes for BG3 using BG_PALETTE_SLOT3.
I hope this helps :)

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Getting started with libnds

Post by Derrik » Fri May 16, 2014 4:41 pm

Thanks for the suggestion but is there no other way?

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests