[Wii Programming] Creating the first Wii program

Step-by-step PC tutorials: emulators, setup, optimisation, Windows repair, tools and tips to get the most out of your PC.
Reigning challenge champion User avatar
Tgames
Geek
Administrators
Posts: 3909
Joined: Sun 21 Sep 2008 09:15
Wi-Fi: Oui
Firmware Wii: 4.1E
CFW Wii: Cios57 Rev19
Type de DS: 3DS
Linker DS: M3i Zero
CFW PS3: 3.55 PS3MFW
PS3 Dongle: PS3Key
Type PSP: Slim
Firmware PSP: 5.00-M33 CFW
Location: France

[Wii Programming] Creating the first Wii program

Post by Tgames »

Automatically translated from French.


Image unavailable (removed by its host)
1. Initializing the homebrew

First of all open "Programmer's Notepad", and do "File" and "New" => "C/C++".

Alright let's go, let's code!

Add these lines, these are the libraries we're going to call in our program.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <ogcsys.h>
#include <unistd.h>
#include <ogc/pad.h> // Librairie pour la Manette Gamecube
#include <wiiuse/wpad.h>  // Librairie pour la Wiimote
Then add these lines which initialize the video, text display, and initialize the Wii controller

Code: Select all

#define gotoXY(x,y) printf("\x1b[%i;%iH", x, y)

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

//---------------------------------------------------------------------------------
int main(int argc, char **argv) 
{
   VIDEO_Init(); //Initialise la vidéo
   WPAD_Init(); // Initialise la wiimote
   rmode = VIDEO_GetPreferredMode(NULL);
   xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
   console_init(xfb,0,0,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
   VIDEO_Configure(rmode);
   VIDEO_SetNextFramebuffer(xfb);
   VIDEO_SetBlack(FALSE);
   VIDEO_Flush();
   VIDEO_WaitVSync();
   if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 
Without the initialization code nothing will happen in the program, remember that, it's very important!

2. Using controllers. Let's use the wiimote, the Gamecube Controller, Classic Controller, Nunchuk Controller! (and yes that's a lot!)

Wiimote:

Code: Select all

printf("Premier Programme Wii -- https://www.tgames.fr"); // Écrit à l'écran ces mots
gotoXY(2, 3); // Emplacement du texte à l'écran 
 
u32 pressed;
	   struct expansion_t ext;
if (b & WPAD_BUTTON_A)
		wpad_status &= PSX_BUTTON_START;

	   
	   WPAD_ScanPads();

/* Voici différentes lignes qui sont identiques mais fonctionnent toutes différemment.
Ces lignes servent à synchroniser les boutons à la reconnaissance sur la wii
A l'appui sur un touche un condition se déroule, si elle n'est pas respecté elle est remplacé par une autre  */

// Etat des bouttons de la Wiimote avec WPAD_ButtonsDown
	   pressed = WPAD_ButtonsDown(WPAD_CHAN_0); 
	   gotoXY(5, 3);
	   printf("Boutons Wiimote avec WPAD_ButtonsDown: ");
	   if (pressed & WPAD_BUTTON_A)     { printf ("A"); }      else { printf (" "); }
	   if (pressed & WPAD_BUTTON_B)     { printf ("B"); }      else { printf (" "); }
	   if (pressed & WPAD_BUTTON_1)     { printf ("1"); }      else { printf (" "); }  
	   if (pressed & WPAD_BUTTON_2)     { printf ("2"); }      else { printf (" "); }                    
	   if (pressed & WPAD_BUTTON_MINUS) { printf ("-"); }      else { printf (" "); }
	   if (pressed & WPAD_BUTTON_PLUS)  { printf ("+"); }      else { printf (" "); }      
	   if (pressed & WPAD_BUTTON_LEFT)  { printf (" Gauche"); } else { printf ("       "); } 
	   if (pressed & WPAD_BUTTON_RIGHT) { printf (" Droit");  } else { printf ("      ");  } 
	   if (pressed & WPAD_BUTTON_UP)    { printf (" Haut");   } else { printf ("     ");   } 
	   if (pressed & WPAD_BUTTON_DOWN)  { printf (" Bas");    } else { printf ("    ");    } 	   
	   
	   // Etat des bouttons de la Wiimote avec WPAD_ButtonsHeld
	   pressed = WPAD_ButtonsHeld(WPAD_CHAN_0); 
	   gotoXY(6, 3);
	   printf("Boutons Wiimote avec WPAD_ButtonsHeld: ");
	   if (pressed & WPAD_BUTTON_A)     { printf ("A"); }      else { printf (" "); }
	   if (pressed & WPAD_BUTTON_B)     { printf ("B"); }      else { printf (" "); }
	   if (pressed & WPAD_BUTTON_1)     { printf ("1"); }      else { printf (" "); }  
	   if (pressed & WPAD_BUTTON_2)     { printf ("2"); }      else { printf (" "); }                    
	   if (pressed & WPAD_BUTTON_MINUS) { printf ("-"); }      else { printf (" "); }
	   if (pressed & WPAD_BUTTON_PLUS)  { printf ("+"); }      else { printf (" "); }      
	   if (pressed & WPAD_BUTTON_LEFT)  { printf (" Gauche"); } else { printf ("       "); } 
	   if (pressed & WPAD_BUTTON_RIGHT) { printf (" Droit");  } else { printf ("      ");  } 
	   if (pressed & WPAD_BUTTON_UP)    { printf (" Haut");   } else { printf ("     ");   } 
	   if (pressed & WPAD_BUTTON_DOWN)  { printf (" Bas");    } else { printf ("    ");    } 
	   
	   // Etat des bouttons de la Wiimote avec WPAD_ButtonsUp
	   pressed = WPAD_ButtonsUp(WPAD_CHAN_0); 
	   gotoXY(7, 3);
	   printf("Boutons Wiimote avec WPAD_ButtonsUp:   ");
	   if (pressed & WPAD_BUTTON_A)     { printf ("A"); }      else { printf (" "); }
	   if (pressed & WPAD_BUTTON_B)     { printf ("B"); }      else { printf (" "); }
	   if (pressed & WPAD_BUTTON_1)     { printf ("1"); }      else { printf (" "); }  
	   if (pressed & WPAD_BUTTON_2)     { printf ("2"); }      else { printf (" "); }                    
	   if (pressed & WPAD_BUTTON_MINUS) { printf ("-"); }      else { printf (" "); }
	   if (pressed & WPAD_BUTTON_PLUS)  { printf ("+"); }      else { printf (" "); }      
	   if (pressed & WPAD_BUTTON_LEFT)  { printf (" Gauche"); } else { printf ("       "); } 
	   if (pressed & WPAD_BUTTON_RIGHT) { printf (" Droit");  } else { printf ("      ");  } 
	   if (pressed & WPAD_BUTTON_UP)    { printf (" Haut");   } else { printf ("     ");   } 
	   if (pressed & WPAD_BUTTON_DOWN)  { printf (" Bas");    } else { printf ("    ");    } 
Now let's move on to recognizing extensions plugged into the wiimote (Nunchuk, Classic Controller...)

Code: Select all

// Extension Wiimote
	   WPAD_Expansion(WPAD_CHAN_0, &ext);
	   gotoXY(9, 3);
	   printf("Extension: ");
	   switch (ext.type)
	   {
		   case WPAD_EXP_NONE:        printf ("Aucun            "); break;
		   case WPAD_EXP_NUNCHUK:     printf ("Nunchuk          "); break;
		   case WPAD_EXP_CLASSIC:     printf ("Manette classique"); break;
		   case WPAD_EXP_GUITARHERO3: printf ("Guitar Hero 3    "); break;
		   case WPAD_EXP_UNKNOWN:     printf ("Manette inconnue "); break;
	   }
Using the Nunchuk.

Code: Select all

// Etat des bouttons de la Wiimote avec WPAD_ButtonsDown
	   pressed = WPAD_ButtonsDown(WPAD_CHAN_0); 
	   gotoXY (3, 5);
	   printf("Boutons Nunchuk avec WPAD_ButtonsDown: ");
	   if (pressed & WPAD_NUNCHUK_BUTTON_Z)     { printf ("Z"); } else { printf (" "); }
	   if (pressed & WPAD_NUNCHUK_BUTTON_C)     { printf ("C"); } else { printf (" "); }
 	   
	   
	   // Etat des bouttons de la Wiimote avec WPAD_ButtonsHeld
	   pressed = WPAD_ButtonsHeld(WPAD_CHAN_0); 
	   gotoXY (3, 6);
	   printf("Boutons Nunchuk avec WPAD_ButtonsHeld: ");
	   if (pressed & WPAD_NUNCHUK_BUTTON_Z)     { printf ("Z"); } else { printf (" "); }
	   if (pressed & WPAD_NUNCHUK_BUTTON_C)     { printf ("C"); } else { printf (" "); }
	   
	   // Etat des bouttons de la Wiimote avec WPAD_ButtonsUp
	   pressed = WPAD_ButtonsUp(WPAD_CHAN_0); 
	   gotoXY (3, 7);
	   printf("Boutons Nunchuk avec WPAD_ButtonsUp:   ");
	   if (pressed & WPAD_NUNCHUK_BUTTON_Z)     { printf ("Z"); } else { printf (" "); }
	   if (pressed & WPAD_NUNCHUK_BUTTON_C)     { printf ("C"); } else { printf (" "); } 
	   
     
	   // Joypad du nunchuk
	   WPAD_Expansion(WPAD_CHAN_0, &ext);
	   gotoXY (3, 9);
	   printf("Joypad Position  X:%3i - Y:%3i      ", ext.nunchuk.js.pos.x,    ext.nunchuk.js.pos.y);
	   printf("Joypad Center    X:%3i - Y:%3i      ", ext.nunchuk.js.center.x, ext.nunchuk.js.center.y);
	   gotoXY (3, 10);
	   printf("Joypad Min       X:%3i - Y:%3i      ", ext.nunchuk.js.min.x,    ext.nunchuk.js.min.y);
	   printf("Joypad Max       X:%3i - Y:%3i      ", ext.nunchuk.js.max.x,    ext.nunchuk.js.max.y);
       
	   X = ext.nunchuk.js.pos.x - ext.nunchuk.js.center.x;
	   Y = - (ext.nunchuk.js.pos.y - ext.nunchuk.js.center.y);
	   gotoXY (3, 12);
	   printf ("Valeur joypad par calcul  X:%4i - Y:%4i ", X, Y);
	   
	   X /= 4*2; Y /= 8*2;
	   gotoXY (35,   20);  
	   printf ("+");
	   gotoXY (35+X, 20+Y);
	   printf ("*");
Using the classic controller.

Code: Select all

 WPAD_ScanPads();
	   gotoXY (20+X1, 22+Y1); printf (".");	   
	   gotoXY (55+X2, 22+Y2); printf (".");
	   
	   // Etat des bouttons de la Wiimote avec WPAD_ButtonsDown
	   pressed = WPAD_ButtonsDown(WPAD_CHAN_0); 
	   gotoXY (3, 5);
	   printf("Boutons Nunchuk avec WPAD_ButtonsDown: ");
	   if (pressed & WPAD_CLASSIC_BUTTON_LEFT)   { printf ("G"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_RIGHT)  { printf ("D"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_UP)     { printf ("H"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_DOWN)   { printf ("B"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_A)      { printf ("A"); }    else { printf (" "); }
	   if (pressed & WPAD_CLASSIC_BUTTON_B)      { printf ("B"); }    else { printf (" "); }
	   if (pressed & WPAD_CLASSIC_BUTTON_X)      { printf ("X"); }    else { printf (" "); }
	   if (pressed & WPAD_CLASSIC_BUTTON_Y)      { printf ("Y"); }    else { printf (" "); }                   
	   if (pressed & WPAD_CLASSIC_BUTTON_PLUS)   { printf ("+"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_MINUS)  { printf ("-"); }    else { printf (" "); }    
	   if (pressed & WPAD_CLASSIC_BUTTON_ZL)     { printf (" ZL");  } else { printf ("   ");  }
	   if (pressed & WPAD_CLASSIC_BUTTON_ZR)     { printf (" ZR");  } else { printf ("   ");  }
	   if (pressed & WPAD_CLASSIC_BUTTON_FULL_L) { printf (" L");   } else { printf ("  ");   }
	   if (pressed & WPAD_CLASSIC_BUTTON_FULL_R) { printf ("R ");   } else { printf ("  ");   }
 	   if (pressed & WPAD_CLASSIC_BUTTON_HOME)   { printf ("Home"); } else { printf ("    "); }
	   
	   
	   // Etat des bouttons de la Wiimote avec WPAD_ButtonsHeld
	   pressed = WPAD_ButtonsHeld(WPAD_CHAN_0); 
	   gotoXY (3, 6);
	   printf("Boutons Nunchuk avec WPAD_ButtonsHeld: ");
	   if (pressed & WPAD_CLASSIC_BUTTON_LEFT)   { printf ("G"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_RIGHT)  { printf ("D"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_UP)     { printf ("H"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_DOWN)   { printf ("B"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_A)      { printf ("A"); }    else { printf (" "); }
	   if (pressed & WPAD_CLASSIC_BUTTON_B)      { printf ("B"); }    else { printf (" "); }
	   if (pressed & WPAD_CLASSIC_BUTTON_X)      { printf ("X"); }    else { printf (" "); }
	   if (pressed & WPAD_CLASSIC_BUTTON_Y)      { printf ("Y"); }    else { printf (" "); }                   
	   if (pressed & WPAD_CLASSIC_BUTTON_PLUS)   { printf ("+"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_MINUS)  { printf ("-"); }    else { printf (" "); }    
	   if (pressed & WPAD_CLASSIC_BUTTON_ZL)     { printf (" ZL");  } else { printf ("   ");  }
	   if (pressed & WPAD_CLASSIC_BUTTON_ZR)     { printf (" ZR");  } else { printf ("   ");  }
	   if (pressed & WPAD_CLASSIC_BUTTON_FULL_L) { printf (" L");   } else { printf ("  ");   }
	   if (pressed & WPAD_CLASSIC_BUTTON_FULL_R) { printf ("R ");   } else { printf ("  ");   }
 	   if (pressed & WPAD_CLASSIC_BUTTON_HOME)   { printf ("Home"); } else { printf ("    "); }	
	   
	   
	   // Etat des bouttons de la Wiimote avec WPAD_ButtonsUp
	   pressed = WPAD_ButtonsUp(WPAD_CHAN_0); 
	   gotoXY (3, 7);
	   printf("Boutons Nunchuk avec WPAD_ButtonsUp:   ");
	   if (pressed & WPAD_CLASSIC_BUTTON_LEFT)   { printf ("G"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_RIGHT)  { printf ("D"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_UP)     { printf ("H"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_DOWN)   { printf ("B"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_A)      { printf ("A"); }    else { printf (" "); }
	   if (pressed & WPAD_CLASSIC_BUTTON_B)      { printf ("B"); }    else { printf (" "); }
	   if (pressed & WPAD_CLASSIC_BUTTON_X)      { printf ("X"); }    else { printf (" "); }
	   if (pressed & WPAD_CLASSIC_BUTTON_Y)      { printf ("Y"); }    else { printf (" "); }                   
	   if (pressed & WPAD_CLASSIC_BUTTON_PLUS)   { printf ("+"); }    else { printf (" "); } 
	   if (pressed & WPAD_CLASSIC_BUTTON_MINUS)  { printf ("-"); }    else { printf (" "); }    
	   if (pressed & WPAD_CLASSIC_BUTTON_ZL)     { printf (" ZL");  } else { printf ("   ");  }
	   if (pressed & WPAD_CLASSIC_BUTTON_ZR)     { printf (" ZR");  } else { printf ("   ");  }
	   if (pressed & WPAD_CLASSIC_BUTTON_FULL_L) { printf (" L");   } else { printf ("  ");   }
	   if (pressed & WPAD_CLASSIC_BUTTON_FULL_R) { printf ("R ");   } else { printf ("  ");   }
 	   if (pressed & WPAD_CLASSIC_BUTTON_HOME)   { printf ("Home"); } else { printf ("    "); }
	   
     
	   // Joypads
	   WPAD_Expansion(WPAD_CHAN_0, &ext);
	   gotoXY (3, 9);
	   printf("Joypad Pos.      Left X:%2i Y:%2i     Right X:%2i Y:%2i ", ext.classic.ljs.pos.x,    ext.classic.ljs.pos.y,    ext.classic.rjs.pos.x,    ext.classic.rjs.pos.y);
	   gotoXY (3, 10);
	   printf("Joypad Center    Left X:%2i Y:%2i     Right X:%2i Y:%2i ", ext.classic.ljs.center.x, ext.classic.ljs.center.y, ext.classic.rjs.center.x, ext.classic.rjs.center.y);
	   gotoXY (3, 11);
	   printf("Joypad Min       Left X:%2i Y:%2i     Right X:%2i Y:%2i ", ext.classic.ljs.min.x,    ext.classic.ljs.min.y,    ext.classic.rjs.min.x,    ext.classic.rjs.min.y);
	   gotoXY (3, 12);  
	   printf("Joypad Max       Left X:%2i Y:%2i     Right X:%2i Y:%2i ", ext.classic.ljs.max.x,    ext.classic.ljs.max.y,    ext.classic.rjs.max.x,    ext.classic.rjs.max.y);
       
	   X1 =   ((ext.classic.ljs.pos.x - ext.classic.ljs.center.x) * 200 / (ext.classic.ljs.max.x - ext.classic.ljs.min.x));
	   Y1 = - ((ext.classic.ljs.pos.y - ext.classic.ljs.center.y) * 200 / (ext.classic.ljs.max.y - ext.classic.ljs.min.y));
	   X2 =   ((ext.classic.rjs.pos.x - ext.classic.rjs.center.x) * 200 / (ext.classic.rjs.max.x - ext.classic.rjs.min.x));
	   Y2 = - ((ext.classic.rjs.pos.y - ext.classic.rjs.center.y) * 200 / (ext.classic.rjs.max.y - ext.classic.rjs.min.y));
	   gotoXY (3, 14);
	   printf ("Valeur joypad par calcul    Left X:%4i Y:%4i    Right X:%4i Y:%4i ", X1, Y1, X2, Y2);
	   
	   X1 /= 4*3; Y1 /= 8*3;
	   gotoXY (20,    22);    printf ("+");
	   gotoXY (20+X1, 22+Y1); printf ("*");
	   
	   X2 /= 4*3; Y2 /= 8*3;
	   gotoXY (55,    22);    printf ("+");
	   gotoXY (55+X2, 22+Y2); printf ("*");
And finally for the Gamecube controller!

Code: Select all

           u32 pressed;
           PAD_ScanPads();
	   gotoXY (20+X1, 22-Y1); printf (".");	   
	   gotoXY (55+X2, 22-Y2); printf (".");
	   
	   // Etat des bouttons de la manette GameCube avec PAD_ButtonsDown
	   pressed = PAD_ButtonsDown(PAD_CHAN0);
	   gotoXY(3, 5);
	   printf("Boutons manette GameCube avec PAD_ButtonsDown: ");
	   if (pressed & PAD_BUTTON_A)     { printf ("A"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_B)     { printf ("B"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_X)     { printf ("X"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_Y)     { printf ("Y"); }      else { printf (" "); }
	   if (pressed & PAD_TRIGGER_Z)    { printf ("Z"); }      else { printf (" "); }
	   if (pressed & PAD_TRIGGER_L)    { printf ("L"); }      else { printf (" "); }
	   if (pressed & PAD_TRIGGER_R)    { printf ("R"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_LEFT)  { printf (" Gauche"); } else { printf ("       "); }
	   if (pressed & PAD_BUTTON_RIGHT) { printf (" Droit");  } else { printf ("      ");  }
	   if (pressed & PAD_BUTTON_UP)    { printf (" Haut");   } else { printf ("     ");   }
	   if (pressed & PAD_BUTTON_DOWN)  { printf (" Bas");    } else { printf ("    ");    }
	   
	   // Etat des bouttons de la manette GameCube avec PAD_ButtonsHeld
	   pressed = PAD_ButtonsHeld(PAD_CHAN0);
	   gotoXY(3, 6);
	   printf("Boutons manette GameCube avec PAD_ButtonsHeld: ");
	   if (pressed & PAD_BUTTON_A)     { printf ("A"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_B)     { printf ("B"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_X)     { printf ("X"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_Y)     { printf ("Y"); }      else { printf (" "); }
	   if (pressed & PAD_TRIGGER_Z)    { printf ("Z"); }      else { printf (" "); }
	   if (pressed & PAD_TRIGGER_L)    { printf ("L"); }      else { printf (" "); }
	   if (pressed & PAD_TRIGGER_R)    { printf ("R"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_LEFT)  { printf (" Gauche"); } else { printf ("       "); }
	   if (pressed & PAD_BUTTON_RIGHT) { printf (" Droit");  } else { printf ("      ");  }
	   if (pressed & PAD_BUTTON_UP)    { printf (" Haut");   } else { printf ("     ");   }
	   if (pressed & PAD_BUTTON_DOWN)  { printf (" Bas");    } else { printf ("    ");    }
	   
	   // Etat des bouttons de la manette GameCube avec PAD_ButtonsUp
	   pressed = PAD_ButtonsUp(PAD_CHAN0);
	   gotoXY(3, 7);
	   printf("Boutons manette GameCube avec PAD_ButtonsUp:   ");
	   if (pressed & PAD_BUTTON_A)     { printf ("A"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_B)     { printf ("B"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_X)     { printf ("X"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_Y)     { printf ("Y"); }      else { printf (" "); }
	   if (pressed & PAD_TRIGGER_Z)    { printf ("Z"); }      else { printf (" "); }
	   if (pressed & PAD_TRIGGER_L)    { printf ("L"); }      else { printf (" "); }
	   if (pressed & PAD_TRIGGER_R)    { printf ("R"); }      else { printf (" "); }
	   if (pressed & PAD_BUTTON_LEFT)  { printf (" Gauche"); } else { printf ("       "); }
	   if (pressed & PAD_BUTTON_RIGHT) { printf (" Droit");  } else { printf ("      ");  }
	   if (pressed & PAD_BUTTON_UP)    { printf (" Haut");   } else { printf ("     ");   }
	   if (pressed & PAD_BUTTON_DOWN)  { printf (" Bas");    } else { printf ("    ");    }
	   
	   
	   // Etat des joypads de la manette GameCube
	   X1 = PAD_StickX(PAD_CHAN0);
	   Y1 = PAD_StickY(PAD_CHAN0);	
	   X2 = PAD_SubStickX(PAD_CHAN0);
	   Y2 = PAD_SubStickY(PAD_CHAN0);  
	   
	   gotoXY (3, 9);
	   printf("PAD_StickX:   %3i - PAD_StickY:   %3i ", X1, Y1);
	   gotoXY (3, 10);
	   printf("PAD_SubStickX:%3i - PAD_SubStickY:%3i ", X2, Y2);
	   gotoXY (3, 11);
	   printf("PAD_TriggerL: %3i - PAD_TriggerR: %3i ", PAD_TriggerL(PAD_CHAN0), PAD_TriggerR(PAD_CHAN0));
	   
	   X1 /= 4*2; Y1 /= 8*2;
	   gotoXY (20,    22);    printf ("+");
	   gotoXY (20+X1, 22-Y1); printf ("*");
	   
	   X2 /= 4*2; Y2 /= 8*2;
	   gotoXY (55,    22);    printf ("+");
	   gotoXY (55+X2, 22-Y2); printf ("*");

3. Using the wii's restart modes! Now that I've covered everything about using controllers, we're going to talk about the wii's restart modes, turning off the wii, returning to the loader.

For this add the line for the wiimote:

To return to the loader:

Code: Select all

if ( pressed & WPAD_BUTTON_HOME ) { exit(0); }
Or to return to the wii menu

Code: Select all

if ( pressed & WPAD_BUTTON_HOME ) { SYS_ResetSystem(SYS_RETURNTOMENU,0,0); }
Or to restart the wii

Code: Select all

if ( pressed & WPAD_BUTTON_HOME ) { SYS_ResetSystem(SYS_RESTART,0,0); }
Or to turn off the wii

Code: Select all

if ( pressed & WPAD_BUTTON_HOME ) { SYS_ResetSystem(SYS_POWEROFF,0,0); }

To be added after the other if (pressed & WPAD_BUTTON_xx )....

For the classic controller just replace
pressed & WPAD_BUTTON_HOME with pressed & WPAD_CLASSIC_BUTTON_HOME

That will still work.

For the Gamecube controller just replace
pressed & WPAD_BUTTON_HOME with pressed & PAD_BUTTON_START

There we go, we're done with the tutorial on Controller functions, video/controller initialization and the wii's restart modes!!

If you want to make a good 2D game, start by reading section 2 of the Zéro site, SDL is also available on wii, it will let you make complex programs. ;)
Youtube Officiel du forum Tgames : ICI
User avatar
kyno
Gamer
Members
Posts: 1096
Joined: Sat 18 Oct 2008 10:32
Wi-Fi: Oui
Firmware Wii: 3.4E
CFW Wii: CIOS57Rev19+hermesv5
PS3 Dongle: Aucun

Re: [Wii Programming] Creating the first Wii program

Post by kyno »

Automatically translated from French.

I didn't find it on the site du zero o_O, can you help me please? :lol:
Reigning challenge champion User avatar
Tgames
Geek
Administrators
Posts: 3909
Joined: Sun 21 Sep 2008 09:15
Wi-Fi: Oui
Firmware Wii: 4.1E
CFW Wii: Cios57 Rev19
Type de DS: 3DS
Linker DS: M3i Zero
CFW PS3: 3.55 PS3MFW
PS3 Dongle: PS3Key
Type PSP: Slim
Firmware PSP: 5.00-M33 CFW
Location: France

Re: [Wii Programming] Creating the first Wii program

Post by Tgames »

Automatically translated from French.

Youtube Officiel du forum Tgames : ICI
User avatar
kyno
Gamer
Members
Posts: 1096
Joined: Sat 18 Oct 2008 10:32
Wi-Fi: Oui
Firmware Wii: 3.4E
CFW Wii: CIOS57Rev19+hermesv5
PS3 Dongle: Aucun

Re: [Wii Programming] Creating the first Wii program

Post by kyno »

Automatically translated from French.

ah ok :lol: sorry I thought there was a wii section :lol: :lol: (you can immediately see how smart I am ^^)
For the Gamecube controller you just need to replace
pressed & WPAD_BUTTON_HOME with pressed & PAD_BUTTON_START
and if you want to press the z button for example, you put For the Gamecube controller you just need to replace
pressed & WPAD_BUTTON_HOME with pressed & PAD_TRIGGER_Z??
CashMan
Novice
Members
Posts: 34
Joined: Sun 21 Sep 2008 12:07
Wi-Fi: Oui
Firmware Wii: 3.3J
CFW Wii: IOS38 rev14

Re: [Wii Programming] Creating the first Wii program

Post by CashMan »

Automatically translated from French.

GRRLIB 3.0.1 is more reliable for 2D programming on Wii than SDL ;)
User avatar
floriolink
Novice
Members
Posts: 88
Joined: Sat 18 Oct 2008 11:25
Wi-Fi: Oui
Firmware Wii: 3.2U
CFW Wii: Cios 36rev6

Re: [Wii Programming] Creating the first Wii program

Post by floriolink »

Automatically translated from French.

how do you compile to .dol or .elf?
User avatar
floriolink
Novice
Members
Posts: 88
Joined: Sat 18 Oct 2008 11:25
Wi-Fi: Oui
Firmware Wii: 3.2U
CFW Wii: Cios 36rev6

Re: [Wii Programming] Creating the first Wii program

Post by floriolink »

Automatically translated from French.

I really can't find it even with devkit pro. When I run make it tells me the specified file can't be found.
help me please
Reigning challenge champion User avatar
Tgames
Geek
Administrators
Posts: 3909
Joined: Sun 21 Sep 2008 09:15
Wi-Fi: Oui
Firmware Wii: 4.1E
CFW Wii: Cios57 Rev19
Type de DS: 3DS
Linker DS: M3i Zero
CFW PS3: 3.55 PS3MFW
PS3 Dongle: PS3Key
Type PSP: Slim
Firmware PSP: 5.00-M33 CFW
Location: France

Re: [Wii Programming] Creating the first Wii program

Post by Tgames »

Automatically translated from French.

you need to be in the folder where the make file is (without extension)
Youtube Officiel du forum Tgames : ICI
User avatar
floriolink
Novice
Members
Posts: 88
Joined: Sat 18 Oct 2008 11:25
Wi-Fi: Oui
Firmware Wii: 3.2U
CFW Wii: Cios 36rev6

Re: [Wii Programming] Creating the first Wii program

Post by floriolink »

Automatically translated from French.

still doesn't work, can you try to be more specific please?!
Reigning challenge champion User avatar
Tgames
Geek
Administrators
Posts: 3909
Joined: Sun 21 Sep 2008 09:15
Wi-Fi: Oui
Firmware Wii: 4.1E
CFW Wii: Cios57 Rev19
Type de DS: 3DS
Linker DS: M3i Zero
CFW PS3: 3.55 PS3MFW
PS3 Dongle: PS3Key
Type PSP: Slim
Firmware PSP: 5.00-M33 CFW
Location: France

Re: [Wii Programming] Creating the first Wii program

Post by Tgames »

Automatically translated from French.

Using a command prompt (CMD), you type the cd commands to get into the folder that contains the sources and that also has a makefile or wiimakefile or make file (without any extension).

Example: I want to compile a program located in the directory C:\DevKitPro\Exemple\Wii\MonHB

you type: cd... several times to reach c:/

Then you type cd DevkitPro, then cd Exemple, etc...

Then you type make

There you go that's all.
Youtube Officiel du forum Tgames : ICI
User avatar
floriolink
Novice
Members
Posts: 88
Joined: Sat 18 Oct 2008 11:25
Wi-Fi: Oui
Firmware Wii: 3.2U
CFW Wii: Cios 36rev6

Re: [Wii Programming] Creating the first Wii program

Post by floriolink »

Automatically translated from French.

Thanks tgames for your help but unfortunately it doesn't work and I'd like to show the extent of the problem:
Already my project is named: my programme wii.dol and is located at: C:\DevKitPro\Exemple\Wii\Mon application\my programme wii.dol
The error during the make action is:
> "make"
> Failed to create process: The specified file cannot be found.
> Process Exit Code: 0
> Time Taken: 00:00
I wrote all the code then I launch the file: template.PNPROJ, there I click on make and it gives me the error, help me please :cry:
I'd add that when I launch the main.c file that was already in the archive downloaded with devkit pro and I run make it doesn't work
User avatar
floriolink
Novice
Members
Posts: 88
Joined: Sat 18 Oct 2008 11:25
Wi-Fi: Oui
Firmware Wii: 3.2U
CFW Wii: Cios 36rev6

Re: [Wii Programming] Creating the first Wii program

Post by floriolink »

Automatically translated from French.

would anyone have an idea please

Everything for PC