setting Vram I to Sub BG giving error

Post Reply
olwildcory723
Posts: 9
Joined: Tue Jan 06, 2009 7:18 am

setting Vram I to Sub BG giving error

Post by olwildcory723 » Fri Jan 30, 2009 1:54 pm

Hi. I've been learning libnds and have been playing with things. In the documentation I've read, this code should work, but it gives me an error when compiling. Here is the code that throws the error:

Code: Select all

	vramSetBankI(VRAM_I_SUB_BG);
It gives me the error 'VRAM_I_SUB_BG' undeclared. The tutorials at drunkencoders say that that is an acceptable mapping of the I vram bank. Is this a bug?

Morgawr
Posts: 7
Joined: Tue Jan 27, 2009 8:29 pm

Re: setting Vram I to Sub BG giving error

Post by Morgawr » Fri Jan 30, 2009 4:36 pm

olwildcory723 wrote:Hi. I've been learning libnds and have been playing with things. In the documentation I've read, this code should work, but it gives me an error when compiling. Here is the code that throws the error:

Code: Select all

	vramSetBankI(VRAM_I_SUB_BG);
It gives me the error 'VRAM_I_SUB_BG' undeclared. The tutorials at drunkencoders say that that is an acceptable mapping of the I vram bank. Is this a bug?
Try using this:

Code: Select all

vramSetBankI(VRAM_I_SUB_BG_0x06208000);
I don't know if it works, but it gives me no error when I try to compile it ;)

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: setting Vram I to Sub BG giving error

Post by Sylus101 » Fri Jan 30, 2009 4:37 pm

EDIT - Morgawr beat me to it, but here's a bit more to expand on it.

The video.h file has this:

VRAM_I_SUB_BG_0x06208000

Since Sub screen bg ram starts at 0x06200000 and this has no offset, I wasn't sure right off hand why it looked this way.

I took a look at the gbatek sheet http://nocash.emubase.de/gbatek.htm (my best friend for understanding what's going on at hardware level) and found this:

VRAM SIZE MST OFS ARM9, 2D Graphics Engine B, BG-VRAM (max 128K)
C 128K 4 - 6200000h
H 32K 1 - 6200000h
I 16K 1 - 6208000h


My guess is that the enumeration was changed to clarify where this was pointing.
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

olwildcory723
Posts: 9
Joined: Tue Jan 06, 2009 7:18 am

Re: setting Vram I to Sub BG giving error

Post by olwildcory723 » Fri Jan 30, 2009 5:57 pm

Thanks for the help, guys. I've got more questions now though. For the bg on the sub screen I've noticed you can only map VRAM for the SUB BG to banks C, H and I. This gives you 128 + 32 + 16 = 176K. What I'm trying (hoping) to do is to be able to display two backgrounds, one on BG3 and one on BG2. BG3 would be 16 bit and take up the 128K (even though 256*192*2bytes = 98K). BG2 would have to be 8 bit and would be 256*192*1byte = 48K.

So, two questions.

Is there any way to utilize the remaining memory space in VRAM C (128 - 98 = 30K), and if so, how?

Is there any problem setting an 8 bit bmp background to VRAM H and I? Does the image data just overflow from H into I and all I really need to know is where the data starts (at the beginning of H)?

Hope those questions are clear enough. One note -- I'm exploring what's possible not necessarily what's practical. Thanks!

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: setting Vram I to Sub BG giving error

Post by Sylus101 » Sat Jan 31, 2009 12:21 am

Couple of things....

1st of all, the sub engine can only have 128K max, so it's not C+H+I, it's C or H or I or H+I. (bummer I know...). This is actually why Bank I starts in memory where it does. If you enable both H and I for SUB BG Memory, H is 32K which if it starts at 0x06200000, 32k = 0x8000 in hex, so it pretty well makes sense that I needs to start at 0x06208000... anyway...

If you need more, you would have to be careful with your code, but you can switch the screens so that engine A outputs on bottom and B on top. This would only be an option if you're okay with 128K or less for BG's on the top screen.

As for the using the 96K for a 16bit BG and then the leftover 32K for something else, you could do it, but all it would be available for is map and/or tile data for a tiled bg, not likely an 8bit bg (Maybe you could but it would only be for the top 128 horizontal lines...). What you have to get used to using are a couple of different offset settings that help point a particular bg layer's map and/or tile data to particular memory locations. I'm trying to make that a major focus for my blog, but it's been slow going as I've spent a lot of time on a game project lately. Got my sprite animation handling code finished and have been deep into game mechanics coding...

I'll come back and try to post something more about it... but the docs do mention how the bgcontrol register offsets are used in the bgInit() function. There is another one in the display control register, though...
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

dovoto
Developer
Posts: 43
Joined: Fri Aug 12, 2005 10:01 pm
Contact:

Re: setting Vram I to Sub BG giving error

Post by dovoto » Sat Jan 31, 2009 12:27 am

You can use a sprites to render the 16 bit layer. Just set 2D mapping mode and built a bg with 12 64x64 sprites:

This is from my 3D on both screens demo:

Code: Select all

 105 //-------------------------------------------------------
  106 // set up a 2D layer construced of bitmap sprites
  107 // this holds the image when rendering to the top screen
  108 //-------------------------------------------------------
  109 void initSubSprites(void){
  110 //-------------------------------------------------------
  111 
  112 	oamInit(&oamSub, SpriteMapping_Bmp_2D_256, false);
  113 
  114 	int x = 0;
  115 	int y = 0;
  116 
  117 	//set up a 4x3 grid of 64x64 sprites to cover the screen
  118 	for(y = 0; y < 3; y++)
  119 	for(x = 0; x < 4; x++)
  120 	{
  121 		u16 *offset = &SPRITE_GFX_SUB[(x * 64) + (y * 64 * 256)];
  122 
  123 		oamSet(&oamSub, x + y * 4, x * 64, y * 64, 0, 15, SpriteSize_64x64,
  124 			SpriteColorFormat_Bmp, offset, -1, false,false,false,false,false);
  125 	}
  126 
  127 	swiWaitForVBlank();
  128 
  129 	oamUpdate(&oamSub);
  130 }


Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests