Difference between revisions of "User:Cboomf"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
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. | 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 : === | ===Code dump : === | ||
Line 22: | Line 24: | ||
#include "stm.c" | #include "stm.c" | ||
#include "es.h" | #include "es.h" | ||
− | |||
− | |||
− | |||
− | |||
− | |||
#include "../gfx/music.h" | #include "../gfx/music.h" | ||
typedef void (*Loader_Entry)(void); | typedef void (*Loader_Entry)(void); | ||
− | static u32 * | + | static u32 *xbb; |
Loader_Entry loader = (Loader_Entry)0x80001800; | Loader_Entry loader = (Loader_Entry)0x80001800; | ||
− | + | void clearscreen(void) | |
− | |||
− | void | ||
{ | { | ||
− | + | int y; | |
− | + | for(y=0;y<34;y++) | |
+ | printf(" \n"); | ||
} | } | ||
Line 47: | Line 43: | ||
printf("Menu\n"); | printf("Menu\n"); | ||
printf("----\n"); | printf("----\n"); | ||
− | printf("Start + Z | + | printf("Start + Z = Return to loader\n"); |
printf("A !! = Elf Loader\n"); | printf("A !! = Elf Loader\n"); | ||
printf("B !! = System Utils\n"); | printf("B !! = System Utils\n"); | ||
printf("Y ! = Fun\n"); | printf("Y ! = Fun\n"); | ||
− | printf("X | + | printf("X !! = Shutdown Wii\n"); |
return; | return; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Line 68: | Line 57: | ||
loader(); | loader(); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Line 113: | Line 89: | ||
} | } | ||
return; | return; | ||
+ | } | ||
+ | |||
+ | void hello(void) | ||
+ | { | ||
+ | printf("Hello world!\n"); | ||
+ | printf("v 0.15"); | ||
} | } | ||
void shutdown(void) { | void shutdown(void) { | ||
− | + | static u8 stm_inbuf[0x20] ATTRIBUTE_ALIGN(32); | |
− | + | static u8 stm_iobuf[0x20] ATTRIBUTE_ALIGN(32); | |
− | + | int fd; | |
+ | |||
+ | fd=0; | ||
+ | fd=IOS_Open("/dev/stm/immediate", 2); | ||
+ | IOS_Ioctl(fd, 0x2004, stm_inbuf, 0x20, stm_iobuf, 0x20); | ||
+ | IOS_Close(fd); | ||
} | } | ||
void fun(void) { | void fun(void) { | ||
− | |||
− | |||
− | |||
− | |||
printf("FUN\n"); | printf("FUN\n"); | ||
− | |||
int ver; | int ver; | ||
int revma; | int revma; | ||
int revmi; | int revmi; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
ver=IOS_GetVersion(); | ver=IOS_GetVersion(); | ||
Line 143: | Line 119: | ||
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); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
printf("Press A to continue\n"); | printf("Press A to continue\n"); | ||
Line 166: | Line 126: | ||
int buttonsDown = PAD_ButtonsHeld(0); | int buttonsDown = PAD_ButtonsHeld(0); | ||
if (buttonsDown & PAD_BUTTON_A){ | if (buttonsDown & PAD_BUTTON_A){ | ||
− | |||
clearscreen(); | clearscreen(); | ||
menutext(); | menutext(); | ||
− | |||
return; | return; | ||
} | } | ||
Line 187: | Line 145: | ||
} | } | ||
if (buttonsDown & PAD_BUTTON_X){ | if (buttonsDown & PAD_BUTTON_X){ | ||
− | shutdown(); | + | //shutdown(); |
} | } | ||
if (buttonsDown & PAD_BUTTON_B){ | if (buttonsDown & PAD_BUTTON_B){ | ||
Line 214: | Line 172: | ||
****************************************************************************/ | ****************************************************************************/ | ||
− | |||
− | |||
VIDEO_Init(); | VIDEO_Init(); | ||
PAD_Init(); | PAD_Init(); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
switch(VIDEO_GetCurrentTvMode()) { | switch(VIDEO_GetCurrentTvMode()) { | ||
Line 240: | Line 191: | ||
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); | ||
− | + | xbb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); | |
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); | console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); | ||
Line 256: | Line 207: | ||
hello(); | hello(); | ||
printf("\n"); | printf("\n"); | ||
− | printf("My first native wii homebrew | + | printf("My first native wii homebrew\n"); |
− | printf(" | + | printf("\n"); |
while(1) { | while(1) { | ||
Line 266: | Line 217: | ||
return 0; | return 0; | ||
} | } | ||
+ | </source> | ||
+ | |||
+ | == Updates == | ||
+ | |||
+ | These may be updates/fixes for the code above | ||
+ | |||
+ | <source lang="c"> | ||
</source> | </source> |
Revision as of 12:07, 19 April 2008
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>
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
#include "ios.c"
#include "stm.c"
#include "es.h"
#include "../gfx/music.h"
typedef void (*Loader_Entry)(void);
static u32 *xbb;
Loader_Entry loader = (Loader_Entry)0x80001800;
void clearscreen(void)
{
int y;
for(y=0;y<34;y++)
printf(" \n");
}
void menutext(void)
{
printf("Menu\n");
printf("----\n");
printf("Start + Z = Return to loader\n");
printf("A !! = Elf Loader\n");
printf("B !! = System Utils\n");
printf("Y ! = Fun\n");
printf("X !! = Shutdown Wii\n");
return;
}
void checkAndReload(void) {
PAD_ScanPads();
int buttonsDown = PAD_ButtonsHeld(0);
if( (buttonsDown & PAD_TRIGGER_Z) && (buttonsDown & PAD_BUTTON_START)) {
loader();
}
}
void sysutils(void) {
bool pressed;
pressed=false;
clearscreen();
printf("System Utils Menu\n");
printf("-----------------\n\n");
printf("X = Load IOS37\n");
printf("Y = Load IOS9\n");
printf("B = Go Back\n");
printf("Press A to continue \n");
while((pressed=false)) {
VIDEO_WaitVSync();
PAD_ScanPads();
int buttonsDown = PAD_ButtonsHeld(0);
if (buttonsDown & PAD_BUTTON_X){
__IOS_LaunchNewIOS(37);
pressed=true;
}
if (buttonsDown & PAD_BUTTON_Y){
IOS_ReloadIOS(9);
pressed=true;
}
if (buttonsDown & PAD_BUTTON_B){
pressed=true;
}
}
return;
}
void hello(void)
{
printf("Hello world!\n");
printf("v 0.15");
}
void shutdown(void) {
static u8 stm_inbuf[0x20] ATTRIBUTE_ALIGN(32);
static u8 stm_iobuf[0x20] ATTRIBUTE_ALIGN(32);
int fd;
fd=0;
fd=IOS_Open("/dev/stm/immediate", 2);
IOS_Ioctl(fd, 0x2004, stm_inbuf, 0x20, stm_iobuf, 0x20);
IOS_Close(fd);
}
void fun(void) {
printf("FUN\n");
int ver;
int revma;
int revmi;
ver=IOS_GetVersion();
revma=IOS_GetRevisionMajor();
revmi=IOS_GetRevisionMinor();
printf("IOS Version : %d Revision : %d.%d \n\n", ver, revma, revmi);
printf("Press A to continue\n");
while(1) {
VIDEO_WaitVSync();
PAD_ScanPads();
int buttonsDown = PAD_ButtonsHeld(0);
if (buttonsDown & PAD_BUTTON_A){
clearscreen();
menutext();
return;
}
}
}
void menu(void) {
clearscreen();
menutext();
while(1) {
VIDEO_WaitVSync();
checkAndReload();
PAD_ScanPads();
int buttonsDown = PAD_ButtonsHeld(0);
if (buttonsDown & PAD_BUTTON_Y){
fun();
}
if (buttonsDown & PAD_BUTTON_X){
//shutdown();
}
if (buttonsDown & PAD_BUTTON_B){
//sysutils();
}
if (buttonsDown & PAD_BUTTON_A){
//elfloader();
}
}
}
void start(void) {
PAD_ScanPads();
int buttonsDown = PAD_ButtonsHeld(0);
if(buttonsDown & PAD_BUTTON_START) {
menu();
}
}
int main(int argc, char **argv) {
/****************************************************************************
Initialise Video
Initialise GCPad for input
****************************************************************************/
VIDEO_Init();
PAD_Init();
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;
}
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
xbb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(xfb,20,20,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();
/****************************************************************************
Main code
****************************************************************************/
hello();
printf("\n");
printf("My first native wii homebrew\n");
printf("\n");
while(1) {
VIDEO_WaitVSync();
start();
}
return 0;
}
Updates
These may be updates/fixes for the code above