#56801 - mesh - Tue Oct 11, 2005 5:45 pm
I have been lurking this forum for about a month now and this is my first post. I have read the beginners faq and am currently working through various tutorials for gba development. I would really appreciate it if someone could check my understanding of the following code. Just to see if I am on the right track. I have a beginners understanding of the C language but, have only been programming for Windows (console), and Allegro. Programming for new hardware is a new and exciting undertaking for me. Anyway, here is the code that I have commented as to how I understand it:
The above code comes from the tutorial here.
The only thing I am confused about is that the author said that the 16bit RGB value is stored in two 8bit addresses. It looks to me like if the code loops through all addresses and gives each a value of RGB then how does the compiler know to submit the value every two addresses. Ex. the first value will be stored at 8bit address 0x6000000 and 0x6000001. The next loop iteration, according to the author, will store the RGB value at 0x6000002 and 0x6000003 etc. But according to the code (from what I understand) won't the value be stored at every address and not every other address?
I know this is probably a stupid question and I probably will look back on it and think "Why did I ask this?..." but I am just a little confused about it. Anyway thanks for taking time to read the question and any help will be greatly appreciated.
Code: |
#include "gba.h"
int main() { u16 x; //define x as an unsigned short variable// SetMode(MODE_3 | BG2_ENABLE); //gives us the binary: 0000010000000011 //ex. 0000010000000000 + 0000000000000011 = above //also sets the value at pointer REG_DISPCNT to //0000010000000011 //setting the pointer to this binary number enables Video Mode 3 //and BG mode 2 (the only BG mode available in Video Mode 3) for(x=0; x<(240*160); x++) //loop through all addresses in pointer (pointers can be // indexed like arrays) FrontBuffer[x] //starting at FrontBuffer[0] { FrontBuffer[x]=RGB(31, 0, 0); // Change the RGB value of the pixel located at //FrontBuffer[x] to red //RGB = 11111 00000 00000 //this is only a 15bit value (the 16th bit is ignored) //this 16 bit value is stored in two 8bit addresses starting at //0x6000000 } return 0; // since main() is supposed to return an int we return 0 to let it //know everything executed properly } |
The above code comes from the tutorial here.
The only thing I am confused about is that the author said that the 16bit RGB value is stored in two 8bit addresses. It looks to me like if the code loops through all addresses and gives each a value of RGB then how does the compiler know to submit the value every two addresses. Ex. the first value will be stored at 8bit address 0x6000000 and 0x6000001. The next loop iteration, according to the author, will store the RGB value at 0x6000002 and 0x6000003 etc. But according to the code (from what I understand) won't the value be stored at every address and not every other address?
I know this is probably a stupid question and I probably will look back on it and think "Why did I ask this?..." but I am just a little confused about it. Anyway thanks for taking time to read the question and any help will be greatly appreciated.