In memory of Ben “bushing” Byer, who passed away on Monday, February 8th, 2016.

Difference between revisions of "User:Cboomf"

From WiiBrew
Jump to navigation Jump to search
Line 33: Line 33:
 
#include <ogc/es.h>
 
#include <ogc/es.h>
 
#include <ogc/gu.h>
 
#include <ogc/gu.h>
 +
#include <ogc/usb.h>
 +
#include <bte/bte.h>
  
 
static void *xfb = NULL;
 
static void *xfb = NULL;
Line 51: Line 53:
 
typedef void (*Loader_Entry)(void);
 
typedef void (*Loader_Entry)(void);
 
static u32 *xjb;
 
static u32 *xjb;
 +
 +
wiimote** wiimotes;
  
 
Loader_Entry loader = (Loader_Entry)0x80001800;
 
Loader_Entry loader = (Loader_Entry)0x80001800;
  
 
extern u16 *GRRLIB_buffer;
 
extern u16 *GRRLIB_buffer;
 +
unsigned int buttonA=0;
 +
unsigned int buttonB=0;
 +
unsigned int buttonUp=0;
 +
unsigned int buttonDown=0;
 +
unsigned int buttonLeft=0;
 +
unsigned int buttonRight=0;
 +
unsigned int buttonPlus=0;
 +
unsigned int buttonMinus=0;
 +
unsigned int buttonHome=0;
 +
unsigned int buttonOne=0;
 +
unsigned int buttonTwo=0;
 +
unsigned int rumble=0;
 +
unsigned int irx=0,iry=0;
  
 
void wiimote_event(struct wiimote_t* wm, int event)
 
void wiimote_event(struct wiimote_t* wm, int event)
 
{
 
{
 +
    wiiuse_rumble(wiimotes[0], rumble);
 +
switch (event) {
 +
case WIIUSE_EVENT:
 +
 +
buttonB=0;
 +
buttonA=0;
 +
buttonUp=0;
 +
buttonDown=0;
 +
buttonLeft=0;
 +
buttonRight=0;
 +
buttonPlus=0;
 +
buttonMinus=0;
 +
buttonHome=0;
 +
buttonOne=0;
 +
buttonTwo=0;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_B))
 +
buttonB=1;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_A))
 +
    buttonA=1;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP))
 +
    buttonUp=1;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
 +
    buttonDown=1;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT))
 +
    buttonLeft=1;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT))
 +
    buttonRight=1;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME))
 +
    buttonHome=1;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE))
 +
    buttonOne=1;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO))
 +
    buttonTwo=1;
 +
 +
if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
 +
    buttonPlus=1;
 +
 +
if ( IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
 +
    buttonMinus=1;
 +
 +
break;
 +
 +
default:
 +
break;
 +
}
 +
 
}
 
}
  
 
void hello(void)
 
void hello(void)
 
{
 
{
     printf("Hello world!\n");
+
     printf("   Hello world!\n");
printf("v 0.3");
+
printf("   v 0.45");
 
}
 
}
  
 
void menutext(void)
 
void menutext(void)
 
{
 
{
     printf("Menu\n");
+
     printf("   Menu\n");
printf("----\n");
+
printf("   ----\n");
printf("Start + Z   = Return to loader\n");
+
printf("    Home        = Return to loader\n");
printf("A !!         = Elf Loader\n");
+
printf("   Up  !!     = Elf Loader\n");
printf("B !!         = System Utils\n");
+
printf("   Down !!     = System Utils\n");
printf("Y !         = Fun\n");
+
printf("   Left !       = Fun\n");
printf("X            = Reboot Wii\n");
+
printf("   Right        = Reboot Wii\n");
 
     return;
 
     return;
 
}
 
}
Line 86: Line 158:
  
 
void checkAndReload(void) {
 
void checkAndReload(void) {
  PAD_ScanPads();
+
   if((buttonHome==1)){
  int buttonsDown = PAD_ButtonsHeld(0);
 
   if( (buttonsDown & PAD_TRIGGER_Z) && (buttonsDown & PAD_BUTTON_START)) {
 
 
     loader();
 
     loader();
 
   }
 
   }
Line 96: Line 166:
 
     xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
 
     xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
 
xjb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
 
xjb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
+
CON_Init(xfb,20,120,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
 
 
 
VIDEO_Configure(rmode);
 
VIDEO_Configure(rmode);
Line 121: Line 191:
 
__STM_Init();
 
__STM_Init();
 
    
 
    
     printf("FUN\n");
+
     printf("   FUN\n");
printf("---\n\n");
+
printf("   ---\n\n");
 
 
 
int ver;
 
int ver;
Line 134: Line 204:
 
revma=IOS_GetRevisionMajor();
 
revma=IOS_GetRevisionMajor();
 
revmi=IOS_GetRevisionMinor();
 
revmi=IOS_GetRevisionMinor();
     printf("IOS Version : %d  Revision : %d.%d \n\n", ver, revma, revmi);
+
     printf("   IOS Version : %d  Revision : %d.%d \n\n", ver, revma, revmi);
 
 
 
 
Line 140: Line 210:
 
     ((u32*)stm_inbuf)[0x00] = 0x70000000;
 
     ((u32*)stm_inbuf)[0x00] = 0x70000000;
 
IOS_Ioctl( di_fd, stm_inbuf[0x00], stm_inbuf, 0x20, stm_iobuf, 0x20);
 
IOS_Ioctl( di_fd, stm_inbuf[0x00], stm_inbuf, 0x20, stm_iobuf, 0x20);
printf("DVD ID : %s \n\n",stm_iobuf);
+
printf("   DVD ID : %s \n\n",stm_iobuf);
 
IOS_Close(di_fd);
 
IOS_Close(di_fd);
 
 
GRRLIB_DrawImg(10,50, music_width, music_high, music_img, 0, 1);
+
//GRRLIB_DrawImg(10,50, music_width, music_high, music_img, 0, 1);
GRRLIB_Render();
+
//GRRLIB_Render();
 +
 +
printf("    Press + to rumble\n");
 +
printf("    Press - to stop\n\n");
 
 
printf("Press A to continue\n");
+
printf("   Press A to continue\n");
 
while(1) {
 
while(1) {
 
VIDEO_WaitVSync();
 
VIDEO_WaitVSync();
PAD_ScanPads();
+
if ((buttonA==1)){
int buttonsDown = PAD_ButtonsHeld(0);
 
if (buttonsDown & PAD_BUTTON_A){
 
 
    console();
 
    console();
 
             clearscreen();
 
             clearscreen();
Line 158: Line 229:
 
        return;       
 
        return;       
 
    }
 
    }
 +
if ((buttonPlus==1)){
 +
    rumble=1;
 +
}
 +
if ((buttonMinus==1)){
 +
    rumble=0;
 +
}
 
}
 
}
 
}
 
}
Line 167: Line 244:
 
VIDEO_WaitVSync();
 
VIDEO_WaitVSync();
 
    checkAndReload();
 
    checkAndReload();
PAD_ScanPads();
+
if ((buttonLeft==1)){
int buttonsDown = PAD_ButtonsHeld(0);
 
if (buttonsDown & PAD_BUTTON_Y){
 
 
             fun();
 
             fun();
 
    }
 
    }
if (buttonsDown & PAD_BUTTON_X){
+
if ((buttonRight==1)){
 
             shutdown();
 
             shutdown();
 
    }
 
    }
if (buttonsDown & PAD_BUTTON_B){
+
if ((buttonDown==1)){
 
    //sysutils();
 
    //sysutils();
 
}
 
}
if (buttonsDown & PAD_BUTTON_A){
+
if ((buttonUp==1)){
 
    //elfloader();
 
    //elfloader();
 
}
 
}
Line 186: Line 261:
  
 
void start(void) {
 
void start(void) {
    PAD_ScanPads();
+
if((buttonB==1)) {
    int buttonsDown = PAD_ButtonsHeld(0);
+
  menu();
    if(buttonsDown & PAD_BUTTON_START) {
+
}
      menu();
 
    }
 
 
}
 
}
  
 
int main(int argc, char **argv) {
 
int main(int argc, char **argv) {
  
  /****************************************************************************  
+
    /****************************************************************************  
 
Initialise Video
 
Initialise Video
 
     Initialise GCPad for input
 
     Initialise GCPad for input
Line 201: Line 274:
  
 
GRRLIB_buffer=(u16 *)malloc(640*240*2);
 
GRRLIB_buffer=(u16 *)malloc(640*240*2);
wiimote** wiimotes;
 
 
 
 
VIDEO_Init();
 
VIDEO_Init();
 
PAD_Init();
 
PAD_Init();
 
 
*((u32*)0xcd0000c0) |= 0x100;
+
//rmode = &TVPal528IntDf;
bte_init();
+
bte_start();
 
wiimotes = wiiuse_init(MAX_WIIMOTES,wiimote_event);
 
 
GRRLIB_InitVideo();
 
GRRLIB_Start();
 
GRRLIB_FillScreen(0x0000);
 
GRRLIB_Render();
 
 
 
 
switch(VIDEO_GetCurrentTvMode()) {
 
switch(VIDEO_GetCurrentTvMode()) {
 
case VI_NTSC:
 
case VI_NTSC:
Line 233: Line 297:
 
console();
 
console();
 
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
 
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
 +
 +
printf("    Press 1&2\n\n");
 +
 +
*((u32*)0xcd0000c0) |= 0x100;
 +
bte_init();
 +
bte_start();
 +
wiimotes = wiiuse_init(MAX_WIIMOTES,wiimote_event);
 +
wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
 +
wiiuse_connect(wiimotes, MAX_WIIMOTES);
 +
wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);
 +
wiiuse_rumble(wiimotes[0], 1);
 +
usleep(200000); /* 200ms */
 +
wiiuse_rumble(wiimotes[0], 0);
 +
 +
clearscreen();
 +
 +
GRRLIB_InitVideo();
 +
GRRLIB_Start();
 +
GRRLIB_FillScreen(0x0000);
 +
GRRLIB_Render();
 +
 +
console();
 
 
 
     /****************************************************************************  
 
     /****************************************************************************  
Line 240: Line 326:
 
hello();
 
hello();
 
printf("\n");
 
printf("\n");
printf("My first native wii homebrew\n\n");
+
printf("   My first native wii homebrew\n\n");
printf("Press Start :-)\n\n");
+
printf("   Press B :-)\n\n");
 
 
 
while(1) {
 
while(1) {
Line 250: Line 336:
 
return 0;
 
return 0;
 
}
 
}
 +
 +
  
 
</source>
 
</source>

Revision as of 11:15, 27 April 2008

I am a NERD ;-)

PC SPECS :-

1: PIII 750MHz (over clocked to 800MHz), 64MB Dual Screen Graphics Card, 256MB Ram, 20GB Hard Drive, Win 98 + Ubuntu 7.10
2: Celeron 1.2GHz, 16MB Graohics Card, 512 MB Ram, 2x 15GB Hard Drives, Ubuntu 7.10
3: Celeron 1.2GHz, 16MB Graphics Card, 256 MB Ram, 20GB Hard Drive, Win 98
4: AMD Athlon 1.8GHz, 128MB Graphics Card, 512MB Ram, 80GB Hard Drive, Win XP
5: P1 233MHz, 8MB Graphics Card, 256MB Ram, 3GB Hard Drive, Win 95
6: LAPTOP : Celeron 1.7GHz, 230MB Graphics Card, 1GB Ram, 2x 20GB Hard Drives, Win XP + Ubuntu 7.10


I am currently coding ( attempting ;-) ) a package of seemingly random bits of code that may server a purpose, may not but, it is just to learn C and have some fun with my wii.

If someone can improve it put any improvements in the Updates section at the bottom ;-)

Code dump :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <ogc/ipc.h>
#include <stdarg.h>
#include <ctype.h>
#include <unistd.h>
#include <assert.h>
#include <ogc/ios.h>
#include <ogc/stm.h>
#include <ogc/es.h>
#include <ogc/gu.h>
#include <ogc/usb.h>
#include <bte/bte.h>

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

#define USB_ALIGN __attribute__ ((aligned(32)))

#define MAX_WIIMOTES				4

#include "GRRLIB.h"

#include "wiiuse.h"

#include "../gfx/music.h"
#include "../gfx/cursor.h"
#include "../gfx/impact.h"

typedef void (*Loader_Entry)(void);
static u32 *xjb;

wiimote** wiimotes;

Loader_Entry loader = (Loader_Entry)0x80001800;

extern u16 *GRRLIB_buffer;
unsigned int buttonA=0;
unsigned int buttonB=0;
unsigned int buttonUp=0;
unsigned int buttonDown=0;
unsigned int buttonLeft=0;
unsigned int buttonRight=0;
unsigned int buttonPlus=0;
unsigned int buttonMinus=0;
unsigned int buttonHome=0;
unsigned int buttonOne=0;
unsigned int buttonTwo=0;
unsigned int rumble=0;
unsigned int irx=0,iry=0;

void wiimote_event(struct wiimote_t* wm, int event)
{
    wiiuse_rumble(wiimotes[0], rumble);
	switch (event) {
		case WIIUSE_EVENT:
		
			buttonB=0;
			buttonA=0;
			buttonUp=0;
			buttonDown=0;
			buttonLeft=0;
			buttonRight=0;
			buttonPlus=0;
			buttonMinus=0;
			buttonHome=0;
			buttonOne=0;
			buttonTwo=0;

			if (IS_PRESSED(wm, WIIMOTE_BUTTON_B))
				buttonB=1;
				
			if (IS_PRESSED(wm, WIIMOTE_BUTTON_A))
			    buttonA=1;
				
			if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP))
			    buttonUp=1;
				
			if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN))
			    buttonDown=1;
				
			if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT))
			    buttonLeft=1;
				
			if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT))
			    buttonRight=1;
				
			if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME))
			    buttonHome=1;
				
			if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE))
			    buttonOne=1;
				
			if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO))
			    buttonTwo=1;
				
			if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
			    buttonPlus=1;
				
			if ( IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
			    buttonMinus=1;
				
			break;
		
		default:
			break;
	}

}

void hello(void)
{
    printf("    Hello world!\n");
	printf("    v 0.45");
}

void menutext(void)
{
    printf("    Menu\n");
	printf("    ----\n");
	printf("    Home         = Return to loader\n");
	printf("    Up   !!      = Elf Loader\n");
	printf("    Down !!      = System Utils\n");
	printf("    Left !       = Fun\n");
	printf("    Right        = Reboot Wii\n");
    return;
}

void clearscreen(void)
{
		int y;
	    for(y=0;y<34;y++)
			printf("                                                                          \n");
}

void checkAndReload(void) {
  if((buttonHome==1)){
    loader();
  }
}

void console(void) {
    xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	xjb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	CON_Init(xfb,20,120,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();
}

void sysutils(void) { 
	return;
}

void shutdown(void) {
    __STM_Init();
	STM_RebootSystem();
	__STM_Close();
}

void fun(void) {

    clearscreen();
	__STM_Init();
  
    printf("    FUN\n");
	printf("    ---\n\n");
	
	int ver;
	int revma;
	int revmi;
	int di_fd;
	static u8 stm_inbuf[0x20] ATTRIBUTE_ALIGN(32);
	static u8 stm_iobuf[0x20] ATTRIBUTE_ALIGN(32);
	
	ver=IOS_GetVersion();
	revma=IOS_GetRevisionMajor();
	revmi=IOS_GetRevisionMinor();
    printf("    IOS Version : %d   Revision : %d.%d \n\n", ver, revma, revmi);
	
	
	di_fd=IOS_Open("/dev/di",1);
    ((u32*)stm_inbuf)[0x00] = 0x70000000;
	IOS_Ioctl( di_fd, stm_inbuf[0x00], stm_inbuf, 0x20, stm_iobuf, 0x20);	
	printf("    DVD ID : %s \n\n",stm_iobuf);
	IOS_Close(di_fd);
	
	//GRRLIB_DrawImg(10,50, music_width, music_high, music_img, 0, 1);
	//GRRLIB_Render();
	
	printf("    Press + to rumble\n");
	printf("    Press - to stop\n\n");
	
	printf("    Press A to continue\n");
	while(1) {
		VIDEO_WaitVSync();
		if ((buttonA==1)){
		    console();
            clearscreen();
	        menutext();
			__STM_Close();
	        return;       
	    }
		if ((buttonPlus==1)){
		    rumble=1;
		}
		if ((buttonMinus==1)){
		    rumble=0;
		}
	}
}

void menu(void) {
    clearscreen();
	menutext();
	while(1) {
		VIDEO_WaitVSync();
	    checkAndReload();
		if ((buttonLeft==1)){
            fun();
	    }
		if ((buttonRight==1)){
            shutdown();
	    }
		if ((buttonDown==1)){
		    //sysutils();
		}
		if ((buttonUp==1)){
		    //elfloader();
		}
    }
}


void start(void) {
	if((buttonB==1)) {
	  menu();
	}
}

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

    /**************************************************************************** 
	Initialise Video
    Initialise GCPad for input
	****************************************************************************/

	GRRLIB_buffer=(u16 *)malloc(640*240*2);
		
	VIDEO_Init();
	PAD_Init();
	
	//rmode = &TVPal528IntDf;
	
	switch(VIDEO_GetCurrentTvMode()) {
		case VI_NTSC:
			rmode = &TVNtsc480IntDf;
			break;
		case VI_PAL:
			rmode = &TVPal528IntDf;
			break;
		case VI_MPAL:
			rmode = &TVMpal480IntDf;
			break;
		default:
			rmode = &TVNtsc480IntDf;
			break;
	}

	console();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
	
	printf("    Press 1&2\n\n");
	
	*((u32*)0xcd0000c0) |= 0x100;
	bte_init();
	bte_start();
	wiimotes = wiiuse_init(MAX_WIIMOTES,wiimote_event);
	wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
	wiiuse_connect(wiimotes, MAX_WIIMOTES);
	wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);
	wiiuse_rumble(wiimotes[0], 1);
	usleep(200000); /* 200ms */
	wiiuse_rumble(wiimotes[0], 0);
	
	clearscreen();
		
	GRRLIB_InitVideo();
	GRRLIB_Start();
	GRRLIB_FillScreen(0x0000);
	GRRLIB_Render();

	console();
	
    /**************************************************************************** 
	Main code
	****************************************************************************/

	hello();
	printf("\n");
	printf("    My first native wii homebrew\n\n");
	printf("    Press B :-)\n\n");
	
	while(1) {
		VIDEO_WaitVSync();
		start();	
	}
	
	return 0;
}

Updates

These may be updates/fixes for the code above

  • I was able to compile your code. I think you need the most recent cvs of the libogc use Drack's guide

http://www.tehskeen.com/forums/showthread.php?t=2968

    • Thanks for that now i just have an error about usb functions in libbte

Also you should not include .c files in the header.