RGB15 does not work
Posted: Tue May 12, 2009 6:11 pm
Hi there.
Still playing around to learn libnds, I'm in trouble understanding some basic things.
Maybe I could avoid lots of these questions if I could find some theory about bg and memory, but I still didn't find any really good
Do you have some links ?
Ok, here are my problems.
(Note: I'm currently working under the Desmume emulator)
The first one is about MODE_FB, a little misunderstanding...
Consider this code:So far, the above works fine, but maybe you can spot some slight errors ?
When I have a look at the documentation: MODE_FB0
Why ?
My second problem is related to MODE_3_2D. Look for the comments, they contain the questions.
This code has been stolen from another post here, and a little bit changed: that's maybe where my error comes from, but... can't find
Edit: mmh, comments are not easy to find, sorry... let me tell questions here.
1. What's the use and meaning of this bgOffset I have to use in bgInitSub ?
2. RGB15 macro works weirdly this time. I have to shift it left in order to get it displayed...
Still playing around to learn libnds, I'm in trouble understanding some basic things.
Maybe I could avoid lots of these questions if I could find some theory about bg and memory, but I still didn't find any really good

Ok, here are my problems.
(Note: I'm currently working under the Desmume emulator)
The first one is about MODE_FB, a little misunderstanding...
Consider this code:
Code: Select all
int main() {
videoSetMode(MODE_FB0);
vramSetBankA(VRAM_A_LCD);
lcdMainOnTop();
drawHorizontalLine(VRAM_A, 30, 30, 50, RGB15(31, 31, 31));
drawVerticalLine(VRAM_A, 30, 30, 50, rand());
drawRect(VRAM_A, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, rand());
while(1) {
swiWaitForVBlank();
}
return 0;
}
When I have a look at the documentation: MODE_FB0
Therefore I thought that using MODE_FB1 instead of FB0 would work, but noMODE_FB0 video display from main memory
MODE_FB1 video display directly from VRAM_A in LCD mode

My second problem is related to MODE_3_2D. Look for the comments, they contain the questions.
This code has been stolen from another post here, and a little bit changed: that's maybe where my error comes from, but... can't find
Code: Select all
int main(void) {
PrintConsole console;
touchPosition touch;
int bgOffset;
u16 *gfxBG;
videoSetMode(0); // Disable main screen
videoSetModeSub(MODE_3_2D);
console = *consoleInit(0, 1, BgType_Text4bpp, BgSize_T_256x256, 0, 1, false, true);
bgOffset = 2; // Why this ?
bgInitSub(BG_PRIORITY_3, BgType_Bmp16, BgSize_B16_256x256, bgOffset, 0 );
gfxBG = BG_GFX_SUB + ((bgOffset * 16384) >> 1);
iprintf("Console works fine");
while(1) {
scanKeys();
if(keysHeld() & KEY_TOUCH) {
touchRead(&touch);
// If I don't shift left RGB15, it will not display at all
// where on the previous program it worked nicely. Did I miss something ?
gfxBG[touch.py * SCREEN_WIDTH + touch.px] = RGB15(31, 31, 31) << 1;
}
swiWaitForVBlank();
}
}
1. What's the use and meaning of this bgOffset I have to use in bgInitSub ?
2. RGB15 macro works weirdly this time. I have to shift it left in order to get it displayed...