Line 1:
Line 1:
<pre>
<pre>
−
#include <stdio.h>
+
// Libraries
−
#include <stdlib.h>
+
#include <wiiuse/wpad.h>
−
#include <gccore.h>
+
#include <ogc/lwp_watchdog.h>
−
#include <wiiuse/wpad.h>
+
#include <wiisprite.h>
−
#include <mp3player.h>
+
#include <mp3player.h>
−
#include <fat.h>
−
#include <network.h>
−
#include "GRRLIB.h"
+
// Graphics
−
#include "..\fonts\font5.h"
+
#include "aurora_png.h"
−
#include "..\gfx\logo.h"
+
#include "banner_png.h"
−
#include "..\sfx\intro.c"
−
static void *xfb = NULL;
+
// Music
−
static GXRModeObj *rmode = NULL;
+
#include "syst002_mp3.h"
−
extern u16 *GRRLIB_buffer;
−
u32 pressed;
−
void Reboot()
+
using namespace wsp;
−
{
−
int fd = IOS_Open("/dev/stm/immediate",0);
−
IOS_Ioctl(fd,0x2001,NULL,0,NULL,0);
−
IOS_Close(fd);
−
}
−
void loader()
+
// Variables
−
{
+
GameWindow gwd;
−
GRRLIB_FillScreen(0x0000);
−
GRRLIB_Render();
−
exit(0);
−
}
−
#define GRRPrint(line,text,fgcolor,bgcolor); GRRLIB_Print(50,50+font5_char_high*line,font5_char_width,font5_char_high,text,font5,fgcolor,bgcolor);
+
Sprite logo;
−
#define WHITE 0xffff
+
Image logoImage;
−
#define BLACK 0x0000
−
#define DEST_IP "72.14.207.99"
+
Sprite backdrop;
−
#define DEST_PORT 80
+
Image bgImage;
−
//---------------------------------------------------------------------------------
−
int main(int argc, char **argv) {
−
//---------------------------------------------------------------------------------
−
GRRLIB_buffer = (u16 *)malloc(640*480*2);
+
// Return to Loader
−
+
void gotoLoader()
−
// Initialise the video system
+
{
−
VIDEO_Init();
+
gwd.SetBackground((GXColor){0,0,0,255}); // Set Background Black
−
+
gwd.Flush(); // Flush the Output
−
// This function initialises the attached controllers
+
if (MP3Player_IsPlaying()) { MP3Player_Stop(); }
−
WPAD_Init();
+
exit(0); // Exit without Errors
−
−
// 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();
−
−
GRRLIB_InitVideo();
−
GRRLIB_Start();
−
−
GRRLIB_FillScreen(0xFFFF);
−
GRRLIB_Render();
−
VIDEO_WaitVSync();
−
−
GRRLIB_DrawImg(80,50,logo_width,logo_high,logo_img,0,1);
−
−
GRRLIB_Print(50,200,font5_char_width,font5_char_high,"Starting Music...",font5,BLACK,WHITE);
−
−
GRRLIB_Render();
−
−
MP3Player_Init();
−
MP3Player_PlayBuffer(intro,size_intro,NULL);
−
−
GRRLIB_Print(50,220,font5_char_width,font5_char_high,"Creating Socket...",font5,BLACK,WHITE);GRRLIB_Render();
−
−
while(net_init()==-11);
−
−
int s;
−
s = net_socket(AF_INET,SOCK_STREAM,0);
−
−
if(s < 0)
−
{
−
GRRLIB_Print(50,240,font5_char_width,font5_char_high,"Failed Creation.",font5,BLACK,WHITE);GRRLIB_Render();
−
while(!WPAD_ButtonsDown(0)) { /* Do Nothing */ }
−
loader();
}
}
−
struct sockaddr_in dest_addr;
+
// Main Function
+
int main(int argc, char **argv)
+
{
+
gwd.InitVideo();
+
LayerManager manager(3);
+
+
// Set the Background Black
+
gwd.SetBackground((GXColor){0,0,0,255});
−
dest_addr.sin_family = AF_INET;
+
// Load the PoKéQuesT Logo
−
dest_addr.sin_port = htons(DEST_PORT);
+
if(logoImage.LoadImage(banner_png) != IMG_LOAD_ERROR_NONE) exit(0);
−
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
+
logo.SetImage(&logoImage);
−
// memset(dest_addr.sin_zero,'\0',sizeof(dest_addr.sin_zero));
+
// Position it
+
logo.SetPosition(88,0);
+
manager.Append(&logo);
−
GRRLIB_Print(50,240,font5_char_width,font5_char_high,"Connecting to Socket...",font5,BLACK,WHITE);GRRLIB_Render();
+
// Load the Background
+
if(bgImage.LoadImage(aurora_png) != IMG_LOAD_ERROR_NONE) exit(0);
+
backdrop.SetImage(&bgImage);
+
// Position it
+
backdrop.SetPosition(10,10);
+
manager.Append(&backdrop);
+
+
// Get Wiimote Working
+
WPAD_Init();
+
WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
−
if(net_connect(s,(struct sockaddr *)&dest_addr,sizeof(dest_addr)) < 0)
+
// Music!
−
{
+
MP3Player_Init();
−
GRRLIB_Print(50,260,font5_char_width,font5_char_high,"Connection Failed.",font5,BLACK,WHITE);GRRLIB_Render();
+
MP3Player_PlayBuffer(syst002_mp3,syst002_mp3_size,NULL);
−
}
−
else
−
{
−
GRRLIB_Print(50,260,font5_char_width,font5_char_high,"Connection Succesful.",font5,BLACK,WHITE);GRRLIB_Render();
−
net_close(s);
−
GRRLIB_Print(50,280,font5_char_width,font5_char_high,"Closed Connection.",font5,BLACK,WHITE);GRRLIB_Render();
−
}
−
−
−
while(1) {
+
// Start Thread for Home Button
−
// Make sure the Music Stays Looping!
+
// lwp_t homeButtonThread;
−
if(!MP3Player_IsPlaying()) MP3Player_PlayBuffer(intro,size_intro,NULL);
+
// LWP_CreateThread(&homeButtonThread,homeButton,NULL,NULL,0,80);
−
// Call WPAD_ScanPads each loop, this reads the latest controller states
+
while(true)
−
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
−
pressed = WPAD_ButtonsDown(0);
−
−
// We return to the launcher application via exit
−
if ( pressed & WPAD_BUTTON_HOME )
{
{
−
if (MP3Player_IsPlaying())
+
if (!MP3Player_IsPlaying()) { MP3Player_PlayBuffer(syst002_mp3,syst002_mp3_size,NULL); }
−
{
+
WPAD_ScanPads();
−
MP3Player_Stop();
+
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) { gotoLoader(); }
−
}
+
manager.Draw(0,0);
−
loader();
+
gwd.Flush();
}
}
−
+
manager.Draw(0,0);
−
// Wait for the next frame
+
gwd.Flush();
−
VIDEO_WaitVSync();
+
return 0;
}
}
−
−
return 0;
−
}
</pre>
</pre>