Bienvenue sur mon blog de programation sur la wii.Je n'ai pas programé depuis depuis plus d'une décenie alors mes programme seront assez de base pour le moment. Pourquoi sur la wii? Bien pkoi pas. La scene homebrew (logiciel maison) explose en se moment et j'ai envie de participé. Du moin comme je le peux. Pour ceux qui ne sont pas au courant il es possible grace a un hack de zelda twilight princess de fair rouler des logiciel maison sans aucune modification materiel de la wii. Aller voir sur www.wiibrew.org tout y es. Je suis tres peux familier avec la programation c/c++ alors pour mon premier programe jai seulement modifier un exemple de code disponible ici.
Voila ma version "pimpé" du "hello world!". Ce programe affiche un "hello world!" qui se deplace a lecran et bondit sur les coté de limage. Vous remarquerer p-e un erreur de programation. Les coordonné x et y on été inversé. Voila le code:
#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <iostream>
using namespace std ;
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
//---------------------------------------------------------------------------------
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();
// The console understands VT terminal escape codes
// This positions the cursor on row 2, column 0
// we can use variables for this with format codes too
// e.g. printf ("\x1b[%d;%dH", row, column );
// les lignes suivante vienne du "hello world" original
// printf("\x1b[0;0H");
// printf("Hello World!");
// initiation des variables
int x = 0 ;
int y = 0 ;
int xv = 1 ;
int yv = 1 ;
int wait ;
while(1) {
printf("\x1b[%d;%dH", x , y );
printf(" "); // efface la derniere ecriture
x = x + xv ;//Deplace x
if ( x > 28 ) {
xv = -1 ; // si x es a la limite de lecran effectuer la variation contraire
}
if ( x < 1 ) {
xv = 1 ; // si x es au debut de lecran effectuer la variation contraire
}
y = y + yv ; // meme chose maitenant avec la coordone y
if ( y > 67 ) {
yv = -1 ;
}
if ( y < 1 ) {
yv = 1 ;
}
printf("\x1b[%d;%dH", x, y ); // ecrit hello world selon les nouvelles coordonee
printf("Hello world!");
wait = 0;
while ( wait < 10 ) { // ajout dune boucle pour ralentire le defilement. Ici on verifi si la touche home de la wii mote es pressé
wait++;
// Call WPAD_ScanPads each loop, this reads the latest controller states
WPAD_ScanPads();
// WPAD_ButtonsDown tells us which buttons were pressed in this loop
// this is a "one shot" state which will not fire again until the button has been released
u32 pressed = WPAD_ButtonsDown(0);
// We return to the launcher application via exit
if ( pressed & WPAD_BUTTON_HOME ) exit(0);
// l'ancienne version verifiais si le botton a etais afoncé et affichais un msg
// if (pressed & WPAD_BUTTON_A)
// {
// cout<<"You pushed the A button \n";
// }
// Wait for the next frame
VIDEO_WaitVSync();
}
}
return 0;
}
NB: Les commantaire en anglais vienne du code original
mardi 8 juillet 2008
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire