Introduction

Day 1
GBA Hardware

Day 2
"Hello, World!"

Day 3
Input

Day 4
Backgrounds -
  Bitmapped Modes

Day 5
Sprites

Day 6
Backgrounds -
  Tile Modes

Day 7
Project 1 -
  Tetris

Quiz - Week 1

Day 8
Sprites #2 -
  Animation

Day 9
Maps

Day 10
Sprites #3 -
  Animation #2

Day 11
Backgrounds -
  Rotation

Day 12
Sprites #4 -
  Mosaic

Version History

Downloads

Books

Links

Graphics FAQ

GFX2GBA Readme

Games

Projects

Credits

Support

HAM Tutorial :: Day 2 :: "Hello, World!"

 

I would say it's about time to do some actual coding. So, without further ado, here we go!

NOTE: For these tutorials I am assuming that you are using Visual HAM to write and test your code. You can build the .gba file with F5 or build and run it (in VBA) by pressing F7. Make sure you press ESC to exit VBA.

 
// The Main HAM Library
#include <mygba.h>

// Function: main()
int main()
{
    // Initialize HAMlib
    ham_Init();

    // Initialize the text display system on BGMODE 0
    ham_InitText(0);

    // Draw some text to the screen
    ham_DrawText(0,0,"Hello, World!");

    // Infinite loop to keep the program running
    while(1) {}

	return 0; 
} // End of main()
 

Code Explanation

#include <mygba.h>
This is the main include that you'll need in all of your HAM programs.

ham_Init();
This is needed in every HAM program to initialize HAMlib and must be the first HAM function called.

ham_InitText(0);
You can pass it background 0 - 3. You can only run the HAM text system in background mode 0 - 2. Remember these are the tile modes.
NOTE: If backgrounds and background modes don't make sense to you right now, come back after Day 4 or Day 6.

ham_DrawText(0,0,"Hello, World!");
The first number passed is the column and the second is the row. For example 0,3 would be the first column in the fourth row.
Horizontal Values: 0 - 29
Vertical Values: 0 - 19

while(1)
Without this, the program would just keep ending and rebooting.

Well, that's it for Day 2. I don't think there is anything difficult about the code. Feel free to tinker with it before moving on to Day 3. One more thing, you won't actually use this to display text when you make a "real" game. It's really only for debugging purposes.

 

Download Code

NOTE: You may need to Right-click and choose Save As.

HAM Version 2.80 And Higher
Download All Files In One Zip: Day2_Hello_World.zip

View Demo Now

Discuss Day 2

 

<<

HOME

>>