GameBoy Advance Barebones: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
Nathan (talk | contribs)
No edit summary
Nathan (talk | contribs)
Line 146:
This is a quick and dirty explanation of the earlier code. Those previously mentioned warped minds for whom this section is intended will probably prefer it that way. A more detailed discussion will be given later.
 
As I said, GBA programming is low-level programming and sometimes goes right down to the bit. The ''0x04000000'' and ''0x06000000'' are parts of the accessible memory sections. These numbers themselves don't mean much, by the way; they just refer to different sections. There aren't really ''0x02000000'' between these two sections. As you can see in the memory map, these two sections are for the IO registers and VRAM, respectively.
 
To work with these sections in C, we have to make pointers out of them, which is what the ‘unsigned''unsigned int*'' and ‘unsigned''unsigned short*'' do. The types used here are almost arbitrary; almost, because some of them are more convenient than others. For example, the GBA has a number of different video modes, and in modes 3 and 5 VRAM is used to store 16-bit colors, so in that case casting it to halfword pointers is a good idea. Again, it is not required to do so, and in some cases different people will use different types of pointers. If you're using someone else's code, be sure to note the datatypes of the pointers used, not just the names.
 
The word at ''0400:0000'' contains the main bits for the display control. By writing 0x0403 into it, we tell the GBA to use video mode 3 and activate background 2. What this actually means will be explained in the video and bitmap mode chapters.
 
In mode 3, VRAM is a 16-bit bitmap; when we make a halfword pointer for it, each entry is a pixel. This bitmap itself is the same size as the screen (240x160) and because of the way bitmaps and C matrices work, by using something of the form ‘array''array[y*width + x]'' are the contents of coordinates (x, y) on screen. That gives us our 3 pixel locations. We fill these with three 16-bit numbers that happen to be full red, green and blue in 5.5.5 BGR format. Or is that RGB, I always forget. In any case, that's what makes the pixels appear. After that there is one more important line, which is the infinite loop. Normally, infinite loops are things to be avoided, but in this case what happens after ''main()'' returns is rather undefined because there's little to return to, so it's best to avoid that possibility.
 
== Links ==