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 > Setting Pixels

#168971 - Drovor - Sun Jun 07, 2009 1:17 am

I'm trying to make a simple dynamic "minimap" type display for my 3D application on the DS (3D on main, minimap on sub). The 3D hardware seems to be fairly independent of the memory so I've managed to get fairly far without getting into memory management (aside from mapping 1 VRAM bank as texture memory), the sub screen has basically been a debug console so far.

My goal is to be able to draw a large minimap on the sub screen dynamically (probably per-pixel) as needed based on a tile-based 2D array I have already created (and displayed on the 3D hardware).

Since it was my original plan to write the pixels directly going around the 2D hardware seemed to make sense so I was looking at some examples at dev-scene and here which use the framebuffer directly in videoSetMode(MODE_FB0); but I haven't been able to get that to work on the sub screen at this point (also to future proof the code I suspect utilizing the 2D hardware at some point will be a good idea so...).

I began reading Pataters guide to try and get an idea for how the "videoSetMode" calls should be used. I have integrated some of his code and have a PNG image displayed on the sub screen. But I'm not sure how to modify the pixels directly after assigning while in this mode ( videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE); )
The backgrounds are copied with a call to dmaCopyHalfWords at memory address BG_BMP_RAM( ... ), should I be able to assign values to that memory directly, or would it be best to create a temporary array and use dmaCopyHalfWords to write it into the BG ram?
Can I still access the framebuffer directly after the BG is drawn like with MODE_FB0?

Finally... maybe all of this is the wrong approach for what I'm trying to do, so any links or alternative ideas would be greatly appreciated.

#168972 - Drovor - Sun Jun 07, 2009 5:16 am

I think I found an answer in a recent post on the devkitpro forum: HERE. I still have a lot reading and tinkering to do to figure out how I *should* utilize the 2D hardware to do my minimap, but this will give me a jumping point for a framebuffer-esque mode on the sub screen:

Code:

   videoSetModeSub(MODE_5_2D);
   vramSetBankH(VRAM_H_SUB_BG);
   vramSetBankI(VRAM_I_SUB_BG_0x06208000);
   int SubPtr = bgInitSub(2, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
   for(int i=0; i < 256; i++)
   {
      BG_PALETTE_SUB[i] = RGB15(i & 0x1F, i & 0x1F, i & 0x1F);
   }
   u16 *SubData = bgGetGfxPtr(SubPtr);
   for(int y=0; y < 128; y++)
   {
      for(int x=0; x < 192 / 2; x++)
         SubData[x + y * 192 / 2] = ((x * 2) & 0xFF) | (((x * 2 + 1) << 8) & 0xFF00);
   }


I hope I'll be able to put some sort of background image in there, and just draw in my minimap pixel-by-pixel over it. :)

edit:
found another great example here: http://www.dev-scene.com/NDS/Tutorials_Day_3#Bitmap_on_the_sub_display

#168973 - samel - Sun Jun 07, 2009 10:44 am

MODE_FB0 could only be used on the main screen.

videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE); give you a extended rotation background [which you can use as framebuffer].
BG_BMP_RAM( ... ) return a pointer to the "framebuffer" memory.
The pointer it's an unsigned short int * where each short int rappresent a pixel: bit15 it's alpha bit14-10 are blue bit9-5 are green bit4-0 are red.

The code you write it's the same as above but with a indexed framebuffer.
You have a palette of color and in the "framebuffer" you have to put index of color in the palette.

from the link to dev-scene:
Code:

BACKGROUND.bg3_rotation.xdy = 0;
   BACKGROUND.bg3_rotation.xdx = 1 << 8;
   BACKGROUND.bg3_rotation.ydx = 0;
   BACKGROUND.bg3_rotation.ydy = 1 << 8;

With these instruction you can scale and rotate the background [MODE5 BG3 in this case]

hope this will help, feel free to ask

#168977 - Drovor - Sun Jun 07, 2009 8:39 pm

Thanks, I think this part makes sense to me now. Enough sense to be able to learn from the "all_in_one" background demo at least!