synkro
0xdeadbeef
Code:
/*
* GP32 Tutorial 01 "Hello World!"
*
* Intro
* -----
* You want to learn coding for the GP32 but have no clue where to start?
* Then you found the right tutorials! These are for you when:
*
* - you have basic programming knowledge (from BASIC,...)
* - you have already installed a compiler and Mr. Mirko's SDK
* (http://home.t-online.de/home/mirkoroller/gp32/)
* - you have a proper development enviroment
* - you can't learn from the examples and manual directly
* - you need more than knowlegde about the SDK
* - you need someone explaining the stuff to you
* - can understand my bad english
*
* These tutorials will:
*
* - introduce you to C programming for the GP32
* - explain how the GP32 works
* - show basic techniques to handle the GP32
* - NOT help you installing a compiler on your PC
* - NOT guide you to a complete game engine
* - NOT help you on makefiles or editor issues
* - NOT show any ARM ASM or Thumb
*
* Why not using the official SDK? There are already some beginner tutorials
* from rico covering this. Also Mr. Mirko's SDK will become a serious
* replacement, it is minimalistic and fast.
*
* If you have any questions ask the dudes and dudettes at:
* www.gp32x.de or #gp32dev (EFNET) they know everything and are willing
* to help you anytime.
* If you have any c/c, ideas or suggestions mail me: synkro(at)gmx(dot)net
*
* Let's start!
* ------------
* 1. Open this file in your fav editor and make sure it compiles properly
* without any errors or warnings. Try tp execute the FXE in GeePee32 or
* on your GP32. I will now explain the things in detail, some in the
* following paragraphs or directly in the code.
* You won't understand everything on the first go, maybe after some weeks
* but that's ok! Rome wasn't build on a single day or with one tutorial.
* Just read everything carefuly...
*
* 2. Every C program starts its execution with the "main" function. Every
* programm has to have one, that's the place the GP32 starts the execution.
* The first "void" means that this function won't return any value after
* execution. The second "void" in braces means that the "main" function
* needs no arguments on execution.
*
* 3. The following commands are in "{,}" These define commands together into
* a block.
*
* 4. unsigned short *framebuffer;
* This declares a pointer to the primary FRAMEBUFFER. A pointer is a
* memory cell which contains an address of a data element. The variable
* name is preceded by a '*' character. A framebuffer is a memory area
* treated like a screen or any other data element.
*
* 5. Every function starting with "gp_" is part of Mr. Mirko's SDK. Keep in
* in mind that C is case sensitive.
*
* 6. char text[23] = "Hello World! What else?";
* We can allocate arrays of simple types by adding a pair of square
* brackets enclosing a number which is the size of the array after the
* variable's name. This is an array of chars we fill with a short
* message also called string. This string has a length of 23.
*
* 7. int x_pos = 50;
* int (integer) is a data type that stores whole numbers. We declare a
* variable named 'x_pos' as an integer with the value 50.
*
* 8. while (1){}
* This is an endless loop to prevent the program to end before we can
* see anything on the screen. While the condition is true, in this case
* the condition is '1' also always true.
*
* So, that's it so far for this time. Try to re-type (not copy and paste)
* the following code and try to understand what each line does. Before you
* go over to the next chapter fool around with the code:
* A) Add new lines of text
* B) in different colors and on different positions.
* C) Clear the screen in any other color
*
* Disclaimer
* ----------
* This Tutorial is based on Mr. Mirko's SDK (mirko@mirkoroller.de)
* download it at: http://home.t-online.de/home/mirkoroller/gp32/
* THIS TUTORIAL IS NOT WRITTEN BY MR. MIRKO! Parts of this Tutorial
* are from the SDK's examples or manual.
*
* SDK by Mr. Mirko mirko(at)mirkoroller(dot)de
* Tutorial by synkro synkro(at)gmx(dot)net
* 26.04.2004 14:09:49
*/
#include <gp32.h> // Includes the SDK header with all definitions
unsigned short *framebuffer; // A framebuffer pointer
void main(void)
{
framebuffer = (unsigned short*) FRAMEBUFFER;
// We point the framebuffer pointer to a memory area used
// for the screen. We manipulate the screen by manipulating
// this framebuffer.
gp_SetScreen(framebuffer, 16);
// We set the framebuffer into 16bit mode. We will always use
// the 16bit mode because I am to lazy to write about palette
// handling and it is just the best screen mode.
int i;
for (i=0; i<320*240; i++) framebuffer[i]=0xFFFF;
// Though the screen is two dimensional, it is possible
// to access the framebuffer linear. All data in memory
// is aligned the same way. In this loop we set every
// pixel white (0xFFFF), we clear the screen.
gp_SetCpuSpeed(66);
// We set the CPU clock to 66MHz. It compromises battery
// life and performance.
char text[23] = "Hello World! What else?";
// An array of chars also known as string.
int x_pos = 50; // This int stores the x-position of the text
int y_pos = 110;
int length = 23; // length of the char[] to be drawn
int color = 0xF000; // RGB (RRRRRGGGGGBBBBB0 = 16 bit)
gp_SetFont8(x_pos, y_pos, length, text, color, framebuffer);
// We draw a string named text with lenght of 23
// at (x_pos, y_pos) on the framebuffer. This function
// is part of the SDK.
while (1) // This while loop ist always true.
{
}
} // End of the "main" function
Last edited by a moderator: