The Gaming Revolution
Would you like to react to this message? Create an account in a few clicks or log in to continue.


An awesome place to hang out and talk about Games & Stuff!
 
HomeLatest imagesRegisterLog in

 

 Simple C Coding tutorial

Go down 
AuthorMessage
WiiSpazzm
Hacker Administrator
Hacker Administrator
WiiSpazzm


Posts : 42
Join date : 2009-08-19
Age : 29
Location : Look behind you... nah I cba to murder you.

Simple C Coding tutorial Empty
PostSubject: Simple C Coding tutorial   Simple C Coding tutorial EmptyWed Apr 07, 2010 1:55 pm

This is for use with libogc and DevkitPPC!

Keep in mind, I code in C and not C++!!!
Functions and how to use them!
You can start a function a few ways.

If you are lazy (like me) and do not understand C very well (like me xD)

My tutorial is missing a chunk. Here is a fix.

If you need more space like Function Name, Instead of a space use _
It will not respond well to space or - due to it thinking it's an integer. lol

Code:

s32 Function_Name()
{
// Code goes here!
return 0; // This needs to be at the end of s32 functions!
}

ALWAYS add the brackets beside the function name, or the compiler will be
(NOOB FIX IT!)

You may also use this:
Code:
void function_name()
{
// code here! No return is needed for void functions.
}

Now, CALLING the function is easy. Just don't screw up.

(Code from the template)
Code:

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

// Initialise the video system
VIDEO_Init();

// This function initialises the attached controllers
WPAD_Init();

// Obtain the preferred video mode from the system
// This will correspond to the settings in the Wii menu
rmode = VIDEO_GetPreferredMode(NULL);

// Allocate memory for the display in the uncached region
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));

// Initialise the console, required for printf
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

// Set up the video registers with the chosen mode
VIDEO_Configure(rmode);

// Tell the video hardware where our display memory is
VIDEO_SetNextFramebuffer(xfb);

// Make the display visible
VIDEO_SetBlack(FALSE);

// Flush the video register changes to the hardware
VIDEO_Flush();

// Wait for Video setup to complete
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

// Now that all of the video is set up, you can run the function!
Function_Name();

}

Calling a function needs to be in this format:
Function_Name(); Always add the () brackets and the ; after it, to close the deal. (lol)

More later... I am too tired.
Back to top Go down
 
Simple C Coding tutorial
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
The Gaming Revolution :: Next-Gen :: Nintendo Wii-
Jump to: