Saturday, July 16, 2011

A Simple Tutorial On Nintendo GBA Programming

This post is intended as a simple introduction to Nintendo GameBoy Advance Programming. The language used for this tutorial will be plain old ANSI C. Firstly , download the GBDK  , The HAM SDK or just the GNU GCC-ARM compiler (and compile from the command line yourself).

                                                              HARDWARE:
Unlike PC programming (in a fairly high-level language); programming for consoles and embedded systems requires a thorough knowledge of the underlying hardware, so here is a brief overview of the Hardware of the Nintendo GBA.

-> The GBA has a 32-bit 16.78 MHz ARM CPU (ARM7TDMI to be exact).
-> The GBA has 96 KB Video Memory.
-> The GBA has 256 KB external RAM
-> The GBA has 32 KB of internal RAM
-> The GBA has 6 VIDEO MODES. (for this tutorial we will be working with MODE 3)

                                               SETTING UP YOUR IMAGE.

For this turorial , we will blit a bitmap onto the screen.

->Firstly you will need to get a tool that converts Windows BMPs (or any image format) to C code (or ASM code). I reccommend Gfx2Gba which is a free tool available with the HAM SDK and can be also downloaded individually.

-> Make an image (or convert one) to a 16-color or 256-color Bitmap as Gfx2Gba only supports there formats. And resize it to 240x160 resolution .

-> Put the image in the same directory as your source code and use Gfx2Gba to convert it.
     Use the command:          gfx2gba   -fsrr  -c32k    yourimage.bmp

-> This will generate a C source file called "yourimage.raw.c" (here yourimage is assumed to be the name of your image).

                                                             CODE:

/* CODE BEGINS HERE  (main.c) */

/*Include the bitmap*/
#include "miata.raw.c"

/*Video Mode 3*/
#define MODE_3 0x3  

/*The Screen */
#define SCREEN_W 240  
#define SCREEN_H 160

/*Memory Register for Video Modes*/
#define REG_MODE *(unsigned long*) 0x4000000  

/*Setting the Mode*/
#define SET_MODE(mode) REG_MODE=mode

/*Enabling Background 4*/
#define BG2_ENABLE 0x400


unsigned short* VideoBuffer = (unsigned short*) 0x6000000 /*Address of Video Memory) NOTE: We treat this as an array when blitting */


/* The Blit Pixel function , sets the color of pixels on the
   screen */

void BlitPixel(int x, int y, unsigned short color)
{
    /*Pointer Arithmetic... (The greatness of C) */

    VideoBuffer[y*SCREEN_W+x] = color;
}

/* Now for the main function */

int main (void)                       /* No arguments...*/
{
    int X , Y;  /*Screen Co-ordinates*/
    
    SET_MODE(BG2_ENABLE|MODE_3);

    /*Move through the entire screen and copy the color
      of every pixel of miata.bmp to the corresponding 
      pixel on the screen... */

    for (Y=0; Y < SCREEN_H; Y++)
    { 
        for (X=0; X < SCREEN_W; X++)
              BlitPixel(X ,Y, miata_Bitmap[ Y * SCREEN_W + X]);
    }

    while (1) {}   /*Main Loop*/
    return 0;
}




I Understand That Console Programming Is Not For The Faint Of Heart. But if you give it a try you'll find it to be a lot of fun especially GBA. And you will find that the experience and knowledge you gained by programming for consoles was worth all the hard work. Also you don't need to code everything from scratch, there are many third-party libraries to make like easier. I recommend using the HAM Library , as it is free for both commercial and non-commercial uses , (see HAM License) and has a good design.

Saturday, March 26, 2011

Python - GUI Programming with PyGTK.

PyGTK are basically Python bindings for GTK+. Its basically C Gtk+ ported to Python, making it easier to use without removing any features. Most Python developers prefer wxPython (Python bindings for wxWidgets) or tkinter (default Python GUI Library, ported from Tcl/tk), but personally, I think pyGTK is way easier and more powerful. pyGTK not only offers superior widgets but also has pre-made widget containers in which you can just pack all your widgets. It is more object-oriented and needs less coding. The trump card of the GTK toolkit is the Glade UI designer in which you can design all the widgets and export them as an xml string which you can later use with your program.
For good pyGTK examples, head over to my project site:
http://code.google.com/p/burningprodigytech
 

Friday, December 17, 2010

Python - The New Standard In Game Programming?





Well.... I know what you all will say (if you know anything about game development). You will say,  "Python is slow...." and "Python is lame...". But think about it. Is Python really that lame? I mean it is true that Python is slower and somewhat less portable than C or C++ or even Visual Basic, and that is a disadvantage at times. But the main thing that is holding Python back is the rumour about it being less powerful, which is an absolute lie because whatever Python is, it's not weak. Python is being rapidly updated and there are several graphics libraries for it which make it way easier to use than C, C++ , C# , V Basic or even Java. and those libraries are powerful; a popular example being 'Pygame'. Python also has way more built-ins. The only language more preferable for game programming than Python is C++, which is really difficult to master. Therefore Python is seriously awesome for Game Programming. Just give it a try!

Monday, December 13, 2010

Trendy Game Consoles

In this list I am not including Game Consoles based on their Specs, Features, Technology or Games. I am simply making a list for some of the most good- looking and well-designed consoles. Sleekness , Coolness and Design are what I rate on:


                                      NINTENDO DS







SONY PLAYSTATION 2



NINTENDO GAMEBOY ADVANCE SP



NINTENDO Wii



SONY PLAYSTATION PORTABLE





Sunday, December 12, 2010

GBA Game Programming with HAM

For a long time programming for the Nintendo Game Boy Advance has been difficult and has only been done by a few chosen professionals. But now, thanks to the HAM Cross Compiler, its gotten a lot easier. Even I can do it! For a Beginner's guide and simple tutorials go to http://www.aaronrogers.com/ham/Day1/day1.php , and for more advanced (and a thousand times more difficult) knowledge go to www.jharbour.com




So hurry up and get started!!!
Oh and if you get stuck somewhere feel free to consult me.
"A single conversation with a wise man is better than ten years of study."
(Chinese Proverb)