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 > assignment of value

#52626 - Tomik - Thu Sep 01, 2005 1:39 pm

How can I give a Adress a static value ??

Adress: 0x4000204
Value: 0x0800

??

Thanks for help, Thomas

#52632 - Cearn - Thu Sep 01, 2005 3:52 pm

Pointers, maybe?
Code:
u16 *ptr= (u16*)0x04000204;  // create pointer reference
*ptr= 0x0800;                // dereference

*(u16*)0x04000204 = 0x0800;  // all at once

// or the preferred way: defines (and volatiles)
#define REG_WSCNT         *(vu16*)(0x04000204)
REG_WSCNT= 0x0800;


Don't forget to dereference the pointer. Merely using "ptr= 0x0800" just reassigns the pointer (make it point to another address), not the value at that address.

#52634 - Tomik - Thu Sep 01, 2005 4:08 pm

Thankis first, BUT if i do thi I get messages like:

error C2371: 'ptr' : newdefinition; different basictyps

what can i do, i tried all the source variantes, but nothing works!

#52635 - Cearn - Thu Sep 01, 2005 4:17 pm

What's the exact code you're trying? And do all the demos and tutorial examples give the same problem, because this is the way pretty much everything is done. Do you have all the typedefs you need? (u16, vu16, etc)

Absolutely minimal, yet full, code:
Code:

int main()
{
    *(unsigned short*)0x04000000 = 0x0403;
    *(unsigned short*)0x06001E40 = 0x001F;

    while(1);

    return 0;
}

puts 0x0403 into address 0x04000000, and 0x001F into 0x06001E40. If the numbers don't make sense to you, that's exactly why we're using named constants is so important :P.

#52639 - Tomik - Thu Sep 01, 2005 4:29 pm

Code:
// memory location defines
u16* FrontBuffer = (u16*)0x6000000;   
u16* BackBuffer = (u16*)0x600A000;
u16* videoBuffer;
volatile u16* ScanlineCounter = (volatile u16*)0x4000006;

u16 *ptr= (u16*)0x04000204;  // create pointer reference
*ptr= 0x0800;                // dereference

*(u16*)0x04000204 = 0x0800;  // all at once


u16 *paletteMem = (u16*)0x5000000;      // PalMemory is 256 16 bit BGR values starting at 0x5000000

void EraseScreen(void);            // erases the screen in mode4
void Flip(void);               // flips between the back/front buffer
void WaitForVblank(void);         // waits for the drawer to get to end before flip
void Raster(void);               // draws the raster
void Logo(void);               // display the mie logo and sleeps for some seconds   
void Pixel(int *yArr);            // draws the 120 pixels and scrolls them
void RandomValue(int *yArr);      // random value generator - later use: signal input

int main(void)
{
   *(unsigned short*)0x04000204 = 0x0800;

   int yArr[120];
   int i;

   for(i=0;i<120;i++)
   {
      yArr[i]=80;
   }
   
   SetMode(MODE_4 | BG2_ENABLE ); //set mode 4

   EraseScreen();
   Logo();
   WaitForVblank();
   Flip();
   Sleep(100);
   RandomValue(yArr);
   
   while(1)
   {   
      Raster();
      Pixel(yArr);                        
      WaitForVblank();
      Flip();      
   }
}


And still the Clock at the PHIP Pin is not working !!

Thomas

#52644 - Cearn - Thu Sep 01, 2005 4:44 pm

Tomik wrote:
Code:
// <snip>

u16 *ptr= (u16*)0x04000204;  // create pointer reference
*ptr= 0x0800;                // dereference

*(u16*)0x04000204 = 0x0800;  // all at once

// <snip>
int main(void)
{
    // <snip>
}



Assignments can only be done inside functions, not global scop. that's probably why this doesn't compile. Just to be sure what I mean here, this:
Code:
u16 *ptr= (u16*)0x04000204;  // create pointer reference

is the definition of a pointer (ptr); a global pointer in fact. "But the '=', that's an assignment". Well, technically, it is an initialization (definition+assignment), which is still legal to use outside functions (at least, I think it's called an initialization, it might be something else). Move the assignment inside a function and it should work.

#52645 - Tomik - Thu Sep 01, 2005 5:01 pm

i checked it and well, no problems with compile but the clock is still not alive ?
what can i do ?

Thomas

Ps: have to leave now, be back in some hours !!

#52718 - Tomik - Fri Sep 02, 2005 8:54 am

@Cearn: IT WORKS ... I got the Clock ... thanks a lot !!