#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gccore.h>
#ifdef HW_RVL
#include <wiiuse/wpad.h>
#endif
#define VERSION 5
/*
Sram Flags info
bit(s) Description
7 ? (=0)
6 ? (=0)
5 ? (=1)
4 ? (=0)
3 ? (=1)
2 0: mono 1: stereo
1 ? (=0)
0 ? (=0)
*/
#define SRAM_AUDIOBIT 2
#define SRAM_ENGLISH 0
#define SRAM_GERMAN 1
#define SRAM_FRENCH 2
#define SRAM_SPANISH 3
#define SRAM_ITALIAN 4
#define SRAM_DUTCH 5
extern syssram* __SYS_LockSram();
extern syssramex* __SYS_LockSramEx();
extern u32 __SYS_UnlockSram(u32 write);
extern u32 __SYS_UnlockSramEx(u32 write);
void SYS_SetSramLang(u8 lang)
{
u32 write;
syssram *sram;
write = 0;
sram = __SYS_LockSram();
if(sram->lang != lang) {
sram->lang = lang;
write = 1;
}
__SYS_UnlockSram(write);
}
u8 SYS_GetSramLang()
{
u8 lang;
syssram *sram;
lang = 0;
sram = __SYS_LockSram();
lang = sram->lang;
__SYS_UnlockSram(0);
return lang;
}
void SYS_SetSramFlags(u8 flags)
{
u32 write;
syssram *sram;
write = 0;
sram = __SYS_LockSram();
if(sram->flags != flags) {
sram->flags = flags;
write = 1;
}
__SYS_UnlockSram(write);
}
u8 SYS_GetSramFlags()
{
u8 flags;
syssram *sram;
flags = 0;
sram = __SYS_LockSram();
flags = sram->flags;
__SYS_UnlockSram(0);
return flags;
}
//callbacks
int reboot=0, shutdown=0;
void __Sys_ResetCallback(void)
{
/* Reboot console */
reboot=1;
}
void __Sys_PowerCallback(void)
{
/* Poweroff console */
shutdown=1;
}
void __Wpad_PowerCallback(s32 chan)
{
/* Poweroff console */
shutdown=1;
}
void Shutdown()
{
SYS_ResetSystem(SYS_POWEROFF, 0, 0);
}
void Reboot()
{
if (*(u32*)0x80001800) exit(0);
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
}
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
u8 language, flags;
char srambuff[64];
syssram *sram;
syssramex *sramex;
// Initialise the video system
VIDEO_Init();
//set callbacks
SYS_SetResetCallback(__Sys_ResetCallback);
PAD_Init();
#ifdef HW_RVL
SYS_SetPowerCallback(__Sys_PowerCallback);
// This function initialises the attached controllers
WPAD_Init();
WPAD_SetIdleTimeout(60);
WPAD_SetPowerButtonCallback(__Wpad_PowerCallback);
#endif
// 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();
again:
// 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("\tOpen Sram Language Modifier v%d by suloku\n\n", VERSION);
printf("Current Sram language: ");
language = SYS_GetSramLang();
switch (language){
case SRAM_ENGLISH:
printf("\x1b[32;1mEnglish \n\n");
break;
case SRAM_GERMAN:
printf("\x1b[32;1mGerman \n\n");
break;
case SRAM_FRENCH:
printf("\x1b[32;1mFrench \n\n");
break;
case SRAM_SPANISH:
printf("\x1b[32;1mSpanish \n\n");
break;
case SRAM_ITALIAN:
printf("\x1b[32;1mItalian \n\n");
break;
case SRAM_DUTCH:
printf("\x1b[32;1mDutch \n\n");
break;
default:
printf("\x1b[31;1mSomething went wrong");
break;
}
printf("\x1b[37;1m");
printf("Current audio flag: ");
flags = SYS_GetSramFlags();
if ( ( flags & (1 << SRAM_AUDIOBIT) ) ){
printf("\x1b[31;1mStereo\n");
}else{
printf("\x1b[31;1mMono \n");
}
printf("\x1b[37;1m");
#ifdef HW_RVL
printf("Press DOWN/Z to toogle between MONO and STEREO\n\n");
printf("Press one of the following to change the Sram language:\n"); printf("\t\t\t");
printf(" A : English \t\t\t");
printf(" B : German \n"); printf("\t\t\t");
printf("-/Y: French \t\t\t");
printf("+/X: Spanish \n"); printf("\t\t\t");
printf("1/R: Italian \t\t\t");
printf("2/L: Dutch \n\n");
printf("\x1b[31;1mWarning! \x1b[37;1mIf you launch your gamecube game from the wii's disk channel sram will be reset to default! Please use an alternative loading method.\n\n");
printf("Press HOME/START to exit\n\n");
#else
printf("Press Z to toogle between MONO and STEREO\n\n");
printf("Press one of the following to change the Sram language:\n"); printf("\t\t\t");
printf("A: English \t\t\t");
printf("B: German \n"); printf("\t\t\t");
printf("Y: French \t\t\t");
printf("X: Spanish \n"); printf("\t\t\t");
printf("R: Italian \t\t\t");
printf("L: Dutch \n\n");
printf("Press START to exit\n\n");
#endif
//should use the sizeof versions, but in current libogc git (27 aug 2012)
//syssramex->flash_id is declared as u16 and it is u8, resulting in
//syssramex structure being 46 bytes instead of 44 (full sram being 64 bytes)
sram = __SYS_LockSram();
//memcpy(srambuff, sram, sizeof(syssram));
memcpy(srambuff, sram, 20);
__SYS_UnlockSram(0);
sramex = __SYS_LockSramEx();
//memcpy(srambuff+sizeof(syssram), sramex, sizeof(sissramex));
memcpy(srambuff+20, sramex, 44);
__SYS_UnlockSramEx(0);
int i;
printf("SRAM Hex View\n\n");
printf(" \t\t 0 1 2 3 4 5 6 7 8 9 A B C D E F\n");
for (i=0;i<64;i++){
if( (i%16) == 0 )
printf("\n0x%d0h\t\t", i/16);
if (i==0x12){
printf("\x1b[32;1m%02X ", srambuff[i]);
printf("\x1b[37;1m");
}else if (i==0x13){
printf("\x1b[31;1m%02X ", srambuff[i]);
printf("\x1b[37;1m");
}else{
printf("%02X ", srambuff[i]);
}
}
while(1) {
PAD_ScanPads();
u32 pressedgc = PAD_ButtonsDown(0);
#ifdef HW_RVL
// 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);
#endif
if ( pressedgc & PAD_BUTTON_A
#ifdef HW_RVL
|| pressed & WPAD_BUTTON_A
#endif
)
SYS_SetSramLang(SRAM_ENGLISH);
if ( pressedgc & PAD_BUTTON_B
#ifdef HW_RVL
|| pressed & WPAD_BUTTON_B
#endif
)
SYS_SetSramLang(SRAM_GERMAN);
if ( pressedgc & PAD_BUTTON_Y
#ifdef HW_RVL
|| pressed & WPAD_BUTTON_MINUS
#endif
)
SYS_SetSramLang(SRAM_FRENCH);
if ( pressedgc & PAD_BUTTON_X
#ifdef HW_RVL
|| pressed & WPAD_BUTTON_PLUS
#endif
)
SYS_SetSramLang(SRAM_SPANISH);
if ( pressedgc & PAD_TRIGGER_R
#ifdef HW_RVL
|| pressed & WPAD_BUTTON_1
#endif
)
SYS_SetSramLang(SRAM_ITALIAN);
if ( pressedgc & PAD_TRIGGER_L
#ifdef HW_RVL
|| pressed & WPAD_BUTTON_2
#endif
)
SYS_SetSramLang(SRAM_DUTCH);
if ( pressedgc & PAD_TRIGGER_Z
#ifdef HW_RVL
|| pressed & WPAD_BUTTON_DOWN
#endif
){
flags ^= 1 << SRAM_AUDIOBIT;
SYS_SetSramFlags(flags);
}
// We return to the launcher application via exit
if ( reboot || pressedgc & PAD_BUTTON_START
#ifdef HW_RVL
|| pressed & WPAD_BUTTON_HOME
#endif
) Reboot();
if (shutdown)
Shutdown();
if ( pressedgc
#ifdef HW_RVL
|| pressed
#endif
) goto again;
// Wait for the next frame
VIDEO_WaitVSync();
}
return 0;
}