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.

Beginners > Memory pointer

#35301 - WillyWonka - Wed Feb 02, 2005 8:01 pm

I'm trying to load a level from Mappy into my code which uses http://devkit.tk libgba.

The mappy code says this:

Code:
   DISPCNT = DISP_MODE (0);

   BG0CNT = BG_CHARBASE_0x06004000 | BG_COLOUR_256 | BG_TEXT_32x32 | BG_MAPBASE(0x0000);


And I'm trying to convert it. This is what I have:
Code:
   SetMode( MODE_0 | BG0_ON | BG_256_COLOR | BG_SIZE_0 );
   while (1) { VBlankIntrWait();}      // loop forever


VisualBoyAdv tells me that it's going into Mode 0 alright, BG0 is on (But the others appear to be on as well). The map is 256x256. It says that it's in 16 colour mode which is wrong. And I can't figure out how to set the CHAR_BASE(m) properly so that it sets it to 0x6004000. VBA says that it's 0x6000000.

In general, I'm confused :) What should I have there?

#35302 - DekuTree64 - Wed Feb 02, 2005 8:12 pm

WillyWonka wrote:
Code:
   DISPCNT = DISP_MODE (0);

   BG0CNT = BG_CHARBASE_0x06004000 | BG_COLOUR_256 | BG_TEXT_32x32 | BG_MAPBASE(0x0000);


And I'm trying to convert it. This is what I have:
Code:
   SetMode( MODE_0 | BG0_ON | BG_256_COLOR | BG_SIZE_0 );
   while (1) { VBlankIntrWait();}      // loop forever

Those are not the same thing. SetMode generally just puts the value you give it in REG_DISPCNT.
You'll need to either find a BG control setting function in whatever library you have, or do it the easy way and set the register directly. It should work fine to just copy/paste the top one into your project, and if your defines don't match perfectly, you can check GBATEK or the Cowbite spec to see how the BG control registers are layed out and create your own defines for the things you need.
Then if all else fails, post your gba.h.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#35305 - WillyWonka - Wed Feb 02, 2005 9:15 pm

I got it.

Code:
    BGCTRL[0] = BG_256_COLOR | BG_SIZE_0 | SCREEN_BASE(0) | CHAR_BASE(5);
   SetMode( MODE_0 | BG0_ON );


I just don't understand why CHARR_BASE(5) was the correct value (It outputted 0x6004000).

#35307 - DekuTree64 - Wed Feb 02, 2005 9:24 pm

It should be CHAR_BASE(1). Each char base is 16KB, or 0x4000 bytes, and there is 64KB of BG VRAM, so the highest base block number is 3.

Setting 5 in there will actually get you char block 1, but it will overflow into the bit above the char block field and set it too (which appearently doesn't cause any noticable problem).
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#35313 - WillyWonka - Wed Feb 02, 2005 11:07 pm

Okay, thanks. That would explain why at one point the mosaic flag was turned on.