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 > Help with sticking stuff into the BGPalatte memory

#55630 - BrokenMemories - Fri Sep 30, 2005 3:46 am

Okay I'm doing the gbajunkie tutorials but using devkitARM and the header files that come with dkARM.

Now this is the code that comes with the tutorial

Code:

void PlotPixel(int x,int y, unsigned short int c)
{
   VideoBuffer[(y) * 120 + (x)] = (c);
}

int main()
{
   int loop;
   int x, y;

        SetMode(MODE_4 | BG2_ENABLE);                //set mode 4 and enable background 2

   for(loop = 0; loop < 256; loop++)                    //256 entries allowed
      BGPaletteMem[loop] = junkiePalette[loop];       //load the palette into palette memory

   while(1)
   {
      for(y = 0; y < 160; y++)                       //screen height
      {
         for(x = 0; x < 120; x++)                   //screen width
         {
            PlotPixel(x,y, junkieData[y*120+x]);   //load image data into
         }                                 //memory pixel by pixel
      }
   }
}


relevent (i think) headers stuff

Code:


u16* BGPaletteMem    =(u16*)0x5000000;
u16* VideoBuffer       =(u16*)0x6000000;



junkiePalette is a .h file with the bin data for an image.

anyways what I gather from this code is that BGPaletteMem is a memory address, right? and then he just pipes the data from junkiePalette straight into it. What I want to know is what is the relative #define in the DevKitARM headers (they are funny to read, sorry for being such a newb)

what does this mean, (form gba_video of dkA libgba)

Code:
#define BG_PALETTE(m)      ((m)<<12)


If I get this right, thats a macro that says what ever 'm' is, do something to 'm' by using <<12. What I want to know is what does <<12 mean. All of the devKitARM headers use it eg

snipit from gba_video.h from libgba of dkA
Code:

#define BACKBUFFER   (1<<4)   // buffer display select
#define OBJ_1D_MAP   (1<<6)   // sprite 1 dimensional mapping
#define   LCDC_OFF   (1<<7)   // LCDC OFF


I'm assuming it is short hand for memory/register addresses, I just dont know how to read it into 0x05000200 etc.

thanks in advance to replys :-)

~BM~

#55634 - BrokenMemories - Fri Sep 30, 2005 4:19 am

Okay I figured out that

Code:


u16* BGPaletteMem    =(u16*)0x5000000;
u16* VideoBuffer       =(u16*)0x6000000;



from junkies tuts is
Code:

#define BG_COLORS      ((u16 *)0x05000000)

//and VideoBuffer can be made by adding this too gba_video.h

#define VRAM_CTRL      ((u16 *)VRAM)


Still lost to what the
Code:
#define XDEFINED         (1<<12)


etc means

~BM~

#55635 - BrokenMemories - Fri Sep 30, 2005 4:25 am

Oh and this is the modified code should anyone want it.

Code:

//////////////////////////////////////////////////////////////////////////
// File:    imagedisp.                                                  //
// Description: A program that displays an image on the GBA            //
// Author:   gbajunkie (with lots of code from dovoto)               //
//         slightly modified my BrokenMemories for DevKitARM         //
//   Date:    15th March 2002                                            //
//////////////////////////////////////////////////////////////////////////

#include <gba_base.h>
#include <gba_types.h>
#include <gba_video.h>
#include "junkie.h"   //holds the image information in an array

void PlotPixel(int x,int y, unsigned short int c)
{
   VRAM_INPUT[(y) * 120 + (x)] = (c);
}

int main()
{
   int loop;
   int x, y;

        SetMode(MODE_4 | BG2_ENABLE);                //set mode 4 and enable background 2

   for(loop = 0; loop < 256; loop++)                    //256 entries allowed
      BG_COLORS[loop] = junkiePalette[loop];       //load the palette into palette memory

   while(1)
   {
      for(y = 0; y < 160; y++)                       //screen height
      {
         for(x = 0; x < 120; x++)                   //screen width
         {
            PlotPixel(x,y, junkieData[y*120+x]);   //load image data into
         }                                 //memory pixel by pixel
      }
   }
}

#55640 - tepples - Fri Sep 30, 2005 5:02 am

The << operator means a binary shift to the left. For example, 1 << 12 is 1 shifted to the left 12 places, or 0001000000000000(binary) = 4096.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.