Need Help Understanding 2d Example

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

Need Help Understanding 2d Example

Post by olwildcory723 » Sun Jan 18, 2009 6:03 am

Hi all. I'm going through all the examples in attempt to comment everything so its understandable to a newbie like me. I'm starting in the graphics, 2d examples. In the 256_color_bmp example, I need some clarification. (BTW I do try to find these answers before I post and I could not).

Ok. So here my newbieness shows. Here is the code in question:

Code: Select all

dmaCopy(drunkenlogoBitmap, 	//Source - from grit header
        bgGetGfxPtr(bg3),     //Destination (function points to memory allocation of bg3
        256*256);             //size -- still don't understand what 256*256 is

dmaCopy(drunkenlogoPal,       //Source - from grit header
        BG_PALETTE,           //Destination, BG_PALETTE refers to something, can't find exactly
        256*2);               //size -- still don't understand what 256*2 is
I get that the dmaCopy is loading the bitmap image into the right memory place, and that the palette is also loaded into the memory via the DMA (for speed) rather than some loop or something. I just don't understand the details here. So you can see in my notes where I'm confused. I couldn't find anything about BG_PALETTE, except I'm assuming its a constant that points to the memory location where the NDS looks for the pallete for the background. Also, I'm still confused about the 256*256 and 256*2. Is that because its the size of the image? If so, I get that, but why is the palette 256*2 and not just 256?

Thanks in advance for your help :)

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

Re: Need Help Understanding 2d Example

Post by Sylus101 » Sun Jan 18, 2009 6:07 pm

You're right about BG_PALETTE. It is defined in video.h in this way (along with the bg palette for the sub engine):

Code: Select all

#define BG_PALETTE       ((u16*)0x05000000)/** \brief background palette memory*/
#define BG_PALETTE_SUB   ((u16*)0x05000400)/** \brief background palette memory (sub engine)*/
The size is in bytes. So in the case of the drunkenlogoBitmap, it's a 256 by 256 pixel image * 1 byte per pixel. Each byte is basically a reference to a location in the palette. 256 color = 8 bit = 1 byte, so that's the size of that background and how many bytes dmaCopy needs to copy.

The palette is a 256 color palette, but it's entries are each 16 bit color values = 2 bytes each, hence 256 * 2.

Honestly, what you might see more often with something like this is the use of sizeof(u16) instead of 2, but no biggie.

(sorry if I mentioned things you already knew, just tried to give a complete answer)
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

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

Re: Need Help Understanding 2d Example

Post by olwildcory723 » Mon Jan 19, 2009 12:45 am

Thanks again Sylus. I'm a php/javascript/html/flash web design guy who's trying to understand C for the sole purpose of coding on the DS. Not the best background for it, I know, but oh well. That makes much more sense now. The whole memory allocation stuff is all new to me and I'm still not sure if I'm supposed to learn it all more in-depth, or if I'll just be able to rely on the abstraction put in place by the developers like in this BG_PALETTE situation.

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

Re: Need Help Understanding 2d Example

Post by Sylus101 » Mon Jan 19, 2009 3:36 am

No problem. I started off about a year ago without knowing any C and being pretty impatient in wanting to get something up and running right away. I went with a higher abstraction level library called PAlib because learning C and libnds at the same time was pretty daunting. PALib, I should mention, relies on libnds to work.

I'm not sure what to recommend to be honest. Most tried and true libnds'ers would tell you to stay away from PALib as it's not particularly kept up, some community members are working on it, and is currently incompatible with the most recent of devkitARM and libnds builds. It is, however, very easy to jump into if you absolutely have to have something on screen right away. One thing in particular that it handles for you is sprite animations and that can be a pain to write yourself, especially if you're just learning C. I'm in the midst of writing some functions to handle animations for a current project, and it's proving to be tricky.

I would say, give learning libnds a fair shot. The flexibility is great, and hell, I'm happy to share what I know as I'm learning as well and will answer what I can. I check in quite often as I'm hoping to get some feedback for some of my older questions but since they have to do with recent additions by Dovoto, I have a feeling he's the only one that can answer them. He posted recently about moving, so I'm sure he's up to other things. Lives... I guess we all have other things to do :)
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

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

Re: Need Help Understanding 2d Example

Post by WinterMute » Wed Jan 21, 2009 4:56 am

Until such times as the PAlib maintainers create a library which works without destroying the toolchain on which PAlib depends we cannot recommend its use under any circumstances.

http://wiki.devkitpro.org/index.php/PAlib

Personally I would prefer if PAlib was not mentioned around here at all.
Help keep devkitPro toolchains free, Donate today

Personal Blog

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

Re: Need Help Understanding 2d Example

Post by Sylus101 » Wed Jan 21, 2009 7:35 pm

:shock:

By your command...
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest