#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <mp3player.h>
#include <fat.h>
#include <network.h>
#include "GRRLIB.h"
#include "..\fonts\font5.h"
#include "..\gfx\logo.h"
#include "..\sfx\intro.c"
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
extern u16 *GRRLIB_buffer;
u32 pressed;
void Reboot()
{
int fd = IOS_Open("/dev/stm/immediate",0);
IOS_Ioctl(fd,0x2001,NULL,0,NULL,0);
IOS_Close(fd);
}
void loader()
{
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);
#define WHITE 0xffff
#define BLACK 0x0000
#define DEST_IP "72.14.207.99"
#define DEST_PORT 80
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
GRRLIB_buffer = (u16 *)malloc(640*480*2);
// 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();
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;
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(DEST_PORT);
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
// memset(dest_addr.sin_zero,'\0',sizeof(dest_addr.sin_zero));
GRRLIB_Print(50,240,font5_char_width,font5_char_high,"Connecting to Socket...",font5,BLACK,WHITE);GRRLIB_Render();
if(net_connect(s,(struct sockaddr *)&dest_addr,sizeof(dest_addr)) < 0)
{
GRRLIB_Print(50,260,font5_char_width,font5_char_high,"Connection Failed.",font5,BLACK,WHITE);GRRLIB_Render();
}
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) {
// Make sure the Music Stays Looping!
if(!MP3Player_IsPlaying()) MP3Player_PlayBuffer(intro,size_intro,NULL);
// 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
pressed = WPAD_ButtonsDown(0);
// We return to the launcher application via exit
if ( pressed & WPAD_BUTTON_HOME )
{
if (MP3Player_IsPlaying())
{
MP3Player_Stop();
}
loader();
}
// Wait for the next frame
VIDEO_WaitVSync();
}
return 0;
}