gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Need some help with setting up screens

#137004 - Jeremysr - Tue Aug 07, 2007 8:24 am

Hi, after using DSLua and PAlib for a while I decided to try using just libnds. So far for my game I'm using framebuffer mode for the top screen and it works good, but now I want to use the same sort of mode for the bottom screen. From this tutorial I found out I have to use an extended background for the sub screen. So I tried it and tried filling the sub screen with white, but it just remains black. So can someone tell me what I'm doing wrong?

Code:
#include "tiledata.h"
#include "fontdata.h"
#include "tile.h"
#include "font.h"
#include "levels.h"
#include "run.h"

int main(void) {
//   int won;
//   int program[] = { 2,2,2,5 };
   int i;

   irqInit();
   irqEnable(IRQ_VBLANK);
   
   // Main screen turn on
   videoSetMode(MODE_FB0);
   vramSetBankA(VRAM_A_LCD);

   // Sub screen turn on
   videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE);
   vramSetBankC(VRAM_C_SUB_BG);
   BG2_CR = BG_BMP16_256x256;

//   loadLevel(0);
//   won = run(program);
//   
//   if (won) {
//      printStringCenter("You Won!");
//   } else {
//      printStringCenter("You Lost!");
//   }

   for (i = 0; i < 256*256; i++)
      VRAM_C[i] = RGB15(31, 31, 31) | BIT(15);

   while (1) {
      swiWaitForVBlank();
   }
}

#137015 - tepples - Tue Aug 07, 2007 1:08 pm

A few things to try:
  • Get the extended background working on the main screen first. That is, instead of frame buffer on main and extended rotation on sub, you will have extended rotation on both.
  • Make sure to set SUB_BG2_CR (which affects the sub screen) in addition to BG2_CR (which affects only the main screen).
  • This may not be necessary, but make sure the rotation matrices (BG2_XDX, SUB_BG2_XDX, etc.) are how you want them (i.e. {256, 0, 0, 256, 0, 0} for the common case).

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#137037 - knight0fdragon - Tue Aug 07, 2007 4:10 pm

A few things, each background has its own control register, each for main and each for sub, so one thing you would want to change is this:
BG2_CR = BG_BMP16_256x256; to SUB_BG2_CR = BG_BMP16_256x256;

Next, you cannot write to VRAM C directly in frame buffer mode, it is instead mapped to address 0x06200000, which is what this function does:
vramSetBankC(VRAM_C_SUB_BG);

so instead of writing to VRAM_C, you would want to write to BG_GFX_SUB

and like tepples said, you need to add the additional affine matrix registers

SUB_BG2_XDX = 1 << 8;
SUB_BG2_XDY = 0 <<8;
SUB_BG2_YDX = 0 << 8;
SUB_BG2_YDY = 1 << 8;


the reason for 1 << 8 is because it is 8.8 fixed point
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#137107 - Jeremysr - Wed Aug 08, 2007 12:03 am

Thanks everyone, I got it working! :)