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 > draw pic from banks H & I doesnt work if using POWER_ALL

#174351 - gusano - Wed Jun 02, 2010 6:10 pm

Hi,

I searched this forum and found that you can draw a 2D image from vram banks H & I. Those banks add up to 48k, enough to cover 256x192. I tried the following code and it worked on both the emulator and the DS hardware:

Code:

// Include DS hardware access class
#include <nds.h>

#include "logo.h"


//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
   
   videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE );
   vramSetBankH(VRAM_H_SUB_BG);   // 32k bank
   vramSetBankI(VRAM_I_SUB_BG_0x06208000);   // 16k bank
   int bg3 = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);
   dmaCopy(logoBitmap, bgGetGfxPtr(bg3), 256*192);
   dmaCopy(logoPal, BG_PALETTE_SUB, 256*2);

   // Game loop
   while(1)
   {
      swiWaitForVBlank();
   }
   
   return 0;
}



But I tried to add the code to an existing project and it didn't work on the DS hardware (it DID work on the emulator). My existing project has the line:

// Turn on all 2D hardware on the DS
REG_POWERCNT = (unsigned char)POWER_ALL;

This causes the previous code to fail... any ideas why? AFAIK, I need to power everything because I'm trying to render 3D on the main screen, and also this image on the subscreen.


EDIT: I've tried several combinations of the POWER options and still it fails on the DS hardware. I'm not sure what could be the problem.

#174353 - DiscoStew - Wed Jun 02, 2010 7:08 pm

CORRECTION:

REG_POWERCNT, according to GBATek and within libnds, is a 16-bit register, but for some reason, PM_ARM9_DIRECT is used, and is set as bit 17 (BIT(16)), which is outside the range that a 16-bit (0-15) register can hold. Any particular reason for this?

----------------------------------------------------------------------
OLD:

REG_POWERCNT is a 32-bit memory register. Casting a variable with 'unsigned char' keeps only the first 8 bits of the variable, and POWER_ALL holds information up to the 17th bit.

Code:

#define PM_ARM9_DIRECT BIT(16)
/*! \enum PM_Bits
\brief Power Management control bits
*/
typedef enum
{
   PM_SOUND_AMP      = BIT(0) ,   /*!< \brief Power the sound hardware (needed to hear stuff in GBA mode too) */
   PM_SOUND_MUTE      = BIT(1),    /*!< \brief   Mute the main speakers, headphone output will still work. */
   PM_BACKLIGHT_BOTTOM   = BIT(2),    /*!< \brief   Enable the top backlight if set */
   PM_BACKLIGHT_TOP   = BIT(3)  ,  /*!< \brief   Enable the bottom backlight if set */
   PM_SYSTEM_PWR      = BIT(6) ,   /*!< \brief  Turn the power *off* if set */

   POWER_LCD      = PM_ARM9_DIRECT | BIT(0),      //!<   Controls the power for both LCD screens.
   POWER_2D_A      = PM_ARM9_DIRECT | BIT(1),      //!<   Controls the power for the main 2D core.
   POWER_MATRIX   = PM_ARM9_DIRECT | BIT(2),      //!<   Controls the power for the 3D matrix.
   POWER_3D_CORE   = PM_ARM9_DIRECT | BIT(3),      //!<   Controls the power for the main 3D core.
   POWER_2D_B      = PM_ARM9_DIRECT | BIT(9),      //!<   Controls the power for the sub 2D core.
   POWER_SWAP_LCDS   = PM_ARM9_DIRECT | BIT(15),      //!<   Controls which screen should use the main core.
   POWER_ALL_2D   = PM_ARM9_DIRECT | POWER_LCD | POWER_2D_A | POWER_2D_B,   //!< power just 2D hardware
   POWER_ALL      = PM_ARM9_DIRECT | POWER_ALL_2D | POWER_3D_CORE | POWER_MATRIX //!< power everything

}PM_Bits;

_________________
DS - It's all about DiscoStew

#174355 - gusano - Wed Jun 02, 2010 8:46 pm

Thanks a million DiscoStew!!

That's some bad copy-pasting on my part :S

If I just do REG_POWERCNT = POWER_ALL I get a compiler warning, but it works!

I'll try to find out why PM_ARM9_DIRECT is used, when REG_POWERCNT is 16-bit...

#174363 - sverx - Thu Jun 03, 2010 3:31 pm

I guess it's because there's something can be switched on/off directly from the ARM9 and some cannot, like back-light, for instance...