Upcoming Events
Unite 2010
11/10 - 11/12 @ Montrťal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27††

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
64 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Contents
 Getting Input
 Example

 Printable version
 Discuss this article

The Series
 Volume I
 Volume II
 Volume III

Example

If you somehow donít understand input, hereís a little example to clench the deal:

#include "gba.h"          //Defined in Volume 2 (ALWAYS include this first)
#include "keypad.h"
#include "screenmodes.h"  //Defined in Volume 2
 
u16* theVideoBuffer = (u16*)VideoBuffer;
#define RGB(r,g,b) (r+(g<<5)+(b<<10))   //Macro to build a color
 
void FillScreen( u16 color )
{
  u16 x, y;
  for ( x = 0; x < 240; x++ )
    for ( y = 0; y < 160; y++ )
      theVideoBuffer[ y * 240 + x ] = color;
}
 
int main()
{
  SetMode( SCREENMODE3 | BG2ENABLE );
 
  while ( 1 )
    if ( KEY_DOWN( KEYUP) )
      FillScreen( RGB(31,0,0) );
    else if ( KEY_DOWN( KEYDOWN) )
      FillScreen( RGB(0,31,0) );
    else if ( KEY_DOWN(KEYLEFT) )
      FillScreen( RGB(0,0,31) );
    else if ( KEY_DOWN(KEYRIGHT) )
      FillScreen( RGB(31,31,0) );
    else if ( KEY_DOWN(KEYA) )
      FillScreen( RGB(0,31,31) );
    else if ( KEY_DOWN(KEYB) )
      FillScreen( RGB(31,0,31) );
    else if ( KEY_DOWN(KEYSTART) )
      break;
 
  return 0;
}

All the demo does is fill the screen with a certain color depending on what button is pressed. Start ends the program.

Next Article

In the next article, Iím going to give you information on a slightly complex/tricky topic-tile modes.

Acknowledgements

I would like to thank dovoto, as his tutorials have been my biggest source of information on GBA development since I started.† Check out his site at www.thepernproject.com.† I'd also like to thank the guys in #gamedev and #gbadev on EFNet in IRC for all their help, and all the help they'll be giving me as I write these articles.†Furthermore, I would like to thank www.gbadev.org/.† The site is a great resource, and it is definitely worth your time.

Special thanks to www.gamedev.net for being my largest game development resource and for putting my articles on their site.† Extra special thanks to Inspi for helping me with my coding woes and checking over this article.

If you have any questions or comments, you can always e-mail me at genesisgenocide@yahoo.com or nairb@usa.com.†I can't promise I'll answer your questions, like your comments, or listen to your suggestions, but I'll at least read the e-mail (as long as it doesn't look like spam).