Hello.
So I started looking into programming for the Wii.
I installed DevKitPPC and successfully completed the HelloWorld tutorial.
Compiled the dol and ran it. So far so good.
Now I am trying to write my own first program... A very simple one that when ran will tell how much disk space is left on the USB hard drive.
I have been looking over the usbstorage.h file, as this was the only one I could see that had anything to do with the USB hard drive.
I believe the command I need to use is this one: s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors);
However I am unsure how to actually use it, I'm guessing I need to fill in some information for each variable inside the ()'s, but I have no clue what to put in.
If you could shed some light for me, it would be much appreciated.
So I started looking into programming for the Wii.
I installed DevKitPPC and successfully completed the HelloWorld tutorial.
Compiled the dol and ran it. So far so good.
Now I am trying to write my own first program... A very simple one that when ran will tell how much disk space is left on the USB hard drive.
I have been looking over the usbstorage.h file, as this was the only one I could see that had anything to do with the USB hard drive.
I believe the command I need to use is this one: s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors);
However I am unsure how to actually use it, I'm guessing I need to fill in some information for each variable inside the ()'s, but I have no clue what to put in.
If you could shed some light for me, it would be much appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <fat.h>
#include <ogc/usbstorage.h>
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 );
printf("\x1b[2;0H");
printf("RiCK420 has taken over your Wii! Please wait patiently! \n");
printf("\n");
// RiCK's code BEGIN //
// Initialize file system (FAT)
if (!fatInitDefault()) {
printf("Unable to initialize FAT subsystem. \n");
printf("\n");
}
else {
printf("Initialized FAT subsystem, exiting. \n");
printf("\n");
}
// Change dir to root
int chdir();
if (chdir("/")) {
printf("Could not change to root directory. \n");
printf("\n");
}
else {
printf("Directory succesfully changed to root. \n");
printf("\n");
}
// Above this point is working and does something, however I am unsure if this is even needed?
// Is this only for the SD card maybe?
// This stuff looks more like it is for the USBStorage specifically
s32 USBStorage_Initialize(); // This doesn't give any errors so I guess it worked.
s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors);
// ^ This line needs some work, it doesn't output anything like I expected it too.
// Maybe all those variables in the () need to actually be filled in with some information?
// Exiting Routine
fatUnmount(0);
printf("...EXITING! \n");
exit(0);
// RiCK's code END //
while(1) {
// 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);
// Wait for the next frame
VIDEO_WaitVSync();
}
return 0;
}